[libubootenv,v2,0/8] Add the FWU metadata storage format

Message ID 20261113171737.470894-1-dario.binacchi@amarulasolutions.com
Headers
Series Add the FWU metadata storage format |

Message

Dario Binacchi Nov. 13, 2026, 5:17 p.m. UTC
This series lets libubootenv access the Arm FWU metadata through a
namespace, as discussed in [1]. An update agent can then switch the boot
bank with the existing API and tools, together with the U-Boot
environment.

- Patch 1 is a fix: filewrite() ignores the result of fsync().
- Patch 2 moves loading and storing behind callbacks selected by the
  format of the namespace. No functional change.
- Patch 3 adds an optional callback to validate a value before it is
  set. No functional change.
- Patch 4 adds the "fwu-mdata" format, versions 1 and 2. Only
  active_index, previous_active_index and bank<N>_state are exposed.
- Patch 5 documents it.
- Patches 6-8 add unit tests based on cmocka, as in SWUpdate, for both
  versions of the metadata.

The SWUpdate side follows in a separate series.

v1 was tested on the STM32MP257F-EV1 with TF-A and U-Boot, FWU metadata
version 2 with two banks: update of either bank from SWUpdate,
acceptance at boot, rollback by TF-A after failed trial boots. v2 was
tested on the same board, updating both banks from SWUpdate, and on the
host with the new unit tests.

Changes in v2:
- Clear the accepted flags of the images when a bank leaves the
  accepted state in version 2 too
- Convert the fields of the metadata, which are little endian
- Check the values when they are set, through a new callback (patch 3)
- Document the requirement for MTD and that version 1 does not support
  "invalid"
- Add unit tests (patches 6-8)

[1] https://groups.google.com/g/swupdate/c/kYr2Hy-f3us

Link to v1: https://groups.google.com/g/swupdate/c/_nJSCCjWETU

Dario Binacchi (8):
  uboot_env: report fsync errors when writing to a file
  uboot_env: access the storage through callbacks
  uboot_env: add a callback to validate a value before it is set
  add FWU metadata storage format
  docs: fw_env_config.md: document the FWU metadata format
  tests: add unit test infrastructure based on cmocka
  fwu_mdata: move the metadata structures to a private header
  tests: add unit tests for the FWU metadata format

 .gitlab-ci.yml         |   4 +-
 CMakeLists.txt         |   7 +
 docs/fw_env_config.md  |  65 ++++
 src/CMakeLists.txt     |   2 +
 src/extended_config.c  |  59 ++++
 src/fw_printenv.c      |   7 +-
 src/fwu_mdata.c        | 723 +++++++++++++++++++++++++++++++++++++++++
 src/fwu_mdata.h        |  60 ++++
 src/uboot_env.c        |  68 +++-
 src/uboot_private.h    |  41 ++-
 tests/CMakeLists.txt   |  19 ++
 tests/test_fwu_mdata.c | 637 +++++++++++++++++++++++++++++++++++
 12 files changed, 1679 insertions(+), 13 deletions(-)
 create mode 100644 src/fwu_mdata.c
 create mode 100644 src/fwu_mdata.h
 create mode 100644 tests/CMakeLists.txt
 create mode 100644 tests/test_fwu_mdata.c

-- 
2.43.0
  

Comments

Stefano Babic Nov. 13, 2026, 5:51 p.m. UTC | #1
Hi Dario,

many thabks !

I have applied all patches for both libubootenv and SWUpdate.

Regards,
Stefano

On 11/13/26 18:17, Dario Binacchi wrote:
> This series lets libubootenv access the Arm FWU metadata through a
> namespace, as discussed in [1]. An update agent can then switch the boot
> bank with the existing API and tools, together with the U-Boot
> environment.
> 
> - Patch 1 is a fix: filewrite() ignores the result of fsync().
> - Patch 2 moves loading and storing behind callbacks selected by the
>    format of the namespace. No functional change.
> - Patch 3 adds an optional callback to validate a value before it is
>    set. No functional change.
> - Patch 4 adds the "fwu-mdata" format, versions 1 and 2. Only
>    active_index, previous_active_index and bank<N>_state are exposed.
> - Patch 5 documents it.
> - Patches 6-8 add unit tests based on cmocka, as in SWUpdate, for both
>    versions of the metadata.
> 
> The SWUpdate side follows in a separate series.
> 
> v1 was tested on the STM32MP257F-EV1 with TF-A and U-Boot, FWU metadata
> version 2 with two banks: update of either bank from SWUpdate,
> acceptance at boot, rollback by TF-A after failed trial boots. v2 was
> tested on the same board, updating both banks from SWUpdate, and on the
> host with the new unit tests.
> 
> Changes in v2:
> - Clear the accepted flags of the images when a bank leaves the
>    accepted state in version 2 too
> - Convert the fields of the metadata, which are little endian
> - Check the values when they are set, through a new callback (patch 3)
> - Document the requirement for MTD and that version 1 does not support
>    "invalid"
> - Add unit tests (patches 6-8)
> 
> [1] https://groups.google.com/g/swupdate/c/kYr2Hy-f3us
> 
> Link to v1: https://groups.google.com/g/swupdate/c/_nJSCCjWETU
> 
> Dario Binacchi (8):
>    uboot_env: report fsync errors when writing to a file
>    uboot_env: access the storage through callbacks
>    uboot_env: add a callback to validate a value before it is set
>    add FWU metadata storage format
>    docs: fw_env_config.md: document the FWU metadata format
>    tests: add unit test infrastructure based on cmocka
>    fwu_mdata: move the metadata structures to a private header
>    tests: add unit tests for the FWU metadata format
> 
>   .gitlab-ci.yml         |   4 +-
>   CMakeLists.txt         |   7 +
>   docs/fw_env_config.md  |  65 ++++
>   src/CMakeLists.txt     |   2 +
>   src/extended_config.c  |  59 ++++
>   src/fw_printenv.c      |   7 +-
>   src/fwu_mdata.c        | 723 +++++++++++++++++++++++++++++++++++++++++
>   src/fwu_mdata.h        |  60 ++++
>   src/uboot_env.c        |  68 +++-
>   src/uboot_private.h    |  41 ++-
>   tests/CMakeLists.txt   |  19 ++
>   tests/test_fwu_mdata.c | 637 +++++++++++++++++++++++++++++++++++
>   12 files changed, 1679 insertions(+), 13 deletions(-)
>   create mode 100644 src/fwu_mdata.c
>   create mode 100644 src/fwu_mdata.h
>   create mode 100644 tests/CMakeLists.txt
>   create mode 100644 tests/test_fwu_mdata.c
>