blob: 9ab6b1dd080195978c96db5db9e9b628b232a21d [file] [log] [blame]
Tom Rini83d290c2018-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 Glass24b852a2015-11-08 23:47:45 -070014#include <console.h>
Simon Glass0098e172014-04-10 20:01:30 -060015#include <bootretry.h>
Simon Glass18d66532014-04-10 20:01:25 -060016#include <cli.h>
wdenk38635852002-08-27 05:55:31 +000017#include <command.h>
Simon Glass24b852a2015-11-08 23:47:45 -070018#include <console.h>
Simon Glass0ee482522019-12-28 10:44:40 -070019#include <flash.h>
Simon Glassd20a40d2013-02-24 20:30:22 +000020#include <hash.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060021#include <log.h>
Joe Hershberger0eb25b62015-03-22 17:08:59 -050022#include <mapmem.h>
Simon Glass90526e92020-05-10 11:39:56 -060023#include <rand.h>
Sergei Poselenova6e6fc62008-04-09 16:09:41 +020024#include <watchdog.h>
Simon Glass0628ab82013-02-24 17:33:15 +000025#include <asm/io.h>
Simon Glasscd93d622020-05-10 11:40:13 -060026#include <linux/bitops.h>
Simon Glass15a33e42012-11-30 13:01:20 +000027#include <linux/compiler.h>
Simon Glassc05ed002020-05-10 11:40:11 -060028#include <linux/delay.h>
Simon Glass15a33e42012-11-30 13:01:20 +000029
30DECLARE_GLOBAL_DATA_PTR;
wdenk38635852002-08-27 05:55:31 +000031
Simon Glass09140112020-05-10 11:40:03 -060032#ifndef CONFIG_SYS_MEMTEST_SCRATCH
33#define CONFIG_SYS_MEMTEST_SCRATCH 0
34#endif
35
Simon Glass76be8f72020-06-02 19:26:45 -060036/* Create a compile-time value */
Simon Glass46809762020-06-02 19:26:46 -060037#ifdef MEM_SUPPORT_64BIT_DATA
38#define SUPPORT_64BIT_DATA 1
Simon Glass76be8f72020-06-02 19:26:45 -060039#define HELP_Q ", .q"
40#else
Simon Glass46809762020-06-02 19:26:46 -060041#define SUPPORT_64BIT_DATA 0
Simon Glass76be8f72020-06-02 19:26:45 -060042#define HELP_Q ""
43#endif
44
Simon Glass09140112020-05-10 11:40:03 -060045static int mod_mem(struct cmd_tbl *, int, int, int, char * const []);
wdenk38635852002-08-27 05:55:31 +000046
47/* Display values from last command.
48 * Memory modify remembered values are different from display memory.
49 */
Scott Wood581508b2015-03-19 09:43:12 -070050static ulong dp_last_addr, dp_last_size;
51static ulong dp_last_length = 0x40;
52static ulong mm_last_addr, mm_last_size;
wdenk38635852002-08-27 05:55:31 +000053
54static ulong base_address = 0;
55
56/* Memory Display
57 *
58 * Syntax:
York Sun4d1fd7f2014-02-26 17:03:19 -080059 * md{.b, .w, .l, .q} {addr} {len}
wdenk38635852002-08-27 05:55:31 +000060 */
61#define DISP_LINE_LEN 16
Simon Glass09140112020-05-10 11:40:03 -060062static int do_mem_md(struct cmd_tbl *cmdtp, int flag, int argc,
63 char *const argv[])
wdenk38635852002-08-27 05:55:31 +000064{
Tuomas Tynkkynenc68c03f2017-10-10 21:59:42 +030065 ulong addr, length, bytes;
66 const void *buf;
wdenk27b207f2003-07-24 23:38:38 +000067 int size;
wdenk38635852002-08-27 05:55:31 +000068 int rc = 0;
69
70 /* We use the last specified parameters, unless new ones are
71 * entered.
72 */
73 addr = dp_last_addr;
74 size = dp_last_size;
75 length = dp_last_length;
76
Wolfgang Denk47e26b12010-07-17 01:06:04 +020077 if (argc < 2)
Simon Glass4c12eeb2011-12-10 08:44:01 +000078 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +000079
80 if ((flag & CMD_FLAG_REPEAT) == 0) {
81 /* New command specified. Check for a size specification.
82 * Defaults to long if no or incorrect specification.
83 */
wdenk27b207f2003-07-24 23:38:38 +000084 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
85 return 1;
wdenk38635852002-08-27 05:55:31 +000086
87 /* Address is specified since argc > 1
88 */
89 addr = simple_strtoul(argv[1], NULL, 16);
90 addr += base_address;
91
92 /* If another parameter, it is the length to display.
93 * Length is the number of objects, not number of bytes.
94 */
95 if (argc > 2)
96 length = simple_strtoul(argv[2], NULL, 16);
97 }
98
Tuomas Tynkkynenc68c03f2017-10-10 21:59:42 +030099 bytes = size * length;
100 buf = map_sysmem(addr, bytes);
wdenk2abbe072003-06-16 23:50:08 +0000101
Tuomas Tynkkynenc68c03f2017-10-10 21:59:42 +0300102 /* Print the lines. */
103 print_buffer(addr, buf, size, length, DISP_LINE_LEN / size);
104 addr += bytes;
105 unmap_sysmem(buf);
wdenk38635852002-08-27 05:55:31 +0000106
107 dp_last_addr = addr;
108 dp_last_length = length;
109 dp_last_size = size;
110 return (rc);
111}
112
Simon Glass09140112020-05-10 11:40:03 -0600113static int do_mem_mm(struct cmd_tbl *cmdtp, int flag, int argc,
114 char *const argv[])
wdenk38635852002-08-27 05:55:31 +0000115{
116 return mod_mem (cmdtp, 1, flag, argc, argv);
117}
Simon Glass09140112020-05-10 11:40:03 -0600118
119static int do_mem_nm(struct cmd_tbl *cmdtp, int flag, int argc,
120 char *const argv[])
wdenk38635852002-08-27 05:55:31 +0000121{
122 return mod_mem (cmdtp, 0, flag, argc, argv);
123}
124
Simon Glass09140112020-05-10 11:40:03 -0600125static int do_mem_mw(struct cmd_tbl *cmdtp, int flag, int argc,
126 char *const argv[])
wdenk38635852002-08-27 05:55:31 +0000127{
Simon Glass46809762020-06-02 19:26:46 -0600128 ulong writeval; /* 64-bit if SUPPORT_64BIT_DATA */
York Sun4d1fd7f2014-02-26 17:03:19 -0800129 ulong addr, count;
wdenk27b207f2003-07-24 23:38:38 +0000130 int size;
Simon Glasscc5e1962015-03-05 12:25:18 -0700131 void *buf, *start;
Simon Glass0628ab82013-02-24 17:33:15 +0000132 ulong bytes;
wdenk38635852002-08-27 05:55:31 +0000133
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200134 if ((argc < 3) || (argc > 4))
Simon Glass4c12eeb2011-12-10 08:44:01 +0000135 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000136
137 /* Check for size specification.
138 */
wdenk27b207f2003-07-24 23:38:38 +0000139 if ((size = cmd_get_data_size(argv[0], 4)) < 1)
140 return 1;
wdenk38635852002-08-27 05:55:31 +0000141
142 /* Address is specified since argc > 1
143 */
144 addr = simple_strtoul(argv[1], NULL, 16);
145 addr += base_address;
146
147 /* Get the value to write.
148 */
Simon Glass46809762020-06-02 19:26:46 -0600149 if (SUPPORT_64BIT_DATA)
150 writeval = simple_strtoull(argv[2], NULL, 16);
151 else
152 writeval = simple_strtoul(argv[2], NULL, 16);
wdenk38635852002-08-27 05:55:31 +0000153
154 /* Count ? */
155 if (argc == 4) {
156 count = simple_strtoul(argv[3], NULL, 16);
157 } else {
158 count = 1;
159 }
160
Simon Glass0628ab82013-02-24 17:33:15 +0000161 bytes = size * count;
Simon Glasscc5e1962015-03-05 12:25:18 -0700162 start = map_sysmem(addr, bytes);
163 buf = start;
wdenk38635852002-08-27 05:55:31 +0000164 while (count-- > 0) {
165 if (size == 4)
York Sun76698b42014-02-12 15:55:35 -0800166 *((u32 *)buf) = (u32)writeval;
Simon Glass46809762020-06-02 19:26:46 -0600167 else if (SUPPORT_64BIT_DATA && size == 8)
168 *((ulong *)buf) = writeval;
wdenk38635852002-08-27 05:55:31 +0000169 else if (size == 2)
York Sun76698b42014-02-12 15:55:35 -0800170 *((u16 *)buf) = (u16)writeval;
wdenk38635852002-08-27 05:55:31 +0000171 else
York Sun76698b42014-02-12 15:55:35 -0800172 *((u8 *)buf) = (u8)writeval;
Simon Glass0628ab82013-02-24 17:33:15 +0000173 buf += size;
wdenk38635852002-08-27 05:55:31 +0000174 }
Simon Glasscc5e1962015-03-05 12:25:18 -0700175 unmap_sysmem(start);
wdenk38635852002-08-27 05:55:31 +0000176 return 0;
177}
178
Joel Johnson72732312020-01-29 09:17:18 -0700179#ifdef CONFIG_CMD_MX_CYCLIC
Simon Glass09140112020-05-10 11:40:03 -0600180static int do_mem_mdc(struct cmd_tbl *cmdtp, int flag, int argc,
181 char *const argv[])
stroese4aaf29b2004-12-16 17:42:39 +0000182{
183 int i;
184 ulong count;
185
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200186 if (argc < 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000187 return CMD_RET_USAGE;
stroese4aaf29b2004-12-16 17:42:39 +0000188
189 count = simple_strtoul(argv[3], NULL, 10);
190
191 for (;;) {
192 do_mem_md (NULL, 0, 3, argv);
193
194 /* delay for <count> ms... */
195 for (i=0; i<count; i++)
Simon Glass07e11142020-05-10 11:40:10 -0600196 udelay(1000);
stroese4aaf29b2004-12-16 17:42:39 +0000197
198 /* check for ctrl-c to abort... */
199 if (ctrlc()) {
200 puts("Abort\n");
201 return 0;
202 }
203 }
204
205 return 0;
206}
207
Simon Glass09140112020-05-10 11:40:03 -0600208static int do_mem_mwc(struct cmd_tbl *cmdtp, int flag, int argc,
209 char *const argv[])
stroese4aaf29b2004-12-16 17:42:39 +0000210{
211 int i;
212 ulong count;
213
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200214 if (argc < 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000215 return CMD_RET_USAGE;
stroese4aaf29b2004-12-16 17:42:39 +0000216
217 count = simple_strtoul(argv[3], NULL, 10);
218
219 for (;;) {
220 do_mem_mw (NULL, 0, 3, argv);
221
222 /* delay for <count> ms... */
223 for (i=0; i<count; i++)
Simon Glass07e11142020-05-10 11:40:10 -0600224 udelay(1000);
stroese4aaf29b2004-12-16 17:42:39 +0000225
226 /* check for ctrl-c to abort... */
227 if (ctrlc()) {
228 puts("Abort\n");
229 return 0;
230 }
231 }
232
233 return 0;
234}
Joel Johnson72732312020-01-29 09:17:18 -0700235#endif /* CONFIG_CMD_MX_CYCLIC */
stroese4aaf29b2004-12-16 17:42:39 +0000236
Simon Glass09140112020-05-10 11:40:03 -0600237static int do_mem_cmp(struct cmd_tbl *cmdtp, int flag, int argc,
238 char *const argv[])
wdenk38635852002-08-27 05:55:31 +0000239{
Simon Glass0628ab82013-02-24 17:33:15 +0000240 ulong addr1, addr2, count, ngood, bytes;
wdenk27b207f2003-07-24 23:38:38 +0000241 int size;
wdenk38635852002-08-27 05:55:31 +0000242 int rcode = 0;
Mike Frysinger054ea172012-01-20 09:07:21 +0000243 const char *type;
Simon Glass0628ab82013-02-24 17:33:15 +0000244 const void *buf1, *buf2, *base;
Simon Glass46809762020-06-02 19:26:46 -0600245 ulong word1, word2; /* 64-bit if SUPPORT_64BIT_DATA */
wdenk38635852002-08-27 05:55:31 +0000246
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200247 if (argc != 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000248 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000249
250 /* Check for size specification.
251 */
wdenk27b207f2003-07-24 23:38:38 +0000252 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
253 return 1;
York Sun4d1fd7f2014-02-26 17:03:19 -0800254 type = size == 8 ? "double word" :
255 size == 4 ? "word" :
256 size == 2 ? "halfword" : "byte";
wdenk38635852002-08-27 05:55:31 +0000257
258 addr1 = simple_strtoul(argv[1], NULL, 16);
259 addr1 += base_address;
260
261 addr2 = simple_strtoul(argv[2], NULL, 16);
262 addr2 += base_address;
263
264 count = simple_strtoul(argv[3], NULL, 16);
265
Simon Glass0628ab82013-02-24 17:33:15 +0000266 bytes = size * count;
267 base = buf1 = map_sysmem(addr1, bytes);
268 buf2 = map_sysmem(addr2, bytes);
Mike Frysingerfeb12a12012-01-20 09:07:22 +0000269 for (ngood = 0; ngood < count; ++ngood) {
wdenk38635852002-08-27 05:55:31 +0000270 if (size == 4) {
York Sun76698b42014-02-12 15:55:35 -0800271 word1 = *(u32 *)buf1;
272 word2 = *(u32 *)buf2;
Simon Glass46809762020-06-02 19:26:46 -0600273 } else if (SUPPORT_64BIT_DATA && size == 8) {
274 word1 = *(ulong *)buf1;
275 word2 = *(ulong *)buf2;
Mike Frysinger054ea172012-01-20 09:07:21 +0000276 } else if (size == 2) {
York Sun76698b42014-02-12 15:55:35 -0800277 word1 = *(u16 *)buf1;
278 word2 = *(u16 *)buf2;
Mike Frysinger054ea172012-01-20 09:07:21 +0000279 } else {
York Sun76698b42014-02-12 15:55:35 -0800280 word1 = *(u8 *)buf1;
281 word2 = *(u8 *)buf2;
wdenk38635852002-08-27 05:55:31 +0000282 }
Mike Frysinger054ea172012-01-20 09:07:21 +0000283 if (word1 != word2) {
Simon Glass0628ab82013-02-24 17:33:15 +0000284 ulong offset = buf1 - base;
Mike Frysinger054ea172012-01-20 09:07:21 +0000285 printf("%s at 0x%08lx (%#0*lx) != %s at 0x%08lx (%#0*lx)\n",
Simon Glass0628ab82013-02-24 17:33:15 +0000286 type, (ulong)(addr1 + offset), size, word1,
287 type, (ulong)(addr2 + offset), size, word2);
Mike Frysinger054ea172012-01-20 09:07:21 +0000288 rcode = 1;
289 break;
wdenk38635852002-08-27 05:55:31 +0000290 }
Mike Frysinger054ea172012-01-20 09:07:21 +0000291
Simon Glass0628ab82013-02-24 17:33:15 +0000292 buf1 += size;
293 buf2 += size;
Stefan Roeseeaadb442010-09-13 11:10:34 +0200294
295 /* reset watchdog from time to time */
Mike Frysingerfeb12a12012-01-20 09:07:22 +0000296 if ((ngood % (64 << 10)) == 0)
Stefan Roeseeaadb442010-09-13 11:10:34 +0200297 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000298 }
Simon Glass0628ab82013-02-24 17:33:15 +0000299 unmap_sysmem(buf1);
300 unmap_sysmem(buf2);
wdenk38635852002-08-27 05:55:31 +0000301
Mike Frysinger054ea172012-01-20 09:07:21 +0000302 printf("Total of %ld %s(s) were the same\n", ngood, type);
wdenk38635852002-08-27 05:55:31 +0000303 return rcode;
304}
305
Simon Glass09140112020-05-10 11:40:03 -0600306static int do_mem_cp(struct cmd_tbl *cmdtp, int flag, int argc,
307 char *const argv[])
wdenk38635852002-08-27 05:55:31 +0000308{
Fabio Estevamc2538422016-12-15 16:00:13 -0200309 ulong addr, dest, count;
Philippe Reynes787f10a2019-12-02 17:33:22 +0100310 void *src, *dst;
wdenk27b207f2003-07-24 23:38:38 +0000311 int size;
wdenk38635852002-08-27 05:55:31 +0000312
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200313 if (argc != 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000314 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000315
316 /* Check for size specification.
317 */
wdenk27b207f2003-07-24 23:38:38 +0000318 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
319 return 1;
wdenk38635852002-08-27 05:55:31 +0000320
321 addr = simple_strtoul(argv[1], NULL, 16);
322 addr += base_address;
323
324 dest = simple_strtoul(argv[2], NULL, 16);
325 dest += base_address;
326
327 count = simple_strtoul(argv[3], NULL, 16);
328
329 if (count == 0) {
330 puts ("Zero length ???\n");
331 return 1;
332 }
333
Philippe Reynes787f10a2019-12-02 17:33:22 +0100334 src = map_sysmem(addr, count * size);
335 dst = map_sysmem(dest, count * size);
336
Masahiro Yamadae856bdc2017-02-11 22:43:54 +0900337#ifdef CONFIG_MTD_NOR_FLASH
wdenk38635852002-08-27 05:55:31 +0000338 /* check if we are copying to Flash */
Philippe Reynes787f10a2019-12-02 17:33:22 +0100339 if (addr2info((ulong)dst)) {
wdenk38635852002-08-27 05:55:31 +0000340 int rc;
341
wdenk4b9206e2004-03-23 22:14:11 +0000342 puts ("Copy to Flash... ");
wdenk38635852002-08-27 05:55:31 +0000343
Philippe Reynes787f10a2019-12-02 17:33:22 +0100344 rc = flash_write((char *)src, (ulong)dst, count * size);
wdenk38635852002-08-27 05:55:31 +0000345 if (rc != 0) {
Simon Glass0ee482522019-12-28 10:44:40 -0700346 flash_perror(rc);
Philippe Reynes787f10a2019-12-02 17:33:22 +0100347 unmap_sysmem(src);
348 unmap_sysmem(dst);
wdenk38635852002-08-27 05:55:31 +0000349 return (1);
350 }
351 puts ("done\n");
Philippe Reynes787f10a2019-12-02 17:33:22 +0100352 unmap_sysmem(src);
353 unmap_sysmem(dst);
wdenk38635852002-08-27 05:55:31 +0000354 return 0;
355 }
356#endif
357
Philippe Reynes787f10a2019-12-02 17:33:22 +0100358 memcpy(dst, src, count * size);
Masahiro Yamadaa3a47492014-10-23 17:46:24 +0900359
Philippe Reynes787f10a2019-12-02 17:33:22 +0100360 unmap_sysmem(src);
361 unmap_sysmem(dst);
wdenk38635852002-08-27 05:55:31 +0000362 return 0;
363}
364
Simon Glass09140112020-05-10 11:40:03 -0600365static int do_mem_base(struct cmd_tbl *cmdtp, int flag, int argc,
366 char *const argv[])
wdenk38635852002-08-27 05:55:31 +0000367{
368 if (argc > 1) {
369 /* Set new base address.
370 */
371 base_address = simple_strtoul(argv[1], NULL, 16);
372 }
373 /* Print the current base address.
374 */
375 printf("Base Address: 0x%08lx\n", base_address);
376 return 0;
377}
378
Simon Glass09140112020-05-10 11:40:03 -0600379static int do_mem_loop(struct cmd_tbl *cmdtp, int flag, int argc,
380 char *const argv[])
wdenk38635852002-08-27 05:55:31 +0000381{
Simon Glass0628ab82013-02-24 17:33:15 +0000382 ulong addr, length, i, bytes;
wdenk27b207f2003-07-24 23:38:38 +0000383 int size;
Simon Glass46809762020-06-02 19:26:46 -0600384 volatile ulong *llp; /* 64-bit if SUPPORT_64BIT_DATA */
York Sun76698b42014-02-12 15:55:35 -0800385 volatile u32 *longp;
386 volatile u16 *shortp;
387 volatile u8 *cp;
Simon Glass0628ab82013-02-24 17:33:15 +0000388 const void *buf;
wdenk38635852002-08-27 05:55:31 +0000389
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200390 if (argc < 3)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000391 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000392
Robert P. J. Day85de63e2013-02-03 02:29:54 +0000393 /*
394 * Check for a size specification.
wdenk38635852002-08-27 05:55:31 +0000395 * Defaults to long if no or incorrect specification.
396 */
wdenk27b207f2003-07-24 23:38:38 +0000397 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
398 return 1;
wdenk38635852002-08-27 05:55:31 +0000399
400 /* Address is always specified.
401 */
402 addr = simple_strtoul(argv[1], NULL, 16);
403
404 /* Length is the number of objects, not number of bytes.
405 */
406 length = simple_strtoul(argv[2], NULL, 16);
407
Simon Glass0628ab82013-02-24 17:33:15 +0000408 bytes = size * length;
409 buf = map_sysmem(addr, bytes);
410
wdenk38635852002-08-27 05:55:31 +0000411 /* We want to optimize the loops to run as fast as possible.
412 * If we have only one object, just run infinite loops.
413 */
414 if (length == 1) {
Simon Glass46809762020-06-02 19:26:46 -0600415 if (SUPPORT_64BIT_DATA && size == 8) {
416 llp = (ulong *)buf;
York Sun4d1fd7f2014-02-26 17:03:19 -0800417 for (;;)
418 i = *llp;
419 }
wdenk38635852002-08-27 05:55:31 +0000420 if (size == 4) {
York Sun76698b42014-02-12 15:55:35 -0800421 longp = (u32 *)buf;
wdenk38635852002-08-27 05:55:31 +0000422 for (;;)
423 i = *longp;
424 }
425 if (size == 2) {
York Sun76698b42014-02-12 15:55:35 -0800426 shortp = (u16 *)buf;
wdenk38635852002-08-27 05:55:31 +0000427 for (;;)
428 i = *shortp;
429 }
York Sun76698b42014-02-12 15:55:35 -0800430 cp = (u8 *)buf;
wdenk38635852002-08-27 05:55:31 +0000431 for (;;)
432 i = *cp;
433 }
434
Simon Glass46809762020-06-02 19:26:46 -0600435 if (SUPPORT_64BIT_DATA && size == 8) {
York Sun4d1fd7f2014-02-26 17:03:19 -0800436 for (;;) {
Simon Glass46809762020-06-02 19:26:46 -0600437 llp = (ulong *)buf;
York Sun4d1fd7f2014-02-26 17:03:19 -0800438 i = length;
439 while (i-- > 0)
440 *llp++;
441 }
442 }
wdenk38635852002-08-27 05:55:31 +0000443 if (size == 4) {
444 for (;;) {
York Sun76698b42014-02-12 15:55:35 -0800445 longp = (u32 *)buf;
wdenk38635852002-08-27 05:55:31 +0000446 i = length;
447 while (i-- > 0)
Marek Vasutf3b3c3d2011-09-26 02:26:06 +0200448 *longp++;
wdenk38635852002-08-27 05:55:31 +0000449 }
450 }
451 if (size == 2) {
452 for (;;) {
York Sun76698b42014-02-12 15:55:35 -0800453 shortp = (u16 *)buf;
wdenk38635852002-08-27 05:55:31 +0000454 i = length;
455 while (i-- > 0)
Marek Vasutf3b3c3d2011-09-26 02:26:06 +0200456 *shortp++;
wdenk38635852002-08-27 05:55:31 +0000457 }
458 }
459 for (;;) {
York Sun76698b42014-02-12 15:55:35 -0800460 cp = (u8 *)buf;
wdenk38635852002-08-27 05:55:31 +0000461 i = length;
462 while (i-- > 0)
Marek Vasutf3b3c3d2011-09-26 02:26:06 +0200463 *cp++;
wdenk38635852002-08-27 05:55:31 +0000464 }
Simon Glass0628ab82013-02-24 17:33:15 +0000465 unmap_sysmem(buf);
Simon Glass92765f422013-06-11 11:14:35 -0700466
467 return 0;
wdenk38635852002-08-27 05:55:31 +0000468}
469
wdenk56523f12004-07-11 17:40:54 +0000470#ifdef CONFIG_LOOPW
Simon Glass09140112020-05-10 11:40:03 -0600471static int do_mem_loopw(struct cmd_tbl *cmdtp, int flag, int argc,
472 char *const argv[])
wdenk56523f12004-07-11 17:40:54 +0000473{
York Sun4d1fd7f2014-02-26 17:03:19 -0800474 ulong addr, length, i, bytes;
wdenk56523f12004-07-11 17:40:54 +0000475 int size;
Simon Glass46809762020-06-02 19:26:46 -0600476 volatile ulong *llp; /* 64-bit if SUPPORT_64BIT_DATA */
477 ulong data; /* 64-bit if SUPPORT_64BIT_DATA */
York Sun76698b42014-02-12 15:55:35 -0800478 volatile u32 *longp;
479 volatile u16 *shortp;
480 volatile u8 *cp;
Simon Glass0628ab82013-02-24 17:33:15 +0000481 void *buf;
wdenk81050922004-07-11 20:04:51 +0000482
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200483 if (argc < 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000484 return CMD_RET_USAGE;
wdenk56523f12004-07-11 17:40:54 +0000485
Robert P. J. Day85de63e2013-02-03 02:29:54 +0000486 /*
487 * Check for a size specification.
wdenk56523f12004-07-11 17:40:54 +0000488 * Defaults to long if no or incorrect specification.
489 */
490 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
491 return 1;
492
493 /* Address is always specified.
494 */
495 addr = simple_strtoul(argv[1], NULL, 16);
496
497 /* Length is the number of objects, not number of bytes.
498 */
499 length = simple_strtoul(argv[2], NULL, 16);
500
501 /* data to write */
Simon Glass46809762020-06-02 19:26:46 -0600502 if (SUPPORT_64BIT_DATA)
503 data = simple_strtoull(argv[3], NULL, 16);
504 else
505 data = simple_strtoul(argv[3], NULL, 16);
wdenk81050922004-07-11 20:04:51 +0000506
Simon Glass0628ab82013-02-24 17:33:15 +0000507 bytes = size * length;
508 buf = map_sysmem(addr, bytes);
509
wdenk56523f12004-07-11 17:40:54 +0000510 /* We want to optimize the loops to run as fast as possible.
511 * If we have only one object, just run infinite loops.
512 */
513 if (length == 1) {
Simon Glass46809762020-06-02 19:26:46 -0600514 if (SUPPORT_64BIT_DATA && size == 8) {
515 llp = (ulong *)buf;
York Sun4d1fd7f2014-02-26 17:03:19 -0800516 for (;;)
517 *llp = data;
518 }
wdenk56523f12004-07-11 17:40:54 +0000519 if (size == 4) {
York Sun76698b42014-02-12 15:55:35 -0800520 longp = (u32 *)buf;
wdenk56523f12004-07-11 17:40:54 +0000521 for (;;)
522 *longp = data;
York Sun4d1fd7f2014-02-26 17:03:19 -0800523 }
wdenk56523f12004-07-11 17:40:54 +0000524 if (size == 2) {
York Sun76698b42014-02-12 15:55:35 -0800525 shortp = (u16 *)buf;
wdenk56523f12004-07-11 17:40:54 +0000526 for (;;)
527 *shortp = data;
528 }
York Sun76698b42014-02-12 15:55:35 -0800529 cp = (u8 *)buf;
wdenk56523f12004-07-11 17:40:54 +0000530 for (;;)
531 *cp = data;
532 }
533
Simon Glass46809762020-06-02 19:26:46 -0600534 if (SUPPORT_64BIT_DATA && size == 8) {
York Sun4d1fd7f2014-02-26 17:03:19 -0800535 for (;;) {
Simon Glass46809762020-06-02 19:26:46 -0600536 llp = (ulong *)buf;
York Sun4d1fd7f2014-02-26 17:03:19 -0800537 i = length;
538 while (i-- > 0)
539 *llp++ = data;
540 }
541 }
wdenk56523f12004-07-11 17:40:54 +0000542 if (size == 4) {
543 for (;;) {
York Sun76698b42014-02-12 15:55:35 -0800544 longp = (u32 *)buf;
wdenk56523f12004-07-11 17:40:54 +0000545 i = length;
546 while (i-- > 0)
547 *longp++ = data;
548 }
549 }
550 if (size == 2) {
551 for (;;) {
York Sun76698b42014-02-12 15:55:35 -0800552 shortp = (u16 *)buf;
wdenk56523f12004-07-11 17:40:54 +0000553 i = length;
554 while (i-- > 0)
555 *shortp++ = data;
556 }
557 }
558 for (;;) {
York Sun76698b42014-02-12 15:55:35 -0800559 cp = (u8 *)buf;
wdenk56523f12004-07-11 17:40:54 +0000560 i = length;
561 while (i-- > 0)
562 *cp++ = data;
563 }
564}
565#endif /* CONFIG_LOOPW */
566
Tom Rini68149e92013-03-12 10:07:19 -0400567#ifdef CONFIG_CMD_MEMTEST
Simon Glass5512d5b2013-02-28 17:47:14 +0000568static ulong mem_test_alt(vu_long *buf, ulong start_addr, ulong end_addr,
569 vu_long *dummy)
wdenk38635852002-08-27 05:55:31 +0000570{
Simon Glassc9638f52013-02-24 17:33:16 +0000571 vu_long *addr;
Simon Glassc9638f52013-02-24 17:33:16 +0000572 ulong errs = 0;
573 ulong val, readback;
574 int j;
Simon Glassc9638f52013-02-24 17:33:16 +0000575 vu_long offset;
576 vu_long test_offset;
577 vu_long pattern;
578 vu_long temp;
579 vu_long anti_pattern;
580 vu_long num_words;
wdenk38635852002-08-27 05:55:31 +0000581 static const ulong bitpattern[] = {
582 0x00000001, /* single bit */
583 0x00000003, /* two adjacent bits */
584 0x00000007, /* three adjacent bits */
585 0x0000000F, /* four adjacent bits */
586 0x00000005, /* two non-adjacent bits */
587 0x00000015, /* three non-adjacent bits */
588 0x00000055, /* four non-adjacent bits */
589 0xaaaaaaaa, /* alternating 1/0 */
590 };
wdenk38635852002-08-27 05:55:31 +0000591
Simon Glass5512d5b2013-02-28 17:47:14 +0000592 num_words = (end_addr - start_addr) / sizeof(vu_long);
Simon Glass8c86bbe2013-02-24 17:33:20 +0000593
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000594 /*
595 * Data line test: write a pattern to the first
596 * location, write the 1's complement to a 'parking'
597 * address (changes the state of the data bus so a
598 * floating bus doesn't give a false OK), and then
599 * read the value back. Note that we read it back
600 * into a variable because the next time we read it,
601 * it might be right (been there, tough to explain to
602 * the quality guys why it prints a failure when the
603 * "is" and "should be" are obviously the same in the
604 * error message).
605 *
606 * Rather than exhaustively testing, we test some
607 * patterns by shifting '1' bits through a field of
608 * '0's and '0' bits through a field of '1's (i.e.
609 * pattern and ~pattern).
610 */
Simon Glass5512d5b2013-02-28 17:47:14 +0000611 addr = buf;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000612 for (j = 0; j < sizeof(bitpattern) / sizeof(bitpattern[0]); j++) {
613 val = bitpattern[j];
614 for (; val != 0; val <<= 1) {
Simon Glass5512d5b2013-02-28 17:47:14 +0000615 *addr = val;
Simon Glassc9638f52013-02-24 17:33:16 +0000616 *dummy = ~val; /* clear the test data off the bus */
wdenk38635852002-08-27 05:55:31 +0000617 readback = *addr;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000618 if (readback != val) {
Simon Glassc9638f52013-02-24 17:33:16 +0000619 printf("FAILURE (data line): "
620 "expected %08lx, actual %08lx\n",
621 val, readback);
622 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000623 if (ctrlc())
Simon Glass51209b12013-02-24 17:33:17 +0000624 return -1;
wdenk38635852002-08-27 05:55:31 +0000625 }
626 *addr = ~val;
627 *dummy = val;
628 readback = *addr;
Simon Glassc9638f52013-02-24 17:33:16 +0000629 if (readback != ~val) {
630 printf("FAILURE (data line): "
631 "Is %08lx, should be %08lx\n",
632 readback, ~val);
633 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000634 if (ctrlc())
Simon Glass51209b12013-02-24 17:33:17 +0000635 return -1;
wdenk38635852002-08-27 05:55:31 +0000636 }
wdenk38635852002-08-27 05:55:31 +0000637 }
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000638 }
wdenk38635852002-08-27 05:55:31 +0000639
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000640 /*
641 * Based on code whose Original Author and Copyright
642 * information follows: Copyright (c) 1998 by Michael
643 * Barr. This software is placed into the public
644 * domain and may be used for any purpose. However,
645 * this notice must not be changed or removed and no
646 * warranty is either expressed or implied by its
647 * publication or distribution.
648 */
wdenk38635852002-08-27 05:55:31 +0000649
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000650 /*
651 * Address line test
wdenk38635852002-08-27 05:55:31 +0000652
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000653 * Description: Test the address bus wiring in a
654 * memory region by performing a walking
655 * 1's test on the relevant bits of the
656 * address and checking for aliasing.
657 * This test will find single-bit
658 * address failures such as stuck-high,
659 * stuck-low, and shorted pins. The base
660 * address and size of the region are
661 * selected by the caller.
wdenk38635852002-08-27 05:55:31 +0000662
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000663 * Notes: For best results, the selected base
664 * address should have enough LSB 0's to
665 * guarantee single address bit changes.
666 * For example, to test a 64-Kbyte
667 * region, select a base address on a
668 * 64-Kbyte boundary. Also, select the
669 * region size as a power-of-two if at
670 * all possible.
671 *
672 * Returns: 0 if the test succeeds, 1 if the test fails.
673 */
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000674 pattern = (vu_long) 0xaaaaaaaa;
675 anti_pattern = (vu_long) 0x55555555;
wdenk38635852002-08-27 05:55:31 +0000676
Simon Glass5512d5b2013-02-28 17:47:14 +0000677 debug("%s:%d: length = 0x%.8lx\n", __func__, __LINE__, num_words);
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000678 /*
679 * Write the default pattern at each of the
680 * power-of-two offsets.
681 */
Simon Glass5512d5b2013-02-28 17:47:14 +0000682 for (offset = 1; offset < num_words; offset <<= 1)
683 addr[offset] = pattern;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000684
685 /*
686 * Check for address bits stuck high.
687 */
688 test_offset = 0;
Simon Glass5512d5b2013-02-28 17:47:14 +0000689 addr[test_offset] = anti_pattern;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000690
Simon Glass5512d5b2013-02-28 17:47:14 +0000691 for (offset = 1; offset < num_words; offset <<= 1) {
692 temp = addr[offset];
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000693 if (temp != pattern) {
Simon Glassc9638f52013-02-24 17:33:16 +0000694 printf("\nFAILURE: Address bit stuck high @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000695 " expected 0x%.8lx, actual 0x%.8lx\n",
David Feng102c0512014-02-12 16:10:08 +0800696 start_addr + offset*sizeof(vu_long),
697 pattern, temp);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400698 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000699 if (ctrlc())
Simon Glass51209b12013-02-24 17:33:17 +0000700 return -1;
wdenk38635852002-08-27 05:55:31 +0000701 }
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000702 }
Simon Glass5512d5b2013-02-28 17:47:14 +0000703 addr[test_offset] = pattern;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000704 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000705
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000706 /*
707 * Check for addr bits stuck low or shorted.
708 */
Simon Glass5512d5b2013-02-28 17:47:14 +0000709 for (test_offset = 1; test_offset < num_words; test_offset <<= 1) {
710 addr[test_offset] = anti_pattern;
wdenk38635852002-08-27 05:55:31 +0000711
Simon Glass5512d5b2013-02-28 17:47:14 +0000712 for (offset = 1; offset < num_words; offset <<= 1) {
713 temp = addr[offset];
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000714 if ((temp != pattern) && (offset != test_offset)) {
715 printf("\nFAILURE: Address bit stuck low or"
716 " shorted @ 0x%.8lx: expected 0x%.8lx,"
717 " actual 0x%.8lx\n",
David Feng102c0512014-02-12 16:10:08 +0800718 start_addr + offset*sizeof(vu_long),
719 pattern, temp);
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000720 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000721 if (ctrlc())
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000722 return -1;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000723 }
wdenk38635852002-08-27 05:55:31 +0000724 }
Simon Glass5512d5b2013-02-28 17:47:14 +0000725 addr[test_offset] = pattern;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000726 }
wdenk38635852002-08-27 05:55:31 +0000727
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000728 /*
729 * Description: Test the integrity of a physical
730 * memory device by performing an
731 * increment/decrement test over the
732 * entire region. In the process every
733 * storage bit in the device is tested
734 * as a zero and a one. The base address
735 * and the size of the region are
736 * selected by the caller.
737 *
738 * Returns: 0 if the test succeeds, 1 if the test fails.
739 */
Simon Glass5512d5b2013-02-28 17:47:14 +0000740 num_words++;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000741
742 /*
743 * Fill memory with a known pattern.
744 */
745 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
746 WATCHDOG_RESET();
Simon Glass5512d5b2013-02-28 17:47:14 +0000747 addr[offset] = pattern;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000748 }
749
750 /*
751 * Check each location and invert it for the second pass.
752 */
753 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
754 WATCHDOG_RESET();
Simon Glass5512d5b2013-02-28 17:47:14 +0000755 temp = addr[offset];
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000756 if (temp != pattern) {
Simon Glassc9638f52013-02-24 17:33:16 +0000757 printf("\nFAILURE (read/write) @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000758 " expected 0x%.8lx, actual 0x%.8lx)\n",
David Feng102c0512014-02-12 16:10:08 +0800759 start_addr + offset*sizeof(vu_long),
760 pattern, temp);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400761 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000762 if (ctrlc())
Simon Glass51209b12013-02-24 17:33:17 +0000763 return -1;
wdenk38635852002-08-27 05:55:31 +0000764 }
765
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000766 anti_pattern = ~pattern;
Simon Glass5512d5b2013-02-28 17:47:14 +0000767 addr[offset] = anti_pattern;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000768 }
769
770 /*
771 * Check each location for the inverted pattern and zero it.
772 */
773 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
774 WATCHDOG_RESET();
775 anti_pattern = ~pattern;
Simon Glass5512d5b2013-02-28 17:47:14 +0000776 temp = addr[offset];
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000777 if (temp != anti_pattern) {
Simon Glassc9638f52013-02-24 17:33:16 +0000778 printf("\nFAILURE (read/write): @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000779 " expected 0x%.8lx, actual 0x%.8lx)\n",
David Feng102c0512014-02-12 16:10:08 +0800780 start_addr + offset*sizeof(vu_long),
781 anti_pattern, temp);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400782 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000783 if (ctrlc())
Simon Glass51209b12013-02-24 17:33:17 +0000784 return -1;
wdenk38635852002-08-27 05:55:31 +0000785 }
Simon Glass5512d5b2013-02-28 17:47:14 +0000786 addr[offset] = 0;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000787 }
Simon Glass51209b12013-02-24 17:33:17 +0000788
Rasmus Villemoesfea67302016-01-07 11:36:04 +0100789 return errs;
Simon Glassc9638f52013-02-24 17:33:16 +0000790}
wdenk38635852002-08-27 05:55:31 +0000791
Stefan Roese8e434cb2020-03-05 07:21:32 +0100792static int compare_regions(volatile unsigned long *bufa,
793 volatile unsigned long *bufb, size_t count)
794{
795 volatile unsigned long *p1 = bufa;
796 volatile unsigned long *p2 = bufb;
797 int errs = 0;
798 size_t i;
799
800 for (i = 0; i < count; i++, p1++, p2++) {
801 if (*p1 != *p2) {
802 printf("FAILURE: 0x%08lx != 0x%08lx (delta=0x%08lx -> bit %ld) at offset 0x%08lx\n",
803 (unsigned long)*p1, (unsigned long)*p2,
804 *p1 ^ *p2, __ffs(*p1 ^ *p2),
805 (unsigned long)(i * sizeof(unsigned long)));
806 errs++;
807 }
808 }
809
810 return errs;
811}
812
813static ulong test_bitflip_comparison(volatile unsigned long *bufa,
814 volatile unsigned long *bufb, size_t count)
815{
816 volatile unsigned long *p1 = bufa;
817 volatile unsigned long *p2 = bufb;
818 unsigned int j, k;
819 unsigned long q;
820 size_t i;
821 int max;
822 int errs = 0;
823
824 max = sizeof(unsigned long) * 8;
825 for (k = 0; k < max; k++) {
826 q = 0x00000001L << k;
827 for (j = 0; j < 8; j++) {
828 WATCHDOG_RESET();
829 q = ~q;
830 p1 = (volatile unsigned long *)bufa;
831 p2 = (volatile unsigned long *)bufb;
832 for (i = 0; i < count; i++)
833 *p1++ = *p2++ = (i % 2) == 0 ? q : ~q;
834
835 errs += compare_regions(bufa, bufb, count);
836 }
837
838 if (ctrlc())
839 return -1UL;
840 }
841
842 return errs;
843}
844
Simon Glass5512d5b2013-02-28 17:47:14 +0000845static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr,
846 vu_long pattern, int iteration)
Simon Glassc9638f52013-02-24 17:33:16 +0000847{
Simon Glass5512d5b2013-02-28 17:47:14 +0000848 vu_long *end;
Simon Glassc9638f52013-02-24 17:33:16 +0000849 vu_long *addr;
Simon Glassc9638f52013-02-24 17:33:16 +0000850 ulong errs = 0;
Simon Glass5512d5b2013-02-28 17:47:14 +0000851 ulong incr, length;
Simon Glassc9638f52013-02-24 17:33:16 +0000852 ulong val, readback;
853
Simon Glass51209b12013-02-24 17:33:17 +0000854 /* Alternate the pattern */
wdenk38635852002-08-27 05:55:31 +0000855 incr = 1;
Simon Glass51209b12013-02-24 17:33:17 +0000856 if (iteration & 1) {
857 incr = -incr;
858 /*
859 * Flip the pattern each time to make lots of zeros and
860 * then, the next time, lots of ones. We decrement
861 * the "negative" patterns and increment the "positive"
862 * patterns to preserve this feature.
863 */
864 if (pattern & 0x80000000)
865 pattern = -pattern; /* complement & increment */
866 else
867 pattern = ~pattern;
868 }
Simon Glass5512d5b2013-02-28 17:47:14 +0000869 length = (end_addr - start_addr) / sizeof(ulong);
870 end = buf + length;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000871 printf("\rPattern %08lX Writing..."
872 "%12s"
873 "\b\b\b\b\b\b\b\b\b\b",
874 pattern, "");
wdenk38635852002-08-27 05:55:31 +0000875
Simon Glass5512d5b2013-02-28 17:47:14 +0000876 for (addr = buf, val = pattern; addr < end; addr++) {
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000877 WATCHDOG_RESET();
878 *addr = val;
879 val += incr;
880 }
wdenk38635852002-08-27 05:55:31 +0000881
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000882 puts("Reading...");
wdenk38635852002-08-27 05:55:31 +0000883
Simon Glass5512d5b2013-02-28 17:47:14 +0000884 for (addr = buf, val = pattern; addr < end; addr++) {
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000885 WATCHDOG_RESET();
886 readback = *addr;
887 if (readback != val) {
Simon Glass5512d5b2013-02-28 17:47:14 +0000888 ulong offset = addr - buf;
889
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000890 printf("\nMem error @ 0x%08X: "
891 "found %08lX, expected %08lX\n",
David Feng102c0512014-02-12 16:10:08 +0800892 (uint)(uintptr_t)(start_addr + offset*sizeof(vu_long)),
Simon Glass5512d5b2013-02-28 17:47:14 +0000893 readback, val);
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000894 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000895 if (ctrlc())
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000896 return -1;
wdenk38635852002-08-27 05:55:31 +0000897 }
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000898 val += incr;
899 }
wdenk38635852002-08-27 05:55:31 +0000900
Rasmus Villemoesfea67302016-01-07 11:36:04 +0100901 return errs;
Simon Glassc9638f52013-02-24 17:33:16 +0000902}
903
904/*
905 * Perform a memory test. A more complete alternative test can be
906 * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until
907 * interrupted by ctrl-c or by a failure of one of the sub-tests.
908 */
Simon Glass09140112020-05-10 11:40:03 -0600909static int do_mem_mtest(struct cmd_tbl *cmdtp, int flag, int argc,
910 char *const argv[])
Simon Glassc9638f52013-02-24 17:33:16 +0000911{
Simon Glass8c86bbe2013-02-24 17:33:20 +0000912 ulong start, end;
Michal Simeke519f032020-05-04 13:54:40 +0200913 vu_long scratch_space;
914 vu_long *buf, *dummy = &scratch_space;
Tom Riniadcc5702015-04-07 09:38:54 -0400915 ulong iteration_limit = 0;
Stefan Roesea8c708e2020-03-05 07:21:29 +0100916 ulong count = 0;
Simon Glass51209b12013-02-24 17:33:17 +0000917 ulong errs = 0; /* number of errors, or -1 if interrupted */
Pavel Macheke37f1eb2015-04-01 13:50:41 +0200918 ulong pattern = 0;
Simon Glass51209b12013-02-24 17:33:17 +0000919 int iteration;
Simon Glassc9638f52013-02-24 17:33:16 +0000920
Pavel Macheke37f1eb2015-04-01 13:50:41 +0200921 start = CONFIG_SYS_MEMTEST_START;
922 end = CONFIG_SYS_MEMTEST_END;
923
Simon Glassc9638f52013-02-24 17:33:16 +0000924 if (argc > 1)
Pavel Macheke37f1eb2015-04-01 13:50:41 +0200925 if (strict_strtoul(argv[1], 16, &start) < 0)
926 return CMD_RET_USAGE;
Simon Glassc9638f52013-02-24 17:33:16 +0000927
928 if (argc > 2)
Pavel Macheke37f1eb2015-04-01 13:50:41 +0200929 if (strict_strtoul(argv[2], 16, &end) < 0)
930 return CMD_RET_USAGE;
Simon Glassc9638f52013-02-24 17:33:16 +0000931
932 if (argc > 3)
Pavel Macheke37f1eb2015-04-01 13:50:41 +0200933 if (strict_strtoul(argv[3], 16, &pattern) < 0)
934 return CMD_RET_USAGE;
Simon Glassc9638f52013-02-24 17:33:16 +0000935
936 if (argc > 4)
Pavel Macheke37f1eb2015-04-01 13:50:41 +0200937 if (strict_strtoul(argv[4], 16, &iteration_limit) < 0)
938 return CMD_RET_USAGE;
939
940 if (end < start) {
941 printf("Refusing to do empty test\n");
942 return -1;
943 }
Simon Glassc9638f52013-02-24 17:33:16 +0000944
Michal Simekdfe461d2016-02-24 08:36:02 +0100945 printf("Testing %08lx ... %08lx:\n", start, end);
Simon Glass8c86bbe2013-02-24 17:33:20 +0000946 debug("%s:%d: start %#08lx end %#08lx\n", __func__, __LINE__,
947 start, end);
Simon Glass51209b12013-02-24 17:33:17 +0000948
Simon Glass5512d5b2013-02-28 17:47:14 +0000949 buf = map_sysmem(start, end - start);
Simon Glass51209b12013-02-24 17:33:17 +0000950 for (iteration = 0;
951 !iteration_limit || iteration < iteration_limit;
952 iteration++) {
953 if (ctrlc()) {
Simon Glass51209b12013-02-24 17:33:17 +0000954 errs = -1UL;
955 break;
956 }
957
958 printf("Iteration: %6d\r", iteration + 1);
959 debug("\n");
Stefan Roesef14bfa72020-03-05 07:21:31 +0100960 if (IS_ENABLED(CONFIG_SYS_ALT_MEMTEST)) {
Simon Glass5512d5b2013-02-28 17:47:14 +0000961 errs = mem_test_alt(buf, start, end, dummy);
Stefan Roese8e434cb2020-03-05 07:21:32 +0100962 if (errs == -1UL)
963 break;
964 count += errs;
965 errs = test_bitflip_comparison(buf,
966 buf + (end - start) / 2,
967 (end - start) /
968 sizeof(unsigned long));
Simon Glass5512d5b2013-02-28 17:47:14 +0000969 } else {
970 errs = mem_test_quick(buf, start, end, pattern,
971 iteration);
972 }
973 if (errs == -1UL)
974 break;
Stefan Roesea8c708e2020-03-05 07:21:29 +0100975 count += errs;
Simon Glass5512d5b2013-02-28 17:47:14 +0000976 }
977
Stefan Roese54de2442020-03-05 07:21:30 +0100978 unmap_sysmem((void *)buf);
Simon Glass51209b12013-02-24 17:33:17 +0000979
980 if (errs == -1UL) {
Simon Glassc44d4382013-02-24 17:33:19 +0000981 /* Memory test was aborted - write a newline to finish off */
982 putc('\n');
Simon Glass51209b12013-02-24 17:33:17 +0000983 }
Stefan Roesea8c708e2020-03-05 07:21:29 +0100984 printf("Tested %d iteration(s) with %lu errors.\n", iteration, count);
Simon Glassc9638f52013-02-24 17:33:16 +0000985
Stefan Roesea8c708e2020-03-05 07:21:29 +0100986 return errs != 0;
wdenk38635852002-08-27 05:55:31 +0000987}
Wolfgang Denka2681702013-03-08 10:51:32 +0000988#endif /* CONFIG_CMD_MEMTEST */
wdenk38635852002-08-27 05:55:31 +0000989
990/* Modify memory.
991 *
992 * Syntax:
York Sun4d1fd7f2014-02-26 17:03:19 -0800993 * mm{.b, .w, .l, .q} {addr}
wdenk38635852002-08-27 05:55:31 +0000994 */
995static int
Simon Glass09140112020-05-10 11:40:03 -0600996mod_mem(struct cmd_tbl *cmdtp, int incrflag, int flag, int argc,
997 char *const argv[])
wdenk38635852002-08-27 05:55:31 +0000998{
York Sun4d1fd7f2014-02-26 17:03:19 -0800999 ulong addr;
Simon Glass46809762020-06-02 19:26:46 -06001000 ulong i; /* 64-bit if SUPPORT_64BIT_DATA */
wdenk27b207f2003-07-24 23:38:38 +00001001 int nbytes, size;
Simon Glass0628ab82013-02-24 17:33:15 +00001002 void *ptr = NULL;
wdenk38635852002-08-27 05:55:31 +00001003
Wolfgang Denk47e26b12010-07-17 01:06:04 +02001004 if (argc != 2)
Simon Glass4c12eeb2011-12-10 08:44:01 +00001005 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +00001006
Simon Glassb26440f2014-04-10 20:01:31 -06001007 bootretry_reset_cmd_timeout(); /* got a good command to get here */
wdenk38635852002-08-27 05:55:31 +00001008 /* We use the last specified parameters, unless new ones are
1009 * entered.
1010 */
1011 addr = mm_last_addr;
1012 size = mm_last_size;
1013
1014 if ((flag & CMD_FLAG_REPEAT) == 0) {
1015 /* New command specified. Check for a size specification.
1016 * Defaults to long if no or incorrect specification.
1017 */
wdenk27b207f2003-07-24 23:38:38 +00001018 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
1019 return 1;
wdenk38635852002-08-27 05:55:31 +00001020
1021 /* Address is specified since argc > 1
1022 */
1023 addr = simple_strtoul(argv[1], NULL, 16);
1024 addr += base_address;
1025 }
1026
1027 /* Print the address, followed by value. Then accept input for
1028 * the next value. A non-converted value exits.
1029 */
1030 do {
Simon Glass0628ab82013-02-24 17:33:15 +00001031 ptr = map_sysmem(addr, size);
wdenk38635852002-08-27 05:55:31 +00001032 printf("%08lx:", addr);
1033 if (size == 4)
York Sun76698b42014-02-12 15:55:35 -08001034 printf(" %08x", *((u32 *)ptr));
Simon Glass46809762020-06-02 19:26:46 -06001035 else if (SUPPORT_64BIT_DATA && size == 8)
1036 printf(" %0lx", *((ulong *)ptr));
wdenk38635852002-08-27 05:55:31 +00001037 else if (size == 2)
York Sun76698b42014-02-12 15:55:35 -08001038 printf(" %04x", *((u16 *)ptr));
wdenk38635852002-08-27 05:55:31 +00001039 else
York Sun76698b42014-02-12 15:55:35 -08001040 printf(" %02x", *((u8 *)ptr));
wdenk38635852002-08-27 05:55:31 +00001041
Simon Glasse1bf8242014-04-10 20:01:27 -06001042 nbytes = cli_readline(" ? ");
wdenk38635852002-08-27 05:55:31 +00001043 if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
1044 /* <CR> pressed as only input, don't modify current
1045 * location and move to next. "-" pressed will go back.
1046 */
1047 if (incrflag)
1048 addr += nbytes ? -size : size;
1049 nbytes = 1;
Simon Glassb26440f2014-04-10 20:01:31 -06001050 /* good enough to not time out */
1051 bootretry_reset_cmd_timeout();
wdenk38635852002-08-27 05:55:31 +00001052 }
1053#ifdef CONFIG_BOOT_RETRY_TIME
1054 else if (nbytes == -2) {
1055 break; /* timed out, exit the command */
1056 }
1057#endif
1058 else {
1059 char *endp;
Simon Glass46809762020-06-02 19:26:46 -06001060 if (SUPPORT_64BIT_DATA)
1061 i = simple_strtoull(console_buffer, &endp, 16);
1062 else
1063 i = simple_strtoul(console_buffer, &endp, 16);
wdenk38635852002-08-27 05:55:31 +00001064 nbytes = endp - console_buffer;
1065 if (nbytes) {
wdenk38635852002-08-27 05:55:31 +00001066 /* good enough to not time out
1067 */
Simon Glassb26440f2014-04-10 20:01:31 -06001068 bootretry_reset_cmd_timeout();
wdenk38635852002-08-27 05:55:31 +00001069 if (size == 4)
York Sun76698b42014-02-12 15:55:35 -08001070 *((u32 *)ptr) = i;
Simon Glass46809762020-06-02 19:26:46 -06001071 else if (SUPPORT_64BIT_DATA && size == 8)
1072 *((ulong *)ptr) = i;
wdenk38635852002-08-27 05:55:31 +00001073 else if (size == 2)
York Sun76698b42014-02-12 15:55:35 -08001074 *((u16 *)ptr) = i;
wdenk38635852002-08-27 05:55:31 +00001075 else
York Sun76698b42014-02-12 15:55:35 -08001076 *((u8 *)ptr) = i;
wdenk38635852002-08-27 05:55:31 +00001077 if (incrflag)
1078 addr += size;
1079 }
1080 }
1081 } while (nbytes);
Simon Glass0628ab82013-02-24 17:33:15 +00001082 if (ptr)
1083 unmap_sysmem(ptr);
wdenk38635852002-08-27 05:55:31 +00001084
1085 mm_last_addr = addr;
1086 mm_last_size = size;
1087 return 0;
1088}
1089
Mike Frysinger710b9932010-12-21 14:19:51 -05001090#ifdef CONFIG_CMD_CRC32
1091
Simon Glass09140112020-05-10 11:40:03 -06001092static int do_mem_crc(struct cmd_tbl *cmdtp, int flag, int argc,
1093 char *const argv[])
wdenk38635852002-08-27 05:55:31 +00001094{
Simon Glassd20a40d2013-02-24 20:30:22 +00001095 int flags = 0;
1096 int ac;
1097 char * const *av;
wdenk38635852002-08-27 05:55:31 +00001098
Wolfgang Denk47e26b12010-07-17 01:06:04 +02001099 if (argc < 3)
Simon Glass4c12eeb2011-12-10 08:44:01 +00001100 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +00001101
wdenkc26e4542004-04-18 10:13:26 +00001102 av = argv + 1;
1103 ac = argc - 1;
Daniel Thompson221a9492017-05-19 17:26:58 +01001104#ifdef CONFIG_CRC32_VERIFY
wdenkc26e4542004-04-18 10:13:26 +00001105 if (strcmp(*av, "-v") == 0) {
Joe Hershbergera69bdba2015-05-05 12:23:53 -05001106 flags |= HASH_FLAG_VERIFY | HASH_FLAG_ENV;
wdenkc26e4542004-04-18 10:13:26 +00001107 av++;
1108 ac--;
wdenkc26e4542004-04-18 10:13:26 +00001109 }
Simon Glassd20a40d2013-02-24 20:30:22 +00001110#endif
wdenkc26e4542004-04-18 10:13:26 +00001111
Simon Glassd20a40d2013-02-24 20:30:22 +00001112 return hash_command("crc32", flags, cmdtp, flag, ac, av);
wdenkc26e4542004-04-18 10:13:26 +00001113}
wdenkc26e4542004-04-18 10:13:26 +00001114
Mike Frysinger710b9932010-12-21 14:19:51 -05001115#endif
1116
Jean-Jacques Hiblot803e1a32019-07-02 14:23:26 +02001117#ifdef CONFIG_CMD_RANDOM
Simon Glass09140112020-05-10 11:40:03 -06001118static int do_random(struct cmd_tbl *cmdtp, int flag, int argc,
1119 char *const argv[])
Jean-Jacques Hiblot803e1a32019-07-02 14:23:26 +02001120{
1121 unsigned long addr, len;
1122 unsigned long seed; // NOT INITIALIZED ON PURPOSE
1123 unsigned int *buf, *start;
1124 unsigned char *buf8;
1125 unsigned int i;
1126
Eugeniy Paltsev5f2c4e02020-03-20 19:38:17 +03001127 if (argc < 3 || argc > 4)
1128 return CMD_RET_USAGE;
Jean-Jacques Hiblot803e1a32019-07-02 14:23:26 +02001129
1130 len = simple_strtoul(argv[2], NULL, 16);
1131 addr = simple_strtoul(argv[1], NULL, 16);
1132
1133 if (argc == 4) {
1134 seed = simple_strtoul(argv[3], NULL, 16);
1135 if (seed == 0) {
1136 printf("The seed cannot be 0. Using 0xDEADBEEF.\n");
1137 seed = 0xDEADBEEF;
1138 }
1139 } else {
1140 seed = get_timer(0) ^ rand();
1141 }
1142
1143 srand(seed);
1144 start = map_sysmem(addr, len);
1145 buf = start;
1146 for (i = 0; i < (len / 4); i++)
1147 *buf++ = rand();
1148
1149 buf8 = (unsigned char *)buf;
1150 for (i = 0; i < (len % 4); i++)
1151 *buf8++ = rand() & 0xFF;
1152
1153 unmap_sysmem(start);
1154 printf("%lu bytes filled with random data\n", len);
Eugeniy Paltsev5f2c4e02020-03-20 19:38:17 +03001155
1156 return CMD_RET_SUCCESS;
Jean-Jacques Hiblot803e1a32019-07-02 14:23:26 +02001157}
1158#endif
1159
wdenk8bde7f72003-06-27 21:31:46 +00001160/**************************************************/
wdenk0d498392003-07-01 21:06:45 +00001161U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001162 md, 3, 1, do_mem_md,
Peter Tyser2fb26042009-01-27 18:03:12 -06001163 "memory display",
Simon Glass76be8f72020-06-02 19:26:45 -06001164 "[.b, .w, .l" HELP_Q "] address [# of objects]"
wdenk8bde7f72003-06-27 21:31:46 +00001165);
1166
1167
wdenk0d498392003-07-01 21:06:45 +00001168U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001169 mm, 2, 1, do_mem_mm,
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001170 "memory modify (auto-incrementing address)",
Simon Glass76be8f72020-06-02 19:26:45 -06001171 "[.b, .w, .l" HELP_Q "] address"
wdenk8bde7f72003-06-27 21:31:46 +00001172);
1173
1174
wdenk0d498392003-07-01 21:06:45 +00001175U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001176 nm, 2, 1, do_mem_nm,
Peter Tyser2fb26042009-01-27 18:03:12 -06001177 "memory modify (constant address)",
Simon Glass76be8f72020-06-02 19:26:45 -06001178 "[.b, .w, .l" HELP_Q "] address"
wdenk8bde7f72003-06-27 21:31:46 +00001179);
1180
wdenk0d498392003-07-01 21:06:45 +00001181U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001182 mw, 4, 1, do_mem_mw,
Peter Tyser2fb26042009-01-27 18:03:12 -06001183 "memory write (fill)",
Simon Glass76be8f72020-06-02 19:26:45 -06001184 "[.b, .w, .l" HELP_Q "] address value [count]"
wdenk8bde7f72003-06-27 21:31:46 +00001185);
1186
wdenk0d498392003-07-01 21:06:45 +00001187U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001188 cp, 4, 1, do_mem_cp,
Peter Tyser2fb26042009-01-27 18:03:12 -06001189 "memory copy",
Simon Glass76be8f72020-06-02 19:26:45 -06001190 "[.b, .w, .l" HELP_Q "] source target count"
wdenk8bde7f72003-06-27 21:31:46 +00001191);
1192
wdenk0d498392003-07-01 21:06:45 +00001193U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001194 cmp, 4, 1, do_mem_cmp,
Peter Tyser2fb26042009-01-27 18:03:12 -06001195 "memory compare",
Simon Glass76be8f72020-06-02 19:26:45 -06001196 "[.b, .w, .l" HELP_Q "] addr1 addr2 count"
wdenk8bde7f72003-06-27 21:31:46 +00001197);
1198
Mike Frysinger710b9932010-12-21 14:19:51 -05001199#ifdef CONFIG_CMD_CRC32
1200
Daniel Thompson221a9492017-05-19 17:26:58 +01001201#ifndef CONFIG_CRC32_VERIFY
wdenkc26e4542004-04-18 10:13:26 +00001202
wdenk0d498392003-07-01 21:06:45 +00001203U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001204 crc32, 4, 1, do_mem_crc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001205 "checksum calculation",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001206 "address count [addr]\n - compute CRC32 checksum [save at addr]"
wdenk8bde7f72003-06-27 21:31:46 +00001207);
1208
Daniel Thompson221a9492017-05-19 17:26:58 +01001209#else /* CONFIG_CRC32_VERIFY */
wdenkc26e4542004-04-18 10:13:26 +00001210
1211U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001212 crc32, 5, 1, do_mem_crc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001213 "checksum calculation",
wdenkc26e4542004-04-18 10:13:26 +00001214 "address count [addr]\n - compute CRC32 checksum [save at addr]\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001215 "-v address count crc\n - verify crc of memory area"
wdenkc26e4542004-04-18 10:13:26 +00001216);
1217
Daniel Thompson221a9492017-05-19 17:26:58 +01001218#endif /* CONFIG_CRC32_VERIFY */
wdenkc26e4542004-04-18 10:13:26 +00001219
Mike Frysinger710b9932010-12-21 14:19:51 -05001220#endif
1221
Simon Glass15a33e42012-11-30 13:01:20 +00001222#ifdef CONFIG_CMD_MEMINFO
Simon Glass09140112020-05-10 11:40:03 -06001223static int do_mem_info(struct cmd_tbl *cmdtp, int flag, int argc,
1224 char *const argv[])
Simon Glass15a33e42012-11-30 13:01:20 +00001225{
Simon Glass428a6a12019-11-14 12:57:44 -07001226 puts("DRAM: ");
1227 print_size(gd->ram_size, "\n");
Simon Glass15a33e42012-11-30 13:01:20 +00001228
1229 return 0;
1230}
1231#endif
1232
wdenk0d498392003-07-01 21:06:45 +00001233U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001234 base, 2, 1, do_mem_base,
Peter Tyser2fb26042009-01-27 18:03:12 -06001235 "print or set address offset",
wdenk8bde7f72003-06-27 21:31:46 +00001236 "\n - print address offset for memory commands\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001237 "base off\n - set address offset for memory commands to 'off'"
wdenk8bde7f72003-06-27 21:31:46 +00001238);
1239
wdenk0d498392003-07-01 21:06:45 +00001240U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001241 loop, 3, 1, do_mem_loop,
Peter Tyser2fb26042009-01-27 18:03:12 -06001242 "infinite loop on address range",
Simon Glass76be8f72020-06-02 19:26:45 -06001243 "[.b, .w, .l" HELP_Q "] address number_of_objects"
wdenk8bde7f72003-06-27 21:31:46 +00001244);
1245
wdenk56523f12004-07-11 17:40:54 +00001246#ifdef CONFIG_LOOPW
1247U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001248 loopw, 4, 1, do_mem_loopw,
Peter Tyser2fb26042009-01-27 18:03:12 -06001249 "infinite write loop on address range",
Simon Glass76be8f72020-06-02 19:26:45 -06001250 "[.b, .w, .l" HELP_Q "] address number_of_objects data_to_write"
wdenk56523f12004-07-11 17:40:54 +00001251);
1252#endif /* CONFIG_LOOPW */
1253
Wolfgang Denka2681702013-03-08 10:51:32 +00001254#ifdef CONFIG_CMD_MEMTEST
wdenk0d498392003-07-01 21:06:45 +00001255U_BOOT_CMD(
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +01001256 mtest, 5, 1, do_mem_mtest,
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001257 "simple RAM read/write test",
1258 "[start [end [pattern [iterations]]]]"
wdenk8bde7f72003-06-27 21:31:46 +00001259);
Wolfgang Denka2681702013-03-08 10:51:32 +00001260#endif /* CONFIG_CMD_MEMTEST */
wdenk8bde7f72003-06-27 21:31:46 +00001261
Joel Johnson72732312020-01-29 09:17:18 -07001262#ifdef CONFIG_CMD_MX_CYCLIC
stroese4aaf29b2004-12-16 17:42:39 +00001263U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001264 mdc, 4, 1, do_mem_mdc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001265 "memory display cyclic",
Simon Glass76be8f72020-06-02 19:26:45 -06001266 "[.b, .w, .l" HELP_Q "] address count delay(ms)"
stroese4aaf29b2004-12-16 17:42:39 +00001267);
1268
1269U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001270 mwc, 4, 1, do_mem_mwc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001271 "memory write cyclic",
Simon Glass76be8f72020-06-02 19:26:45 -06001272 "[.b, .w, .l" HELP_Q "] address value delay(ms)"
stroese4aaf29b2004-12-16 17:42:39 +00001273);
Joel Johnson72732312020-01-29 09:17:18 -07001274#endif /* CONFIG_CMD_MX_CYCLIC */
Simon Glass15a33e42012-11-30 13:01:20 +00001275
1276#ifdef CONFIG_CMD_MEMINFO
1277U_BOOT_CMD(
1278 meminfo, 3, 1, do_mem_info,
1279 "display memory information",
1280 ""
1281);
1282#endif
Jean-Jacques Hiblot803e1a32019-07-02 14:23:26 +02001283
1284#ifdef CONFIG_CMD_RANDOM
1285U_BOOT_CMD(
1286 random, 4, 0, do_random,
1287 "fill memory with random pattern",
1288 "<addr> <len> [<seed>]\n"
1289 " - Fill 'len' bytes of memory starting at 'addr' with random data\n"
1290);
1291#endif