[U-Boot] [PATCH 0/20] Improvements to memory, hashing functions for sandbox

This series aims to get all the memory functions running correctly on sandbox.
There was some discussion about this a while ago, and a commit was added to show a possible approach:
355a8357 sandbox: Change md command to use map_physmem
This commit was subsequently reverted because it used map_physmem() instead of the NOP that most architectures need for the memory functions.
This series introduces map_sysmem(), a NOP on all architectures except sandbox. It allows us to use a ram buffer to which all U-Boot addresses are relative. The memory commands (including hashing) are updated to use this so that sandbox can now use those commands.
Half of the mtest code is behind #ifdefs and there is duplication of some functions in both versions of the memory test. Several patches here clean this up a bit and get it working on sandbox.
The numeric setenv_ulong() function is a useful way of avoiding a 'char buf[17]; sprintf(buf, "%ld", ...); setenv("...", buf)' sequence. There is also setenv_addr(). What is missing is setenv_hex() which sets a ulong in hex format. Add this function and then make use of it in the main places: common/ drivers/ and net/.
The recently added and very basic hash instructure can help reduce code duplication in some cases. Redo the crc32 command to use this, and make it available through the 'hash' command. Also a few bugs were found in hashing with verify disabled - the arg count was not checked and a variable declaration was missing.
To permit the memory tester to run on sandbox, we need ctrl-C to work. To achieve this, add a proper implementation of sandbox's tstc(), with a simple FIFO for character input. An os_usleep() is added to ensure that U-Boot does not consume infinite CPU when setting at the command prompt.
With all of this it is possible to use the memory commands in sandbox, as well as crc32 and the other hashing commands.
Simon Glass (19): Tidy up error checking and fix bug in hash command Update print_buffer() to use const sandbox: Add un/map_sysmen() to deal with sandbox's ram_buf sandbox: Change memory commands to use map_physmem Split out the memory tests into separate functions Use common mtest iteration counting Fix mtest indenting Bring mtest putc() into common code Reduce casting in mtest Update set_working_fdt_addr() to use setenv_addr() common: Use new numeric setenv functions drivers: Use new numeric setenv functions net: Use new numeric setenv functions image: Use crc header file instead of C prototypes Roll crc32 into hash infrastructure sandbox: config: Enable hash functions and mtest Move CONFIG_SYS_MEMTEST_SCRATCH #ifdef to top of file sandbox: Update mtest to fix crashes sandbox: Allow hash functions to work correctly
Taylor Hutt (1): sandbox: Improve sandbox serial port keyboard interface
README | 9 + arch/sandbox/config.mk | 1 + arch/sandbox/cpu/os.c | 8 + arch/sandbox/include/asm/io.h | 10 + common/cmd_bootm.c | 11 +- common/cmd_cbfs.c | 4 +- common/cmd_cramfs.c | 4 +- common/cmd_fdos.c | 4 +- common/cmd_fdt.c | 11 +- common/cmd_hash.c | 4 + common/cmd_jffs2.c | 4 +- common/cmd_load.c | 12 +- common/cmd_mem.c | 798 ++++++++++++++++++++--------------------- common/cmd_mtdparts.c | 4 +- common/cmd_nand.c | 12 +- common/cmd_nvedit.c | 11 +- common/cmd_reiser.c | 4 +- common/cmd_setexpr.c | 39 ++- common/cmd_unzip.c | 4 +- common/cmd_ximg.c | 7 +- common/cmd_zfs.c | 3 +- common/cmd_zip.c | 4 +- common/hash.c | 31 ++- common/image.c | 4 +- drivers/net/fm/fm.c | 4 +- drivers/serial/sandbox.c | 44 ++- fs/fs.c | 4 +- fs/ubifs/ubifs.c | 4 +- include/common.h | 29 ++- include/configs/sandbox.h | 9 +- include/hash.h | 2 +- include/os.h | 10 + include/u-boot/crc.h | 11 + lib/crc32.c | 9 + lib/display_options.c | 3 +- net/net.c | 8 +- 36 files changed, 612 insertions(+), 528 deletions(-)

There are two problems:
1. The argument count needs to be checked before argv is used 2. When verify is not enabled, we need to define a constant zero value
Signed-off-by: Simon Glass sjg@chromium.org --- common/cmd_hash.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/common/cmd_hash.c b/common/cmd_hash.c index 689c608..eb6a338 100644 --- a/common/cmd_hash.c +++ b/common/cmd_hash.c @@ -32,11 +32,15 @@ static int do_hash(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) #ifdef CONFIG_HASH_VERIFY int verify = 0;
+ if (argc < 4) + return CMD_RET_USAGE; if (!strcmp(argv[1], "-v")) { verify = 1; argc--; argv++; } +#else + const int verify = 0; #endif /* Move forward to 'algorithm' parameter */ argc--;

On Wed, Dec 26, 2012 at 10:56 AM, Simon Glass sjg@chromium.org wrote:
There are two problems:
- The argument count needs to be checked before argv is used
- When verify is not enabled, we need to define a constant zero value
Signed-off-by: Simon Glass sjg@chromium.org
Applied to x86/master.

The buffer cannot be changed by this function, so change the buffer pointer to a const. This allows callers with const pointer to use the function without a cast.
Signed-off-by: Simon Glass sjg@chromium.org --- include/common.h | 3 ++- lib/display_options.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/include/common.h b/include/common.h index d0bf1e8..f2035c0 100644 --- a/include/common.h +++ b/include/common.h @@ -270,7 +270,8 @@ int cpu_init(void); phys_size_t initdram (int); int display_options (void); void print_size(unsigned long long, const char *); -int print_buffer (ulong addr, void* data, uint width, uint count, uint linelen); +int print_buffer(ulong addr, const void *data, uint width, uint count, + uint linelen);
/* common/main.c */ void main_loop (void); diff --git a/lib/display_options.c b/lib/display_options.c index 694d2f2..0339970 100644 --- a/lib/display_options.c +++ b/lib/display_options.c @@ -98,7 +98,8 @@ void print_size(unsigned long long size, const char *s) */ #define MAX_LINE_LENGTH_BYTES (64) #define DEFAULT_LINE_LENGTH_BYTES (16) -int print_buffer (ulong addr, void* data, uint width, uint count, uint linelen) +int print_buffer(ulong addr, const void *data, uint width, uint count, + uint linelen) { /* linebuf as a union causes proper alignment */ union linebuf {

On Wed, Dec 26, 2012 at 10:56 AM, Simon Glass sjg@chromium.org wrote:
The buffer cannot be changed by this function, so change the buffer pointer to a const. This allows callers with const pointer to use the function without a cast.
Signed-off-by: Simon Glass sjg@chromium.org
Applied to x86/master.

