diff mbox series

[RFC,05/10] FWU: stm32mp1: Add helper functions for accessing metadata

Message ID 20211125070146.2389-6-sughosh.ganu@linaro.org
State Superseded
Headers show
Series FWU: Add support for FWU Multi Bank Update feature | expand

Commit Message

Sughosh Ganu Nov. 25, 2021, 7:01 a.m. UTC
Add helper functions needed for accessing the metadata which contains
information on the updatable images. These functions have been added
for the STM32MP157C-DK2 board which has the updatable images on the
uSD card, formatted as GPT partitions.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
---
 board/st/stm32mp1/stm32mp1.c | 63 ++++++++++++++++++++++++++++++++++++
 include/fwu_metadata.h       |  3 ++
 2 files changed, 66 insertions(+)

Comments

Patrick Delaunay Dec. 7, 2021, 2:33 p.m. UTC | #1
Hi Sanghosh

On 11/25/21 8:01 AM, Sughosh Ganu wrote:
> Add helper functions needed for accessing the metadata which contains
> information on the updatable images. These functions have been added
> for the STM32MP157C-DK2 board which has the updatable images on the
> uSD card, formatted as GPT partitions.
>
> Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
> ---
>   board/st/stm32mp1/stm32mp1.c | 63 ++++++++++++++++++++++++++++++++++++
>   include/fwu_metadata.h       |  3 ++
>   2 files changed, 66 insertions(+)
>
> diff --git a/board/st/stm32mp1/stm32mp1.c b/board/st/stm32mp1/stm32mp1.c
> index 84592677e4..a6884d2772 100644
> --- a/board/st/stm32mp1/stm32mp1.c
> +++ b/board/st/stm32mp1/stm32mp1.c
> @@ -7,6 +7,7 @@
>   
>   #include <common.h>
>   #include <adc.h>
> +#include <blk.h>
>   #include <bootm.h>
>   #include <clk.h>
>   #include <config.h>
> @@ -14,6 +15,7 @@
>   #include <env.h>
>   #include <env_internal.h>
>   #include <fdt_support.h>
> +#include <fwu_metadata.h>
>   #include <g_dnl.h>
>   #include <generic-phy.h>
>   #include <hang.h>
> @@ -23,6 +25,7 @@
>   #include <log.h>
>   #include <malloc.h>
>   #include <misc.h>
> +#include <mmc.h>
>   #include <mtd_node.h>
>   #include <net.h>
>   #include <netdev.h>
> @@ -938,3 +941,63 @@ static void board_copro_image_process(ulong fw_image, size_t fw_size)
>   }
>   
>   U_BOOT_FIT_LOADABLE_HANDLER(IH_TYPE_COPRO, board_copro_image_process);
> +
> +#ifdef CONFIG_FWU_MULTI_BANK_UPDATE
> +
> +int fwu_plat_get_update_index(u32 *update_idx)
> +{
> +	int ret;
> +	u32 active_idx;
> +
> +	ret = fwu_get_active_index(&active_idx);
> +
> +	if (ret < 0)
> +		return -1;
> +
> +	*update_idx = active_idx ^= 0x1;
> +
> +	return ret;
> +}
> +
> +int fwu_plat_get_blk_desc(struct blk_desc **desc)
> +{
> +	int ret;
> +	struct mmc *mmc;
> +	struct udevice *dev;
> +
> +	/*
> +	 * Initial support is being added for the DK2
> +	 * platform
> +	 */
> +	if (CONFIG_IS_ENABLED(TARGET_ST_STM32MP15x) &&
> +	    (of_machine_is_compatible("st,stm32mp157c-dk2"))) {
> +		ret = uclass_get_device(UCLASS_MMC, 0, &dev);
> +		if (ret)
> +			return -1;
> +
> +		mmc = mmc_get_mmc_dev(dev);
> +		if (!mmc)
> +			return -1;
> +
> +		if (mmc_init(mmc))
> +			return -1;
> +
> +		*desc = mmc_get_blk_desc(mmc);
> +		if (!*desc)
> +			return -1;
> +	}
> +
> +	return 0;
> +}
> +
> +struct fwu_metadata_ops *get_plat_fwu_metadata_ops(void)
> +{
> +	if (CONFIG_IS_ENABLED(TARGET_ST_STM32MP15x) &&
> +	    (of_machine_is_compatible("st,stm32mp157c-dk2"))) {
> +		return &fwu_gpt_blk_ops;
> +	}
> +
> +	return NULL;
> +}
> +
> +#endif /* CONFIG_FWU_MULTI_BANK_UPDATE */
> diff --git a/include/fwu_metadata.h b/include/fwu_metadata.h
> index e692ef7506..6a5e814ab6 100644
> --- a/include/fwu_metadata.h
> +++ b/include/fwu_metadata.h
> @@ -122,4 +122,7 @@ int fwu_accept_image(efi_guid_t *img_type_id);
>   int fwu_clear_accept_image(efi_guid_t *img_type_id, u32 bank);
>   int fwu_get_metadata(struct fwu_metadata **metadata);
>   
> +int fwu_plat_get_update_index(u32 *update_idx);
> +int fwu_plat_get_blk_desc(struct blk_desc **desc);
> +
>   #endif /* _FWU_METADATA_H_ */


