diff mbox series

[05/14] qemu: arm64: Add support for dynamic mtdparts for the platform

Message ID 20201126184110.30521-6-sughosh.ganu@linaro.org
State Changes Requested, archived
Delegated to: Heinrich Schuchardt
Headers show
Series qemu: arm64: Add support for uefi capsule update on qemu arm64 platform | expand

Commit Message

Sughosh Ganu Nov. 26, 2020, 6:41 p.m. UTC
Add support for setting the default values for mtd partitions on the
platform for the nor flash. This would be used for updating the
firmware image using uefi capsule update with the dfu mtd backend
driver.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
---
 board/emulation/qemu-arm/qemu-arm.c | 70 +++++++++++++++++++++++++++++
 include/configs/qemu-arm.h          |  7 +++
 2 files changed, 77 insertions(+)

Comments

Heinrich Schuchardt Dec. 5, 2020, 10:29 a.m. UTC | #1
On 11/26/20 7:41 PM, Sughosh Ganu wrote:
> Add support for setting the default values for mtd partitions on the
> platform for the nor flash. This would be used for updating the
> firmware image using uefi capsule update with the dfu mtd backend
> driver.
>
> Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
> ---
>   board/emulation/qemu-arm/qemu-arm.c | 70 +++++++++++++++++++++++++++++
>   include/configs/qemu-arm.h          |  7 +++
>   2 files changed, 77 insertions(+)
>
> diff --git a/board/emulation/qemu-arm/qemu-arm.c b/board/emulation/qemu-arm/qemu-arm.c
> index b3d5b3d5c2..d5ed3eebaf 100644
> --- a/board/emulation/qemu-arm/qemu-arm.c
> +++ b/board/emulation/qemu-arm/qemu-arm.c

Is this development really QEMU specific or is it something we would
could reuse for other systems too? If yes, we should put it into another
directory (drivers/mtd/ or drivers/dfu/).

Best regards

Heinrich

> @@ -197,3 +197,73 @@ void flash_write32(u32 value, void *addr)
>   {
>   	asm("str %" __W "1, %0" : "=m"(*(u32 *)addr) : "r"(value));
>   }
> +
> +#if defined(CONFIG_EFI_CAPSULE_FIRMWARE_MANAGEMENT)
> +
> +#include <mtd.h>
> +
> +static void board_get_mtdparts(const char *dev, const char *partition,
> +			       char *mtdids, char *mtdparts)
> +{
> +	/* mtdids: "<dev>=<dev>, ...." */
> +	if (mtdids[0] != '\0')
> +		strcat(mtdids, ",");
> +	strcat(mtdids, dev);
> +	strcat(mtdids, "=");
> +	strcat(mtdids, dev);
> +
> +	/* mtdparts: "mtdparts=<dev>:<mtdparts_<dev>>;..." */
> +	if (mtdparts[0] != '\0')
> +		strncat(mtdparts, ";", MTDPARTS_LEN);
> +	else
> +		strcat(mtdparts, "mtdparts=");
> +
> +	strncat(mtdparts, dev, MTDPARTS_LEN);
> +	strncat(mtdparts, ":", MTDPARTS_LEN);
> +	strncat(mtdparts, partition, MTDPARTS_LEN);
> +}
> +
> +void board_mtdparts_default(const char **mtdids, const char **mtdparts)
> +{
> +	struct mtd_info *mtd;
> +	struct udevice *dev;
> +	const char *mtd_partition;
> +	static char parts[3 * MTDPARTS_LEN + 1];
> +	static char ids[MTDIDS_LEN + 1];
> +	static bool mtd_initialized;
> +
> +	if (mtd_initialized) {
> +		*mtdids = ids;
> +		*mtdparts = parts;
> +		return;
> +	}
> +
> +	memset(parts, 0, sizeof(parts));
> +	memset(ids, 0, sizeof(ids));
> +
> +	/* probe all MTD devices */
> +	for (uclass_first_device(UCLASS_MTD, &dev); dev;
> +	     uclass_next_device(&dev)) {
> +		debug("mtd device = %s\n", dev->name);
> +	}
> +
> +	mtd = get_mtd_device_nm("nor0");
> +	if (!IS_ERR_OR_NULL(mtd)) {
> +		mtd_partition = MTDPARTS_NOR0;
> +		board_get_mtdparts("nor0", mtd_partition, ids, parts);
> +		put_mtd_device(mtd);
> +	}
> +
> +	mtd = get_mtd_device_nm("nor1");
> +	if (!IS_ERR_OR_NULL(mtd)) {
> +		mtd_partition = MTDPARTS_NOR1;
> +		board_get_mtdparts("nor1", mtd_partition, ids, parts);
> +		put_mtd_device(mtd);
> +	}
> +
> +	mtd_initialized = true;
> +	*mtdids = ids;
> +	*mtdparts = parts;
> +	debug("%s:mtdids=%s & mtdparts=%s\n", __func__, ids, parts);
> +}
> +#endif /* CONFIG_EFI_CAPSULE_FIRMWARE_MANAGEMENT */
> diff --git a/include/configs/qemu-arm.h b/include/configs/qemu-arm.h
> index 273fa1a7d7..69ff329434 100644
> --- a/include/configs/qemu-arm.h
> +++ b/include/configs/qemu-arm.h
> @@ -32,6 +32,13 @@
>
>   #include <config_distro_bootcmd.h>
>
> +#if defined(CONFIG_EFI_CAPSULE_FIRMWARE_MANAGEMENT)
> +#define CONFIG_SYS_MTDPARTS_RUNTIME
> +#endif
> +
> +#define MTDPARTS_NOR0	"64m(u-boot)\0"
> +#define MTDPARTS_NOR1	"64m(u-boot-env)\0"
> +
>   #define CONFIG_EXTRA_ENV_SETTINGS \
>   	"fdt_high=0xffffffff\0" \
>   	"initrd_high=0xffffffff\0" \
>
Sughosh Ganu Dec. 7, 2020, 5:30 a.m. UTC | #2
On Sat, 5 Dec 2020 at 16:00, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:

> On 11/26/20 7:41 PM, Sughosh Ganu wrote:
> > Add support for setting the default values for mtd partitions on the
> > platform for the nor flash. This would be used for updating the
> > firmware image using uefi capsule update with the dfu mtd backend
> > driver.
> >
> > Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
> > ---
> >   board/emulation/qemu-arm/qemu-arm.c | 70 +++++++++++++++++++++++++++++
> >   include/configs/qemu-arm.h          |  7 +++
> >   2 files changed, 77 insertions(+)
> >
> > diff --git a/board/emulation/qemu-arm/qemu-arm.c
> b/board/emulation/qemu-arm/qemu-arm.c
> > index b3d5b3d5c2..d5ed3eebaf 100644
> > --- a/board/emulation/qemu-arm/qemu-arm.c
> > +++ b/board/emulation/qemu-arm/qemu-arm.c
>
> Is this development really QEMU specific or is it something we would
> could reuse for other systems too? If yes, we should put it into another
> directory (drivers/mtd/ or drivers/dfu/).
>

I think the functionality added in this patch is specific for a particular
board, given that the number and type of mtd devices would be specific to a
board. Even if the mtd device detection can be done dynamically, it would
be required to get the partition information from the board specific files.
Merging all the functionality under a common directory like drivers/mtd/,
if done, should be taken up as a separate effort. Thanks.

-sughosh


