diff options
Diffstat (limited to 'cmd/bcb.c')
-rw-r--r-- | cmd/bcb.c | 68 |
1 files changed, 33 insertions, 35 deletions
@@ -24,17 +24,17 @@ static struct bootloader_message bcb = { { 0 } }; static int bcb_cmd_get(char *cmd) { - if (!strncmp(cmd, "load", sizeof("load"))) + if (!strcmp(cmd, "load")) return BCB_CMD_LOAD; - if (!strncmp(cmd, "set", sizeof("set"))) + if (!strcmp(cmd, "set")) return BCB_CMD_FIELD_SET; - if (!strncmp(cmd, "clear", sizeof("clear"))) + if (!strcmp(cmd, "clear")) return BCB_CMD_FIELD_CLEAR; - if (!strncmp(cmd, "test", sizeof("test"))) + if (!strcmp(cmd, "test")) return BCB_CMD_FIELD_TEST; - if (!strncmp(cmd, "store", sizeof("store"))) + if (!strcmp(cmd, "store")) return BCB_CMD_STORE; - if (!strncmp(cmd, "dump", sizeof("dump"))) + if (!strcmp(cmd, "dump")) return BCB_CMD_FIELD_DUMP; else return -1; @@ -46,9 +46,6 @@ static int bcb_is_misused(int argc, char *const argv[]) switch (cmd) { case BCB_CMD_LOAD: - if (argc != 3) - goto err; - break; case BCB_CMD_FIELD_SET: if (argc != 3) goto err; @@ -86,23 +83,23 @@ err: 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 (!strncmp(name, "command", sizeof("command"))) { - *field = bcb.command; - *size = sizeof(bcb.command); - } else if (!strncmp(name, "status", sizeof("status"))) { - *field = bcb.status; - *size = sizeof(bcb.status); - } else if (!strncmp(name, "recovery", sizeof("recovery"))) { - *field = bcb.recovery; - *size = sizeof(bcb.recovery); - } else if (!strncmp(name, "stage", sizeof("stage"))) { - *field = bcb.stage; - *size = sizeof(bcb.stage); - } else if (!strncmp(name, "reserved", sizeof("reserved"))) { - *field = bcb.reserved; - *size = sizeof(bcb.reserved); + if (!strcmp(name, "command")) { + *fieldp = bcb.command; + *sizep = sizeof(bcb.command); + } else if (!strcmp(name, "status")) { + *fieldp = bcb.status; + *sizep = sizeof(bcb.status); + } else if (!strcmp(name, "recovery")) { + *fieldp = bcb.recovery; + *sizep = sizeof(bcb.recovery); + } else if (!strcmp(name, "stage")) { + *fieldp = bcb.stage; + *sizep = sizeof(bcb.stage); + } else if (!strcmp(name, "reserved")) { + *fieldp = bcb.reserved; + *sizep = sizeof(bcb.reserved); } else { printf("Error: Unknown bcb field '%s'\n", name); return -1; @@ -111,8 +108,8 @@ static int bcb_field_get(char *name, char **field, int *size) return 0; } -static int -do_bcb_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +static int do_bcb_load(cmd_tbl_t *cmdtp, int flag, int argc, + char * const argv[]) { struct blk_desc *desc; disk_partition_t info; @@ -122,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); if (ret < 0) - goto err_1; + goto err_read_fail; part = simple_strtoul(argv[2], &endp, 0); if (*endp == '\0') { ret = part_get_info(desc, part, &info); if (ret) - goto err_1; + goto err_read_fail; } else { part = part_get_info_by_name(desc, argv[2], &info); if (part < 0) { ret = part; - goto err_1; + goto err_read_fail; } } cnt = DIV_ROUND_UP(sizeof(struct bootloader_message), info.blksz); if (cnt > info.size) - goto err_2; + goto err_too_small; if (blk_dread(desc, info.start, cnt, &bcb) != cnt) { ret = -EIO; - goto err_1; + goto err_read_fail; } bcb_dev = desc->devnum; @@ -151,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); return CMD_RET_SUCCESS; -err_1: +err_read_fail: printf("Error: mmc %s:%s read failed (%d)\n", argv[1], argv[2], ret); goto err; -err_2: +err_too_small: printf("Error: mmc %s:%s too small!", argv[1], argv[2]); goto err; err: @@ -307,7 +304,8 @@ static int do_bcb(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) return CMD_RET_USAGE; 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, * since the latter prints out the full-blown help text */ |