public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH v2] cmd: mem: Add a command to fill the memory with random data
@ 2019-07-02  8:36 Jean-Jacques Hiblot
  2019-07-02  8:50 ` Jean-Jacques Hiblot
  0 siblings, 1 reply; 3+ messages in thread
From: Jean-Jacques Hiblot @ 2019-07-02  8:36 UTC (permalink / raw)
  To: u-boot

This command fills the memory with data produced by rand().
This command depends on CONFIG_LIB_RAND.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
---
changes in v2:
- Do not include the command if CONFIG_LIB_RAND is not set
- make do_random() static

cmd/Kconfig |  3 ++-
 cmd/mem.c   | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+), 1 deletion(-)

diff --git a/cmd/Kconfig b/cmd/Kconfig
index cda7931fe3..f9385fcc08 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -537,7 +537,7 @@ config CMD_MEMINFO
 	  Display memory information.
 
 config CMD_MEMORY
-	bool "md, mm, nm, mw, cp, cmp, base, loop"
+	bool "md, mm, nm, mw, cp, cmp, base, loop, random"
 	default y
 	help
 	  Memory commands.
@@ -549,6 +549,7 @@ config CMD_MEMORY
 	    cmp - memory compare
 	    base - print or set address offset
 	    loop - initialize loop on address range
+	    random - fill memory with random data
 
 config CMD_MEMTEST
 	bool "memtest"
diff --git a/cmd/mem.c b/cmd/mem.c
index 392ed1756b..e5af12db57 100644
--- a/cmd/mem.c
+++ b/cmd/mem.c
@@ -1082,6 +1082,49 @@ static int do_mem_crc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
 #endif
 
+#ifdef CONFIG_LIB_RAND
+static int do_random(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+	unsigned long addr, len;
+	unsigned long seed; // NOT INITIALIZED ON PURPOSE
+	unsigned int *buf, *start;
+	unsigned char *buf8;
+	unsigned int i;
+
+	if (argc < 3 || argc > 4) {
+		printf("usage: %s <addr> <len> [<seed>]\n", argv[0]);
+		return 0;
+	}
+
+	len = simple_strtoul(argv[2], NULL, 16);
+	addr = simple_strtoul(argv[1], NULL, 16);
+
+	if (argc == 4) {
+		seed = simple_strtoul(argv[3], NULL, 16);
+		if (seed == 0) {
+			printf("The seed cannot be 0. Using 0xDEADBEEF.\n");
+			seed = 0xDEADBEEF;
+		}
+	} else {
+		seed = get_timer(0) ^ rand();
+	}
+
+	srand(seed);
+	start = map_sysmem(addr, len);
+	buf = start;
+	for (i = 0; i < (len / 4); i++)
+		*buf++ = rand();
+
+	buf8 = (unsigned char *)buf;
+	for (i = 0; i < (len % 4); i++)
+		*buf8++ = rand() & 0xFF;
+
+	unmap_sysmem(start);
+	printf("%lu bytes filled with random data\n", len);
+	return 1;
+}
+#endif
+
 /**************************************************/
 U_BOOT_CMD(
 	md,	3,	1,	do_mem_md,
@@ -1250,3 +1293,12 @@ U_BOOT_CMD(
 	""
 );
 #endif
+
+#ifdef CONFIG_LIB_RAND
+U_BOOT_CMD(
+	random,	4,	0,	do_random,
+	"fill memory with random pattern",
+	"<addr> <len> [<seed>]\n"
+	"   - Fill 'len' bytes of memory starting at 'addr' with random data\n"
+);
+#endif
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [U-Boot] [PATCH v2] cmd: mem: Add a command to fill the memory with random data
  2019-07-02  8:36 [U-Boot] [PATCH v2] cmd: mem: Add a command to fill the memory with random data Jean-Jacques Hiblot
@ 2019-07-02  8:50 ` Jean-Jacques Hiblot
  2019-07-02 12:03   ` Tom Rini
  0 siblings, 1 reply; 3+ messages in thread
From: Jean-Jacques Hiblot @ 2019-07-02  8:50 UTC (permalink / raw)
  To: u-boot

+Tom

On 02/07/2019 10:36, Jean-Jacques Hiblot wrote:
> This command fills the memory with data produced by rand().
> This command depends on CONFIG_LIB_RAND.
>
> Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
> ---
> changes in v2:
> - Do not include the command if CONFIG_LIB_RAND is not set
> - make do_random() static
>
> cmd/Kconfig |  3 ++-
>   cmd/mem.c   | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>   2 files changed, 54 insertions(+), 1 deletion(-)
>
> diff --git a/cmd/Kconfig b/cmd/Kconfig
> index cda7931fe3..f9385fcc08 100644
> --- a/cmd/Kconfig
> +++ b/cmd/Kconfig
> @@ -537,7 +537,7 @@ config CMD_MEMINFO
>   	  Display memory information.
>   
>   config CMD_MEMORY
> -	bool "md, mm, nm, mw, cp, cmp, base, loop"
> +	bool "md, mm, nm, mw, cp, cmp, base, loop, random"
>   	default y
>   	help
>   	  Memory commands.
> @@ -549,6 +549,7 @@ config CMD_MEMORY
>   	    cmp - memory compare
>   	    base - print or set address offset
>   	    loop - initialize loop on address range
> +	    random - fill memory with random data
>   
>   config CMD_MEMTEST
>   	bool "memtest"
> diff --git a/cmd/mem.c b/cmd/mem.c
> index 392ed1756b..e5af12db57 100644
> --- a/cmd/mem.c
> +++ b/cmd/mem.c
> @@ -1082,6 +1082,49 @@ static int do_mem_crc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
>   
>   #endif
>   
> +#ifdef CONFIG_LIB_RAND
> +static int do_random(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
> +{
> +	unsigned long addr, len;
> +	unsigned long seed; // NOT INITIALIZED ON PURPOSE
> +	unsigned int *buf, *start;
> +	unsigned char *buf8;
> +	unsigned int i;
> +
> +	if (argc < 3 || argc > 4) {
> +		printf("usage: %s <addr> <len> [<seed>]\n", argv[0]);
> +		return 0;
> +	}
> +
> +	len = simple_strtoul(argv[2], NULL, 16);
> +	addr = simple_strtoul(argv[1], NULL, 16);
> +
> +	if (argc == 4) {
> +		seed = simple_strtoul(argv[3], NULL, 16);
> +		if (seed == 0) {
> +			printf("The seed cannot be 0. Using 0xDEADBEEF.\n");
> +			seed = 0xDEADBEEF;
> +		}
> +	} else {
> +		seed = get_timer(0) ^ rand();
> +	}
> +
> +	srand(seed);
> +	start = map_sysmem(addr, len);
> +	buf = start;
> +	for (i = 0; i < (len / 4); i++)
> +		*buf++ = rand();
> +
> +	buf8 = (unsigned char *)buf;
> +	for (i = 0; i < (len % 4); i++)
> +		*buf8++ = rand() & 0xFF;
> +
> +	unmap_sysmem(start);
> +	printf("%lu bytes filled with random data\n", len);
> +	return 1;
> +}
> +#endif
> +
>   /**************************************************/
>   U_BOOT_CMD(
>   	md,	3,	1,	do_mem_md,
> @@ -1250,3 +1293,12 @@ U_BOOT_CMD(
>   	""
>   );
>   #endif
> +
> +#ifdef CONFIG_LIB_RAND
> +U_BOOT_CMD(
> +	random,	4,	0,	do_random,
> +	"fill memory with random pattern",
> +	"<addr> <len> [<seed>]\n"
> +	"   - Fill 'len' bytes of memory starting at 'addr' with random data\n"
> +);
> +#endif

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [U-Boot] [PATCH v2] cmd: mem: Add a command to fill the memory with random data
  2019-07-02  8:50 ` Jean-Jacques Hiblot
