mbox series

[v5,0/8] efi: capsule: Capsule Update fixes and enhancements

Message ID 20220401191759.1670812-1-sughosh.ganu@linaro.org
Headers show
Series efi: capsule: Capsule Update fixes and enhancements | expand

Message

Sughosh Ganu April 1, 2022, 7:17 p.m. UTC
This series is cleaning up the usage of the image GUIDs that are used
in capsule update and the EFI System Resource Table(ESRT). There are
some other enhancements being made to the capsule update code to make
it more robust.

Firstly, an overview of the fixes being made.

Currently, there are two instances of the Firmware Management
Protocol(FMP), one defined for updating the FIT images, and the other
for updating raw images. The FMP code defines two GUID values, one for
all FIT images, and one for raw images. Depending on the FMP instance
used on a platform, the platform needs to use the corresponding image
GUID value for all images on the platform, and also across platforms.

A few issues are being fixed through the patch series. One, that an
image for a different platform can be flashed on another platform if
both the platforms are using the same FMP instance. So, for e.g. a
capsule generated for the Socionext DeveloperBox platform can be
flashed on the ZynqMP platform, since both the platforms use the
CONFIG_EFI_CAPSULE_FIRMWARE_RAW instance of the FMP. This can be
corrected if each firmware image that can be updated through the
capsule update mechanism has it's own unique image GUID.

The second issue that this patch series fixes is the value of FwClass
in the ESRT. With the current logic, all firmware image entries in the
ESRT display the same GUID value -- either the FIT GUID or the raw
GUID. This is not in compliance with the UEFI specification, as the
specification requires all entries to have unique GUID values.

The third issue being fixed is the population of the
EFI_FIRMWARE_IMAGE_DESCRIPTOR array. The current code uses the dfu
framework for populating the image descriptor array. However, there
might be other images that are not to be updated through the capsule
update mechanism also registered with the dfu framework. As a result
of this, the ESRT will show up entries of images that are not to be
targeted by the capsule update mechanism.

These issues are being fixed by defining a structure, efi_fw_images. A
platform can then define image related information like the image GUID
and image name. Every platform that uses capsule update mechanism
needs to define fw_images array. This array will then be used to
populate the image descriptor array, and also in determining if a
particular capsule's payload can be used for updating an image on the
platform.


The other part of the patches are some enhancements being made to the
capsule update code to make it more robust.

The first enhancement being made is to have a check for the image
index being passed through the capsule header. The capsule update code
uses the image index value as the dfu alt number, which points to the
partition to which the update must be made. The platform is supposed
to define the image index value for the updatable firmare images as
part of the fw_images array. This value must correspond to the dfu alt
num for the corresponding image, and can be obtained by checking the
output of the 'dfu list' u-boot command. At the time of update, the
image index being passed through the capsule is checked against the
image index value obtained from the platform.

The second enhancement made is the retrieval of the dfu_alt_info
variable from the set_dfu_alt_info function instead of using the
value defined in the environment. The dfu framework checks for the
existence of this function, and if the function is not defined, gets
the value from the environment. This can cause in an incorrect update
if the environment variable value is incorrect. A weak function is
defined for populating dfu_alt_info from the information obtained from
the platform. This function gets invoked on all platforms which
enabled capsule update feature.

The first patch adds the structure efi_capsule_update_info and
initialises the structure on all platforms which enable capsule update
feature

The second patch populates the image descriptor array in the
GetImageInfo function with the values from the fw_images array defined
in the board file

The third patch adds a check for the image index value from the
capsule header against the value obtained from the fw_images array for
the corresponding image

The fourth patch defines a weak function set_dfu_alt_info which is
used to populate dfu_alt_info to be used for capsule updates.

The fifth patch splits the capsule update test script into two, one
for FMP for raw images, and one for FMP for FIT images. The test for
FIT images is being enabled on the sandbox_flattree variant.

The sixth patch removes the now unused FIT and raw image GUID values
from the FMP module.

The seventh patch removes the --raw and --fit command line parameters
in the mkeficapsule utility.

The eighth patch makes corresponding changes in the capsule update
related documentation.

Changes since V4:
-----------------

* Define a structure efi_capsule_update_info which includes the string
  for populating dfu_alt_info
* Initialise the string for dfu_alt_info in the board file
* Drop the image_count variable as was suggested by Ilias
* Drop another unused variable names_len
* Define a weak function set_dfu_alt_info for setting the variable in
  a non board specific file as suggested by Ilias
