Skip to contentSkip to conversation

efi_loader: add capsule update support

PATCH Superseded AKASHI Takahiro 5 participants 35 messages Sep 7, 2020 – Sep 18, 2020

v6 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v6 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-#4,#12: preparatory patches
Patch#5-#11,#13: main part of implementation
Patch#14-#15: utilities
Patch#16-#17: pytests

[1] https://git.linaro.org/people/takahiro.akashi/u-boot.git efi/capsule

Prerequisite patches
====================
In this version, the DFU change by Heinrich[2] is, at least temporarily, not a prerequisite due to the discussions[3].

[2] https://lists.denx.de/pipermail/u-boot/2020-July/420950.html
[3] https://lists.denx.de/pipermail/u-boot/2020-August/424716.html

Test
====
* passed all the pytests which are included in this patch series on sandbox build locally.

Please note that the capsule pytest itself won't be run in the CI partly because some specific configuration for sandbox build is required and partly because there is a problem with virt-make-fs. See test_efi_capsule_firmware.py.

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
=======
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 (17):
dfu: rename dfu_tftp_write() to dfu_write_by_name()
dfu: modify an argument type for an address
common: update: add a generic interface for FIT image
dfu: export dfu_list
efi_loader: add option to initialise EFI subsystem early
efi_loader: add efi_create_indexed_name()
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
dfu: add dfu_write_by_alt()
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

 cmd/efidebug.c                                | 235 +++++
 common/Kconfig                                |  15 +
 common/Makefile                               |   3 +-
 common/board_r.c                              |   6 +
 common/main.c                                 |   4 +
 common/update.c                               |  77 +-
 drivers/dfu/Kconfig                           |   6 +
 drivers/dfu/Makefile                          |   2 +-
 drivers/dfu/dfu.c                             |   2 +-
 drivers/dfu/dfu_alt.c                         | 125 +++
 drivers/dfu/dfu_tftp.c                        |  65 --
 include/dfu.h                                 |  57 +-
 include/efi_api.h                             | 166 ++++
 include/efi_loader.h                          |  30 +
 include/image.h                               |  12 +
 lib/efi_loader/Kconfig                        |  72 ++
 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                    | 106 +-
 test/py/tests/test_efi_capsule/conftest.py    |  72 ++
 test/py/tests/test_efi_capsule/defs.py        |  12 +
 .../test_efi_capsule/test_capsule_firmware.py | 241 +++++
 .../tests/test_efi_capsule/uboot_bin_env.its  |  36 +
 tools/Makefile                                |   2 +
 tools/mkeficapsule.c                          | 239 +++++
 27 files changed, 2871 insertions(+), 140 deletions(-)
 create mode 100644 drivers/dfu/dfu_alt.c
 delete mode 100644 drivers/dfu/dfu_tftp.c
 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/conftest.py
 create mode 100644 test/py/tests/test_efi_capsule/defs.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
#1 lore raw

PATCH v6 1/17 dfu: rename dfu_tftp_write() to dfu_write_by_name()

This function is essentially independent from tftp, and will also be utilised in implementing UEFI capsule update in a later commit. So just give it a more generic name.
In addition, a new configuration option, CONFIG_DFU_ALT, was introduced so that the file will be compiled with different options, particularly one added in a later commit.

---
 common/update.c                       |  5 +++--
 drivers/dfu/Kconfig                   |  5 +++++
 drivers/dfu/Makefile                  |  2 +-
 drivers/dfu/{dfu_tftp.c => dfu_alt.c} | 17 ++++++++++++--
 include/dfu.h                         | 32 +++++++++++++--------------
 5 files changed, 40 insertions(+), 21 deletions(-)
 rename drivers/dfu/{dfu_tftp.c => dfu_alt.c} (67%)
common/update.c +3 -2
index 36b6b7523d50..39946776d74f 100644
@@ -324,8 +324,9 @@ got_update_file:
 			}
 		} else if (fit_image_check_type(fit, noffset,
 						IH_TYPE_FIRMWARE)) {
-			ret = dfu_tftp_write(fit_image_name, update_addr,
-					     update_size, interface, devstring);
+			ret = dfu_write_by_name(fit_image_name, update_addr,
+						update_size, interface,
+						devstring);
 			if (ret)
 				return ret;
 		}
drivers/dfu/Kconfig +5 -0
index 0eec00ba734d..78f901ff348a 100644
@@ -14,8 +14,13 @@ config DFU_OVER_TFTP
 	depends on NET
 
 if DFU
+config DFU_ALT
+	bool
+	default n
+
 config DFU_TFTP
 	bool "DFU via TFTP"
+	select DFU_ALT
 	select DFU_OVER_TFTP
 	help
 	  This option allows performing update of DFU-managed medium with data
drivers/dfu/Makefile +1 -1
index 0d7925c083ef..cc7de1d3ed9b 100644
@@ -9,5 +9,5 @@ obj-$(CONFIG_$(SPL_)DFU_MTD) += dfu_mtd.o
 obj-$(CONFIG_$(SPL_)DFU_NAND) += dfu_nand.o
 obj-$(CONFIG_$(SPL_)DFU_RAM) += dfu_ram.o
 obj-$(CONFIG_$(SPL_)DFU_SF) += dfu_sf.o
-obj-$(CONFIG_$(SPL_)DFU_TFTP) += dfu_tftp.o
+obj-$(CONFIG_$(SPL_)DFU_ALT) += dfu_alt.o
 obj-$(CONFIG_$(SPL_)DFU_VIRT) += dfu_virt.o
drivers/dfu/dfu_alt.c renamed from drivers/dfu/dfu_tftp.c +15 -2
similarity index 67%
rename from drivers/dfu/dfu_tftp.c
rename to drivers/dfu/dfu_alt.c
index ffae4bb54f80..5b1b13d7170d 100644
@@ -10,8 +10,21 @@
 #include <errno.h>
 #include <dfu.h>
 
-int dfu_tftp_write(char *dfu_entity_name, unsigned int addr, unsigned int len,
-		   char *interface, char *devstring)
+/**
+ * dfu_write_by_name() - write data to DFU medium
+ * @dfu_entity_name:    Name of DFU entity to write
+ * @addr:               Address of data buffer to write
+ * @len:                Number of bytes
+ * @interface:          Destination DFU medium (e.g. "mmc")
+ * @devstring:          Instance number of destination DFU medium (e.g. "1")
+ *
+ * This function is storing data received on DFU supported medium which
+ * is specified by @dfu_entity_name.
+ *
+ * Return:              0 - on success, error code - otherwise
+ */
+int dfu_write_by_name(char *dfu_entity_name, unsigned int addr,
+		      unsigned int len, char *interface, char *devstring)
 {
 	char *s, *sb;
 	int alt_setting_num, ret;
include/dfu.h +16 -16
index 84abdc79acd1..cecfbd76597b 100644
@@ -494,27 +494,27 @@ static inline int dfu_fill_entity_virt(struct dfu_entity *dfu, char *devstr,
 #endif
 
 /**
- * dfu_tftp_write() - write TFTP data to DFU medium
+ * dfu_write_by_name() - write data to DFU medium
+ * @dfu_entity_name:	Name of DFU entity to write
+ * @addr:		Address of data buffer to write
+ * @len:		Number of bytes
+ * @interface:		Destination DFU medium (e.g. "mmc")
+ * @devstring:		Instance number of destination DFU medium (e.g. "1")
  *
- * This function is storing data received via TFTP on DFU supported medium.
+ * This function is storing data received on DFU supported medium which
+ * is specified by @dfu_entity_name.
  *
- * @dfu_entity_name:	name of DFU entity to write
- * @addr:		address of data buffer to write
- * @len:		number of bytes
- * @interface:		destination DFU medium (e.g. "mmc")
- * @devstring:		instance number of destination DFU medium (e.g. "1")
- *
- * Return:		0 on success, otherwise error code
+ * Return:		0 - on success, error code - otherwise
  */
-#if CONFIG_IS_ENABLED(DFU_TFTP)
-int dfu_tftp_write(char *dfu_entity_name, unsigned int addr, unsigned int len,
-		   char *interface, char *devstring);
+#if CONFIG_IS_ENABLED(DFU_ALT)
+int dfu_write_by_name(char *dfu_entity_name, unsigned int addr,
+		      unsigned int len, char *interface, char *devstring);
 #else
-static inline int dfu_tftp_write(char *dfu_entity_name, unsigned int addr,
-				 unsigned int len, char *interface,
-				 char *devstring)
+static inline int dfu_write_by_name(char *dfu_entity_name, unsigned int addr,
+				    unsigned int len, char *interface,
+				    char *devstring)
 {
-	puts("TFTP write support for DFU not available!\n");
+	puts("write support for DFU not available!\n");
 	return -ENOSYS;
 }
 #endif
Signature · 1 line
2.28.0
#2 lore raw

PATCH v6 1/17 dfu: rename dfu_tftp_write() to dfu_write_by_name()

Quoted 38 lines · AKASHI Takahiro

This function is essentially independent from tftp, and will also be utilised in implementing UEFI capsule update in a later commit. So just give it a more generic name.
In addition, a new configuration option, CONFIG_DFU_ALT, was introduced so that the file will be compiled with different options, particularly one added in a later commit.

---
 common/update.c                       |  5 +++--
 drivers/dfu/Kconfig                   |  5 +++++
 drivers/dfu/Makefile                  |  2 +-
 drivers/dfu/{dfu_tftp.c => dfu_alt.c} | 17 ++++++++++++--
 include/dfu.h                         | 32 +++++++++++++--------------
 5 files changed, 40 insertions(+), 21 deletions(-)
 rename drivers/dfu/{dfu_tftp.c => dfu_alt.c} (67%)
common/update.c +3 -2
index 36b6b7523d50..39946776d74f 100644
@@ -324,8 +324,9 @@ got_update_file:
 			}
 		} else if (fit_image_check_type(fit, noffset,
 						IH_TYPE_FIRMWARE)) {
-			ret = dfu_tftp_write(fit_image_name, update_addr,
-					     update_size, interface, devstring);
+			ret = dfu_write_by_name(fit_image_name, update_addr,
+						update_size, interface,
+						devstring);
 			if (ret)
 				return ret;
 		}
drivers/dfu/Kconfig +0 -0
index 0eec00ba734d..78f901ff348a 100644

drivers/dfu/Kconfig config DFU_OVER_TFTP · line 18

Quoted 5 lines
drivers/dfu/Kconfig +2 -0
@@ -14,8 +14,13 @@ config DFU_OVER_TFTP
 	depends on NET
 
 if DFU
+config DFU_ALT
+	bool

You cannot define CONFIG_DFU_ALT as bool. This symbol already exists as string in include/configs/odroid.h, include/configs/s5p_goni.h, et.al. It is used to initialize environment variable dfu_alt_info. Your patch leads to an error on Travis:

arm: + odroid

+In file included from <command-line>:

