]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - common/cmd_mem.c
ppc/85xx: Fix inclusion of 83xx immap in 85xx builds
[karo-tx-uboot.git] / common / cmd_mem.c
index a203e0d3e4dd021a084c214f5c36c8e6b6798b9c..a34b342f09e8d27a5c0a53e4b23ed55995828c4a 100644 (file)
 
 #include <common.h>
 #include <command.h>
-#if defined(CONFIG_CMD_MMC)
-#include <mmc.h>
-#endif
 #ifdef CONFIG_HAS_DATAFLASH
 #include <dataflash.h>
 #endif
 #include <watchdog.h>
 
+#include <u-boot/md5.h>
+#include <sha1.h>
+
 #ifdef CMD_MEM_DEBUG
 #define        PRINTF(fmt,args...)     printf (fmt ,##args)
 #else
@@ -404,46 +404,6 @@ int do_mem_cp ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
        }
 #endif
 
-#if defined(CONFIG_CMD_MMC)
-       if (mmc2info(dest)) {
-               int rc;
-
-               puts ("Copy to MMC... ");
-               switch (rc = mmc_write ((uchar *)addr, dest, count*size)) {
-               case 0:
-                       putc ('\n');
-                       return 1;
-               case -1:
-                       puts ("failed\n");
-                       return 1;
-               default:
-                       printf ("%s[%d] FIXME: rc=%d\n",__FILE__,__LINE__,rc);
-                       return 1;
-               }
-               puts ("done\n");
-               return 0;
-       }
-
-       if (mmc2info(addr)) {
-               int rc;
-
-               puts ("Copy from MMC... ");
-               switch (rc = mmc_read (addr, (uchar *)dest, count*size)) {
-               case 0:
-                       putc ('\n');
-                       return 1;
-               case -1:
-                       puts ("failed\n");
-                       return 1;
-               default:
-                       printf ("%s[%d] FIXME: rc=%d\n",__FILE__,__LINE__,rc);
-                       return 1;
-               }
-               puts ("done\n");
-               return 0;
-       }
-#endif
-
 #ifdef CONFIG_HAS_DATAFLASH
        /* Check if we are copying from RAM or Flash to DataFlash */
        if (addr_dataflash(dest) && !addr_dataflash(addr)){
@@ -671,7 +631,7 @@ 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;
+       ulong   errs = 0;
        int iterations = 1;
        int iteration_limit;
 
@@ -738,9 +698,9 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 
 
                if (iteration_limit && iterations > iteration_limit) {
-                       printf("Tested %d iteration(s) without errors.\n",
-                               iterations-1);
-                       return 0;
+                       printf("Tested %d iteration(s) with %lu errors.\n",
+                               iterations-1, errs);
+                       return errs != 0;
                }
 
                printf("Iteration: %6d\r", iterations);
@@ -772,9 +732,14 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
                        *dummy  = ~val; /* clear the test data off of the bus */
                        readback = *addr;
                        if(readback != val) {
-                            printf ("FAILURE (data line): "
+                           printf ("FAILURE (data line): "
                                "expected %08lx, actual %08lx\n",
                                          val, readback);
+                           errs++;
+                           if (ctrlc()) {
+                               putc ('\n');
+                               return 1;
+                           }
                        }
                        *addr  = ~val;
                        *dummy  = val;
@@ -783,6 +748,11 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
                            printf ("FAILURE (data line): "
                                "Is %08lx, should be %08lx\n",
                                        readback, ~val);
+                           errs++;
+                           if (ctrlc()) {
+                               putc ('\n');
+                               return 1;
+                           }
                        }
                    }
                }
@@ -848,7 +818,11 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
                        printf ("\nFAILURE: Address bit stuck high @ 0x%.8lx:"
                                " expected 0x%.8lx, actual 0x%.8lx\n",
                                (ulong)&start[offset], pattern, temp);
-                       return 1;
+                       errs++;
+                       if (ctrlc()) {
+                           putc ('\n');
+                           return 1;
+                       }
                    }
                }
                start[test_offset] = pattern;
@@ -866,7 +840,11 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
                            printf ("\nFAILURE: Address bit stuck low or shorted @"
                                " 0x%.8lx: expected 0x%.8lx, actual 0x%.8lx\n",
                                (ulong)&start[offset], pattern, temp);
-                           return 1;
+                           errs++;
+                           if (ctrlc()) {
+                               putc ('\n');
+                               return 1;
+                           }
                        }
                    }
                    start[test_offset] = pattern;
