blob: 9b97f7bf694458e39e31ed981504790c6bf6d986 [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
36static int mod_mem(struct cmd_tbl *, int, int, int, char * const []);
wdenk38635852002-08-27 05:55:31 +000037
38/* Display values from last command.
39 * Memory modify remembered values are different from display memory.
40 */
Scott Wood581508b2015-03-19 09:43:12 -070041static ulong dp_last_addr, dp_last_size;
42static ulong dp_last_length = 0x40;
43static ulong mm_last_addr, mm_last_size;
wdenk38635852002-08-27 05:55:31 +000044
45static ulong base_address = 0;
46
47/* Memory Display
48 *
49 * Syntax:
York Sun4d1fd7f2014-02-26 17:03:19 -080050 * md{.b, .w, .l, .q} {addr} {len}
wdenk38635852002-08-27 05:55:31 +000051 */
52#define DISP_LINE_LEN 16
Simon Glass09140112020-05-10 11:40:03 -060053static int do_mem_md(struct cmd_tbl *cmdtp, int flag, int argc,
54 char *const argv[])
wdenk38635852002-08-27 05:55:31 +000055{
Tuomas Tynkkynenc68c03f2017-10-10 21:59:42 +030056 ulong addr, length, bytes;
57 const void *buf;
wdenk27b207f2003-07-24 23:38:38 +000058 int size;
wdenk38635852002-08-27 05:55:31 +000059 int rc = 0;
60
61 /* We use the last specified parameters, unless new ones are
62 * entered.
63 */
64 addr = dp_last_addr;
65 size = dp_last_size;
66 length = dp_last_length;
67
Wolfgang Denk47e26b12010-07-17 01:06:04 +020068 if (argc < 2)
Simon Glass4c12eeb2011-12-10 08:44:01 +000069 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +000070
71 if ((flag & CMD_FLAG_REPEAT) == 0) {
72 /* New command specified. Check for a size specification.
73 * Defaults to long if no or incorrect specification.
74 */
wdenk27b207f2003-07-24 23:38:38 +000075 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
76 return 1;
wdenk38635852002-08-27 05:55:31 +000077
78 /* Address is specified since argc > 1
79 */
80 addr = simple_strtoul(argv[1], NULL, 16);
81 addr += base_address;
82
83 /* If another parameter, it is the length to display.
84 * Length is the number of objects, not number of bytes.
85 */
86 if (argc > 2)
87 length = simple_strtoul(argv[2], NULL, 16);
88 }
89
Tuomas Tynkkynenc68c03f2017-10-10 21:59:42 +030090 bytes = size * length;
91 buf = map_sysmem(addr, bytes);
wdenk2abbe072003-06-16 23:50:08 +000092
Tuomas Tynkkynenc68c03f2017-10-10 21:59:42 +030093 /* Print the lines. */
94 print_buffer(addr, buf, size, length, DISP_LINE_LEN / size);
95 addr += bytes;
96 unmap_sysmem(buf);
wdenk38635852002-08-27 05:55:31 +000097
98 dp_last_addr = addr;
99 dp_last_length = length;
100 dp_last_size = size;
101 return (rc);
102}
103
Simon Glass09140112020-05-10 11:40:03 -0600104static int do_mem_mm(struct cmd_tbl *cmdtp, int flag, int argc,
105 char *const argv[])
wdenk38635852002-08-27 05:55:31 +0000106{
107 return mod_mem (cmdtp, 1, flag, argc, argv);
108}
Simon Glass09140112020-05-10 11:40:03 -0600109
110static int do_mem_nm(struct cmd_tbl *cmdtp, int flag, int argc,
111 char *const argv[])
wdenk38635852002-08-27 05:55:31 +0000112{
113 return mod_mem (cmdtp, 0, flag, argc, argv);
114}
115
Simon Glass09140112020-05-10 11:40:03 -0600116static int do_mem_mw(struct cmd_tbl *cmdtp, int flag, int argc,
117 char *const argv[])
wdenk38635852002-08-27 05:55:31 +0000118{
Simon Glass4d979bf2019-12-28 10:45:10 -0700119#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -0800120 u64 writeval;
121#else
122 ulong writeval;
123#endif
124 ulong addr, count;
wdenk27b207f2003-07-24 23:38:38 +0000125 int size;
Simon Glasscc5e1962015-03-05 12:25:18 -0700126 void *buf, *start;
Simon Glass0628ab82013-02-24 17:33:15 +0000127 ulong bytes;
wdenk38635852002-08-27 05:55:31 +0000128
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200129 if ((argc < 3) || (argc > 4))
Simon Glass4c12eeb2011-12-10 08:44:01 +0000130 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000131
132 /* Check for size specification.
133 */
wdenk27b207f2003-07-24 23:38:38 +0000134 if ((size = cmd_get_data_size(argv[0], 4)) < 1)
135 return 1;
wdenk38635852002-08-27 05:55:31 +0000136
137 /* Address is specified since argc > 1
138 */
139 addr = simple_strtoul(argv[1], NULL, 16);
140 addr += base_address;
141
142 /* Get the value to write.
143 */
Simon Glass4d979bf2019-12-28 10:45:10 -0700144#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -0800145 writeval = simple_strtoull(argv[2], NULL, 16);
146#else
wdenk38635852002-08-27 05:55:31 +0000147 writeval = simple_strtoul(argv[2], NULL, 16);
York Sun4d1fd7f2014-02-26 17:03:19 -0800148#endif
wdenk38635852002-08-27 05:55:31 +0000149
150 /* Count ? */
151 if (argc == 4) {
152 count = simple_strtoul(argv[3], NULL, 16);
153 } else {
154 count = 1;
155 }
156
Simon Glass0628ab82013-02-24 17:33:15 +0000157 bytes = size * count;
Simon Glasscc5e1962015-03-05 12:25:18 -0700158 start = map_sysmem(addr, bytes);
159 buf = start;
wdenk38635852002-08-27 05:55:31 +0000160 while (count-- > 0) {
161 if (size == 4)
York Sun76698b42014-02-12 15:55:35 -0800162 *((u32 *)buf) = (u32)writeval;
Simon Glass4d979bf2019-12-28 10:45:10 -0700163#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -0800164 else if (size == 8)
165 *((u64 *)buf) = (u64)writeval;
166#endif
wdenk38635852002-08-27 05:55:31 +0000167 else if (size == 2)
York Sun76698b42014-02-12 15:55:35 -0800168 *((u16 *)buf) = (u16)writeval;
wdenk38635852002-08-27 05:55:31 +0000169 else
York Sun76698b42014-02-12 15:55:35 -0800170 *((u8 *)buf) = (u8)writeval;
Simon Glass0628ab82013-02-24 17:33:15 +0000171 buf += size;
wdenk38635852002-08-27 05:55:31 +0000172 }
Simon Glasscc5e1962015-03-05 12:25:18 -0700173 unmap_sysmem(start);
wdenk38635852002-08-27 05:55:31 +0000174 return 0;
175}
176
Joel Johnson72732312020-01-29 09:17:18 -0700177#ifdef CONFIG_CMD_MX_CYCLIC
Simon Glass09140112020-05-10 11:40:03 -0600178static int do_mem_mdc(struct cmd_tbl *cmdtp, int flag, int argc,
179 char *const argv[])
stroese4aaf29b2004-12-16 17:42:39 +0000180{
181 int i;
182 ulong count;
183
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200184 if (argc < 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000185 return CMD_RET_USAGE;
stroese4aaf29b2004-12-16 17:42:39 +0000186
187 count = simple_strtoul(argv[3], NULL, 10);
188
189 for (;;) {
190 do_mem_md (NULL, 0, 3, argv);
191
192 /* delay for <count> ms... */
193 for (i=0; i<count; i++)
Simon Glass07e11142020-05-10 11:40:10 -0600194 udelay(1000);
stroese4aaf29b2004-12-16 17:42:39 +0000195
196 /* check for ctrl-c to abort... */
197 if (ctrlc()) {
198 puts("Abort\n");
199 return 0;
200 }
201 }
202
203 return 0;
204}
205
Simon Glass09140112020-05-10 11:40:03 -0600206static int do_mem_mwc(struct cmd_tbl *cmdtp, int flag, int argc,
207 char *const argv[])
stroese4aaf29b2004-12-16 17:42:39 +0000208{
209 int i;
210 ulong count;
211
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200212 if (argc < 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000213 return CMD_RET_USAGE;
stroese4aaf29b2004-12-16 17:42:39 +0000214
215 count = simple_strtoul(argv[3], NULL, 10);
216
217 for (;;) {
218 do_mem_mw (NULL, 0, 3, argv);
219
220 /* delay for <count> ms... */
221 for (i=0; i<count; i++)
Simon Glass07e11142020-05-10 11:40:10 -0600222 udelay(1000);
stroese4aaf29b2004-12-16 17:42:39 +0000223
224 /* check for ctrl-c to abort... */
225 if (ctrlc()) {
226 puts("Abort\n");
227 return 0;
228 }
229 }
230
231 return 0;
232}
Joel Johnson72732312020-01-29 09:17:18 -0700233#endif /* CONFIG_CMD_MX_CYCLIC */
stroese4aaf29b2004-12-16 17:42:39 +0000234
Simon Glass09140112020-05-10 11:40:03 -0600235static int do_mem_cmp(struct cmd_tbl *cmdtp, int flag, int argc,
236 char *const argv[])
wdenk38635852002-08-27 05:55:31 +0000237{
Simon Glass0628ab82013-02-24 17:33:15 +0000238 ulong addr1, addr2, count, ngood, bytes;
wdenk27b207f2003-07-24 23:38:38 +0000239 int size;
wdenk38635852002-08-27 05:55:31 +0000240 int rcode = 0;
Mike Frysinger054ea172012-01-20 09:07:21 +0000241 const char *type;
Simon Glass0628ab82013-02-24 17:33:15 +0000242 const void *buf1, *buf2, *base;
Simon Glass4d979bf2019-12-28 10:45:10 -0700243#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -0800244 u64 word1, word2;
245#else
246 ulong word1, word2;
247#endif
wdenk38635852002-08-27 05:55:31 +0000248
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200249 if (argc != 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000250 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000251
252 /* Check for size specification.
253 */
wdenk27b207f2003-07-24 23:38:38 +0000254 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
255 return 1;
York Sun4d1fd7f2014-02-26 17:03:19 -0800256 type = size == 8 ? "double word" :
257 size == 4 ? "word" :
258 size == 2 ? "halfword" : "byte";
wdenk38635852002-08-27 05:55:31 +0000259
260 addr1 = simple_strtoul(argv[1], NULL, 16);
261 addr1 += base_address;
262
263 addr2 = simple_strtoul(argv[2], NULL, 16);
264 addr2 += base_address;
265
266 count = simple_strtoul(argv[3], NULL, 16);
267
Simon Glass0628ab82013-02-24 17:33:15 +0000268 bytes = size * count;
269 base = buf1 = map_sysmem(addr1, bytes);
270 buf2 = map_sysmem(addr2, bytes);
Mike Frysingerfeb12a12012-01-20 09:07:22 +0000271 for (ngood = 0; ngood < count; ++ngood) {
wdenk38635852002-08-27 05:55:31 +0000272 if (size == 4) {
York Sun76698b42014-02-12 15:55:35 -0800273 word1 = *(u32 *)buf1;
274 word2 = *(u32 *)buf2;
Simon Glass4d979bf2019-12-28 10:45:10 -0700275#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -0800276 } else if (size == 8) {
277 word1 = *(u64 *)buf1;
278 word2 = *(u64 *)buf2;
279#endif
Mike Frysinger054ea172012-01-20 09:07:21 +0000280 } else if (size == 2) {
York Sun76698b42014-02-12 15:55:35 -0800281 word1 = *(u16 *)buf1;
282 word2 = *(u16 *)buf2;
Mike Frysinger054ea172012-01-20 09:07:21 +0000283 } else {
York Sun76698b42014-02-12 15:55:35 -0800284 word1 = *(u8 *)buf1;
285 word2 = *(u8 *)buf2;
wdenk38635852002-08-27 05:55:31 +0000286 }
Mike Frysinger054ea172012-01-20 09:07:21 +0000287 if (word1 != word2) {
Simon Glass0628ab82013-02-24 17:33:15 +0000288 ulong offset = buf1 - base;
Simon Glass4d979bf2019-12-28 10:45:10 -0700289#ifdef MEM_SUPPORT_64BIT_DATA
Masahiro Yamadadee37fc2018-08-06 20:47:40 +0900290 printf("%s at 0x%p (%#0*llx) != %s at 0x%p (%#0*llx)\n",
York Sun4d1fd7f2014-02-26 17:03:19 -0800291 type, (void *)(addr1 + offset), size, word1,
292 type, (void *)(addr2 + offset), size, word2);
293#else
Mike Frysinger054ea172012-01-20 09:07:21 +0000294 printf("%s at 0x%08lx (%#0*lx) != %s at 0x%08lx (%#0*lx)\n",
Simon Glass0628ab82013-02-24 17:33:15 +0000295 type, (ulong)(addr1 + offset), size, word1,
296 type, (ulong)(addr2 + offset), size, word2);
York Sun4d1fd7f2014-02-26 17:03:19 -0800297#endif
Mike Frysinger054ea172012-01-20 09:07:21 +0000298 rcode = 1;
299 break;
wdenk38635852002-08-27 05:55:31 +0000300 }
Mike Frysinger054ea172012-01-20 09:07:21 +0000301
Simon Glass0628ab82013-02-24 17:33:15 +0000302 buf1 += size;
303 buf2 += size;
Stefan Roeseeaadb442010-09-13 11:10:34 +0200304
305 /* reset watchdog from time to time */
Mike Frysingerfeb12a12012-01-20 09:07:22 +0000306 if ((ngood % (64 << 10)) == 0)
Stefan Roeseeaadb442010-09-13 11:10:34 +0200307 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000308 }
Simon Glass0628ab82013-02-24 17:33:15 +0000309 unmap_sysmem(buf1);
310 unmap_sysmem(buf2);
wdenk38635852002-08-27 05:55:31 +0000311
Mike Frysinger054ea172012-01-20 09:07:21 +0000312 printf("Total of %ld %s(s) were the same\n", ngood, type);
wdenk38635852002-08-27 05:55:31 +0000313 return rcode;
314}
315
Simon Glass09140112020-05-10 11:40:03 -0600316static int do_mem_cp(struct cmd_tbl *cmdtp, int flag, int argc,
317 char *const argv[])
wdenk38635852002-08-27 05:55:31 +0000318{
Fabio Estevamc2538422016-12-15 16:00:13 -0200319 ulong addr, dest, count;
Philippe Reynes787f10a2019-12-02 17:33:22 +0100320 void *src, *dst;
wdenk27b207f2003-07-24 23:38:38 +0000321 int size;
wdenk38635852002-08-27 05:55:31 +0000322
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200323 if (argc != 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000324 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000325
326 /* Check for size specification.
327 */
wdenk27b207f2003-07-24 23:38:38 +0000328 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
329 return 1;
wdenk38635852002-08-27 05:55:31 +0000330
331 addr = simple_strtoul(argv[1], NULL, 16);
332 addr += base_address;
333
334 dest = simple_strtoul(argv[2], NULL, 16);
335 dest += base_address;
336
337 count = simple_strtoul(argv[3], NULL, 16);
338
339 if (count == 0) {
340 puts ("Zero length ???\n");
341 return 1;
342 }
343
Philippe Reynes787f10a2019-12-02 17:33:22 +0100344 src = map_sysmem(addr, count * size);
345 dst = map_sysmem(dest, count * size);
346
Masahiro Yamadae856bdc2017-02-11 22:43:54 +0900347#ifdef CONFIG_MTD_NOR_FLASH
wdenk38635852002-08-27 05:55:31 +0000348 /* check if we are copying to Flash */
Philippe Reynes787f10a2019-12-02 17:33:22 +0100349 if (addr2info((ulong)dst)) {
wdenk38635852002-08-27 05:55:31 +0000350 int rc;
351
wdenk4b9206e2004-03-23 22:14:11 +0000352 puts ("Copy to Flash... ");
wdenk38635852002-08-27 05:55:31 +0000353
Philippe Reynes787f10a2019-12-02 17:33:22 +0100354 rc = flash_write((char *)src, (ulong)dst, count * size);
wdenk38635852002-08-27 05:55:31 +0000355 if (rc != 0) {
Simon Glass0ee482522019-12-28 10:44:40 -0700356 flash_perror(rc);
Philippe Reynes787f10a2019-12-02 17:33:22 +0100357 unmap_sysmem(src);
358 unmap_sysmem(dst);
wdenk38635852002-08-27 05:55:31 +0000359 return (1);
360 }
361 puts ("done\n");
Philippe Reynes787f10a2019-12-02 17:33:22 +0100362 unmap_sysmem(src);
363 unmap_sysmem(dst);
wdenk38635852002-08-27 05:55:31 +0000364 return 0;
365 }
366#endif
367
Philippe Reynes787f10a2019-12-02 17:33:22 +0100368 memcpy(dst, src, count * size);
Masahiro Yamadaa3a47492014-10-23 17:46:24 +0900369
Philippe Reynes787f10a2019-12-02 17:33:22 +0100370 unmap_sysmem(src);
371 unmap_sysmem(dst);
wdenk38635852002-08-27 05:55:31 +0000372 return 0;
373}
374
Simon Glass09140112020-05-10 11:40:03 -0600375static int do_mem_base(struct cmd_tbl *cmdtp, int flag, int argc,
376 char *const argv[])
wdenk38635852002-08-27 05:55:31 +0000377{
378 if (argc > 1) {
379 /* Set new base address.
380 */
381 base_address = simple_strtoul(argv[1], NULL, 16);
382 }
383 /* Print the current base address.
384 */
385 printf("Base Address: 0x%08lx\n", base_address);
386 return 0;
387}
388
Simon Glass09140112020-05-10 11:40:03 -0600389static int do_mem_loop(struct cmd_tbl *cmdtp, int flag, int argc,
390 char *const argv[])
wdenk38635852002-08-27 05:55:31 +0000391{
Simon Glass0628ab82013-02-24 17:33:15 +0000392 ulong addr, length, i, bytes;
wdenk27b207f2003-07-24 23:38:38 +0000393 int size;
Simon Glass4d979bf2019-12-28 10:45:10 -0700394#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -0800395 volatile u64 *llp;
396#endif
York Sun76698b42014-02-12 15:55:35 -0800397 volatile u32 *longp;
398 volatile u16 *shortp;
399 volatile u8 *cp;
Simon Glass0628ab82013-02-24 17:33:15 +0000400 const void *buf;
wdenk38635852002-08-27 05:55:31 +0000401
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200402 if (argc < 3)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000403 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000404
Robert P. J. Day85de63e2013-02-03 02:29:54 +0000405 /*
406 * Check for a size specification.
wdenk38635852002-08-27 05:55:31 +0000407 * Defaults to long if no or incorrect specification.
408 */
wdenk27b207f2003-07-24 23:38:38 +0000409 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
410 return 1;
wdenk38635852002-08-27 05:55:31 +0000411
412 /* Address is always specified.
413 */
414 addr = simple_strtoul(argv[1], NULL, 16);
415
416 /* Length is the number of objects, not number of bytes.
417 */
418 length = simple_strtoul(argv[2], NULL, 16);
419
Simon Glass0628ab82013-02-24 17:33:15 +0000420 bytes = size * length;
421 buf = map_sysmem(addr, bytes);
422
wdenk38635852002-08-27 05:55:31 +0000423 /* We want to optimize the loops to run as fast as possible.
424 * If we have only one object, just run infinite loops.
425 */
426 if (length == 1) {
Simon Glass4d979bf2019-12-28 10:45:10 -0700427#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -0800428 if (size == 8) {
429 llp = (u64 *)buf;
430 for (;;)
431 i = *llp;
432 }
433#endif
wdenk38635852002-08-27 05:55:31 +0000434 if (size == 4) {
York Sun76698b42014-02-12 15:55:35 -0800435 longp = (u32 *)buf;
wdenk38635852002-08-27 05:55:31 +0000436 for (;;)
437 i = *longp;
438 }
439 if (size == 2) {
York Sun76698b42014-02-12 15:55:35 -0800440 shortp = (u16 *)buf;
wdenk38635852002-08-27 05:55:31 +0000441 for (;;)
442 i = *shortp;
443 }
York Sun76698b42014-02-12 15:55:35 -0800444 cp = (u8 *)buf;
wdenk38635852002-08-27 05:55:31 +0000445 for (;;)
446 i = *cp;
447 }
448
Simon Glass4d979bf2019-12-28 10:45:10 -0700449#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -0800450 if (size == 8) {
451 for (;;) {
452 llp = (u64 *)buf;
453 i = length;
454 while (i-- > 0)
455 *llp++;
456 }
457 }
458#endif
wdenk38635852002-08-27 05:55:31 +0000459 if (size == 4) {
460 for (;;) {
York Sun76698b42014-02-12 15:55:35 -0800461 longp = (u32 *)buf;
wdenk38635852002-08-27 05:55:31 +0000462 i = length;
463 while (i-- > 0)
Marek Vasutf3b3c3d2011-09-26 02:26:06 +0200464 *longp++;
wdenk38635852002-08-27 05:55:31 +0000465 }
466 }
467 if (size == 2) {
468 for (;;) {
York Sun76698b42014-02-12 15:55:35 -0800469 shortp = (u16 *)buf;
wdenk38635852002-08-27 05:55:31 +0000470 i = length;
471 while (i-- > 0)
Marek Vasutf3b3c3d2011-09-26 02:26:06 +0200472 *shortp++;
wdenk38635852002-08-27 05:55:31 +0000473 }
474 }
475 for (;;) {
York Sun76698b42014-02-12 15:55:35 -0800476 cp = (u8 *)buf;
wdenk38635852002-08-27 05:55:31 +0000477 i = length;
478 while (i-- > 0)
Marek Vasutf3b3c3d2011-09-26 02:26:06 +0200479 *cp++;
wdenk38635852002-08-27 05:55:31 +0000480 }
Simon Glass0628ab82013-02-24 17:33:15 +0000481 unmap_sysmem(buf);
Simon Glass92765f422013-06-11 11:14:35 -0700482
483 return 0;
wdenk38635852002-08-27 05:55:31 +0000484}
485
wdenk56523f12004-07-11 17:40:54 +0000486#ifdef CONFIG_LOOPW
Simon Glass09140112020-05-10 11:40:03 -0600487static int do_mem_loopw(struct cmd_tbl *cmdtp, int flag, int argc,
488 char *const argv[])
wdenk56523f12004-07-11 17:40:54 +0000489{
York Sun4d1fd7f2014-02-26 17:03:19 -0800490 ulong addr, length, i, bytes;
wdenk56523f12004-07-11 17:40:54 +0000491 int size;
Simon Glass4d979bf2019-12-28 10:45:10 -0700492#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -0800493 volatile u64 *llp;
494 u64 data;
495#else
496 ulong data;
497#endif
York Sun76698b42014-02-12 15:55:35 -0800498 volatile u32 *longp;
499 volatile u16 *shortp;
500 volatile u8 *cp;
Simon Glass0628ab82013-02-24 17:33:15 +0000501 void *buf;
wdenk81050922004-07-11 20:04:51 +0000502
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200503 if (argc < 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000504 return CMD_RET_USAGE;
wdenk56523f12004-07-11 17:40:54 +0000505
Robert P. J. Day85de63e2013-02-03 02:29:54 +0000506 /*
507 * Check for a size specification.
wdenk56523f12004-07-11 17:40:54 +0000508 * Defaults to long if no or incorrect specification.
509 */
510 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
511 return 1;
512
513 /* Address is always specified.
514 */
515 addr = simple_strtoul(argv[1], NULL, 16);
516
517 /* Length is the number of objects, not number of bytes.
518 */
519 length = simple_strtoul(argv[2], NULL, 16);
520
521 /* data to write */
Simon Glass4d979bf2019-12-28 10:45:10 -0700522#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -0800523 data = simple_strtoull(argv[3], NULL, 16);
524#else
wdenk56523f12004-07-11 17:40:54 +0000525 data = simple_strtoul(argv[3], NULL, 16);
York Sun4d1fd7f2014-02-26 17:03:19 -0800526#endif
wdenk81050922004-07-11 20:04:51 +0000527
Simon Glass0628ab82013-02-24 17:33:15 +0000528 bytes = size * length;
529 buf = map_sysmem(addr, bytes);
530
wdenk56523f12004-07-11 17:40:54 +0000531 /* We want to optimize the loops to run as fast as possible.
532 * If we have only one object, just run infinite loops.
533 */
534 if (length == 1) {
Simon Glass4d979bf2019-12-28 10:45:10 -0700535#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -0800536 if (size == 8) {
537 llp = (u64 *)buf;
538 for (;;)
539 *llp = data;
540 }
541#endif
wdenk56523f12004-07-11 17:40:54 +0000542 if (size == 4) {
York Sun76698b42014-02-12 15:55:35 -0800543 longp = (u32 *)buf;
wdenk56523f12004-07-11 17:40:54 +0000544 for (;;)
545 *longp = data;
York Sun4d1fd7f2014-02-26 17:03:19 -0800546 }
wdenk56523f12004-07-11 17:40:54 +0000547 if (size == 2) {
York Sun76698b42014-02-12 15:55:35 -0800548 shortp = (u16 *)buf;
wdenk56523f12004-07-11 17:40:54 +0000549 for (;;)
550 *shortp = data;
551 }
York Sun76698b42014-02-12 15:55:35 -0800552 cp = (u8 *)buf;
wdenk56523f12004-07-11 17:40:54 +0000553 for (;;)
554 *cp = data;
555 }
556
Simon Glass4d979bf2019-12-28 10:45:10 -0700557#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -0800558 if (size == 8) {
559 for (;;) {
560 llp = (u64 *)buf;
561 i = length;
562 while (i-- > 0)
563 *llp++ = data;
564 }
565 }
566#endif
wdenk56523f12004-07-11 17:40:54 +0000567 if (size == 4) {
568 for (;;) {
York Sun76698b42014-02-12 15:55:35 -0800569 longp = (u32 *)buf;
wdenk56523f12004-07-11 17:40:54 +0000570 i = length;
571 while (i-- > 0)
572 *longp++ = data;
573 }
574 }
575 if (size == 2) {
576 for (;;) {
York Sun76698b42014-02-12 15:55:35 -0800577 shortp = (u16 *)buf;
wdenk56523f12004-07-11 17:40:54 +0000578 i = length;
579 while (i-- > 0)
580 *shortp++ = data;
581 }
582 }
583 for (;;) {
York Sun76698b42014-02-12 15:55:35 -0800584 cp = (u8 *)buf;
wdenk56523f12004-07-11 17:40:54 +0000585 i = length;
586 while (i-- > 0)
587 *cp++ = data;
588 }
589}
590#endif /* CONFIG_LOOPW */
591
Tom Rini68149e92013-03-12 10:07:19 -0400592#ifdef CONFIG_CMD_MEMTEST
Simon Glass5512d5b2013-02-28 17:47:14 +0000593static ulong mem_test_alt(vu_long *buf, ulong start_addr, ulong end_addr,
594 vu_long *dummy)
wdenk38635852002-08-27 05:55:31 +0000595{
Simon Glassc9638f52013-02-24 17:33:16 +0000596 vu_long *addr;
Simon Glassc9638f52013-02-24 17:33:16 +0000597 ulong errs = 0;
598 ulong val, readback;
599 int j;
Simon Glassc9638f52013-02-24 17:33:16 +0000600 vu_long offset;
601 vu_long test_offset;
602 vu_long pattern;
603 vu_long temp;
604 vu_long anti_pattern;
605 vu_long num_words;
wdenk38635852002-08-27 05:55:31 +0000606 static const ulong bitpattern[] = {
607 0x00000001, /* single bit */
608 0x00000003, /* two adjacent bits */
609 0x00000007, /* three adjacent bits */
610 0x0000000F, /* four adjacent bits */
611 0x00000005, /* two non-adjacent bits */
612 0x00000015, /* three non-adjacent bits */
613 0x00000055, /* four non-adjacent bits */
614 0xaaaaaaaa, /* alternating 1/0 */
615 };
wdenk38635852002-08-27 05:55:31 +0000616
Simon Glass5512d5b2013-02-28 17:47:14 +0000617 num_words = (end_addr - start_addr) / sizeof(vu_long);
Simon Glass8c86bbe2013-02-24 17:33:20 +0000618
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000619 /*
620 * Data line test: write a pattern to the first
621 * location, write the 1's complement to a 'parking'
622 * address (changes the state of the data bus so a
623 * floating bus doesn't give a false OK), and then
624 * read the value back. Note that we read it back
625 * into a variable because the next time we read it,
626 * it might be right (been there, tough to explain to
627 * the quality guys why it prints a failure when the
628 * "is" and "should be" are obviously the same in the
629 * error message).
630 *
631 * Rather than exhaustively testing, we test some
632 * patterns by shifting '1' bits through a field of
633 * '0's and '0' bits through a field of '1's (i.e.
634 * pattern and ~pattern).
635 */
Simon Glass5512d5b2013-02-28 17:47:14 +0000636 addr = buf;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000637 for (j = 0; j < sizeof(bitpattern) / sizeof(bitpattern[0]); j++) {
638 val = bitpattern[j];
639 for (; val != 0; val <<= 1) {
Simon Glass5512d5b2013-02-28 17:47:14 +0000640 *addr = val;
Simon Glassc9638f52013-02-24 17:33:16 +0000641 *dummy = ~val; /* clear the test data off the bus */
wdenk38635852002-08-27 05:55:31 +0000642 readback = *addr;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000643 if (readback != val) {
Simon Glassc9638f52013-02-24 17:33:16 +0000644 printf("FAILURE (data line): "
645 "expected %08lx, actual %08lx\n",
646 val, readback);
647 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000648 if (ctrlc())
Simon Glass51209b12013-02-24 17:33:17 +0000649 return -1;
wdenk38635852002-08-27 05:55:31 +0000650 }
651 *addr = ~val;
652 *dummy = val;
653 readback = *addr;
Simon Glassc9638f52013-02-24 17:33:16 +0000654 if (readback != ~val) {
655 printf("FAILURE (data line): "
656 "Is %08lx, should be %08lx\n",
657 readback, ~val);
658 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000659 if (ctrlc())
Simon Glass51209b12013-02-24 17:33:17 +0000660 return -1;
wdenk38635852002-08-27 05:55:31 +0000661 }
wdenk38635852002-08-27 05:55:31 +0000662 }
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000663 }
wdenk38635852002-08-27 05:55:31 +0000664
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000665 /*
666 * Based on code whose Original Author and Copyright
667 * information follows: Copyright (c) 1998 by Michael
668 * Barr. This software is placed into the public
669 * domain and may be used for any purpose. However,
670 * this notice must not be changed or removed and no
671 * warranty is either expressed or implied by its
672 * publication or distribution.
673 */
wdenk38635852002-08-27 05:55:31 +0000674
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000675 /*
676 * Address line test
wdenk38635852002-08-27 05:55:31 +0000677
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000678 * Description: Test the address bus wiring in a
679 * memory region by performing a walking
680 * 1's test on the relevant bits of the
681 * address and checking for aliasing.
682 * This test will find single-bit
683 * address failures such as stuck-high,
684 * stuck-low, and shorted pins. The base
685 * address and size of the region are
686 * selected by the caller.
wdenk38635852002-08-27 05:55:31 +0000687
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000688 * Notes: For best results, the selected base
689 * address should have enough LSB 0's to
690 * guarantee single address bit changes.
691 * For example, to test a 64-Kbyte
692 * region, select a base address on a
693 * 64-Kbyte boundary. Also, select the
694 * region size as a power-of-two if at
695 * all possible.
696 *
697 * Returns: 0 if the test succeeds, 1 if the test fails.
698 */
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000699 pattern = (vu_long) 0xaaaaaaaa;
700 anti_pattern = (vu_long) 0x55555555;
wdenk38635852002-08-27 05:55:31 +0000701
Simon Glass5512d5b2013-02-28 17:47:14 +0000702 debug("%s:%d: length = 0x%.8lx\n", __func__, __LINE__, num_words);
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000703 /*
704 * Write the default pattern at each of the
705 * power-of-two offsets.
706 */
Simon Glass5512d5b2013-02-28 17:47:14 +0000707 for (offset = 1; offset < num_words; offset <<= 1)
708 addr[offset] = pattern;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000709
710 /*
711 * Check for address bits stuck high.
712 */
713 test_offset = 0;
Simon Glass5512d5b2013-02-28 17:47:14 +0000714 addr[test_offset] = anti_pattern;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000715
Simon Glass5512d5b2013-02-28 17:47:14 +0000716 for (offset = 1; offset < num_words; offset <<= 1) {
717 temp = addr[offset];
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000718 if (temp != pattern) {
Simon Glassc9638f52013-02-24 17:33:16 +0000719 printf("\nFAILURE: Address bit stuck high @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000720 " expected 0x%.8lx, actual 0x%.8lx\n",
David Feng102c0512014-02-12 16:10:08 +0800721 start_addr + offset*sizeof(vu_long),
722 pattern, temp);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400723 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000724 if (ctrlc())
Simon Glass51209b12013-02-24 17:33:17 +0000725 return -1;
wdenk38635852002-08-27 05:55:31 +0000726 }
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000727 }
Simon Glass5512d5b2013-02-28 17:47:14 +0000728 addr[test_offset] = pattern;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000729 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000730
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000731 /*
732 * Check for addr bits stuck low or shorted.
733 */
Simon Glass5512d5b2013-02-28 17:47:14 +0000734 for (test_offset = 1; test_offset < num_words; test_offset <<= 1) {
735 addr[test_offset] = anti_pattern;
wdenk38635852002-08-27 05:55:31 +0000736
Simon Glass5512d5b2013-02-28 17:47:14 +0000737 for (offset = 1; offset < num_words; offset <<= 1) {
738 temp = addr[offset];
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000739 if ((temp != pattern) && (offset != test_offset)) {
740 printf("\nFAILURE: Address bit stuck low or"
741 " shorted @ 0x%.8lx: expected 0x%.8lx,"
742 " actual 0x%.8lx\n",
David Feng102c0512014-02-12 16:10:08 +0800743 start_addr + offset*sizeof(vu_long),
744 pattern, temp);
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000745 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000746 if (ctrlc())
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000747 return -1;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000748 }
wdenk38635852002-08-27 05:55:31 +0000749 }
Simon Glass5512d5b2013-02-28 17:47:14 +0000750 addr[test_offset] = pattern;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000751 }
wdenk38635852002-08-27 05:55:31 +0000752
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000753 /*
754 * Description: Test the integrity of a physical
755 * memory device by performing an
756 * increment/decrement test over the
757 * entire region. In the process every
758 * storage bit in the device is tested
759 * as a zero and a one. The base address
760 * and the size of the region are
761 * selected by the caller.
762 *
763 * Returns: 0 if the test succeeds, 1 if the test fails.
764 */
Simon Glass5512d5b2013-02-28 17:47:14 +0000765 num_words++;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000766
767 /*
768 * Fill memory with a known pattern.
769 */
770 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
771 WATCHDOG_RESET();
Simon Glass5512d5b2013-02-28 17:47:14 +0000772 addr[offset] = pattern;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000773 }
774
775 /*
776 * Check each location and invert it for the second pass.
777 */
778 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
779 WATCHDOG_RESET();
Simon Glass5512d5b2013-02-28 17:47:14 +0000780 temp = addr[offset];
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000781 if (temp != pattern) {
Simon Glassc9638f52013-02-24 17:33:16 +0000782 printf("\nFAILURE (read/write) @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000783 " expected 0x%.8lx, actual 0x%.8lx)\n",
David Feng102c0512014-02-12 16:10:08 +0800784 start_addr + offset*sizeof(vu_long),
785 pattern, temp);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400786 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000787 if (ctrlc())
Simon Glass51209b12013-02-24 17:33:17 +0000788 return -1;
wdenk38635852002-08-27 05:55:31 +0000789 }
790
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000791 anti_pattern = ~pattern;
Simon Glass5512d5b2013-02-28 17:47:14 +0000792 addr[offset] = anti_pattern;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000793 }
794
795 /*
796 * Check each location for the inverted pattern and zero it.
797 */
798 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
799 WATCHDOG_RESET();
800 anti_pattern = ~pattern;
Simon Glass5512d5b2013-02-28 17:47:14 +0000801 temp = addr[offset];
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000802 if (temp != anti_pattern) {
Simon Glassc9638f52013-02-24 17:33:16 +0000803 printf("\nFAILURE (read/write): @ 0x%.8lx:"
wdenk38635852002-08-27 05:55:31 +0000804 " expected 0x%.8lx, actual 0x%.8lx)\n",
David Feng102c0512014-02-12 16:10:08 +0800805 start_addr + offset*sizeof(vu_long),
806 anti_pattern, temp);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400807 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000808 if (ctrlc())
Simon Glass51209b12013-02-24 17:33:17 +0000809 return -1;
wdenk38635852002-08-27 05:55:31 +0000810 }
Simon Glass5512d5b2013-02-28 17:47:14 +0000811 addr[offset] = 0;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000812 }
Simon Glass51209b12013-02-24 17:33:17 +0000813
Rasmus Villemoesfea67302016-01-07 11:36:04 +0100814 return errs;
Simon Glassc9638f52013-02-24 17:33:16 +0000815}
wdenk38635852002-08-27 05:55:31 +0000816
Stefan Roese8e434cb2020-03-05 07:21:32 +0100817static int compare_regions(volatile unsigned long *bufa,
818 volatile unsigned long *bufb, size_t count)
819{
820 volatile unsigned long *p1 = bufa;
821 volatile unsigned long *p2 = bufb;
822 int errs = 0;
823 size_t i;
824
825 for (i = 0; i < count; i++, p1++, p2++) {
826 if (*p1 != *p2) {
827 printf("FAILURE: 0x%08lx != 0x%08lx (delta=0x%08lx -> bit %ld) at offset 0x%08lx\n",
828 (unsigned long)*p1, (unsigned long)*p2,
829 *p1 ^ *p2, __ffs(*p1 ^ *p2),
830 (unsigned long)(i * sizeof(unsigned long)));
831 errs++;
832 }
833 }
834
835 return errs;
836}
837
838static ulong test_bitflip_comparison(volatile unsigned long *bufa,
839 volatile unsigned long *bufb, size_t count)
840{
841 volatile unsigned long *p1 = bufa;
842 volatile unsigned long *p2 = bufb;
843 unsigned int j, k;
844 unsigned long q;
845 size_t i;
846 int max;
847 int errs = 0;
848
849 max = sizeof(unsigned long) * 8;
850 for (k = 0; k < max; k++) {
851 q = 0x00000001L << k;
852 for (j = 0; j < 8; j++) {
853 WATCHDOG_RESET();
854 q = ~q;
855 p1 = (volatile unsigned long *)bufa;
856 p2 = (volatile unsigned long *)bufb;
857 for (i = 0; i < count; i++)
858 *p1++ = *p2++ = (i % 2) == 0 ? q : ~q;
859
860 errs += compare_regions(bufa, bufb, count);
861 }
862
863 if (ctrlc())
864 return -1UL;
865 }
866
867 return errs;
868}
869
Simon Glass5512d5b2013-02-28 17:47:14 +0000870static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr,
871 vu_long pattern, int iteration)
Simon Glassc9638f52013-02-24 17:33:16 +0000872{
Simon Glass5512d5b2013-02-28 17:47:14 +0000873 vu_long *end;
Simon Glassc9638f52013-02-24 17:33:16 +0000874 vu_long *addr;
Simon Glassc9638f52013-02-24 17:33:16 +0000875 ulong errs = 0;
Simon Glass5512d5b2013-02-28 17:47:14 +0000876 ulong incr, length;
Simon Glassc9638f52013-02-24 17:33:16 +0000877 ulong val, readback;
878
Simon Glass51209b12013-02-24 17:33:17 +0000879 /* Alternate the pattern */
wdenk38635852002-08-27 05:55:31 +0000880 incr = 1;
Simon Glass51209b12013-02-24 17:33:17 +0000881 if (iteration & 1) {
882 incr = -incr;
883 /*
884 * Flip the pattern each time to make lots of zeros and
885 * then, the next time, lots of ones. We decrement
886 * the "negative" patterns and increment the "positive"
887 * patterns to preserve this feature.
888 */
889 if (pattern & 0x80000000)
890 pattern = -pattern; /* complement & increment */
891 else
892 pattern = ~pattern;
893 }
Simon Glass5512d5b2013-02-28 17:47:14 +0000894 length = (end_addr - start_addr) / sizeof(ulong);
895 end = buf + length;
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000896 printf("\rPattern %08lX Writing..."
897 "%12s"
898 "\b\b\b\b\b\b\b\b\b\b",
899 pattern, "");
wdenk38635852002-08-27 05:55:31 +0000900
Simon Glass5512d5b2013-02-28 17:47:14 +0000901 for (addr = buf, val = pattern; addr < end; addr++) {
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000902 WATCHDOG_RESET();
903 *addr = val;
904 val += incr;
905 }
wdenk38635852002-08-27 05:55:31 +0000906
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000907 puts("Reading...");
wdenk38635852002-08-27 05:55:31 +0000908
Simon Glass5512d5b2013-02-28 17:47:14 +0000909 for (addr = buf, val = pattern; addr < end; addr++) {
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000910 WATCHDOG_RESET();
911 readback = *addr;
912 if (readback != val) {
Simon Glass5512d5b2013-02-28 17:47:14 +0000913 ulong offset = addr - buf;
914
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000915 printf("\nMem error @ 0x%08X: "
916 "found %08lX, expected %08lX\n",
David Feng102c0512014-02-12 16:10:08 +0800917 (uint)(uintptr_t)(start_addr + offset*sizeof(vu_long)),
Simon Glass5512d5b2013-02-28 17:47:14 +0000918 readback, val);
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000919 errs++;
Simon Glassc44d4382013-02-24 17:33:19 +0000920 if (ctrlc())
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000921 return -1;
wdenk38635852002-08-27 05:55:31 +0000922 }
Simon Glass7ecbd4d2013-02-24 17:33:18 +0000923 val += incr;
924 }
wdenk38635852002-08-27 05:55:31 +0000925
Rasmus Villemoesfea67302016-01-07 11:36:04 +0100926 return errs;
Simon Glassc9638f52013-02-24 17:33:16 +0000927}
928
929/*
930 * Perform a memory test. A more complete alternative test can be
931 * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until
932 * interrupted by ctrl-c or by a failure of one of the sub-tests.
933 */
Simon Glass09140112020-05-10 11:40:03 -0600934static int do_mem_mtest(struct cmd_tbl *cmdtp, int flag, int argc,
935 char *const argv[])
Simon Glassc9638f52013-02-24 17:33:16 +0000936{
Simon Glass8c86bbe2013-02-24 17:33:20 +0000937 ulong start, end;
Michal Simeke519f032020-05-04 13:54:40 +0200938 vu_long scratch_space;
939 vu_long *buf, *dummy = &scratch_space;
Tom Riniadcc5702015-04-07 09:38:54 -0400940 ulong iteration_limit = 0;
Stefan Roesea8c708e2020-03-05 07:21:29 +0100941 ulong count = 0;
Simon Glass51209b12013-02-24 17:33:17 +0000942 ulong errs = 0; /* number of errors, or -1 if interrupted */
Pavel Macheke37f1eb2015-04-01 13:50:41 +0200943 ulong pattern = 0;
Simon Glass51209b12013-02-24 17:33:17 +0000944 int iteration;
Simon Glassc9638f52013-02-24 17:33:16 +0000945
Pavel Macheke37f1eb2015-04-01 13:50:41 +0200946 start = CONFIG_SYS_MEMTEST_START;
947 end = CONFIG_SYS_MEMTEST_END;
948
Simon Glassc9638f52013-02-24 17:33:16 +0000949 if (argc > 1)
Pavel Macheke37f1eb2015-04-01 13:50:41 +0200950 if (strict_strtoul(argv[1], 16, &start) < 0)
951 return CMD_RET_USAGE;
Simon Glassc9638f52013-02-24 17:33:16 +0000952
953 if (argc > 2)
Pavel Macheke37f1eb2015-04-01 13:50:41 +0200954 if (strict_strtoul(argv[2], 16, &end) < 0)
955 return CMD_RET_USAGE;
Simon Glassc9638f52013-02-24 17:33:16 +0000956
957 if (argc > 3)
Pavel Macheke37f1eb2015-04-01 13:50:41 +0200958 if (strict_strtoul(argv[3], 16, &pattern) < 0)
959 return CMD_RET_USAGE;
Simon Glassc9638f52013-02-24 17:33:16 +0000960
961 if (argc > 4)
Pavel Macheke37f1eb2015-04-01 13:50:41 +0200962 if (strict_strtoul(argv[4], 16, &iteration_limit) < 0)
963 return CMD_RET_USAGE;
964
965 if (end < start) {
966 printf("Refusing to do empty test\n");
967 return -1;
968 }
Simon Glassc9638f52013-02-24 17:33:16 +0000969
Michal Simekdfe461d2016-02-24 08:36:02 +0100970 printf("Testing %08lx ... %08lx:\n", start, end);
Simon Glass8c86bbe2013-02-24 17:33:20 +0000971 debug("%s:%d: start %#08lx end %#08lx\n", __func__, __LINE__,
972 start, end);
Simon Glass51209b12013-02-24 17:33:17 +0000973
Simon Glass5512d5b2013-02-28 17:47:14 +0000974 buf = map_sysmem(start, end - start);
Simon Glass51209b12013-02-24 17:33:17 +0000975 for (iteration = 0;
976 !iteration_limit || iteration < iteration_limit;
977 iteration++) {
978 if (ctrlc()) {
Simon Glass51209b12013-02-24 17:33:17 +0000979 errs = -1UL;
980 break;
981 }
982
983 printf("Iteration: %6d\r", iteration + 1);
984 debug("\n");
Stefan Roesef14bfa72020-03-05 07:21:31 +0100985 if (IS_ENABLED(CONFIG_SYS_ALT_MEMTEST)) {
Simon Glass5512d5b2013-02-28 17:47:14 +0000986 errs = mem_test_alt(buf, start, end, dummy);
Stefan Roese8e434cb2020-03-05 07:21:32 +0100987 if (errs == -1UL)
988 break;
989 count += errs;
990 errs = test_bitflip_comparison(buf,
991 buf + (end - start) / 2,
992 (end - start) /
993 sizeof(unsigned long));
Simon Glass5512d5b2013-02-28 17:47:14 +0000994 } else {
995 errs = mem_test_quick(buf, start, end, pattern,
996 iteration);
997 }
998 if (errs == -1UL)
999 break;
Stefan Roesea8c708e2020-03-05 07:21:29 +01001000 count += errs;
Simon Glass5512d5b2013-02-28 17:47:14 +00001001 }
1002
Stefan Roese54de2442020-03-05 07:21:30 +01001003 unmap_sysmem((void *)buf);
Simon Glass51209b12013-02-24 17:33:17 +00001004
1005 if (errs == -1UL) {
Simon Glassc44d4382013-02-24 17:33:19 +00001006 /* Memory test was aborted - write a newline to finish off */
1007 putc('\n');
Simon Glass51209b12013-02-24 17:33:17 +00001008 }
Stefan Roesea8c708e2020-03-05 07:21:29 +01001009 printf("Tested %d iteration(s) with %lu errors.\n", iteration, count);
Simon Glassc9638f52013-02-24 17:33:16 +00001010
Stefan Roesea8c708e2020-03-05 07:21:29 +01001011 return errs != 0;
wdenk38635852002-08-27 05:55:31 +00001012}
Wolfgang Denka2681702013-03-08 10:51:32 +00001013#endif /* CONFIG_CMD_MEMTEST */
wdenk38635852002-08-27 05:55:31 +00001014
1015/* Modify memory.
1016 *
1017 * Syntax:
York Sun4d1fd7f2014-02-26 17:03:19 -08001018 * mm{.b, .w, .l, .q} {addr}
1019 * nm{.b, .w, .l, .q} {addr}
wdenk38635852002-08-27 05:55:31 +00001020 */
1021static int
Simon Glass09140112020-05-10 11:40:03 -06001022mod_mem(struct cmd_tbl *cmdtp, int incrflag, int flag, int argc,
1023 char *const argv[])
wdenk38635852002-08-27 05:55:31 +00001024{
York Sun4d1fd7f2014-02-26 17:03:19 -08001025 ulong addr;
Simon Glass4d979bf2019-12-28 10:45:10 -07001026#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001027 u64 i;
1028#else
1029 ulong i;
1030#endif
wdenk27b207f2003-07-24 23:38:38 +00001031 int nbytes, size;
Simon Glass0628ab82013-02-24 17:33:15 +00001032 void *ptr = NULL;
wdenk38635852002-08-27 05:55:31 +00001033
Wolfgang Denk47e26b12010-07-17 01:06:04 +02001034 if (argc != 2)
Simon Glass4c12eeb2011-12-10 08:44:01 +00001035 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +00001036
Simon Glassb26440f2014-04-10 20:01:31 -06001037 bootretry_reset_cmd_timeout(); /* got a good command to get here */
wdenk38635852002-08-27 05:55:31 +00001038 /* We use the last specified parameters, unless new ones are
1039 * entered.
1040 */
1041 addr = mm_last_addr;
1042 size = mm_last_size;
1043
1044 if ((flag & CMD_FLAG_REPEAT) == 0) {
1045 /* New command specified. Check for a size specification.
1046 * Defaults to long if no or incorrect specification.
1047 */
wdenk27b207f2003-07-24 23:38:38 +00001048 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
1049 return 1;
wdenk38635852002-08-27 05:55:31 +00001050
1051 /* Address is specified since argc > 1
1052 */
1053 addr = simple_strtoul(argv[1], NULL, 16);
1054 addr += base_address;
1055 }
1056
1057 /* Print the address, followed by value. Then accept input for
1058 * the next value. A non-converted value exits.
1059 */
1060 do {
Simon Glass0628ab82013-02-24 17:33:15 +00001061 ptr = map_sysmem(addr, size);
wdenk38635852002-08-27 05:55:31 +00001062 printf("%08lx:", addr);
1063 if (size == 4)
York Sun76698b42014-02-12 15:55:35 -08001064 printf(" %08x", *((u32 *)ptr));
Simon Glass4d979bf2019-12-28 10:45:10 -07001065#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001066 else if (size == 8)
Masahiro Yamadadee37fc2018-08-06 20:47:40 +09001067 printf(" %016llx", *((u64 *)ptr));
York Sun4d1fd7f2014-02-26 17:03:19 -08001068#endif
wdenk38635852002-08-27 05:55:31 +00001069 else if (size == 2)
York Sun76698b42014-02-12 15:55:35 -08001070 printf(" %04x", *((u16 *)ptr));
wdenk38635852002-08-27 05:55:31 +00001071 else
York Sun76698b42014-02-12 15:55:35 -08001072 printf(" %02x", *((u8 *)ptr));
wdenk38635852002-08-27 05:55:31 +00001073
Simon Glasse1bf8242014-04-10 20:01:27 -06001074 nbytes = cli_readline(" ? ");
wdenk38635852002-08-27 05:55:31 +00001075 if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
1076 /* <CR> pressed as only input, don't modify current
1077 * location and move to next. "-" pressed will go back.
1078 */
1079 if (incrflag)
1080 addr += nbytes ? -size : size;
1081 nbytes = 1;
Simon Glassb26440f2014-04-10 20:01:31 -06001082 /* good enough to not time out */
1083 bootretry_reset_cmd_timeout();
wdenk38635852002-08-27 05:55:31 +00001084 }
1085#ifdef CONFIG_BOOT_RETRY_TIME
1086 else if (nbytes == -2) {
1087 break; /* timed out, exit the command */
1088 }
1089#endif
1090 else {
1091 char *endp;
Simon Glass4d979bf2019-12-28 10:45:10 -07001092#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001093 i = simple_strtoull(console_buffer, &endp, 16);
1094#else
wdenk38635852002-08-27 05:55:31 +00001095 i = simple_strtoul(console_buffer, &endp, 16);
York Sun4d1fd7f2014-02-26 17:03:19 -08001096#endif
wdenk38635852002-08-27 05:55:31 +00001097 nbytes = endp - console_buffer;
1098 if (nbytes) {
wdenk38635852002-08-27 05:55:31 +00001099 /* good enough to not time out
1100 */
Simon Glassb26440f2014-04-10 20:01:31 -06001101 bootretry_reset_cmd_timeout();
wdenk38635852002-08-27 05:55:31 +00001102 if (size == 4)
York Sun76698b42014-02-12 15:55:35 -08001103 *((u32 *)ptr) = i;
Simon Glass4d979bf2019-12-28 10:45:10 -07001104#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001105 else if (size == 8)
1106 *((u64 *)ptr) = i;
1107#endif
wdenk38635852002-08-27 05:55:31 +00001108 else if (size == 2)
York Sun76698b42014-02-12 15:55:35 -08001109 *((u16 *)ptr) = i;
wdenk38635852002-08-27 05:55:31 +00001110 else
York Sun76698b42014-02-12 15:55:35 -08001111 *((u8 *)ptr) = i;
wdenk38635852002-08-27 05:55:31 +00001112 if (incrflag)
1113 addr += size;
1114 }
1115 }
1116 } while (nbytes);
Simon Glass0628ab82013-02-24 17:33:15 +00001117 if (ptr)
1118 unmap_sysmem(ptr);
wdenk38635852002-08-27 05:55:31 +00001119
1120 mm_last_addr = addr;
1121 mm_last_size = size;
1122 return 0;
1123}
1124
Mike Frysinger710b9932010-12-21 14:19:51 -05001125#ifdef CONFIG_CMD_CRC32
1126
Simon Glass09140112020-05-10 11:40:03 -06001127static int do_mem_crc(struct cmd_tbl *cmdtp, int flag, int argc,
1128 char *const argv[])
wdenk38635852002-08-27 05:55:31 +00001129{
Simon Glassd20a40d2013-02-24 20:30:22 +00001130 int flags = 0;
1131 int ac;
1132 char * const *av;
wdenk38635852002-08-27 05:55:31 +00001133
Wolfgang Denk47e26b12010-07-17 01:06:04 +02001134 if (argc < 3)
Simon Glass4c12eeb2011-12-10 08:44:01 +00001135 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +00001136
wdenkc26e4542004-04-18 10:13:26 +00001137 av = argv + 1;
1138 ac = argc - 1;
Daniel Thompson221a9492017-05-19 17:26:58 +01001139#ifdef CONFIG_CRC32_VERIFY
wdenkc26e4542004-04-18 10:13:26 +00001140 if (strcmp(*av, "-v") == 0) {
Joe Hershbergera69bdba2015-05-05 12:23:53 -05001141 flags |= HASH_FLAG_VERIFY | HASH_FLAG_ENV;
wdenkc26e4542004-04-18 10:13:26 +00001142 av++;
1143 ac--;
wdenkc26e4542004-04-18 10:13:26 +00001144 }
Simon Glassd20a40d2013-02-24 20:30:22 +00001145#endif
wdenkc26e4542004-04-18 10:13:26 +00001146
Simon Glassd20a40d2013-02-24 20:30:22 +00001147 return hash_command("crc32", flags, cmdtp, flag, ac, av);
wdenkc26e4542004-04-18 10:13:26 +00001148}
wdenkc26e4542004-04-18 10:13:26 +00001149
Mike Frysinger710b9932010-12-21 14:19:51 -05001150#endif
1151
Jean-Jacques Hiblot803e1a32019-07-02 14:23:26 +02001152#ifdef CONFIG_CMD_RANDOM
Simon Glass09140112020-05-10 11:40:03 -06001153static int do_random(struct cmd_tbl *cmdtp, int flag, int argc,
1154 char *const argv[])
Jean-Jacques Hiblot803e1a32019-07-02 14:23:26 +02001155{
1156 unsigned long addr, len;
1157 unsigned long seed; // NOT INITIALIZED ON PURPOSE
1158 unsigned int *buf, *start;
1159 unsigned char *buf8;
1160 unsigned int i;
1161
Eugeniy Paltsev5f2c4e02020-03-20 19:38:17 +03001162 if (argc < 3 || argc > 4)
1163 return CMD_RET_USAGE;
Jean-Jacques Hiblot803e1a32019-07-02 14:23:26 +02001164
1165 len = simple_strtoul(argv[2], NULL, 16);
1166 addr = simple_strtoul(argv[1], NULL, 16);
1167
1168 if (argc == 4) {
1169 seed = simple_strtoul(argv[3], NULL, 16);
1170 if (seed == 0) {
1171 printf("The seed cannot be 0. Using 0xDEADBEEF.\n");
1172 seed = 0xDEADBEEF;
1173 }
1174 } else {
1175 seed = get_timer(0) ^ rand();
1176 }
1177
1178 srand(seed);
1179 start = map_sysmem(addr, len);
1180 buf = start;
1181 for (i = 0; i < (len / 4); i++)
1182 *buf++ = rand();
1183
1184 buf8 = (unsigned char *)buf;
1185 for (i = 0; i < (len % 4); i++)
1186 *buf8++ = rand() & 0xFF;
1187
1188 unmap_sysmem(start);
1189 printf("%lu bytes filled with random data\n", len);
Eugeniy Paltsev5f2c4e02020-03-20 19:38:17 +03001190
1191 return CMD_RET_SUCCESS;
Jean-Jacques Hiblot803e1a32019-07-02 14:23:26 +02001192}
1193#endif
1194
wdenk8bde7f72003-06-27 21:31:46 +00001195/**************************************************/
wdenk0d498392003-07-01 21:06:45 +00001196U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001197 md, 3, 1, do_mem_md,
Peter Tyser2fb26042009-01-27 18:03:12 -06001198 "memory display",
Simon Glass4d979bf2019-12-28 10:45:10 -07001199#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001200 "[.b, .w, .l, .q] address [# of objects]"
1201#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001202 "[.b, .w, .l] address [# of objects]"
York Sun4d1fd7f2014-02-26 17:03:19 -08001203#endif
wdenk8bde7f72003-06-27 21:31:46 +00001204);
1205
1206
wdenk0d498392003-07-01 21:06:45 +00001207U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001208 mm, 2, 1, do_mem_mm,
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001209 "memory modify (auto-incrementing address)",
Simon Glass4d979bf2019-12-28 10:45:10 -07001210#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001211 "[.b, .w, .l, .q] address"
1212#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001213 "[.b, .w, .l] address"
York Sun4d1fd7f2014-02-26 17:03:19 -08001214#endif
wdenk8bde7f72003-06-27 21:31:46 +00001215);
1216
1217
wdenk0d498392003-07-01 21:06:45 +00001218U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001219 nm, 2, 1, do_mem_nm,
Peter Tyser2fb26042009-01-27 18:03:12 -06001220 "memory modify (constant address)",
Simon Glass4d979bf2019-12-28 10:45:10 -07001221#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001222 "[.b, .w, .l, .q] address"
1223#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001224 "[.b, .w, .l] address"
York Sun4d1fd7f2014-02-26 17:03:19 -08001225#endif
wdenk8bde7f72003-06-27 21:31:46 +00001226);
1227
wdenk0d498392003-07-01 21:06:45 +00001228U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001229 mw, 4, 1, do_mem_mw,
Peter Tyser2fb26042009-01-27 18:03:12 -06001230 "memory write (fill)",
Simon Glass4d979bf2019-12-28 10:45:10 -07001231#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001232 "[.b, .w, .l, .q] address value [count]"
1233#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001234 "[.b, .w, .l] address value [count]"
York Sun4d1fd7f2014-02-26 17:03:19 -08001235#endif
wdenk8bde7f72003-06-27 21:31:46 +00001236);
1237
wdenk0d498392003-07-01 21:06:45 +00001238U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001239 cp, 4, 1, do_mem_cp,
Peter Tyser2fb26042009-01-27 18:03:12 -06001240 "memory copy",
Simon Glass4d979bf2019-12-28 10:45:10 -07001241#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001242 "[.b, .w, .l, .q] source target count"
1243#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001244 "[.b, .w, .l] source target count"
York Sun4d1fd7f2014-02-26 17:03:19 -08001245#endif
wdenk8bde7f72003-06-27 21:31:46 +00001246);
1247
wdenk0d498392003-07-01 21:06:45 +00001248U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001249 cmp, 4, 1, do_mem_cmp,
Peter Tyser2fb26042009-01-27 18:03:12 -06001250 "memory compare",
Simon Glass4d979bf2019-12-28 10:45:10 -07001251#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001252 "[.b, .w, .l, .q] addr1 addr2 count"
1253#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001254 "[.b, .w, .l] addr1 addr2 count"
York Sun4d1fd7f2014-02-26 17:03:19 -08001255#endif
wdenk8bde7f72003-06-27 21:31:46 +00001256);
1257
Mike Frysinger710b9932010-12-21 14:19:51 -05001258#ifdef CONFIG_CMD_CRC32
1259
Daniel Thompson221a9492017-05-19 17:26:58 +01001260#ifndef CONFIG_CRC32_VERIFY
wdenkc26e4542004-04-18 10:13:26 +00001261
wdenk0d498392003-07-01 21:06:45 +00001262U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001263 crc32, 4, 1, do_mem_crc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001264 "checksum calculation",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001265 "address count [addr]\n - compute CRC32 checksum [save at addr]"
wdenk8bde7f72003-06-27 21:31:46 +00001266);
1267
Daniel Thompson221a9492017-05-19 17:26:58 +01001268#else /* CONFIG_CRC32_VERIFY */
wdenkc26e4542004-04-18 10:13:26 +00001269
1270U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001271 crc32, 5, 1, do_mem_crc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001272 "checksum calculation",
wdenkc26e4542004-04-18 10:13:26 +00001273 "address count [addr]\n - compute CRC32 checksum [save at addr]\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001274 "-v address count crc\n - verify crc of memory area"
wdenkc26e4542004-04-18 10:13:26 +00001275);
1276
Daniel Thompson221a9492017-05-19 17:26:58 +01001277#endif /* CONFIG_CRC32_VERIFY */
wdenkc26e4542004-04-18 10:13:26 +00001278
Mike Frysinger710b9932010-12-21 14:19:51 -05001279#endif
1280
Simon Glass15a33e42012-11-30 13:01:20 +00001281#ifdef CONFIG_CMD_MEMINFO
Simon Glass09140112020-05-10 11:40:03 -06001282static int do_mem_info(struct cmd_tbl *cmdtp, int flag, int argc,
1283 char *const argv[])
Simon Glass15a33e42012-11-30 13:01:20 +00001284{
Simon Glass428a6a12019-11-14 12:57:44 -07001285 puts("DRAM: ");
1286 print_size(gd->ram_size, "\n");
Simon Glass15a33e42012-11-30 13:01:20 +00001287
1288 return 0;
1289}
1290#endif
1291
wdenk0d498392003-07-01 21:06:45 +00001292U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001293 base, 2, 1, do_mem_base,
Peter Tyser2fb26042009-01-27 18:03:12 -06001294 "print or set address offset",
wdenk8bde7f72003-06-27 21:31:46 +00001295 "\n - print address offset for memory commands\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001296 "base off\n - set address offset for memory commands to 'off'"
wdenk8bde7f72003-06-27 21:31:46 +00001297);
1298
wdenk0d498392003-07-01 21:06:45 +00001299U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001300 loop, 3, 1, do_mem_loop,
Peter Tyser2fb26042009-01-27 18:03:12 -06001301 "infinite loop on address range",
Simon Glass4d979bf2019-12-28 10:45:10 -07001302#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001303 "[.b, .w, .l, .q] address number_of_objects"
1304#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001305 "[.b, .w, .l] address number_of_objects"
York Sun4d1fd7f2014-02-26 17:03:19 -08001306#endif
wdenk8bde7f72003-06-27 21:31:46 +00001307);
1308
wdenk56523f12004-07-11 17:40:54 +00001309#ifdef CONFIG_LOOPW
1310U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001311 loopw, 4, 1, do_mem_loopw,
Peter Tyser2fb26042009-01-27 18:03:12 -06001312 "infinite write loop on address range",
Simon Glass4d979bf2019-12-28 10:45:10 -07001313#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001314 "[.b, .w, .l, .q] address number_of_objects data_to_write"
1315#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001316 "[.b, .w, .l] address number_of_objects data_to_write"
York Sun4d1fd7f2014-02-26 17:03:19 -08001317#endif
wdenk56523f12004-07-11 17:40:54 +00001318);
1319#endif /* CONFIG_LOOPW */
1320
Wolfgang Denka2681702013-03-08 10:51:32 +00001321#ifdef CONFIG_CMD_MEMTEST
wdenk0d498392003-07-01 21:06:45 +00001322U_BOOT_CMD(
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +01001323 mtest, 5, 1, do_mem_mtest,
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001324 "simple RAM read/write test",
1325 "[start [end [pattern [iterations]]]]"
wdenk8bde7f72003-06-27 21:31:46 +00001326);
Wolfgang Denka2681702013-03-08 10:51:32 +00001327#endif /* CONFIG_CMD_MEMTEST */
wdenk8bde7f72003-06-27 21:31:46 +00001328
Joel Johnson72732312020-01-29 09:17:18 -07001329#ifdef CONFIG_CMD_MX_CYCLIC
stroese4aaf29b2004-12-16 17:42:39 +00001330U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001331 mdc, 4, 1, do_mem_mdc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001332 "memory display cyclic",
Simon Glass4d979bf2019-12-28 10:45:10 -07001333#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001334 "[.b, .w, .l, .q] address count delay(ms)"
1335#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001336 "[.b, .w, .l] address count delay(ms)"
York Sun4d1fd7f2014-02-26 17:03:19 -08001337#endif
stroese4aaf29b2004-12-16 17:42:39 +00001338);
1339
1340U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001341 mwc, 4, 1, do_mem_mwc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001342 "memory write cyclic",
Simon Glass4d979bf2019-12-28 10:45:10 -07001343#ifdef MEM_SUPPORT_64BIT_DATA
York Sun4d1fd7f2014-02-26 17:03:19 -08001344 "[.b, .w, .l, .q] address value delay(ms)"
1345#else
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001346 "[.b, .w, .l] address value delay(ms)"
York Sun4d1fd7f2014-02-26 17:03:19 -08001347#endif
stroese4aaf29b2004-12-16 17:42:39 +00001348);
Joel Johnson72732312020-01-29 09:17:18 -07001349#endif /* CONFIG_CMD_MX_CYCLIC */
Simon Glass15a33e42012-11-30 13:01:20 +00001350
1351#ifdef CONFIG_CMD_MEMINFO
1352U_BOOT_CMD(
1353 meminfo, 3, 1, do_mem_info,
1354 "display memory information",
1355 ""
1356);
1357#endif
Jean-Jacques Hiblot803e1a32019-07-02 14:23:26 +02001358
1359#ifdef CONFIG_CMD_RANDOM
1360U_BOOT_CMD(
1361 random, 4, 0, do_random,
1362 "fill memory with random pattern",
1363 "<addr> <len> [<seed>]\n"
1364 " - Fill 'len' bytes of memory starting at 'addr' with random data\n"
1365);
1366#endif