+include/linux/kconfig.h:21:49: error: pasting "__ARG_PLACEHOLDER_" and ""uImage fat 0 1;"" does not give a valid preprocessing token

+ 21 | #define _config_enabled(value)
__config_enabled(__ARG_PLACEHOLDER_##value)

Best regards

Heinrich

Quoted 99 lines
drivers/dfu/Kconfig +3 -0
+	default n
+
 config DFU_TFTP
 	bool "DFU via TFTP"
+	select DFU_ALT
 	select DFU_OVER_TFTP
 	help
 	  This option allows performing update of DFU-managed medium with data
drivers/dfu/Makefile +1 -1
index 0d7925c083ef..cc7de1d3ed9b 100644
@@ -9,5 +9,5 @@ obj-$(CONFIG_$(SPL_)DFU_MTD) += dfu_mtd.o
 obj-$(CONFIG_$(SPL_)DFU_NAND) += dfu_nand.o
 obj-$(CONFIG_$(SPL_)DFU_RAM) += dfu_ram.o
 obj-$(CONFIG_$(SPL_)DFU_SF) += dfu_sf.o
-obj-$(CONFIG_$(SPL_)DFU_TFTP) += dfu_tftp.o
+obj-$(CONFIG_$(SPL_)DFU_ALT) += dfu_alt.o
 obj-$(CONFIG_$(SPL_)DFU_VIRT) += dfu_virt.o
drivers/dfu/dfu_alt.c renamed from drivers/dfu/dfu_tftp.c +15 -2
similarity index 67%
rename from drivers/dfu/dfu_tftp.c
rename to drivers/dfu/dfu_alt.c
index ffae4bb54f80..5b1b13d7170d 100644
@@ -10,8 +10,21 @@
 #include <errno.h>
 #include <dfu.h>
 
-int dfu_tftp_write(char *dfu_entity_name, unsigned int addr, unsigned int len,
-		   char *interface, char *devstring)
+/**
+ * dfu_write_by_name() - write data to DFU medium
+ * @dfu_entity_name:    Name of DFU entity to write
+ * @addr:               Address of data buffer to write
+ * @len:                Number of bytes
+ * @interface:          Destination DFU medium (e.g. "mmc")
+ * @devstring:          Instance number of destination DFU medium (e.g. "1")
+ *
+ * This function is storing data received on DFU supported medium which
+ * is specified by @dfu_entity_name.
+ *
+ * Return:              0 - on success, error code - otherwise
+ */
+int dfu_write_by_name(char *dfu_entity_name, unsigned int addr,
+		      unsigned int len, char *interface, char *devstring)
 {
 	char *s, *sb;
 	int alt_setting_num, ret;
include/dfu.h +16 -16
index 84abdc79acd1..cecfbd76597b 100644
@@ -494,27 +494,27 @@ static inline int dfu_fill_entity_virt(struct dfu_entity *dfu, char *devstr,
 #endif
 
 /**
- * dfu_tftp_write() - write TFTP data to DFU medium
+ * dfu_write_by_name() - write data to DFU medium
+ * @dfu_entity_name:	Name of DFU entity to write
+ * @addr:		Address of data buffer to write
+ * @len:		Number of bytes
+ * @interface:		Destination DFU medium (e.g. "mmc")
+ * @devstring:		Instance number of destination DFU medium (e.g. "1")
  *
- * This function is storing data received via TFTP on DFU supported medium.
+ * This function is storing data received on DFU supported medium which
+ * is specified by @dfu_entity_name.
  *
- * @dfu_entity_name:	name of DFU entity to write
- * @addr:		address of data buffer to write
- * @len:		number of bytes
- * @interface:		destination DFU medium (e.g. "mmc")
- * @devstring:		instance number of destination DFU medium (e.g. "1")
- *
- * Return:		0 on success, otherwise error code
+ * Return:		0 - on success, error code - otherwise
  */
-#if CONFIG_IS_ENABLED(DFU_TFTP)
-int dfu_tftp_write(char *dfu_entity_name, unsigned int addr, unsigned int len,
-		   char *interface, char *devstring);
+#if CONFIG_IS_ENABLED(DFU_ALT)
+int dfu_write_by_name(char *dfu_entity_name, unsigned int addr,
+		      unsigned int len, char *interface, char *devstring);
 #else
-static inline int dfu_tftp_write(char *dfu_entity_name, unsigned int addr,
-				 unsigned int len, char *interface,
-				 char *devstring)
+static inline int dfu_write_by_name(char *dfu_entity_name, unsigned int addr,
+				    unsigned int len, char *interface,
+				    char *devstring)
 {
-	puts("TFTP write support for DFU not available!\n");
+	puts("write support for DFU not available!\n");
 	return -ENOSYS;
 }
 #endif
#3 lore raw

PATCH v6 1/17 dfu: rename dfu_tftp_write() to dfu_write_by_name()

Quoted 50 lines · Heinrich Schuchardt
Quoted 38 lines · AKASHI Takahiro

This function is essentially independent from tftp, and will also be utilised in implementing UEFI capsule update in a later commit. So just give it a more generic name.
In addition, a new configuration option, CONFIG_DFU_ALT, was introduced so that the file will be compiled with different options, particularly one added in a later commit.

---
 common/update.c                       |  5 +++--
 drivers/dfu/Kconfig                   |  5 +++++
 drivers/dfu/Makefile                  |  2 +-
 drivers/dfu/{dfu_tftp.c => dfu_alt.c} | 17 ++++++++++++--
 include/dfu.h                         | 32 +++++++++++++--------------
 5 files changed, 40 insertions(+), 21 deletions(-)
 rename drivers/dfu/{dfu_tftp.c => dfu_alt.c} (67%)
common/update.c +3 -2
index 36b6b7523d50..39946776d74f 100644
@@ -324,8 +324,9 @@ got_update_file:
 			}
 		} else if (fit_image_check_type(fit, noffset,
 						IH_TYPE_FIRMWARE)) {
-			ret = dfu_tftp_write(fit_image_name, update_addr,
-					     update_size, interface, devstring);
+			ret = dfu_write_by_name(fit_image_name, update_addr,
+						update_size, interface,
+						devstring);
 			if (ret)
 				return ret;
 		}
drivers/dfu/Kconfig +0 -0
index 0eec00ba734d..78f901ff348a 100644

drivers/dfu/Kconfig config DFU_OVER_TFTP · line 18

Quoted 5 lines
drivers/dfu/Kconfig +2 -0
@@ -14,8 +14,13 @@ config DFU_OVER_TFTP
 	depends on NET
 
 if DFU
+config DFU_ALT
+	bool

You cannot define CONFIG_DFU_ALT as bool. This symbol already exists as string in include/configs/odroid.h, include/configs/s5p_goni.h, et.al. It is used to initialize environment variable dfu_alt_info. Your patch leads to an error on Travis:

Quoted 1 line

arm: + odroid

Okay, will fix it.
DFU_WRITE_ALT? Or, as Heinrich suggested, move them to dfu.c if Lukasz agrees.

# I haven't seen any comments from him yet though.

-Takahiro Akashi

Quoted 112 lines
(quoted diff) +2 -0
+In file included from <command-line>:
 
+include/linux/kconfig.h:21:49: error: pasting "__ARG_PLACEHOLDER_" and

""uImage fat 0 1;"" does not give a valid preprocessing token

+ 21 | #define _config_enabled(value)
__config_enabled(__ARG_PLACEHOLDER_##value)

Best regards

Heinrich

Quoted 99 lines
drivers/dfu/Kconfig +3 -0
+	default n
+
 config DFU_TFTP
 	bool "DFU via TFTP"
+	select DFU_ALT
 	select DFU_OVER_TFTP
 	help
 	  This option allows performing update of DFU-managed medium with data
drivers/dfu/Makefile +1 -1
index 0d7925c083ef..cc7de1d3ed9b 100644
@@ -9,5 +9,5 @@ obj-$(CONFIG_$(SPL_)DFU_MTD) += dfu_mtd.o
 obj-$(CONFIG_$(SPL_)DFU_NAND) += dfu_nand.o
 obj-$(CONFIG_$(SPL_)DFU_RAM) += dfu_ram.o
 obj-$(CONFIG_$(SPL_)DFU_SF) += dfu_sf.o
-obj-$(CONFIG_$(SPL_)DFU_TFTP) += dfu_tftp.o
+obj-$(CONFIG_$(SPL_)DFU_ALT) += dfu_alt.o
 obj-$(CONFIG_$(SPL_)DFU_VIRT) += dfu_virt.o
drivers/dfu/dfu_alt.c renamed from drivers/dfu/dfu_tftp.c +15 -2
similarity index 67%
rename from drivers/dfu/dfu_tftp.c
rename to drivers/dfu/dfu_alt.c
index ffae4bb54f80..5b1b13d7170d 100644
@@ -10,8 +10,21 @@
 #include <errno.h>
 #include <dfu.h>
 
-int dfu_tftp_write(char *dfu_entity_name, unsigned int addr, unsigned int len,
-		   char *interface, char *devstring)
+/**
+ * dfu_write_by_name() - write data to DFU medium
+ * @dfu_entity_name:    Name of DFU entity to write
+ * @addr:               Address of data buffer to write
+ * @len:                Number of bytes
+ * @interface:          Destination DFU medium (e.g. "mmc")
+ * @devstring:          Instance number of destination DFU medium (e.g. "1")
+ *
+ * This function is storing data received on DFU supported medium which
+ * is specified by @dfu_entity_name.
+ *
+ * Return:              0 - on success, error code - otherwise
+ */
+int dfu_write_by_name(char *dfu_entity_name, unsigned int addr,
+		      unsigned int len, char *interface, char *devstring)
 {
 	char *s, *sb;
 	int alt_setting_num, ret;
include/dfu.h +16 -16
index 84abdc79acd1..cecfbd76597b 100644
@@ -494,27 +494,27 @@ static inline int dfu_fill_entity_virt(struct dfu_entity *dfu, char *devstr,
 #endif
 
 /**
- * dfu_tftp_write() - write TFTP data to DFU medium
+ * dfu_write_by_name() - write data to DFU medium
+ * @dfu_entity_name:	Name of DFU entity to write
+ * @addr:		Address of data buffer to write
+ * @len:		Number of bytes
+ * @interface:		Destination DFU medium (e.g. "mmc")
+ * @devstring:		Instance number of destination DFU medium (e.g. "1")
  *
- * This function is storing data received via TFTP on DFU supported medium.
+ * This function is storing data received on DFU supported medium which
+ * is specified by @dfu_entity_name.
  *
- * @dfu_entity_name:	name of DFU entity to write
- * @addr:		address of data buffer to write
- * @len:		number of bytes
- * @interface:		destination DFU medium (e.g. "mmc")
- * @devstring:		instance number of destination DFU medium (e.g. "1")
- *
- * Return:		0 on success, otherwise error code
+ * Return:		0 - on success, error code - otherwise
  */
-#if CONFIG_IS_ENABLED(DFU_TFTP)
-int dfu_tftp_write(char *dfu_entity_name, unsigned int addr, unsigned int len,
-		   char *interface, char *devstring);
+#if CONFIG_IS_ENABLED(DFU_ALT)
+int dfu_write_by_name(char *dfu_entity_name, unsigned int addr,
+		      unsigned int len, char *interface, char *devstring);
 #else
-static inline int dfu_tftp_write(char *dfu_entity_name, unsigned int addr,
-				 unsigned int len, char *interface,
-				 char *devstring)
+static inline int dfu_write_by_name(char *dfu_entity_name, unsigned int addr,
+				    unsigned int len, char *interface,
+				    char *devstring)
 {
-	puts("TFTP write support for DFU not available!\n");
+	puts("write support for DFU not available!\n");
 	return -ENOSYS;
 }
 #endif
#4 lore raw

PATCH v6 1/17 dfu: rename dfu_tftp_write() to dfu_write_by_name()

Quoted 51 lines · AKASHI Takahiro
Quoted 50 lines · Heinrich Schuchardt
Quoted 38 lines · AKASHI Takahiro

This function is essentially independent from tftp, and will also be utilised in implementing UEFI capsule update in a later commit. So just give it a more generic name.
In addition, a new configuration option, CONFIG_DFU_ALT, was introduced so that the file will be compiled with different options, particularly one added in a later commit.

---
 common/update.c                       |  5 +++--
 drivers/dfu/Kconfig                   |  5 +++++
 drivers/dfu/Makefile                  |  2 +-
 drivers/dfu/{dfu_tftp.c => dfu_alt.c} | 17 ++++++++++++--
 include/dfu.h                         | 32 +++++++++++++--------------
 5 files changed, 40 insertions(+), 21 deletions(-)
 rename drivers/dfu/{dfu_tftp.c => dfu_alt.c} (67%)
common/update.c +3 -2
index 36b6b7523d50..39946776d74f 100644
@@ -324,8 +324,9 @@ got_update_file:
 			}
 		} else if (fit_image_check_type(fit, noffset,
 						IH_TYPE_FIRMWARE)) {
-			ret = dfu_tftp_write(fit_image_name, update_addr,
-					     update_size, interface, devstring);
+			ret = dfu_write_by_name(fit_image_name, update_addr,
+						update_size, interface,
+						devstring);
 			if (ret)
 				return ret;
 		}
drivers/dfu/Kconfig +0 -0
index 0eec00ba734d..78f901ff348a 100644

drivers/dfu/Kconfig config DFU_OVER_TFTP · line 18

Quoted 5 lines
drivers/dfu/Kconfig +2 -0
@@ -14,8 +14,13 @@ config DFU_OVER_TFTP
 	depends on NET
 
 if DFU
+config DFU_ALT
+	bool

You cannot define CONFIG_DFU_ALT as bool. This symbol already exists as string in include/configs/odroid.h, include/configs/s5p_goni.h, et.al. It is used to initialize environment variable dfu_alt_info. Your patch leads to an error on Travis:

Quoted 7 lines
Quoted 1 line

arm: + odroid

Okay, will fix it.
DFU_WRITE_ALT? Or, as Heinrich suggested, move them to dfu.c if Lukasz agrees.

# I haven't seen any comments from him yet though.

I think what you're introducing as "CONFIG_DFU_ALT" and renaming "drivers/dfu/dfu_tftp.c" to "drivers/dfu/dfu_alt.c" is what's confusing. That I think needs a different name than "alt" to convey that it's a generic "from DRAM to flash/etc" hook.

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/20200909/edadad07/attachment.sig>
#5 lore raw

PATCH v6 1/17 dfu: rename dfu_tftp_write() to dfu_write_by_name()

Quoted 58 lines · Tom Rini
Quoted 57 lines · AKASHI Takahiro
Quoted 50 lines · Heinrich Schuchardt
Quoted 38 lines · AKASHI Takahiro

This function is essentially independent from tftp, and will also be utilised in implementing UEFI capsule update in a later commit. So just give it a more generic name.
In addition, a new configuration option, CONFIG_DFU_ALT, was introduced so that the file will be compiled with different options, particularly one added in a later commit.

---
 common/update.c                       |  5 +++--
 drivers/dfu/Kconfig                   |  5 +++++
 drivers/dfu/Makefile                  |  2 +-
 drivers/dfu/{dfu_tftp.c => dfu_alt.c} | 17 ++++++++++++--
 include/dfu.h                         | 32 +++++++++++++--------------
 5 files changed, 40 insertions(+), 21 deletions(-)
 rename drivers/dfu/{dfu_tftp.c => dfu_alt.c} (67%)
common/update.c +3 -2
index 36b6b7523d50..39946776d74f 100644
@@ -324,8 +324,9 @@ got_update_file:
 			}
 		} else if (fit_image_check_type(fit, noffset,
 						IH_TYPE_FIRMWARE)) {
-			ret = dfu_tftp_write(fit_image_name, update_addr,
-					     update_size, interface, devstring);
+			ret = dfu_write_by_name(fit_image_name, update_addr,
+						update_size, interface,
+						devstring);
 			if (ret)
 				return ret;
 		}