@@ -904,7 +882,11 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
                        printf ("\nFAILURE (read/write) @ 0x%.8lx:"
                                " expected 0x%.8lx, actual 0x%.8lx)\n",
                                (ulong)&start[offset], pattern, temp);
-                       return 1;
+                       errs++;
+                       if (ctrlc()) {
+                           putc ('\n');
+                           return 1;
+                       }
                    }
 
                    anti_pattern = ~pattern;
@@ -922,7 +904,11 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
                        printf ("\nFAILURE (read/write): @ 0x%.8lx:"
                                " expected 0x%.8lx, actual 0x%.8lx)\n",
                                (ulong)&start[offset], anti_pattern, temp);
-                       return 1;
+                       errs++;
+                       if (ctrlc()) {
+                           putc ('\n');
+                           return 1;
+                       }
                    }
                    start[offset] = 0;
                }
@@ -937,9 +923,9 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
                }
 
                if (iteration_limit && iterations > iteration_limit) {
-                       printf("Tested %d iteration(s) without errors.\n",
-                               iterations-1);
-                       return 0;
+                       printf("Tested %d iteration(s) with %lu errors.\n",
+                               iterations-1, errs);
+                       return errs != 0;
                }
                ++iterations;
 
@@ -963,7 +949,11 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
                                printf ("\nMem error @ 0x%08X: "
                                        "found %08lX, expected %08lX\n",
                                        (uint)addr, readback, val);
-                               rcode = 1;
+                               errs++;
+                               if (ctrlc()) {
+                                       putc ('\n');
+                                       return 1;
+                               }
                        }
                        val += incr;
                }
@@ -983,7 +973,7 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
                incr = -incr;
        }
 #endif
-       return rcode;
+       return 0;       /* not reached */
 }
 
 
@@ -1184,6 +1174,55 @@ int do_mem_crc (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 }
 #endif /* CONFIG_CRC32_VERIFY */
 
