Re: [PATCH v8 03/13] FWU: Add FWU metadata access driver for GPT partitioned block devices

2022-08-19 Thread Sughosh Ganu
hi Simon,

On Thu, 18 Aug 2022 at 23:19, Simon Glass  wrote:
>
> Hi Sughosh,
>
> On Thu, 18 Aug 2022 at 05:39, Sughosh Ganu  wrote:
> >
> > hi Simon,
> >
> > On Thu, 18 Aug 2022 at 08:51, Simon Glass  wrote:
> > >
> > > Hi Sughosh,
> > >
> > > On Wed, 17 Aug 2022 at 06:44, Sughosh Ganu  
> > > wrote:
> > > >
> > > > In the FWU Multi Bank Update feature, the information about the
> > > > updatable images is stored as part of the metadata, on a separate
> > > > partition. Add a driver for reading from and writing to the metadata
> > > > when the updatable images and the metadata are stored on a block
> > > > device which is formated with GPT based partition scheme.
> > > >
> > > > Signed-off-by: Sughosh Ganu 
> > > > Reviewed-by: Patrick Delaunay 
> > > > ---
> > > > Changes since V7: None
> > > >
> > > >  drivers/fwu-mdata/Kconfig |   9 +
> > > >  drivers/fwu-mdata/Makefile|   1 +
> > > >  drivers/fwu-mdata/fwu_mdata_gpt_blk.c | 410 ++
> > > >  include/fwu.h |   5 +
> > > >  4 files changed, 425 insertions(+)
> > > >  create mode 100644 drivers/fwu-mdata/fwu_mdata_gpt_blk.c
> > > >
> > > > diff --git a/drivers/fwu-mdata/Kconfig b/drivers/fwu-mdata/Kconfig
> > > > index d6a21c8e19..d5edef19d6 100644
> > > > --- a/drivers/fwu-mdata/Kconfig
> > > > +++ b/drivers/fwu-mdata/Kconfig
> > > > @@ -5,3 +5,12 @@ config DM_FWU_MDATA
> > > >   Enable support for accessing FWU Metadata partitions. The
> > > >   FWU Metadata partitions reside on the same storage device
> > > >   which contains the other FWU updatable firmware images.
> > >
> > > Can we link to the docs here, or will it be easy for people to find in
> > > the U-Boot docs?
> >
> > The link to the spec is being provided in the documentation for the
> > feature. I guess that should suffice.
>
> Yes it's the U-Boot documentation that I am referring to. I assume people can 
> type 'FWU metadata' in the docs and it will come up. If so, that seems OK.
>
> >
> > >
> > > > +
> > > > +config FWU_MDATA_GPT_BLK
> > > > +   bool "FWU Metadata access for GPT partitioned Block devices"
> > > > +   select PARTITION_TYPE_GUID
> > > > +   select PARTITION_UUIDS
> > > > +   depends on DM && HAVE_BLOCK_DEVICE && EFI_PARTITION
> > > > +   help
> > > > + Enable support for accessing FWU Metadata on GPT partitioned
> > > > + block devices.
> > >
> > > GPT-partitioned (I think)
> >
> > I see "GPT partition" being used elsewhere. I don't have a strong
> > opinion on this though.
> >
> > >
> > > > diff --git a/drivers/fwu-mdata/Makefile b/drivers/fwu-mdata/Makefile
> > > > index e53a8c9983..313049f67a 100644
> > > > --- a/drivers/fwu-mdata/Makefile
> > > > +++ b/drivers/fwu-mdata/Makefile
> > > > @@ -4,3 +4,4 @@
> > > >  #
> > > >
> > > >  obj-$(CONFIG_DM_FWU_MDATA) += fwu-mdata-uclass.o
> > > > +obj-$(CONFIG_FWU_MDATA_GPT_BLK) += fwu_mdata_gpt_blk.o
> > > > diff --git a/drivers/fwu-mdata/fwu_mdata_gpt_blk.c 
> > > > b/drivers/fwu-mdata/fwu_mdata_gpt_blk.c
> > >
> > > Perhaps just call it gpt_blk.c since it is in this directory
> >
> > Actually, there are both type of examples that can be seen under
> > drivers/. For e.g. the drivers/clk/ has all files starting with clk_*.
> > Similarly, under drivers/reset/. But there are other examples as well.
> > But this is not a big effort. I will change the name as per your
> > suggestion.
> >
> > >
> > > > new file mode 100644
> > > > index 00..f694c4369b
> > > > --- /dev/null
> > > > +++ b/drivers/fwu-mdata/fwu_mdata_gpt_blk.c
> > > > @@ -0,0 +1,410 @@
> > > > +// SPDX-License-Identifier: GPL-2.0-or-later
> > > > +/*
> > > > + * Copyright (c) 2022, Linaro Limited
> > > > + */
> > > > +
> > > > +#define LOG_CATEGORY UCLASS_FWU_MDATA
> > > > +
> > > > +#include 
> > > > +#include 
> > > > +#include 
> > > > +#include 
> > > > +#include 
> > > > +#include 
> > > > +#include 
> > > > +#include 
> > > > +#include 
> > > > +#include 
> > > > +
> > > > +#include 
> > > > +#include 
> > > > +#include 
> > > > +#include 
> > > > +
> > > > +#define PRIMARY_PART   BIT(0)
> > > > +#define SECONDARY_PART BIT(1)
> > > > +#define BOTH_PARTS (PRIMARY_PART | SECONDARY_PART)
> > > > +
> > > > +#define MDATA_READ BIT(0)
> > > > +#define MDATA_WRITEBIT(1)
> > > > +
> > >
> > > comment?
> >
> > Umm, is the macro name not descriptive enough? They are just being
> > used to select a read or write operation.
>
> I mean the function below
>
> >
> > >
> > > > +static int gpt_get_mdata_partitions(struct blk_desc *desc,
> > > > +   u16 *primary_mpart,
> > > > +   u16 *secondary_mpart)
> > >
> > > Should use uint, no need to select a 16-bit var so far as I can get
> >
> > Okay
> >
>
> [..]
>
> > > > +static int gpt_get_mdata(struct blk_desc *desc, struct fwu_mdata 
> > > > **mdata)
> > >
> > > mdatap
> >
> > Okay
> >