From: Taylor Hutt thutt@chromium.org
Implements the tstc() interface for the serial driver. Multiplexing the console between the serial port and a keyboard uses a polling method of checking if characters are available; this means that the serial console must be non-blocking when attempting to read characters.
Signed-off-by: Taylor Hutt thutt@chromium.org Signed-off-by: Simon Glass sjg@chromium.org --- arch/sandbox/cpu/os.c | 8 ++++++++ drivers/serial/sandbox.c | 44 ++++++++++++++++++++++++++++++++++++++------ include/os.h | 10 ++++++++++ 3 files changed, 56 insertions(+), 6 deletions(-)
diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c index 36637af..3e37c93 100644 --- a/arch/sandbox/cpu/os.c +++ b/arch/sandbox/cpu/os.c @@ -44,6 +44,14 @@ ssize_t os_read(int fd, void *buf, size_t count) return read(fd, buf, count); }
+ssize_t os_read_no_block(int fd, void *buf, size_t count) +{ + const int flags = fcntl(fd, F_GETFL, 0); + + fcntl(fd, F_SETFL, flags | O_NONBLOCK); + return os_read(fd, buf, count); +} + ssize_t os_write(int fd, const void *buf, size_t count) { return write(fd, buf, count); diff --git a/drivers/serial/sandbox.c b/drivers/serial/sandbox.c index cb19401..b73520c 100644 --- a/drivers/serial/sandbox.c +++ b/drivers/serial/sandbox.c @@ -30,6 +30,19 @@ #include <serial.h> #include <linux/compiler.h>
+/* + * + * serial_buf: A buffer that holds keyboard characters for the + * Sandbox U-boot. + * + * invariants: + * serial_buf_write == serial_buf_read -> empty buffer + * (serial_buf_write + 1) % 16 == serial_buf_read -> full buffer + */ +static char serial_buf[16]; +static unsigned int serial_buf_write; +static unsigned int serial_buf_read; + static int sandbox_serial_init(void) { os_tty_raw(0); @@ -50,18 +63,37 @@ static void sandbox_serial_puts(const char *str) os_write(1, str, strlen(str)); }
-static int sandbox_serial_getc(void) +static unsigned int increment_buffer_index(unsigned int index) +{ + return (index + 1) % ARRAY_SIZE(serial_buf); +} + +static int sandbox_serial_tstc(void) { - char buf; + const unsigned int next_index = + increment_buffer_index(serial_buf_write); ssize_t count;
- count = os_read(0, &buf, 1); - return count == 1 ? buf : 0; + os_usleep(100); + if (next_index == serial_buf_read) + return 1; /* buffer full */ + + count = os_read_no_block(0, &serial_buf[serial_buf_write], 1); + if (count == 1) + serial_buf_write = next_index; + return serial_buf_write != serial_buf_read; }
-static int sandbox_serial_tstc(void) +static int sandbox_serial_getc(void) { - return 0; + int result; + + while (!sandbox_serial_tstc()) + ; /* buffer empty */ + + result = serial_buf[serial_buf_read]; + serial_buf_read = increment_buffer_index(serial_buf_read); + return result; }
static struct serial_device sandbox_serial_drv = { diff --git a/include/os.h b/include/os.h index 699682a..c452d1b 100644 --- a/include/os.h +++ b/include/os.h @@ -40,6 +40,16 @@ struct sandbox_state; ssize_t os_read(int fd, void *buf, size_t count);
/** + * Access to the OS read() system call with non-blocking access + * + * \param fd File descriptor as returned by os_open() + * \param buf Buffer to place data + * \param count Number of bytes to read + * \return number of bytes read, or -1 on error + */ +ssize_t os_read_no_block(int fd, void *buf, size_t count); + +/** * Access to the OS write() system call * * \param fd File descriptor as returned by os_open()

On Wed, Dec 26, 2012 at 10:56 AM, Simon Glass sjg@chromium.org wrote:
From: Taylor Hutt thutt@chromium.org
Implements the tstc() interface for the serial driver. Multiplexing the console between the serial port and a keyboard uses a polling method of checking if characters are available; this means that the serial console must be non-blocking when attempting to read characters.
Signed-off-by: Taylor Hutt thutt@chromium.org Signed-off-by: Simon Glass sjg@chromium.org
Applied to x86/master.

Sandbox doesn't actually provide U-Boot access to the machine's physical memory. Instead it provides a RAM buffer of configurable size, and all memory accesses are within that buffer. Sandbox memory starts at 0 and is CONFIG_DRAM_SIZE bytes in size. Allowing access outside this buffer might produce unpredictable results in the event of an error, and would expose the host machine's memory architecture to the sandbox U-Boot.
Most U-Boot functions assume that they can just access memory at given address. For sandbox this is not true.
Add a map_sysmem() call which converts a U-Boot address to a system address. In most cases this is a NOP, but for sandbox it returns a pointer to that memory inside the RAM buffer.
To get a U-Boot feature to work correctly within sandbox, you should call map_sysmem() to get a pointer to the address, and then use that address for any U-Boot memory accesses.
Signed-off-by: Simon Glass sjg@chromium.org --- README | 9 +++++++++ arch/sandbox/config.mk | 1 + arch/sandbox/include/asm/io.h | 10 ++++++++++ include/common.h | 12 ++++++++++++ 4 files changed, 32 insertions(+), 0 deletions(-)
diff --git a/README b/README index 78f40df..8dd3867 100644 --- a/README +++ b/README @@ -3769,6 +3769,15 @@ Low Level (hardware related) configuration options: that is executed before the actual U-Boot. E.g. when compiling a NAND SPL.
+- CONFIG_ARCH_MAP_SYSMEM + Generally U-Boot (and in particular the md command) uses + effective address. It is therefore not necessary to regard + U-Boot address as virtual addresses that need to be translated + to physical addresses. However, sandbox requires this, since + it maintains its own little RAM buffer which contains all + addressable memory. This option causes some memory accesses + to be mapped through map_sysmem() / unmap_sysmem(). + - CONFIG_USE_ARCH_MEMCPY CONFIG_USE_ARCH_MEMSET If these options are used a optimized version of memcpy/memset will diff --git a/arch/sandbox/config.mk b/arch/sandbox/config.mk index 02ce4a4..4fd0d4e 100644 --- a/arch/sandbox/config.mk +++ b/arch/sandbox/config.mk @@ -18,4 +18,5 @@ # MA 02111-1307 USA
PLATFORM_CPPFLAGS += -DCONFIG_SANDBOX -D__SANDBOX__ -U_FORTIFY_SOURCE +PLATFORM_CPPFLAGS += -DCONFIG_ARCH_MAP_SYSMEM PLATFORM_LIBS += -lrt diff --git a/arch/sandbox/include/asm/io.h b/arch/sandbox/include/asm/io.h index 0392d21..d8c0236 100644 --- a/arch/sandbox/include/asm/io.h +++ b/arch/sandbox/include/asm/io.h @@ -39,3 +39,13 @@ static inline void unmap_physmem(void *vaddr, unsigned long flags) {
} + +/* For sandbox, we want addresses to point into our RAM buffer */ +static inline void *map_sysmem(phys_addr_t paddr, unsigned long len) +{ + return map_physmem(paddr, len, MAP_WRBACK); +} + +static inline void unmap_sysmem(const void *vaddr) +{ +} diff --git a/include/common.h b/include/common.h index f2035c0..08d01db 100644 --- a/include/common.h +++ b/include/common.h @@ -861,6 +861,18 @@ int cpu_disable(int nr); int cpu_release(int nr, int argc, char * const argv[]); #endif
+/* Define a null map_sysmem() if the architecture doesn't use it */ +# ifndef CONFIG_ARCH_MAP_SYSMEM +static inline void *map_sysmem(phys_addr_t paddr, unsigned long len) +{ + return (void *)(uintptr_t)paddr; +} + +static inline void unmap_sysmem(const void *vaddr) +{ +} +# endif + #endif /* __ASSEMBLY__ */
#ifdef CONFIG_PPC

On Wed, Dec 26, 2012 at 10:56 AM, Simon Glass sjg@chromium.org wrote:
Sandbox doesn't actually provide U-Boot access to the machine's physical memory. Instead it provides a RAM buffer of configurable size, and all memory accesses are within that buffer. Sandbox memory starts at 0 and is CONFIG_DRAM_SIZE bytes in size. Allowing access outside this buffer might produce unpredictable results in the event of an error, and would expose the host machine's memory architecture to the sandbox U-Boot.
Most U-Boot functions assume that they can just access memory at given address. For sandbox this is not true.
Add a map_sysmem() call which converts a U-Boot address to a system address. In most cases this is a NOP, but for sandbox it returns a pointer to that memory inside the RAM buffer.
To get a U-Boot feature to work correctly within sandbox, you should call map_sysmem() to get a pointer to the address, and then use that address for any U-Boot memory accesses.
Signed-off-by: Simon Glass sjg@chromium.org
I haven't seen any comments on this one, either because no one noticed or because it is OK. I am collecting up this series and will send a pull request, for Tom to review.
Applied to x86/master.

Sandbox wants to support commands which use memory. The map_sysmen() call provides this feature, so use this in the memory commands.
Signed-off-by: Simon Glass sjg@chromium.org --- common/cmd_mem.c | 122 +++++++++++++++++++++++++++++++++++------------------- 1 files changed, 79 insertions(+), 43 deletions(-)
diff --git a/common/cmd_mem.c b/common/cmd_mem.c index 4d64cff..e2adea9 100644 --- a/common/cmd_mem.c +++ b/common/cmd_mem.c @@ -33,6 +33,7 @@ #include <dataflash.h> #endif #include <watchdog.h> +#include <asm/io.h>
static int mod_mem(cmd_tbl_t *, int, int, int, char * const []);
@@ -135,9 +136,13 @@ static int do_mem_md(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) # endif
{ + ulong bytes = size * length; + const void *buf = map_sysmem(addr, bytes); + /* Print the lines. */ - print_buffer(addr, (void*)addr, size, length, DISP_LINE_LEN/size); - addr += size*length; + print_buffer(addr, buf, size, length, DISP_LINE_LEN / size); + addr += bytes; + unmap_sysmem(buf); } #endif
@@ -160,6 +165,8 @@ static int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { ulong addr, writeval, count; int size; + void *buf; + ulong bytes;
if ((argc < 3) || (argc > 4)) return CMD_RET_USAGE; @@ -185,15 +192,18 @@ static int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) count = 1; }
+ bytes = size * count; + buf = map_sysmem(addr, bytes); while (count-- > 0) { if (size == 4) - *((ulong *)addr) = (ulong )writeval; + *((ulong *)buf) = (ulong)writeval; else if (size == 2) - *((ushort *)addr) = (ushort)writeval; + *((ushort *)buf) = (ushort)writeval; else - *((u_char *)addr) = (u_char)writeval; - addr += size; + *((u_char *)buf) = (u_char)writeval; + buf += size; } + unmap_sysmem(buf); return 0; }
@@ -255,10 +265,11 @@ int do_mem_mwc ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
static int do_mem_cmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { - ulong addr1, addr2, count, ngood; + ulong addr1, addr2, count, ngood, bytes; int size; int rcode = 0; const char *type; + const void *buf1, *buf2, *base;
if (argc != 4) return CMD_RET_USAGE; @@ -291,33 +302,40 @@ static int do_mem_cmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) } #endif
+ bytes = size * count; + base = buf1 = map_sysmem(addr1, bytes); + buf2 = map_sysmem(addr2, bytes); for (ngood = 0; ngood < count; ++ngood) { ulong word1, word2; if (size == 4) { - word1 = *(ulong *)addr1; - word2 = *(ulong *)addr2; + word1 = *(ulong *)buf1; + word2 = *(ulong *)buf2; } else if (size == 2) { - word1 = *(ushort *)addr1; - word2 = *(ushort *)addr2; + word1 = *(ushort *)buf1; + word2 = *(ushort *)buf2; } else { - word1 = *(u_char *)addr1; - word2 = *(u_char *)addr2; + word1 = *(u_char *)buf1; + word2 = *(u_char *)buf2; } if (word1 != word2) { + ulong offset = buf1 - base; + printf("%s at 0x%08lx (%#0*lx) != %s at 0x%08lx (%#0*lx)\n", - type, addr1, size, word1, - type, addr2, size, word2); + type, (ulong)(addr1 + offset), size, word1, + type, (ulong)(addr2 + offset), size, word2); rcode = 1; break; }
- addr1 += size; - addr2 += size; + buf1 += size; + buf2 += size;
/* reset watchdog from time to time */ if ((ngood % (64 << 10)) == 0) WATCHDOG_RESET(); } + unmap_sysmem(buf1); + unmap_sysmem(buf2);
printf("Total of %ld %s(s) were the same\n", ngood, type); return rcode; @@ -325,8 +343,10 @@ static int do_mem_cmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
static int do_mem_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { - ulong addr, dest, count; + ulong addr, dest, count, bytes; int size; + const void *src; + void *buf;
if (argc != 4) return CMD_RET_USAGE; @@ -416,15 +436,18 @@ static int do_mem_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) } #endif
+ bytes = size * count; + buf = map_sysmem(addr, bytes); + src = map_sysmem(addr, bytes); while (count-- > 0) { if (size == 4) - *((ulong *)dest) = *((ulong *)addr); + *((ulong *)buf) = *((ulong *)src); else if (size == 2) - *((ushort *)dest) = *((ushort *)addr); + *((ushort *)buf) = *((ushort *)src); else - *((u_char *)dest) = *((u_char *)addr); - addr += size; - dest += size; + *((u_char *)buf) = *((u_char *)src); + src += size; + buf += size;
/* reset watchdog from time to time */ if ((count % (64 << 10)) == 0) @@ -450,11 +473,12 @@ static int do_mem_base(cmd_tbl_t *cmdtp, int flag, int argc, static int do_mem_loop(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { - ulong addr, length, i; + ulong addr, length, i, bytes; int size; volatile uint *longp; volatile ushort *shortp; volatile u_char *cp; + const void *buf;
if (argc < 3) return CMD_RET_USAGE; @@ -473,28 +497,31 @@ static int do_mem_loop(cmd_tbl_t *cmdtp, int flag, int argc, */ length = simple_strtoul(argv[2], NULL, 16);
+ bytes = size * length; + buf = map_sysmem(addr, bytes); + /* We want to optimize the loops to run as fast as possible. * If we have only one object, just run infinite loops. */ if (length == 1) { if (size == 4) { - longp = (uint *)addr; + longp = (uint *)buf; for (;;) i = *longp; } if (size == 2) { - shortp = (ushort *)addr; + shortp = (ushort *)buf; for (;;) i = *shortp; } - cp = (u_char *)addr; + cp = (u_char *)buf; for (;;) i = *cp; }
if (size == 4) { for (;;) { - longp = (uint *)addr; + longp = (uint *)buf; i = length; while (i-- > 0) *longp++; @@ -502,28 +529,30 @@ static int do_mem_loop(cmd_tbl_t *cmdtp, int flag, int argc, } if (size == 2) { for (;;) { - shortp = (ushort *)addr; + shortp = (ushort *)buf; i = length; while (i-- > 0) *shortp++; } } for (;;) { - cp = (u_char *)addr; + cp = (u_char *)buf; i = length; while (i-- > 0) *cp++; } + unmap_sysmem(buf); }
#ifdef CONFIG_LOOPW int do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { - ulong addr, length, i, data; + ulong addr, length, i, data, bytes; int size; volatile uint *longp; volatile ushort *shortp; volatile u_char *cp; + void *buf;
if (argc < 4) return CMD_RET_USAGE; @@ -545,28 +574,31 @@ int do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) /* data to write */ data = simple_strtoul(argv[3], NULL, 16);
+ bytes = size * length; + buf = map_sysmem(addr, bytes); + /* We want to optimize the loops to run as fast as possible. * If we have only one object, just run infinite loops. */ if (length == 1) { if (size == 4) { - longp = (uint *)addr; + longp = (uint *)buf; for (;;) *longp = data; } if (size == 2) { - shortp = (ushort *)addr; + shortp = (ushort *)buf; for (;;) *shortp = data; } - cp = (u_char *)addr; + cp = (u_char *)buf; for (;;) *cp = data; }
if (size == 4) { for (;;) { - longp = (uint *)addr; + longp = (uint *)buf; i = length; while (i-- > 0) *longp++ = data; @@ -574,14 +606,14 @@ int do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) } if (size == 2) { for (;;) { - shortp = (ushort *)addr; + shortp = (ushort *)buf; i = length; while (i-- > 0) *shortp++ = data; } } for (;;) { - cp = (u_char *)addr; + cp = (u_char *)buf; i = length; while (i-- > 0) *cp++ = data; @@ -957,6 +989,7 @@ mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[]) { ulong addr, i; int nbytes, size; + void *ptr = NULL;
if (argc != 2) return CMD_RET_USAGE; @@ -1001,13 +1034,14 @@ mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[]) * the next value. A non-converted value exits. */ do { + ptr = map_sysmem(addr, size); printf("%08lx:", addr); if (size == 4) - printf(" %08x", *((uint *)addr)); + printf(" %08x", *((uint *)ptr)); else if (size == 2) - printf(" %04x", *((ushort *)addr)); + printf(" %04x", *((ushort *)ptr)); else - printf(" %02x", *((u_char *)addr)); + printf(" %02x", *((u_char *)ptr));
nbytes = readline (" ? "); if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) { @@ -1037,16 +1071,18 @@ mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[]) reset_cmd_timeout(); #endif if (size == 4) - *((uint *)addr) = i; + *((uint *)ptr) = i; else if (size == 2) - *((ushort *)addr) = i; + *((ushort *)ptr) = i; else - *((u_char *)addr) = i; + *((u_char *)ptr) = i; if (incrflag) addr += size; } } } while (nbytes); + if (ptr) + unmap_sysmem(ptr);
mm_last_addr = addr; mm_last_size = size;

On Wed, Dec 26, 2012 at 10:56 AM, Simon Glass sjg@chromium.org wrote:
Sandbox wants to support commands which use memory. The map_sysmen() call provides this feature, so use this in the memory commands.
Signed-off-by: Simon Glass sjg@chromium.org
Applied to x86/master.
common/cmd_mem.c | 122 +++++++++++++++++++++++++++++++++++------------------- 1 files changed, 79 insertions(+), 43 deletions(-)

Half of the code is currently hidden behind an #ifdef. Move the two memory tests into their own functions and use the compiler to eliminate the unused code.
Signed-off-by: Simon Glass sjg@chromium.org --- common/cmd_mem.c | 217 +++++++++++++++++++++++++++++------------------------- 1 files changed, 116 insertions(+), 101 deletions(-)
diff --git a/common/cmd_mem.c b/common/cmd_mem.c index e2adea9..36ac6f4 100644 --- a/common/cmd_mem.c +++ b/common/cmd_mem.c @@ -621,36 +621,26 @@ int do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) } #endif /* CONFIG_LOOPW */
-/* - * Perform a memory test. A more complete alternative test can be - * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until - * interrupted by ctrl-c or by a failure of one of the sub-tests. - */ -static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, - char * const argv[]) +static int mem_test_alt(vu_long *start, vu_long *end, + int iteration_limit) { - vu_long *addr, *start, *end; - ulong val; - ulong readback; - ulong errs = 0; + vu_long *addr; int iterations = 1; - int iteration_limit; - -#if defined(CONFIG_SYS_ALT_MEMTEST) - vu_long len; - vu_long offset; - vu_long test_offset; - vu_long pattern; - vu_long temp; - vu_long anti_pattern; - vu_long num_words; + ulong errs = 0; + ulong val, readback; + int j; + vu_long len; + vu_long offset; + vu_long test_offset; + vu_long pattern; + vu_long temp; + vu_long anti_pattern; + vu_long num_words; #if defined(CONFIG_SYS_MEMTEST_SCRATCH) - vu_long *dummy = (vu_long*)CONFIG_SYS_MEMTEST_SCRATCH; + vu_long *dummy = (vu_long *)CONFIG_SYS_MEMTEST_SCRATCH; #else vu_long *dummy = NULL; /* yes, this is address 0x0, not NULL */ #endif - int j; - static const ulong bitpattern[] = { 0x00000001, /* single bit */ 0x00000003, /* two adjacent bits */ @@ -661,43 +651,18 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, 0x00000055, /* four non-adjacent bits */ 0xaaaaaaaa, /* alternating 1/0 */ }; -#else - ulong incr; - ulong pattern; -#endif
- if (argc > 1) - start = (ulong *)simple_strtoul(argv[1], NULL, 16); - else - start = (ulong *)CONFIG_SYS_MEMTEST_START; - - if (argc > 2) - end = (ulong *)simple_strtoul(argv[2], NULL, 16); - else - end = (ulong *)(CONFIG_SYS_MEMTEST_END); - - if (argc > 3) - pattern = (ulong)simple_strtoul(argv[3], NULL, 16); - else - pattern = 0; - - if (argc > 4) - iteration_limit = (ulong)simple_strtoul(argv[4], NULL, 16); - else - iteration_limit = 0; - -#if defined(CONFIG_SYS_ALT_MEMTEST) - printf ("Testing %08x ... %08x:\n", (uint)start, (uint)end); + printf("Testing %08x ... %08x:\n", (uint)(uintptr_t)start, + (uint)(uintptr_t)end); debug("%s:%d: start 0x%p end 0x%p\n", - __FUNCTION__, __LINE__, start, end); + __func__, __LINE__, start, end);
for (;;) { if (ctrlc()) { - putc ('\n'); + putc('\n'); return 1; }
- if (iteration_limit && iterations > iteration_limit) { printf("Tested %d iteration(s) with %lu errors.\n", iterations-1, errs); @@ -726,34 +691,35 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, * pattern and ~pattern). */ addr = start; - for (j = 0; j < sizeof(bitpattern)/sizeof(bitpattern[0]); j++) { + for (j = 0; j < sizeof(bitpattern) / sizeof(bitpattern[0]); + j++) { val = bitpattern[j]; - for(; val != 0; val <<= 1) { + for (; val != 0; val <<= 1) { *addr = val; - *dummy = ~val; /* clear the test data off of the bus */ + *dummy = ~val; /* clear the test data off the bus */ readback = *addr; if(readback != val) { - printf ("FAILURE (data line): " - "expected %08lx, actual %08lx\n", - val, readback); - errs++; - if (ctrlc()) { - putc ('\n'); - return 1; - } + printf("FAILURE (data line): " + "expected %08lx, actual %08lx\n", + val, readback); + errs++; + if (ctrlc()) { + putc('\n'); + return 1; + } } *addr = ~val; *dummy = val; readback = *addr; - if(readback != ~val) { - printf ("FAILURE (data line): " - "Is %08lx, should be %08lx\n", - readback, ~val); - errs++; - if (ctrlc()) { - putc ('\n'); - return 1; - } + if (readback != ~val) { + printf("FAILURE (data line): " + "Is %08lx, should be %08lx\n", + readback, ~val); + errs++; + if (ctrlc()) { + putc('\n'); + return 1; + } } } } @@ -797,15 +763,13 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, anti_pattern = (vu_long) 0x55555555;
debug("%s:%d: length = 0x%.8lx\n", - __FUNCTION__, __LINE__, - len); + __func__, __LINE__, len); /* * Write the default pattern at each of the * power-of-two offsets. */ - for (offset = 1; offset < len; offset <<= 1) { + for (offset = 1; offset < len; offset <<= 1) start[offset] = pattern; - }
/* * Check for address bits stuck high. @@ -816,12 +780,12 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, for (offset = 1; offset < len; offset <<= 1) { temp = start[offset]; if (temp != pattern) { - printf ("\nFAILURE: Address bit stuck high @ 0x%.8lx:" + printf("\nFAILURE: Address bit stuck high @ 0x%.8lx:" " expected 0x%.8lx, actual 0x%.8lx\n", (ulong)&start[offset], pattern, temp); errs++; if (ctrlc()) { - putc ('\n'); + putc('\n'); return 1; } } @@ -838,12 +802,12 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, for (offset = 1; offset < len; offset <<= 1) { temp = start[offset]; if ((temp != pattern) && (offset != test_offset)) { - printf ("\nFAILURE: Address bit stuck low or shorted @" + printf("\nFAILURE: Address bit stuck low or shorted @" " 0x%.8lx: expected 0x%.8lx, actual 0x%.8lx\n", (ulong)&start[offset], pattern, temp); errs++; if (ctrlc()) { - putc ('\n'); + putc('\n'); return 1; } } @@ -880,13 +844,13 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, WATCHDOG_RESET(); temp = start[offset]; if (temp != pattern) { - printf ("\nFAILURE (read/write) @ 0x%.8lx:" + printf("\nFAILURE (read/write) @ 0x%.8lx:" " expected 0x%.8lx, actual 0x%.8lx)\n", (ulong)&start[offset], pattern, temp); errs++; if (ctrlc()) { - putc ('\n'); - return 1; + putc('\n'); + return 1; } }
@@ -902,24 +866,33 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, anti_pattern = ~pattern; temp = start[offset]; if (temp != anti_pattern) { - printf ("\nFAILURE (read/write): @ 0x%.8lx:" + printf("\nFAILURE (read/write): @ 0x%.8lx:" " expected 0x%.8lx, actual 0x%.8lx)\n", (ulong)&start[offset], anti_pattern, temp); errs++; if (ctrlc()) { - putc ('\n'); - return 1; + putc('\n'); + return 1; } } start[offset] = 0; } } +} + +static int mem_test_quick(vu_long *start, vu_long *end, + int iteration_limit, vu_long pattern) +{ + vu_long *addr; + int iterations = 1; + ulong errs = 0; + ulong incr; + ulong val, readback;
-#else /* The original, quickie test */ incr = 1; for (;;) { if (ctrlc()) { - putc ('\n'); + putc('\n'); return 1; }
@@ -930,29 +903,29 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, } ++iterations;
- printf ("\rPattern %08lX Writing..." + printf("\rPattern %08lX Writing..." "%12s" "\b\b\b\b\b\b\b\b\b\b", pattern, "");
- for (addr=start,val=pattern; addr<end; addr++) { + for (addr = start, val = pattern; addr < end; addr++) { WATCHDOG_RESET(); *addr = val; - val += incr; + val += incr; }
- puts ("Reading..."); + puts("Reading...");
- for (addr=start,val=pattern; addr<end; addr++) { + for (addr = start, val = pattern; addr < end; addr++) { WATCHDOG_RESET(); readback = *addr; if (readback != val) { - printf ("\nMem error @ 0x%08X: " + printf("\nMem error @ 0x%08X: " "found %08lX, expected %08lX\n", (uint)(uintptr_t)addr, readback, val); errs++; if (ctrlc()) { - putc ('\n'); + putc('\n'); return 1; } } @@ -965,16 +938,58 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, * the "negative" patterns and increment the "positive" * patterns to preserve this feature. */ - if(pattern & 0x80000000) { + if (pattern & 0x80000000) pattern = -pattern; /* complement & increment */ - } - else { + else pattern = ~pattern; - } incr = -incr; } +} + +/* + * Perform a memory test. A more complete alternative test can be + * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until + * interrupted by ctrl-c or by a failure of one of the sub-tests. + */ +static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, + char * const argv[]) +{ + vu_long *start, *end; + int iteration_limit; + int ret; + ulong pattern; +#if defined(CONFIG_SYS_ALT_MEMTEST) + const int alt_test = 1; +#else + const int alt_test = 0; #endif - return 0; /* not reached */ + + if (argc > 1) + start = (ulong *)simple_strtoul(argv[1], NULL, 16); + else + start = (ulong *)CONFIG_SYS_MEMTEST_START; + + if (argc > 2) + end = (ulong *)simple_strtoul(argv[2], NULL, 16); + else + end = (ulong *)(CONFIG_SYS_MEMTEST_END); + + if (argc > 3) + pattern = (ulong)simple_strtoul(argv[3], NULL, 16); + else + pattern = 0; + + if (argc > 4) + iteration_limit = (ulong)simple_strtoul(argv[4], NULL, 16); + else + iteration_limit = 0; + + if (alt_test) + ret = mem_test_alt(start, end, iteration_limit); + else + ret = mem_test_quick(start, end, iteration_limit, pattern); + + return ret; /* not reached */ }

On Wed, Dec 26, 2012 at 10:56 AM, Simon Glass sjg@chromium.org wrote:
Half of the code is currently hidden behind an #ifdef. Move the two memory tests into their own functions and use the compiler to eliminate the unused code.
Signed-off-by: Simon Glass sjg@chromium.org
Applied to x86/master.
common/cmd_mem.c | 217 +++++++++++++++++++++++++++++------------------------- 1 files changed, 116 insertions(+), 101 deletions(-)

The iteration code is the same for each version of the memory test, so pull it out into the common function.
Signed-off-by: Simon Glass sjg@chromium.org --- common/cmd_mem.c | 123 ++++++++++++++++++++++++++---------------------------- 1 files changed, 59 insertions(+), 64 deletions(-)
diff --git a/common/cmd_mem.c b/common/cmd_mem.c index 36ac6f4..41c1e70 100644 --- a/common/cmd_mem.c +++ b/common/cmd_mem.c @@ -621,11 +621,9 @@ int do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) } #endif /* CONFIG_LOOPW */
-static int mem_test_alt(vu_long *start, vu_long *end, - int iteration_limit) +static ulong mem_test_alt(vu_long *start, vu_long *end) { vu_long *addr; - int iterations = 1; ulong errs = 0; ulong val, readback; int j; @@ -652,27 +650,6 @@ static int mem_test_alt(vu_long *start, vu_long *end, 0xaaaaaaaa, /* alternating 1/0 */ };
- printf("Testing %08x ... %08x:\n", (uint)(uintptr_t)start, - (uint)(uintptr_t)end); - debug("%s:%d: start 0x%p end 0x%p\n", - __func__, __LINE__, start, end); - - for (;;) { - if (ctrlc()) { - putc('\n'); - return 1; - } - - if (iteration_limit && iterations > iteration_limit) { - printf("Tested %d iteration(s) with %lu errors.\n", - iterations-1, errs); - return errs != 0; - } - - printf("Iteration: %6d\r", iterations); - debug("\n"); - iterations++; - /* * Data line test: write a pattern to the first * location, write the 1's complement to a 'parking' @@ -705,7 +682,7 @@ static int mem_test_alt(vu_long *start, vu_long *end, errs++; if (ctrlc()) { putc('\n'); - return 1; + return -1; } } *addr = ~val; @@ -718,7 +695,7 @@ static int mem_test_alt(vu_long *start, vu_long *end, errs++; if (ctrlc()) { putc('\n'); - return 1; + return -1; } } } @@ -786,7 +763,7 @@ static int mem_test_alt(vu_long *start, vu_long *end, errs++; if (ctrlc()) { putc('\n'); - return 1; + return -1; } } } @@ -808,7 +785,7 @@ static int mem_test_alt(vu_long *start, vu_long *end, errs++; if (ctrlc()) { putc('\n'); - return 1; + return -1; } } } @@ -850,7 +827,7 @@ static int mem_test_alt(vu_long *start, vu_long *end, errs++; if (ctrlc()) { putc('\n'); - return 1; + return -1; } }
@@ -872,37 +849,38 @@ static int mem_test_alt(vu_long *start, vu_long *end, errs++; if (ctrlc()) { putc('\n'); - return 1; + return -1; } } start[offset] = 0; } - } + + return 0; }
-static int mem_test_quick(vu_long *start, vu_long *end, - int iteration_limit, vu_long pattern) +static ulong mem_test_quick(vu_long *start, vu_long *end, vu_long pattern, + int iteration) { vu_long *addr; - int iterations = 1; ulong errs = 0; ulong incr; ulong val, readback;
+ /* Alternate the pattern */ incr = 1; - for (;;) { - if (ctrlc()) { - putc('\n'); - return 1; - } - - if (iteration_limit && iterations > iteration_limit) { - printf("Tested %d iteration(s) with %lu errors.\n", - iterations-1, errs); - return errs != 0; - } - ++iterations; - + if (iteration & 1) { + incr = -incr; + /* + * Flip the pattern each time to make lots of zeros and + * then, the next time, lots of ones. We decrement + * the "negative" patterns and increment the "positive" + * patterns to preserve this feature. + */ + if (pattern & 0x80000000) + pattern = -pattern; /* complement & increment */ + else + pattern = ~pattern; + } printf("\rPattern %08lX Writing..." "%12s" "\b\b\b\b\b\b\b\b\b\b", @@ -926,24 +904,13 @@ static int mem_test_quick(vu_long *start, vu_long *end, errs++; if (ctrlc()) { putc('\n'); - return 1; + return -1; } } val += incr; }
- /* - * Flip the pattern each time to make lots of zeros and - * then, the next time, lots of ones. We decrement - * the "negative" patterns and increment the "positive" - * patterns to preserve this feature. - */ - if (pattern & 0x80000000) - pattern = -pattern; /* complement & increment */ - else - pattern = ~pattern; - incr = -incr; - } + return 0; }
/* @@ -957,7 +924,9 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, vu_long *start, *end; int iteration_limit; int ret; + ulong errs = 0; /* number of errors, or -1 if interrupted */ ulong pattern; + int iteration; #if defined(CONFIG_SYS_ALT_MEMTEST) const int alt_test = 1; #else @@ -984,10 +953,36 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, else iteration_limit = 0;
- if (alt_test) - ret = mem_test_alt(start, end, iteration_limit); - else - ret = mem_test_quick(start, end, iteration_limit, pattern); + printf("Testing %08x ... %08x:\n", (uint)(uintptr_t)start, + (uint)(uintptr_t)end); + debug("%s:%d: start 0x%p end 0x%p\n", + __func__, __LINE__, start, end); + + for (iteration = 0; + !iteration_limit || iteration < iteration_limit; + iteration++) { + if (ctrlc()) { + putc('\n'); + errs = -1UL; + break; + } + + printf("Iteration: %6d\r", iteration + 1); + debug("\n"); + if (alt_test) + errs = mem_test_alt(start, end); + else + errs = mem_test_quick(start, end, pattern, iteration); + } + + if (errs == -1UL) { + /* Memory test was aborted */ + ret = 1; + } else { + printf("Tested %d iteration(s) with %lu errors.\n", + iteration, errs); + ret = errs != 0; + }
return ret; /* not reached */ }

On Wed, Dec 26, 2012 at 10:57 AM, Simon Glass sjg@chromium.org wrote:
The iteration code is the same for each version of the memory test, so pull it out into the common function.
Signed-off-by: Simon Glass sjg@chromium.org
Applied to x86/master.
common/cmd_mem.c | 123 ++++++++++++++++++++++++++---------------------------- 1 files changed, 59 insertions(+), 64 deletions(-)

Some of the inner loops are not indented correctly. Fix this.
Signed-off-by: Simon Glass sjg@chromium.org --- common/cmd_mem.c | 324 +++++++++++++++++++++++++++--------------------------- 1 files changed, 162 insertions(+), 162 deletions(-)
diff --git a/common/cmd_mem.c b/common/cmd_mem.c index 41c1e70..648f93b 100644 --- a/common/cmd_mem.c +++ b/common/cmd_mem.c @@ -650,32 +650,31 @@ static ulong mem_test_alt(vu_long *start, vu_long *end) 0xaaaaaaaa, /* alternating 1/0 */ };
- /* - * Data line test: write a pattern to the first - * location, write the 1's complement to a 'parking' - * address (changes the state of the data bus so a - * floating bus doen't give a false OK), and then - * read the value back. Note that we read it back - * into a variable because the next time we read it, - * it might be right (been there, tough to explain to - * the quality guys why it prints a failure when the - * "is" and "should be" are obviously the same in the - * error message). - * - * Rather than exhaustively testing, we test some - * patterns by shifting '1' bits through a field of - * '0's and '0' bits through a field of '1's (i.e. - * pattern and ~pattern). - */ - addr = start; - for (j = 0; j < sizeof(bitpattern) / sizeof(bitpattern[0]); - j++) { - val = bitpattern[j]; - for (; val != 0; val <<= 1) { + /* + * Data line test: write a pattern to the first + * location, write the 1's complement to a 'parking' + * address (changes the state of the data bus so a + * floating bus doen't give a false OK), and then + * read the value back. Note that we read it back + * into a variable because the next time we read it, + * it might be right (been there, tough to explain to + * the quality guys why it prints a failure when the + * "is" and "should be" are obviously the same in the + * error message). + * + * Rather than exhaustively testing, we test some + * patterns by shifting '1' bits through a field of + * '0's and '0' bits through a field of '1's (i.e. + * pattern and ~pattern). + */ + addr = start; + for (j = 0; j < sizeof(bitpattern) / sizeof(bitpattern[0]); j++) { + val = bitpattern[j]; + for (; val != 0; val <<= 1) { *addr = val; *dummy = ~val; /* clear the test data off the bus */ readback = *addr; - if(readback != val) { + if (readback != val) { printf("FAILURE (data line): " "expected %08lx, actual %08lx\n", val, readback); @@ -698,129 +697,130 @@ static ulong mem_test_alt(vu_long *start, vu_long *end) return -1; } } - } } + }
- /* - * Based on code whose Original Author and Copyright - * information follows: Copyright (c) 1998 by Michael - * Barr. This software is placed into the public - * domain and may be used for any purpose. However, - * this notice must not be changed or removed and no - * warranty is either expressed or implied by its - * publication or distribution. - */ - - /* - * Address line test - * - * Description: Test the address bus wiring in a - * memory region by performing a walking - * 1's test on the relevant bits of the - * address and checking for aliasing. - * This test will find single-bit - * address failures such as stuck -high, - * stuck-low, and shorted pins. The base - * address and size of the region are - * selected by the caller. - * - * Notes: For best results, the selected base - * address should have enough LSB 0's to - * guarantee single address bit changes. - * For example, to test a 64-Kbyte - * region, select a base address on a - * 64-Kbyte boundary. Also, select the - * region size as a power-of-two if at - * all possible. - * - * Returns: 0 if the test succeeds, 1 if the test fails. - */ - len = ((ulong)end - (ulong)start)/sizeof(vu_long); - pattern = (vu_long) 0xaaaaaaaa; - anti_pattern = (vu_long) 0x55555555; + /* + * Based on code whose Original Author and Copyright + * information follows: Copyright (c) 1998 by Michael + * Barr. This software is placed into the public + * domain and may be used for any purpose. However, + * this notice must not be changed or removed and no + * warranty is either expressed or implied by its + * publication or distribution. + */
- debug("%s:%d: length = 0x%.8lx\n", - __func__, __LINE__, len); - /* - * Write the default pattern at each of the - * power-of-two offsets. - */ - for (offset = 1; offset < len; offset <<= 1) - start[offset] = pattern; + /* + * Address line test + + * Description: Test the address bus wiring in a + * memory region by performing a walking + * 1's test on the relevant bits of the + * address and checking for aliasing. + * This test will find single-bit + * address failures such as stuck -high, + * stuck-low, and shorted pins. The base + * address and size of the region are + * selected by the caller. + + * Notes: For best results, the selected base + * address should have enough LSB 0's to + * guarantee single address bit changes. + * For example, to test a 64-Kbyte + * region, select a base address on a + * 64-Kbyte boundary. Also, select the + * region size as a power-of-two if at + * all possible. + * + * Returns: 0 if the test succeeds, 1 if the test fails. + */ + len = ((ulong)end - (ulong)start)/sizeof(vu_long); + pattern = (vu_long) 0xaaaaaaaa; + anti_pattern = (vu_long) 0x55555555; + + debug("%s:%d: length = 0x%.8lx\n", + __func__, __LINE__, len); + /* + * Write the default pattern at each of the + * power-of-two offsets. + */ + for (offset = 1; offset < len; offset <<= 1) + start[offset] = pattern;
- /* - * Check for address bits stuck high. - */ - test_offset = 0; - start[test_offset] = anti_pattern; + /* + * Check for address bits stuck high. + */ + test_offset = 0; + start[test_offset] = anti_pattern;
- for (offset = 1; offset < len; offset <<= 1) { - temp = start[offset]; - if (temp != pattern) { + for (offset = 1; offset < len; offset <<= 1) { + temp = start[offset]; + if (temp != pattern) { printf("\nFAILURE: Address bit stuck high @ 0x%.8lx:" " expected 0x%.8lx, actual 0x%.8lx\n", (ulong)&start[offset], pattern, temp); errs++; if (ctrlc()) { - putc('\n'); - return -1; + putc('\n'); + return -1; } - } } - start[test_offset] = pattern; - WATCHDOG_RESET(); + } + start[test_offset] = pattern; + WATCHDOG_RESET();
- /* - * Check for addr bits stuck low or shorted. - */ - for (test_offset = 1; test_offset < len; test_offset <<= 1) { - start[test_offset] = anti_pattern; + /* + * Check for addr bits stuck low or shorted. + */ + for (test_offset = 1; test_offset < len; test_offset <<= 1) { + start[test_offset] = anti_pattern;
- for (offset = 1; offset < len; offset <<= 1) { + for (offset = 1; offset < len; offset <<= 1) { temp = start[offset]; if ((temp != pattern) && (offset != test_offset)) { - printf("\nFAILURE: Address bit stuck low or shorted @" - " 0x%.8lx: expected 0x%.8lx, actual 0x%.8lx\n", - (ulong)&start[offset], pattern, temp); - errs++; - if (ctrlc()) { - putc('\n'); - return -1; - } + printf("\nFAILURE: Address bit stuck low or" + " shorted @ 0x%.8lx: expected 0x%.8lx," + " actual 0x%.8lx\n", + (ulong)&start[offset], pattern, temp); + errs++; + if (ctrlc()) { + putc('\n'); + return -1; + } } - } - start[test_offset] = pattern; } + start[test_offset] = pattern; + }
- /* - * Description: Test the integrity of a physical - * memory device by performing an - * increment/decrement test over the - * entire region. In the process every - * storage bit in the device is tested - * as a zero and a one. The base address - * and the size of the region are - * selected by the caller. - * - * Returns: 0 if the test succeeds, 1 if the test fails. - */ - num_words = ((ulong)end - (ulong)start)/sizeof(vu_long) + 1; + /* + * Description: Test the integrity of a physical + * memory device by performing an + * increment/decrement test over the + * entire region. In the process every + * storage bit in the device is tested + * as a zero and a one. The base address + * and the size of the region are + * selected by the caller. + * + * Returns: 0 if the test succeeds, 1 if the test fails. + */ + num_words = ((ulong)end - (ulong)start)/sizeof(vu_long) + 1;
- /* - * Fill memory with a known pattern. - */ - for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) { - WATCHDOG_RESET(); - start[offset] = pattern; - } + /* + * Fill memory with a known pattern. + */ + for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) { + WATCHDOG_RESET(); + start[offset] = pattern; + }
- /* - * Check each location and invert it for the second pass. - */ - for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) { - WATCHDOG_RESET(); - temp = start[offset]; - if (temp != pattern) { + /* + * Check each location and invert it for the second pass. + */ + for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) { + WATCHDOG_RESET(); + temp = start[offset]; + if (temp != pattern) { printf("\nFAILURE (read/write) @ 0x%.8lx:" " expected 0x%.8lx, actual 0x%.8lx)\n", (ulong)&start[offset], pattern, temp); @@ -829,20 +829,20 @@ static ulong mem_test_alt(vu_long *start, vu_long *end) putc('\n'); return -1; } - } - - anti_pattern = ~pattern; - start[offset] = anti_pattern; }
- /* - * Check each location for the inverted pattern and zero it. - */ - for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) { - WATCHDOG_RESET(); - anti_pattern = ~pattern; - temp = start[offset]; - if (temp != anti_pattern) { + anti_pattern = ~pattern; + start[offset] = anti_pattern; + } + + /* + * Check each location for the inverted pattern and zero it. + */ + for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) { + WATCHDOG_RESET(); + anti_pattern = ~pattern; + temp = start[offset]; + if (temp != anti_pattern) { printf("\nFAILURE (read/write): @ 0x%.8lx:" " expected 0x%.8lx, actual 0x%.8lx)\n", (ulong)&start[offset], anti_pattern, temp); @@ -851,9 +851,9 @@ static ulong mem_test_alt(vu_long *start, vu_long *end) putc('\n'); return -1; } - } - start[offset] = 0; } + start[offset] = 0; + }
return 0; } @@ -881,34 +881,34 @@ static ulong mem_test_quick(vu_long *start, vu_long *end, vu_long pattern, else pattern = ~pattern; } - printf("\rPattern %08lX Writing..." - "%12s" - "\b\b\b\b\b\b\b\b\b\b", - pattern, ""); + printf("\rPattern %08lX Writing..." + "%12s" + "\b\b\b\b\b\b\b\b\b\b", + pattern, "");
- for (addr = start, val = pattern; addr < end; addr++) { - WATCHDOG_RESET(); - *addr = val; - val += incr; - } + for (addr = start, val = pattern; addr < end; addr++) { + WATCHDOG_RESET(); + *addr = val; + val += incr; + }
- puts("Reading..."); + puts("Reading...");
- for (addr = start, val = pattern; addr < end; addr++) { - WATCHDOG_RESET(); - readback = *addr; - if (readback != val) { - printf("\nMem error @ 0x%08X: " - "found %08lX, expected %08lX\n", - (uint)(uintptr_t)addr, readback, val); - errs++; - if (ctrlc()) { - putc('\n'); - return -1; - } + for (addr = start, val = pattern; addr < end; addr++) { + WATCHDOG_RESET(); + readback = *addr; + if (readback != val) { + printf("\nMem error @ 0x%08X: " + "found %08lX, expected %08lX\n", + (uint)(uintptr_t)addr, readback, val); + errs++; + if (ctrlc()) { + putc('\n'); + return -1; } - val += incr; } + val += incr; + }
return 0; }

On Wed, Dec 26, 2012 at 10:57 AM, Simon Glass sjg@chromium.org wrote:
Some of the inner loops are not indented correctly. Fix this.
Signed-off-by: Simon Glass sjg@chromium.org
Applied to x86/master.
common/cmd_mem.c | 324 +++++++++++++++++++++++++++--------------------------- 1 files changed, 162 insertions(+), 162 deletions(-)

If we get a Ctrl-C abort, we always print a newline. Move this repeated code out of the functions and into a single place in the caller.
Signed-off-by: Simon Glass sjg@chromium.org --- common/cmd_mem.c | 32 +++++++++----------------------- 1 files changed, 9 insertions(+), 23 deletions(-)
diff --git a/common/cmd_mem.c b/common/cmd_mem.c index 648f93b..a2f6cda 100644 --- a/common/cmd_mem.c +++ b/common/cmd_mem.c @@ -679,10 +679,8 @@ static ulong mem_test_alt(vu_long *start, vu_long *end) "expected %08lx, actual %08lx\n", val, readback); errs++; - if (ctrlc()) { - putc('\n'); + if (ctrlc()) return -1; - } } *addr = ~val; *dummy = val; @@ -692,10 +690,8 @@ static ulong mem_test_alt(vu_long *start, vu_long *end) "Is %08lx, should be %08lx\n", readback, ~val); errs++; - if (ctrlc()) { - putc('\n'); + if (ctrlc()) return -1; - } } } } @@ -760,10 +756,8 @@ static ulong mem_test_alt(vu_long *start, vu_long *end) " expected 0x%.8lx, actual 0x%.8lx\n", (ulong)&start[offset], pattern, temp); errs++; - if (ctrlc()) { - putc('\n'); + if (ctrlc()) return -1; - } } } start[test_offset] = pattern; @@ -783,10 +777,8 @@ static ulong mem_test_alt(vu_long *start, vu_long *end) " actual 0x%.8lx\n", (ulong)&start[offset], pattern, temp); errs++; - if (ctrlc()) { - putc('\n'); + if (ctrlc()) return -1; - } } } start[test_offset] = pattern; @@ -825,10 +817,8 @@ static ulong mem_test_alt(vu_long *start, vu_long *end) " expected 0x%.8lx, actual 0x%.8lx)\n", (ulong)&start[offset], pattern, temp); errs++; - if (ctrlc()) { - putc('\n'); + if (ctrlc()) return -1; - } }
anti_pattern = ~pattern; @@ -847,10 +837,8 @@ static ulong mem_test_alt(vu_long *start, vu_long *end) " expected 0x%.8lx, actual 0x%.8lx)\n", (ulong)&start[offset], anti_pattern, temp); errs++; - if (ctrlc()) { - putc('\n'); + if (ctrlc()) return -1; - } } start[offset] = 0; } @@ -902,10 +890,8 @@ static ulong mem_test_quick(vu_long *start, vu_long *end, vu_long pattern, "found %08lX, expected %08lX\n", (uint)(uintptr_t)addr, readback, val); errs++; - if (ctrlc()) { - putc('\n'); + if (ctrlc()) return -1; - } } val += incr; } @@ -962,7 +948,6 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, !iteration_limit || iteration < iteration_limit; iteration++) { if (ctrlc()) { - putc('\n'); errs = -1UL; break; } @@ -976,7 +961,8 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, }
if (errs == -1UL) { - /* Memory test was aborted */ + /* Memory test was aborted - write a newline to finish off */ + putc('\n'); ret = 1; } else { printf("Tested %d iteration(s) with %lu errors.\n",

On Wed, Dec 26, 2012 at 10:57 AM, Simon Glass sjg@chromium.org wrote:
If we get a Ctrl-C abort, we always print a newline. Move this repeated code out of the functions and into a single place in the caller.
Signed-off-by: Simon Glass sjg@chromium.org
Applied to x86/master.
common/cmd_mem.c | 32 +++++++++----------------------- 1 files changed, 9 insertions(+), 23 deletions(-)

Use a ulong for the command arguments, and only cast to an address when needed. This fixes warnings in sandbox where pointers are typically 64 bits long.
Signed-off-by: Simon Glass sjg@chromium.org --- common/cmd_mem.c | 30 ++++++++++++++++++------------ 1 files changed, 18 insertions(+), 12 deletions(-)
diff --git a/common/cmd_mem.c b/common/cmd_mem.c index a2f6cda..c45a31e 100644 --- a/common/cmd_mem.c +++ b/common/cmd_mem.c @@ -621,8 +621,9 @@ int do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) } #endif /* CONFIG_LOOPW */
-static ulong mem_test_alt(vu_long *start, vu_long *end) +static ulong mem_test_alt(ulong start_addr, ulong end_addr) { + vu_long *start, *end; vu_long *addr; ulong errs = 0; ulong val, readback; @@ -650,6 +651,9 @@ static ulong mem_test_alt(vu_long *start, vu_long *end) 0xaaaaaaaa, /* alternating 1/0 */ };
+ start = (vu_long *)start_addr; + end = (vu_long *)end_addr; + /* * Data line test: write a pattern to the first * location, write the 1's complement to a 'parking' @@ -730,7 +734,7 @@ static ulong mem_test_alt(vu_long *start, vu_long *end) * * Returns: 0 if the test succeeds, 1 if the test fails. */ - len = ((ulong)end - (ulong)start)/sizeof(vu_long); + len = (end_addr - start_addr) / sizeof(vu_long); pattern = (vu_long) 0xaaaaaaaa; anti_pattern = (vu_long) 0x55555555;
@@ -846,9 +850,10 @@ static ulong mem_test_alt(vu_long *start, vu_long *end) return 0; }
-static ulong mem_test_quick(vu_long *start, vu_long *end, vu_long pattern, +static ulong mem_test_quick(ulong start_addr, ulong end_addr, vu_long pattern, int iteration) { + vu_long *start, *end; vu_long *addr; ulong errs = 0; ulong incr; @@ -869,6 +874,8 @@ static ulong mem_test_quick(vu_long *start, vu_long *end, vu_long pattern, else pattern = ~pattern; } + start = (vu_long *)start_addr; + end = (vu_long *)end_addr; printf("\rPattern %08lX Writing..." "%12s" "\b\b\b\b\b\b\b\b\b\b", @@ -907,7 +914,7 @@ static ulong mem_test_quick(vu_long *start, vu_long *end, vu_long pattern, static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { - vu_long *start, *end; + ulong start, end; int iteration_limit; int ret; ulong errs = 0; /* number of errors, or -1 if interrupted */ @@ -920,14 +927,14 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, #endif
if (argc > 1) - start = (ulong *)simple_strtoul(argv[1], NULL, 16); + start = simple_strtoul(argv[1], NULL, 16); else - start = (ulong *)CONFIG_SYS_MEMTEST_START; + start = CONFIG_SYS_MEMTEST_START;
if (argc > 2) - end = (ulong *)simple_strtoul(argv[2], NULL, 16); + end = simple_strtoul(argv[2], NULL, 16); else - end = (ulong *)(CONFIG_SYS_MEMTEST_END); + end = CONFIG_SYS_MEMTEST_END;
if (argc > 3) pattern = (ulong)simple_strtoul(argv[3], NULL, 16); @@ -939,10 +946,9 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, else iteration_limit = 0;
- printf("Testing %08x ... %08x:\n", (uint)(uintptr_t)start, - (uint)(uintptr_t)end); - debug("%s:%d: start 0x%p end 0x%p\n", - __func__, __LINE__, start, end); + printf("Testing %08x ... %08x:\n", (uint)start, (uint)end); + debug("%s:%d: start %#08lx end %#08lx\n", __func__, __LINE__, + start, end);
for (iteration = 0; !iteration_limit || iteration < iteration_limit;

On Wed, Dec 26, 2012 at 10:57 AM, Simon Glass sjg@chromium.org wrote:
Use a ulong for the command arguments, and only cast to an address when needed. This fixes warnings in sandbox where pointers are typically 64 bits long.
Signed-off-by: Simon Glass sjg@chromium.org
Applied to x86/master.
common/cmd_mem.c | 30 ++++++++++++++++++------------ 1 files changed, 18 insertions(+), 12 deletions(-)

We might as well use this common function instead of repeating the same code.
Signed-off-by: Simon Glass sjg@chromium.org --- common/cmd_fdt.c | 11 ++--------- common/cmd_nvedit.c | 8 ++++---- include/common.h | 14 +++++++++++++- 3 files changed, 19 insertions(+), 14 deletions(-)
diff --git a/common/cmd_fdt.c b/common/cmd_fdt.c index 9e2de34..0bdf7b6 100644 --- a/common/cmd_fdt.c +++ b/common/cmd_fdt.c @@ -56,12 +56,8 @@ struct fdt_header *working_fdt;
void set_working_fdt_addr(void *addr) { - char buf[17]; - working_fdt = addr; - - sprintf(buf, "%lx", (unsigned long)addr); - setenv("fdtaddr", buf); + setenv_addr("fdtaddr", addr); }
/* @@ -348,10 +344,7 @@ static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) } if (subcmd[0] == 's') { /* get the num nodes at this level */ - char buf[11]; - - sprintf(buf, "%d", curIndex + 1); - setenv(var, buf); + setenv_ulong(var, curIndex + 1); } else { /* node index not found */ printf("libfdt node not found\n"); diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index 7633f0c..44e88aa 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -295,17 +295,17 @@ int setenv_ulong(const char *varname, ulong value) }
/** - * Set an environment variable to an address in hex + * Set an environment variable to an value in hex * * @param varname Environmet variable to set - * @param addr Value to set it to + * @param value Value to set it to * @return 0 if ok, 1 on error */ -int setenv_addr(const char *varname, const void *addr) +int setenv_hex(const char *varname, ulong value) { char str[17];
- sprintf(str, "%lx", (uintptr_t)addr); + sprintf(str, "%lx", value); return setenv(varname, str); }
diff --git a/include/common.h b/include/common.h index 08d01db..8ecaf56 100644 --- a/include/common.h +++ b/include/common.h @@ -349,7 +349,19 @@ int getenv_yesno(const char *var); int saveenv (void); int setenv (const char *, const char *); int setenv_ulong(const char *varname, ulong value); -int setenv_addr(const char *varname, const void *addr); +int setenv_hex(const char *varname, ulong value); +/** + * setenv_addr - Set an environment variable to an address in hex + * + * @varname: Environmet variable to set + * @addr: Value to set it to + * @return 0 if ok, 1 on error + */ +static inline int setenv_addr(const char *varname, const void *addr) +{ + return setenv_hex(varname, (ulong)addr); +} + #ifdef CONFIG_ARM # include <asm/mach-types.h> # include <asm/setup.h>

When using $fdtaddr in $bootcmd and $bootcmd is automatically called, $fdtaddr is yet not defined.
Signed-off-by: Barak Wasserstrom wbarak@gmail.com --- common/main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/common/main.c b/common/main.c index e2d2e09..77b9076 100644 --- a/common/main.c +++ b/common/main.c @@ -378,6 +378,10 @@ void main_loop (void)
bootstage_mark_name(BOOTSTAGE_ID_MAIN_LOOP, "main_loop");
+#if defined CONFIG_OF_CONTROL + set_working_fdt_addr((void *)gd->fdt_blob); +#endif /* CONFIG_OF_CONTROL */ + #ifdef CONFIG_BOOTCOUNT_LIMIT bootcount = bootcount_load(); bootcount++; @@ -500,10 +504,6 @@ void main_loop (void) #endif /* CONFIG_MENUKEY */ #endif /* CONFIG_BOOTDELAY */
-#if defined CONFIG_OF_CONTROL - set_working_fdt_addr((void *)gd->fdt_blob); -#endif /* CONFIG_OF_CONTROL */ - /* * Main Loop for Monitor Command Processing */

On Wed, Dec 26, 2012 at 10:57 AM, Simon Glass sjg@chromium.org wrote:
We might as well use this common function instead of repeating the same code.
Signed-off-by: Simon Glass sjg@chromium.org
Applied to x86/master.
common/cmd_fdt.c | 11 ++--------- common/cmd_nvedit.c | 8 ++++---- include/common.h | 14 +++++++++++++- 3 files changed, 19 insertions(+), 14 deletions(-)

When using $fdtaddr in $bootcmd and $bootcmd is automatically called, $fdtaddr is yet not defined.
Signed-off-by: Barak Wasserstrom wbarak@gmail.com --- common/main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/common/main.c b/common/main.c index e2d2e09..77b9076 100644 --- a/common/main.c +++ b/common/main.c @@ -378,6 +378,10 @@ void main_loop (void)
bootstage_mark_name(BOOTSTAGE_ID_MAIN_LOOP, "main_loop");
+#if defined CONFIG_OF_CONTROL + set_working_fdt_addr((void *)gd->fdt_blob); +#endif /* CONFIG_OF_CONTROL */ + #ifdef CONFIG_BOOTCOUNT_LIMIT bootcount = bootcount_load(); bootcount++; @@ -500,10 +504,6 @@ void main_loop (void) #endif /* CONFIG_MENUKEY */ #endif /* CONFIG_BOOTDELAY */
-#if defined CONFIG_OF_CONTROL - set_working_fdt_addr((void *)gd->fdt_blob); -#endif /* CONFIG_OF_CONTROL */ - /* * Main Loop for Monitor Command Processing */

When using $fdtaddr in $bootcmd and $bootcmd is automatically called, $fdtaddr is yet not defined.
Signed-off-by: Barak Wasserstrom wbarak@gmail.com --- common/main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/common/main.c b/common/main.c index e2d2e09..77b9076 100644 --- a/common/main.c +++ b/common/main.c @@ -378,6 +378,10 @@ void main_loop (void)
bootstage_mark_name(BOOTSTAGE_ID_MAIN_LOOP, "main_loop");
+#if defined CONFIG_OF_CONTROL + set_working_fdt_addr((void *)gd->fdt_blob); +#endif /* CONFIG_OF_CONTROL */ + #ifdef CONFIG_BOOTCOUNT_LIMIT bootcount = bootcount_load(); bootcount++; @@ -500,10 +504,6 @@ void main_loop (void) #endif /* CONFIG_MENUKEY */ #endif /* CONFIG_BOOTDELAY */
-#if defined CONFIG_OF_CONTROL - set_working_fdt_addr((void *)gd->fdt_blob); -#endif /* CONFIG_OF_CONTROL */ - /* * Main Loop for Monitor Command Processing */

Use setenv_ulong(), setenv_hex() and setenv_addr() in common/
Signed-off-by: Simon Glass sjg@chromium.org --- common/cmd_bootm.c | 11 +++-------- common/cmd_cbfs.c | 4 +--- common/cmd_cramfs.c | 4 +--- common/cmd_fdos.c | 4 +--- common/cmd_jffs2.c | 4 +--- common/cmd_load.c | 12 +++--------- common/cmd_mtdparts.c | 4 +--- common/cmd_nand.c | 12 +++--------- common/cmd_nvedit.c | 3 +-- common/cmd_reiser.c | 4 +--- common/cmd_setexpr.c | 39 +++++++++++++++++++++++++++------------ common/cmd_unzip.c | 4 +--- common/cmd_ximg.c | 7 ++----- common/cmd_zfs.c | 3 +-- common/cmd_zip.c | 4 +--- 15 files changed, 48 insertions(+), 71 deletions(-)
diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c index f7595c0..2debfe3 100644 --- a/common/cmd_bootm.c +++ b/common/cmd_bootm.c @@ -447,9 +447,7 @@ static int bootm_start_standalone(ulong iflag, int argc, char * const argv[])
/* Don't start if "autostart" is set to "no" */ if (((s = getenv("autostart")) != NULL) && (strcmp(s, "no") == 0)) { - char buf[32]; - sprintf(buf, "%lX", images.os.image_len); - setenv("filesize", buf); + setenv_hex("filesize", images.os.image_len); return 0; } appl = (int (*)(int, char * const []))(ulong)ntohl(images.ep); @@ -523,17 +521,14 @@ static int do_bootm_subcommand(cmd_tbl_t *cmdtp, int flag, int argc, case BOOTM_STATE_RAMDISK: { ulong rd_len = images.rd_end - images.rd_start; - char str[17];
ret = boot_ramdisk_high(&images.lmb, images.rd_start, rd_len, &images.initrd_start, &images.initrd_end); if (ret) return ret;
- sprintf(str, "%lx", images.initrd_start); - setenv("initrd_start", str); - sprintf(str, "%lx", images.initrd_end); - setenv("initrd_end", str); + setenv_hex("initrd_start", images.initrd_start); + setenv_hex("initrd_end", images.initrd_end); } break; #endif diff --git a/common/cmd_cbfs.c b/common/cmd_cbfs.c index 3b6cfd8..f51534b 100644 --- a/common/cmd_cbfs.c +++ b/common/cmd_cbfs.c @@ -65,7 +65,6 @@ int do_cbfs_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) const struct cbfs_cachenode *file; unsigned long offset; unsigned long count; - char buf[12]; long size;
if (argc < 3) { @@ -95,8 +94,7 @@ int do_cbfs_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
printf("\n%ld bytes read\n", size);
- sprintf(buf, "%lX", size); - setenv("filesize", buf); + setenv_hex("filesize", size);
return 0; } diff --git a/common/cmd_cramfs.c b/common/cmd_cramfs.c index e7f496e..0e43ab6 100644 --- a/common/cmd_cramfs.c +++ b/common/cmd_cramfs.c @@ -146,11 +146,9 @@ int do_cramfs_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) size = cramfs_load ((char *) offset, &part, filename);
if (size > 0) { - char buf[10]; printf("### CRAMFS load complete: %d bytes loaded to 0x%lx\n", size, offset); - sprintf(buf, "%x", size); - setenv("filesize", buf); + setenv_hex("filesize", size); } else { printf("### CRAMFS LOAD ERROR<%x> for %s!\n", size, filename); } diff --git a/common/cmd_fdos.c b/common/cmd_fdos.c index fbee861..5a35cc1 100644 --- a/common/cmd_fdos.c +++ b/common/cmd_fdos.c @@ -40,7 +40,6 @@ int do_fdosboot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) char *name; char *ep; int size; - char buf [12]; int drive = CONFIG_SYS_FDC_DRIVE_NUMBER;
/* pre-set load_addr */ @@ -91,8 +90,7 @@ int do_fdosboot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) } flush_cache (load_addr, size);
- sprintf(buf, "%x", size); - setenv("filesize", buf); + setenv_hex("filesize", size);
printf("Floppy DOS load complete: %d bytes loaded to 0x%lx\n", size, load_addr); diff --git a/common/cmd_jffs2.c b/common/cmd_jffs2.c index 27296dd..4a4a000 100644 --- a/common/cmd_jffs2.c +++ b/common/cmd_jffs2.c @@ -525,11 +525,9 @@ int do_jffs2_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) }
if (size > 0) { - char buf[10]; printf("### %s load complete: %d bytes loaded to 0x%lx\n", fsname, size, offset); - sprintf(buf, "%x", size); - setenv("filesize", buf); + setenv_hex("filesize", size); } else { printf("### %s LOAD ERROR<%x> for %s!\n", fsname, size, filename); } diff --git a/common/cmd_load.c b/common/cmd_load.c index 2c8dab1..e56b983 100644 --- a/common/cmd_load.c +++ b/common/cmd_load.c @@ -149,7 +149,6 @@ static ulong load_serial(long offset) int type; /* return code for record type */ ulong addr; /* load address from S-Record */ ulong size; /* number of bytes transferred */ - char buf[32]; ulong store_addr; ulong start_addr = ~0; ulong end_addr = 0; @@ -198,8 +197,7 @@ static ulong load_serial(long offset) start_addr, end_addr, size, size ); flush_cache(start_addr, size); - sprintf(buf, "%lX", size); - setenv("filesize", buf); + setenv_hex("filesize", size); return (addr); case SREC_START: break; @@ -519,7 +517,6 @@ static int do_load_serial_bin(cmd_tbl_t *cmdtp, int flag, int argc, static ulong load_serial_bin(ulong offset) { int size, i; - char buf[32];
set_kerm_bin_mode((ulong *) offset); size = k_recv(); @@ -539,8 +536,7 @@ static ulong load_serial_bin(ulong offset) flush_cache(offset, size);
printf("## Total Size = 0x%08x = %d Bytes\n", size, size); - sprintf(buf, "%X", size); - setenv("filesize", buf); + setenv_hex("filesize", size);
return offset; } @@ -965,7 +961,6 @@ static int getcxmodem(void) { static ulong load_serial_ymodem(ulong offset) { int size; - char buf[32]; int err; int res; connection_info_t info; @@ -1012,8 +1007,7 @@ static ulong load_serial_ymodem(ulong offset) flush_cache(offset, size);
printf("## Total Size = 0x%08x = %d Bytes\n", size, size); - sprintf(buf, "%X", size); - setenv("filesize", buf); + setenv_hex("filesize", size);
return offset; } diff --git a/common/cmd_mtdparts.c b/common/cmd_mtdparts.c index 06fc171..0cfca0c 100644 --- a/common/cmd_mtdparts.c +++ b/common/cmd_mtdparts.c @@ -230,7 +230,6 @@ static void memsize_format(char *buf, u32 size) */ static void index_partitions(void) { - char buf[16]; u16 mtddevnum; struct part_info *part; struct list_head *dentry; @@ -244,8 +243,7 @@ static void index_partitions(void) dev = list_entry(dentry, struct mtd_device, link); if (dev == current_mtd_dev) { mtddevnum += current_mtd_partnum; - sprintf(buf, "%d", mtddevnum); - setenv("mtddevnum", buf); + setenv_ulong("mtddevnum", mtddevnum); break; } mtddevnum += dev->num_parts; diff --git a/common/cmd_nand.c b/common/cmd_nand.c index 1568594..6ebd333 100644 --- a/common/cmd_nand.c +++ b/common/cmd_nand.c @@ -373,7 +373,6 @@ static void nand_print_and_set_info(int idx) { nand_info_t *nand = &nand_info[idx]; struct nand_chip *chip = nand->priv; - char buf[32];
printf("Device %d: ", idx); if (chip->numchips > 1) @@ -385,14 +384,9 @@ static void nand_print_and_set_info(int idx) printf(" Erase size %8d b\n", nand->erasesize);
/* Set geometry info */ - sprintf(buf, "%x", nand->writesize); - setenv("nand_writesize", buf); - - sprintf(buf, "%x", nand->oobsize); - setenv("nand_oobsize", buf); - - sprintf(buf, "%x", nand->erasesize); - setenv("nand_erasesize", buf); + setenv_hex("nand_writesize", nand->writesize); + setenv_hex("nand_oobsize", nand->oobsize); + setenv_hex("nand_erasesize", nand->erasesize); }
static int raw_access(nand_info_t *nand, ulong addr, loff_t off, ulong count, diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index 44e88aa..d646d90 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -891,8 +891,7 @@ NXTARG: ; envp->flags = ACTIVE_FLAG; #endif } - sprintf(buf, "%zX", (size_t)(len + offsetof(env_t, data))); - setenv("filesize", buf); + setenv_hex("filesize", len + offsetof(env_t, data));
return 0;
diff --git a/common/cmd_reiser.c b/common/cmd_reiser.c index e658618..717c7f6 100644 --- a/common/cmd_reiser.c +++ b/common/cmd_reiser.c @@ -100,7 +100,6 @@ int do_reiserload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) ulong addr = 0, filelen; disk_partition_t info; block_dev_desc_t *dev_desc = NULL; - char buf [12]; unsigned long count; char *addr_str;
@@ -175,8 +174,7 @@ int do_reiserload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) load_addr = addr;
printf ("\n%ld bytes read\n", filelen); - sprintf(buf, "%lX", filelen); - setenv("filesize", buf); + setenv_hex("filesize", filelen);
return filelen; } diff --git a/common/cmd_setexpr.c b/common/cmd_setexpr.c index 5a04295..7a38e94 100644 --- a/common/cmd_setexpr.c +++ b/common/cmd_setexpr.c @@ -53,7 +53,7 @@ static ulong get_arg(char *s, int w) static int do_setexpr(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { ulong a, b; - char buf[16]; + ulong value; int w;
/* Validate arguments */ @@ -67,8 +67,7 @@ static int do_setexpr(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) a = get_arg(argv[2], w);
if (argc == 3) { - sprintf(buf, "%lx", a); - setenv(argv[1], buf); + setenv_hex(argv[1], a);
return 0; } @@ -76,20 +75,36 @@ static int do_setexpr(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) b = get_arg(argv[4], w);
switch (argv[3][0]) { - case '|': sprintf(buf, "%lx", (a | b)); break; - case '&': sprintf(buf, "%lx", (a & b)); break; - case '+': sprintf(buf, "%lx", (a + b)); break; - case '^': sprintf(buf, "%lx", (a ^ b)); break; - case '-': sprintf(buf, "%lx", (a - b)); break; - case '*': sprintf(buf, "%lx", (a * b)); break; - case '/': sprintf(buf, "%lx", (a / b)); break; - case '%': sprintf(buf, "%lx", (a % b)); break; + case '|': + value = a | b; + break; + case '&': + value = a & b; + break; + case '+': + value = a + b; + break; + case '^': + value = a ^ b; + break; + case '-': + value = a - b; + break; + case '*': + value = a * b; + break; + case '/': + value = a / b; + break; + case '%': + value = a % b; + break; default: printf("invalid op\n"); return 1; }
- setenv(argv[1], buf); + setenv_hex(argv[1], value);
return 0; } diff --git a/common/cmd_unzip.c b/common/cmd_unzip.c index 43ed791..7470c2b 100644 --- a/common/cmd_unzip.c +++ b/common/cmd_unzip.c @@ -28,7 +28,6 @@ static int do_unzip(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { unsigned long src, dst; unsigned long src_len = ~0UL, dst_len = ~0UL; - char buf[32];
switch (argc) { case 4: @@ -46,8 +45,7 @@ static int do_unzip(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) return 1;
printf("Uncompressed size: %ld = 0x%lX\n", src_len, src_len); - sprintf(buf, "%lX", src_len); - setenv("filesize", buf); + setenv_hex("filesize", src_len);
return 0; } diff --git a/common/cmd_ximg.c b/common/cmd_ximg.c index 42a7eba..ea0a26e 100644 --- a/common/cmd_ximg.c +++ b/common/cmd_ximg.c @@ -50,7 +50,6 @@ do_imgextract(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) ulong data, len, count; int verify; int part = 0; - char pbuf[10]; image_header_t *hdr; #if defined(CONFIG_FIT) const char *uname = NULL; @@ -256,10 +255,8 @@ do_imgextract(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) puts("OK\n"); }
- sprintf(pbuf, "%8lx", data); - setenv("fileaddr", pbuf); - sprintf(pbuf, "%8lx", len); - setenv("filesize", pbuf); + setenv_hex("fileaddr", data); + setenv_hex("filesize", len);
return 0; } diff --git a/common/cmd_zfs.c b/common/cmd_zfs.c index 1df0c4d..900e977 100644 --- a/common/cmd_zfs.c +++ b/common/cmd_zfs.c @@ -129,8 +129,7 @@ static int do_zfs_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[] load_addr = addr;
printf("%llu bytes read\n", zfile.size); - sprintf(buf, "%llX", zfile.size); - setenv("filesize", buf); + setenv_hex("filesize", zfile.size);
return 0; } diff --git a/common/cmd_zip.c b/common/cmd_zip.c index a73c86d..8607da8 100644 --- a/common/cmd_zip.c +++ b/common/cmd_zip.c @@ -28,7 +28,6 @@ static int do_zip(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { unsigned long src, dst; unsigned long src_len, dst_len = ~0UL; - char buf[32];
switch (argc) { case 5: @@ -47,8 +46,7 @@ static int do_zip(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) return 1;
printf("Compressed size: %ld = 0x%lX\n", dst_len, dst_len); - sprintf(buf, "%lX", dst_len); - setenv("filesize", buf); + setenv_hex("filesize", dst_len);
return 0; }

On Wed, Dec 26, 2012 at 10:57 AM, Simon Glass sjg@chromium.org wrote:
Use setenv_ulong(), setenv_hex() and setenv_addr() in common/
Signed-off-by: Simon Glass sjg@chromium.org
Applied to x86/master.
common/cmd_bootm.c | 11 +++-------- common/cmd_cbfs.c | 4 +--- common/cmd_cramfs.c | 4 +--- common/cmd_fdos.c | 4 +--- common/cmd_jffs2.c | 4 +--- common/cmd_load.c | 12 +++--------- common/cmd_mtdparts.c | 4 +--- common/cmd_nand.c | 12 +++--------- common/cmd_nvedit.c | 3 +-- common/cmd_reiser.c | 4 +--- common/cmd_setexpr.c | 39 +++++++++++++++++++++++++++------------ common/cmd_unzip.c | 4 +--- common/cmd_ximg.c | 7 ++----- common/cmd_zfs.c | 3 +-- common/cmd_zip.c | 4 +--- 15 files changed, 48 insertions(+), 71 deletions(-)

On Wed, Dec 26, 2012 at 10:57:05AM -0800, Simon Glass wrote:
Use setenv_ulong(), setenv_hex() and setenv_addr() in common/
Signed-off-by: Simon Glass sjg@chromium.org
[snip]
diff --git a/common/cmd_fdos.c b/common/cmd_fdos.c index fbee861..5a35cc1 100644 --- a/common/cmd_fdos.c +++ b/common/cmd_fdos.c
[snip]
@@ -91,8 +90,7 @@ int do_fdosboot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) } flush_cache (load_addr, size);
- sprintf(buf, "%x", size);
- setenv("filesize", buf);
- setenv_hex("filesize", size);
Tab and space mixing in the function. I'll fix if git am --whitespace=fix doesn't spot and fix.

Hi Tom,
On Mon, Feb 18, 2013 at 2:08 PM, Tom Rini trini@ti.com wrote:
On Wed, Dec 26, 2012 at 10:57:05AM -0800, Simon Glass wrote:
Use setenv_ulong(), setenv_hex() and setenv_addr() in common/
Signed-off-by: Simon Glass sjg@chromium.org
[snip]
diff --git a/common/cmd_fdos.c b/common/cmd_fdos.c index fbee861..5a35cc1 100644 --- a/common/cmd_fdos.c +++ b/common/cmd_fdos.c
[snip]
@@ -91,8 +90,7 @@ int do_fdosboot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) } flush_cache (load_addr, size);
- sprintf(buf, "%x", size);
- setenv("filesize", buf);
setenv_hex("filesize", size);
Tab and space mixing in the function. I'll fix if git am --whitespace=fix doesn't spot and fix.
I'll change it back to spaces so that it is consistent, even if checkpatch is upset. There are now 5 patches changed so I will send out the whole series again.
-- Tom
Regards, Simon

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On 02/24/2013 12:45 PM, Simon Glass wrote:
Hi Tom,
On Mon, Feb 18, 2013 at 2:08 PM, Tom Rini trini@ti.com wrote:
On Wed, Dec 26, 2012 at 10:57:05AM -0800, Simon Glass wrote:
Use setenv_ulong(), setenv_hex() and setenv_addr() in common/
Signed-off-by: Simon Glass sjg@chromium.org
[snip]
diff --git a/common/cmd_fdos.c b/common/cmd_fdos.c index fbee861..5a35cc1 100644 --- a/common/cmd_fdos.c +++ b/common/cmd_fdos.c
[snip]
@@ -91,8 +90,7 @@ int do_fdosboot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) } flush_cache (load_addr, size);
- sprintf(buf, "%x", size); - setenv("filesize", buf); +
setenv_hex("filesize", size);
Tab and space mixing in the function. I'll fix if git am --whitespace=fix doesn't spot and fix.
I'll change it back to spaces so that it is consistent, even if checkpatch is upset. There are now 5 patches changed so I will send out the whole series again.
Right, we should always be consistent with the file. From my read of the series, this was the only one where the file used spaces and the new insert was tabs, that's what I'm getting at. I guess the others didn't stick out as obviously?
- -- Tom

