summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorHeinrich Schuchardt <heinrich.schuchardt@canonical.com>2023-01-02 18:21:14 +0100
committerJagan Teki <jagan@amarulasolutions.com>2023-01-26 21:04:16 +0530
commitfa3b38d4c432745b05e417c750c1c59c347fc18e (patch)
tree0d3c080e1493ed70ada7d7417fb87d3636a66b81 /cmd
parent53f4ef0a4b809e6c147fb8deed03354631b2f564 (diff)
cmd: fix return code of 'sf write' and 'sf read'
If the offset or the size passed to the 'sf write' or 'sf read' command exceeds the size of the SPI flash displaying the command usage is not helpful. Return CMD_RET_FAILURE instead of CMD_RET_USAGE. Use the CMD_RET_* constants instead of 0, 1, -1. Simplify a logical expression in the final return statement. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> Reviewed-by: Jagan Teki <jagan@amarulasolutions.com>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/sf.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/cmd/sf.c b/cmd/sf.c
index cf92ac4109..272521bcec 100644
--- a/cmd/sf.c
+++ b/cmd/sf.c
@@ -281,33 +281,33 @@ static int do_spi_flash_read_write(int argc, char *const argv[])
loff_t offset, len, maxsize;
if (argc < 3)
- return -1;
+ return CMD_RET_USAGE;
addr = hextoul(argv[1], &endp);
if (*argv[1] == 0 || *endp != 0)
- return -1;
+ return CMD_RET_USAGE;
if (mtd_arg_off_size(argc - 2, &argv[2], &dev, &offset, &len,
&maxsize, MTD_DEV_TYPE_NOR, flash->size))
- return -1;
+ return CMD_RET_FAILURE;
/* Consistency checking */
if (offset + len > flash->size) {
printf("ERROR: attempting %s past flash size (%#x)\n",
argv[0], flash->size);
- return 1;
+ return CMD_RET_FAILURE;
}
if (strncmp(argv[0], "read", 4) != 0 && flash->flash_is_unlocked &&
!flash->flash_is_unlocked(flash, offset, len)) {
printf("ERROR: flash area is locked\n");
- return 1;
+ return CMD_RET_FAILURE;
}
buf = map_physmem(addr, len, MAP_WRBACK);
if (!buf && addr) {
puts("Failed to map physical memory\n");
- return 1;
+ return CMD_RET_FAILURE;
}
if (strcmp(argv[0], "update") == 0) {
@@ -332,7 +332,7 @@ static int do_spi_flash_read_write(int argc, char *const argv[])
unmap_physmem(buf, len);
- return ret == 0 ? 0 : 1;
+ return ret ? CMD_RET_FAILURE : CMD_RET_SUCCESS;
}
static int do_spi_flash_erase(int argc, char *const argv[])