Re: [PATCH v8 03/13] FWU: Add FWU metadata access driver for GPT partitioned block devices

2022-08-18 Thread Simon Glass
Hi Sughosh,

On Thu, 18 Aug 2022 at 05:39, Sughosh Ganu  wrote:
>
> hi Simon,
>
> On Thu, 18 Aug 2022 at 08:51, Simon Glass  wrote:
> >
> > Hi Sughosh,
> >
> > On Wed, 17 Aug 2022 at 06:44, Sughosh Ganu 
wrote:
> > >
> > > In the FWU Multi Bank Update feature, the information about the
> > > updatable images is stored as part of the metadata, on a separate
> > > partition. Add a driver for reading from and writing to the metadata
> > > when the updatable images and the metadata are stored on a block
> > > device which is formated with GPT based partition scheme.
> > >
> > > Signed-off-by: Sughosh Ganu 
> > > Reviewed-by: Patrick Delaunay 
> > > ---
> > > Changes since V7: None
> > >
> > >  drivers/fwu-mdata/Kconfig |   9 +
> > >  drivers/fwu-mdata/Makefile|   1 +
> > >  drivers/fwu-mdata/fwu_mdata_gpt_blk.c | 410
++
> > >  include/fwu.h |   5 +
> > >  4 files changed, 425 insertions(+)
> > >  create mode 100644 drivers/fwu-mdata/fwu_mdata_gpt_blk.c
> > >
> > > diff --git a/drivers/fwu-mdata/Kconfig b/drivers/fwu-mdata/Kconfig
> > > index d6a21c8e19..d5edef19d6 100644
> > > --- a/drivers/fwu-mdata/Kconfig
> > > +++ b/drivers/fwu-mdata/Kconfig
> > > @@ -5,3 +5,12 @@ config DM_FWU_MDATA
> > >   Enable support for accessing FWU Metadata partitions. The
> > >   FWU Metadata partitions reside on the same storage device
> > >   which contains the other FWU updatable firmware images.
> >
> > Can we link to the docs here, or will it be easy for people to find in
> > the U-Boot docs?
>
> The link to the spec is being provided in the documentation for the
> feature. I guess that should suffice.

