diff options
author | Tom Rini <trini@konsulko.com> | 2019-07-18 11:31:37 -0400 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2019-07-18 11:31:37 -0400 |
commit | 0de815356474912ef5bef9a69f0327a5a93bb2c2 (patch) | |
tree | 92db8fda09396081f58a0c5fb182e72fbc3fdd50 /cmd/mem.c | |
parent | 9a06eb800c1bdc68aa81fcad6d4f404e12dfff33 (diff) | |
parent | bf88d2b023063a0c46d7617a4f6897d5d561662d (diff) |
Merge branch '2019-07-17-master-imports'
- Various FS/disk related fixes with security implications.
- Proper fix for the pci_ep test.
- Assorted bugfixes
- Some MediaTek updates.
- 'env erase' support.
Diffstat (limited to 'cmd/mem.c')
-rw-r--r-- | cmd/mem.c | 52 |
1 files changed, 52 insertions, 0 deletions
@@ -1082,6 +1082,49 @@ static int do_mem_crc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) #endif +#ifdef CONFIG_CMD_RANDOM +static int do_random(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + unsigned long addr, len; + unsigned long seed; // NOT INITIALIZED ON PURPOSE + unsigned int *buf, *start; + unsigned char *buf8; + unsigned int i; + + if (argc < 3 || argc > 4) { + printf("usage: %s <addr> <len> [<seed>]\n", argv[0]); + return 0; + } + + len = simple_strtoul(argv[2], NULL, 16); + addr = simple_strtoul(argv[1], NULL, 16); + + if (argc == 4) { + seed = simple_strtoul(argv[3], NULL, 16); + if (seed == 0) { + printf("The seed cannot be 0. Using 0xDEADBEEF.\n"); + seed = 0xDEADBEEF; + } + } else { + seed = get_timer(0) ^ rand(); + } + + srand(seed); + start = map_sysmem(addr, len); + buf = start; + for (i = 0; i < (len / 4); i++) + *buf++ = rand(); + + buf8 = (unsigned char *)buf; + for (i = 0; i < (len % 4); i++) + *buf8++ = rand() & 0xFF; + + unmap_sysmem(start); + printf("%lu bytes filled with random data\n", len); + return 1; +} +#endif + /**************************************************/ U_BOOT_CMD( md, 3, 1, do_mem_md, @@ -1250,3 +1293,12 @@ U_BOOT_CMD( "" ); #endif + +#ifdef CONFIG_CMD_RANDOM +U_BOOT_CMD( + random, 4, 0, do_random, + "fill memory with random pattern", + "<addr> <len> [<seed>]\n" + " - Fill 'len' bytes of memory starting at 'addr' with random data\n" +); +#endif |