[RFC PATCH 04/10] FWU: Add metadata access functions for GPT partitioned block devices

Jason Liu jason.hui.liu at nxp.com
Thu Dec 9 10:35:53 CET 2021



> -----Original Message-----
> From: Sughosh Ganu <sughosh.ganu at linaro.org>
> Sent: 2021年11月25日 15:02
> To: u-boot at lists.denx.de
> Cc: Patrick Delaunay <patrick.delaunay at foss.st.com>; Patrice Chotard
> <patrice.chotard at foss.st.com>; Heinrich Schuchardt <xypron.glpk at gmx.de>;
> Alexander Graf <agraf at csgraf.de>; Simon Glass <sjg at chromium.org>; Bin
> Meng <bmeng.cn at gmail.com>; Peng Fan <peng.fan at nxp.com>; AKASHI
> Takahiro <takahiro.akashi at linaro.org>; Ilias Apalodimas
> <ilias.apalodimas at linaro.org>; Jose Marinho <jose.marinho at arm.com>; Grant
> Likely <grant.likely at arm.com>; Jason Liu <jason.hui.liu at nxp.com>; Sughosh
> Ganu <sughosh.ganu at linaro.org>
> Subject: [RFC PATCH 04/10] FWU: Add metadata access functions for GPT
> partitioned block devices
> 
> In the FWU Multi Bank Update feature, the information about the updatable
> images is stored as part of the metadata, on a separate partition. Add
> functions for reading from and writing to the metadata when the updatable
> images and the metadata are stored on a block device which is formated
with
> GPT based partition scheme.
> 
> Signed-off-by: Sughosh Ganu <sughosh.ganu at linaro.org>
> ---
>  lib/fwu_updates/fwu_metadata_gpt_blk.c | 716
> +++++++++++++++++++++++++
>  1 file changed, 716 insertions(+)
>  create mode 100644 lib/fwu_updates/fwu_metadata_gpt_blk.c
> 
> diff --git a/lib/fwu_updates/fwu_metadata_gpt_blk.c
> b/lib/fwu_updates/fwu_metadata_gpt_blk.c
> new file mode 100644
> index 0000000000..98cc53f706
> --- /dev/null
> +++ b/lib/fwu_updates/fwu_metadata_gpt_blk.c
> @@ -0,0 +1,716 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Copyright (c) 2021, Linaro Limited
> + */
> +
> +#include <blk.h>
> +#include <efi_loader.h>
> +#include <fwu_metadata.h>
> +#include <malloc.h>
> +#include <memalign.h>
> +#include <part.h>
> +#include <part_efi.h>
> +
> +#include <linux/errno.h>
> +#include <linux/types.h>
> +#include <u-boot/crc.h>
> +
> +#define PRIMARY_VALID		0x1
> +#define SECONDARY_VALID		0x2
> +
> +#define MDATA_READ		(u8)0x1
> +#define MDATA_WRITE		(u8)0x2
> +
> +#define IMAGE_ACCEPT_SET	(u8)0x1
> +#define IMAGE_ACCEPT_CLEAR	(u8)0x2

Better to define as the followings:

#define MDATA_READ		((u8)0x1)
#define MDATA_WRITE		((u8)0x2)

#define IMAGE_ACCEPT_SET	((u8)0x1)
#define IMAGE_ACCEPT_CLEAR	((u8)0x2)

> +
> +static int gpt_verify_metadata(struct fwu_metadata *metadata, bool
> +pri_part) {
> +	u32 calc_crc32;
> +	void *buf;
> +
> +	buf = &metadata->version;
> +	calc_crc32 = crc32(0, buf, sizeof(*metadata) - sizeof(u32));
> +
> +	if (calc_crc32 != metadata->crc32) {
> +		log_err("crc32 check failed for %s metadata partition\n",
> +			pri_part ? "primary" : "secondary");
> +		return -1;
> +	}
> +
> +	return 0;
> +}
> +
> +static int gpt_get_metadata_partitions(struct blk_desc *desc,
> +				       u32 *primary_mpart,
> +				       u32 *secondary_mpart)
> +{
> +	int i, ret;
> +	u32 nparts, mparts;
> +	gpt_entry *gpt_pte = NULL;
> +	const efi_guid_t fwu_metadata_guid = FWU_METADATA_GUID;
> +
> +	ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1,
> +				     desc->blksz);
> +
> +	ret = get_gpt_hdr_parts(desc, gpt_head, &gpt_pte);
> +	if (ret < 0) {
> +		log_err("Error getting GPT header and partitions\n");
> +		ret = -EIO;
> +		goto out;
> +	}
> +
> +	nparts = gpt_head->num_partition_entries;
> +	for (i = 0, mparts = 0; i < nparts; i++) {
> +		if (!guidcmp(&fwu_metadata_guid,
> +			     &gpt_pte[i].partition_type_guid)) {
> +			++mparts;
> +			if (!*primary_mpart)
> +				*primary_mpart = i + 1;
> +			else
> +				*secondary_mpart = i + 1;
> +		}
> +	}
> +
> +	if (mparts != 2) {
> +		log_err("Expect two copies of the metadata instead of %d\n",
> +			mparts);
> +		ret = -EINVAL;
> +	} else {
> +		ret = 0;
> +	}
> +out:
> +	free(gpt_pte);
> +
> +	return ret;
> +}
> +
> +static int gpt_get_metadata_disk_part(struct blk_desc *desc,
> +				      struct disk_partition *info,
> +				      u32 part_num)
> +{
> +	int ret;
> +	char *metadata_guid_str = "8a7a84a0-8387-40f6-ab41-a8b9a5a60d23";

Is this hard-code guid_string intentioned?

> +
> +	ret = part_get_info(desc, part_num, info);

Jason Liu
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 9583 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20211209/7498f28a/attachment.bin>


More information about the U-Boot mailing list