From 4ebb55e96177a4b5f05e1407e01095cb4924d0a5 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Thu, 17 Jan 2019 16:41:13 -0800 Subject: ls: Adjust amount of space allocated for filesize Maximum file size on 64-bit system is 2^63-1 (9223372036854775807), which takes more that 14 characters of space. In order to keep things properly aligned adjust that spacing to 20 on 64-bit platforms. Before: ls -l /dev/ d--------- 0 . d--------- 0 .. crw------- 16384 dds-eeprom crw------- 256 e1000-invm0 crw------- 16384 eeprom0 cr-------- 0 full crw------- 2048 imx-ocotp crw------- 16384 main-eeprom crw------- 64 mdio0-phy00 crw------- 9223372036854775807 mem c-w------- 0 netconsole-1 c-w------- 0 null crw------- 256060514304 nvme0n1 cr-------- 0 prng crw------- 4294967296 ram0 c-w------- 0 serial0-1 cr-------- 0 zero After: ls -l /dev/ d--------- 0 . d--------- 0 .. crw------- 16384 dds-eeprom crw------- 256 e1000-invm0 crw------- 16384 eeprom0 cr-------- 0 full crw------- 2048 imx-ocotp crw------- 16384 main-eeprom crw------- 64 mdio0-phy00 crw------- 9223372036854775807 mem c-w------- 0 netconsole-1 c-w------- 0 null crw------- 256060514304 nvme0n1 cr-------- 0 prng crw------- 4294967296 ram0 c-w------- 0 serial0-1 cr-------- 0 zero Signed-off-by: Andrey Smirnov Signed-off-by: Sascha Hauer --- commands/ls.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'commands') diff --git a/commands/ls.c b/commands/ls.c index e54991862d..e5e37d75c5 100644 --- a/commands/ls.c +++ b/commands/ls.c @@ -26,6 +26,15 @@ #include #include +/* + * SIZELEN = strlen(itoa(MAX_LFS_FILESIZE)) + 1; + */ +#ifdef CONFIG_CPU_64 +#define SIZELEN 20 +#else +#define SIZELEN 14 +#endif + static void ls_one(const char *path, const char* fullname) { char modestr[11]; @@ -38,7 +47,8 @@ static void ls_one(const char *path, const char* fullname) return; mkmodestr(s.st_mode, modestr); - printf("%s %14llu %*.*s", modestr, s.st_size, namelen, namelen, path); + printf("%s %*llu %*.*s", modestr, SIZELEN, s.st_size, namelen, + namelen, path); if (S_ISLNK(s.st_mode)) { char realname[PATH_MAX]; -- cgit v1.2.3 From d4c88b90c558d595bec49de933052ad855da5c69 Mon Sep 17 00:00:00 2001 From: Uwe Kleine-König Date: Fri, 25 Jan 2019 21:59:34 +0100 Subject: i2c_probe: limit slave addresses to [0x04, 0x77] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adresses below 0x04 and above 0x77 are reserved in the i2c bus specification, so don't probe these addresses unless requested explicitly. Also do more strict boundary checking: - ensure start address is greater or equal to zero; - don't decrease stopaddr after checking it being greater or equal to startaddr. Signed-off-by: Uwe Kleine-König Signed-off-by: Sascha Hauer --- commands/i2c.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'commands') diff --git a/commands/i2c.c b/commands/i2c.c index 2f7f820d4d..65ff7378ec 100644 --- a/commands/i2c.c +++ b/commands/i2c.c @@ -44,7 +44,7 @@ static void i2c_probe_range(struct i2c_adapter *adapter, int startaddr, int stop static int do_i2c_probe(int argc, char *argv[]) { struct i2c_adapter *adapter = NULL; - int startaddr = 0, stopaddr = 0x7f; + int startaddr = 4, stopaddr = 0x77; if (argc > 1) { adapter = i2c_get_adapter(simple_strtoul(argv[1], NULL, 0)); @@ -57,13 +57,15 @@ static int do_i2c_probe(int argc, char *argv[]) if (argc > 3) stopaddr = simple_strtol(argv[3], NULL, 0); + if (stopaddr > 0x7f) + stopaddr = 0x7f; + + if (startaddr < 0) + startaddr = 0; if (startaddr > stopaddr) return COMMAND_ERROR_USAGE; - if (stopaddr > 0x7F) - stopaddr = 0x7F; - if (adapter) { i2c_probe_range(adapter, startaddr, stopaddr); } else { -- cgit v1.2.3 From 1b6253ab991d272adf8c84b0a6063b4076253d61 Mon Sep 17 00:00:00 2001 From: Uwe Kleine-König Date: Fri, 25 Jan 2019 21:59:35 +0100 Subject: i2c_probe: Use a quick write transfer instead of writing a zero MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This matches the method implemented in i2cdetect(8) when using its -q option. With this change an rx8130 RTC is detectable using i2c_probe. This failed before because this chip acks the first byte (containing its address and the R/̅W bit) but nacks the following 0 (representing the target address to write nothing to) which makes i2c_write_reg() return with an error and so the chip is not listed as available. Signed-off-by: Uwe Kleine-König Signed-off-by: Sascha Hauer --- commands/i2c.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'commands') diff --git a/commands/i2c.c b/commands/i2c.c index 65ff7378ec..77d65e3fa3 100644 --- a/commands/i2c.c +++ b/commands/i2c.c @@ -24,19 +24,19 @@ static void i2c_probe_range(struct i2c_adapter *adapter, int startaddr, int stopaddr) { - struct i2c_client client = {}; int addr; - int ret; - u8 reg; - - client.adapter = adapter; printf("probing i2c%d range 0x%02x-0x%02x: ", adapter->nr, startaddr, stopaddr); for (addr = startaddr; addr <= stopaddr && !ctrlc(); addr++) { - client.addr = addr; - ret = i2c_write_reg(&client, 0x00, ®, 0); - if (ret == 0) + struct i2c_msg msg = { + .addr = addr, + .buf = NULL, + .len = 0, + }; + int ret = i2c_transfer(adapter, &msg, 1); + if (ret == 1) printf("0x%02x ", addr); + } printf("\n"); } -- cgit v1.2.3