Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 55 additions & 1 deletion cmd/fastboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
#include <watchdog.h>
#include <linux/printk.h>
#include <linux/stringify.h>
#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_BLOCK)
#include <fb_block.h>
#endif

#if CONFIG_IS_ENABLED(NET)
static int do_fastboot_udp(int argc, char *const argv[],
Expand Down Expand Up @@ -119,6 +122,38 @@ static int do_fastboot_usb(int argc, char *const argv[],
return ret;
}

#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_BLOCK)
static int do_fastboot_device(int argc, char *const argv[])
{
const char *interface;
int device;
char *endp;

if (argc < 3) {
/* Print current settings */
interface = fastboot_block_get_interface();
device = fastboot_block_get_device();
printf("fastboot block interface: %s, device: %d\n",
interface && *interface ? interface : "(not set)", device);
return CMD_RET_SUCCESS;
}

interface = argv[1];
device = simple_strtoul(argv[2], &endp, 0);
if (*endp != '\0') {
pr_err("Error: Invalid device number\n");
return CMD_RET_FAILURE;
}

fastboot_block_set_interface(interface);
fastboot_block_set_device(device);
printf("Set fastboot block interface to '%s', device to %d\n",
interface, device);

return CMD_RET_SUCCESS;
}
#endif

static int do_fastboot(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
{
Expand Down Expand Up @@ -154,6 +189,14 @@ static int do_fastboot(struct cmd_tbl *cmdtp, int flag, int argc,
;
}

#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_BLOCK)
if (argc > 0 && !strcmp(argv[1], "device")) {
argv++;
argc--;
return do_fastboot_device(argc, argv);
}
#endif

/* Handle case when USB controller param is just '-' */
if (argc == 1) {
pr_err("Error: Incorrect USB controller index\n");
Expand All @@ -179,7 +222,18 @@ static int do_fastboot(struct cmd_tbl *cmdtp, int flag, int argc,
U_BOOT_CMD(
fastboot, CONFIG_SYS_MAXARGS, 1, do_fastboot,
"run as a fastboot usb or udp device",
"[-l addr] [-s size] usb <controller> | udp\n"
"[-l addr] [-s size] usb <controller>"
#if IS_ENABLED(CONFIG_TCP_FUNCTION_FASTBOOT)
" | tcp"
#endif
#if IS_ENABLED(CONFIG_UDP_FUNCTION_FASTBOOT)
" | udp"
#endif
#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_BLOCK)
"\nfastboot device <interface> <dev> - set flash interface and device"
"\nfastboot device - show current interface and device"
#endif
"\n"
"\taddr - address of buffer used during data transfers ("
__stringify(CONFIG_FASTBOOT_BUF_ADDR) ")\n"
"\tsize - size of buffer used during data transfers ("
Expand Down
44 changes: 39 additions & 5 deletions drivers/fastboot/fb_block.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,43 @@
#include <malloc.h>
#include <part.h>

/**
* fastboot_block_interface - runtime block interface name
*/
static char fastboot_block_interface[16];

/**
* fastboot_block_device - runtime block device ID
*/
static int fastboot_block_device = -1;

void fastboot_block_set_interface(const char *interface)
{
strncpy(fastboot_block_interface, interface, 16);
}

const char *fastboot_block_get_interface(void)
{
if (*fastboot_block_interface)
return fastboot_block_interface;
return config_opt_enabled(CONFIG_FASTBOOT_FLASH_BLOCK,
CONFIG_FASTBOOT_FLASH_BLOCK_INTERFACE_NAME,
NULL);
}

void fastboot_block_set_device(int device)
{
fastboot_block_device = device;
}

int fastboot_block_get_device(void)
{
if (fastboot_block_device >= 0)
return fastboot_block_device;
return config_opt_enabled(CONFIG_FASTBOOT_FLASH_BLOCK,
CONFIG_FASTBOOT_FLASH_BLOCK_DEVICE_ID, -1);
}

/**
* FASTBOOT_MAX_BLOCKS_ERASE - maximum blocks to erase per derase call
*
Expand Down Expand Up @@ -125,11 +162,8 @@ int fastboot_block_get_part_info(const char *part_name,
char *response)
{
int ret;
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);
const char *interface = fastboot_block_get_interface();
const int device = fastboot_block_get_device();

if (!part_name || !strcmp(part_name, "")) {
fastboot_fail("partition not given", response);
Expand Down
28 changes: 28 additions & 0 deletions include/fb_block.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,32 @@ void fastboot_block_write_sparse_image(struct blk_desc *dev_desc, struct disk_pa
void fastboot_block_flash_write(const char *part_name, void *download_buffer,
u32 download_bytes, char *response);

/**
* fastboot_block_set_interface() - Set the block interface name
*
* @interface: Interface name (e.g., "mmc", "scsi", "nvme")
*/
void fastboot_block_set_interface(const char *interface);

/**
* fastboot_block_get_interface() - Get the block interface name
*
* Return: Interface name, or config default if not set
*/
const char *fastboot_block_get_interface(void);

/**
* fastboot_block_set_device() - Set the block device ID
*
* @device: Device ID number
*/
void fastboot_block_set_device(int device);

/**
* fastboot_block_get_device() - Get the block device ID
*
* Return: Device ID, or config default if not set
*/
int fastboot_block_get_device(void);

#endif // _FB_BLOCK_H_