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

Sughosh Ganu sughosh.ganu at linaro.org
Mon Dec 7 06:30:29 CET 2020


On Sat, 5 Dec 2020 at 16:00, Heinrich Schuchardt <xypron.glpk at 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 at 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" \
> >
>
>


More information about the U-Boot mailing list