efi_loader: add capsule update support
v9 cover efi_loader: add capsule update support
Summary
=======
'UpdateCapsule' is one of runtime services defined in UEFI specification and its aim is to allow a caller (OS) to pass information to the firmware, i.e. U-Boot. This is mostly used to update firmware binary on devices by instructions from OS.
While 'UpdateCapsule' is a runtime services function, it is, at least initially, supported only before exiting boot services alike other runtime functions, [Get/]SetVariable. This is because modifying storage which may be shared with OS must be carefully designed and there is no general assumption that we can do it.
Therefore, we practically support only "capsule on disk"; any capsule can be handed over to UEFI subsystem as a file on a specific file system.
In this patch series, all the related definitions and structures are given as UEFI specification describes, and basic framework for capsule support is provided. Currently supported is
* firmware update (Firmware Management Protocol or simply FMP)
Most of functionality of firmware update is provided by FMP driver and it can be, by nature, system/platform-specific. So you can and should implement your own FMP driver(s) based on your system requirements. Under the current implementation, we provide two basic but generic drivers with two formats:
* FIT image format (as used in TFTP update and dfu)
* raw image format
It's totally up to users which one, or both, should be used on users' system depending on user requirements.
Quick usage
===========
1. You can create a capsule file with the following host command:
$ mkeficapsule [--fit <fit image> | --raw <raw image>] <output file>
2. Put the file under:
/EFI/UpdateCapsule of UEFI system partition
3. Specify firmware storage to be updated in "dfu_alt_info" variable (Please follow README.dfu for details.)
==> env set dfu_alt_info '...'
4. After setting up UEFI's OsIndications variable, reboot U-Boot:
OsIndications <= EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED
Patch structure
===============
Patch#1-#6: main part of implementation
Patch#7-#8: utilities
Patch#9-#10: pytests
Patch#11: for sandbox test
[1] https://git.linaro.org/people/takahiro.akashi/u-boot.git efi/capsule
Prerequisite patches
====================
None
Test
====
* passed all the pytests which are included in this patch series on sandbox build locally.
* In Travis CI, all tests skipped (or 'S', but it's not a failure, 'F') because "virt-make-fs" cannot be executed.
Issues
======
* Timing of executing capsules-on-disk
Currently, processing a capsule is triggered only as part of UEFI subsystem initialization. This means that, for example, firmware update, may not take place@system booting time and will potentially be delayed until a first call of any UEFI functions.
=> See patch#5 for my proposal
* A bunch of warnings like
WARNING: Use 'if (IS_ENABLED(CONFIG...))' instead of '#if or #ifdef' where possible
I don't think that fixing those improves anything.
* Add a document in uefi.rst
TODO's
======
(Won't be addressed in this series.)
* capsule authentication
* capsule dependency (dependency expression instruction set, or depex)
* loading drivers in a capsule
* handling RESET flag in a capsule and QeuryCapsuleCaps
* full semantics of ESRT (EFI System Resource Table)
* enabling capsule API at runtime
* json capsule
* recovery from update failure
Changes
=======
v9 (November 17, 2020)
* rebased on v2021.01-rc2
* removed already-merged patches
* aligned with a function prototype change of efi_create_indexed_name() (Patch#1-2)
# See Travis CI status in v8 below
v8 (November 13, 2020)
* fix a "not used" warning against update_load() in some configuration (Patch#3)
* fix failures (marked as 'F') in *secure boot* test in Travis CI by making "EFI_CAPSULE_ON_DISK_EARLY" 'default n' (Patch#8)
* fix failures (marked as 'E') at pytest setup in Travis CI by changing a python file's name along with removing unused definitions (Patch#16)
* add Patch#18 to enable tests to be run with default sandbox config (Patch#18)
v7 (October 29, 2020)
* rename CONFIG_DFU_ALT to CONFIG_DFU_WRITE_ALT (Patch#1,#3,#13)
v6 RESEND (October 29, 2020)
* rebased on v2021.01-rc1
v6 (September 7, 2020)
* temporarily drop the prerequisite patch[2]
* add a missing field (dependencies) in efi_api.h (but never used) (Patch#10)
* add a missing field (image_capsule_support) and related definitions in efi_api.h (Patch#10, #15)
* cosmetic changes on constant definitions in efi_api.h (Patch#10)
* strict check for INVALID_PARAMETER at GET_IMAGE_INFO api (Patch#11,#13)
* fix warnings in pytest (Patch#16,#17)
v5 (August 3, 2020)
* removed superfluous type conversion at dfu_write_from_mem_addr() (Patch#2)
* introduced a common helper function, efi_create_indexed_name() (Patch#6,#7,#8)
* use efi_[get|set]_variable_int(), if necessary, with READ_ONLY (Patch#7,#8)
* return EFI_UNSUPPORTED at Patch#7
* changed the word, number, to 'index' (Patch#7,#8)
* removed 'ifdef CONFIG_EFI_CAPSULE_ON_DISK' from a header (Patch#8)
* initialize 'CapsuleLast' in efi_init_obj_list() (Patch#7,#8)
* added 'const' qualifier for filename argument at efi_capsule_[read|delete]_file() (Patch#8)
v4 (July 22, 2020)
* rebased to Heinrich's current efi-2020-10
* rework dfu-related code to align with Heinrich's change (Patch#1,#3)
* change a type of 'addr' argument from int to 'void *' per Sughosh's comment (Patch#2-#3,#11-#12)
* rework/simplify pytests (Patch#15-#16)
- utilize virt-make-fs
- drop Test Case 1 (updating U-Boot environment data)
- remove useless definitions (MNT_PNT, EFI_CAPSULE_IMAGE_NAME)
- apply autopep8
v3 (July 10, 2020)
* rebased to Heinrich's current efi-2020-10-rc1
* refactor efi_firmware_[fit|raw]_get_image_info() (patch#11,#13)
v2 (June 17, 2020)
* rebased to v2020.07-rc4
* add preparatory patches for dfu (Patch#1-#5, #12)
* rework FIT capsule driver to utilize dfu_alt_info instead of CONFIG_xxx (patch#11)
* extend get_image_info() to correspond to dfu_alt_info (patch#11)
* add a 'raw binary' capsule support
(patch#13, #17)
* allow multiple capsule formats (with different GUIDs) to be installed (patch#11, #13)
* extend mkeficapsule command to accept additional parameters, like version/index/hardware instance for a capsule header info. (patch#15)
* mkeficapsule can now also generate raw-binary capsule (patch#16)
* add function descriptions
* apply autopep8 to pytests and fix more against pylint
v1 (April 27, 2020)
* rebased to v2020.07-rc
* removed already-merged patches (RFC's #1 to #4)
* dropped 'variable update' capsule support (RFC's patch#10)
* dropped 'variable configuration table' support (RFC's patch#11) (Those two should be discussed separately.)
* add preparatory patches (patch#1/#2)
* fix several build errors
* rename some Kconfig options to be aligned with UEFI specification's terms (patch#3,4,6,7)
* enforce UpdateCapsule API to be disabled after ExitBootServices (patch#3)
* use config table, runtime_services_supported, instead of variable (patch#3)
* make EFI_CAPSULE_ON_DISK buildable even if UpdateCapsule API is disabled (patch4)
* support OsIndications, invoking capsule-on-disk only if the variable indicates so (patch#4)
* introduced EFI_CAPSULE_ON_DISK_EARLY to invoke capsule-on-disk in U-Boot initialization (patch#4)
* detect capsule files only if they are on EFI system partition (patch#4)
* use printf, rather than EFI_PRINT, in error cases (patch#4)
* use 'header_size' field to retrieve capsule data, adding sanity checks against capsule size (patch#6)
* call fmpt driver interfaces with EFI_CALL (patch#6)
* remove 'variable update capsule'-related code form mkeficapsule (patch#9)
* add a test case of OsIndications not being set properly (patch#10)
* adjust test scenario for EFI_CAPSULE_ON_DISK_EARLY (patch#10)
* revise pytest scripts (patch#10)
Initial release as RFC (March 17, 2020)
AKASHI Takahiro (11):
efi_loader: define UpdateCapsule api
efi_loader: capsule: add capsule_on_disk support
efi_loader: capsule: add memory range capsule definitions
efi_loader: capsule: support firmware update
efi_loader: add firmware management protocol for FIT image
efi_loader: add firmware management protocol for raw image
cmd: add "efidebug capsule" command
tools: add mkeficapsule command for UEFI capsule update test/py: efi_capsule: test for FIT image capsule test/py: efi_capsule: test for raw image capsule
sandbox: enable capsule update for testing
cmd/efidebug.c | 235 +++++ common/main.c | 4 + configs/sandbox64_defconfig | 6 + configs/sandbox_defconfig | 6 + include/efi_api.h | 166 ++++ include/efi_loader.h | 27 + lib/efi_loader/Kconfig | 68 ++ lib/efi_loader/Makefile | 2 + lib/efi_loader/efi_capsule.c | 917 ++++++++++++++++++ lib/efi_loader/efi_firmware.c | 403 ++++++++ lib/efi_loader/efi_runtime.c | 104 +- lib/efi_loader/efi_setup.c | 76 +- .../py/tests/test_efi_capsule/capsule_defs.py | 5 + test/py/tests/test_efi_capsule/conftest.py | 74 ++ .../test_efi_capsule/test_capsule_firmware.py | 241 +++++ .../tests/test_efi_capsule/uboot_bin_env.its | 36 + tools/Makefile | 2 + tools/mkeficapsule.c | 239 +++++ 18 files changed, 2557 insertions(+), 54 deletions(-) create mode 100644 lib/efi_loader/efi_capsule.c create mode 100644 lib/efi_loader/efi_firmware.c create mode 100644 test/py/tests/test_efi_capsule/capsule_defs.py create mode 100644 test/py/tests/test_efi_capsule/conftest.py create mode 100644 test/py/tests/test_efi_capsule/test_capsule_firmware.py create mode 100644 test/py/tests/test_efi_capsule/uboot_bin_env.its create mode 100644 tools/mkeficapsule.c
Signature · 1 line
2.28.0
PATCH v9 1/11 efi_loader: define UpdateCapsule api
In this commit, skeleton functions for capsule-related API's are added under CONFIG_EFI_UPDATE_CAPSULE configuration. Detailed implementation for a specific capsule type will be added in the succeeding patches.
--- include/efi_api.h | 12 +++ include/efi_loader.h | 13 +++ lib/efi_loader/Kconfig | 11 +++ lib/efi_loader/Makefile | 1 + lib/efi_loader/efi_capsule.c | 165 +++++++++++++++++++++++++++++++++++ lib/efi_loader/efi_runtime.c | 104 ++++++++++++---------- lib/efi_loader/efi_setup.c | 64 +++++++++++--- 7 files changed, 316 insertions(+), 54 deletions(-) create mode 100644 lib/efi_loader/efi_capsule.c
include/efi_api.h +12 -0
@@ -217,6 +217,10 @@ enum efi_reset_type {#define CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE 0x00020000#define CAPSULE_FLAGS_INITIATE_RESET 0x00040000 +#define EFI_CAPSULE_REPORT_GUID \ + EFI_GUID(0x39b68c46, 0xf7fb, 0x441b, 0xb6, 0xec, \ + 0x16, 0xb0, 0xf6, 0x98, 0x21, 0xf3) +struct efi_capsule_header {efi_guid_t capsule_guid;u32 header_size;
@@ -224,6 +228,14 @@ struct efi_capsule_header {u32 capsule_image_size; } __packed; +struct efi_capsule_result_variable_header { +u32 variable_total_size; +u32 reserved; +efi_guid_t capsule_guid; +struct efi_time capsule_processed; +efi_status_t capsule_status; +} __packed; +#define EFI_RT_SUPPORTED_GET_TIME 0x0001#define EFI_RT_SUPPORTED_SET_TIME 0x0002#define EFI_RT_SUPPORTED_GET_WAKEUP_TIME 0x0004
include/efi_loader.h +13 -0
@@ -207,6 +207,8 @@ extern const efi_guid_t efi_guid_cert_type_pkcs7;/* GUID of RNG protocol */ extern const efi_guid_t efi_guid_rng_protocol; +/* GUID of capsule update result */ +extern const efi_guid_t efi_guid_capsule_report;extern unsigned int __efi_runtime_start, __efi_runtime_stop;extern unsigned int __efi_runtime_rel_start, __efi_runtime_rel_stop;
@@ -807,6 +809,17 @@ void efi_memcpy_runtime(void *dest, const void *src, size_t n);/* commonly used helper function */ u16 *efi_create_indexed_name (u16 *buffer,const char *name,unsigned int index); +/* Capsule update */ +efi_status_t EFIAPI efi_update_capsule( +struct efi_capsule_header **capsule_header_array, +efi_uintn_t capsule_count, +u64 scatter_gather_list); +efi_status_t EFIAPI efi_query_capsule_caps( +struct efi_capsule_header **capsule_header_array, +efi_uintn_t capsule_count, +u64 *maximum_capsule_size, +u32 *reset_type); +#else /* CONFIG_IS_ENABLED(EFI_LOADER) */ /* Without CONFIG_EFI_LOADER we don't have a runtime section, stub it out */
lib/efi_loader/Kconfig +11 -0
@@ -93,6 +93,17 @@ config EFI_SET_TIME Provide the SetTime() runtime service at boottime. This service can be used by an EFI application to adjust the real time clock. +config EFI_HAVE_CAPSULE_SUPPORT + bool + +config EFI_RUNTIME_UPDATE_CAPSULE + bool "UpdateCapsule() runtime service" + default n + select EFI_HAVE_CAPSULE_SUPPORT + help + Select this option if you want to use UpdateCapsule and + QueryCapsuleCapabilities API's. + config EFI_DEVICE_PATH_TO_TEXT bool "Device path to text protocol" default y
lib/efi_loader/Makefile +1 -0
@@ -23,6 +23,7 @@ endif obj-$(CONFIG_CMD_BOOTEFI_HELLO) += helloworld_efi.o obj-y += efi_bootmgr.o obj-y += efi_boottime.o +obj-$(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) += efi_capsule.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
lib/efi_loader/efi_capsule.c new file +165 -0
165 lines not on this page · raw message
lib/efi_loader/efi_runtime.c +60 -44
135 lines not on this page · raw message
lib/efi_loader/efi_setup.c +54 -10
95 lines not on this page · raw message
Signature · 1 line
2.28.0
PATCH v9 2/11 efi_loader: capsule: add capsule_on_disk support
In reply to AKASHI TakahiroCapsule data can be loaded into the system either via UpdateCapsule runtime service or files on a file system (of boot device). The latter case is called "capsules on disk", and actual updates will take place at the next boot time.
In this commit, we will support capsule on disk mechanism.
Please note that U-Boot itself has no notion of "boot device" and all the capsule files to be executed will be detected only if they are located in a specific directory, \EFI\UpdateCapsule, on a device that is identified as a boot device by "BootXXXX" variables.
--- common/main.c | 4 + include/efi_loader.h | 9 + lib/efi_loader/Kconfig | 22 ++ lib/efi_loader/efi_capsule.c | 498 +++++++++++++++++++++++++++++++++++ lib/efi_loader/efi_setup.c | 8 + 5 files changed, 541 insertions(+)
common/main.c +4 -0
@@ -16,6 +16,7 @@#include <init.h> #include <net.h> #include <version.h> +#include <efi_loader.h> static void run_preboot_environment_command (void ) {
@@ -53,6 +54,9 @@ void main_loop(void)if (IS_ENABLED (CONFIG_UPDATE_TFTP ))update_tftp (0UL ,NULL ,NULL ); +if (IS_ENABLED (CONFIG_EFI_CAPSULE_ON_DISK_EARLY )) +efi_launch_capsules (); + s =bootdelay_process ();if (cli_process_fdt (&s))cli_secure_boot_cmd (s);
include/efi_loader.h +9 -0
@@ -820,6 +820,11 @@ efi_status_t EFIAPI efi_query_capsule_caps( u64 *maximum_capsule_size, u32 *reset_type); +#define EFI_CAPSULE_DIR L"\\EFI\\UpdateCapsule\\" + +/* Hook at initialization */ +efi_status_t efi_launch_capsules (void ); +#else /* CONFIG_IS_ENABLED(EFI_LOADER) */ /* Without CONFIG_EFI_LOADER we don't have a runtime section, stub it out */
@@ -836,6 +841,10 @@ static inline void efi_set_bootdev(const char *dev, const char *devnr, const char *path) { }static inline void efi_net_set_dhcp_ack (void *pkt,int len) { }static inline void efi_print_image_infos (void *pc) { } +static inline efi_status_t efi_launch_capsules (void ) +{ +return EFI_SUCCESS ; +}#endif /* CONFIG_IS_ENABLED(EFI_LOADER) */
lib/efi_loader/Kconfig +22 -0
@@ -104,6 +104,28 @@ config EFI_RUNTIME_UPDATE_CAPSULE Select this option if you want to use UpdateCapsule and QueryCapsuleCapabilities API's. +config EFI_CAPSULE_ON_DISK + bool "Enable capsule-on-disk support" + select EFI_HAVE_CAPSULE_SUPPORT + default n + help + Select this option if you want to use capsule-on-disk feature, + that is, capsules can be fetched and executed from files + under a specific directory on UEFI system partition instead of + via UpdateCapsule API. + +config EFI_CAPSULE_ON_DISK_EARLY + bool "Initiate capsule-on-disk at U-Boot boottime" + depends on EFI_CAPSULE_ON_DISK + default n + select EFI_SETUP_EARLY + help + Normally, without this option enabled, capsules will be + executed only at the first time of invoking one of efi command. + If this option is enabled, capsules will be enforced to be + executed as part of U-Boot initialisation so that they will + surely take place whatever is set to distro_bootcmd. + config EFI_DEVICE_PATH_TO_TEXT bool "Device path to text protocol" default y
lib/efi_loader/efi_capsule.c +498 -0
511 lines not on this page · raw message
lib/efi_loader/efi_setup.c +8 -0
@@ -155,6 +155,10 @@ static efi_status_t efi_init_os_indications(void) os_indications_supported |=EFI_OS_INDICATIONS_CAPSULE_RESULT_VAR_SUPPORTED ; +if (IS_ENABLED (CONFIG_EFI_CAPSULE_ON_DISK )) + os_indications_supported |= +EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED ; + return efi_set_variable_int(L"OsIndicationsSupported", &efi_global_variable_guid, EFI_VARIABLE_BOOTSERVICE_ACCESS |
@@ -275,6 +279,10 @@ efi_status_t efi_init_obj_list(void)if (ret !=EFI_SUCCESS ) goto out; +/* Execute capsules after reboot */ +if (IS_ENABLED (CONFIG_EFI_CAPSULE_ON_DISK ) && + !IS_ENABLED (CONFIG_EFI_CAPSULE_ON_DISK_EARLY )) + ret =efi_launch_capsules (); out: efi_obj_list_initialized = ret;return ret;
Signature · 1 line
2.28.0
PATCH v9 3/11 efi_loader: capsule: add memory range capsule definitions
In reply to AKASHI TakahiroMemory range capsule gives us a way to notify that some memory regions should be left untouched across the next reset.
See UEFI specification, section 8.5.3.
Since how we should handle this kind of capsule is totally up to the system, no implementation will be added in this commit.
--- include/efi_api.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
include/efi_api.h +17 -0
@@ -221,6 +221,10 @@ enum efi_reset_type {EFI_GUID (0x39b68c46 ,0xf7fb ,0x441b ,0xb6 ,0xec , \ 0x16, 0xb0, 0xf6, 0x98, 0x21, 0xf3) +#define EFI_MEMORY_RANGE_CAPSULE_GUID \ + EFI_GUID(0xde9f0ec, 0x88b6, 0x428f, 0x97, 0x7a, \ + 0x25, 0x8f, 0x1d, 0xe, 0x5e, 0x72) +struct efi_capsule_header {efi_guid_t capsule_guid;u32 header_size;
@@ -236,6 +240,19 @@ struct efi_capsule_result_variable_header {efi_status_t capsule_status; } __packed; +struct efi_memory_range { +efi_physical_addr_t address; +u64 length; +}; + +struct efi_memory_range_capsule { +struct efi_capsule_header *header; +/* EFI_MEMORY_TYPE: 0x80000000-0xFFFFFFFF */ +enum efi_mem_type os_requested_memory_type; +u64 number_of_memory_ranges; +struct efi_memory_range memory_ranges[]; +} __packed; +#define EFI_RT_SUPPORTED_GET_TIME 0x0001#define EFI_RT_SUPPORTED_SET_TIME 0x0002#define EFI_RT_SUPPORTED_GET_WAKEUP_TIME 0x0004
Signature · 1 line
2.28.0
PATCH v9 4/11 efi_loader: capsule: support firmware update
In reply to AKASHI TakahiroA capsule tagged with the guid, EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID, is handled as a firmware update object.
What efi_update_capsule() basically does is to load any firmware management protocol (or fmp) drivers contained in a capsule, find out an appropriate fmp driver and then invoke its set_image() interface against each binary in a capsule.
In this commit, however, loading drivers is not supported.
The result of applying a capsule is set to be stored in "CapsuleXXXX" variable, but its implementation is deferred to a fmp driver.
--- include/efi_api.h | 129 +++++++++++++++++++ include/efi_loader.h | 2 + lib/efi_loader/Kconfig | 8 ++ lib/efi_loader/efi_capsule.c | 238 ++++++++++++++++++++++++++++++++++- lib/efi_loader/efi_setup.c | 4 + 5 files changed, 380 insertions(+), 1 deletion(-)
include/efi_api.h +129 -0
@@ -217,6 +217,9 @@ enum efi_reset_type {#define CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE 0x00020000#define CAPSULE_FLAGS_INITIATE_RESET 0x00040000 +#define CAPSULE_SUPPORT_AUTHENTICATION 0x0000000000000001 +#define CAPSULE_SUPPORT_DEPENDENCY 0x0000000000000002 +#define EFI_CAPSULE_REPORT_GUID \ EFI_GUID(0x39b68c46, 0xf7fb, 0x441b, 0xb6, 0xec, \ 0x16, 0xb0, 0xf6, 0x98, 0x21, 0xf3)
@@ -225,6 +228,10 @@ enum efi_reset_type {EFI_GUID (0xde9f0ec ,0x88b6 ,0x428f ,0x97 ,0x7a , \ 0x25, 0x8f, 0x1d, 0xe, 0x5e, 0x72) +#define EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID \ + EFI_GUID(0x6dcbd5ed, 0xe82d, 0x4c44, 0xbd, 0xa1, \ + 0x71, 0x94, 0x19, 0x9a, 0xd9, 0x2a) +struct efi_capsule_header {efi_guid_t capsule_guid;u32 header_size;
@@ -253,6 +260,33 @@ struct efi_memory_range_capsule {struct efi_memory_range memory_ranges[]; } __packed; +struct efi_firmware_management_capsule_header { +u32 version; +u16 embedded_driver_count; +u16 payload_item_count; +u64 item_offset_list[]; +} __packed; + +struct efi_firmware_management_capsule_image_header { +u32 version; +efi_guid_t update_image_type_id; +u8 update_image_index; +u8 reserved[3 ]; +u32 update_image_size; +u32 update_vendor_code_size; +u64 update_hardware_instance; +u64 image_capsule_support; +} __packed; + +struct efi_capsule_result_variable_fmp { +u16 version; +u8 payload_index; +u8 update_image_index; +efi_guid_t update_image_type_id; +// u16 capsule_file_name[]; +// u16 capsule_target[]; +} __packed; +#define EFI_RT_SUPPORTED_GET_TIME 0x0001#define EFI_RT_SUPPORTED_SET_TIME 0x0002#define EFI_RT_SUPPORTED_GET_WAKEUP_TIME 0x0004
@@ -1808,4 +1842,99 @@ struct efi_signature_list {/* struct efi_signature_data signatures[...][signature_size]; */ } __attribute__((__packed__)); +/* +* Firmware management protocol +*/ +#define EFI_FIRMWARE_MANAGEMENT_PROTOCOL_GUID \ + EFI_GUID(0x86c77a67, 0x0b97, 0x4633, 0xa1, 0x87, \ + 0x49, 0x10, 0x4d, 0x06, 0x85, 0xc7) + +#define IMAGE_ATTRIBUTE_IMAGE_UPDATABLE 0x0000000000000001 +#define IMAGE_ATTRIBUTE_RESET_REQUIRED 0x0000000000000002 +#define IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED 0x0000000000000004 +#define IMAGE_ATTRIBUTE_IN_USE 0x0000000000000008 +#define IMAGE_ATTRIBUTE_UEFI_IMAGE 0x0000000000000010 +#define IMAGE_ATTRIBUTE_DEPENDENCY 0x0000000000000020 + +#define IMAGE_COMPATIBILITY_CHECK_SUPPORTED 0x0000000000000001 + +#define IMAGE_UPDATABLE_VALID 0x0000000000000001 +#define IMAGE_UPDATABLE_INVALID 0x0000000000000002 +#define IMAGE_UPDATABLE_INVALID_TYPE 0x0000000000000004 +#define IMAGE_UPDATABLE_INVALID_OLLD 0x0000000000000008 +#define IMAGE_UPDATABLE_VALID_WITH_VENDOR_CODE 0x0000000000000010 + +#define PACKAGE_ATTRIBUTE_VERSION_UPDATABLE 0x0000000000000001 +#define PACKAGE_ATTRIBUTE_RESET_REQUIRED 0x0000000000000002 +#define PACKAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED 0x0000000000000004 + +#define EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION 4 + +typedef struct efi_firmware_image_dependencies { +u8 dependencies[0 ]; +}efi_firmware_image_dep_t ; + +struct efi_firmware_image_descriptor { +u8 image_index; +efi_guid_t image_type_id; +u64 image_id; +u16 *image_id_name; +u32 version; +u16 *version_name; +efi_uintn_t size; +u64 attributes_supported; +u64 attributes_setting; +u64 compatibilities; +u32 lowest_supported_image_version; +u32 last_attempt_version; +u32 last_attempt_status; +u64 hardware_instance; +efi_firmware_image_dep_t *dependencies; +}; + +struct efi_firmware_management_protocol { + efi_status_t (EFIAPI *get_image_info)( + struct efi_firmware_management_protocol *this, + efi_uintn_t *image_info_size, + struct efi_firmware_image_descriptor *image_info, + u32 *descriptor_version, + u8 *descriptor_count, + efi_uintn_t *descriptor_size, + u32 *package_version, + u16 **package_version_name); + efi_status_t (EFIAPI *get_image)( + struct efi_firmware_management_protocol *this, + u8 image_index, + void *image, + efi_uintn_t *image_size); + efi_status_t (EFIAPI *set_image)( + struct efi_firmware_management_protocol *this, + u8 image_index, + const void *image, + efi_uintn_t image_size, + const void *vendor_code, + efi_status_t (*progress)(efi_uintn_t completion), + u16 **abort_reason); + efi_status_t (EFIAPI *check_image)( + struct efi_firmware_management_protocol *this, + u8 image_index, + const void *image, + efi_uintn_t *image_size, + u32 *image_updatable); + efi_status_t (EFIAPI *get_package_info)( + struct efi_firmware_management_protocol *this, + u32 *package_version, + u16 **package_version_name, + u32 *package_version_name_maxlen, + u64 *attributes_supported, + u64 *attributes_setting); + efi_status_t (EFIAPI *set_package_info)( + struct efi_firmware_management_protocol *this, + const void *image, + efi_uintn_t *image_size, + const void *vendor_code, + u32 package_version, + const u16 *package_version_name); +}; +#endif
include/efi_loader.h +2 -0
@@ -209,6 +209,8 @@ extern const efi_guid_t efi_guid_cert_type_pkcs7;extern const efi_guid_t efi_guid_rng_protocol;/* GUID of capsule update result */ extern const efi_guid_t efi_guid_capsule_report; +/* GUID of firmware management protocol */ +extern const efi_guid_t efi_guid_firmware_management_protocol;extern unsigned int __efi_runtime_start, __efi_runtime_stop;extern unsigned int __efi_runtime_rel_start, __efi_runtime_rel_stop;
lib/efi_loader/Kconfig +8 -0
@@ -126,6 +126,14 @@ config EFI_CAPSULE_ON_DISK_EARLY executed as part of U-Boot initialisation so that they will surely take place whatever is set to distro_bootcmd. +config EFI_CAPSULE_FIRMWARE_MANAGEMENT + bool "Capsule: Firmware Management Protocol" + depends on EFI_HAVE_CAPSULE_SUPPORT + default y + help + Select this option if you want to enable capsule-based + firmware update using Firmware Management Protocol. + config EFI_DEVICE_PATH_TO_TEXT bool "Device path to text protocol" default y
lib/efi_loader/efi_capsule.c +237 -1
258 lines not on this page · raw message
lib/efi_loader/efi_setup.c +4 -0
@@ -159,6 +159,10 @@ static efi_status_t efi_init_os_indications(void) os_indications_supported |=EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED ; +if (IS_ENABLED (CONFIG_EFI_CAPSULE_FIRMWARE_MANAGEMENT )) + os_indications_supported |= +EFI_OS_INDICATIONS_FMP_CAPSULE_SUPPORTED ; + return efi_set_variable_int(L"OsIndicationsSupported", &efi_global_variable_guid, EFI_VARIABLE_BOOTSERVICE_ACCESS |
Signature · 1 line
2.28.0
PATCH v9 4/11 efi_loader: capsule: support firmware update
hi Takahiro,
Quoted 77 lines · AKASHI Takahiro
A capsule tagged with the guid,
EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID, is handled as a firmware update object.
Whatefi_update_capsule()basically does is to load any firmware management protocol (or fmp) drivers contained in a capsule, find out an appropriate fmp driver and then invoke itsset_image()interface against each binary in a capsule.
In this commit, however, loading drivers is not supported.The result of applying a capsule is set to be stored in "CapsuleXXXX" variable, but its implementation is deferred to a fmp driver.
Signed-off-by AKASHI Takahiro <[email protected]>--- include/efi_api.h | 129 +++++++++++++++++++ include/efi_loader.h | 2 + lib/efi_loader/Kconfig | 8 ++ lib/efi_loader/efi_capsule.c | 238 ++++++++++++++++++++++++++++++++++- lib/efi_loader/efi_setup.c | 4 + 5 files changed, 380 insertions(+), 1 deletion(-)include/efi_api.h +34
-0@@ -217,6 +217,9 @@ enum efi_reset_type {#define CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE 0x00020000#define CAPSULE_FLAGS_INITIATE_RESET 0x00040000 +#define CAPSULE_SUPPORT_AUTHENTICATION 0x0000000000000001 +#define CAPSULE_SUPPORT_DEPENDENCY 0x0000000000000002 +#define EFI_CAPSULE_REPORT_GUID \ EFI_GUID(0x39b68c46, 0xf7fb, 0x441b, 0xb6, 0xec, \ 0x16, 0xb0, 0xf6, 0x98, 0x21, 0xf3)@@ -225,6 +228,10 @@ enum efi_reset_type {EFI_GUID (0xde9f0ec ,0x88b6 ,0x428f ,0x97 ,0x7a , \ 0x25, 0x8f, 0x1d, 0xe, 0x5e, 0x72) +#define EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID \ + EFI_GUID(0x6dcbd5ed, 0xe82d, 0x4c44, 0xbd, 0xa1, \ + 0x71, 0x94, 0x19, 0x9a, 0xd9, 0x2a) +struct efi_capsule_header {efi_guid_t capsule_guid;u32 header_size;@@ -253,6 +260,33 @@ struct efi_memory_range_capsule {struct efi_memory_range memory_ranges[]; } __packed; +struct efi_firmware_management_capsule_header { +u32 version; +u16 embedded_driver_count; +u16 payload_item_count; +u64 item_offset_list[]; +} __packed; + +struct efi_firmware_management_capsule_image_header { +u32 version; +efi_guid_t update_image_type_id; +u8 update_image_index; +u8 reserved[3 ]; +u32 update_image_size; +u32 update_vendor_code_size; +u64 update_hardware_instance; +u64 image_capsule_support; +} __packed; + +struct efi_capsule_result_variable_fmp { +u16 version; +u8 payload_index; +u8 update_image_index; +efi_guid_t update_image_type_id; +// u16 capsule_file_name[]; +// u16 capsule_target[]; +} __packed; +
<snip>
Quoted 79 lines
include/efi_api.h +54
-0+/** +* efi_capsule_update_firmware - update firmware from capsule +* @capsule_data: Capsule +* +* Update firmware, using a capsule, @capsule_data. Loading any FMP +* drivers embedded in a capsule is not supported. +* +* Return: status code +*/ +static efi_status_t efi_capsule_update_firmware ( +struct efi_capsule_header *capsule_data) +{ +struct efi_firmware_management_capsule_header *capsule; +struct efi_firmware_management_capsule_image_header *image; +size_t capsule_size; +void *image_binary, *vendor_code; +efi_handle_t *handles; +efi_uintn_t no_handles; +int item; +struct efi_firmware_management_protocol *fmp; +u16 *abort_reason; +efi_status_t ret =EFI_SUCCESS ; + +/* sanity check */ +if (capsule_data->header_size <sizeof (*capsule) || + capsule_data->header_size >= capsule_data->capsule_image_size) +return EFI_INVALID_PARAMETER ; + + capsule = (void *)capsule_data + capsule_data->header_size; + capsule_size = capsule_data->capsule_image_size + - capsule_data->header_size; + +if (capsule->version !=0x00000001 ) +return EFI_INVALID_PARAMETER ; + +/* Drivers */ +/* TODO: support loading drivers */ + + handles =NULL ; + ret =EFI_CALL (efi_locate_handle_buffer ( +BY_PROTOCOL , + &efi_guid_firmware_management_protocol, +NULL , &no_handles, (efi_handle_t **)&handles)); +if (ret !=EFI_SUCCESS ) +return EFI_UNSUPPORTED ; + +/* Payload */ +for (item = capsule->embedded_driver_count; + item < capsule->embedded_driver_count + + capsule->payload_item_count; item++) { +/* sanity check */ +if ((capsule->item_offset_list[item] +sizeof (*image) + >= capsule_size)) { + printf("EFI: A capsule has not enough size ofdata\n");
include/efi_api.h +15
-0+ ret =EFI_INVALID_PARAMETER ; + goto out; + } + + image = (void *)capsule + capsule->item_offset_list[item]; + +if (image->version !=0x00000001 && + image->version !=0x00000002 && + image->version !=0x00000003 ) { + ret =EFI_INVALID_PARAMETER ; + goto out; + } + +/* find a device for update firmware */ +/* TODO: should we pass index as well, or nothing but type? */
include/efi_api.h +6
-0+ fmp =efi_fmp_find (&image->update_image_type_id, + image->version ==0x1 ?0 : + image->update_hardware_instance, + handles, no_handles); +if (!fmp) { + printf("EFI Capsule: driver not found for firmwaretype: %pUl, hardware instance: %lld\n",
include/efi_api.h
Quoted 9 lines
include/efi_api.h +9
-0+ &image->update_image_type_id, + image->version ==0x1 ?0 : + image->update_hardware_instance); + ret =EFI_UNSUPPORTED ; + goto out; + } + +/* do it */ + image_binary = (void *)image +sizeof (*image);
Sorry for not having spotted this earlier. But since we are supporting the first three versions of the struct efi_firmware_management_capsule_image_header, the above logic needs to be changed to accomodate versions 1 and 2. So in case of a version 1 structure, the fields update_hardware_instance and image_capsule_support need to be discarded. Similarly for a version 2 structure, the image_capsule_support field needs to be discarded while calculating the image_binary pointer.
-sughosh
PATCH v9 4/11 efi_loader: capsule: support firmware update
Sughosh,
Quoted 175 lines · Sughosh Ganu
hi Takahiro,
Quoted 77 lines · AKASHI Takahiro
A capsule tagged with the guid,
EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID, is handled as a firmware update object.
Whatefi_update_capsule()basically does is to load any firmware management protocol (or fmp) drivers contained in a capsule, find out an appropriate fmp driver and then invoke itsset_image()interface against each binary in a capsule.
In this commit, however, loading drivers is not supported.The result of applying a capsule is set to be stored in "CapsuleXXXX" variable, but its implementation is deferred to a fmp driver.
Signed-off-by AKASHI Takahiro <[email protected]>--- include/efi_api.h | 129 +++++++++++++++++++ include/efi_loader.h | 2 + lib/efi_loader/Kconfig | 8 ++ lib/efi_loader/efi_capsule.c | 238 ++++++++++++++++++++++++++++++++++- lib/efi_loader/efi_setup.c | 4 + 5 files changed, 380 insertions(+), 1 deletion(-)include/efi_api.h +34
-0@@ -217,6 +217,9 @@ enum efi_reset_type {#define CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE 0x00020000#define CAPSULE_FLAGS_INITIATE_RESET 0x00040000 +#define CAPSULE_SUPPORT_AUTHENTICATION 0x0000000000000001 +#define CAPSULE_SUPPORT_DEPENDENCY 0x0000000000000002 +#define EFI_CAPSULE_REPORT_GUID \ EFI_GUID(0x39b68c46, 0xf7fb, 0x441b, 0xb6, 0xec, \ 0x16, 0xb0, 0xf6, 0x98, 0x21, 0xf3)@@ -225,6 +228,10 @@ enum efi_reset_type {EFI_GUID (0xde9f0ec ,0x88b6 ,0x428f ,0x97 ,0x7a , \ 0x25, 0x8f, 0x1d, 0xe, 0x5e, 0x72) +#define EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID \ + EFI_GUID(0x6dcbd5ed, 0xe82d, 0x4c44, 0xbd, 0xa1, \ + 0x71, 0x94, 0x19, 0x9a, 0xd9, 0x2a) +struct efi_capsule_header {efi_guid_t capsule_guid;u32 header_size;@@ -253,6 +260,33 @@ struct efi_memory_range_capsule {struct efi_memory_range memory_ranges[]; } __packed; +struct efi_firmware_management_capsule_header { +u32 version; +u16 embedded_driver_count; +u16 payload_item_count; +u64 item_offset_list[]; +} __packed; + +struct efi_firmware_management_capsule_image_header { +u32 version; +efi_guid_t update_image_type_id; +u8 update_image_index; +u8 reserved[3 ]; +u32 update_image_size; +u32 update_vendor_code_size; +u64 update_hardware_instance; +u64 image_capsule_support; +} __packed; + +struct efi_capsule_result_variable_fmp { +u16 version; +u8 payload_index; +u8 update_image_index; +efi_guid_t update_image_type_id; +// u16 capsule_file_name[]; +// u16 capsule_target[]; +} __packed; +<snip>
Quoted 79 lines
include/efi_api.h +54
-0+/** +* efi_capsule_update_firmware - update firmware from capsule +* @capsule_data: Capsule +* +* Update firmware, using a capsule, @capsule_data. Loading any FMP +* drivers embedded in a capsule is not supported. +* +* Return: status code +*/ +static efi_status_t efi_capsule_update_firmware ( +struct efi_capsule_header *capsule_data) +{ +struct efi_firmware_management_capsule_header *capsule; +struct efi_firmware_management_capsule_image_header *image; +size_t capsule_size; +void *image_binary, *vendor_code; +efi_handle_t *handles; +efi_uintn_t no_handles; +int item; +struct efi_firmware_management_protocol *fmp; +u16 *abort_reason; +efi_status_t ret =EFI_SUCCESS ; + +/* sanity check */ +if (capsule_data->header_size <sizeof (*capsule) || + capsule_data->header_size >= capsule_data->capsule_image_size) +return EFI_INVALID_PARAMETER ; + + capsule = (void *)capsule_data + capsule_data->header_size; + capsule_size = capsule_data->capsule_image_size + - capsule_data->header_size; + +if (capsule->version !=0x00000001 ) +return EFI_INVALID_PARAMETER ; + +/* Drivers */ +/* TODO: support loading drivers */ + + handles =NULL ; + ret =EFI_CALL (efi_locate_handle_buffer ( +BY_PROTOCOL , + &efi_guid_firmware_management_protocol, +NULL , &no_handles, (efi_handle_t **)&handles)); +if (ret !=EFI_SUCCESS ) +return EFI_UNSUPPORTED ; + +/* Payload */ +for (item = capsule->embedded_driver_count; + item < capsule->embedded_driver_count + + capsule->payload_item_count; item++) { +/* sanity check */ +if ((capsule->item_offset_list[item] +sizeof (*image) + >= capsule_size)) { + printf("EFI: A capsule has not enough size ofdata\n");
include/efi_api.h +15
-0+ ret =EFI_INVALID_PARAMETER ; + goto out; + } + + image = (void *)capsule + capsule->item_offset_list[item]; + +if (image->version !=0x00000001 && + image->version !=0x00000002 && + image->version !=0x00000003 ) { + ret =EFI_INVALID_PARAMETER ; + goto out; + } + +/* find a device for update firmware */ +/* TODO: should we pass index as well, or nothing but type? */
include/efi_api.h +6
-0+ fmp =efi_fmp_find (&image->update_image_type_id, + image->version ==0x1 ?0 : + image->update_hardware_instance, + handles, no_handles); +if (!fmp) { + printf("EFI Capsule: driver not found for firmwaretype: %pUl, hardware instance: %lld\n",
include/efi_api.h
Quoted 9 lines
include/efi_api.h +9
-0+ &image->update_image_type_id, + image->version ==0x1 ?0 : + image->update_hardware_instance); + ret =EFI_UNSUPPORTED ; + goto out; + } + +/* do it */ + image_binary = (void *)image +sizeof (*image);
Quoted 8 lines
Sorry for not having spotted this earlier. But since we are supporting the first three versions of the struct
efi_firmware_management_capsule_image_header, the above logic needs to be changed to accomodate versions 1 and 2. So in case of a version 1 structure, the fieldsupdate_hardware_instanceandimage_capsule_supportneed to be discarded. Similarly for a version 2 structure, theimage_capsule_supportfield needs to be discarded while calculating theimage_binarypointer.
Thank you for catching this issue, you're right.
Given, however, that the firmware update is quite firmware-specific and that we don't have any "backward compatibility" requirement, it would be better to simply drop the support for previous versions and to support the current/latest one, in this case, 3.
We have a similar issue on 'struct efi_firmware_image_descriptor'. I hope that imposing a version check/restriction won't bring any inconvenience to anybody.
-Takahiro Akashi
Quoted 1 line
-sughosh
PATCH v9 4/11 efi_loader: capsule: support firmware update
Takahiro,
Quoted 198 lines · AKASHI Takahiro
Sughosh,
Quoted 3 lines · Sughosh Ganu
hi Takahiro,
On Tue, 17 Nov 2020 at 05:58, AKASHI Takahiro <
takahiro.akashi at linaro.org>
Quoted 3 lines
Quoted 1 line · wrote:
A capsule tagged with the guid,
EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID,Quoted 2 lines
Quoted 2 lines
is handled as a firmware update object.
Whatefi_update_capsule()basically does is to load any firmwaremanagement
Quoted 1 line
Quoted 1 line
protocol (or fmp) drivers contained in a capsule, find out an
appropriate
Quoted 1 line
Quoted 1 line
fmp driver and then invoke its
set_image()interface against eachbinary
Quoted 94 lines
Quoted 72 lines
in a capsule.
In this commit, however, loading drivers is not supported.The result of applying a capsule is set to be stored in "CapsuleXXXX" variable, but its implementation is deferred to a fmp driver.
Signed-off-by AKASHI Takahiro <[email protected]>--- include/efi_api.h | 129 +++++++++++++++++++ include/efi_loader.h | 2 + lib/efi_loader/Kconfig | 8 ++ lib/efi_loader/efi_capsule.c | 238 ++++++++++++++++++++++++++++++++++- lib/efi_loader/efi_setup.c | 4 + 5 files changed, 380 insertions(+), 1 deletion(-)include/efi_api.h +34
-0@@ -217,6 +217,9 @@ enum efi_reset_type {#define CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE 0x00020000#define CAPSULE_FLAGS_INITIATE_RESET 0x00040000 +#define CAPSULE_SUPPORT_AUTHENTICATION 0x0000000000000001 +#define CAPSULE_SUPPORT_DEPENDENCY 0x0000000000000002 +#define EFI_CAPSULE_REPORT_GUID \ EFI_GUID(0x39b68c46, 0xf7fb, 0x441b, 0xb6, 0xec, \ 0x16, 0xb0, 0xf6, 0x98, 0x21, 0xf3)@@ -225,6 +228,10 @@ enum efi_reset_type {EFI_GUID (0xde9f0ec ,0x88b6 ,0x428f ,0x97 ,0x7a , \ 0x25, 0x8f, 0x1d, 0xe, 0x5e, 0x72) +#define EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID \ + EFI_GUID(0x6dcbd5ed, 0xe82d, 0x4c44, 0xbd, 0xa1, \ + 0x71, 0x94, 0x19, 0x9a, 0xd9, 0x2a) +struct efi_capsule_header {efi_guid_t capsule_guid;u32 header_size;@@ -253,6 +260,33 @@ struct efi_memory_range_capsule {struct efi_memory_range memory_ranges[]; } __packed; +struct efi_firmware_management_capsule_header { +u32 version; +u16 embedded_driver_count; +u16 payload_item_count; +u64 item_offset_list[]; +} __packed; + +struct efi_firmware_management_capsule_image_header { +u32 version; +efi_guid_t update_image_type_id; +u8 update_image_index; +u8 reserved[3 ]; +u32 update_image_size; +u32 update_vendor_code_size; +u64 update_hardware_instance; +u64 image_capsule_support; +} __packed; + +struct efi_capsule_result_variable_fmp { +u16 version; +u8 payload_index; +u8 update_image_index; +efi_guid_t update_image_type_id; +// u16 capsule_file_name[]; +// u16 capsule_target[]; +} __packed; +<snip>
Quoted 18 lines
include/efi_api.h +18
-0+/** +* efi_capsule_update_firmware - update firmware from capsule +* @capsule_data: Capsule +* +* Update firmware, using a capsule, @capsule_data. Loading any FMP +* drivers embedded in a capsule is not supported. +* +* Return: status code +*/ +static efi_status_t efi_capsule_update_firmware ( +struct efi_capsule_header *capsule_data) +{ +struct efi_firmware_management_capsule_header *capsule; +struct efi_firmware_management_capsule_image_header *image; +size_t capsule_size; +void *image_binary, *vendor_code; +efi_handle_t *handles; +efi_uintn_t no_handles;Quoted 8 lines
include/efi_api.h
Quoted 8 lines
include/efi_api.h +8
-0+int item; +struct efi_firmware_management_protocol *fmp; +u16 *abort_reason; +efi_status_t ret =EFI_SUCCESS ; + +/* sanity check */ +if (capsule_data->header_size <sizeof (*capsule) || + capsule_data->header_size >=
capsule_data->capsule_image_size)Quoted 26 lines
Quoted 26 lines
include/efi_api.h +26
-0+return EFI_INVALID_PARAMETER ; + + capsule = (void *)capsule_data + capsule_data->header_size; + capsule_size = capsule_data->capsule_image_size + - capsule_data->header_size; + +if (capsule->version !=0x00000001 ) +return EFI_INVALID_PARAMETER ; + +/* Drivers */ +/* TODO: support loading drivers */ + + handles =NULL ; + ret =EFI_CALL (efi_locate_handle_buffer ( +BY_PROTOCOL , + &efi_guid_firmware_management_protocol, +NULL , &no_handles, (efi_handle_t **)&handles)); +if (ret !=EFI_SUCCESS ) +return EFI_UNSUPPORTED ; + +/* Payload */ +for (item = capsule->embedded_driver_count; + item < capsule->embedded_driver_count + + capsule->payload_item_count; item++) { +/* sanity check */ + if ((capsule->item_offset_list[item] + sizeof(*image)Quoted 8 lines
include/efi_api.h
Quoted 8 lines
include/efi_api.h +2
-0+ >= capsule_size)) { + printf("EFI: A capsule has not enough size ofdata\n");
include/efi_api.h +5
-0+ ret =EFI_INVALID_PARAMETER ; + goto out; + } + + image = (void *)capsule +capsule->item_offset_list[item];
Quoted 6 lines
Quoted 6 lines
include/efi_api.h +6
-0+ +if (image->version !=0x00000001 && + image->version !=0x00000002 && + image->version !=0x00000003 ) { + ret =EFI_INVALID_PARAMETER ; + goto out;Quoted 8 lines
include/efi_api.h
Quoted 8 lines
include/efi_api.h +4
-0+ } + +/* find a device for update firmware */ +/* TODO: should we pass index as well, or nothing but type? */
include/efi_api.h +3
-0+ fmp = efi_fmp_find(&image->update_image_type_id, + image->version == 0x1 ? 0 : +
image->update_hardware_instance,Quoted 3 lines
include/efi_api.h
Quoted 3 lines
include/efi_api.h +3
-0+ handles, no_handles); +if (!fmp) { + printf("EFI Capsule: driver not found forfirmware
Quoted 4 lines
include/efi_api.h
Quoted 4 lines
type: %pUl, hardware instance: %lld\n",
include/efi_api.h +3
-0+ &image->update_image_type_id, + image->version == 0x1 ? 0 : +
image->update_hardware_instance);Quoted 9 lines
include/efi_api.h
Quoted 7 lines
include/efi_api.h +6
-0+ ret =EFI_UNSUPPORTED ; + goto out; + } + +/* do it */ + image_binary = (void *)image +sizeof (*image);Sorry for not having spotted this earlier. But since we are supporting
the
Quoted 7 lines
first three versions of the struct
efi_firmware_management_capsule_image_header, the above logic needs to be changed to accomodate versions 1 and 2. So in case of a version 1 structure, the fieldsupdate_hardware_instanceandimage_capsule_supportneed to be discarded. Similarly for a version 2 structure, theimage_capsule_supportfield needs to be discarded while calculating theimage_binarypointer.
Quoted 7 lines
Thank you for catching this issue, you're right.
Given, however, that the firmware update is quite firmware-specific and that we don't have any "backward compatibility" requirement, it would be better to simply drop the support for previous versions and to support the current/latest one, in this case, 3.
The edk2 scripts which i use for generating the capsules are currently using version 2. So if it's not too much of a hassle, i will prefer having support for version 2 at least. However, if you don't want to respin the series again, I can take care of this in my series for adding support for capsule update on the qemu arm platform.
-sughosh
Quoted 8 lines
We have a similar issue on 'struct
efi_firmware_image_descriptor'. I hope that imposing a version check/restriction won't bring any inconvenience to anybody.-Takahiro Akashi
Quoted 1 line
-sughosh
PATCH v9 4/11 efi_loader: capsule: support firmware update
Sughosh,
Quoted 205 lines · Sughosh Ganu
Takahiro,
Quoted 200 lines · AKASHI Takahiro
Sughosh,
Quoted 3 lines · Sughosh Ganu
hi Takahiro,
On Tue, 17 Nov 2020 at 05:58, AKASHI Takahiro <
takahiro.akashi at linaro.org>
Quoted 3 lines
Quoted 1 line · wrote:
A capsule tagged with the guid,
EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID,Quoted 2 lines
Quoted 2 lines
is handled as a firmware update object.
Whatefi_update_capsule()basically does is to load any firmwaremanagement
Quoted 1 line
Quoted 1 line
protocol (or fmp) drivers contained in a capsule, find out an
appropriate
Quoted 1 line
Quoted 1 line
fmp driver and then invoke its
set_image()interface against eachbinary
Quoted 94 lines
Quoted 72 lines
in a capsule.
In this commit, however, loading drivers is not supported.The result of applying a capsule is set to be stored in "CapsuleXXXX" variable, but its implementation is deferred to a fmp driver.
Signed-off-by AKASHI Takahiro <[email protected]>--- include/efi_api.h | 129 +++++++++++++++++++ include/efi_loader.h | 2 + lib/efi_loader/Kconfig | 8 ++ lib/efi_loader/efi_capsule.c | 238 ++++++++++++++++++++++++++++++++++- lib/efi_loader/efi_setup.c | 4 + 5 files changed, 380 insertions(+), 1 deletion(-)include/efi_api.h +34
-0@@ -217,6 +217,9 @@ enum efi_reset_type {#define CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE 0x00020000#define CAPSULE_FLAGS_INITIATE_RESET 0x00040000 +#define CAPSULE_SUPPORT_AUTHENTICATION 0x0000000000000001 +#define CAPSULE_SUPPORT_DEPENDENCY 0x0000000000000002 +#define EFI_CAPSULE_REPORT_GUID \ EFI_GUID(0x39b68c46, 0xf7fb, 0x441b, 0xb6, 0xec, \ 0x16, 0xb0, 0xf6, 0x98, 0x21, 0xf3)@@ -225,6 +228,10 @@ enum efi_reset_type {EFI_GUID (0xde9f0ec ,0x88b6 ,0x428f ,0x97 ,0x7a , \ 0x25, 0x8f, 0x1d, 0xe, 0x5e, 0x72) +#define EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID \ + EFI_GUID(0x6dcbd5ed, 0xe82d, 0x4c44, 0xbd, 0xa1, \ + 0x71, 0x94, 0x19, 0x9a, 0xd9, 0x2a) +struct efi_capsule_header {efi_guid_t capsule_guid;u32 header_size;@@ -253,6 +260,33 @@ struct efi_memory_range_capsule {struct efi_memory_range memory_ranges[]; } __packed; +struct efi_firmware_management_capsule_header { +u32 version; +u16 embedded_driver_count; +u16 payload_item_count; +u64 item_offset_list[]; +} __packed; + +struct efi_firmware_management_capsule_image_header { +u32 version; +efi_guid_t update_image_type_id; +u8 update_image_index; +u8 reserved[3 ]; +u32 update_image_size; +u32 update_vendor_code_size; +u64 update_hardware_instance; +u64 image_capsule_support; +} __packed; + +struct efi_capsule_result_variable_fmp { +u16 version; +u8 payload_index; +u8 update_image_index; +efi_guid_t update_image_type_id; +// u16 capsule_file_name[]; +// u16 capsule_target[]; +} __packed; +<snip>
Quoted 18 lines
include/efi_api.h +18
-0+/** +* efi_capsule_update_firmware - update firmware from capsule +* @capsule_data: Capsule +* +* Update firmware, using a capsule, @capsule_data. Loading any FMP +* drivers embedded in a capsule is not supported. +* +* Return: status code +*/ +static efi_status_t efi_capsule_update_firmware ( +struct efi_capsule_header *capsule_data) +{ +struct efi_firmware_management_capsule_header *capsule; +struct efi_firmware_management_capsule_image_header *image; +size_t capsule_size; +void *image_binary, *vendor_code; +efi_handle_t *handles; +efi_uintn_t no_handles;Quoted 8 lines
include/efi_api.h
Quoted 8 lines
include/efi_api.h +8
-0+int item; +struct efi_firmware_management_protocol *fmp; +u16 *abort_reason; +efi_status_t ret =EFI_SUCCESS ; + +/* sanity check */ +if (capsule_data->header_size <sizeof (*capsule) || + capsule_data->header_size >=
capsule_data->capsule_image_size)Quoted 26 lines
Quoted 26 lines
include/efi_api.h +26
-0+return EFI_INVALID_PARAMETER ; + + capsule = (void *)capsule_data + capsule_data->header_size; + capsule_size = capsule_data->capsule_image_size + - capsule_data->header_size; + +if (capsule->version !=0x00000001 ) +return EFI_INVALID_PARAMETER ; + +/* Drivers */ +/* TODO: support loading drivers */ + + handles =NULL ; + ret =EFI_CALL (efi_locate_handle_buffer ( +BY_PROTOCOL , + &efi_guid_firmware_management_protocol, +NULL , &no_handles, (efi_handle_t **)&handles)); +if (ret !=EFI_SUCCESS ) +return EFI_UNSUPPORTED ; + +/* Payload */ +for (item = capsule->embedded_driver_count; + item < capsule->embedded_driver_count + + capsule->payload_item_count; item++) { +/* sanity check */ + if ((capsule->item_offset_list[item] + sizeof(*image)Quoted 8 lines
include/efi_api.h
Quoted 8 lines
include/efi_api.h +2
-0+ >= capsule_size)) { + printf("EFI: A capsule has not enough size ofdata\n");
include/efi_api.h +5
-0+ ret =EFI_INVALID_PARAMETER ; + goto out; + } + + image = (void *)capsule +capsule->item_offset_list[item];
Quoted 6 lines
Quoted 6 lines
include/efi_api.h +6
-0+ +if (image->version !=0x00000001 && + image->version !=0x00000002 && + image->version !=0x00000003 ) { + ret =EFI_INVALID_PARAMETER ; + goto out;Quoted 8 lines
include/efi_api.h
Quoted 8 lines
include/efi_api.h +4
-0+ } + +/* find a device for update firmware */ +/* TODO: should we pass index as well, or nothing but type? */
include/efi_api.h +3
-0+ fmp = efi_fmp_find(&image->update_image_type_id, + image->version == 0x1 ? 0 : +
image->update_hardware_instance,Quoted 3 lines
include/efi_api.h
Quoted 3 lines
include/efi_api.h +3
-0+ handles, no_handles); +if (!fmp) { + printf("EFI Capsule: driver not found forfirmware
Quoted 4 lines
include/efi_api.h
Quoted 4 lines
type: %pUl, hardware instance: %lld\n",
include/efi_api.h +3
-0+ &image->update_image_type_id, + image->version == 0x1 ? 0 : +
image->update_hardware_instance);Quoted 9 lines
include/efi_api.h
Quoted 7 lines
include/efi_api.h +6
-0+ ret =EFI_UNSUPPORTED ; + goto out; + } + +/* do it */ + image_binary = (void *)image +sizeof (*image);Sorry for not having spotted this earlier. But since we are supporting
the
Quoted 7 lines
first three versions of the struct
efi_firmware_management_capsule_image_header, the above logic needs to be changed to accomodate versions 1 and 2. So in case of a version 1 structure, the fieldsupdate_hardware_instanceandimage_capsule_supportneed to be discarded. Similarly for a version 2 structure, theimage_capsule_supportfield needs to be discarded while calculating theimage_binarypointer.Thank you for catching this issue, you're right.
Quoted 8 lines
Quoted 5 lines
Given, however, that the firmware update is quite firmware-specific and that we don't have any "backward compatibility" requirement, it would be better to simply drop the support for previous versions and to support the current/latest one, in this case, 3.
The edk2 scripts which i use for generating the capsules are currently using version 2.
Personally, I think edk2's script should be updated to catch up with the latest specification.
Quoted 4 lines
So if it's not too much of a hassle, i will prefer having support for version 2 at least. However, if you don't want to respin the series again, I can take care of this in my series for adding support for capsule update on the qemu arm platform.
I will have to respin the code to drop the current "half-baked" support for previous versions if Heinrich anticipates it.
After that, it's up to you to implement additional support as a follow-up patch.
-Takahiro Akashi
Quoted 11 lines
-sughosh
Quoted 8 lines
We have a similar issue on 'struct
efi_firmware_image_descriptor'. I hope that imposing a version check/restriction won't bring any inconvenience to anybody.-Takahiro Akashi
Quoted 1 line
-sughosh
PATCH v9 4/11 efi_loader: capsule: support firmware update
In reply to AKASHI TakahiroQuoted 353 lines · AKASHI Takahiro
A capsule tagged with the guid,
EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID, is handled as a firmware update object.
Whatefi_update_capsule()basically does is to load any firmware management protocol (or fmp) drivers contained in a capsule, find out an appropriate fmp driver and then invoke itsset_image()interface against each binary in a capsule.
In this commit, however, loading drivers is not supported.The result of applying a capsule is set to be stored in "CapsuleXXXX" variable, but its implementation is deferred to a fmp driver.
Signed-off-by AKASHI Takahiro <[email protected]>--- include/efi_api.h | 129 +++++++++++++++++++ include/efi_loader.h | 2 + lib/efi_loader/Kconfig | 8 ++ lib/efi_loader/efi_capsule.c | 238 ++++++++++++++++++++++++++++++++++- lib/efi_loader/efi_setup.c | 4 + 5 files changed, 380 insertions(+), 1 deletion(-)include/efi_api.h +129
-0@@ -217,6 +217,9 @@ enum efi_reset_type {#define CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE 0x00020000#define CAPSULE_FLAGS_INITIATE_RESET 0x00040000 +#define CAPSULE_SUPPORT_AUTHENTICATION 0x0000000000000001 +#define CAPSULE_SUPPORT_DEPENDENCY 0x0000000000000002 +#define EFI_CAPSULE_REPORT_GUID \ EFI_GUID(0x39b68c46, 0xf7fb, 0x441b, 0xb6, 0xec, \ 0x16, 0xb0, 0xf6, 0x98, 0x21, 0xf3)@@ -225,6 +228,10 @@ enum efi_reset_type {EFI_GUID (0xde9f0ec ,0x88b6 ,0x428f ,0x97 ,0x7a , \ 0x25, 0x8f, 0x1d, 0xe, 0x5e, 0x72) +#define EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID \ + EFI_GUID(0x6dcbd5ed, 0xe82d, 0x4c44, 0xbd, 0xa1, \ + 0x71, 0x94, 0x19, 0x9a, 0xd9, 0x2a) +struct efi_capsule_header {efi_guid_t capsule_guid;u32 header_size;@@ -253,6 +260,33 @@ struct efi_memory_range_capsule {struct efi_memory_range memory_ranges[]; } __packed; +struct efi_firmware_management_capsule_header { +u32 version; +u16 embedded_driver_count; +u16 payload_item_count; +u64 item_offset_list[]; +} __packed; + +struct efi_firmware_management_capsule_image_header { +u32 version; +efi_guid_t update_image_type_id; +u8 update_image_index; +u8 reserved[3 ]; +u32 update_image_size; +u32 update_vendor_code_size; +u64 update_hardware_instance; +u64 image_capsule_support; +} __packed; + +struct efi_capsule_result_variable_fmp { +u16 version; +u8 payload_index; +u8 update_image_index; +efi_guid_t update_image_type_id; +// u16 capsule_file_name[]; +// u16 capsule_target[]; +} __packed; +#define EFI_RT_SUPPORTED_GET_TIME 0x0001#define EFI_RT_SUPPORTED_SET_TIME 0x0002#define EFI_RT_SUPPORTED_GET_WAKEUP_TIME 0x0004@@ -1808,4 +1842,99 @@ struct efi_signature_list {/* struct efi_signature_data signatures[...][signature_size]; */ } __attribute__((__packed__)); +/* +* Firmware management protocol +*/ +#define EFI_FIRMWARE_MANAGEMENT_PROTOCOL_GUID \ + EFI_GUID(0x86c77a67, 0x0b97, 0x4633, 0xa1, 0x87, \ + 0x49, 0x10, 0x4d, 0x06, 0x85, 0xc7) + +#define IMAGE_ATTRIBUTE_IMAGE_UPDATABLE 0x0000000000000001 +#define IMAGE_ATTRIBUTE_RESET_REQUIRED 0x0000000000000002 +#define IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED 0x0000000000000004 +#define IMAGE_ATTRIBUTE_IN_USE 0x0000000000000008 +#define IMAGE_ATTRIBUTE_UEFI_IMAGE 0x0000000000000010 +#define IMAGE_ATTRIBUTE_DEPENDENCY 0x0000000000000020 + +#define IMAGE_COMPATIBILITY_CHECK_SUPPORTED 0x0000000000000001 + +#define IMAGE_UPDATABLE_VALID 0x0000000000000001 +#define IMAGE_UPDATABLE_INVALID 0x0000000000000002 +#define IMAGE_UPDATABLE_INVALID_TYPE 0x0000000000000004 +#define IMAGE_UPDATABLE_INVALID_OLLD 0x0000000000000008 +#define IMAGE_UPDATABLE_VALID_WITH_VENDOR_CODE 0x0000000000000010 + +#define PACKAGE_ATTRIBUTE_VERSION_UPDATABLE 0x0000000000000001 +#define PACKAGE_ATTRIBUTE_RESET_REQUIRED 0x0000000000000002 +#define PACKAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED 0x0000000000000004 + +#define EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION 4 + +typedef struct efi_firmware_image_dependencies { +u8 dependencies[0 ]; +}efi_firmware_image_dep_t ; + +struct efi_firmware_image_descriptor { +u8 image_index; +efi_guid_t image_type_id; +u64 image_id; +u16 *image_id_name; +u32 version; +u16 *version_name; +efi_uintn_t size; +u64 attributes_supported; +u64 attributes_setting; +u64 compatibilities; +u32 lowest_supported_image_version; +u32 last_attempt_version; +u32 last_attempt_status; +u64 hardware_instance; +efi_firmware_image_dep_t *dependencies; +}; + +struct efi_firmware_management_protocol { + efi_status_t (EFIAPI *get_image_info)( + struct efi_firmware_management_protocol *this, + efi_uintn_t *image_info_size, + struct efi_firmware_image_descriptor *image_info, + u32 *descriptor_version, + u8 *descriptor_count, + efi_uintn_t *descriptor_size, + u32 *package_version, + u16 **package_version_name); + efi_status_t (EFIAPI *get_image)( + struct efi_firmware_management_protocol *this, + u8 image_index, + void *image, + efi_uintn_t *image_size); + efi_status_t (EFIAPI *set_image)( + struct efi_firmware_management_protocol *this, + u8 image_index, + const void *image, + efi_uintn_t image_size, + const void *vendor_code, + efi_status_t (*progress)(efi_uintn_t completion), + u16 **abort_reason); + efi_status_t (EFIAPI *check_image)( + struct efi_firmware_management_protocol *this, + u8 image_index, + const void *image, + efi_uintn_t *image_size, + u32 *image_updatable); + efi_status_t (EFIAPI *get_package_info)( + struct efi_firmware_management_protocol *this, + u32 *package_version, + u16 **package_version_name, + u32 *package_version_name_maxlen, + u64 *attributes_supported, + u64 *attributes_setting); + efi_status_t (EFIAPI *set_package_info)( + struct efi_firmware_management_protocol *this, + const void *image, + efi_uintn_t *image_size, + const void *vendor_code, + u32 package_version, + const u16 *package_version_name); +}; +#endif include/efi_loader.h +2
-0@@ -209,6 +209,8 @@ extern const efi_guid_t efi_guid_cert_type_pkcs7;extern const efi_guid_t efi_guid_rng_protocol;/* GUID of capsule update result */ extern const efi_guid_t efi_guid_capsule_report; +/* GUID of firmware management protocol */ +extern const efi_guid_t efi_guid_firmware_management_protocol;extern unsigned int __efi_runtime_start, __efi_runtime_stop;extern unsigned int __efi_runtime_rel_start, __efi_runtime_rel_stop;lib/efi_loader/Kconfig +8
-0@@ -126,6 +126,14 @@ config EFI_CAPSULE_ON_DISK_EARLY executed as part of U-Boot initialisation so that they will surely take place whatever is set to distro_bootcmd. +config EFI_CAPSULE_FIRMWARE_MANAGEMENT + bool "Capsule: Firmware Management Protocol" + depends on EFI_HAVE_CAPSULE_SUPPORT + default y + help + Select this option if you want to enable capsule-based + firmware update using Firmware Management Protocol. + config EFI_DEVICE_PATH_TO_TEXT bool "Device path to text protocol" default ylib/efi_loader/efi_capsule.c +127
-0@@ -15,6 +15,10 @@#include <sort.h> const efi_guid_t efi_guid_capsule_report =EFI_CAPSULE_REPORT_GUID ; +static const efi_guid_t efi_guid_firmware_management_capsule_id = +EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID ; +const efi_guid_t efi_guid_firmware_management_protocol = +EFI_FIRMWARE_MANAGEMENT_PROTOCOL_GUID ;#ifdef CONFIG_EFI_CAPSULE_ON_DISK /* for file system access */ @@ -88,6 +92,218 @@ void set_capsule_result(int index, struct efi_capsule_header *capsule,printf ("EFI: creating %ls failed\n" , variable_name16); } +#ifdef CONFIG_EFI_CAPSULE_FIRMWARE_MANAGEMENT +/** +* efi_fmp_find - search for Firmware Management Protocol drivers +* @image_type: Image type guid +* @instance: Instance number +* @handles: Handles of FMP drivers +* @no_handles: Number of handles +* +* Search for Firmware Management Protocol drivers, matching the image +* type, @image_type and the machine instance, @instance, from the list, +* @handles. +* +* Return: +* * Protocol instance - on success +* * NULL - on failure +*/ +static struct efi_firmware_management_protocol * +efi_fmp_find (efi_guid_t *image_type,u64 instance,efi_handle_t *handles, +efi_uintn_t no_handles) +{ +efi_handle_t *handle; +struct efi_firmware_management_protocol *fmp; +struct efi_firmware_image_descriptor *image_info, *desc; +efi_uintn_t info_size, descriptor_size; +u32 descriptor_version; +u8 descriptor_count; +u32 package_version; +u16 *package_version_name; +bool found = false; +int i, j; +efi_status_t ret; + +for (i =0 , handle = handles; i < no_handles; i++, handle++) { + ret =EFI_CALL (efi_handle_protocol ( + *handle, + &efi_guid_firmware_management_protocol, + (void **)&fmp)); +if (ret !=EFI_SUCCESS ) +continue ; + +/* get device's image info */ + info_size =0 ; + image_info =NULL ; + descriptor_version =0 ; + descriptor_count =0 ; + descriptor_size =0 ; + package_version =0 ; + package_version_name =NULL ; + ret =EFI_CALL (fmp->get_image_info (fmp, &info_size, + image_info, + &descriptor_version, + &descriptor_count, + &descriptor_size, + &package_version, + &package_version_name)); +if (ret !=EFI_BUFFER_TOO_SMALL ) + goto skip; + + image_info =malloc (info_size); +if (!image_info) + goto skip; + + ret =EFI_CALL (fmp->get_image_info (fmp, &info_size, + image_info, + &descriptor_version, + &descriptor_count, + &descriptor_size, + &package_version, + &package_version_name)); +if (ret !=EFI_SUCCESS ) + goto skip; + +/* matching */ +for (j =0 , desc = image_info; j < descriptor_count; + j++, desc = (void *)desc + descriptor_size) { +EFI_PRINT ("+++ desc[%d] index: %d, name: %ls\n" , + j, desc->image_index, desc->image_id_name); +if (!guidcmp (&desc->image_type_id, image_type) && + (!instance || + !desc->hardware_instance || + (descriptor_version >=3 && + desc->hardware_instance == instance))) + found = true; + } + +skip: +efi_free_pool (package_version_name); +free (image_info); +EFI_CALL (efi_close_protocol ( + (efi_handle_t )fmp, + &efi_guid_firmware_management_protocol, +NULL ,NULL )); +if (found) +return fmp; + } + +return NULL ; +} + +/** +* efi_capsule_update_firmware - update firmware from capsule +* @capsule_data: Capsule +* +* Update firmware, using a capsule, @capsule_data. Loading any FMP +* drivers embedded in a capsule is not supported. +* +* Return: status code +*/ +static efi_status_t efi_capsule_update_firmware ( +struct efi_capsule_header *capsule_data) +{ +struct efi_firmware_management_capsule_header *capsule; +struct efi_firmware_management_capsule_image_header *image; +size_t capsule_size; +void *image_binary, *vendor_code; +efi_handle_t *handles; +efi_uintn_t no_handles; +int item; +struct efi_firmware_management_protocol *fmp; +u16 *abort_reason; +efi_status_t ret =EFI_SUCCESS ; + +/* sanity check */
lib/efi_loader/efi_capsule.c void set_capsule_result(int index, struct efi_capsule_header *capsule, · line 227
Quoted 10 lines
lib/efi_loader/efi_capsule.c +10
-0+if (capsule_data->header_size <sizeof (*capsule) || + capsule_data->header_size >= capsule_data->capsule_image_size) +return EFI_INVALID_PARAMETER ; + + capsule = (void *)capsule_data + capsule_data->header_size; + capsule_size = capsule_data->capsule_image_size + - capsule_data->header_size; + +if (capsule->version !=0x00000001 ) +return EFI_INVALID_PARAMETER ;
For an unsupported capsule format we should return EFI_UNSUPPORTED according to the spec.
lib/efi_loader/efi_capsule.c void set_capsule_result(int index, struct efi_capsule_header *capsule, · line 230
Quoted 3 lines
lib/efi_loader/efi_capsule.c +3
-0+ +/* Drivers */ +/* TODO: support loading drivers */
Please, describe the requirement in the spec that you do not yet fulfill yet more clearly.
Quoted 7 lines
lib/efi_loader/efi_capsule.c +7
-0+ + handles =NULL ; + ret =EFI_CALL (efi_locate_handle_buffer ( +BY_PROTOCOL , + &efi_guid_firmware_management_protocol, +NULL , &no_handles, (efi_handle_t **)&handles)); +if (ret !=EFI_SUCCESS )
lib/efi_loader/efi_capsule.c void set_capsule_result(int index, struct efi_capsule_header *capsule, · line 247
Quoted 10 lines
lib/efi_loader/efi_capsule.c +10
-0+return EFI_UNSUPPORTED ; + +/* Payload */ +for (item = capsule->embedded_driver_count; + item < capsule->embedded_driver_count + + capsule->payload_item_count; item++) { +/* sanity check */ +if ((capsule->item_offset_list[item] +sizeof (*image) + >= capsule_size)) { +printf ("EFI: A capsule has not enough size of data\n" );
%s/enough size of data/enough data/
lib/efi_loader/efi_capsule.c void set_capsule_result(int index, struct efi_capsule_header *capsule, · line 259
Quoted 12 lines
lib/efi_loader/efi_capsule.c +12
-0+ ret =EFI_INVALID_PARAMETER ; + goto out; + } + + image = (void *)capsule + capsule->item_offset_list[item]; + +if (image->version !=0x00000001 && + image->version !=0x00000002 && + image->version !=0x00000003 ) { + ret =EFI_INVALID_PARAMETER ; + goto out; + }
UEFI 2.8 has EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER.Version = 3. Why should we support outdated versions?
Do you really support all three versions? Are they all tested? Sughosh's mail sounded like 'no'.
For unsupported capsule format the return value should be EFI_UNSUPPORTED.
lib/efi_loader/efi_capsule.c void set_capsule_result(int index, struct efi_capsule_header *capsule, · line 262
Quoted 3 lines
lib/efi_loader/efi_capsule.c +3
-0+ +/* find a device for update firmware */ +/* TODO: should we pass index as well, or nothing but type? */
Does this mean that the patch is not yet ready for merging?
Quoted 4 lines
lib/efi_loader/efi_capsule.c +4
-0+ fmp =efi_fmp_find (&image->update_image_type_id, + image->version ==0x1 ?0 : + image->update_hardware_instance, + handles, no_handles);
lib/efi_loader/efi_capsule.c void set_capsule_result(int index, struct efi_capsule_header *capsule, · line 276
Quoted 10 lines
lib/efi_loader/efi_capsule.c +10
-0+if (!fmp) { +printf ("EFI Capsule: driver not found for firmware type: %pUl, hardware instance: %lld\n" , + &image->update_image_type_id, + image->version ==0x1 ?0 : + image->update_hardware_instance); + ret =EFI_UNSUPPORTED ; + goto out; + } + +/* do it */
Do what?
lib/efi_loader/efi_capsule.c void set_capsule_result(int index, struct efi_capsule_header *capsule, · line 288
Quoted 12 lines
lib/efi_loader/efi_capsule.c +12
-0+ image_binary = (void *)image +sizeof (*image); + vendor_code = image_binary + image->update_image_size; + + abort_reason =NULL ; + ret =EFI_CALL (fmp->set_image (fmp, image->update_image_index, + image_binary, + image->update_image_size, + vendor_code,NULL , + &abort_reason)); +if (ret !=EFI_SUCCESS ) { +printf ("EFI Capsule: firmware update failed: %ls\n" , + abort_reason);
Why don't you use log_err() or EFI_PRINT()?
Quoted 23 lines
lib/efi_loader/efi_capsule.c +18
-0+efi_free_pool (abort_reason); + goto out; + } + } + +out: +efi_free_pool (handles); + +return ret; +} +#else +static efi_status_t efi_capsule_update_firmware ( +struct efi_capsule_header *capsule_data) +{ +return EFI_UNSUPPORTED ; +} +#endif /* CONFIG_EFI_CAPSULE_FIRMWARE_MANAGEMENT */ +/** * efi_update_capsule() - process information from operating system * @capsule_header_array: Array of virtual address pointers @@ -118,9 +334,29 @@ efi_status_t EFIAPI efi_update_capsule( goto out;
lib/efi_loader/efi_capsule.c efi_status_t EFIAPI efi_update_capsule( · line 343
Quoted 10 lines
lib/efi_loader/efi_capsule.c +5
-1} - ret =EFI_UNSUPPORTED ; + ret =EFI_SUCCESS ;for (i =0 , capsule = *capsule_header_array; i < capsule_count; i++, capsule = *(++capsule_header_array)) { +/* sanity check */ +if (capsule->header_size <sizeof (*capsule) || + capsule->capsule_image_size <sizeof (*capsule)) { +printf ("EFI: A capsule has not enough size of data\n" );
%s/enough size of data/enough data/
lib/efi_loader/efi_capsule.c efi_status_t EFIAPI efi_update_capsule( · line 344
Quoted 1 line
lib/efi_loader/efi_capsule.c +1
-0+continue ;
You print an error message above. Why don't you exit with an error status?
Best regards
Heinrich
Quoted 34 lines
lib/efi_loader/efi_capsule.c +15
-0+ } + +EFI_PRINT ("Capsule[%d] (guid:%pUl)\n" , + i, &capsule->capsule_guid); +if (!guidcmp (&capsule->capsule_guid, + &efi_guid_firmware_management_capsule_id)) { + ret =efi_capsule_update_firmware (capsule); + }else { +printf ("EFI: not support capsule type: %pUl\n" , + &capsule->capsule_guid); + ret =EFI_UNSUPPORTED ; + } + +if (ret !=EFI_SUCCESS ) + goto out; } out:return EFI_EXIT (ret);lib/efi_loader/efi_setup.c +4
-0@@ -159,6 +159,10 @@ static efi_status_t efi_init_os_indications(void) os_indications_supported |=EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED ; +if (IS_ENABLED (CONFIG_EFI_CAPSULE_FIRMWARE_MANAGEMENT )) + os_indications_supported |= +EFI_OS_INDICATIONS_FMP_CAPSULE_SUPPORTED ; + return efi_set_variable_int(L"OsIndicationsSupported", &efi_global_variable_guid, EFI_VARIABLE_BOOTSERVICE_ACCESS |
PATCH v9 4/11 efi_loader: capsule: support firmware update
Heinrich,
Quoted 359 lines · Heinrich Schuchardt
Quoted 358 lines · AKASHI Takahiro
A capsule tagged with the guid,
EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID, is handled as a firmware update object.
Whatefi_update_capsule()basically does is to load any firmware management protocol (or fmp) drivers contained in a capsule, find out an appropriate fmp driver and then invoke itsset_image()interface against each binary in a capsule.
In this commit, however, loading drivers is not supported.The result of applying a capsule is set to be stored in "CapsuleXXXX" variable, but its implementation is deferred to a fmp driver.
Signed-off-by AKASHI Takahiro <[email protected]>--- include/efi_api.h | 129 +++++++++++++++++++ include/efi_loader.h | 2 + lib/efi_loader/Kconfig | 8 ++ lib/efi_loader/efi_capsule.c | 238 ++++++++++++++++++++++++++++++++++- lib/efi_loader/efi_setup.c | 4 + 5 files changed, 380 insertions(+), 1 deletion(-)include/efi_api.h +129
-0@@ -217,6 +217,9 @@ enum efi_reset_type {#define CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE 0x00020000#define CAPSULE_FLAGS_INITIATE_RESET 0x00040000 +#define CAPSULE_SUPPORT_AUTHENTICATION 0x0000000000000001 +#define CAPSULE_SUPPORT_DEPENDENCY 0x0000000000000002 +#define EFI_CAPSULE_REPORT_GUID \ EFI_GUID(0x39b68c46, 0xf7fb, 0x441b, 0xb6, 0xec, \ 0x16, 0xb0, 0xf6, 0x98, 0x21, 0xf3)@@ -225,6 +228,10 @@ enum efi_reset_type {EFI_GUID (0xde9f0ec ,0x88b6 ,0x428f ,0x97 ,0x7a , \ 0x25, 0x8f, 0x1d, 0xe, 0x5e, 0x72) +#define EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID \ + EFI_GUID(0x6dcbd5ed, 0xe82d, 0x4c44, 0xbd, 0xa1, \ + 0x71, 0x94, 0x19, 0x9a, 0xd9, 0x2a) +struct efi_capsule_header {efi_guid_t capsule_guid;u32 header_size;@@ -253,6 +260,33 @@ struct efi_memory_range_capsule {struct efi_memory_range memory_ranges[]; } __packed; +struct efi_firmware_management_capsule_header { +u32 version; +u16 embedded_driver_count; +u16 payload_item_count; +u64 item_offset_list[]; +} __packed; + +struct efi_firmware_management_capsule_image_header { +u32 version; +efi_guid_t update_image_type_id; +u8 update_image_index; +u8 reserved[3 ]; +u32 update_image_size; +u32 update_vendor_code_size; +u64 update_hardware_instance; +u64 image_capsule_support; +} __packed; + +struct efi_capsule_result_variable_fmp { +u16 version; +u8 payload_index; +u8 update_image_index; +efi_guid_t update_image_type_id; +// u16 capsule_file_name[]; +// u16 capsule_target[]; +} __packed; +#define EFI_RT_SUPPORTED_GET_TIME 0x0001#define EFI_RT_SUPPORTED_SET_TIME 0x0002#define EFI_RT_SUPPORTED_GET_WAKEUP_TIME 0x0004@@ -1808,4 +1842,99 @@ struct efi_signature_list {/* struct efi_signature_data signatures[...][signature_size]; */ } __attribute__((__packed__)); +/* +* Firmware management protocol +*/ +#define EFI_FIRMWARE_MANAGEMENT_PROTOCOL_GUID \ + EFI_GUID(0x86c77a67, 0x0b97, 0x4633, 0xa1, 0x87, \ + 0x49, 0x10, 0x4d, 0x06, 0x85, 0xc7) + +#define IMAGE_ATTRIBUTE_IMAGE_UPDATABLE 0x0000000000000001 +#define IMAGE_ATTRIBUTE_RESET_REQUIRED 0x0000000000000002 +#define IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED 0x0000000000000004 +#define IMAGE_ATTRIBUTE_IN_USE 0x0000000000000008 +#define IMAGE_ATTRIBUTE_UEFI_IMAGE 0x0000000000000010 +#define IMAGE_ATTRIBUTE_DEPENDENCY 0x0000000000000020 + +#define IMAGE_COMPATIBILITY_CHECK_SUPPORTED 0x0000000000000001 + +#define IMAGE_UPDATABLE_VALID 0x0000000000000001 +#define IMAGE_UPDATABLE_INVALID 0x0000000000000002 +#define IMAGE_UPDATABLE_INVALID_TYPE 0x0000000000000004 +#define IMAGE_UPDATABLE_INVALID_OLLD 0x0000000000000008 +#define IMAGE_UPDATABLE_VALID_WITH_VENDOR_CODE 0x0000000000000010 + +#define PACKAGE_ATTRIBUTE_VERSION_UPDATABLE 0x0000000000000001 +#define PACKAGE_ATTRIBUTE_RESET_REQUIRED 0x0000000000000002 +#define PACKAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED 0x0000000000000004 + +#define EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION 4 + +typedef struct efi_firmware_image_dependencies { +u8 dependencies[0 ]; +}efi_firmware_image_dep_t ; + +struct efi_firmware_image_descriptor { +u8 image_index; +efi_guid_t image_type_id; +u64 image_id; +u16 *image_id_name; +u32 version; +u16 *version_name; +efi_uintn_t size; +u64 attributes_supported; +u64 attributes_setting; +u64 compatibilities; +u32 lowest_supported_image_version; +u32 last_attempt_version; +u32 last_attempt_status; +u64 hardware_instance; +efi_firmware_image_dep_t *dependencies; +}; + +struct efi_firmware_management_protocol { + efi_status_t (EFIAPI *get_image_info)( + struct efi_firmware_management_protocol *this, + efi_uintn_t *image_info_size, + struct efi_firmware_image_descriptor *image_info, + u32 *descriptor_version, + u8 *descriptor_count, + efi_uintn_t *descriptor_size, + u32 *package_version, + u16 **package_version_name); + efi_status_t (EFIAPI *get_image)( + struct efi_firmware_management_protocol *this, + u8 image_index, + void *image, + efi_uintn_t *image_size); + efi_status_t (EFIAPI *set_image)( + struct efi_firmware_management_protocol *this, + u8 image_index, + const void *image, + efi_uintn_t image_size, + const void *vendor_code, + efi_status_t (*progress)(efi_uintn_t completion), + u16 **abort_reason); + efi_status_t (EFIAPI *check_image)( + struct efi_firmware_management_protocol *this, + u8 image_index, + const void *image, + efi_uintn_t *image_size, + u32 *image_updatable); + efi_status_t (EFIAPI *get_package_info)( + struct efi_firmware_management_protocol *this, + u32 *package_version, + u16 **package_version_name, + u32 *package_version_name_maxlen, + u64 *attributes_supported, + u64 *attributes_setting); + efi_status_t (EFIAPI *set_package_info)( + struct efi_firmware_management_protocol *this, + const void *image, + efi_uintn_t *image_size, + const void *vendor_code, + u32 package_version, + const u16 *package_version_name); +}; +#endif include/efi_loader.h +2
-0@@ -209,6 +209,8 @@ extern const efi_guid_t efi_guid_cert_type_pkcs7;extern const efi_guid_t efi_guid_rng_protocol;/* GUID of capsule update result */ extern const efi_guid_t efi_guid_capsule_report; +/* GUID of firmware management protocol */ +extern const efi_guid_t efi_guid_firmware_management_protocol;extern unsigned int __efi_runtime_start, __efi_runtime_stop;extern unsigned int __efi_runtime_rel_start, __efi_runtime_rel_stop;lib/efi_loader/Kconfig +8
-0@@ -126,6 +126,14 @@ config EFI_CAPSULE_ON_DISK_EARLY executed as part of U-Boot initialisation so that they will surely take place whatever is set to distro_bootcmd. +config EFI_CAPSULE_FIRMWARE_MANAGEMENT + bool "Capsule: Firmware Management Protocol" + depends on EFI_HAVE_CAPSULE_SUPPORT + default y + help + Select this option if you want to enable capsule-based + firmware update using Firmware Management Protocol. + config EFI_DEVICE_PATH_TO_TEXT bool "Device path to text protocol" default ylib/efi_loader/efi_capsule.c +132
-0@@ -15,6 +15,10 @@#include <sort.h> const efi_guid_t efi_guid_capsule_report =EFI_CAPSULE_REPORT_GUID ; +static const efi_guid_t efi_guid_firmware_management_capsule_id = +EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID ; +const efi_guid_t efi_guid_firmware_management_protocol = +EFI_FIRMWARE_MANAGEMENT_PROTOCOL_GUID ;#ifdef CONFIG_EFI_CAPSULE_ON_DISK /* for file system access */ @@ -88,6 +92,218 @@ void set_capsule_result(int index, struct efi_capsule_header *capsule,printf ("EFI: creating %ls failed\n" , variable_name16); } +#ifdef CONFIG_EFI_CAPSULE_FIRMWARE_MANAGEMENT +/** +* efi_fmp_find - search for Firmware Management Protocol drivers +* @image_type: Image type guid +* @instance: Instance number +* @handles: Handles of FMP drivers +* @no_handles: Number of handles +* +* Search for Firmware Management Protocol drivers, matching the image +* type, @image_type and the machine instance, @instance, from the list, +* @handles. +* +* Return: +* * Protocol instance - on success +* * NULL - on failure +*/ +static struct efi_firmware_management_protocol * +efi_fmp_find (efi_guid_t *image_type,u64 instance,efi_handle_t *handles, +efi_uintn_t no_handles) +{ +efi_handle_t *handle; +struct efi_firmware_management_protocol *fmp; +struct efi_firmware_image_descriptor *image_info, *desc; +efi_uintn_t info_size, descriptor_size; +u32 descriptor_version; +u8 descriptor_count; +u32 package_version; +u16 *package_version_name; +bool found = false; +int i, j; +efi_status_t ret; + +for (i =0 , handle = handles; i < no_handles; i++, handle++) { + ret =EFI_CALL (efi_handle_protocol ( + *handle, + &efi_guid_firmware_management_protocol, + (void **)&fmp)); +if (ret !=EFI_SUCCESS ) +continue ; + +/* get device's image info */ + info_size =0 ; + image_info =NULL ; + descriptor_version =0 ; + descriptor_count =0 ; + descriptor_size =0 ; + package_version =0 ; + package_version_name =NULL ; + ret =EFI_CALL (fmp->get_image_info (fmp, &info_size, + image_info, + &descriptor_version, + &descriptor_count, + &descriptor_size, + &package_version, + &package_version_name)); +if (ret !=EFI_BUFFER_TOO_SMALL ) + goto skip; + + image_info =malloc (info_size); +if (!image_info) + goto skip; + + ret =EFI_CALL (fmp->get_image_info (fmp, &info_size, + image_info, + &descriptor_version, + &descriptor_count, + &descriptor_size, + &package_version, + &package_version_name)); +if (ret !=EFI_SUCCESS ) + goto skip; + +/* matching */ +for (j =0 , desc = image_info; j < descriptor_count; + j++, desc = (void *)desc + descriptor_size) { +EFI_PRINT ("+++ desc[%d] index: %d, name: %ls\n" , + j, desc->image_index, desc->image_id_name); +if (!guidcmp (&desc->image_type_id, image_type) && + (!instance || + !desc->hardware_instance || + (descriptor_version >=3 && + desc->hardware_instance == instance))) + found = true; + } + +skip: +efi_free_pool (package_version_name); +free (image_info); +EFI_CALL (efi_close_protocol ( + (efi_handle_t )fmp, + &efi_guid_firmware_management_protocol, +NULL ,NULL )); +if (found) +return fmp; + } + +return NULL ; +} + +/** +* efi_capsule_update_firmware - update firmware from capsule +* @capsule_data: Capsule +* +* Update firmware, using a capsule, @capsule_data. Loading any FMP +* drivers embedded in a capsule is not supported. +* +* Return: status code +*/ +static efi_status_t efi_capsule_update_firmware ( +struct efi_capsule_header *capsule_data) +{ +struct efi_firmware_management_capsule_header *capsule; +struct efi_firmware_management_capsule_image_header *image; +size_t capsule_size; +void *image_binary, *vendor_code; +efi_handle_t *handles; +efi_uintn_t no_handles; +int item; +struct efi_firmware_management_protocol *fmp; +u16 *abort_reason; +efi_status_t ret =EFI_SUCCESS ; + +/* sanity check */ +if (capsule_data->header_size <sizeof (*capsule) || + capsule_data->header_size >= capsule_data->capsule_image_size) +return EFI_INVALID_PARAMETER ; + + capsule = (void *)capsule_data + capsule_data->header_size;
Quoted 8 lines
lib/efi_loader/efi_capsule.c void set_capsule_result(int index, struct efi_capsule_header *capsule, · line 227
Quoted 5 lines
lib/efi_loader/efi_capsule.c +5
-0+ capsule_size = capsule_data->capsule_image_size + - capsule_data->header_size; + +if (capsule->version !=0x00000001 ) +return EFI_INVALID_PARAMETER ;For an unsupported capsule format we should return
EFI_UNSUPPORTEDaccording to the spec.
I don't mind which error should be returned here, but I didn't find any explicit description for the case. Did you?
Quoted 6 lines
lib/efi_loader/efi_capsule.c void set_capsule_result(int index, struct efi_capsule_header *capsule, · line 230
Quoted 3 lines
lib/efi_loader/efi_capsule.c +3
-0+ +/* Drivers */ +/* TODO: support loading drivers */ Please, describe the requirement in the spec that you do not yet fulfill yet more clearly.
Driver is a driver, I think that the description is trivial. Anyhow, this is not "TODO" as U-Boot has no ability to load/ support any dynamic modules.
So it would be better to drop the text itself.
Quoted 11 lines
Quoted 11 lines
lib/efi_loader/efi_capsule.c +11
-0+ + handles =NULL ; + ret =EFI_CALL (efi_locate_handle_buffer ( +BY_PROTOCOL , + &efi_guid_firmware_management_protocol, +NULL , &no_handles, (efi_handle_t **)&handles)); +if (ret !=EFI_SUCCESS ) +return EFI_UNSUPPORTED ; + +/* Payload */ + for (item = capsule->embedded_driver_count;
Quoted 8 lines
lib/efi_loader/efi_capsule.c void set_capsule_result(int index, struct efi_capsule_header *capsule, · line 247
Quoted 6 lines
lib/efi_loader/efi_capsule.c +6
-0+ item < capsule->embedded_driver_count + + capsule->payload_item_count; item++) { +/* sanity check */ +if ((capsule->item_offset_list[item] +sizeof (*image) + >= capsule_size)) { +printf ("EFI: A capsule has not enough size of data\n" );%s/enough size of data/enough data/
I don't think that it is a wrong English, but I don't care either.
Quoted 16 lines
lib/efi_loader/efi_capsule.c void set_capsule_result(int index, struct efi_capsule_header *capsule, · line 259
Quoted 12 lines
lib/efi_loader/efi_capsule.c +12
-0+ ret =EFI_INVALID_PARAMETER ; + goto out; + } + + image = (void *)capsule + capsule->item_offset_list[item]; + +if (image->version !=0x00000001 && + image->version !=0x00000002 && + image->version !=0x00000003 ) { + ret =EFI_INVALID_PARAMETER ; + goto out; + }UEFI 2.8 has EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER.Version = 3. Why should we support outdated versions?
Quoted 2 lines
Do you really support all three versions? Are they all tested? Sughosh's mail sounded like 'no'.
That's why I said, in my reply to Sughosh, that I would drop the code for *half-baked* support.
Quoted 1 line
For unsupported capsule format the return value should be
EFI_UNSUPPORTED.
See above.
Quoted 5 lines
lib/efi_loader/efi_capsule.c void set_capsule_result(int index, struct efi_capsule_header *capsule, · line 262
Quoted 3 lines
lib/efi_loader/efi_capsule.c +3
-0+ +/* find a device for update firmware */ +/* TODO: should we pass index as well, or nothing but type? */ Does this mean that the patch is not yet ready for merging?
I'm asking.
If you don't mind, I will drop the text here.
Quoted 8 lines
Quoted 8 lines
lib/efi_loader/efi_capsule.c +8
-0+ fmp =efi_fmp_find (&image->update_image_type_id, + image->version ==0x1 ?0 : + image->update_hardware_instance, + handles, no_handles); +if (!fmp) { + printf("EFI Capsule: driver not found for firmware type: %pUl, hardware instance: %lld\n", + &image->update_image_type_id, + image->version == 0x1 ? 0 :
Quoted 8 lines
lib/efi_loader/efi_capsule.c void set_capsule_result(int index, struct efi_capsule_header *capsule, · line 276
Quoted 6 lines
lib/efi_loader/efi_capsule.c +6
-0+ image->update_hardware_instance); + ret =EFI_UNSUPPORTED ; + goto out; + } + +/* do it */ Do what?
Do update (set_image).
Quoted 15 lines
lib/efi_loader/efi_capsule.c void set_capsule_result(int index, struct efi_capsule_header *capsule, · line 288
Quoted 13 lines
lib/efi_loader/efi_capsule.c +12
-0+ image_binary = (void *)image +sizeof (*image); + vendor_code = image_binary + image->update_image_size; + + abort_reason =NULL ; + ret =EFI_CALL (fmp->set_image (fmp, image->update_image_index, + image_binary, + image->update_image_size, + vendor_code,NULL , + &abort_reason)); +if (ret !=EFI_SUCCESS ) { +printf ("EFI Capsule: firmware update failed: %ls\n" , + abort_reason);Why don't you use
log_err()orEFI_PRINT()?
In the past, I used to use printf().
You recently changed your policy, preferring log_xxx().
Quoted 36 lines
Quoted 23 lines
lib/efi_loader/efi_capsule.c +18
-0+efi_free_pool (abort_reason); + goto out; + } + } + +out: +efi_free_pool (handles); + +return ret; +} +#else +static efi_status_t efi_capsule_update_firmware ( +struct efi_capsule_header *capsule_data) +{ +return EFI_UNSUPPORTED ; +} +#endif /* CONFIG_EFI_CAPSULE_FIRMWARE_MANAGEMENT */ +/** * efi_update_capsule() - process information from operating system * @capsule_header_array: Array of virtual address pointers @@ -118,9 +334,29 @@ efi_status_t EFIAPI efi_update_capsule( goto out;lib/efi_loader/efi_capsule.c efi_status_t EFIAPI efi_update_capsule( · line 343
Quoted 10 lines
lib/efi_loader/efi_capsule.c +5
-1} - ret =EFI_UNSUPPORTED ; + ret =EFI_SUCCESS ;for (i =0 , capsule = *capsule_header_array; i < capsule_count; i++, capsule = *(++capsule_header_array)) { +/* sanity check */ +if (capsule->header_size <sizeof (*capsule) || + capsule->capsule_image_size <sizeof (*capsule)) { +printf ("EFI: A capsule has not enough size of data\n" );%s/enough size of data/enough data/
Quoted 3 lines
lib/efi_loader/efi_capsule.c efi_status_t EFIAPI efi_update_capsule( · line 344
Quoted 1 line
lib/efi_loader/efi_capsule.c +1
-0+continue ;You print an error message above. Why don't you exit with an error status?
Different capsules may modify different part of system images (or different firmware).
So one failure may not always imply the immediate termination of the whole process.
I think that, without any concrete "recovery" story, it would make little sense to discuss this issue.
Sughosh will have a future plan of, what is said, A/B update.
-Takahiro Akashi
Quoted 39 lines
Best regards
Heinrich
Quoted 34 lines
lib/efi_loader/efi_capsule.c +15
-0+ } + +EFI_PRINT ("Capsule[%d] (guid:%pUl)\n" , + i, &capsule->capsule_guid); +if (!guidcmp (&capsule->capsule_guid, + &efi_guid_firmware_management_capsule_id)) { + ret =efi_capsule_update_firmware (capsule); + }else { +printf ("EFI: not support capsule type: %pUl\n" , + &capsule->capsule_guid); + ret =EFI_UNSUPPORTED ; + } + +if (ret !=EFI_SUCCESS ) + goto out; } out:return EFI_EXIT (ret);lib/efi_loader/efi_setup.c +4
-0@@ -159,6 +159,10 @@ static efi_status_t efi_init_os_indications(void) os_indications_supported |=EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED ; +if (IS_ENABLED (CONFIG_EFI_CAPSULE_FIRMWARE_MANAGEMENT )) + os_indications_supported |= +EFI_OS_INDICATIONS_FMP_CAPSULE_SUPPORTED ; + return efi_set_variable_int(L"OsIndicationsSupported", &efi_global_variable_guid, EFI_VARIABLE_BOOTSERVICE_ACCESS |
PATCH v9 5/11 efi_loader: add firmware management protocol for FIT image
In reply to AKASHI TakahiroIn this commit, a very simple firmware management protocol driver is implemented. It will take a common FIT image firmware in a capsule file and apply the data using dfu backend storage drivers via update_fit() interface.
So "dfu_alt_info" variable should be properly set to specify a device and location to be updated. Please read README.dfu.
Fit image is a common file format for firmware update on U-Boot, and this protocol works neatly just as a wrapper for one.
--- include/efi_api.h | 4 + include/efi_loader.h | 2 + lib/efi_loader/Kconfig | 11 ++ lib/efi_loader/Makefile | 1 + lib/efi_loader/efi_capsule.c | 12 +- lib/efi_loader/efi_firmware.c | 291 ++++++++++++++++++++++++++++++++++ 6 files changed, 320 insertions(+), 1 deletion(-) create mode 100644 lib/efi_loader/efi_firmware.c
include/efi_api.h +4 -0
@@ -1849,6 +1849,10 @@ struct efi_signature_list {EFI_GUID (0x86c77a67 ,0x0b97 ,0x4633 ,0xa1 ,0x87 , \ 0x49, 0x10, 0x4d, 0x06, 0x85, 0xc7) +#define EFI_FIRMWARE_IMAGE_TYPE_UBOOT_FIT_GUID \ + EFI_GUID(0xae13ff2d, 0x9ad4, 0x4e25, 0x9a, 0xc8, \ + 0x6d, 0x80, 0xb3, 0xb2, 0x21, 0x47) +#define IMAGE_ATTRIBUTE_IMAGE_UPDATABLE 0x0000000000000001#define IMAGE_ATTRIBUTE_RESET_REQUIRED 0x0000000000000002#define IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED 0x0000000000000004
include/efi_loader.h +2 -0
@@ -811,6 +811,8 @@ void efi_memcpy_runtime(void *dest, const void *src, size_t n);/* commonly used helper function */ u16 *efi_create_indexed_name (u16 *buffer,const char *name,unsigned int index); +extern const struct efi_firmware_management_protocol efi_fmp_fit; +/* Capsule update */ efi_status_t EFIAPI efi_update_capsule( struct efi_capsule_header **capsule_header_array,
lib/efi_loader/Kconfig +11 -0
@@ -134,6 +134,17 @@ 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 image" + depends on EFI_CAPSULE_FIRMWARE_MANAGEMENT + depends on FIT + select UPDATE_FIT + select DFU + default n + help + Select this option if you want to enable firmware management protocol + driver for FIT image + config EFI_DEVICE_PATH_TO_TEXT bool "Device path to text protocol" default y
lib/efi_loader/Makefile +1 -0
@@ -24,6 +24,7 @@ obj-$(CONFIG_CMD_BOOTEFI_HELLO) += helloworld_efi.o obj-y += efi_bootmgr.o obj-y += efi_boottime.o obj-$(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) += efi_capsule.o +obj-$(CONFIG_EFI_CAPSULE_FIRMWARE_FIT) += efi_firmware.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
lib/efi_loader/efi_capsule.c +11 -1
@@ -804,7 +804,17 @@ static void efi_capsule_scan_done(void)*/ efi_status_t __weak arch_efi_load_capsule_drivers (void ) { -return EFI_SUCCESS ; +__maybe_unused efi_handle_t handle; +efi_status_t ret =EFI_SUCCESS ; + +if (IS_ENABLED (CONFIG_EFI_CAPSULE_FIRMWARE_FIT )) { + handle =NULL ; + ret =EFI_CALL (efi_install_multiple_protocol_interfaces ( + &handle, &efi_guid_firmware_management_protocol, + &efi_fmp_fit,NULL )); + } + +return ret; }/**
lib/efi_loader/efi_firmware.c new file +291 -0
291 lines not on this page · raw message
Signature · 1 line
2.28.0
PATCH v9 6/11 efi_loader: add firmware management protocol for raw image
In reply to AKASHI TakahiroIn this commit, a very simple firmware management protocol driver is implemented. It will take a binary image in a capsule file and apply the data using dfu backend storage drivers via dfu_write_by_alt() interface.
So "dfu_alt_info" variable should be properly set to specify a device and location to be updated. Please read README.dfu.
--- include/efi_api.h | 4 + include/efi_loader.h | 1 + lib/efi_loader/Kconfig | 16 +++ lib/efi_loader/Makefile | 2 +- lib/efi_loader/efi_capsule.c | 8 ++ lib/efi_loader/efi_firmware.c | 226 +++++++++++++++++++++++++--------- 6 files changed, 199 insertions(+), 58 deletions(-)
include/efi_api.h +4 -0
@@ -1853,6 +1853,10 @@ struct efi_signature_list {EFI_GUID (0xae13ff2d ,0x9ad4 ,0x4e25 ,0x9a ,0xc8 , \ 0x6d, 0x80, 0xb3, 0xb2, 0x21, 0x47) +#define EFI_FIRMWARE_IMAGE_TYPE_UBOOT_RAW_GUID \ + EFI_GUID(0xe2bb9c06, 0x70e9, 0x4b14, 0x97, 0xa3, \ + 0x5a, 0x79, 0x13, 0x17, 0x6e, 0x3f) +#define IMAGE_ATTRIBUTE_IMAGE_UPDATABLE 0x0000000000000001#define IMAGE_ATTRIBUTE_RESET_REQUIRED 0x0000000000000002#define IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED 0x0000000000000004
include/efi_loader.h +1 -0
@@ -812,6 +812,7 @@ void efi_memcpy_runtime(void *dest, const void *src, size_t n);u16 *efi_create_indexed_name (u16 *buffer,const char *name,unsigned int index);extern const struct efi_firmware_management_protocol efi_fmp_fit; +extern const struct efi_firmware_management_protocol efi_fmp_raw;/* Capsule update */ efi_status_t EFIAPI efi_update_capsule(
lib/efi_loader/Kconfig +16 -0
@@ -126,6 +126,10 @@ config EFI_CAPSULE_ON_DISK_EARLY executed as part of U-Boot initialisation so that they will surely take place whatever is set to distro_bootcmd. +config EFI_CAPSULE_FIRMWARE + bool + default n + config EFI_CAPSULE_FIRMWARE_MANAGEMENT bool "Capsule: Firmware Management Protocol" depends on EFI_HAVE_CAPSULE_SUPPORT
@@ -140,11 +144,23 @@ config EFI_CAPSULE_FIRMWARE_FIT 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
lib/efi_loader/Makefile +1 -1
@@ -24,7 +24,7 @@ obj-$(CONFIG_CMD_BOOTEFI_HELLO) += helloworld_efi.o obj-y += efi_bootmgr.o obj-y += efi_boottime.o obj-$(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) += efi_capsule.o -obj-$(CONFIG_EFI_CAPSULE_FIRMWARE_FIT) += efi_firmware.o +obj-$(CONFIG_EFI_CAPSULE_FIRMWARE) += efi_firmware.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
lib/efi_loader/efi_capsule.c +8 -0
@@ -814,6 +814,14 @@ efi_status_t __weak arch_efi_load_capsule_drivers(void) &efi_fmp_fit, NULL)); } +if (IS_ENABLED (CONFIG_EFI_CAPSULE_FIRMWARE_RAW )) { + handle =NULL ; + ret =EFI_CALL (efi_install_multiple_protocol_interfaces ( + &efi_root, + &efi_guid_firmware_management_protocol, + &efi_fmp_raw,NULL )); + } +return ret; }
lib/efi_loader/efi_firmware.c +169 -57
269 lines not on this page · raw message
Signature · 1 line
2.28.0
PATCH v9 7/11 cmd: add "efidebug capsule" command
In reply to AKASHI Takahiro"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable
--- cmd/efidebug.c | 235 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 235 insertions(+)
cmd/efidebug.c +235 -0
@@ -19,6 +19,228 @@#include <linux/ctype.h> #define BS systab.boottime +#define RT systab.runtime + +#ifdef CONFIG_EFI_HAVE_CAPSULE_SUPPORT +/** +* do_efi_capsule_update() - process a capsule update +* +* @cmdtp: Command table +* @flag: Command flag +* @argc: Number of arguments +* @argv: Argument array +* Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure +* +* Implement efidebug "capsule update" sub-command. +* process a capsule update. +* +* efidebug capsule update [-v] <capsule address> +*/ +static int do_efi_capsule_update (struct cmd_tbl *cmdtp,int flag, +int argc,char *const argv[]) +{ +struct efi_capsule_header *capsule; +int verbose =0 ; +char *endp; +efi_status_t ret; + +if (argc !=2 && argc !=3 ) +return CMD_RET_USAGE ; + +if (argc ==3 ) { +if (strcmp (argv[1 ],"-v" )) +return CMD_RET_USAGE ; + + verbose =1 ; + argc--; + argv++; + } + + capsule = (typeof (capsule ))simple_strtoul (argv[1 ], &endp,16 ); +if (endp == argv[1 ]) { +printf ("Invalid address: %s" , argv[1 ]); +return CMD_RET_FAILURE ; + } + +if (verbose) { +printf ("Capsule guid: %pUl\n" , &capsule->capsule_guid); +printf ("Capsule flags: 0x%x\n" , capsule->flags); +printf ("Capsule header size: 0x%x\n" , capsule->header_size); +printf ("Capsule image size: 0x%x\n" , + capsule->capsule_image_size); + } + + ret =EFI_CALL (RT ->update_capsule (&capsule,1 , (u64 )NULL )); +if (ret) { +printf ("Cannot handle a capsule at %p" , capsule); +return CMD_RET_FAILURE ; + } + +return CMD_RET_SUCCESS ; +} + +/** +* do_efi_capsule_show() - show capsule information +* +* @cmdtp: Command table +* @flag: Command flag +* @argc: Number of arguments +* @argv: Argument array +* Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure +* +* Implement efidebug "capsule show" sub-command. +* show capsule information. +* +* efidebug capsule show <capsule address> +*/ +static int do_efi_capsule_show (struct cmd_tbl *cmdtp,int flag, +int argc,char *const argv[]) +{ +struct efi_capsule_header *capsule; +char *endp; + +if (argc !=2 ) +return CMD_RET_USAGE ; + + capsule = (typeof (capsule ))simple_strtoul (argv[1 ], &endp,16 ); +if (endp == argv[1 ]) { +printf ("Invalid address: %s" , argv[1 ]); +return CMD_RET_FAILURE ; + } + +printf ("Capsule guid: %pUl\n" , &capsule->capsule_guid); +printf ("Capsule flags: 0x%x\n" , capsule->flags); +printf ("Capsule header size: 0x%x\n" , capsule->header_size); +printf ("Capsule image size: 0x%x\n" , + capsule->capsule_image_size); + +return CMD_RET_SUCCESS ; +} + +/** +* do_efi_capsule_res() - show a capsule update result +* +* @cmdtp: Command table +* @flag: Command flag +* @argc: Number of arguments +* @argv: Argument array +* Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure +* +* Implement efidebug "capsule result" sub-command. +* show a capsule update result. +* If result number is not specified, CapsuleLast will be shown. +* +* efidebug capsule result [<capsule result number>] +*/ +static int do_efi_capsule_res (struct cmd_tbl *cmdtp,int flag, +int argc,char *const argv[]) +{ +int capsule_id; +char *endp; +char var_name[12 ]; +u16 var_name16[12 ], *p; +efi_guid_t guid; +struct efi_capsule_result_variable_header *result =NULL ; +efi_uintn_t size; +efi_status_t ret; + +if (argc !=1 && argc !=2 ) +return CMD_RET_USAGE ; + + guid = efi_guid_capsule_report; +if (argc ==1 ) { + size =sizeof (var_name16); + ret =EFI_CALL (RT ->get_variable (L"CapsuleLast" , &guid,NULL , + &size, var_name16)); +if (ret !=EFI_SUCCESS ) { +if (ret ==EFI_NOT_FOUND ) +printf ("CapsuleLast doesn't exist\n" ); +else +printf ("Failed to get CapsuleLast\n" ); + +return CMD_RET_FAILURE ; + } +printf ("CapsuleLast is %ls\n" , var_name16); + }else { + argc--; + argv++; + + capsule_id =simple_strtoul (argv[0 ], &endp,16 ); +if (capsule_id <0 || capsule_id >0xffff ) +return CMD_RET_USAGE ; + +sprintf (var_name,"Capsule%04X" , capsule_id); + p = var_name16; +utf8_utf16_strncpy (&p, var_name,9 ); + } + + size =0 ; + ret =EFI_CALL (RT ->get_variable (var_name16, &guid,NULL , &size,NULL )); +if (ret ==EFI_BUFFER_TOO_SMALL ) { + result =malloc (size); + ret =EFI_CALL (RT ->get_variable (var_name16, &guid,NULL , &size, + result)); +if (ret !=EFI_SUCCESS ) { +free (result); +printf ("Failed to get %ls\n" , var_name16); + +return CMD_RET_FAILURE ; + } + } + +printf ("Result total size: 0x%x\n" , result->variable_total_size); +printf ("Capsule guid: %pUl\n" , &result->capsule_guid); +printf ("Time processed: %04d-%02d-%02d %02d:%02d:%02d\n" , + result->capsule_processed.year, result->capsule_processed.month, + result->capsule_processed.day, result->capsule_processed.hour, + result->capsule_processed.minute, + result->capsule_processed.second); +printf ("Capsule status: 0x%lx\n" , result->capsule_status); + +free (result); + +return CMD_RET_SUCCESS ; +} + +static struct cmd_tbl cmd_efidebug_capsule_sub[] = { +U_BOOT_CMD_MKENT (update,CONFIG_SYS_MAXARGS ,1 , do_efi_capsule_update, +"" ,"" ), +U_BOOT_CMD_MKENT (show,CONFIG_SYS_MAXARGS ,1 , do_efi_capsule_show, +"" ,"" ), +U_BOOT_CMD_MKENT (result,CONFIG_SYS_MAXARGS ,1 , do_efi_capsule_res, +"" ,"" ), +}; + +/** +* do_efi_capsule() - manage UEFI capsules +* +* @cmdtp: Command table +* @flag: Command flag +* @argc: Number of arguments +* @argv: Argument array +* Return: CMD_RET_SUCCESS on success, +* CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure +* +* Implement efidebug "capsule" sub-command. +*/ +static int do_efi_capsule (struct cmd_tbl *cmdtp,int flag, +int argc,char *const argv[]) +{ +struct cmd_tbl *cp; + +if (argc <2 ) +return CMD_RET_USAGE ; + + argc--; argv++; + + cp =find_cmd_tbl (argv[0 ], cmd_efidebug_capsule_sub, +ARRAY_SIZE (cmd_efidebug_capsule_sub)); +if (!cp) +return CMD_RET_USAGE ; + +return cp->cmd (cmdtp, flag, argc, argv); +} +#endif /* CONFIG_EFI_HAVE_CAPSULE_SUPPORT */ /** * efi_get_device_handle_info() - get information of UEFI device
@@ -1237,6 +1459,10 @@ static int do_efi_query_info(struct cmd_tbl *cmdtp, int flag,static struct cmd_tbl cmd_efidebug_sub[] = {U_BOOT_CMD_MKENT (boot,CONFIG_SYS_MAXARGS ,1 , do_efi_boot_opt,"" ,"" ), +#ifdef CONFIG_EFI_HAVE_CAPSULE_SUPPORT +U_BOOT_CMD_MKENT (capsule,CONFIG_SYS_MAXARGS ,1 , do_efi_capsule, +"" ,"" ), +#endifU_BOOT_CMD_MKENT (devices,CONFIG_SYS_MAXARGS ,1 , do_efi_show_devices,"" ,"" ), U_BOOT_CMD_MKENT(drivers, CONFIG_SYS_MAXARGS, 1, do_efi_show_drivers,
@@ -1311,6 +1537,15 @@ static char efidebug_help_text[] = "efidebug boot order [<bootid#1> [<bootid#2> [<bootid#3> [...]]]]\n" " - set/show UEFI boot order\n" "\n" +#ifdef CONFIG_EFI_HAVE_CAPSULE_SUPPORT + "efidebug capsule update [-v] <capsule address>\n" + " - process a capsule\n" + "efidebug capsule show <capsule address>\n" + " - show capsule information\n" + "efidebug capsule result [<capsule result var>]\n" + " - show a capsule update result\n" + "\n" +#endif"efidebug devices\n" " - show UEFI devices\n" "efidebug drivers\n"
Signature · 1 line
2.28.0
PATCH v9 8/11 tools: add mkeficapsule command for UEFI capsule update
In reply to AKASHI TakahiroThis is a utility mainly for test purpose.
mkeficapsule -f: create a test capsule file for FIT image firmware
Having said that, you will be able to customize the code to fit your specific requirements for your platform.
--- tools/Makefile | 2 + tools/mkeficapsule.c | 238 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 240 insertions(+) create mode 100644 tools/mkeficapsule.c
tools/Makefile +2 -0
@@ -218,6 +218,8 @@ hostprogs-$(CONFIG_MIPS) += mips-relocs hostprogs-$(CONFIG_ASN1_COMPILER) += asn1_compiler HOSTCFLAGS_asn1_compiler.o = -idirafter $(srctree)/include +hostprogs-$(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) += mkeficapsule + # We build some files with extra pedantic flags to try to minimize things # that won't build on some weird host compiler -- though there are lots of # exceptions for files that aren't complaint.
tools/mkeficapsule.c new file +238 -0
238 lines not on this page · raw message
Signature · 1 line
2.28.0
PATCH v9 8/11 tools: add mkeficapsule command for UEFI capsule update
Quoted 141 lines · AKASHI Takahiro
This is a utility mainly for test purpose.
mkeficapsule -f: create a test capsule file for FIT image firmwareHaving said that, you will be able to customize the code to fit your specific requirements for your platform.
Signed-off-by AKASHI Takahiro <[email protected]>--- tools/Makefile | 2 + tools/mkeficapsule.c | 238 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 240 insertions(+)create mode 100644
tools/mkeficapsule.ctools/Makefile +2
-0@@ -218,6 +218,8 @@ hostprogs-$(CONFIG_MIPS) += mips-relocs hostprogs-$(CONFIG_ASN1_COMPILER) += asn1_compiler HOSTCFLAGS_asn1_compiler.o = -idirafter $(srctree)/include +hostprogs-$(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) += mkeficapsule + # We build some files with extra pedantic flags to try to minimize things # that won't build on some weird host compiler -- though there are lots of # exceptions for files that aren't complaint.tools/mkeficapsule.c new file +109
-0@@ -0,0 +1,238 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright 2018 Linaro Limited +* Author: AKASHI Takahiro +*/ + +#include <getopt.h> +#include <malloc.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <linux/types.h> +#include <sys/stat.h> +#include <sys/types.h> + +typedef __u8 u8 ; +typedef __u16 u16 ; +typedef __u32 u32 ; +typedef __u64 u64 ; +typedef __s16 s16 ; +typedef __s32 s32 ; + +#define aligned_u64 __aligned_u64 + +#ifndef __packed +#define __packed __attribute__((packed)) +#endif + +#include <efi.h> +#include <efi_api.h> + +static const char *tool_name ="mkeficapsule" ; + +efi_guid_t efi_guid_fm_capsule =EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID ; +efi_guid_t efi_guid_image_type_uboot_fit = +EFI_FIRMWARE_IMAGE_TYPE_UBOOT_FIT_GUID ; +efi_guid_t efi_guid_image_type_uboot_raw = +EFI_FIRMWARE_IMAGE_TYPE_UBOOT_RAW_GUID ; + +static struct option options[] = { + {"fit" , required_argument,NULL ,'f' }, + {"raw" , required_argument,NULL ,'r' }, + {"index" , required_argument,NULL ,'i' }, + {"instance" , required_argument,NULL ,'I' }, + {"version" , required_argument,NULL ,'v' }, + {"help" , no_argument,NULL ,'h' }, + {NULL ,0 ,NULL ,0 }, +}; + +static void print_usage (void ) +{ +printf ("Usage: %s [options] <output file>\n" +"Options:\n" +"\t--fit <fit image> new FIT image file\n" +"\t--raw <raw image> new raw image file\n" +"\t--index <index> update image index\n" +"\t--instance <instance> update hardware instance\n" +"\t--version <version> firmware version\n" +"\t--help print a help message\n" , + tool_name); +} + +static int create_fwbin (char *path,char *bin,efi_guid_t *guid, +unsigned long version,unsigned long index, +unsigned long instance) +{ +struct efi_capsule_header header; +struct efi_firmware_management_capsule_header capsule; +struct efi_firmware_management_capsule_image_header image; +FILE *f, *g; +struct stat bin_stat; +u8 *data; +size_t size; + +#ifdef DEBUG +printf ("For output: %s\n" , path); +printf ("\tbin: %s\n\ttype: %pUl\n" bin, guid); +printf ("\tversion: %ld\n\tindex: %ld\n\tinstance: %ld\n" , + version, index, instance); +#endif + + g =fopen (bin,"r" ); +if (!g) { +printf ("cannot open %s\n" , bin); +return -1 ; + } +if (stat (bin, &bin_stat) <0 ) { +printf ("cannot determine the size of %s\n" , bin); + goto err_1; + } + data =malloc (bin_stat.st_size); +if (!data) { +printf ("cannot allocate memory: %lx\n" , bin_stat.st_size); + goto err_1; + } + f =fopen (path,"w" ); +if (!f) { +printf ("cannot open %s\n" , path); + goto err_2; + } + header.capsule_guid = efi_guid_fm_capsule; + header.header_size =sizeof (header); + header.flags =CAPSULE_FLAGS_PERSIST_ACROSS_RESET ;/* TODO */ + header.capsule_image_size =sizeof (header) + +sizeof (capsule) +sizeof (u64) + +sizeof (image) + + bin_stat.st_size; +
tools/mkeficapsule.c line 119
Quoted 10 lines
tools/mkeficapsule.c new file +10
-0+ size =fwrite (&header,1 ,sizeof (header), f); +if (size <sizeof (header)) { +printf ("write failed (%lx)\n" , size); + goto err_3; + } + + capsule.version =0x00000001 ; + capsule.embedded_driver_count =0 ; + capsule.payload_item_count =1 ; + capsule.item_offset_list[0 ] =sizeof (capsule) +sizeof (u64);
With the complete series applied, building sandbox_defconfig:
tools/mkeficapsule.c: In function ?main?:tools/mkeficapsule.c:120:26: warning: array subscript 0 is outside array bounds of ?u64[]? {aka ?long long unsigned int[]?} [-Warray-bounds]
120 | capsule.item_offset_list[0] = sizeof(capsule) + sizeof(u64);
| ~~~~~~~~~~~~~~~~~~~~~~~~^~~Please, ensure that the code compiles without warnings.
I have been using GCC 10.2 as supplied by Debian Bullseye on an ARM64 system.
Best regards
Heinrich
Quoted 120 lines
tools/mkeficapsule.c new file +119
-0+ size =fwrite (&capsule,1 ,sizeof (capsule) +sizeof (u64), f); +if (size < (sizeof (capsule) +sizeof (u64))) { +printf ("write failed (%lx)\n" , size); + goto err_3; + } + + image.version = version; +memcpy (&image.update_image_type_id, guid,sizeof (*guid)); + image.update_image_index = index; + image.update_image_size = bin_stat.st_size; + image.update_vendor_code_size =0 ;/* none */ + image.update_hardware_instance = instance; + image.image_capsule_support =0 ; + + size =fwrite (&image,1 ,sizeof (image), f); +if (size <sizeof (image)) { +printf ("write failed (%lx)\n" , size); + goto err_3; + } + size =fread (data,1 , bin_stat.st_size, g); +if (size < bin_stat.st_size) { +printf ("read failed (%lx)\n" , size); + goto err_3; + } + size =fwrite (data,1 , bin_stat.st_size, f); +if (size < bin_stat.st_size) { +printf ("write failed (%lx)\n" , size); + goto err_3; + } + +fclose (f); +fclose (g); +free (data); + +return 0 ; + +err_3: +fclose (f); +err_2: +free (data); +err_1: +fclose (g); + +return -1 ; +} + +/* +* Usage: +* $ mkeficapsule -f <firmware binary> <output file> +*/ +int main (int argc,char **argv) +{ +char *file; +efi_guid_t *guid; +unsigned long index, instance, version; +int c, idx; + + file =NULL ; + guid =NULL ; + index =0 ; + instance =0 ; + version =0 ; +for (;;) { + c =getopt_long (argc, argv,"f:r:i:I:v:h" , options, &idx); +if (c ==-1 ) +break ; + +switch (c) { +case 'f' : +if (file) { +printf ("Image already specified\n" ); +return -1 ; + } + file = optarg; + guid = &efi_guid_image_type_uboot_fit; +break ; +case 'r' : +if (file) { +printf ("Image already specified\n" ); +return -1 ; + } + file = optarg; + guid = &efi_guid_image_type_uboot_raw; +break ; +case 'i' : + index =strtoul (optarg,NULL ,0 ); +break ; +case 'I' : + instance =strtoul (optarg,NULL ,0 ); +break ; +case 'v' : + version =strtoul (optarg,NULL ,0 ); +break ; +case 'h' : +print_usage (); +return 0 ; + } + } + +/* need a output file */ +if (argc != optind +1 ) { +print_usage (); +return -1 ; + } + +/* need a fit image file or raw image file */ +if (!file) { +print_usage (); +return -1 ; + } + +if (create_fwbin (argv[optind], file, guid, version, index, instance) + <0 ) { +printf ("Creating firmware capsule failed\n" ); +return -1 ; + } + +return 0 ; +}
PATCH v9 8/11 tools: add mkeficapsule command for UEFI capsule update
Heinrich,
Quoted 155 lines · Heinrich Schuchardt
Quoted 141 lines · AKASHI Takahiro
This is a utility mainly for test purpose.
mkeficapsule -f: create a test capsule file for FIT image firmwareHaving said that, you will be able to customize the code to fit your specific requirements for your platform.
Signed-off-by AKASHI Takahiro <[email protected]>--- tools/Makefile | 2 + tools/mkeficapsule.c | 238 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 240 insertions(+)create mode 100644
tools/mkeficapsule.ctools/Makefile +2
-0@@ -218,6 +218,8 @@ hostprogs-$(CONFIG_MIPS) += mips-relocs hostprogs-$(CONFIG_ASN1_COMPILER) += asn1_compiler HOSTCFLAGS_asn1_compiler.o = -idirafter $(srctree)/include +hostprogs-$(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) += mkeficapsule + # We build some files with extra pedantic flags to try to minimize things # that won't build on some weird host compiler -- though there are lots of # exceptions for files that aren't complaint.tools/mkeficapsule.c new file +109
-0@@ -0,0 +1,238 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright 2018 Linaro Limited +* Author: AKASHI Takahiro +*/ + +#include <getopt.h> +#include <malloc.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <linux/types.h> +#include <sys/stat.h> +#include <sys/types.h> + +typedef __u8 u8 ; +typedef __u16 u16 ; +typedef __u32 u32 ; +typedef __u64 u64 ; +typedef __s16 s16 ; +typedef __s32 s32 ; + +#define aligned_u64 __aligned_u64 + +#ifndef __packed +#define __packed __attribute__((packed)) +#endif + +#include <efi.h> +#include <efi_api.h> + +static const char *tool_name ="mkeficapsule" ; + +efi_guid_t efi_guid_fm_capsule =EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID ; +efi_guid_t efi_guid_image_type_uboot_fit = +EFI_FIRMWARE_IMAGE_TYPE_UBOOT_FIT_GUID ; +efi_guid_t efi_guid_image_type_uboot_raw = +EFI_FIRMWARE_IMAGE_TYPE_UBOOT_RAW_GUID ; + +static struct option options[] = { + {"fit" , required_argument,NULL ,'f' }, + {"raw" , required_argument,NULL ,'r' }, + {"index" , required_argument,NULL ,'i' }, + {"instance" , required_argument,NULL ,'I' }, + {"version" , required_argument,NULL ,'v' }, + {"help" , no_argument,NULL ,'h' }, + {NULL ,0 ,NULL ,0 }, +}; + +static void print_usage (void ) +{ +printf ("Usage: %s [options] <output file>\n" +"Options:\n" +"\t--fit <fit image> new FIT image file\n" +"\t--raw <raw image> new raw image file\n" +"\t--index <index> update image index\n" +"\t--instance <instance> update hardware instance\n" +"\t--version <version> firmware version\n" +"\t--help print a help message\n" , + tool_name); +} + +static int create_fwbin (char *path,char *bin,efi_guid_t *guid, +unsigned long version,unsigned long index, +unsigned long instance) +{ +struct efi_capsule_header header; +struct efi_firmware_management_capsule_header capsule; +struct efi_firmware_management_capsule_image_header image; +FILE *f, *g; +struct stat bin_stat; +u8 *data; +size_t size; + +#ifdef DEBUG +printf ("For output: %s\n" , path); +printf ("\tbin: %s\n\ttype: %pUl\n" bin, guid); +printf ("\tversion: %ld\n\tindex: %ld\n\tinstance: %ld\n" , + version, index, instance); +#endif + + g =fopen (bin,"r" ); +if (!g) { +printf ("cannot open %s\n" , bin); +return -1 ; + } +if (stat (bin, &bin_stat) <0 ) { +printf ("cannot determine the size of %s\n" , bin); + goto err_1; + } + data =malloc (bin_stat.st_size); +if (!data) { +printf ("cannot allocate memory: %lx\n" , bin_stat.st_size); + goto err_1; + } + f =fopen (path,"w" ); +if (!f) { +printf ("cannot open %s\n" , path); + goto err_2; + } + header.capsule_guid = efi_guid_fm_capsule; + header.header_size =sizeof (header); + header.flags =CAPSULE_FLAGS_PERSIST_ACROSS_RESET ;/* TODO */ + header.capsule_image_size =sizeof (header) + +sizeof (capsule) +sizeof (u64) + +sizeof (image) + + bin_stat.st_size; +tools/mkeficapsule.c line 119
Quoted 10 lines
tools/mkeficapsule.c new file +10
-0+ size =fwrite (&header,1 ,sizeof (header), f); +if (size <sizeof (header)) { +printf ("write failed (%lx)\n" , size); + goto err_3; + } + + capsule.version =0x00000001 ; + capsule.embedded_driver_count =0 ; + capsule.payload_item_count =1 ; + capsule.item_offset_list[0 ] =sizeof (capsule) +sizeof (u64);With the complete series applied, building
sandbox_defconfig:
Quoted 7 lines
tools/mkeficapsule.c: In function ?main?:tools/mkeficapsule.c:120:26: warning: array subscript 0 is outside array bounds of ?u64[]? {aka ?long long unsigned int[]?} [-Warray-bounds]120 | capsule.item_offset_list[0] = sizeof(capsule) + sizeof(u64); | ~~~~~~~~~~~~~~~~~~~~~~~~^~~Please, ensure that the code compiles without warnings.
Fixing this warning would be easy, but I didn't see it with gcc9.2 (from Linaro/Arm) or even in the results of Travis CI.
So I wonder if it is mandatory that the code compiles without warnings, and if so, which compiler and which version are required?
-Takahiro Akashi
Quoted 128 lines
I have been using GCC 10.2 as supplied by Debian Bullseye on an ARM64 system.
Best regards
Heinrich
Quoted 120 lines
tools/mkeficapsule.c new file +119
-0+ size =fwrite (&capsule,1 ,sizeof (capsule) +sizeof (u64), f); +if (size < (sizeof (capsule) +sizeof (u64))) { +printf ("write failed (%lx)\n" , size); + goto err_3; + } + + image.version = version; +memcpy (&image.update_image_type_id, guid,sizeof (*guid)); + image.update_image_index = index; + image.update_image_size = bin_stat.st_size; + image.update_vendor_code_size =0 ;/* none */ + image.update_hardware_instance = instance; + image.image_capsule_support =0 ; + + size =fwrite (&image,1 ,sizeof (image), f); +if (size <sizeof (image)) { +printf ("write failed (%lx)\n" , size); + goto err_3; + } + size =fread (data,1 , bin_stat.st_size, g); +if (size < bin_stat.st_size) { +printf ("read failed (%lx)\n" , size); + goto err_3; + } + size =fwrite (data,1 , bin_stat.st_size, f); +if (size < bin_stat.st_size) { +printf ("write failed (%lx)\n" , size); + goto err_3; + } + +fclose (f); +fclose (g); +free (data); + +return 0 ; + +err_3: +fclose (f); +err_2: +free (data); +err_1: +fclose (g); + +return -1 ; +} + +/* +* Usage: +* $ mkeficapsule -f <firmware binary> <output file> +*/ +int main (int argc,char **argv) +{ +char *file; +efi_guid_t *guid; +unsigned long index, instance, version; +int c, idx; + + file =NULL ; + guid =NULL ; + index =0 ; + instance =0 ; + version =0 ; +for (;;) { + c =getopt_long (argc, argv,"f:r:i:I:v:h" , options, &idx); +if (c ==-1 ) +break ; + +switch (c) { +case 'f' : +if (file) { +printf ("Image already specified\n" ); +return -1 ; + } + file = optarg; + guid = &efi_guid_image_type_uboot_fit; +break ; +case 'r' : +if (file) { +printf ("Image already specified\n" ); +return -1 ; + } + file = optarg; + guid = &efi_guid_image_type_uboot_raw; +break ; +case 'i' : + index =strtoul (optarg,NULL ,0 ); +break ; +case 'I' : + instance =strtoul (optarg,NULL ,0 ); +break ; +case 'v' : + version =strtoul (optarg,NULL ,0 ); +break ; +case 'h' : +print_usage (); +return 0 ; + } + } + +/* need a output file */ +if (argc != optind +1 ) { +print_usage (); +return -1 ; + } + +/* need a fit image file or raw image file */ +if (!file) { +print_usage (); +return -1 ; + } + +if (create_fwbin (argv[optind], file, guid, version, index, instance) + <0 ) { +printf ("Creating firmware capsule failed\n" ); +return -1 ; + } + +return 0 ; +}
PATCH v9 8/11 tools: add mkeficapsule command for UEFI capsule update
Quoted 164 lines · AKASHI Takahiro
Heinrich,
Quoted 161 lines · Heinrich Schuchardt
Quoted 141 lines · AKASHI Takahiro
This is a utility mainly for test purpose.
mkeficapsule -f: create a test capsule file for FIT image firmwareHaving said that, you will be able to customize the code to fit your specific requirements for your platform.
Signed-off-by AKASHI Takahiro <[email protected]>--- tools/Makefile | 2 + tools/mkeficapsule.c | 238 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 240 insertions(+)create mode 100644
tools/mkeficapsule.ctools/Makefile +2
-0@@ -218,6 +218,8 @@ hostprogs-$(CONFIG_MIPS) += mips-relocs hostprogs-$(CONFIG_ASN1_COMPILER) += asn1_compiler HOSTCFLAGS_asn1_compiler.o = -idirafter $(srctree)/include +hostprogs-$(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) += mkeficapsule + # We build some files with extra pedantic flags to try to minimize things # that won't build on some weird host compiler -- though there are lots of # exceptions for files that aren't complaint.tools/mkeficapsule.c new file +109
-0@@ -0,0 +1,238 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright 2018 Linaro Limited +* Author: AKASHI Takahiro +*/ + +#include <getopt.h> +#include <malloc.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <linux/types.h> +#include <sys/stat.h> +#include <sys/types.h> + +typedef __u8 u8 ; +typedef __u16 u16 ; +typedef __u32 u32 ; +typedef __u64 u64 ; +typedef __s16 s16 ; +typedef __s32 s32 ; + +#define aligned_u64 __aligned_u64 + +#ifndef __packed +#define __packed __attribute__((packed)) +#endif + +#include <efi.h> +#include <efi_api.h> + +static const char *tool_name ="mkeficapsule" ; + +efi_guid_t efi_guid_fm_capsule =EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID ; +efi_guid_t efi_guid_image_type_uboot_fit = +EFI_FIRMWARE_IMAGE_TYPE_UBOOT_FIT_GUID ; +efi_guid_t efi_guid_image_type_uboot_raw = +EFI_FIRMWARE_IMAGE_TYPE_UBOOT_RAW_GUID ; + +static struct option options[] = { + {"fit" , required_argument,NULL ,'f' }, + {"raw" , required_argument,NULL ,'r' }, + {"index" , required_argument,NULL ,'i' }, + {"instance" , required_argument,NULL ,'I' }, + {"version" , required_argument,NULL ,'v' }, + {"help" , no_argument,NULL ,'h' }, + {NULL ,0 ,NULL ,0 }, +}; + +static void print_usage (void ) +{ +printf ("Usage: %s [options] <output file>\n" +"Options:\n" +"\t--fit <fit image> new FIT image file\n" +"\t--raw <raw image> new raw image file\n" +"\t--index <index> update image index\n" +"\t--instance <instance> update hardware instance\n" +"\t--version <version> firmware version\n" +"\t--help print a help message\n" , + tool_name); +} + +static int create_fwbin (char *path,char *bin,efi_guid_t *guid, +unsigned long version,unsigned long index, +unsigned long instance) +{ +struct efi_capsule_header header; +struct efi_firmware_management_capsule_header capsule; +struct efi_firmware_management_capsule_image_header image; +FILE *f, *g; +struct stat bin_stat; +u8 *data; +size_t size; + +#ifdef DEBUG +printf ("For output: %s\n" , path); +printf ("\tbin: %s\n\ttype: %pUl\n" bin, guid); +printf ("\tversion: %ld\n\tindex: %ld\n\tinstance: %ld\n" , + version, index, instance); +#endif + + g =fopen (bin,"r" ); +if (!g) { +printf ("cannot open %s\n" , bin); +return -1 ; + } +if (stat (bin, &bin_stat) <0 ) { +printf ("cannot determine the size of %s\n" , bin); + goto err_1; + } + data =malloc (bin_stat.st_size); +if (!data) { +printf ("cannot allocate memory: %lx\n" , bin_stat.st_size); + goto err_1; + } + f =fopen (path,"w" ); +if (!f) { +printf ("cannot open %s\n" , path); + goto err_2; + } + header.capsule_guid = efi_guid_fm_capsule; + header.header_size =sizeof (header); + header.flags =CAPSULE_FLAGS_PERSIST_ACROSS_RESET ;/* TODO */ + header.capsule_image_size =sizeof (header) + +sizeof (capsule) +sizeof (u64) + +sizeof (image) + + bin_stat.st_size; +tools/mkeficapsule.c line 119
Quoted 10 lines
tools/mkeficapsule.c new file +10
-0+ size =fwrite (&header,1 ,sizeof (header), f); +if (size <sizeof (header)) { +printf ("write failed (%lx)\n" , size); + goto err_3; + } + + capsule.version =0x00000001 ; + capsule.embedded_driver_count =0 ; + capsule.payload_item_count =1 ; + capsule.item_offset_list[0 ] =sizeof (capsule) +sizeof (u64);With the complete series applied, building
sandbox_defconfig:
tools/mkeficapsule.c: In function ?main?:tools/mkeficapsule.c:120:26: warning: array subscript 0 is outside array bounds of ?u64[]? {aka ?long long unsigned int[]?} [-Warray-bounds]120 | capsule.item_offset_list[0] = sizeof(capsule) + sizeof(u64); | ~~~~~~~~~~~~~~~~~~~~~~~~^~~
Quoted 4 lines
Quoted 1 line
Please, ensure that the code compiles without warnings.
Fixing this warning would be easy, but I didn't see it with gcc9.2 (from Linaro/Arm) or even in the results of Travis CI.
Oops, I found that this is not a warning, but a potential bug. The code does overrun a variable, capsule, allocated on the stack while it is apparently harmless as the neighboring variable, image, is initialized later.
Quoted 2 lines
So I wonder if it is mandatory that the code compiles without warnings, and if so, which compiler and which version are required?
Yet, this question remains.
-Takahiro Akashi
Quoted 130 lines
Quoted 130 lines
I have been using GCC 10.2 as supplied by Debian Bullseye on an ARM64 system.
Best regards
Heinrich
Quoted 120 lines
tools/mkeficapsule.c new file +119
-0+ size =fwrite (&capsule,1 ,sizeof (capsule) +sizeof (u64), f); +if (size < (sizeof (capsule) +sizeof (u64))) { +printf ("write failed (%lx)\n" , size); + goto err_3; + } + + image.version = version; +memcpy (&image.update_image_type_id, guid,sizeof (*guid)); + image.update_image_index = index; + image.update_image_size = bin_stat.st_size; + image.update_vendor_code_size =0 ;/* none */ + image.update_hardware_instance = instance; + image.image_capsule_support =0 ; + + size =fwrite (&image,1 ,sizeof (image), f); +if (size <sizeof (image)) { +printf ("write failed (%lx)\n" , size); + goto err_3; + } + size =fread (data,1 , bin_stat.st_size, g); +if (size < bin_stat.st_size) { +printf ("read failed (%lx)\n" , size); + goto err_3; + } + size =fwrite (data,1 , bin_stat.st_size, f); +if (size < bin_stat.st_size) { +printf ("write failed (%lx)\n" , size); + goto err_3; + } + +fclose (f); +fclose (g); +free (data); + +return 0 ; + +err_3: +fclose (f); +err_2: +free (data); +err_1: +fclose (g); + +return -1 ; +} + +/* +* Usage: +* $ mkeficapsule -f <firmware binary> <output file> +*/ +int main (int argc,char **argv) +{ +char *file; +efi_guid_t *guid; +unsigned long index, instance, version; +int c, idx; + + file =NULL ; + guid =NULL ; + index =0 ; + instance =0 ; + version =0 ; +for (;;) { + c =getopt_long (argc, argv,"f:r:i:I:v:h" , options, &idx); +if (c ==-1 ) +break ; + +switch (c) { +case 'f' : +if (file) { +printf ("Image already specified\n" ); +return -1 ; + } + file = optarg; + guid = &efi_guid_image_type_uboot_fit; +break ; +case 'r' : +if (file) { +printf ("Image already specified\n" ); +return -1 ; + } + file = optarg; + guid = &efi_guid_image_type_uboot_raw; +break ; +case 'i' : + index =strtoul (optarg,NULL ,0 ); +break ; +case 'I' : + instance =strtoul (optarg,NULL ,0 ); +break ; +case 'v' : + version =strtoul (optarg,NULL ,0 ); +break ; +case 'h' : +print_usage (); +return 0 ; + } + } + +/* need a output file */ +if (argc != optind +1 ) { +print_usage (); +return -1 ; + } + +/* need a fit image file or raw image file */ +if (!file) { +print_usage (); +return -1 ; + } + +if (create_fwbin (argv[optind], file, guid, version, index, instance) + <0 ) { +printf ("Creating firmware capsule failed\n" ); +return -1 ; + } + +return 0 ; +}
PATCH v9 8/11 tools: add mkeficapsule command for UEFI capsule update
In reply to AKASHI TakahiroAm 25. November 2020 02:05:06 MEZ schrieb AKASHI Takahiro <[email protected]>:
Quoted 172 lines
Heinrich,
Quoted 3 lines · Heinrich Schuchardt
Quoted 2 lines · AKASHI Takahiro
This is a utility mainly for test purpose.
mkeficapsule -f: create a test capsule file for FIT imagefirmware
Quoted 8 lines
Quoted 8 lines
Having said that, you will be able to customize the code to fit your specific requirements for your platform.
Signed-off-by AKASHI Takahiro <[email protected]>--- tools/Makefile | 2 + tools/mkeficapsule.c | 238+++++++++++++++++++++++++++++++++++++++++++
Quoted 11 lines
Quoted 11 lines
2 files changed, 240 insertions(+)create mode 100644
tools/mkeficapsule.ctools/Makefile +0
-0@@ -218,6 +218,8 @@ hostprogs-$(CONFIG_MIPS) += mips-relocs hostprogs-$(CONFIG_ASN1_COMPILER) += asn1_compiler HOSTCFLAGS_asn1_compiler.o = -idirafter $(srctree)/includeQuoted 3 lines
tools/Makefile hostprogs-$(CONFIG_MIPS) += mips-relocs
Quoted 3 lines
tools/Makefile +2
-0+hostprogs-$(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) += mkeficapsule + # We build some files with extra pedantic flags to try tominimize things
Quoted 1 line
tools/Makefile hostprogs-$(CONFIG_MIPS) += mips-relocs · line 224
Quoted 1 line
tools/Makefile +0
-0# that won't build on some weird host compiler -- though thereare lots of
Quoted 34 lines
Quoted 34 lines
tools/Makefile +0
-0# exceptions for files that aren't complaint.tools/mkeficapsule.c new file +27
-0@@ -0,0 +1,238 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright 2018 Linaro Limited +* Author: AKASHI Takahiro +*/ + +#include <getopt.h> +#include <malloc.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <linux/types.h> +#include <sys/stat.h> +#include <sys/types.h> + +typedef __u8 u8 ; +typedef __u16 u16 ; +typedef __u32 u32 ; +typedef __u64 u64 ; +typedef __s16 s16 ; +typedef __s32 s32 ; + +#define aligned_u64 __aligned_u64 + +#ifndef __packed +#define __packed __attribute__((packed))Quoted 8 lines
tools/mkeficapsule.c
Quoted 8 lines
tools/mkeficapsule.c new file +8
-0+#endif + +#include <efi.h> +#include <efi_api.h> + +static const char *tool_name ="mkeficapsule" ; + +efi_guid_t efi_guid_fm_capsule =
EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID;Quoted 87 lines
Quoted 74 lines
tools/mkeficapsule.c new file +74
-0+efi_guid_t efi_guid_image_type_uboot_fit = +EFI_FIRMWARE_IMAGE_TYPE_UBOOT_FIT_GUID ; +efi_guid_t efi_guid_image_type_uboot_raw = +EFI_FIRMWARE_IMAGE_TYPE_UBOOT_RAW_GUID ; + +static struct option options[] = { + {"fit" , required_argument,NULL ,'f' }, + {"raw" , required_argument,NULL ,'r' }, + {"index" , required_argument,NULL ,'i' }, + {"instance" , required_argument,NULL ,'I' }, + {"version" , required_argument,NULL ,'v' }, + {"help" , no_argument,NULL ,'h' }, + {NULL ,0 ,NULL ,0 }, +}; + +static void print_usage (void ) +{ +printf ("Usage: %s [options] <output file>\n" +"Options:\n" +"\t--fit <fit image> new FIT image file\n" +"\t--raw <raw image> new raw image file\n" +"\t--index <index> update image index\n" +"\t--instance <instance> update hardware instance\n" +"\t--version <version> firmware version\n" +"\t--help print a help message\n" , + tool_name); +} + +static int create_fwbin (char *path,char *bin,efi_guid_t *guid, +unsigned long version,unsigned long index, +unsigned long instance) +{ +struct efi_capsule_header header; +struct efi_firmware_management_capsule_header capsule; +struct efi_firmware_management_capsule_image_header image; +FILE *f, *g; +struct stat bin_stat; +u8 *data; +size_t size; + +#ifdef DEBUG +printf ("For output: %s\n" , path); +printf ("\tbin: %s\n\ttype: %pUl\n" bin, guid); +printf ("\tversion: %ld\n\tindex: %ld\n\tinstance: %ld\n" , + version, index, instance); +#endif + + g =fopen (bin,"r" ); +if (!g) { +printf ("cannot open %s\n" , bin); +return -1 ; + } +if (stat (bin, &bin_stat) <0 ) { +printf ("cannot determine the size of %s\n" , bin); + goto err_1; + } + data =malloc (bin_stat.st_size); +if (!data) { +printf ("cannot allocate memory: %lx\n" , bin_stat.st_size); + goto err_1; + } + f =fopen (path,"w" ); +if (!f) { +printf ("cannot open %s\n" , path); + goto err_2; + } + header.capsule_guid = efi_guid_fm_capsule; + header.header_size =sizeof (header); + header.flags =CAPSULE_FLAGS_PERSIST_ACROSS_RESET ;/* TODO */ + header.capsule_image_size =sizeof (header) + +sizeof (capsule) +sizeof (u64) + +sizeof (image) + + bin_stat.st_size; +tools/mkeficapsule.c line 119
Quoted 10 lines
tools/mkeficapsule.c new file +10
-0+ size =fwrite (&header,1 ,sizeof (header), f); +if (size <sizeof (header)) { +printf ("write failed (%lx)\n" , size); + goto err_3; + } + + capsule.version =0x00000001 ; + capsule.embedded_driver_count =0 ; + capsule.payload_item_count =1 ; + capsule.item_offset_list[0 ] =sizeof (capsule) +sizeof (u64);With the complete series applied, building
sandbox_defconfig:Quoted 2 lines
tools/mkeficapsule.c: In function ?main?:tools/mkeficapsule.c:120:26: warning: array subscript 0 is outsidearray
Quoted 5 lines
bounds of ?u64[]? {aka ?long long unsigned int[]?} [-Warray-bounds]
120 | capsule.item_offset_list[0] = sizeof(capsule) + sizeof(u64); | ~~~~~~~~~~~~~~~~~~~~~~~~^~~Please, ensure that the code compiles without warnings.
Quoted 8 lines
Fixing this warning would be easy, but I didn't see it with gcc9.2 (from Linaro/Arm) or even in the results of Travis CI.
So I wonder if it is mandatory that the code compiles without warnings, and if so, which compiler and which version are required?
-Takahiro Akashi
Our settings for gitlab CI and Travis CI are that all warnings are treated as errors.
So we must build without warning.
Best regards
Heinrich
Quoted 130 lines
Quoted 112 lines
I have been using GCC 10.2 as supplied by Debian Bullseye on an ARM64 system.
Best regards
Heinrich
Quoted 104 lines
tools/mkeficapsule.c new file +104
-0+ size =fwrite (&capsule,1 ,sizeof (capsule) +sizeof (u64), f); +if (size < (sizeof (capsule) +sizeof (u64))) { +printf ("write failed (%lx)\n" , size); + goto err_3; + } + + image.version = version; +memcpy (&image.update_image_type_id, guid,sizeof (*guid)); + image.update_image_index = index; + image.update_image_size = bin_stat.st_size; + image.update_vendor_code_size =0 ;/* none */ + image.update_hardware_instance = instance; + image.image_capsule_support =0 ; + + size =fwrite (&image,1 ,sizeof (image), f); +if (size <sizeof (image)) { +printf ("write failed (%lx)\n" , size); + goto err_3; + } + size =fread (data,1 , bin_stat.st_size, g); +if (size < bin_stat.st_size) { +printf ("read failed (%lx)\n" , size); + goto err_3; + } + size =fwrite (data,1 , bin_stat.st_size, f); +if (size < bin_stat.st_size) { +printf ("write failed (%lx)\n" , size); + goto err_3; + } + +fclose (f); +fclose (g); +free (data); + +return 0 ; + +err_3: +fclose (f); +err_2: +free (data); +err_1: +fclose (g); + +return -1 ; +} + +/* +* Usage: +* $ mkeficapsule -f <firmware binary> <output file> +*/ +int main (int argc,char **argv) +{ +char *file; +efi_guid_t *guid; +unsigned long index, instance, version; +int c, idx; + + file =NULL ; + guid =NULL ; + index =0 ; + instance =0 ; + version =0 ; +for (;;) { + c =getopt_long (argc, argv,"f:r:i:I:v:h" , options, &idx); +if (c ==-1 ) +break ; + +switch (c) { +case 'f' : +if (file) { +printf ("Image already specified\n" ); +return -1 ; + } + file = optarg; + guid = &efi_guid_image_type_uboot_fit; +break ; +case 'r' : +if (file) { +printf ("Image already specified\n" ); +return -1 ; + } + file = optarg; + guid = &efi_guid_image_type_uboot_raw; +break ; +case 'i' : + index =strtoul (optarg,NULL ,0 ); +break ; +case 'I' : + instance =strtoul (optarg,NULL ,0 ); +break ; +case 'v' : + version =strtoul (optarg,NULL ,0 ); +break ; +case 'h' : +print_usage (); +return 0 ; + } + } + +/* need a output file */ +if (argc != optind +1 ) { +print_usage (); +return -1 ; + }Quoted 8 lines
tools/mkeficapsule.c
Quoted 8 lines
tools/mkeficapsule.c new file +8
-0+ +/* need a fit image file or raw image file */ +if (!file) { +print_usage (); +return -1 ; + } + + if (create_fwbin(argv[optind], file, guid, version, index,instance)
Quoted 9 lines
Quoted 8 lines
tools/mkeficapsule.c new file +7
-0+ < 0) { +printf ("Creating firmware capsule failed\n" ); +return -1 ; + } + +return 0 ; +}
PATCH v9 8/11 tools: add mkeficapsule command for UEFI capsule update
Heinrich,
Quoted 178 lines · Heinrich Schuchardt
Am 25. November 2020 02:05:06 MEZ schrieb AKASHI Takahiro <[email protected]>:
Quoted 177 lines
Heinrich,
Quoted 3 lines · Heinrich Schuchardt
Quoted 2 lines · AKASHI Takahiro
This is a utility mainly for test purpose.
mkeficapsule -f: create a test capsule file for FIT imagefirmware
Quoted 8 lines
Quoted 8 lines
Having said that, you will be able to customize the code to fit your specific requirements for your platform.
Signed-off-by AKASHI Takahiro <[email protected]>--- tools/Makefile | 2 + tools/mkeficapsule.c | 238+++++++++++++++++++++++++++++++++++++++++++
Quoted 11 lines
Quoted 11 lines
2 files changed, 240 insertions(+)create mode 100644
tools/mkeficapsule.ctools/Makefile +0
-0@@ -218,6 +218,8 @@ hostprogs-$(CONFIG_MIPS) += mips-relocs hostprogs-$(CONFIG_ASN1_COMPILER) += asn1_compiler HOSTCFLAGS_asn1_compiler.o = -idirafter $(srctree)/includeQuoted 3 lines
tools/Makefile hostprogs-$(CONFIG_MIPS) += mips-relocs
Quoted 3 lines
tools/Makefile +2
-0+hostprogs-$(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) += mkeficapsule + # We build some files with extra pedantic flags to try tominimize things
Quoted 1 line
tools/Makefile hostprogs-$(CONFIG_MIPS) += mips-relocs · line 224
Quoted 1 line
tools/Makefile +0
-0# that won't build on some weird host compiler -- though thereare lots of
Quoted 34 lines
Quoted 34 lines
tools/Makefile +0
-0# exceptions for files that aren't complaint.tools/mkeficapsule.c new file +27
-0@@ -0,0 +1,238 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright 2018 Linaro Limited +* Author: AKASHI Takahiro +*/ + +#include <getopt.h> +#include <malloc.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <linux/types.h> +#include <sys/stat.h> +#include <sys/types.h> + +typedef __u8 u8 ; +typedef __u16 u16 ; +typedef __u32 u32 ; +typedef __u64 u64 ; +typedef __s16 s16 ; +typedef __s32 s32 ; + +#define aligned_u64 __aligned_u64 + +#ifndef __packed +#define __packed __attribute__((packed))Quoted 8 lines
tools/mkeficapsule.c
Quoted 8 lines
tools/mkeficapsule.c new file +8
-0+#endif + +#include <efi.h> +#include <efi_api.h> + +static const char *tool_name ="mkeficapsule" ; + +efi_guid_t efi_guid_fm_capsule =
EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID;Quoted 87 lines
Quoted 74 lines
tools/mkeficapsule.c new file +74
-0+efi_guid_t efi_guid_image_type_uboot_fit = +EFI_FIRMWARE_IMAGE_TYPE_UBOOT_FIT_GUID ; +efi_guid_t efi_guid_image_type_uboot_raw = +EFI_FIRMWARE_IMAGE_TYPE_UBOOT_RAW_GUID ; + +static struct option options[] = { + {"fit" , required_argument,NULL ,'f' }, + {"raw" , required_argument,NULL ,'r' }, + {"index" , required_argument,NULL ,'i' }, + {"instance" , required_argument,NULL ,'I' }, + {"version" , required_argument,NULL ,'v' }, + {"help" , no_argument,NULL ,'h' }, + {NULL ,0 ,NULL ,0 }, +}; + +static void print_usage (void ) +{ +printf ("Usage: %s [options] <output file>\n" +"Options:\n" +"\t--fit <fit image> new FIT image file\n" +"\t--raw <raw image> new raw image file\n" +"\t--index <index> update image index\n" +"\t--instance <instance> update hardware instance\n" +"\t--version <version> firmware version\n" +"\t--help print a help message\n" , + tool_name); +} + +static int create_fwbin (char *path,char *bin,efi_guid_t *guid, +unsigned long version,unsigned long index, +unsigned long instance) +{ +struct efi_capsule_header header; +struct efi_firmware_management_capsule_header capsule; +struct efi_firmware_management_capsule_image_header image; +FILE *f, *g; +struct stat bin_stat; +u8 *data; +size_t size; + +#ifdef DEBUG +printf ("For output: %s\n" , path); +printf ("\tbin: %s\n\ttype: %pUl\n" bin, guid); +printf ("\tversion: %ld\n\tindex: %ld\n\tinstance: %ld\n" , + version, index, instance); +#endif + + g =fopen (bin,"r" ); +if (!g) { +printf ("cannot open %s\n" , bin); +return -1 ; + } +if (stat (bin, &bin_stat) <0 ) { +printf ("cannot determine the size of %s\n" , bin); + goto err_1; + } + data =malloc (bin_stat.st_size); +if (!data) { +printf ("cannot allocate memory: %lx\n" , bin_stat.st_size); + goto err_1; + } + f =fopen (path,"w" ); +if (!f) { +printf ("cannot open %s\n" , path); + goto err_2; + } + header.capsule_guid = efi_guid_fm_capsule; + header.header_size =sizeof (header); + header.flags =CAPSULE_FLAGS_PERSIST_ACROSS_RESET ;/* TODO */ + header.capsule_image_size =sizeof (header) + +sizeof (capsule) +sizeof (u64) + +sizeof (image) + + bin_stat.st_size; +tools/mkeficapsule.c line 119
Quoted 10 lines
tools/mkeficapsule.c new file +10
-0+ size =fwrite (&header,1 ,sizeof (header), f); +if (size <sizeof (header)) { +printf ("write failed (%lx)\n" , size); + goto err_3; + } + + capsule.version =0x00000001 ; + capsule.embedded_driver_count =0 ; + capsule.payload_item_count =1 ; + capsule.item_offset_list[0 ] =sizeof (capsule) +sizeof (u64);With the complete series applied, building
sandbox_defconfig:Quoted 2 lines
tools/mkeficapsule.c: In function ?main?:tools/mkeficapsule.c:120:26: warning: array subscript 0 is outsidearray
Quoted 5 lines
bounds of ?u64[]? {aka ?long long unsigned int[]?} [-Warray-bounds]
120 | capsule.item_offset_list[0] = sizeof(capsule) + sizeof(u64); | ~~~~~~~~~~~~~~~~~~~~~~~~^~~Please, ensure that the code compiles without warnings.
Fixing this warning would be easy, but I didn't see it with gcc9.2 (from Linaro/Arm) or even in the results of Travis CI.
So I wonder if it is mandatory that the code compiles without warnings, and if so, which compiler and which version are required?
First, can you please make a comment here against my question?
Quoted 5 lines
Quoted 3 lines
-Takahiro Akashi
Our settings for gitlab CI and Travis CI are that all warnings are treated as errors.
As I said, I've never seen this warning/error in Travis CI. I don't know how we can confirm the result of gitlab CI.
-Takahiro Akashi
Quoted 137 lines
So we must build without warning.
Best regards
Heinrich
Quoted 130 lines
Quoted 112 lines
I have been using GCC 10.2 as supplied by Debian Bullseye on an ARM64 system.
Best regards
Heinrich
Quoted 104 lines
tools/mkeficapsule.c new file +104
-0+ size =fwrite (&capsule,1 ,sizeof (capsule) +sizeof (u64), f); +if (size < (sizeof (capsule) +sizeof (u64))) { +printf ("write failed (%lx)\n" , size); + goto err_3; + } + + image.version = version; +memcpy (&image.update_image_type_id, guid,sizeof (*guid)); + image.update_image_index = index; + image.update_image_size = bin_stat.st_size; + image.update_vendor_code_size =0 ;/* none */ + image.update_hardware_instance = instance; + image.image_capsule_support =0 ; + + size =fwrite (&image,1 ,sizeof (image), f); +if (size <sizeof (image)) { +printf ("write failed (%lx)\n" , size); + goto err_3; + } + size =fread (data,1 , bin_stat.st_size, g); +if (size < bin_stat.st_size) { +printf ("read failed (%lx)\n" , size); + goto err_3; + } + size =fwrite (data,1 , bin_stat.st_size, f); +if (size < bin_stat.st_size) { +printf ("write failed (%lx)\n" , size); + goto err_3; + } + +fclose (f); +fclose (g); +free (data); + +return 0 ; + +err_3: +fclose (f); +err_2: +free (data); +err_1: +fclose (g); + +return -1 ; +} + +/* +* Usage: +* $ mkeficapsule -f <firmware binary> <output file> +*/ +int main (int argc,char **argv) +{ +char *file; +efi_guid_t *guid; +unsigned long index, instance, version; +int c, idx; + + file =NULL ; + guid =NULL ; + index =0 ; + instance =0 ; + version =0 ; +for (;;) { + c =getopt_long (argc, argv,"f:r:i:I:v:h" , options, &idx); +if (c ==-1 ) +break ; + +switch (c) { +case 'f' : +if (file) { +printf ("Image already specified\n" ); +return -1 ; + } + file = optarg; + guid = &efi_guid_image_type_uboot_fit; +break ; +case 'r' : +if (file) { +printf ("Image already specified\n" ); +return -1 ; + } + file = optarg; + guid = &efi_guid_image_type_uboot_raw; +break ; +case 'i' : + index =strtoul (optarg,NULL ,0 ); +break ; +case 'I' : + instance =strtoul (optarg,NULL ,0 ); +break ; +case 'v' : + version =strtoul (optarg,NULL ,0 ); +break ; +case 'h' : +print_usage (); +return 0 ; + } + } + +/* need a output file */ +if (argc != optind +1 ) { +print_usage (); +return -1 ; + }Quoted 8 lines
tools/mkeficapsule.c
Quoted 8 lines
tools/mkeficapsule.c new file +8
-0+ +/* need a fit image file or raw image file */ +if (!file) { +print_usage (); +return -1 ; + } + + if (create_fwbin(argv[optind], file, guid, version, index,instance)
Quoted 9 lines
Quoted 8 lines
tools/mkeficapsule.c new file +7
-0+ < 0) { +printf ("Creating firmware capsule failed\n" ); +return -1 ; + } + +return 0 ; +}
PATCH v9 8/11 tools: add mkeficapsule command for UEFI capsule update
Am 25. November 2020 08:32:08 MEZ schrieb AKASHI Takahiro <[email protected]>:
Quoted 193 lines
Heinrich,
Quoted 1 line · Heinrich Schuchardt
Am 25. November 2020 02:05:06 MEZ schrieb AKASHI Takahiro
Quoted 97 lines
Quoted 97 lines
Heinrich,
Quoted 3 lines · Heinrich Schuchardt
Quoted 2 lines · AKASHI Takahiro
This is a utility mainly for test purpose.
mkeficapsule -f: create a test capsule file for FIT imagefirmware
Quoted 8 lines
Quoted 8 lines
Having said that, you will be able to customize the code to fit your specific requirements for your platform.
Signed-off-by AKASHI Takahiro <[email protected]>--- tools/Makefile | 2 + tools/mkeficapsule.c | 238+++++++++++++++++++++++++++++++++++++++++++
Quoted 11 lines
Quoted 11 lines
2 files changed, 240 insertions(+)create mode 100644
tools/mkeficapsule.ctools/Makefile +0
-0@@ -218,6 +218,8 @@ hostprogs-$(CONFIG_MIPS) += mips-relocs hostprogs-$(CONFIG_ASN1_COMPILER) += asn1_compiler HOSTCFLAGS_asn1_compiler.o = -idirafter $(srctree)/includeQuoted 3 lines
tools/Makefile hostprogs-$(CONFIG_MIPS) += mips-relocs
Quoted 3 lines
tools/Makefile +2
-0+hostprogs-$(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) += mkeficapsule + # We build some files with extra pedantic flags to try tominimize things
Quoted 1 line
tools/Makefile hostprogs-$(CONFIG_MIPS) += mips-relocs · line 224
Quoted 1 line
tools/Makefile +0
-0# that won't build on some weird host compiler -- though thereare lots of
Quoted 34 lines
Quoted 34 lines
tools/Makefile +0
-0# exceptions for files that aren't complaint.tools/mkeficapsule.c new file +27
-0@@ -0,0 +1,238 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright 2018 Linaro Limited +* Author: AKASHI Takahiro +*/ + +#include <getopt.h> +#include <malloc.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <linux/types.h> +#include <sys/stat.h> +#include <sys/types.h> + +typedef __u8 u8 ; +typedef __u16 u16 ; +typedef __u32 u32 ; +typedef __u64 u64 ; +typedef __s16 s16 ; +typedef __s32 s32 ; + +#define aligned_u64 __aligned_u64 + +#ifndef __packed +#define __packed __attribute__((packed))Quoted 8 lines
tools/mkeficapsule.c
Quoted 8 lines
tools/mkeficapsule.c new file +8
-0+#endif + +#include <efi.h> +#include <efi_api.h> + +static const char *tool_name ="mkeficapsule" ; + +efi_guid_t efi_guid_fm_capsule =
EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID;Quoted 21 lines
Quoted 21 lines
tools/mkeficapsule.c new file +21
-0+efi_guid_t efi_guid_image_type_uboot_fit = +EFI_FIRMWARE_IMAGE_TYPE_UBOOT_FIT_GUID ; +efi_guid_t efi_guid_image_type_uboot_raw = +EFI_FIRMWARE_IMAGE_TYPE_UBOOT_RAW_GUID ; + +static struct option options[] = { + {"fit" , required_argument,NULL ,'f' }, + {"raw" , required_argument,NULL ,'r' }, + {"index" , required_argument,NULL ,'i' }, + {"instance" , required_argument,NULL ,'I' }, + {"version" , required_argument,NULL ,'v' }, + {"help" , no_argument,NULL ,'h' }, + {NULL ,0 ,NULL ,0 }, +}; + +static void print_usage (void ) +{ +printf ("Usage: %s [options] <output file>\n" +"Options:\n" +"\t--fit <fit image> new FIT image file\n" + "\t--raw <raw image> new raw image file\n"Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
tools/mkeficapsule.c
Quoted 8 lines
tools/mkeficapsule.c new file +8
-0+"\t--index <index> update image index\n" +"\t--instance <instance> update hardware instance\n" +"\t--version <version> firmware version\n" +"\t--help print a help message\n" , + tool_name); +} + +static int create_fwbin(char *path, char *bin, efi_guid_t*guid,
Quoted 58 lines
Quoted 58 lines
Quoted 58 lines
Quoted 45 lines
tools/mkeficapsule.c new file +45
-0+ unsigned long version, unsigned long index, + unsigned long instance) +{ + struct efi_capsule_header header; +struct efi_firmware_management_capsule_header capsule; +struct efi_firmware_management_capsule_image_header image; +FILE *f, *g; +struct stat bin_stat; +u8 *data; +size_t size; + +#ifdef DEBUG +printf ("For output: %s\n" , path); +printf ("\tbin: %s\n\ttype: %pUl\n" bin, guid); +printf ("\tversion: %ld\n\tindex: %ld\n\tinstance: %ld\n" , + version, index, instance); +#endif + + g =fopen (bin,"r" ); +if (!g) { +printf ("cannot open %s\n" , bin); +return -1 ; + } +if (stat (bin, &bin_stat) <0 ) { +printf ("cannot determine the size of %s\n" , bin); + goto err_1; + } + data =malloc (bin_stat.st_size); +if (!data) { +printf ("cannot allocate memory: %lx\n" , bin_stat.st_size); + goto err_1; + } + f =fopen (path,"w" ); +if (!f) { +printf ("cannot open %s\n" , path); + goto err_2; + } + header.capsule_guid = efi_guid_fm_capsule; + header.header_size =sizeof (header); + header.flags =CAPSULE_FLAGS_PERSIST_ACROSS_RESET ;/* TODO */ + header.capsule_image_size =sizeof (header) + +sizeof (capsule) +sizeof (u64) + +sizeof (image) + + bin_stat.st_size; +tools/mkeficapsule.c line 119
Quoted 10 lines
tools/mkeficapsule.c new file +10
-0+ size =fwrite (&header,1 ,sizeof (header), f); +if (size <sizeof (header)) { +printf ("write failed (%lx)\n" , size); + goto err_3; + } + + capsule.version =0x00000001 ; + capsule.embedded_driver_count =0 ; + capsule.payload_item_count =1 ; + capsule.item_offset_list[0 ] =sizeof (capsule) +sizeof (u64);With the complete series applied, building
sandbox_defconfig:Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
tools/mkeficapsule.c: In function ?main?:tools/mkeficapsule.c:120:26: warning: array subscript 0 is outsidearray
Quoted 1 line
bounds of ?u64[]? {aka ?long long unsigned int[]?}
[-Warray-bounds]
Quoted 1 line
Quoted 1 line
Quoted 1 line
120 | capsule.item_offset_list[0] = sizeof(capsule) +
sizeof(u64);
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
| ~~~~~~~~~~~~~~~~~~~~~~~~^~~Please, ensure that the code compiles without warnings.
Fixing this warning would be easy, but I didn't see it with gcc9.2 (from Linaro/Arm) or even in the results of Travis CI.
So I wonder if it is mandatory that the code compiles without
warnings,
Quoted 1 line
Quoted 1 line
and if so, which compiler and which version are required?
First, can you please make a comment here against my question?
Quoted 4 lines
Quoted 3 lines
-Takahiro Akashi
Quoted 7 lines
Quoted 1 line
Our settings for gitlab CI and Travis CI are that all warnings are
treated as errors.
As I said, I've never seen this warning/error in Travis CI. I don't know how we can confirm the result of gitlab CI.
-Takahiro Akashi
Just make sure that GCC 10+ does not complain locally.
Tom will update the CI in January. I dont want to see a build error then.
Best regards
Heinrich
Quoted 140 lines
Quoted 10 lines
So we must build without warning.
Best regards
Heinrich
Quoted 2 lines
Quoted 2 lines
I have been using GCC 10.2 as supplied by Debian Bullseye on an
ARM64
Quoted 129 lines
Quoted 128 lines
Quoted 110 lines
system.
Best regards
Heinrich
Quoted 104 lines
tools/mkeficapsule.c new file +104
-0+ size =fwrite (&capsule,1 ,sizeof (capsule) +sizeof (u64), f); +if (size < (sizeof (capsule) +sizeof (u64))) { +printf ("write failed (%lx)\n" , size); + goto err_3; + } + + image.version = version; +memcpy (&image.update_image_type_id, guid,sizeof (*guid)); + image.update_image_index = index; + image.update_image_size = bin_stat.st_size; + image.update_vendor_code_size =0 ;/* none */ + image.update_hardware_instance = instance; + image.image_capsule_support =0 ; + + size =fwrite (&image,1 ,sizeof (image), f); +if (size <sizeof (image)) { +printf ("write failed (%lx)\n" , size); + goto err_3; + } + size =fread (data,1 , bin_stat.st_size, g); +if (size < bin_stat.st_size) { +printf ("read failed (%lx)\n" , size); + goto err_3; + } + size =fwrite (data,1 , bin_stat.st_size, f); +if (size < bin_stat.st_size) { +printf ("write failed (%lx)\n" , size); + goto err_3; + } + +fclose (f); +fclose (g); +free (data); + +return 0 ; + +err_3: +fclose (f); +err_2: +free (data); +err_1: +fclose (g); + +return -1 ; +} + +/* +* Usage: +* $ mkeficapsule -f <firmware binary> <output file> +*/ +int main (int argc,char **argv) +{ +char *file; +efi_guid_t *guid; +unsigned long index, instance, version; +int c, idx; + + file =NULL ; + guid =NULL ; + index =0 ; + instance =0 ; + version =0 ; +for (;;) { + c =getopt_long (argc, argv,"f:r:i:I:v:h" , options, &idx); +if (c ==-1 ) +break ; + +switch (c) { +case 'f' : +if (file) { +printf ("Image already specified\n" ); +return -1 ; + } + file = optarg; + guid = &efi_guid_image_type_uboot_fit; +break ; +case 'r' : +if (file) { +printf ("Image already specified\n" ); +return -1 ; + } + file = optarg; + guid = &efi_guid_image_type_uboot_raw; +break ; +case 'i' : + index =strtoul (optarg,NULL ,0 ); +break ; +case 'I' : + instance =strtoul (optarg,NULL ,0 ); +break ; +case 'v' : + version =strtoul (optarg,NULL ,0 ); +break ; +case 'h' : +print_usage (); +return 0 ; + } + } + +/* need a output file */ +if (argc != optind +1 ) { +print_usage (); +return -1 ; + }Quoted 8 lines
tools/mkeficapsule.c
Quoted 8 lines
tools/mkeficapsule.c new file +8
-0+ +/* need a fit image file or raw image file */ +if (!file) { +print_usage (); +return -1 ; + } + + if (create_fwbin(argv[optind], file, guid, version, index,instance)
Quoted 9 lines
Quoted 8 lines
tools/mkeficapsule.c new file +7
-0+ < 0) { +printf ("Creating firmware capsule failed\n" ); +return -1 ; + } + +return 0 ; +}
PATCH v9 8/11 tools: add mkeficapsule command for UEFI capsule update
Quoted 203 lines · Heinrich Schuchardt
Am 25. November 2020 08:32:08 MEZ schrieb AKASHI Takahiro <[email protected]>:
Quoted 193 lines
Heinrich,
Quoted 1 line · Heinrich Schuchardt
Am 25. November 2020 02:05:06 MEZ schrieb AKASHI Takahiro
Quoted 97 lines
Quoted 97 lines
Heinrich,
Quoted 3 lines · Heinrich Schuchardt
Quoted 2 lines · AKASHI Takahiro
This is a utility mainly for test purpose.
mkeficapsule -f: create a test capsule file for FIT imagefirmware
Quoted 8 lines
Quoted 8 lines
Having said that, you will be able to customize the code to fit your specific requirements for your platform.
Signed-off-by AKASHI Takahiro <[email protected]>--- tools/Makefile | 2 + tools/mkeficapsule.c | 238+++++++++++++++++++++++++++++++++++++++++++
Quoted 11 lines
Quoted 11 lines
2 files changed, 240 insertions(+)create mode 100644
tools/mkeficapsule.ctools/Makefile +0
-0@@ -218,6 +218,8 @@ hostprogs-$(CONFIG_MIPS) += mips-relocs hostprogs-$(CONFIG_ASN1_COMPILER) += asn1_compiler HOSTCFLAGS_asn1_compiler.o = -idirafter $(srctree)/includeQuoted 3 lines
tools/Makefile hostprogs-$(CONFIG_MIPS) += mips-relocs
Quoted 3 lines
tools/Makefile +2
-0+hostprogs-$(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) += mkeficapsule + # We build some files with extra pedantic flags to try tominimize things
Quoted 1 line
tools/Makefile hostprogs-$(CONFIG_MIPS) += mips-relocs · line 224
Quoted 1 line
tools/Makefile +0
-0# that won't build on some weird host compiler -- though thereare lots of
Quoted 34 lines
Quoted 34 lines
tools/Makefile +0
-0# exceptions for files that aren't complaint.tools/mkeficapsule.c new file +27
-0@@ -0,0 +1,238 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright 2018 Linaro Limited +* Author: AKASHI Takahiro +*/ + +#include <getopt.h> +#include <malloc.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <linux/types.h> +#include <sys/stat.h> +#include <sys/types.h> + +typedef __u8 u8 ; +typedef __u16 u16 ; +typedef __u32 u32 ; +typedef __u64 u64 ; +typedef __s16 s16 ; +typedef __s32 s32 ; + +#define aligned_u64 __aligned_u64 + +#ifndef __packed +#define __packed __attribute__((packed))Quoted 8 lines
tools/mkeficapsule.c
Quoted 8 lines
tools/mkeficapsule.c new file +8
-0+#endif + +#include <efi.h> +#include <efi_api.h> + +static const char *tool_name ="mkeficapsule" ; + +efi_guid_t efi_guid_fm_capsule =
EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID;Quoted 21 lines
Quoted 21 lines
tools/mkeficapsule.c new file +21
-0+efi_guid_t efi_guid_image_type_uboot_fit = +EFI_FIRMWARE_IMAGE_TYPE_UBOOT_FIT_GUID ; +efi_guid_t efi_guid_image_type_uboot_raw = +EFI_FIRMWARE_IMAGE_TYPE_UBOOT_RAW_GUID ; + +static struct option options[] = { + {"fit" , required_argument,NULL ,'f' }, + {"raw" , required_argument,NULL ,'r' }, + {"index" , required_argument,NULL ,'i' }, + {"instance" , required_argument,NULL ,'I' }, + {"version" , required_argument,NULL ,'v' }, + {"help" , no_argument,NULL ,'h' }, + {NULL ,0 ,NULL ,0 }, +}; + +static void print_usage (void ) +{ +printf ("Usage: %s [options] <output file>\n" +"Options:\n" +"\t--fit <fit image> new FIT image file\n" + "\t--raw <raw image> new raw image file\n"Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
tools/mkeficapsule.c
Quoted 8 lines
tools/mkeficapsule.c new file +8
-0+"\t--index <index> update image index\n" +"\t--instance <instance> update hardware instance\n" +"\t--version <version> firmware version\n" +"\t--help print a help message\n" , + tool_name); +} + +static int create_fwbin(char *path, char *bin, efi_guid_t*guid,
Quoted 58 lines
Quoted 58 lines
Quoted 58 lines
Quoted 45 lines
tools/mkeficapsule.c new file +45
-0+ unsigned long version, unsigned long index, + unsigned long instance) +{ + struct efi_capsule_header header; +struct efi_firmware_management_capsule_header capsule; +struct efi_firmware_management_capsule_image_header image; +FILE *f, *g; +struct stat bin_stat; +u8 *data; +size_t size; + +#ifdef DEBUG +printf ("For output: %s\n" , path); +printf ("\tbin: %s\n\ttype: %pUl\n" bin, guid); +printf ("\tversion: %ld\n\tindex: %ld\n\tinstance: %ld\n" , + version, index, instance); +#endif + + g =fopen (bin,"r" ); +if (!g) { +printf ("cannot open %s\n" , bin); +return -1 ; + } +if (stat (bin, &bin_stat) <0 ) { +printf ("cannot determine the size of %s\n" , bin); + goto err_1; + } + data =malloc (bin_stat.st_size); +if (!data) { +printf ("cannot allocate memory: %lx\n" , bin_stat.st_size); + goto err_1; + } + f =fopen (path,"w" ); +if (!f) { +printf ("cannot open %s\n" , path); + goto err_2; + } + header.capsule_guid = efi_guid_fm_capsule; + header.header_size =sizeof (header); + header.flags =CAPSULE_FLAGS_PERSIST_ACROSS_RESET ;/* TODO */ + header.capsule_image_size =sizeof (header) + +sizeof (capsule) +sizeof (u64) + +sizeof (image) + + bin_stat.st_size; +tools/mkeficapsule.c line 119
Quoted 10 lines
tools/mkeficapsule.c new file +10
-0+ size =fwrite (&header,1 ,sizeof (header), f); +if (size <sizeof (header)) { +printf ("write failed (%lx)\n" , size); + goto err_3; + } + + capsule.version =0x00000001 ; + capsule.embedded_driver_count =0 ; + capsule.payload_item_count =1 ; + capsule.item_offset_list[0 ] =sizeof (capsule) +sizeof (u64);With the complete series applied, building
sandbox_defconfig:Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
tools/mkeficapsule.c: In function ?main?:tools/mkeficapsule.c:120:26: warning: array subscript 0 is outsidearray
Quoted 1 line
bounds of ?u64[]? {aka ?long long unsigned int[]?}
[-Warray-bounds]
Quoted 1 line
Quoted 1 line
Quoted 1 line
120 | capsule.item_offset_list[0] = sizeof(capsule) +sizeof(u64);
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
| ~~~~~~~~~~~~~~~~~~~~~~~~^~~Please, ensure that the code compiles without warnings.
Fixing this warning would be easy, but I didn't see it with gcc9.2 (from Linaro/Arm) or even in the results of Travis CI.
So I wonder if it is mandatory that the code compiles without
warnings,
Quoted 1 line
Quoted 1 line
and if so, which compiler and which version are required?
First, can you please make a comment here against my question?
Quoted 4 lines
Quoted 3 lines
-Takahiro Akashi
Quoted 7 lines
Quoted 1 line
Our settings for gitlab CI and Travis CI are that all warnings are
treated as errors.
As I said, I've never seen this warning/error in Travis CI. I don't know how we can confirm the result of gitlab CI.
-Takahiro Akashi
Quoted 7 lines
Just make sure that GCC 10+ does not complain locally.
Tom will update the CI in January. I dont want to see a build error then.
Best regards
Heinrich
Dear Takahiro,
reading through your code it is obvious that this in not only a stray warning by GCC but a veritable bug in your patch.
You define capsule as:
69 ????????struct efi_firmware_management_capsule_header capsule;
capsule.item_offset_list[] has zero bytes.
Here you write outside of your structure:
120 capsule.item_offset_list[0] = sizeof(capsule) + sizeof(u64);
To solve this you could make capsule a pointer.
struct efi_firmware_management_capsule_header *capsule;
capsule = malloc(sizeof(struct efi_firmware_management_capsule_header) +
sizeof(u64));
if (!capusule)
goto err;
capsule.item_offset_list[0] = sizeof(capsule) + sizeof(u64);
Best regards
Heinrich
Quoted 142 lines
Quoted 141 lines
Quoted 11 lines
So we must build without warning.
Best regards
Heinrich
Quoted 2 lines
Quoted 2 lines
I have been using GCC 10.2 as supplied by Debian Bullseye on an
ARM64
Quoted 129 lines
Quoted 128 lines
Quoted 110 lines
system.
Best regards
Heinrich
Quoted 104 lines
tools/mkeficapsule.c new file +104
-0+ size =fwrite (&capsule,1 ,sizeof (capsule) +sizeof (u64), f); +if (size < (sizeof (capsule) +sizeof (u64))) { +printf ("write failed (%lx)\n" , size); + goto err_3; + } + + image.version = version; +memcpy (&image.update_image_type_id, guid,sizeof (*guid)); + image.update_image_index = index; + image.update_image_size = bin_stat.st_size; + image.update_vendor_code_size =0 ;/* none */ + image.update_hardware_instance = instance; + image.image_capsule_support =0 ; + + size =fwrite (&image,1 ,sizeof (image), f); +if (size <sizeof (image)) { +printf ("write failed (%lx)\n" , size); + goto err_3; + } + size =fread (data,1 , bin_stat.st_size, g); +if (size < bin_stat.st_size) { +printf ("read failed (%lx)\n" , size); + goto err_3; + } + size =fwrite (data,1 , bin_stat.st_size, f); +if (size < bin_stat.st_size) { +printf ("write failed (%lx)\n" , size); + goto err_3; + } + +fclose (f); +fclose (g); +free (data); + +return 0 ; + +err_3: +fclose (f); +err_2: +free (data); +err_1: +fclose (g); + +return -1 ; +} + +/* +* Usage: +* $ mkeficapsule -f <firmware binary> <output file> +*/ +int main (int argc,char **argv) +{ +char *file; +efi_guid_t *guid; +unsigned long index, instance, version; +int c, idx; + + file =NULL ; + guid =NULL ; + index =0 ; + instance =0 ; + version =0 ; +for (;;) { + c =getopt_long (argc, argv,"f:r:i:I:v:h" , options, &idx); +if (c ==-1 ) +break ; + +switch (c) { +case 'f' : +if (file) { +printf ("Image already specified\n" ); +return -1 ; + } + file = optarg; + guid = &efi_guid_image_type_uboot_fit; +break ; +case 'r' : +if (file) { +printf ("Image already specified\n" ); +return -1 ; + } + file = optarg; + guid = &efi_guid_image_type_uboot_raw; +break ; +case 'i' : + index =strtoul (optarg,NULL ,0 ); +break ; +case 'I' : + instance =strtoul (optarg,NULL ,0 ); +break ; +case 'v' : + version =strtoul (optarg,NULL ,0 ); +break ; +case 'h' : +print_usage (); +return 0 ; + } + } + +/* need a output file */ +if (argc != optind +1 ) { +print_usage (); +return -1 ; + }Quoted 8 lines
tools/mkeficapsule.c
Quoted 8 lines
tools/mkeficapsule.c new file +8
-0+ +/* need a fit image file or raw image file */ +if (!file) { +print_usage (); +return -1 ; + } + + if (create_fwbin(argv[optind], file, guid, version, index,instance)
Quoted 9 lines
Quoted 8 lines
tools/mkeficapsule.c new file +7
-0+ < 0) { +printf ("Creating firmware capsule failed\n" ); +return -1 ; + } + +return 0 ; +}
PATCH v9 8/11 tools: add mkeficapsule command for UEFI capsule update
Heinrich,
Quoted 208 lines · Heinrich Schuchardt
Quoted 207 lines · Heinrich Schuchardt
Am 25. November 2020 08:32:08 MEZ schrieb AKASHI Takahiro <[email protected]>:
Quoted 193 lines
Heinrich,
Quoted 1 line · Heinrich Schuchardt
Am 25. November 2020 02:05:06 MEZ schrieb AKASHI Takahiro
Quoted 97 lines
Quoted 97 lines
Heinrich,
Quoted 3 lines · Heinrich Schuchardt
Quoted 2 lines · AKASHI Takahiro
This is a utility mainly for test purpose.
mkeficapsule -f: create a test capsule file for FIT imagefirmware
Quoted 8 lines
Quoted 8 lines
Having said that, you will be able to customize the code to fit your specific requirements for your platform.
Signed-off-by AKASHI Takahiro <[email protected]>--- tools/Makefile | 2 + tools/mkeficapsule.c | 238+++++++++++++++++++++++++++++++++++++++++++
Quoted 11 lines
Quoted 11 lines
2 files changed, 240 insertions(+)create mode 100644
tools/mkeficapsule.ctools/Makefile +0
-0@@ -218,6 +218,8 @@ hostprogs-$(CONFIG_MIPS) += mips-relocs hostprogs-$(CONFIG_ASN1_COMPILER) += asn1_compiler HOSTCFLAGS_asn1_compiler.o = -idirafter $(srctree)/includeQuoted 3 lines
tools/Makefile hostprogs-$(CONFIG_MIPS) += mips-relocs · line 223
Quoted 3 lines
tools/Makefile +2
-0+hostprogs-$(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) += mkeficapsule + # We build some files with extra pedantic flags to try tominimize things
Quoted 1 line
tools/Makefile hostprogs-$(CONFIG_MIPS) += mips-relocs · line 224
Quoted 1 line
tools/Makefile +0
-0# that won't build on some weird host compiler -- though thereare lots of
Quoted 34 lines
Quoted 34 lines
tools/Makefile +0
-0# exceptions for files that aren't complaint.tools/mkeficapsule.c new file +27
-0@@ -0,0 +1,238 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright 2018 Linaro Limited +* Author: AKASHI Takahiro +*/ + +#include <getopt.h> +#include <malloc.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <linux/types.h> +#include <sys/stat.h> +#include <sys/types.h> + +typedef __u8 u8 ; +typedef __u16 u16 ; +typedef __u32 u32 ; +typedef __u64 u64 ; +typedef __s16 s16 ; +typedef __s32 s32 ; + +#define aligned_u64 __aligned_u64 + +#ifndef __packed +#define __packed __attribute__((packed))Quoted 8 lines
tools/mkeficapsule.c line 35
Quoted 8 lines
tools/mkeficapsule.c new file +8
-0+#endif + +#include <efi.h> +#include <efi_api.h> + +static const char *tool_name ="mkeficapsule" ; + +efi_guid_t efi_guid_fm_capsule =
EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID;Quoted 21 lines
Quoted 21 lines
tools/mkeficapsule.c new file +21
-0+efi_guid_t efi_guid_image_type_uboot_fit = +EFI_FIRMWARE_IMAGE_TYPE_UBOOT_FIT_GUID ; +efi_guid_t efi_guid_image_type_uboot_raw = +EFI_FIRMWARE_IMAGE_TYPE_UBOOT_RAW_GUID ; + +static struct option options[] = { + {"fit" , required_argument,NULL ,'f' }, + {"raw" , required_argument,NULL ,'r' }, + {"index" , required_argument,NULL ,'i' }, + {"instance" , required_argument,NULL ,'I' }, + {"version" , required_argument,NULL ,'v' }, + {"help" , no_argument,NULL ,'h' }, + {NULL ,0 ,NULL ,0 }, +}; + +static void print_usage (void ) +{ +printf ("Usage: %s [options] <output file>\n" +"Options:\n" +"\t--fit <fit image> new FIT image file\n" + "\t--raw <raw image> new raw image file\n"Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
tools/mkeficapsule.c line 64
Quoted 8 lines
tools/mkeficapsule.c new file +8
-0+"\t--index <index> update image index\n" +"\t--instance <instance> update hardware instance\n" +"\t--version <version> firmware version\n" +"\t--help print a help message\n" , + tool_name); +} + +static int create_fwbin(char *path, char *bin, efi_guid_t*guid,
Quoted 58 lines
Quoted 58 lines
Quoted 58 lines
Quoted 45 lines
tools/mkeficapsule.c new file +45
-0+ unsigned long version, unsigned long index, + unsigned long instance) +{ + struct efi_capsule_header header; +struct efi_firmware_management_capsule_header capsule; +struct efi_firmware_management_capsule_image_header image; +FILE *f, *g; +struct stat bin_stat; +u8 *data; +size_t size; + +#ifdef DEBUG +printf ("For output: %s\n" , path); +printf ("\tbin: %s\n\ttype: %pUl\n" bin, guid); +printf ("\tversion: %ld\n\tindex: %ld\n\tinstance: %ld\n" , + version, index, instance); +#endif + + g =fopen (bin,"r" ); +if (!g) { +printf ("cannot open %s\n" , bin); +return -1 ; + } +if (stat (bin, &bin_stat) <0 ) { +printf ("cannot determine the size of %s\n" , bin); + goto err_1; + } + data =malloc (bin_stat.st_size); +if (!data) { +printf ("cannot allocate memory: %lx\n" , bin_stat.st_size); + goto err_1; + } + f =fopen (path,"w" ); +if (!f) { +printf ("cannot open %s\n" , path); + goto err_2; + } + header.capsule_guid = efi_guid_fm_capsule; + header.header_size =sizeof (header); + header.flags =CAPSULE_FLAGS_PERSIST_ACROSS_RESET ;/* TODO */ + header.capsule_image_size =sizeof (header) + +sizeof (capsule) +sizeof (u64) + +sizeof (image) + + bin_stat.st_size; +tools/mkeficapsule.c line 119
Quoted 10 lines
tools/mkeficapsule.c new file +10
-0+ size =fwrite (&header,1 ,sizeof (header), f); +if (size <sizeof (header)) { +printf ("write failed (%lx)\n" , size); + goto err_3; + } + + capsule.version =0x00000001 ; + capsule.embedded_driver_count =0 ; + capsule.payload_item_count =1 ; + capsule.item_offset_list[0 ] =sizeof (capsule) +sizeof (u64);With the complete series applied, building
sandbox_defconfig:Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
tools/mkeficapsule.c: In function ?main?:tools/mkeficapsule.c:120:26: warning: array subscript 0 is outsidearray
Quoted 1 line
bounds of ?u64[]? {aka ?long long unsigned int[]?}
[-Warray-bounds]
Quoted 1 line
Quoted 1 line
Quoted 1 line
120 | capsule.item_offset_list[0] = sizeof(capsule) +sizeof(u64);
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
| ~~~~~~~~~~~~~~~~~~~~~~~~^~~Please, ensure that the code compiles without warnings.
Fixing this warning would be easy, but I didn't see it with gcc9.2 (from Linaro/Arm) or even in the results of Travis CI.
So I wonder if it is mandatory that the code compiles without
warnings,
Quoted 1 line
Quoted 1 line
and if so, which compiler and which version are required?
First, can you please make a comment here against my question?
Quoted 4 lines
Quoted 3 lines
-Takahiro Akashi
Quoted 7 lines
Quoted 1 line
Our settings for gitlab CI and Travis CI are that all warnings are
treated as errors.
As I said, I've never seen this warning/error in Travis CI. I don't know how we can confirm the result of gitlab CI.
-Takahiro Akashi
Just make sure that GCC 10+ does not complain locally.
Tom will update the CI in January. I dont want to see a build error then.
Quoted 8 lines
Quoted 3 lines
Best regards
Heinrich
Dear Takahiro,
reading through your code it is obvious that this in not only a stray warning by GCC but a veritable bug in your patch.
Yes, I know.
That is why I said:
(https://lists.denx.de/pipermail/u-boot/2020-November/433453.html)
Quoted 3 lines
Oops, I found that this is not a warning, but a potential bug. The code does overrun a variable, capsule, allocated on the stack while it is apparently harmless as the neighboring variable, image, is initialized later.
-Takahiro Akashi
Quoted 169 lines
You define capsule as:
69 ????????struct
efi_firmware_management_capsule_headercapsule;capsule.item_offset_list[] has zero bytes.
Here you write outside of your structure:
120 capsule.item_offset_list[0] = sizeof(capsule) + sizeof(u64);
To solve this you could make capsule a pointer.
struct
efi_firmware_management_capsule_header*capsule;capsule = malloc(sizeof(struct
efi_firmware_management_capsule_header) +sizeof(u64));if (!capusule)
goto err;capsule.item_offset_list[0] = sizeof(capsule) + sizeof(u64);
Best regards
Heinrich
Quoted 142 lines
Quoted 141 lines
Quoted 11 lines
So we must build without warning.
Best regards
Heinrich
Quoted 2 lines
Quoted 2 lines
I have been using GCC 10.2 as supplied by Debian Bullseye on an
ARM64
Quoted 129 lines
Quoted 128 lines
Quoted 110 lines
system.
Best regards
Heinrich
Quoted 104 lines
tools/mkeficapsule.c new file +104
-0+ size =fwrite (&capsule,1 ,sizeof (capsule) +sizeof (u64), f); +if (size < (sizeof (capsule) +sizeof (u64))) { +printf ("write failed (%lx)\n" , size); + goto err_3; + } + + image.version = version; +memcpy (&image.update_image_type_id, guid,sizeof (*guid)); + image.update_image_index = index; + image.update_image_size = bin_stat.st_size; + image.update_vendor_code_size =0 ;/* none */ + image.update_hardware_instance = instance; + image.image_capsule_support =0 ; + + size =fwrite (&image,1 ,sizeof (image), f); +if (size <sizeof (image)) { +printf ("write failed (%lx)\n" , size); + goto err_3; + } + size =fread (data,1 , bin_stat.st_size, g); +if (size < bin_stat.st_size) { +printf ("read failed (%lx)\n" , size); + goto err_3; + } + size =fwrite (data,1 , bin_stat.st_size, f); +if (size < bin_stat.st_size) { +printf ("write failed (%lx)\n" , size); + goto err_3; + } + +fclose (f); +fclose (g); +free (data); + +return 0 ; + +err_3: +fclose (f); +err_2: +free (data); +err_1: +fclose (g); + +return -1 ; +} + +/* +* Usage: +* $ mkeficapsule -f <firmware binary> <output file> +*/ +int main (int argc,char **argv) +{ +char *file; +efi_guid_t *guid; +unsigned long index, instance, version; +int c, idx; + + file =NULL ; + guid =NULL ; + index =0 ; + instance =0 ; + version =0 ; +for (;;) { + c =getopt_long (argc, argv,"f:r:i:I:v:h" , options, &idx); +if (c ==-1 ) +break ; + +switch (c) { +case 'f' : +if (file) { +printf ("Image already specified\n" ); +return -1 ; + } + file = optarg; + guid = &efi_guid_image_type_uboot_fit; +break ; +case 'r' : +if (file) { +printf ("Image already specified\n" ); +return -1 ; + } + file = optarg; + guid = &efi_guid_image_type_uboot_raw; +break ; +case 'i' : + index =strtoul (optarg,NULL ,0 ); +break ; +case 'I' : + instance =strtoul (optarg,NULL ,0 ); +break ; +case 'v' : + version =strtoul (optarg,NULL ,0 ); +break ; +case 'h' : +print_usage (); +return 0 ; + } + } + +/* need a output file */ +if (argc != optind +1 ) { +print_usage (); +return -1 ; + }Quoted 8 lines
tools/mkeficapsule.c line 231
Quoted 8 lines
tools/mkeficapsule.c new file +8
-0+ +/* need a fit image file or raw image file */ +if (!file) { +print_usage (); +return -1 ; + } + + if (create_fwbin(argv[optind], file, guid, version, index,instance)
Quoted 9 lines
Quoted 8 lines
tools/mkeficapsule.c new file +7
-0+ < 0) { +printf ("Creating firmware capsule failed\n" ); +return -1 ; + } + +return 0 ; +}
PATCH v9 8/11 tools: add mkeficapsule command for UEFI capsule update
In reply to Heinrich SchuchardtSughosh,
Quoted 170 lines · Heinrich Schuchardt
Quoted 141 lines · AKASHI Takahiro
This is a utility mainly for test purpose.
mkeficapsule -f: create a test capsule file for FIT image firmwareHaving said that, you will be able to customize the code to fit your specific requirements for your platform.
Signed-off-by AKASHI Takahiro <[email protected]>--- tools/Makefile | 2 + tools/mkeficapsule.c | 238 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 240 insertions(+)create mode 100644
tools/mkeficapsule.ctools/Makefile +2
-0@@ -218,6 +218,8 @@ hostprogs-$(CONFIG_MIPS) += mips-relocs hostprogs-$(CONFIG_ASN1_COMPILER) += asn1_compiler HOSTCFLAGS_asn1_compiler.o = -idirafter $(srctree)/include +hostprogs-$(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) += mkeficapsule + # We build some files with extra pedantic flags to try to minimize things # that won't build on some weird host compiler -- though there are lots of # exceptions for files that aren't complaint.tools/mkeficapsule.c new file +109
-0@@ -0,0 +1,238 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright 2018 Linaro Limited +* Author: AKASHI Takahiro +*/ + +#include <getopt.h> +#include <malloc.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <linux/types.h> +#include <sys/stat.h> +#include <sys/types.h> + +typedef __u8 u8 ; +typedef __u16 u16 ; +typedef __u32 u32 ; +typedef __u64 u64 ; +typedef __s16 s16 ; +typedef __s32 s32 ; + +#define aligned_u64 __aligned_u64 + +#ifndef __packed +#define __packed __attribute__((packed)) +#endif + +#include <efi.h> +#include <efi_api.h> + +static const char *tool_name ="mkeficapsule" ; + +efi_guid_t efi_guid_fm_capsule =EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID ; +efi_guid_t efi_guid_image_type_uboot_fit = +EFI_FIRMWARE_IMAGE_TYPE_UBOOT_FIT_GUID ; +efi_guid_t efi_guid_image_type_uboot_raw = +EFI_FIRMWARE_IMAGE_TYPE_UBOOT_RAW_GUID ; + +static struct option options[] = { + {"fit" , required_argument,NULL ,'f' }, + {"raw" , required_argument,NULL ,'r' }, + {"index" , required_argument,NULL ,'i' }, + {"instance" , required_argument,NULL ,'I' }, + {"version" , required_argument,NULL ,'v' }, + {"help" , no_argument,NULL ,'h' }, + {NULL ,0 ,NULL ,0 }, +}; + +static void print_usage (void ) +{ +printf ("Usage: %s [options] <output file>\n" +"Options:\n" +"\t--fit <fit image> new FIT image file\n" +"\t--raw <raw image> new raw image file\n" +"\t--index <index> update image index\n" +"\t--instance <instance> update hardware instance\n" +"\t--version <version> firmware version\n" +"\t--help print a help message\n" , + tool_name); +} + +static int create_fwbin (char *path,char *bin,efi_guid_t *guid, +unsigned long version,unsigned long index, +unsigned long instance) +{ +struct efi_capsule_header header; +struct efi_firmware_management_capsule_header capsule; +struct efi_firmware_management_capsule_image_header image; +FILE *f, *g; +struct stat bin_stat; +u8 *data; +size_t size; + +#ifdef DEBUG +printf ("For output: %s\n" , path); +printf ("\tbin: %s\n\ttype: %pUl\n" bin, guid); +printf ("\tversion: %ld\n\tindex: %ld\n\tinstance: %ld\n" , + version, index, instance); +#endif + + g =fopen (bin,"r" ); +if (!g) { +printf ("cannot open %s\n" , bin); +return -1 ; + } +if (stat (bin, &bin_stat) <0 ) { +printf ("cannot determine the size of %s\n" , bin); + goto err_1; + } + data =malloc (bin_stat.st_size); +if (!data) { +printf ("cannot allocate memory: %lx\n" , bin_stat.st_size); + goto err_1; + } + f =fopen (path,"w" ); +if (!f) { +printf ("cannot open %s\n" , path); + goto err_2; + } + header.capsule_guid = efi_guid_fm_capsule; + header.header_size =sizeof (header); + header.flags =CAPSULE_FLAGS_PERSIST_ACROSS_RESET ;/* TODO */ + header.capsule_image_size =sizeof (header) + +sizeof (capsule) +sizeof (u64) + +sizeof (image) + + bin_stat.st_size; +tools/mkeficapsule.c line 119
Quoted 10 lines
tools/mkeficapsule.c new file +10
-0+ size =fwrite (&header,1 ,sizeof (header), f); +if (size <sizeof (header)) { +printf ("write failed (%lx)\n" , size); + goto err_3; + } + + capsule.version =0x00000001 ; + capsule.embedded_driver_count =0 ; + capsule.payload_item_count =1 ; + capsule.item_offset_list[0 ] =sizeof (capsule) +sizeof (u64);With the complete series applied, building
sandbox_defconfig:
tools/mkeficapsule.c: In function ?main?:tools/mkeficapsule.c:120:26: warning: array subscript 0 is outside array bounds of ?u64[]? {aka ?long long unsigned int[]?} [-Warray-bounds]120 | capsule.item_offset_list[0] = sizeof(capsule) + sizeof(u64); | ~~~~~~~~~~~~~~~~~~~~~~~~^~~Please, ensure that the code compiles without warnings.
I have been using GCC 10.2 as supplied by Debian Bullseye on an ARM64 system.
Best regards
Heinrich
Quoted 7 lines
tools/mkeficapsule.c line 126
Quoted 7 lines
tools/mkeficapsule.c new file +7
-0+ size =fwrite (&capsule,1 ,sizeof (capsule) +sizeof (u64), f); +if (size < (sizeof (capsule) +sizeof (u64))) { +printf ("write failed (%lx)\n" , size); + goto err_3; + } + + image.version = version;
After some cleanup works, I found that the version was wrongly set here. The value of 'version' in this structure must be the one of this structure's layout, not the one for firmware itself. So I decided to remove "--version" option from the command. (Note U-Boot has no notion of "firmware version" anyway.)
I hope that this change won't hinder your effort in extending this command for capsule authentication.
Thanks,
-Takahiro Akashi
Quoted 114 lines
Quoted 113 lines
tools/mkeficapsule.c new file +112
-0+memcpy (&image.update_image_type_id, guid,sizeof (*guid)); + image.update_image_index = index; + image.update_image_size = bin_stat.st_size; + image.update_vendor_code_size =0 ;/* none */ + image.update_hardware_instance = instance; + image.image_capsule_support =0 ; + + size =fwrite (&image,1 ,sizeof (image), f); +if (size <sizeof (image)) { +printf ("write failed (%lx)\n" , size); + goto err_3; + } + size =fread (data,1 , bin_stat.st_size, g); +if (size < bin_stat.st_size) { +printf ("read failed (%lx)\n" , size); + goto err_3; + } + size =fwrite (data,1 , bin_stat.st_size, f); +if (size < bin_stat.st_size) { +printf ("write failed (%lx)\n" , size); + goto err_3; + } + +fclose (f); +fclose (g); +free (data); + +return 0 ; + +err_3: +fclose (f); +err_2: +free (data); +err_1: +fclose (g); + +return -1 ; +} + +/* +* Usage: +* $ mkeficapsule -f <firmware binary> <output file> +*/ +int main (int argc,char **argv) +{ +char *file; +efi_guid_t *guid; +unsigned long index, instance, version; +int c, idx; + + file =NULL ; + guid =NULL ; + index =0 ; + instance =0 ; + version =0 ; +for (;;) { + c =getopt_long (argc, argv,"f:r:i:I:v:h" , options, &idx); +if (c ==-1 ) +break ; + +switch (c) { +case 'f' : +if (file) { +printf ("Image already specified\n" ); +return -1 ; + } + file = optarg; + guid = &efi_guid_image_type_uboot_fit; +break ; +case 'r' : +if (file) { +printf ("Image already specified\n" ); +return -1 ; + } + file = optarg; + guid = &efi_guid_image_type_uboot_raw; +break ; +case 'i' : + index =strtoul (optarg,NULL ,0 ); +break ; +case 'I' : + instance =strtoul (optarg,NULL ,0 ); +break ; +case 'v' : + version =strtoul (optarg,NULL ,0 ); +break ; +case 'h' : +print_usage (); +return 0 ; + } + } + +/* need a output file */ +if (argc != optind +1 ) { +print_usage (); +return -1 ; + } + +/* need a fit image file or raw image file */ +if (!file) { +print_usage (); +return -1 ; + } + +if (create_fwbin (argv[optind], file, guid, version, index, instance) + <0 ) { +printf ("Creating firmware capsule failed\n" ); +return -1 ; + } + +return 0 ; +}
PATCH v9 8/11 tools: add mkeficapsule command for UEFI capsule update
Takahiro,
Quoted 185 lines · AKASHI Takahiro
Sughosh,
Quoted 11 lines · Heinrich Schuchardt
Quoted 10 lines · AKASHI Takahiro
This is a utility mainly for test purpose.
mkeficapsule -f: create a test capsule file for FIT image firmwareHaving said that, you will be able to customize the code to fit your specific requirements for your platform.
Signed-off-by AKASHI Takahiro <[email protected]>--- tools/Makefile | 2 + tools/mkeficapsule.c | 238+++++++++++++++++++++++++++++++++++++++++++
Quoted 11 lines
Quoted 11 lines
2 files changed, 240 insertions(+)create mode 100644
tools/mkeficapsule.ctools/Makefile +0
-0@@ -218,6 +218,8 @@ hostprogs-$(CONFIG_MIPS) += mips-relocs hostprogs-$(CONFIG_ASN1_COMPILER) += asn1_compiler HOSTCFLAGS_asn1_compiler.o = -idirafter $(srctree)/includeQuoted 3 lines
tools/Makefile hostprogs-$(CONFIG_MIPS) += mips-relocs
Quoted 3 lines
tools/Makefile +2
-0+hostprogs-$(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) += mkeficapsule + # We build some files with extra pedantic flags to try to minimizethings
Quoted 1 line
tools/Makefile hostprogs-$(CONFIG_MIPS) += mips-relocs · line 224
Quoted 1 line
tools/Makefile +0
-0# that won't build on some weird host compiler -- though there arelots of
Quoted 34 lines
Quoted 34 lines
tools/Makefile +0
-0# exceptions for files that aren't complaint.tools/mkeficapsule.c new file +27
-0@@ -0,0 +1,238 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright 2018 Linaro Limited +* Author: AKASHI Takahiro +*/ + +#include <getopt.h> +#include <malloc.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <linux/types.h> +#include <sys/stat.h> +#include <sys/types.h> + +typedef __u8 u8 ; +typedef __u16 u16 ; +typedef __u32 u32 ; +typedef __u64 u64 ; +typedef __s16 s16 ; +typedef __s32 s32 ; + +#define aligned_u64 __aligned_u64 + +#ifndef __packed +#define __packed __attribute__((packed))Quoted 8 lines
tools/mkeficapsule.c
Quoted 8 lines
tools/mkeficapsule.c new file +8
-0+#endif + +#include <efi.h> +#include <efi_api.h> + +static const char *tool_name ="mkeficapsule" ; + +efi_guid_t efi_guid_fm_capsule =
EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID;Quoted 93 lines
Quoted 74 lines
tools/mkeficapsule.c new file +74
-0+efi_guid_t efi_guid_image_type_uboot_fit = +EFI_FIRMWARE_IMAGE_TYPE_UBOOT_FIT_GUID ; +efi_guid_t efi_guid_image_type_uboot_raw = +EFI_FIRMWARE_IMAGE_TYPE_UBOOT_RAW_GUID ; + +static struct option options[] = { + {"fit" , required_argument,NULL ,'f' }, + {"raw" , required_argument,NULL ,'r' }, + {"index" , required_argument,NULL ,'i' }, + {"instance" , required_argument,NULL ,'I' }, + {"version" , required_argument,NULL ,'v' }, + {"help" , no_argument,NULL ,'h' }, + {NULL ,0 ,NULL ,0 }, +}; + +static void print_usage (void ) +{ +printf ("Usage: %s [options] <output file>\n" +"Options:\n" +"\t--fit <fit image> new FIT image file\n" +"\t--raw <raw image> new raw image file\n" +"\t--index <index> update image index\n" +"\t--instance <instance> update hardware instance\n" +"\t--version <version> firmware version\n" +"\t--help print a help message\n" , + tool_name); +} + +static int create_fwbin (char *path,char *bin,efi_guid_t *guid, +unsigned long version,unsigned long index, +unsigned long instance) +{ +struct efi_capsule_header header; +struct efi_firmware_management_capsule_header capsule; +struct efi_firmware_management_capsule_image_header image; +FILE *f, *g; +struct stat bin_stat; +u8 *data; +size_t size; + +#ifdef DEBUG +printf ("For output: %s\n" , path); +printf ("\tbin: %s\n\ttype: %pUl\n" bin, guid); +printf ("\tversion: %ld\n\tindex: %ld\n\tinstance: %ld\n" , + version, index, instance); +#endif + + g =fopen (bin,"r" ); +if (!g) { +printf ("cannot open %s\n" , bin); +return -1 ; + } +if (stat (bin, &bin_stat) <0 ) { +printf ("cannot determine the size of %s\n" , bin); + goto err_1; + } + data =malloc (bin_stat.st_size); +if (!data) { +printf ("cannot allocate memory: %lx\n" , bin_stat.st_size); + goto err_1; + } + f =fopen (path,"w" ); +if (!f) { +printf ("cannot open %s\n" , path); + goto err_2; + } + header.capsule_guid = efi_guid_fm_capsule; + header.header_size =sizeof (header); + header.flags =CAPSULE_FLAGS_PERSIST_ACROSS_RESET ;/* TODO */ + header.capsule_image_size =sizeof (header) + +sizeof (capsule) +sizeof (u64) + +sizeof (image) + + bin_stat.st_size; +tools/mkeficapsule.c line 119
Quoted 10 lines
tools/mkeficapsule.c new file +10
-0+ size =fwrite (&header,1 ,sizeof (header), f); +if (size <sizeof (header)) { +printf ("write failed (%lx)\n" , size); + goto err_3; + } + + capsule.version =0x00000001 ; + capsule.embedded_driver_count =0 ; + capsule.payload_item_count =1 ; + capsule.item_offset_list[0 ] =sizeof (capsule) +sizeof (u64);With the complete series applied, building
sandbox_defconfig:
tools/mkeficapsule.c: In function ?main?:tools/mkeficapsule.c:120:26: warning: array subscript 0 is outside array bounds of ?u64[]? {aka ?long long unsigned int[]?} [-Warray-bounds]120 | capsule.item_offset_list[0] = sizeof(capsule) + sizeof(u64); | ~~~~~~~~~~~~~~~~~~~~~~~~^~~Quoted 16 lines
Please, ensure that the code compiles without warnings.
I have been using GCC 10.2 as supplied by Debian Bullseye on an ARM64 system.
Best regards
Heinrich
Quoted 7 lines
tools/mkeficapsule.c new file +7
-0+ size =fwrite (&capsule,1 ,sizeof (capsule) +sizeof (u64), f); +if (size < (sizeof (capsule) +sizeof (u64))) { +printf ("write failed (%lx)\n" , size); + goto err_3; + } + + image.version = version;
Quoted 9 lines
After some cleanup works, I found that the version was wrongly set here. The value of 'version' in this structure must be the one of this structure's layout, not the one for firmware itself. So I decided to remove "--version" option from the command. (Note U-Boot has no notion of "firmware version" anyway.)
I hope that this change won't hinder your effort in extending this command for capsule authentication.
Your change to remove the 'version' option would not hinder my changes to add the public-key certificate to the dtb for capsule authentication.
-sughosh
Quoted 121 lines
Thanks,
-Takahiro AkashiQuoted 97 lines
Quoted 97 lines
tools/mkeficapsule.c new file +97
-0+memcpy (&image.update_image_type_id, guid,sizeof (*guid)); + image.update_image_index = index; + image.update_image_size = bin_stat.st_size; + image.update_vendor_code_size =0 ;/* none */ + image.update_hardware_instance = instance; + image.image_capsule_support =0 ; + + size =fwrite (&image,1 ,sizeof (image), f); +if (size <sizeof (image)) { +printf ("write failed (%lx)\n" , size); + goto err_3; + } + size =fread (data,1 , bin_stat.st_size, g); +if (size < bin_stat.st_size) { +printf ("read failed (%lx)\n" , size); + goto err_3; + } + size =fwrite (data,1 , bin_stat.st_size, f); +if (size < bin_stat.st_size) { +printf ("write failed (%lx)\n" , size); + goto err_3; + } + +fclose (f); +fclose (g); +free (data); + +return 0 ; + +err_3: +fclose (f); +err_2: +free (data); +err_1: +fclose (g); + +return -1 ; +} + +/* +* Usage: +* $ mkeficapsule -f <firmware binary> <output file> +*/ +int main (int argc,char **argv) +{ +char *file; +efi_guid_t *guid; +unsigned long index, instance, version; +int c, idx; + + file =NULL ; + guid =NULL ; + index =0 ; + instance =0 ; + version =0 ; +for (;;) { + c =getopt_long (argc, argv,"f:r:i:I:v:h" , options, &idx); +if (c ==-1 ) +break ; + +switch (c) { +case 'f' : +if (file) { +printf ("Image already specified\n" ); +return -1 ; + } + file = optarg; + guid = &efi_guid_image_type_uboot_fit; +break ; +case 'r' : +if (file) { +printf ("Image already specified\n" ); +return -1 ; + } + file = optarg; + guid = &efi_guid_image_type_uboot_raw; +break ; +case 'i' : + index =strtoul (optarg,NULL ,0 ); +break ; +case 'I' : + instance =strtoul (optarg,NULL ,0 ); +break ; +case 'v' : + version =strtoul (optarg,NULL ,0 ); +break ; +case 'h' : +print_usage (); +return 0 ; + } + } + +/* need a output file */ +if (argc != optind +1 ) { +print_usage (); +return -1 ; + }Quoted 8 lines
tools/mkeficapsule.c
Quoted 8 lines
tools/mkeficapsule.c new file +8
-0+ +/* need a fit image file or raw image file */ +if (!file) { +print_usage (); +return -1 ; + } + + if (create_fwbin(argv[optind], file, guid, version, index,instance)
Quoted 9 lines
Quoted 8 lines
tools/mkeficapsule.c new file +7
-0+ < 0) { +printf ("Creating firmware capsule failed\n" ); +return -1 ; + } + +return 0 ; +}
PATCH v9 8/11 tools: add mkeficapsule command for UEFI capsule update
Quoted 196 lines · Sughosh Ganu
Takahiro,
Quoted 191 lines · AKASHI Takahiro
Sughosh,
Quoted 11 lines · Heinrich Schuchardt
Quoted 10 lines · AKASHI Takahiro
This is a utility mainly for test purpose.
mkeficapsule -f: create a test capsule file for FIT image firmwareHaving said that, you will be able to customize the code to fit your specific requirements for your platform.
Signed-off-by AKASHI Takahiro <[email protected]>--- tools/Makefile | 2 + tools/mkeficapsule.c | 238+++++++++++++++++++++++++++++++++++++++++++
Quoted 11 lines
Quoted 11 lines
2 files changed, 240 insertions(+)create mode 100644
tools/mkeficapsule.ctools/Makefile +0
-0@@ -218,6 +218,8 @@ hostprogs-$(CONFIG_MIPS) += mips-relocs hostprogs-$(CONFIG_ASN1_COMPILER) += asn1_compiler HOSTCFLAGS_asn1_compiler.o = -idirafter $(srctree)/includeQuoted 3 lines
tools/Makefile hostprogs-$(CONFIG_MIPS) += mips-relocs
Quoted 3 lines
tools/Makefile +2
-0+hostprogs-$(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) += mkeficapsule + # We build some files with extra pedantic flags to try to minimizethings
Quoted 1 line
tools/Makefile hostprogs-$(CONFIG_MIPS) += mips-relocs · line 224
Quoted 1 line
tools/Makefile +0
-0# that won't build on some weird host compiler -- though there arelots of
Quoted 34 lines
Quoted 34 lines
tools/Makefile +0
-0# exceptions for files that aren't complaint.tools/mkeficapsule.c new file +27
-0@@ -0,0 +1,238 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright 2018 Linaro Limited +* Author: AKASHI Takahiro +*/ + +#include <getopt.h> +#include <malloc.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <linux/types.h> +#include <sys/stat.h> +#include <sys/types.h> + +typedef __u8 u8 ; +typedef __u16 u16 ; +typedef __u32 u32 ; +typedef __u64 u64 ; +typedef __s16 s16 ; +typedef __s32 s32 ; + +#define aligned_u64 __aligned_u64 + +#ifndef __packed +#define __packed __attribute__((packed))Quoted 8 lines
tools/mkeficapsule.c
Quoted 8 lines
tools/mkeficapsule.c new file +8
-0+#endif + +#include <efi.h> +#include <efi_api.h> + +static const char *tool_name ="mkeficapsule" ; + +efi_guid_t efi_guid_fm_capsule =
EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID;Quoted 93 lines
Quoted 74 lines
tools/mkeficapsule.c new file +74
-0+efi_guid_t efi_guid_image_type_uboot_fit = +EFI_FIRMWARE_IMAGE_TYPE_UBOOT_FIT_GUID ; +efi_guid_t efi_guid_image_type_uboot_raw = +EFI_FIRMWARE_IMAGE_TYPE_UBOOT_RAW_GUID ; + +static struct option options[] = { + {"fit" , required_argument,NULL ,'f' }, + {"raw" , required_argument,NULL ,'r' }, + {"index" , required_argument,NULL ,'i' }, + {"instance" , required_argument,NULL ,'I' }, + {"version" , required_argument,NULL ,'v' }, + {"help" , no_argument,NULL ,'h' }, + {NULL ,0 ,NULL ,0 }, +}; + +static void print_usage (void ) +{ +printf ("Usage: %s [options] <output file>\n" +"Options:\n" +"\t--fit <fit image> new FIT image file\n" +"\t--raw <raw image> new raw image file\n" +"\t--index <index> update image index\n" +"\t--instance <instance> update hardware instance\n" +"\t--version <version> firmware version\n" +"\t--help print a help message\n" , + tool_name); +} + +static int create_fwbin (char *path,char *bin,efi_guid_t *guid, +unsigned long version,unsigned long index, +unsigned long instance) +{ +struct efi_capsule_header header; +struct efi_firmware_management_capsule_header capsule; +struct efi_firmware_management_capsule_image_header image; +FILE *f, *g; +struct stat bin_stat; +u8 *data; +size_t size; + +#ifdef DEBUG +printf ("For output: %s\n" , path); +printf ("\tbin: %s\n\ttype: %pUl\n" bin, guid); +printf ("\tversion: %ld\n\tindex: %ld\n\tinstance: %ld\n" , + version, index, instance); +#endif + + g =fopen (bin,"r" ); +if (!g) { +printf ("cannot open %s\n" , bin); +return -1 ; + } +if (stat (bin, &bin_stat) <0 ) { +printf ("cannot determine the size of %s\n" , bin); + goto err_1; + } + data =malloc (bin_stat.st_size); +if (!data) { +printf ("cannot allocate memory: %lx\n" , bin_stat.st_size); + goto err_1; + } + f =fopen (path,"w" ); +if (!f) { +printf ("cannot open %s\n" , path); + goto err_2; + } + header.capsule_guid = efi_guid_fm_capsule; + header.header_size =sizeof (header); + header.flags =CAPSULE_FLAGS_PERSIST_ACROSS_RESET ;/* TODO */ + header.capsule_image_size =sizeof (header) + +sizeof (capsule) +sizeof (u64) + +sizeof (image) + + bin_stat.st_size; +tools/mkeficapsule.c line 119
Quoted 10 lines
tools/mkeficapsule.c new file +10
-0+ size =fwrite (&header,1 ,sizeof (header), f); +if (size <sizeof (header)) { +printf ("write failed (%lx)\n" , size); + goto err_3; + } + + capsule.version =0x00000001 ; + capsule.embedded_driver_count =0 ; + capsule.payload_item_count =1 ; + capsule.item_offset_list[0 ] =sizeof (capsule) +sizeof (u64);With the complete series applied, building
sandbox_defconfig:
tools/mkeficapsule.c: In function ?main?:tools/mkeficapsule.c:120:26: warning: array subscript 0 is outside array bounds of ?u64[]? {aka ?long long unsigned int[]?} [-Warray-bounds]120 | capsule.item_offset_list[0] = sizeof(capsule) + sizeof(u64); | ~~~~~~~~~~~~~~~~~~~~~~~~^~~Quoted 16 lines
Please, ensure that the code compiles without warnings.
I have been using GCC 10.2 as supplied by Debian Bullseye on an ARM64 system.
Best regards
Heinrich
Quoted 7 lines
tools/mkeficapsule.c new file +7
-0+ size =fwrite (&capsule,1 ,sizeof (capsule) +sizeof (u64), f); +if (size < (sizeof (capsule) +sizeof (u64))) { +printf ("write failed (%lx)\n" , size); + goto err_3; + } + + image.version = version;After some cleanup works, I found that the version was wrongly set here. The value of 'version' in this structure must be the one of this structure's layout, not the one for firmware itself. So I decided to remove "--version" option from the command. (Note U-Boot has no notion of "firmware version" anyway.)
Quoted 6 lines
Quoted 3 lines
I hope that this change won't hinder your effort in extending this command for capsule authentication.
Your change to remove the 'version' option would not hinder my changes to add the public-key certificate to the dtb for capsule authentication.
Thank you for the confirmation.
-Takahiro Akashi
Quoted 124 lines
-sughosh
Quoted 121 lines
Thanks,
-Takahiro AkashiQuoted 97 lines
Quoted 97 lines
tools/mkeficapsule.c new file +97
-0+memcpy (&image.update_image_type_id, guid,sizeof (*guid)); + image.update_image_index = index; + image.update_image_size = bin_stat.st_size; + image.update_vendor_code_size =0 ;/* none */ + image.update_hardware_instance = instance; + image.image_capsule_support =0 ; + + size =fwrite (&image,1 ,sizeof (image), f); +if (size <sizeof (image)) { +printf ("write failed (%lx)\n" , size); + goto err_3; + } + size =fread (data,1 , bin_stat.st_size, g); +if (size < bin_stat.st_size) { +printf ("read failed (%lx)\n" , size); + goto err_3; + } + size =fwrite (data,1 , bin_stat.st_size, f); +if (size < bin_stat.st_size) { +printf ("write failed (%lx)\n" , size); + goto err_3; + } + +fclose (f); +fclose (g); +free (data); + +return 0 ; + +err_3: +fclose (f); +err_2: +free (data); +err_1: +fclose (g); + +return -1 ; +} + +/* +* Usage: +* $ mkeficapsule -f <firmware binary> <output file> +*/ +int main (int argc,char **argv) +{ +char *file; +efi_guid_t *guid; +unsigned long index, instance, version; +int c, idx; + + file =NULL ; + guid =NULL ; + index =0 ; + instance =0 ; + version =0 ; +for (;;) { + c =getopt_long (argc, argv,"f:r:i:I:v:h" , options, &idx); +if (c ==-1 ) +break ; + +switch (c) { +case 'f' : +if (file) { +printf ("Image already specified\n" ); +return -1 ; + } + file = optarg; + guid = &efi_guid_image_type_uboot_fit; +break ; +case 'r' : +if (file) { +printf ("Image already specified\n" ); +return -1 ; + } + file = optarg; + guid = &efi_guid_image_type_uboot_raw; +break ; +case 'i' : + index =strtoul (optarg,NULL ,0 ); +break ; +case 'I' : + instance =strtoul (optarg,NULL ,0 ); +break ; +case 'v' : + version =strtoul (optarg,NULL ,0 ); +break ; +case 'h' : +print_usage (); +return 0 ; + } + } + +/* need a output file */ +if (argc != optind +1 ) { +print_usage (); +return -1 ; + }Quoted 8 lines
tools/mkeficapsule.c
Quoted 8 lines
tools/mkeficapsule.c new file +8
-0+ +/* need a fit image file or raw image file */ +if (!file) { +print_usage (); +return -1 ; + } + + if (create_fwbin(argv[optind], file, guid, version, index,instance)
Quoted 9 lines
Quoted 8 lines
tools/mkeficapsule.c new file +7
-0+ < 0) { +printf ("Creating firmware capsule failed\n" ); +return -1 ; + } + +return 0 ; +}
PATCH v9 9/11 test/py: efi_capsule: test for FIT image capsule
In reply to AKASHI TakahiroThe test can run on sandbox build and it attempts to execute a firmware update via a capsule-on-disk, using a FIT image capsule, CONFIG_EFI_CAPSULE_FIT.
To run this test successfully, you need configure U-Boot specifically; See test_capsule_firmware.py for requirements, and hence it won't run on Travis CI, at least, for now.
--- .../py/tests/test_efi_capsule/capsule_defs.py | 5 + test/py/tests/test_efi_capsule/conftest.py | 71 +++++++ .../test_efi_capsule/test_capsule_firmware.py | 178 ++++++++++++++++++ .../tests/test_efi_capsule/uboot_bin_env.its | 36 ++++ tools/mkeficapsule.c | 3 +- 5 files changed, 292 insertions(+), 1 deletion(-) create mode 100644 test/py/tests/test_efi_capsule/capsule_defs.py create mode 100644 test/py/tests/test_efi_capsule/conftest.py create mode 100644 test/py/tests/test_efi_capsule/test_capsule_firmware.py create mode 100644 test/py/tests/test_efi_capsule/uboot_bin_env.its
test/py/tests/test_efi_capsule/capsule_defs.py new file +5 -0
@@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0+ + +# Directories +CAPSULE_DATA_DIR = '/EFI/CapsuleTestData' +CAPSULE_INSTALL_DIR = '/EFI/UpdateCapsule'
test/py/tests/test_efi_capsule/conftest.py new file +71 -0
71 lines not on this page · raw message
test/py/tests/test_efi_capsule/test_capsule_firmware.py new file +178 -0
178 lines not on this page · raw message
test/py/tests/test_efi_capsule/uboot_bin_env.its new file +36 -0
@@ -0,0 +1,36 @@ +/* + * Automatic software update for U-Boot + * Make sure the flashing addresses ('load' prop) is correct for your board! + */ + +/dts-v1/; + +/ { + description = "Automatic U-Boot environment update"; + #address-cells = <2>; + + images { + u-boot-bin at 100000 { + description = "U-Boot binary on SPI Flash"; + data = /incbin/("BINFILE1"); + compression = "none"; + type = "firmware"; + arch = "sandbox"; + load = <0>; + hash-1 { + algo = "sha1"; + }; + }; + u-boot-env at 150000 { + description = "U-Boot environment on SPI Flash"; + data = /incbin/("BINFILE2"); + compression = "none"; + type = "firmware"; + arch = "sandbox"; + load = <0>; + hash-1 { + algo = "sha1"; + }; + }; + }; +};
tools/mkeficapsule.c +2 -1
@@ -101,7 +101,8 @@ static int create_fwbin(char *path, char *bin, efi_guid_t *guid, } header.capsule_guid = efi_guid_fm_capsule; header.header_size =sizeof (header); - header.flags =CAPSULE_FLAGS_PERSIST_ACROSS_RESET ;/* TODO */ +/* TODO: The current implementation ignores flags */ + header.flags =CAPSULE_FLAGS_PERSIST_ACROSS_RESET ; header.capsule_image_size =sizeof (header) +sizeof (capsule) +sizeof (u64) +sizeof (image)
Signature · 1 line
2.28.0
PATCH v9 10/11 test/py: efi_capsule: test for raw image capsule
In reply to AKASHI TakahiroThe test can run on sandbox build and it attempts to execute a firmware update via a capsule-on-disk, using a raw image capsule, CONFIG_EFI_CAPSULE_RAW.
To run this test successfully, you need configure U-Boot specifically; See test_capsule_firmware.py for requirements, and hence it won't run on Travis CI, at least, for now.
--- test/py/tests/test_efi_capsule/conftest.py | 3 + .../test_efi_capsule/test_capsule_firmware.py | 63 +++++++++++++++++++ 2 files changed, 66 insertions(+)
test/py/tests/test_efi_capsule/conftest.py +3 -0
@@ -53,6 +53,9 @@ def efi_capsule_data(request, u_boot_config): check_call('cd %s; %s/tools/mkeficapsule --fit uboot_bin_env.itb --version 1 --index 1 Test01' % (data_dir, u_boot_config.build_dir), shell=True) + check_call('cd %s; %s/tools/mkeficapsule --raw u-boot.bin.new --version 1 --index 1 Test02' % + (data_dir, u_boot_config.build_dir), + shell=True) # Create a disk image with EFI system partition check_call('virt-make-fs --partition=gpt --size=+1M --type=vfat %s %s' %
test/py/tests/test_efi_capsule/test_capsule_firmware.py +63 -0
72 lines not on this page · raw message
Signature · 1 line
2.28.0
PATCH v9 11/11 sandbox: enable capsule update for testing
In reply to AKASHI TakahiroAdd more configuration options to allow for efi capsule update on sandbox.
--- configs/sandbox64_defconfig | 6 ++++++ configs/sandbox_defconfig | 6 ++++++ 2 files changed, 12 insertions(+)
configs/sandbox64_defconfig +6 -0
@@ -231,3 +231,9 @@ CONFIG_TEST_FDTDEC=y CONFIG_UNIT_TEST=y CONFIG_UT_TIME=y CONFIG_UT_DM=y +# +CONFIG_DFU_SF=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
configs/sandbox_defconfig +6 -0
@@ -274,3 +274,9 @@ CONFIG_TEST_FDTDEC=y CONFIG_UNIT_TEST=y CONFIG_UT_TIME=y CONFIG_UT_DM=y +# +CONFIG_DFU_SF=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
Signature · 1 line
2.28.0
PATCH v9 11/11 sandbox: enable capsule update for testing
Quoted 4 lines · AKASHI Takahiro
Add more configuration options to allow for efi capsule update on sandbox.
Signed-off-by AKASHI Takahiro <[email protected]>
This patch leads to a build failure:
https://gitlab.denx.de/u-boot/custodians/u-boot-efi/-/jobs/181984
Building current source for 1 boards (1 thread, 40 jobs per thread)
sandbox: + sandbox+common/update.c:178:12: error: 'update_flash' defined but not used [-Werror=unused-function]
+ static int update_flash(ulong addr_source, ulong addr_first, ulong size)
+ ^~~~~~~~~~~~
+cc1: all warnings being treated as errors
+make[2]: *** [common/update.o] Error 1
+make[1]: *** [common] Error 2
+make: *** [sub-make] Error 2
I suggest you mark function update_fetch as __maybe_unused.
Best regards
Heinrich
Quoted 34 lines
--- configs/sandbox64_defconfig | 6 ++++++ configs/sandbox_defconfig | 6 ++++++ 2 files changed, 12 insertions(+)configs/sandbox64_defconfig +6
-0@@ -231,3 +231,9 @@ CONFIG_TEST_FDTDEC=y CONFIG_UNIT_TEST=y CONFIG_UT_TIME=y CONFIG_UT_DM=y +# +CONFIG_DFU_SF=y +CONFIG_EFI_RUNTIME_UPDATE_CAPSULE=y +CONFIG_EFI_CAPSULE_ON_DISK=y +CONFIG_EFI_CAPSULE_FIRMWARE_FIT=y +CONFIG_EFI_CAPSULE_FIRMWARE_RAW=yconfigs/sandbox_defconfig +6
-0@@ -274,3 +274,9 @@ CONFIG_TEST_FDTDEC=y CONFIG_UNIT_TEST=y CONFIG_UT_TIME=y CONFIG_UT_DM=y +# +CONFIG_DFU_SF=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
PATCH v9 11/11 sandbox: enable capsule update for testing
Heinrich,
Quoted 21 lines · Heinrich Schuchardt
Quoted 4 lines · AKASHI Takahiro
Add more configuration options to allow for efi capsule update on sandbox.
Signed-off-by AKASHI Takahiro <[email protected]>This patch leads to a build failure:
https://gitlab.denx.de/u-boot/custodians/u-boot-efi/-/jobs/181984
Building current source for 1 boards (1 thread, 40 jobs per thread)
sandbox: + sandbox+common/update.c:178:12: error: 'update_flash' defined but not used [-Werror=unused-function]
+ static intupdate_flash(ulong addr_source, ulong addr_first, ulong size)(quoted diff) +5
-0+ ^~~~~~~~~~~~ +cc1: all warnings being treated as errors +make[2]: *** [common/update.o] Error 1 +make[1]: *** [common] Error 2 +make: *** [sub-make] Error 2
Quoted 1 line
I suggest you mark function
update_fetchas__maybe_unused.
I suppose that you have not applied my patch:
https://lists.denx.de/pipermail/u-boot/2020-November/433064.html
-Takahiro Akashi
Quoted 40 lines
Best regards
Heinrich
Quoted 34 lines
--- configs/sandbox64_defconfig | 6 ++++++ configs/sandbox_defconfig | 6 ++++++ 2 files changed, 12 insertions(+)configs/sandbox64_defconfig +6
-0@@ -231,3 +231,9 @@ CONFIG_TEST_FDTDEC=y CONFIG_UNIT_TEST=y CONFIG_UT_TIME=y CONFIG_UT_DM=y +# +CONFIG_DFU_SF=y +CONFIG_EFI_RUNTIME_UPDATE_CAPSULE=y +CONFIG_EFI_CAPSULE_ON_DISK=y +CONFIG_EFI_CAPSULE_FIRMWARE_FIT=y +CONFIG_EFI_CAPSULE_FIRMWARE_RAW=yconfigs/sandbox_defconfig +6
-0@@ -274,3 +274,9 @@ CONFIG_TEST_FDTDEC=y CONFIG_UNIT_TEST=y CONFIG_UT_TIME=y CONFIG_UT_DM=y +# +CONFIG_DFU_SF=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
v9 cover efi_loader: add capsule update support
In reply to AKASHI TakahiroQuoted 71 lines · AKASHI Takahiro
Summary
=======
'UpdateCapsule' is one of runtime services defined in UEFI specification and its aim is to allow a caller (OS) to pass information to the firmware, i.e. U-Boot. This is mostly used to update firmware binary on devices by instructions from OS.While 'UpdateCapsule' is a runtime services function, it is, at least initially, supported only before exiting boot services alike other runtime functions, [Get/]SetVariable. This is because modifying storage which may be shared with OS must be carefully designed and there is no general assumption that we can do it.
Therefore, we practically support only "capsule on disk"; any capsule can be handed over to UEFI subsystem as a file on a specific file system.
In this patch series, all the related definitions and structures are given as UEFI specification describes, and basic framework for capsule support is provided. Currently supported is
* firmware update (Firmware Management Protocol or simply FMP)Most of functionality of firmware update is provided by FMP driver and it can be, by nature, system/platform-specific. So you can and should implement your own FMP driver(s) based on your system requirements. Under the current implementation, we provide two basic but generic drivers with two formats:
* FIT image format (as used in TFTP update and dfu)
* raw image formatIt's totally up to users which one, or both, should be used on users' system depending on user requirements.
Quick usage
===========
1. You can create a capsule file with the following host command:$ mkeficapsule [--fit <fit image> | --raw <raw image>] <output file>2. Put the file under:
/EFI/UpdateCapsule of UEFI system partition
3. Specify firmware storage to be updated in "
dfu_alt_info" variable (Please follow README.dfu for details.)==> env set dfu_alt_info '...'4. After setting up UEFI's OsIndications variable, reboot U-Boot:
OsIndications <=
EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTEDPatch structure
===============
Patch#1-#6: main part of implementation
Patch#7-#8: utilities
Patch#9-#10: pytests
Patch#11: for sandbox test[1] https://git.linaro.org/people/takahiro.akashi/u-boot.git efi/capsule
Prerequisite patches
====================
NoneTest
====
* passed all the pytests which are included in this patch series on sandbox build locally.
* In Travis CI, all tests skipped (or 'S', but it's not a failure, 'F') because "virt-make-fs" cannot be executed.
Quoted 13 lines
Issues
======
* Timing of executing capsules-on-disk
Currently, processing a capsule is triggered only as part of UEFI subsystem initialization. This means that, for example, firmware update, may not take place at system booting time and will potentially be delayed until a first call of any UEFI functions.
=> See patch#5 for my proposal
* A bunch of warnings like
WARNING: Use 'if (IS_ENABLED(CONFIG...))' instead of '#if or #ifdef' where possible
I don't think that fixing those improves anything.
* Add a document inuefi.rst
What is your status for the test running on Gitlab CI?
I still see test/py/tests/test_efi_capsule/test_capsule_firmware.py sss [ 0%] in
https://gitlab.denx.de/u-boot/custodians/u-boot-efi/-/jobs/182120
Best regards
Heinrich
Quoted 165 lines
TODO's
======
(Won't be addressed in this series.)
* capsule authentication
* capsule dependency (dependency expression instruction set, or depex)
* loading drivers in a capsule
* handling RESET flag in a capsule and QeuryCapsuleCaps
* full semantics of ESRT (EFI System Resource Table)
* enabling capsule API at runtime
* json capsule
* recovery from update failureChanges
=======
v9 (November 17, 2020)
* rebased on v2021.01-rc2
* removed already-merged patches
* aligned with a function prototype change ofefi_create_indexed_name()(Patch#1-2)
# See Travis CI status in v8 belowv8 (November 13, 2020)
* fix a "not used" warning againstupdate_load()in some configuration (Patch#3)
* fix failures (marked as 'F') in *secure boot* test in Travis CI by making "EFI_CAPSULE_ON_DISK_EARLY" 'default n' (Patch#8)
* fix failures (marked as 'E') at pytest setup in Travis CI by changing a python file's name along with removing unused definitions (Patch#16)
* add Patch#18 to enable tests to be run with default sandbox config (Patch#18)v7 (October 29, 2020)
* renameCONFIG_DFU_ALTtoCONFIG_DFU_WRITE_ALT(Patch#1,#3,#13)v6 RESEND (October 29, 2020)
* rebased on v2021.01-rc1v6 (September 7, 2020)
* temporarily drop the prerequisite patch[2]
* add a missing field (dependencies) inefi_api.h(but never used) (Patch#10)
* add a missing field (image_capsule_support) and related definitions inefi_api.h(Patch#10, #15)
* cosmetic changes on constant definitions inefi_api.h(Patch#10)
* strict check forINVALID_PARAMETERatGET_IMAGE_INFOapi (Patch#11,#13)
* fix warnings in pytest (Patch#16,#17)v5 (August 3, 2020)
* removed superfluous type conversion atdfu_write_from_mem_addr()(Patch#2)
* introduced a common helper function,efi_create_indexed_name()(Patch#6,#7,#8)
* use efi_[get|set]_variable_int(), if necessary, withREAD_ONLY(Patch#7,#8)
* returnEFI_UNSUPPORTEDat Patch#7
* changed the word, number, to 'index' (Patch#7,#8)
* removed 'ifdefCONFIG_EFI_CAPSULE_ON_DISK' from a header (Patch#8)
* initialize 'CapsuleLast' inefi_init_obj_list()(Patch#7,#8)
* added 'const' qualifier for filename argument at efi_capsule_[read|delete]_file() (Patch#8)v4 (July 22, 2020)
* rebased to Heinrich's current efi-2020-10
* rework dfu-related code to align with Heinrich's change (Patch#1,#3)
* change a type of 'addr' argument from int to 'void *' per Sughosh's comment (Patch#2-#3,#11-#12)
* rework/simplify pytests (Patch#15-#16)
- utilize virt-make-fs
- drop Test Case 1 (updating U-Boot environment data)
- remove useless definitions (MNT_PNT,EFI_CAPSULE_IMAGE_NAME)
- apply autopep8v3 (July 10, 2020)
* rebased to Heinrich's current efi-2020-10-rc1
* refactor efi_firmware_[fit|raw]_get_image_info() (patch#11,#13)v2 (June 17, 2020)
* rebased to v2020.07-rc4
* add preparatory patches for dfu (Patch#1-#5, #12)
* rework FIT capsule driver to utilizedfu_alt_infoinstead ofCONFIG_xxx(patch#11)
* extendget_image_info()to correspond todfu_alt_info(patch#11)
* add a 'raw binary' capsule support
(patch#13, #17)
* allow multiple capsule formats (with different GUIDs) to be installed (patch#11, #13)
* extend mkeficapsule command to accept additional parameters, like version/index/hardware instance for a capsule header info. (patch#15)
* mkeficapsule can now also generate raw-binary capsule (patch#16)
* add function descriptions
* apply autopep8 to pytests and fix more against pylintv1 (April 27, 2020)
* rebased to v2020.07-rc
* removed already-merged patches (RFC's #1 to #4)
* dropped 'variable update' capsule support (RFC's patch#10)
* dropped 'variable configuration table' support (RFC's patch#11) (Those two should be discussed separately.)
* add preparatory patches (patch#1/#2)
* fix several build errors
* rename someKconfigoptions to be aligned with UEFI specification's terms (patch#3,4,6,7)
* enforce UpdateCapsule API to be disabled after ExitBootServices (patch#3)
* use config table,runtime_services_supported, instead of variable (patch#3)
* makeEFI_CAPSULE_ON_DISKbuildable even if UpdateCapsule API is disabled (patch4)
* support OsIndications, invoking capsule-on-disk only if the variable indicates so (patch#4)
* introducedEFI_CAPSULE_ON_DISK_EARLYto invoke capsule-on-disk in U-Boot initialization (patch#4)
* detect capsule files only if they are on EFI system partition (patch#4)
* use printf, rather thanEFI_PRINT, in error cases (patch#4)
* use 'header_size' field to retrieve capsule data, adding sanity checks against capsule size (patch#6)
* call fmpt driver interfaces withEFI_CALL(patch#6)
* remove 'variable update capsule'-related code form mkeficapsule (patch#9)
* add a test case of OsIndications not being set properly (patch#10)
* adjust test scenario forEFI_CAPSULE_ON_DISK_EARLY(patch#10)
* revise pytest scripts (patch#10)Initial release as RFC (March 17, 2020)
AKASHI Takahiro (11):
efi_loader: define UpdateCapsule api
efi_loader: capsule: addcapsule_on_disksupport
efi_loader: capsule: add memory range capsule definitions
efi_loader: capsule: support firmware update
efi_loader: add firmware management protocol for FIT image
efi_loader: add firmware management protocol for raw image
cmd: add "efidebug capsule" command
tools: add mkeficapsule command for UEFI capsule update test/py:efi_capsule: test for FIT image capsule test/py:efi_capsule: test for raw image capsule
sandbox: enable capsule update for testingcmd/efidebug.c | 235 +++++ common/main.c | 4 + configs/sandbox64_defconfig | 6 + configs/sandbox_defconfig | 6 + include/efi_api.h | 166 ++++ include/efi_loader.h | 27 + lib/efi_loader/Kconfig | 68 ++ lib/efi_loader/Makefile | 2 + lib/efi_loader/efi_capsule.c | 917 ++++++++++++++++++ lib/efi_loader/efi_firmware.c | 403 ++++++++ lib/efi_loader/efi_runtime.c | 104 +- lib/efi_loader/efi_setup.c | 76 +- .../py/tests/test_efi_capsule/capsule_defs.py | 5 + test/py/tests/test_efi_capsule/conftest.py | 74 ++ .../test_efi_capsule/test_capsule_firmware.py | 241 +++++ .../tests/test_efi_capsule/uboot_bin_env.its | 36 + tools/Makefile | 2 + tools/mkeficapsule.c | 239 +++++ 18 files changed, 2557 insertions(+), 54 deletions(-)create mode 100644
lib/efi_loader/efi_capsule.c
create mode 100644lib/efi_loader/efi_firmware.c
create mode 100644test/py/tests/test_efi_capsule/capsule_defs.pycreate mode 100644test/py/tests/test_efi_capsule/conftest.pycreate mode 100644test/py/tests/test_efi_capsule/test_capsule_firmware.pycreate mode 100644 test/py/tests/test_efi_capsule/uboot_bin_env.its create mode 100644tools/mkeficapsule.c
v9 cover efi_loader: add capsule update support
Quoted 86 lines · Heinrich Schuchardt
Quoted 71 lines · AKASHI Takahiro
Summary
=======
'UpdateCapsule' is one of runtime services defined in UEFI specification and its aim is to allow a caller (OS) to pass information to the firmware, i.e. U-Boot. This is mostly used to update firmware binary on devices by instructions from OS.While 'UpdateCapsule' is a runtime services function, it is, at least initially, supported only before exiting boot services alike other runtime functions, [Get/]SetVariable. This is because modifying storage which may be shared with OS must be carefully designed and there is no general assumption that we can do it.
Therefore, we practically support only "capsule on disk"; any capsule can be handed over to UEFI subsystem as a file on a specific file system.
In this patch series, all the related definitions and structures are given as UEFI specification describes, and basic framework for capsule support is provided. Currently supported is
* firmware update (Firmware Management Protocol or simply FMP)Most of functionality of firmware update is provided by FMP driver and it can be, by nature, system/platform-specific. So you can and should implement your own FMP driver(s) based on your system requirements. Under the current implementation, we provide two basic but generic drivers with two formats:
* FIT image format (as used in TFTP update and dfu)
* raw image formatIt's totally up to users which one, or both, should be used on users' system depending on user requirements.
Quick usage
===========
1. You can create a capsule file with the following host command:$ mkeficapsule [--fit <fit image> | --raw <raw image>] <output file>2. Put the file under:
/EFI/UpdateCapsule of UEFI system partition
3. Specify firmware storage to be updated in "
dfu_alt_info" variable (Please follow README.dfu for details.)==> env set dfu_alt_info '...'4. After setting up UEFI's OsIndications variable, reboot U-Boot:
OsIndications <=
EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTEDPatch structure
===============
Patch#1-#6: main part of implementation
Patch#7-#8: utilities
Patch#9-#10: pytests
Patch#11: for sandbox test[1] https://git.linaro.org/people/takahiro.akashi/u-boot.git efi/capsule
Prerequisite patches
====================
NoneTest
====
* passed all the pytests which are included in this patch series on sandbox build locally.
* In Travis CI, all tests skipped (or 'S', but it's not a failure, 'F') because "virt-make-fs" cannot be executed.Quoted 13 lines
Issues
======
* Timing of executing capsules-on-disk
Currently, processing a capsule is triggered only as part of UEFI subsystem initialization. This means that, for example, firmware update, may not take place at system booting time and will potentially be delayed until a first call of any UEFI functions.
=> See patch#5 for my proposal
* A bunch of warnings like
WARNING: Use 'if (IS_ENABLED(CONFIG...))' instead of '#if or #ifdef' where possible
I don't think that fixing those improves anything.
* Add a document inuefi.rst
Quoted 6 lines
What is your status for the test running on Gitlab CI?
I still see
test/py/tests/test_efi_capsule/test_capsule_firmware.pysss [ 0%] in
https://gitlab.denx.de/u-boot/custodians/u-boot-efi/-/jobs/182120
That means that Azure, Travis and GitLab are just not going to run any of the capsule tests. If they can be run manually, that's apparently as good as we're going to get to start with.
That's not the ideal situation, certainly. But you haven't answered his question about if you agree with, or not, what I say about some try/catch method of using sudo or make-virt-fs, whatever the running instance supports. That's likely the blocker to further progress on CI and these tests running. Thanks.
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20201124/5a84b073/attachment.sig>
v9 cover efi_loader: add capsule update support
Quoted 98 lines · Tom Rini
Quoted 86 lines · Heinrich Schuchardt
Quoted 71 lines · AKASHI Takahiro
Summary
=======
'UpdateCapsule' is one of runtime services defined in UEFI specification and its aim is to allow a caller (OS) to pass information to the firmware, i.e. U-Boot. This is mostly used to update firmware binary on devices by instructions from OS.While 'UpdateCapsule' is a runtime services function, it is, at least initially, supported only before exiting boot services alike other runtime functions, [Get/]SetVariable. This is because modifying storage which may be shared with OS must be carefully designed and there is no general assumption that we can do it.
Therefore, we practically support only "capsule on disk"; any capsule can be handed over to UEFI subsystem as a file on a specific file system.
In this patch series, all the related definitions and structures are given as UEFI specification describes, and basic framework for capsule support is provided. Currently supported is
* firmware update (Firmware Management Protocol or simply FMP)Most of functionality of firmware update is provided by FMP driver and it can be, by nature, system/platform-specific. So you can and should implement your own FMP driver(s) based on your system requirements. Under the current implementation, we provide two basic but generic drivers with two formats:
* FIT image format (as used in TFTP update and dfu)
* raw image formatIt's totally up to users which one, or both, should be used on users' system depending on user requirements.
Quick usage
===========
1. You can create a capsule file with the following host command:$ mkeficapsule [--fit <fit image> | --raw <raw image>] <output file>2. Put the file under:
/EFI/UpdateCapsule of UEFI system partition
3. Specify firmware storage to be updated in "
dfu_alt_info" variable (Please follow README.dfu for details.)==> env set
dfu_alt_info'...'4. After setting up UEFI's OsIndications variable, reboot U-Boot:
OsIndications <=
EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTEDPatch structure
===============
Patch#1-#6: main part of implementation
Patch#7-#8: utilities
Patch#9-#10: pytests
Patch#11: for sandbox test[1] https://git.linaro.org/people/takahiro.akashi/u-boot.git efi/capsule
Prerequisite patches
====================
NoneTest
====
* passed all the pytests which are included in this patch series on sandbox build locally.
* In Travis CI, all tests skipped (or 'S', but it's not a failure, 'F') because "virt-make-fs" cannot be executed.Quoted 13 lines
Issues
======
* Timing of executing capsules-on-disk
Currently, processing a capsule is triggered only as part of UEFI subsystem initialization. This means that, for example, firmware update, may not take place at system booting time and will potentially be delayed until a first call of any UEFI functions.
=> See patch#5 for my proposal
* A bunch of warnings like
WARNING: Use 'if (IS_ENABLED(CONFIG...))' instead of '#if or #ifdef' where possible
I don't think that fixing those improves anything.
* Add a document inuefi.rstQuoted 6 lines
What is your status for the test running on Gitlab CI?
I still see
test/py/tests/test_efi_capsule/test_capsule_firmware.pysss [ 0%] in
https://gitlab.denx.de/u-boot/custodians/u-boot-efi/-/jobs/182120That means that Azure, Travis and GitLab are just not going to run any of the capsule tests. If they can be run manually, that's apparently as good as we're going to get to start with.
Quoted 6 lines
That's not the ideal situation, certainly. But you haven't answered his question about if you agree with, or not, what I say about some try/catch method of using sudo or make-virt-fs, whatever the running instance supports. That's likely the blocker to further progress on CI and these tests running. Thanks.
What the series does is adding another wrapper around FIT images.
The series has build errors. So nothing to be merged now.
We have been talking about CI tests for the series since September at least and I have not seen any progress.
This reminds me of the FAT tests that are skipped on CI.
Best regards
Heinrich
v9 cover efi_loader: add capsule update support
Quoted 106 lines · Heinrich Schuchardt
Quoted 98 lines · Tom Rini
Quoted 86 lines · Heinrich Schuchardt
Quoted 71 lines · AKASHI Takahiro
Summary
=======
'UpdateCapsule' is one of runtime services defined in UEFI specification and its aim is to allow a caller (OS) to pass information to the firmware, i.e. U-Boot. This is mostly used to update firmware binary on devices by instructions from OS.While 'UpdateCapsule' is a runtime services function, it is, at least initially, supported only before exiting boot services alike other runtime functions, [Get/]SetVariable. This is because modifying storage which may be shared with OS must be carefully designed and there is no general assumption that we can do it.
Therefore, we practically support only "capsule on disk"; any capsule can be handed over to UEFI subsystem as a file on a specific file system.
In this patch series, all the related definitions and structures are given as UEFI specification describes, and basic framework for capsule support is provided. Currently supported is
* firmware update (Firmware Management Protocol or simply FMP)Most of functionality of firmware update is provided by FMP driver and it can be, by nature, system/platform-specific. So you can and should implement your own FMP driver(s) based on your system requirements. Under the current implementation, we provide two basic but generic drivers with two formats:
* FIT image format (as used in TFTP update and dfu)
* raw image formatIt's totally up to users which one, or both, should be used on users' system depending on user requirements.
Quick usage
===========
1. You can create a capsule file with the following host command:$ mkeficapsule [--fit <fit image> | --raw <raw image>] <output file>2. Put the file under:
/EFI/UpdateCapsule of UEFI system partition
3. Specify firmware storage to be updated in "
dfu_alt_info" variable (Please follow README.dfu for details.)==> env set
dfu_alt_info'...'4. After setting up UEFI's OsIndications variable, reboot U-Boot:
OsIndications <=
EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTEDPatch structure
===============
Patch#1-#6: main part of implementation
Patch#7-#8: utilities
Patch#9-#10: pytests
Patch#11: for sandbox test[1] https://git.linaro.org/people/takahiro.akashi/u-boot.git efi/capsule
Prerequisite patches
====================
NoneTest
====
* passed all the pytests which are included in this patch series on sandbox build locally.
* In Travis CI, all tests skipped (or 'S', but it's not a failure, 'F') because "virt-make-fs" cannot be executed.Quoted 13 lines
Issues
======
* Timing of executing capsules-on-disk
Currently, processing a capsule is triggered only as part of UEFI subsystem initialization. This means that, for example, firmware update, may not take place at system booting time and will potentially be delayed until a first call of any UEFI functions.
=> See patch#5 for my proposal
* A bunch of warnings like
WARNING: Use 'if (IS_ENABLED(CONFIG...))' instead of '#if or #ifdef' where possible
I don't think that fixing those improves anything.
* Add a document inuefi.rstQuoted 6 lines
What is your status for the test running on Gitlab CI?
I still see
test/py/tests/test_efi_capsule/test_capsule_firmware.pysss [ 0%] in
https://gitlab.denx.de/u-boot/custodians/u-boot-efi/-/jobs/182120That means that Azure, Travis and GitLab are just not going to run any of the capsule tests. If they can be run manually, that's apparently as good as we're going to get to start with.
Quoted 6 lines
That's not the ideal situation, certainly. But you haven't answered his question about if you agree with, or not, what I say about some try/catch method of using sudo or make-virt-fs, whatever the running instance supports. That's likely the blocker to further progress on CI and these tests running. Thanks.
Quoted 3 lines
What the series does is adding another wrapper around FIT images.
The series has build errors. So nothing to be merged now.
Again? I thought v8 at least passed all CI.
Quoted 5 lines
We have been talking about CI tests for the series since September at least and I have not seen any progress.
This reminds me of the FAT tests that are skipped on CI.
Well, the outstanding question about making the tests run in CI has been blocked on your feedback. I believe that in order for any of these (or the FAT ones) to run in CI, sudo has to work, and possibly something else too. I say we need fall-back to make-virt-fs rather than it being an only option.
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20201124/36e3e8ea/attachment.sig>