drivers/dfu/Kconfig +0 -0
index 0eec00ba734d..78f901ff348a 100644

drivers/dfu/Kconfig config DFU_OVER_TFTP · line 18

Quoted 5 lines
drivers/dfu/Kconfig +2 -0
@@ -14,8 +14,13 @@ config DFU_OVER_TFTP
 	depends on NET
 
 if DFU
+config DFU_ALT
+	bool

You cannot define CONFIG_DFU_ALT as bool. This symbol already exists as string in include/configs/odroid.h, include/configs/s5p_goni.h, et.al. It is used to initialize environment variable dfu_alt_info. Your patch leads to an error on Travis:

Quoted 1 line

arm: + odroid

Okay, will fix it.
DFU_WRITE_ALT? Or, as Heinrich suggested, move them to dfu.c if Lukasz agrees.

Quoted 6 lines
Quoted 1 line

# I haven't seen any comments from him yet though.

I think what you're introducing as "CONFIG_DFU_ALT" and renaming "drivers/dfu/dfu_tftp.c" to "drivers/dfu/dfu_alt.c" is what's confusing. That I think needs a different name than "alt" to convey that it's a generic "from DRAM to flash/etc" hook.

Whatever the name is, I need reviews on all of my DFU patches from Lukasz in the first place.

-Takahiro Akashi

Quoted 2 lines
Signature · 1 line
Tom
#6 lore raw

PATCH v6 1/17 dfu: rename dfu_tftp_write() to dfu_write_by_name()

Quoted 61 lines · AKASHI Takahiro
Quoted 60 lines · Tom Rini
Quoted 58 lines · AKASHI Takahiro
Quoted 50 lines · Heinrich Schuchardt
Quoted 38 lines · AKASHI Takahiro

This function is essentially independent from tftp, and will also be utilised in implementing UEFI capsule update in a later commit. So just give it a more generic name.
In addition, a new configuration option, CONFIG_DFU_ALT, was introduced so that the file will be compiled with different options, particularly one added in a later commit.

---
 common/update.c                       |  5 +++--
 drivers/dfu/Kconfig                   |  5 +++++
 drivers/dfu/Makefile                  |  2 +-
 drivers/dfu/{dfu_tftp.c => dfu_alt.c} | 17 ++++++++++++--
 include/dfu.h                         | 32 +++++++++++++--------------
 5 files changed, 40 insertions(+), 21 deletions(-)
 rename drivers/dfu/{dfu_tftp.c => dfu_alt.c} (67%)
common/update.c +3 -2
index 36b6b7523d50..39946776d74f 100644
@@ -324,8 +324,9 @@ got_update_file:
 			}
 		} else if (fit_image_check_type(fit, noffset,
 						IH_TYPE_FIRMWARE)) {
-			ret = dfu_tftp_write(fit_image_name, update_addr,
-					     update_size, interface, devstring);
+			ret = dfu_write_by_name(fit_image_name, update_addr,
+						update_size, interface,
+						devstring);
 			if (ret)
 				return ret;
 		}
drivers/dfu/Kconfig +0 -0
index 0eec00ba734d..78f901ff348a 100644

drivers/dfu/Kconfig config DFU_OVER_TFTP · line 18

Quoted 5 lines
drivers/dfu/Kconfig +2 -0
@@ -14,8 +14,13 @@ config DFU_OVER_TFTP
 	depends on NET
 
 if DFU
+config DFU_ALT
+	bool

You cannot define CONFIG_DFU_ALT as bool. This symbol already exists as string in include/configs/odroid.h, include/configs/s5p_goni.h, et.al. It is used to initialize environment variable dfu_alt_info. Your patch leads to an error on Travis:

Quoted 1 line

arm: + odroid

Okay, will fix it.
DFU_WRITE_ALT? Or, as Heinrich suggested, move them to dfu.c if Lukasz agrees.

# I haven't seen any comments from him yet though.

Quoted 7 lines
Quoted 4 lines

I think what you're introducing as "CONFIG_DFU_ALT" and renaming "drivers/dfu/dfu_tftp.c" to "drivers/dfu/dfu_alt.c" is what's confusing. That I think needs a different name than "alt" to convey that it's a generic "from DRAM to flash/etc" hook.

Whatever the name is, I need reviews on all of my DFU patches from Lukasz in the first place.

The lower impact on the rest of the DFU subsytem and other automated testing that can be done, the easier it can be for someone else to review the DFU parts if Lukasz isn't able to find time to do it. 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/20200910/d19265d2/attachment.sig>
#7 lore raw

PATCH v6 1/17 dfu: rename dfu_tftp_write() to dfu_write_by_name()

Tom, Lukasz,

Quoted 67 lines · Tom Rini
Quoted 66 lines · AKASHI Takahiro
Quoted 64 lines · Tom Rini
Quoted 51 lines · AKASHI Takahiro
Quoted 50 lines · Heinrich Schuchardt
Quoted 38 lines · AKASHI Takahiro

This function is essentially independent from tftp, and will also be utilised in implementing UEFI capsule update in a later commit. So just give it a more generic name.
In addition, a new configuration option, CONFIG_DFU_ALT, was introduced so that the file will be compiled with different options, particularly one added in a later commit.

---
 common/update.c                       |  5 +++--
 drivers/dfu/Kconfig                   |  5 +++++
 drivers/dfu/Makefile                  |  2 +-
 drivers/dfu/{dfu_tftp.c => dfu_alt.c} | 17 ++++++++++++--
 include/dfu.h                         | 32 +++++++++++++--------------
 5 files changed, 40 insertions(+), 21 deletions(-)
 rename drivers/dfu/{dfu_tftp.c => dfu_alt.c} (67%)
common/update.c +3 -2
index 36b6b7523d50..39946776d74f 100644
@@ -324,8 +324,9 @@ got_update_file:
 			}
 		} else if (fit_image_check_type(fit, noffset,
 						IH_TYPE_FIRMWARE)) {
-			ret = dfu_tftp_write(fit_image_name, update_addr,
-					     update_size, interface, devstring);
+			ret = dfu_write_by_name(fit_image_name, update_addr,
+						update_size, interface,
+						devstring);
 			if (ret)
 				return ret;
 		}