One general question:


How we can handle the EV1 board with 2 MMC devices => eMMC (mmc1) / 
SDCard (mmc0)

and how to managed HW partition of eMMC boot1 / boot2

=> for eMMC boot, the TF-A BL2 is located in these eMMC hw partition.


in the serie, I see only support for partition > 0 => partition in GPT 
but not the update of eMMC boot partition.


Regards

Patrick
Sughosh Ganu Dec. 8, 2021, 10:18 a.m. UTC | #2
hi Patrick,

On Tue, 7 Dec 2021 at 20:03, Patrick DELAUNAY <patrick.delaunay@foss.st.com>
wrote:

> Hi Sanghosh
>
> On 11/25/21 8:01 AM, Sughosh Ganu wrote:
> > Add helper functions needed for accessing the metadata which contains
> > information on the updatable images. These functions have been added
> > for the STM32MP157C-DK2 board which has the updatable images on the
> > uSD card, formatted as GPT partitions.
> >
> > Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
> > ---
> >   board/st/stm32mp1/stm32mp1.c | 63 ++++++++++++++++++++++++++++++++++++
> >   include/fwu_metadata.h       |  3 ++
> >   2 files changed, 66 insertions(+)
> >
> > diff --git a/board/st/stm32mp1/stm32mp1.c b/board/st/stm32mp1/stm32mp1.c
> > index 84592677e4..a6884d2772 100644
> > --- a/board/st/stm32mp1/stm32mp1.c
> > +++ b/board/st/stm32mp1/stm32mp1.c
> > @@ -7,6 +7,7 @@
> >
> >   #include <common.h>
> >   #include <adc.h>
> > +#include <blk.h>
> >   #include <bootm.h>
> >   #include <clk.h>
> >   #include <config.h>
> > @@ -14,6 +15,7 @@
> >   #include <env.h>
> >   #include <env_internal.h>
> >   #include <fdt_support.h>
> > +#include <fwu_metadata.h>
> >   #include <g_dnl.h>
> >   #include <generic-phy.h>
> >   #include <hang.h>
> > @@ -23,6 +25,7 @@
> >   #include <log.h>
> >   #include <malloc.h>
> >   #include <misc.h>
> > +#include <mmc.h>
> >   #include <mtd_node.h>
> >   #include <net.h>
> >   #include <netdev.h>
> > @@ -938,3 +941,63 @@ static void board_copro_image_process(ulong
> fw_image, size_t fw_size)
> >   }
> >
> >   U_BOOT_FIT_LOADABLE_HANDLER(IH_TYPE_COPRO, board_copro_image_process);
> > +
> > +#ifdef CONFIG_FWU_MULTI_BANK_UPDATE
> > +
> > +int fwu_plat_get_update_index(u32 *update_idx)
> > +{
> > +     int ret;
> > +     u32 active_idx;
> > +
> > +     ret = fwu_get_active_index(&active_idx);
> > +
> > +     if (ret < 0)
> > +             return -1;
> > +
> > +     *update_idx = active_idx ^= 0x1;
> > +
> > +     return ret;
> > +}
> > +
> > +int fwu_plat_get_blk_desc(struct blk_desc **desc)
> > +{
> > +     int ret;
> > +     struct mmc *mmc;
> > +     struct udevice *dev;
> > +
> > +     /*
> > +      * Initial support is being added for the DK2
> > +      * platform
> > +      */
> > +     if (CONFIG_IS_ENABLED(TARGET_ST_STM32MP15x) &&
> > +         (of_machine_is_compatible("st,stm32mp157c-dk2"))) {
> > +             ret = uclass_get_device(UCLASS_MMC, 0, &dev);
> > +             if (ret)
> > +                     return -1;
> > +
> > +             mmc = mmc_get_mmc_dev(dev);
> > +             if (!mmc)
> > +                     return -1;
> > +
> > +             if (mmc_init(mmc))
> > +                     return -1;
> > +
> > +             *desc = mmc_get_blk_desc(mmc);
> > +             if (!*desc)
> > +                     return -1;
> > +     }
> > +
> > +     return 0;
> > +}
> > +
> > +struct fwu_metadata_ops *get_plat_fwu_metadata_ops(void)
> > +{
> > +     if (CONFIG_IS_ENABLED(TARGET_ST_STM32MP15x) &&
> > +         (of_machine_is_compatible("st,stm32mp157c-dk2"))) {
> > +             return &fwu_gpt_blk_ops;
> > +     }
> > +
> > +     return NULL;
> > +}
> > +
> > +#endif /* CONFIG_FWU_MULTI_BANK_UPDATE */
> > diff --git a/include/fwu_metadata.h b/include/fwu_metadata.h
> > index e692ef7506..6a5e814ab6 100644
> > --- a/include/fwu_metadata.h
> > +++ b/include/fwu_metadata.h
> > @@ -122,4 +122,7 @@ int fwu_accept_image(efi_guid_t *img_type_id);
> >   int fwu_clear_accept_image(efi_guid_t *img_type_id, u32 bank);
> >   int fwu_get_metadata(struct fwu_metadata **metadata);
> >
> > +int fwu_plat_get_update_index(u32 *update_idx);
> > +int fwu_plat_get_blk_desc(struct blk_desc **desc);
> > +
> >   #endif /* _FWU_METADATA_H_ */
>
>
> One general question:
>
>
> How we can handle the EV1 board with 2 MMC devices => eMMC (mmc1) /
> SDCard (mmc0)
>