Yes it's the U-Boot documentation that I am referring to. I assume people
can type 'FWU metadata' in the docs and it will come up. If so, that seems
OK.

>
> >
> > > +
> > > +config FWU_MDATA_GPT_BLK
> > > +   bool "FWU Metadata access for GPT partitioned Block devices"
> > > +   select PARTITION_TYPE_GUID
> > > +   select PARTITION_UUIDS
> > > +   depends on DM && HAVE_BLOCK_DEVICE && EFI_PARTITION
> > > +   help
> > > + Enable support for accessing FWU Metadata on GPT partitioned
> > > + block devices.
> >
> > GPT-partitioned (I think)
>
> I see "GPT partition" being used elsewhere. I don't have a strong
> opinion on this though.
>
> >
> > > diff --git a/drivers/fwu-mdata/Makefile b/drivers/fwu-mdata/Makefile
> > > index e53a8c9983..313049f67a 100644
> > > --- a/drivers/fwu-mdata/Makefile
> > > +++ b/drivers/fwu-mdata/Makefile
> > > @@ -4,3 +4,4 @@
> > >  #
> > >
> > >  obj-$(CONFIG_DM_FWU_MDATA) += fwu-mdata-uclass.o
> > > +obj-$(CONFIG_FWU_MDATA_GPT_BLK) += fwu_mdata_gpt_blk.o
> > > diff --git a/drivers/fwu-mdata/fwu_mdata_gpt_blk.c
b/drivers/fwu-mdata/fwu_mdata_gpt_blk.c
> >
> > Perhaps just call it gpt_blk.c since it is in this directory
>
> Actually, there are both type of examples that can be seen under
> drivers/. For e.g. the drivers/clk/ has all files starting with clk_*.
> Similarly, under drivers/reset/. But there are other examples as well.
> But this is not a big effort. I will change the name as per your
> suggestion.
>
> >
> > > new file mode 100644
> > > index 00..f694c4369b
> > > --- /dev/null
> > > +++ b/drivers/fwu-mdata/fwu_mdata_gpt_blk.c
> > > @@ -0,0 +1,410 @@
> > > +// SPDX-License-Identifier: GPL-2.0-or-later
> > > +/*
> > > + * Copyright (c) 2022, Linaro Limited
> > > + */
> > > +
> > > +#define LOG_CATEGORY UCLASS_FWU_MDATA
> > > +
> > > +#include 
> > > +#include 
> > > +#include 
> > > +#include 
> > > +#include 
> > > +#include 
> > > +#include 
> > > +#include 
> > > +#include 
> > > +#include 
> > > +
> > > +#include 
> > > +#include 
> > > +#include 
> > > +#include 
> > > +
> > > +#define PRIMARY_PART   BIT(0)
> > > +#define SECONDARY_PART BIT(1)
> > > +#define BOTH_PARTS (PRIMARY_PART | SECONDARY_PART)
> > > +
> > > +#define MDATA_READ BIT(0)
> > > +#define MDATA_WRITEBIT(1)
> > > +
> >
> > comment?
>
> Umm, is the macro name not descriptive enough? They are just being
> used to select a read or write operation.

I mean the function below

>
> >
> > > +static int gpt_get_mdata_partitions(struct blk_desc *desc,
> > > +   u16 *primary_mpart,
> > > +   u16 *secondary_mpart)
> >
> > Should use uint, no need to select a 16-bit var so far as I can get
>
> Okay
>

[..]

