cmd: bcb: Apply non-functional refinements
These have been reported by Simon in [1] and fixed in [2].
However, since [1] has already been pushed to u-boot/master, the
improvements incorporated in [2] are now extracted and resubmitted.
The changes are in the area of coding style and best practices:
* s/field/fieldp/, s/size/sizep/, to convey that the variables return
an output to the caller
* s/err_1/err_read_fail/, s/err_2/err_too_small/, to be more descriptive
* Made sure 'static int do_bcb_load' appears on the same line
* Placed a `/*` on top of multi-line comment
[1] https://patchwork.ozlabs.org/patch/1104244/#2200259
[2] https://patchwork.ozlabs.org/cover/1128661/
("[v4,0/4] Add 'bcb' command to read/modify/write Android BCB")
Fixes: db7b7a05b2
("cmd: Add 'bcb' command to read/modify/write BCB fields")
Reported-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Eugeniu Rosca <erosca@de.adit-jv.com>
Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>
This commit is contained in:
43
cmd/bcb.c
43
cmd/bcb.c
@@ -83,23 +83,23 @@ err:
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int bcb_field_get(char *name, char **field, int *size)
|
static int bcb_field_get(char *name, char **fieldp, int *sizep)
|
||||||
{
|
{
|
||||||
if (!strcmp(name, "command")) {
|
if (!strcmp(name, "command")) {
|
||||||
*field = bcb.command;
|
*fieldp = bcb.command;
|
||||||
*size = sizeof(bcb.command);
|
*sizep = sizeof(bcb.command);
|
||||||
} else if (!strcmp(name, "status")) {
|
} else if (!strcmp(name, "status")) {
|
||||||
*field = bcb.status;
|
*fieldp = bcb.status;
|
||||||
*size = sizeof(bcb.status);
|
*sizep = sizeof(bcb.status);
|
||||||
} else if (!strcmp(name, "recovery")) {
|
} else if (!strcmp(name, "recovery")) {
|
||||||
*field = bcb.recovery;
|
*fieldp = bcb.recovery;
|
||||||
*size = sizeof(bcb.recovery);
|
*sizep = sizeof(bcb.recovery);
|
||||||
} else if (!strcmp(name, "stage")) {
|
} else if (!strcmp(name, "stage")) {
|
||||||
*field = bcb.stage;
|
*fieldp = bcb.stage;
|
||||||
*size = sizeof(bcb.stage);
|
*sizep = sizeof(bcb.stage);
|
||||||
} else if (!strcmp(name, "reserved")) {
|
} else if (!strcmp(name, "reserved")) {
|
||||||
*field = bcb.reserved;
|
*fieldp = bcb.reserved;
|
||||||
*size = sizeof(bcb.reserved);
|
*sizep = sizeof(bcb.reserved);
|
||||||
} else {
|
} else {
|
||||||
printf("Error: Unknown bcb field '%s'\n", name);
|
printf("Error: Unknown bcb field '%s'\n", name);
|
||||||
return -1;
|
return -1;
|
||||||
@@ -108,8 +108,8 @@ static int bcb_field_get(char *name, char **field, int *size)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int do_bcb_load(cmd_tbl_t *cmdtp, int flag, int argc,
|
||||||
do_bcb_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
char * const argv[])
|
||||||
{
|
{
|
||||||
struct blk_desc *desc;
|
struct blk_desc *desc;
|
||||||
disk_partition_t info;
|
disk_partition_t info;
|
||||||
@@ -119,28 +119,28 @@ do_bcb_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
|||||||
|
|
||||||
ret = blk_get_device_by_str("mmc", argv[1], &desc);
|
ret = blk_get_device_by_str("mmc", argv[1], &desc);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto err_1;
|
goto err_read_fail;
|
||||||
|
|
||||||
part = simple_strtoul(argv[2], &endp, 0);
|
part = simple_strtoul(argv[2], &endp, 0);
|
||||||
if (*endp == '\0') {
|
if (*endp == '\0') {
|
||||||
ret = part_get_info(desc, part, &info);
|
ret = part_get_info(desc, part, &info);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto err_1;
|
goto err_read_fail;
|
||||||
} else {
|
} else {
|
||||||
part = part_get_info_by_name(desc, argv[2], &info);
|
part = part_get_info_by_name(desc, argv[2], &info);
|
||||||
if (part < 0) {
|
if (part < 0) {
|
||||||
ret = part;
|
ret = part;
|
||||||
goto err_1;
|
goto err_read_fail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cnt = DIV_ROUND_UP(sizeof(struct bootloader_message), info.blksz);
|
cnt = DIV_ROUND_UP(sizeof(struct bootloader_message), info.blksz);
|
||||||
if (cnt > info.size)
|
if (cnt > info.size)
|
||||||
goto err_2;
|
goto err_too_small;
|
||||||
|
|
||||||
if (blk_dread(desc, info.start, cnt, &bcb) != cnt) {
|
if (blk_dread(desc, info.start, cnt, &bcb) != cnt) {
|
||||||
ret = -EIO;
|
ret = -EIO;
|
||||||
goto err_1;
|
goto err_read_fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
bcb_dev = desc->devnum;
|
bcb_dev = desc->devnum;
|
||||||
@@ -148,10 +148,10 @@ do_bcb_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
|||||||
debug("%s: Loaded from mmc %d:%d\n", __func__, bcb_dev, bcb_part);
|
debug("%s: Loaded from mmc %d:%d\n", __func__, bcb_dev, bcb_part);
|
||||||
|
|
||||||
return CMD_RET_SUCCESS;
|
return CMD_RET_SUCCESS;
|
||||||
err_1:
|
err_read_fail:
|
||||||
printf("Error: mmc %s:%s read failed (%d)\n", argv[1], argv[2], ret);
|
printf("Error: mmc %s:%s read failed (%d)\n", argv[1], argv[2], ret);
|
||||||
goto err;
|
goto err;
|
||||||
err_2:
|
err_too_small:
|
||||||
printf("Error: mmc %s:%s too small!", argv[1], argv[2]);
|
printf("Error: mmc %s:%s too small!", argv[1], argv[2]);
|
||||||
goto err;
|
goto err;
|
||||||
err:
|
err:
|
||||||
@@ -304,7 +304,8 @@ static int do_bcb(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
|
|||||||
return CMD_RET_USAGE;
|
return CMD_RET_USAGE;
|
||||||
|
|
||||||
if (bcb_is_misused(argc, argv)) {
|
if (bcb_is_misused(argc, argv)) {
|
||||||
/* We try to improve the user experience by reporting the
|
/*
|
||||||
|
* We try to improve the user experience by reporting the
|
||||||
* root-cause of misusage, so don't return CMD_RET_USAGE,
|
* root-cause of misusage, so don't return CMD_RET_USAGE,
|
||||||
* since the latter prints out the full-blown help text
|
* since the latter prints out the full-blown help text
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user