fastboot: block: Add GPT/MBR and device selection
v2 cover fastboot: block: Add GPT/MBR and device selection
This series enables GPT and MBR partition table operations for fastboot block devices and introduces device selection syntax.
Patch 1 implements device selection syntax allowing users to specify the target block device using "N:partition" format, where N is the device number.
Patch 2 adds fastboot_flash_gpt_partition_table() and fastboot_flash_mbr_partition_table() helper functions that handle flashing of GPT and MBR partition tables to block devices.
Patch 3 adds support for flashing GPT and MBR partition tables to the fastboot block backend. This enables operations like "fastboot flash gpt gpt.img" and "fastboot flash mbr mbr.img" for block devices.
Patch 4 documents the new syntax with usage examples.
CI test results
---------------
https://github.com/u-boot/u-boot/pull/941/checks
All checks have passed
---
Changes in v2:
- Seperate adding device selection syntax and GPT/MBR flashing support
into seperate patches.
- Introduce common helper functions such as
fastboot_flash_gpt_partition_table and
fastboot_flash_mbr_partition_table functions that can be used both
in fb_mmc.c and fb_block.c fot GPT and MBR flashing.
- Link to v1: https://lore.kernel.org/u-boot/[email protected]/
---
Balaji Selvanathan (4):
fastboot: block: Add device selection syntax
fastboot: Add GPT/MBR partition table flashing helper functions
fastboot: block: Add GPT/MBR partition table flashing support
doc: fastboot: Document block device selection syntax
doc/android/fastboot.rst | 41 +++++++++++++++++ drivers/fastboot/Kconfig | 4 +- drivers/fastboot/fb_block.c | 102 +++++++++++++++++++++++++++++++++++++++++-- drivers/fastboot/fb_common.c | 94 +++++++++++++++++++++++++++++++++++++++ drivers/fastboot/fb_mmc.c | 49 +++------------------ include/fastboot-internal.h | 30 +++++++++++++ 6 files changed, 272 insertions(+), 48 deletions(-)
---
base-commit: 9f61fd5b80a43ae20ba115e3a2933d47d720ab82
change-id: 20260427-fb_gpt-86d7d6595dad
Best regards,
Signature · 1 line
Balaji Selvanathan <[email protected]>
PATCH v2 1/4 fastboot: block: Add device selection syntax
Implement device selection syntax allowing users to specify the target block device using "N:partition" format, where N is the device number. When no device is specified, the default from CONFIG_FASTBOOT_FLASH_BLOCK_DEVICE_ID is used.
Modify fastboot_block_get_part_info() to use the new parsing function, enabling operations like "fastboot flash 0:boot boot.img" to write to specific devices while maintaining backward compatibility with the existing "fastboot flash boot boot.img" syntax.
Example usage:
fastboot flash 0:boot boot.img # Flash to device 0 fastboot flash 1:system system.img # Flash to device 1 fastboot flash boot boot.img # Use default device
---
Changes in v2:
- Newly created in v2
- Has only device selection syntax related changes
--- drivers/fastboot/fb_block.c | 53 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 4 deletions(-)
drivers/fastboot/fb_block.c +49 -4
@@ -11,6 +11,7 @@#include <image-sparse.h> #include <malloc.h> #include <part.h> +#include <vsprintf.h> /** * FASTBOOT_MAX_BLOCKS_ERASE - maximum blocks to erase per derase call
@@ -124,6 +125,44 @@ static lbaint_t fb_block_sparse_reserve(struct sparse_storage *info,return blkcnt; } +/** +* parse_device_partition() - Parse and validate device:partition format +* @part_name: Input string in format "N:partition" or "partition" +* @device: Output device number +* @partition_name: Output partition name pointer (can be NULL) +* +* Parses the input string to extract device number and partition name. +* If no device is specified, uses the default from config. +* Returns: 0 on success, -EINVAL if format is invalid +*/ +static int parse_device_partition (const char *part_name,int *device, +const char **partition_name) +{ +const char *colon_pos; + + *device =config_opt_enabled (CONFIG_FASTBOOT_FLASH_BLOCK , +CONFIG_FASTBOOT_FLASH_BLOCK_DEVICE_ID ,-1 ); + +/* Check for colon in partition name */ + colon_pos =strchr (part_name,':' ); + +/* Reject invalid format like ":partition" */ +if (colon_pos && colon_pos == part_name) +return -EINVAL ; + +/* Override if device:partition format detected */ +if (colon_pos && colon_pos > part_name) { + *device =simple_strtoul (part_name,NULL ,10 ); +if (partition_name) + *partition_name = colon_pos +1 ; + }else { +if (partition_name) + *partition_name = part_name; + } + +return 0 ; +} + int fastboot_block_get_part_info(const char *part_name, struct blk_desc **dev_desc, struct disk_partition *part_info,
@@ -133,25 +172,31 @@ int fastboot_block_get_part_info(const char *part_name,const char *interface =config_opt_enabled (CONFIG_FASTBOOT_FLASH_BLOCK ,CONFIG_FASTBOOT_FLASH_BLOCK_INTERFACE_NAME ,NULL ); -const int device =config_opt_enabled (CONFIG_FASTBOOT_FLASH_BLOCK , -CONFIG_FASTBOOT_FLASH_BLOCK_DEVICE_ID ,-1 ); +int device; +const char *partition_name;if (!part_name || !strcmp (part_name,"" )) {fastboot_fail ("partition not given" , response);return -ENOENT ; } +if (!interface || !strcmp (interface,"" )) {fastboot_fail ("block interface isn't provided" , response);return -EINVAL ; } +if (parse_device_partition (part_name, &device, &partition_name) <0 ) { +fastboot_fail ("invalid partition name format" , response); +return -EINVAL ; + } + *dev_desc =blk_get_dev (interface, device); -if (!dev_desc) { +if (!*dev_desc) {fastboot_fail ("no such device" , response);return -ENODEV ; } - ret =part_get_info_by_name (*dev_desc, part_name, part_info); + ret =part_get_info_by_name (*dev_desc, partition_name, part_info);if (ret <0 )fastboot_fail ("failed to get partition info" , response);
Signature · 1 line
2.34.1
Re: [PATCH v2 1/4] fastboot: block: Add device selection syntax
Hi Balaji,
Quoted 24 lines · Balaji Selvanathan
fastboot: block: Add device selection syntax
Implement device selection syntax allowing users to specify the target block device using 'N:partition' format, where N is the device number. When no device is specified, the default from
CONFIG_FASTBOOT_FLASH_BLOCK_DEVICE_IDis used.Modify
fastboot_block_get_part_info()to use the new parsing function, enabling operations like "fastboot flash 0:boot boot.img" to write to specific devices while maintaining backward compatibility with the existing "fastboot flash boot boot.img" syntax.Example usage:
fastboot flash 0:boot boot.img # Flash to device 0 fastboot flash 1:system system.img # Flash to device 1 fastboot flash boot boot.img # Use default deviceSigned-off-by Balaji Selvanathan <[email protected]>
drivers/fastboot/fb_block.c| 53 +++++++++++++++++++++++++++++++++++++++++----1 file changed, 49 insertions(+), 4 deletions(-)
drivers/fastboot/fb_block.c int fastboot_block_get_part_info(const char *part_name, · line 176
Quoted 6 lines
drivers/fastboot/fb_block.c +1
-1@@ -133,25 +172,31 @@ int fastboot_block_get_part_info(const char *part_name, *dev_desc =blk_get_dev (interface, device); -if (!dev_desc) { +if (!*dev_desc) {fastboot_fail ("no such device" , response);return -ENODEV ; }
This is a real bug fix - the old test could never fail since dev_desc is the address of a local pointer - but it is unrelated to the device-selection syntax. Please split it into its own patch at the start of the series so it is easy to backport.
drivers/fastboot/fb_block.c static lbaint_t fb_block_sparse_reserve(struct sparse_storage *info, · line 127
Quoted 5 lines
drivers/fastboot/fb_block.c +3
-0@@ -124,6 +125,44 @@ static lbaint_t fb_block_sparse_reserve(struct sparse_storage *info, +/* Override if device:partition format detected */ +if (colon_pos && colon_pos > part_name) { + *device =simple_strtoul (part_name,NULL ,10 );
simple_strtoul() with a NULL endp silently accepts anything - 'foo:boot' parses as device 0 and quietly writes to the default device, which is exactly the surprise the new syntax is meant to avoid. Please pass an endp and reject input where the consumed length doesn't reach colon_pos, so a malformed prefix becomes -EINVAL. dectoul() is preferred over simple_strtoul(..., 10) in new code.
drivers/fastboot/fb_block.c static lbaint_t fb_block_sparse_reserve(struct sparse_storage *info, · line 126
Quoted 4 lines
drivers/fastboot/fb_block.c +2
-0@@ -124,6 +125,44 @@ static lbaint_t fb_block_sparse_reserve(struct sparse_storage *info, +static int parse_device_partition (const char *part_name,int *device, +const char **partition_name)
U-Boot already uses dev:partnum for partition numbers (part_get_info_by_dev_and_name_or_num() - '0:1' means device 0, partition 1) and dev#partname for names. Reusing ':' for a name lookup means '0:1' becomes ambiguous on boards that label partitions numerically. How about '#' instead, to match the rest of the disk layer?
drivers/fastboot/fb_block.c static lbaint_t fb_block_sparse_reserve(struct sparse_storage *info, · line 125
Quoted 3 lines
drivers/fastboot/fb_block.c +1
-0@@ -124,6 +125,44 @@ static lbaint_t fb_block_sparse_reserve(struct sparse_storage *info, +* @partition_name: Output partition name pointer (can be NULL)
Just to clarify, the kernel-doc says partition_name can be NULL but every caller in this patch passes non-NULL - the NULL handling only becomes useful in patch 3, so please move it to the patch that needs it, so each patch is self-contained.
Regards,
Simon
PATCH v2 2/4 fastboot: Add GPT/MBR partition table flashing helper functions
In reply to Balaji SelvanathanAdd fastboot_flash_gpt_partition_table() and fastboot_flash_mbr_partition_table() helper functions that handle flashing of GPT and MBR partition tables to block devices.
The MMC backend now uses these helper functions for GPT and MBR operations, simplifying the code while maintaining the same functionality.
---
Changes in v2:
- Newly created in v2
- Adds fastboot_flash_gpt_partition_table() and fastboot_flash_mbr_partition_table() helper functions
- Update fb_mmc.c to use these functions
--- drivers/fastboot/fb_common.c | 94 ++++++++++++++++++++++++++++++++++++++++++++ drivers/fastboot/fb_mmc.c | 49 ++++------------------- include/fastboot-internal.h | 30 ++++++++++++++ 3 files changed, 131 insertions(+), 42 deletions(-)
drivers/fastboot/fb_common.c +94 -0
@@ -245,3 +245,97 @@ void fastboot_init(void *buf_addr, u32 buf_size)fastboot_set_progress_callback (NULL ); } + +#if CONFIG_IS_ENABLED (EFI_PARTITION ) +/** +* fastboot_flash_gpt_partition_table() - Flash GPT partition table +* @interface: Block interface name (e.g., "mmc", "scsi") +* @device: Device number +* @download_buffer: Buffer containing GPT data +* @response: Fastboot response buffer +*/ +void fastboot_flash_gpt_partition_table (const char *interface, +int device, +void *download_buffer, +char *response) +{ +struct blk_desc *dev_desc; + +if (!interface || !strcmp (interface,"" )) { +fastboot_fail ("block interface isn't provided" , response); +return ; + } + + dev_desc =blk_get_dev (interface, device); +if (!dev_desc) { +fastboot_fail ("no such device" , response); +return ; + } + +printf ("%s: updating MBR, Primary and Backup GPT(s) on %s device %d\n" , + __func__, interface, dev_desc->devnum); + +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); +} +#endif + +#if CONFIG_IS_ENABLED (DOS_PARTITION ) +/** +* fastboot_flash_mbr_partition_table() - Flash MBR partition table +* @interface: Block interface name (e.g., "mmc", "scsi") +* @device: Device number +* @download_buffer: Buffer containing MBR data +* @response: Fastboot response buffer +*/ +void fastboot_flash_mbr_partition_table (const char *interface, +int device, +void *download_buffer, +char *response) +{ +struct blk_desc *dev_desc; + +if (!interface || !strcmp (interface,"" )) { +fastboot_fail ("block interface isn't provided" , response); +return ; + } + + dev_desc =blk_get_dev (interface, device); +if (!dev_desc) { +fastboot_fail ("no such device" , response); +return ; + } + +printf ("%s: updating MBR on %s device %d\n" , __func__, interface, + dev_desc->devnum); + +if (is_valid_dos_buf (download_buffer)) { +printf ("%s: invalid MBR - refusing to write to flash\n" , __func__); +fastboot_fail ("invalid MBR partition" , response); +return ; + } + +if (write_mbr_sector (dev_desc, download_buffer)) { +printf ("%s: writing MBR partition failed\n" , __func__); +fastboot_fail ("writing MBR partition failed" , response); +return ; + } + +part_init (dev_desc); +printf ("........ success\n" ); +fastboot_okay (NULL , response); +} +#endif
drivers/fastboot/fb_mmc.c +7 -42
67 lines not on this page · raw message
include/fastboot-internal.h +30 -0
@@ -40,4 +40,34 @@ void fastboot_getvar_all(char *response);*/ void fastboot_getvar (char *cmd_parameter,char *response); +#if CONFIG_IS_ENABLED (EFI_PARTITION ) +/** +* fastboot_flash_gpt_partition_table() - Flash GPT partition table +* +* @interface: Block interface name (e.g., "mmc", "scsi") +* @device: Device number +* @download_buffer: Buffer containing GPT data +* @response: Pointer to fastboot response buffer +*/ +void fastboot_flash_gpt_partition_table (const char *interface, +int device, +void *download_buffer, +char *response); +#endif + +#if CONFIG_IS_ENABLED (DOS_PARTITION ) +/** +* fastboot_flash_mbr_partition_table() - Flash MBR partition table +* +* @interface: Block interface name (e.g., "mmc", "scsi") +* @device: Device number +* @download_buffer: Buffer containing MBR data +* @response: Pointer to fastboot response buffer +*/ +void fastboot_flash_mbr_partition_table (const char *interface, +int device, +void *download_buffer, +char *response); +#endif +#endif
Signature · 1 line
2.34.1
Re: [PATCH v2 2/4] fastboot: Add GPT/MBR partition table flashing helper functions
Hi Balaji,
Quoted 19 lines · Balaji Selvanathan
fastboot: Add GPT/MBR partition table flashing helper functions
Add
fastboot_flash_gpt_partition_table()andfastboot_flash_mbr_partition_table()helper functions that handle flashing of GPT and MBR partition tables to block devices.The MMC backend now uses these helper functions for GPT and MBR operations, simplifying the code while maintaining the same functionality.
Signed-off-by Balaji Selvanathan <[email protected]>
drivers/fastboot/fb_common.c| 94 ++++++++++++++++++++++++++++++++++++++++++++drivers/fastboot/fb_mmc.c | 49 ++++------------------- include/fastboot-internal.h | 30 ++++++++++++++ 3 files changed, 131 insertions(+), 42 deletions(-)
drivers/fastboot/fb_common.c void fastboot_init(void *buf_addr, u32 buf_size) · line 249
Quoted 5 lines
drivers/fastboot/fb_common.c +5
-0@@ -245,3 +245,97 @@ void fastboot_init(void *buf_addr, u32 buf_size) + dev_desc =blk_get_dev (interface, device); +if (!dev_desc) { +fastboot_fail ("no such device" , response); +return ; + }
Looks like a regression for the MMC path: the current fastboot_mmc_get_dev() rejects dev_desc->type == DEV_TYPE_UNKNOWN (mmc driver present but no card) and reports 'invalid mmc device'. That check is gone after this refactor, so an unprobed mmc falls through to is_valid_gpt_buf() / write_mbr_and_gpt_partitions() with an unusable dev_desc - please add the DEV_TYPE_UNKNOWN check in both helpers so the common path is at least as strict as the code it replaces.
Quoted 4 lines
drivers/fastboot/fb_common.c +2
-0@@ -245,3 +245,97 @@ void fastboot_init(void *buf_addr, u32 buf_size) +#if CONFIG_IS_ENABLED (EFI_PARTITION ) +/**
drivers/fastboot/fb_common.c void fastboot_init(void *buf_addr, u32 buf_size) · line 256
Quoted 10 lines
drivers/fastboot/fb_common.c +10
-0+* fastboot_flash_gpt_partition_table() - Flash GPT partition table +* @interface: Block interface name (e.g., 'mmc', 'scsi') +* @device: Device number +* @download_buffer: Buffer containing GPT data +* @response: Fastboot response buffer +*/ +void fastboot_flash_gpt_partition_table (const char *interface, +int device, +void *download_buffer, +char *response)
The two helpers are almost identical - only is_valid_*_buf(), write_mbr_*() and a couple of printed strings differ. Please factor the common parts (interface check, blk_get_dev(), DEV_TYPE_UNKNOWN check, part_init() + okay) and have the GPT and MBR variants supply just the validate/write step. As written, the fail-paths are duplicated and will drift over time.
drivers/fastboot/fb_common.c void fastboot_init(void *buf_addr, u32 buf_size) · line 246
Quoted 4 lines
drivers/fastboot/fb_common.c +2
-0@@ -245,3 +245,97 @@ void fastboot_init(void *buf_addr, u32 buf_size) +if (is_valid_gpt_buf (dev_desc, download_buffer)) { +printf ("%s: invalid GPT - refusing to write to flash\n" , __func__);
fb_common.c does not include <part.h> or <blk.h> even though it now calls blk_get_dev(), is_valid_gpt_buf(), write_mbr_and_gpt_partitions(), is_valid_dos_buf(), write_mbr_sector() and part_init(). It builds today via a transitive include, but let's add explicit includes.
drivers/fastboot/fb_mmc.c int fastboot_mmc_get_part_info(const char *part_name, · line 343
Quoted 4 lines
drivers/fastboot/fb_mmc.c +1
-1@@ -343,7 +343,7 @@ int fastboot_mmc_get_part_info(const char *part_name, -static struct blk_desc *fastboot_mmc_get_dev (char *response) +static struct blk_desc __maybe_unused *fastboot_mmc_get_dev (char *response)
The convention is 'static __maybe_unused struct blk_desc *fastboot_mmc_get_dev(...)'
drivers/fastboot/fb_common.c void fastboot_init(void *buf_addr, u32 buf_size) · line 248
Quoted 6 lines
drivers/fastboot/fb_common.c +4
-0@@ -245,3 +245,97 @@ void fastboot_init(void *buf_addr, u32 buf_size) +if (!interface || !strcmp (interface,"" )) { +fastboot_fail ("block interface isn't provided" , response); +return ; + }
The MMC caller passes the literal 'mmc', so this branch is dead on that path. The check is really for the block backend in patch 3, where the interface comes from CONFIG_FASTBOOT_FLASH_BLOCK_INTERFACE_NAME. That validation belongs in the block caller (alongside the parse_device_partition() call), not duplicated in both common helpers
- same reason fastboot_block_get_part_info() already does the check itself.
Regards,
Simon
PATCH v2 3/4 fastboot: block: Add GPT/MBR partition table flashing support
In reply to Balaji SelvanathanAdd support for flashing GPT and MBR partition tables to the fastboot block backend. This enables operations like "fastboot flash gpt gpt.img" and "fastboot flash mbr mbr.img" for block devices.
The implementation validates partition table names and rejects invalid input formats such as ":gpt" or ":mbr" where the device prefix is missing. Valid formats include "gpt", "mbr", "0:gpt", and "1:mbr".
Update Kconfig dependencies to allow FASTBOOT_GPT_NAME and FASTBOOT_MBR_NAME to work with both MMC and block backends.`
---
Changes in v2:
- Newly created in v2
- Adds GPT and MBR flash support to fastboot block codes
--- drivers/fastboot/Kconfig | 4 ++-- drivers/fastboot/fb_block.c | 49 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-)
drivers/fastboot/Kconfig +2 -2
@@ -227,7 +227,7 @@ config FASTBOOT_FLASH_BLOCK_DEVICE_ID config FASTBOOT_GPT_NAME string "Target name for updating GPT" - depends on FASTBOOT_FLASH_MMC && EFI_PARTITION + depends on (FASTBOOT_FLASH_MMC || FASTBOOT_FLASH_BLOCK) && EFI_PARTITION default "gpt" help The fastboot "flash" command supports writing the downloaded
@@ -240,7 +240,7 @@ config FASTBOOT_GPT_NAME config FASTBOOT_MBR_NAME string "Target name for updating MBR" - depends on FASTBOOT_FLASH_MMC && DOS_PARTITION + depends on (FASTBOOT_FLASH_MMC || FASTBOOT_FLASH_BLOCK) && DOS_PARTITION default "mbr" help The fastboot "flash" command allows to write the downloaded image
drivers/fastboot/fb_block.c +49 -0
61 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH v2 3/4] fastboot: block: Add GPT/MBR partition table flashing support
Hi Balaji,
Quoted 22 lines · Balaji Selvanathan
fastboot: block: Add GPT/MBR partition table flashing support
Add support for flashing GPT and MBR partition tables to the fastboot block backend. This enables operations like "fastboot flash gpt gpt.img" and "fastboot flash mbr mbr.img" for block devices.
The implementation validates partition table names and rejects invalid input formats such as ':gpt' or ':mbr' where the device prefix is missing. Valid formats include 'gpt', 'mbr', '0:gpt', and '1:mbr'.
Update
Kconfigdependencies to allowFASTBOOT_GPT_NAMEandFASTBOOT_MBR_NAMEto work with both MMC and block backends.Signed-off-by Balaji Selvanathan <[email protected]>
drivers/fastboot/Kconfig| 4 ++--drivers/fastboot/fb_block.c | 49 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-)
drivers/fastboot/Kconfig config FASTBOOT_FLASH_BLOCK_DEVICE_ID · line 228
Quoted 2 lines
drivers/fastboot/Kconfig +2
-0@@ -227,7 +227,7 @@ config FASTBOOT_FLASH_BLOCK_DEVICE_ID +Update Kconfig dependencies to allow FASTBOOT_GPT_NAME and +FASTBOOT_MBR_NAME to work with both MMC and block backends.`
Stray backtick at the end of this paragraph - please drop it.
Quoted 19 lines
drivers/fastboot/fb_block.c +17
-0@@ -361,6 +382,34 @@ void fastboot_block_flash_write(const char *part_name, void *download_buffer, +#if CONFIG_IS_ENABLED (EFI_PARTITION ) +if (is_partition_table_name (part_name,CONFIG_FASTBOOT_GPT_NAME )) { +int device; +const char *interface =config_opt_enabled (CONFIG_FASTBOOT_FLASH_BLOCK , +CONFIG_FASTBOOT_FLASH_BLOCK_INTERFACE_NAME , +NULL ); + +parse_device_partition (part_name, &device,NULL ); +fastboot_flash_gpt_partition_table (interface, device, + download_buffer, response); +return ; + } +#endif + +#if CONFIG_IS_ENABLED (DOS_PARTITION ) +if (is_partition_table_name (part_name,CONFIG_FASTBOOT_MBR_NAME )) { +int device;
drivers/fastboot/fb_block.c void fastboot_block_flash_write(const char *part_name, void *download_buffer, · line 408
Quoted 10 lines
drivers/fastboot/fb_block.c +10
-0+const char *interface =config_opt_enabled (CONFIG_FASTBOOT_FLASH_BLOCK , +CONFIG_FASTBOOT_FLASH_BLOCK_INTERFACE_NAME , +NULL ); + +parse_device_partition (part_name, &device,NULL ); +fastboot_flash_mbr_partition_table (interface, device, + download_buffer, response); + return; + } +#endif
The two arms are near-identical and both repeat the interface lookup that fastboot_block_get_part_info() already does. Please factor the interface/device resolution into a small helper (or move it above the #ifs) so the GPT and MBR branches reduce to the is_partition_table_name() check and the helper call.
drivers/fastboot/fb_block.c void fastboot_block_flash_write(const char *part_name, void *download_buffer, · line 384
Quoted 5 lines
drivers/fastboot/fb_block.c +3
-0@@ -361,6 +382,34 @@ void fastboot_block_flash_write(const char *part_name, void *download_buffer, +parse_device_partition (part_name, &device,NULL ); +fastboot_flash_gpt_partition_table (interface, device, + download_buffer, response);
The return value of parse_device_partition() is discarded...is_partition_table_name() happens to filter out ':gpt' today, so this is safe by construction, but the coupling is pretty fragile - please check the return and fastboot_fail() on -EINVAL, or add a comment explaining why it cannot fail. Same in the MBR branch.
Regards,
Simon
PATCH v2 4/4 doc: fastboot: Document block device selection syntax
In reply to Balaji SelvanathanAdd documentation for the device selection syntax in fastboot block device operations. Users can now specify target devices using "N:partition" format where N is the device number.
Document usage examples for regular partition operations like "fastboot flash 0:boot boot.img" and partition table operations like "fastboot flash 1:gpt gpt.img". When no device number is specified, the default from CONFIG_FASTBOOT_FLASH_BLOCK_DEVICE_ID is used.
---
Changes in v2:
- No changes
--- doc/android/fastboot.rst | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)
doc/android/fastboot.rst +41 -0
@@ -147,6 +147,38 @@ The Fastboot implementation in U-Boot allows to write images into disk partitions. Target partitions are referred on the host computer by their names. +Device Selection for Block Devices +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +When using ``FASTBOOT_FLASH_BLOCK``, you can specify which block device to +target by prefixing the partition name with the device number and a colon. + +Syntax:: + + <device_number>:<partition_name> + +Examples:: + + fastboot flash 0:boot boot.img # Flash to device 0, partition "boot" + fastboot flash 1:system system.img # Flash to device 1, partition "system" + fastboot flash 0:gpt gpt.img # Write GPT to device 0 + fastboot flash 1:mbr mbr.img # Write MBR to device 1 + +If no device number is specified, the default device from +``CONFIG_FASTBOOT_FLASH_BLOCK_DEVICE_ID`` is used:: + + fastboot flash boot boot.img # Uses default device + +This syntax is supported for: + +* Regular partition flashing +* GPT partition table updates (``gpt`` or ``N:gpt``) +* MBR partition table updates (``mbr`` or ``N:mbr``) +* Partition erasing operations + +Partition Name Formats +^^^^^^^^^^^^^^^^^^^^^^ + For GPT/EFI the respective partition name is used. For MBR the partitions are referred by generic names according to the
@@ -186,6 +218,15 @@ configuration options: CONFIG_FASTBOOT_GPT_NAME CONFIG_FASTBOOT_MBR_NAME +When using block devices (``FASTBOOT_FLASH_BLOCK``), you can specify the target +device by prefixing with the device number:: + + fastboot flash 0:gpt gpt.img # Write GPT to device 0 + fastboot flash 1:mbr mbr.img # Write MBR to device 1 + +If no device number is specified, the default device from +``CONFIG_FASTBOOT_FLASH_BLOCK_DEVICE_ID`` is used. + In Action ---------
Signature · 1 line
2.34.1
Re: [PATCH v2 4/4] doc: fastboot: Document block device selection syntax
Hi Balaji,
Quoted 20 lines · Balaji Selvanathan
doc: fastboot: Document block device selection syntax
Add documentation for the device selection syntax in fastboot block device operations. Users can now specify target devices using 'N:partition' format where N is the device number.
Document usage examples for regular partition operations like "fastboot flash 0:boot boot.img" and partition table operations like "fastboot flash 1:gpt gpt.img". When no device number is specified, the default from
CONFIG_FASTBOOT_FLASH_BLOCK_DEVICE_IDis used.Reviewed-by Mattijs Korpershoek <[email protected]>Signed-off-by Balaji Selvanathan <[email protected]>
doc/android/fastboot.rst| 41 +++++++++++++++++++++++++++++++++++++++++1 file changed, 41 insertions(+)
doc/android/fastboot.rst The Fastboot implementation in U-Boot allows to write images into disk · line 151
Quoted 5 lines
doc/android/fastboot.rst +2
-0@@ -147,6 +147,38 @@ The Fastboot implementation in U-Boot allows to write images into disk partitions. Target partitions are referred on the host computer by their names. +Device Selection for Block Devices +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Other subsection headings in this file use sentence case ('USB configuration', 'Partition aliases', etc). Please rename to 'Device selection for block devices' to match - and likewise 'Partition name formats' below.
doc/android/fastboot.rst configuration options: · line 228
Quoted 13 lines
doc/android/fastboot.rst +8
-0@@ -186,6 +218,15 @@ configuration options: CONFIG_FASTBOOT_GPT_NAME CONFIG_FASTBOOT_MBR_NAME +When using block devices (`FASTBOOT_FLASH_BLOCK), you can specify the target +device by prefixing with the device number:: + + fastboot flash 0:gpt gpt.img # Write GPT to device 0 + fastboot flash 1:mbr mbr.img # Write MBR to device 1 + +If no device number is specified, the default device from +CONFIG_FASTBOOT_FLASH_BLOCK_DEVICE_ID is used.
This duplicates what was added a few paragraphs up in 'Device Selection for Block Devices' (same '0:gpt'/'1:mbr' examples and the same default-device sentence). How about dropping this block and adding a one-liner cross-reference, e.g. 'See above for the N:partition syntax when using FASTBOOT_FLASH_BLOCK'.
doc/android/fastboot.rst The Fastboot implementation in U-Boot allows to write images into disk · line 152
Quoted 8 lines
doc/android/fastboot.rst +6
-0@@ -147,6 +147,38 @@ The Fastboot implementation in U-Boot allows to write images into disk +This syntax is supported for: + +* Regular partition flashing +* GPT partition table updates (gpt or N:gpt) +* MBR partition table updates (mbr or N:mbr`) +* Partition erasing operations
Just to check, does erase actually go through the same parser? It does today via fastboot_block_get_part_info(), but worth confirming it's exercised since the commit message only mentions flash.
Regards,
Simon
Hi Balaji,
Quoted 3 lines · Balaji Selvanathan
Patch 2 adds
fastboot_flash_gpt_partition_table()andfastboot_flash_mbr_partition_table()helper functions that handle flashing of GPT and MBR partition tables to block devices.
Patch 2 also refactors fb_mmc.c to use the new helpers — please mention the MMC conversion here in v3.
Quoted 2 lines
Patch 1 implements device selection syntax allowing users to specify the target block device using 'N:partition' format
Since you are adding a new feature (the N:partition parser, plus GPT/MBR flashing on the block backend), please add test coverage. See test/dm/fastboot.c which already exercises fastboot_mmc_get_part_info() - you can add cases there for the block
path: a successful '0:foo' parse, the bare 'foo' fallback to the default device, and rejection of a leading-colon name like ':gpt'. Otherwise the parser and is_partition_table_name() interaction are easy to break in future refactors.
BTW the v2 changelog has 'Seperate' (twice) and 'fot' - please tidy this up.
Regards,
Simon