]> git.ipfire.org Git - people/ms/u-boot.git/blobdiff - common/cmd_mem.c
usb: dwc3: add dwc3 folder from linux kernel to u-boot
[people/ms/u-boot.git] / common / cmd_mem.c
index 0d50dcfe9c1b8083a35f3cc6df5796a12a0149a2..3f85c1aa85b9cc9cb3d2e397f653895a417b0e6a 100644 (file)
@@ -19,6 +19,7 @@
 #include <dataflash.h>
 #endif
 #include <hash.h>
+#include <inttypes.h>
 #include <watchdog.h>
 #include <asm/io.h>
 #include <linux/compiler.h>
@@ -338,7 +339,8 @@ static int do_mem_cmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
                if (word1 != word2) {
                        ulong offset = buf1 - base;
 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
-                       printf("%s at 0x%p (%#0*llx) != %s at 0x%p (%#0*llx)\n",
+                       printf("%s at 0x%p (%#0*"PRIx64") != %s at 0x%p (%#0*"
+                              PRIx64 ")\n",
                               type, (void *)(addr1 + offset), size, word1,
                               type, (void *)(addr2 + offset), size, word2);
 #else
@@ -997,10 +999,10 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
 {
        ulong start, end;
        vu_long *buf, *dummy;
-       int iteration_limit;
+       ulong iteration_limit = 0;
        int ret;
        ulong errs = 0; /* number of errors, or -1 if interrupted */
-       ulong pattern;
+       ulong pattern = 0;
        int iteration;
 #if defined(CONFIG_SYS_ALT_MEMTEST)
        const int alt_test = 1;
@@ -1008,25 +1010,29 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
        const int alt_test = 0;
 #endif
 
+       start = CONFIG_SYS_MEMTEST_START;
+       end = CONFIG_SYS_MEMTEST_END;
+
        if (argc > 1)
-               start = simple_strtoul(argv[1], NULL, 16);
-       else
-               start = CONFIG_SYS_MEMTEST_START;
+               if (strict_strtoul(argv[1], 16, &start) < 0)
+                       return CMD_RET_USAGE;
 
        if (argc > 2)
-               end = simple_strtoul(argv[2], NULL, 16);
-       else
-               end = CONFIG_SYS_MEMTEST_END;
+               if (strict_strtoul(argv[2], 16, &end) < 0)
+                       return CMD_RET_USAGE;
 
        if (argc > 3)
-               pattern = (ulong)simple_strtoul(argv[3], NULL, 16);
-       else
-               pattern = 0;
+               if (strict_strtoul(argv[3], 16, &pattern) < 0)
+                       return CMD_RET_USAGE;
 
        if (argc > 4)
-               iteration_limit = (ulong)simple_strtoul(argv[4], NULL, 16);
-       else
-               iteration_limit = 0;
+               if (strict_strtoul(argv[4], 16, &iteration_limit) < 0)
+                       return CMD_RET_USAGE;
+
+       if (end < start) {
+               printf("Refusing to do empty test\n");
+               return -1;
+       }
 
        printf("Testing %08x ... %08x:\n", (uint)start, (uint)end);
        debug("%s:%d: start %#08lx end %#08lx\n", __func__, __LINE__,
@@ -1077,7 +1083,7 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
                ret = errs != 0;
        }
 
-       return ret;     /* not reached */
+       return ret;
 }
 #endif /* CONFIG_CMD_MEMTEST */
 
@@ -1146,7 +1152,7 @@ mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
                        printf(" %08x", *((u32 *)ptr));
 #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
                else if (size == 8)
-                       printf(" %016llx", *((u64 *)ptr));
+                       printf(" %016" PRIx64, *((u64 *)ptr));
 #endif
                else if (size == 2)
                        printf(" %04x", *((u16 *)ptr));