diff options
Diffstat (limited to 'common/efi')
-rw-r--r-- | common/efi/Kconfig | 27 | ||||
-rw-r--r-- | common/efi/Makefile | 6 | ||||
-rw-r--r-- | common/efi/devicepath.c | 830 | ||||
-rw-r--r-- | common/efi/efivar-filename.c | 116 | ||||
-rw-r--r-- | common/efi/errno.c | 90 | ||||
-rw-r--r-- | common/efi/guid.c | 97 | ||||
-rw-r--r-- | common/efi/payload/Makefile | 7 | ||||
-rw-r--r-- | common/efi/payload/env-efi/network/eth0-discover | 5 | ||||
-rw-r--r-- | common/efi/payload/fdt.c | 43 | ||||
-rw-r--r-- | common/efi/payload/image.c | 287 | ||||
-rw-r--r-- | common/efi/payload/init.c | 387 | ||||
-rw-r--r-- | common/efi/payload/iomem.c | 179 |
12 files changed, 0 insertions, 2074 deletions
diff --git a/common/efi/Kconfig b/common/efi/Kconfig deleted file mode 100644 index 15246ccbf0..0000000000 --- a/common/efi/Kconfig +++ /dev/null @@ -1,27 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only - -menu "EFI (Extensible Firmware Interface) Support" - -config EFI_BOOTUP - bool - select EFI - select EFI_GUID - select EFI_DEVICEPATH - select PRINTF_UUID - select PRINTF_WCHAR - select BLOCK - select PARTITION_DISK - select HW_HAS_PCI - -config EFI - bool - -config EFI_GUID - bool - help - With this option a table of EFI guids is compiled in. - -config EFI_DEVICEPATH - bool - -endmenu diff --git a/common/efi/Makefile b/common/efi/Makefile deleted file mode 100644 index a7cebde4f1..0000000000 --- a/common/efi/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only - -obj-$(CONFIG_EFI_BOOTUP) += payload/ -obj-$(CONFIG_EFI_GUID) += guid.o -obj-$(CONFIG_EFI_DEVICEPATH) += devicepath.o -obj-y += errno.o efivar-filename.o diff --git a/common/efi/devicepath.c b/common/efi/devicepath.c deleted file mode 100644 index 584f1fbd1d..0000000000 --- a/common/efi/devicepath.c +++ /dev/null @@ -1,830 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only - -#include <common.h> -#include <efi.h> -#include <malloc.h> -#include <string.h> -#include <wchar.h> -#include <efi/device-path.h> - -struct string { - char *str; - int len; -}; - -char *cprintf(struct string *str, const char *fmt, ...) - __attribute__ ((format(__printf__, 2, 3))); - -char *cprintf(struct string *str, const char *fmt, ...) -{ - va_list args; - int len; - - va_start(args, fmt); - if (str->str) - len = vsprintf(str->str + str->len, fmt, args); - else - len = vsnprintf(NULL, 0, fmt, args); - va_end(args); - - str->len += len; - - return NULL; -} - -#define MIN_ALIGNMENT_SIZE 8 /* FIXME: X86_64 specific */ -#define ALIGN_SIZE(a) ((a % MIN_ALIGNMENT_SIZE) ? MIN_ALIGNMENT_SIZE - (a % MIN_ALIGNMENT_SIZE) : 0) - -#define EFI_DP_TYPE_MASK 0x7f -#define EFI_DP_TYPE_UNPACKED 0x80 - -#define END_DEVICE_PATH_TYPE 0x7f - -#define END_ENTIRE_DEVICE_PATH_SUBTYPE 0xff -#define END_INSTANCE_DEVICE_PATH_SUBTYPE 0x01 -#define END_DEVICE_PATH_LENGTH (sizeof(struct efi_device_path)) - -#define DP_IS_END_TYPE(a) -#define DP_IS_END_SUBTYPE(a) ( ((a)->sub_type == END_ENTIRE_DEVICE_PATH_SUBTYPE ) - -#define device_path_type(a) ( ((a)->type) & EFI_DP_TYPE_MASK ) -#define next_device_path_node(a) ( (struct efi_device_path *) ( ((u8 *) (a)) + (a)->length)) -#define is_device_path_end_type(a) ( device_path_type(a) == END_DEVICE_PATH_TYPE ) -#define is_device_path_end_sub_type(a) ( (a)->sub_type == END_ENTIRE_DEVICE_PATH_SUBTYPE ) -#define is_device_path_end(a) ( is_device_path_end_type(a) && is_device_path_end_sub_type(a) ) -#define is_device_path_unpacked(a) ( (a)->type & EFI_DP_TYPE_UNPACKED ) - -#define set_device_path_end_node(a) { \ - (a)->type = END_DEVICE_PATH_TYPE; \ - (a)->sub_type = END_ENTIRE_DEVICE_PATH_SUBTYPE; \ - (a)->length = sizeof(struct efi_device_path); \ - } - -struct efi_device_path end_device_path = { - .type = END_DEVICE_PATH_TYPE, - .sub_type = END_ENTIRE_DEVICE_PATH_SUBTYPE, - .length = END_DEVICE_PATH_LENGTH, -}; - -struct efi_device_path end_instance_device_path = { - .type = END_DEVICE_PATH_TYPE, - .sub_type = END_INSTANCE_DEVICE_PATH_SUBTYPE, - .length = END_DEVICE_PATH_LENGTH, -}; - -struct efi_device_path * -device_path_from_handle(efi_handle_t Handle) -{ - efi_status_t Status; - struct efi_device_path *device_path; - - Status = BS->handle_protocol(Handle, &efi_device_path_protocol_guid, - (void *) &device_path); - if (EFI_ERROR(Status)) - device_path = NULL; - - return device_path; -} - -static struct efi_device_path * -unpack_device_path(const struct efi_device_path *dev_path) -{ - const struct efi_device_path *Src; - struct efi_device_path *Dest, *new_path; - unsigned long Size; - - /* Walk device path and round sizes to valid boundaries */ - - Src = dev_path; - Size = 0; - for (;;) { - Size += Src->length; - Size += ALIGN_SIZE(Size); - - if (is_device_path_end(Src)) { - break; - } - - Src = next_device_path_node(Src); - } - - new_path = xzalloc(Size); - - Src = dev_path; - Dest = new_path; - for (;;) { - Size = Src->length; - memcpy(Dest, Src, Size); - Size += ALIGN_SIZE(Size); - Dest->length = Size; - Dest->type |= EFI_DP_TYPE_UNPACKED; - Dest = - (struct efi_device_path *) (((u8 *) Dest) + Size); - - if (is_device_path_end(Src)) - break; - - Src = next_device_path_node(Src); - } - - return new_path; -} - -static void -dev_path_pci(struct string *str, void *dev_path) -{ - struct pci_device_path *Pci; - - Pci = dev_path; - cprintf(str, "Pci(0x%x,0x%x)", Pci->Device, Pci->Function); -} - -static void -dev_path_pccard(struct string *str, void *dev_path) -{ - struct pccard_device_path *Pccard; - - Pccard = dev_path; - cprintf(str, "Pccard(0x%x)", Pccard->function_number); -} - -static void -dev_path_mem_map(struct string *str, void *dev_path) -{ - struct memmap_device_path *mem_map; - - mem_map = dev_path; - cprintf(str, "mem_map(%d,0x%llx,0x%llx)", - mem_map->memory_type, - mem_map->starting_address, mem_map->ending_address); -} - -static void -dev_path_controller(struct string *str, void *dev_path) -{ - struct controller_device_path *Controller; - - Controller = dev_path; - cprintf(str, "Ctrl(%d)", Controller->Controller); -} - -static void -dev_path_vendor(struct string *str, void *dev_path) -{ - struct vendor_device_path *Vendor; - char *type; - struct unknown_device_vendor_device_path *unknown_dev_path; - - Vendor = dev_path; - switch (device_path_type(&Vendor->header)) { - case HARDWARE_DEVICE_PATH: - type = "Hw"; - break; - case MESSAGING_DEVICE_PATH: - type = "Msg"; - break; - case MEDIA_DEVICE_PATH: - type = "Media"; - break; - default: - type = "?"; - break; - } - - cprintf(str, "Ven%s(%pU", type, &Vendor->Guid); - if (efi_guidcmp(Vendor->Guid, efi_unknown_device_guid) == 0) { - /* GUID used by EFI to enumerate an EDD 1.1 device */ - unknown_dev_path = - (struct unknown_device_vendor_device_path *) Vendor; - cprintf(str, ":%02x)", unknown_dev_path->legacy_drive_letter); - } else { - cprintf(str, ")"); - } -} - -/* - type: 2 (ACPI Device Path) sub_type: 1 (ACPI Device Path) - */ -static void -dev_path_acpi(struct string *str, void *dev_path) -{ - struct acpi_hid_device_path *Acpi; - - Acpi = dev_path; - if ((Acpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) { - switch (EISA_ID_TO_NUM(Acpi->HID)) { - case 0x301: - cprintf(str, "Keyboard(%d)", Acpi->UID); - break; - - case 0x401: - cprintf(str, "parallel_port(%d)", Acpi->UID); - break; - case 0x501: - cprintf(str, "Serial(%d)", Acpi->UID); - break; - case 0x604: - cprintf(str, "Floppy(%d)", Acpi->UID); - break; - case 0xa03: - cprintf(str, "pci_root(%d)", Acpi->UID); - break; - case 0xa08: - cprintf(str, "pcie_root(%d)", Acpi->UID); - break; - default: - cprintf(str, "Acpi(PNP%04x", - EISA_ID_TO_NUM(Acpi->HID)); - if (Acpi->UID) - cprintf(str, ",%d", Acpi->UID); - cprintf(str, ")"); - break; - } - } else { - cprintf(str, "Acpi(0x%X", Acpi->HID); - if (Acpi->UID) - cprintf(str, ",%d", Acpi->UID); - cprintf(str, ")"); - } -} - -static void -dev_path_atapi(struct string *str, void *dev_path) -{ - struct atapi_device_path *Atapi; - - Atapi = dev_path; - cprintf(str, "Ata(%s,%s)", - Atapi->primary_secondary ? "Secondary" : "Primary", - Atapi->slave_master ? "Slave" : "Master"); -} - -static void -dev_path_scsi(struct string *str, void *dev_path) -{ - struct scsi_device_path *Scsi; - - Scsi = dev_path; - cprintf(str, "Scsi(%d,%d)", Scsi->Pun, Scsi->Lun); -} - -static void -dev_path_fibre(struct string *str, void *dev_path) -{ - struct fibrechannel_device_path *Fibre; - - Fibre = dev_path; - cprintf(str, "Fibre%s(0x%016llx,0x%016llx)", - device_path_type(&Fibre->header) == - MSG_FIBRECHANNEL_DP ? "" : "Ex", Fibre->WWN, Fibre->Lun); -} - -static void -dev_path1394(struct string *str, void *dev_path) -{ - struct f1394_device_path *F1394; - - F1394 = dev_path; - cprintf(str, "1394(%pU)", &F1394->Guid); -} - -static void -dev_path_usb(struct string *str, void *dev_path) -{ - struct usb_device_path *Usb; - - Usb = dev_path; - cprintf(str, "Usb(0x%x,0x%x)", Usb->Port, Usb->Endpoint); -} - -static void -dev_path_i2_o(struct string *str, void *dev_path) -{ - struct i2_o_device_path *i2_o; - - i2_o = dev_path; - cprintf(str, "i2_o(0x%X)", i2_o->Tid); -} - -static void -dev_path_mac_addr(struct string *str, void *dev_path) -{ - struct mac_addr_device_path *MAC; - unsigned long hw_address_size; - unsigned long Index; - - MAC = dev_path; - - /* hw_address_size = sizeof(EFI_MAC_ADDRESS); */ - hw_address_size = MAC->header.length; - hw_address_size -= sizeof (MAC->header); - hw_address_size -= sizeof (MAC->if_type); - if (MAC->if_type == 0x01 || MAC->if_type == 0x00) - hw_address_size = 6; - - cprintf(str, "Mac("); - - for (Index = 0; Index < hw_address_size; Index++) - cprintf(str, "%02x", MAC->mac_address.Addr[Index]); - - if (MAC->if_type != 0) - cprintf(str, ",%d", MAC->if_type); - - cprintf(str, ")"); -} - -static void -cat_print_iPv4(struct string *str, efi_ipv4_address * address) -{ - cprintf(str, "%d.%d.%d.%d", address->Addr[0], address->Addr[1], - address->Addr[2], address->Addr[3]); -} - -static bool -is_not_null_iPv4(efi_ipv4_address * address) -{ - u8 val; - - val = address->Addr[0] | address->Addr[1]; - val |= address->Addr[2] | address->Addr[3]; - - return val != 0; -} - -static void -cat_print_network_protocol(struct string *str, u16 Proto) -{ - if (Proto == 6) - cprintf(str, "TCP"); - else if (Proto == 17) - cprintf(str, "UDP"); - else - cprintf(str, "%d", Proto); -} - -static void -dev_path_iPv4(struct string *str, void *dev_path) -{ - struct ipv4_device_path *ip; - bool show; - - ip = dev_path; - cprintf(str, "IPv4("); - cat_print_iPv4(str, &ip->remote_ip_address); - cprintf(str, ","); - cat_print_network_protocol(str, ip->Protocol); - cprintf(str, ",%s", ip->static_ip_address ? "Static" : "DHCP"); - show = is_not_null_iPv4(&ip->local_ip_address); - if (!show - && ip->header.length == - sizeof (struct ipv4_device_path)) { - /* only version 2 includes gateway and netmask */ - show |= is_not_null_iPv4(&ip->gateway_ip_address); - show |= is_not_null_iPv4(&ip->subnet_mask); - } - if (show) { - cprintf(str, ","); - cat_print_iPv4(str, &ip->local_ip_address); - if (ip->header.length == - sizeof (struct ipv4_device_path)) { - /* only version 2 includes gateway and netmask */ - show = is_not_null_iPv4(&ip->gateway_ip_address); - show |= is_not_null_iPv4(&ip->subnet_mask); - if (show) { - cprintf(str, ","); - cat_print_iPv4(str, &ip->gateway_ip_address); - if (is_not_null_iPv4(&ip->subnet_mask)) { - cprintf(str, ","); - cat_print_iPv4(str, &ip->subnet_mask); - } - } - } - } - cprintf(str, ")"); -} - -#define cat_print_iPv6_ADD( x , y ) ( ( (u16) ( x ) ) << 8 | ( y ) ) -static void -cat_print_ipv6(struct string *str, efi_ipv6_address * address) -{ - cprintf(str, "%x:%x:%x:%x:%x:%x:%x:%x", - cat_print_iPv6_ADD(address->Addr[0], address->Addr[1]), - cat_print_iPv6_ADD(address->Addr[2], address->Addr[3]), - cat_print_iPv6_ADD(address->Addr[4], address->Addr[5]), - cat_print_iPv6_ADD(address->Addr[6], address->Addr[7]), - cat_print_iPv6_ADD(address->Addr[8], address->Addr[9]), - cat_print_iPv6_ADD(address->Addr[10], address->Addr[11]), - cat_print_iPv6_ADD(address->Addr[12], address->Addr[13]), - cat_print_iPv6_ADD(address->Addr[14], address->Addr[15])); -} - -static void -dev_path_iPv6(struct string *str, void *dev_path) -{ - struct ipv6_device_path *ip; - - ip = dev_path; - cprintf(str, "IPv6("); - cat_print_ipv6(str, &ip->remote_ip_address); - cprintf(str, ","); - cat_print_network_protocol(str, ip->Protocol); - cprintf(str, ",%s,", ip->IPAddress_origin ? - (ip->IPAddress_origin == 1 ? "stateless_auto_configure" : - "stateful_auto_configure") : "Static"); - cat_print_ipv6(str, &ip->local_ip_address); - if (ip->header.length == - sizeof (struct ipv6_device_path)) { - cprintf(str, ","); - cat_print_ipv6(str, &ip->gateway_ip_address); - cprintf(str, ","); - cprintf(str, "%d", ip->prefix_length); - } - cprintf(str, ")"); -} - -static void -dev_path_infini_band(struct string *str, void *dev_path) -{ - struct infiniband_device_path *infini_band; - - infini_band = dev_path; - cprintf(str, "Infiniband(0x%x,%pU,0x%llx,0x%llx,0x%llx)", - infini_band->resource_flags, &infini_band->port_gid, - infini_band->service_id, infini_band->target_port_id, - infini_band->device_id); -} - -static void -dev_path_uart(struct string *str, void *dev_path) -{ - struct uart_device_path *Uart; - s8 Parity; - - Uart = dev_path; - switch (Uart->Parity) { - case 0: - Parity = 'D'; - break; - case 1: - Parity = 'N'; - break; - case 2: - Parity = 'E'; - break; - case 3: - Parity = 'O'; - break; - case 4: - Parity = 'M'; - break; - case 5: - Parity = 'S'; - break; - default: - Parity = 'x'; - break; - } - - if (Uart->baud_rate == 0) - cprintf(str, "Uart(DEFAULT %c", Parity); - else - cprintf(str, "Uart(%lld %c", Uart->baud_rate, Parity); - - if (Uart->data_bits == 0) - cprintf(str, "D"); - else - cprintf(str, "%d", Uart->data_bits); - - switch (Uart->stop_bits) { - case 0: - cprintf(str, "D)"); - break; - case 1: - cprintf(str, "1)"); - break; - case 2: - cprintf(str, "1.5)"); - break; - case 3: - cprintf(str, "2)"); - break; - default: - cprintf(str, "x)"); - break; - } -} - -static void -dev_path_sata(struct string *str, void *dev_path) -{ - struct sata_device_path *sata; - - sata = dev_path; - cprintf(str, "Sata(0x%x,0x%x,0x%x)", sata->HBAPort_number, - sata->port_multiplier_port_number, sata->Lun); -} - -static void -dev_path_hard_drive(struct string *str, void *dev_path) -{ - struct harddrive_device_path *hd; - - hd = dev_path; - switch (hd->signature_type) { - case SIGNATURE_TYPE_MBR: - cprintf(str, "HD(Part%d,Sig%08x)", - hd->partition_number, *((u32 *) (&(hd->signature[0]))) - ); - break; - case SIGNATURE_TYPE_GUID: - cprintf(str, "HD(Part%d,Sig%pU)", - hd->partition_number, - (efi_guid_t *) & (hd->signature[0]) - ); - break; - default: - cprintf(str, "HD(Part%d,mbr_type=%02x,sig_type=%02x)", - hd->partition_number, hd->mbr_type, hd->signature_type); - break; - } -} - -static void -dev_path_cdrom(struct string *str, void *dev_path) -{ - struct cdrom_device_path *cd; - - cd = dev_path; - cprintf(str, "CDROM(0x%x)", cd->boot_entry); -} - -static void -dev_path_file_path(struct string *str, void *dev_path) -{ - struct filepath_device_path *Fp; - char *dst; - - Fp = dev_path; - - dst = strdup_wchar_to_char(Fp->path_name); - - cprintf(str, "%s", dst); - - free(dst); -} - -static void -dev_path_media_protocol(struct string *str, void *dev_path) -{ - struct media_protocol_device_path *media_prot; - - media_prot = dev_path; - cprintf(str, "%pU", &media_prot->Protocol); -} - -static void -dev_path_bss_bss(struct string *str, void *dev_path) -{ - struct bbs_bbs_device_path *Bss; - char *type; - - Bss = dev_path; - switch (Bss->device_type) { - case BBS_TYPE_FLOPPY: - type = "Floppy"; - break; - case BBS_TYPE_HARDDRIVE: - type = "Harddrive"; - break; - case BBS_TYPE_CDROM: - type = "CDROM"; - break; - case BBS_TYPE_PCMCIA: - type = "PCMCIA"; - break; - case BBS_TYPE_USB: - type = "Usb"; - break; - case BBS_TYPE_EMBEDDED_NETWORK: - type = "Net"; - break; - default: - type = "?"; - break; - } - - cprintf(str, "Bss-%s(%s)", type, Bss->String); -} - -static void -dev_path_end_instance(struct string *str, void *dev_path) -{ - cprintf(str, ","); -} - -/** - * Print unknown device node. - * UEFI 2.4 ยง 9.6.1.6 table 89. - */ - -static void -dev_path_node_unknown(struct string *str, void *dev_path) -{ - struct efi_device_path *Path; - u8 *value; - int length, index; - Path = dev_path; - value = dev_path; - value += 4; - switch (Path->type) { - case HARDWARE_DEVICE_PATH:{ - /* Unknown Hardware Device Path */ - cprintf(str, "hardware_path(%d", Path->sub_type); - break; - } - case ACPI_DEVICE_PATH:{/* Unknown ACPI Device Path */ - cprintf(str, "acpi_path(%d", Path->sub_type); - break; - } - case MESSAGING_DEVICE_PATH:{ - /* Unknown Messaging Device Path */ - cprintf(str, "Msg(%d", Path->sub_type); - break; - } - case MEDIA_DEVICE_PATH:{ - /* Unknown Media Device Path */ - cprintf(str, "media_path(%d", Path->sub_type); - break; - } - case BBS_DEVICE_PATH:{ /* Unknown BIOS Boot Specification Device Path */ - cprintf(str, "bbs_path(%d", Path->sub_type); - break; - } - default:{ /* Unknown Device Path */ - cprintf(str, "Path(%d,%d", Path->type, Path->sub_type); - break; - } - } - length = Path->length; - for (index = 0; index < length; index++) { - if (index == 0) - cprintf(str, ",0x"); - cprintf(str, "%02x", *value); - value++; - } - cprintf(str, ")"); -} - -/* - * Table to convert "type" and "sub_type" to a "convert to text" function/ - * Entries hold "type" and "sub_type" for know values. - * Special "sub_type" 0 is used as default for known type with unknown subtype. - */ -struct { - u8 type; - u8 sub_type; - void (*Function) (struct string *, void *); -} dev_path_table[] = { - { - HARDWARE_DEVICE_PATH, HW_PCI_DP, dev_path_pci}, { - HARDWARE_DEVICE_PATH, HW_PCCARD_DP, dev_path_pccard}, { - HARDWARE_DEVICE_PATH, HW_MEMMAP_DP, dev_path_mem_map}, { - HARDWARE_DEVICE_PATH, HW_VENDOR_DP, dev_path_vendor}, { - HARDWARE_DEVICE_PATH, HW_CONTROLLER_DP, dev_path_controller}, { - ACPI_DEVICE_PATH, ACPI_DP, dev_path_acpi}, { - MESSAGING_DEVICE_PATH, MSG_ATAPI_DP, dev_path_atapi}, { - MESSAGING_DEVICE_PATH, MSG_SCSI_DP, dev_path_scsi}, { - MESSAGING_DEVICE_PATH, MSG_FIBRECHANNEL_DP, dev_path_fibre}, { - MESSAGING_DEVICE_PATH, MSG_1394_DP, dev_path1394}, { - MESSAGING_DEVICE_PATH, MSG_USB_DP, dev_path_usb}, { - MESSAGING_DEVICE_PATH, MSG_I2_o_DP, dev_path_i2_o}, { - MESSAGING_DEVICE_PATH, MSG_MAC_ADDR_DP, dev_path_mac_addr}, { - MESSAGING_DEVICE_PATH, MSG_IPv4_DP, dev_path_iPv4}, { - MESSAGING_DEVICE_PATH, MSG_IPv6_DP, dev_path_iPv6}, { - MESSAGING_DEVICE_PATH, MSG_INFINIBAND_DP, dev_path_infini_band}, { - MESSAGING_DEVICE_PATH, MSG_UART_DP, dev_path_uart}, { - MESSAGING_DEVICE_PATH, MSG_SATA_DP, dev_path_sata}, { - MESSAGING_DEVICE_PATH, MSG_VENDOR_DP, dev_path_vendor}, { - MEDIA_DEVICE_PATH, MEDIA_HARDDRIVE_DP, dev_path_hard_drive}, { - MEDIA_DEVICE_PATH, MEDIA_CDROM_DP, dev_path_cdrom}, { - MEDIA_DEVICE_PATH, MEDIA_VENDOR_DP, dev_path_vendor}, { - MEDIA_DEVICE_PATH, MEDIA_FILEPATH_DP, dev_path_file_path}, { - MEDIA_DEVICE_PATH, MEDIA_PROTOCOL_DP, dev_path_media_protocol}, { - BBS_DEVICE_PATH, BBS_BBS_DP, dev_path_bss_bss}, { - END_DEVICE_PATH_TYPE, END_INSTANCE_DEVICE_PATH_SUBTYPE, - dev_path_end_instance}, { - 0, 0, NULL} -}; - -static int __device_path_to_str(struct string *str, struct efi_device_path *dev_path) -{ - struct efi_device_path *dev_path_node; - void (*dump_node) (struct string *, void *); - int i; - - dev_path = unpack_device_path(dev_path); - - dev_path_node = dev_path; - while (!is_device_path_end(dev_path_node)) { - dump_node = NULL; - for (i = 0; dev_path_table[i].Function; i += 1) { - - if (device_path_type(dev_path_node) == - dev_path_table[i].type - && dev_path_node->sub_type == - dev_path_table[i].sub_type) { - dump_node = dev_path_table[i].Function; - break; - } - } - - if (!dump_node) - dump_node = dev_path_node_unknown; - - if (str->len && dump_node != dev_path_end_instance) - cprintf(str, "/"); - - dump_node(str, dev_path_node); - - dev_path_node = next_device_path_node(dev_path_node); - } - - return 0; -} - -char *device_path_to_str(struct efi_device_path *dev_path) -{ - struct string str = {}; - - __device_path_to_str(&str, dev_path); - - str.str = malloc(str.len + 1); - if (!str.str) - return NULL; - - str.len = 0; - - __device_path_to_str(&str, dev_path); - - return str.str; -} - -u8 device_path_to_type(struct efi_device_path *dev_path) -{ - struct efi_device_path *dev_path_next; - - dev_path = unpack_device_path(dev_path); - dev_path_next = next_device_path_node(dev_path); - - while (!is_device_path_end(dev_path_next)) { - dev_path = dev_path_next; - dev_path_next = next_device_path_node(dev_path); - } - - return device_path_type(dev_path); -} - -u8 device_path_to_subtype(struct efi_device_path *dev_path) -{ - struct efi_device_path *dev_path_next; - - dev_path = unpack_device_path(dev_path); - dev_path_next = next_device_path_node(dev_path); - - while (!is_device_path_end(dev_path_next)) { - dev_path = dev_path_next; - dev_path_next = next_device_path_node(dev_path); - } - - return dev_path->sub_type; -} - -char *device_path_to_partuuid(struct efi_device_path *dev_path) -{ - struct efi_device_path *dev_path_node; - struct harddrive_device_path *hd; - char *str = NULL;; - - dev_path = unpack_device_path(dev_path); - - for (dev_path_node = dev_path; !is_device_path_end(dev_path_node); - dev_path_node = next_device_path_node(dev_path_node)) { - - if (device_path_type(dev_path_node) != MEDIA_DEVICE_PATH) - continue; - - if (dev_path_node->sub_type != MEDIA_HARDDRIVE_DP) - continue; - - hd = (struct harddrive_device_path *)dev_path_node; - - if (hd->signature_type != SIGNATURE_TYPE_GUID) - continue; - - str = xasprintf("%pUl", (efi_guid_t *)&(hd->signature[0])); - break; - } - - return str; -} - diff --git a/common/efi/efivar-filename.c b/common/efi/efivar-filename.c deleted file mode 100644 index 51d0130fa7..0000000000 --- a/common/efi/efivar-filename.c +++ /dev/null @@ -1,116 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ - -#include <linux/ctype.h> -#include <string.h> -#include <efi/efi-util.h> - -static int char_to_nibble(char c) -{ - int ret = tolower(c); - - return ret <= '9' ? ret - '0' : ret - 'a' + 10; -} - -static int read_byte_str(const char *str, u8 *out) -{ - if (!isxdigit(*str) || !isxdigit(*(str + 1))) - return -EINVAL; - - *out = (char_to_nibble(*str) << 4) | char_to_nibble(*(str + 1)); - - return 0; -} - -static int efi_guid_parse(const char *str, efi_guid_t *guid) -{ - int i, ret; - u8 idx[] = { 3, 2, 1, 0, 5, 4, 7, 6, 8, 9, 10, 11, 12, 13, 14, 15 }; - - for (i = 0; i < 16; i++) { - ret = read_byte_str(str, &guid->b[idx[i]]); - if (ret) - return ret; - str += 2; - - switch (i) { - case 3: - case 5: - case 7: - case 9: - if (*str != '-') - return -EINVAL; - str++; - break; - } - } - - return 0; -} - - -int __efivarfs_parse_filename(const char *filename, efi_guid_t *vendor, - s16 *name, size_t *namelen) -{ - int len, ret; - const char *guidstr; - int i; - - len = strlen(filename); - - if (len < sizeof("-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")) - return -EINVAL; - - guidstr = filename + len - sizeof("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"); - if (*guidstr != '-' || guidstr == filename) - return -EINVAL; - - guidstr++; - - ret = efi_guid_parse(guidstr, vendor); - if (ret) - return ret; - - if (guidstr - filename > *namelen) - ret = -EFBIG; - - *namelen = guidstr - filename; - - if (ret) - return ret; - - for (i = 0; i < *namelen - 1; i++) - name[i] = filename[i]; - - name[i] = L'\0'; - - return 0; -} - -int efivarfs_parse_filename(const char *filename, efi_guid_t *vendor, - s16 **name) -{ - int ret; - s16 *varname; - size_t namelen = 0; - int i; - - if (*filename == '/') - filename++; - - ret = __efivarfs_parse_filename(filename, vendor, NULL, &namelen); - if (ret != -EFBIG) - return ret; - - varname = xzalloc(namelen * sizeof(s16)); - - for (i = 0; i < namelen - 1; i++) - varname[i] = filename[i]; - - varname[i] = L'\0'; - - *name = varname; - - return 0; -} - - diff --git a/common/efi/errno.c b/common/efi/errno.c deleted file mode 100644 index 3bb68e7781..0000000000 --- a/common/efi/errno.c +++ /dev/null @@ -1,90 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only - -#include <efi/efi-util.h> -#include <errno.h> - -const char *efi_strerror(efi_status_t err) -{ - const char *str; - - switch (err) { - case EFI_SUCCESS: str = "Success"; break; - case EFI_LOAD_ERROR: str = "Load Error"; break; - case EFI_INVALID_PARAMETER: str = "Invalid Parameter"; break; - case EFI_UNSUPPORTED: str = "Unsupported"; break; - case EFI_BAD_BUFFER_SIZE: str = "Bad Buffer Size"; break; - case EFI_BUFFER_TOO_SMALL: str = "Buffer Too Small"; break; - case EFI_NOT_READY: str = "Not Ready"; break; - case EFI_DEVICE_ERROR: str = "Device Error"; break; - case EFI_WRITE_PROTECTED: str = "Write Protected"; break; - case EFI_OUT_OF_RESOURCES: str = "Out of Resources"; break; - case EFI_VOLUME_CORRUPTED: str = "Volume Corrupt"; break; - case EFI_VOLUME_FULL: str = "Volume Full"; break; - case EFI_NO_MEDIA: str = "No Media"; break; - case EFI_MEDIA_CHANGED: str = "Media changed"; break; - case EFI_NOT_FOUND: str = "Not Found"; break; - case EFI_ACCESS_DENIED: str = "Access Denied"; break; - case EFI_NO_RESPONSE: str = "No Response"; break; - case EFI_NO_MAPPING: str = "No mapping"; break; - case EFI_TIMEOUT: str = "Time out"; break; - case EFI_NOT_STARTED: str = "Not started"; break; - case EFI_ALREADY_STARTED: str = "Already started"; break; - case EFI_ABORTED: str = "Aborted"; break; - case EFI_ICMP_ERROR: str = "ICMP Error"; break; - case EFI_TFTP_ERROR: str = "TFTP Error"; break; - case EFI_PROTOCOL_ERROR: str = "Protocol Error"; break; - case EFI_INCOMPATIBLE_VERSION: str = "Incompatible Version"; break; - case EFI_SECURITY_VIOLATION: str = "Security Violation"; break; - case EFI_CRC_ERROR: str = "CRC Error"; break; - case EFI_END_OF_MEDIA: str = "End of Media"; break; - case EFI_END_OF_FILE: str = "End of File"; break; - case EFI_INVALID_LANGUAGE: str = "Invalid Language"; break; - case EFI_COMPROMISED_DATA: str = "Compromised Data"; break; - default: str = "unknown error"; - } - - return str; -} - -int efi_errno(efi_status_t err) -{ - int ret; - - switch (err) { - case EFI_SUCCESS: ret = 0; break; - case EFI_LOAD_ERROR: ret = EIO; break; - case EFI_INVALID_PARAMETER: ret = EINVAL; break; - case EFI_UNSUPPORTED: ret = ENOTSUPP; break; - case EFI_BAD_BUFFER_SIZE: ret = EINVAL; break; - case EFI_BUFFER_TOO_SMALL: ret = EINVAL; break; - case EFI_NOT_READY: ret = EAGAIN; break; - case EFI_DEVICE_ERROR: ret = EIO; break; - case EFI_WRITE_PROTECTED: ret = EROFS; break; - case EFI_OUT_OF_RESOURCES: ret = ENOMEM; break; - case EFI_VOLUME_CORRUPTED: ret = EIO; break; - case EFI_VOLUME_FULL: ret = ENOSPC; break; - case EFI_NO_MEDIA: ret = ENOMEDIUM; break; - case EFI_MEDIA_CHANGED: ret = ENOMEDIUM; break; - case EFI_NOT_FOUND: ret = ENODEV; break; - case EFI_ACCESS_DENIED: ret = EACCES; break; - case EFI_NO_RESPONSE: ret = ETIMEDOUT; break; - case EFI_NO_MAPPING: ret = EINVAL; break; - case EFI_TIMEOUT: ret = ETIMEDOUT; break; - case EFI_NOT_STARTED: ret = EINVAL; break; - case EFI_ALREADY_STARTED: ret = EINVAL; break; - case EFI_ABORTED: ret = EINTR; break; - case EFI_ICMP_ERROR: ret = EINVAL; break; - case EFI_TFTP_ERROR: ret = EINVAL; break; - case EFI_PROTOCOL_ERROR: ret = EPROTO; break; - case EFI_INCOMPATIBLE_VERSION: ret = EINVAL; break; - case EFI_SECURITY_VIOLATION: ret = EINVAL; break; - case EFI_CRC_ERROR: ret = EINVAL; break; - case EFI_END_OF_MEDIA: ret = EINVAL; break; - case EFI_END_OF_FILE: ret = EINVAL; break; - case EFI_INVALID_LANGUAGE: ret = EINVAL; break; - case EFI_COMPROMISED_DATA: ret = EINVAL; break; - default: ret = EINVAL; - } - - return ret; -} diff --git a/common/efi/guid.c b/common/efi/guid.c deleted file mode 100644 index ca16f4520f..0000000000 --- a/common/efi/guid.c +++ /dev/null @@ -1,97 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only - -#include <common.h> -#include <efi.h> - -efi_guid_t efi_file_info_id = EFI_FILE_INFO_GUID; -efi_guid_t efi_simple_file_system_protocol_guid = EFI_SIMPLE_FILE_SYSTEM_GUID; -efi_guid_t efi_device_path_protocol_guid = EFI_DEVICE_PATH_PROTOCOL_GUID; -efi_guid_t efi_loaded_image_protocol_guid = EFI_LOADED_IMAGE_PROTOCOL_GUID; -efi_guid_t efi_unknown_device_guid = EFI_UNKNOWN_DEVICE_GUID; -efi_guid_t efi_null_guid = EFI_NULL_GUID; -efi_guid_t efi_global_variable_guid = EFI_GLOBAL_VARIABLE_GUID; -efi_guid_t efi_block_io_protocol_guid = EFI_BLOCK_IO_PROTOCOL_GUID; -efi_guid_t efi_rng_protocol_guid = EFI_RNG_PROTOCOL_GUID; -efi_guid_t efi_barebox_vendor_guid = EFI_BAREBOX_VENDOR_GUID; -efi_guid_t efi_systemd_vendor_guid = EFI_SYSTEMD_VENDOR_GUID; -efi_guid_t efi_fdt_guid = EFI_DEVICE_TREE_GUID; - -#define EFI_GUID_STRING(guid, short, long) do { \ - if (!efi_guidcmp(guid, *g)) \ - return long; \ - } while(0) - -const char *efi_guid_string(efi_guid_t *g) -{ - EFI_GUID_STRING(EFI_NULL_GUID, "NULL", "NULL GUID"); - EFI_GUID_STRING(EFI_MPS_TABLE_GUID, "MPS Table", "MPS Table GUID in EFI System Table"); - EFI_GUID_STRING(EFI_ACPI_TABLE_GUID, "ACPI Table", "ACPI 1.0 Table GUID in EFI System Table"); - EFI_GUID_STRING(EFI_ACPI_20_TABLE_GUID, "ACPI 2.0 Table", "ACPI 2.0 Table GUID in EFI System Table"); - EFI_GUID_STRING(EFI_SMBIOS_TABLE_GUID, "SMBIOS Table", "SMBIOS Table GUID in EFI System Table"); - EFI_GUID_STRING(EFI_SAL_SYSTEM_TABLE_GUID, "SAL System Table", "SAL System Table GUID in EFI System Table"); - EFI_GUID_STRING(EFI_HCDP_TABLE_GUID, "HDCP Table", "HDCP Table GUID in EFI System Table"); - EFI_GUID_STRING(EFI_UGA_IO_PROTOCOL_GUID, "UGA Protocol", "EFI 1.1 UGA Protocol"); - EFI_GUID_STRING(EFI_GLOBAL_VARIABLE_GUID, "Efi", "Efi Variable GUID"); - EFI_GUID_STRING(EFI_UV_SYSTEM_TABLE_GUID, "UV System Table", "UV System Table GUID in EFI System Table"); - EFI_GUID_STRING(EFI_LINUX_EFI_CRASH_GUID, "Linux EFI Crash", "Linux EFI Crash GUID"); - EFI_GUID_STRING(EFI_LOADED_IMAGE_PROTOCOL_GUID, "LoadedImage Protocol", "EFI 1.0 Loaded Image Protocol"); - EFI_GUID_STRING(EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID, "EFI Graphics Output Protocol", "UEFI Graphics Output Protocol"); - EFI_GUID_STRING(EFI_UGA_PROTOCOL_GUID, "UGA Draw Protocol", "EFI 1.1 UGA Draw Protocol"); - EFI_GUID_STRING(EFI_UGA_IO_PROTOCOL_GUID, "UGA Protocol", "EFI 1.1 UGA Protocol"); - EFI_GUID_STRING(EFI_PCI_IO_PROTOCOL_GUID, "PCI IO Protocol", "EFI 1.1 PCI IO Protocol"); - EFI_GUID_STRING(EFI_USB_IO_PROTOCOL_GUID, "USB IO Protocol", "EFI 1.0 USB IO Protocol"); - EFI_GUID_STRING(EFI_FILE_INFO_GUID, "File Info", "EFI File Info"); - EFI_GUID_STRING(EFI_SIMPLE_FILE_SYSTEM_GUID, "Filesystem", "EFI 1.0 Simple FileSystem"); - EFI_GUID_STRING(EFI_DEVICE_TREE_GUID, "Device Tree", "EFI Device Tree GUID"); - EFI_GUID_STRING(EFI_DEVICE_PATH_PROTOCOL_GUID, "Device Path Protocol", "EFI 1.0 Device Path protocol"); - EFI_GUID_STRING(EFI_SIMPLE_NETWORK_PROTOCOL_GUID, "Simple Network Protocol", "EFI 1.0 Simple Network Protocol"); - EFI_GUID_STRING(EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID, "Filesystem Protocol", "EFI 1.0 Simple FileSystem Protocol"); - EFI_GUID_STRING(EFI_UNKNOWN_DEVICE_GUID, "Efi Unknown Device", "Efi Unknown Device GUID"); - EFI_GUID_STRING(EFI_BLOCK_IO_PROTOCOL_GUID, "BlockIo Protocol", "EFI 1.0 Block IO protocol"); - - EFI_GUID_STRING(EFI_FIRMWARE_VOLUME2_PROTOCOL_GUID, "FirmwareVolume2Protocol", "Efi FirmwareVolume2Protocol"); - EFI_GUID_STRING(EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL_GUID, "FirmwareVolumeBlock Protocol", "Firmware Volume Block protocol"); - EFI_GUID_STRING(EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_GUID, "PciRootBridgeIo Protocol", "EFI 1.1 Pci Root Bridge IO Protocol"); - EFI_GUID_STRING(EFI_ISA_ACPI_PROTOCOL_GUID, "ISA Acpi Protocol", "ISA Acpi Protocol"); - EFI_GUID_STRING(EFI_ISA_IO_PROTOCOL_GUID, "ISA IO Protocol", "ISA IO Protocol"); - EFI_GUID_STRING(EFI_STANDARD_ERROR_DEVICE_GUID, "Standard Error Device Guid", "EFI Standard Error Device Guid"); - EFI_GUID_STRING(EFI_CONSOLE_OUT_DEVICE_GUID, "Console Out Device Guid", "EFI Console Out Device Guid"); - EFI_GUID_STRING(EFI_CONSOLE_IN_DEVICE_GUID, "Console In Device Guid", "EFI Console In Device Guid"); - EFI_GUID_STRING(EFI_SIMPLE_TEXT_OUT_PROTOCOL_GUID, "Simple Text Out Protocol", "EFI 1.0 Simple Text Out Protocol"); - EFI_GUID_STRING(EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL_GUID, "Simple Text Input Ex Protocol", "UEFI 2.1 Simple Text Input Ex Protocol"); - EFI_GUID_STRING(EFI_SIMPLE_TEXT_IN_PROTOCOL_GUID, "Simple Text In Protocol", "EFI 1.0 Simple Text In Protocol"); - EFI_GUID_STRING(EFI_DISK_IO_PROTOCOL_GUID, "DiskIo Protocol", "EFI 1.0 Disk IO Protocol"); - EFI_GUID_STRING(EFI_IDE_CONTROLLER_INIT_PROTOCOL_GUID, "IDE Controller Init Protocol", "Platform IDE Init Protocol"); - EFI_GUID_STRING(EFI_DISK_INFO_PROTOCOL_GUID, "Disk Info Protocol", "Disk Info Protocol"); - EFI_GUID_STRING(EFI_SERIAL_IO_PROTOCOL_GUID, "SerialIo Protocol", "EFI 1.0 Serial IO Protocol"); - EFI_GUID_STRING(EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL_GUID, "Bus Specific Driver Override Protocol", "EFI 1.1 Bus Specific Driver Override Protocol"); - EFI_GUID_STRING(EFI_LOAD_FILE2_PROTOCOL_GUID, "LoadFile2 Protocol", "EFI Load File 2 Protocol"); - EFI_GUID_STRING(EFI_MTFTP4_SERVICE_BINDING_PROTOCOL_GUID, "MTFTP4 Service Binding Protocol", "MTFTP4 Service Binding Protocol"); - EFI_GUID_STRING(EFI_DHCP4_PROTOCOL_GUID, "DHCP4 Protocol", "DHCP4 Protocol"); - EFI_GUID_STRING(EFI_UDP4_SERVICE_BINDING_PROTOCOL_GUID, "UDP4 Service Binding Protocol", "UDP4 Service Binding Protocol"); - EFI_GUID_STRING(EFI_TCP4_SERVICE_BINDING_PROTOCOL_GUID, "TCP4 Service Binding Protocol", "TCP4 Service Binding Protocol"); - EFI_GUID_STRING(EFI_IP4_SERVICE_BINDING_PROTOCOL_GUID, "IP4 Service Binding Protocol", "IP4 Service Binding Protocol"); - EFI_GUID_STRING(EFI_IP4_CONFIG_PROTOCOL_GUID, "Ip4Config Protocol", "Ip4Config Protocol"); - EFI_GUID_STRING(EFI_ARP_SERVICE_BINDING_PROTOCOL_GUID, "ARP Service Binding Protocol", "ARP Service Binding Protocol"); - EFI_GUID_STRING(EFI_MANAGED_NETWORK_SERVICE_BINDING_PROTOCOL_GUID, "Managed Network Service Binding Protocol", "Managed Network Service Binding Protocol"); - EFI_GUID_STRING(EFI_VLAN_CONFIG_PROTOCOL_GUID, "VlanConfig Protocol", "VlanConfig Protocol"); - EFI_GUID_STRING(EFI_HII_CONFIG_ACCESS_PROTOCOL_GUID, "HII Config Access Protocol", "HII Config Access 2.1 protocol"); - EFI_GUID_STRING(EFI_LOAD_FILE_PROTOCOL_GUID, "LoadFile Protocol", "EFI 1.0 Load File Protocol"); - EFI_GUID_STRING(EFI_COMPONENT_NAME2_PROTOCOL_GUID, "Component Name2 Protocol", "UEFI 2.0 Component Name2 Protocol"); - EFI_GUID_STRING(EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL_GUID_31, "Network Interface Identifier Protocol_31", "EFI1.1 Network Interface Identifier Protocol"); - EFI_GUID_STRING(EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL_GUID, "Network Interface Identifier Protocol", "EFI Network Interface Identifier Protocol"); - EFI_GUID_STRING(EFI_TIMESTAMP_PROTOCOL_GUID, "Timestamp", "Timestamp"); - - /* TPM 1.2 */ - EFI_GUID_STRING( EFI_TCG_PROTOCOL_GUID, "TcgService", "TCGServices Protocol"); - /* TPM 2.0 */ - EFI_GUID_STRING( EFI_TCG2_PROTOCOL_GUID, "Tcg2Service", "TCG2Services Protocol"); - - /* File */ - EFI_GUID_STRING(EFI_IDEBUSDXE_INF_GUID, "IdeBusDxe.inf", "EFI IdeBusDxe.inf File GUID"); - EFI_GUID_STRING(EFI_TERMINALDXE_INF_GUID, "TerminalDxe.inf", "EFI TerminalDxe.inf File GUID"); - EFI_GUID_STRING(EFI_ISCSIDXE_INF_GUID, "IScsiDxe.inf", "EFI IScsiDxe.inf File GUID"); - EFI_GUID_STRING(EFI_VLANCONFIGDXE_INF_GUID, "VlanConfigDxe.inf", "EFI VlanConfigDxe.inf File GUID"); - - return "unknown"; -} diff --git a/common/efi/payload/Makefile b/common/efi/payload/Makefile deleted file mode 100644 index eeed046b00..0000000000 --- a/common/efi/payload/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only - -obj-y += init.o -obj-y += image.o -obj-$(CONFIG_OFTREE) += fdt.o -bbenv-y += env-efi -obj-$(CONFIG_CMD_IOMEM) += iomem.o diff --git a/common/efi/payload/env-efi/network/eth0-discover b/common/efi/payload/env-efi/network/eth0-discover deleted file mode 100644 index 62c31a553c..0000000000 --- a/common/efi/payload/env-efi/network/eth0-discover +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -for i in /boot/network-drivers/*; do - $i; -done diff --git a/common/efi/payload/fdt.c b/common/efi/payload/fdt.c deleted file mode 100644 index dbbc93fb7d..0000000000 --- a/common/efi/payload/fdt.c +++ /dev/null @@ -1,43 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 - -#define pr_fmt(fmt) "efi-fdt: " fmt - -#include <common.h> -#include <init.h> -#include <libfile.h> -#include <efi/efi-payload.h> -#include <efi/efi-device.h> - -static int efi_fdt_probe(void) -{ - efi_config_table_t *ect; - - for_each_efi_config_table(ect) { - struct fdt_header *oftree; - u32 magic, size; - int ret; - - if (efi_guidcmp(ect->guid, EFI_DEVICE_TREE_GUID)) - continue; - - oftree = (void *)ect->table; - magic = be32_to_cpu(oftree->magic); - - if (magic != FDT_MAGIC) { - pr_err("table has invalid magic 0x%08x\n", magic); - return -EILSEQ; - } - - size = be32_to_cpu(oftree->totalsize); - ret = write_file("/efi.dtb", oftree, size); - if (ret) { - pr_err("error saving /efi.dtb: %pe\n", ERR_PTR(ret)); - return ret; - } - - return 0; - } - - return 0; -} -late_initcall(efi_fdt_probe); diff --git a/common/efi/payload/image.c b/common/efi/payload/image.c deleted file mode 100644 index 8e39098ae8..0000000000 --- a/common/efi/payload/image.c +++ /dev/null @@ -1,287 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * image.c - barebox EFI payload support - * - * Copyright (c) 2014 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix - */ - -#include <clock.h> -#include <common.h> -#include <linux/sizes.h> -#include <memory.h> -#include <command.h> -#include <magicvar.h> -#include <init.h> -#include <driver.h> -#include <io.h> -#include <efi.h> -#include <malloc.h> -#include <string.h> -#include <linux/err.h> -#include <boot.h> -#include <bootm.h> -#include <fs.h> -#include <libfile.h> -#include <binfmt.h> -#include <wchar.h> -#include <efi/efi-payload.h> -#include <efi/efi-device.h> - -struct linux_kernel_header { - /* first sector of the image */ - uint8_t code1[0x0020]; - uint16_t cl_magic; /**< Magic number 0xA33F */ - uint16_t cl_offset; /**< The offset of command line */ - uint8_t code2[0x01F1 - 0x0020 - 2 - 2]; - uint8_t setup_sects; /**< The size of the setup in sectors */ - uint16_t root_flags; /**< If the root is mounted readonly */ - uint16_t syssize; /**< obsolete */ - uint16_t swap_dev; /**< obsolete */ - uint16_t ram_size; /**< obsolete */ - uint16_t vid_mode; /**< Video mode control */ - uint16_t root_dev; /**< Default root device number */ - uint16_t boot_flag; /**< 0xAA55 magic number */ - - /* second sector of the image */ - uint16_t jump; /**< Jump instruction (this is code!) */ - uint32_t header; /**< Magic signature "HdrS" */ - uint16_t version; /**< Boot protocol version supported */ - uint32_t realmode_swtch; /**< Boot loader hook */ - uint16_t start_sys; /**< The load-low segment (obsolete) */ - uint16_t kernel_version; /**< Points to kernel version string */ - uint8_t type_of_loader; /**< Boot loader identifier */ - uint8_t loadflags; /**< Boot protocol option flags */ - uint16_t setup_move_size; /**< Move to high memory size */ - uint32_t code32_start; /**< Boot loader hook */ - uint32_t ramdisk_image; /**< initrd load address */ - uint32_t ramdisk_size; /**< initrd size */ - uint32_t bootsect_kludge; /**< obsolete */ - uint16_t heap_end_ptr; /**< Free memory after setup end */ - uint8_t ext_loader_ver; /**< boot loader's extension of the version number */ - uint8_t ext_loader_type; /**< boot loader's extension of its type */ - uint32_t cmd_line_ptr; /**< Points to the kernel command line */ - uint32_t initrd_addr_max; /**< Highest address for initrd */ - uint32_t kernel_alignment; /**< Alignment unit required by the kernel */ - uint8_t relocatable_kernel; /** */ - uint8_t min_alignment; /** */ - uint16_t xloadflags; /** */ - uint32_t cmdline_size; /** */ - uint32_t hardware_subarch; /** */ - uint64_t hardware_subarch_data; /** */ - uint32_t payload_offset; /** */ - uint32_t payload_length; /** */ - uint64_t setup_data; /** */ - uint64_t pref_address; /** */ - uint32_t init_size; /** */ - uint32_t handover_offset; /** */ -} __attribute__ ((packed)); - -static int efi_load_image(const char *file, efi_loaded_image_t **loaded_image, - efi_handle_t *h) -{ - void *exe; - size_t size; - efi_handle_t handle; - efi_status_t efiret = EFI_SUCCESS; - - exe = read_file(file, &size); - if (!exe) - return -EINVAL; - - efiret = BS->load_image(false, efi_parent_image, efi_device_path, exe, size, - &handle); - if (EFI_ERROR(efiret)) { - pr_err("failed to LoadImage: %s\n", efi_strerror(efiret)); - goto out; - }; - - efiret = BS->open_protocol(handle, &efi_loaded_image_protocol_guid, - (void **)loaded_image, - efi_parent_image, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL); - if (EFI_ERROR(efiret)) { - pr_err("failed to OpenProtocol: %s\n", efi_strerror(efiret)); - BS->unload_image(handle); - goto out; - } - - *h = handle; -out: - free(exe); - return -efi_errno(efiret); -} - -static int efi_execute_image(const char *file) -{ - efi_handle_t handle; - efi_loaded_image_t *loaded_image; - efi_status_t efiret; - struct linux_kernel_header *image_header; - const char *options; - bool is_driver; - int ret; - - ret = efi_load_image(file, &loaded_image, &handle); - if (ret) - return ret; - - is_driver = (loaded_image->image_code_type == EFI_BOOT_SERVICES_CODE) || - (loaded_image->image_code_type == EFI_RUNTIME_SERVICES_CODE); - - image_header = (struct linux_kernel_header *)loaded_image->image_base; - if (image_header->boot_flag == 0xAA55 && - image_header->header == 0x53726448) { - pr_debug("Linux kernel detected. Adding bootargs."); - options = linux_bootargs_get(); - pr_err("add linux options '%s'\n", options); - if (options) { - loaded_image->load_options = xstrdup_char_to_wchar(options); - loaded_image->load_options_size = - (strlen(options) + 1) * sizeof(wchar_t); - } - shutdown_barebox(); - } - - efi_pause_devices(); - - efiret = BS->start_image(handle, NULL, NULL); - if (EFI_ERROR(efiret)) - pr_err("failed to StartImage: %s\n", efi_strerror(efiret)); - - efi_continue_devices(); - - if (!is_driver) - BS->unload_image(handle); - - efi_connect_all(); - efi_register_devices(); - - return -efi_errno(efiret); -} - -#ifdef __x86_64__ -typedef void(*handover_fn)(void *image, efi_system_table_t *table, - struct linux_kernel_header *header); - -static inline void linux_efi_handover(efi_handle_t handle, - struct linux_kernel_header *header) -{ - handover_fn handover; - - handover = (handover_fn)((long)header->code32_start + 512 + - header->handover_offset); - handover(handle, efi_sys_table, header); -} -#else -typedef void(*handover_fn)(VOID *image, EFI_SYSTEM_TABLE *table, - struct SetupHeader *setup) __attribute__((regparm(0))); - -static inline void linux_efi_handover(efi_handle_t handle, - struct linux_kernel_header *header) -{ - handover_fn handover; - - handover = (handover_fn)((long)header->code32_start + - header->handover_offset); - handover(handle, efi_sys_table, header); -} -#endif - -static int do_bootm_efi(struct image_data *data) -{ - void *tmp; - void *initrd = NULL; - size_t size; - efi_handle_t handle; - int ret; - const char *options; - efi_loaded_image_t *loaded_image; - struct linux_kernel_header *image_header, *boot_header; - - ret = efi_load_image(data->os_file, &loaded_image, &handle); - if (ret) - return ret; - - image_header = (struct linux_kernel_header *)loaded_image->image_base; - - if (image_header->boot_flag != 0xAA55 || - image_header->header != 0x53726448 || - image_header->version < 0x20b || - !image_header->relocatable_kernel) { - pr_err("Not a valid kernel image!\n"); - BS->unload_image(handle); - return -EINVAL; - } - - boot_header = xmalloc(0x4000); - memset(boot_header, 0, 0x4000); - memcpy(boot_header, image_header, sizeof(*image_header)); - - boot_header->type_of_loader = 0xff; - - if (data->initrd_file) { - tmp = read_file(data->initrd_file, &size); - initrd = xmemalign(PAGE_SIZE, PAGE_ALIGN(size)); - memcpy(initrd, tmp, size); - memset(initrd + size, 0, PAGE_ALIGN(size) - size); - free(tmp); - boot_header->ramdisk_image = (uint64_t)initrd; - boot_header->ramdisk_size = PAGE_ALIGN(size); - } - - options = linux_bootargs_get(); - if (options) { - boot_header->cmd_line_ptr = (uint64_t)options; - boot_header->cmdline_size = strlen(options); - } - - boot_header->code32_start = (uint64_t)loaded_image->image_base + - (image_header->setup_sects+1) * 512; - - if (bootm_verbose(data)) { - printf("\nStarting kernel at 0x%p", loaded_image->image_base); - if (data->initrd_file) - printf(", initrd at 0x%08x", - boot_header->ramdisk_image); - printf("...\n"); - } - - if (data->dryrun) { - BS->unload_image(handle); - free(boot_header); - free(initrd); - return 0; - } - - efi_set_variable_usec("LoaderTimeExecUSec", &efi_systemd_vendor_guid, - get_time_ns()/1000); - - shutdown_barebox(); - linux_efi_handover(handle, boot_header); - - return 0; -} - -static struct image_handler efi_handle_tr = { - .name = "EFI Application", - .bootm = do_bootm_efi, - .filetype = filetype_exe, -}; - -static int efi_execute(struct binfmt_hook *b, char *file, int argc, char **argv) -{ - return efi_execute_image(file); -} - -static struct binfmt_hook binfmt_efi_hook = { - .type = filetype_exe, - .hook = efi_execute, -}; - -static int efi_register_image_handler(void) -{ - register_image_handler(&efi_handle_tr); - binfmt_register(&binfmt_efi_hook); - - return 0; -} -late_initcall(efi_register_image_handler); diff --git a/common/efi/payload/init.c b/common/efi/payload/init.c deleted file mode 100644 index 3ee5d66d60..0000000000 --- a/common/efi/payload/init.c +++ /dev/null @@ -1,387 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * init.c - barebox EFI payload support - * - * Copyright (c) 2014 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix - */ - -#ifdef CONFIG_DEBUG_LL -#define DEBUG -#endif - -#include <linux/linkage.h> -#include <common.h> -#include <linux/sizes.h> -#include <memory.h> -#include <clock.h> -#include <command.h> -#include <magicvar.h> -#include <init.h> -#include <restart.h> -#include <poweroff.h> -#include <driver.h> -#include <platform_data/serial-ns16550.h> -#include <io.h> -#include <efi.h> -#include <malloc.h> -#include <string.h> -#include <linux/err.h> -#include <boot.h> -#include <fs.h> -#include <binfmt.h> -#include <wchar.h> -#include <envfs.h> -#include <efi/efi-payload.h> -#include <efi/efi-device.h> -#include <libfile.h> -#include <state.h> -#include <bbu.h> - -efi_runtime_services_t *RT; -efi_boot_services_t *BS; -efi_system_table_t *efi_sys_table; -efi_handle_t efi_parent_image; -struct efi_device_path *efi_device_path; -efi_loaded_image_t *efi_loaded_image; - -void *efi_get_variable(char *name, efi_guid_t *vendor, int *var_size) -{ - efi_status_t efiret; - void *buf; - unsigned long size = 0; - s16 *name16 = xstrdup_char_to_wchar(name); - - efiret = RT->get_variable(name16, vendor, NULL, &size, NULL); - - if (EFI_ERROR(efiret) && efiret != EFI_BUFFER_TOO_SMALL) { - buf = ERR_PTR(-efi_errno(efiret)); - goto out; - } - - buf = malloc(size); - if (!buf) { - buf = ERR_PTR(-ENOMEM); - goto out; - } - - efiret = RT->get_variable(name16, vendor, NULL, &size, buf); - if (EFI_ERROR(efiret)) { - free(buf); - buf = ERR_PTR(-efi_errno(efiret)); - goto out; - } - - if (var_size) - *var_size = size; - -out: - free(name16); - - return buf; -} - -int efi_set_variable(char *name, efi_guid_t *vendor, uint32_t attributes, - void *buf, unsigned long size) -{ - efi_status_t efiret = EFI_SUCCESS; - s16 *name16 = xstrdup_char_to_wchar(name); - - efiret = RT->set_variable(name16, vendor, attributes, size, buf); - - free(name16); - - return -efi_errno(efiret); -} - -int efi_set_variable_usec(char *name, efi_guid_t *vendor, uint64_t usec) -{ - char buf[20]; - wchar_t buf16[40]; - - snprintf(buf, sizeof(buf), "%lld", usec); - strcpy_char_to_wchar(buf16, buf); - - return efi_set_variable(name, vendor, - EFI_VARIABLE_BOOTSERVICE_ACCESS | - EFI_VARIABLE_RUNTIME_ACCESS, buf16, - (strlen(buf)+1) * sizeof(wchar_t)); -} - -struct efi_boot { - u32 attributes; - u16 file_path_len; - char *description; - struct efi_device_path *path; - void *binary; -}; - -static struct efi_boot *efi_get_boot(int num) -{ - struct efi_boot *boot = xzalloc(sizeof(*boot)); - void *buf, *ptr; - int size; - char *name; - - name = xasprintf("Boot%04X", num); - - buf = efi_get_global_var(name, &size); - - free(name); - - if (IS_ERR(buf)) { - free(boot); - return NULL; - } - - ptr = buf; - - boot->attributes = *(u32 *)ptr; - - ptr += sizeof(u32); - - boot->file_path_len = *(u16 *)ptr; - - ptr += sizeof(u16); - - boot->description = xstrdup_wchar_to_char(ptr); - - ptr += (strlen(boot->description) + 1) * 2; - - printf("description: %s\n", boot->description); - - boot->path = memdup(ptr, boot->file_path_len); - - printf("path: %s\n", device_path_to_str(boot->path)); - - return boot; -} - -static int misc_init(void) -{ - efi_get_boot(1); - efi_get_boot(2); - efi_get_boot(3); - - return 0; -} -late_initcall(misc_init); - -static struct NS16550_plat ns16550_plat = { - .clock = 115200 * 16, -}; - -static int efi_console_init(void) -{ - barebox_set_model("barebox EFI payload"); - - add_generic_device("efi-stdio", DEVICE_ID_SINGLE, NULL, 0 , 0, 0, NULL); - - add_ns16550_device(0, 0x3f8, 0x10, IORESOURCE_IO | IORESOURCE_MEM_8BIT, - &ns16550_plat); - - return 0; -} -console_initcall(efi_console_init); - -static void __noreturn efi_restart_system(struct restart_handler *rst) -{ - RT->reset_system(EFI_RESET_WARM, EFI_SUCCESS, 0, NULL); - - hang(); -} - -static void __noreturn efi_poweroff_system(struct poweroff_handler *handler) -{ - shutdown_barebox(); - RT->reset_system(EFI_RESET_SHUTDOWN, EFI_SUCCESS, 0, NULL); - - hang(); -} - -static int restart_register_feature(void) -{ - restart_handler_register_fn("efi", efi_restart_system); - poweroff_handler_register_fn(efi_poweroff_system); - - return 0; -} -coredevice_initcall(restart_register_feature); - -extern char image_base[]; -extern initcall_t __barebox_initcalls_start[], __barebox_early_initcalls_end[], - __barebox_initcalls_end[]; - -static int efi_init(void) -{ - char *env; - - defaultenv_append_directory(env_efi); - - env = xasprintf("/efivars/barebox-env-%pUl", &efi_barebox_vendor_guid); - default_environment_path_set(env); - - return 0; -} -device_initcall(efi_init); - -/** - * efi-main - Entry point for EFI images - */ -void efi_main(efi_handle_t image, efi_system_table_t *sys_table) -{ - efi_physical_addr_t mem; - size_t memsize; - efi_status_t efiret; - -#ifdef DEBUG - sys_table->con_out->output_string(sys_table->con_out, L"barebox\n"); -#endif - - BS = sys_table->boottime; - - efi_parent_image = image; - efi_sys_table = sys_table; - RT = sys_table->runtime; - - efiret = BS->open_protocol(efi_parent_image, &efi_loaded_image_protocol_guid, - (void **)&efi_loaded_image, - efi_parent_image, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL); - if (!EFI_ERROR(efiret)) - BS->handle_protocol(efi_loaded_image->device_handle, - &efi_device_path_protocol_guid, (void **)&efi_device_path); - - mem = 0x3fffffff; - for (memsize = SZ_256M; memsize >= SZ_8M; memsize /= 2) { - efiret = BS->allocate_pages(EFI_ALLOCATE_MAX_ADDRESS, - EFI_LOADER_DATA, - memsize/PAGE_SIZE, &mem); - if (!EFI_ERROR(efiret)) - break; - if (efiret != EFI_OUT_OF_RESOURCES) - panic("failed to allocate malloc pool: %s\n", - efi_strerror(efiret)); - } - if (EFI_ERROR(efiret)) - panic("failed to allocate malloc pool: %s\n", - efi_strerror(efiret)); - mem_malloc_init((void *)mem, (void *)mem + memsize - 1); - - start_barebox(); -} - -static int efi_core_init(void) -{ - struct device *dev; - int ret; - - dev = device_alloc("efi-cs", DEVICE_ID_SINGLE); - ret = platform_device_register(dev); - if (ret) - return ret; - - dev = device_alloc("efi-wdt", DEVICE_ID_SINGLE); - return platform_device_register(dev); -} -core_initcall(efi_core_init); - -static int efi_postcore_init(void) -{ - char *uuid; - - efi_set_variable_usec("LoaderTimeInitUSec", &efi_systemd_vendor_guid, - get_time_ns()/1000); - - uuid = device_path_to_partuuid(device_path_from_handle( - efi_loaded_image->device_handle)); - if (uuid) { - wchar_t *uuid16 = xstrdup_char_to_wchar(uuid); - efi_set_variable("LoaderDevicePartUUID", - &efi_systemd_vendor_guid, - EFI_VARIABLE_BOOTSERVICE_ACCESS | - EFI_VARIABLE_RUNTIME_ACCESS, - uuid16, (strlen(uuid)+1) * sizeof(wchar_t)); - free(uuid); - free(uuid16); - } - - bbu_register_std_file_update("fat", 0, "/boot/EFI/BOOT/BOOTx64.EFI", - filetype_exe); - - return 0; -} -postcore_initcall(efi_postcore_init); - -static int efi_late_init(void) -{ - char *state_desc; - int ret; - - if (!IS_ENABLED(CONFIG_STATE)) - return 0; - - state_desc = xasprintf("/boot/EFI/barebox/state.dtb"); - - if (state_desc) { - void *fdt; - size_t size; - struct device_node *root = NULL; - struct device_node *np = NULL; - struct state *state; - - fdt = read_file(state_desc, &size); - if (!fdt) { - pr_err("unable to read %s: %s\n", state_desc, - strerror(errno)); - return -errno; - } - - if (file_detect_type(fdt, size) != filetype_oftree) { - pr_err("%s is not an oftree file.\n", state_desc); - free(fdt); - return -EINVAL; - } - - root = of_unflatten_dtb(fdt, size); - - free(fdt); - - if (IS_ERR(root)) - return PTR_ERR(root); - - ret = barebox_register_of(root); - if (ret) - pr_warn("Failed to register device-tree: %pe\n", ERR_PTR(ret)); - - np = of_find_node_by_alias(root, "state"); - - state = state_new_from_node(np, false); - if (IS_ERR(state)) - return PTR_ERR(state); - - ret = state_load(state); - if (ret != -ENOMEDIUM) - pr_warn("Failed to load persistent state, continuing with defaults, %d\n", - ret); - - return 0; - } - - return 0; -} -late_initcall(efi_late_init); - -static int do_efiexit(int argc, char *argv[]) -{ - return BS->exit(efi_parent_image, EFI_SUCCESS, 0, NULL); -} - -BAREBOX_CMD_HELP_START(efiexit) -BAREBOX_CMD_HELP_TEXT("Leave barebox and return to the calling EFI process\n") -BAREBOX_CMD_HELP_END - -BAREBOX_CMD_START(efiexit) - .cmd = do_efiexit, - BAREBOX_CMD_DESC("Usage: efiexit") - BAREBOX_CMD_GROUP(CMD_GRP_MISC) - BAREBOX_CMD_HELP(cmd_efiexit_help) -BAREBOX_CMD_END diff --git a/common/efi/payload/iomem.c b/common/efi/payload/iomem.c deleted file mode 100644 index 6b92ca993a..0000000000 --- a/common/efi/payload/iomem.c +++ /dev/null @@ -1,179 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -// Copyright (c) 2019 Ahmad Fatoum, Pengutronix - -#define pr_fmt(fmt) "efi-iomem: " fmt - -#include <common.h> -#include <init.h> -#include <efi.h> -#include <efi/efi-payload.h> -#include <memory.h> -#include <linux/sizes.h> - -static int efi_parse_mmap(struct efi_memory_desc *desc, bool verbose) -{ - struct resource *res; - u32 flags; - const char *name; - char *fullname; - resource_size_t va_base, va_size; - int ret = 0; - - va_size = desc->npages * SZ_4K; - if (!va_size) - return 0; - - /* XXX At least OVMF doesn't populate ->virt_start and leaves it at zero - * for all mapping. Thus assume a 1:1 mapping and ignore virt_start - */ - va_base = desc->phys_start; - - switch (desc->type) { - case EFI_RESERVED_TYPE: - if (verbose) - return 0; - name = "reserved"; - flags = IORESOURCE_MEM | IORESOURCE_DISABLED; - break; - case EFI_LOADER_CODE: - name = "loader code"; - flags = IORESOURCE_MEM | IORESOURCE_READONLY; - break; - case EFI_LOADER_DATA: - name = "loader data"; - flags = IORESOURCE_MEM; - break; - case EFI_BOOT_SERVICES_CODE: - if (!verbose) - return 0; - name = "boot services code"; - flags = IORESOURCE_MEM | IORESOURCE_READONLY; - break; - case EFI_BOOT_SERVICES_DATA: - if (!verbose) - return 0; - name = "boot services data"; - flags = IORESOURCE_MEM; - break; - case EFI_RUNTIME_SERVICES_CODE: - if (!verbose) - return 0; - name = "runtime services code"; - flags = IORESOURCE_MEM | IORESOURCE_READONLY; - break; - case EFI_RUNTIME_SERVICES_DATA: - if (!verbose) - return 0; - name = "runtime services data"; - flags = IORESOURCE_MEM; - break; - case EFI_CONVENTIONAL_MEMORY: - if (!verbose) - return 0; - name = "conventional memory"; - flags = IORESOURCE_MEM | IORESOURCE_PREFETCH | IORESOURCE_CACHEABLE; - break; - case EFI_UNUSABLE_MEMORY: - if (!verbose) - return 0; - name = "unusable"; - flags = IORESOURCE_MEM | IORESOURCE_DISABLED; - break; - case EFI_ACPI_RECLAIM_MEMORY: - if (!verbose) - return 0; - name = "ACPI reclaim memory"; - flags = IORESOURCE_MEM | IORESOURCE_READONLY; - break; - case EFI_ACPI_MEMORY_NVS: - if (!verbose) - return 0; - name = "ACPI NVS memory"; - flags = IORESOURCE_MEM | IORESOURCE_READONLY; - break; - case EFI_MEMORY_MAPPED_IO: - if (!verbose) - return 0; - name = "MMIO"; - flags = IORESOURCE_MEM; - break; - case EFI_MEMORY_MAPPED_IO_PORT_SPACE: - if (!verbose) - return 0; - name = "MMIOPORT"; - flags = IORESOURCE_IO; - break; - case EFI_PAL_CODE: - if (!verbose) - return 0; - name = "PAL code"; - flags = IORESOURCE_MEM | IORESOURCE_ROM_BIOS_COPY; - break; - default: - if (!(desc->type & (1U << 31))) { - pr_warn("illegal memory type = %u >= %u\n", - desc->type, EFI_MAX_MEMORY_TYPE); - return -EINVAL; - } - - if (!verbose) - return 0; - - name = "vendor reserved"; - flags = IORESOURCE_MEM | IORESOURCE_ROM_BIOS_COPY; - } - - fullname = xasprintf("%s@%llx", name, desc->phys_start); - - pr_debug("%s: (0x%llx+0x%llx)\n", fullname, va_base, va_size); - - res = request_iomem_region(fullname, va_base, va_base + va_size - 1); - if (IS_ERR(res)) { - ret = PTR_ERR(res); - goto out; - } - - res->flags |= flags; - -out: - free(fullname); - return ret; -} - -static int efi_barebox_populate_mmap(void) -{ - void *desc; - u8 *mmap_buf = NULL; - efi_status_t efiret; - size_t mmap_size; - size_t mapkey; - size_t descsz; - u32 descver; - int ret = 0; - - mmap_size = sizeof(struct efi_memory_desc); - - do { - mmap_buf = xrealloc(mmap_buf, mmap_size); - efiret = BS->get_memory_map(&mmap_size, mmap_buf, - &mapkey, &descsz, &descver); - } while (efiret == EFI_BUFFER_TOO_SMALL); - - if (EFI_ERROR(efiret)) { - ret = -efi_errno(efiret); - goto out; - } - - if (descver != 1) { - ret = -ENOSYS; - goto out; - } - - for (desc = mmap_buf; (u8 *)desc < mmap_buf + mmap_size; desc += descsz) - efi_parse_mmap(desc, __is_defined(DEBUG)); - -out: - free(mmap_buf); - return ret; -} -mem_initcall(efi_barebox_populate_mmap); |