Add command for getting ramsize in scripts
v7 cover Add command for getting ramsize in scripts
From: Frank Wunderlich <[email protected]>
Add command for getting ramsize in scripts
v7:
- add guard for test to not fail for x86_64 qemu board
- extend doc and config help text
v6:
- add missing return for error in env_set_long
v5:
- move msize to meminfo and drop first param (always display as MiB)
- rename msize to memsize
- add doc and test so it becomes a series
Frank Wunderlich (3):
cmd: mem: add command for getting ram size for use in scripts
test: cmd: add test for memsize
doc: cmd: add usage doc for memsize
cmd/Kconfig | 8 ++++++++ cmd/meminfo.c | 25 +++++++++++++++++++++++ doc/usage/cmd/memsize.rst | 43 +++++++++++++++++++++++++++++++++++++++ test/cmd/meminfo.c | 20 ++++++++++++++++++ 4 files changed, 96 insertions(+) create mode 100644 doc/usage/cmd/memsize.rst
Signature · 1 line
2.43.0
PATCH v7 1/3 cmd: mem: add command for getting ram size for use in scripts
From: Frank Wunderlich <[email protected]>
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>
---
v7: add more information to help text in Kconfig
v6: add missing return for error in env_set_ulong
v5: move msize to meminfo and drop first param (always display as MiB)
rename msize to memsize
v4: drop rounding to full MB/GB as it leads to wrong display
v3: add missing ifdefs
v2: add Kconfig entry
--- cmd/Kconfig | 7 +++++++ cmd/meminfo.c | 25 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+)
cmd/Kconfig +7 -0
@@ -925,6 +925,13 @@ config CMD_MEMINFO_MAP See doc/usage/cmd/meminfo.rst for more information. +config CMD_MEMSIZE + bool "memsize" + depends on CMD_MEMINFO + help + Get RAM via command for use in scripts. Print or assign decimal value + in MiB to environment variable. + config CMD_MEMORY bool "md, mm, nm, mw, cp, cmp, base, loop" default y
cmd/meminfo.c +25 -0
@@ -8,10 +8,12 @@#include <bootstage.h> #include <command.h> #include <display_options.h> +#include <env.h> #include <lmb.h> #include <malloc.h> #include <mapmem.h> #include <asm/global_data.h> +#include <linux/sizes.h> DECLARE_GLOBAL_DATA_PTR ;
@@ -98,8 +100,31 @@ static int do_meminfo(struct cmd_tbl *cmdtp, int flag, int argc,return 0 ; } +#ifdef CONFIG_CMD_MEMSIZE +static int do_mem_size (struct cmd_tbl *cmdtp,int flag,int argc, +char *const argv[]) +{ +u64 memsize = gd->ram_size /SZ_1M ; + +if (argc >1 ) +return env_set_ulong (argv[1 ], memsize); +else +printf ("%lld MiB\n" , memsize); + +return 0 ; +} +#endif /* CONFIG_CMD_MEMSIZE */ +U_BOOT_CMD ( meminfo,1 ,1 , do_meminfo,"display memory information" ,"" ); + +#ifdef CONFIG_CMD_MEMSIZE +U_BOOT_CMD ( + memsize,2 ,1 , do_mem_size, +"get detected ram size in MiB, optional set env variable with value" , +"[envvar]" +); +#endif /* CONFIG_CMD_MEMSIZE */
Signature · 1 line
2.43.0
PATCH v7 2/3 test: cmd: add test for memsize
In reply to Frank WunderlichFrom: Frank Wunderlich <[email protected]>
Add a test for memsize command in same way as meminfo.
---
v7: guard test with config option
tested via:
$ ./u-boot -T -c "ut cmd cmd_test_memsize" ... Test: memsize: meminfo.c Tests run: 1, 0 ms, average: 0 ms, failures: 0 --- cmd/Kconfig | 1 + test/cmd/meminfo.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+)
cmd/Kconfig +1 -0
@@ -927,6 +927,7 @@ config CMD_MEMINFO_MAP config CMD_MEMSIZE bool "memsize" + default y if SANDBOX depends on CMD_MEMINFO help Get RAM via command for use in scripts. Print or assign decimal value
test/cmd/meminfo.c +20 -0
@@ -7,6 +7,7 @@*/ #include <dm/test.h> +#include <env.h> #include <test/cmd.h> #include <test/ut.h>
@@ -39,4 +40,23 @@ static int cmd_test_meminfo(struct unit_test_state *uts)return 0 ; } +CMD_TEST (cmd_test_meminfo,UTF_CONSOLE ); + +/* Test 'memsize' command */ +#ifdef CONFIG_CMD_MEMSIZE +static int cmd_test_memsize (struct unit_test_state *uts) +{ +ut_assertok (run_command ("memsize" ,0 )); +ut_assert_nextline ("256 MiB" ); +ut_assert_console_end (); + +ut_assertok (run_command ("memsize memsz" ,0 )); +ut_asserteq_str ("256" ,env_get ("memsz" )); +ut_assert_console_end (); + +return 0 ; +} + +CMD_TEST (cmd_test_memsize,UTF_CONSOLE ); +#endif
Signature · 1 line
2.43.0
PATCH v7 3/3 doc: cmd: add usage doc for memsize
In reply to Frank WunderlichFrom: Frank Wunderlich <[email protected]>
Add documentation for memsize command.
---
v7:
- update documentation including decimal notation
--- doc/usage/cmd/memsize.rst | 43 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 doc/usage/cmd/memsize.rst
doc/usage/cmd/memsize.rst new file +43 -0
@@ -0,0 +1,43 @@ +.. SPDX-License-Identifier: GPL-2.0+: + +.. index:: + single: memsize (command) + +memsize command +=============== + +Synopsis +-------- + +:: + + memsize [name] + +Description +----------- + +The memsize command shows the amount of RAM in MiB in decimal notation. +Optionally same value can be assigned to an environment variable. + +Examples +-------- + +This first example shows printing of ram size: + +:: + + => memsize + 8192 MiB + +This second example shows assign ram size to environment variable: + +:: + + => memsize memsz + => printenv memsz + memsz=8192 + +Return value +------------ + +The return value is always 0 except error happens on setting environment variable.
Signature · 1 line
2.43.0
Quoted 14 lines · Frank Wunderlich
From: Frank Wunderlich <[email protected]>
Add command for getting ramsize in scripts
v7:
- add guard for test to not fail forx86_64qemu board
- extend doc and config help text
v6:
- add missing return for error inenv_set_long
v5:
- move msize to meminfo and drop first param (always display as MiB)
- rename msize to memsize
- add doc and test so it becomes a series
Quoted 1 line
[...]
Applied to u-boot/master, thanks!
[1/3] cmd: mem: add command for getting ram size for use in scripts
commit: e202eca183b0f1d6747b934482dc6249abdd742b
[2/3] test: cmd: add test for memsize
commit: 8acc8a654643ca26b0bdd4af37010da7cc796753
[3/3] doc: cmd: add usage doc for memsize
commit: b4842032d542cfde271aab61b80ab870b27b07b2Signature · 1 line
Tom