The current metadata structure has a location_uuid, which can be used to
identify the device which will contain the banks of firmware images. The
current code for DK2 board does not have this implemented, but adding this
logic should not be difficult. Based on the location_uuid, we can identify
the device and return the blk_desc of that device.


>
> and how to managed HW partition of eMMC boot1 / boot2
>
> => for eMMC boot, the TF-A BL2 is located in these eMMC hw partition.
>
>
> in the serie, I see only support for partition > 0 => partition in GPT
> but not the update of eMMC boot partition.
>

I will get back to you on this. The current specification is dealing with
GPT formatted devices. Need to check how the boot partitions will be
supported for multiple banks of images.

 -sughosh


>
> Regards
>
> Patrick
>
>
diff mbox series

Patch

diff --git a/board/st/stm32mp1/stm32mp1.c b/board/st/stm32mp1/stm32mp1.c
index 84592677e4..a6884d2772 100644
--- a/board/st/stm32mp1/stm32mp1.c
+++ b/board/st/stm32mp1/stm32mp1.c
@@ -7,6 +7,7 @@ 
 
 #include <common.h>
 #include <adc.h>
+#include <blk.h>
 #include <bootm.h>
 #include <clk.h>
 #include <config.h>
@@ -14,6 +15,7 @@ 
 #include <env.h>
 #include <env_internal.h>
 #include <fdt_support.h>
+#include <fwu_metadata.h>
 #include <g_dnl.h>
 #include <generic-phy.h>
 #include <hang.h>
@@ -23,6 +25,7 @@ 
 #include <log.h>
 #include <malloc.h>
 #include <misc.h>
+#include <mmc.h>
 #include <mtd_node.h>
 #include <net.h>
 #include <netdev.h>
@@ -938,3 +941,63 @@  static void board_copro_image_process(ulong fw_image, size_t fw_size)
 }
 
 U_BOOT_FIT_LOADABLE_HANDLER(IH_TYPE_COPRO, board_copro_image_process);
+
+#ifdef CONFIG_FWU_MULTI_BANK_UPDATE
+
+int fwu_plat_get_update_index(u32 *update_idx)
+{
+	int ret;
+	u32 active_idx;
+
+	ret = fwu_get_active_index(&active_idx);
+
+	if (ret < 0)
+		return -1;
+
+	*update_idx = active_idx ^= 0x1;
+
+	return ret;
+}
+
+int fwu_plat_get_blk_desc(struct blk_desc **desc)
+{
+	int ret;
+	struct mmc *mmc;
+	struct udevice *dev;
+
+	/*
+	 * Initial support is being added for the DK2
+	 * platform
+	 */
+	if (CONFIG_IS_ENABLED(TARGET_ST_STM32MP15x) &&
+	    (of_machine_is_compatible("st,stm32mp157c-dk2"))) {
+		ret = uclass_get_device(UCLASS_MMC, 0, &dev);
+		if (ret)
+			return -1;
+
+		mmc = mmc_get_mmc_dev(dev);
+		if (!mmc)
+			return -1;
+
+		if (mmc_init(mmc))
+			return -1;
+
+		*desc = mmc_get_blk_desc(mmc);
+		if (!*desc)
+			return -1;
+	}
+
+	return 0;
+}
+
+struct fwu_metadata_ops *get_plat_fwu_metadata_ops(void)
+{
+	if (CONFIG_IS_ENABLED(TARGET_ST_STM32MP15x) &&
+	    (of_machine_is_compatible("st,stm32mp157c-dk2"))) {
+		return &fwu_gpt_blk_ops;
+	}
+
+	return NULL;
+}
+
+#endif /* CONFIG_FWU_MULTI_BANK_UPDATE */
diff --git a/include/fwu_metadata.h b/include/fwu_metadata.h
index e692ef7506..6a5e814ab6 100644
--- a/include/fwu_metadata.h
+++ b/include/fwu_metadata.h
@@ -122,4 +122,7 @@  int fwu_accept_image(efi_guid_t *img_type_id);
 int fwu_clear_accept_image(efi_guid_t *img_type_id, u32 bank);
 int fwu_get_metadata(struct fwu_metadata **metadata);
 
+int fwu_plat_get_update_index(u32 *update_idx);
+int fwu_plat_get_blk_desc(struct blk_desc **desc);
+
 #endif /* _FWU_METADATA_H_ */