cmd: bcb: Extract '__bcb_load' from 'do_bcb_load' for internal needs

Enriching the functionality of U-Boot 'bcb' may assume using the
existing sub-commands as building blocks for the next ones.

A clean way to achive the above is to expose a number of static
routines, each mapped to an existing user command (e.g. load/set/store),
with a user/caller-friendly prototype (i.e. do not force the caller
to wrap an integer into a string).

This first patch makes '__bcb_load' available for internal needs.

No functional change, except for a tiny update in error handling.

Signed-off-by: Eugeniu Rosca <erosca@de.adit-jv.com>
Signed-off-by: Roman Kovalivskyi <roman.kovalivskyi@globallogic.com>
This commit is contained in:
Eugeniu Rosca 2020-10-23 11:52:19 +03:00 committed by Marek Vasut
parent 8b387f112b
commit 24e85bbd69

View File

@ -110,8 +110,7 @@ static int bcb_field_get(char *name, char **fieldp, int *sizep)
return 0;
}
static int do_bcb_load(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
static int __bcb_load(int devnum, const char *partp)
{
struct blk_desc *desc;
struct disk_partition info;
@ -119,17 +118,19 @@ static int do_bcb_load(struct cmd_tbl *cmdtp, int flag, int argc,
char *endp;
int part, ret;
ret = blk_get_device_by_str("mmc", argv[1], &desc);
if (ret < 0)
desc = blk_get_devnum_by_type(IF_TYPE_MMC, devnum);
if (!desc) {
ret = -ENODEV;
goto err_read_fail;
}
part = simple_strtoul(argv[2], &endp, 0);
part = simple_strtoul(partp, &endp, 0);
if (*endp == '\0') {
ret = part_get_info(desc, part, &info);
if (ret)
goto err_read_fail;
} else {
part = part_get_info_by_name(desc, argv[2], &info);
part = part_get_info_by_name(desc, partp, &info);
if (part < 0) {
ret = part;
goto err_read_fail;
@ -151,10 +152,10 @@ static int do_bcb_load(struct cmd_tbl *cmdtp, int flag, int argc,
return CMD_RET_SUCCESS;
err_read_fail:
printf("Error: mmc %s:%s read failed (%d)\n", argv[1], argv[2], ret);
printf("Error: mmc %d:%s read failed (%d)\n", devnum, partp, ret);
goto err;
err_too_small:
printf("Error: mmc %s:%s too small!", argv[1], argv[2]);
printf("Error: mmc %d:%s too small!", devnum, partp);
goto err;
err:
bcb_dev = -1;
@ -163,6 +164,20 @@ err:
return CMD_RET_FAILURE;
}
static int do_bcb_load(struct cmd_tbl *cmdtp, int flag, int argc,
char * const argv[])
{
char *endp;
int devnum = simple_strtoul(argv[1], &endp, 0);
if (*endp != '\0') {
printf("Error: Device id '%s' not a number\n", argv[1]);
return CMD_RET_FAILURE;
}
return __bcb_load(devnum, argv[2]);
}
static int do_bcb_set(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
{