[U-Boot] [PATCH 17/18] efi_loader: refactor efi_setup_loaded_image

Heinrich Schuchardt xypron.glpk at gmx.de
Wed Nov 8 19:22:37 UTC 2017


On 11/08/2017 04:18 PM, Alexander Graf wrote:
> On 10/26/2017 07:25 PM, Heinrich Schuchardt wrote:
>> Use helper functions to add protocols.
>>
>> Signed-off-by: Heinrich Schuchardt <xypron.glpk at gmx.de>
>> ---
>>   lib/efi_loader/efi_boottime.c | 39 
>> +++++++++++++++++++++++++--------------
>>   1 file changed, 25 insertions(+), 14 deletions(-)
>>
>> diff --git a/lib/efi_loader/efi_boottime.c 
>> b/lib/efi_loader/efi_boottime.c
>> index a526280e4c..3f23e6d638 100644
>> --- a/lib/efi_loader/efi_boottime.c
>> +++ b/lib/efi_loader/efi_boottime.c
>> @@ -1193,34 +1193,45 @@ void efi_setup_loaded_image(struct 
>> efi_loaded_image *info, struct efi_object *ob
>>                   struct efi_device_path *device_path,
>>                   struct efi_device_path *file_path)
>>   {
>> +    efi_status_t ret;
>> +
>>       obj->handle = info;
>> +    info->file_path = file_path;
>> +    if (device_path)
>> +        info->device_handle = efi_dp_find_obj(device_path, NULL);
>> +
>> +    list_add_tail(&obj->link, &efi_obj_list);
>>       /*
>>        * When asking for the device path interface, return
>>        * bootefi_device_path
>>        */
>> -    obj->protocols[0].guid = &efi_guid_device_path;
>> -    obj->protocols[0].protocol_interface = device_path;
>> +    ret = efi_add_protocol(obj->handle, &efi_guid_device_path, 
>> device_path);
> 
> Can we always assume that there are no other protocols installed 
> already? The current code simply overrides them if there are any.
> 

efi_setup_loaded_image is called from efi_load_image with a newly 
allocated obj, from do_bootefi_exit and do_bootefi with an initial local 
obj. So there cannot be any protocol existing.

We unlink the image from the object list after use so none of the 
protocols will be available when calling the next EFI application.

Best regards

Heinrich

> 
> Alex
> 
>> +    if (ret != EFI_SUCCESS)
>> +        goto failure;
>>       /*
>>        * When asking for the loaded_image interface, just
>>        * return handle which points to loaded_image_info
>>        */
>> -    obj->protocols[1].guid = &efi_guid_loaded_image;
>> -    obj->protocols[1].protocol_interface = info;
>> -
>> -    obj->protocols[2].guid = &efi_guid_console_control;
>> -    obj->protocols[2].protocol_interface = (void *)&efi_console_control;
>> +    ret = efi_add_protocol(obj->handle, &efi_guid_loaded_image, info);
>> +    if (ret != EFI_SUCCESS)
>> +        goto failure;
>> -    obj->protocols[3].guid = &efi_guid_device_path_to_text_protocol;
>> -    obj->protocols[3].protocol_interface =
>> -        (void *)&efi_device_path_to_text;
>> +    ret = efi_add_protocol(obj->handle, &efi_guid_console_control,
>> +                   (void *)&efi_console_control);
>> +    if (ret != EFI_SUCCESS)
>> +        goto failure;
>> -    info->file_path = file_path;
>> -    if (device_path)
>> -        info->device_handle = efi_dp_find_obj(device_path, NULL);
>> +    ret = efi_add_protocol(obj->handle,
>> +                   &efi_guid_device_path_to_text_protocol,
>> +                   (void *)&efi_device_path_to_text);
>> +    if (ret != EFI_SUCCESS)
>> +        goto failure;
>> -    list_add_tail(&obj->link, &efi_obj_list);
>> +    return;
>> +failure:
>> +    printf("ERROR: Failure to install protocols for loaded image\n");
>>   }
>>   /*
> 
> 
> 



More information about the U-Boot mailing list