Skip to content

Commit 7b9f96a

Browse files
committed
fastboot: Add "fastboot device" command for runtime block device selection
Add the ability to change the fastboot flash target device at runtime without recompiling. This is useful for: - Platforms with multiple storage options (eMMC + UFS + NVMe) - Development and testing scenarios - Recovery situations where the default device is unavailable New command syntax: fastboot device <interface> <dev> - set flash interface and device fastboot device - show current interface and device Implementation details: - Add fastboot_block_set_interface() and fastboot_block_set_device() functions to set runtime values - Add fastboot_block_get_interface() and fastboot_block_get_device() getters that return runtime value if set, otherwise fall back to Kconfig defaults - Update fb_block.c to use the new getter functions - Add command handler gated by CONFIG_FASTBOOT_FLASH_BLOCK Example usage: => fastboot device scsi 0 Set fastboot block interface to 'scsi', device to 0 => fastboot usb 0 (now flashing targets SCSI device 0 instead of default) Change-Id: 7b54f839-5659-4aaf-b58f-d6107e08a24d Signed-off-by: Anton Burticica <mouse@ya.ru>
1 parent cb2e54d commit 7b9f96a

File tree

3 files changed

+122
-6
lines changed

3 files changed

+122
-6
lines changed

cmd/fastboot.c

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
#include <watchdog.h>
1616
#include <linux/printk.h>
1717
#include <linux/stringify.h>
18+
#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_BLOCK)
19+
#include <fb_block.h>
20+
#endif
1821