* Drop the definitions of set_dfu_alt_info that were being added in
  the board files
* Change the description of the platform data based on the changes
  made in earlier patches


Changes since V3:
-----------------

* Do not remove the existing dfu_alt_info definitions made by
  platforms in the config files, as discussed with Masami.
* Squash the selection of the SET_DFU_ALT_INFO config symbol for
  capsule update feature as part of this patch.
* Rephrase the commit message to indicate that the doc changes are not
  just limited to adding the GUID values, but other info as well.
* Elaborate with an example on the relation between the dfu alt number
  and the image index 

Changes since V2:
-----------------

* Add a new member image_index to the struct efi_fw_images to allow
  the platforms to define the values for images.
* Address review comments from Michal Simek for the xilinx boards.
* Fix double inclusion of efi_loader.h as was pointed out by Heiko
  Thiery.
* Use the image index values defined in the platform's fw_images array
  for the image descriptors
* Add a description for adding image index value and definition of
  set_dfu_alt_info function for the capsule updates.

Changes since V1:
-----------------

* Make changes for the xilinx boards as suggested by Michal Simek.
* Add a GUID for the sandbox FIT image.
* Split the capsule update test cases into two scripts, one for raw
  images and one for FIT images.
* Add the capsule update test case for FIT images on sandbox64 and
  sandbox_flattree variants.
* Add capsule update support on sandbox_flattree variant for enabling
  FIT capsule update testing as part of the python tests

Sughosh Ganu (8):
  capsule: board: Add information needed for capsule updates
  capsule: FMP: Populate the image descriptor array from platform data
  capsule: Put a check for image index before the update
  efi: Define set_dfu_alt_info() for boards with UEFI capsule update
    enabled
  test: capsule: Modify the capsule tests to use GUID values for sandbox
  FMP: Remove GUIDs for FIT and raw images
  mkeficapsule: Remove raw and FIT GUID types
  doc: uefi: Update the capsule update related documentation

 .../imx8mp_rsb3720a1/imx8mp_rsb3720a1.c       |  25 +++
 .../imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c   |  24 +++
 board/emulation/qemu-arm/qemu-arm.c           |  24 +++
 board/kontron/pitx_imx8m/pitx_imx8m.c         |  21 +-
 board/kontron/sl-mx8mm/sl-mx8mm.c             |  20 ++
 board/kontron/sl28/sl28.c                     |  21 ++
 board/sandbox/sandbox.c                       |  34 ++++
 board/socionext/developerbox/developerbox.c   |  33 ++++
 board/xilinx/common/board.c                   |  28 +++
 configs/sandbox64_defconfig                   |   1 -
 configs/sandbox_defconfig                     |   1 -
 configs/sandbox_flattree_defconfig            |   5 +
 doc/develop/uefi/uefi.rst                     |  51 ++++-
 include/configs/imx8mm-cl-iot-gate.h          |  10 +
 include/configs/imx8mp_rsb3720.h              |  10 +
 include/configs/kontron-sl-mx8mm.h            |   6 +
 include/configs/kontron_pitx_imx8m.h          |   6 +
 include/configs/kontron_sl28.h                |   6 +
 include/configs/qemu-arm.h                    |  10 +
 include/configs/sandbox.h                     |  14 ++
 include/configs/synquacer.h                   |  14 ++
 include/configs/xilinx_versal.h               |   6 +
 include/configs/xilinx_zynqmp.h               |  10 +
 include/configs/zynq-common.h                 |  10 +
 include/efi_api.h                             |   8 -
 include/efi_loader.h                          |  36 ++++
 lib/efi_loader/Kconfig                        |   2 +
 lib/efi_loader/efi_capsule.c                  |   8 +-
 lib/efi_loader/efi_firmware.c                 | 122 +++++-------
 test/py/tests/test_efi_capsule/conftest.py    |  21 +-
 .../test_capsule_firmware_fit.py              | 186 ++++++++++++++++++
 ...rmware.py => test_capsule_firmware_raw.py} | 159 +++++----------
 tools/eficapsule.h                            |   8 -
 tools/mkeficapsule.c                          |  26 +--
 34 files changed, 733 insertions(+), 233 deletions(-)
 create mode 100644 test/py/tests/test_efi_capsule/test_capsule_firmware_fit.py
 rename test/py/tests/test_efi_capsule/{test_capsule_firmware.py => test_capsule_firmware_raw.py} (75%)