Hi Tom,
On Sun, Feb 24, 2013 at 12:53 PM, Tom Rini trini@ti.com wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On 02/24/2013 12:45 PM, Simon Glass wrote:
Hi Tom,
On Mon, Feb 18, 2013 at 2:08 PM, Tom Rini trini@ti.com wrote:
On Wed, Dec 26, 2012 at 10:57:05AM -0800, Simon Glass wrote:
Use setenv_ulong(), setenv_hex() and setenv_addr() in common/
Signed-off-by: Simon Glass sjg@chromium.org
[snip]
diff --git a/common/cmd_fdos.c b/common/cmd_fdos.c index fbee861..5a35cc1 100644 --- a/common/cmd_fdos.c +++ b/common/cmd_fdos.c
[snip]
@@ -91,8 +90,7 @@ int do_fdosboot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) } flush_cache (load_addr, size);
- sprintf(buf, "%x", size); - setenv("filesize", buf); +
setenv_hex("filesize", size);
Tab and space mixing in the function. I'll fix if git am --whitespace=fix doesn't spot and fix.
I'll change it back to spaces so that it is consistent, even if checkpatch is upset. There are now 5 patches changed so I will send out the whole series again.
Right, we should always be consistent with the file. From my read of the series, this was the only one where the file used spaces and the new insert was tabs, that's what I'm getting at. I guess the others didn't stick out as obviously?
Well I didn't see any other similar problem. There are a few warnings - in one case I am moving code and then fixing it up in a later commit. But I think this is the only one where I am deliberating following the prevailing style to fit in with the surrounding code.
Regards, Simon
Tom -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
iQIcBAEBAgAGBQJRKn3kAAoJENk4IS6UOR1WV5gP/Ro7jY8wwUV0O4UMYuFidIVG 9SsElNnJoFaoO+qske9MAR6YknpJNb0hu10ZSZWoA+Db1gGeHMwAydG/F8eYJOad IE26MJVzzSbjmsQx7UJcRKNPfDLKWcZDUMtDC+2YAjT8PvUDRkOqHKqLc/WxcawM ytsw7o+6lf7GWYABjjEdJkRqd4kd+lq+l6sQoBk0qqQkergjP4+Si3BN3h77ZupV 8hTA7idf3/6ezKjHB3jyMl5kSFrgEPPdhrRNlaYAFriYKpDIwINHEWAYXgQpAtWW YSA0CQBKZMVE9liMWy3ZWDFslcfk0i72H3m2IP1kNsyRRx0wuekkUlVONc9AQoVe x3aSnw3LDt0b3SaGhoMLwVKoL6ZI6IKUfAvJNh/tmc/vNbrDmrot2z8mPd4ccKp4 AfrhlpH4KE8eU6zsVpsVWJ85LHaIBu/5SvW73UFLCDZwwnUUIKCj4A903cweCuoG i8VrY11OliR/yABz+NRRek7Y8pyBMqq40ES4lZJYrcKXwi0k3OwAraCrA73IZeg3 d50ME2WTBQ+tR0cFfp8BZxTVYxrTpHA2diOHL7rdFRfAlii3Wt6Ee9Zbb+ozir6q TKfxVqJYmHpTYiEt6CuYpq6GD+wQnWbAYkZw5DbmEeq65UUid/UUPcLhDhEinmg6 wbo0UcLD2TLRqc9IS9fX =lxH4 -----END PGP SIGNATURE-----

