efi_loader: manage protocols in a linked list (v3)
v3 cover efi_loader: manage protocols in a linked list (v3)
Up to now the protocols of an EFI handle where contained in an array of fixed size. With the patch series the protocols are managed in a linked list. This both saves memory and gives more flexibility.
The LocateDevicePath boot service is implemented according to the UEFI specification.
A unit test for the LocateDevicePath boot service and the device path to text protocol are added.
Some bug fixes are provided.
v3
Remove patch
efi_loader: efi_bootmgr: do not make hidden assignments (A patch to add device path printing in printf() is pending.)
Resubmit
efi_loader: helloworld.c: remove superfluous include
v2
Enhance the helloworld example to check if the image handle is passed corectly. Adjust the related py test.
Use a helper function to initialize EFI objects.
Further minor bug fixes.
Heinrich Schuchardt (18):
efi_loader: helloworld.c: remove superfluous include
efi_loader: size of media device path node represenation
efi_loader: efi_dp_str should print path not node
efi_loader: fix efi_convert_device_node_to_text
efi_loader: reimplement LocateDevicePath
efi_selftest: test EFI_DEVICE_PATH_TO_TEXT_PROTOCOL
efi_loader: efi_disk: use efi_add_protocol
efi_loader: efi_net: use efi_add_protocol
efi_loader: efi_gop: use efi_add_protocol
efi_loader: simplify efi_open_protocol
efi_loader: simplify find_obj
efi_loader: manage protocols in a linked list
efi_selftest: compile without special compiler flags
efi_selftest: add missing line feed
efi_loader: output load options in helloworld test/py: check return code of helloworld
efi_loader: pass handle of loaded image
efi_loader: helper function to add EFI object to list
cmd/bootefi.c | 7 +- include/efi_loader.h | 8 +- lib/efi_loader/efi_boottime.c | 287 ++++++++++++--------- lib/efi_loader/efi_device_path.c | 43 ++-- lib/efi_loader/efi_device_path_to_text.c | 167 ++++++------ lib/efi_loader/efi_disk.c | 38 +-- lib/efi_loader/efi_gop.c | 16 +- lib/efi_loader/efi_net.c | 35 +-- lib/efi_loader/helloworld.c | 38 ++- lib/efi_selftest/Makefile | 24 +- lib/efi_selftest/efi_selftest.c | 2 +- lib/efi_selftest/efi_selftest_devicepath.c | 391 +++++++++++++++++++++++++++++ test/py/tests/test_efi_loader.py | 2 + 13 files changed, 770 insertions(+), 288 deletions(-) create mode 100644 lib/efi_selftest/efi_selftest_devicepath.c
Signature · 1 line
2.14.2
PATCH v3 1/18 efi_loader: helloworld.c: remove superfluous include
Remove a superfluous include from helloworld.c
---
v3
resubmitted patch added
--- lib/efi_loader/helloworld.c | 1 - 1 file changed, 1 deletion(-)
lib/efi_loader/helloworld.c +0 -1
@@ -8,7 +8,6 @@*/ #include <common.h> -#include <part_efi.h> #include <efi_api.h> efi_status_t EFIAPI efi_main(efi_handle_t handle,
Signature · 1 line
2.14.2
PATCH v3 2/18 efi_loader: size of media device path node represenation
In reply to Heinrich SchuchardtIn the format specifier we want to specify the maximum width in case an ending \0 is missing.
So slen must be used as precision and not as field width.
---
v3
no change
v2
no change
--- lib/efi_loader/efi_device_path_to_text.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/efi_loader/efi_device_path_to_text.c +1 -1
@@ -153,7 +153,7 @@ static char *dp_media(char *s, struct efi_device_path *dp)struct efi_device_path_file_path *fp = (struct efi_device_path_file_path *)dp;int slen = (dp->length -sizeof (*dp)) /2 ; - s +=sprintf (s,"/%-*ls" , slen, fp->str); + s +=sprintf (s,"/%-.*ls" , slen, fp->str);break ; }default :
Signature · 1 line
2.14.2
PATCH v3 3/18 efi_loader: efi_dp_str should print path not node
In reply to Heinrich Schuchardtefi_dp_str is meant to print a device path and not a device node.
The old coding only worked because efi_convert_device_node_to_text was screwed up to expect paths instead of nodes.
---
v3
no change
v2
no change
--- lib/efi_loader/efi_device_path_to_text.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
lib/efi_loader/efi_device_path_to_text.c +6 -7
@@ -208,13 +208,6 @@ static uint16_t *efi_convert_device_node_to_text(return out; } -/* helper for debug prints.. efi_free_pool() the result. */ -uint16_t *efi_dp_str (struct efi_device_path *dp) -{ -return efi_convert_device_node_to_text (dp, true, true); -} - - static uint16_t EFIAPI *efi_convert_device_node_to_text_ext( struct efi_device_path *device_node, bool display_only,
@@ -251,6 +244,12 @@ static uint16_t EFIAPI *efi_convert_device_path_to_text(return buffer; } +/* helper for debug prints.. efi_free_pool() the result. */ +uint16_t *efi_dp_str (struct efi_device_path *dp) +{ +return EFI_CALL (efi_convert_device_path_to_text (dp, true, true)); +} +const struct efi_device_path_to_text_protocol efi_device_path_to_text = { .convert_device_node_to_text = efi_convert_device_node_to_text_ext, .convert_device_path_to_text = efi_convert_device_path_to_text,
Signature · 1 line
2.14.2
PATCH v3 4/18 efi_loader: fix efi_convert_device_node_to_text
In reply to Heinrich SchuchardtWe need to implement to different functions for the EFI_DEVICE_PATH_TO_TEXT_PROTOCOL:
ConvertDeviceNodeToText ConvertDevicePathToText
A recent patch screwed up efi_convert_device_node_to_text to expect a device path and not a node.
The patch makes both service functions work again.
efi_convert_device_node_to_text is renamed to efi_convert_single_device_node_to_text and efi_convert_device_node_to_text_ext is renamed to efi_convert_device_node_to_text to avoid future confusion.
A test of ConvertDeviceNodeToText will be provided in a follow-up patch.
---
v3
Correctly handle NULL values.
v2
no change
--- lib/efi_loader/efi_device_path_to_text.c | 154 ++++++++++++++++++------------- 1 file changed, 88 insertions(+), 66 deletions(-)
lib/efi_loader/efi_device_path_to_text.c +88 -66
@@ -12,12 +12,31 @@#define MAC_OUTPUT_LEN 22#define UNKNOWN_OUTPUT_LEN 23 +#define MAX_NODE_LEN 512 +#define MAX_PATH_LEN 1024 +const efi_guid_t efi_guid_device_path_to_text_protocol =EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID ; +static u16 *efi_str_to_u16 (char *str) +{ +efi_uintn_t len; +u16 *out; +efi_status_t ret; + + len =strlen (str) +1 ; + ret =efi_allocate_pool (EFI_ALLOCATE_ANY_PAGES , len *sizeof (u16), + (void **)&out); +if (ret !=EFI_SUCCESS ) +return NULL ; +ascii2unicode (out, str); + out[len -1 ] =0 ; +return out; +} +static char *dp_unknown (char *s,struct efi_device_path *dp) { - s +=sprintf (s,"/UNKNOWN(%04x,%04x)" , dp->type, dp->sub_type); + s +=sprintf (s,"UNKNOWN(%04x,%04x)" , dp->type, dp->sub_type);return s; }
@@ -27,7 +46,7 @@ static char *dp_hardware(char *s, struct efi_device_path *dp)case DEVICE_PATH_SUB_TYPE_MEMORY : {struct efi_device_path_memory *mdp = (struct efi_device_path_memory *)dp; - s +=sprintf (s,"/MemoryMapped(0x%x,0x%llx,0x%llx)" , + s +=sprintf (s,"MemoryMapped(0x%x,0x%llx,0x%llx)" , mdp->memory_type, mdp->start_address, mdp->end_address);
@@ -36,7 +55,7 @@ static char *dp_hardware(char *s, struct efi_device_path *dp)case DEVICE_PATH_SUB_TYPE_VENDOR : {struct efi_device_path_vendor *vdp = (struct efi_device_path_vendor *)dp; - s +=sprintf (s,"/VenHw(%pUl)" , &vdp->guid); + s +=sprintf (s,"VenHw(%pUl)" , &vdp->guid);break ; }default :
@@ -52,7 +71,7 @@ static char *dp_acpi(char *s, struct efi_device_path *dp)case DEVICE_PATH_SUB_TYPE_ACPI_DEVICE : {struct efi_device_path_acpi_path *adp = (struct efi_device_path_acpi_path *)dp; - s +=sprintf (s,"/Acpi(PNP%04x" ,EISA_PNP_NUM (adp->hid)); + s +=sprintf (s,"Acpi(PNP%04x" ,EISA_PNP_NUM (adp->hid));if (adp->uid) s +=sprintf (s,",%d" , adp->uid); s +=sprintf (s,")" );
@@ -71,7 +90,7 @@ static char *dp_msging(char *s, struct efi_device_path *dp)case DEVICE_PATH_SUB_TYPE_MSG_USB : {struct efi_device_path_usb *udp = (struct efi_device_path_usb *)dp; - s +=sprintf (s,"/Usb(0x%x,0x%x)" , udp->parent_port_number, + s +=sprintf (s,"Usb(0x%x,0x%x)" , udp->parent_port_number, udp->usb_interface);break ; }
@@ -82,7 +101,7 @@ static char *dp_msging(char *s, struct efi_device_path *dp)if (mdp->if_type !=0 && mdp->if_type !=1 )break ; - s += sprintf(s, "/MAC(%02x%02x%02x%02x%02x%02x,0x%1x)", + s += sprintf(s, "MAC(%02x%02x%02x%02x%02x%02x,0x%1x)", mdp->mac.addr[0], mdp->mac.addr[1], mdp->mac.addr[2], mdp->mac.addr[3], mdp->mac.addr[4], mdp->mac.addr[5],
@@ -94,7 +113,7 @@ static char *dp_msging(char *s, struct efi_device_path *dp)struct efi_device_path_usb_class *ucdp = (struct efi_device_path_usb_class *)dp; - s +=sprintf (s,"/USBClass(%x,%x,%x,%x,%x)" , + s +=sprintf (s,"USBClass(%x,%x,%x,%x,%x)" , ucdp->vendor_id, ucdp->product_id, ucdp->device_class, ucdp->device_subclass, ucdp->device_protocol);
@@ -108,7 +127,7 @@ static char *dp_msging(char *s, struct efi_device_path *dp) "SDCard" : "MMC";struct efi_device_path_sd_mmc_path *sddp = (struct efi_device_path_sd_mmc_path *)dp; - s +=sprintf (s,"/%s(Slot%u)" , typename, sddp->slot_number); + s +=sprintf (s,"%s(Slot%u)" , typename, sddp->slot_number);break ; }default :
@@ -128,15 +147,15 @@ static char *dp_media(char *s, struct efi_device_path *dp)switch (hddp->signature_type) {case SIG_TYPE_MBR : - s +=sprintf (s,"/HD(Part%d,Sig%08x)" , + s +=sprintf (s,"HD(Part%d,Sig%08x)" , hddp->partition_number, *(uint32_t *)sig);break ;case SIG_TYPE_GUID : - s +=sprintf (s,"/HD(Part%d,Sig%pUl)" , + s +=sprintf (s,"HD(Part%d,Sig%pUl)" , hddp->partition_number, sig);default : - s +=sprintf (s,"/HD(Part%d,MBRType=%02x,SigType=%02x)" , + s +=sprintf (s,"HD(Part%d,MBRType=%02x,SigType=%02x)" , hddp->partition_number, hddp->partmap_type, hddp->signature_type); }
@@ -146,14 +165,16 @@ static char *dp_media(char *s, struct efi_device_path *dp)case DEVICE_PATH_SUB_TYPE_CDROM_PATH : {struct efi_device_path_cdrom_path *cddp = (struct efi_device_path_cdrom_path *)dp; - s +=sprintf (s,"/CDROM(0x%x)" , cddp->boot_entry); + s +=sprintf (s,"CDROM(0x%x)" , cddp->boot_entry);break ; }case DEVICE_PATH_SUB_TYPE_FILE_PATH : {struct efi_device_path_file_path *fp = (struct efi_device_path_file_path *)dp;int slen = (dp->length -sizeof (*dp)) /2 ; - s +=sprintf (s,"/%-.*ls" , slen, fp->str); +if (slen >MAX_NODE_LEN -2 ) + slen =MAX_NODE_LEN -2 ; + s +=sprintf (s,"%-.*ls" , slen, fp->str);break ; }default :
@@ -163,65 +184,59 @@ static char *dp_media(char *s, struct efi_device_path *dp)return s; } -static uint16_t *efi_convert_device_node_to_text ( -struct efi_device_path *dp, -bool display_only, -bool allow_shortcuts) +/* +* Converts a single node to a char string. +* +* @buffer output buffer +* @dp device path or node +* @return end of string +*/ +static char *efi_convert_single_device_node_to_text ( +char *buffer, +struct efi_device_path *dp) { -unsigned long len; -efi_status_t r; -char buf[512 ];/* this ought be be big enough for worst case */ -char *str = buf; -uint16_t *out; - -while (dp) { -switch (dp->type) { -case DEVICE_PATH_TYPE_HARDWARE_DEVICE : - str =dp_hardware (str, dp); -break ; -case DEVICE_PATH_TYPE_ACPI_DEVICE : - str =dp_acpi (str, dp); -break ; -case DEVICE_PATH_TYPE_MESSAGING_DEVICE : - str =dp_msging (str, dp); -break ; -case DEVICE_PATH_TYPE_MEDIA_DEVICE : - str =dp_media (str, dp); -break ; -default : - str =dp_unknown (str, dp); - } +char *str = buffer; - dp =efi_dp_next (dp); +switch (dp->type) { +case DEVICE_PATH_TYPE_HARDWARE_DEVICE : + str =dp_hardware (str, dp); +break ; +case DEVICE_PATH_TYPE_ACPI_DEVICE : + str =dp_acpi (str, dp); +break ; +case DEVICE_PATH_TYPE_MESSAGING_DEVICE : + str =dp_msging (str, dp); +break ; +case DEVICE_PATH_TYPE_MEDIA_DEVICE : + str =dp_media (str, dp); +break ; +default : + str =dp_unknown (str, dp); } - *str++ ='\0' ; - - len = str - buf; - r =efi_allocate_pool (EFI_ALLOCATE_ANY_PAGES ,2 * len, (void **)&out); -if (r !=EFI_SUCCESS ) -return NULL ; - -ascii2unicode (out, buf); - out[len -1 ] =0 ; - -return out; + *str ='\0' ; +return str; } -static uint16_t EFIAPI *efi_convert_device_node_to_text_ext( +static uint16_t EFIAPI *efi_convert_device_node_to_text(struct efi_device_path *device_node,bool display_only,bool allow_shortcuts) { -uint16_t *buffer; +char str[MAX_NODE_LEN ]; +uint16_t *text =NULL ;EFI_ENTRY ("%p, %d, %d" , device_node, display_only, allow_shortcuts); - buffer =efi_convert_device_node_to_text (device_node, display_only, - allow_shortcuts); +if (!device_node) + goto out; +efi_convert_single_device_node_to_text (str, device_node); + + text =efi_str_to_u16 (str); +out:EFI_EXIT (EFI_SUCCESS ); -return buffer; +return text; } static uint16_t EFIAPI *efi_convert_device_path_to_text(
@@ -229,19 +244,26 @@ static uint16_t EFIAPI *efi_convert_device_path_to_text(bool display_only, bool allow_shortcuts) { - uint16_t *buffer; + uint16_t *text = NULL; +char buffer[MAX_PATH_LEN ]; +char *str = buffer;EFI_ENTRY ("%p, %d, %d" , device_path, display_only, allow_shortcuts); -/* -* Our device paths are all of depth one. So its is sufficient to -* to convert the first node. -*/ - buffer =efi_convert_device_node_to_text (device_path, display_only, - allow_shortcuts); +if (!device_path) + goto out; +while (device_path && + str +MAX_NODE_LEN < buffer +MAX_PATH_LEN ) { + *str++ ='/' ; + str =efi_convert_single_device_node_to_text (str, device_path); + device_path =efi_dp_next (device_path); + } + + text =efi_str_to_u16 (buffer); +out:EFI_EXIT (EFI_SUCCESS ); -return buffer; +return text; }/* helper for debug prints.. efi_free_pool() the result. */
@@ -251,6 +273,6 @@ uint16_t *efi_dp_str(struct efi_device_path *dp) }const struct efi_device_path_to_text_protocol efi_device_path_to_text = { - .convert_device_node_to_text = efi_convert_device_node_to_text_ext, + .convert_device_node_to_text = efi_convert_device_node_to_text, .convert_device_path_to_text = efi_convert_device_path_to_text, };
Signature · 1 line
2.14.2
PATCH v3 5/18 efi_loader: reimplement LocateDevicePath
In reply to Heinrich SchuchardtThe current implementation of efi_locate_device_path does not match the UEFI specification. It completely ignores the protocol parameters.
---
v3
remove trailing dot in comment
v2
no change
--- lib/efi_loader/efi_boottime.c | 106 ++++++++++++++++++++++++++++++------------ 1 file changed, 76 insertions(+), 30 deletions(-)
lib/efi_loader/efi_boottime.c +76 -30
@@ -1080,36 +1080,6 @@ static efi_status_t EFIAPI efi_locate_handle_ext( buffer_size, buffer)); } -/* -* Get the device path and handle of an device implementing a protocol. -* -* This function implements the LocateDevicePath service. -* See the Unified Extensible Firmware Interface (UEFI) specification -* for details. -* -* @protocol GUID of the protocol -* @device_path device path -* @device handle of the device -* @return status code -*/ -static efi_status_t EFIAPI efi_locate_device_path( -const efi_guid_t *protocol, -struct efi_device_path **device_path, -efi_handle_t *device) -{ -struct efi_object *efiobj; - -EFI_ENTRY ("%pUl, %p, %p" , protocol, device_path, device); - - efiobj =efi_dp_find_obj (*device_path, device_path); -if (!efiobj) -return EFI_EXIT (EFI_NOT_FOUND ); - - *device = efiobj->handle; - -return EFI_EXIT (EFI_SUCCESS ); -} -/* Collapses configuration table entries, removing index i */ static void efi_remove_configuration_table (int i) {
@@ -1813,6 +1783,82 @@ static efi_status_t EFIAPI efi_locate_protocol(const efi_guid_t *protocol,return EFI_EXIT (EFI_NOT_FOUND ); } +/* +* Get the device path and handle of an device implementing a protocol. +* +* This function implements the LocateDevicePath service. +* See the Unified Extensible Firmware Interface (UEFI) specification +* for details. +* +* @protocol GUID of the protocol +* @device_path device path +* @device handle of the device +* @return status code +*/ +static efi_status_t EFIAPI efi_locate_device_path( +const efi_guid_t *protocol, +struct efi_device_path **device_path, +efi_handle_t *device) +{ +struct efi_device_path *dp; +size_t i; +struct efi_handler *handler; +efi_handle_t *handles; +size_t len, len_dp; +size_t len_best =0 ; +efi_uintn_t no_handles; +u8 *remainder; +efi_status_t ret; + +EFI_ENTRY ("%pUl, %p, %p" , protocol, device_path, device); + +if (!protocol || !device_path || !*device_path || !device) { + ret =EFI_INVALID_PARAMETER ; + goto out; + } + +/* Find end of device path */ + len =efi_dp_size (*device_path); + +/* Get all handles implementing the protocol */ + ret =EFI_CALL (efi_locate_handle_buffer (BY_PROTOCOL , protocol,NULL , + &no_handles, &handles)); +if (ret !=EFI_SUCCESS ) + goto out; + +for (i =0 ; i < no_handles; ++i) { +/* Find the device path protocol */ + ret =efi_search_protocol (handles[i], &efi_guid_device_path, + &handler); +if (ret !=EFI_SUCCESS ) +continue ; + dp = (struct efi_device_path *)handler->protocol_interface; + len_dp =efi_dp_size (dp); +/* +* This handle can only be a better fit +* if its device path length is longer than the best fit and +* if its device path length is shorter of equal the searched +* device path. +*/ +if (len_dp <= len_best || len_dp > len) +continue ; +/* Check if dp is a subpath of device_path */ +if (memcmp (*device_path, dp, len_dp)) +continue ; + *device = handles[i]; + len_best = len_dp; + } +if (len_best) { + remainder = (u8 *)*device_path + len_best; + *device_path = (struct efi_device_path *)remainder; + ret =EFI_SUCCESS ; + }else { + ret =EFI_NOT_FOUND ; + } +out: +return EFI_EXIT (ret); +} +/* * Install multiple protocol interfaces. *
Signature · 1 line
2.14.2
PATCH v3 6/18 efi_selftest: test EFI_DEVICE_PATH_TO_TEXT_PROTOCOL
In reply to Heinrich SchuchardtProvide a test for the EFI_DEVICE_PATH_TO_TEXT_PROTOCOL protocol.
---
v3
Print all installed device paths.
v2
No change
--- lib/efi_selftest/Makefile | 3 + lib/efi_selftest/efi_selftest_devicepath.c | 391 +++++++++++++++++++++++++++++ 2 files changed, 394 insertions(+) create mode 100644 lib/efi_selftest/efi_selftest_devicepath.c
lib/efi_selftest/Makefile +3 -0
@@ -11,6 +11,8 @@ CFLAGS_efi_selftest.o := $(CFLAGS_EFI) CFLAGS_REMOVE_efi_selftest.o := $(CFLAGS_NON_EFI) CFLAGS_efi_selftest_console.o := $(CFLAGS_EFI) CFLAGS_REMOVE_efi_selftest_console.o := $(CFLAGS_NON_EFI) +CFLAGS_efi_selftest_devicepathe.o := $(CFLAGS_EFI) +CFLAGS_REMOVE_efi_selftest_devicepath.o := $(CFLAGS_NON_EFI) CFLAGS_efi_selftest_events.o := $(CFLAGS_EFI) CFLAGS_REMOVE_efi_selftest_events.o := $(CFLAGS_NON_EFI) CFLAGS_efi_selftest_exitbootservices.o := $(CFLAGS_EFI)
@@ -33,6 +35,7 @@ CFLAGS_REMOVE_efi_selftest_watchdog.o := $(CFLAGS_NON_EFI) obj-$(CONFIG_CMD_BOOTEFI_SELFTEST) += \ efi_selftest.o \ efi_selftest_console.o \ +efi_selftest_devicepath.o \ efi_selftest_events.o \ efi_selftest_exitbootservices.o \ efi_selftest_gop.o \
lib/efi_selftest/efi_selftest_devicepath.c new file +390 -0
390 lines not on this page · raw message
Signature · 1 line
2.14.2
PATCH v3 7/18 efi_loader: efi_disk: use efi_add_protocol
In reply to Heinrich SchuchardtUse efi_add_protocol to install protocols.
---
v3
no change
v2
no change
--- lib/efi_loader/efi_disk.c | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-)
lib/efi_loader/efi_disk.c +23 -16
@@ -213,33 +213,40 @@ static void efi_disk_add_dev(const char *name, unsigned int part) {struct efi_disk_obj *diskobj; +efi_status_t ret;/* Don't add empty devices */ if (!desc->lba)return ; diskobj =calloc (1 ,sizeof (*diskobj)); -if (!diskobj) { -printf ("ERROR: Out of memory\n" ); -return ; - } +if (!diskobj) + goto out_of_memory; + +/* Hook up to the device list */ +list_add_tail (&diskobj->parent.link, &efi_obj_list);/* Fill in object data */ diskobj->dp =efi_dp_from_part (desc, part); diskobj->part = part; - diskobj->parent.protocols[0 ].guid = &efi_block_io_guid; - diskobj->parent.protocols[0 ].protocol_interface = &diskobj->ops; - diskobj->parent.protocols[1 ].guid = &efi_guid_device_path; - diskobj->parent.protocols[1 ].protocol_interface = diskobj->dp; + diskobj->parent.handle = diskobj; + ret =efi_add_protocol (diskobj->parent.handle, &efi_block_io_guid, + &diskobj->ops); +if (ret !=EFI_SUCCESS ) + goto out_of_memory; + ret =efi_add_protocol (diskobj->parent.handle, &efi_guid_device_path, + diskobj->dp); +if (ret !=EFI_SUCCESS ) + goto out_of_memory;if (part >=1 ) { diskobj->volume =efi_simple_file_system (desc, part, diskobj->dp); - diskobj->parent.protocols[2 ].guid = - &efi_simple_file_system_protocol_guid; - diskobj->parent.protocols[2 ].protocol_interface = - diskobj->volume; + ret =efi_add_protocol (diskobj->parent.handle, + &efi_simple_file_system_protocol_guid, + &diskobj->volume); +if (ret !=EFI_SUCCESS ) + goto out_of_memory; } - diskobj->parent.handle = diskobj; diskobj->ops = block_io_disk_template; diskobj->ifname = if_typename; diskobj->dev_index = dev_index;
@@ -253,9 +260,9 @@ static void efi_disk_add_dev(const char *name, diskobj->media.io_align = desc->blksz; diskobj->media.last_block = desc->lba - offset; diskobj->ops.media = &diskobj->media; - -/* Hook up to the device list */ -list_add_tail (&diskobj->parent.link, &efi_obj_list); +return ; +out_of_memory: +printf ("ERROR: Out of memory\n" ); } static int efi_disk_create_eltorito(struct blk_desc *desc,
Signature · 1 line
2.14.2
PATCH v3 8/18 efi_loader: efi_net: use efi_add_protocol
In reply to Heinrich SchuchardtUse efi_add_protocol to add protocols.
---
v3
no change
v2
no change
--- lib/efi_loader/efi_net.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-)
lib/efi_loader/efi_net.c +20 -14
@@ -292,20 +292,26 @@ int efi_net_register(void)/* We only expose the "active" eth device, so one is enough */ netobj =calloc (1 ,sizeof (*netobj)); -if (!netobj) { -printf ("ERROR: Out of memory\n" ); -return 1 ; - } +if (!netobj) + goto out_of_memory; + +/* Hook net up to the device list */ +list_add_tail (&netobj->parent.link, &efi_obj_list);/* Fill in object data */ - netobj->parent.protocols[0 ].guid = &efi_net_guid; - netobj->parent.protocols[0 ].protocol_interface = &netobj->net; - netobj->parent.protocols[1 ].guid = &efi_guid_device_path; - netobj->parent.protocols[1 ].protocol_interface = -efi_dp_from_eth (); - netobj->parent.protocols[2 ].guid = &efi_pxe_guid; - netobj->parent.protocols[2 ].protocol_interface = &netobj->pxe; netobj->parent.handle = &netobj->net; + r =efi_add_protocol (netobj->parent.handle, &efi_net_guid, + &netobj->net); +if (r !=EFI_SUCCESS ) + goto out_of_memory; + r =efi_add_protocol (netobj->parent.handle, &efi_guid_device_path, +efi_dp_from_eth ()); +if (r !=EFI_SUCCESS ) + goto out_of_memory; + r =efi_add_protocol (netobj->parent.handle, &efi_pxe_guid, + &netobj->pxe); +if (r !=EFI_SUCCESS ) + goto out_of_memory; netobj->net.revision =EFI_SIMPLE_NETWORK_PROTOCOL_REVISION ; netobj->net.start = efi_net_start; netobj->net.stop = efi_net_stop;
@@ -330,9 +336,6 @@ int efi_net_register(void)if (dhcp_ack) netobj->pxe_mode.dhcp_ack = *dhcp_ack; -/* Hook net up to the device list */ -list_add_tail (&netobj->parent.link, &efi_obj_list); -/* * Create WaitForPacket event. */
@@ -365,4 +368,7 @@ int efi_net_register(void) }return 0 ; +out_of_memory: +printf ("ERROR: Out of memory\n" ); +return 1 ; }
Signature · 1 line
2.14.2
PATCH v3 9/18 efi_loader: efi_gop: use efi_add_protocol
In reply to Heinrich SchuchardtUse efi_add_protocol to add protocol.
---
v3
no change
v2
no change
--- lib/efi_loader/efi_gop.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
lib/efi_loader/efi_gop.c +10 -5
@@ -132,6 +132,7 @@ int efi_gop_register(void)u32 bpix, col, row;u64 fb_base, fb_size;void *fb; +efi_status_t ret;#ifdef CONFIG_DM_VIDEO struct udevice *vdev;
@@ -178,10 +179,17 @@ int efi_gop_register(void)return 1 ; } +/* Hook up to the device list */ +list_add_tail (&gopobj->parent.link, &efi_obj_list); +/* Fill in object data */ - gopobj->parent.protocols[0 ].guid = &efi_gop_guid; - gopobj->parent.protocols[0 ].protocol_interface = &gopobj->ops; gopobj->parent.handle = &gopobj->ops; + ret =efi_add_protocol (gopobj->parent.handle, &efi_gop_guid, + &gopobj->ops); +if (ret !=EFI_SUCCESS ) { +printf ("ERROR: Out of memory\n" ); +return 1 ; + } gopobj->ops.query_mode = gop_query_mode; gopobj->ops.set_mode = gop_set_mode; gopobj->ops.blt = gop_blt;
@@ -210,8 +218,5 @@ int efi_gop_register(void) gopobj->bpix = bpix; gopobj->fb = fb; -/* Hook up to the device list */ -list_add_tail (&gopobj->parent.link, &efi_obj_list); -return 0 ; }
Signature · 1 line
2.14.2
PATCH v3 10/18 efi_loader: simplify efi_open_protocol
In reply to Heinrich SchuchardtUse function efi_search_protocol.
---
v3
no change
v2
no change
--- lib/efi_loader/efi_boottime.c | 36 ++++++------------------------------ 1 file changed, 6 insertions(+), 30 deletions(-)
lib/efi_loader/efi_boottime.c +6 -30
@@ -2051,8 +2051,7 @@ static efi_status_t EFIAPI efi_open_protocol( void **protocol_interface, void *agent_handle, void *controller_handle, uint32_t attributes) { - struct list_head *lhandle; -int i; + struct efi_handler *handler;efi_status_t r =EFI_INVALID_PARAMETER ; EFI_ENTRY("%p, %pUl, %p, %p, %p, 0x%x", handle, protocol,
@@ -2065,8 +2064,6 @@ static efi_status_t EFIAPI efi_open_protocol( goto out; } -EFI_PRINT_GUID ("protocol" , protocol); -switch (attributes) {case EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL :case EFI_OPEN_PROTOCOL_GET_PROTOCOL :
@@ -2087,33 +2084,12 @@ static efi_status_t EFIAPI efi_open_protocol( goto out; } -list_for_each (lhandle, &efi_obj_list) { -struct efi_object *efiobj; - efiobj = list_entry(lhandle, struct efi_object, link); - -if (efiobj->handle != handle) -continue ; - -for (i =0 ; i <ARRAY_SIZE (efiobj->protocols); i++) { -struct efi_handler *handler = &efiobj->protocols[i]; -const efi_guid_t *hprotocol = handler->guid; -if (!hprotocol) -continue ; -if (!guidcmp (hprotocol, protocol)) { -if (attributes != -EFI_OPEN_PROTOCOL_TEST_PROTOCOL ) { - *protocol_interface = - handler->protocol_interface; - } - r =EFI_SUCCESS ; - goto out; - } - } - goto unsupported; - } + r =efi_search_protocol (handle, protocol, &handler); +if (r !=EFI_SUCCESS ) + goto out; -unsupported: - r =EFI_UNSUPPORTED ; +if (attributes !=EFI_OPEN_PROTOCOL_TEST_PROTOCOL ) + *protocol_interface = handler->protocol_interface; out:return EFI_EXIT (r); }
Signature · 1 line
2.14.2
PATCH v3 11/18 efi_loader: simplify find_obj
In reply to Heinrich SchuchardtUse function efi_search_protocol().
---
v3
fix typo in commit message
v2
no change
--- lib/efi_loader/efi_device_path.c | 43 ++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 24 deletions(-)
lib/efi_loader/efi_device_path.c +19 -24
@@ -128,32 +128,27 @@ static struct efi_object *find_obj(struct efi_device_path *dp, bool short_path,struct efi_object *efiobj;list_for_each_entry (efiobj, &efi_obj_list, link) { -int i; - -for (i =0 ; i <ARRAY_SIZE (efiobj->protocols); i++) { -struct efi_handler *handler = &efiobj->protocols[i]; -struct efi_device_path *obj_dp; - -if (!handler->guid) -break ; - -if (guidcmp (handler->guid, &efi_guid_device_path)) -continue ; - - obj_dp = handler->protocol_interface; - -do { -if (efi_dp_match (dp, obj_dp) ==0 ) { -if (rem) { - *rem = ((void *)dp) + -efi_dp_size (obj_dp); - } -return efiobj; +struct efi_handler *handler; +struct efi_device_path *obj_dp; +efi_status_t ret; + + ret =efi_search_protocol (efiobj->handle, + &efi_guid_device_path, &handler); +if (ret !=EFI_SUCCESS ) +continue ; + obj_dp = handler->protocol_interface; + +do { +if (efi_dp_match (dp, obj_dp) ==0 ) { +if (rem) { + *rem = ((void *)dp) + +efi_dp_size (obj_dp); } +return efiobj; + } - obj_dp =shorten_path (efi_dp_next (obj_dp)); - }while (short_path && obj_dp); - } + obj_dp =shorten_path (efi_dp_next (obj_dp)); + }while (short_path && obj_dp); }return NULL ;
Signature · 1 line
2.14.2
PATCH v3 12/18 efi_loader: manage protocols in a linked list
In reply to Heinrich Schuchardt---
v3
no change
v2
no change
--- include/efi_loader.h | 6 ++- lib/efi_loader/efi_boottime.c | 107 ++++++++++++++++++++---------------------- lib/efi_loader/efi_disk.c | 1 + lib/efi_loader/efi_gop.c | 1 + lib/efi_loader/efi_net.c | 1 + 5 files changed, 58 insertions(+), 58 deletions(-)
include/efi_loader.h +4 -2
@@ -101,6 +101,8 @@ extern unsigned int __efi_runtime_rel_start, __efi_runtime_rel_stop;* interface (usually a struct with callback functions), this struct maps the * protocol GUID to the respective protocol interface */ struct efi_handler { +/* Link to the list of protocols of a handle */ +struct list_head link;const efi_guid_t *guid;void *protocol_interface; };
@@ -115,8 +117,8 @@ struct efi_handler {struct efi_object {/* Every UEFI object is part of a global object list */ struct list_head link; -/* We support up to 16 "protocols" an object can be accessed through */ -struct efi_handler protocols[16 ]; +/* The list of protocols */ +struct list_head protocols;/* The object spawner can either use this for data or as identifier */ void *handle; };
lib/efi_loader/efi_boottime.c +51 -56
175 lines not on this page · raw message
lib/efi_loader/efi_disk.c +1 -0
@@ -224,6 +224,7 @@ static void efi_disk_add_dev(const char *name, goto out_of_memory;/* Hook up to the device list */ +INIT_LIST_HEAD (&diskobj->parent.protocols);list_add_tail (&diskobj->parent.link, &efi_obj_list);/* Fill in object data */
lib/efi_loader/efi_gop.c +1 -0
@@ -180,6 +180,7 @@ int efi_gop_register(void) }/* Hook up to the device list */ +INIT_LIST_HEAD (&gopobj->parent.protocols);list_add_tail (&gopobj->parent.link, &efi_obj_list);/* Fill in object data */
lib/efi_loader/efi_net.c +1 -0
@@ -296,6 +296,7 @@ int efi_net_register(void) goto out_of_memory;/* Hook net up to the device list */ +INIT_LIST_HEAD (&netobj->parent.protocols);list_add_tail (&netobj->parent.link, &efi_obj_list);/* Fill in object data */
Signature · 1 line
2.14.2
PATCH v3 13/18 efi_selftest: compile without special compiler flags
In reply to Heinrich SchuchardtAs the selftest is not compiled as an EFI binary we do not need special compiler flags.
This avoids the checkarmreloc error on vexpress_ca15_tc2.
---
v3
no change
v2
no change
--- lib/efi_selftest/Makefile | 25 ------------------------- 1 file changed, 25 deletions(-)
lib/efi_selftest/Makefile +0 -25
@@ -7,31 +7,6 @@ # This file only gets included with CONFIG_EFI_LOADER set, so all # object inclusion implicitly depends on it -CFLAGS_efi_selftest.o := $(CFLAGS_EFI) -CFLAGS_REMOVE_efi_selftest.o := $(CFLAGS_NON_EFI) -CFLAGS_efi_selftest_console.o := $(CFLAGS_EFI) -CFLAGS_REMOVE_efi_selftest_console.o := $(CFLAGS_NON_EFI) -CFLAGS_efi_selftest_devicepathe.o := $(CFLAGS_EFI) -CFLAGS_REMOVE_efi_selftest_devicepath.o := $(CFLAGS_NON_EFI) -CFLAGS_efi_selftest_events.o := $(CFLAGS_EFI) -CFLAGS_REMOVE_efi_selftest_events.o := $(CFLAGS_NON_EFI) -CFLAGS_efi_selftest_exitbootservices.o := $(CFLAGS_EFI) -CFLAGS_REMOVE_efi_selftest_exitbootservices.o := $(CFLAGS_NON_EFI) -CFLAGS_efi_selftest_gop.o := $(CFLAGS_EFI) -CFLAGS_REMOVE_efi_selftest_gop.o := $(CFLAGS_NON_EFI) -CFLAGS_efi_selftest_manageprotocols.o := $(CFLAGS_EFI) -CFLAGS_REMOVE_efi_selftest_manageprotocols.o := $(CFLAGS_NON_EFI) -CFLAGS_efi_selftest_snp.o := $(CFLAGS_EFI) -CFLAGS_REMOVE_efi_selftest_snp.o := $(CFLAGS_NON_EFI) -CFLAGS_efi_selftest_textoutput.o := $(CFLAGS_EFI) -CFLAGS_REVMOE_efi_selftest_textoutput.o := $(CFLAGS_NON_EFI) -CFLAGS_efi_selftest_tpl.o := $(CFLAGS_EFI) -CFLAGS_REMOVE_efi_selftest_tpl.o := $(CFLAGS_NON_EFI) -CFLAGS_efi_selftest_util.o := $(CFLAGS_EFI) -CFLAGS_REMOVE_efi_selftest_util.o := $(CFLAGS_NON_EFI) -CFLAGS_efi_selftest_watchdog.o := $(CFLAGS_EFI) -CFLAGS_REMOVE_efi_selftest_watchdog.o := $(CFLAGS_NON_EFI) - obj-$(CONFIG_CMD_BOOTEFI_SELFTEST) += \ efi_selftest.o \ efi_selftest_console.o \
Signature · 1 line
2.14.2
PATCH v3 14/18 efi_selftest: add missing line feed
In reply to Heinrich SchuchardtAdd a missing line feed for an error message.
---
v3
no change
v2
new patch
--- lib/efi_selftest/efi_selftest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/efi_selftest/efi_selftest.c +1 -1
@@ -239,7 +239,7 @@ efi_status_t EFIAPI efi_selftest(efi_handle_t image_handle, ret = boottime->handle_protocol (image_handle, &efi_guid_loaded_image, (void **)&loaded_image);if (ret !=EFI_SUCCESS ) { -efi_st_error ("Cannot open loaded image protocol" ); +efi_st_error ("Cannot open loaded image protocol\n" );return ret; }
Signature · 1 line
2.14.2
PATCH v3 15/18 efi_loader: output load options in helloworld
In reply to Heinrich SchuchardtWe need to test if we pass a valid image handle when loading and EFI application. This cannot be done in efi_selftest as it is not loaded as an image.
So let's enhance helloworld a bit.
---
v3
no change
v2
new patch
--- lib/efi_loader/helloworld.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-)
lib/efi_loader/helloworld.c +35 -2
@@ -5,19 +5,52 @@* Written by Simon Glass <[email protected]> * * SPDX-License-Identifier: GPL-2.0+ +* +* This program demonstrates calling a boottime service. +* It writes a greeting and the load options to the console. */ #include <common.h> #include <efi_api.h> +/* +* Entry point of the EFI application. +* +* @handle handle of the loaded image +* @systable system table +* @return status code +*/ efi_status_t EFIAPI efi_main(efi_handle_t handle,struct efi_system_table *systable) {struct efi_simple_text_output_protocol *con_out = systable->con_out;struct efi_boot_services *boottime = systable->boottime; +struct efi_loaded_image *loaded_image; +const efi_guid_t loaded_image_guid =LOADED_IMAGE_GUID ; +efi_status_t ret; con_out->output_string (con_out,L"Hello, world!\n" ); - boottime->exit (handle,0 ,0 ,NULL ); -return EFI_SUCCESS ; +/* Get the loaded image protocol */ + ret = boottime->handle_protocol (handle, &loaded_image_guid, + (void **)&loaded_image); +if (ret !=EFI_SUCCESS ) { + con_out->output_string (con_out, +L"Cannot open loaded image protocol\n" ); + goto out; + } +/* Output the load options */ + con_out->output_string (con_out,L"Load options: " ); +if (loaded_image->load_options_size && loaded_image->load_options) + con_out->output_string (con_out, + (u16 *)loaded_image->load_options); +else + con_out->output_string (con_out,L"<none>" ); + con_out->output_string (con_out,L"\n" ); + +out: + boottime->exit (handle, ret,0 ,NULL ); + +/* We should never arrive here */ +return ret; }
Signature · 1 line
2.14.2
PATCH v3 15/18 efi_loader: output load options in helloworld
Quoted 8 lines · Heinrich Schuchardt
We need to test if we pass a valid image handle when loading and EFI application. This cannot be done in
efi_selftestas it is not loaded as an image.So let's enhance helloworld a bit.
Reviewed-by Simon Glass <[email protected]>Signed-off-by Heinrich Schuchardt <[email protected]>
This particular patch/commit bbf75dd9345d0b1a7ec7a50016547eb7c759b7af ("efi_loader: output load options in helloworld") was bisected and causes the Lamobo_R1_defconfig build using the toolchain at [1] to fail with:
/home/fainelli/work/toolchains/stbgcc-6.3-1.1/bin/arm-linux-ld.bfd:
error: required section '.got' not found in the linker script /home/fainelli/work/toolchains/stbgcc-6.3-1.1/bin/arm-linux-ld.bfd:
final link failed: Invalid operation scripts/Makefile.lib:409: recipe for target 'lib/efi_loader/helloworld_efi.so' failed
make[2]: *** [lib/efi_loader/helloworld_efi.so] Error 1
rm lib/efi_loader/helloworld.oscripts/Makefile.build:425: recipe for target 'lib/efi_loader' failed make[1]: *** [lib/efi_loader] Error 2
[1]: https://github.com/Broadcom/stbgcc-6.3/releases/tag/stbgcc-6.3-1.1
Quoted 69 lines
---
v3
no change
v2
new patch--- lib/efi_loader/helloworld.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-)lib/efi_loader/helloworld.c +35
-2@@ -5,19 +5,52 @@* Written by Simon Glass <[email protected]> * * SPDX-License-Identifier: GPL-2.0+ +* +* This program demonstrates calling a boottime service. +* It writes a greeting and the load options to the console. */ #include <common.h> #include <efi_api.h> +/* +* Entry point of the EFI application. +* +* @handle handle of the loaded image +* @systable system table +* @return status code +*/ efi_status_t EFIAPI efi_main(efi_handle_t handle,struct efi_system_table *systable) {struct efi_simple_text_output_protocol *con_out = systable->con_out;struct efi_boot_services *boottime = systable->boottime; +struct efi_loaded_image *loaded_image; +const efi_guid_t loaded_image_guid =LOADED_IMAGE_GUID ; +efi_status_t ret; con_out->output_string (con_out,L"Hello, world!\n" ); - boottime->exit (handle,0 ,0 ,NULL ); -return EFI_SUCCESS ; +/* Get the loaded image protocol */ + ret = boottime->handle_protocol (handle, &loaded_image_guid, + (void **)&loaded_image); +if (ret !=EFI_SUCCESS ) { + con_out->output_string (con_out, +L"Cannot open loaded image protocol\n" ); + goto out; + } +/* Output the load options */ + con_out->output_string (con_out,L"Load options: " ); +if (loaded_image->load_options_size && loaded_image->load_options) + con_out->output_string (con_out, + (u16 *)loaded_image->load_options); +else + con_out->output_string (con_out,L"<none>" ); + con_out->output_string (con_out,L"\n" ); + +out: + boottime->exit (handle, ret,0 ,NULL ); + +/* We should never arrive here */ +return ret; }
Signature · 1 line
Florian
PATCH v3 15/18 efi_loader: output load options in helloworld
Quoted 28 lines · Florian Fainelli
Quoted 8 lines · Heinrich Schuchardt
We need to test if we pass a valid image handle when loading and EFI application. This cannot be done in
efi_selftestas it is not loaded as an image.So let's enhance helloworld a bit.
Reviewed-by Simon Glass <[email protected]>Signed-off-by Heinrich Schuchardt <[email protected]>This particular patch/commit
bbf75dd9345d0b1a7ec7a50016547eb7c759b7af("efi_loader: output load options in helloworld") was bisected and causes theLamobo_R1_defconfigbuild using the toolchain at [1] to fail with:
/home/fainelli/work/toolchains/stbgcc-6.3-1.1/bin/arm-linux-ld.bfd:
error: required section '.got' not found in the linker script/home/fainelli/work/toolchains/stbgcc-6.3-1.1/bin/arm-linux-ld.bfd:
final link failed: Invalid operationscripts/Makefile.lib:409: recipe for target 'lib/efi_loader/helloworld_efi.so' failed
make[2]: *** [lib/efi_loader/helloworld_efi.so] Error 1
rmlib/efi_loader/helloworld.oscripts/Makefile.build:425: recipe for target 'lib/efi_loader' failed make[1]: *** [lib/efi_loader] Error 2
Quoted 2 lines
[1]: https://github.com/Broadcom/stbgcc-6.3/releases/tag/stbgcc-6.3-1.1
Isn't this fixed by
http://git.denx.de/?p=u-boot.git;a=commit;h=3bb74f9800cdc4cf10a87f2725242c2565256654
"efi_loader helloworld.efi: Fix building with -Os" ?
Best Regards
Heinrich
Quoted 70 lines
Quoted 69 lines
---
v3
no change
v2
new patch--- lib/efi_loader/helloworld.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-)lib/efi_loader/helloworld.c +35
-2@@ -5,19 +5,52 @@* Written by Simon Glass <[email protected]> * * SPDX-License-Identifier: GPL-2.0+ +* +* This program demonstrates calling a boottime service. +* It writes a greeting and the load options to the console. */ #include <common.h> #include <efi_api.h> +/* +* Entry point of the EFI application. +* +* @handle handle of the loaded image +* @systable system table +* @return status code +*/ efi_status_t EFIAPI efi_main(efi_handle_t handle,struct efi_system_table *systable) {struct efi_simple_text_output_protocol *con_out = systable->con_out;struct efi_boot_services *boottime = systable->boottime; +struct efi_loaded_image *loaded_image; +const efi_guid_t loaded_image_guid =LOADED_IMAGE_GUID ; +efi_status_t ret; con_out->output_string (con_out,L"Hello, world!\n" ); - boottime->exit (handle,0 ,0 ,NULL ); -return EFI_SUCCESS ; +/* Get the loaded image protocol */ + ret = boottime->handle_protocol (handle, &loaded_image_guid, + (void **)&loaded_image); +if (ret !=EFI_SUCCESS ) { + con_out->output_string (con_out, +L"Cannot open loaded image protocol\n" ); + goto out; + } +/* Output the load options */ + con_out->output_string (con_out,L"Load options: " ); +if (loaded_image->load_options_size && loaded_image->load_options) + con_out->output_string (con_out, + (u16 *)loaded_image->load_options); +else + con_out->output_string (con_out,L"<none>" ); + con_out->output_string (con_out,L"\n" ); + +out: + boottime->exit (handle, ret,0 ,NULL ); + +/* We should never arrive here */ +return ret; }
PATCH v3 15/18 efi_loader: output load options in helloworld
Quoted 29 lines · Heinrich Schuchardt
Quoted 28 lines · Florian Fainelli
Quoted 8 lines · Heinrich Schuchardt
We need to test if we pass a valid image handle when loading and EFI application. This cannot be done in
efi_selftestas it is not loaded as an image.So let's enhance helloworld a bit.
Reviewed-by Simon Glass <[email protected]>Signed-off-by Heinrich Schuchardt <[email protected]>This particular patch/commit
bbf75dd9345d0b1a7ec7a50016547eb7c759b7af("efi_loader: output load options in helloworld") was bisected and causes theLamobo_R1_defconfigbuild using the toolchain at [1] to fail with:
/home/fainelli/work/toolchains/stbgcc-6.3-1.1/bin/arm-linux-ld.bfd:
error: required section '.got' not found in the linker script/home/fainelli/work/toolchains/stbgcc-6.3-1.1/bin/arm-linux-ld.bfd:
final link failed: Invalid operationscripts/Makefile.lib:409: recipe for target 'lib/efi_loader/helloworld_efi.so' failed
make[2]: *** [lib/efi_loader/helloworld_efi.so] Error 1
rmlib/efi_loader/helloworld.oscripts/Makefile.build:425: recipe for target 'lib/efi_loader' failed make[1]: *** [lib/efi_loader] Error 2
Quoted 7 lines
Quoted 2 lines
[1]: https://github.com/Broadcom/stbgcc-6.3/releases/tag/stbgcc-6.3-1.1
Isn't this fixed by
http://git.denx.de/?p=u-boot.git;a=commit;h=3bb74f9800cdc4cf10a87f2725242c2565256654"
efi_loaderhelloworld.efi: Fix building with -Os" ?
Nope, my tree is at v2018.01-rc1-115-g335f7b1290ce which contains that commit already.
Signature · 1 line
Florian
PATCH v3 15/18 efi_loader: output load options in helloworld
Quoted 35 lines · Florian Fainelli
Quoted 32 lines · Heinrich Schuchardt
Quoted 30 lines · Florian Fainelli
Quoted 8 lines · Heinrich Schuchardt
We need to test if we pass a valid image handle when loading and EFI application. This cannot be done in
efi_selftestas it is not loaded as an image.So let's enhance helloworld a bit.
Reviewed-by Simon Glass <[email protected]>Signed-off-by Heinrich Schuchardt <[email protected]>This particular patch/commit
bbf75dd9345d0b1a7ec7a50016547eb7c759b7af("efi_loader: output load options in helloworld") was bisected and causes theLamobo_R1_defconfigbuild using the toolchain at [1] to fail with:
/home/fainelli/work/toolchains/stbgcc-6.3-1.1/bin/arm-linux-ld.bfd:
error: required section '.got' not found in the linker script/home/fainelli/work/toolchains/stbgcc-6.3-1.1/bin/arm-linux-ld.bfd:
final link failed: Invalid operationscripts/Makefile.lib:409: recipe for target 'lib/efi_loader/helloworld_efi.so' failed
make[2]: *** [lib/efi_loader/helloworld_efi.so] Error 1
rmlib/efi_loader/helloworld.oscripts/Makefile.build:425: recipe for target 'lib/efi_loader' failed make[1]: *** [lib/efi_loader] Error 2[1]: https://github.com/Broadcom/stbgcc-6.3/releases/tag/stbgcc-6.3-1.1
Quoted 7 lines
Quoted 4 lines
Isn't this fixed by
http://git.denx.de/?p=u-boot.git;a=commit;h=3bb74f9800cdc4cf10a87f2725242c2565256654"
efi_loaderhelloworld.efi: Fix building with -Os" ?Nope, my tree is at v2018.01-rc1-115-g335f7b1290ce which contains that commit already.
Yeah, but the issue is the same :(
$ nm lib/efi_loader/helloworld.o
00000000 T efi_main
U memcpyGcc simply optimizes the loaded_image_guid assignment into a memcpy() and I can't find any way to prohibit it from doing that.
I guess the easiest way out of that mess is to just not do a dynamic struct assignment but instead put loaded_image_guid explicitly into the .rodata section.
I'll send a patch.
Alex
PATCH v3 16/18 test/py: check return code of helloworld
In reply to Heinrich SchuchardtCheck that helloworld.efi returns EFI_SUCCESS.
---
v3
no change
v2
new patch
--- test/py/tests/test_efi_loader.py | 2 ++ 1 file changed, 2 insertions(+)
test/py/tests/test_efi_loader.py +2 -0
@@ -154,6 +154,8 @@ def test_efi_helloworld_net(u_boot_console): output = u_boot_console.run_command('bootefi %x' % addr) expected_text = 'Hello, world' assert expected_text in output + expected_text = '## Application terminated, r = 0' + assert expected_text in output @pytest.mark.buildconfigspec('cmd_bootefi_hello') def test_efi_helloworld_builtin(u_boot_console):
Signature · 1 line
2.14.2
PATCH v3 17/18 efi_loader: pass handle of loaded image
In reply to Heinrich SchuchardtThe handle of a loaded image is the value of the handle member of the loaded image info object and not the address of the loaded image info.
---
v3
no change
v2
new patch
--- cmd/bootefi.c | 7 ++++--- lib/efi_loader/efi_boottime.c | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-)
cmd/bootefi.c +4 -3
@@ -254,7 +254,8 @@ static efi_status_t do_bootefi_exec(void *efi, void *fdt,dcache_disable ();/* flush cache before switch to EL2 */ /* Move into EL2 and keep running there */ -armv8_switch_to_el2 ((ulong )entry, (ulong)&loaded_image_info, +armv8_switch_to_el2 ((ulong )entry, + (ulong)&loaded_image_info_obj.handle, (ulong)&systab,0 , (ulong )efi_run_in_el2,ES_TO_AARCH64 );
@@ -263,7 +264,7 @@ static efi_status_t do_bootefi_exec(void *efi, void *fdt, }#endif - ret =efi_do_enter (&loaded_image_info, &systab, entry); + ret =efi_do_enter (loaded_image_info_obj.handle, &systab, entry); exit:/* image has returned, loaded-image obj goes *poof*: */
@@ -350,7 +351,7 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])/* Transfer environment variable efi_selftest as load options */ set_load_options (&loaded_image_info,"efi_selftest" );/* Execute the test */ - r =efi_selftest (&loaded_image_info, &systab); + r =efi_selftest (loaded_image_info_obj.handle, &systab);efi_restore_gd ();free (loaded_image_info.load_options);list_del (&loaded_image_info_obj.link);
lib/efi_loader/efi_boottime.c +1 -1
@@ -1317,7 +1317,7 @@ static efi_status_t EFIAPI efi_load_image(bool boot_policy, info->system_table = &systab; info->parent_handle = parent_image; - *image_handle = info; + *image_handle = obj->handle;return EFI_EXIT (EFI_SUCCESS ); }
Signature · 1 line
2.14.2
PATCH v3 18/18 efi_loader: helper function to add EFI object to list
In reply to Heinrich SchuchardtTo avoid duplicate coding provide a helper function that initializes an EFI object and adds it to the EFI object list.
efi_exit() is the only place where we dereference a handle to obtain a protocol interface. Add a comment to the function.
---
v3
no change
v2
new patch
--- include/efi_loader.h | 2 ++ lib/efi_loader/efi_boottime.c | 40 +++++++++++++++++++++++++++++++++------- lib/efi_loader/efi_disk.c | 4 +--- lib/efi_loader/efi_gop.c | 4 +--- lib/efi_loader/efi_net.c | 4 +--- 5 files changed, 38 insertions(+), 16 deletions(-)
include/efi_loader.h +2 -0
@@ -186,6 +186,8 @@ void efi_restore_gd(void);void efi_runtime_relocate (ulong offset,struct efi_mem_desc *map);/* Call this to set the current device name */ void efi_set_bootdev (const char *dev,const char *devnr,const char *path); +/* Add a new object to the object list. */ +void efi_add_handle (struct efi_object *obj);/* Create handle */ efi_status_t efi_create_handle (void **handle);/* Call this to validate a handle and find the EFI object for it */
lib/efi_loader/efi_boottime.c +33 -7
@@ -321,6 +321,23 @@ static efi_status_t EFIAPI efi_free_pool_ext(void *buffer)return EFI_EXIT (r); } +/* +* Add a new object to the object list. +* +* The protocols list is initialized. +* The object handle is set. +* +* @obj object to be added +*/ +void efi_add_handle (struct efi_object *obj) +{ +if (!obj) +return ; +INIT_LIST_HEAD (&obj->protocols); + obj->handle = obj; +list_add_tail (&obj->link, &efi_obj_list); +} +/* * Create handle. *
@@ -337,11 +354,8 @@ efi_status_t efi_create_handle(void **handle) (void **)&obj);if (r !=EFI_SUCCESS )return r; -memset (obj,0 ,sizeof (struct efi_object )); - obj->handle = obj; -INIT_LIST_HEAD (&obj->protocols); -list_add_tail (&obj->link, &efi_obj_list); - *handle = obj; +efi_add_handle (obj); + *handle = obj->handle;return r; }
@@ -1163,14 +1177,15 @@ void efi_setup_loaded_image(struct efi_loaded_image *info, struct efi_object *ob {efi_status_t ret; +/* Add internal object to object list */ +efi_add_handle (obj); +/* efi_exit() assumes that the handle points to the info */ obj->handle = info; info->file_path = file_path;if (device_path) info->device_handle =efi_dp_find_obj (device_path,NULL ); -INIT_LIST_HEAD (&obj->protocols); -list_add_tail (&obj->link, &efi_obj_list);/* * When asking for the device path interface, return * bootefi_device_path
@@ -1379,6 +1394,17 @@ static efi_status_t EFIAPI efi_exit(efi_handle_t image_handle, efi_status_t exit_status, unsigned long exit_data_size, int16_t *exit_data) { +/* +* We require that the handle points to the original loaded +* image protocol interface. +* +* For getting the longjmp address this is safer than locating +* the protocol because the protocol may have been reinstalled +* pointing to another memory location. +* +* TODO: We should call the unload procedure of the loaded +* image protocol. +*/ struct efi_loaded_image *loaded_image_info = (void *)image_handle; EFI_ENTRY("%p, %ld, %ld, %p", image_handle, exit_status,
lib/efi_loader/efi_disk.c +1 -3
@@ -224,13 +224,11 @@ static void efi_disk_add_dev(const char *name, goto out_of_memory;/* Hook up to the device list */ -INIT_LIST_HEAD (&diskobj->parent.protocols); -list_add_tail (&diskobj->parent.link, &efi_obj_list); +efi_add_handle (&diskobj->parent);/* Fill in object data */ diskobj->dp =efi_dp_from_part (desc, part); diskobj->part = part; - diskobj->parent.handle = diskobj; ret =efi_add_protocol (diskobj->parent.handle, &efi_block_io_guid, &diskobj->ops);if (ret !=EFI_SUCCESS )
lib/efi_loader/efi_gop.c +1 -3
@@ -180,11 +180,9 @@ int efi_gop_register(void) }/* Hook up to the device list */ -INIT_LIST_HEAD (&gopobj->parent.protocols); -list_add_tail (&gopobj->parent.link, &efi_obj_list); +efi_add_handle (&gopobj->parent);/* Fill in object data */ - gopobj->parent.handle = &gopobj->ops; ret =efi_add_protocol (gopobj->parent.handle, &efi_gop_guid, &gopobj->ops);if (ret !=EFI_SUCCESS ) {
lib/efi_loader/efi_net.c +1 -3
@@ -296,11 +296,9 @@ int efi_net_register(void) goto out_of_memory;/* Hook net up to the device list */ -INIT_LIST_HEAD (&netobj->parent.protocols); -list_add_tail (&netobj->parent.link, &efi_obj_list); +efi_add_handle (&netobj->parent);/* Fill in object data */ - netobj->parent.handle = &netobj->net; r =efi_add_protocol (netobj->parent.handle, &efi_net_guid, &netobj->net);if (r !=EFI_SUCCESS )
Signature · 1 line
2.14.2
v3 cover efi_loader: manage protocols in a linked list (v3)
In reply to Heinrich SchuchardtHi,
Quoted 40 lines · Heinrich Schuchardt
Up to now the protocols of an EFI handle where contained in an array of fixed size. With the patch series the protocols are managed in a linked list. This both saves memory and gives more flexibility.
The LocateDevicePath boot service is implemented according to the UEFI specification.
A unit test for the LocateDevicePath boot service and the device path to text protocol are added.
Some bug fixes are provided.
v3
Remove patch
efi_loader:efi_bootmgr: do not make hidden assignments (A patch to add device path printing inprintf()is pending.)
Resubmit
efi_loader:helloworld.c: remove superfluous include
v2
Enhance the helloworld example to check if the image handle is passed corectly. Adjust the related py test.Use a helper function to initialize EFI objects.
Further minor bug fixes.
Heinrich Schuchardt (18):
efi_loader:helloworld.c: remove superfluous include
efi_loader: size of media device path node represenation
efi_loader:efi_dp_strshould print path not node
efi_loader: fixefi_convert_device_node_to_text
efi_loader: reimplement LocateDevicePath
efi_selftest: testEFI_DEVICE_PATH_TO_TEXT_PROTOCOL
efi_loader:efi_disk: useefi_add_protocol
efi_loader:efi_net: useefi_add_protocol
efi_loader:efi_gop: useefi_add_protocol
efi_loader: simplifyefi_open_protocol
Quoted 9 lines
efi_loader: simplifyfind_obj
efi_loader: manage protocols in a linked list
efi_selftest: compile without special compiler flags
efi_selftest: add missing line feed
efi_loader: output load options in helloworld test/py: check return code of helloworld
efi_loader: pass handle of loaded image
efi_loader: helper function to add EFI object to list
This series seems to have been hanging around for a while. Is it going to be applied soon?
Regards,
Simon
v3 cover efi_loader: manage protocols in a linked list (v3)
Quoted 52 lines · Simon Glass
Hi,
Quoted 40 lines · Heinrich Schuchardt
Up to now the protocols of an EFI handle where contained in an array of fixed size. With the patch series the protocols are managed in a linked list. This both saves memory and gives more flexibility.
The LocateDevicePath boot service is implemented according to the UEFI specification.
A unit test for the LocateDevicePath boot service and the device path to text protocol are added.
Some bug fixes are provided.
v3
Remove patch
efi_loader:efi_bootmgr: do not make hidden assignments (A patch to add device path printing inprintf()is pending.)
Resubmit
efi_loader:helloworld.c: remove superfluous include
v2
Enhance the helloworld example to check if the image handle is passed corectly. Adjust the related py test.Use a helper function to initialize EFI objects.
Further minor bug fixes.
Heinrich Schuchardt (18):
efi_loader:helloworld.c: remove superfluous include
efi_loader: size of media device path node represenation
efi_loader:efi_dp_strshould print path not node
efi_loader: fixefi_convert_device_node_to_text
efi_loader: reimplement LocateDevicePath
efi_selftest: testEFI_DEVICE_PATH_TO_TEXT_PROTOCOL
efi_loader:efi_disk: useefi_add_protocol
efi_loader:efi_net: useefi_add_protocol
efi_loader:efi_gop: useefi_add_protocol
efi_loader: simplifyefi_open_protocolQuoted 9 lines
efi_loader: simplifyfind_obj
efi_loader: manage protocols in a linked list
efi_selftest: compile without special compiler flags
efi_selftest: add missing line feed
efi_loader: output load options in helloworld test/py: check return code of helloworld
efi_loader: pass handle of loaded image
efi_loader: helper function to add EFI object to list
Quoted 2 lines
This series seems to have been hanging around for a while. Is it going to be applied soon?
Well, v3 was only one day old by the time you wrote :). But yes, on it.
Alex