+#ifdef CONFIG_CMD_MD5SUM
+int do_md5sum(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+{
+       unsigned long addr, len;
+       unsigned int i;
+       u8 output[16];
+
+       if (argc < 3) {
+               cmd_usage(cmdtp);
+               return 1;
+       }
+
+       addr = simple_strtoul(argv[1], NULL, 16);
+       len = simple_strtoul(argv[2], NULL, 16);
+
+       md5((unsigned char *) addr, len, output);
+       printf("md5 for %08lx ... %08lx ==> ", addr, addr + len - 1);
+       for (i = 0; i < 16; i++)
+               printf("%02x", output[i]);
+       printf("\n");
+
+       return 0;
+}
+#endif
+
+#ifdef CONFIG_CMD_SHA1
+int do_sha1sum(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+{
+       unsigned long addr, len;
+       unsigned int i;
+       u8 output[20];
+
+       if (argc < 3) {
+               cmd_usage(cmdtp);
+               return 1;
+       }
+
+       addr = simple_strtoul(argv[1], NULL, 16);
+       len = simple_strtoul(argv[2], NULL, 16);
+
+       sha1_csum((unsigned char *) addr, len, output);
+       printf("SHA1 for %08lx ... %08lx ==> ", addr, addr + len - 1);
+       for (i = 0; i < 20; i++)
+               printf("%02x", output[i]);
+       printf("\n");
+
+       return 0;
+}
+#endif
 
 #ifdef CONFIG_CMD_UNZIP
 int  gunzip (void *, int, unsigned char *, unsigned long *);
@@ -1215,39 +1254,39 @@ int do_unzip ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 U_BOOT_CMD(
        md,     3,      1,      do_mem_md,
        "memory display",
-       "[.b, .w, .l] address [# of objects]\n    - memory display\n"
+       "[.b, .w, .l] address [# of objects]"
 );
 
 
 U_BOOT_CMD(
        mm,     2,      1,      do_mem_mm,
-       "memory modify (auto-incrementing)",
-       "[.b, .w, .l] address\n" "    - memory modify, auto increment address\n"
+       "memory modify (auto-incrementing address)",
+       "[.b, .w, .l] address"
 );
 
 
 U_BOOT_CMD(
        nm,     2,      1,      do_mem_nm,
        "memory modify (constant address)",
-       "[.b, .w, .l] address\n    - memory modify, read and keep address\n"
+       "[.b, .w, .l] address"
 );
 
 U_BOOT_CMD(
        mw,     4,      1,      do_mem_mw,
        "memory write (fill)",
-       "[.b, .w, .l] address value [count]\n   - write memory\n"
+       "[.b, .w, .l] address value [count]"
 );
 
 U_BOOT_CMD(
        cp,     4,      1,      do_mem_cp,
        "memory copy",
-       "[.b, .w, .l] source target count\n    - copy memory\n"
+       "[.b, .w, .l] source target count"
 );
 
 U_BOOT_CMD(
        cmp,    4,      1,      do_mem_cmp,
        "memory compare",
-       "[.b, .w, .l] addr1 addr2 count\n    - compare memory\n"
+       "[.b, .w, .l] addr1 addr2 count"
 );
 
 #ifndef CONFIG_CRC32_VERIFY
@@ -1255,7 +1294,7 @@ U_BOOT_CMD(
 U_BOOT_CMD(
        crc32,  4,      1,      do_mem_crc,
        "checksum calculation",
-       "address count [addr]\n    - compute CRC32 checksum [save at addr]\n"
+       "address count [addr]\n    - compute CRC32 checksum [save at addr]"
 );
 
 #else  /* CONFIG_CRC32_VERIFY */
@@ -1264,7 +1303,7 @@ U_BOOT_CMD(
        crc32,  5,      1,      do_mem_crc,
        "checksum calculation",
        "address count [addr]\n    - compute CRC32 checksum [save at addr]\n"
-       "-v address count crc\n    - verify crc of memory area\n"
+       "-v address count crc\n    - verify crc of memory area"
 );
 
 #endif /* CONFIG_CRC32_VERIFY */
@@ -1273,50 +1312,63 @@ U_BOOT_CMD(
        base,   2,      1,      do_mem_base,
        "print or set address offset",
        "\n    - print address offset for memory commands\n"
-       "base off\n    - set address offset for memory commands to 'off'\n"
+       "base off\n    - set address offset for memory commands to 'off'"
 );
 
 U_BOOT_CMD(
        loop,   3,      1,      do_mem_loop,
        "infinite loop on address range",
-       "[.b, .w, .l] address number_of_objects\n"
-       "    - loop on a set of addresses\n"
+       "[.b, .w, .l] address number_of_objects"
 );
 
 #ifdef CONFIG_LOOPW
 U_BOOT_CMD(
        loopw,  4,      1,      do_mem_loopw,
        "infinite write loop on address range",
-       "[.b, .w, .l] address number_of_objects data_to_write\n"
-       "    - loop on a set of addresses\n"
+       "[.b, .w, .l] address number_of_objects data_to_write"
 );
 #endif /* CONFIG_LOOPW */
 
 U_BOOT_CMD(
        mtest,  5,      1,      do_mem_mtest,
-       "simple RAM test",
-       "[start [end [pattern [iterations]]]]\n"
-       "    - simple RAM read/write test\n"
+       "simple RAM read/write test",
+       "[start [end [pattern [iterations]]]]"
 );
 
 #ifdef CONFIG_MX_CYCLIC
 U_BOOT_CMD(
        mdc,    4,      1,      do_mem_mdc,
        "memory display cyclic",
-       "[.b, .w, .l] address count delay(ms)\n    - memory display cyclic\n"
+       "[.b, .w, .l] address count delay(ms)"
 );
 
 U_BOOT_CMD(
        mwc,    4,      1,      do_mem_mwc,
        "memory write cyclic",
-       "[.b, .w, .l] address value delay(ms)\n    - memory write cyclic\n"
+       "[.b, .w, .l] address value delay(ms)"
 );
 #endif /* CONFIG_MX_CYCLIC */
 
+#ifdef CONFIG_CMD_MD5SUM
+U_BOOT_CMD(
+       md5sum, 3,      1,      do_md5sum,
+       "compute MD5 message digest",
+       "address count"
+);
+#endif
+
+#ifdef CONFIG_CMD_SHA1SUM
+U_BOOT_CMD(
+       sha1sum,        3,      1,      do_sha1sum,
+       "compute SHA1 message digest",
+       "address count"
+);
+#endif /* CONFIG_CMD_SHA1 */
+
 #ifdef CONFIG_CMD_UNZIP
 U_BOOT_CMD(
        unzip,  4,      1,      do_unzip,
        "unzip a memory region",
-       "srcaddr dstaddr [dstsize]\n"
+       "srcaddr dstaddr [dstsize]"
 );
 #endif /* CONFIG_CMD_UNZIP */