blob: 4d8825418832b4037914f82be9edad5da3adaf48 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
wdenk38635852002-08-27 05:55:31 +00002/*
3 * (C) Copyright 2000
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
wdenk38635852002-08-27 05:55:31 +00005 */
6
7/*
8 * Memory Functions
9 *
10 * Copied from FADS ROM, Dan Malek (dmalek@jlc.net)
11 */
12
13#include <common.h>
Simon Glassa73bda42015-11-08 23:47:45 -070014#include <console.h>
Simon Glass399ed9a2014-04-10 20:01:30 -060015#include <bootretry.h>
Simon Glassdec3c012014-04-10 20:01:25 -060016#include <cli.h>
wdenk38635852002-08-27 05:55:31 +000017#include <command.h>
Simon Glassa73bda42015-11-08 23:47:45 -070018#include <console.h>
Simon Glassa606ffc2019-12-28 10:44:40 -070019#include <flash.h>
Simon Glass0bbd76f2013-02-24 20:30:22 +000020#include <hash.h>
Simon Glass0f2af882020-05-10 11:40:05 -060021#include <log.h>
Joe Hershberger65b905b2015-03-22 17:08:59 -050022#include <mapmem.h>
Simon Glass274e0b02020-05-10 11:39:56 -060023#include <rand.h>
Sergei Poselenov474dbb82008-04-09 16:09:41 +020024#include <watchdog.h>
Simon Glasse6d0ca22013-02-24 17:33:15 +000025#include <asm/io.h>
Simon Glasseacd14f2012-11-30 13:01:20 +000026#include <linux/compiler.h>
Simon Glassdbd79542020-05-10 11:40:11 -060027#include <linux/delay.h>
Simon Glasseacd14f2012-11-30 13:01:20 +000028
29DECLARE_GLOBAL_DATA_PTR;
wdenk38635852002-08-27 05:55:31 +000030
Simon Glassed38aef2020-05-10 11:40:03 -060031#ifndef CONFIG_SYS_MEMTEST_SCRATCH
32#define CONFIG_SYS_MEMTEST_SCRATCH 0
33#endif
34
35static int mod_mem(struct cmd_tbl *, int, int, int, char * const []);
wdenk38635852002-08-27 05:55:31 +000036
37/* Display values from last command.
38 * Memory modify remembered values are different from display memory.
39 */
Scott Wood3ec02882015-03-19 09:43:12 -070040static ulong dp_last_addr, dp_last_size;
41static ulong dp_last_length = 0x40;
42static ulong mm_last_addr, mm_last_size;
wdenk38635852002-08-27 05:55:31 +000043
44static ulong base_address = 0;
45
46/* Memory Display
47 *
48 * Syntax:
York Sun6c480012014-02-26 17:03:19 -080049 * md{.b, .w, .l, .q} {addr} {len}
wdenk38635852002-08-27 05:55:31 +000050 */
51#define DISP_LINE_LEN 16
Simon Glassed38aef2020-05-10 11:40:03 -060052static int do_mem_md(struct cmd_tbl *cmdtp, int flag, int argc,
53 char *const argv[])
wdenk38635852002-08-27 05:55:31 +000054{
Tuomas Tynkkynen1b725202017-10-10 21:59:42 +030055 ulong addr, length, bytes;
56 const void *buf;
wdenk874ac262003-07-24 23:38:38 +000057 int size;
wdenk38635852002-08-27 05:55:31 +000058 int rc = 0;
59
60 /* We use the last specified parameters, unless new ones are
61 * entered.
62 */
63 addr = dp_last_addr;
64 size = dp_last_size;
65 length = dp_last_length;
66
Wolfgang Denk3b683112010-07-17 01:06:04 +020067 if (argc < 2)
Simon Glassa06dfc72011-12-10 08:44:01 +000068 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +000069
70 if ((flag & CMD_FLAG_REPEAT) == 0) {
71 /* New command specified. Check for a size specification.
72 * Defaults to long if no or incorrect specification.
73 */
wdenk874ac262003-07-24 23:38:38 +000074 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
75 return 1;
wdenk38635852002-08-27 05:55:31 +000076
77 /* Address is specified since argc > 1
78 */
79 addr = simple_strtoul(argv[1], NULL, 16);
80 addr += base_address;
81
82 /* If another parameter, it is the length to display.
83 * Length is the number of objects, not number of bytes.
84 */
85 if (argc > 2)
86 length = simple_strtoul(argv[2], NULL, 16);
87 }
88
Tuomas Tynkkynen1b725202017-10-10 21:59:42 +030089 bytes = size * length;
90 buf = map_sysmem(addr, bytes);
Simon Glasse6d0ca22013-02-24 17:33:15 +000091
Tuomas Tynkkynen1b725202017-10-10 21:59:42 +030092 /* Print the lines. */
93 print_buffer(addr, buf, size, length, DISP_LINE_LEN / size);
94 addr += bytes;
95 unmap_sysmem(buf);
wdenk38635852002-08-27 05:55:31 +000096
97 dp_last_addr = addr;
98 dp_last_length = length;
99 dp_last_size = size;
100 return (rc);
101}
102
Simon Glassed38aef2020-05-10 11:40:03 -0600103static int do_mem_mm(struct cmd_tbl *cmdtp, int flag, int argc,
104 char *const argv[])
wdenk38635852002-08-27 05:55:31 +0000105{
106 return mod_mem (cmdtp, 1, flag, argc, argv);
107}
Simon Glassed38aef2020-05-10 11:40:03 -0600108
109static int do_mem_nm(struct cmd_tbl *cmdtp, int flag, int argc,
110 char *const argv[])
wdenk38635852002-08-27 05:55:31 +0000111{
112 return mod_mem (cmdtp, 0, flag, argc, argv);
113}
114
Simon Glassed38aef2020-05-10 11:40:03 -0600115static int do_mem_mw(struct cmd_tbl *cmdtp, int flag, int argc,
116 char *const argv[])
wdenk38635852002-08-27 05:55:31 +0000117{
Simon Glass8927bf22019-12-28 10:45:10 -0700118#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800119 u64 writeval;
120#else
121 ulong writeval;
122#endif
123 ulong addr, count;
wdenk874ac262003-07-24 23:38:38 +0000124 int size;
Simon Glass3c4a2872015-03-05 12:25:18 -0700125 void *buf, *start;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000126 ulong bytes;
wdenk38635852002-08-27 05:55:31 +0000127
Wolfgang Denk3b683112010-07-17 01:06:04 +0200128 if ((argc < 3) || (argc > 4))
Simon Glassa06dfc72011-12-10 08:44:01 +0000129 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000130
131 /* Check for size specification.
132 */
wdenk874ac262003-07-24 23:38:38 +0000133 if ((size = cmd_get_data_size(argv[0], 4)) < 1)
134 return 1;
wdenk38635852002-08-27 05:55:31 +0000135
136 /* Address is specified since argc > 1
137 */
138 addr = simple_strtoul(argv[1], NULL, 16);
139 addr += base_address;
140
141 /* Get the value to write.
142 */
Simon Glass8927bf22019-12-28 10:45:10 -0700143#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800144 writeval = simple_strtoull(argv[2], NULL, 16);
145#else
wdenk38635852002-08-27 05:55:31 +0000146 writeval = simple_strtoul(argv[2], NULL, 16);
York Sun6c480012014-02-26 17:03:19 -0800147#endif
wdenk38635852002-08-27 05:55:31 +0000148
149 /* Count ? */
150 if (argc == 4) {
151 count = simple_strtoul(argv[3], NULL, 16);
152 } else {
153 count = 1;
154 }
155
Simon Glasse6d0ca22013-02-24 17:33:15 +0000156 bytes = size * count;
Simon Glass3c4a2872015-03-05 12:25:18 -0700157 start = map_sysmem(addr, bytes);
158 buf = start;
wdenk38635852002-08-27 05:55:31 +0000159 while (count-- > 0) {
160 if (size == 4)
York Sund8a405d2014-02-12 15:55:35 -0800161 *((u32 *)buf) = (u32)writeval;
Simon Glass8927bf22019-12-28 10:45:10 -0700162#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800163 else if (size == 8)
164 *((u64 *)buf) = (u64)writeval;
165#endif
wdenk38635852002-08-27 05:55:31 +0000166 else if (size == 2)
York Sund8a405d2014-02-12 15:55:35 -0800167 *((u16 *)buf) = (u16)writeval;
wdenk38635852002-08-27 05:55:31 +0000168 else
York Sund8a405d2014-02-12 15:55:35 -0800169 *((u8 *)buf) = (u8)writeval;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000170 buf += size;
wdenk38635852002-08-27 05:55:31 +0000171 }
Simon Glass3c4a2872015-03-05 12:25:18 -0700172 unmap_sysmem(start);
wdenk38635852002-08-27 05:55:31 +0000173 return 0;
174}
175
Joel Johnsondb5a97e2020-01-29 09:17:18 -0700176#ifdef CONFIG_CMD_MX_CYCLIC
Simon Glassed38aef2020-05-10 11:40:03 -0600177static int do_mem_mdc(struct cmd_tbl *cmdtp, int flag, int argc,
178 char *const argv[])
stroesefb5e0ac2004-12-16 17:42:39 +0000179{
180 int i;
181 ulong count;
182
Wolfgang Denk3b683112010-07-17 01:06:04 +0200183 if (argc < 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000184 return CMD_RET_USAGE;
stroesefb5e0ac2004-12-16 17:42:39 +0000185
186 count = simple_strtoul(argv[3], NULL, 10);
187
188 for (;;) {
189 do_mem_md (NULL, 0, 3, argv);
190
191 /* delay for <count> ms... */
192 for (i=0; i<count; i++)
Simon Glass0db4b942020-05-10 11:40:10 -0600193 udelay(1000);
stroesefb5e0ac2004-12-16 17:42:39 +0000194
195 /* check for ctrl-c to abort... */
196 if (ctrlc()) {
197 puts("Abort\n");
198 return 0;
199 }
200 }
201
202 return 0;
203}
204
Simon Glassed38aef2020-05-10 11:40:03 -0600205static int do_mem_mwc(struct cmd_tbl *cmdtp, int flag, int argc,
206 char *const argv[])
stroesefb5e0ac2004-12-16 17:42:39 +0000207{
208 int i;
209 ulong count;
210
Wolfgang Denk3b683112010-07-17 01:06:04 +0200211 if (argc < 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000212 return CMD_RET_USAGE;
stroesefb5e0ac2004-12-16 17:42:39 +0000213
214 count = simple_strtoul(argv[3], NULL, 10);
215
216 for (;;) {
217 do_mem_mw (NULL, 0, 3, argv);
218
219 /* delay for <count> ms... */
220 for (i=0; i<count; i++)
Simon Glass0db4b942020-05-10 11:40:10 -0600221 udelay(1000);
stroesefb5e0ac2004-12-16 17:42:39 +0000222
223 /* check for ctrl-c to abort... */
224 if (ctrlc()) {
225 puts("Abort\n");
226 return 0;
227 }
228 }
229
230 return 0;
231}
Joel Johnsondb5a97e2020-01-29 09:17:18 -0700232#endif /* CONFIG_CMD_MX_CYCLIC */
stroesefb5e0ac2004-12-16 17:42:39 +0000233
Simon Glassed38aef2020-05-10 11:40:03 -0600234static int do_mem_cmp(struct cmd_tbl *cmdtp, int flag, int argc,
235 char *const argv[])
wdenk38635852002-08-27 05:55:31 +0000236{
Simon Glasse6d0ca22013-02-24 17:33:15 +0000237 ulong addr1, addr2, count, ngood, bytes;
wdenk874ac262003-07-24 23:38:38 +0000238 int size;
wdenk38635852002-08-27 05:55:31 +0000239 int rcode = 0;
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000240 const char *type;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000241 const void *buf1, *buf2, *base;
Simon Glass8927bf22019-12-28 10:45:10 -0700242#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800243 u64 word1, word2;
244#else
245 ulong word1, word2;
246#endif
wdenk38635852002-08-27 05:55:31 +0000247
Wolfgang Denk3b683112010-07-17 01:06:04 +0200248 if (argc != 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000249 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000250
251 /* Check for size specification.
252 */
wdenk874ac262003-07-24 23:38:38 +0000253 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
254 return 1;
York Sun6c480012014-02-26 17:03:19 -0800255 type = size == 8 ? "double word" :
256 size == 4 ? "word" :
257 size == 2 ? "halfword" : "byte";
wdenk38635852002-08-27 05:55:31 +0000258
259 addr1 = simple_strtoul(argv[1], NULL, 16);
260 addr1 += base_address;
261
262 addr2 = simple_strtoul(argv[2], NULL, 16);
263 addr2 += base_address;
264
265 count = simple_strtoul(argv[3], NULL, 16);
266
Simon Glasse6d0ca22013-02-24 17:33:15 +0000267 bytes = size * count;
268 base = buf1 = map_sysmem(addr1, bytes);
269 buf2 = map_sysmem(addr2, bytes);
Mike Frysingera66afbd2012-01-20 09:07:22 +0000270 for (ngood = 0; ngood < count; ++ngood) {
wdenk38635852002-08-27 05:55:31 +0000271 if (size == 4) {
York Sund8a405d2014-02-12 15:55:35 -0800272 word1 = *(u32 *)buf1;
273 word2 = *(u32 *)buf2;
Simon Glass8927bf22019-12-28 10:45:10 -0700274#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800275 } else if (size == 8) {
276 word1 = *(u64 *)buf1;
277 word2 = *(u64 *)buf2;
278#endif
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000279 } else if (size == 2) {
York Sund8a405d2014-02-12 15:55:35 -0800280 word1 = *(u16 *)buf1;
281 word2 = *(u16 *)buf2;
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000282 } else {
York Sund8a405d2014-02-12 15:55:35 -0800283 word1 = *(u8 *)buf1;
284 word2 = *(u8 *)buf2;
wdenk38635852002-08-27 05:55:31 +0000285 }
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000286 if (word1 != word2) {
Simon Glasse6d0ca22013-02-24 17:33:15 +0000287 ulong offset = buf1 - base;
Simon Glass8927bf22019-12-28 10:45:10 -0700288#ifdef MEM_SUPPORT_64BIT_DATA
Masahiro Yamadac7570a32018-08-06 20:47:40 +0900289 printf("%s at 0x%p (%#0*llx) != %s at 0x%p (%#0*llx)\n",
York Sun6c480012014-02-26 17:03:19 -0800290 type, (void *)(addr1 + offset), size, word1,
291 type, (void *)(addr2 + offset), size, word2);
292#else
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000293 printf("%s at 0x%08lx (%#0*lx) != %s at 0x%08lx (%#0*lx)\n",
Simon Glasse6d0ca22013-02-24 17:33:15 +0000294 type, (ulong)(addr1 + offset), size, word1,
295 type, (ulong)(addr2 + offset), size, word2);
York Sun6c480012014-02-26 17:03:19 -0800296#endif
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000297 rcode = 1;
298 break;
wdenk38635852002-08-27 05:55:31 +0000299 }
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000300
Simon Glasse6d0ca22013-02-24 17:33:15 +0000301 buf1 += size;
302 buf2 += size;
Stefan Roesed4ef82b2010-09-13 11:10:34 +0200303
304 /* reset watchdog from time to time */
Mike Frysingera66afbd2012-01-20 09:07:22 +0000305 if ((ngood % (64 << 10)) == 0)
Stefan Roesed4ef82b2010-09-13 11:10:34 +0200306 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000307 }
Simon Glasse6d0ca22013-02-24 17:33:15 +0000308 unmap_sysmem(buf1);
309 unmap_sysmem(buf2);
wdenk38635852002-08-27 05:55:31 +0000310
Mike Frysinger62a7ea72012-01-20 09:07:21 +0000311 printf("Total of %ld %s(s) were the same\n", ngood, type);
wdenk38635852002-08-27 05:55:31 +0000312 return rcode;
313}
314
Simon Glassed38aef2020-05-10 11:40:03 -0600315static int do_mem_cp(struct cmd_tbl *cmdtp, int flag, int argc,
316 char *const argv[])
wdenk38635852002-08-27 05:55:31 +0000317{
Fabio Estevamb03b0c82016-12-15 16:00:13 -0200318 ulong addr, dest, count;
Philippe Reynesb5f461a2019-12-02 17:33:22 +0100319 void *src, *dst;
wdenk874ac262003-07-24 23:38:38 +0000320 int size;
wdenk38635852002-08-27 05:55:31 +0000321
Wolfgang Denk3b683112010-07-17 01:06:04 +0200322 if (argc != 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000323 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000324
325 /* Check for size specification.
326 */
wdenk874ac262003-07-24 23:38:38 +0000327 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
328 return 1;
wdenk38635852002-08-27 05:55:31 +0000329
330 addr = simple_strtoul(argv[1], NULL, 16);
331 addr += base_address;
332
333 dest = simple_strtoul(argv[2], NULL, 16);
334 dest += base_address;
335
336 count = simple_strtoul(argv[3], NULL, 16);
337
338 if (count == 0) {
339 puts ("Zero length ???\n");
340 return 1;
341 }
342
Philippe Reynesb5f461a2019-12-02 17:33:22 +0100343 src = map_sysmem(addr, count * size);
344 dst = map_sysmem(dest, count * size);
345
Masahiro Yamada8cea9b52017-02-11 22:43:54 +0900346#ifdef CONFIG_MTD_NOR_FLASH
wdenk38635852002-08-27 05:55:31 +0000347 /* check if we are copying to Flash */
Philippe Reynesb5f461a2019-12-02 17:33:22 +0100348 if (addr2info((ulong)dst)) {
wdenk38635852002-08-27 05:55:31 +0000349 int rc;
350
wdenk42c05472004-03-23 22:14:11 +0000351 puts ("Copy to Flash... ");
wdenk38635852002-08-27 05:55:31 +0000352
Philippe Reynesb5f461a2019-12-02 17:33:22 +0100353 rc = flash_write((char *)src, (ulong)dst, count * size);
wdenk38635852002-08-27 05:55:31 +0000354 if (rc != 0) {
Simon Glassa606ffc2019-12-28 10:44:40 -0700355 flash_perror(rc);
Philippe Reynesb5f461a2019-12-02 17:33:22 +0100356 unmap_sysmem(src);
357 unmap_sysmem(dst);
wdenk38635852002-08-27 05:55:31 +0000358 return (1);
359 }
360 puts ("done\n");
Philippe Reynesb5f461a2019-12-02 17:33:22 +0100361 unmap_sysmem(src);
362 unmap_sysmem(dst);
wdenk38635852002-08-27 05:55:31 +0000363 return 0;
364 }
wdenk7a428cc2003-06-15 22:40:42 +0000365#endif
366
Philippe Reynesb5f461a2019-12-02 17:33:22 +0100367 memcpy(dst, src, count * size);
Masahiro Yamada787b0c52014-10-23 17:46:24 +0900368
Philippe Reynesb5f461a2019-12-02 17:33:22 +0100369 unmap_sysmem(src);
370 unmap_sysmem(dst);
wdenk38635852002-08-27 05:55:31 +0000371 return 0;
372}
373
Simon Glassed38aef2020-05-10 11:40:03 -0600374static int do_mem_base(struct cmd_tbl *cmdtp, int flag, int argc,
375 char *const argv[])
wdenk38635852002-08-27 05:55:31 +0000376{
377 if (argc > 1) {
378 /* Set new base address.
379 */
380 base_address = simple_strtoul(argv[1], NULL, 16);
381 }
382 /* Print the current base address.
383 */
384 printf("Base Address: 0x%08lx\n", base_address);
385 return 0;
386}
387
Simon Glassed38aef2020-05-10 11:40:03 -0600388static int do_mem_loop(struct cmd_tbl *cmdtp, int flag, int argc,
389 char *const argv[])
wdenk38635852002-08-27 05:55:31 +0000390{
Simon Glasse6d0ca22013-02-24 17:33:15 +0000391 ulong addr, length, i, bytes;
wdenk874ac262003-07-24 23:38:38 +0000392 int size;
Simon Glass8927bf22019-12-28 10:45:10 -0700393#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800394 volatile u64 *llp;
395#endif
York Sund8a405d2014-02-12 15:55:35 -0800396 volatile u32 *longp;
397 volatile u16 *shortp;
398 volatile u8 *cp;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000399 const void *buf;
wdenk38635852002-08-27 05:55:31 +0000400
Wolfgang Denk3b683112010-07-17 01:06:04 +0200401 if (argc < 3)
Simon Glassa06dfc72011-12-10 08:44:01 +0000402 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000403
Robert P. J. Day21c9b782013-02-03 02:29:54 +0000404 /*
405 * Check for a size specification.
wdenk38635852002-08-27 05:55:31 +0000406 * Defaults to long if no or incorrect specification.
407 */
wdenk874ac262003-07-24 23:38:38 +0000408 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
409 return 1;
wdenk38635852002-08-27 05:55:31 +0000410
411 /* Address is always specified.
412 */
413 addr = simple_strtoul(argv[1], NULL, 16);
414
415 /* Length is the number of objects, not number of bytes.
416 */
417 length = simple_strtoul(argv[2], NULL, 16);
418
Simon Glasse6d0ca22013-02-24 17:33:15 +0000419 bytes = size * length;
420 buf = map_sysmem(addr, bytes);
421
wdenk38635852002-08-27 05:55:31 +0000422 /* We want to optimize the loops to run as fast as possible.
423 * If we have only one object, just run infinite loops.
424 */
425 if (length == 1) {
Simon Glass8927bf22019-12-28 10:45:10 -0700426#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800427 if (size == 8) {
428 llp = (u64 *)buf;
429 for (;;)
430 i = *llp;
431 }
432#endif
wdenk38635852002-08-27 05:55:31 +0000433 if (size == 4) {
York Sund8a405d2014-02-12 15:55:35 -0800434 longp = (u32 *)buf;
wdenk38635852002-08-27 05:55:31 +0000435 for (;;)
436 i = *longp;
437 }
438 if (size == 2) {
York Sund8a405d2014-02-12 15:55:35 -0800439 shortp = (u16 *)buf;
wdenk38635852002-08-27 05:55:31 +0000440 for (;;)
441 i = *shortp;
442 }
York Sund8a405d2014-02-12 15:55:35 -0800443 cp = (u8 *)buf;
wdenk38635852002-08-27 05:55:31 +0000444 for (;;)
445 i = *cp;
446 }
447
Simon Glass8927bf22019-12-28 10:45:10 -0700448#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800449 if (size == 8) {
450 for (;;) {
451 llp = (u64 *)buf;
452 i = length;
453 while (i-- > 0)
454 *llp++;
455 }
456 }
457#endif
wdenk38635852002-08-27 05:55:31 +0000458 if (size == 4) {
459 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800460 longp = (u32 *)buf;
wdenk38635852002-08-27 05:55:31 +0000461 i = length;
462 while (i-- > 0)
Marek Vasut7d335822011-09-26 02:26:06 +0200463 *longp++;
wdenk38635852002-08-27 05:55:31 +0000464 }
465 }
466 if (size == 2) {
467 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800468 shortp = (u16 *)buf;
wdenk38635852002-08-27 05:55:31 +0000469 i = length;
470 while (i-- > 0)
Marek Vasut7d335822011-09-26 02:26:06 +0200471 *shortp++;
wdenk38635852002-08-27 05:55:31 +0000472 }
473 }
474 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800475 cp = (u8 *)buf;
wdenk38635852002-08-27 05:55:31 +0000476 i = length;
477 while (i-- > 0)
Marek Vasut7d335822011-09-26 02:26:06 +0200478 *cp++;
wdenk38635852002-08-27 05:55:31 +0000479 }
Simon Glasse6d0ca22013-02-24 17:33:15 +0000480 unmap_sysmem(buf);
Simon Glass50d9eb92013-06-11 11:14:35 -0700481
482 return 0;
wdenk38635852002-08-27 05:55:31 +0000483}
484
wdenk64519362004-07-11 17:40:54 +0000485#ifdef CONFIG_LOOPW
Simon Glassed38aef2020-05-10 11:40:03 -0600486static int do_mem_loopw(struct cmd_tbl *cmdtp, int flag, int argc,
487 char *const argv[])
wdenk64519362004-07-11 17:40:54 +0000488{
York Sun6c480012014-02-26 17:03:19 -0800489 ulong addr, length, i, bytes;
wdenk64519362004-07-11 17:40:54 +0000490 int size;
Simon Glass8927bf22019-12-28 10:45:10 -0700491#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800492 volatile u64 *llp;
493 u64 data;
494#else
495 ulong data;
496#endif
York Sund8a405d2014-02-12 15:55:35 -0800497 volatile u32 *longp;
498 volatile u16 *shortp;
499 volatile u8 *cp;
Simon Glasse6d0ca22013-02-24 17:33:15 +0000500 void *buf;
wdenk7dd13292004-07-11 20:04:51 +0000501
Wolfgang Denk3b683112010-07-17 01:06:04 +0200502 if (argc < 4)
Simon Glassa06dfc72011-12-10 08:44:01 +0000503 return CMD_RET_USAGE;
wdenk64519362004-07-11 17:40:54 +0000504
Robert P. J. Day21c9b782013-02-03 02:29:54 +0000505 /*
506 * Check for a size specification.
wdenk64519362004-07-11 17:40:54 +0000507 * Defaults to long if no or incorrect specification.
508 */
509 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
510 return 1;
511
512 /* Address is always specified.
513 */
514 addr = simple_strtoul(argv[1], NULL, 16);
515
516 /* Length is the number of objects, not number of bytes.
517 */
518 length = simple_strtoul(argv[2], NULL, 16);
519
520 /* data to write */
Simon Glass8927bf22019-12-28 10:45:10 -0700521#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800522 data = simple_strtoull(argv[3], NULL, 16);
523#else
wdenk64519362004-07-11 17:40:54 +0000524 data = simple_strtoul(argv[3], NULL, 16);
York Sun6c480012014-02-26 17:03:19 -0800525#endif
wdenk7dd13292004-07-11 20:04:51 +0000526
Simon Glasse6d0ca22013-02-24 17:33:15 +0000527 bytes = size * length;
528 buf = map_sysmem(addr, bytes);
529
wdenk64519362004-07-11 17:40:54 +0000530 /* We want to optimize the loops to run as fast as possible.
531 * If we have only one object, just run infinite loops.
532 */
533 if (length == 1) {
Simon Glass8927bf22019-12-28 10:45:10 -0700534#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800535 if (size == 8) {
536 llp = (u64 *)buf;
537 for (;;)
538 *llp = data;
539 }
540#endif
wdenk64519362004-07-11 17:40:54 +0000541 if (size == 4) {
York Sund8a405d2014-02-12 15:55:35 -0800542 longp = (u32 *)buf;
wdenk64519362004-07-11 17:40:54 +0000543 for (;;)
544 *longp = data;
York Sun6c480012014-02-26 17:03:19 -0800545 }
wdenk64519362004-07-11 17:40:54 +0000546 if (size == 2) {
York Sund8a405d2014-02-12 15:55:35 -0800547 shortp = (u16 *)buf;
wdenk64519362004-07-11 17:40:54 +0000548 for (;;)
549 *shortp = data;
550 }
York Sund8a405d2014-02-12 15:55:35 -0800551 cp = (u8 *)buf;
wdenk64519362004-07-11 17:40:54 +0000552 for (;;)
553 *cp = data;
554 }
555
Simon Glass8927bf22019-12-28 10:45:10 -0700556#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -0800557 if (size == 8) {
558 for (;;) {
559 llp = (u64 *)buf;
560 i = length;
561 while (i-- > 0)
562 *llp++ = data;
563 }
564 }
565#endif
wdenk64519362004-07-11 17:40:54 +0000566 if (size == 4) {
567 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800568 longp = (u32 *)buf;
wdenk64519362004-07-11 17:40:54 +0000569 i = length;
570 while (i-- > 0)
571 *longp++ = data;
572 }
573 }
574 if (size == 2) {
575 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800576 shortp = (u16 *)buf;
wdenk64519362004-07-11 17:40:54 +0000577 i = length;
578 while (i-- > 0)
579 *shortp++ = data;
580 }
581 }
582 for (;;) {
York Sund8a405d2014-02-12 15:55:35 -0800583 cp = (u8 *)buf;
wdenk64519362004-07-11 17:40:54 +0000584 i = length;
585 while (i-- > 0)
586 *cp++ = data;
587 }
588}
589#endif /* CONFIG_LOOPW */
590
Tom Rinia5f02702013-03-12 10:07:19 -0400591#ifdef CONFIG_CMD_MEMTEST
Simon Glassad02a012013-02-28 17:47:14 +0000592static ulong mem_test_alt(vu_long *buf, ulong start_addr, ulong end_addr,
593 vu_long *dummy)
wdenk38635852002-08-27 05:55:31 +0000594{
Simon Glass8f2c7582013-02-24 17:33:16 +0000595 vu_long *addr;
Simon Glass8f2c7582013-02-24 17:33:16 +0000596 ulong errs = 0;
597 ulong val, readback;
598 int j;
Simon Glass8f2c7582013-02-24 17:33:16 +0000599 vu_long offset;
600 vu_long test_offset;
601 vu_long pattern;
602 vu_long temp;
603 vu_long anti_pattern;
604 vu_long num_words;
wdenk38635852002-08-27 05:55:31 +0000605 static const ulong bitpattern[] = {
606 0x00000001, /* single bit */
607 0x00000003, /* two adjacent bits */
608 0x00000007, /* three adjacent bits */
609 0x0000000F, /* four adjacent bits */
610 0x00000005, /* two non-adjacent bits */
611 0x00000015, /* three non-adjacent bits */
612 0x00000055, /* four non-adjacent bits */
613 0xaaaaaaaa, /* alternating 1/0 */
614 };
wdenk38635852002-08-27 05:55:31 +0000615
Simon Glassad02a012013-02-28 17:47:14 +0000616 num_words = (end_addr - start_addr) / sizeof(vu_long);
Simon Glass51075252013-02-24 17:33:20 +0000617
Simon Glass130103e2013-02-24 17:33:18 +0000618 /*
619 * Data line test: write a pattern to the first
620 * location, write the 1's complement to a 'parking'
621 * address (changes the state of the data bus so a
622 * floating bus doesn't give a false OK), and then
623 * read the value back. Note that we read it back
624 * into a variable because the next time we read it,
625 * it might be right (been there, tough to explain to
626 * the quality guys why it prints a failure when the
627 * "is" and "should be" are obviously the same in the
628 * error message).
629 *
630 * Rather than exhaustively testing, we test some
631 * patterns by shifting '1' bits through a field of
632 * '0's and '0' bits through a field of '1's (i.e.
633 * pattern and ~pattern).
634 */
Simon Glassad02a012013-02-28 17:47:14 +0000635 addr = buf;
Simon Glass130103e2013-02-24 17:33:18 +0000636 for (j = 0; j < sizeof(bitpattern) / sizeof(bitpattern[0]); j++) {
637 val = bitpattern[j];
638 for (; val != 0; val <<= 1) {
Simon Glassad02a012013-02-28 17:47:14 +0000639 *addr = val;
Simon Glass8f2c7582013-02-24 17:33:16 +0000640 *dummy = ~val; /* clear the test data off the bus */
wdenk38635852002-08-27 05:55:31 +0000641 readback = *addr;
Simon Glass130103e2013-02-24 17:33:18 +0000642 if (readback != val) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000643 printf("FAILURE (data line): "
644 "expected %08lx, actual %08lx\n",
645 val, readback);
646 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000647 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000648 return -1;
wdenk38635852002-08-27 05:55:31 +0000649 }
650 *addr = ~val;
651 *dummy = val;
652 readback = *addr;
Simon Glass8f2c7582013-02-24 17:33:16 +0000653 if (readback != ~val) {
654 printf("FAILURE (data line): "
655 "Is %08lx, should be %08lx\n",
656 readback, ~val);
657 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000658 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000659 return -1;
wdenk38635852002-08-27 05:55:31 +0000660 }
wdenk38635852002-08-27 05:55:31 +0000661 }
Simon Glass130103e2013-02-24 17:33:18 +0000662 }
wdenk38635852002-08-27 05:55:31 +0000663
Simon Glass130103e2013-02-24 17:33:18 +0000664 /*
665 * Based on code whose Original Author and Copyright
666 * information follows: Copyright (c) 1998 by Michael
667 * Barr. This software is placed into the public
668 * domain and may be used for any purpose. However,
669 * this notice must not be changed or removed and no
670 * warranty is either expressed or implied by its
671 * publication or distribution.
672 */
wdenk38635852002-08-27 05:55:31 +0000673
Simon Glass130103e2013-02-24 17:33:18 +0000674 /*
675 * Address line test
wdenk38635852002-08-27 05:55:31 +0000676
Simon Glass130103e2013-02-24 17:33:18 +0000677 * Description: Test the address bus wiring in a
678 * memory region by performing a walking
679 * 1's test on the relevant bits of the
680 * address and checking for aliasing.
681 * This test will find single-bit
682 * address failures such as stuck-high,
683 * stuck-low, and shorted pins. The base
684 * address and size of the region are
685 * selected by the caller.
wdenk38635852002-08-27 05:55:31 +0000686
Simon Glass130103e2013-02-24 17:33:18 +0000687 * Notes: For best results, the selected base
688 * address should have enough LSB 0's to
689 * guarantee single address bit changes.
690 * For example, to test a 64-Kbyte
691 * region, select a base address on a
692 * 64-Kbyte boundary. Also, select the
693 * region size as a power-of-two if at
694 * all possible.
695 *
696 * Returns: 0 if the test succeeds, 1 if the test fails.
697 */
Simon Glass130103e2013-02-24 17:33:18 +0000698 pattern = (vu_long) 0xaaaaaaaa;
699 anti_pattern = (vu_long) 0x55555555;
wdenk38635852002-08-27 05:55:31 +0000700
Simon Glassad02a012013-02-28 17:47:14 +0000701 debug("%s:%d: length = 0x%.8lx\n", __func__, __LINE__, num_words);
Simon Glass130103e2013-02-24 17:33:18 +0000702 /*
703 * Write the default pattern at each of the
704 * power-of-two offsets.
705 */
Simon Glassad02a012013-02-28 17:47:14 +0000706 for (offset = 1; offset < num_words; offset <<= 1)
707 addr[offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000708
709 /*
710 * Check for address bits stuck high.
711 */
712 test_offset = 0;
Simon Glassad02a012013-02-28 17:47:14 +0000713 addr[test_offset] = anti_pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000714
Simon Glassad02a012013-02-28 17:47:14 +0000715 for (offset = 1; offset < num_words; offset <<= 1) {
716 temp = addr[offset];
Simon Glass130103e2013-02-24 17:33:18 +0000717 if (temp != pattern) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000718 printf("\nFAILURE: Address bit stuck high @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000719 " expected 0x%.8lx, actual 0x%.8lx\n",
David Fengf40b2212014-02-12 16:10:08 +0800720 start_addr + offset*sizeof(vu_long),
721 pattern, temp);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400722 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000723 if (ctrlc())
Simon Glass130103e2013-02-24 17:33:18 +0000724 return -1;
wdenk38635852002-08-27 05:55:31 +0000725 }
Simon Glass130103e2013-02-24 17:33:18 +0000726 }
Simon Glassad02a012013-02-28 17:47:14 +0000727 addr[test_offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000728 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000729
Simon Glass130103e2013-02-24 17:33:18 +0000730 /*
731 * Check for addr bits stuck low or shorted.
732 */
Simon Glassad02a012013-02-28 17:47:14 +0000733 for (test_offset = 1; test_offset < num_words; test_offset <<= 1) {
734 addr[test_offset] = anti_pattern;
wdenk38635852002-08-27 05:55:31 +0000735
Simon Glassad02a012013-02-28 17:47:14 +0000736 for (offset = 1; offset < num_words; offset <<= 1) {
737 temp = addr[offset];
wdenk38635852002-08-27 05:55:31 +0000738 if ((temp != pattern) && (offset != test_offset)) {
Simon Glass130103e2013-02-24 17:33:18 +0000739 printf("\nFAILURE: Address bit stuck low or"
740 " shorted @ 0x%.8lx: expected 0x%.8lx,"
741 " actual 0x%.8lx\n",
David Fengf40b2212014-02-12 16:10:08 +0800742 start_addr + offset*sizeof(vu_long),
743 pattern, temp);
Simon Glass130103e2013-02-24 17:33:18 +0000744 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000745 if (ctrlc())
Simon Glass130103e2013-02-24 17:33:18 +0000746 return -1;
wdenk38635852002-08-27 05:55:31 +0000747 }
wdenk38635852002-08-27 05:55:31 +0000748 }
Simon Glassad02a012013-02-28 17:47:14 +0000749 addr[test_offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000750 }
wdenk38635852002-08-27 05:55:31 +0000751
Simon Glass130103e2013-02-24 17:33:18 +0000752 /*
753 * Description: Test the integrity of a physical
754 * memory device by performing an
755 * increment/decrement test over the
756 * entire region. In the process every
757 * storage bit in the device is tested
758 * as a zero and a one. The base address
759 * and the size of the region are
760 * selected by the caller.
761 *
762 * Returns: 0 if the test succeeds, 1 if the test fails.
763 */
Simon Glassad02a012013-02-28 17:47:14 +0000764 num_words++;
wdenk38635852002-08-27 05:55:31 +0000765
Simon Glass130103e2013-02-24 17:33:18 +0000766 /*
767 * Fill memory with a known pattern.
768 */
769 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
770 WATCHDOG_RESET();
Simon Glassad02a012013-02-28 17:47:14 +0000771 addr[offset] = pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000772 }
wdenk38635852002-08-27 05:55:31 +0000773
Simon Glass130103e2013-02-24 17:33:18 +0000774 /*
775 * Check each location and invert it for the second pass.
776 */
777 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
778 WATCHDOG_RESET();
Simon Glassad02a012013-02-28 17:47:14 +0000779 temp = addr[offset];
Simon Glass130103e2013-02-24 17:33:18 +0000780 if (temp != pattern) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000781 printf("\nFAILURE (read/write) @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000782 " expected 0x%.8lx, actual 0x%.8lx)\n",
David Fengf40b2212014-02-12 16:10:08 +0800783 start_addr + offset*sizeof(vu_long),
784 pattern, temp);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400785 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000786 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000787 return -1;
wdenk38635852002-08-27 05:55:31 +0000788 }
789
Simon Glass130103e2013-02-24 17:33:18 +0000790 anti_pattern = ~pattern;
Simon Glassad02a012013-02-28 17:47:14 +0000791 addr[offset] = anti_pattern;
Simon Glass130103e2013-02-24 17:33:18 +0000792 }
793
794 /*
795 * Check each location for the inverted pattern and zero it.
796 */
797 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
798 WATCHDOG_RESET();
799 anti_pattern = ~pattern;
Simon Glassad02a012013-02-28 17:47:14 +0000800 temp = addr[offset];
Simon Glass130103e2013-02-24 17:33:18 +0000801 if (temp != anti_pattern) {
Simon Glass8f2c7582013-02-24 17:33:16 +0000802 printf("\nFAILURE (read/write): @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000803 " expected 0x%.8lx, actual 0x%.8lx)\n",
David Fengf40b2212014-02-12 16:10:08 +0800804 start_addr + offset*sizeof(vu_long),
805 anti_pattern, temp);
Paul Gortmakercb47b4f2009-10-02 18:18:33 -0400806 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000807 if (ctrlc())
Simon Glass57ee4432013-02-24 17:33:17 +0000808 return -1;
wdenk38635852002-08-27 05:55:31 +0000809 }
Simon Glassad02a012013-02-28 17:47:14 +0000810 addr[offset] = 0;
Simon Glass130103e2013-02-24 17:33:18 +0000811 }
Simon Glass57ee4432013-02-24 17:33:17 +0000812
Rasmus Villemoesabd06c92016-01-07 11:36:04 +0100813 return errs;
Simon Glass8f2c7582013-02-24 17:33:16 +0000814}
815
Stefan Roesefbfd5a12020-03-05 07:21:32 +0100816static int compare_regions(volatile unsigned long *bufa,
817 volatile unsigned long *bufb, size_t count)
818{
819 volatile unsigned long *p1 = bufa;
820 volatile unsigned long *p2 = bufb;
821 int errs = 0;
822 size_t i;
823
824 for (i = 0; i < count; i++, p1++, p2++) {
825 if (*p1 != *p2) {
826 printf("FAILURE: 0x%08lx != 0x%08lx (delta=0x%08lx -> bit %ld) at offset 0x%08lx\n",
827 (unsigned long)*p1, (unsigned long)*p2,
828 *p1 ^ *p2, __ffs(*p1 ^ *p2),
829 (unsigned long)(i * sizeof(unsigned long)));
830 errs++;
831 }
832 }
833
834 return errs;
835}
836
837static ulong test_bitflip_comparison(volatile unsigned long *bufa,
838 volatile unsigned long *bufb, size_t count)
839{
840 volatile unsigned long *p1 = bufa;
841 volatile unsigned long *p2 = bufb;
842 unsigned int j, k;
843 unsigned long q;
844 size_t i;
845 int max;
846 int errs = 0;
847
848 max = sizeof(unsigned long) * 8;
849 for (k = 0; k < max; k++) {
850 q = 0x00000001L << k;
851 for (j = 0; j < 8; j++) {
852 WATCHDOG_RESET();
853 q = ~q;
854 p1 = (volatile unsigned long *)bufa;
855 p2 = (volatile unsigned long *)bufb;
856 for (i = 0; i < count; i++)
857 *p1++ = *p2++ = (i % 2) == 0 ? q : ~q;
858
859 errs += compare_regions(bufa, bufb, count);
860 }
861
862 if (ctrlc())
863 return -1UL;
864 }
865
866 return errs;
867}
868
Simon Glassad02a012013-02-28 17:47:14 +0000869static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr,
870 vu_long pattern, int iteration)
Simon Glass8f2c7582013-02-24 17:33:16 +0000871{
Simon Glassad02a012013-02-28 17:47:14 +0000872 vu_long *end;
Simon Glass8f2c7582013-02-24 17:33:16 +0000873 vu_long *addr;
Simon Glass8f2c7582013-02-24 17:33:16 +0000874 ulong errs = 0;
Simon Glassad02a012013-02-28 17:47:14 +0000875 ulong incr, length;
Simon Glass8f2c7582013-02-24 17:33:16 +0000876 ulong val, readback;
wdenk38635852002-08-27 05:55:31 +0000877
Simon Glass57ee4432013-02-24 17:33:17 +0000878 /* Alternate the pattern */
wdenk38635852002-08-27 05:55:31 +0000879 incr = 1;
Simon Glass57ee4432013-02-24 17:33:17 +0000880 if (iteration & 1) {
881 incr = -incr;
882 /*
883 * Flip the pattern each time to make lots of zeros and
884 * then, the next time, lots of ones. We decrement
885 * the "negative" patterns and increment the "positive"
886 * patterns to preserve this feature.
887 */
888 if (pattern & 0x80000000)
889 pattern = -pattern; /* complement & increment */
890 else
891 pattern = ~pattern;
892 }
Simon Glassad02a012013-02-28 17:47:14 +0000893 length = (end_addr - start_addr) / sizeof(ulong);
894 end = buf + length;
Simon Glass130103e2013-02-24 17:33:18 +0000895 printf("\rPattern %08lX Writing..."
896 "%12s"
897 "\b\b\b\b\b\b\b\b\b\b",
898 pattern, "");
wdenk38635852002-08-27 05:55:31 +0000899
Simon Glassad02a012013-02-28 17:47:14 +0000900 for (addr = buf, val = pattern; addr < end; addr++) {
Simon Glass130103e2013-02-24 17:33:18 +0000901 WATCHDOG_RESET();
902 *addr = val;
903 val += incr;
904 }
wdenk38635852002-08-27 05:55:31 +0000905
Simon Glass130103e2013-02-24 17:33:18 +0000906 puts("Reading...");
wdenk38635852002-08-27 05:55:31 +0000907
Simon Glassad02a012013-02-28 17:47:14 +0000908 for (addr = buf, val = pattern; addr < end; addr++) {
Simon Glass130103e2013-02-24 17:33:18 +0000909 WATCHDOG_RESET();
910 readback = *addr;
911 if (readback != val) {
Simon Glassad02a012013-02-28 17:47:14 +0000912 ulong offset = addr - buf;
913
Simon Glass130103e2013-02-24 17:33:18 +0000914 printf("\nMem error @ 0x%08X: "
915 "found %08lX, expected %08lX\n",
David Fengf40b2212014-02-12 16:10:08 +0800916 (uint)(uintptr_t)(start_addr + offset*sizeof(vu_long)),
Simon Glassad02a012013-02-28 17:47:14 +0000917 readback, val);
Simon Glass130103e2013-02-24 17:33:18 +0000918 errs++;
Simon Glasseb4598b2013-02-24 17:33:19 +0000919 if (ctrlc())
Simon Glass130103e2013-02-24 17:33:18 +0000920 return -1;
wdenk38635852002-08-27 05:55:31 +0000921 }
Simon Glass130103e2013-02-24 17:33:18 +0000922 val += incr;
923 }
wdenk38635852002-08-27 05:55:31 +0000924
Rasmus Villemoesabd06c92016-01-07 11:36:04 +0100925 return errs;
Simon Glass8f2c7582013-02-24 17:33:16 +0000926}
927
928/*
929 * Perform a memory test. A more complete alternative test can be
930 * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until
931 * interrupted by ctrl-c or by a failure of one of the sub-tests.
932 */
Simon Glassed38aef2020-05-10 11:40:03 -0600933static int do_mem_mtest(struct cmd_tbl *cmdtp, int flag, int argc,
934 char *const argv[])
Simon Glass8f2c7582013-02-24 17:33:16 +0000935{
Simon Glass51075252013-02-24 17:33:20 +0000936 ulong start, end;
Michal Simek9eaf6442020-05-04 13:54:40 +0200937 vu_long scratch_space;
938 vu_long *buf, *dummy = &scratch_space;
Tom Rinib9180882015-04-07 09:38:54 -0400939 ulong iteration_limit = 0;
Stefan Roese32265fc2020-03-05 07:21:29 +0100940 ulong count = 0;
Simon Glass57ee4432013-02-24 17:33:17 +0000941 ulong errs = 0; /* number of errors, or -1 if interrupted */
Pavel Machekd319f592015-04-01 13:50:41 +0200942 ulong pattern = 0;
Simon Glass57ee4432013-02-24 17:33:17 +0000943 int iteration;
Simon Glass8f2c7582013-02-24 17:33:16 +0000944
Pavel Machekd319f592015-04-01 13:50:41 +0200945 start = CONFIG_SYS_MEMTEST_START;
946 end = CONFIG_SYS_MEMTEST_END;
947
Simon Glass8f2c7582013-02-24 17:33:16 +0000948 if (argc > 1)
Pavel Machekd319f592015-04-01 13:50:41 +0200949 if (strict_strtoul(argv[1], 16, &start) < 0)
950 return CMD_RET_USAGE;
Simon Glass8f2c7582013-02-24 17:33:16 +0000951
952 if (argc > 2)
Pavel Machekd319f592015-04-01 13:50:41 +0200953 if (strict_strtoul(argv[2], 16, &end) < 0)
954 return CMD_RET_USAGE;
Simon Glass8f2c7582013-02-24 17:33:16 +0000955
956 if (argc > 3)
Pavel Machekd319f592015-04-01 13:50:41 +0200957 if (strict_strtoul(argv[3], 16, &pattern) < 0)
958 return CMD_RET_USAGE;
Simon Glass8f2c7582013-02-24 17:33:16 +0000959
960 if (argc > 4)
Pavel Machekd319f592015-04-01 13:50:41 +0200961 if (strict_strtoul(argv[4], 16, &iteration_limit) < 0)
962 return CMD_RET_USAGE;
963
964 if (end < start) {
965 printf("Refusing to do empty test\n");
966 return -1;
967 }
Simon Glass8f2c7582013-02-24 17:33:16 +0000968
Michal Simek45f8e332016-02-24 08:36:02 +0100969 printf("Testing %08lx ... %08lx:\n", start, end);
Simon Glass51075252013-02-24 17:33:20 +0000970 debug("%s:%d: start %#08lx end %#08lx\n", __func__, __LINE__,
971 start, end);
Simon Glass57ee4432013-02-24 17:33:17 +0000972
Simon Glassad02a012013-02-28 17:47:14 +0000973 buf = map_sysmem(start, end - start);
Simon Glass57ee4432013-02-24 17:33:17 +0000974 for (iteration = 0;
975 !iteration_limit || iteration < iteration_limit;
976 iteration++) {
977 if (ctrlc()) {
Simon Glass57ee4432013-02-24 17:33:17 +0000978 errs = -1UL;
979 break;
980 }
981
982 printf("Iteration: %6d\r", iteration + 1);
983 debug("\n");
Stefan Roese1eb8b1e2020-03-05 07:21:31 +0100984 if (IS_ENABLED(CONFIG_SYS_ALT_MEMTEST)) {
Simon Glassad02a012013-02-28 17:47:14 +0000985 errs = mem_test_alt(buf, start, end, dummy);
Stefan Roesefbfd5a12020-03-05 07:21:32 +0100986 if (errs == -1UL)
987 break;
988 count += errs;
989 errs = test_bitflip_comparison(buf,
990 buf + (end - start) / 2,
991 (end - start) /
992 sizeof(unsigned long));
Simon Glassad02a012013-02-28 17:47:14 +0000993 } else {
994 errs = mem_test_quick(buf, start, end, pattern,
995 iteration);
996 }
997 if (errs == -1UL)
998 break;
Stefan Roese32265fc2020-03-05 07:21:29 +0100999 count += errs;
Simon Glassad02a012013-02-28 17:47:14 +00001000 }
1001
Stefan Roesec1d47db2020-03-05 07:21:30 +01001002 unmap_sysmem((void *)buf);
Simon Glass57ee4432013-02-24 17:33:17 +00001003
1004 if (errs == -1UL) {
Simon Glasseb4598b2013-02-24 17:33:19 +00001005 /* Memory test was aborted - write a newline to finish off */
1006 putc('\n');
Simon Glass57ee4432013-02-24 17:33:17 +00001007 }
Stefan Roese32265fc2020-03-05 07:21:29 +01001008 printf("Tested %d iteration(s) with %lu errors.\n", iteration, count);
Simon Glass8f2c7582013-02-24 17:33:16 +00001009
Stefan Roese32265fc2020-03-05 07:21:29 +01001010 return errs != 0;
wdenk38635852002-08-27 05:55:31 +00001011}
Wolfgang Denk9d009282013-03-08 10:51:32 +00001012#endif /* CONFIG_CMD_MEMTEST */
wdenk38635852002-08-27 05:55:31 +00001013
1014/* Modify memory.
1015 *
1016 * Syntax:
York Sun6c480012014-02-26 17:03:19 -08001017 * mm{.b, .w, .l, .q} {addr}
1018 * nm{.b, .w, .l, .q} {addr}
wdenk38635852002-08-27 05:55:31 +00001019 */
1020static int
Simon Glassed38aef2020-05-10 11:40:03 -06001021mod_mem(struct cmd_tbl *cmdtp, int incrflag, int flag, int argc,
1022 char *const argv[])
wdenk38635852002-08-27 05:55:31 +00001023{
York Sun6c480012014-02-26 17:03:19 -08001024 ulong addr;
Simon Glass8927bf22019-12-28 10:45:10 -07001025#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001026 u64 i;
1027#else
1028 ulong i;
1029#endif
wdenk874ac262003-07-24 23:38:38 +00001030 int nbytes, size;
Simon Glasse6d0ca22013-02-24 17:33:15 +00001031 void *ptr = NULL;
wdenk38635852002-08-27 05:55:31 +00001032
Wolfgang Denk3b683112010-07-17 01:06:04 +02001033 if (argc != 2)
Simon Glassa06dfc72011-12-10 08:44:01 +00001034 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +00001035
Simon Glass09007c42014-04-10 20:01:31 -06001036 bootretry_reset_cmd_timeout(); /* got a good command to get here */
wdenk38635852002-08-27 05:55:31 +00001037 /* We use the last specified parameters, unless new ones are
1038 * entered.
1039 */
1040 addr = mm_last_addr;
1041 size = mm_last_size;
1042
1043 if ((flag & CMD_FLAG_REPEAT) == 0) {
1044 /* New command specified. Check for a size specification.
1045 * Defaults to long if no or incorrect specification.
1046 */
wdenk874ac262003-07-24 23:38:38 +00001047 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
1048 return 1;
wdenk38635852002-08-27 05:55:31 +00001049
1050 /* Address is specified since argc > 1
1051 */
1052 addr = simple_strtoul(argv[1], NULL, 16);
1053 addr += base_address;
1054 }
wdenk381669a2003-06-16 23:50:08 +00001055
wdenk38635852002-08-27 05:55:31 +00001056 /* Print the address, followed by value. Then accept input for
1057 * the next value. A non-converted value exits.
1058 */
1059 do {
Simon Glasse6d0ca22013-02-24 17:33:15 +00001060 ptr = map_sysmem(addr, size);
wdenk38635852002-08-27 05:55:31 +00001061 printf("%08lx:", addr);
1062 if (size == 4)
York Sund8a405d2014-02-12 15:55:35 -08001063 printf(" %08x", *((u32 *)ptr));
Simon Glass8927bf22019-12-28 10:45:10 -07001064#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001065 else if (size == 8)
Masahiro Yamadac7570a32018-08-06 20:47:40 +09001066 printf(" %016llx", *((u64 *)ptr));
York Sun6c480012014-02-26 17:03:19 -08001067#endif
wdenk38635852002-08-27 05:55:31 +00001068 else if (size == 2)
York Sund8a405d2014-02-12 15:55:35 -08001069 printf(" %04x", *((u16 *)ptr));
wdenk38635852002-08-27 05:55:31 +00001070 else
York Sund8a405d2014-02-12 15:55:35 -08001071 printf(" %02x", *((u8 *)ptr));
wdenk38635852002-08-27 05:55:31 +00001072
Simon Glassbe6aafc2014-04-10 20:01:27 -06001073 nbytes = cli_readline(" ? ");
wdenk38635852002-08-27 05:55:31 +00001074 if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
1075 /* <CR> pressed as only input, don't modify current
1076 * location and move to next. "-" pressed will go back.
1077 */
1078 if (incrflag)
1079 addr += nbytes ? -size : size;
1080 nbytes = 1;
Simon Glass09007c42014-04-10 20:01:31 -06001081 /* good enough to not time out */
1082 bootretry_reset_cmd_timeout();
wdenk38635852002-08-27 05:55:31 +00001083 }
1084#ifdef CONFIG_BOOT_RETRY_TIME
1085 else if (nbytes == -2) {
1086 break; /* timed out, exit the command */
1087 }
1088#endif
1089 else {
1090 char *endp;
Simon Glass8927bf22019-12-28 10:45:10 -07001091#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001092 i = simple_strtoull(console_buffer, &endp, 16);
1093#else
wdenk38635852002-08-27 05:55:31 +00001094 i = simple_strtoul(console_buffer, &endp, 16);
York Sun6c480012014-02-26 17:03:19 -08001095#endif
wdenk38635852002-08-27 05:55:31 +00001096 nbytes = endp - console_buffer;
1097 if (nbytes) {
wdenk38635852002-08-27 05:55:31 +00001098 /* good enough to not time out
1099 */
Simon Glass09007c42014-04-10 20:01:31 -06001100 bootretry_reset_cmd_timeout();
wdenk38635852002-08-27 05:55:31 +00001101 if (size == 4)
York Sund8a405d2014-02-12 15:55:35 -08001102 *((u32 *)ptr) = i;
Simon Glass8927bf22019-12-28 10:45:10 -07001103#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001104 else if (size == 8)
1105 *((u64 *)ptr) = i;
1106#endif
wdenk38635852002-08-27 05:55:31 +00001107 else if (size == 2)
York Sund8a405d2014-02-12 15:55:35 -08001108 *((u16 *)ptr) = i;
wdenk38635852002-08-27 05:55:31 +00001109 else
York Sund8a405d2014-02-12 15:55:35 -08001110 *((u8 *)ptr) = i;
wdenk38635852002-08-27 05:55:31 +00001111 if (incrflag)
1112 addr += size;
1113 }
1114 }
1115 } while (nbytes);
Simon Glasse6d0ca22013-02-24 17:33:15 +00001116 if (ptr)
1117 unmap_sysmem(ptr);
wdenk38635852002-08-27 05:55:31 +00001118
1119 mm_last_addr = addr;
1120 mm_last_size = size;
1121 return 0;
1122}
1123
Mike Frysinger321ab9e2010-12-21 14:19:51 -05001124#ifdef CONFIG_CMD_CRC32
1125
Simon Glassed38aef2020-05-10 11:40:03 -06001126static int do_mem_crc(struct cmd_tbl *cmdtp, int flag, int argc,
1127 char *const argv[])
wdenk38635852002-08-27 05:55:31 +00001128{
Simon Glass0bbd76f2013-02-24 20:30:22 +00001129 int flags = 0;
wdenk6203e402004-04-18 10:13:26 +00001130 int ac;
Wolfgang Denk6262d0212010-06-28 22:00:46 +02001131 char * const *av;
wdenk6203e402004-04-18 10:13:26 +00001132
Simon Glass0bbd76f2013-02-24 20:30:22 +00001133 if (argc < 3)
Simon Glassa06dfc72011-12-10 08:44:01 +00001134 return CMD_RET_USAGE;
wdenk6203e402004-04-18 10:13:26 +00001135
1136 av = argv + 1;
1137 ac = argc - 1;
Daniel Thompsona9e2c672017-05-19 17:26:58 +01001138#ifdef CONFIG_CRC32_VERIFY
wdenk6203e402004-04-18 10:13:26 +00001139 if (strcmp(*av, "-v") == 0) {
Joe Hershberger5fcee9a2015-05-05 12:23:53 -05001140 flags |= HASH_FLAG_VERIFY | HASH_FLAG_ENV;
wdenk6203e402004-04-18 10:13:26 +00001141 av++;
1142 ac--;
wdenk6203e402004-04-18 10:13:26 +00001143 }
Simon Glass0bbd76f2013-02-24 20:30:22 +00001144#endif
wdenk6203e402004-04-18 10:13:26 +00001145
Simon Glass0bbd76f2013-02-24 20:30:22 +00001146 return hash_command("crc32", flags, cmdtp, flag, ac, av);
wdenk6203e402004-04-18 10:13:26 +00001147}
wdenk6203e402004-04-18 10:13:26 +00001148
Robin Getz93d6cb02009-07-27 00:07:59 -04001149#endif
1150
Jean-Jacques Hiblotd3f09372019-07-02 14:23:26 +02001151#ifdef CONFIG_CMD_RANDOM
Simon Glassed38aef2020-05-10 11:40:03 -06001152static int do_random(struct cmd_tbl *cmdtp, int flag, int argc,
1153 char *const argv[])
Jean-Jacques Hiblotd3f09372019-07-02 14:23:26 +02001154{
1155 unsigned long addr, len;
1156 unsigned long seed; // NOT INITIALIZED ON PURPOSE
1157 unsigned int *buf, *start;
1158 unsigned char *buf8;
1159 unsigned int i;
1160
Eugeniy Paltsev82accda2020-03-20 19:38:17 +03001161 if (argc < 3 || argc > 4)
1162 return CMD_RET_USAGE;
Jean-Jacques Hiblotd3f09372019-07-02 14:23:26 +02001163
1164 len = simple_strtoul(argv[2], NULL, 16);
1165 addr = simple_strtoul(argv[1], NULL, 16);
1166
1167 if (argc == 4) {
1168 seed = simple_strtoul(argv[3], NULL, 16);
1169 if (seed == 0) {
1170 printf("The seed cannot be 0. Using 0xDEADBEEF.\n");
1171 seed = 0xDEADBEEF;
1172 }
1173 } else {
1174 seed = get_timer(0) ^ rand();
1175 }
1176
1177 srand(seed);
1178 start = map_sysmem(addr, len);
1179 buf = start;
1180 for (i = 0; i < (len / 4); i++)
1181 *buf++ = rand();
1182
1183 buf8 = (unsigned char *)buf;
1184 for (i = 0; i < (len % 4); i++)
1185 *buf8++ = rand() & 0xFF;
1186
1187 unmap_sysmem(start);
1188 printf("%lu bytes filled with random data\n", len);
Eugeniy Paltsev82accda2020-03-20 19:38:17 +03001189
1190 return CMD_RET_SUCCESS;
Jean-Jacques Hiblotd3f09372019-07-02 14:23:26 +02001191}
1192#endif
1193
wdenk57b2d802003-06-27 21:31:46 +00001194/**************************************************/
wdenkf287a242003-07-01 21:06:45 +00001195U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001196 md, 3, 1, do_mem_md,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001197 "memory display",
Simon Glass8927bf22019-12-28 10:45:10 -07001198#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001199 "[.b, .w, .l, .q] address [# of objects]"
1200#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001201 "[.b, .w, .l] address [# of objects]"
York Sun6c480012014-02-26 17:03:19 -08001202#endif
wdenk57b2d802003-06-27 21:31:46 +00001203);
1204
1205
wdenkf287a242003-07-01 21:06:45 +00001206U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001207 mm, 2, 1, do_mem_mm,
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001208 "memory modify (auto-incrementing address)",
Simon Glass8927bf22019-12-28 10:45:10 -07001209#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001210 "[.b, .w, .l, .q] address"
1211#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001212 "[.b, .w, .l] address"
York Sun6c480012014-02-26 17:03:19 -08001213#endif
wdenk57b2d802003-06-27 21:31:46 +00001214);
1215
1216
wdenkf287a242003-07-01 21:06:45 +00001217U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001218 nm, 2, 1, do_mem_nm,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001219 "memory modify (constant address)",
Simon Glass8927bf22019-12-28 10:45:10 -07001220#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001221 "[.b, .w, .l, .q] address"
1222#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001223 "[.b, .w, .l] address"
York Sun6c480012014-02-26 17:03:19 -08001224#endif
wdenk57b2d802003-06-27 21:31:46 +00001225);
1226
wdenkf287a242003-07-01 21:06:45 +00001227U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001228 mw, 4, 1, do_mem_mw,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001229 "memory write (fill)",
Simon Glass8927bf22019-12-28 10:45:10 -07001230#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001231 "[.b, .w, .l, .q] address value [count]"
1232#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001233 "[.b, .w, .l] address value [count]"
York Sun6c480012014-02-26 17:03:19 -08001234#endif
wdenk57b2d802003-06-27 21:31:46 +00001235);
1236
wdenkf287a242003-07-01 21:06:45 +00001237U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001238 cp, 4, 1, do_mem_cp,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001239 "memory copy",
Simon Glass8927bf22019-12-28 10:45:10 -07001240#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001241 "[.b, .w, .l, .q] source target count"
1242#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001243 "[.b, .w, .l] source target count"
York Sun6c480012014-02-26 17:03:19 -08001244#endif
wdenk57b2d802003-06-27 21:31:46 +00001245);
1246
wdenkf287a242003-07-01 21:06:45 +00001247U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001248 cmp, 4, 1, do_mem_cmp,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001249 "memory compare",
Simon Glass8927bf22019-12-28 10:45:10 -07001250#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001251 "[.b, .w, .l, .q] addr1 addr2 count"
1252#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001253 "[.b, .w, .l] addr1 addr2 count"
York Sun6c480012014-02-26 17:03:19 -08001254#endif
wdenk57b2d802003-06-27 21:31:46 +00001255);
1256
Mike Frysinger321ab9e2010-12-21 14:19:51 -05001257#ifdef CONFIG_CMD_CRC32
1258
Daniel Thompsona9e2c672017-05-19 17:26:58 +01001259#ifndef CONFIG_CRC32_VERIFY
wdenk6203e402004-04-18 10:13:26 +00001260
wdenkf287a242003-07-01 21:06:45 +00001261U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001262 crc32, 4, 1, do_mem_crc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001263 "checksum calculation",
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001264 "address count [addr]\n - compute CRC32 checksum [save at addr]"
wdenk57b2d802003-06-27 21:31:46 +00001265);
1266
Daniel Thompsona9e2c672017-05-19 17:26:58 +01001267#else /* CONFIG_CRC32_VERIFY */
wdenk6203e402004-04-18 10:13:26 +00001268
1269U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001270 crc32, 5, 1, do_mem_crc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001271 "checksum calculation",
wdenk6203e402004-04-18 10:13:26 +00001272 "address count [addr]\n - compute CRC32 checksum [save at addr]\n"
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001273 "-v address count crc\n - verify crc of memory area"
wdenk6203e402004-04-18 10:13:26 +00001274);
1275
Daniel Thompsona9e2c672017-05-19 17:26:58 +01001276#endif /* CONFIG_CRC32_VERIFY */
wdenk6203e402004-04-18 10:13:26 +00001277
Mike Frysinger321ab9e2010-12-21 14:19:51 -05001278#endif
1279
Simon Glasseacd14f2012-11-30 13:01:20 +00001280#ifdef CONFIG_CMD_MEMINFO
Simon Glassed38aef2020-05-10 11:40:03 -06001281static int do_mem_info(struct cmd_tbl *cmdtp, int flag, int argc,
1282 char *const argv[])
Simon Glasseacd14f2012-11-30 13:01:20 +00001283{
Simon Glass320a5d42019-11-14 12:57:44 -07001284 puts("DRAM: ");
1285 print_size(gd->ram_size, "\n");
Simon Glasseacd14f2012-11-30 13:01:20 +00001286
1287 return 0;
1288}
1289#endif
1290
wdenkf287a242003-07-01 21:06:45 +00001291U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001292 base, 2, 1, do_mem_base,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001293 "print or set address offset",
wdenk57b2d802003-06-27 21:31:46 +00001294 "\n - print address offset for memory commands\n"
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001295 "base off\n - set address offset for memory commands to 'off'"
wdenk57b2d802003-06-27 21:31:46 +00001296);
1297
wdenkf287a242003-07-01 21:06:45 +00001298U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001299 loop, 3, 1, do_mem_loop,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001300 "infinite loop on address range",
Simon Glass8927bf22019-12-28 10:45:10 -07001301#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001302 "[.b, .w, .l, .q] address number_of_objects"
1303#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001304 "[.b, .w, .l] address number_of_objects"
York Sun6c480012014-02-26 17:03:19 -08001305#endif
wdenk57b2d802003-06-27 21:31:46 +00001306);
wdenk64519362004-07-11 17:40:54 +00001307
1308#ifdef CONFIG_LOOPW
1309U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001310 loopw, 4, 1, do_mem_loopw,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001311 "infinite write loop on address range",
Simon Glass8927bf22019-12-28 10:45:10 -07001312#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001313 "[.b, .w, .l, .q] address number_of_objects data_to_write"
1314#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001315 "[.b, .w, .l] address number_of_objects data_to_write"
York Sun6c480012014-02-26 17:03:19 -08001316#endif
wdenk64519362004-07-11 17:40:54 +00001317);
1318#endif /* CONFIG_LOOPW */
wdenk57b2d802003-06-27 21:31:46 +00001319
Wolfgang Denk9d009282013-03-08 10:51:32 +00001320#ifdef CONFIG_CMD_MEMTEST
wdenkf287a242003-07-01 21:06:45 +00001321U_BOOT_CMD(
Dirk Eibachb2659892008-12-16 14:51:56 +01001322 mtest, 5, 1, do_mem_mtest,
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001323 "simple RAM read/write test",
1324 "[start [end [pattern [iterations]]]]"
wdenk57b2d802003-06-27 21:31:46 +00001325);
Wolfgang Denk9d009282013-03-08 10:51:32 +00001326#endif /* CONFIG_CMD_MEMTEST */
stroesefb5e0ac2004-12-16 17:42:39 +00001327
Joel Johnsondb5a97e2020-01-29 09:17:18 -07001328#ifdef CONFIG_CMD_MX_CYCLIC
stroesefb5e0ac2004-12-16 17:42:39 +00001329U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001330 mdc, 4, 1, do_mem_mdc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001331 "memory display cyclic",
Simon Glass8927bf22019-12-28 10:45:10 -07001332#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001333 "[.b, .w, .l, .q] address count delay(ms)"
1334#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001335 "[.b, .w, .l] address count delay(ms)"
York Sun6c480012014-02-26 17:03:19 -08001336#endif
stroesefb5e0ac2004-12-16 17:42:39 +00001337);
1338
1339U_BOOT_CMD(
Wolfgang Denka1be4762008-05-20 16:00:29 +02001340 mwc, 4, 1, do_mem_mwc,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001341 "memory write cyclic",
Simon Glass8927bf22019-12-28 10:45:10 -07001342#ifdef MEM_SUPPORT_64BIT_DATA
York Sun6c480012014-02-26 17:03:19 -08001343 "[.b, .w, .l, .q] address value delay(ms)"
1344#else
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001345 "[.b, .w, .l] address value delay(ms)"
York Sun6c480012014-02-26 17:03:19 -08001346#endif
stroesefb5e0ac2004-12-16 17:42:39 +00001347);
Joel Johnsondb5a97e2020-01-29 09:17:18 -07001348#endif /* CONFIG_CMD_MX_CYCLIC */
Simon Glasseacd14f2012-11-30 13:01:20 +00001349
1350#ifdef CONFIG_CMD_MEMINFO
1351U_BOOT_CMD(
1352 meminfo, 3, 1, do_mem_info,
1353 "display memory information",
1354 ""
1355);
1356#endif
Jean-Jacques Hiblotd3f09372019-07-02 14:23:26 +02001357
1358#ifdef CONFIG_CMD_RANDOM
1359U_BOOT_CMD(
1360 random, 4, 0, do_random,
1361 "fill memory with random pattern",
1362 "<addr> <len> [<seed>]\n"
1363 " - Fill 'len' bytes of memory starting at 'addr' with random data\n"
1364);
1365#endif