Use setenv_ulong(), setenv_hex() and setenv_addr() in drivers/
Signed-off-by: Simon Glass sjg@chromium.org --- fs/fs.c | 4 +--- fs/ubifs/ubifs.c | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-)
diff --git a/fs/fs.c b/fs/fs.c index 023e7ef..2c9f2c5 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -256,7 +256,6 @@ int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], unsigned long bytes; unsigned long pos; int len_read; - char buf[12]; unsigned long time;
if (argc < 2) @@ -308,8 +307,7 @@ int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], } puts("\n");
- sprintf(buf, "0x%x", len_read); - setenv("filesize", buf); + setenv_hex("filesize", len_read);
return 0; } diff --git a/fs/ubifs/ubifs.c b/fs/ubifs/ubifs.c index 44be3f5..273c0a9 100644 --- a/fs/ubifs/ubifs.c +++ b/fs/ubifs/ubifs.c @@ -687,7 +687,6 @@ int ubifs_load(char *filename, u32 addr, u32 size) int i; int count; int last_block_size = 0; - char buf [10];
c->ubi = ubi_open_volume(c->vi.ubi_num, c->vi.vol_id, UBI_READONLY); /* ubifs_findfile will resolve symlinks, so we know that we get @@ -740,8 +739,7 @@ int ubifs_load(char *filename, u32 addr, u32 size) if (err) printf("Error reading file '%s'\n", filename); else { - sprintf(buf, "%X", size); - setenv("filesize", buf); + setenv_hex("filesize", size); printf("Done\n"); }

On Wed, Dec 26, 2012 at 10:57 AM, Simon Glass sjg@chromium.org wrote:
Use setenv_ulong(), setenv_hex() and setenv_addr() in drivers/
Signed-off-by: Simon Glass sjg@chromium.org
Applied to x86/master.
fs/fs.c | 4 +--- fs/ubifs/ubifs.c | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-)

On Wed, Dec 26, 2012 at 10:57:06AM -0800, Simon Glass wrote:
Use setenv_ulong(), setenv_hex() and setenv_addr() in drivers/
Signed-off-by: Simon Glass sjg@chromium.org
fs/fs.c | 4 +--- fs/ubifs/ubifs.c | 4 +---
fs/ not drivers/

Use setenv_hex() and setenv_addr() in net/
Signed-off-by: Simon Glass sjg@chromium.org --- drivers/net/fm/fm.c | 4 +--- net/net.c | 8 ++------ 2 files changed, 3 insertions(+), 9 deletions(-)
diff --git a/drivers/net/fm/fm.c b/drivers/net/fm/fm.c index 49c74c2..8d70586 100644 --- a/drivers/net/fm/fm.c +++ b/drivers/net/fm/fm.c @@ -362,7 +362,6 @@ static void fm_init_qmi(struct fm_qmi_common *qmi) int fm_init_common(int index, struct ccsr_fman *reg) { int rc; - char env_addr[32]; #if defined(CONFIG_SYS_QE_FMAN_FW_IN_NOR) void *addr = (void *)CONFIG_SYS_QE_FMAN_FW_ADDR; #elif defined(CONFIG_SYS_QE_FMAN_FW_IN_NAND) @@ -416,8 +415,7 @@ int fm_init_common(int index, struct ccsr_fman *reg) rc = fman_upload_firmware(index, ®->fm_imem, addr); if (rc) return rc; - sprintf(env_addr, "0x%lx", (long unsigned int)addr); - setenv("fman_ucode", env_addr); + setenv_addr("fman_ucode", addr);
fm_init_muram(index, ®->muram); fm_init_qmi(®->fm_qmi_common); diff --git a/net/net.c b/net/net.c index a40cde1..df94789 100644 --- a/net/net.c +++ b/net/net.c @@ -528,15 +528,11 @@ restart: case NETLOOP_SUCCESS: net_cleanup_loop(); if (NetBootFileXferSize > 0) { - char buf[20]; printf("Bytes transferred = %ld (%lx hex)\n", NetBootFileXferSize, NetBootFileXferSize); - sprintf(buf, "%lX", NetBootFileXferSize); - setenv("filesize", buf); - - sprintf(buf, "%lX", (unsigned long)load_addr); - setenv("fileaddr", buf); + setenv_hex("filesize", NetBootFileXferSize); + setenv_hex("fileaddr", load_addr); } if (protocol != NETCONS) eth_halt();

On Wed, Dec 26, 2012 at 10:57 AM, Simon Glass sjg@chromium.org wrote:
Use setenv_hex() and setenv_addr() in net/
Signed-off-by: Simon Glass sjg@chromium.org
Applied to x86/master.
drivers/net/fm/fm.c | 4 +--- net/net.c | 8 ++------ 2 files changed, 3 insertions(+), 9 deletions(-)

We have an existing header which the crc32 definitions, so use it.
Signed-off-by: Simon Glass sjg@chromium.org --- common/image.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/common/image.c b/common/image.c index 95498e6..936b08c 100644 --- a/common/image.c +++ b/common/image.c @@ -75,6 +75,8 @@ static const image_header_t *image_get_ramdisk(ulong rd_addr, uint8_t arch, #include <image.h> #endif /* !USE_HOSTCC*/
+#include <u-boot/crc.h> + static const table_entry_t uimage_arch[] = { { IH_ARCH_INVALID, NULL, "Invalid ARCH", }, { IH_ARCH_ALPHA, "alpha", "Alpha", }, @@ -161,8 +163,6 @@ static const table_entry_t uimage_comp[] = { { -1, "", "", }, };
-uint32_t crc32(uint32_t, const unsigned char *, uint); -uint32_t crc32_wd(uint32_t, const unsigned char *, uint, uint); #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC) static void genimg_print_time(time_t timestamp); #endif