> Best regards
>
> Heinrich
>
> > @@ -197,3 +197,73 @@ void flash_write32(u32 value, void *addr)
> >   {
> >       asm("str %" __W "1, %0" : "=m"(*(u32 *)addr) : "r"(value));
> >   }
> > +
> > +#if defined(CONFIG_EFI_CAPSULE_FIRMWARE_MANAGEMENT)
> > +
> > +#include <mtd.h>
> > +
> > +static void board_get_mtdparts(const char *dev, const char *partition,
> > +                            char *mtdids, char *mtdparts)
> > +{
> > +     /* mtdids: "<dev>=<dev>, ...." */
> > +     if (mtdids[0] != '\0')
> > +             strcat(mtdids, ",");
> > +     strcat(mtdids, dev);
> > +     strcat(mtdids, "=");
> > +     strcat(mtdids, dev);
> > +
> > +     /* mtdparts: "mtdparts=<dev>:<mtdparts_<dev>>;..." */
> > +     if (mtdparts[0] != '\0')
> > +             strncat(mtdparts, ";", MTDPARTS_LEN);
> > +     else
> > +             strcat(mtdparts, "mtdparts=");
> > +
> > +     strncat(mtdparts, dev, MTDPARTS_LEN);
> > +     strncat(mtdparts, ":", MTDPARTS_LEN);
> > +     strncat(mtdparts, partition, MTDPARTS_LEN);
> > +}
> > +
> > +void board_mtdparts_default(const char **mtdids, const char **mtdparts)
> > +{
> > +     struct mtd_info *mtd;
> > +     struct udevice *dev;
> > +     const char *mtd_partition;
> > +     static char parts[3 * MTDPARTS_LEN + 1];
> > +     static char ids[MTDIDS_LEN + 1];
> > +     static bool mtd_initialized;
> > +
> > +     if (mtd_initialized) {
> > +             *mtdids = ids;
> > +             *mtdparts = parts;
> > +             return;
> > +     }
> > +
> > +     memset(parts, 0, sizeof(parts));
> > +     memset(ids, 0, sizeof(ids));
> > +
> > +     /* probe all MTD devices */
> > +     for (uclass_first_device(UCLASS_MTD, &dev); dev;
> > +          uclass_next_device(&dev)) {
> > +             debug("mtd device = %s\n", dev->name);
> > +     }
> > +
> > +     mtd = get_mtd_device_nm("nor0");
> > +     if (!IS_ERR_OR_NULL(mtd)) {
> > +             mtd_partition = MTDPARTS_NOR0;
> > +             board_get_mtdparts("nor0", mtd_partition, ids, parts);
> > +             put_mtd_device(mtd);
> > +     }
> > +
> > +     mtd = get_mtd_device_nm("nor1");
> > +     if (!IS_ERR_OR_NULL(mtd)) {
> > +             mtd_partition = MTDPARTS_NOR1;
> > +             board_get_mtdparts("nor1", mtd_partition, ids, parts);
> > +             put_mtd_device(mtd);
> > +     }
> > +
> > +     mtd_initialized = true;
> > +     *mtdids = ids;
> > +     *mtdparts = parts;
> > +     debug("%s:mtdids=%s & mtdparts=%s\n", __func__, ids, parts);
> > +}
> > +#endif /* CONFIG_EFI_CAPSULE_FIRMWARE_MANAGEMENT */
> > diff --git a/include/configs/qemu-arm.h b/include/configs/qemu-arm.h
> > index 273fa1a7d7..69ff329434 100644
> > --- a/include/configs/qemu-arm.h
> > +++ b/include/configs/qemu-arm.h
> > @@ -32,6 +32,13 @@
> >
> >   #include <config_distro_bootcmd.h>
> >
> > +#if defined(CONFIG_EFI_CAPSULE_FIRMWARE_MANAGEMENT)
> > +#define CONFIG_SYS_MTDPARTS_RUNTIME
> > +#endif
> > +
> > +#define MTDPARTS_NOR0        "64m(u-boot)\0"
> > +#define MTDPARTS_NOR1        "64m(u-boot-env)\0"
> > +
> >   #define CONFIG_EXTRA_ENV_SETTINGS \
> >       "fdt_high=0xffffffff\0" \
> >       "initrd_high=0xffffffff\0" \
> >
>
>
Tom Rini Dec. 7, 2020, 6:44 p.m. UTC | #3
On Sat, Dec 05, 2020 at 11:29:58AM +0100, Heinrich Schuchardt wrote:
> On 11/26/20 7:41 PM, Sughosh Ganu wrote:
> > Add support for setting the default values for mtd partitions on the
> > platform for the nor flash. This would be used for updating the
> > firmware image using uefi capsule update with the dfu mtd backend
> > driver.
> > 
> > Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
> > ---
> >   board/emulation/qemu-arm/qemu-arm.c | 70 +++++++++++++++++++++++++++++
> >   include/configs/qemu-arm.h          |  7 +++
> >   2 files changed, 77 insertions(+)
> > 
> > diff --git a/board/emulation/qemu-arm/qemu-arm.c b/board/emulation/qemu-arm/qemu-arm.c
> > index b3d5b3d5c2..d5ed3eebaf 100644
> > --- a/board/emulation/qemu-arm/qemu-arm.c
> > +++ b/board/emulation/qemu-arm/qemu-arm.c
[snip]
> > +#if defined(CONFIG_EFI_CAPSULE_FIRMWARE_MANAGEMENT)
> > +#define CONFIG_SYS_MTDPARTS_RUNTIME
> > +#endif

This symbol is in Kconfig and needs to be enabled that way.
Sughosh Ganu Dec. 8, 2020, 5:12 a.m. UTC | #4
On Tue, 8 Dec 2020 at 00:14, Tom Rini <trini@konsulko.com> wrote:

> On Sat, Dec 05, 2020 at 11:29:58AM +0100, Heinrich Schuchardt wrote:
> > On 11/26/20 7:41 PM, Sughosh Ganu wrote:
> > > Add support for setting the default values for mtd partitions on the
> > > platform for the nor flash. This would be used for updating the
> > > firmware image using uefi capsule update with the dfu mtd backend
> > > driver.
> > >
> > > Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
> > > ---
> > >   board/emulation/qemu-arm/qemu-arm.c | 70
> +++++++++++++++++++++++++++++
> > >   include/configs/qemu-arm.h          |  7 +++
> > >   2 files changed, 77 insertions(+)
> > >
> > > diff --git a/board/emulation/qemu-arm/qemu-arm.c
> b/board/emulation/qemu-arm/qemu-arm.c
> > > index b3d5b3d5c2..d5ed3eebaf 100644
> > > --- a/board/emulation/qemu-arm/qemu-arm.c
> > > +++ b/board/emulation/qemu-arm/qemu-arm.c
> [snip]
> > > +#if defined(CONFIG_EFI_CAPSULE_FIRMWARE_MANAGEMENT)
> > > +#define CONFIG_SYS_MTDPARTS_RUNTIME
> > > +#endif
>
> This symbol is in Kconfig and needs to be enabled that way.
>

