From 709292a63afc60bc840493315acf18c6c5e27eb4 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Thu, 26 Sep 2019 21:40:18 +0200 Subject: efi_loader: appending to non-existent variable Appending to a non-existent variable must result in an error of type EFI_NOT_FOUND. Fixes: 09c76b79a9db ("efi_loader: SetVariable() deleting variables") Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_variable.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c index 4c554c546b2..d0daf7bdebb 100644 --- a/lib/efi_loader/efi_variable.c +++ b/lib/efi_loader/efi_variable.c @@ -478,10 +478,12 @@ efi_status_t EFIAPI efi_set_variable(u16 *variable_name, old_size = 0; } } else { - if ((data_size == 0 && - !(attributes & EFI_VARIABLE_APPEND_WRITE)) || - !attributes) { - /* delete, but nothing to do */ + if (data_size == 0 || !attributes || + (attributes & EFI_VARIABLE_APPEND_WRITE)) { + /* + * Trying to delete or to update a non-existent + * variable. + */ ret = EFI_NOT_FOUND; goto out; } -- cgit v1.2.3 From c9dd62f9c243f48b0facc5ce252041ccb7a06362 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Thu, 26 Sep 2019 21:35:20 +0200 Subject: efi_selftest: correct SetVariable() test Errors should not only be announced as text but should also result in EFI_ST_FAILURE being returned. Signed-off-by: Heinrich Schuchardt --- lib/efi_selftest/efi_selftest_variables.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/lib/efi_selftest/efi_selftest_variables.c b/lib/efi_selftest/efi_selftest_variables.c index a6b41d1f008..02c9d30a3d4 100644 --- a/lib/efi_selftest/efi_selftest_variables.c +++ b/lib/efi_selftest/efi_selftest_variables.c @@ -120,27 +120,29 @@ static int execute(void) 7, v + 8); if (ret != EFI_SUCCESS) { efi_st_error("SetVariable(APPEND_WRITE) failed\n"); - } else { - len = EFI_ST_MAX_DATA_SIZE; - ret = runtime->get_variable(L"efi_st_var1", &guid_vendor1, - &attr, &len, data); - if (ret != EFI_SUCCESS) { - efi_st_error("GetVariable failed\n"); - return EFI_ST_FAILURE; - } - if (len != 15) - efi_st_todo("GetVariable returned wrong length %u\n", - (unsigned int)len); - if (memcmp(data, v, len)) - efi_st_todo("GetVariable returned wrong value\n"); + return EFI_ST_FAILURE; + } + len = EFI_ST_MAX_DATA_SIZE; + ret = runtime->get_variable(L"efi_st_var1", &guid_vendor1, + &attr, &len, data); + if (ret != EFI_SUCCESS) { + efi_st_error("GetVariable failed\n"); + return EFI_ST_FAILURE; } + if (len != 15) + efi_st_todo("GetVariable returned wrong length %u\n", + (unsigned int)len); + if (memcmp(data, v, len)) + efi_st_todo("GetVariable returned wrong value\n"); /* Append variable 2 */ ret = runtime->set_variable(L"efi_none", &guid_vendor1, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_APPEND_WRITE, 15, v); - if (ret != EFI_NOT_FOUND) + if (ret != EFI_NOT_FOUND) { efi_st_error("SetVariable(APPEND_WRITE) with size 0 to non-existent variable returns wrong code\n"); + return EFI_ST_FAILURE; + } /* Append variable 3 */ ret = runtime->set_variable(L"PlatformLangCodes", &guid_global, EFI_VARIABLE_BOOTSERVICE_ACCESS | -- cgit v1.2.3 From 1b7313d91fc6f52368abba409646683410e7bd41 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Thu, 26 Sep 2019 22:10:25 +0200 Subject: efi_selftest: testing read-only variables The UEFI spec has this sentence: "Variables that have runtime access but that are not nonvolatile are read-only data variables once ExitBootServices() is performed." At least EDK2 therefore treats variable PlatformLangCodes only as read-only at runtime. Nowhere do we make this variable read-only in U-Boot. Do not use variable PlatformLangCodes for testing if the read only attribute of variables is observed before ExitBootServices(). Fixes: 5a24239c951e ("efi_loader: selftest: enable APPEND_WRITE tests") Signed-off-by: Heinrich Schuchardt --- lib/efi_selftest/efi_selftest_variables.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/lib/efi_selftest/efi_selftest_variables.c b/lib/efi_selftest/efi_selftest_variables.c index 02c9d30a3d4..5d98c029b86 100644 --- a/lib/efi_selftest/efi_selftest_variables.c +++ b/lib/efi_selftest/efi_selftest_variables.c @@ -21,9 +21,6 @@ static const efi_guid_t guid_vendor0 = static const efi_guid_t guid_vendor1 = EFI_GUID(0xff629290, 0x1fc1, 0xd73f, 0x8f, 0xb1, 0x32, 0xf9, 0x0c, 0xa0, 0x42, 0xea); -static const efi_guid_t guid_global = - EFI_GUID(0x8be4df61, 0x93ca, 0x11d2, - 0xaa, 0x0d, 0x00, 0xe0, 0x98, 0x03, 0x2b, 0x8c); /* * Setup unit test. @@ -143,14 +140,6 @@ static int execute(void) efi_st_error("SetVariable(APPEND_WRITE) with size 0 to non-existent variable returns wrong code\n"); return EFI_ST_FAILURE; } - /* Append variable 3 */ - ret = runtime->set_variable(L"PlatformLangCodes", &guid_global, - EFI_VARIABLE_BOOTSERVICE_ACCESS | - EFI_VARIABLE_RUNTIME_ACCESS | - EFI_VARIABLE_APPEND_WRITE, - 15, v); - if (ret != EFI_WRITE_PROTECTED) - efi_st_todo("SetVariable(APPEND_WRITE) to read-only variable returns wrong code\n"); /* Enumerate variables */ boottime->set_mem(&guid, 16, 0); *varname = 0; -- cgit v1.2.3 From e5d8971bfda1f0d224ebf00118b20e0a294c7732 Mon Sep 17 00:00:00 2001 From: Mian Yousaf Kaukab Date: Tue, 24 Sep 2019 17:10:24 +0200 Subject: Revert "ARM: tegra: reserve unmapped RAM so EFI doesn't use it" This reverts commit 0797f7f0b7e1d7853e2842ddc235ffef139fa792. Tegra specific solution is not required any more as efi core has been made aware of ram_top with the following commit: 7b78d6438a efi_loader: Reserve unaccessible memory Signed-off-by: Mian Yousaf Kaukab --- arch/arm/mach-tegra/board2.c | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/arch/arm/mach-tegra/board2.c b/arch/arm/mach-tegra/board2.c index f13bd256cc2..07f54f06848 100644 --- a/arch/arm/mach-tegra/board2.c +++ b/arch/arm/mach-tegra/board2.c @@ -6,7 +6,6 @@ #include #include -#include #include #include #include @@ -224,19 +223,6 @@ int board_early_init_f(void) int board_late_init(void) { -#if CONFIG_IS_ENABLED(EFI_LOADER) - if (gd->bd->bi_dram[1].start) { - /* - * Only bank 0 is below board_get_usable_ram_top(), so all of - * bank 1 is not mapped by the U-Boot MMU configuration, and so - * we must prevent EFI from using it. - */ - efi_add_memory_map(gd->bd->bi_dram[1].start, - gd->bd->bi_dram[1].size >> EFI_PAGE_SHIFT, - EFI_BOOT_SERVICES_DATA, false); - } -#endif - #if defined(CONFIG_TEGRA_SUPPORT_NON_SECURE) if (tegra_cpu_is_non_secure()) { printf("CPU is in NS mode\n"); -- cgit v1.2.3 From 6810caf856ba68e124e4f8f9a522996a45f5232d Mon Sep 17 00:00:00 2001 From: AKASHI Takahiro Date: Fri, 4 Oct 2019 13:46:25 +0900 Subject: cmd: env: fix a typo in a comment of do_env_set_efi() A wrong function name is referred to in a comment of do_env_set_efi(). Signed-off-by: AKASHI Takahiro Reviewed-by: Heinrich Schuchardt --- cmd/nvedit_efi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/nvedit_efi.c b/cmd/nvedit_efi.c index ed6d09a5304..ede4cd5235e 100644 --- a/cmd/nvedit_efi.c +++ b/cmd/nvedit_efi.c @@ -330,7 +330,7 @@ out: } /** - * do_env_print_efi() - set UEFI variable + * do_env_set_efi() - set UEFI variable * * @cmdtp: Command table * @flag: Command flag -- cgit v1.2.3 From c50b2883dfc1ce355dc37238741ef97cd2c5d000 Mon Sep 17 00:00:00 2001 From: Patrick Wildt Date: Thu, 3 Oct 2019 13:48:47 +0200 Subject: nvme: add accessor to namespace id and eui64 This adds a function which can be used by e.g. EFI to retrieve the namespace identifier and EUI64. For that it adds the EUI64 to its driver internal namespace structure and copies the EUI64 during namespace identification. Signed-off-by: Patrick Wildt Tested-by: Heinrich Schuchardt Reviewed-by: Bin Meng --- drivers/nvme/nvme.c | 13 +++++++++++++ drivers/nvme/nvme.h | 1 + include/nvme.h | 12 ++++++++++++ 3 files changed, 26 insertions(+) diff --git a/drivers/nvme/nvme.c b/drivers/nvme/nvme.c index 47f101e2808..ee6b581d9e1 100644 --- a/drivers/nvme/nvme.c +++ b/drivers/nvme/nvme.c @@ -621,6 +621,18 @@ static int nvme_get_info_from_identify(struct nvme_dev *dev) return 0; } +int nvme_get_namespace_id(struct udevice *udev, u32 *ns_id, u8 *eui64) +{ + struct nvme_ns *ns = dev_get_priv(udev); + + if (ns_id) + *ns_id = ns->ns_id; + if (eui64) + memcpy(eui64, ns->eui64, sizeof(ns->eui64)); + + return 0; +} + int nvme_scan_namespace(void) { struct uclass *uc; @@ -657,6 +669,7 @@ static int nvme_blk_probe(struct udevice *udev) if (nvme_identify(ndev, ns->ns_id, 0, (dma_addr_t)(long)id)) return -EIO; + memcpy(&ns->eui64, &id->eui64, sizeof(id->eui64)); flbas = id->flbas & NVME_NS_FLBAS_LBA_MASK; ns->flbas = flbas; ns->lba_shift = id->lbaf[flbas].ds; diff --git a/drivers/nvme/nvme.h b/drivers/nvme/nvme.h index 922f7abfe85..0e8cb221a7a 100644 --- a/drivers/nvme/nvme.h +++ b/drivers/nvme/nvme.h @@ -637,6 +637,7 @@ struct nvme_ns { struct list_head list; struct nvme_dev *dev; unsigned ns_id; + u8 eui64[8]; int devnum; int lba_shift; u8 flbas; diff --git a/include/nvme.h b/include/nvme.h index 2c3d14d2418..2cdf8ce320c 100644 --- a/include/nvme.h +++ b/include/nvme.h @@ -78,4 +78,16 @@ int nvme_scan_namespace(void); */ int nvme_print_info(struct udevice *udev); +/** + * nvme_get_namespace_id - return namespace identifier + * + * This returns the namespace identifier. + * + * @udev: NVMe controller device + * @ns_id: Place where to put the name space identifier + * @eui64: Place where to put the IEEE Extended Unique Identifier + * @return: 0 on success, -ve on error + */ +int nvme_get_namespace_id(struct udevice *udev, u32 *ns_id, u8 *eui64); + #endif /* __NVME_H__ */ -- cgit v1.2.3 From f2d247df506eaf984f26ec03baf115d70bd75b9c Mon Sep 17 00:00:00 2001 From: Patrick Wildt Date: Thu, 3 Oct 2019 16:24:17 +0200 Subject: efi: device path for nvme This allows our EFI API to create a device path node for NVMe devices. It adds the necessary device path struct, uses the nvme namespace accessor to retrieve the id and eui64, and also provides support for the device path text protocol. Signed-off-by: Patrick Wildt Tested-by: Heinrich Schuchardt Reviewed-by: Heinrich Schuchardt --- include/efi_api.h | 7 +++++++ lib/efi_loader/efi_device_path.c | 20 ++++++++++++++++++++ lib/efi_loader/efi_device_path_to_text.c | 15 +++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/include/efi_api.h b/include/efi_api.h index 37e56da4603..22396172e15 100644 --- a/include/efi_api.h +++ b/include/efi_api.h @@ -422,6 +422,7 @@ struct efi_device_path_acpi_path { # define DEVICE_PATH_SUB_TYPE_MSG_USB 0x05 # define DEVICE_PATH_SUB_TYPE_MSG_MAC_ADDR 0x0b # define DEVICE_PATH_SUB_TYPE_MSG_USB_CLASS 0x0f +# define DEVICE_PATH_SUB_TYPE_MSG_NVME 0x17 # define DEVICE_PATH_SUB_TYPE_MSG_SD 0x1a # define DEVICE_PATH_SUB_TYPE_MSG_MMC 0x1d @@ -464,6 +465,12 @@ struct efi_device_path_sd_mmc_path { u8 slot_number; } __packed; +struct efi_device_path_nvme { + struct efi_device_path dp; + u32 ns_id; + u8 eui64[8]; +} __packed; + #define DEVICE_PATH_TYPE_MEDIA_DEVICE 0x04 # define DEVICE_PATH_SUB_TYPE_HARD_DRIVE_PATH 0x01 # define DEVICE_PATH_SUB_TYPE_CDROM_PATH 0x02 diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c index 86297bb7c11..897fc1b2e8a 100644 --- a/lib/efi_loader/efi_device_path.c +++ b/lib/efi_loader/efi_device_path.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -451,6 +452,11 @@ static unsigned dp_size(struct udevice *dev) return dp_size(dev->parent) + sizeof(struct efi_device_path_sd_mmc_path); #endif +#if defined(CONFIG_NVME) + case UCLASS_NVME: + return dp_size(dev->parent) + + sizeof(struct efi_device_path_nvme); +#endif #ifdef CONFIG_SANDBOX case UCLASS_ROOT: /* @@ -583,6 +589,20 @@ static void *dp_fill(void *buf, struct udevice *dev) sddp->slot_number = dev->seq; return &sddp[1]; } +#endif +#if defined(CONFIG_NVME) + case UCLASS_NVME: { + struct efi_device_path_nvme *dp = + dp_fill(buf, dev->parent); + u32 ns_id; + + dp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE; + dp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_NVME; + dp->dp.length = sizeof(*dp); + nvme_get_namespace_id(dev, &ns_id, dp->eui64); + memcpy(&dp->ns_id, &ns_id, sizeof(ns_id)); + return &dp[1]; + } #endif default: debug("%s(%u) %s: unhandled parent class: %s (%u)\n", diff --git a/lib/efi_loader/efi_device_path_to_text.c b/lib/efi_loader/efi_device_path_to_text.c index 0f3796b373b..af1adbb71ef 100644 --- a/lib/efi_loader/efi_device_path_to_text.c +++ b/lib/efi_loader/efi_device_path_to_text.c @@ -148,6 +148,21 @@ static char *dp_msging(char *s, struct efi_device_path *dp) break; } + case DEVICE_PATH_SUB_TYPE_MSG_NVME: { + struct efi_device_path_nvme *ndp = + (struct efi_device_path_nvme *)dp; + u32 ns_id; + int i; + + memcpy(&ns_id, &ndp->ns_id, sizeof(ns_id)); + s += sprintf(s, "NVMe(0x%x,", ns_id); + for (i = 0; i < sizeof(ndp->eui64); ++i) + s += sprintf(s, "%s%02x", i ? "-" : "", + ndp->eui64[i]); + s += sprintf(s, ")"); + + break; + } case DEVICE_PATH_SUB_TYPE_MSG_SD: case DEVICE_PATH_SUB_TYPE_MSG_MMC: { const char *typename = -- cgit v1.2.3 From 3b728f8728fa7c596d30ecd27ebb64d37a54a12e Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sun, 6 Oct 2019 15:44:22 +0200 Subject: cmd: disable CMD_NVEDIT_EFI by default The growth of the UEFI sub-system leads to build failures for systems with strict limits on the U-Boot image size. CMD_NVEDIT_EFI supports displaying and editing of UEFI variables. The setting is not needed for booting. Disabling it by default reduces the size of the U-Boot image by 2 KiB. Signed-off-by: Heinrich Schuchardt --- cmd/Kconfig | 1 - 1 file changed, 1 deletion(-) diff --git a/cmd/Kconfig b/cmd/Kconfig index 4e61565aab1..8e55b34c961 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -531,7 +531,6 @@ config CMD_ENV_FLAGS config CMD_NVEDIT_EFI bool "env [set|print] -e - set/print UEFI variables" depends on EFI_LOADER - default y imply HEXDUMP help UEFI variables are encoded as some form of U-Boot variables. -- cgit v1.2.3