Skip to contentSkip to conversation

gpt: enable writing a full-featured GPT via 'gpt write' over fastboot

PATCH Tom Rini 4 participants 14 messages Sep 28 – Oct 7 8 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Tom Rini

author
#1 lore raw
Quoted 27 lines · Sumit Singh Dhami

This work is done as part of Snagboot support for Qualcomm Lemans-EVK to help flash GPT via u-boot 'gpt write' command. It addresses the following issues:
- Incorrect first/last LBA computation for devices whose block size is not 512 bytes.
- No option available in 'gpt write' to set full 64-bit gpt partition attributes.
- Fastboot EP_BUFFER_SIZE is not configurable and set to 4096 bytes which overflows when long command strings are passed. (We faced this issue when we passed 'gpt write' via 'fastboot oem run' with a very long partition list).

The changes are followed by a final patch that adds all the config options required for writing a GPT via 'gpt write' over fastboot to qcom-snagboot.config file.

Sumit Singh Dhami (8):
disk: part_efi: fix first/last usable LBA computation
disk: part_efi: support writing full 64-bit GPT partition attributes
disk: part_efi: read full GPT partition attributes
cmd: gpt: support setting full 64-bit GPT partition attributes
cmd: gpt: report partition attributes via 'gpt setenv'
doc: gpt: document 'attrs' key and gpt_partition_attrs var
usb: gadget: fastboot: allow configuring the endpoint buffer size
configs: add fastboot config options for writing GPT

Quoted 5 lines
 cmd/gpt.c                       | 26 ++++++++++++++++++++++++--
 configs/qcom-snagboot.config    |  7 +++++++
 disk/Kconfig                    |  8 ++++++++
 disk/part_efi.c                 | 18 ++++++++++++++----
 doc/README.gpt                  | 11 +++++++++++

Looks like doc/README.gpt is something that needs to be converted to rST and then updated?

Signature · 1 line
Tom

A message that is not in the archive (sent off-list or not yet received): [email protected]

author
#3 lore raw

Re: [PATCH v1 4/8] cmd: gpt: support setting full 64-bit GPT partition attributes

Quoted 18 lines · Sumit Singh Dhami

The 'gpt write' partition list syntax only allows setting the legacy BIOS-bootable bit via the 'bootable' key.

Parse an optional 'attrs=<value>' key when CONFIG_PARTITION_ATTR is enabled and store it via disk_partition_set_gpt_attr(), so that gpt_fill_pte() writes the requested 64-bit attributes value into the partition's GPT entry.

---
 cmd/gpt.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
cmd/gpt.c +0 -0
index 205f696c807..f610c7aa6b5 100644