1922
#if CONFIG_IS_ENABLED(NET)
2023
static int do_fastboot_udp(int argc, char *const argv[],
@@ -119,6 +122,38 @@ static int do_fastboot_usb(int argc, char *const argv[],
119122
return ret;
120123
}
121124

125+
#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_BLOCK)
126+
static int do_fastboot_device(int argc, char *const argv[])
127+
{
128+
const char *interface;
129+
int device;
130+
char *endp;
131+
132+
if (argc < 3) {
133+
/* Print current settings */
134+
interface = fastboot_block_get_interface();
135+
device = fastboot_block_get_device();
136+
printf("fastboot block interface: %s, device: %d\n",
137+
interface && *interface ? interface : "(not set)", device);
138+
return CMD_RET_SUCCESS;
139+
}
140+
141+
interface = argv[1];
142+
device = simple_strtoul(argv[2], &endp, 0);
143+
if (*endp != '\0') {
144+
pr_err("Error: Invalid device number\n");
145+
return CMD_RET_FAILURE;
146+
}
147+
148+
fastboot_block_set_interface(interface);
149+
fastboot_block_set_device(device);
150+
printf("Set fastboot block interface to '%s', device to %d\n",
151+
interface, device);
152+
153+
return CMD_RET_SUCCESS;
154+
}
155+
#endif
156+
122157
static int do_fastboot(struct cmd_tbl *cmdtp, int flag, int argc,
123158
char *const argv[])
124159
{
@@ -154,6 +189,14 @@ static int do_fastboot(struct cmd_tbl *cmdtp, int flag, int argc,
154189
;
155190
}
156191

192+
#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_BLOCK)
193+
if (argc > 0 && !strcmp(argv[1], "device")) {
194+
argv++;
195+
argc--;
196+
return do_fastboot_device(argc, argv);
197+
}
198+
#endif
199+
157200
/* Handle case when USB controller param is just '-' */
158201
if (argc == 1) {
159202
pr_err("Error: Incorrect USB controller index\n");
@@ -179,7 +222,18 @@ static int do_fastboot(struct cmd_tbl *cmdtp, int flag, int argc,
179222
U_BOOT_CMD(
180223
fastboot, CONFIG_SYS_MAXARGS, 1, do_fastboot,
181224
"run as a fastboot usb or udp device",
182-
"[-l addr] [-s size] usb <controller> | udp\n"
225+
"[-l addr] [-s size] usb <controller>"
226+
#if IS_ENABLED(CONFIG_TCP_FUNCTION_FASTBOOT)
227+
" | tcp"
228+
#endif
229+
#if IS_ENABLED(CONFIG_UDP_FUNCTION_FASTBOOT)
230+
" | udp"
231+
#endif
232+
#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_BLOCK)
233+
"\nfastboot device <interface> <dev> - set flash interface and device"
234+
"\nfastboot device - show current interface and device"
235+
#endif
236+
"\n"
183237
"\taddr - address of buffer used during data transfers ("
184238
__stringify(CONFIG_FASTBOOT_BUF_ADDR) ")\n"
185239
"\tsize - size of buffer used during data transfers ("

drivers/fastboot/fb_block.c

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,43 @@
1212
#include <malloc.h>
1313
#include <part.h>
1414

15+
/**
16+
* fastboot_block_interface - runtime block interface name
17+
*/
18+
static char fastboot_block_interface[16];
19+
20+
/**
21+
* fastboot_block_device - runtime block device ID
22+
*/
23+
static int fastboot_block_device = -1;
24+
25+
void fastboot_block_set_interface(const char *interface)
26+
{
27+
strncpy(fastboot_block_interface, interface, 16);
28+
}
29+
30+
const char *fastboot_block_get_interface(void)
31+
{
32+
if (*fastboot_block_interface)
33+
return fastboot_block_interface;
34+
return config_opt_enabled(CONFIG_FASTBOOT_FLASH_BLOCK,
35+
CONFIG_FASTBOOT_FLASH_BLOCK_INTERFACE_NAME,
36+
NULL);
37+
}
38+
39+
void fastboot_block_set_device(int device)
40+
{
41+
fastboot_block_device = device;
42+
}
43+
44+
int fastboot_block_get_device(void)
45+
{
46+
if (fastboot_block_device >= 0)
47+
return fastboot_block_device;
48+
return config_opt_enabled(CONFIG_FASTBOOT_FLASH_BLOCK,
49+
CONFIG_FASTBOOT_FLASH_BLOCK_DEVICE_ID, -1);
50+
}
51+
1552
/**
1653
* FASTBOOT_MAX_BLOCKS_ERASE - maximum blocks to erase per derase call
1754
*
@@ -125,11 +162,8 @@ int fastboot_block_get_part_info(const char *part_name,
125162
char *response)
126163
{
127164
int ret;
128-
const char *interface = config_opt_enabled(CONFIG_FASTBOOT_FLASH_BLOCK,
129-
CONFIG_FASTBOOT_FLASH_BLOCK_INTERFACE_NAME,
130-
NULL);
131-
const int device = config_opt_enabled(CONFIG_FASTBOOT_FLASH_BLOCK,
132-
CONFIG_FASTBOOT_FLASH_BLOCK_DEVICE_ID, -1);
165+
const char *interface = fastboot_block_get_interface();
166+
const int device = fastboot_block_get_device();
133167

134168
if (!part_name || !strcmp(part_name, "")) {
135169
fastboot_fail("partition not given", response);

include/fb_block.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,32 @@ void fastboot_block_write_sparse_image(struct blk_desc *dev_desc, struct disk_pa
102102
void fastboot_block_flash_write(const char *part_name, void *download_buffer,
103103
u32 download_bytes, char *response);
104104

105+
/**
106+
* fastboot_block_set_interface() - Set the block interface name
107+
*
108+
* @interface: Interface name (e.g., "mmc", "scsi", "nvme")
109+
*/
110+
void fastboot_block_set_interface(const char *interface);
111+
112+
/**
113+
* fastboot_block_get_interface() - Get the block interface name
114+
*
115+
* Return: Interface name, or config default if not set
116+
*/
117+
const char *fastboot_block_get_interface(void);
118+
119+
/**
120+
* fastboot_block_set_device() - Set the block device ID
121+
*
122+
* @device: Device ID number
123+
*/
124+
void fastboot_block_set_device(int device);
125+
126+
/**
127+
* fastboot_block_get_device() - Get the block device ID
128+
*
129+
* Return: Device ID, or config default if not set
130+
*/
131+
int fastboot_block_get_device(void);
132+
105133
#endif // _FB_BLOCK_H_

0 commit comments

Comments
 (0)