On Mon, 16 Jun 2025 at 15:15, Padmarao Begari <padmarao.beg...@amd.com> wrote: > > FWU metadata information is unavailable for platform-specific > operations since FWU initialization has not yet occurred. > The initialization function is invoked as part of the main > loop event. To address this, the FWU platform hook function > is introduced during FWU initialization, allowing metadata > processing with platform-specific operations. > > Signed-off-by: Padmarao Begari <padmarao.beg...@amd.com> > --- > drivers/fwu-mdata/fwu-mdata-uclass.c | 17 +++++++++++++++ > drivers/fwu-mdata/raw_mtd.c | 6 ++++++ > include/fwu.h | 32 ++++++++++++++++++++++++++++ > lib/fwu_updates/fwu.c | 8 +++++++ > 4 files changed, 63 insertions(+) > > diff --git a/drivers/fwu-mdata/fwu-mdata-uclass.c > b/drivers/fwu-mdata/fwu-mdata-uclass.c > index 92abb94dcc9..f63ee234c87 100644 > --- a/drivers/fwu-mdata/fwu-mdata-uclass.c > +++ b/drivers/fwu-mdata/fwu-mdata-uclass.c > @@ -50,6 +50,23 @@ int fwu_write_mdata(struct udevice *dev, struct fwu_mdata > *mdata, bool primary, > return ops->write_mdata(dev, mdata, primary, size); > } > > +/** > + * fwu_platform_hook() - Wrapper around fwu_mdata_ops.platform_hook() > + * > + * Return: 0 if OK, -ve on error > + */ > +int fwu_platform_hook(struct udevice *dev, struct fwu_data *data) > +{ > + const struct fwu_mdata_ops *ops = device_get_ops(dev); > + > + if (!ops->platform_hook) { > + log_debug("platform_hook() method not defined\n"); > + return -ENOSYS; > + } > + > + return ops->platform_hook(dev, data); > +} > + > UCLASS_DRIVER(fwu_mdata) = { > .id = UCLASS_FWU_MDATA, > .name = "fwu-mdata", > diff --git a/drivers/fwu-mdata/raw_mtd.c b/drivers/fwu-mdata/raw_mtd.c > index 78a709f766c..f7542474632 100644 > --- a/drivers/fwu-mdata/raw_mtd.c > +++ b/drivers/fwu-mdata/raw_mtd.c > @@ -106,6 +106,11 @@ static int fwu_mtd_write_mdata(struct udevice *dev, > struct fwu_mdata *mdata, > return mtd_io_data(mtd, offs, size, mdata, FWU_MTD_WRITE); > } > > +__weak int fwu_mtd_platform_hook(struct udevice *dev, struct fwu_data *data) > +{ > + return 0; > +} > + > static int flash_partition_offset(struct udevice *dev, const char > *part_name, fdt_addr_t *offset) > { > ofnode node, parts_node; > @@ -272,6 +277,7 @@ static int fwu_mdata_mtd_probe(struct udevice *dev) > static struct fwu_mdata_ops fwu_mtd_ops = { > .read_mdata = fwu_mtd_read_mdata, > .write_mdata = fwu_mtd_write_mdata, > + .platform_hook = fwu_mtd_platform_hook, > };
Instead of doing this through the driver, it would be much easier to just defined a weak platform hook function, and then have the actual one in the platform specific code. We are not adding any value by going through the driver, as this is not a generic function. -sughosh > > static const struct udevice_id fwu_mdata_ids[] = { > diff --git a/include/fwu.h b/include/fwu.h > index 6441de370c9..65797190f3e 100644 > --- a/include/fwu.h > +++ b/include/fwu.h > @@ -77,6 +77,15 @@ struct fwu_mdata_ops { > */ > int (*write_mdata)(struct udevice *dev, struct fwu_mdata *mdata, > bool primary, uint32_t size); > + > + /** > + * platform_hook() - Hook the given FWU data copy > + * @dev: FWU metadata device > + * @data: Copy of the FWU metadata to hook > + * > + * Return: 0 if OK, -ve on error > + */ > + int (*platform_hook)(struct udevice *dev, struct fwu_data *data); > }; > > #define FWU_IMAGE_ACCEPTED 0x1 > @@ -129,6 +138,29 @@ int fwu_read_mdata(struct udevice *dev, struct fwu_mdata > *mdata, > int fwu_write_mdata(struct udevice *dev, struct fwu_mdata *mdata, > bool primary, uint32_t size); > > +/** > + * fwu_platform_hook() - Wrapper around fwu_mdata_ops.platform_hook() > + * @dev: FWU metadata device > + * @data: FWU metadata > + * > + * It is a platform-specific function that processes fwu metadata. > + * > + * Return: 0 if OK, -ve on error > + */ > +int fwu_platform_hook(struct udevice *dev, struct fwu_data *data); > + > +/** > + * fwu_mtd_platform_hook() - Hook the given FWU data copy > + * @dev: FWU metadata device > + * @data: FWU metadata > + > + * This function extracts the FWU metadata and prepares it for processing. > + * > + * Return: 0 if OK, -ve on error > + * > + */ > +int fwu_mtd_platform_hook(struct udevice *dev, struct fwu_data *data); > + > /** > * fwu_get_mdata() - Read, verify and return the FWU metadata > * > diff --git a/lib/fwu_updates/fwu.c b/lib/fwu_updates/fwu.c > index 7f085a0211f..47aa6fad1ab 100644 > --- a/lib/fwu_updates/fwu.c > +++ b/lib/fwu_updates/fwu.c > @@ -712,6 +712,7 @@ static int fwu_boottime_checks(void) > { > int ret; > u32 boot_idx, active_idx; > + struct fwu_data *data; > > ret = uclass_first_device_err(UCLASS_FWU_MDATA, &g_dev); > if (ret) { > @@ -770,6 +771,13 @@ static int fwu_boottime_checks(void) > if (!ret) > boottime_check = 1; > > + data = fwu_get_data(); > + ret = fwu_platform_hook(g_dev, data); > + if (ret && ret != -ENOSYS) { > + log_err("fwu_platform_hook() failed\n"); > + return ret; > + } > + > return 0; > } > EVENT_SPY_SIMPLE(EVT_MAIN_LOOP, fwu_boottime_checks); > -- > 2.25.1 >