summaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2018-09-11 17:23:32 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2018-09-11 17:23:32 +0200
commit44ca0897af60c6568c7f51923dd0ad29b09b034d (patch)
tree69bb20887650b4bf76d0c07a9b6e1dd0a204f7ab /commands
parentbe22bb4527e3be70718dfee414e08b17c399f9fd (diff)
parentb0af360ccc38cbf3dd5b947c5948445bac8dd3ce (diff)
downloadbarebox-44ca0897af60c6568c7f51923dd0ad29b09b034d.tar.gz
Merge branch 'for-next/misc'
Diffstat (limited to 'commands')
-rw-r--r--commands/i2c.c31
-rw-r--r--commands/nand.c11
2 files changed, 30 insertions, 12 deletions
diff --git a/commands/i2c.c b/commands/i2c.c
index f0d16af..2f7f820 100644
--- a/commands/i2c.c
+++ b/commands/i2c.c
@@ -145,8 +145,12 @@ static int do_i2c_write(int argc, char *argv[])
ret = 0;
if (verbose) {
- printf("wrote %i bytes starting at reg 0x%04x to i2cdev 0x%02x on bus %i\n",
- count, reg, addr, adapter->nr);
+ if (reg >= 0)
+ printf("wrote %i bytes starting at reg 0x%04x to i2cdev 0x%02x on bus %i\n",
+ count, reg, addr, adapter->nr);
+ else
+ printf("sent %i bytes in master send mode to i2cdev 0x%02x on bus %i\n",
+ count, addr, adapter->nr);
for (i = 0; i < count; i++)
printf("0x%02x ", *(buf + i));
printf("\n");
@@ -161,7 +165,7 @@ BAREBOX_CMD_HELP_START(i2c_write)
BAREBOX_CMD_HELP_TEXT("Options:")
BAREBOX_CMD_HELP_OPT ("-b BUS\t", "i2c bus number (default 0)")
BAREBOX_CMD_HELP_OPT ("-a ADDR\t", "i2c device address")
-BAREBOX_CMD_HELP_OPT ("-r START", "start register")
+BAREBOX_CMD_HELP_OPT ("-r START", "start register (optional, master send mode if none given)")
BAREBOX_CMD_HELP_OPT ("-w\t", "use word (16 bit) wide access")
BAREBOX_CMD_HELP_OPT ("-v\t", "verbose")
BAREBOX_CMD_HELP_END
@@ -204,7 +208,7 @@ static int do_i2c_read(int argc, char *argv[])
}
}
- if ((addr < 0) || (reg < 0) || (count < 1) || (addr > 0x7F))
+ if ((addr < 0) || (count < 1) || (addr > 0x7F))
return COMMAND_ERROR_USAGE;
adapter = i2c_get_adapter(bus);
@@ -217,12 +221,21 @@ static int do_i2c_read(int argc, char *argv[])
client.addr = addr;
buf = xmalloc(count);
- ret = i2c_read_reg(&client, reg | wide, buf, count);
+ if (reg >= 0)
+ ret = i2c_read_reg(&client, reg | wide, buf, count);
+ else
+ ret = i2c_master_recv(&client, buf, count);
if (ret == count) {
int i;
- if (verbose)
- printf("read %i bytes starting at reg 0x%04x from i2cdev 0x%02x on bus %i\n",
- count, reg, addr, adapter->nr);
+ if (verbose) {
+ if (reg >= 0)
+ printf("read %i bytes starting at reg 0x%04x from i2cdev 0x%02x on bus %i\n",
+ count, reg, addr, adapter->nr);
+ else
+ printf("received %i bytes in master receive mode from i2cdev 0x%02x on bus %i\n",
+ count, addr, adapter->nr);
+ }
+
for (i = 0; i < count; i++)
printf("0x%02x ", *(buf + i));
printf("\n");
@@ -237,7 +250,7 @@ BAREBOX_CMD_HELP_START(i2c_read)
BAREBOX_CMD_HELP_TEXT("Options:")
BAREBOX_CMD_HELP_OPT("-b BUS\t", "i2c bus number (default 0)")
BAREBOX_CMD_HELP_OPT("-a ADDR\t", "i2c device address")
-BAREBOX_CMD_HELP_OPT("-r START", "start register")
+BAREBOX_CMD_HELP_OPT("-r START", "start register (optional, master receive mode if none given)")
BAREBOX_CMD_HELP_OPT("-w\t", "use word (16 bit) wide access")
BAREBOX_CMD_HELP_OPT("-c COUNT", "byte count")
BAREBOX_CMD_HELP_OPT("-v\t", "verbose")
diff --git a/commands/nand.c b/commands/nand.c
index b065a66..c57b394 100644
--- a/commands/nand.c
+++ b/commands/nand.c
@@ -41,7 +41,7 @@ static int do_nand(int argc, char *argv[])
int command = 0;
loff_t badblock = 0;
int fd;
- int ret;
+ int ret = 0;
struct mtd_info_user mtdinfo;
while((opt = getopt(argc, argv, "adb:g:i")) > 0) {
@@ -88,13 +88,18 @@ static int do_nand(int argc, char *argv[])
optind++;
}
+
+ goto out_ret;
}
if (command == NAND_DEL) {
while (optind < argc) {
- dev_remove_bb_dev(basename(argv[optind]));
+ if (dev_remove_bb_dev(basename(argv[optind])))
+ return 1;
optind++;
}
+
+ goto out_ret;
}
fd = open(argv[optind], O_RDWR);
@@ -149,10 +154,10 @@ static int do_nand(int argc, char *argv[])
printf("No bad blocks\n");
}
- ret = 0;
out:
close(fd);
+out_ret:
return ret;
}