Re: [PATCHv2 2/5] FWU: mtd: Add helper functions for accessing FWU metadata

Ilias Apalodimas
2022-10-14T07:10:29Z

Hi Sughosh, Jassi
On Sun, Oct 02, 2022 at 06:51:45PM -0500, jassisinghbrar@gmail.com wrote:
> From: Sughosh Ganu <sughosh.ganu@linaro.org>
>
> Add helper functions needed for accessing the FWU metadata which
> contains information on the updatable images.
>
> Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
> Signed-off-by: Jassi Brar <jaswinder.singh@linaro.org>
> ---
> include/fwu.h | 27 ++++++
> lib/fwu_updates/Makefile | 1 +
> lib/fwu_updates/fwu_mtd.c | 178 ++++++++++++++++++++++++++++++++++++++
> 3 files changed, 206 insertions(+)
> create mode 100644 lib/fwu_updates/fwu_mtd.c
>
> diff --git a/include/fwu.h b/include/fwu.h
> index b5c59dc161..48c83f7618 100644
> --- a/include/fwu.h
> +++ b/include/fwu.h
> @@ -8,6 +8,7 @@
>
> #include <blk.h>
> #include <efi.h>
> +#include <mtd.h>
>
> #include <linux/types.h>
>
> @@ -296,4 +297,30 @@ u8 fwu_update_checks_pass(void);
> */
> int fwu_trial_state_ctr_start(void);
>
> +/**

[..]

> +#include <dm/ofnode.h>
> +
> +int fwu_mtd_get_alt_num(efi_guid_t *image_id, u8 *alt_num,
> + const char *mtd_dev)
> +{
> + int i, nalt;
> + int ret = -1;
> + struct mtd_info *mtd;
> + struct dfu_entity *dfu;
> + ofnode node, parts_node;
> + fdt_addr_t offset, size;
> + char uuidbuf[UUID_STR_LEN + 1];
> +
> + mtd_probe_devices();
> + mtd = get_mtd_device_nm(mtd_dev);
> +
> + /* Find partition node under given MTD device. */
> + parts_node = ofnode_by_compatible(mtd_get_ofnode(mtd),
> + "fixed-partitions");
> +
> + uuid_bin_to_str(image_id->b, uuidbuf, UUID_STR_FORMAT_STD);
> + node = ofnode_by_prop_value(parts_node, "uuid", uuidbuf,
> + sizeof(uuidbuf));
> + if (!ofnode_valid(node)) {
> + log_warning("Warning: Failed to find partition by image UUID\n");
> + return -ENOENT;
> + }
> +
> + offset = ofnode_get_addr_size_index_notrans(node, 0, &size);
> + if (offset == FDT_ADDR_T_NONE || !size)
> + return -ENOENT;
> +
> + dfu_init_env_entities(NULL, NULL);
> +
> + nalt = 0;
> + list_for_each_entry(dfu, &dfu_list, list)
> + nalt++;

Sughosh we need to update this and follow similar logic to the GPT patches,
where nalt goes away and this is converted to a while (true) loop
> +
> + if (!nalt) {
> + log_warning("No entities in dfu_alt_info\n");
> + dfu_free_entities();
> + return -ENOENT;
> + }
> +
> + for (i = 0; i < nalt; i++) {
> + dfu = dfu_get_entity(i);
> +
> + /* Only MTD RAW access */
> + if (!dfu || dfu->dev_type != DFU_DEV_MTD ||
> + dfu->layout != DFU_RAW_ADDR ||
> + dfu->data.mtd.start != offset ||
> + dfu->data.mtd.size != size)
> + continue;

This needs to be rebased as well and that code needs to be added in that
new function you created

> +
> + *alt_num = dfu->alt;
> + ret = 0;
> + break;
> + }
> +
> + dfu_free_entities();
> +
> + return ret;
> +}
> +
> +static int gen_image_alt_info(char *buf, size_t len, int sidx,
> + struct fwu_image_entry *img, struct mtd_info *mtd)
> +{
> + int i;
> + const char *suuid;

[...]

Thanks
/Ilias