From 7891fe675d03f2407b040c472ae76050bc88c24e Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Thu, 10 Jun 2021 23:10:52 +0200 Subject: [PATCH 01/19] efi_loader: TPL_HIGH_LEVEL not allowed for CreateEvent According to chapter 7.1 "Event, Timer, and Task Priority Services" TPL_HIGH_LEVEL should not be exposed to applications and drivers. According to the discussion with EDK II contributors this implies that CreateEvent() shall not allow to create events with TPL_HIGH_LEVEL. Cc: Samer El-Haj-Mahmoud Signed-off-by: Heinrich Schuchardt Acked-by: Samer El-Haj-Mahmoud --- lib/efi_loader/efi_boottime.c | 1 - lib/efi_selftest/efi_selftest_tpl.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index 4777b35fd4..f6d5ba05e3 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -264,7 +264,6 @@ efi_status_t is_valid_tpl(efi_uintn_t tpl) case TPL_APPLICATION: case TPL_CALLBACK: case TPL_NOTIFY: - case TPL_HIGH_LEVEL: return EFI_SUCCESS; default: return EFI_INVALID_PARAMETER; diff --git a/lib/efi_selftest/efi_selftest_tpl.c b/lib/efi_selftest/efi_selftest_tpl.c index 70a355eae6..0c0e412ae2 100644 --- a/lib/efi_selftest/efi_selftest_tpl.c +++ b/lib/efi_selftest/efi_selftest_tpl.c @@ -55,7 +55,7 @@ static int setup(const efi_handle_t handle, return EFI_ST_FAILURE; } ret = boottime->create_event(EVT_TIMER | EVT_NOTIFY_WAIT, - TPL_HIGH_LEVEL, notify, NULL, &event_wait); + TPL_NOTIFY, notify, NULL, &event_wait); if (ret != EFI_SUCCESS) { efi_st_error("could not create event\n"); return EFI_ST_FAILURE; From 2b8723c5a11f03f152972b2879447b9a77c53aac Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sat, 12 Jun 2021 00:01:44 +0200 Subject: [PATCH 02/19] efidebug: correct display of BootOrder Display the number of the boot option and not its index. Fixes: 2ecee31017bf ("efi_loader: use efi_create_indexed_name()") Signed-off-by: Heinrich Schuchardt --- cmd/efidebug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/efidebug.c b/cmd/efidebug.c index c6352719dd..8211a589ac 100644 --- a/cmd/efidebug.c +++ b/cmd/efidebug.c @@ -1340,7 +1340,7 @@ static int show_efi_boot_order(void) num = size / sizeof(u16); for (i = 0; i < num; i++) { efi_create_indexed_name(var_name16, sizeof(var_name16), - "Boot", i); + "Boot", bootorder[i]); size = 0; ret = EFI_CALL(efi_get_variable(var_name16, From 8c6532d7c44d826b4fe0e0c9a571a335054386b8 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Thu, 10 Jun 2021 12:13:52 +0200 Subject: [PATCH 03/19] smbios: convert function descriptions to Sphinx style Use 'Return:' instead of '@return:'. Signed-off-by: Heinrich Schuchardt --- lib/smbios.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/smbios.c b/lib/smbios.c index 9eb226ec9f..26df2bf123 100644 --- a/lib/smbios.c +++ b/lib/smbios.c @@ -47,7 +47,7 @@ struct smbios_ctx { * @addr: start address to write the structure * @handle: the structure's handle, a unique 16-bit number * @ctx: context for writing the tables - * @return: size of the structure + * Return: size of the structure */ typedef int (*smbios_write_type)(ulong *addr, int handle, struct smbios_ctx *ctx); @@ -72,7 +72,7 @@ struct smbios_write_method { * * @ctx: SMBIOS context * @str: string to add - * @return: string number in the string area (1 or more) + * Return: string number in the string area (1 or more) */ static int smbios_add_string(struct smbios_ctx *ctx, const char *str) { @@ -111,7 +111,7 @@ static int smbios_add_string(struct smbios_ctx *ctx, const char *str) * * @ctx: context for writing the tables * @prop: property to write - * @return 0 if not found, else SMBIOS string number (1 or more) + * Return: 0 if not found, else SMBIOS string number (1 or more) */ static int smbios_add_prop_si(struct smbios_ctx *ctx, const char *prop, int sysinfo_id) @@ -139,7 +139,7 @@ static int smbios_add_prop_si(struct smbios_ctx *ctx, const char *prop, * smbios_add_prop() - Add a property from the devicetree * * @prop: property to write - * @return 0 if not found, else SMBIOS string number (1 or more) + * Return: 0 if not found, else SMBIOS string number (1 or more) */ static int smbios_add_prop(struct smbios_ctx *ctx, const char *prop) { @@ -187,7 +187,7 @@ int smbios_update_version(const char *version) * This computes the size of the string area including the string terminator. * * @ctx: SMBIOS context - * @return: string area size + * Return: string area size */ static int smbios_string_table_len(const struct smbios_ctx *ctx) { From a86ed41bff94f90af2e1a8798e20920ef0353e97 Mon Sep 17 00:00:00 2001 From: Adarsh Babu Kalepalli Date: Fri, 11 Jun 2021 19:45:11 +0530 Subject: [PATCH 04/19] doc/usage: cmd-usage help file for askenv help file for using askenv cmd is created. It provides description on the command purpose, description of arguments, couple of examples (illustrating command usage), configuration parameter and possible return values. Signed-off-by: Adarsh Babu Kalepalli Add missing entry in doc/usage/index.rst. Signed-off-by: Heinrich Schuchardt --- doc/usage/askenv.rst | 87 ++++++++++++++++++++++++++++++++++++++++++++ doc/usage/index.rst | 1 + 2 files changed, 88 insertions(+) create mode 100644 doc/usage/askenv.rst diff --git a/doc/usage/askenv.rst b/doc/usage/askenv.rst new file mode 100644 index 0000000000..5c4ca35d4c --- /dev/null +++ b/doc/usage/askenv.rst @@ -0,0 +1,87 @@ +.. SPDX-License-Identifier: GPL-2.0+: + +askenv command +=============== + +Synopsis +-------- + +:: + + askenv name [message] [size] + +Description +----------- + +Display message and get environment variable name of max size characters +from stdin. + +name + name of the environment variable + +message + message is displayed while the command waits for the value to be + entered from stdin.if no message is specified,a default message + "Please enter name:" will be displayed. + +size + maximum number of characters that will be stored in environment + variable name.this is in decimal number format (unlike in + other commands where size values are in hexa-decimal). Default + value of size is 1023 (CONFIG_SYS_CBSIZE - 1). + +Example +------- + +Value of a environment variable env1 without message and size parameters: + +:: + + => askenv env1;echo $? + Please enter 'env1': val1 + 0 + => printenv env1 + env1=val1 + +Value of a environment variable env2 with message and size parameters: + +:: + + => askenv env2 Please type-in a value for env2: 10;echo $? + Please type-in a value for env2: 1234567890123 + 0 + => printenv env2 + env2=1234567890 + +Value of a environment variable env3 with size parameter only: + +:: + + => askenv env3 10;echo $? + Please enter 'env3': val3 + 0 + => printenv env3 + env3=val3 + +Return Value of askenv command, when used without any other arguments: + +:: + + => askenv;echo $? + askenv - get environment variables from stdin + + Usage: + askenv name [message] [size] + - display 'message' and get environment variable 'name' from stdin (max 'size' chars) + 1 + +Configuration +------------- + +The askenv command is only available if CMD_ASKENV=y + +Return value +------------ + +The return value $? is set to 0 (true). +If no other arguments are specified (along with askenv), it is set to 1 (false). diff --git a/doc/usage/index.rst b/doc/usage/index.rst index 843b4371f1..40b796a3a9 100644 --- a/doc/usage/index.rst +++ b/doc/usage/index.rst @@ -17,6 +17,7 @@ Shell commands :maxdepth: 1 addrmap + askenv base bootefi booti From ff192304b69944734a661227c2d00aab5b15cdaf Mon Sep 17 00:00:00 2001 From: Ilias Apalodimas Date: Wed, 9 Jun 2021 18:14:47 +0300 Subject: [PATCH 05/19] smbios: Fix BIOS Characteristics Extension Byte 2 We currently define the EFI support of an SMBIOS table as the third bit of "BIOS Characteristics Extension Byte 1". The latest DMTF spec defines it on "BIOS Characteristics Extension Byte 2". Signed-off-by: Ilias Apalodimas Remove superfluous assignment. Signed-off-by: Heinrich Schuchardt --- include/smbios.h | 2 +- lib/smbios.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/smbios.h b/include/smbios.h index ffeefb4737..fc49fc10b9 100644 --- a/include/smbios.h +++ b/include/smbios.h @@ -60,7 +60,7 @@ struct __packed smbios_entry { #define BIOS_CHARACTERISTICS_SELECTABLE_BOOT (1 << 16) #define BIOS_CHARACTERISTICS_EXT1_ACPI (1 << 0) -#define BIOS_CHARACTERISTICS_EXT1_UEFI (1 << 3) +#define BIOS_CHARACTERISTICS_EXT2_UEFI (1 << 3) #define BIOS_CHARACTERISTICS_EXT2_TARGET (1 << 2) struct __packed smbios_type0 { diff --git a/lib/smbios.c b/lib/smbios.c index 26df2bf123..b69f5e8c48 100644 --- a/lib/smbios.c +++ b/lib/smbios.c @@ -229,9 +229,9 @@ static int smbios_write_type0(ulong *current, int handle, t->bios_characteristics_ext1 = BIOS_CHARACTERISTICS_EXT1_ACPI; #endif #ifdef CONFIG_EFI_LOADER - t->bios_characteristics_ext1 |= BIOS_CHARACTERISTICS_EXT1_UEFI; + t->bios_characteristics_ext2 |= BIOS_CHARACTERISTICS_EXT2_UEFI; #endif - t->bios_characteristics_ext2 = BIOS_CHARACTERISTICS_EXT2_TARGET; + t->bios_characteristics_ext2 |= BIOS_CHARACTERISTICS_EXT2_TARGET; /* bios_major_release has only one byte, so drop century */ t->bios_major_release = U_BOOT_VERSION_NUM % 100; From 70e80666f26a516096f3787e884d42818d8b4087 Mon Sep 17 00:00:00 2001 From: Ilias Apalodimas Date: Thu, 10 Jun 2021 12:33:15 +0300 Subject: [PATCH 06/19] smbios: Fix SMBIOS tables Commit e4f8e543f1a9("smbios: Drop the unused Kconfig options") break SMBIOS tables. The reason is that the patch drops the Kconfig options *after* removing the code using them, but that changes the semantics of the code completely. Prior to the change a non NULL value was used in the 'product' and 'manufacturer ' fields. Chapter 6.2 of the DMTF spec requires Manufacturer and Product Name to be non-null on some of the tables. So let's add sane defaults for Type1/2/3. * Before the patchset: Handle 0x0002, DMI type 2, 14 bytes Base Board Information Manufacturer: Not Specified Product Name: Not Specified Version: Not Specified Serial Number: Not Specified Asset Tag: Not Specified Features: Board is a hosting board Location In Chassis: Not Specified Chassis Handle: 0x0000 Type: Motherboard Invalid entry length (0). DMI table is broken! Stop. * After the patchset: Handle 0x0005, DMI type 32, 11 bytes System Boot Information Status: No errors detected Handle 0x0006, DMI type 127, 4 bytes End Of Table Fixes: e4f8e543f1a9 ("smbios: Drop the unused Kconfig options") Signed-off-by: Ilias Apalodimas --- lib/smbios.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/smbios.c b/lib/smbios.c index b69f5e8c48..b52e125eeb 100644 --- a/lib/smbios.c +++ b/lib/smbios.c @@ -258,7 +258,11 @@ static int smbios_write_type1(ulong *current, int handle, fill_smbios_header(t, SMBIOS_SYSTEM_INFORMATION, len, handle); smbios_set_eos(ctx, t->eos); t->manufacturer = smbios_add_prop(ctx, "manufacturer"); + if (!t->manufacturer) + t->manufacturer = smbios_add_string(ctx, "Unknown"); t->product_name = smbios_add_prop(ctx, "product"); + if (!t->product_name) + t->product_name = smbios_add_string(ctx, "Unknown Product"); t->version = smbios_add_prop_si(ctx, "version", SYSINFO_ID_SMBIOS_SYSTEM_VERSION); if (serial_str) { @@ -288,7 +292,11 @@ static int smbios_write_type2(ulong *current, int handle, fill_smbios_header(t, SMBIOS_BOARD_INFORMATION, len, handle); smbios_set_eos(ctx, t->eos); t->manufacturer = smbios_add_prop(ctx, "manufacturer"); + if (!t->manufacturer) + t->manufacturer = smbios_add_string(ctx, "Unknown"); t->product_name = smbios_add_prop(ctx, "product"); + if (!t->product_name) + t->product_name = smbios_add_string(ctx, "Unknown Product"); t->version = smbios_add_prop_si(ctx, "version", SYSINFO_ID_SMBIOS_BASEBOARD_VERSION); t->asset_tag_number = smbios_add_prop(ctx, "asset-tag"); @@ -313,6 +321,8 @@ static int smbios_write_type3(ulong *current, int handle, fill_smbios_header(t, SMBIOS_SYSTEM_ENCLOSURE, len, handle); smbios_set_eos(ctx, t->eos); t->manufacturer = smbios_add_prop(ctx, "manufacturer"); + if (!t->manufacturer) + t->manufacturer = smbios_add_string(ctx, "Unknown"); t->chassis_type = SMBIOS_ENCLOSURE_DESKTOP; t->bootup_state = SMBIOS_STATE_SAFE; t->power_supply_state = SMBIOS_STATE_SAFE; From e2e95e5e25421fbef499e21bf94a5339701f9a99 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Thu, 10 Jun 2021 14:00:00 +0200 Subject: [PATCH 07/19] spi: Update speed/mode on change The spi_get_bus_and_cs() may be called on the same bus and chipselect with different frequency or mode. This is valid usecase, but the code fails to notify the controller of such a configuration change. Call spi_set_speed_mode() in case bus frequency or bus mode changed to let the controller update the configuration. The problem can easily be triggered using the sspi command: => sspi 0:0@1000 => sspi 0:0@2000 Without this patch, both transfers happen at 1000 Hz. With this patch, the later transfer happens correctly at 2000 Hz. Signed-off-by: Marek Vasut Cc: Jagan Teki Cc: Patrick Delaunay --- drivers/spi/spi-uclass.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c index ee30110b56..d867b27806 100644 --- a/drivers/spi/spi-uclass.c +++ b/drivers/spi/spi-uclass.c @@ -391,6 +391,8 @@ int spi_get_bus_and_cs(int busnum, int cs, int speed, int mode, } else if (ret) { dev_err(bus, "Invalid chip select %d:%d (err=%d)\n", busnum, cs, ret); return ret; + } else if (dev) { + plat = dev_get_parent_plat(dev); } if (!device_active(dev)) { @@ -416,12 +418,22 @@ int spi_get_bus_and_cs(int busnum, int cs, int speed, int mode, goto err; } + /* In case bus frequency or mode changed, update it. */ + if ((speed && bus_data->speed && bus_data->speed != speed) || + (plat && plat->mode != mode)) { + ret = spi_set_speed_mode(bus, speed, mode); + if (ret) + goto err_speed_mode; + } + *busp = bus; *devp = slave; log_debug("%s: bus=%p, slave=%p\n", __func__, bus, *devp); return 0; +err_speed_mode: + spi_release_bus(slave); err: log_debug("%s: Error path, created=%d, device '%s'\n", __func__, created, dev->name); From 4e1903a645453deab5ec5dd1cf4f0061469b99c3 Mon Sep 17 00:00:00 2001 From: Tom Rini Date: Wed, 30 Jun 2021 11:38:52 -0400 Subject: [PATCH 08/19] TEST: USB_HOST not USB Signed-off-by: Tom Rini --- Makefile | 4 ++-- cmd/Kconfig | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 027e31e09e..96d3eaa18a 100644 --- a/Makefile +++ b/Makefile @@ -824,7 +824,7 @@ libs-y += drivers/usb/eth/ libs-$(CONFIG_USB_DEVICE) += drivers/usb/gadget/ libs-$(CONFIG_USB_GADGET) += drivers/usb/gadget/ libs-$(CONFIG_USB_GADGET) += drivers/usb/gadget/udc/ -libs-y += drivers/usb/host/ +libs-$(CONFIG_USB_HOST) += drivers/usb/host/ libs-y += drivers/usb/mtu3/ libs-y += drivers/usb/musb/ libs-y += drivers/usb/musb-new/ @@ -1115,7 +1115,7 @@ ifneq ($(CONFIG_DM),y) @echo >&2 "====================================================" endif $(call deprecated,CONFIG_DM_USB CONFIG_OF_CONTROL CONFIG_BLK,\ - USB,v2019.07,$(CONFIG_USB)) + USB_HOST,v2019.07,$(CONFIG_USB_HOST)) $(call deprecated,CONFIG_DM_PCI,PCI,v2019.07,$(CONFIG_PCI)) $(call deprecated,CONFIG_DM_VIDEO,video,v2019.07,\ $(CONFIG_LCD)$(CONFIG_VIDEO)) diff --git a/cmd/Kconfig b/cmd/Kconfig index a9fb4eead2..a13a68f8f3 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -1322,7 +1322,7 @@ config CMD_UNIVERSE config CMD_USB bool "usb" - depends on USB + depends on USB_HOST select HAVE_BLOCK_DEVICE help USB support. From b7ad721c83fdbeeb71189d5f259c109cb1c38895 Mon Sep 17 00:00:00 2001 From: Tom Rini Date: Wed, 30 Jun 2021 13:09:49 -0400 Subject: [PATCH 09/19] Revert "TEST: USB_HOST not USB" This reverts commit 4e1903a645453deab5ec5dd1cf4f0061469b99c3. This local commit was not intended to be pushed out. Signed-off-by: Tom Rini --- Makefile | 4 ++-- cmd/Kconfig | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 96d3eaa18a..027e31e09e 100644 --- a/Makefile +++ b/Makefile @@ -824,7 +824,7 @@ libs-y += drivers/usb/eth/ libs-$(CONFIG_USB_DEVICE) += drivers/usb/gadget/ libs-$(CONFIG_USB_GADGET) += drivers/usb/gadget/ libs-$(CONFIG_USB_GADGET) += drivers/usb/gadget/udc/ -libs-$(CONFIG_USB_HOST) += drivers/usb/host/ +libs-y += drivers/usb/host/ libs-y += drivers/usb/mtu3/ libs-y += drivers/usb/musb/ libs-y += drivers/usb/musb-new/ @@ -1115,7 +1115,7 @@ ifneq ($(CONFIG_DM),y) @echo >&2 "====================================================" endif $(call deprecated,CONFIG_DM_USB CONFIG_OF_CONTROL CONFIG_BLK,\ - USB_HOST,v2019.07,$(CONFIG_USB_HOST)) + USB,v2019.07,$(CONFIG_USB)) $(call deprecated,CONFIG_DM_PCI,PCI,v2019.07,$(CONFIG_PCI)) $(call deprecated,CONFIG_DM_VIDEO,video,v2019.07,\ $(CONFIG_LCD)$(CONFIG_VIDEO)) diff --git a/cmd/Kconfig b/cmd/Kconfig index a13a68f8f3..a9fb4eead2 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -1322,7 +1322,7 @@ config CMD_UNIVERSE config CMD_USB bool "usb" - depends on USB_HOST + depends on USB select HAVE_BLOCK_DEVICE help USB support. From 3ef772230db077a7122de11d93cfc4ff570fb4a7 Mon Sep 17 00:00:00 2001 From: Masami Hiramatsu Date: Tue, 22 Jun 2021 17:38:51 +0300 Subject: [PATCH 10/19] efi: Fix to use null handle to create new handle for efi_fmp_raw When running the efidebug capsule disk-update command, the efi_fmp_raw protocol installation fails with 2 (EFI_INVALID_PARAMETER) as below. This is because the code passes efi_root instead of the handle local var. => efidebug capsule disk-update EFI: Call: efi_install_multiple_protocol_interfaces( &handle, &efi_guid_firmware_management_protocol, &efi_fmp_fit, NULL) EFI: Entry efi_install_multiple_protocol_interfaces(00000000fbaf5988) EFI: Call: efi_install_protocol_interface( handle, protocol, EFI_NATIVE_INTERFACE, protocol_interface) EFI: Entry efi_install_protocol_interface(00000000fbaf5988, 86c77a67-0b97-4633-a187-49104d0685c7, 0, 00000000fbfa6ee8) EFI: new handle 00000000fbb37520 EFI: Exit: efi_install_protocol_interface: 0 EFI: 0 returned by efi_install_protocol_interface( handle, protocol, EFI_NATIVE_INTERFACE, protocol_interface) EFI: Exit: efi_install_multiple_protocol_interfaces: 0 EFI: 0 returned by efi_install_multiple_protocol_interfaces( &handle, &efi_guid_firmware_management_protocol, &efi_fmp_fit, NULL) EFI: Call: efi_install_multiple_protocol_interfaces( &efi_root, &efi_guid_firmware_management_protocol, &efi_fmp_raw, NULL) EFI: Entry efi_install_multiple_protocol_interfaces(00000000fbfec648) EFI: Call: efi_install_protocol_interface( handle, protocol, EFI_NATIVE_INTERFACE, protocol_interface) EFI: Entry efi_install_protocol_interface(00000000fbfec648, 86c77a67-0b97-4633-a187-49104d0685c7, 0, 00000000fbfa6f18) EFI: handle 00000000fbaf8520 EFI: Exit: efi_install_protocol_interface: 2 EFI: 2 returned by efi_install_protocol_interface( handle, protocol, EFI_NATIVE_INTERFACE, protocol_interface) EFI: Exit: efi_install_multiple_protocol_interfaces: 2 EFI: 2 returned by efi_install_multiple_protocol_interfaces( &efi_root, &efi_guid_firmware_management_protocol, &efi_fmp_raw, NULL) Command failed, result=1 To fix this issue, pass the handle local var which is set NULL right before installing efi_fmp_raw as same as the installing efi_fmp_fit. (In both cases, the local reference to the handle will be just discarded) Signed-off-by: Masami Hiramatsu Signed-off-by: Ilias Apalodimas Reviewed-by: Heinrich Schuchardt --- lib/efi_loader/efi_capsule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_capsule.c index 60309d4a07..cc6ed453ed 100644 --- a/lib/efi_loader/efi_capsule.c +++ b/lib/efi_loader/efi_capsule.c @@ -940,7 +940,7 @@ efi_status_t __weak arch_efi_load_capsule_drivers(void) if (IS_ENABLED(CONFIG_EFI_CAPSULE_FIRMWARE_RAW)) { handle = NULL; ret = EFI_CALL(efi_install_multiple_protocol_interfaces( - &efi_root, + &handle, &efi_guid_firmware_management_protocol, &efi_fmp_raw, NULL)); } From b891ff18f8999c89d00e1a963a4bc07afe3ae061 Mon Sep 17 00:00:00 2001 From: Ilias Apalodimas Date: Tue, 22 Jun 2021 17:38:52 +0300 Subject: [PATCH 11/19] efi_loader: Force a single FMP instance per hardware store Chapter 23 of the EFI spec (rev 2.9) says: "A specific updatable hardware firmware store must be represented by exactly one FMP instance". This is not the case for us, since both of our FMP protocols can be installed at the same time because they are controlled by a single 'dfu_alt_info' env variable. So make the config options depend on each other and allow the user to install one of them at any given time. If we fix the meta-data provided by the 'dfu_alt_info' in the future, to hint about the capsule type (fit or raw) we can revise this and enable both FMPs to be installed, as long as they target different firmware hardware stores Note that we are not using a Kconfig 'choice' on purpose, since we want to allow both of those to be installed and tested in sandbox Signed-off-by: Ilias Apalodimas Reviewed-by: Heinrich Schuchardt --- configs/xilinx_zynqmp_virt_defconfig | 1 - lib/efi_loader/Kconfig | 45 ++++++++++++++-------------- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/configs/xilinx_zynqmp_virt_defconfig b/configs/xilinx_zynqmp_virt_defconfig index b9351d4504..a3d944d94b 100644 --- a/configs/xilinx_zynqmp_virt_defconfig +++ b/configs/xilinx_zynqmp_virt_defconfig @@ -187,5 +187,4 @@ CONFIG_OF_LIBFDT_OVERLAY=y CONFIG_EFI_SET_TIME=y CONFIG_EFI_RUNTIME_UPDATE_CAPSULE=y CONFIG_EFI_CAPSULE_ON_DISK=y -CONFIG_EFI_CAPSULE_FIRMWARE_FIT=y CONFIG_EFI_CAPSULE_FIRMWARE_RAW=y diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig index 6242caceb7..684adfb623 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -161,6 +161,28 @@ config EFI_CAPSULE_FIRMWARE_MANAGEMENT Select this option if you want to enable capsule-based firmware update using Firmware Management Protocol. +config EFI_CAPSULE_FIRMWARE_FIT + bool "FMP driver for FIT images" + depends on FIT + depends on EFI_CAPSULE_FIRMWARE_MANAGEMENT + select UPDATE_FIT + select DFU + select EFI_CAPSULE_FIRMWARE + help + Select this option if you want to enable firmware management protocol + driver for FIT image + +config EFI_CAPSULE_FIRMWARE_RAW + bool "FMP driver for raw images" + depends on EFI_CAPSULE_FIRMWARE_MANAGEMENT + depends on SANDBOX || (!SANDBOX && !EFI_CAPSULE_FIRMWARE_FIT) + select DFU_WRITE_ALT + select DFU + select EFI_CAPSULE_FIRMWARE + help + Select this option if you want to enable firmware management protocol + driver for raw image + config EFI_CAPSULE_AUTHENTICATE bool "Update Capsule authentication" depends on EFI_CAPSULE_FIRMWARE @@ -181,29 +203,6 @@ config EFI_CAPSULE_AUTHENTICATE Select this option if you want to enable capsule authentication -config EFI_CAPSULE_FIRMWARE_FIT - bool "FMP driver for FIT image" - depends on EFI_CAPSULE_FIRMWARE_MANAGEMENT - depends on FIT - select UPDATE_FIT - select DFU - select EFI_CAPSULE_FIRMWARE - default n - help - Select this option if you want to enable firmware management protocol - driver for FIT image - -config EFI_CAPSULE_FIRMWARE_RAW - bool "FMP driver for raw image" - depends on EFI_CAPSULE_FIRMWARE_MANAGEMENT - select DFU - select DFU_WRITE_ALT - select EFI_CAPSULE_FIRMWARE - default n - help - Select this option if you want to enable firmware management protocol - driver for raw image - config EFI_DEVICE_PATH_TO_TEXT bool "Device path to text protocol" default y From 6e0184b86f689045a0acc268e1899ce7757c65d0 Mon Sep 17 00:00:00 2001 From: Ilias Apalodimas Date: Tue, 22 Jun 2021 17:38:53 +0300 Subject: [PATCH 12/19] efi_loader: Always install FMPs We only install FMPs if a CapsuleUpdate is requested. Since we now have an ESRT table which relies on FMPs to build the required information, it makes more sense to unconditionally install them. This will allow userspace applications (e.g fwupd) to make use of the ERST and provide us with files we can use to run CapsuleUpdate on-disk Signed-off-by: Ilias Apalodimas Reviewed-by: Heinrich Schuchardt --- include/efi_loader.h | 1 + lib/efi_loader/efi_capsule.c | 11 +++-------- lib/efi_loader/efi_setup.c | 6 ++++++ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/include/efi_loader.h b/include/efi_loader.h index 0a9c82a257..b81180cfda 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -972,4 +972,5 @@ efi_status_t efi_esrt_register(void); * - error code otherwise. */ efi_status_t efi_esrt_populate(void); +efi_status_t efi_load_capsule_drivers(void); #endif /* _EFI_LOADER_H */ diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_capsule.c index cc6ed453ed..d7136035d8 100644 --- a/lib/efi_loader/efi_capsule.c +++ b/lib/efi_loader/efi_capsule.c @@ -919,13 +919,13 @@ static void efi_capsule_scan_done(void) } /** - * arch_efi_load_capsule_drivers - initialize capsule drivers + * efi_load_capsule_drivers - initialize capsule drivers * - * Architecture or board specific initialization routine + * Generic FMP drivers backed by DFU * * Return: status code */ -efi_status_t __weak arch_efi_load_capsule_drivers(void) +efi_status_t __weak efi_load_capsule_drivers(void) { __maybe_unused efi_handle_t handle; efi_status_t ret = EFI_SUCCESS; @@ -976,11 +976,6 @@ efi_status_t efi_launch_capsules(void) index = get_last_capsule(); - /* Load capsule drivers */ - ret = arch_efi_load_capsule_drivers(); - if (ret != EFI_SUCCESS) - return ret; - /* * Find capsules on disk. * All the capsules are collected at the beginning because diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c index 3c5cf9a435..2dc6ba8337 100644 --- a/lib/efi_loader/efi_setup.c +++ b/lib/efi_loader/efi_setup.c @@ -254,6 +254,12 @@ efi_status_t efi_init_obj_list(void) if (ret != EFI_SUCCESS) goto out; + if (IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT)) { + ret = efi_load_capsule_drivers(); + if (ret != EFI_SUCCESS) + goto out; + } + #if defined(CONFIG_LCD) || defined(CONFIG_DM_VIDEO) ret = efi_gop_register(); if (ret != EFI_SUCCESS) From abd62e4d41112893d70ddcbe7faad887116ed323 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Tue, 29 Jun 2021 10:09:14 +0200 Subject: [PATCH 13/19] efi_loader: missing parentheses in query_console_size After if we should use parentheses to keep the code readable. Fixes: a95f4c885991 ("efi_loader: NULL dereference in EFI console") Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_console.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_console.c b/lib/efi_loader/efi_console.c index 6040f3a99a..3b012e1a66 100644 --- a/lib/efi_loader/efi_console.c +++ b/lib/efi_loader/efi_console.c @@ -342,7 +342,7 @@ static void query_console_size(void) int rows = 25, cols = 80; int ret = -ENODEV; - if IS_ENABLED(CONFIG_DM_VIDEO) + if (IS_ENABLED(CONFIG_DM_VIDEO)) ret = query_vidconsole(&rows, &cols); if (ret) ret = query_console_serial(&rows, &cols); From 417a3c24c9991d3d9df8401063188324bf404952 Mon Sep 17 00:00:00 2001 From: Masami Hiramatsu Date: Thu, 1 Jul 2021 00:49:48 +0900 Subject: [PATCH 14/19] efi_loader: Improve the parameter check for QueryVariableInfo() Improve efi_query_variable_info() to check the parameter settings and return correct error code according to the UEFI Specification 2.9, and the Self Certification Test (SCT) II Case Specification, June 2017, chapter 4.1.4 QueryVariableInfo(). Reported-by: Kazuhiko Sakamoto Signed-off-by: Masami Hiramatsu Reviewed-by: Heinrich Schuchardt --- lib/efi_loader/efi_var_common.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/efi_loader/efi_var_common.c b/lib/efi_loader/efi_var_common.c index 83479dd142..3d92afe2eb 100644 --- a/lib/efi_loader/efi_var_common.c +++ b/lib/efi_loader/efi_var_common.c @@ -163,6 +163,19 @@ efi_status_t EFIAPI efi_query_variable_info( EFI_ENTRY("%x %p %p %p", attributes, maximum_variable_storage_size, remaining_variable_storage_size, maximum_variable_size); + if (!maximum_variable_storage_size || + !remaining_variable_storage_size || + !maximum_variable_size || + !(attributes & EFI_VARIABLE_BOOTSERVICE_ACCESS)) + return EFI_EXIT(EFI_INVALID_PARAMETER); + + if ((attributes & ~(u32)EFI_VARIABLE_MASK) || + (attributes & EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS) || + (attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) || + (!IS_ENABLED(CONFIG_EFI_SECURE_BOOT) && + (attributes & EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS))) + return EFI_EXIT(EFI_UNSUPPORTED); + ret = efi_query_variable_info_int(attributes, maximum_variable_storage_size, remaining_variable_storage_size, From 149108a3eb594b03561073aa6fd512cacab57c62 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Tue, 29 Jun 2021 13:33:09 +0200 Subject: [PATCH 15/19] efi_loader: clear OsIndications After each reboot we must clear flag EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED in variable OsIndications. Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_setup.c | 40 +++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c index 2dc6ba8337..a2338d74af 100644 --- a/lib/efi_loader/efi_setup.c +++ b/lib/efi_loader/efi_setup.c @@ -5,9 +5,12 @@ * Copyright (c) 2016-2018 Alexander Graf et al. */ +#define LOG_CATEGORY LOGC_EFI + #include #include #include +#include #define OBJ_LIST_NOT_INITIALIZED 1 @@ -171,6 +174,37 @@ static efi_status_t efi_init_os_indications(void) &os_indications_supported, false); } + +/** + * efi_clear_os_indications() - clear OsIndications + * + * Clear EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED + */ +static efi_status_t efi_clear_os_indications(void) +{ + efi_uintn_t size; + u64 os_indications; + efi_status_t ret; + + size = sizeof(os_indications); + ret = efi_get_variable_int(L"OsIndications", &efi_global_variable_guid, + NULL, &size, &os_indications, NULL); + if (ret != EFI_SUCCESS) + os_indications = 0; + else + os_indications &= + ~EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED; + ret = efi_set_variable_int(L"OsIndications", &efi_global_variable_guid, + EFI_VARIABLE_NON_VOLATILE | + EFI_VARIABLE_BOOTSERVICE_ACCESS | + EFI_VARIABLE_RUNTIME_ACCESS, + sizeof(os_indications), &os_indications, + false); + if (ret != EFI_SUCCESS) + log_err("Setting %ls failed\n", L"OsIndications"); + return ret; +} + /** * efi_init_obj_list() - Initialize and populate EFI object list * @@ -178,7 +212,7 @@ static efi_status_t efi_init_os_indications(void) */ efi_status_t efi_init_obj_list(void) { - efi_status_t ret = EFI_SUCCESS; + efi_status_t r, ret = EFI_SUCCESS; /* Initialize once only */ if (efi_obj_list_initialized != OBJ_LIST_NOT_INITIALIZED) @@ -297,7 +331,11 @@ efi_status_t efi_init_obj_list(void) if (IS_ENABLED(CONFIG_EFI_CAPSULE_ON_DISK) && !IS_ENABLED(CONFIG_EFI_CAPSULE_ON_DISK_EARLY)) ret = efi_launch_capsules(); + out: + r = efi_clear_os_indications(); + if (ret == EFI_SUCCESS) + ret = r; efi_obj_list_initialized = ret; return ret; } From 0fa5020c024e49222ca97ead3502b332d35dea76 Mon Sep 17 00:00:00 2001 From: Ilias Apalodimas Date: Tue, 29 Jun 2021 07:55:51 +0300 Subject: [PATCH 16/19] efi_loader: Allow capsule update on-disk without checking OsIndications Although U-Boot supports capsule update on-disk, it's lack of support for SetVariable at runtime prevents applications like fwupd from using it. In order to perform the capsule update on-disk the spec says that the OS must copy the capsule to the \EFI\UpdateCapsule directory and set a bit in the OsIndications variable. The firmware then checks for the EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED bit in OsIndications variable, which is set by the submitter to trigger processing of the capsule on the next reboot. Let's add a config option which ignores the bit and just relies on the capsule being present. Since U-Boot deletes the capsule while processing it, we won't end up applying it multiple times. Note that this is allowed for all capsules. In the future, once authenticated capsules are fully supported, we can limit the functionality to those only. Signed-off-by: apalos Reword Kconfig description. Reviewed-by: Heinrich Schuchardt Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/Kconfig | 10 ++++++++++ lib/efi_loader/efi_capsule.c | 36 ++++++++++++++++++++++++++++-------- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig index 684adfb623..156b391521 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -137,6 +137,16 @@ config EFI_CAPSULE_ON_DISK under a specific directory on UEFI system partition instead of via UpdateCapsule API. +config EFI_IGNORE_OSINDICATIONS + bool "Ignore OsIndications for CapsuleUpdate on-disk" + depends on EFI_CAPSULE_ON_DISK + default n + help + There are boards where U-Boot does not support SetVariable at runtime. + Select this option if you want to use the capsule-on-disk feature + without setting the EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED + flag in variable OsIndications. + config EFI_CAPSULE_ON_DISK_EARLY bool "Initiate capsule-on-disk at U-Boot boottime" depends on EFI_CAPSULE_ON_DISK diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_capsule.c index d7136035d8..50bed32bfb 100644 --- a/lib/efi_loader/efi_capsule.c +++ b/lib/efi_loader/efi_capsule.c @@ -948,6 +948,33 @@ efi_status_t __weak efi_load_capsule_drivers(void) return ret; } +/** + * check_run_capsules - Check whether capsule update should run + * + * The spec says OsIndications must be set in order to run the capsule update + * on-disk. Since U-Boot doesn't support runtime SetVariable, allow capsules to + * run explicitly if CONFIG_EFI_IGNORE_OSINDICATIONS is selected + */ +static bool check_run_capsules(void) +{ + u64 os_indications; + efi_uintn_t size; + efi_status_t ret; + + if (IS_ENABLED(CONFIG_EFI_IGNORE_OSINDICATIONS)) + return true; + + size = sizeof(os_indications); + ret = efi_get_variable_int(L"OsIndications", &efi_global_variable_guid, + NULL, &size, &os_indications, NULL); + if (ret == EFI_SUCCESS && + (os_indications + & EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED)) + return true; + + return false; +} + /** * efi_launch_capsule - launch capsules * @@ -958,20 +985,13 @@ efi_status_t __weak efi_load_capsule_drivers(void) */ efi_status_t efi_launch_capsules(void) { - u64 os_indications; - efi_uintn_t size; struct efi_capsule_header *capsule = NULL; u16 **files; unsigned int nfiles, index, i; u16 variable_name16[12]; efi_status_t ret; - size = sizeof(os_indications); - ret = efi_get_variable_int(L"OsIndications", &efi_global_variable_guid, - NULL, &size, &os_indications, NULL); - if (ret != EFI_SUCCESS || - !(os_indications - & EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED)) + if (!check_run_capsules()) return EFI_SUCCESS; index = get_last_capsule(); From 760d2f9e9e66c7eacfbcff21dcd3733d16526438 Mon Sep 17 00:00:00 2001 From: Da Xue Date: Fri, 2 Jul 2021 12:32:43 -0400 Subject: [PATCH 17/19] autoboot: fix MENUKEY replace CONFIG_AUTOBOOT_USE_MENUKEY with CONFIG_AUTOBOOT_MENUKEY Signed-off-by: Da Xue --- common/autoboot.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/autoboot.c b/common/autoboot.c index c0b71af4d1..b42148c729 100644 --- a/common/autoboot.c +++ b/common/autoboot.c @@ -45,7 +45,7 @@ static int menukey; #endif #ifdef CONFIG_AUTOBOOT_USE_MENUKEY -#define AUTOBOOT_MENUKEY CONFIG_AUTOBOOT_USE_MENUKEY +#define AUTOBOOT_MENUKEY CONFIG_AUTOBOOT_MENUKEY #else #define AUTOBOOT_MENUKEY 0 #endif From 8c6d8c32192049f8dafaaafae68eb9124b21c1e0 Mon Sep 17 00:00:00 2001 From: Da Xue Date: Fri, 2 Jul 2021 17:11:40 -0400 Subject: [PATCH 18/19] configs: libretech: set SPI mode to 0 Kconfig defaults to mode 3 if CONFIG_SF_DEFAULT_MODE is not set. It becomes an issue since meson_spifc does not support SPI_CPHA. Needed after commit e2e95e5e25 ("spi: Update speed/mode on change"). Fixes: e2e95e5e25 ("spi: Update speed/mode on change") Signed-off-by:Da Xue [narmstrong: reformated commit reference & added Fixes tag] Signed-off-by: Neil Armstrong --- configs/libretech-ac_defconfig | 1 + configs/libretech-cc_v2_defconfig | 1 + configs/libretech-s905d-pc_defconfig | 1 + configs/libretech-s912-pc_defconfig | 1 + 4 files changed, 4 insertions(+) diff --git a/configs/libretech-ac_defconfig b/configs/libretech-ac_defconfig index ec51f2ad38..9abbcad3c0 100644 --- a/configs/libretech-ac_defconfig +++ b/configs/libretech-ac_defconfig @@ -39,6 +39,7 @@ CONFIG_MMC_MESON_GX=y CONFIG_MTD=y CONFIG_DM_MTD=y CONFIG_DM_SPI_FLASH=y +CONFIG_SF_DEFAULT_MODE=0x0 CONFIG_SPI_FLASH_GIGADEVICE=y CONFIG_SPI_FLASH_SPANSION=y CONFIG_PHY_MESON_GXL=y diff --git a/configs/libretech-cc_v2_defconfig b/configs/libretech-cc_v2_defconfig index 97c8a9e47b..7dc6ed2f29 100644 --- a/configs/libretech-cc_v2_defconfig +++ b/configs/libretech-cc_v2_defconfig @@ -35,6 +35,7 @@ CONFIG_MMC_MESON_GX=y CONFIG_MTD=y CONFIG_DM_MTD=y CONFIG_DM_SPI_FLASH=y +CONFIG_SF_DEFAULT_MODE=0x0 CONFIG_SPI_FLASH_GIGADEVICE=y CONFIG_PHY_MESON_GXL=y CONFIG_DM_ETH=y diff --git a/configs/libretech-s905d-pc_defconfig b/configs/libretech-s905d-pc_defconfig index c0301a0aa0..93523c23cf 100644 --- a/configs/libretech-s905d-pc_defconfig +++ b/configs/libretech-s905d-pc_defconfig @@ -36,6 +36,7 @@ CONFIG_SARADC_MESON=y CONFIG_MMC_MESON_GX=y CONFIG_MTD=y CONFIG_DM_SPI_FLASH=y +CONFIG_SF_DEFAULT_MODE=0x0 CONFIG_SPI_FLASH_GIGADEVICE=y CONFIG_PHY_REALTEK=y CONFIG_DM_ETH=y diff --git a/configs/libretech-s912-pc_defconfig b/configs/libretech-s912-pc_defconfig index e2faea6242..669f000f7f 100644 --- a/configs/libretech-s912-pc_defconfig +++ b/configs/libretech-s912-pc_defconfig @@ -35,6 +35,7 @@ CONFIG_SARADC_MESON=y CONFIG_MMC_MESON_GX=y CONFIG_MTD=y CONFIG_DM_SPI_FLASH=y +CONFIG_SF_DEFAULT_MODE=0x0 CONFIG_SPI_FLASH_GIGADEVICE=y CONFIG_PHY_REALTEK=y CONFIG_DM_ETH=y From 840658b093976390e9537724f802281c9c8439f5 Mon Sep 17 00:00:00 2001 From: Tom Rini Date: Mon, 5 Jul 2021 11:11:28 -0400 Subject: [PATCH 19/19] Prepare v2021.07 Signed-off-by: Tom Rini --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 027e31e09e..2ab9c53192 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ VERSION = 2021 PATCHLEVEL = 07 SUBLEVEL = -EXTRAVERSION = -rc5 +EXTRAVERSION = NAME = # *DOCUMENTATION*