Dear Simon Glass,
We have an existing header which the crc32 definitions, so use it.
Signed-off-by: Simon Glass sjg@chromium.org
Looks ok.
Acked-by: Marek Vasut marex@denx.de
Best regards, Marek Vasut

On Wed, Dec 26, 2012 at 2:02 PM, Marek Vasut marex@denx.de wrote:
Dear Simon Glass,
We have an existing header which the crc32 definitions, so use it.
Signed-off-by: Simon Glass sjg@chromium.org
Looks ok.
Acked-by: Marek Vasut marex@denx.de
Applied to x86/master.
Best regards, Marek Vasut

Add the CRC32 algorithm to the list of available hashes, and make the crc32 command use hash_command(). Add a new crc32_wd_buf() to make this possible, which puts its result in a buffer rather than returning it as a 32-bit value.
Signed-off-by: Simon Glass sjg@chromium.org --- common/cmd_mem.c | 73 ++++--------------------------------------------- common/hash.c | 6 ++++ include/hash.h | 2 +- include/u-boot/crc.h | 11 +++++++ lib/crc32.c | 9 ++++++ 5 files changed, 33 insertions(+), 68 deletions(-)
diff --git a/common/cmd_mem.c b/common/cmd_mem.c index c45a31e..701157d 100644 --- a/common/cmd_mem.c +++ b/common/cmd_mem.c @@ -32,6 +32,7 @@ #ifdef CONFIG_HAS_DATAFLASH #include <dataflash.h> #endif +#include <hash.h> #include <watchdog.h> #include <asm/io.h>
@@ -1093,89 +1094,27 @@ mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
#ifdef CONFIG_CMD_CRC32
-#ifndef CONFIG_CRC32_VERIFY - static int do_mem_crc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { - ulong addr, length; - ulong crc; - ulong *ptr; - - if (argc < 3) - return CMD_RET_USAGE; - - addr = simple_strtoul (argv[1], NULL, 16); - addr += base_address; - - length = simple_strtoul (argv[2], NULL, 16); - - crc = crc32_wd (0, (const uchar *) addr, length, CHUNKSZ_CRC32); - - printf ("CRC32 for %08lx ... %08lx ==> %08lx\n", - addr, addr + length - 1, crc); - - if (argc > 3) { - ptr = (ulong *) simple_strtoul (argv[3], NULL, 16); - *ptr = crc; - } - - return 0; -} - -#else /* CONFIG_CRC32_VERIFY */ - -int do_mem_crc (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) -{ - ulong addr, length; - ulong crc; - ulong *ptr; - ulong vcrc; - int verify; + int verify = 0; int ac; char * const *av;
- if (argc < 3) { -usage: + if (argc < 3) return CMD_RET_USAGE; - }
av = argv + 1; ac = argc - 1; +#ifdef CONFIG_HASH_VERIFY if (strcmp(*av, "-v") == 0) { verify = 1; av++; ac--; - if (ac < 3) - goto usage; - } else - verify = 0; - - addr = simple_strtoul(*av++, NULL, 16); - addr += base_address; - length = simple_strtoul(*av++, NULL, 16); - - crc = crc32_wd (0, (const uchar *) addr, length, CHUNKSZ_CRC32); - - if (!verify) { - printf ("CRC32 for %08lx ... %08lx ==> %08lx\n", - addr, addr + length - 1, crc); - if (ac > 2) { - ptr = (ulong *) simple_strtoul (*av++, NULL, 16); - *ptr = crc; - } - } else { - vcrc = simple_strtoul(*av++, NULL, 16); - if (vcrc != crc) { - printf ("CRC32 for %08lx ... %08lx ==> %08lx != %08lx ** ERROR **\n", - addr, addr + length - 1, crc, vcrc); - return 1; - } } +#endif
- return 0; - + return hash_command("crc32", verify, cmdtp, flag, ac, av); } -#endif /* CONFIG_CRC32_VERIFY */
#endif
diff --git a/common/hash.c b/common/hash.c index e3a6e43..e92b4b1 100644 --- a/common/hash.c +++ b/common/hash.c @@ -50,6 +50,12 @@ static struct hash_algo hash_algo[] = { CHUNKSZ_SHA256, }, #endif + { + "CRC32", + 4, + crc32_wd_buf, + CHUNKSZ_CRC32, + }, };
/** diff --git a/include/hash.h b/include/hash.h index 34ba558..ba2ba65 100644 --- a/include/hash.h +++ b/include/hash.h @@ -22,7 +22,7 @@ #ifndef _HASH_H #define _HASH_H
-#ifdef CONFIG_SHA1SUM_VERIFY +#if defined(CONFIG_SHA1SUM_VERIFY) || defined(CONFIG_CRC32_VERIFY) #define CONFIG_HASH_VERIFY #endif
diff --git a/include/u-boot/crc.h b/include/u-boot/crc.h index 07badbf..08e509e 100644 --- a/include/u-boot/crc.h +++ b/include/u-boot/crc.h @@ -30,4 +30,15 @@ uint32_t crc32 (uint32_t, const unsigned char *, uint); uint32_t crc32_wd (uint32_t, const unsigned char *, uint, uint); uint32_t crc32_no_comp (uint32_t, const unsigned char *, uint);
+/** + * crc32_wd_buf - Perform CRC32 on a buffer and return result in buffer + * + * @input: Input buffer + * @ilen: Input buffer length + * @output: Place to put checksum result (4 bytes) + * @chunk_sz: Trigger watchdog after processing this many bytes + */ +void crc32_wd_buf(const unsigned char *input, uint ilen, + unsigned char *output, uint chunk_sz); + #endif /* _UBOOT_CRC_H */ diff --git a/lib/crc32.c b/lib/crc32.c index 27335a3..76205da 100644 --- a/lib/crc32.c +++ b/lib/crc32.c @@ -249,3 +249,12 @@ uint32_t ZEXPORT crc32_wd (uint32_t crc,
return crc; } + +void crc32_wd_buf(const unsigned char *input, unsigned int ilen, + unsigned char *output, unsigned int chunk_sz) +{ + uint32_t crc; + + crc = crc32_wd(0, input, ilen, chunk_sz); + memcpy(output, &crc, sizeof(crc)); +}

