summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorTom Rini <[email protected]>2026-02-07 11:51:43 -0600
committerTom Rini <[email protected]>2026-02-07 11:51:43 -0600
commitb887a1c1a1110582d178faad4397a0197938454e (patch)
tree6f902115518ca668333f34095442b95646c71af1 /cmd
parent2ffab9da9142c03dc0f2ce056ccd2b0f43c02742 (diff)
parentb4842032d542cfde271aab61b80ab870b27b07b2 (diff)
Merge patch series "Add command for getting ramsize in scripts"
Frank Wunderlich <[email protected]> says: Add command for getting ramsize in scripts Link: https://lore.kernel.org/r/[email protected]
Diffstat (limited to 'cmd')
-rw-r--r--cmd/Kconfig8
-rw-r--r--cmd/meminfo.c25
2 files changed, 33 insertions, 0 deletions
diff --git a/cmd/Kconfig b/cmd/Kconfig
index cc4dd5a3163..322ebe600c5 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -940,6 +940,14 @@ config CMD_MEMINFO_MAP
See doc/usage/cmd/meminfo.rst for more information.
+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
+ in MiB to environment variable.
+
config CMD_MEMORY
bool "md, mm, nm, mw, cp, cmp, base, loop"
default y
diff --git a/cmd/meminfo.c b/cmd/meminfo.c
index b731280d106..69a5b1b51a2 100644
--- a/cmd/meminfo.c
+++ b/cmd/meminfo.c
@@ -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 */