X-Git-Url: https://git.karo-electronics.de/?a=blobdiff_plain;f=common%2Fcmd_mem.c;h=d7666c2f302591b5c8461f9514c66c32606fa93c;hb=3f510db522d160179dff3ddcce9b18f6241c2c24;hp=2bdbc9df157140add0bc0bbfe165539ba46e112c;hpb=56523f12830227fc18437bf935fefdb10fe25cca;p=karo-tx-uboot.git diff --git a/common/cmd_mem.c b/common/cmd_mem.c index 2bdbc9df15..d7666c2f30 100644 --- a/common/cmd_mem.c +++ b/common/cmd_mem.c @@ -29,42 +29,13 @@ #include #include -#if (CONFIG_COMMANDS & CFG_CMD_MMC) +#if defined(CONFIG_CMD_MMC) #include #endif #ifdef CONFIG_HAS_DATAFLASH #include #endif - -#if (CONFIG_COMMANDS & (CFG_CMD_MEMORY | \ - CFG_CMD_I2C | \ - CFG_CMD_ITEST | \ - CFG_CMD_PCI | \ - CMD_CMD_PORTIO ) ) -int cmd_get_data_size(char* arg, int default_size) -{ - /* Check for a size specification .b, .w or .l. - */ - int len = strlen(arg); - if (len > 2 && arg[len-2] == '.') { - switch(arg[len-1]) { - case 'b': - return 1; - case 'w': - return 2; - case 'l': - return 4; - case 's': - return -2; - default: - return -1; - } - } - return default_size; -} -#endif - -#if (CONFIG_COMMANDS & CFG_CMD_MEMORY) +#include #ifdef CMD_MEM_DEBUG #define PRINTF(fmt,args...) printf (fmt ,##args) @@ -92,8 +63,9 @@ static ulong base_address = 0; int do_mem_md ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { ulong addr, length; - ulong i, nbytes, linebytes; - u_char *cp; +#if defined(CONFIG_HAS_DATAFLASH) + ulong nbytes, linebytes; +#endif int size; int rc = 0; @@ -128,6 +100,7 @@ int do_mem_md ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) length = simple_strtoul(argv[2], NULL, 16); } +#if defined(CONFIG_HAS_DATAFLASH) /* Print the lines. * * We buffer all read data, so we can make sure data is read only @@ -136,64 +109,48 @@ int do_mem_md ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) nbytes = length * size; do { char linebuf[DISP_LINE_LEN]; - uint *uip = (uint *)linebuf; - ushort *usp = (ushort *)linebuf; - u_char *ucp = (u_char *)linebuf; -#ifdef CONFIG_HAS_DATAFLASH - int rc; -#endif - printf("%08lx:", addr); + void* p; linebytes = (nbytes>DISP_LINE_LEN)?DISP_LINE_LEN:nbytes; -#ifdef CONFIG_HAS_DATAFLASH - if ((rc = read_dataflash(addr, (linebytes/size)*size, linebuf)) == DATAFLASH_OK){ - /* if outside dataflash */ - /*if (rc != 1) { - dataflash_perror (rc); - return (1); - }*/ - for (i=0; i 0x7e)) - putc ('.'); - else - printf("%c", *cp); - cp++; - } - putc ('\n'); nbytes -= linebytes; + addr += linebytes; if (ctrlc()) { rc = 1; break; } } while (nbytes > 0); +#else + +# if defined(CONFIG_BLACKFIN) + /* See if we're trying to display L1 inst */ + if (addr_bfin_on_chip_mem(addr)) { + char linebuf[DISP_LINE_LEN]; + ulong linebytes, nbytes = length * size; + do { + linebytes = (nbytes > DISP_LINE_LEN) ? DISP_LINE_LEN : nbytes; + memcpy(linebuf, (void *)addr, linebytes); + print_buffer(addr, linebuf, size, linebytes/size, DISP_LINE_LEN/size); + + nbytes -= linebytes; + addr += linebytes; + if (ctrlc()) { + rc = 1; + break; + } + } while (nbytes > 0); + } else +# endif + + { + /* Print the lines. */ + print_buffer(addr, (void*)addr, size, length, DISP_LINE_LEN/size); + addr += size*length; + } +#endif dp_last_addr = addr; dp_last_length = length; @@ -253,6 +210,66 @@ int do_mem_mw ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) return 0; } +#ifdef CONFIG_MX_CYCLIC +int do_mem_mdc ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +{ + int i; + ulong count; + + if (argc < 4) { + printf ("Usage:\n%s\n", cmdtp->usage); + return 1; + } + + count = simple_strtoul(argv[3], NULL, 10); + + for (;;) { + do_mem_md (NULL, 0, 3, argv); + + /* delay for ms... */ + for (i=0; iusage); + return 1; + } + + count = simple_strtoul(argv[3], NULL, 10); + + for (;;) { + do_mem_mw (NULL, 0, 3, argv); + + /* delay for ms... */ + for (i=0; i 0) { @@ -359,18 +383,18 @@ int do_mem_cp ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) return 1; } -#ifndef CFG_NO_FLASH +#ifndef CONFIG_SYS_NO_FLASH /* check if we are copying to Flash */ if ( (addr2info(dest) != NULL) #ifdef CONFIG_HAS_DATAFLASH - && (!addr_dataflash(addr)) + && (!addr_dataflash(dest)) #endif ) { int rc; puts ("Copy to Flash... "); - rc = flash_write ((uchar *)addr, dest, count*size); + rc = flash_write ((char *)addr, dest, count*size); if (rc != 0) { flash_perror (rc); return (1); @@ -380,7 +404,7 @@ int do_mem_cp ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) } #endif -#if (CONFIG_COMMANDS & CFG_CMD_MMC) +#if defined(CONFIG_CMD_MMC) if (mmc2info(dest)) { int rc; @@ -438,7 +462,11 @@ int do_mem_cp ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) } /* Check if we are copying from DataFlash to RAM */ - if (addr_dataflash(addr) && !addr_dataflash(dest) && (addr2info(dest)==NULL) ){ + if (addr_dataflash(addr) && !addr_dataflash(dest) +#ifndef CONFIG_SYS_NO_FLASH + && (addr2info(dest) == NULL) +#endif + ){ int rc; rc = read_dataflash(addr, count * size, (char *) dest); if (rc != 1) { @@ -454,6 +482,14 @@ int do_mem_cp ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) } #endif +#ifdef CONFIG_BLACKFIN + /* See if we're copying to/from L1 inst */ + if (addr_bfin_on_chip_mem(dest) || addr_bfin_on_chip_mem(addr)) { + memcpy((void *)dest, (void *)addr, count * size); + return 0; + } +#endif + while (count-- > 0) { if (size == 4) *((ulong *)dest) = *((ulong *)addr); @@ -558,7 +594,7 @@ int do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) volatile uint *longp; volatile ushort *shortp; volatile u_char *cp; - + if (argc < 4) { printf ("Usage:\n%s\n", cmdtp->usage); return 1; @@ -580,7 +616,7 @@ int do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) /* data to write */ data = simple_strtoul(argv[3], NULL, 16); - + /* We want to optimize the loops to run as fast as possible. * If we have only one object, just run infinite loops. */ @@ -627,7 +663,7 @@ int do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) /* * Perform a memory test. A more complete alternative test can be - * configured using CFG_ALT_MEMTEST. The complete test loops until + * 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. */ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) @@ -635,19 +671,20 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) vu_long *addr, *start, *end; ulong val; ulong readback; + int rcode = 0; -#if defined(CFG_ALT_MEMTEST) - vu_long addr_mask; +#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; -#if defined(CFG_MEMTEST_SCRATCH) - vu_long *dummy = (vu_long*)CFG_MEMTEST_SCRATCH; +#if defined(CONFIG_SYS_MEMTEST_SCRATCH) + vu_long *dummy = (vu_long*)CONFIG_SYS_MEMTEST_SCRATCH; #else - vu_long *dummy = NULL; + vu_long *dummy = 0; /* yes, this is address 0x0, not NULL */ #endif int j; int iterations = 1; @@ -665,19 +702,18 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) #else ulong incr; ulong pattern; - int rcode = 0; #endif if (argc > 1) { start = (ulong *)simple_strtoul(argv[1], NULL, 16); } else { - start = (ulong *)CFG_MEMTEST_START; + start = (ulong *)CONFIG_SYS_MEMTEST_START; } if (argc > 2) { end = (ulong *)simple_strtoul(argv[2], NULL, 16); } else { - end = (ulong *)(CFG_MEMTEST_END); + end = (ulong *)(CONFIG_SYS_MEMTEST_END); } if (argc > 3) { @@ -686,7 +722,7 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) pattern = 0; } -#if defined(CFG_ALT_MEMTEST) +#if defined(CONFIG_SYS_ALT_MEMTEST) printf ("Testing %08x ... %08x:\n", (uint)start, (uint)end); PRINTF("%s:%d: start 0x%p end 0x%p\n", __FUNCTION__, __LINE__, start, end); @@ -736,7 +772,7 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) if(readback != ~val) { printf ("FAILURE (data line): " "Is %08lx, should be %08lx\n", - val, readback); + readback, ~val); } } } @@ -774,26 +810,19 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) * all possible. * * Returns: 0 if the test succeeds, 1 if the test fails. - * - * ## NOTE ## Be sure to specify start and end - * addresses such that addr_mask has - * lots of bits set. For example an - * address range of 01000000 02000000 is - * bad while a range of 01000000 - * 01ffffff is perfect. */ - addr_mask = ((ulong)end - (ulong)start)/sizeof(vu_long); + len = ((ulong)end - (ulong)start)/sizeof(vu_long); pattern = (vu_long) 0xaaaaaaaa; anti_pattern = (vu_long) 0x55555555; - PRINTF("%s:%d: addr mask = 0x%.8lx\n", + PRINTF("%s:%d: length = 0x%.8lx\n", __FUNCTION__, __LINE__, - addr_mask); + len); /* * Write the default pattern at each of the * power-of-two offsets. */ - for (offset = 1; (offset & addr_mask) != 0; offset <<= 1) { + for (offset = 1; offset < len; offset <<= 1) { start[offset] = pattern; } @@ -803,7 +832,7 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) test_offset = 0; start[test_offset] = anti_pattern; - for (offset = 1; (offset & addr_mask) != 0; offset <<= 1) { + for (offset = 1; offset < len; offset <<= 1) { temp = start[offset]; if (temp != pattern) { printf ("\nFAILURE: Address bit stuck high @ 0x%.8lx:" @@ -813,14 +842,15 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) } } start[test_offset] = pattern; + WATCHDOG_RESET(); /* * Check for addr bits stuck low or shorted. */ - for (test_offset = 1; (test_offset & addr_mask) != 0; test_offset <<= 1) { + for (test_offset = 1; test_offset < len; test_offset <<= 1) { start[test_offset] = anti_pattern; - for (offset = 1; (offset & addr_mask) != 0; 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 @" @@ -850,6 +880,7 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) * Fill memory with a known pattern. */ for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) { + WATCHDOG_RESET(); start[offset] = pattern; } @@ -857,6 +888,7 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) * 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:" @@ -873,6 +905,7 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) * 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) { @@ -899,6 +932,7 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) pattern, ""); for (addr=start,val=pattern; addrusage); + return 1; + } + + return !!gunzip((void *) dst, dst_len, (void *) src, &src_len); +} +#endif /* CONFIG_CMD_UNZIP */ + + /**************************************************/ -#if (CONFIG_COMMANDS & CFG_CMD_MEMORY) U_BOOT_CMD( - md, 3, 1, do_mem_md, - "md - memory display\n", - "[.b, .w, .l] address [# of objects]\n - memory display\n" + md, 3, 1, do_mem_md, + "md - memory display\n", + "[.b, .w, .l] address [# of objects]\n - memory display\n" ); U_BOOT_CMD( - mm, 2, 1, do_mem_mm, - "mm - memory modify (auto-incrementing)\n", + mm, 2, 1, do_mem_mm, + "mm - memory modify (auto-incrementing)\n", "[.b, .w, .l] address\n" " - memory modify, auto increment address\n" ); U_BOOT_CMD( - nm, 2, 1, do_mem_nm, - "nm - memory modify (constant address)\n", + nm, 2, 1, do_mem_nm, + "nm - memory modify (constant address)\n", "[.b, .w, .l] address\n - memory modify, read and keep address\n" ); U_BOOT_CMD( - mw, 4, 1, do_mem_mw, - "mw - memory write (fill)\n", - "[.b, .w, .l] address value [count]\n - write memory\n" + mw, 4, 1, do_mem_mw, + "mw - memory write (fill)\n", + "[.b, .w, .l] address value [count]\n - write memory\n" ); U_BOOT_CMD( - cp, 4, 1, do_mem_cp, - "cp - memory copy\n", + cp, 4, 1, do_mem_cp, + "cp - memory copy\n", "[.b, .w, .l] source target count\n - copy memory\n" ); U_BOOT_CMD( - cmp, 4, 1, do_mem_cmp, - "cmp - memory compare\n", + cmp, 4, 1, do_mem_cmp, + "cmp - memory compare\n", "[.b, .w, .l] addr1 addr2 count\n - compare memory\n" ); #ifndef CONFIG_CRC32_VERIFY U_BOOT_CMD( - crc32, 4, 1, do_mem_crc, - "crc32 - checksum calculation\n", + crc32, 4, 1, do_mem_crc, + "crc32 - checksum calculation\n", "address count [addr]\n - compute CRC32 checksum [save at addr]\n" ); #else /* CONFIG_CRC32_VERIFY */ U_BOOT_CMD( - crc32, 5, 1, do_mem_crc, - "crc32 - checksum calculation\n", + crc32, 5, 1, do_mem_crc, + "crc32 - checksum calculation\n", "address count [addr]\n - compute CRC32 checksum [save at addr]\n" "-v address count crc\n - verify crc of memory area\n" ); @@ -1185,34 +1254,53 @@ U_BOOT_CMD( #endif /* CONFIG_CRC32_VERIFY */ U_BOOT_CMD( - base, 2, 1, do_mem_base, - "base - print or set address offset\n", + base, 2, 1, do_mem_base, + "base - print or set address offset\n", "\n - print address offset for memory commands\n" "base off\n - set address offset for memory commands to 'off'\n" ); U_BOOT_CMD( - loop, 3, 1, do_mem_loop, - "loop - infinite loop on address range\n", + loop, 3, 1, do_mem_loop, + "loop - infinite loop on address range\n", "[.b, .w, .l] address number_of_objects\n" " - loop on a set of addresses\n" ); #ifdef CONFIG_LOOPW U_BOOT_CMD( - loopw, 4, 1, do_mem_loopw, - "loopw - infinite write loop on address range\n", + loopw, 4, 1, do_mem_loopw, + "loopw - infinite write loop on address range\n", "[.b, .w, .l] address number_of_objects data_to_write\n" " - loop on a set of addresses\n" ); #endif /* CONFIG_LOOPW */ U_BOOT_CMD( - mtest, 4, 1, do_mem_mtest, - "mtest - simple RAM test\n", + mtest, 4, 1, do_mem_mtest, + "mtest - simple RAM test\n", "[start [end [pattern]]]\n" " - simple RAM read/write test\n" ); -#endif -#endif /* CFG_CMD_MEMORY */ +#ifdef CONFIG_MX_CYCLIC +U_BOOT_CMD( + mdc, 4, 1, do_mem_mdc, + "mdc - memory display cyclic\n", + "[.b, .w, .l] address count delay(ms)\n - memory display cyclic\n" +); + +U_BOOT_CMD( + mwc, 4, 1, do_mem_mwc, + "mwc - memory write cyclic\n", + "[.b, .w, .l] address value delay(ms)\n - memory write cyclic\n" +); +#endif /* CONFIG_MX_CYCLIC */ + +#ifdef CONFIG_CMD_UNZIP +U_BOOT_CMD( + unzip, 4, 1, do_unzip, + "unzip - unzip a memory region\n", + "srcaddr dstaddr [dstsize]\n" +); +#endif /* CONFIG_CMD_UNZIP */