[PATCH v2 1/4] fastboot: block: Add device selection syntax
Simon Glass
sjg at chromium.org
Tue Apr 28 20:18:42 CEST 2026
Hi Balaji,
On 2026-04-27T12:06:41, Balaji Selvanathan
<balaji.selvanathan at oss.qualcomm.com> wrote:
> 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
>
> Signed-off-by: Balaji Selvanathan <balaji.selvanathan at oss.qualcomm.com>
>
> drivers/fastboot/fb_block.c | 53 +++++++++++++++++++++++++++++++++++++++++----
> 1 file changed, 49 insertions(+), 4 deletions(-)
> diff --git a/drivers/fastboot/fb_block.c b/drivers/fastboot/fb_block.c
> @@ -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.
> diff --git a/drivers/fastboot/fb_block.c b/drivers/fastboot/fb_block.c
> @@ -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.
> diff --git a/drivers/fastboot/fb_block.c b/drivers/fastboot/fb_block.c
> @@ -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?
> diff --git a/drivers/fastboot/fb_block.c b/drivers/fastboot/fb_block.c
> @@ -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
More information about the U-Boot
mailing list