diff mbox series

[RFC,02/10] stm32mp: dfu: Move the ram partitions to the end of the dfu_alt_info variable

Message ID 20211125070146.2389-3-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
With the FWU multi bank update feature enabled, the dfu alt no that is
used to identify the partition to be updated is derived at runtime and
should match the partition number on the storage media. Achieve this
by moving the ram partitions to the end of the dfu_alt_info variable.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
---
 board/st/common/stm32mp_dfu.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

Comments

Etienne Carriere Dec. 8, 2021, 1:13 p.m. UTC | #1
On Thu, 25 Nov 2021 at 08:03, Sughosh Ganu <sughosh.ganu@linaro.org> wrote:
>
> With the FWU multi bank update feature enabled, the dfu alt no that is
> used to identify the partition to be updated is derived at runtime and
> should match the partition number on the storage media. Achieve this
> by moving the ram partitions to the end of the dfu_alt_info variable.
>
> Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
> ---
>  board/st/common/stm32mp_dfu.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/board/st/common/stm32mp_dfu.c b/board/st/common/stm32mp_dfu.c
> index 00d1fb8f59..394a2704ee 100644
> --- a/board/st/common/stm32mp_dfu.c
> +++ b/board/st/common/stm32mp_dfu.c
> @@ -102,6 +102,7 @@ static void board_get_alt_info_mtd(struct mtd_info *mtd, char *buf)
>
>  void set_dfu_alt_info(char *interface, char *devstr)
>  {
> +       int len;
>         struct udevice *dev;
>         struct mtd_info *mtd;
>
> @@ -112,9 +113,6 @@ void set_dfu_alt_info(char *interface, char *devstr)
>
>         memset(buf, 0, sizeof(buf));
>
> -       snprintf(buf, DFU_ALT_BUF_LEN,
> -                "ram 0=%s", CONFIG_DFU_ALT_RAM0);
> -
>         if (CONFIG_IS_ENABLED(MMC)) {
>                 if (!uclass_get_device(UCLASS_MMC, 0, &dev))
>                         board_get_alt_info_mmc(dev, buf);
> @@ -151,6 +149,13 @@ void set_dfu_alt_info(char *interface, char *devstr)
>                         strncat(buf, "&virt 1=PMIC", DFU_ALT_BUF_LEN);
>         }
>
> +       len = strlen(buf);
> +       if (buf[0] != '\0')
> +               len += snprintf(buf + len, DFU_ALT_BUF_LEN - len, "&");
> +
> +       snprintf(buf + len, DFU_ALT_BUF_LEN,
> +                "ram 0=%s", CONFIG_DFU_ALT_RAM0);

s/DFU_ALT_BUF_LEN/DFU_ALT_BUF_LEN - len/

Should check snprintf() return value.

> +
>         env_set("dfu_alt_info", buf);
>         puts("DFU alt info setting: done\n");
>  }
> --
> 2.17.1
>
Sughosh Ganu Dec. 9, 2021, 9:04 a.m. UTC | #2
hi Etienne,

On Wed, 8 Dec 2021 at 18:44, Etienne Carriere <etienne.carriere@linaro.org>
wrote:

> On Thu, 25 Nov 2021 at 08:03, Sughosh Ganu <sughosh.ganu@linaro.org>
> wrote:
> >
> > With the FWU multi bank update feature enabled, the dfu alt no that is
> > used to identify the partition to be updated is derived at runtime and
> > should match the partition number on the storage media. Achieve this
> > by moving the ram partitions to the end of the dfu_alt_info variable.
> >
> > Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
> > ---
> >  board/st/common/stm32mp_dfu.c | 11 ++++++++---
> >  1 file changed, 8 insertions(+), 3 deletions(-)
> >
> > diff --git a/board/st/common/stm32mp_dfu.c
> b/board/st/common/stm32mp_dfu.c
> > index 00d1fb8f59..394a2704ee 100644
> > --- a/board/st/common/stm32mp_dfu.c
> > +++ b/board/st/common/stm32mp_dfu.c
> > @@ -102,6 +102,7 @@ static void board_get_alt_info_mtd(struct mtd_info
> *mtd, char *buf)
> >
> >  void set_dfu_alt_info(char *interface, char *devstr)
> >  {
> > +       int len;
> >         struct udevice *dev;
> >         struct mtd_info *mtd;
> >
> > @@ -112,9 +113,6 @@ void set_dfu_alt_info(char *interface, char *devstr)
> >
> >         memset(buf, 0, sizeof(buf));
> >
> > -       snprintf(buf, DFU_ALT_BUF_LEN,
> > -                "ram 0=%s", CONFIG_DFU_ALT_RAM0);
> > -
> >         if (CONFIG_IS_ENABLED(MMC)) {
> >                 if (!uclass_get_device(UCLASS_MMC, 0, &dev))
> >                         board_get_alt_info_mmc(dev, buf);
> > @@ -151,6 +149,13 @@ void set_dfu_alt_info(char *interface, char *devstr)
> >                         strncat(buf, "&virt 1=PMIC", DFU_ALT_BUF_LEN);
> >         }
> >
> > +       len = strlen(buf);
> > +       if (buf[0] != '\0')
> > +               len += snprintf(buf + len, DFU_ALT_BUF_LEN - len, "&");
> > +
> > +       snprintf(buf + len, DFU_ALT_BUF_LEN,
> > +                "ram 0=%s", CONFIG_DFU_ALT_RAM0);
>
> s/DFU_ALT_BUF_LEN/DFU_ALT_BUF_LEN - len/
>
> Should check snprintf() return value.
>

This patch would not be needed, if what Patrick suggested[1] works.

-sughosh

[1] -  https://lists.denx.de/pipermail/u-boot/2021-December/469256.html


> > +
> >         env_set("dfu_alt_info", buf);
> >         puts("DFU alt info setting: done\n");
> >  }
> > --
> > 2.17.1
> >
>
diff mbox series

Patch

diff --git a/board/st/common/stm32mp_dfu.c b/board/st/common/stm32mp_dfu.c
index 00d1fb8f59..394a2704ee 100644
--- a/board/st/common/stm32mp_dfu.c
+++ b/board/st/common/stm32mp_dfu.c
@@ -102,6 +102,7 @@  static void board_get_alt_info_mtd(struct mtd_info *mtd, char *buf)
 
 void set_dfu_alt_info(char *interface, char *devstr)
 {
+	int len;
 	struct udevice *dev;
 	struct mtd_info *mtd;
 
@@ -112,9 +113,6 @@  void set_dfu_alt_info(char *interface, char *devstr)
 
 	memset(buf, 0, sizeof(buf));
 
-	snprintf(buf, DFU_ALT_BUF_LEN,
-		 "ram 0=%s", CONFIG_DFU_ALT_RAM0);
-
 	if (CONFIG_IS_ENABLED(MMC)) {
 		if (!uclass_get_device(UCLASS_MMC, 0, &dev))
 			board_get_alt_info_mmc(dev, buf);
@@ -151,6 +149,13 @@  void set_dfu_alt_info(char *interface, char *devstr)
 			strncat(buf, "&virt 1=PMIC", DFU_ALT_BUF_LEN);
 	}
 
+	len = strlen(buf);
+	if (buf[0] != '\0')
+		len += snprintf(buf + len, DFU_ALT_BUF_LEN - len, "&");
+
+	snprintf(buf + len, DFU_ALT_BUF_LEN,
+		 "ram 0=%s", CONFIG_DFU_ALT_RAM0);
+
 	env_set("dfu_alt_info", buf);
 	puts("DFU alt info setting: done\n");
 }