@ 2019-07-02 12:03   ` Tom Rini
  0 siblings, 0 replies; 3+ messages in thread
From: Tom Rini @ 2019-07-02 12:03 UTC (permalink / raw)
  To: u-boot

On Tue, Jul 02, 2019 at 10:50:43AM +0200, Jean-Jacques Hiblot wrote:
> +Tom
> 
> On 02/07/2019 10:36, Jean-Jacques Hiblot wrote:
> >This command fills the memory with data produced by rand().
> >This command depends on CONFIG_LIB_RAND.
> >
> >Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
> >---
> >changes in v2:
> >- Do not include the command if CONFIG_LIB_RAND is not set
> >- make do_random() static
> >
> >cmd/Kconfig |  3 ++-
> >  cmd/mem.c   | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
> >  2 files changed, 54 insertions(+), 1 deletion(-)
> >
> >diff --git a/cmd/Kconfig b/cmd/Kconfig
> >index cda7931fe3..f9385fcc08 100644
> >--- a/cmd/Kconfig
> >+++ b/cmd/Kconfig
> >@@ -537,7 +537,7 @@ config CMD_MEMINFO
> >  	  Display memory information.
> >  config CMD_MEMORY
> >-	bool "md, mm, nm, mw, cp, cmp, base, loop"
> >+	bool "md, mm, nm, mw, cp, cmp, base, loop, random"
> >  	default y
> >  	help
> >  	  Memory commands.
> >@@ -549,6 +549,7 @@ config CMD_MEMORY
> >  	    cmp - memory compare
> >  	    base - print or set address offset
> >  	    loop - initialize loop on address range
> >+	    random - fill memory with random data
> >  config CMD_MEMTEST
> >  	bool "memtest"
> >diff --git a/cmd/mem.c b/cmd/mem.c
> >index 392ed1756b..e5af12db57 100644
> >--- a/cmd/mem.c
> >+++ b/cmd/mem.c
> >@@ -1082,6 +1082,49 @@ static int do_mem_crc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
> >  #endif
> >+#ifdef CONFIG_LIB_RAND
> >+static int do_random(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
> >+{
> >+	unsigned long addr, len;
> >+	unsigned long seed; // NOT INITIALIZED ON PURPOSE
> >+	unsigned int *buf, *start;
> >+	unsigned char *buf8;
> >+	unsigned int i;
> >+
> >+	if (argc < 3 || argc > 4) {
> >+		printf("usage: %s <addr> <len> [<seed>]\n", argv[0]);
> >+		return 0;
> >+	}
> >+
> >+	len = simple_strtoul(argv[2], NULL, 16);
> >+	addr = simple_strtoul(argv[1], NULL, 16);
> >+
> >+	if (argc == 4) {
> >+		seed = simple_strtoul(argv[3], NULL, 16);
> >+		if (seed == 0) {
> >+			printf("The seed cannot be 0. Using 0xDEADBEEF.\n");
> >+			seed = 0xDEADBEEF;
> >+		}
> >+	} else {
> >+		seed = get_timer(0) ^ rand();
> >+	}
> >+
> >+	srand(seed);
> >+	start = map_sysmem(addr, len);
> >+	buf = start;
> >+	for (i = 0; i < (len / 4); i++)
> >+		*buf++ = rand();
> >+
> >+	buf8 = (unsigned char *)buf;
> >+	for (i = 0; i < (len % 4); i++)
> >+		*buf8++ = rand() & 0xFF;
> >+
> >+	unmap_sysmem(start);
> >+	printf("%lu bytes filled with random data\n", len);
> >+	return 1;
> >+}
> >+#endif
> >+
> >  /**************************************************/
> >  U_BOOT_CMD(
> >  	md,	3,	1,	do_mem_md,
> >@@ -1250,3 +1293,12 @@ U_BOOT_CMD(
> >  	""
> >  );
> >  #endif
> >+
> >+#ifdef CONFIG_LIB_RAND
> >+U_BOOT_CMD(
> >+	random,	4,	0,	do_random,
> >+	"fill memory with random pattern",
> >+	"<addr> <len> [<seed>]\n"
> >+	"   - Fill 'len' bytes of memory starting at 'addr' with random data\n"
> >+);
> >+#endif

This needs to be a new CONFIG option that depends on CMD_MEM, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190702/072fd185/attachment.sig>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-07-02 12:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-07-02  8:36 [U-Boot] [PATCH v2] cmd: mem: Add a command to fill the memory with random data Jean-Jacques Hiblot
2019-07-02  8:50 ` Jean-Jacques Hiblot
2019-07-02 12:03   ` Tom Rini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox