[PATCH v4 02/11] FWU: Add FWU metadata access driver for GPT partitioned block devices

Masami Hiramatsu masami.hiramatsu at linaro.org
Wed Feb 9 05:56:36 CET 2022


Hi Sughosh,

While porting mdata-sf driver, I'm confusing on the devicetree
usage.

2022年2月8日(火) 3:21 Sughosh Ganu <sughosh.ganu at linaro.org>:

> +int fwu_get_mdata_device(struct udevice **mdata_dev)
> +{
> +       u32 phandle;
> +       int ret, size;
> +       struct udevice *dev, *child;
> +       ofnode fwu_mdata_node;
> +       const fdt32_t *phandle_p = NULL;
> +
> +       fwu_mdata_node = ofnode_path("/fwu-mdata");
> +       if (!ofnode_valid(fwu_mdata_node)) {
> +               log_err("fwu-node not found\n");
> +               return -ENOENT;
> +       }

So this seems to get the udevice from path, but I think fwu-mdata node
has "u-boot,fwu-mdata" compatible property, in that case probe function
already gets the node. Why would you search it again by path?

> +
> +       phandle_p = ofnode_get_property(fwu_mdata_node, "fwu-mdata-store",
> +                                       &size);
> +       if (!phandle_p) {
> +               log_err("fwu-mdata-store property not found\n");
> +               return -ENOENT;
> +       }
> +
> +       phandle = fdt32_to_cpu(*phandle_p);
> +
> +       ret = device_get_global_by_ofnode(ofnode_get_by_phandle(phandle),
> +                                         &dev);
> +       if (ret)
> +               return ret;
> +
> +       ret = -ENODEV;
> +       for (device_find_first_child(dev, &child); child;
> +            device_find_next_child(&child)) {
> +               if (device_get_uclass_id(child) == UCLASS_BLK) {
> +                       *mdata_dev = child;

I thought that the blk device node directly passed by the
"fwu-mdata-store" property. Would we need to search it from
children nodes?

BTW, if we can use the devicetree, can we define the number of banks
and the number of images can be described too?
Of course as I said in the other thread, I would like to put the
dfu_alt_info like information in the devicetree too.
(But it maybe different from this discussion)

Thank you,


> +                       ret = 0;
> +               }
> +       }
> +
> +       return ret;
> +}
> +
> +static int fwu_mdata_gpt_blk_probe(struct udevice *dev)
> +{
> +       int ret;
> +       struct udevice *mdata_dev = NULL;
> +
> +       ret = fwu_get_mdata_device(&mdata_dev);
> +       if (ret)
> +               return ret;
> +
> +       dev_set_priv(dev, mdata_dev);
> +
> +       return 0;
> +}
> +
> +static const struct fwu_mdata_ops fwu_gpt_blk_ops = {
> +       .get_image_alt_num = fwu_gpt_get_image_alt_num,
> +       .mdata_check = fwu_gpt_mdata_check,
> +       .get_mdata = fwu_gpt_get_mdata,
> +       .update_mdata = fwu_gpt_update_mdata,
> +};
> +
> +static const struct udevice_id fwu_mdata_ids[] = {
> +       { .compatible = "u-boot,fwu-mdata" },

> +       { }
> +};
> +
> +U_BOOT_DRIVER(fwu_mdata_gpt_blk) = {
> +       .name           = "fwu-mdata-gpt-blk",
> +       .id             = UCLASS_FWU_MDATA,
> +       .of_match       = fwu_mdata_ids,
> +       .ops            = &fwu_gpt_blk_ops,
> +       .probe          = fwu_mdata_gpt_blk_probe,
> +};
> diff --git a/include/fwu.h b/include/fwu.h
> index 5a99c579fc..2c7db2dff9 100644
> --- a/include/fwu.h
> +++ b/include/fwu.h
> @@ -43,6 +43,8 @@ int fwu_get_active_index(u32 *active_idx);
>  int fwu_update_active_index(u32 active_idx);
>  int fwu_get_image_alt_num(efi_guid_t image_type_id, u32 update_bank,
>                           int *alt_num);
> +int fwu_get_mdata_device(struct udevice **mdata_dev);
> +int fwu_verify_mdata(struct fwu_mdata *mdata, bool pri_part);
>  int fwu_mdata_check(void);
>  int fwu_revert_boot_index(void);
>  int fwu_accept_image(efi_guid_t *img_type_id, u32 bank);
> --
> 2.17.1
>


--
Masami Hiramatsu


More information about the U-Boot mailing list