drivers/dfu/Kconfig +0 -0
index 0eec00ba734d..78f901ff348a 100644

drivers/dfu/Kconfig config DFU_OVER_TFTP · line 18

Quoted 5 lines
drivers/dfu/Kconfig +2 -0
@@ -14,8 +14,13 @@ config DFU_OVER_TFTP
 	depends on NET
 
 if DFU
+config DFU_ALT
+	bool

You cannot define CONFIG_DFU_ALT as bool. This symbol already exists as string in include/configs/odroid.h, include/configs/s5p_goni.h, et.al. It is used to initialize environment variable dfu_alt_info. Your patch leads to an error on Travis:

Quoted 7 lines
Quoted 1 line

arm: + odroid

Okay, will fix it.
DFU_WRITE_ALT? Or, as Heinrich suggested, move them to dfu.c if Lukasz agrees.

# I haven't seen any comments from him yet though.

I think what you're introducing as "CONFIG_DFU_ALT" and renaming "drivers/dfu/dfu_tftp.c" to "drivers/dfu/dfu_alt.c" is what's confusing. That I think needs a different name than "alt" to convey that it's a generic "from DRAM to flash/etc" hook.

Quoted 6 lines
Quoted 2 lines

Whatever the name is, I need reviews on all of my DFU patches from Lukasz in the first place.

The lower impact on the rest of the DFU subsytem and other automated testing that can be done, the easier it can be for someone else to review the DFU parts if Lukasz isn't able to find time to do it.

It sounds nice, but who will take that role?

Please name that person(s) if you're still busy on other stuffs.

        -> Lukasz

-Takahiro Akashi

Quoted 4 lines

Thanks.

Signature · 1 line
Tom
#8 lore raw

PATCH v6 1/17 dfu: rename dfu_tftp_write() to dfu_write_by_name()

Quoted 70 lines · AKASHI Takahiro

Tom, Lukasz,

Quoted 67 lines · Tom Rini
Quoted 66 lines · AKASHI Takahiro
Quoted 64 lines · Tom Rini
Quoted 51 lines · AKASHI Takahiro
Quoted 50 lines · Heinrich Schuchardt
Quoted 38 lines · AKASHI Takahiro

This function is essentially independent from tftp, and will also be utilised in implementing UEFI capsule update in a later commit. So just give it a more generic name.
In addition, a new configuration option, CONFIG_DFU_ALT, was introduced so that the file will be compiled with different options, particularly one added in a later commit.

---
 common/update.c                       |  5 +++--
 drivers/dfu/Kconfig                   |  5 +++++
 drivers/dfu/Makefile                  |  2 +-
 drivers/dfu/{dfu_tftp.c => dfu_alt.c} | 17 ++++++++++++--
 include/dfu.h                         | 32 +++++++++++++--------------
 5 files changed, 40 insertions(+), 21 deletions(-)
 rename drivers/dfu/{dfu_tftp.c => dfu_alt.c} (67%)
common/update.c +3 -2
index 36b6b7523d50..39946776d74f 100644
@@ -324,8 +324,9 @@ got_update_file:
 			}
 		} else if (fit_image_check_type(fit, noffset,
 						IH_TYPE_FIRMWARE)) {
-			ret = dfu_tftp_write(fit_image_name, update_addr,
-					     update_size, interface, devstring);
+			ret = dfu_write_by_name(fit_image_name, update_addr,
+						update_size, interface,
+						devstring);
 			if (ret)
 				return ret;
 		}
drivers/dfu/Kconfig +0 -0
index 0eec00ba734d..78f901ff348a 100644

drivers/dfu/Kconfig config DFU_OVER_TFTP · line 18

Quoted 5 lines
drivers/dfu/Kconfig +2 -0
@@ -14,8 +14,13 @@ config DFU_OVER_TFTP
 	depends on NET
 
 if DFU
+config DFU_ALT
+	bool

You cannot define CONFIG_DFU_ALT as bool. This symbol already exists as string in include/configs/odroid.h, include/configs/s5p_goni.h, et.al. It is used to initialize environment variable dfu_alt_info. Your patch leads to an error on Travis:

Quoted 7 lines
Quoted 1 line

arm: + odroid

Okay, will fix it.
DFU_WRITE_ALT? Or, as Heinrich suggested, move them to dfu.c if Lukasz agrees.

# I haven't seen any comments from him yet though.

I think what you're introducing as "CONFIG_DFU_ALT" and renaming "drivers/dfu/dfu_tftp.c" to "drivers/dfu/dfu_alt.c" is what's confusing. That I think needs a different name than "alt" to convey that it's a generic "from DRAM to flash/etc" hook.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Whatever the name is, I need reviews on all of my DFU patches from Lukasz in the first place.

The lower impact on the rest of the DFU subsytem and other automated testing that can be done, the easier it can be for someone else to review the DFU parts if Lukasz isn't able to find time to do it.

It sounds nice, but who will take that role?

Me.

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/20200917/680405e1/attachment.sig>
#9 lore raw

PATCH v6 1/17 dfu: rename dfu_tftp_write() to dfu_write_by_name()

Quoted 84 lines · On Thu, 17 Sep 2020 21:32:25 -0400 Tom Rini <[email protected]> wrote:
Quoted 83 lines · AKASHI Takahiro

Tom, Lukasz,

Quoted 80 lines · Tom Rini
Quoted 78 lines · AKASHI Takahiro
Quoted 67 lines · Tom Rini
Quoted 65 lines · AKASHI Takahiro
Quoted 57 lines · Heinrich Schuchardt
Quoted 44 lines · AKASHI Takahiro

This function is essentially independent from tftp, and will also be utilised in implementing UEFI capsule update in a later commit. So just give it a more generic name. In addition, a new configuration option, CONFIG_DFU_ALT, was introduced so that the file will be compiled with different options, particularly one added in a later commit.

Signed-off-by: AKASHI Takahiro
<[email protected]> ---

 common/update.c                       |  5 +++--
 drivers/dfu/Kconfig                   |  5 +++++
 drivers/dfu/Makefile                  |  2 +-
 drivers/dfu/{dfu_tftp.c => dfu_alt.c} | 17

++++++++++++-- include/dfu.h |
32 +++++++++++++-------------- 5 files changed, 40 insertions(+), 21 deletions(-) rename drivers/dfu/{dfu_tftp.c => dfu_alt.c} (67%)

common/update.c +2 -2
index 36b6b7523d50..39946776d74f 100644
@@ -324,8 +324,9 @@ got_update_file:
 			}
 		} else if (fit_image_check_type(fit,
 noffset, IH_TYPE_FIRMWARE)) {
-			ret =
 dfu_tftp_write(fit_image_name, update_addr,
-
 update_size, interface, devstring);
+			ret =
 dfu_write_by_name(fit_image_name, update_addr,
+

update_size, interface,
+
devstring); if (ret)

common/update.c +0 -0
 				return ret;
 		}
drivers/dfu/Kconfig +0 -0
index 0eec00ba734d..78f901ff348a 100644

drivers/dfu/Kconfig config DFU_OVER_TFTP · line 18

Quoted 5 lines
drivers/dfu/Kconfig +2 -0
@@ -14,8 +14,13 @@ config DFU_OVER_TFTP
 	depends on NET
 
 if DFU
+config DFU_ALT
+	bool  

You cannot define CONFIG_DFU_ALT as bool. This symbol already exists as string in include/configs/odroid.h, include/configs/s5p_goni.h, et.al. It is used to initialize environment variable dfu_alt_info. Your patch leads to an error on Travis:

Quoted 1 line

arm: + odroid

Okay, will fix it.
DFU_WRITE_ALT? Or, as Heinrich suggested, move them to dfu.c if Lukasz agrees.

Quoted 7 lines
Quoted 1 line

# I haven't seen any comments from him yet though.

I think what you're introducing as "CONFIG_DFU_ALT" and renaming "drivers/dfu/dfu_tftp.c" to "drivers/dfu/dfu_alt.c" is what's confusing. That I think needs a different name than "alt" to convey that it's a generic "from DRAM to flash/etc" hook.

Whatever the name is, I need reviews on all of my DFU patches from Lukasz in the first place.

Quoted 9 lines
Quoted 6 lines
Quoted 4 lines

The lower impact on the rest of the DFU subsytem and other automated testing that can be done, the easier it can be for someone else to review the DFU parts if Lukasz isn't able to find time to do it.

It sounds nice, but who will take that role?

Me.

I thought that there is some ongoing discussion between Heinrich and Takahiro regarding those patches ...

And yes, I'm busy with other work and my time budget is unfortunately reduced since March 2020.

It would be good to have some help to not block ongoing DFU development.

Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma at denx.de -------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200918/abdf0e8c/attachment.sig>

#10 lore raw

PATCH v6 2/17 dfu: modify an argument type for an address

In reply to AKASHI Takahiro

The range of an addressable pointer can go beyond 'integer'. So change the argument type to a void pointer.

---
 common/update.c       | 3 ++-
 drivers/dfu/dfu_alt.c | 6 +++---
 include/dfu.h         | 4 ++--
 3 files changed, 7 insertions(+), 6 deletions(-)