On Wed, Dec 26, 2012 at 10:57 AM, Simon Glass sjg@chromium.org wrote:
Add the CRC32 algorithm to the list of available hashes, and make the crc32 command use hash_command(). Add a new crc32_wd_buf() to make this possible, which puts its result in a buffer rather than returning it as a 32-bit value.
Signed-off-by: Simon Glass sjg@chromium.org
Applied to x86/master.
common/cmd_mem.c | 73 ++++--------------------------------------------- common/hash.c | 6 ++++ include/hash.h | 2 +- include/u-boot/crc.h | 11 +++++++ lib/crc32.c | 9 ++++++ 5 files changed, 33 insertions(+), 68 deletions(-)

Dear Simon Glass,
In message CAPnjgZ0hKP-Lr9TiUXCQEa-JhOGEB_6JXuBsCJq-FtAYhDJnww@mail.gmail.com you wrote:
On Wed, Dec 26, 2012 at 10:57 AM, Simon Glass sjg@chromium.org wrote:
Add the CRC32 algorithm to the list of available hashes, and make the crc32 command use hash_command(). Add a new crc32_wd_buf() to make this possible, which puts its result in a buffer rather than returning it as a 32-bit value.
Signed-off-by: Simon Glass sjg@chromium.org
Applied to x86/master.
common/cmd_mem.c | 73 ++++--------------------------------------------- common/hash.c | 6 ++++ include/hash.h | 2 +- include/u-boot/crc.h | 11 +++++++ lib/crc32.c | 9 ++++++ 5 files changed, 33 insertions(+), 68 deletions(-)
Umm... this (and a lot of the other things) is all common stuff. This is not supposed to go through the x86 repository.
The x86 tree should ONLY be used for x86 spoecific stuff.
Please do no use this for pull requests. Tom has to pick up these directly.
Best regards,
Wolfgang Denk

Hi Wolfgang,
On Sun, Feb 17, 2013 at 12:53 PM, Wolfgang Denk wd@denx.de wrote:
Dear Simon Glass,
In message CAPnjgZ0hKP-Lr9TiUXCQEa-JhOGEB_6JXuBsCJq-FtAYhDJnww@mail.gmail.com you wrote:
On Wed, Dec 26, 2012 at 10:57 AM, Simon Glass sjg@chromium.org wrote:
Add the CRC32 algorithm to the list of available hashes, and make the crc32 command use hash_command(). Add a new crc32_wd_buf() to make this possible, which puts its result in a buffer rather than returning it as a 32-bit value.
Signed-off-by: Simon Glass sjg@chromium.org
Applied to x86/master.
common/cmd_mem.c | 73 ++++--------------------------------------------- common/hash.c | 6 ++++ include/hash.h | 2 +- include/u-boot/crc.h | 11 +++++++ lib/crc32.c | 9 ++++++ 5 files changed, 33 insertions(+), 68 deletions(-)
Umm... this (and a lot of the other things) is all common stuff. This is not supposed to go through the x86 repository.
The x86 tree should ONLY be used for x86 spoecific stuff.
Please do no use this for pull requests. Tom has to pick up these directly.
OK, understood, have replied on your other thread and will await further instructions.
Regards, Simon
Best regards,
Wolfgang Denk
-- DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de Use C++ to confuse your enemies; use C to produce stable code.

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On 02/17/2013 03:53 PM, Wolfgang Denk wrote:
Dear Simon Glass,
In message CAPnjgZ0hKP-Lr9TiUXCQEa-JhOGEB_6JXuBsCJq-FtAYhDJnww@mail.gmail.com you wrote:
On Wed, Dec 26, 2012 at 10:57 AM, Simon Glass sjg@chromium.org wrote:
Add the CRC32 algorithm to the list of available hashes, and make the crc32 command use hash_command(). Add a new crc32_wd_buf() to make this possible, which puts its result in a buffer rather than returning it as a 32-bit value.
Signed-off-by: Simon Glass sjg@chromium.org
Applied to x86/master.
--- common/cmd_mem.c | 73 ++++--------------------------------------------- common/hash.c | 6 ++++ include/hash.h | 2 +- include/u-boot/crc.h | 11 +++++++ lib/crc32.c | 9 ++++++ 5 files changed, 33 insertions(+), 68 deletions(-)
Umm... this (and a lot of the other things) is all common stuff. This is not supposed to go through the x86 repository.
The x86 tree should ONLY be used for x86 spoecific stuff.
Please do no use this for pull requests. Tom has to pick up these directly.
There's another thread I don't have yet (and I don't have this one in gmail yet even). But, I am OK with custodians using their repos, but not the master branch, for unrelated but otherwise good patches. I'm also fine with patchwork bundles. I suppose we could use the staging repository for these changes instead.
- -- Tom

Dear Tom,
In message 51216721.1010603@ti.com you wrote:
There's another thread I don't have yet (and I don't have this one in gmail yet even). But, I am OK with custodians using their repos, but not the master branch, for unrelated but otherwise good patches. I'm also fine with patchwork bundles. I suppose we could use the staging repository for these changes instead.
What I mostly object about there is that these patches would go into mainline basicly unreviewed, as patch submission and pull request is all done from a single person, with no other feedback on the patches at all. And this affects a lot of common code...
Actually, I see this change when pulling u-boot-x86.git/master:
-> bloat-o-meter u-boot-before u-boot add/remove: 9/0 grow/shrink: 3/14 up/down: 1006/-560 (446) function old new delta hash_command - 424 +424 strncasecmp - 156 +156 simple_itoa - 104 +104 crc32_wd_buf - 76 +76 setenv_hex - 68 +68 setenv_ulong - 52 +52 strcasecmp - 36 +36 do_mem_loopw 304 328 +24 static.local - 22 +22 do_mem_loop 268 288 +20 hash_algo - 16 +16 do_mem_cmp 332 340 +8 do_mem_mw 224 220 -4 set_working_fdt_addr 72 52 -20 load_serial_ymodem 300 280 -20 load_serial 512 492 -20 index_partitions 200 180 -20 do_load_serial_bin 1844 1824 -20 do_load 468 448 -20 do_jffs2_fsload 320 300 -20 do_imgextract 636 592 -44 NetLoop 832 788 -44 do_mem_cp 312 252 -60 do_bootm 1244 1180 -64 do_mem_crc 188 88 -100 do_mem_mtest 1436 1332 -104
So there are changes all over the place, including a growth of the memory footprint. I think this needs at least minimal review.
Best regards,
Wolfgang Denk

Hi Wolfgang,
On Mon, Feb 18, 2013 at 3:35 AM, Wolfgang Denk wd@denx.de wrote:
Dear Tom,
In message 51216721.1010603@ti.com you wrote:
There's another thread I don't have yet (and I don't have this one in gmail yet even). But, I am OK with custodians using their repos, but not the master branch, for unrelated but otherwise good patches. I'm also fine with patchwork bundles. I suppose we could use the staging repository for these changes instead.
What I mostly object about there is that these patches would go into mainline basicly unreviewed, as patch submission and pull request is all done from a single person, with no other feedback on the patches at all. And this affects a lot of common code...
Fair enough. I suspect a number of people scan the code, but few feel invested enough to formally Ack it. Also, providing a full review of such a series can take quite a bit of time. Against that, I think it is better to get code in and tested than have it sit around until just before the next release.
Actually, I see this change when pulling u-boot-x86.git/master:
Thanks for looking at it. Some of it is just the code moving around, but I will take a look at why hash_command grows so much, and why the overall size has grown. Clearly I didn't do enough here when I checked the series. One change was trying to unify the verify feature, so perhaps something has gone wrong there.
-> bloat-o-meter u-boot-before u-boot add/remove: 9/0 grow/shrink: 3/14 up/down: 1006/-560 (446) function old new delta hash_command - 424 +424 strncasecmp - 156 +156 simple_itoa - 104 +104 crc32_wd_buf - 76 +76 setenv_hex - 68 +68 setenv_ulong - 52 +52 strcasecmp - 36 +36 do_mem_loopw 304 328 +24 static.local - 22 +22 do_mem_loop 268 288 +20 hash_algo - 16 +16 do_mem_cmp 332 340 +8 do_mem_mw 224 220 -4 set_working_fdt_addr 72 52 -20 load_serial_ymodem 300 280 -20 load_serial 512 492 -20 index_partitions 200 180 -20 do_load_serial_bin 1844 1824 -20 do_load 468 448 -20 do_jffs2_fsload 320 300 -20 do_imgextract 636 592 -44 NetLoop 832 788 -44 do_mem_cp 312 252 -60 do_bootm 1244 1180 -64 do_mem_crc 188 88 -100 do_mem_mtest 1436 1332 -104
So there are changes all over the place, including a growth of the memory footprint. I think this needs at least minimal review.
We need more reviewers I think.
Regards, Simon
Best regards,
Wolfgang Denk
-- DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de Time is an illusion perpetrated by the manufacturers of space.

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On 02/18/2013 11:36 AM, Simon Glass wrote:
Hi Wolfgang,
On Mon, Feb 18, 2013 at 3:35 AM, Wolfgang Denk wd@denx.de wrote:
Dear Tom,
In message 51216721.1010603@ti.com you wrote:
There's another thread I don't have yet (and I don't have this one in gmail yet even). But, I am OK with custodians using their repos, but not the master branch, for unrelated but otherwise good patches. I'm also fine with patchwork bundles. I suppose we could use the staging repository for these changes instead.
What I mostly object about there is that these patches would go into mainline basicly unreviewed, as patch submission and pull request is all done from a single person, with no other feedback on the patches at all. And this affects a lot of common code...
Fair enough. I suspect a number of people scan the code, but few feel invested enough to formally Ack it. Also, providing a full review of such a series can take quite a bit of time. Against that, I think it is better to get code in and tested than have it sit around until just before the next release.
[snip]
So there are changes all over the place, including a growth of the memory footprint. I think this needs at least minimal review.
We need more reviewers I think.
This is where I'm trying to find a good balance right now. If we just wait for reviewed-by lines to fly by, things will sit forever. Partly because enough folks don't feel like they "own" things enough to risk saying they reviewed something that turns out later to have a bug. And partly there's just not enough folks reading patches. I do try and give things some sort of read-over when it's the person posting who is doing the merging, especially for common rather than "their area" code.
- -- Tom

Hi Wolfgang,
On Mon, Feb 18, 2013 at 3:35 AM, Wolfgang Denk wd@denx.de wrote:
Dear Tom,
In message 51216721.1010603@ti.com you wrote:
There's another thread I don't have yet (and I don't have this one in gmail yet even). But, I am OK with custodians using their repos, but not the master branch, for unrelated but otherwise good patches. I'm also fine with patchwork bundles. I suppose we could use the staging repository for these changes instead.
What I mostly object about there is that these patches would go into mainline basicly unreviewed, as patch submission and pull request is all done from a single person, with no other feedback on the patches at all. And this affects a lot of common code...
Actually, I see this change when pulling u-boot-x86.git/master:
-> bloat-o-meter u-boot-before u-boot
What board is this please?
Some specific notes here - I think it boils down to moving crc32 into the hash framework. This adds some overhead, but has a few benefits.
add/remove: 9/0 grow/shrink: 3/14 up/down: 1006/-560 (446) function old new delta hash_command - 424 +424
This is the generic hashing command. What is happening here is that the crc32 command is getting a few more features, more like sha1sum. However, this might not be desriable - and in fact this patch changes the behaviour of the CRC storage and verify to support using an environment variable, and requiring * before the argument when an address is required! That needs to be fixed, at least.
The intent is to try to unify the hashing/crc features into a single framework. If you enable only crc32 and nothing else then this has quite a cost (0.5KB at present). I think I can reduce this code by making the full features of hash.c only available when something more than just crc32 is enabled. However, it might involve some #ifdefs...
strncasecmp - 156 +156 simple_itoa - 104 +104 crc32_wd_buf - 76 +76 setenv_hex - 68 +68 setenv_ulong - 52 +52 strcasecmp - 36 +36 do_mem_loopw 304 328 +24 static.local - 22 +22 do_mem_loop 268 288 +20 hash_algo - 16 +16 do_mem_cmp 332 340 +8 do_mem_mw 224 220 -4 set_working_fdt_addr 72 52 -20 load_serial_ymodem 300 280 -20 load_serial 512 492 -20 index_partitions 200 180 -20 do_load_serial_bin 1844 1824 -20 do_load 468 448 -20 do_jffs2_fsload 320 300 -20 do_imgextract 636 592 -44 NetLoop 832 788 -44 do_mem_cp 312 252 -60 do_bootm 1244 1180 -64 do_mem_crc 188 88 -100 do_mem_mtest 1436 1332 -104
So there are changes all over the place, including a growth of the memory footprint. I think this needs at least minimal review.
Best regards,
Wolfgang Denk
-- DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de Time is an illusion perpetrated by the manufacturers of space.

On Mon, Feb 18, 2013 at 09:06:01AM -0800, Simon Glass wrote:
Hi Wolfgang,
On Mon, Feb 18, 2013 at 3:35 AM, Wolfgang Denk wd@denx.de wrote:
Dear Tom,
In message 51216721.1010603@ti.com you wrote:
There's another thread I don't have yet (and I don't have this one in gmail yet even). But, I am OK with custodians using their repos, but not the master branch, for unrelated but otherwise good patches. I'm also fine with patchwork bundles. I suppose we could use the staging repository for these changes instead.
What I mostly object about there is that these patches would go into mainline basicly unreviewed, as patch submission and pull request is all done from a single person, with no other feedback on the patches at all. And this affects a lot of common code...
Actually, I see this change when pulling u-boot-x86.git/master:
-> bloat-o-meter u-boot-before u-boot
What board is this please?
Some specific notes here - I think it boils down to moving crc32 into the hash framework. This adds some overhead, but has a few benefits.
So you're going to v2 this part?

Hi Tom,
On Mon, Feb 18, 2013 at 2:45 PM, Tom Rini trini@ti.com wrote:
On Mon, Feb 18, 2013 at 09:06:01AM -0800, Simon Glass wrote:
Hi Wolfgang,
On Mon, Feb 18, 2013 at 3:35 AM, Wolfgang Denk wd@denx.de wrote:
Dear Tom,
In message 51216721.1010603@ti.com you wrote:
There's another thread I don't have yet (and I don't have this one in gmail yet even). But, I am OK with custodians using their repos, but not the master branch, for unrelated but otherwise good patches. I'm also fine with patchwork bundles. I suppose we could use the staging repository for these changes instead.
What I mostly object about there is that these patches would go into mainline basicly unreviewed, as patch submission and pull request is all done from a single person, with no other feedback on the patches at all. And this affects a lot of common code...
Actually, I see this change when pulling u-boot-x86.git/master:
-> bloat-o-meter u-boot-before u-boot
What board is this please?
Some specific notes here - I think it boils down to moving crc32 into the hash framework. This adds some overhead, but has a few benefits.
So you're going to v2 this part?
Yes, sorry for the hold-up, but I think this patch needs a few tweaks. I may even need to create a separate patch depending on how much I need to change common/hash.c. Hopefully it is just a case of adding some #ifdefs (!) and another parameter to select the behaviour required. I will make time for this tomorrow because then I am away until next week.
-- Tom

Hi Tom,
On Mon, Feb 18, 2013 at 2:45 PM, Tom Rini trini@ti.com wrote:
On Mon, Feb 18, 2013 at 09:06:01AM -0800, Simon Glass wrote:
Hi Wolfgang,
On Mon, Feb 18, 2013 at 3:35 AM, Wolfgang Denk wd@denx.de wrote:
Dear Tom,
In message 51216721.1010603@ti.com you wrote:
There's another thread I don't have yet (and I don't have this one in gmail yet even). But, I am OK with custodians using their repos, but not the master branch, for unrelated but otherwise good patches. I'm also fine with patchwork bundles. I suppose we could use the staging repository for these changes instead.
What I mostly object about there is that these patches would go into mainline basicly unreviewed, as patch submission and pull request is all done from a single person, with no other feedback on the patches at all. And this affects a lot of common code...
Actually, I see this change when pulling u-boot-x86.git/master:
-> bloat-o-meter u-boot-before u-boot
What board is this please?
Some specific notes here - I think it boils down to moving crc32 into the hash framework. This adds some overhead, but has a few benefits.
So you're going to v2 this part?
I have just sent 3 v2 patches to the mailing list. There is a new patch 16 to be inserted before this patch, an updated version of this patch, and an updated version of the final patch in the series (which was number 20 and is now number 21).
I have ended up just using #ifdef to remove most of the hash code if only crc32 is in use. It's not particularly elegant but I was not able to significantly reduce the code size impact any other way. Please take a look at it and see what you think.
Just in case it is useful, I have pushed a new 'us-mem3' branch to x86, but this is not for pulling (it has not been through patchwork), just for testing / comparison.
I will be away until Monday so probably no further response from me until then.
Regards, Simon
-- Tom

Dear Simon,
In message CAPnjgZ09okKf0qTnifKOrvg37nEnSNLFzyLBLp+4jt6U_L3RCg@mail.gmail.com you wrote:
-> bloat-o-meter u-boot-before u-boot
What board is this please?
That was TQM5200S
This is the generic hashing command. What is happening here is that the crc32 command is getting a few more features, more like sha1sum. However, this might not be desriable - and in fact this patch changes the behaviour of the CRC storage and verify to support using an environment variable, and requiring * before the argument when an address is required! That needs to be fixed, at least.
Indeed - such a change of user interface must not be done here (though it does make a lot of sense to use common code for this stuff).
The intent is to try to unify the hashing/crc features into a single
Understood and appreciayed.
framework. If you enable only crc32 and nothing else then this has quite a cost (0.5KB at present). I think I can reduce this code by making the full features of hash.c only available when something more than just crc32 is enabled. However, it might involve some #ifdefs...
Actually 0.5 k is quite heavy impact, so I guess the #ifdef's win...
Best regards,
Wolfgang Denk

Enable the hash command and sha1/256 hashing for sandbox. Also use a better address for memory testing (since the existing one is set up for linux host memory space).
Signed-off-by: Simon Glass sjg@chromium.org --- include/configs/sandbox.h | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/include/configs/sandbox.h b/include/configs/sandbox.h index 9c431bf..9f51a0b 100644 --- a/include/configs/sandbox.h +++ b/include/configs/sandbox.h @@ -63,8 +63,8 @@ #define CONFIG_SYS_HZ 1000
/* Memory things - we don't really want a memory test */ -#define CONFIG_SYS_LOAD_ADDR 0x10000000 -#define CONFIG_SYS_MEMTEST_START 0x10000000 +#define CONFIG_SYS_LOAD_ADDR 0x00000000 +#define CONFIG_SYS_MEMTEST_START 0x00100000 #define CONFIG_SYS_MEMTEST_END (CONFIG_SYS_MEMTEST_START + 0x1000) #define CONFIG_PHYS_64BIT
@@ -85,6 +85,11 @@ #undef CONFIG_CMD_NET #undef CONFIG_CMD_NFS
+#define CONFIG_CMD_HASH +#define CONFIG_HASH_VERIFY +#define CONFIG_SHA1 +#define CONFIG_SHA256 + #define CONFIG_BOOTARGS ""
#define CONFIG_EXTRA_ENV_SETTINGS "stdin=serial\0" \

On Wed, Dec 26, 2012 at 10:57 AM, Simon Glass sjg@chromium.org wrote:
Enable the hash command and sha1/256 hashing for sandbox. Also use a better address for memory testing (since the existing one is set up for linux host memory space).
Signed-off-by: Simon Glass sjg@chromium.org
Applied to x86/master.
include/configs/sandbox.h | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-)

This config effectively has a default value of 0, so add this setting at the top of the code to remove an #ifdef in the C function.
Signed-off-by: Simon Glass sjg@chromium.org --- common/cmd_mem.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/common/cmd_mem.c b/common/cmd_mem.c index 701157d..f83acdf 100644 --- a/common/cmd_mem.c +++ b/common/cmd_mem.c @@ -36,6 +36,10 @@ #include <watchdog.h> #include <asm/io.h>
+#ifndef CONFIG_SYS_MEMTEST_SCRATCH +#define CONFIG_SYS_MEMTEST_SCRATCH 0 +#endif + static int mod_mem(cmd_tbl_t *, int, int, int, char * const []);
/* Display values from last command. @@ -636,11 +640,7 @@ static ulong mem_test_alt(ulong start_addr, ulong end_addr) vu_long temp; vu_long anti_pattern; vu_long num_words; -#if defined(CONFIG_SYS_MEMTEST_SCRATCH) vu_long *dummy = (vu_long *)CONFIG_SYS_MEMTEST_SCRATCH; -#else - vu_long *dummy = NULL; /* yes, this is address 0x0, not NULL */ -#endif static const ulong bitpattern[] = { 0x00000001, /* single bit */ 0x00000003, /* two adjacent bits */

On Wed, Dec 26, 2012 at 10:57 AM, Simon Glass sjg@chromium.org wrote:
This config effectively has a default value of 0, so add this setting at the top of the code to remove an #ifdef in the C function.
Signed-off-by: Simon Glass sjg@chromium.org
Applied to x86/master.
common/cmd_mem.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)

Use map_sysmem() in the memory tester so that it works as expected on sandbox.
Signed-off-by: Simon Glass sjg@chromium.org --- common/cmd_mem.c | 97 +++++++++++++++++++++++++++++------------------------- 1 files changed, 52 insertions(+), 45 deletions(-)
diff --git a/common/cmd_mem.c b/common/cmd_mem.c index f83acdf..1bbe166 100644 --- a/common/cmd_mem.c +++ b/common/cmd_mem.c @@ -626,21 +626,19 @@ int do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) } #endif /* CONFIG_LOOPW */
-static ulong mem_test_alt(ulong start_addr, ulong end_addr) +static ulong mem_test_alt(vu_long *buf, ulong start_addr, ulong end_addr, + vu_long *dummy) { - vu_long *start, *end; vu_long *addr; ulong errs = 0; ulong val, readback; int j; - vu_long len; vu_long offset; vu_long test_offset; vu_long pattern; vu_long temp; vu_long anti_pattern; vu_long num_words; - vu_long *dummy = (vu_long *)CONFIG_SYS_MEMTEST_SCRATCH; static const ulong bitpattern[] = { 0x00000001, /* single bit */ 0x00000003, /* two adjacent bits */ @@ -652,8 +650,7 @@ static ulong mem_test_alt(ulong start_addr, ulong end_addr) 0xaaaaaaaa, /* alternating 1/0 */ };
- start = (vu_long *)start_addr; - end = (vu_long *)end_addr; + num_words = (end_addr - start_addr) / sizeof(vu_long);
/* * Data line test: write a pattern to the first @@ -672,11 +669,11 @@ static ulong mem_test_alt(ulong start_addr, ulong end_addr) * '0's and '0' bits through a field of '1's (i.e. * pattern and ~pattern). */ - addr = start; + addr = buf; for (j = 0; j < sizeof(bitpattern) / sizeof(bitpattern[0]); j++) { val = bitpattern[j]; for (; val != 0; val <<= 1) { - *addr = val; + *addr = val; *dummy = ~val; /* clear the test data off the bus */ readback = *addr; if (readback != val) { @@ -735,58 +732,56 @@ static ulong mem_test_alt(ulong start_addr, ulong end_addr) * * Returns: 0 if the test succeeds, 1 if the test fails. */ - len = (end_addr - start_addr) / sizeof(vu_long); pattern = (vu_long) 0xaaaaaaaa; anti_pattern = (vu_long) 0x55555555;
- debug("%s:%d: length = 0x%.8lx\n", - __func__, __LINE__, len); + debug("%s:%d: length = 0x%.8lx\n", __func__, __LINE__, num_words); /* * Write the default pattern at each of the * power-of-two offsets. */ - for (offset = 1; offset < len; offset <<= 1) - start[offset] = pattern; + for (offset = 1; offset < num_words; offset <<= 1) + addr[offset] = pattern;
/* * Check for address bits stuck high. */ test_offset = 0; - start[test_offset] = anti_pattern; + addr[test_offset] = anti_pattern;
- for (offset = 1; offset < len; offset <<= 1) { - temp = start[offset]; + for (offset = 1; offset < num_words; offset <<= 1) { + temp = addr[offset]; if (temp != pattern) { printf("\nFAILURE: Address bit stuck high @ 0x%.8lx:" " expected 0x%.8lx, actual 0x%.8lx\n", - (ulong)&start[offset], pattern, temp); + start_addr + offset, pattern, temp); errs++; if (ctrlc()) return -1; } } - start[test_offset] = pattern; + addr[test_offset] = pattern; WATCHDOG_RESET();
/* * Check for addr bits stuck low or shorted. */ - for (test_offset = 1; test_offset < len; test_offset <<= 1) { - start[test_offset] = anti_pattern; + for (test_offset = 1; test_offset < num_words; test_offset <<= 1) { + addr[test_offset] = anti_pattern;
- for (offset = 1; offset < len; offset <<= 1) { - temp = start[offset]; + for (offset = 1; offset < num_words; offset <<= 1) { + temp = addr[offset]; if ((temp != pattern) && (offset != test_offset)) { printf("\nFAILURE: Address bit stuck low or" " shorted @ 0x%.8lx: expected 0x%.8lx," " actual 0x%.8lx\n", - (ulong)&start[offset], pattern, temp); + start_addr + offset, pattern, temp); errs++; if (ctrlc()) return -1; } } - start[test_offset] = pattern; + addr[test_offset] = pattern; }
/* @@ -801,14 +796,14 @@ static ulong mem_test_alt(ulong start_addr, ulong end_addr) * * Returns: 0 if the test succeeds, 1 if the test fails. */ - num_words = ((ulong)end - (ulong)start)/sizeof(vu_long) + 1; + num_words++;
/* * Fill memory with a known pattern. */ for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) { WATCHDOG_RESET(); - start[offset] = pattern; + addr[offset] = pattern; }
/* @@ -816,18 +811,18 @@ static ulong mem_test_alt(ulong start_addr, ulong end_addr) */ for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) { WATCHDOG_RESET(); - temp = start[offset]; + temp = addr[offset]; if (temp != pattern) { printf("\nFAILURE (read/write) @ 0x%.8lx:" " expected 0x%.8lx, actual 0x%.8lx)\n", - (ulong)&start[offset], pattern, temp); + start_addr + offset, pattern, temp); errs++; if (ctrlc()) return -1; }
anti_pattern = ~pattern; - start[offset] = anti_pattern; + addr[offset] = anti_pattern; }
/* @@ -836,28 +831,28 @@ static ulong mem_test_alt(ulong start_addr, ulong end_addr) for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) { WATCHDOG_RESET(); anti_pattern = ~pattern; - temp = start[offset]; + temp = addr[offset]; if (temp != anti_pattern) { printf("\nFAILURE (read/write): @ 0x%.8lx:" " expected 0x%.8lx, actual 0x%.8lx)\n", - (ulong)&start[offset], anti_pattern, temp); + start_addr + offset, anti_pattern, temp); errs++; if (ctrlc()) return -1; } - start[offset] = 0; + addr[offset] = 0; }
return 0; }
-static ulong mem_test_quick(ulong start_addr, ulong end_addr, vu_long pattern, - int iteration) +static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr, + vu_long pattern, int iteration) { - vu_long *start, *end; + vu_long *end; vu_long *addr; ulong errs = 0; - ulong incr; + ulong incr, length; ulong val, readback;
/* Alternate the pattern */ @@ -875,14 +870,14 @@ static ulong mem_test_quick(ulong start_addr, ulong end_addr, vu_long pattern, else pattern = ~pattern; } - start = (vu_long *)start_addr; - end = (vu_long *)end_addr; + length = (end_addr - start_addr) / sizeof(ulong); + end = buf + length; printf("\rPattern %08lX Writing..." "%12s" "\b\b\b\b\b\b\b\b\b\b", pattern, "");
- for (addr = start, val = pattern; addr < end; addr++) { + for (addr = buf, val = pattern; addr < end; addr++) { WATCHDOG_RESET(); *addr = val; val += incr; @@ -890,13 +885,16 @@ static ulong mem_test_quick(ulong start_addr, ulong end_addr, vu_long pattern,
puts("Reading...");
- for (addr = start, val = pattern; addr < end; addr++) { + for (addr = buf, val = pattern; addr < end; addr++) { WATCHDOG_RESET(); readback = *addr; if (readback != val) { + ulong offset = addr - buf; + printf("\nMem error @ 0x%08X: " "found %08lX, expected %08lX\n", - (uint)(uintptr_t)addr, readback, val); + (uint)(uintptr_t)(start_addr + offset), + readback, val); errs++; if (ctrlc()) return -1; @@ -916,6 +914,7 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { ulong start, end; + vu_long *buf, *dummy; int iteration_limit; int ret; ulong errs = 0; /* number of errors, or -1 if interrupted */ @@ -951,6 +950,8 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, debug("%s:%d: start %#08lx end %#08lx\n", __func__, __LINE__, start, end);
+ buf = map_sysmem(start, end - start); + dummy = map_sysmem(CONFIG_SYS_MEMTEST_SCRATCH, sizeof(vu_long)); for (iteration = 0; !iteration_limit || iteration < iteration_limit; iteration++) { @@ -961,11 +962,17 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
printf("Iteration: %6d\r", iteration + 1); debug("\n"); - if (alt_test) - errs = mem_test_alt(start, end); - else - errs = mem_test_quick(start, end, pattern, iteration); + if (alt_test) { + errs = mem_test_alt(buf, start, end, dummy); + } else { + errs = mem_test_quick(buf, start, end, pattern, + iteration); + } + if (errs == -1UL) + break; } + unmap_sysmem((void *)buf); + unmap_sysmem((void *)dummy);
if (errs == -1UL) { /* Memory test was aborted - write a newline to finish off */

On Wed, Dec 26, 2012 at 10:57 AM, Simon Glass sjg@chromium.org wrote:
Use map_sysmem() in the memory tester so that it works as expected on sandbox.
Signed-off-by: Simon Glass sjg@chromium.org
Applied to x86/master.
common/cmd_mem.c | 97 +++++++++++++++++++++++++++++------------------------- 1 files changed, 52 insertions(+), 45 deletions(-)

Use map_sysmem() so that hashing is possible on sandbox.
Signed-off-by: Simon Glass sjg@chromium.org --- common/hash.c | 25 +++++++++++++++++-------- 1 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/common/hash.c b/common/hash.c index e92b4b1..2e0a67b 100644 --- a/common/hash.c +++ b/common/hash.c @@ -28,6 +28,7 @@ #include <hash.h> #include <sha1.h> #include <sha256.h> +#include <asm/io.h>
/* * These are the hash algorithms we support. Chips which support accelerated @@ -72,10 +73,13 @@ static void store_result(struct hash_algo *algo, const u8 *sum, unsigned int i;
if (*dest == '*') { - u8 *ptr; + ulong addr; + void *buf;
- ptr = (u8 *)simple_strtoul(dest + 1, NULL, 16); - memcpy(ptr, sum, algo->digest_size); + addr = simple_strtoul(dest + 1, NULL, 16); + buf = map_sysmem(addr, algo->digest_size); + memcpy(buf, sum, algo->digest_size); + unmap_sysmem(buf); } else { char str_output[HASH_MAX_DIGEST_SIZE * 2 + 1]; char *str_ptr = str_output; @@ -105,10 +109,13 @@ static void store_result(struct hash_algo *algo, const u8 *sum, static int parse_verify_sum(struct hash_algo *algo, char *verify_str, u8 *vsum) { if (*verify_str == '*') { - u8 *ptr; + ulong addr; + void *buf;
- ptr = (u8 *)simple_strtoul(verify_str + 1, NULL, 16); - memcpy(vsum, ptr, algo->digest_size); + addr = simple_strtoul(verify_str + 1, NULL, 16); + buf = map_sysmem(addr, algo->digest_size); + memcpy(vsum, buf, algo->digest_size); + unmap_sysmem(buf); } else { unsigned int i; char *vsum_str; @@ -169,6 +176,7 @@ int hash_command(const char *algo_name, int verify, cmd_tbl_t *cmdtp, int flag, { struct hash_algo *algo; ulong addr, len; + void *buf; u8 output[HASH_MAX_DIGEST_SIZE]; u8 vsum[HASH_MAX_DIGEST_SIZE];
@@ -189,8 +197,9 @@ int hash_command(const char *algo_name, int verify, cmd_tbl_t *cmdtp, int flag, return 1; }
- algo->hash_func_ws((const unsigned char *)addr, len, output, - algo->chunk_size); + buf = map_sysmem(addr, len); + algo->hash_func_ws(buf, len, output, algo->chunk_size); + unmap_sysmem(buf);
/* Try to avoid code bloat when verify is not needed */ #ifdef CONFIG_HASH_VERIFY

On Wed, Dec 26, 2012 at 10:57 AM, Simon Glass sjg@chromium.org wrote:
Use map_sysmem() so that hashing is possible on sandbox.
Signed-off-by: Simon Glass sjg@chromium.org
Applied to x86/master.
common/hash.c | 25 +++++++++++++++++-------- 1 files changed, 17 insertions(+), 8 deletions(-)

On Wed, Dec 26, 2012 at 10:56:53AM -0800, Simon Glass wrote:
This series aims to get all the memory functions running correctly on sandbox.
There was some discussion about this a while ago, and a commit was added to show a possible approach:
355a8357 sandbox: Change md command to use map_physmem
This commit was subsequently reverted because it used map_physmem() instead of the NOP that most architectures need for the memory functions.
This series introduces map_sysmem(), a NOP on all architectures except sandbox. It allows us to use a ram buffer to which all U-Boot addresses are relative. The memory commands (including hashing) are updated to use this so that sandbox can now use those commands.
Half of the mtest code is behind #ifdefs and there is duplication of some functions in both versions of the memory test. Several patches here clean this up a bit and get it working on sandbox.
The numeric setenv_ulong() function is a useful way of avoiding a 'char buf[17]; sprintf(buf, "%ld", ...); setenv("...", buf)' sequence. There is also setenv_addr(). What is missing is setenv_hex() which sets a ulong in hex format. Add this function and then make use of it in the main places: common/ drivers/ and net/.
The recently added and very basic hash instructure can help reduce code duplication in some cases. Redo the crc32 command to use this, and make it available through the 'hash' command. Also a few bugs were found in hashing with verify disabled - the arg count was not checked and a variable declaration was missing.
To permit the memory tester to run on sandbox, we need ctrl-C to work. To achieve this, add a proper implementation of sandbox's tstc(), with a simple FIFO for character input. An os_usleep() is added to ensure that U-Boot does not consume infinite CPU when setting at the command prompt.
With all of this it is possible to use the memory commands in sandbox, as well as crc32 and the other hashing commands.
So, aside from a few posted comments: Reviewed-by: Tom Rini trini@ti.com
And pending the answer to if you plan to v2 the hash command part (and since everyone sets CONFIG_CMD_CRC32, we do want to be careful), I'm OK with applying this bundle.
participants (5)
-
Barak Wasserstrom
-
Marek Vasut
-
Simon Glass
-
Tom Rini
-
Wolfgang Denk