cmd/gpt.c static int set_gpt_info(struct blk_desc *dev_desc, · line 601

Quoted 10 lines
cmd/gpt.c +7 -0
@@ -592,6 +592,17 @@ static int set_gpt_info(struct blk_desc *dev_desc,
 
 		offset += parts[i].size + parts[i].start;
 
+		if (CONFIG_IS_ENABLED(PARTITION_ATTR)) {
+			/* attrs */
+			val = extract_val(tok, "attrs");
+			if (val) {	/* 'attrs' is optional */
+				if (extract_env(val, &p))
+					p = val;
+				disk_partition_set_gpt_attr(&parts[i], simple_strtoull(p, NULL, 0));

I'm pointing it out here and assuming you'll check the rest of the series, checkpatch should have complained about this line being too long, please fix globally, thanks.

Signature · 1 line
Tom
#4 lore raw

Re: [PATCH v1 4/8] cmd: gpt: support setting full 64-bit GPT partition attributes

In reply to a message not in the archive

Hi Sumit,

Quoted 17 lines · Sumit Singh Dhami

cmd: gpt: support setting full 64-bit GPT partition attributes

The 'gpt write' partition list syntax only allows setting the legacy BIOS-bootable bit via the 'bootable' key.

Parse an optional 'attrs=<value>' key when CONFIG_PARTITION_ATTR is enabled and store it via disk_partition_set_gpt_attr(), so that gpt_fill_pte() writes the requested 64-bit attributes value into the partition's GPT entry.

cmd/gpt.c | 11 +++++++++++

 1 file changed, 11 insertions(+)

cmd/gpt.c static int set_gpt_info(struct blk_desc *dev_desc, · line 598

Quoted 7 lines
cmd/gpt.c +7 -0
@@ -592,6 +592,17 @@ static int set_gpt_info(struct blk_desc *dev_desc,
+             if (CONFIG_IS_ENABLED(PARTITION_ATTR)) {
+                     /* attrs */
+                     val = extract_val(tok, "attrs");
+                     if (val) {      /* 'attrs' is optional */
+                             if (extract_env(val, &p))
+                                     p = val;
+                             disk_partition_set_gpt_attr(&parts[i], simple_strtoull(p, NULL, 0));

A typo such as attrs=0x800000000000000g or attrs=abc is silently accepted here and a partially-parsed or zero value is written to the disk. Since this is a raw bit-field the user cannot easily see afterwards, please can you pass an end pointer and reject the entry when it does not point at the terminating NUL, as the uuid/type checks above do (print an error and goto err with -4)? Parsing into a local first would also bring this line back under 80 columns.

cmd/gpt.c static int set_gpt_info(struct blk_desc *dev_desc, · line 594

Quoted 5 lines
cmd/gpt.c +3 -0
@@ -592,6 +592,17 @@ static int set_gpt_info(struct blk_desc *dev_desc,
+             if (CONFIG_IS_ENABLED(PARTITION_ATTR)) {
+                     /* attrs */
+                     val = extract_val(tok, "attrs");

Just to check the round trip: 'gpt rename', 'gpt swap' and 'gpt transpose' all go through create_gpt_partitions_list() to rebuild the partition string and back through set_gpt_info(), and that function only emits uuid, name, start, size and bootable. So a table written with attrs= loses those bits as soon as it is renamed. Now that patch 3 populates gpt_attr on read, I think create_gpt_partitions_list() should append ',attrs=0x%016llx' when the attribute is set (and calc_parts_list_len() needs the extra room). Otherwise please at least note the limitation in the docs. What do you think?

Regards,
Simon

A message that is not in the archive (sent off-list or not yet received): [email protected]

author
#6 lore raw

Re: [PATCH v1 6/8] doc: gpt: document 'attrs' key and gpt_partition_attrs var

Quoted 10 lines · Sumit Singh Dhami

Document the 'attrs=<VALUE>' key of the 'gpt write' partition list in doc/README.gpt and doc/usage/cmd/gpt.rst. Document the gpt_partition_attrs variable set by 'gpt setenv'. Update the example partition list and output to show 'attrs=' usage.

---
 doc/README.gpt        | 11 +++++++++++
 doc/usage/cmd/gpt.rst | 11 ++++++++++-
 2 files changed, 21 insertions(+), 1 deletion(-)

Documentation changes should go with the patch that does the feature support.

Signature · 1 line
Tom
#7 lore raw

Re: [PATCH v1 6/8] doc: gpt: document 'attrs' key and gpt_partition_attrs var

In reply to a message not in the archive

Hi Sumit,

Quoted 6 lines · Sumit Singh Dhami

doc: gpt: document 'attrs' key and gpt_partition_attrs var

Document the 'attrs=<VALUE>' key of the 'gpt write' partition list in doc/README.gpt and doc/usage/cmd/gpt.rst. Document the gpt_partition_attrs variable set by 'gpt setenv'. Update the example partition list and output to show 'attrs=' usage.

Documentation normally goes in the same patch as the feature it describes, so the attrs= parts belong in patch 4 and the gpt_partition_attrs parts in patch 5. That keeps each patch self-contained. What do you think?

doc/usage/cmd/gpt.rst partition string · line 56

Quoted 10 lines

doc/README.gpt | 11 +++++++++++

 doc/usage/cmd/gpt.rst | 11 ++++++++++-
 2 files changed, 21 insertions(+), 1 deletion(-)
doc/usage/cmd/gpt.rst +1 -0
@@ -56,6 +56,7 @@ partition string
+    * attrs=<VALUE> - The GPT partition attributes, optional if CONFIG_PARTITION_ATTR=y is enabled

Not quite. The uuid line says "optional if ..." because the uuid becomes optional when CONFIG_RANDOM_UUID is enabled. Here attrs is always optional but only does anything with CONFIG_PARTITION_ATTR, so it should follow the type line instead, e.g. "The full 64-bit GPT partition attributes, requires CONFIG_PARTITION_ATTR=y". It is also worth mentioning here (as README.gpt does) that the bootable flag is still ORed in on top of whatever value is given, since that is easy to trip over.

Regards,
Simon

A message that is not in the archive (sent off-list or not yet received): [email protected]

author
#9 lore raw

Re: [PATCH v1 7/8] usb: gadget: fastboot: allow configuring the endpoint buffer size

Quoted 45 lines · Sumit Singh Dhami

The hard-coded 4096-byte EP_BUFFER_SIZE limits the maximum length of a fastboot command received over USB. Long "oem run" commands, such as a multi-partition "gpt write", can exceed that and get rejected with "buffer overflow".

Make the buffer size configurable via CONFIG_FASTBOOT_EP_BUFFER_SIZE, defaulting to 4096. The value must stay a multiple of the endpoint's maxpacket size.

---
 drivers/fastboot/Kconfig        | 14 ++++++++++++++
 drivers/usb/gadget/f_fastboot.c |  2 +-
 2 files changed, 15 insertions(+), 1 deletion(-)
drivers/fastboot/Kconfig +14 -0
index a4539844d89..32609fddecb 100644
@@ -49,6 +49,20 @@ config TCP_FUNCTION_FASTBOOT
 
 if FASTBOOT
 
+config FASTBOOT_EP_BUFFER_SIZE
+	hex "Fastboot bulk endpoint buffer size"
+	default 0x1000
+	help
+	  Size of the buffer used for fastboot bulk endpoint transfers.
+	  This bounds both the maximum length of a fastboot command received
+	  over USB and the chunk size used during the download data phase.
+	  A larger value is needed to accept long commands, for example
+	  "oem run" with a large command string.
+
+	  Must be an integral multiple of the endpoint maxpacket size (64,
+	  512 or 1024 bytes), otherwise transfers break on controllers such
+	  as DWC3.
+
 config FASTBOOT_BUF_ADDR
 	hex "Define FASTBOOT buffer address"
 	default 0x82000000 if MX6SX || MX6SL || MX6UL || MX6SLL
drivers/usb/gadget/f_fastboot.c +0 -0
index 8df0e3f331d..d65ed1c70a4 100644

drivers/usb/gadget/f_fastboot.c line 37

Quoted 8 lines
drivers/usb/gadget/f_fastboot.c +1 -1
@@ -31,7 +31,7 @@
 #define RX_ENDPOINT_MAXIMUM_PACKET_SIZE_1_1  (0x0040)
 #define TX_ENDPOINT_MAXIMUM_PACKET_SIZE      (0x0040)
 
-#define EP_BUFFER_SIZE			4096
+#define EP_BUFFER_SIZE		CONFIG_FASTBOOT_EP_BUFFER_SIZE
 /*
  * EP_BUFFER_SIZE must always be an integral multiple of maxpacket size
  * (64 or 512 or 1024), else we break on certain controllers like DWC3

Now that EP_BUFFER_SIZE is user-controlled, do we have some logic further in the code to introduce a build time failure if what this comment is saying is not true?

Signature · 1 line
Tom
#10 lore raw

Re: [PATCH v1 7/8] usb: gadget: fastboot: allow configuring the endpoint buffer size

In reply to a message not in the archive

Hi Sumit,

Quoted 19 lines · Sumit Singh Dhami

usb: gadget: fastboot: allow configuring the endpoint buffer size

The hard-coded 4096-byte EP_BUFFER_SIZE limits the maximum length of a fastboot command received over USB. Long "oem run" commands, such as a multi-partition "gpt write", can exceed that and get rejected with "buffer overflow".

Make the buffer size configurable via CONFIG_FASTBOOT_EP_BUFFER_SIZE, defaulting to 4096. The value must stay a multiple of the endpoint's maxpacket size.

drivers/fastboot/Kconfig | 14 ++++++++++++++

 drivers/usb/gadget/f_fastboot.c |  2 +-
 2 files changed, 15 insertions(+), 1 deletion(-)

drivers/fastboot/Kconfig config TCP_FUNCTION_FASTBOOT · line 51

Quoted 3 lines
drivers/fastboot/Kconfig +3 -0
@@ -49,6 +49,20 @@ config TCP_FUNCTION_FASTBOOT
+config FASTBOOT_EP_BUFFER_SIZE
+     hex "Fastboot bulk endpoint buffer size"
+     default 0x1000

This only affects f_fastboot.c, i.e. the USB gadget, but it appears for UDP/TCP-only builds too since it sits under 'if FASTBOOT'. Please can you add 'depends on USB_FUNCTION_FASTBOOT' (or move it next to that option)?

drivers/fastboot/Kconfig config TCP_FUNCTION_FASTBOOT · line 51

Quoted 5 lines
drivers/fastboot/Kconfig +3 -0
@@ -49,6 +49,20 @@ config TCP_FUNCTION_FASTBOOT
+       Must be an integral multiple of the endpoint maxpacket size (64,
+       512 or 1024 bytes), otherwise transfers break on controllers such
+       as DWC3.

Since this is now user-settable, it would be better to enforce the constraint at build time rather than in the help text, e.g. a BUILD_BUG_ON() or preprocessor check in f_fastboot.c that the value is a multiple of 1024 (which covers all three cases). What do you think?

drivers/fastboot/Kconfig config TCP_FUNCTION_FASTBOOT · line 50

Quoted 4 lines
drivers/fastboot/Kconfig +2 -0
@@ -49,6 +49,20 @@ config TCP_FUNCTION_FASTBOOT
+       A larger value is needed to accept long commands, for example
+       "oem run" with a large command string.

My understanding is that the fastboot protocol caps commands at 4096 bytes and the standard host tool refuses to send anything longer, so raising this only helps with hosts that don't enforce that (such as Snagboot?). Please say so here and in the commit message, so people don't expect the stock fastboot binary to benefit.

Regards,
Simon

A message that is not in the archive (sent off-list or not yet received): [email protected]

Reviewed-by
#12 lore raw

Re: [PATCH v1 1/8] disk: part_efi: fix first/last usable LBA computation

Quoted 8 lines · Sumit Singh Dhami

disk: part_efi: fix first/last usable LBA computation

gpt_fill_header() hard-codes 32 blocks for the GPT Partition Entry Array when computing first_usable_lba, and 34 (32 PTE blocks + 1 primary header block + 1 for the last LBA offset) for last_usable_lba. These values are only correct when the block size is 512 bytes and the default 16 KB Partition Entry Array size is used.

Quoted 8 lines

Compute the number of blocks required for the PTE based on device's actual block size and use this value in place of the hard-coded constants, so the first/last usable LBA are calculated correctly.

disk/part_efi.c | 7 +++++--

 1 file changed, 5 insertions(+), 2 deletions(-)

A message that is not in the archive (sent off-list or not yet received): [email protected]

#14 lore raw

Re: [PATCH v1 2/8] disk: part_efi: support writing full 64-bit GPT partition attributes

Hi Sumit,

Quoted 19 lines · Sumit Singh Dhami

disk: part_efi: support writing full 64-bit GPT partition attributes

Currently gpt_fill_pte() always zeroes the GPT partition entry's 64-bit attributes field, and only ever sets the legacy BIOS bootable bit.

Add a new CONFIG_PARTITION_ATTR option that, when enabled, adds new fields to struct disk_partition along with their accessors to support writing full 64-bit attributes.

disk/Kconfig | 8 ++++++++

 disk/part_efi.c |  9 +++++++--
 include/part.h  | 30 ++++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+), 2 deletions(-)

include/part.h struct disk_partition { · line 79

Quoted 4 lines
include/part.h +4 -0
@@ -76,6 +76,10 @@ struct disk_partition {
+#if CONFIG_IS_ENABLED(PARTITION_ATTR)
+     u64 gpt_attr;           /* raw 64-bit GPT partition attributes, if attrs= was given */
+     bool gpt_attr_valid;    /* true if attrs= was present in the partitions list */
+#endif

I don't think gpt_attr_valid is needed. Every caller of gpt_restore() zero-initialises the partition array (calloc() in set_gpt_info(), designated initialisers in the tests), so when attrs is not given gpt_attr is 0 and the memset() in gpt_fill_pte() gives the same result as assigning it. Patch 5 also uses disk_partition_gpt_attr() without checking the flag. Please can you drop the bool and the _valid accessor, so the write path becomes a single assignment?

Also the comments refer to attrs= which is 'gpt write' syntax; this struct is used by all the partition drivers, so please describe the field in terms of the GPT entry.

disk/part_efi.c int gpt_fill_pte(struct blk_desc *desc, · line 534

Quoted 6 lines
disk/part_efi.c +4 -0
@@ -531,8 +531,13 @@ int gpt_fill_pte(struct blk_desc *desc,
+             if (CONFIG_IS_ENABLED(PARTITION_ATTR) &&
+                 disk_partition_gpt_attr_valid(&partitions[i]))
+                     gpt_e[i].attributes.raw =
+                             disk_partition_gpt_attr(&partitions[i]);

The CONFIG_IS_ENABLED() check is redundant since the accessor already returns false when the option is disabled. Also raw is a little-endian on-disk value, so this should use cpu_to_le64() (and le64_to_cpu() on the read side in patch 3), even though the existing bitfield code doesn't get this right either.

Regards,
Simon

A message that is not in the archive (sent off-list or not yet received): [email protected]

#16 lore raw

Re: [PATCH v1 3/8] disk: part_efi: read full GPT partition attributes

Hi Sumit,

Quoted 6 lines · Sumit Singh Dhami

disk: part_efi: read full GPT partition attributes

gpt_fill_pte() writes the full 64-bit GPT partition attributes field when CONFIG_PARTITION_ATTR is enabled. However, part_get_info_efi(), the counterpart function used to read a partition's info back from an existing GPT never populated gpt_attr/gpt_attr_valid.

If you are using an AI tool for this, please set it up to use present tense for commits :-)

Quoted 12 lines

Populate gpt_attr from the on-disk GPT entry's raw attributes field, and set gpt_attr_valid to true mirroring the write path in gpt_fill_pte().

disk/part_efi.c | 2 ++

 1 file changed, 2 insertions(+)

disk/part_efi.c static int __maybe_unused part_get_info_efi(struct blk_desc *desc, int part, · line 307

Quoted 2 lines
disk/part_efi.c +2 -0
@@ -306,6 +306,8 @@ static int __maybe_unused part_get_info_efi(struct blk_desc *desc, int part,
+     if (CONFIG_IS_ENABLED(PARTITION_ATTR))
+             disk_partition_set_gpt_attr(info, gpt_pte.attributes.raw);

The accessor already compiles to nothing when PARTITION_ATTR is disabled, so please drop the 'if' and call disk_partition_set_gpt_attr() directly. That is the point of having the accessor.

Regards,
Simon

A message that is not in the archive (sent off-list or not yet received): [email protected]

#18 lore raw

Re: [PATCH v1 5/8] cmd: gpt: report partition attributes via 'gpt setenv'

Hi Sumit,

Quoted 17 lines · Sumit Singh Dhami

cmd: gpt: report partition attributes via 'gpt setenv'

'gpt setenv' sets a series of gpt_partition_* environment variables describing a partition, but does not expose the GPT partition entry's attributes field.

Set a new gpt_partition_attrs variable holding the full 64-bit attributes value as a hexadecimal string, when CONFIG_PARTITION_ATTR is enabled.

cmd/gpt.c | 15 +++++++++++++--

 1 file changed, 13 insertions(+), 2 deletions(-)

cmd/gpt.c static int gpt_setenv_part_variables(struct disk_partition *pinfo, int i) · line 802

Quoted 6 lines
cmd/gpt.c +6 -0
@@ -796,6 +797,16 @@ static int gpt_setenv_part_variables(struct disk_partition *pinfo, int i)
+     if (CONFIG_IS_ENABLED(PARTITION_ATTR)) {
+             char attrs_str[19];     /* "0x" + 16 hex digits + NUL */
+
+             snprintf(attrs_str, sizeof(attrs_str), "0x%016llx",
+                     disk_partition_gpt_attr(pinfo));
+             ret = env_set("gpt_partition_attrs", attrs_str);

The other hex variables set here (gpt_partition_addr, gpt_partition_size, gpt_partition_entry) come from env_set_hex(), so they have no 0x prefix and no zero padding. This one is formatted differently, so scripts have to treat it specially. I suspect '%llx' would be better so it matches the existing variables, unless there is a reason for the prefix. What do you think?

cmd/gpt.c static int gpt_setenv_part_variables(struct disk_partition *pinfo, int i) · line 800

Quoted 6 lines
cmd/gpt.c +4 -0
@@ -796,6 +797,16 @@ static int gpt_setenv_part_variables(struct disk_partition *pinfo, int i)
+             ret = env_set("gpt_partition_attrs", attrs_str);
+             if (ret)
+                     goto fail;
+     }

Since you are adding a new feature you need a test, and this patch is the natural place since it exposes the value where a test can check it. Please can you enable CONFIG_PARTITION_ATTR in configs/sandbox_defconfig and extend test_gpt_setenv() in test/py/tests/test_gpt.py to check gpt_partition_attrs for part1 (bootable) and part2? That also covers the read path in patch 3 and, with a 'gpt write' using attrs=, the write path in patches 2 and 4, which currently have none.

Regards,
Simon

#19 lore raw
In reply to a message not in the archive

Hi Sumit,

Quoted 3 lines · Sumit Singh Dhami

Sumit Singh Dhami (8):
...
configs: add fastboot config options for writing GPT

I seem to be missing a patch? Perhaps a patchwork problem.

Quoted 2 lines

No option available in 'gpt write' to set full 64-bit gpt partition attributes.

This adds a Kconfig option and a new field plus a 'valid' flag to struct disk_partition, but the struct already holds the top 16 bits of the attributes in type_flags unconditionally, so we end up with two partial copies of the same on-disk field. Did you consider widening the existing field to the full 64 bits, without a Kconfig option? That would avoid layout differences between builds and keep the read and write paths symmetric. What do you think?

Regards,
Simon

#20 lore raw
In reply to a message not in the archive

Hi Sumit,

Quoted 12 lines · Sumit Singh Dhami

This work is done as part of Snagboot support for Qualcomm Lemans-EVK to help flash GPT via u-boot 'gpt write' command. It addresses the following issues:
- Incorrect first/last LBA computation for devices whose block size is not 512 bytes.
- No option available in 'gpt write' to set full 64-bit gpt partition attributes.
- Fastboot EP_BUFFER_SIZE is not configurable and set to 4096 bytes which overflows when long command strings are passed. (We faced this issue when we passed 'gpt write' via 'fastboot oem run' with a very long partition list).

Quoted 3 lines

The changes are followed by a final patch that adds all the config options required for writing a GPT via 'gpt write' over fastboot to qcom-snagboot.config file.

I've not looked that much into detail in this series, but enabling "fastboot oem run" feels wrong to me. "oem run" is a debug command. I don't recommend shipping any board by default with it.

Also, more generally, I don't see to understand why it needs to be implemented this way? (Sending "gpt write" via "fastboot oem run")

It seems to me that we already handle gpt flashing in fastboot.
See: drivers/fastboot/fb_mmc.c

"""

#if CONFIG_IS_ENABLED(EFI_PARTITION)
	if (strcmp(cmd, CONFIG_FASTBOOT_GPT_NAME) == 0) {
		dev_desc = fastboot_mmc_get_dev(response);
		if (!dev_desc)
			return;

		printf("%s: updating MBR, Primary and Backup GPT(s)\n",
		       __func__);
		if (is_valid_gpt_buf(dev_desc, download_buffer)) {
			printf("%s: invalid GPT - refusing to write to flash\n",
			       __func__);
			fastboot_fail("invalid GPT partition", response);
			return;
		}
		if (write_mbr_and_gpt_partitions(dev_desc, download_buffer)) {
			printf("%s: writing GPT partitions failed\n", __func__);
			fastboot_fail("writing GPT partitions failed",
				      response);
			return;
		}
		part_init(dev_desc);
		printf("........ success\n");
		fastboot_okay(NULL, response);
		return;
	}

#endif
"""

Can we explain how this is any different please ?

#21 lore raw

Hi Mattijs,

Quoted 9 lines · Mattijs Korpershoek

I've not looked that much into detail in this series, but enabling "fastboot oem run" feels wrong to me. "oem run" is a debug command. I don't recommend shipping any board by default with it.

Also, more generally, I don't see to understand why it needs to be implemented this way? (Sending "gpt write" via "fastboot oem run")

It seems to me that we already handle gpt flashing in fastboot.
See: drivers/fastboot/fb_mmc.c

...

Quoted 1 line

Can we explain how this is any different please ?

Thanks for pointing out the existing GPT handling in fb_mmc.c.

Our use case is recovery through Snagboot. Instead of flashing a GPT image pre-built on host, we need to construct the GPT on the target during recovery because some GPT header fields (for ex. LastUsableLBA) depend on the actual disk size which may not be available when a GPT image is prepared on the host.

For this reason, we use the already available u-boot's 'gpt write' command. The host passes the partition information to u-boot, and 'gpt write' constructs the corresponding GPT at runtime using the disk size reported by the device. This also allows final partition to use 'size=-', so that its size is calculated dyanmically from the remaining space.

Fastboot 'oem run' is enabled for Snagboot recovery build only, so that a script running on host such as Snagboot's Snagfactory module, can pass the 'gpt write' command along with partition info to u-boot to construct GPT in the recovery process.

Best regards
Sumit Singh Dhami