"Das U-Boot" Source Tree
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

cmd: mem: add command for getting ram size for use in scripts

Add a command for getting detected ram size with possibility to
assign it to an environment variable.

example usage:

BPI-R4> memsize
4096 MiB
BPI-R4> memsize memsz
BPI-R4> printenv memsz
memsz=4096
BPI-R4>

board with 8GB ram:

BPI-R4> memsize
8192 MiB
BPI-R4> memsize memsz
BPI-R4> printenv memsz
memsz=8192
BPI-R4>

Signed-off-by: Frank Wunderlich <frank-w@public-files.de>

authored by

Frank Wunderlich and committed by
Tom Rini
e202eca1 6b2d0574

+32
+7
cmd/Kconfig
··· 940 940 941 941 See doc/usage/cmd/meminfo.rst for more information. 942 942 943 + config CMD_MEMSIZE 944 + bool "memsize" 945 + depends on CMD_MEMINFO 946 + help 947 + Get RAM via command for use in scripts. Print or assign decimal value 948 + in MiB to environment variable. 949 + 943 950 config CMD_MEMORY 944 951 bool "md, mm, nm, mw, cp, cmp, base, loop" 945 952 default y
+25
cmd/meminfo.c
··· 8 8 #include <bootstage.h> 9 9 #include <command.h> 10 10 #include <display_options.h> 11 + #include <env.h> 11 12 #include <lmb.h> 12 13 #include <malloc.h> 13 14 #include <mapmem.h> 14 15 #include <asm/global_data.h> 16 + #include <linux/sizes.h> 15 17 16 18 DECLARE_GLOBAL_DATA_PTR; 17 19 ··· 98 100 return 0; 99 101 } 100 102 103 + #ifdef CONFIG_CMD_MEMSIZE 104 + static int do_mem_size(struct cmd_tbl *cmdtp, int flag, int argc, 105 + char *const argv[]) 106 + { 107 + u64 memsize = gd->ram_size / SZ_1M; 108 + 109 + if (argc > 1) 110 + return env_set_ulong(argv[1], memsize); 111 + else 112 + printf("%lld MiB\n", memsize); 113 + 114 + return 0; 115 + } 116 + #endif /* CONFIG_CMD_MEMSIZE */ 117 + 101 118 U_BOOT_CMD( 102 119 meminfo, 1, 1, do_meminfo, 103 120 "display memory information", 104 121 "" 105 122 ); 123 + 124 + #ifdef CONFIG_CMD_MEMSIZE 125 + U_BOOT_CMD( 126 + memsize, 2, 1, do_mem_size, 127 + "get detected ram size in MiB, optional set env variable with value", 128 + "[envvar]" 129 + ); 130 + #endif /* CONFIG_CMD_MEMSIZE */