common/update.c +2 -1
index 39946776d74f..8dd6ee8b7ddb 100644
@@ -324,7 +324,8 @@ got_update_file:
 			}
 		} else if (fit_image_check_type(fit, noffset,
 						IH_TYPE_FIRMWARE)) {
-			ret = dfu_write_by_name(fit_image_name, update_addr,
+			ret = dfu_write_by_name(fit_image_name,
+						(void *)update_addr,
 						update_size, interface,
 						devstring);
 			if (ret)
drivers/dfu/dfu_alt.c +3 -3
index 5b1b13d7170d..7528806cd163 100644
@@ -23,14 +23,14 @@
  *
  * Return:              0 - on success, error code - otherwise
  */
-int dfu_write_by_name(char *dfu_entity_name, unsigned int addr,
+int dfu_write_by_name(char *dfu_entity_name, void *addr,
 		      unsigned int len, char *interface, char *devstring)
 {
 	char *s, *sb;
 	int alt_setting_num, ret;
 	struct dfu_entity *dfu;
 
-	debug("%s: name: %s addr: 0x%x len: %d device: %s:%s\n", __func__,
+	debug("%s: name: %s addr: 0x%p len: %d device: %s:%s\n", __func__,
 	      dfu_entity_name, addr, len, interface, devstring);
 
 	ret = dfu_init_env_entities(interface, devstring);
@@ -69,7 +69,7 @@ int dfu_write_by_name(char *dfu_entity_name, unsigned int addr,
 		goto done;
 	}
 
-	ret = dfu_write_from_mem_addr(dfu, (void *)(uintptr_t)addr, len);
+	ret = dfu_write_from_mem_addr(dfu, (void *)addr, len);
 
 done:
 	dfu_free_entities();
include/dfu.h +2 -2
index cecfbd76597b..2299a83a3d94 100644
@@ -507,10 +507,10 @@ static inline int dfu_fill_entity_virt(struct dfu_entity *dfu, char *devstr,
  * Return:		0 - on success, error code - otherwise
  */
 #if CONFIG_IS_ENABLED(DFU_ALT)
-int dfu_write_by_name(char *dfu_entity_name, unsigned int addr,
+int dfu_write_by_name(char *dfu_entity_name, void *addr,
 		      unsigned int len, char *interface, char *devstring);
 #else
-static inline int dfu_write_by_name(char *dfu_entity_name, unsigned int addr,
+static inline int dfu_write_by_name(char *dfu_entity_name, void *addr,
 				    unsigned int len, char *interface,
 				    char *devstring)
 {
Signature · 1 line
2.28.0
#11 lore raw

PATCH v6 3/17 common: update: add a generic interface for FIT image

In reply to AKASHI Takahiro

The main purpose of this patch is to separate a generic interface for updating firmware using DFU drivers from "auto-update" via tftp.

This function will also be used in implementing UEFI capsule update in a later commit.

---
 common/Kconfig      | 15 ++++++++++
 common/Makefile     |  3 +-
 common/update.c     | 71 +++++++++++++++++++++++++++++++++++++++++++++
 drivers/dfu/Kconfig |  1 +
 include/image.h     | 12 ++++++++
 5 files changed, 100 insertions(+), 2 deletions(-)
common/Kconfig +15 -0
index c58f08ba91bf..36998e382bda 100644
@@ -1050,9 +1050,15 @@ endmenu
 
 menu "Update support"
 
+config UPDATE_COMMON
+	bool
+	default n
+	select DFU_ALT
+
 config UPDATE_TFTP
 	bool "Auto-update using fitImage via TFTP"
 	depends on FIT
+	select UPDATE_COMMON
 	help
 	  This option allows performing update of NOR with data in fitImage
 	  sent via TFTP boot.
@@ -1067,6 +1073,15 @@ config UPDATE_TFTP_MSEC_MAX
 	default 100
 	depends on UPDATE_TFTP
 
+config UPDATE_FIT
+	bool "Firmware update using fitImage"
+	depends on FIT
+	depends on DFU
+	select UPDATE_COMMON
+	help
+	  This option allows performing update of DFU-capable storage with
+	  data in fitImage.
+
 config ANDROID_AB
 	bool "Android A/B updates"
 	default n
common/Makefile +1 -2
index 2e7a090588d9..bcf352d01652 100644
@@ -53,8 +53,7 @@ obj-$(CONFIG_LCD_ROTATION) += lcd_console_rotation.o
 obj-$(CONFIG_LCD_DT_SIMPLEFB) += lcd_simplefb.o
 obj-$(CONFIG_LYNXKDI) += lynxkdi.o
 obj-$(CONFIG_MENU) += menu.o
-obj-$(CONFIG_UPDATE_TFTP) += update.o
-obj-$(CONFIG_DFU_TFTP) += update.o
+obj-$(CONFIG_UPDATE_COMMON) += update.o
 obj-$(CONFIG_USB_KEYBOARD) += usb_kbd.o
 obj-$(CONFIG_CMDLINE) += cli_readline.o cli_simple.o
 
common/update.c +71 -0

92 lines not on this page · raw message

drivers/dfu/Kconfig +1 -0
index 78f901ff348a..ce0c42c7df9c 100644
@@ -22,6 +22,7 @@ config DFU_TFTP
 	bool "DFU via TFTP"
 	select DFU_ALT
 	select DFU_OVER_TFTP
+	select UPDATE_COMMON
 	help
 	  This option allows performing update of DFU-managed medium with data
 	  sent via TFTP boot.
include/image.h +12 -0
index 9a5a87dbf870..35b8b7c3d84f 100644
@@ -1592,4 +1592,16 @@ struct fit_loadable_tbl {
 		.handler = _handler, \
 	}
 
+/**
+ * fit_update - update storage with FIT image
+ * @fit:        Pointer to FIT image
+ *
+ * Update firmware on storage using FIT image as input.
+ * The storage area to be update will be identified by the name
+ * in FIT and matching it to "dfu_alt_info" variable.
+ *
+ * Return:      0 on success, non-zero otherwise
+ */
+int fit_update(const void *fit);
+
 #endif	/* __IMAGE_H__ */
Signature · 1 line
2.28.0
#12 lore raw

PATCH v6 4/17 dfu: export dfu_list

In reply to AKASHI Takahiro

This variable will be utilized to enumerate all dfu entities for UEFI capsule firmware update in a later commit.

---
 drivers/dfu/dfu.c | 2 +-
 include/dfu.h     | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)
drivers/dfu/dfu.c +1 -1
index a298c2c43999..501a60b34400 100644
@@ -18,7 +18,7 @@
 #include <linux/list.h>
 #include <linux/compiler.h>
 
-static LIST_HEAD(dfu_list);
+LIST_HEAD(dfu_list);
 static int dfu_alt_num;
 static int alt_num_cnt;
 static struct hash_algo *dfu_hash_algo;
include/dfu.h +3 -0
index 2299a83a3d94..015d1bf895d0 100644
@@ -158,6 +158,9 @@ struct dfu_entity {
 	unsigned int inited:1;
 };
 
+struct list_head;
+extern struct list_head dfu_list;
+
 #ifdef CONFIG_SET_DFU_ALT_INFO
 /**
  * set_dfu_alt_info() - set dfu_alt_info environment variable
Signature · 1 line
2.28.0
#13 lore raw

PATCH v6 5/17 efi_loader: add option to initialise EFI subsystem early

In reply to AKASHI Takahiro

If this option, CONFIG_EFI_SETUP_EARLY, is enabled, the initialisation of UEFI subsystem will be done as part of U-Boot initialisation.

Please note that this option won't be enabled explicitly by users, instead, should be enabled implicitly by other configuration options.

Specifically, this feature will be utilised in implementing capsule-on-disk feature.

---
 common/board_r.c       | 6 ++++++
 lib/efi_loader/Kconfig | 4 ++++
 2 files changed, 10 insertions(+)
common/board_r.c +6 -0
index 9b2fec701a55..0391a1b6acb7 100644
@@ -72,6 +72,9 @@
 #if defined(CONFIG_GPIO_HOG)
 #include <asm/gpio.h>
 #endif
+#ifdef CONFIG_EFI_SETUP_EARLY
+#include <efi_loader.h>
+#endif
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -877,6 +880,9 @@ static init_fnc_t init_sequence_r[] = {
 #endif
 #if defined(CONFIG_PRAM)
 	initr_mem,
+#endif
+#ifdef CONFIG_EFI_SETUP_EARLY
+	(init_fnc_t)efi_init_obj_list,
 #endif
 	run_main_loop,
 };
lib/efi_loader/Kconfig +4 -0
index bad1a29ba804..cbd8fe8c0ad2 100644
@@ -27,6 +27,10 @@ config EFI_LOADER
 
 if EFI_LOADER
 
+config EFI_SETUP_EARLY
+	bool
+	default n
+
 choice
 	prompt "Store for non-volatile UEFI variables"
 	default EFI_VARIABLE_FILE_STORE
Signature · 1 line
2.28.0
#14 lore raw

PATCH v6 6/17 efi_loader: add efi_create_indexed_name()

In reply to AKASHI Takahiro

This function will be used from several places in UEFI subsystem to generate some specific form of utf-16 variable name. For example, L"Capsule0001"

---
 include/efi_loader.h       |  3 +++
 lib/efi_loader/efi_setup.c | 30 ++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+)
include/efi_loader.h +3 -0
index 0baa1d2324c8..a4a123c149fd 100644
@@ -803,6 +803,9 @@ bool efi_image_parse(void *efi, size_t len, struct efi_image_regions **regp,
 /* runtime implementation of memcpy() */
 void efi_memcpy_runtime(void *dest, const void *src, size_t n);
 
+/* commonly used helper function */
+u16 *efi_create_indexed_name(u16 *buffer, const u16 *name, unsigned int index);
+
 #else /* CONFIG_IS_ENABLED(EFI_LOADER) */
 
 /* Without CONFIG_EFI_LOADER we don't have a runtime section, stub it out */
lib/efi_loader/efi_setup.c +30 -0
index 6196c0a06cd7..a09a7b607e11 100644
@@ -6,6 +6,7 @@
  */
 
 #include <common.h>
+#include <charset.h>
 #include <bootm.h>
 #include <efi_loader.h>
 #include <efi_variable.h>
@@ -230,3 +231,32 @@ out:
 	efi_obj_list_initialized = ret;
 	return ret;
 }
+
+/**
+ * efi_create_indexed_name - create a string name with an index
+ * @buffer:	Buffer
+ * @name:	Name string
+ * @index:	Index
+ *
+ * Create a utf-16 string with @name, appending @index.
+ * For example, L"Capsule0001"
+ * This function is expected to be called only from several places
+ * in EFI subsystem. A caller should ensure that the buffer have
+ * enough space for a resulting string, including L"\0".
+ * No strict check against the length will be done here.
+ *
+ * Return: A pointer to the next position after the created string
+ *		in @buffer, or NULL otherwise
+ */
+u16 *efi_create_indexed_name(u16 *buffer, const u16 *name, unsigned int index)
+{
+	u16 *p;
+	char index_buf[5];
+
+	u16_strcpy(buffer, name);
+	p = buffer + utf16_strnlen(name, SIZE_MAX);
+	sprintf(index_buf, "%04X", index);
+	utf8_utf16_strcpy(&p, index_buf);
+
+	return p;
+}
Signature · 1 line
2.28.0
#15 lore raw

PATCH v6 7/17 efi_loader: define UpdateCapsule api

In reply to AKASHI Takahiro

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
index 5744f6aed86d..c128a0a66ce8 100644
@@ -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
index a4a123c149fd..ca50e1c2a18b 100644
@@ -208,6 +208,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;
@@ -806,6 +808,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 u16 *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
index cbd8fe8c0ad2..ee9ebe348ad9 100644
@@ -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
index 9bad1d159b03..c7d231f0e57d 100644
@@ -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
#16 lore raw

PATCH v6 8/17 efi_loader: capsule: add capsule_on_disk support

In reply to AKASHI Takahiro

Capsule 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
index 4b3cd302c3e2..ae5bcdb32f8b 100644
@@ -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
index ca50e1c2a18b..157c560034fc 100644
@@ -819,6 +819,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 */
@@ -835,6 +840,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
index ee9ebe348ad9..6e35cbe64c7f 100644
@@ -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 y
+	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
index 75926c77e61d..2830a7094489 100644
@@ -156,6 +156,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 |
@@ -271,6 +275,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
#17 lore raw

PATCH v6 9/17 efi_loader: capsule: add memory range capsule definitions

In reply to AKASHI Takahiro

Memory 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
index c128a0a66ce8..7a2a087c60ed 100644
@@ -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
#18 lore raw

PATCH v6 10/17 efi_loader: capsule: support firmware update

In reply to AKASHI Takahiro

A 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
index 7a2a087c60ed..966bc6e590bf 100644
@@ -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
index 157c560034fc..9adc7e857b93 100644
@@ -210,6 +210,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
index 6e35cbe64c7f..98bbf6d4ca27 100644
@@ -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
index 2830a7094489..34dd65e30385 100644
@@ -160,6 +160,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
#19 lore raw

PATCH v6 11/17 efi_loader: add firmware management protocol for FIT image

In reply to AKASHI Takahiro

In 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
index 966bc6e590bf..071d0ba866c7 100644
@@ -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
index 9adc7e857b93..6959f62b80a9 100644
@@ -810,6 +810,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 u16 *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
index 98bbf6d4ca27..bc12f0afb4aa 100644
@@ -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
index c7d231f0e57d..23b1828b0fe0 100644
@@ -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
index 2015929e3708..a44f81daaee9 100644
@@ -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
#20 lore raw

PATCH v6 12/17 dfu: add dfu_write_by_alt()

In reply to AKASHI Takahiro

This function is a variant of dfu_write_by_name() and takes a DFU alt setting number for dfu configuration.

It will be utilised to implement UEFI capsule management protocol for raw image in a later commit.

---
 drivers/dfu/dfu_alt.c | 47 +++++++++++++++++++++++++++++++++++++++++++
 include/dfu.h         | 26 +++++++++++++++++++++++-
 2 files changed, 72 insertions(+), 1 deletion(-)
drivers/dfu/dfu_alt.c +47 -0
index 7528806cd163..d5827812070c 100644
@@ -76,3 +76,50 @@ done:
 
 	return ret;
 }
+
+/**
+ * dfu_write_by_alt() - write data to DFU medium
+ * @dfu_alt_num:        DFU alt setting number
+ * @addr:               Address of data buffer to write
+ * @len:                Number of bytes
+ * @interface:          Destination DFU medium (e.g. "mmc")
+ * @devstring:          Instance number of destination DFU medium (e.g. "1")
+ *
+ * This function is storing data received on DFU supported medium which
+ * is specified by @dfu_alt_name.
+ *
+ * Return:              0 - on success, error code - otherwise
+ */
+int dfu_write_by_alt(int dfu_alt_num, void *addr, unsigned int len,
+		     char *interface, char *devstring)
+{
+	struct dfu_entity *dfu;
+	int ret;
+
+	debug("%s: alt: %d addr: 0x%p len: %d device: %s:%s\n", __func__,
+	      dfu_alt_num, addr, len, interface, devstring);
+
+	ret = dfu_init_env_entities(interface, devstring);
+	if (ret)
+		goto done;
+
+	if (dfu_alt_num < 0) {
+		pr_err("Invalid alt number: %d", dfu_alt_num);
+		ret = -ENODEV;
+		goto done;
+	}
+
+	dfu = dfu_get_entity(dfu_alt_num);
+	if (!dfu) {
+		pr_err("DFU entity for alt: %d not found!", dfu_alt_num);
+		ret = -ENODEV;
+		goto done;
+	}
+
+	ret = dfu_write_from_mem_addr(dfu, (void *)(uintptr_t)addr, len);
+
+done:
+	dfu_free_entities();
+
+	return ret;
+}
include/dfu.h +25 -1
index 015d1bf895d0..6c5b4aaa5963 100644
@@ -496,6 +496,7 @@ static inline int dfu_fill_entity_virt(struct dfu_entity *dfu, char *devstr,
 }
 #endif
 
+#if CONFIG_IS_ENABLED(DFU_ALT)
 /**
  * dfu_write_by_name() - write data to DFU medium
  * @dfu_entity_name:	Name of DFU entity to write
@@ -509,9 +510,24 @@ static inline int dfu_fill_entity_virt(struct dfu_entity *dfu, char *devstr,
  *
  * Return:		0 - on success, error code - otherwise
  */
-#if CONFIG_IS_ENABLED(DFU_ALT)
 int dfu_write_by_name(char *dfu_entity_name, void *addr,
 		      unsigned int len, char *interface, char *devstring);
+
+/**
+ * dfu_write_by_alt() - write data to DFU medium
+ * @dfu_alt_num:	DFU alt setting number
+ * @addr:		Address of data buffer to write
+ * @len:		Number of bytes
+ * @interface:		Destination DFU medium (e.g. "mmc")
+ * @devstring:		Instance number of destination DFU medium (e.g. "1")
+ *
+ * This function is storing data received on DFU supported medium which
+ * is specified by @dfu_alt_name.
+ *
+ * Return:		0 - on success, error code - otherwise
+ */
+int dfu_write_by_alt(int dfu_alt_num, void *addr, unsigned int len,
+		     char *interface, char *devstring);
 #else
 static inline int dfu_write_by_name(char *dfu_entity_name, void *addr,
 				    unsigned int len, char *interface,
@@ -520,6 +536,14 @@ static inline int dfu_write_by_name(char *dfu_entity_name, void *addr,
 	puts("write support for DFU not available!\n");
 	return -ENOSYS;
 }
+
+static inline int dfu_write_by_alt(int dfu_alt_num, void *addr,
+				   unsigned int len, char *interface,
+				   char *devstring)
+{
+	puts("write support for DFU not available!\n");
+	return -ENOSYS;
+}
 #endif
 
 int dfu_add(struct usb_configuration *c);
Signature · 1 line
2.28.0
#21 lore raw

PATCH v6 13/17 efi_loader: add firmware management protocol for raw image

In reply to AKASHI Takahiro

In 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
index 071d0ba866c7..c7038f863ab2 100644
@@ -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
index 6959f62b80a9..d9ffc333324d 100644
@@ -811,6 +811,7 @@ void efi_memcpy_runtime(void *dest, const void *src, size_t n);
 u16 *efi_create_indexed_name(u16 *buffer, const u16 *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
index bc12f0afb4aa..ae8c3f07b320 100644
@@ -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_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
index 23b1828b0fe0..a7631d92a3b0 100644
@@ -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
index a44f81daaee9..af40b4a1599e 100644
@@ -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
#22 lore raw

PATCH v6 14/17 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
index 9874838b005a..ad7aa4a304a2 100644
@@ -18,6 +18,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
@@ -1232,6 +1454,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,
+			 "", ""),
+#endif
 	U_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,
@@ -1306,6 +1532,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
#23 lore raw

PATCH v6 15/17 tools: add mkeficapsule command for UEFI capsule update

In reply to AKASHI Takahiro

This 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
index 51123fd92983..66d9376803e3 100644
@@ -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
#24 lore raw

PATCH v6 16/17 test/py: efi_capsule: test for FIT image capsule

In reply to AKASHI Takahiro

The 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.

---
 test/py/tests/test_efi_capsule/conftest.py    |  69 +++++++
 test/py/tests/test_efi_capsule/defs.py        |  12 ++
 .../test_efi_capsule/test_capsule_firmware.py | 178 ++++++++++++++++++
 .../tests/test_efi_capsule/uboot_bin_env.its  |  36 ++++
 tools/mkeficapsule.c                          |   3 +-
 5 files changed, 297 insertions(+), 1 deletion(-)
 create mode 100644 test/py/tests/test_efi_capsule/conftest.py
 create mode 100644 test/py/tests/test_efi_capsule/defs.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/conftest.py new file +69 -0
new file mode 100644
index 000000000000..4e7c36f04ba5
@@ -0,0 +1,69 @@
+# SPDX-License-Identifier:      GPL-2.0+
+# Copyright (c) 2020, Linaro Limited
+# Author: AKASHI Takahiro <[email protected]>
+
+import os
+import os.path
+import re
+from subprocess import call, check_call, check_output, CalledProcessError
+import pytest
+from defs import *
+
+#
+# Fixture for UEFI secure boot test
+#
+
+
+ at pytest.fixture(scope='session')
+def efi_capsule_data(request, u_boot_config):
+    """Set up a file system to be used in UEFI capsule test.
+
+    Args:
+        request: Pytest request object.
+        u_boot_config: U-boot configuration.
+
+    Return:
+        A path to disk image to be used for testing
+    """
+    mnt_point = u_boot_config.persistent_data_dir + '/test_efi_capsule'
+    data_dir = mnt_point + CAPSULE_DATA_DIR
+    install_dir = mnt_point + CAPSULE_INSTALL_DIR
+    image_path = u_boot_config.persistent_data_dir + '/test_efi_capsule.img'
+
+    try:
+        # Create a target device
+        check_call('dd if=/dev/zero of=./spi.bin bs=1MiB count=16', shell=True)
+
+        check_call('rm -rf %s' % mnt_point, shell=True)
+        check_call('mkdir -p %s' % data_dir, shell=True)
+        check_call('mkdir -p %s' % install_dir, shell=True)
+
+        # Create capsule files
+        # two regions: one for u-boot.bin and the other for u-boot.env
+        check_call('cd %s; echo -n u-boot:Old > u-boot.bin.old; echo -n u-boot:New > u-boot.bin.new; echo -n u-boot-env:Old -> u-boot.env.old; echo -n u-boot-env:New > u-boot.env.new' % data_dir,
+                   shell=True)
+        check_call('sed -e \"s?BINFILE1?u-boot.bin.new?\" -e \"s?BINFILE2?u-boot.env.new?\" %s/test/py/tests/test_efi_capsule/uboot_bin_env.its > %s/uboot_bin_env.its' %
+                   (u_boot_config.source_dir, data_dir),
+                   shell=True)
+        check_call('cd %s; %s/tools/mkimage -f uboot_bin_env.its uboot_bin_env.itb' %
+                   (data_dir, u_boot_config.build_dir),
+                   shell=True)
+        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)
+
+        # Create a disk image with EFI system partition
+        check_call('virt-make-fs --partition=gpt --size=+1M --type=vfat %s %s' %
+                   (mnt_point, image_path), shell=True)
+        check_call('sgdisk %s -A 1:set:0 -t 1:C12A7328-F81F-11D2-BA4B-00A0C93EC93B' %
+                   image_path, shell=True)
+
+    except CalledProcessError as exception:
+        pytest.skip('Setup failed: %s' % exception.cmd)
+        return
+    else:
+        yield image_path
+    finally:
+        call('rm -rf %s' % mnt_point, shell=True)
+        call('rm -f %s' % image_path, shell=True)
+        call('rm -f ./spi.bin', shell=True)
test/py/tests/test_efi_capsule/defs.py new file +12 -0
new file mode 100644
index 000000000000..2c5b0ee49beb
@@ -0,0 +1,12 @@
+# SPDX-License-Identifier:      GPL-2.0+
+
+# Size in MiB
+EFI_BOOTDEV_IMAGE_SIZE = 16
+EFI_BOOTDEV_PART_SIZE = 8
+
+# Owner guid
+GUID = '11111111-2222-3333-4444-123456789abc'
+
+# Directories
+CAPSULE_DATA_DIR = '/EFI/CapsuleTestData'
+CAPSULE_INSTALL_DIR = '/EFI/UpdateCapsule'
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
new file mode 100644
index 000000000000..31e2f8049f9a
@@ -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
index db95426457cc..45e27d74a5e9 100644
@@ -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
#25 lore raw

PATCH v6 17/17 test/py: efi_capsule: test for raw image capsule

In reply to AKASHI Takahiro

The 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
index 4e7c36f04ba5..4544a24d5351 100644
@@ -51,6 +51,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
#26 lore raw

v6 cover efi_loader: add capsule update support

In reply to AKASHI Takahiro
Quoted 60 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 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-#4,#12: preparatory patches
Patch#5-#11,#13: main part of implementation
Patch#14-#15: utilities
Patch#16-#17: pytests

[1] https://git.linaro.org/people/takahiro.akashi/u-boot.git efi/capsule

Quoted 7 lines

Prerequisite patches
====================
In this version, the DFU change by Heinrich[2] is, at least temporarily, not a prerequisite due to the discussions[3].

[2] https://lists.denx.de/pipermail/u-boot/2020-July/420950.html
[3] https://lists.denx.de/pipermail/u-boot/2020-August/424716.html

The end of the discussion was that the patch is postponed to v2021.01 like your series.

Quoted 8 lines

Test
====
* passed all the pytests which are included in this patch series on sandbox build locally.

Please note that the capsule pytest itself won't be run in the CI partly because some specific configuration for sandbox build is

Shouldn't the sandbox_defconfig changes be added to your series?

Is this the correct change:

configs/sandbox_defconfig +5 -0
index 6e9f029cc9..da82afaa01 100644
@@ -129,6 +129,7 @@ CONFIG_DM_DEMO_SIMPLE=y
 CONFIG_DM_DEMO_SHAPE=y
 CONFIG_BOARD=y
 CONFIG_BOARD_SANDBOX=y
+CONFIG_DFU_SF=y
 CONFIG_DMA=y
 CONFIG_DMA_CHANNELS=y
 CONFIG_SANDBOX_DMA=y
@@ -261,6 +262,10 @@ CONFIG_CMD_DHRYSTONE=y
 CONFIG_TPM=y
 CONFIG_LZ4=y
 CONFIG_ERRNO_STR=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
 CONFIG_EFI_SECURE_BOOT=y
 CONFIG_TEST_FDTDEC=y
 CONFIG_UNIT_TEST=y
Quoted 1 line

required and partly because there is a problem with virt-make-fs.

What problem with virt-make-fs exists? How will this be solved?

Quoted 14 lines

See test_efi_capsule_firmware.py.

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.

Please, use 'if' instead of '#if' where possible so that the compiler checks the code syntax even if the configuration is not set. Like with '#if' the compiler will eliminate unused code.

Best regards

Heinrich

Quoted 160 lines

* 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
=======
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 (17):
dfu: rename dfu_tftp_write() to dfu_write_by_name()
dfu: modify an argument type for an address
common: update: add a generic interface for FIT image
dfu: export dfu_list
efi_loader: add option to initialise EFI subsystem early
efi_loader: add efi_create_indexed_name()
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
dfu: add dfu_write_by_alt()
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

 cmd/efidebug.c                                | 235 +++++
 common/Kconfig                                |  15 +
 common/Makefile                               |   3 +-
 common/board_r.c                              |   6 +
 common/main.c                                 |   4 +
 common/update.c                               |  77 +-
 drivers/dfu/Kconfig                           |   6 +
 drivers/dfu/Makefile                          |   2 +-
 drivers/dfu/dfu.c                             |   2 +-
 drivers/dfu/dfu_alt.c                         | 125 +++
 drivers/dfu/dfu_tftp.c                        |  65 --
 include/dfu.h                                 |  57 +-
 include/efi_api.h                             | 166 ++++
 include/efi_loader.h                          |  30 +
 include/image.h                               |  12 +
 lib/efi_loader/Kconfig                        |  72 ++
 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                    | 106 +-
 test/py/tests/test_efi_capsule/conftest.py    |  72 ++
 test/py/tests/test_efi_capsule/defs.py        |  12 +
 .../test_efi_capsule/test_capsule_firmware.py | 241 +++++
 .../tests/test_efi_capsule/uboot_bin_env.its  |  36 +
 tools/Makefile                                |   2 +
 tools/mkeficapsule.c                          | 239 +++++
 27 files changed, 2871 insertions(+), 140 deletions(-)
 create mode 100644 drivers/dfu/dfu_alt.c
 delete mode 100644 drivers/dfu/dfu_tftp.c
 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/conftest.py
 create mode 100644 test/py/tests/test_efi_capsule/defs.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
#27 lore raw

v6 cover efi_loader: add capsule update support

Quoted 1 line · Heinrich Schuchardt

On 07.09.20 07:34, AKASHI Takahiro wrote:

[snip]

Quoted 3 lines
Quoted 1 line

required and partly because there is a problem with virt-make-fs.

What problem with virt-make-fs exists? How will this be solved?

This I suspect is related to the difficulty of getting tests to run in all of our CI environments, where at least in one case they run and pass, rather than skip. This will require that the series get run through at least Travis and Azure before re-posting, at this point. 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/20200909/89e8040c/attachment.sig>
#28 lore raw

v6 cover efi_loader: add capsule update support

Quoted 5 lines · Tom Rini
Quoted 1 line · Heinrich Schuchardt

On 07.09.20 07:34, AKASHI Takahiro wrote:

[snip]

Quoted 2 lines
Quoted 1 line

required and partly because there is a problem with virt-make-fs.

Quoted 7 lines
Quoted 1 line

What problem with virt-make-fs exists? How will this be solved?

This I suspect is related to the difficulty of getting tests to run in all of our CI environments, where at least in one case they run and pass, rather than skip. This will require that the series get run through at least Travis and Azure before re-posting, at this point. Thanks.

I think that we discussed this issue several times before.

https://lists.denx.de/pipermail/u-boot/2020-July/419430.html
https://lists.denx.de/pipermail/u-boot/2020-July/420712.html

I have not implemented a fallback handling in case of virt-make-fs failure as Heinrich doesn't like it (even dropped the code from my patches.)

The only solution is Heinrich's patch:
https://lists.denx.de/pipermail/u-boot/2020-July/419976.html

-Takahiro Akashi

Quoted 2 lines
Signature · 1 line
Tom
#29 lore raw

v6 cover efi_loader: add capsule update support

Quoted 16 lines · AKASHI Takahiro
Quoted 5 lines · Tom Rini
Quoted 1 line · Heinrich Schuchardt

On 07.09.20 07:34, AKASHI Takahiro wrote:

[snip]

Quoted 2 lines
Quoted 1 line

required and partly because there is a problem with virt-make-fs.

Quoted 7 lines
Quoted 1 line

What problem with virt-make-fs exists? How will this be solved?

This I suspect is related to the difficulty of getting tests to run in all of our CI environments, where at least in one case they run and pass, rather than skip. This will require that the series get run through at least Travis and Azure before re-posting, at this point. Thanks.

I think that we discussed this issue several times before.

Quoted 8 lines

https://lists.denx.de/pipermail/u-boot/2020-July/419430.html
https://lists.denx.de/pipermail/u-boot/2020-July/420712.html

I have not implemented a fallback handling in case of virt-make-fs failure as Heinrich doesn't like it (even dropped the code from my patches.)

The only solution is Heinrich's patch:
https://lists.denx.de/pipermail/u-boot/2020-July/419976.html

The problem is that Heinrich's patch breaks things. A complete solution is required. That patch might be part of the solution, along with perhaps a rework of the logic to try and gracefully catch and re-try when we have a problem with one of the possible tools.

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/20200909/5cc44811/attachment.sig>
#30 lore raw

v6 cover efi_loader: add capsule update support

Quoted 20 lines · Tom Rini
Quoted 19 lines · AKASHI Takahiro
Quoted 5 lines · Tom Rini
Quoted 1 line · Heinrich Schuchardt

On 07.09.20 07:34, AKASHI Takahiro wrote:

[snip]

Quoted 2 lines
Quoted 1 line

required and partly because there is a problem with virt-make-fs.

Quoted 7 lines
Quoted 1 line

What problem with virt-make-fs exists? How will this be solved?

This I suspect is related to the difficulty of getting tests to run in all of our CI environments, where at least in one case they run and pass, rather than skip. This will require that the series get run through at least Travis and Azure before re-posting, at this point. Thanks.

I think that we discussed this issue several times before.

https://lists.denx.de/pipermail/u-boot/2020-July/419430.html
https://lists.denx.de/pipermail/u-boot/2020-July/420712.html

Quoted 8 lines
Quoted 5 lines

I have not implemented a fallback handling in case of virt-make-fs failure as Heinrich doesn't like it (even dropped the code from my patches.)

The only solution is Heinrich's patch:
https://lists.denx.de/pipermail/u-boot/2020-July/419976.html

The problem is that Heinrich's patch breaks things. A complete solution is required.

What kind of issue did you see?

Quoted 3 lines

That patch might be part of the solution, along with perhaps a rework of the logic to try and gracefully catch and re-try when we have a problem with one of the possible tools.

Anyway, I can't do anything here as Heinrich rejects any sudo-based solution. See:

https://lists.denx.de/pipermail/u-boot/2020-July/419951.html

So he is responsible for fixing it.

-Takahiro Akashi

Quoted 2 lines
Signature · 1 line
Tom
#31 lore raw

v6 cover efi_loader: add capsule update support

Quoted 24 lines · AKASHI Takahiro
Quoted 23 lines · Tom Rini
Quoted 22 lines · AKASHI Takahiro
Quoted 5 lines · Tom Rini
Quoted 1 line · Heinrich Schuchardt

On 07.09.20 07:34, AKASHI Takahiro wrote:

[snip]

Quoted 2 lines
Quoted 1 line

required and partly because there is a problem with virt-make-fs.

Quoted 7 lines
Quoted 1 line

What problem with virt-make-fs exists? How will this be solved?

This I suspect is related to the difficulty of getting tests to run in all of our CI environments, where at least in one case they run and pass, rather than skip. This will require that the series get run through at least Travis and Azure before re-posting, at this point. Thanks.

I think that we discussed this issue several times before.

https://lists.denx.de/pipermail/u-boot/2020-July/419430.html
https://lists.denx.de/pipermail/u-boot/2020-July/420712.html

I have not implemented a fallback handling in case of virt-make-fs failure as Heinrich doesn't like it (even dropped the code from my patches.)

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

The only solution is Heinrich's patch:
https://lists.denx.de/pipermail/u-boot/2020-July/419976.html

The problem is that Heinrich's patch breaks things. A complete solution is required.

What kind of issue did you see?

I believe it's in the thread. But in short, we then stop running the other filesystem tests as they get skipped.

Quoted 10 lines
Quoted 3 lines

That patch might be part of the solution, along with perhaps a rework of the logic to try and gracefully catch and re-try when we have a problem with one of the possible tools.

Anyway, I can't do anything here as Heinrich rejects any sudo-based solution. See:

https://lists.denx.de/pipermail/u-boot/2020-July/419951.html

So he is responsible for fixing it.

No, it's on you to provide a solution that runs in both CI and developer machines. It's not sudo or make-virt-fs, it's get the try/catch logic correct in the test framework such that if we can't run sudo we do run make-virt-fs, and if we're able to run the tests somehow, we run the tests somehow.

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/20200910/21903a20/attachment.sig>
#32 lore raw

v6 cover efi_loader: add capsule update support

Tom,

Quoted 28 lines · Tom Rini
Quoted 27 lines · AKASHI Takahiro
Quoted 26 lines · Tom Rini
Quoted 24 lines · AKASHI Takahiro
Quoted 5 lines · Tom Rini
Quoted 1 line · Heinrich Schuchardt

On 07.09.20 07:34, AKASHI Takahiro wrote:

[snip]

Quoted 2 lines
Quoted 1 line

required and partly because there is a problem with virt-make-fs.

Quoted 7 lines
Quoted 1 line

What problem with virt-make-fs exists? How will this be solved?

This I suspect is related to the difficulty of getting tests to run in all of our CI environments, where at least in one case they run and pass, rather than skip. This will require that the series get run through at least Travis and Azure before re-posting, at this point. Thanks.

I think that we discussed this issue several times before.

https://lists.denx.de/pipermail/u-boot/2020-July/419430.html
https://lists.denx.de/pipermail/u-boot/2020-July/420712.html

I have not implemented a fallback handling in case of virt-make-fs failure as Heinrich doesn't like it (even dropped the code from my patches.)

The only solution is Heinrich's patch:
https://lists.denx.de/pipermail/u-boot/2020-July/419976.html

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

The problem is that Heinrich's patch breaks things. A complete solution is required.

What kind of issue did you see?

I believe it's in the thread. But in short, we then stop running the other filesystem tests as they get skipped.

I believe that the reason of failures in filesystem tests is the same; /boot/vmlinuz* have not 'read' permission to users and any commands in libguestfs-tools, including guestmount and virt-make-fs, cannot set up a virtual machine internally used in those commands.

So again, the only solution is to apply Heinrich's patch.

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

That patch might be part of the solution, along with perhaps a rework of the logic to try and gracefully catch and re-try when we have a problem with one of the possible tools.

Anyway, I can't do anything here as Heinrich rejects any sudo-based solution. See:

Quoted 7 lines
Quoted 3 lines

https://lists.denx.de/pipermail/u-boot/2020-July/419951.html

So he is responsible for fixing it.

No, it's on you to provide a solution that runs in both CI and developer machines. It's not sudo or make-virt-fs, it's get the try/catch logic correct in the test framework such that if we can't run sudo

The point is that Heinrich doesn't accept any sudo solution and that he modified my tests to solely use virt-make-fs by the patch above. So what can I do here?

Quoted 3 lines

we do run
make-virt-fs, and if we're able to run the tests somehow, we run the tests somehow.

Again, Heinrich's patch will fix it.

-Takahiro Akashi

Quoted 3 lines
Signature · 2 lines
-- 
Tom
#33 lore raw

v6 cover efi_loader: add capsule update support

Quoted 39 lines · AKASHI Takahiro

Tom,

Quoted 28 lines · Tom Rini
Quoted 27 lines · AKASHI Takahiro
Quoted 26 lines · Tom Rini
Quoted 24 lines · AKASHI Takahiro
Quoted 5 lines · Tom Rini
Quoted 1 line · Heinrich Schuchardt

On 07.09.20 07:34, AKASHI Takahiro wrote:

[snip]

Quoted 2 lines
Quoted 1 line

required and partly because there is a problem with virt-make-fs.

Quoted 7 lines
Quoted 1 line

What problem with virt-make-fs exists? How will this be solved?

This I suspect is related to the difficulty of getting tests to run in all of our CI environments, where at least in one case they run and pass, rather than skip. This will require that the series get run through at least Travis and Azure before re-posting, at this point. Thanks.

I think that we discussed this issue several times before.

https://lists.denx.de/pipermail/u-boot/2020-July/419430.html
https://lists.denx.de/pipermail/u-boot/2020-July/420712.html

I have not implemented a fallback handling in case of virt-make-fs failure as Heinrich doesn't like it (even dropped the code from my patches.)

The only solution is Heinrich's patch:
https://lists.denx.de/pipermail/u-boot/2020-July/419976.html

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

The problem is that Heinrich's patch breaks things. A complete solution is required.

What kind of issue did you see?

I believe it's in the thread. But in short, we then stop running the other filesystem tests as they get skipped.

Quoted 6 lines

I believe that the reason of failures in filesystem tests is the same; /boot/vmlinuz* have not 'read' permission to users and any commands in libguestfs-tools, including guestmount and virt-make-fs, cannot set up a virtual machine internally used in those commands.

So again, the only solution is to apply Heinrich's patch.

No, I believe I fixed that as part of digging in to this at the time.

Quoted 19 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

That patch might be part of the solution, along with perhaps a rework of the logic to try and gracefully catch and re-try when we have a problem with one of the possible tools.

Anyway, I can't do anything here as Heinrich rejects any sudo-based solution. See:

Quoted 7 lines
Quoted 3 lines

https://lists.denx.de/pipermail/u-boot/2020-July/419951.html

So he is responsible for fixing it.

No, it's on you to provide a solution that runs in both CI and developer machines. It's not sudo or make-virt-fs, it's get the try/catch logic correct in the test framework such that if we can't run sudo

The point is that Heinrich doesn't accept any sudo solution and that he modified my tests to solely use virt-make-fs by the patch above. So what can I do here?

Quoted 5 lines
Quoted 3 lines

we do run
make-virt-fs, and if we're able to run the tests somehow, we run the tests somehow.

Again, Heinrich's patch will fix it.

Please put together a series that passes and runs on CI and doesn't make other tests stop running. That's the requirement. If it doesn't run in CI, it doesn't get run frequently enough. If it makes some CI tests stop running, that's a problem too.

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/20200910/3142d24f/attachment.sig>
#34 lore raw

v6 cover efi_loader: add capsule update support

In reply to Heinrich Schuchardt
Quoted 66 lines · Heinrich Schuchardt
Quoted 65 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 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-#4,#12: preparatory patches
Patch#5-#11,#13: main part of implementation
Patch#14-#15: utilities
Patch#16-#17: pytests

[1] https://git.linaro.org/people/takahiro.akashi/u-boot.git efi/capsule

Prerequisite patches
====================
In this version, the DFU change by Heinrich[2] is, at least temporarily, not a prerequisite due to the discussions[3].

Quoted 5 lines
Quoted 2 lines

[2] https://lists.denx.de/pipermail/u-boot/2020-July/420950.html
[3] https://lists.denx.de/pipermail/u-boot/2020-August/424716.html

The end of the discussion was that the patch is postponed to v2021.01 like your series.

My understanding was that the patch will be deferred until v2021.01 and we need more discussions. Right?

Quoted 10 lines
Quoted 8 lines

Test
====
* passed all the pytests which are included in this patch series on sandbox build locally.

Please note that the capsule pytest itself won't be run in the CI partly because some specific configuration for sandbox build is

Shouldn't the sandbox_defconfig changes be added to your series?

I won't hesitate to add them if Simon agrees.
Since the current test removed the dependency on ENV_IS_IN_SPI_FLASH which was required in v3 or early, it would be more acceptable.

Quoted 1 line

Is this the correct change:

It would be fine.

Quoted 24 lines
configs/sandbox_defconfig +5 -0
index 6e9f029cc9..da82afaa01 100644
@@ -129,6 +129,7 @@ CONFIG_DM_DEMO_SIMPLE=y
 CONFIG_DM_DEMO_SHAPE=y
 CONFIG_BOARD=y
 CONFIG_BOARD_SANDBOX=y
+CONFIG_DFU_SF=y
 CONFIG_DMA=y
 CONFIG_DMA_CHANNELS=y
 CONFIG_SANDBOX_DMA=y
@@ -261,6 +262,10 @@ CONFIG_CMD_DHRYSTONE=y
 CONFIG_TPM=y
 CONFIG_LZ4=y
 CONFIG_ERRNO_STR=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
 CONFIG_EFI_SECURE_BOOT=y
 CONFIG_TEST_FDTDEC=y
 CONFIG_UNIT_TEST=y
Quoted 3 lines
Quoted 1 line

required and partly because there is a problem with virt-make-fs.

What problem with virt-make-fs exists? How will this be solved?

See my reply to Tom.

-Takahiro Akashi

Quoted 184 lines
Quoted 14 lines

See test_efi_capsule_firmware.py.

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.

Please, use 'if' instead of '#if' where possible so that the compiler checks the code syntax even if the configuration is not set. Like with '#if' the compiler will eliminate unused code.

Best regards

Heinrich

Quoted 160 lines

* 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
=======
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 (17):
dfu: rename dfu_tftp_write() to dfu_write_by_name()
dfu: modify an argument type for an address
common: update: add a generic interface for FIT image
dfu: export dfu_list
efi_loader: add option to initialise EFI subsystem early
efi_loader: add efi_create_indexed_name()
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
dfu: add dfu_write_by_alt()
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

 cmd/efidebug.c                                | 235 +++++
 common/Kconfig                                |  15 +
 common/Makefile                               |   3 +-
 common/board_r.c                              |   6 +
 common/main.c                                 |   4 +
 common/update.c                               |  77 +-
 drivers/dfu/Kconfig                           |   6 +
 drivers/dfu/Makefile                          |   2 +-
 drivers/dfu/dfu.c                             |   2 +-
 drivers/dfu/dfu_alt.c                         | 125 +++
 drivers/dfu/dfu_tftp.c                        |  65 --
 include/dfu.h                                 |  57 +-
 include/efi_api.h                             | 166 ++++
 include/efi_loader.h                          |  30 +
 include/image.h                               |  12 +
 lib/efi_loader/Kconfig                        |  72 ++
 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                    | 106 +-
 test/py/tests/test_efi_capsule/conftest.py    |  72 ++
 test/py/tests/test_efi_capsule/defs.py        |  12 +
 .../test_efi_capsule/test_capsule_firmware.py | 241 +++++
 .../tests/test_efi_capsule/uboot_bin_env.its  |  36 +
 tools/Makefile                                |   2 +
 tools/mkeficapsule.c                          | 239 +++++
 27 files changed, 2871 insertions(+), 140 deletions(-)
 create mode 100644 drivers/dfu/dfu_alt.c
 delete mode 100644 drivers/dfu/dfu_tftp.c
 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/conftest.py
 create mode 100644 test/py/tests/test_efi_capsule/defs.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