From 7b395232da84ae59bd32985bf944a0a9f417a543 Mon Sep 17 00:00:00 2001 From: Gabor Juhos Date: Mon, 21 Jan 2013 21:10:38 +0000 Subject: malloc: make malloc_bin_reloc static MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On architectures where manual relocation is needed, the 'malloc_bin_reloc' function must be called after 'mem_malloc_init'. Make the 'malloc_bin_reloc' function static and call it directly from 'mem_malloc_init' instead of calling that from board_init_{r,f} functions of the affected architectures. Signed-off-by: Gabor Juhos Cc: Wolfgang Denk Cc: Andreas Bießmann Cc: Jason Jin Cc: Macpaul Lin Cc: Daniel Hellstrom Cc: Daniel Schwierzeck --- common/dlmalloc.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'common') diff --git a/common/dlmalloc.c b/common/dlmalloc.c index b2f0a1ad52..2a9d169f92 100644 --- a/common/dlmalloc.c +++ b/common/dlmalloc.c @@ -1485,7 +1485,7 @@ static mbinptr av_[NAV * 2 + 2] = { }; #ifdef CONFIG_NEEDS_MANUAL_RELOC -void malloc_bin_reloc (void) +static void malloc_bin_reloc(void) { mbinptr *p = &av_[2]; size_t i; @@ -1493,6 +1493,8 @@ void malloc_bin_reloc (void) for (i = 2; i < ARRAY_SIZE(av_); ++i, ++p) *p = (mbinptr)((ulong)*p + gd->reloc_off); } +#else +static inline void malloc_bin_reloc(void) {} #endif ulong mem_malloc_start = 0; @@ -1526,6 +1528,8 @@ void mem_malloc_init(ulong start, ulong size) mem_malloc_brk = start; memset((void *)mem_malloc_start, 0, size); + + malloc_bin_reloc(); } /* field-extraction macros */ -- cgit v1.2.3 From 85de63e2e68d314bea2119b817669034d397f64b Mon Sep 17 00:00:00 2001 From: "Robert P. J. Day" Date: Sun, 3 Feb 2013 02:29:54 +0000 Subject: cmd_mem.c: Fix some typoes, no functional changes Signed-off-by: Robert P. J. Day --- common/cmd_mem.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'common') diff --git a/common/cmd_mem.c b/common/cmd_mem.c index 0f3ffc84ff..d44aa1d733 100644 --- a/common/cmd_mem.c +++ b/common/cmd_mem.c @@ -462,7 +462,8 @@ static int do_mem_loop(cmd_tbl_t *cmdtp, int flag, int argc, if (argc < 3) return CMD_RET_USAGE; - /* Check for a size spefication. + /* + * Check for a size specification. * Defaults to long if no or incorrect specification. */ if ((size = cmd_get_data_size(argv[0], 4)) < 0) @@ -531,7 +532,8 @@ int do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) if (argc < 4) return CMD_RET_USAGE; - /* Check for a size spefication. + /* + * Check for a size specification. * Defaults to long if no or incorrect specification. */ if ((size = cmd_get_data_size(argv[0], 4)) < 0) @@ -683,7 +685,7 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, * 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 + * floating bus doesn'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 @@ -747,7 +749,7 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, * 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, + * address failures such as stuck-high, * stuck-low, and shorted pins. The base * address and size of the region are * selected by the caller. -- cgit v1.2.3 From 70d7cb92528c88b7e0db841d94383d8d0fb350f3 Mon Sep 17 00:00:00 2001 From: "Robert P. J. Day" Date: Sun, 3 Feb 2013 05:46:13 +0000 Subject: cmd_load.c: Add #endif comments to reduce confusion Signed-off-by: Robert P. J. Day --- common/cmd_load.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'common') diff --git a/common/cmd_load.c b/common/cmd_load.c index 2c8dab1a0a..46db9626eb 100644 --- a/common/cmd_load.c +++ b/common/cmd_load.c @@ -1064,8 +1064,8 @@ U_BOOT_CMD( " - save S-Record file over serial line with offset 'off' and size 'size'" ); #endif /* CONFIG_SYS_LOADS_BAUD_CHANGE */ -#endif -#endif +#endif /* CONFIG_CMD_SAVES */ +#endif /* CONFIG_CMD_LOADS */ #if defined(CONFIG_CMD_LOADB) @@ -1085,7 +1085,7 @@ U_BOOT_CMD( " with offset 'off' and baudrate 'baud'" ); -#endif +#endif /* CONFIG_CMD_LOADB */ /* -------------------------------------------------------------------- */ @@ -1115,4 +1115,4 @@ U_BOOT_CMD( "[on|off]" ); -#endif +#endif /* CONFIG_CMD_HWFLOW */ -- cgit v1.2.3 From 1b3e0b191a3b93dee79226a276748c6e9aa1d071 Mon Sep 17 00:00:00 2001 From: Reinhard Arlt Date: Mon, 4 Feb 2013 09:37:11 +0000 Subject: cmd_elf: Fix broken bootvx command Fix broken bootvx command. Signed-off-by: Reinhard Arlt --- common/cmd_elf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'common') diff --git a/common/cmd_elf.c b/common/cmd_elf.c index a667a469b5..ab9c7e332d 100644 --- a/common/cmd_elf.c +++ b/common/cmd_elf.c @@ -198,7 +198,7 @@ int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) * defaults to 0x4200 */ tmp = getenv("bootaddr"); - if (tmp) + if (!tmp) bootaddr = CONFIG_SYS_VXWORKS_BOOT_ADDR; else bootaddr = simple_strtoul(tmp, NULL, 16); -- cgit v1.2.3 From 4f47aceb118b291831a603d7e6ca651d76bf88e0 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Thu, 7 Feb 2013 23:41:02 +0000 Subject: led: The gpio_led.c code expects that LED state is from the enum u-boot is not consistent if state should be 0|1 or of the enum, the GPIO driver expects this to be one of the enum values. Update the caller. Signed-off-by: Holger Hans Peter Freyther --- common/cmd_led.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'common') diff --git a/common/cmd_led.c b/common/cmd_led.c index 7f5ab43c7f..c725f95ac1 100644 --- a/common/cmd_led.c +++ b/common/cmd_led.c @@ -110,13 +110,13 @@ int do_led (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) if (led_commands[i].on) led_commands[i].on(); else - __led_set(led_commands[i].mask, 1); + __led_set(led_commands[i].mask, STATUS_LED_ON); break; case LED_OFF: if (led_commands[i].off) led_commands[i].off(); else - __led_set(led_commands[i].mask, 0); + __led_set(led_commands[i].mask, STATUS_LED_OFF); break; case LED_TOGGLE: if (led_commands[i].toggle) -- cgit v1.2.3 From 3e34cf7bffb87f3a96a87a4d1e0a76df7322b3c1 Mon Sep 17 00:00:00 2001 From: Piotr Wilczek Date: Sun, 27 Jan 2013 22:59:25 +0000 Subject: gpt: fix partion size limit Currently, in gpt command, partion size is converted from string to unsigned long type using 'ustrtol' function. That type limits the partition size to 4GB. This patch changes the conversion function to 'ustrtoll' to return unsigned long long type. Signed-off-by: Piotr Wilczek Signed-off-by: Kyungmin Park --- common/cmd_gpt.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'common') diff --git a/common/cmd_gpt.c b/common/cmd_gpt.c index da7705da69..efd7934bd7 100644 --- a/common/cmd_gpt.c +++ b/common/cmd_gpt.c @@ -27,6 +27,7 @@ #include #include #include +#include #ifndef CONFIG_PARTITION_UUIDS #error CONFIG_PARTITION_UUIDS must be enabled for CONFIG_CMD_GPT to be enabled @@ -131,6 +132,7 @@ static int set_gpt_info(block_dev_desc_t *dev_desc, int p_count; disk_partition_t *parts; int errno = 0; + uint64_t size_ll, start_ll; debug("%s: MMC lba num: 0x%x %d\n", __func__, (unsigned int)dev_desc->lba, (unsigned int)dev_desc->lba); @@ -217,8 +219,8 @@ static int set_gpt_info(block_dev_desc_t *dev_desc, } if (extract_env(val, &p)) p = val; - parts[i].size = ustrtoul(p, &p, 0); - parts[i].size /= dev_desc->blksz; + size_ll = ustrtoull(p, &p, 0); + parts[i].size = lldiv(size_ll, dev_desc->blksz); free(val); /* start address */ @@ -226,8 +228,8 @@ static int set_gpt_info(block_dev_desc_t *dev_desc, if (val) { /* start address is optional */ if (extract_env(val, &p)) p = val; - parts[i].start = ustrtoul(p, &p, 0); - parts[i].start /= dev_desc->blksz; + start_ll = ustrtoull(p, &p, 0); + parts[i].start = lldiv(start_ll, dev_desc->blksz); free(val); } } -- cgit v1.2.3 From 8fdf1e0f6d645f79a9b0677e062bf48d786c5b9e Mon Sep 17 00:00:00 2001 From: Vipin Kumar Date: Sun, 16 Dec 2012 22:32:48 +0000 Subject: imls: Add support to list images in NAND device This patch adds support to list images in NAND flash through imls Signed-off-by: Vipin Kumar --- common/cmd_bootm.c | 167 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 164 insertions(+), 3 deletions(-) (limited to 'common') diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c index f0338babeb..1312a0db8a 100644 --- a/common/cmd_bootm.c +++ b/common/cmd_bootm.c @@ -79,9 +79,15 @@ static int image_info(unsigned long addr); #include #include extern flash_info_t flash_info[]; /* info for FLASH chips */ +#endif + +#if defined(CONFIG_CMD_IMLS) || defined(CONFIG_CMD_IMLS_NAND) static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); #endif +#include +#include + #ifdef CONFIG_SILENT_CONSOLE static void fixup_silent_linux(void); #endif @@ -1192,7 +1198,7 @@ U_BOOT_CMD( /* imls - list all images found in flash */ /*******************************************************************/ #if defined(CONFIG_CMD_IMLS) -static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +static int do_imls_nor(void) { flash_info_t *info; int i, j; @@ -1241,6 +1247,161 @@ next_sector: ; } next_bank: ; } + return 0; +} +#endif + +#if defined(CONFIG_CMD_IMLS_NAND) +static int nand_imls_legacyimage(nand_info_t *nand, int nand_dev, loff_t off, + size_t len) +{ + void *imgdata; + int ret; + + imgdata = malloc(len); + if (!imgdata) { + printf("May be a Legacy Image at NAND device %d offset %08llX:\n", + nand_dev, off); + printf(" Low memory(cannot allocate memory for image)\n"); + return -ENOMEM; + } + + ret = nand_read_skip_bad(nand, off, &len, + imgdata); + if (ret < 0 && ret != -EUCLEAN) { + free(imgdata); + return ret; + } + + if (!image_check_hcrc(imgdata)) { + free(imgdata); + return 0; + } + + printf("Legacy Image at NAND device %d offset %08llX:\n", + nand_dev, off); + image_print_contents(imgdata); + + puts(" Verifying Checksum ... "); + if (!image_check_dcrc(imgdata)) + puts("Bad Data CRC\n"); + else + puts("OK\n"); + + free(imgdata); + + return 0; +} + +static int nand_imls_fitimage(nand_info_t *nand, int nand_dev, loff_t off, + size_t len) +{ + void *imgdata; + int ret; + + imgdata = malloc(len); + if (!imgdata) { + printf("May be a FIT Image at NAND device %d offset %08llX:\n", + nand_dev, off); + printf(" Low memory(cannot allocate memory for image)\n"); + return -ENOMEM; + } + + ret = nand_read_skip_bad(nand, off, &len, + imgdata); + if (ret < 0 && ret != -EUCLEAN) { + free(imgdata); + return ret; + } + + if (!fit_check_format(imgdata)) { + free(imgdata); + return 0; + } + + printf("FIT Image at NAND device %d offset %08llX:\n", nand_dev, off); + + fit_print_contents(imgdata); + free(imgdata); + + return 0; +} + +static int do_imls_nand(void) +{ + nand_info_t *nand; + int nand_dev = nand_curr_device; + size_t len; + loff_t off; + u32 buffer[16]; + + if (nand_dev < 0 || nand_dev >= CONFIG_SYS_MAX_NAND_DEVICE) { + puts("\nNo NAND devices available\n"); + return -ENODEV; + } + + printf("\n"); + + for (nand_dev = 0; nand_dev < CONFIG_SYS_MAX_NAND_DEVICE; nand_dev++) { + nand = &nand_info[nand_dev]; + if (!nand->name || !nand->size) + continue; + + for (off = 0; off < nand->size; off += nand->erasesize) { + const image_header_t *header; + int ret; + + if (nand_block_isbad(nand, off)) + continue; + + len = sizeof(buffer); + + ret = nand_read(nand, off, &len, (u8 *)buffer); + if (ret < 0 && ret != -EUCLEAN) { + printf("NAND read error %d at offset %08llX\n", + ret, off); + continue; + } + + switch (genimg_get_format(buffer)) { + case IMAGE_FORMAT_LEGACY: + header = (const image_header_t *)buffer; + + len = image_get_image_size(header); + nand_imls_legacyimage(nand, nand_dev, off, len); + break; +#if defined(CONFIG_FIT) + case IMAGE_FORMAT_FIT: + len = fit_get_size(buffer); + nand_imls_fitimage(nand, nand_dev, off, len); + break; +#endif + } + } + } + + return 0; +} +#endif + +#if defined(CONFIG_CMD_IMLS) || defined(CONFIG_CMD_IMLS_NAND) +static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + int ret_nor = 0, ret_nand = 0; + +#if defined(CONFIG_CMD_IMLS) + ret_nor = do_imls_nor(); +#endif + +#if defined(CONFIG_CMD_IMLS_NAND) + ret_nand = do_imls_nand(); +#endif + + if (ret_nor) + return ret_nor; + + if (ret_nand) + return ret_nand; return (0); } @@ -1249,8 +1410,8 @@ U_BOOT_CMD( imls, 1, 1, do_imls, "list all images found in flash", "\n" - " - Prints information about all images found at sector\n" - " boundaries in flash." + " - Prints information about all images found at sector/block\n" + " boundaries in nor/nand flash." ); #endif -- cgit v1.2.3 From ced199dc858d57e807d3ec2a511c4bd9a4bd8765 Mon Sep 17 00:00:00 2001 From: Harvey Chapman Date: Thu, 7 Feb 2013 11:34:44 +0000 Subject: nand: fix nand read.option parsing "nand read.part addr off size" would be treated as "nand read.raw addr off 1" It now fails as intended stating "Unknown nand command suffix '.part'" Signed-off-by: Harvey Chapman --- common/cmd_nand.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'common') diff --git a/common/cmd_nand.c b/common/cmd_nand.c index 1568594ca4..495610c405 100644 --- a/common/cmd_nand.c +++ b/common/cmd_nand.c @@ -608,7 +608,7 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) size_t rwsize; ulong pagecount = 1; int read; - int raw; + int raw = 0; if (argc < 4) goto usage; -- cgit v1.2.3 From b76a147b722565bde046f707a5cc92df8ea29738 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Thu, 21 Feb 2013 18:21:55 +0100 Subject: env_nand.c: clarify log messages when env reading fails The single message is misleading, since there is no equivalent success note when reading the other copy succeeds. Instead, warn if one of the redundant copies could not be loaded and emphasise on the error when reading both fails. Signed-off-by: Phil Sutter --- common/env_nand.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'common') diff --git a/common/env_nand.c b/common/env_nand.c index 22e72a20b0..382e8aec5e 100644 --- a/common/env_nand.c +++ b/common/env_nand.c @@ -331,6 +331,7 @@ int get_nand_env_oob(nand_info_t *nand, unsigned long *result) void env_relocate_spec(void) { #if !defined(ENV_IS_EMBEDDED) + int read1_fail = 0, read2_fail = 0; int crc1_ok = 0, crc2_ok = 0; env_t *ep, *tmp_env1, *tmp_env2; @@ -342,11 +343,14 @@ void env_relocate_spec(void) goto done; } - if (readenv(CONFIG_ENV_OFFSET, (u_char *) tmp_env1)) - puts("No Valid Environment Area found\n"); + read1_fail = readenv(CONFIG_ENV_OFFSET, (u_char *) tmp_env1); + read2_fail = readenv(CONFIG_ENV_OFFSET_REDUND, (u_char *) tmp_env2); - if (readenv(CONFIG_ENV_OFFSET_REDUND, (u_char *) tmp_env2)) - puts("No Valid Redundant Environment Area found\n"); + if (read1_fail && read2_fail) + puts("*** Error - No Valid Environment Area found\n"); + else if (read1_fail || read2_fail) + puts("*** Warning - some problems detected " + "reading environment; recovered successfully\n"); crc1_ok = crc32(0, tmp_env1->data, ENV_SIZE) == tmp_env1->crc; crc2_ok = crc32(0, tmp_env2->data, ENV_SIZE) == tmp_env2->crc; -- cgit v1.2.3 From a1eac57a2001ecf86a46f520cd85ef8e9c8b3687 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Thu, 21 Feb 2013 18:21:56 +0100 Subject: common/env_nand.c: calculate crc only when readenv was OK Calculating the checksum of incompletely read data is useless. Signed-off-by: Phil Sutter [scottwood@freescale.com: minor formatting fix] Signed-off-by: Scott Wood --- common/env_nand.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'common') diff --git a/common/env_nand.c b/common/env_nand.c index 382e8aec5e..5b69889c02 100644 --- a/common/env_nand.c +++ b/common/env_nand.c @@ -352,8 +352,10 @@ void env_relocate_spec(void) puts("*** Warning - some problems detected " "reading environment; recovered successfully\n"); - crc1_ok = crc32(0, tmp_env1->data, ENV_SIZE) == tmp_env1->crc; - crc2_ok = crc32(0, tmp_env2->data, ENV_SIZE) == tmp_env2->crc; + crc1_ok = !read1_fail && + (crc32(0, tmp_env1->data, ENV_SIZE) == tmp_env1->crc); + crc2_ok = !read2_fail && + (crc32(0, tmp_env2->data, ENV_SIZE) == tmp_env2->crc); if (!crc1_ok && !crc2_ok) { set_default_env("!bad CRC"); -- cgit v1.2.3 From 6b3ff98da41a084658877282057adeb59ff6e9f2 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 24 Feb 2013 17:33:11 +0000 Subject: Tidy up error checking and fix bug in hash command 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 --- common/cmd_hash.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'common') diff --git a/common/cmd_hash.c b/common/cmd_hash.c index 689c608572..eb6a33873b 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--; -- cgit v1.2.3 From 0628ab8ec59834f98ede267edd21ddb8ba0bb57b Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 24 Feb 2013 17:33:15 +0000 Subject: sandbox: Change memory commands to use map_physmem 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 --- common/cmd_mem.c | 122 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 79 insertions(+), 43 deletions(-) (limited to 'common') diff --git a/common/cmd_mem.c b/common/cmd_mem.c index d44aa1d733..ee7bf9ad33 100644 --- a/common/cmd_mem.c +++ b/common/cmd_mem.c @@ -33,6 +33,7 @@ #include #endif #include +#include #include DECLARE_GLOBAL_DATA_PTR; @@ -138,9 +139,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 @@ -163,6 +168,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; @@ -188,15 +195,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; } @@ -258,10 +268,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; @@ -294,33 +305,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; @@ -328,8 +346,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; @@ -419,15 +439,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) @@ -453,11 +476,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; @@ -477,28 +501,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++; @@ -506,28 +533,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; @@ -550,28 +579,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; @@ -579,14 +611,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; @@ -962,6 +994,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; @@ -1006,13 +1039,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] == '-')) { @@ -1042,16 +1076,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; -- cgit v1.2.3 From c9638f50fbd8e6973c296f6a8f2d5b91a4324c97 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 24 Feb 2013 17:33:16 +0000 Subject: Split out the memory tests into separate functions 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 --- common/cmd_mem.c | 217 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 116 insertions(+), 101 deletions(-) (limited to 'common') diff --git a/common/cmd_mem.c b/common/cmd_mem.c index ee7bf9ad33..0e7a4c67c2 100644 --- a/common/cmd_mem.c +++ b/common/cmd_mem.c @@ -626,36 +626,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 */ @@ -666,43 +656,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); @@ -731,34 +696,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; + } } } } @@ -802,15 +768,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. @@ -821,12 +785,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; } } @@ -843,12 +807,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; } } @@ -885,13 +849,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; } } @@ -907,24 +871,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; } @@ -935,29 +908,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 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 */ } -- cgit v1.2.3 From 51209b1f42cb6d1a7ce7c70be08aef2c988656cc Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 24 Feb 2013 17:33:17 +0000 Subject: Use common mtest iteration counting 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 --- common/cmd_mem.c | 123 ++++++++++++++++++++++++++----------------------------- 1 file changed, 59 insertions(+), 64 deletions(-) (limited to 'common') diff --git a/common/cmd_mem.c b/common/cmd_mem.c index 0e7a4c67c2..02ff65843a 100644 --- a/common/cmd_mem.c +++ b/common/cmd_mem.c @@ -626,11 +626,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; @@ -657,27 +655,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' @@ -710,7 +687,7 @@ static int mem_test_alt(vu_long *start, vu_long *end, errs++; if (ctrlc()) { putc('\n'); - return 1; + return -1; } } *addr = ~val; @@ -723,7 +700,7 @@ static int mem_test_alt(vu_long *start, vu_long *end, errs++; if (ctrlc()) { putc('\n'); - return 1; + return -1; } } } @@ -791,7 +768,7 @@ static int mem_test_alt(vu_long *start, vu_long *end, errs++; if (ctrlc()) { putc('\n'); - return 1; + return -1; } } } @@ -813,7 +790,7 @@ static int mem_test_alt(vu_long *start, vu_long *end, errs++; if (ctrlc()) { putc('\n'); - return 1; + return -1; } } } @@ -855,7 +832,7 @@ static int mem_test_alt(vu_long *start, vu_long *end, errs++; if (ctrlc()) { putc('\n'); - return 1; + return -1; } } @@ -877,37 +854,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", @@ -931,24 +909,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; } /* @@ -962,7 +929,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 @@ -989,10 +958,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 */ } -- cgit v1.2.3 From 7ecbd4d70842362c3a8ad9393e9d9aab7e13afbf Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 24 Feb 2013 17:33:18 +0000 Subject: Fix mtest indenting Some of the inner loops are not indented correctly. Fix this. Signed-off-by: Simon Glass --- common/cmd_mem.c | 322 +++++++++++++++++++++++++++---------------------------- 1 file changed, 161 insertions(+), 161 deletions(-) (limited to 'common') diff --git a/common/cmd_mem.c b/common/cmd_mem.c index 02ff65843a..5235bfe581 100644 --- a/common/cmd_mem.c +++ b/common/cmd_mem.c @@ -655,32 +655,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 doesn'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 doesn'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); @@ -703,129 +702,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. - */ + /* + * 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; + /* + * 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; + 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); @@ -834,20 +834,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); @@ -856,9 +856,9 @@ static ulong mem_test_alt(vu_long *start, vu_long *end) putc('\n'); return -1; } - } - start[offset] = 0; } + start[offset] = 0; + } return 0; } @@ -886,34 +886,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; } -- cgit v1.2.3 From c44d4386e67ac6dd57ddd60fdde54bf7ed581b6e Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 24 Feb 2013 17:33:19 +0000 Subject: Bring mtest putc() into common code 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 --- common/cmd_mem.c | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) (limited to 'common') diff --git a/common/cmd_mem.c b/common/cmd_mem.c index 5235bfe581..f5dd56db54 100644 --- a/common/cmd_mem.c +++ b/common/cmd_mem.c @@ -684,10 +684,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; @@ -697,10 +695,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; - } } } } @@ -765,10 +761,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; @@ -788,10 +782,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; @@ -830,10 +822,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; @@ -852,10 +842,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; } @@ -907,10 +895,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; } @@ -967,7 +953,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; } @@ -981,7 +966,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", -- cgit v1.2.3 From 8c86bbe00f927de0655a65e43344ca0678d1bc34 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 24 Feb 2013 17:33:20 +0000 Subject: Reduce casting in mtest 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 --- common/cmd_mem.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'common') diff --git a/common/cmd_mem.c b/common/cmd_mem.c index f5dd56db54..12dbc1609c 100644 --- a/common/cmd_mem.c +++ b/common/cmd_mem.c @@ -626,8 +626,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; @@ -655,6 +656,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' @@ -735,7 +739,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; @@ -851,9 +855,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; @@ -874,6 +879,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", @@ -912,7 +919,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 */ @@ -925,14 +932,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); @@ -944,10 +951,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; -- cgit v1.2.3 From bfc59966431e6335fd5be0589eec073902cc7bb3 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 24 Feb 2013 17:33:21 +0000 Subject: Update set_working_fdt_addr() to use setenv_addr() We might as well use this common function instead of repeating the same code. Signed-off-by: Simon Glass --- common/cmd_fdt.c | 11 ++--------- common/cmd_nvedit.c | 8 ++++---- 2 files changed, 6 insertions(+), 13 deletions(-) (limited to 'common') diff --git a/common/cmd_fdt.c b/common/cmd_fdt.c index 6eec947fcb..ac77a08b77 100644 --- a/common/cmd_fdt.c +++ b/common/cmd_fdt.c @@ -55,12 +55,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); } /* @@ -347,10 +343,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 7633f0c44a..44e88aa401 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); } -- cgit v1.2.3 From 41ef372c1a2d344621c74aa4bce5cdb0970ba5f1 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 24 Feb 2013 17:33:22 +0000 Subject: common: Use new numeric setenv functions Use setenv_ulong(), setenv_hex() and setenv_addr() in common/ Signed-off-by: Simon Glass --- 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(-) (limited to 'common') diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c index 1312a0db8a..b32991da0d 100644 --- a/common/cmd_bootm.c +++ b/common/cmd_bootm.c @@ -452,9 +452,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); @@ -529,17 +527,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 3b6cfd879b..f51534b07e 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 e7f496e4ea..0e43ab67c0 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 fbee8614ca..8ea1140e7f 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 27296ddd7d..4a4a0000b4 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 46db9626eb..0832e92b17 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 06fc171fe3..0cfca0c46b 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 495610c405..32348f3773 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 44e88aa401..d646d90880 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 e658618c6d..717c7f657b 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 5a042951da..7a38e94507 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 43ed7915fd..7470c2b12e 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 42a7eba766..ea0a26e784 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 1df0c4d72a..900e977c1c 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 a73c86d592..8607da81e2 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; } -- cgit v1.2.3 From 0ccff500cf787bb71e514eb2904d773ec84bf11d Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 24 Feb 2013 17:33:25 +0000 Subject: image: Use crc header file instead of C prototypes We have an existing header which the crc32 definitions, so use it. Signed-off-by: Simon Glass --- common/image.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'common') diff --git a/common/image.c b/common/image.c index ae1a9d3bd1..6afbb40a98 100644 --- a/common/image.c +++ b/common/image.c @@ -74,6 +74,8 @@ static const image_header_t *image_get_ramdisk(ulong rd_addr, uint8_t arch, #include #endif /* !USE_HOSTCC*/ +#include + static const table_entry_t uimage_arch[] = { { IH_ARCH_INVALID, NULL, "Invalid ARCH", }, { IH_ARCH_ALPHA, "alpha", "Alpha", }, @@ -160,8 +162,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 -- cgit v1.2.3 From d5b76673a5dfe0b5250baea3c36cdfa7a9fd5230 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 24 Feb 2013 17:33:26 +0000 Subject: hash: Add a flag to support saving hashes in the environment Some hashing commands permit saving the hash in an environment variable, and verifying a hash from there. But the crc32 command does not support this. In order to permit crc32 to use the generic hashing infrastructure, add a flag to select which behaviour to use. Signed-off-by: Simon Glass --- common/cmd_hash.c | 8 +++--- common/cmd_sha1sum.c | 6 ++--- common/hash.c | 69 +++++++++++++++++++++++++++++++++++++++------------- 3 files changed, 59 insertions(+), 24 deletions(-) (limited to 'common') diff --git a/common/cmd_hash.c b/common/cmd_hash.c index eb6a33873b..8c03b5c723 100644 --- a/common/cmd_hash.c +++ b/common/cmd_hash.c @@ -30,22 +30,22 @@ static int do_hash(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { #ifdef CONFIG_HASH_VERIFY - int verify = 0; + int flags = HASH_FLAG_ENV; if (argc < 4) return CMD_RET_USAGE; if (!strcmp(argv[1], "-v")) { - verify = 1; + flags |= HASH_FLAG_VERIFY; argc--; argv++; } #else - const int verify = 0; + const int flags = HASH_FLAG_ENV; #endif /* Move forward to 'algorithm' parameter */ argc--; argv++; - return hash_command(*argv, verify, cmdtp, flag, argc - 1, argv + 1); + return hash_command(*argv, flags, cmdtp, flag, argc - 1, argv + 1); } #ifdef CONFIG_HASH_VERIFY diff --git a/common/cmd_sha1sum.c b/common/cmd_sha1sum.c index fe927ab248..9f08629b87 100644 --- a/common/cmd_sha1sum.c +++ b/common/cmd_sha1sum.c @@ -31,7 +31,7 @@ int do_sha1sum(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { - int verify = 0; + int flags = HASH_FLAG_ENV; int ac; char * const *av; @@ -42,13 +42,13 @@ int do_sha1sum(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) ac = argc - 1; #ifdef CONFIG_SHA1SUM_VERIFY if (strcmp(*av, "-v") == 0) { - verify = 1; + flags |= HASH_FLAG_VERIFY; av++; ac--; } #endif - return hash_command("sha1", verify, cmdtp, flag, ac, av); + return hash_command("sha1", flags, cmdtp, flag, ac, av); } #ifdef CONFIG_SHA1SUM_VERIFY diff --git a/common/hash.c b/common/hash.c index e3a6e438a3..462853d172 100644 --- a/common/hash.c +++ b/common/hash.c @@ -58,19 +58,31 @@ static struct hash_algo hash_algo[] = { * @algo: Hash algorithm being used * @sum: Hash digest (algo->digest_size bytes) * @dest: Destination, interpreted as a hex address if it starts - * with * or otherwise as an environment variable. + * with * (or allow_env_vars is 0) or otherwise as an + * environment variable. + * @allow_env_vars: non-zero to permit storing the result to an + * variable environment */ static void store_result(struct hash_algo *algo, const u8 *sum, - const char *dest) + const char *dest, int allow_env_vars) { unsigned int i; + int env_var = 0; - if (*dest == '*') { - u8 *ptr; + /* + * If environment variables are allowed, then we assume that 'dest' + * is an environment variable, unless it starts with *, in which + * case we assume it is an address. If not allowed, it is always an + * address. This is to support the crc32 command. + */ + if (allow_env_vars) { + if (*dest == '*') + dest++; + else + env_var = 1; + } - ptr = (u8 *)simple_strtoul(dest + 1, NULL, 16); - memcpy(ptr, sum, algo->digest_size); - } else { + if (env_var) { char str_output[HASH_MAX_DIGEST_SIZE * 2 + 1]; char *str_ptr = str_output; @@ -80,6 +92,11 @@ static void store_result(struct hash_algo *algo, const u8 *sum, } str_ptr = '\0'; setenv(dest, str_output); + } else { + u8 *ptr; + + ptr = (u8 *)simple_strtoul(dest, NULL, 16); + memcpy(ptr, sum, algo->digest_size); } } @@ -94,14 +111,28 @@ static void store_result(struct hash_algo *algo, const u8 *sum, * Otherwise we assume it is an environment variable, and * look up its value (it must contain a hex digest). * @vsum: Returns binary digest value (algo->digest_size bytes) + * @allow_env_vars: non-zero to permit storing the result to an environment + * variable. If 0 then verify_str is assumed to be an + * address, and the * prefix is not expected. * @return 0 if ok, non-zero on error */ -static int parse_verify_sum(struct hash_algo *algo, char *verify_str, u8 *vsum) +static int parse_verify_sum(struct hash_algo *algo, char *verify_str, u8 *vsum, + int allow_env_vars) { - if (*verify_str == '*') { + int env_var = 0; + + /* See comment above in store_result() */ + if (allow_env_vars) { + if (*verify_str == '*') + verify_str++; + else + env_var = 1; + } + + if (env_var) { u8 *ptr; - ptr = (u8 *)simple_strtoul(verify_str + 1, NULL, 16); + ptr = (u8 *)simple_strtoul(verify_str, NULL, 16); memcpy(vsum, ptr, algo->digest_size); } else { unsigned int i; @@ -158,7 +189,7 @@ static void show_hash(struct hash_algo *algo, ulong addr, ulong len, printf("%02x", output[i]); } -int hash_command(const char *algo_name, int verify, cmd_tbl_t *cmdtp, int flag, +int hash_command(const char *algo_name, int flags, cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { struct hash_algo *algo; @@ -169,13 +200,14 @@ int hash_command(const char *algo_name, int verify, cmd_tbl_t *cmdtp, int flag, if (argc < 2) return CMD_RET_USAGE; + addr = simple_strtoul(*argv++, NULL, 16); + len = simple_strtoul(*argv++, NULL, 16); + algo = find_hash_algo(algo_name); if (!algo) { printf("Unknown hash algorithm '%s'\n", algo_name); return CMD_RET_USAGE; } - addr = simple_strtoul(*argv++, NULL, 16); - len = simple_strtoul(*argv++, NULL, 16); argc -= 2; if (algo->digest_size > HASH_MAX_DIGEST_SIZE) { @@ -188,13 +220,14 @@ int hash_command(const char *algo_name, int verify, cmd_tbl_t *cmdtp, int flag, /* Try to avoid code bloat when verify is not needed */ #ifdef CONFIG_HASH_VERIFY - if (verify) { + if (flags & HASH_FLAG_VERIFY) { #else if (0) { #endif if (!argc) return CMD_RET_USAGE; - if (parse_verify_sum(algo, *argv, vsum)) { + if (parse_verify_sum(algo, *argv, vsum, + flags & HASH_FLAG_ENV)) { printf("ERROR: %s does not contain a valid %s sum\n", *argv, algo->name); return 1; @@ -213,8 +246,10 @@ int hash_command(const char *algo_name, int verify, cmd_tbl_t *cmdtp, int flag, show_hash(algo, addr, len, output); printf("\n"); - if (argc) - store_result(algo, output, *argv); + if (argc) { + store_result(algo, output, *argv, + flags & HASH_FLAG_ENV); + } } return 0; -- cgit v1.2.3 From d20a40de9db07de1f1f06a79a4da1cdda5379b75 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 24 Feb 2013 20:30:22 +0000 Subject: Roll crc32 into hash infrastructure 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. Note: For some boards the hash command is not enabled, neither are sha1, sha256 or the verify option. In this case the full hash implementation adds about 500 bytes of overhead. So as a special case, we use #ifdef to select very simple bahaviour in that case. The justification for this is that it is currently a very common case (virtually all boards enable crc32 but only some enable more advanced features). Signed-off-by: Simon Glass --- common/cmd_mem.c | 75 ++++------------------------------- common/hash.c | 118 +++++++++++++++++++++++++++++++++++++------------------ 2 files changed, 87 insertions(+), 106 deletions(-) (limited to 'common') diff --git a/common/cmd_mem.c b/common/cmd_mem.c index 12dbc1609c..95b49b2100 100644 --- a/common/cmd_mem.c +++ b/common/cmd_mem.c @@ -32,6 +32,7 @@ #ifdef CONFIG_HAS_DATAFLASH #include #endif +#include #include #include #include @@ -1098,89 +1099,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 flags = 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; + flags |= HASH_FLAG_VERIFY; 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", flags, cmdtp, flag, ac, av); } -#endif /* CONFIG_CRC32_VERIFY */ #endif diff --git a/common/hash.c b/common/hash.c index 462853d172..ef6fe375d2 100644 --- a/common/hash.c +++ b/common/hash.c @@ -34,13 +34,19 @@ * crypto could perhaps add named version of these algorithms here. */ static struct hash_algo hash_algo[] = { -#ifdef CONFIG_SHA1 + /* + * This is CONFIG_CMD_SHA1SUM instead of CONFIG_SHA1 since otherwise + * it bloats the code for boards which use SHA1 but not the 'hash' + * or 'sha1sum' commands. + */ +#ifdef CONFIG_CMD_SHA1SUM { "SHA1", SHA1_SUM_LEN, sha1_csum_wd, CHUNKSZ_SHA1, }, +#define MULTI_HASH #endif #ifdef CONFIG_SHA256 { @@ -49,9 +55,27 @@ static struct hash_algo hash_algo[] = { sha256_csum_wd, CHUNKSZ_SHA256, }, +#define MULTI_HASH #endif + { + "CRC32", + 4, + crc32_wd_buf, + CHUNKSZ_CRC32, + }, }; +#if defined(CONFIG_HASH_VERIFY) || defined(CONFIG_CMD_HASH) +#define MULTI_HASH +#endif + +/* Try to minimize code size for boards that don't want much hashing */ +#ifdef MULTI_HASH +#define multi_hash() 1 +#else +#define multi_hash() 0 +#endif + /** * store_result: Store the resulting sum to an address or variable * @@ -192,10 +216,7 @@ static void show_hash(struct hash_algo *algo, ulong addr, ulong len, int hash_command(const char *algo_name, int flags, cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { - struct hash_algo *algo; ulong addr, len; - u8 output[HASH_MAX_DIGEST_SIZE]; - u8 vsum[HASH_MAX_DIGEST_SIZE]; if (argc < 2) return CMD_RET_USAGE; @@ -203,52 +224,73 @@ int hash_command(const char *algo_name, int flags, cmd_tbl_t *cmdtp, int flag, addr = simple_strtoul(*argv++, NULL, 16); len = simple_strtoul(*argv++, NULL, 16); - algo = find_hash_algo(algo_name); - if (!algo) { - printf("Unknown hash algorithm '%s'\n", algo_name); - return CMD_RET_USAGE; - } - argc -= 2; + if (multi_hash()) { + struct hash_algo *algo; + u8 output[HASH_MAX_DIGEST_SIZE]; + u8 vsum[HASH_MAX_DIGEST_SIZE]; - if (algo->digest_size > HASH_MAX_DIGEST_SIZE) { - puts("HASH_MAX_DIGEST_SIZE exceeded\n"); - return 1; - } + algo = find_hash_algo(algo_name); + if (!algo) { + printf("Unknown hash algorithm '%s'\n", algo_name); + return CMD_RET_USAGE; + } + argc -= 2; + + if (algo->digest_size > HASH_MAX_DIGEST_SIZE) { + puts("HASH_MAX_DIGEST_SIZE exceeded\n"); + return 1; + } - algo->hash_func_ws((const unsigned char *)addr, len, output, - algo->chunk_size); + algo->hash_func_ws((const unsigned char *)addr, len, output, + algo->chunk_size); - /* Try to avoid code bloat when verify is not needed */ + /* Try to avoid code bloat when verify is not needed */ #ifdef CONFIG_HASH_VERIFY - if (flags & HASH_FLAG_VERIFY) { + if (flags & HASH_FLAG_VERIFY) { #else - if (0) { + if (0) { #endif - if (!argc) - return CMD_RET_USAGE; - if (parse_verify_sum(algo, *argv, vsum, + if (!argc) + return CMD_RET_USAGE; + if (parse_verify_sum(algo, *argv, vsum, flags & HASH_FLAG_ENV)) { - printf("ERROR: %s does not contain a valid %s sum\n", - *argv, algo->name); - return 1; - } - if (memcmp(output, vsum, algo->digest_size) != 0) { - int i; + printf("ERROR: %s does not contain a valid " + "%s sum\n", *argv, algo->name); + return 1; + } + if (memcmp(output, vsum, algo->digest_size) != 0) { + int i; + show_hash(algo, addr, len, output); + printf(" != "); + for (i = 0; i < algo->digest_size; i++) + printf("%02x", vsum[i]); + puts(" ** ERROR **\n"); + return 1; + } + } else { show_hash(algo, addr, len, output); - printf(" != "); - for (i = 0; i < algo->digest_size; i++) - printf("%02x", vsum[i]); - puts(" ** ERROR **\n"); - return 1; + printf("\n"); + + if (argc) { + store_result(algo, output, *argv, + flags & HASH_FLAG_ENV); + } } + + /* Horrible code size hack for boards that just want crc32 */ } else { - show_hash(algo, addr, len, output); - printf("\n"); + ulong crc; + ulong *ptr; + + crc = crc32_wd(0, (const uchar *)addr, len, CHUNKSZ_CRC32); + + printf("CRC32 for %08lx ... %08lx ==> %08lx\n", + addr, addr + len - 1, crc); - if (argc) { - store_result(algo, output, *argv, - flags & HASH_FLAG_ENV); + if (argc > 3) { + ptr = (ulong *)simple_strtoul(argv[3], NULL, 16); + *ptr = crc; } } -- cgit v1.2.3 From 8e169cc943fcf93dd803adc70433b2c587db8796 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 24 Feb 2013 17:33:29 +0000 Subject: Move CONFIG_SYS_MEMTEST_SCRATCH #ifdef to top of file 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 --- common/cmd_mem.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'common') diff --git a/common/cmd_mem.c b/common/cmd_mem.c index 95b49b2100..50838a7614 100644 --- a/common/cmd_mem.c +++ b/common/cmd_mem.c @@ -39,6 +39,10 @@ DECLARE_GLOBAL_DATA_PTR; +#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. @@ -641,11 +645,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 */ -- cgit v1.2.3 From 5512d5b034d3f199f16f7c18171cae7732bb05eb Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 28 Feb 2013 17:47:14 +0000 Subject: sandbox: Update mtest to fix crashes Use map_sysmem() in the memory tester so that it works as expected on sandbox. Signed-off-by: Simon Glass --- common/cmd_mem.c | 108 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 63 insertions(+), 45 deletions(-) (limited to 'common') diff --git a/common/cmd_mem.c b/common/cmd_mem.c index 50838a7614..042c994a1b 100644 --- a/common/cmd_mem.c +++ b/common/cmd_mem.c @@ -631,21 +631,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 */ @@ -657,8 +655,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 @@ -677,11 +674,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) { @@ -740,58 +737,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; } /* @@ -806,14 +801,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; } /* @@ -821,18 +816,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; } /* @@ -841,28 +836,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 */ @@ -880,14 +875,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; @@ -895,13 +890,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; @@ -921,6 +919,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 */ @@ -956,6 +955,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++) { @@ -966,10 +967,27 @@ 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; + } + + /* + * Work-around for eldk-4.2 which gives this warning if we try to + * case in the unmap_sysmem() call: + * warning: initialization discards qualifiers from pointer target type + */ + { + void *vbuf = (void *)buf; + void *vdummy = (void *)dummy; + + unmap_sysmem(vbuf); + unmap_sysmem(vdummy); } if (errs == -1UL) { -- cgit v1.2.3 From bd091b67d0ef2959ed0ff2aa6575ddb0d21c1f71 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 24 Feb 2013 17:33:31 +0000 Subject: sandbox: Allow hash functions to work correctly Use map_sysmem() so that hashing is possible on sandbox. Signed-off-by: Simon Glass --- common/hash.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'common') diff --git a/common/hash.c b/common/hash.c index ef6fe375d2..0d04c4c9a0 100644 --- a/common/hash.c +++ b/common/hash.c @@ -28,6 +28,7 @@ #include #include #include +#include /* * These are the hash algorithms we support. Chips which support accelerated @@ -117,10 +118,13 @@ static void store_result(struct hash_algo *algo, const u8 *sum, str_ptr = '\0'; setenv(dest, str_output); } else { - u8 *ptr; + ulong addr; + void *buf; - ptr = (u8 *)simple_strtoul(dest, NULL, 16); - memcpy(ptr, sum, algo->digest_size); + addr = simple_strtoul(dest, NULL, 16); + buf = map_sysmem(addr, algo->digest_size); + memcpy(buf, sum, algo->digest_size); + unmap_sysmem(buf); } } @@ -154,10 +158,12 @@ static int parse_verify_sum(struct hash_algo *algo, char *verify_str, u8 *vsum, } if (env_var) { - u8 *ptr; + ulong addr; + void *buf; - ptr = (u8 *)simple_strtoul(verify_str, NULL, 16); - memcpy(vsum, ptr, algo->digest_size); + addr = simple_strtoul(verify_str, NULL, 16); + buf = map_sysmem(addr, algo->digest_size); + memcpy(vsum, buf, algo->digest_size); } else { unsigned int i; char *vsum_str; @@ -228,6 +234,7 @@ int hash_command(const char *algo_name, int flags, cmd_tbl_t *cmdtp, int flag, struct hash_algo *algo; u8 output[HASH_MAX_DIGEST_SIZE]; u8 vsum[HASH_MAX_DIGEST_SIZE]; + void *buf; algo = find_hash_algo(algo_name); if (!algo) { @@ -241,8 +248,9 @@ int hash_command(const char *algo_name, int flags, 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 -- cgit v1.2.3 From 218da0f35f4b5e5bf13d3dba6d975d4d5d65516f Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 24 Feb 2013 17:33:32 +0000 Subject: hash: Use lower case for hash algorithm names Rather than use strcasecmp() in the hash algorithm search, require the caller to do this first. Most of U-Boot can use lower case anyway, and the hash command can convert to lower case before calling hash_command(). This saves needing strcasecmp() for boards that use hashing but not the hash command. Signed-off-by: Simon Glass --- common/cmd_hash.c | 4 ++++ common/hash.c | 11 ++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) (limited to 'common') diff --git a/common/cmd_hash.c b/common/cmd_hash.c index 8c03b5c723..4fe0e78613 100644 --- a/common/cmd_hash.c +++ b/common/cmd_hash.c @@ -26,9 +26,11 @@ #include #include #include +#include static int do_hash(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { + char *s; #ifdef CONFIG_HASH_VERIFY int flags = HASH_FLAG_ENV; @@ -45,6 +47,8 @@ static int do_hash(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) /* Move forward to 'algorithm' parameter */ argc--; argv++; + for (s = *argv; *s; s++) + *s = tolower(*s); return hash_command(*argv, flags, cmdtp, flag, argc - 1, argv + 1); } diff --git a/common/hash.c b/common/hash.c index 0d04c4c9a0..f5badcb930 100644 --- a/common/hash.c +++ b/common/hash.c @@ -32,7 +32,8 @@ /* * These are the hash algorithms we support. Chips which support accelerated - * crypto could perhaps add named version of these algorithms here. + * crypto could perhaps add named version of these algorithms here. Note that + * algorithm names must be in lower case. */ static struct hash_algo hash_algo[] = { /* @@ -42,7 +43,7 @@ static struct hash_algo hash_algo[] = { */ #ifdef CONFIG_CMD_SHA1SUM { - "SHA1", + "sha1", SHA1_SUM_LEN, sha1_csum_wd, CHUNKSZ_SHA1, @@ -51,7 +52,7 @@ static struct hash_algo hash_algo[] = { #endif #ifdef CONFIG_SHA256 { - "SHA256", + "sha256", SHA256_SUM_LEN, sha256_csum_wd, CHUNKSZ_SHA256, @@ -59,7 +60,7 @@ static struct hash_algo hash_algo[] = { #define MULTI_HASH #endif { - "CRC32", + "crc32", 4, crc32_wd_buf, CHUNKSZ_CRC32, @@ -202,7 +203,7 @@ static struct hash_algo *find_hash_algo(const char *name) int i; for (i = 0; i < ARRAY_SIZE(hash_algo); i++) { - if (!strcasecmp(name, hash_algo[i].name)) + if (!strcmp(name, hash_algo[i].name)) return &hash_algo[i]; } -- cgit v1.2.3 From 28786eb960a8def9f2bd321c488c71ce96166ae3 Mon Sep 17 00:00:00 2001 From: Stefano Babic Date: Sat, 23 Feb 2013 00:53:27 +0000 Subject: SPL: Change description for spl command Add a more descriptive text to the help of the spl command. Signed-off-by: Stefano Babic Reviewed-by: Tom Rini --- common/cmd_spl.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'common') diff --git a/common/cmd_spl.c b/common/cmd_spl.c index e3c543b46a..94b0a17156 100644 --- a/common/cmd_spl.c +++ b/common/cmd_spl.c @@ -184,7 +184,11 @@ static int do_spl(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) U_BOOT_CMD( spl, 6 , 1, do_spl, "SPL configuration", - "export [kernel_addr] [initrd_addr] " - "[fdt_addr if = fdt] - export a kernel parameter image\n" - "\t initrd_img can be set to \"-\" if fdt_addr without initrd img is" - "used"); + "export [kernel_addr] [initrd_addr] [fdt_addr]\n" + "\timg\t\t\"atags\" or \"fdt\"\n" + "\tkernel_addr\taddress where a kernel image is stored.\n" + "\t\t\tkernel is loaded as part of the boot process, but it is not started.\n" + "\tinitrd_addr\taddress of initial ramdisk\n" + "\t\t\tcan be set to \"-\" if fdt_addr without initrd_addr is used.\n" + "\tfdt_addr\tin case of fdt, the address of the device tree.\n" + ); -- cgit v1.2.3 From a2979dcdbeb39a01dc888090d2c736c2ad3f548d Mon Sep 17 00:00:00 2001 From: Sonic Zhang Date: Thu, 16 Aug 2012 11:56:14 +0800 Subject: blackfin: bf60x: Port blackfin core architecture code to boot on bf60x. Set up clocks, DDR controller, Nor flash controller, reboot, serial port. Add new SPI boot modes. Signed-off-by: Bob Liu Signed-off-by: Sonic Zhang Signed-off-by: Sonic Zhang --- common/cmd_reginfo.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'common') diff --git a/common/cmd_reginfo.c b/common/cmd_reginfo.c index 08a6563448..b591bd3774 100644 --- a/common/cmd_reginfo.c +++ b/common/cmd_reginfo.c @@ -191,7 +191,7 @@ static int do_reginfo(cmd_tbl_t *cmdtp, int flag, int argc, #elif defined(CONFIG_BLACKFIN) puts("\nSystem Configuration registers\n"); - +#ifndef __ADSPBF60x__ puts("\nPLL Registers\n"); printf("\tPLL_DIV: 0x%04x PLL_CTL: 0x%04x\n", bfin_read_PLL_DIV(), bfin_read_PLL_CTL()); @@ -227,7 +227,24 @@ static int do_reginfo(cmd_tbl_t *cmdtp, int flag, int argc, printf("\tEBIU_SDSTAT: 0x%04x EBIU_SDGCTL: 0x%08x\n", bfin_read_EBIU_SDSTAT(), bfin_read_EBIU_SDGCTL()); # endif +#else + puts("\nCGU Registers\n"); + printf("\tCGU_DIV: 0x%08x CGU_CTL: 0x%08x\n", + bfin_read_CGU_DIV(), bfin_read_CGU_CTL()); + printf("\tCGU_STAT: 0x%08x CGU_LOCKCNT: 0x%08x\n", + bfin_read_CGU_STAT(), bfin_read_CGU_CLKOUTSEL()); + puts("\nSMC DDR Registers\n"); + printf("\tDDR_CFG: 0x%08x DDR_TR0: 0x%08x\n", + bfin_read_DMC0_CFG(), bfin_read_DMC0_TR0()); + printf("\tDDR_TR1: 0x%08x DDR_TR2: 0x%08x\n", + bfin_read_DMC0_TR1(), bfin_read_DMC0_TR2()); + printf("\tDDR_MR: 0x%08x DDR_EMR1: 0x%08x\n", + bfin_read_DMC0_MR(), bfin_read_DMC0_EMR1()); + printf("\tDDR_CTL: 0x%08x DDR_STAT: 0x%08x\n", + bfin_read_DMC0_CTL(), bfin_read_DMC0_STAT()); + printf("\tDDR_DLLCTL:0x%08x\n", bfin_read_DMC0_DLLCTL()); +#endif #endif /* CONFIG_BLACKFIN */ return 0; -- cgit v1.2.3 From d304931f236db3af4f6a6f522b140f26e63e3a18 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 26 Dec 2012 09:53:36 +0000 Subject: sandbox: Add 'sb' command to access filesystem features The new 'sb' command is intended to deal with sandbox-specific features that have no parallel in other archs. This commit adds two sub-commands to list a directory and read a file from the host filesystem. Signed-off-by: Simon Glass Reviewed-by: Tom Rini --- common/Makefile | 1 + common/cmd_sandbox.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 common/cmd_sandbox.c (limited to 'common') diff --git a/common/Makefile b/common/Makefile index 54fcc81588..719fc231b8 100644 --- a/common/Makefile +++ b/common/Makefile @@ -152,6 +152,7 @@ COBJS-$(CONFIG_CMD_PXE) += cmd_pxe.o COBJS-$(CONFIG_CMD_READ) += cmd_read.o COBJS-$(CONFIG_CMD_REGINFO) += cmd_reginfo.o COBJS-$(CONFIG_CMD_REISER) += cmd_reiser.o +COBJS-$(CONFIG_SANDBOX) += cmd_sandbox.o COBJS-$(CONFIG_CMD_SATA) += cmd_sata.o COBJS-$(CONFIG_CMD_SF) += cmd_sf.o COBJS-$(CONFIG_CMD_SCSI) += cmd_scsi.o diff --git a/common/cmd_sandbox.c b/common/cmd_sandbox.c new file mode 100644 index 0000000000..206a48614d --- /dev/null +++ b/common/cmd_sandbox.c @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2012, Google Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +#include +#include + +static int do_sandbox_load(cmd_tbl_t *cmdtp, int flag, int argc, + char * const argv[]) +{ + return do_load(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX, 16); +} + +static int do_sandbox_ls(cmd_tbl_t *cmdtp, int flag, int argc, + char * const argv[]) +{ + return do_ls(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX); +} + +static cmd_tbl_t cmd_sandbox_sub[] = { + U_BOOT_CMD_MKENT(load, 3, 0, do_sandbox_load, "", ""), + U_BOOT_CMD_MKENT(ls, 3, 0, do_sandbox_ls, "", ""), +}; + +static int do_sandbox(cmd_tbl_t *cmdtp, int flag, int argc, + char * const argv[]) +{ + cmd_tbl_t *c; + + /* Skip past 'sandbox' */ + argc--; + argv++; + + c = find_cmd_tbl(argv[0], cmd_sandbox_sub, + ARRAY_SIZE(cmd_sandbox_sub)); + + if (c) + return c->cmd(cmdtp, flag, argc, argv); + else + return CMD_RET_USAGE; +} + +U_BOOT_CMD( + sb, 6, 1, do_sandbox, + "Miscellaneous sandbox commands", + "load host [ ] - load a file from host\n" + "sb ls host - save a file to host" +); -- cgit v1.2.3 From 18a3cce9fa9030e0e1fe0678ddcd0ae84d9423ca Mon Sep 17 00:00:00 2001 From: Joe Hershberger Date: Fri, 8 Feb 2013 10:12:34 +0000 Subject: env: Avoid clobbering an edited variable on ctrl-c If readline says there was an error, don't write to the variable! Signed-off-by: Joe Hershberger --- common/cmd_nvedit.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'common') diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index d646d90880..3a05e60103 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -552,7 +552,8 @@ static int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc, else buffer[0] = '\0'; - readline_into_buffer("edit: ", buffer, 0); + if (readline_into_buffer("edit: ", buffer, 0) < 0) + return 1; return setenv(argv[1], buffer); } -- cgit v1.2.3 From 59af76d9ccccea43b9e07d78291bdf99e759c59a Mon Sep 17 00:00:00 2001 From: Daniel Schwierzeck Date: Tue, 26 Feb 2013 04:54:19 +0000 Subject: bootm: fix conditional compilation for bootm ramdisk subcommand All code related to the bootm ramdisk subcommand is conditionally enabled by CONFIG_SYS_BOOT_RAMDISK_HIGH except for the help message. Replace the CONFIG_ARCH defines by CONFIG_SYS_BOOT_RAMDISK_HIGH to fix this. Signed-off-by: Daniel Schwierzeck --- common/cmd_bootm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'common') diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c index b32991da0d..2e9335207c 100644 --- a/common/cmd_bootm.c +++ b/common/cmd_bootm.c @@ -1056,7 +1056,7 @@ static char bootm_help_text[] = "issued in the order below (it's ok to not issue all sub-commands):\n" "\tstart [addr [arg ...]]\n" "\tloados - load OS image\n" -#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC) +#if defined(CONFIG_SYS_BOOT_RAMDISK_HIGH) "\tramdisk - relocate initrd, set env initrd_start/initrd_end\n" #endif #if defined(CONFIG_OF_LIBFDT) -- cgit v1.2.3