Will make the necessary change in the next version. Thanks.

-sughosh
diff mbox series

Patch

diff --git a/board/emulation/qemu-arm/qemu-arm.c b/board/emulation/qemu-arm/qemu-arm.c
index b3d5b3d5c2..d5ed3eebaf 100644
--- a/board/emulation/qemu-arm/qemu-arm.c
+++ b/board/emulation/qemu-arm/qemu-arm.c
@@ -197,3 +197,73 @@  void flash_write32(u32 value, void *addr)
 {
 	asm("str %" __W "1, %0" : "=m"(*(u32 *)addr) : "r"(value));
 }
+
+#if defined(CONFIG_EFI_CAPSULE_FIRMWARE_MANAGEMENT)
+
+#include <mtd.h>
+
+static void board_get_mtdparts(const char *dev, const char *partition,
+			       char *mtdids, char *mtdparts)
+{
+	/* mtdids: "<dev>=<dev>, ...." */
+	if (mtdids[0] != '\0')
+		strcat(mtdids, ",");
+	strcat(mtdids, dev);
+	strcat(mtdids, "=");
+	strcat(mtdids, dev);
+
+	/* mtdparts: "mtdparts=<dev>:<mtdparts_<dev>>;..." */
+	if (mtdparts[0] != '\0')
+		strncat(mtdparts, ";", MTDPARTS_LEN);
+	else
+		strcat(mtdparts, "mtdparts=");
+
+	strncat(mtdparts, dev, MTDPARTS_LEN);
+	strncat(mtdparts, ":", MTDPARTS_LEN);
+	strncat(mtdparts, partition, MTDPARTS_LEN);
+}
+
+void board_mtdparts_default(const char **mtdids, const char **mtdparts)
+{
+	struct mtd_info *mtd;
+	struct udevice *dev;
+	const char *mtd_partition;
+	static char parts[3 * MTDPARTS_LEN + 1];
+	static char ids[MTDIDS_LEN + 1];
+	static bool mtd_initialized;
+
+	if (mtd_initialized) {
+		*mtdids = ids;
+		*mtdparts = parts;
+		return;
+	}
+
+	memset(parts, 0, sizeof(parts));
+	memset(ids, 0, sizeof(ids));
+
+	/* probe all MTD devices */
+	for (uclass_first_device(UCLASS_MTD, &dev); dev;
+	     uclass_next_device(&dev)) {
+		debug("mtd device = %s\n", dev->name);
+	}
+
+	mtd = get_mtd_device_nm("nor0");
+	if (!IS_ERR_OR_NULL(mtd)) {
+		mtd_partition = MTDPARTS_NOR0;
+		board_get_mtdparts("nor0", mtd_partition, ids, parts);
+		put_mtd_device(mtd);
+	}
+
+	mtd = get_mtd_device_nm("nor1");
+	if (!IS_ERR_OR_NULL(mtd)) {
+		mtd_partition = MTDPARTS_NOR1;
+		board_get_mtdparts("nor1", mtd_partition, ids, parts);
+		put_mtd_device(mtd);
+	}
+
+	mtd_initialized = true;
+	*mtdids = ids;
+	*mtdparts = parts;
+	debug("%s:mtdids=%s & mtdparts=%s\n", __func__, ids, parts);
+}
+#endif /* CONFIG_EFI_CAPSULE_FIRMWARE_MANAGEMENT */
diff --git a/include/configs/qemu-arm.h b/include/configs/qemu-arm.h
index 273fa1a7d7..69ff329434 100644
--- a/include/configs/qemu-arm.h
+++ b/include/configs/qemu-arm.h
@@ -32,6 +32,13 @@ 
 
 #include <config_distro_bootcmd.h>
 
+#if defined(CONFIG_EFI_CAPSULE_FIRMWARE_MANAGEMENT)
+#define CONFIG_SYS_MTDPARTS_RUNTIME
+#endif
+
+#define MTDPARTS_NOR0	"64m(u-boot)\0"
+#define MTDPARTS_NOR1	"64m(u-boot-env)\0"
+
 #define CONFIG_EXTRA_ENV_SETTINGS \
 	"fdt_high=0xffffffff\0" \
 	"initrd_high=0xffffffff\0" \