mbox series

[v3,0/9] efi: capsule: Capsule Update fixes and enhancements

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

Message

Sughosh Ganu March 30, 2022, 2:50 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 defined in the board
file. 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. By mandating all the platforms which
enable the capsule update feature to define set_dfu_alt_info function,
the variable is then obtained from the board file rather than the
environment.

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.


The first patch adds the structure efi_fw_images and defines an array
fw_images 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

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 the function set_dfu_alt_info for all the
platforms which enable capsule update feature.

The fifth patch selects SET_DFU_ALT_INFO config symbol for all
platforms that enable capsule update feature.

The sixth 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 seventh patch removes the now unused FIT and raw image GUID values
from the FMP module.

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

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

Sughosh Ganu (9):
  capsule: Add Image GUIDs and image index for platforms using capsule
    updates
  capsule: FMP: Populate the image descriptor array from platform data
  capsule: Put a check for image index before the update
  board: Define set_dfu_alt_info() for boards with UEFI capsule update
    enabled
  capsule: kconfig: Select SET_DFU_ALT_INFO config symbol for capsule
    update
  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       |  44 +++++
 .../imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c   |  43 ++++
 board/emulation/common/qemu_dfu.c             |   6 +-
 board/emulation/qemu-arm/qemu-arm.c           |  20 ++
 board/kontron/pitx_imx8m/pitx_imx8m.c         |  40 +++-
 board/kontron/sl-mx8mm/sl-mx8mm.c             |  39 ++++
 board/kontron/sl28/sl28.c                     |  40 ++++
 board/sandbox/sandbox.c                       |  54 +++++
 board/socionext/developerbox/developerbox.c   |  52 +++++
 board/xilinx/common/board.c                   |  24 +++
 board/xilinx/zynq/board.c                     |   5 +-
 board/xilinx/zynqmp/zynqmp.c                  |   5 +-
 configs/sandbox64_defconfig                   |   1 -
 configs/sandbox_defconfig                     |   1 -
 configs/sandbox_flattree_defconfig            |   5 +
 doc/develop/uefi/uefi.rst                     |  22 ++-
 include/configs/imx8mm-cl-iot-gate.h          |  11 +-
 include/configs/imx8mp_rsb3720.h              |  11 +-
 include/configs/kontron-sl-mx8mm.h            |   7 +-
 include/configs/kontron_pitx_imx8m.h          |   7 +-
 include/configs/kontron_sl28.h                |   8 +-
 include/configs/qemu-arm.h                    |  10 +
 include/configs/sandbox.h                     |  14 ++
 include/configs/synquacer.h                   |  18 +-
 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                          |  21 ++
 lib/efi_loader/Kconfig                        |   2 +
 lib/efi_loader/efi_capsule.c                  |   8 +-
 lib/efi_loader/efi_firmware.c                 |  95 +++------
 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 +--
 37 files changed, 799 insertions(+), 248 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%)