diff options
Diffstat (limited to 'lib/efi_loader')
26 files changed, 427 insertions, 263 deletions
diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig index 6130af14337..3dadbc54b58 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -305,7 +305,6 @@ config EFI_CAPSULE_FIRMWARE_FIT depends on EFI_CAPSULE_FIRMWARE_MANAGEMENT select UPDATE_FIT select DFU - select SET_DFU_ALT_INFO select EFI_CAPSULE_FIRMWARE help Select this option if you want to enable firmware management protocol @@ -317,7 +316,6 @@ config EFI_CAPSULE_FIRMWARE_RAW depends on SANDBOX || (!SANDBOX && !EFI_CAPSULE_FIRMWARE_FIT) select DFU_WRITE_ALT select DFU - select SET_DFU_ALT_INFO select EFI_CAPSULE_FIRMWARE help Select this option if you want to enable firmware management protocol @@ -445,10 +443,9 @@ config EFI_TCG2_PROTOCOL_MEASURE_DTB help When enabled, the DTB image passed to the booted EFI image is measured using the EFI TCG2 protocol. Do not enable this feature if - the passed DTB contains data that change across platform reboots - and cannot be used has a predictable measurement. Otherwise - this feature allows better measurement of the system boot - sequence. + the passed DTB contains data that changes across platform reboots + and cannot be used for a predictable measurement. Otherwise, this + feature allows for better measurement of the system boot sequence. config EFI_LOAD_FILE2_INITRD bool "EFI_FILE_LOAD2_PROTOCOL for Linux initial ramdisk" diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile index 2a0b4172bd7..cf050e5385d 100644 --- a/lib/efi_loader/Makefile +++ b/lib/efi_loader/Makefile @@ -29,6 +29,7 @@ obj-y += efi_boottime.o obj-y += efi_helper.o obj-$(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) += efi_capsule.o obj-$(CONFIG_EFI_CAPSULE_FIRMWARE) += efi_firmware.o +obj-$(CONFIG_EFI_CAPSULE_AUTHENTICATE) += efi_capsule_key.o obj-y += efi_console.o obj-y += efi_device_path.o obj-$(CONFIG_EFI_DEVICE_PATH_TO_TEXT) += efi_device_path_to_text.o @@ -36,7 +37,7 @@ obj-$(CONFIG_EFI_DEVICE_PATH_UTIL) += efi_device_path_utilities.o obj-y += efi_dt_fixup.o obj-y += efi_fdt.o obj-y += efi_file.o -obj-$(CONFIG_EFI_LOADER_HII) += efi_hii.o +obj-$(CONFIG_EFI_LOADER_HII) += efi_hii.o efi_hii_config.o obj-y += efi_image_loader.o obj-y += efi_load_options.o obj-y += efi_memory.o @@ -73,6 +74,23 @@ obj-$(CONFIG_EFI_ECPT) += efi_conformance.o EFI_VAR_SEED_FILE := $(subst $\",,$(CONFIG_EFI_VAR_SEED_FILE)) $(obj)/efi_var_seed.o: $(srctree)/$(EFI_VAR_SEED_FILE) +ifeq ($(CONFIG_EFI_CAPSULE_AUTHENTICATE),y) +capsule_crt_path=($(subst $(quote),,$(CONFIG_EFI_CAPSULE_CRT_FILE))) +capsule_crt_full=$(srctree)/$(subst $(quote),,$(CONFIG_EFI_CAPSULE_CRT_FILE)) +quiet_cmd_capsule_esl_gen = CAPSULE_ESL_GEN $@ +cmd_capsule_esl_gen = cert-to-efi-sig-list $(capsule_crt_full) $@ +$(objtree)/capsule_esl_file: FORCE + @if [ ! -e "$(capsule_crt_full)" ]; then \ + echo "ERROR: path $(capsule_crt_full) is invalid." >&2; \ + echo "EFI CONFIG_EFI_CAPSULE_CRT_FILE must be specified when CONFIG_EFI_CAPSULE_AUTHENTICATE is enabled." >&2; \ + exit 1; \ + fi + $(call cmd,capsule_esl_gen) + +$(obj)/efi_capsule.o: $(objtree)/capsule_esl_file FORCE +asflags-y += -DCAPSULE_ESL_PATH=\"$(objtree)/capsule_esl_file\" +endif + # Set the C flags to add and remove for each app $(foreach f,$(apps-y),\ $(eval CFLAGS_$(f).o := $(CFLAGS_EFI) -Os -ffreestanding)\ diff --git a/lib/efi_loader/capsule_esl.dtsi.in b/lib/efi_loader/capsule_esl.dtsi.in deleted file mode 100644 index bc7db836faa..00000000000 --- a/lib/efi_loader/capsule_esl.dtsi.in +++ /dev/null @@ -1,11 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Devicetree file with the public key EFI Signature List(ESL) - * node. This file is used to generate the dtsi file to be - * included into the DTB. - */ -/ { - signature { - capsule-key = /incbin/("ESL_BIN_FILE"); - }; -}; diff --git a/lib/efi_loader/dtbdump.c b/lib/efi_loader/dtbdump.c index a3d59a2fd3b..1e72404ecc1 100644 --- a/lib/efi_loader/dtbdump.c +++ b/lib/efi_loader/dtbdump.c @@ -29,6 +29,18 @@ static struct efi_system_table *systable; static const efi_guid_t efi_dt_fixup_protocol_guid = EFI_DT_FIXUP_PROTOCOL_GUID; static const efi_guid_t efi_file_info_guid = EFI_FILE_INFO_GUID; static const efi_guid_t efi_system_partition_guid = PARTITION_SYSTEM_GUID; +static bool nocolor; + +/** + * color() - set foreground color + * + * @color: foreground color + */ +static void color(u8 color) +{ + if (!nocolor) + cout->set_attribute(cout, color | EFI_BACKGROUND_BLACK); +} /** * print() - print string @@ -88,15 +100,34 @@ static void printx(unsigned char val) } /** + * cls() - clear screen + */ +static void cls(void) +{ + if (nocolor) + print(u"\r\n"); + else + cout->clear_screen(cout); +} + +/** * error() - print error string * * @string: error text */ static void error(u16 *string) { - cout->set_attribute(cout, EFI_LIGHTRED | EFI_BACKGROUND_BLACK); + color(EFI_LIGHTRED); print(string); - cout->set_attribute(cout, EFI_LIGHTBLUE | EFI_BACKGROUND_BLACK); + color(EFI_LIGHTBLUE); +} + +/** + * efi_drain_input() - drain console input + */ +static void efi_drain_input(void) +{ + cin->reset(cin, true); } /** @@ -116,8 +147,6 @@ static efi_status_t efi_input_yn(void) efi_uintn_t index; efi_status_t ret; - /* Drain the console input */ - ret = cin->reset(cin, true); for (;;) { ret = bs->wait_for_event(1, &cin->wait_for_key, &index); if (ret != EFI_SUCCESS) @@ -158,8 +187,6 @@ static efi_status_t efi_input(u16 *buffer, efi_uintn_t buffer_size) u16 outbuf[2] = u" "; efi_status_t ret; - /* Drain the console input */ - ret = cin->reset(cin, true); *buffer = 0; for (;;) { ret = bs->wait_for_event(1, &cin->wait_for_key, &index); @@ -262,6 +289,9 @@ static u16 *skip_whitespace(u16 *pos) */ static bool starts_with(u16 *string, u16 *keyword) { + if (!string || !keyword) + return false; + for (; *keyword; ++string, ++keyword) { if (*string != *keyword) return false; @@ -737,6 +767,7 @@ static efi_status_t do_dump(void) error(u"Missing end node\r\n"); return EFI_LOAD_ERROR; } + print(u"\r\n"); return EFI_SUCCESS; default: error(u"Invalid device tree token\r\n"); @@ -749,6 +780,30 @@ static efi_status_t do_dump(void) } /** + * get_load_options() - get load options + * + * Return: load options or NULL + */ +static u16 *get_load_options(void) +{ + efi_status_t ret; + struct efi_loaded_image *loaded_image; + + ret = bs->open_protocol(handle, &loaded_image_guid, + (void **)&loaded_image, NULL, NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL); + if (ret != EFI_SUCCESS) { + error(u"Loaded image protocol not found\r\n"); + return NULL; + } + + if (!loaded_image->load_options_size || !loaded_image->load_options) + return NULL; + + return loaded_image->load_options; +} + +/** * efi_main() - entry point of the EFI application. * * @handle: handle of the loaded image @@ -758,24 +813,31 @@ static efi_status_t do_dump(void) efi_status_t EFIAPI efi_main(efi_handle_t image_handle, struct efi_system_table *systab) { + u16 *load_options; + handle = image_handle; systable = systab; cerr = systable->std_err; cout = systable->con_out; cin = systable->con_in; bs = systable->boottime; + load_options = get_load_options(); + + if (starts_with(load_options, u"nocolor")) + nocolor = true; - cout->set_attribute(cout, EFI_LIGHTBLUE | EFI_BACKGROUND_BLACK); - cout->clear_screen(cout); - cout->set_attribute(cout, EFI_WHITE | EFI_BACKGROUND_BLACK); + color(EFI_LIGHTBLUE); + cls(); + color(EFI_WHITE); print(u"DTB Dump\r\n========\r\n\r\n"); - cout->set_attribute(cout, EFI_LIGHTBLUE | EFI_BACKGROUND_BLACK); + color(EFI_LIGHTBLUE); for (;;) { u16 command[BUFFER_SIZE]; u16 *pos; efi_uintn_t ret; + efi_drain_input(); print(u"=> "); ret = efi_input(command, sizeof(command)); if (ret == EFI_ABORTED) @@ -793,7 +855,7 @@ efi_status_t EFIAPI efi_main(efi_handle_t image_handle, do_help(); } - cout->set_attribute(cout, EFI_LIGHTGRAY | EFI_BACKGROUND_BLACK); - cout->clear_screen(cout); + color(EFI_LIGHTGRAY); + cls(); return EFI_SUCCESS; } diff --git a/lib/efi_loader/efi_acpi.c b/lib/efi_loader/efi_acpi.c index 4422b31ac6a..046986a7518 100644 --- a/lib/efi_loader/efi_acpi.c +++ b/lib/efi_loader/efi_acpi.c @@ -7,6 +7,7 @@ #define LOG_CATEGORY LOGC_EFI +#include <bloblist.h> #include <efi_loader.h> #include <log.h> #include <mapmem.h> @@ -34,25 +35,38 @@ efi_status_t efi_acpi_register(void) * add_u_boot_and_runtime(). At some point that function could create a * more detailed map. */ - if (IS_ENABLED(CONFIG_BLOBLIST_TABLES)) - return EFI_SUCCESS; - - /* Mark space used for tables */ - start = ALIGN_DOWN(gd->arch.table_start, EFI_PAGE_MASK); - end = ALIGN(gd->arch.table_end, EFI_PAGE_MASK); - ret = efi_add_memory_map(start, end - start, EFI_ACPI_RECLAIM_MEMORY); - if (ret != EFI_SUCCESS) - return ret; - if (gd->arch.table_start_high) { - start = ALIGN_DOWN(gd->arch.table_start_high, EFI_PAGE_MASK); - end = ALIGN(gd->arch.table_end_high, EFI_PAGE_MASK); + if (IS_ENABLED(CONFIG_BLOBLIST_TABLES)) { + int size; + void *tab = bloblist_get_blob(BLOBLISTT_ACPI_TABLES, &size); + + if (!tab) + return EFI_NOT_FOUND; + addr = map_to_sysmem(tab); + + ret = efi_add_memory_map(addr, size, + EFI_ACPI_RECLAIM_MEMORY); + if (ret != EFI_SUCCESS) + return ret; + } else { + /* Mark space used for tables */ + start = ALIGN_DOWN(gd->arch.table_start, EFI_PAGE_MASK); + end = ALIGN(gd->arch.table_end, EFI_PAGE_MASK); ret = efi_add_memory_map(start, end - start, EFI_ACPI_RECLAIM_MEMORY); if (ret != EFI_SUCCESS) return ret; - } + if (gd->arch.table_start_high) { + start = ALIGN_DOWN(gd->arch.table_start_high, + EFI_PAGE_MASK); + end = ALIGN(gd->arch.table_end_high, EFI_PAGE_MASK); + ret = efi_add_memory_map(start, end - start, + EFI_ACPI_RECLAIM_MEMORY); + if (ret != EFI_SUCCESS) + return ret; + } - addr = gd_acpi_start(); + addr = gd_acpi_start(); + } log_debug("EFI using ACPI tables at %lx\n", addr); /* And expose them to our EFI payload */ diff --git a/lib/efi_loader/efi_bootbin.c b/lib/efi_loader/efi_bootbin.c index deafb2ce1c2..b394f0d60ce 100644 --- a/lib/efi_loader/efi_bootbin.c +++ b/lib/efi_loader/efi_bootbin.c @@ -10,6 +10,7 @@ #include <charset.h> #include <dm.h> #include <efi.h> +#include <efi_device_path.h> #include <efi_loader.h> #include <env.h> #include <image.h> @@ -204,6 +205,8 @@ out: * @image: memory address of the UEFI image * @size: size of the UEFI image * @fdt: device-tree + * @initrd: initrd + * @initrd_sz: initrd size * @dp_dev: EFI device-path * @dp_img: EFI image-path * @@ -213,6 +216,7 @@ out: * Return: status code */ static efi_status_t efi_binary_run_dp(void *image, size_t size, void *fdt, + void *initrd, size_t initrd_sz, struct efi_device_path *dp_dev, struct efi_device_path *dp_img) { @@ -230,6 +234,10 @@ static efi_status_t efi_binary_run_dp(void *image, size_t size, void *fdt, if (ret != EFI_SUCCESS) return ret; + ret = efi_install_initrd(initrd, initrd_sz); + if (ret != EFI_SUCCESS) + return ret; + return efi_run_image(image, size, dp_dev, dp_img); } @@ -239,13 +247,15 @@ static efi_status_t efi_binary_run_dp(void *image, size_t size, void *fdt, * @image: memory address of the UEFI image * @size: size of the UEFI image * @fdt: device-tree + * @initrd: initrd + * @initrd_sz: initrd size * * Execute an EFI binary image loaded at @image. * @size may be zero if the binary is loaded with U-Boot load command. * * Return: status code */ -efi_status_t efi_binary_run(void *image, size_t size, void *fdt) +efi_status_t efi_binary_run(void *image, size_t size, void *fdt, void *initrd, size_t initrd_sz) { efi_handle_t mem_handle = NULL; struct efi_device_path *file_path = NULL; @@ -269,11 +279,14 @@ efi_status_t efi_binary_run(void *image, size_t size, void *fdt) file_path, NULL); if (ret != EFI_SUCCESS) goto out; + + bootefi_device_path = file_path; + bootefi_image_path = NULL; } else { log_debug("Loaded from disk\n"); } - ret = efi_binary_run_dp(image, size, fdt, bootefi_device_path, + ret = efi_binary_run_dp(image, size, fdt, initrd, initrd_sz, bootefi_device_path, bootefi_image_path); out: if (mem_handle) { @@ -355,7 +368,7 @@ efi_status_t efi_bootflow_run(struct bootflow *bflow) log_debug("Booting with external fdt\n"); fdt = map_sysmem(bflow->fdt_addr, 0); } - ret = efi_binary_run_dp(bflow->buf, bflow->size, fdt, device, image); + ret = efi_binary_run_dp(bflow->buf, bflow->size, fdt, NULL, 0, device, image); return ret; } diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c index f9534ef85ed..b9437a81c64 100644 --- a/lib/efi_loader/efi_bootmgr.c +++ b/lib/efi_loader/efi_bootmgr.c @@ -12,6 +12,8 @@ #include <charset.h> #include <dm.h> #include <efi.h> +#include <efi_device_path.h> +#include <env.h> #include <log.h> #include <malloc.h> #include <net.h> @@ -479,6 +481,13 @@ static efi_status_t try_load_from_uri_path(struct efi_device_path_uri *uridp, if (!ctx) return EFI_OUT_OF_RESOURCES; + s = env_get("ipaddr"); + if (!s && dhcp_run(0, NULL, false)) { + log_err("Error: Can't find a valid IP address\n"); + ret = EFI_DEVICE_ERROR; + goto err; + } + s = env_get("loadaddr"); if (!s) { log_err("Error: loadaddr is not set\n"); @@ -527,7 +536,7 @@ static efi_status_t try_load_from_uri_path(struct efi_device_path_uri *uridp, * will be freed in return_to_efibootmgr event callback. */ loaded_dp = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE, - (uintptr_t)image_addr, image_size); + image_addr, image_size); ret = efi_install_multiple_protocol_interfaces( &mem_handle, &efi_guid_device_path, loaded_dp, NULL); if (ret != EFI_SUCCESS) @@ -685,12 +694,12 @@ static efi_status_t try_load_entry(u16 n, efi_handle_t *handle, /* try to register load file2 for initrd's */ if (IS_ENABLED(CONFIG_EFI_LOAD_FILE2_INITRD)) { - ret = efi_initrd_register(); + ret = efi_initrd_register(NULL); if (ret != EFI_SUCCESS) goto error; } - log_info("Booting: %ls\n", lo.label); + log_info("Booting: Label: %ls Device path: %pD\n", lo.label, lo.file_path); /* Ignore the optional data in auto-generated boot options */ if (size >= sizeof(efi_guid_t) && @@ -855,7 +864,8 @@ efi_bootmgr_enumerate_boot_options(struct eficonfig_media_boot_option *opt, lo.label = dev_name; lo.attributes = LOAD_OPTION_ACTIVE; lo.file_path = device_path; - lo.file_path_length = efi_dp_size(device_path) + sizeof(END); + lo.file_path_length = efi_dp_size(device_path) + + sizeof(EFI_DP_END); /* * Set the dedicated guid to optional_data, it is used to identify * the boot option that automatically generated by the bootmenu. diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index f220daa048f..754bc6a6519 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -11,6 +11,7 @@ #include <div64.h> #include <dm/device.h> #include <dm/root.h> +#include <efi_device_path.h> #include <efi_loader.h> #include <irq_func.h> #include <log.h> @@ -57,7 +58,7 @@ static efi_handle_t current_image; * restriction so we need to manually swap its and our view of that register on * EFI callback entry/exit. */ -static volatile gd_t *efi_gd, *app_gd; +static gd_t *efi_gd, *app_gd; #endif efi_status_t efi_uninstall_protocol @@ -3195,7 +3196,7 @@ efi_status_t EFIAPI efi_start_image(efi_handle_t image_handle, struct efi_loaded_image_obj *image_obj = (struct efi_loaded_image_obj *)image_handle; efi_status_t ret; - void *info; + struct efi_loaded_image *info; efi_handle_t parent_image = current_image; efi_status_t exit_status; jmp_buf exit_jmp; @@ -3213,7 +3214,7 @@ efi_status_t EFIAPI efi_start_image(efi_handle_t image_handle, return EFI_EXIT(EFI_SECURITY_VIOLATION); ret = EFI_CALL(efi_open_protocol(image_handle, &efi_guid_loaded_image, - &info, NULL, NULL, + (void **)&info, NULL, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL)); if (ret != EFI_SUCCESS) return EFI_EXIT(EFI_INVALID_PARAMETER); @@ -3266,7 +3267,8 @@ efi_status_t EFIAPI efi_start_image(efi_handle_t image_handle, current_image = image_handle; image_obj->header.type = EFI_OBJECT_TYPE_STARTED_IMAGE; - EFI_PRINT("Jumping into 0x%p\n", image_obj->entry); + EFI_PRINT("Starting image loaded at 0x%p, entry point 0x%p\n", + info->image_base, image_obj->entry); ret = EFI_CALL(image_obj->entry(image_handle, &systab)); /* diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_capsule.c index f8a4a7c6ef4..f19e78ae9d1 100644 --- a/lib/efi_loader/efi_capsule.c +++ b/lib/efi_loader/efi_capsule.c @@ -8,6 +8,7 @@ #define LOG_CATEGORY LOGC_EFI +#include <efi_device_path.h> #include <efi_loader.h> #include <efi_variable.h> #include <env.h> @@ -22,6 +23,7 @@ #include <asm/global_data.h> #include <u-boot/uuid.h> +#include <asm/sections.h> #include <crypto/pkcs7.h> #include <crypto/pkcs7_parser.h> #include <linux/err.h> @@ -284,33 +286,12 @@ out: } #if defined(CONFIG_EFI_CAPSULE_AUTHENTICATE) -int efi_get_public_key_data(void **pkey, efi_uintn_t *pkey_len) +static int efi_get_public_key_data(const void **pkey, efi_uintn_t *pkey_len) { - const void *fdt_blob = gd->fdt_blob; - const void *blob; - const char *cnode_name = "capsule-key"; - const char *snode_name = "signature"; - int sig_node; - int len; - - sig_node = fdt_subnode_offset(fdt_blob, 0, snode_name); - if (sig_node < 0) { - log_err("Unable to get signature node offset\n"); - - return -FDT_ERR_NOTFOUND; - } - - blob = fdt_getprop(fdt_blob, sig_node, cnode_name, &len); - - if (!blob || len < 0) { - log_err("Unable to get capsule-key value\n"); - *pkey = NULL; - *pkey_len = 0; - - return -FDT_ERR_NOTFOUND; - } + const void *blob = __efi_capsule_sig_begin; + const int len = __efi_capsule_sig_end - __efi_capsule_sig_begin; - *pkey = (void *)blob; + *pkey = blob; *pkey_len = len; return 0; @@ -321,7 +302,8 @@ efi_status_t efi_capsule_authenticate(const void *capsule, efi_uintn_t capsule_s { u8 *buf; int ret; - void *fdt_pkey, *pkey; + void *pkey; + const void *stored_pkey; efi_uintn_t pkey_len; uint64_t monotonic_count; struct efi_signature_store *truststore; @@ -373,7 +355,7 @@ efi_status_t efi_capsule_authenticate(const void *capsule, efi_uintn_t capsule_s goto out; } - ret = efi_get_public_key_data(&fdt_pkey, &pkey_len); + ret = efi_get_public_key_data(&stored_pkey, &pkey_len); if (ret < 0) goto out; @@ -381,7 +363,7 @@ efi_status_t efi_capsule_authenticate(const void *capsule, efi_uintn_t capsule_s if (!pkey) goto out; - memcpy(pkey, fdt_pkey, pkey_len); + memcpy(pkey, stored_pkey, pkey_len); truststore = efi_build_signature_store(pkey, pkey_len); if (!truststore) goto out; diff --git a/lib/efi_loader/efi_capsule_key.S b/lib/efi_loader/efi_capsule_key.S new file mode 100644 index 00000000000..80cefbe16ae --- /dev/null +++ b/lib/efi_loader/efi_capsule_key.S @@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * .esl cert for capsule authentication + * + * Copyright (c) 2021, Ilias Apalodimas <ilias.apalodimas@linaro.org> + */ + +#include <config.h> + +.section .rodata.capsule_key.init,"a" +.balign 16 +.global __efi_capsule_sig_begin +__efi_capsule_sig_begin: +.incbin CAPSULE_ESL_PATH +__efi_capsule_sig_end: +.global __efi_capsule_sig_end +.balign 16 diff --git a/lib/efi_loader/efi_console.c b/lib/efi_loader/efi_console.c index 9d9f786a6db..953f6831466 100644 --- a/lib/efi_loader/efi_console.c +++ b/lib/efi_loader/efi_console.c @@ -9,6 +9,7 @@ #include <ansi.h> #include <charset.h> +#include <efi_device_path.h> #include <malloc.h> #include <time.h> #include <dm/device.h> @@ -30,6 +31,17 @@ struct cout_mode { __maybe_unused static struct efi_object uart_obj; +/* + * suppress emission of ANSI escape-characters for use by unit tests. Leave it + * as 0 for the default behaviour + */ +static bool no_ansi; + +void efi_console_set_ansi(bool allow_ansi) +{ + no_ansi = !allow_ansi; +} + static struct cout_mode efi_cout_modes[] = { /* EFI Mode 0 is 80x25 and always present */ { @@ -348,13 +360,6 @@ static int __maybe_unused query_vidconsole(int *rows, int *cols) return 0; } -/** - * efi_setup_console_size() - update the mode table. - * - * By default the only mode available is 80x25. If the console has at least 50 - * lines, enable mode 80x50. If we can query the console size and it is neither - * 80x25 nor 80x50, set it as an additional mode. - */ void efi_setup_console_size(void) { int rows = 25, cols = 80; @@ -362,8 +367,12 @@ void efi_setup_console_size(void) if (IS_ENABLED(CONFIG_VIDEO)) ret = query_vidconsole(&rows, &cols); - if (ret) - ret = query_console_serial(&rows, &cols); + if (ret) { + if (no_ansi) + ret = 0; + else + ret = query_console_serial(&rows, &cols); + } if (ret) return; diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c index c9bf2726fe2..b3fb20b2501 100644 --- a/lib/efi_loader/efi_device_path.c +++ b/lib/efi_loader/efi_device_path.c @@ -10,6 +10,8 @@ #include <blk.h> #include <dm.h> #include <dm/root.h> +#include <efi_device_path.h> +#include <ide.h> #include <log.h> #include <net.h> #include <usb.h> @@ -21,11 +23,11 @@ #include <asm-generic/unaligned.h> #include <linux/compat.h> /* U16_MAX */ -/* template END node: */ -const struct efi_device_path END = { +/* template EFI_DP_END node: */ +const struct efi_device_path EFI_DP_END = { .type = DEVICE_PATH_TYPE_END, .sub_type = DEVICE_PATH_SUB_TYPE_END, - .length = sizeof(END), + .length = sizeof(EFI_DP_END), }; #if defined(CONFIG_MMC) @@ -46,10 +48,6 @@ static bool is_sd(struct blk_desc *desc) } #endif -/* - * Iterate to next block in device-path, terminating (returning NULL) - * at /End* node. - */ struct efi_device_path *efi_dp_next(const struct efi_device_path *dp) { if (dp == NULL) @@ -62,12 +60,6 @@ struct efi_device_path *efi_dp_next(const struct efi_device_path *dp) return (struct efi_device_path *)dp; } -/* - * Compare two device-paths, stopping when the shorter of the two hits - * an End* node. This is useful to, for example, compare a device-path - * representing a device with one representing a file on the device, or - * a device with a parent device. - */ int efi_dp_match(const struct efi_device_path *a, const struct efi_device_path *b) { @@ -90,20 +82,6 @@ int efi_dp_match(const struct efi_device_path *a, } } -/** - * efi_dp_shorten() - shorten device-path - * - * When creating a short boot option we want to use a device-path that is - * independent of the location where the block device is plugged in. - * - * UsbWwi() nodes contain a serial number, hard drive paths a partition - * UUID. Both should be unique. - * - * See UEFI spec, section 3.1.2 for "short-form device path". - * - * @dp: original device-path - * Return: shortened device-path or NULL - */ struct efi_device_path *efi_dp_shorten(struct efi_device_path *dp) { while (dp) { @@ -180,16 +158,6 @@ static efi_handle_t find_handle(struct efi_device_path *dp, return best_handle; } -/** - * efi_dp_find_obj() - find handle by device path - * - * If @rem is provided, the handle with the longest partial match is returned. - * - * @dp: device path to search - * @guid: GUID of protocol that must be installed on path or NULL - * @rem: pointer to receive remaining device path - * Return: matching handle - */ efi_handle_t efi_dp_find_obj(struct efi_device_path *dp, const efi_guid_t *guid, struct efi_device_path **rem) @@ -204,13 +172,6 @@ efi_handle_t efi_dp_find_obj(struct efi_device_path *dp, return handle; } -/* - * Determine the last device path node that is not the end node. - * - * @dp device path - * Return: last node before the end node if it exists - * otherwise NULL - */ const struct efi_device_path *efi_dp_last_node(const struct efi_device_path *dp) { struct efi_device_path *ret; @@ -224,7 +185,6 @@ const struct efi_device_path *efi_dp_last_node(const struct efi_device_path *dp) return ret; } -/* get size of the first device path instance excluding end node */ efi_uintn_t efi_dp_instance_size(const struct efi_device_path *dp) { efi_uintn_t sz = 0; @@ -239,7 +199,6 @@ efi_uintn_t efi_dp_instance_size(const struct efi_device_path *dp) return sz; } -/* get size of multi-instance device path excluding end node */ efi_uintn_t efi_dp_size(const struct efi_device_path *dp) { const struct efi_device_path *p = dp; @@ -253,11 +212,10 @@ efi_uintn_t efi_dp_size(const struct efi_device_path *dp) return (void *)p - (void *)dp; } -/* copy multi-instance device path */ struct efi_device_path *efi_dp_dup(const struct efi_device_path *dp) { struct efi_device_path *ndp; - size_t sz = efi_dp_size(dp) + sizeof(END); + size_t sz = efi_dp_size(dp) + sizeof(EFI_DP_END); if (!dp) return NULL; @@ -270,21 +228,6 @@ struct efi_device_path *efi_dp_dup(const struct efi_device_path *dp) return ndp; } -/** - * efi_dp_concat() - Concatenate two device paths and add and terminate them - * with an end node. - * - * @dp1: First device path - * @dp2: Second device path - * @split_end_node: - * * 0 to concatenate - * * 1 to concatenate with end node added as separator - * * size of dp1 excluding last end node to concatenate with end node as - * separator in case dp1 contains an end node - * - * Return: - * concatenated device path or NULL. Caller must free the returned value - */ struct efi_device_path *efi_dp_concat(const struct efi_device_path *dp1, const struct efi_device_path *dp2, @@ -295,7 +238,7 @@ efi_device_path *efi_dp_concat(const struct efi_device_path *dp1, if (!dp1 && !dp2) { /* return an end node */ - ret = efi_dp_dup(&END); + ret = efi_dp_dup(&EFI_DP_END); } else if (!dp1) { ret = efi_dp_dup(dp2); } else if (!dp2) { @@ -312,9 +255,9 @@ efi_device_path *efi_dp_concat(const struct efi_device_path *dp1, sz1 = split_end_node; if (split_end_node) - end_size = 2 * sizeof(END); + end_size = 2 * sizeof(EFI_DP_END); else - end_size = sizeof(END); + end_size = sizeof(EFI_DP_END); p = efi_alloc(sz1 + sz2 + end_size); if (!p) return NULL; @@ -323,14 +266,14 @@ efi_device_path *efi_dp_concat(const struct efi_device_path *dp1, p += sz1; if (split_end_node) { - memcpy(p, &END, sizeof(END)); - p += sizeof(END); + memcpy(p, &EFI_DP_END, sizeof(EFI_DP_END)); + p += sizeof(EFI_DP_END); } /* the end node of the second device path has to be retained */ memcpy(p, dp2, sz2); p += sz2; - memcpy(p, &END, sizeof(END)); + memcpy(p, &EFI_DP_END, sizeof(EFI_DP_END)); } return ret; @@ -342,26 +285,26 @@ struct efi_device_path *efi_dp_append_node(const struct efi_device_path *dp, struct efi_device_path *ret; if (!node && !dp) { - ret = efi_dp_dup(&END); + ret = efi_dp_dup(&EFI_DP_END); } else if (!node) { ret = efi_dp_dup(dp); } else if (!dp) { size_t sz = node->length; - void *p = efi_alloc(sz + sizeof(END)); + void *p = efi_alloc(sz + sizeof(EFI_DP_END)); if (!p) return NULL; memcpy(p, node, sz); - memcpy(p + sz, &END, sizeof(END)); + memcpy(p + sz, &EFI_DP_END, sizeof(EFI_DP_END)); ret = p; } else { /* both dp and node are non-null */ size_t sz = efi_dp_size(dp); - void *p = efi_alloc(sz + node->length + sizeof(END)); + void *p = efi_alloc(sz + node->length + sizeof(EFI_DP_END)); if (!p) return NULL; memcpy(p, dp, sz); memcpy(p + sz, node, node->length); - memcpy(p + sz + node->length, &END, sizeof(END)); + memcpy(p + sz + node->length, &EFI_DP_END, sizeof(EFI_DP_END)); ret = p; } @@ -399,17 +342,17 @@ struct efi_device_path *efi_dp_append_instance( return efi_dp_dup(dpi); sz = efi_dp_size(dp); szi = efi_dp_instance_size(dpi); - p = efi_alloc(sz + szi + 2 * sizeof(END)); + p = efi_alloc(sz + szi + 2 * sizeof(EFI_DP_END)); if (!p) return NULL; ret = p; - memcpy(p, dp, sz + sizeof(END)); + memcpy(p, dp, sz + sizeof(EFI_DP_END)); p = (void *)p + sz; p->sub_type = DEVICE_PATH_SUB_TYPE_INSTANCE_END; - p = (void *)p + sizeof(END); + p = (void *)p + sizeof(EFI_DP_END); memcpy(p, dpi, szi); p = (void *)p + szi; - memcpy(p, &END, sizeof(END)); + memcpy(p, &EFI_DP_END, sizeof(EFI_DP_END)); return ret; } @@ -424,17 +367,17 @@ struct efi_device_path *efi_dp_get_next_instance(struct efi_device_path **dp, if (!dp || !*dp) return NULL; sz = efi_dp_instance_size(*dp); - p = efi_alloc(sz + sizeof(END)); + p = efi_alloc(sz + sizeof(EFI_DP_END)); if (!p) return NULL; - memcpy(p, *dp, sz + sizeof(END)); + memcpy(p, *dp, sz + sizeof(EFI_DP_END)); *dp = (void *)*dp + sz; if ((*dp)->sub_type == DEVICE_PATH_SUB_TYPE_INSTANCE_END) - *dp = (void *)*dp + sizeof(END); + *dp = (void *)*dp + sizeof(EFI_DP_END); else *dp = NULL; if (size) - *size = sz + sizeof(END); + *size = sz + sizeof(EFI_DP_END); return p; } @@ -449,9 +392,6 @@ bool efi_dp_is_multi_instance(const struct efi_device_path *dp) return p->sub_type == DEVICE_PATH_SUB_TYPE_INSTANCE_END; } -/* size of device-path not including END node for device and all parents - * up to the root device. - */ __maybe_unused static unsigned int dp_size(struct udevice *dev) { if (!dev || !dev->driver) @@ -820,29 +760,21 @@ static void *dp_part_fill(void *buf, struct blk_desc *desc, int part) return dp_part_node(buf, desc, part); } -/* Construct a device-path from a partition on a block device: */ struct efi_device_path *efi_dp_from_part(struct blk_desc *desc, int part) { void *buf, *start; - start = buf = efi_alloc(dp_part_size(desc, part) + sizeof(END)); - if (!buf) + start = efi_alloc(dp_part_size(desc, part) + sizeof(EFI_DP_END)); + if (!start) return NULL; - buf = dp_part_fill(buf, desc, part); + buf = dp_part_fill(start, desc, part); - *((struct efi_device_path *)buf) = END; + *((struct efi_device_path *)buf) = EFI_DP_END; return start; } -/* - * Create a device node for a block device partition. - * - * @buf buffer to which the device path is written - * @desc block device descriptor - * @part partition number, 0 identifies a block device - */ struct efi_device_path *efi_dp_part_node(struct blk_desc *desc, int part) { efi_uintn_t dpsize; @@ -892,13 +824,6 @@ static void path_to_uefi(void *uefi, const char *src) *pos = 0; } -/** - * efi_dp_from_file() - append file path node to device path. - * - * @dp: device path or NULL - * @path: file path or NULL - * Return: device path or NULL in case of an error - */ struct efi_device_path *efi_dp_from_file(const struct efi_device_path *dp, const char *path) { @@ -912,7 +837,7 @@ struct efi_device_path *efi_dp_from_file(const struct efi_device_path *dp, if (fpsize > U16_MAX) return NULL; - buf = efi_alloc(dpsize + fpsize + sizeof(END)); + buf = efi_alloc(dpsize + fpsize + sizeof(EFI_DP_END)); if (!buf) return NULL; @@ -929,7 +854,7 @@ struct efi_device_path *efi_dp_from_file(const struct efi_device_path *dp, pos += fpsize; } - memcpy(pos, &END, sizeof(END)); + memcpy(pos, &EFI_DP_END, sizeof(EFI_DP_END)); return buf; } @@ -938,7 +863,7 @@ struct efi_device_path *efi_dp_from_uart(void) { void *buf, *pos; struct efi_device_path_uart *uart; - size_t dpsize = dp_size(dm_root()) + sizeof(*uart) + sizeof(END); + size_t dpsize = dp_size(dm_root()) + sizeof(*uart) + sizeof(EFI_DP_END); buf = efi_alloc(dpsize); if (!buf) @@ -949,7 +874,7 @@ struct efi_device_path *efi_dp_from_uart(void) uart->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_UART; uart->dp.length = sizeof(*uart); pos += sizeof(*uart); - memcpy(pos, &END, sizeof(END)); + memcpy(pos, &EFI_DP_END, sizeof(EFI_DP_END)); return buf; } @@ -963,13 +888,13 @@ struct efi_device_path __maybe_unused *efi_dp_from_eth(struct udevice *dev) dpsize += dp_size(dev); - start = buf = efi_alloc(dpsize + sizeof(END)); - if (!buf) + start = efi_alloc(dpsize + sizeof(EFI_DP_END)); + if (!start) return NULL; - buf = dp_fill(buf, dev); + buf = dp_fill(start, dev); - *((struct efi_device_path *)buf) = END; + *((struct efi_device_path *)buf) = EFI_DP_END; return start; } @@ -979,7 +904,7 @@ struct efi_device_path __maybe_unused *efi_dp_from_eth(struct udevice *dev) * * Set the device path to an ethernet device path as provided by * efi_dp_from_eth() concatenated with a device path of subtype - * DEVICE_PATH_SUB_TYPE_MSG_IPV4, and an END node. + * DEVICE_PATH_SUB_TYPE_MSG_IPV4, and an EFI_DP_END node. * * @ip: IPv4 local address * @mask: network mask @@ -1010,7 +935,7 @@ static struct efi_device_path *efi_dp_from_ipv4(struct efi_ipv4_address *ip, if (srv) memcpy(&dp.ipv4dp.remote_ip_address, srv, sizeof(*srv)); pos = &dp.end; - memcpy(pos, &END, sizeof(END)); + memcpy(pos, &EFI_DP_END, sizeof(EFI_DP_END)); dp1 = efi_dp_from_eth(dev); if (!dp1) @@ -1023,17 +948,6 @@ static struct efi_device_path *efi_dp_from_ipv4(struct efi_ipv4_address *ip, return dp2; } -/** - * efi_dp_from_http() - set device path from http - * - * Set the device path to an IPv4 path as provided by efi_dp_from_ipv4 - * concatenated with a device path of subtype DEVICE_PATH_SUB_TYPE_MSG_URI, - * and an END node. - * - * @server: URI of remote server - * @dev: net udevice - * Return: pointer to HTTP device path, NULL on error - */ struct efi_device_path *efi_dp_from_http(const char *server, struct udevice *dev) { struct efi_device_path *dp1, *dp2; @@ -1066,7 +980,7 @@ struct efi_device_path *efi_dp_from_http(const char *server, struct udevice *dev } uridp_len = sizeof(struct efi_device_path) + strlen(tmp) + 1; - uridp = efi_alloc(uridp_len + sizeof(END)); + uridp = efi_alloc(uridp_len + sizeof(EFI_DP_END)); if (!uridp) { log_err("Out of memory\n"); return NULL; @@ -1078,7 +992,7 @@ struct efi_device_path *efi_dp_from_http(const char *server, struct udevice *dev memcpy(uridp->uri, tmp, strlen(tmp) + 1); pos = (char *)uridp + uridp_len; - memcpy(pos, &END, sizeof(END)); + memcpy(pos, &EFI_DP_END, sizeof(EFI_DP_END)); dp2 = efi_dp_concat(dp1, (const struct efi_device_path *)uridp, 0); @@ -1096,11 +1010,11 @@ struct efi_device_path *efi_dp_from_mem(uint32_t memory_type, struct efi_device_path_memory *mdp; void *buf, *start; - start = buf = efi_alloc(sizeof(*mdp) + sizeof(END)); - if (!buf) + start = efi_alloc(sizeof(*mdp) + sizeof(EFI_DP_END)); + if (!start) return NULL; - mdp = buf; + mdp = start; mdp->dp.type = DEVICE_PATH_TYPE_HARDWARE_DEVICE; mdp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MEMORY; mdp->dp.length = sizeof(*mdp); @@ -1109,7 +1023,7 @@ struct efi_device_path *efi_dp_from_mem(uint32_t memory_type, mdp->end_address = start_address + size; buf = &mdp[1]; - *((struct efi_device_path *)buf) = END; + *((struct efi_device_path *)buf) = EFI_DP_END; return start; } diff --git a/lib/efi_loader/efi_device_path_utilities.c b/lib/efi_loader/efi_device_path_utilities.c index 552c5bb1f05..87d52df5066 100644 --- a/lib/efi_loader/efi_device_path_utilities.c +++ b/lib/efi_loader/efi_device_path_utilities.c @@ -7,6 +7,7 @@ #define LOG_CATEGORY LOGC_EFI +#include <efi_device_path.h> #include <efi_loader.h> const efi_guid_t efi_guid_device_path_utilities_protocol = @@ -31,7 +32,7 @@ static efi_uintn_t EFIAPI get_device_path_size( efi_uintn_t sz = 0; EFI_ENTRY("%pD", device_path); - /* size includes the END node: */ + /* size includes the EFI_DP_END node: */ if (device_path) sz = efi_dp_size(device_path) + sizeof(struct efi_device_path); return EFI_EXIT(sz); diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c index 5452640354e..47b583cc5e1 100644 --- a/lib/efi_loader/efi_disk.c +++ b/lib/efi_loader/efi_disk.c @@ -11,6 +11,7 @@ #include <dm.h> #include <dm/device-internal.h> #include <dm/tag.h> +#include <efi_device_path.h> #include <event.h> #include <efi_driver.h> #include <efi_loader.h> diff --git a/lib/efi_loader/efi_dt_fixup.c b/lib/efi_loader/efi_dt_fixup.c index 26928cfc454..544e1aa9808 100644 --- a/lib/efi_loader/efi_dt_fixup.c +++ b/lib/efi_loader/efi_dt_fixup.c @@ -168,7 +168,7 @@ efi_dt_fixup(struct efi_dt_fixup_protocol *this, void *dtb, /* Check size */ required_size = fdt_off_dt_strings(dtb) + fdt_size_dt_strings(dtb) + - 0x3000; + CONFIG_SYS_FDT_PAD; total_size = fdt_totalsize(dtb); if (required_size < total_size) required_size = total_size; diff --git a/lib/efi_loader/efi_fdt.c b/lib/efi_loader/efi_fdt.c index 1ba6641d821..bfaa9cfc207 100644 --- a/lib/efi_loader/efi_fdt.c +++ b/lib/efi_loader/efi_fdt.c @@ -8,6 +8,7 @@ #define LOG_CATEGORY LOGC_EFI +#include <efi_device_path.h> #include <efi_loader.h> #include <env.h> #include <errno.h> diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c index 5a754c9cd03..75501e21557 100644 --- a/lib/efi_loader/efi_firmware.c +++ b/lib/efi_loader/efi_firmware.c @@ -12,6 +12,7 @@ #include <dfu.h> #include <efi_loader.h> #include <efi_variable.h> +#include <env.h> #include <fwu.h> #include <image.h> #include <signatures.h> @@ -56,11 +57,6 @@ struct fmp_state { u32 last_attempt_status; /* not used */ }; -__weak void set_dfu_alt_info(char *interface, char *devstr) -{ - env_set("dfu_alt_info", update_info.dfu_string); -} - /** * efi_firmware_get_image_type_id - get image_type_id * @image_index: image index @@ -649,8 +645,10 @@ efi_status_t EFIAPI efi_firmware_fit_set_image( efi_status_t (*progress)(efi_uintn_t completion), u16 **abort_reason) { + int ret; efi_status_t status; struct fmp_state state = { 0 }; + char *orig_dfu_env; EFI_ENTRY("%p %d %p %zu %p %p %p\n", this, image_index, image, image_size, vendor_code, progress, abort_reason); @@ -663,7 +661,28 @@ efi_status_t EFIAPI efi_firmware_fit_set_image( if (status != EFI_SUCCESS) return EFI_EXIT(status); - if (fit_update(image)) + orig_dfu_env = env_get("dfu_alt_info"); + if (orig_dfu_env) { + orig_dfu_env = strdup(orig_dfu_env); + if (!orig_dfu_env) { + log_err("strdup() failed!\n"); + return EFI_EXIT(EFI_OUT_OF_RESOURCES); + } + } + if (env_set("dfu_alt_info", update_info.dfu_string)) { + log_err("Unable to set env variable \"dfu_alt_info\"!\n"); + free(orig_dfu_env); + return EFI_EXIT(EFI_DEVICE_ERROR); + } + + ret = fit_update(image); + + if (env_set("dfu_alt_info", orig_dfu_env)) + log_warning("Unable to restore env variable \"dfu_alt_info\". Further DFU operations may fail!\n"); + + free(orig_dfu_env); + + if (ret) return EFI_EXIT(EFI_DEVICE_ERROR); efi_firmware_set_fmp_state_var(&state, image_index); @@ -717,6 +736,7 @@ efi_status_t EFIAPI efi_firmware_raw_set_image( u8 dfu_alt_num; efi_status_t status; struct fmp_state state = { 0 }; + char *orig_dfu_env; EFI_ENTRY("%p %d %p %zu %p %p %p\n", this, image_index, image, image_size, vendor_code, progress, abort_reason); @@ -747,8 +767,29 @@ efi_status_t EFIAPI efi_firmware_raw_set_image( } } - if (dfu_write_by_alt(dfu_alt_num, (void *)image, image_size, - NULL, NULL)) + orig_dfu_env = env_get("dfu_alt_info"); + if (orig_dfu_env) { + orig_dfu_env = strdup(orig_dfu_env); + if (!orig_dfu_env) { + log_err("strdup() failed!\n"); + return EFI_EXIT(EFI_OUT_OF_RESOURCES); + } + } + if (env_set("dfu_alt_info", update_info.dfu_string)) { + log_err("Unable to set env variable \"dfu_alt_info\"!\n"); + free(orig_dfu_env); + return EFI_EXIT(EFI_DEVICE_ERROR); + } + + ret = dfu_write_by_alt(dfu_alt_num, (void *)image, image_size, + NULL, NULL); + + if (env_set("dfu_alt_info", orig_dfu_env)) + log_warning("Unable to restore env variable \"dfu_alt_info\". Further DFU operations may fail!\n"); + + free(orig_dfu_env); + + if (ret) return EFI_EXIT(EFI_DEVICE_ERROR); efi_firmware_set_fmp_state_var(&state, image_index); diff --git a/lib/efi_loader/efi_gop.c b/lib/efi_loader/efi_gop.c index 4593975be5a..3abb47d610e 100644 --- a/lib/efi_loader/efi_gop.c +++ b/lib/efi_loader/efi_gop.c @@ -26,6 +26,7 @@ static const efi_guid_t efi_gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID; * @ops: graphical output protocol interface * @info: graphical output mode information * @mode: graphical output mode + * @vdev: backing video device * @bpix: bits per pixel * @fb: frame buffer */ @@ -34,6 +35,7 @@ struct efi_gop_obj { struct efi_gop ops; struct efi_gop_mode_info info; struct efi_gop_mode mode; + struct udevice *vdev; /* Fields we only have access to during init */ u32 bpix; void *fb; @@ -122,6 +124,7 @@ static __always_inline efi_status_t gop_blt_int(struct efi_gop *this, u32 *fb32 = gopobj->fb; u16 *fb16 = gopobj->fb; struct efi_gop_pixel *buffer = __builtin_assume_aligned(bufferp, 4); + bool blt_to_video = (operation != EFI_BLT_VIDEO_TO_BLT_BUFFER); if (delta) { /* Check for 4 byte alignment */ @@ -245,6 +248,9 @@ static __always_inline efi_status_t gop_blt_int(struct efi_gop *this, dlineoff += dwidth; } + if (blt_to_video) + video_damage(gopobj->vdev, dx, dy, width, height); + return EFI_SUCCESS; } @@ -551,6 +557,7 @@ efi_status_t efi_gop_register(void) gopobj->info.pixels_per_scanline = col; gopobj->bpix = bpix; gopobj->fb = map_sysmem(fb_base, fb_size); + gopobj->vdev = vdev; return EFI_SUCCESS; } diff --git a/lib/efi_loader/efi_helper.c b/lib/efi_loader/efi_helper.c index 8c32059edda..44b806aadc4 100644 --- a/lib/efi_loader/efi_helper.c +++ b/lib/efi_loader/efi_helper.c @@ -7,6 +7,7 @@ #include <blkmap.h> #include <bootm.h> +#include <efi_device_path.h> #include <env.h> #include <image.h> #include <log.h> @@ -199,7 +200,7 @@ efi_status_t efi_load_option_dp_join(struct efi_device_path **dp, efi_free_pool(tmp_dp); if (!*dp) return EFI_OUT_OF_RESOURCES; - *dp_size += efi_dp_size(initrd_dp) + sizeof(END); + *dp_size += efi_dp_size(initrd_dp) + sizeof(EFI_DP_END); } if (fdt_dp) { @@ -209,10 +210,10 @@ efi_status_t efi_load_option_dp_join(struct efi_device_path **dp, efi_free_pool(tmp_dp); if (!*dp) return EFI_OUT_OF_RESOURCES; - *dp_size += efi_dp_size(fdt_dp) + sizeof(END); + *dp_size += efi_dp_size(fdt_dp) + sizeof(EFI_DP_END); } - *dp_size += sizeof(END); + *dp_size += sizeof(EFI_DP_END); return EFI_SUCCESS; } @@ -485,7 +486,7 @@ static efi_status_t copy_fdt(void **fdtp) * needs to be expanded later. */ fdt = *fdtp; - fdt_pages = efi_size_in_pages(fdt_totalsize(fdt) + 0x3000); + fdt_pages = efi_size_in_pages(fdt_totalsize(fdt) + CONFIG_SYS_FDT_PAD); fdt_size = fdt_pages << EFI_PAGE_SHIFT; ret = efi_allocate_pages(EFI_ALLOCATE_ANY_PAGES, @@ -623,6 +624,35 @@ efi_status_t efi_install_fdt(void *fdt) } /** + * efi_install_initrd() - install initrd + * + * Install the initrd located at @initrd using the EFI_LOAD_FILE2 + * protocol. + * + * @initrd: address of initrd or NULL if none is provided + * @initrd_sz: size of initrd + * Return: status code + */ +efi_status_t efi_install_initrd(void *initrd, size_t initd_sz) +{ + efi_status_t ret; + struct efi_device_path *dp_initrd; + + if (!initrd) + return EFI_SUCCESS; + + dp_initrd = efi_dp_from_mem(EFI_LOADER_DATA, (uintptr_t)initrd, initd_sz); + if (!dp_initrd) + return EFI_OUT_OF_RESOURCES; + + ret = efi_initrd_register(dp_initrd); + if (ret != EFI_SUCCESS) + efi_free_pool(dp_initrd); + + return ret; +} + +/** * do_bootefi_exec() - execute EFI binary * * The image indicated by @handle is started. When it returns the allocated diff --git a/lib/efi_loader/efi_hii.c b/lib/efi_loader/efi_hii.c index 44235970a7c..330d7c5830b 100644 --- a/lib/efi_loader/efi_hii.c +++ b/lib/efi_loader/efi_hii.c @@ -343,6 +343,9 @@ static struct efi_hii_packagelist *new_packagelist(void) struct efi_hii_packagelist *hii; hii = malloc(sizeof(*hii)); + if (!hii) + return NULL; + list_add_tail(&hii->link, &efi_package_lists); hii->max_string_id = 0; INIT_LIST_HEAD(&hii->string_tables); diff --git a/lib/efi_loader/efi_hii_config.c b/lib/efi_loader/efi_hii_config.c index 37d8c6629e2..521481a86d8 100644 --- a/lib/efi_loader/efi_hii_config.c +++ b/lib/efi_loader/efi_hii_config.c @@ -4,10 +4,6 @@ * * Copyright (c) 2017 Leif Lindholm * Copyright (c) 2018 AKASHI Takahiro, Linaro Limited - * - * As this is still a non-working stub and the protocol is neither required - * by the EFI shell nor by the UEFI SCT this module has been removed from - * the Makefile. */ #define LOG_CATEGORY LOGC_EFI diff --git a/lib/efi_loader/efi_load_initrd.c b/lib/efi_loader/efi_load_initrd.c index fb8cc7bcbe3..b5d58943a80 100644 --- a/lib/efi_loader/efi_load_initrd.c +++ b/lib/efi_loader/efi_load_initrd.c @@ -42,6 +42,7 @@ static const struct efi_lo_dp_prefix dp_lf2_handle = { }; static efi_handle_t efi_initrd_handle; +static struct efi_device_path *efi_initrd_dp; /** * get_initrd_fp() - Get initrd device path from a FilePathList device path @@ -73,6 +74,41 @@ static efi_status_t get_initrd_fp(struct efi_device_path **initrd_fp) } /** + * efi_initrd_from_mem() - load initial RAM disk from memory + * + * This function copies the initrd from the memory mapped device + * path pointed to by efi_initrd_dp + * + * @buffer_size: size of allocated buffer + * @buffer: buffer to load the file + * + * Return: status code + */ +static efi_status_t efi_initrd_from_mem(efi_uintn_t *buffer_size, void *buffer) +{ + efi_status_t ret = EFI_NOT_FOUND; + efi_uintn_t bs; + struct efi_device_path_memory *mdp; + + mdp = (struct efi_device_path_memory *)efi_initrd_dp; + if (!mdp) + return ret; + + bs = mdp->end_address - mdp->start_address; + + if (!buffer || *buffer_size < bs) { + ret = EFI_BUFFER_TOO_SMALL; + *buffer_size = bs; + } else { + memcpy(buffer, (void *)(uintptr_t)mdp->start_address, bs); + *buffer_size = bs; + ret = EFI_SUCCESS; + } + + return ret; +} + +/** * efi_load_file2_initrd() - load initial RAM disk * * This function implements the LoadFile service of the EFI_LOAD_FILE2_PROTOCOL @@ -118,6 +154,9 @@ efi_load_file2_initrd(struct efi_load_file_protocol *this, goto out; } + if (efi_initrd_dp) + return EFI_EXIT(efi_initrd_from_mem(buffer_size, buffer)); + ret = get_initrd_fp(&initrd_fp); if (ret != EFI_SUCCESS) goto out; @@ -209,6 +248,9 @@ efi_status_t efi_initrd_deregister(void) NULL); efi_initrd_handle = NULL; + efi_free_pool(efi_initrd_dp); + efi_initrd_dp = NULL; + return ret; } @@ -234,24 +276,31 @@ static void EFIAPI efi_initrd_return_notify(struct efi_event *event, * This function creates a new handle and installs a Linux specific vendor * device path and an EFI_LOAD_FILE2_PROTOCOL. Linux uses the device path * to identify the handle and then calls the LoadFile service of the - * EFI_LOAD_FILE2_PROTOCOL to read the initial RAM disk. + * EFI_LOAD_FILE2_PROTOCOL to read the initial RAM disk. If dp_initrd is + * not provided, the initrd will be taken from the BootCurrent variable + * + * @dp_initrd: optional device path containing an initrd * * Return: status code */ -efi_status_t efi_initrd_register(void) +efi_status_t efi_initrd_register(struct efi_device_path *dp_initrd) { efi_status_t ret; struct efi_event *event; - /* - * Allow the user to continue if Boot#### file path is not set for - * an initrd - */ - ret = check_initrd(); - if (ret == EFI_INVALID_PARAMETER) - return EFI_SUCCESS; - if (ret != EFI_SUCCESS) - return ret; + if (dp_initrd) { + efi_initrd_dp = dp_initrd; + } else { + /* + * Allow the user to continue if Boot#### file path is not set for + * an initrd + */ + ret = check_initrd(); + if (ret == EFI_INVALID_PARAMETER) + return EFI_SUCCESS; + if (ret != EFI_SUCCESS) + return ret; + } ret = efi_install_multiple_protocol_interfaces(&efi_initrd_handle, /* initramfs */ diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c index 0abb1f6159a..0828a47da61 100644 --- a/lib/efi_loader/efi_memory.c +++ b/lib/efi_loader/efi_memory.c @@ -454,6 +454,7 @@ efi_status_t efi_allocate_pages(enum efi_allocate_type type, enum efi_memory_type memory_type, efi_uintn_t pages, uint64_t *memory) { + int err; u64 efi_addr, len; uint flags; efi_status_t ret; @@ -475,17 +476,18 @@ efi_status_t efi_allocate_pages(enum efi_allocate_type type, switch (type) { case EFI_ALLOCATE_ANY_PAGES: /* Any page */ - addr = (u64)lmb_alloc_base(len, EFI_PAGE_SIZE, - LMB_ALLOC_ANYWHERE, flags); - if (!addr) + err = lmb_alloc_mem(LMB_MEM_ALLOC_ANY, EFI_PAGE_SIZE, &addr, + len, flags); + if (err) return EFI_OUT_OF_RESOURCES; break; case EFI_ALLOCATE_MAX_ADDRESS: /* Max address */ addr = map_to_sysmem((void *)(uintptr_t)*memory); - addr = (u64)lmb_alloc_base(len, EFI_PAGE_SIZE, addr, - flags); - if (!addr) + + err = lmb_alloc_mem(LMB_MEM_ALLOC_MAX, EFI_PAGE_SIZE, &addr, + len, flags); + if (err) return EFI_OUT_OF_RESOURCES; break; case EFI_ALLOCATE_ADDRESS: @@ -493,7 +495,7 @@ efi_status_t efi_allocate_pages(enum efi_allocate_type type, return EFI_NOT_FOUND; addr = map_to_sysmem((void *)(uintptr_t)*memory); - if (lmb_alloc_addr(addr, len, flags)) + if (lmb_alloc_mem(LMB_MEM_ALLOC_ADDR, 0, &addr, len, flags)) return EFI_NOT_FOUND; break; default: @@ -506,7 +508,7 @@ efi_status_t efi_allocate_pages(enum efi_allocate_type type, ret = efi_update_memory_map(efi_addr, pages, memory_type, true, false); if (ret != EFI_SUCCESS) { /* Map would overlap, bail out */ - lmb_free_flags(addr, (u64)pages << EFI_PAGE_SHIFT, flags); + lmb_free(addr, (u64)pages << EFI_PAGE_SHIFT, flags); unmap_sysmem((void *)(uintptr_t)efi_addr); return EFI_OUT_OF_RESOURCES; } @@ -546,8 +548,8 @@ efi_status_t efi_free_pages(uint64_t memory, efi_uintn_t pages) * been mapped with map_sysmem() from efi_allocate_pages(). Convert * it back to an address LMB understands */ - status = lmb_free_flags(map_to_sysmem((void *)(uintptr_t)memory), len, - LMB_NOOVERWRITE); + status = lmb_free(map_to_sysmem((void *)(uintptr_t)memory), len, + LMB_NOOVERWRITE); if (status) return EFI_NOT_FOUND; diff --git a/lib/efi_loader/efi_net.c b/lib/efi_loader/efi_net.c index b3291b4f1d5..86f0af9538c 100644 --- a/lib/efi_loader/efi_net.c +++ b/lib/efi_loader/efi_net.c @@ -17,7 +17,9 @@ #define LOG_CATEGORY LOGC_EFI +#include <efi_device_path.h> #include <efi_loader.h> +#include <env.h> #include <dm.h> #include <linux/sizes.h> #include <malloc.h> @@ -51,7 +53,7 @@ static int next_dp_entry; static struct wget_http_info efi_wget_info = { .set_bootdev = false, .check_buffer_size = true, - + .silent = true, }; #endif diff --git a/lib/efi_loader/efi_root_node.c b/lib/efi_loader/efi_root_node.c index 74225edad29..e5246f65df2 100644 --- a/lib/efi_loader/efi_root_node.c +++ b/lib/efi_loader/efi_root_node.c @@ -80,6 +80,9 @@ efi_status_t efi_root_node_register(void) /* HII database protocol */ &efi_guid_hii_database_protocol, &efi_hii_database, + /* EFI HII Configuration Routing Protocol */ + &efi_guid_hii_config_routing_protocol, + &efi_hii_config_routing, #endif NULL); efi_root->type = EFI_OBJECT_TYPE_U_BOOT_FIRMWARE; diff --git a/lib/efi_loader/efi_tcg2.c b/lib/efi_loader/efi_tcg2.c index 210a846ebc8..1832eeb5dce 100644 --- a/lib/efi_loader/efi_tcg2.c +++ b/lib/efi_loader/efi_tcg2.c @@ -10,6 +10,7 @@ #define LOG_CATEGORY LOGC_EFI #include <dm.h> +#include <efi_device_path.h> #include <efi_loader.h> #include <efi_variable.h> #include <efi_tcg2.h> |