> > > +static int gpt_get_mdata(struct blk_desc *desc, struct fwu_mdata
**mdata)
> >
> > mdatap
>
> Okay
>
> >
> > > +{
> > > +   int ret;
> > > +   u16 primary_mpart = 0, secondary_mpart = 0;
> >
> > uint
>
> Okay
>
> >
> > Also do you need to set them to 0
> >
> > Declare a locate mdata and use that here instead of *mdata, which is a
pain.
>
> This function is copying the metadata into the callers copy. Unless I
> don't understand your comment.

I mean it is easier to d

Re: [PATCH v8 03/13] FWU: Add FWU metadata access driver for GPT partitioned block devices

2022-08-18 Thread Sughosh Ganu
hi Simon,

On Thu, 18 Aug 2022 at 08:51, Simon Glass  wrote:
>
> Hi Sughosh,
>
> On Wed, 17 Aug 2022 at 06:44, Sughosh Ganu  wrote:
> >
> > In the FWU Multi Bank Update feature, the information about the
> > updatable images is stored as part of the metadata, on a separate
> > partition. Add a driver for reading from and writing to the metadata
> > when the updatable images and the metadata are stored on a block
> > device which is formated with GPT based partition scheme.
> >
> > Signed-off-by: Sughosh Ganu 
> > Reviewed-by: Patrick Delaunay 
> > ---
> > Changes since V7: None
> >
> >  drivers/fwu-mdata/Kconfig |   9 +
> >  drivers/fwu-mdata/Makefile|   1 +
> >  drivers/fwu-mdata/fwu_mdata_gpt_blk.c | 410 ++
> >  include/fwu.h |   5 +
> >  4 files changed, 425 insertions(+)
> >  create mode 100644 drivers/fwu-mdata/fwu_mdata_gpt_blk.c
> >
> > diff --git a/drivers/fwu-mdata/Kconfig b/drivers/fwu-mdata/Kconfig
> > index d6a21c8e19..d5edef19d6 100644
> > --- a/drivers/fwu-mdata/Kconfig
> > +++ b/drivers/fwu-mdata/Kconfig
> > @@ -5,3 +5,12 @@ config DM_FWU_MDATA
> >   Enable support for accessing FWU Metadata partitions. The
> >   FWU Metadata partitions reside on the same storage device
> >   which contains the other FWU updatable firmware images.
>
> Can we link to the docs here, or will it be easy for people to find in
> the U-Boot docs?

The link to the spec is being provided in the documentation for the
feature. I guess that should suffice.

>
> > +
> > +config FWU_MDATA_GPT_BLK
> > +   bool "FWU Metadata access for GPT partitioned Block devices"
> > +   select PARTITION_TYPE_GUID
> > +   select PARTITION_UUIDS
> > +   depends on DM && HAVE_BLOCK_DEVICE && EFI_PARTITION
> > +   help
> > + Enable support for accessing FWU Metadata on GPT partitioned
> > + block devices.
>
> GPT-partitioned (I think)

I see "GPT partition" being used elsewhere. I don't have a strong
opinion on this though.

>
> > diff --git a/drivers/fwu-mdata/Makefile b/drivers/fwu-mdata/Makefile
> > index e53a8c9983..313049f67a 100644
> > --- a/drivers/fwu-mdata/Makefile
> > +++ b/drivers/fwu-mdata/Makefile
> > @@ -4,3 +4,4 @@
> >  #
> >
> >  obj-$(CONFIG_DM_FWU_MDATA) += fwu-mdata-uclass.o
> > +obj-$(CONFIG_FWU_MDATA_GPT_BLK) += fwu_mdata_gpt_blk.o
> > diff --git a/drivers/fwu-mdata/fwu_mdata_gpt_blk.c 
> > b/drivers/fwu-mdata/fwu_mdata_gpt_blk.c
>
> Perhaps just call it gpt_blk.c since it is in this directory

Actually, there are both type of examples that can be seen under
drivers/. For e.g. the drivers/clk/ has all files starting with clk_*.
Similarly, under drivers/reset/. But there are other examples as well.
But this is not a big effort. I will change the name as per your
suggestion.

>
> > new file mode 100644
> > index 00..f694c4369b
> > --- /dev/null
> > +++ b/drivers/fwu-mdata/fwu_mdata_gpt_blk.c
> > @@ -0,0 +1,410 @@
> > +// SPDX-License-Identifier: GPL-2.0-or-later
> > +/*
> > + * Copyright (c) 2022, Linaro Limited
> > + */
> > +
> > +#define LOG_CATEGORY UCLASS_FWU_MDATA
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +#define PRIMARY_PART   BIT(0)
> > +#define SECONDARY_PART BIT(1)
> > +#define BOTH_PARTS (PRIMARY_PART | SECONDARY_PART)
> > +
> > +#define MDATA_READ BIT(0)
> > +#define MDATA_WRITEBIT(1)
> > +
>
> comment?

Umm, is the macro name not descriptive enough? They are just being
used to select a read or write operation.

>
> > +static int gpt_get_mdata_partitions(struct blk_desc *desc,
> > +   u16 *primary_mpart,
> > +   u16 *secondary_mpart)
>
> Should use uint, no need to select a 16-bit var so far as I can get

Okay

>
> > +{
> > +   int i, ret;
> > +   u32 mdata_parts;
> > +   efi_guid_t part_type_guid;
> > +   struct disk_partition info;
> > +   const efi_guid_t fwu_mdata_guid = FWU_MDATA_GUID;
> > +
> > +   mdata_parts = 0;
> > +   for (i = 1; i < MAX_SEARCH_PARTITIONS; i++) {
> > +   if (part_get_info(desc, i, &info))
> > +   continue;
> > +   uuid_str_to_bin(info.type_guid, part_type_guid.b,
> > +   UUID_STR_FORMAT_GUID);
> > +
> > +   if (!guidcmp(&fwu_mdata_guid, &part_type_guid)) {
> > +   ++mdata_parts;
> > +   if (!*primary_mpart)
> > +   *primary_mpart = i;
> > +   else
> > +   *secondary_mpart = i;
> > +   }
> > +   }
> > +
> > +   if (mdata_parts != 2) {
> > +   log_err("Expect two copies of the FWU metadata in

Re: [PATCH v8 03/13] FWU: Add FWU metadata access driver for GPT partitioned block devices

2022-08-17 Thread Simon Glass
Hi Sughosh,

On Wed, 17 Aug 2022 at 06:44, Sughosh Ganu  wrote:
>
> In the FWU Multi Bank Update feature, the information about the
> updatable images is stored as part of the metadata, on a separate
> partition. Add a driver for reading from and writing to the metadata
> when the updatable images and the metadata are stored on a block
> device which is formated with GPT based partition scheme.
>
> Signed-off-by: Sughosh Ganu 
> Reviewed-by: Patrick Delaunay 
> ---
> Changes since V7: None
>
>  drivers/fwu-mdata/Kconfig |   9 +
>  drivers/fwu-mdata/Makefile|   1 +
>  drivers/fwu-mdata/fwu_mdata_gpt_blk.c | 410 ++
>  include/fwu.h |   5 +
>  4 files changed, 425 insertions(+)
>  create mode 100644 drivers/fwu-mdata/fwu_mdata_gpt_blk.c
>
> diff --git a/drivers/fwu-mdata/Kconfig b/drivers/fwu-mdata/Kconfig
> index d6a21c8e19..d5edef19d6 100644
> --- a/drivers/fwu-mdata/Kconfig
> +++ b/drivers/fwu-mdata/Kconfig
> @@ -5,3 +5,12 @@ config DM_FWU_MDATA
>   Enable support for accessing FWU Metadata partitions. The
>   FWU Metadata partitions reside on the same storage device
>   which contains the other FWU updatable firmware images.

Can we link to the docs here, or will it be easy for people to find in
the U-Boot docs?

> +
> +config FWU_MDATA_GPT_BLK
> +   bool "FWU Metadata access for GPT partitioned Block devices"
> +   select PARTITION_TYPE_GUID
> +   select PARTITION_UUIDS
> +   depends on DM && HAVE_BLOCK_DEVICE && EFI_PARTITION
> +   help
> + Enable support for accessing FWU Metadata on GPT partitioned
> + block devices.

GPT-partitioned (I think)

> diff --git a/drivers/fwu-mdata/Makefile b/drivers/fwu-mdata/Makefile
> index e53a8c9983..313049f67a 100644
> --- a/drivers/fwu-mdata/Makefile
> +++ b/drivers/fwu-mdata/Makefile
> @@ -4,3 +4,4 @@
>  #
>
>  obj-$(CONFIG_DM_FWU_MDATA) += fwu-mdata-uclass.o
> +obj-$(CONFIG_FWU_MDATA_GPT_BLK) += fwu_mdata_gpt_blk.o
> diff --git a/drivers/fwu-mdata/fwu_mdata_gpt_blk.c 
> b/drivers/fwu-mdata/fwu_mdata_gpt_blk.c

Perhaps just call it gpt_blk.c since it is in this directory

> new file mode 100644
> index 00..f694c4369b
> --- /dev/null
> +++ b/drivers/fwu-mdata/fwu_mdata_gpt_blk.c
> @@ -0,0 +1,410 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2022, Linaro Limited
> + */
> +
> +#define LOG_CATEGORY UCLASS_FWU_MDATA
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define PRIMARY_PART   BIT(0)
> +#define SECONDARY_PART BIT(1)
> +#define BOTH_PARTS (PRIMARY_PART | SECONDARY_PART)
> +
> +#define MDATA_READ BIT(0)
> +#define MDATA_WRITEBIT(1)
> +

comment?

> +static int gpt_get_mdata_partitions(struct blk_desc *desc,
> +   u16 *primary_mpart,
> +   u16 *secondary_mpart)

Should use uint, no need to select a 16-bit var so far as I can get

> +{
> +   int i, ret;
> +   u32 mdata_parts;
> +   efi_guid_t part_type_guid;
> +   struct disk_partition info;
> +   const efi_guid_t fwu_mdata_guid = FWU_MDATA_GUID;
> +
> +   mdata_parts = 0;
> +   for (i = 1; i < MAX_SEARCH_PARTITIONS; i++) {
> +   if (part_get_info(desc, i, &info))
> +   continue;
> +   uuid_str_to_bin(info.type_guid, part_type_guid.b,
> +   UUID_STR_FORMAT_GUID);
> +
> +   if (!guidcmp(&fwu_mdata_guid, &part_type_guid)) {
> +   ++mdata_parts;
> +   if (!*primary_mpart)
> +   *primary_mpart = i;
> +   else
> +   *secondary_mpart = i;
> +   }
> +   }
> +
> +   if (mdata_parts != 2) {
> +   log_err("Expect two copies of the FWU metadata instead of 
> %d\n",
> +   mdata_parts);
> +   ret = -EINVAL;
> +   } else {
> +   ret = 0;
> +   }
> +
> +   return ret;
> +}
> +
> +static int gpt_get_mdata_disk_part(struct blk_desc *desc,
> +  struct disk_partition *info,
> +  u32 part_num)
> +{
> +   int ret;
> +   char *mdata_guid_str = "8a7a84a0-8387-40f6-ab41-a8b9a5a60d23";

This is fine, but I wonder if it should that go in a header with all
the other GUIDs? Or does it go hear because it is a string?

> +
> +   ret = part_get_info(desc, part_num, info);
> +   if (ret < 0) {
> +   log_err("Unable to get the partition info for the FWU 
> metadata part %d",
> +   part_num);
> +   return -1;
> +   }
> +
> +   /* Check that it is indeed the FWU metadata partition *

[PATCH v8 03/13] FWU: Add FWU metadata access driver for GPT partitioned block devices

2022-08-17 Thread Sughosh Ganu
In the FWU Multi Bank Update feature, the information about the
updatable images is stored as part of the metadata, on a separate
partition. Add a driver for reading from and writing to the metadata
when the updatable images and the metadata are stored on a block
device which is formated with GPT based partition scheme.

Signed-off-by: Sughosh Ganu 
Reviewed-by: Patrick Delaunay 
---
Changes since V7: None

 drivers/fwu-mdata/Kconfig |   9 +
 drivers/fwu-mdata/Makefile|   1 +
 drivers/fwu-mdata/fwu_mdata_gpt_blk.c | 410 ++
 include/fwu.h |   5 +
 4 files changed, 425 insertions(+)
 create mode 100644 drivers/fwu-mdata/fwu_mdata_gpt_blk.c

diff --git a/drivers/fwu-mdata/Kconfig b/drivers/fwu-mdata/Kconfig
index d6a21c8e19..d5edef19d6 100644
--- a/drivers/fwu-mdata/Kconfig
+++ b/drivers/fwu-mdata/Kconfig
@@ -5,3 +5,12 @@ config DM_FWU_MDATA
  Enable support for accessing FWU Metadata partitions. The
  FWU Metadata partitions reside on the same storage device
  which contains the other FWU updatable firmware images.
+
+config FWU_MDATA_GPT_BLK
+   bool "FWU Metadata access for GPT partitioned Block devices"
+   select PARTITION_TYPE_GUID
+   select PARTITION_UUIDS
+   depends on DM && HAVE_BLOCK_DEVICE && EFI_PARTITION
+   help
+ Enable support for accessing FWU Metadata on GPT partitioned
+ block devices.
diff --git a/drivers/fwu-mdata/Makefile b/drivers/fwu-mdata/Makefile
index e53a8c9983..313049f67a 100644
--- a/drivers/fwu-mdata/Makefile
+++ b/drivers/fwu-mdata/Makefile
@@ -4,3 +4,4 @@
 #
 
 obj-$(CONFIG_DM_FWU_MDATA) += fwu-mdata-uclass.o
+obj-$(CONFIG_FWU_MDATA_GPT_BLK) += fwu_mdata_gpt_blk.o
diff --git a/drivers/fwu-mdata/fwu_mdata_gpt_blk.c 
b/drivers/fwu-mdata/fwu_mdata_gpt_blk.c
new file mode 100644
index 00..f694c4369b
--- /dev/null
+++ b/drivers/fwu-mdata/fwu_mdata_gpt_blk.c
@@ -0,0 +1,410 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2022, Linaro Limited
+ */
+
+#define LOG_CATEGORY UCLASS_FWU_MDATA
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#define PRIMARY_PART   BIT(0)
+#define SECONDARY_PART BIT(1)
+#define BOTH_PARTS (PRIMARY_PART | SECONDARY_PART)
+
+#define MDATA_READ BIT(0)
+#define MDATA_WRITEBIT(1)
+
+static int gpt_get_mdata_partitions(struct blk_desc *desc,
+   u16 *primary_mpart,
+   u16 *secondary_mpart)
+{
+   int i, ret;
+   u32 mdata_parts;
+   efi_guid_t part_type_guid;
+   struct disk_partition info;
+   const efi_guid_t fwu_mdata_guid = FWU_MDATA_GUID;
+
+   mdata_parts = 0;
+   for (i = 1; i < MAX_SEARCH_PARTITIONS; i++) {
+   if (part_get_info(desc, i, &info))
+   continue;
+   uuid_str_to_bin(info.type_guid, part_type_guid.b,
+   UUID_STR_FORMAT_GUID);
+
+   if (!guidcmp(&fwu_mdata_guid, &part_type_guid)) {
+   ++mdata_parts;
+   if (!*primary_mpart)
+   *primary_mpart = i;
+   else
+   *secondary_mpart = i;
+   }
+   }
+
+   if (mdata_parts != 2) {
+   log_err("Expect two copies of the FWU metadata instead of %d\n",
+   mdata_parts);
+   ret = -EINVAL;
+   } else {
+   ret = 0;
+   }
+
+   return ret;
+}
+
+static int gpt_get_mdata_disk_part(struct blk_desc *desc,
+  struct disk_partition *info,
+  u32 part_num)
+{
+   int ret;
+   char *mdata_guid_str = "8a7a84a0-8387-40f6-ab41-a8b9a5a60d23";
+
+   ret = part_get_info(desc, part_num, info);
+   if (ret < 0) {
+   log_err("Unable to get the partition info for the FWU metadata 
part %d",
+   part_num);
+   return -1;
+   }
+
+   /* Check that it is indeed the FWU metadata partition */
+   if (!strncmp(info->type_guid, mdata_guid_str, UUID_STR_LEN)) {
+   /* Found the FWU metadata partition */
+   return 0;
+   }
+
+   return -1;
+}
+
+static int gpt_read_write_mdata(struct blk_desc *desc,
+   struct fwu_mdata *mdata,
+   u8 access, u32 part_num)
+{
+   int ret;
+   u32 len, blk_start, blkcnt;
+   struct disk_partition info;
+
+   ALLOC_CACHE_ALIGN_BUFFER_PAD(struct fwu_mdata, mdata_aligned, 1,
+desc->blksz);
+
+   ret = gpt_get_mdata_disk_part(desc, &info, part_num);
+   if (ret < 0) {
+   printf("Unable to get the FWU metadata parti