summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKory Maincent <[email protected]>2026-02-23 14:18:40 +0100
committerIlias Apalodimas <[email protected]>2026-03-26 08:20:00 +0200
commit44a1e17b2a49d724538b4d500b27b0eda4be015c (patch)
tree682cac2b82f842e3457efaae9b1daefbe20ca581
parent02673659e81391729792ebc1b816d974de3c9abf (diff)
tools: mkfwumdata: Remove dependency on fwu_mdata.h header
The dependency on fwu_mdata.h creates unnecessary configuration requirements. To generate metadata V1, CONFIG_FWU_MDATA_V1 must be enabled, which in turn requires enabling FWU_MULTI_BANK_UPDATE, EFI_CAPSULE_ON_DISK, PARTITION_TYPE_GUID, and other unrelated configs. This is not suitable for a simple standalone tool. Additionally, even with the "-v 1" option to generate V1 metadata, the tool will still include the firmware store description if CONFIG_FWU_MDATA_V1 is not enabled. This structure should only be present in metadata V2. Replace the fwu_mdata.h dependency with the new fwumdata header to make the tool compatible with both V1 and V2 without requiring any defconfig changes. This also uses the access helper functions from the header to eliminate code duplication. Acked-by: Sughosh Ganu <[email protected]> Tested-by: Sughosh Ganu <[email protected]> Signed-off-by: Kory Maincent <[email protected]> Tested-by: Dario Binacchi <[email protected]> Signed-off-by: Ilias Apalodimas <[email protected]>
-rw-r--r--tools/fwumdata_src/mkfwumdata.c96
1 files changed, 17 insertions, 79 deletions
diff --git a/tools/fwumdata_src/mkfwumdata.c b/tools/fwumdata_src/mkfwumdata.c
index 8b25539fd57..b8b60473b91 100644
--- a/tools/fwumdata_src/mkfwumdata.c
+++ b/tools/fwumdata_src/mkfwumdata.c
@@ -17,26 +17,7 @@
#include <u-boot/crc.h>
#include <uuid/uuid.h>
-typedef uint8_t u8;
-typedef int16_t s16;
-typedef uint16_t u16;
-typedef uint32_t u32;
-typedef uint64_t u64;
-
-#undef CONFIG_FWU_NUM_BANKS
-#undef CONFIG_FWU_NUM_IMAGES_PER_BANK
-
-/* This will dynamically allocate the fwu_mdata */
-#define CONFIG_FWU_NUM_BANKS 0
-#define CONFIG_FWU_NUM_IMAGES_PER_BANK 0
-
-/* version 2 supports maximum of 4 banks */
-#define MAX_BANKS_V2 4
-
-#define BANK_INVALID (u8)0xFF
-#define BANK_ACCEPTED (u8)0xFC
-
-#include <fwu_mdata.h>
+#include "fwumdata.h"
static const char *opts_short = "b:i:a:p:v:V:gh";
@@ -116,6 +97,7 @@ static struct fwu_mdata_object *fwu_alloc_mdata(size_t images, size_t banks,
sizeof(struct fwu_image_bank_info) * banks) * images;
} else {
mobj->size = sizeof(struct fwu_mdata) +
+ sizeof(struct fwu_mdata_ext) +
sizeof(struct fwu_fw_store_desc) +
(sizeof(struct fwu_image_entry) +
sizeof(struct fwu_image_bank_info) * banks) * images;
@@ -146,50 +128,6 @@ alloc_err:
return NULL;
}
-static struct fwu_image_entry *
-fwu_get_image(struct fwu_mdata_object *mobj, size_t idx)
-{
- size_t offset;
-
- if (mobj->version == 1) {
- offset = sizeof(struct fwu_mdata) +
- (sizeof(struct fwu_image_entry) +
- sizeof(struct fwu_image_bank_info) * mobj->banks) *
- idx;
- } else {
- offset = sizeof(struct fwu_mdata) +
- sizeof(struct fwu_fw_store_desc) +
- (sizeof(struct fwu_image_entry) +
- sizeof(struct fwu_image_bank_info) * mobj->banks) *
- idx;
- }
-
- return (struct fwu_image_entry *)((char *)mobj->mdata + offset);
-}
-
-static struct fwu_image_bank_info *
-fwu_get_bank(struct fwu_mdata_object *mobj, size_t img_idx, size_t bnk_idx)
-{
- size_t offset;
-
- if (mobj->version == 1) {
- offset = sizeof(struct fwu_mdata) +
- (sizeof(struct fwu_image_entry) +
- sizeof(struct fwu_image_bank_info) * mobj->banks) *
- img_idx + sizeof(struct fwu_image_entry) +
- sizeof(struct fwu_image_bank_info) * bnk_idx;
- } else {
- offset = sizeof(struct fwu_mdata) +
- sizeof(struct fwu_fw_store_desc) +
- (sizeof(struct fwu_image_entry) +
- sizeof(struct fwu_image_bank_info) * mobj->banks) *
- img_idx + sizeof(struct fwu_image_entry) +
- sizeof(struct fwu_image_bank_info) * bnk_idx;
- }
-
- return (struct fwu_image_bank_info *)((char *)mobj->mdata + offset);
-}
-
/**
* convert_uuid_to_guid() - convert UUID to GUID
* @buf: UUID binary
@@ -239,11 +177,13 @@ static int
fwu_parse_fill_image_uuid(struct fwu_mdata_object *mobj,
size_t idx, char *uuids)
{
- struct fwu_image_entry *image = fwu_get_image(mobj, idx);
struct fwu_image_bank_info *bank;
+ struct fwu_image_entry *image;
char *p = uuids, *uuid;
int i;
+ image = fwu_get_image_entry(mobj->mdata, mobj->version,
+ mobj->banks, idx);
if (!image)
return -ENOENT;
@@ -266,7 +206,8 @@ fwu_parse_fill_image_uuid(struct fwu_mdata_object *mobj,
/* Fill bank image-UUID */
for (i = 0; i < mobj->banks; i++) {
- bank = fwu_get_bank(mobj, idx, i);
+ bank = fwu_get_bank_info(mobj->mdata, mobj->version,
+ mobj->banks, idx, i);
if (!bank)
return -ENOENT;
bank->accepted = 1;
@@ -281,25 +222,22 @@ fwu_parse_fill_image_uuid(struct fwu_mdata_object *mobj,
return 0;
}
-#if defined(CONFIG_FWU_MDATA_V1)
-static void fwu_fill_version_specific_mdata(struct fwu_mdata_object *mobj)
-{
-}
-#else
static void fwu_fill_version_specific_mdata(struct fwu_mdata_object *mobj)
{
int i;
struct fwu_fw_store_desc *fw_desc;
- struct fwu_mdata *mdata = mobj->mdata;
+ struct fwu_mdata_ext *mdata_ext;
- mdata->metadata_size = mobj->size;
- mdata->desc_offset = sizeof(struct fwu_mdata);
+ mdata_ext = fwu_get_fw_mdata_ext(mobj->mdata);
+ mdata_ext->metadata_size = mobj->size;
+ mdata_ext->desc_offset = sizeof(struct fwu_mdata) +
+ sizeof(struct fwu_mdata_ext);
for (i = 0; i < MAX_BANKS_V2; i++)
- mdata->bank_state[i] = i < mobj->banks ?
- BANK_ACCEPTED : BANK_INVALID;
+ mdata_ext->bank_state[i] = i < mobj->banks ?
+ FWU_BANK_ACCEPTED : FWU_BANK_INVALID;
- fw_desc = (struct fwu_fw_store_desc *)((u8 *)mdata + sizeof(*mdata));
+ fw_desc = fwu_get_fw_desc(mobj->mdata);
fw_desc->num_banks = mobj->banks;
fw_desc->num_images = mobj->images;
fw_desc->img_entry_size = sizeof(struct fwu_image_entry) +
@@ -307,7 +245,6 @@ static void fwu_fill_version_specific_mdata(struct fwu_mdata_object *mobj)
fw_desc->bank_info_entry_size =
sizeof(struct fwu_image_bank_info);
}
-#endif /* CONFIG_FWU_MDATA_V1 */
/* Caller must ensure that @uuids[] has @mobj->images entries. */
static int fwu_parse_fill_uuids(struct fwu_mdata_object *mobj, char *uuids[])
@@ -320,7 +257,8 @@ static int fwu_parse_fill_uuids(struct fwu_mdata_object *mobj, char *uuids[])
mdata->active_index = active_bank;
mdata->previous_active_index = previous_bank;
- fwu_fill_version_specific_mdata(mobj);
+ if (mdata->version == 2)
+ fwu_fill_version_specific_mdata(mobj);
for (i = 0; i < mobj->images; i++) {
ret = fwu_parse_fill_image_uuid(mobj, i, uuids[i]);