From: Frank Wunderlich <linux@fw-web.de>
To: Tom Rini <trini@konsulko.com>
Cc: Frank Wunderlich <frank-w@public-files.de>,
u-boot@lists.denx.de, Daniel Golle <daniel@makrotopia.org>
Subject: [PATCH v6 1/3] cmd: mem: add command for getting ram size for use in scripts
Date: Sun, 25 Jan 2026 14:12:51 +0100 [thread overview]
Message-ID: <20260125131254.23210-2-linux@fw-web.de> (raw)
In-Reply-To: <20260125131254.23210-1-linux@fw-web.de>
From: Frank Wunderlich <frank-w@public-files.de>
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>
---
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 | 6 ++++++
cmd/meminfo.c | 25 +++++++++++++++++++++++++
2 files changed, 31 insertions(+)
diff --git a/cmd/Kconfig b/cmd/Kconfig
index 5c611fb3016e..be79bf0747df 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -925,6 +925,12 @@ 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.
+
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 aa3b5bafe176..e7db9d065f5a 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 */
--
2.43.0
next prev parent reply other threads:[~2026-01-25 13:13 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-25 13:12 [PATCH v6 0/3] Add command for getting ramsize in scripts Frank Wunderlich
2026-01-25 13:12 ` Frank Wunderlich [this message]
2026-01-25 13:12 ` [PATCH v6 2/3] test: cmd: add test for memsize Frank Wunderlich
2026-02-03 23:34 ` Tom Rini
2026-02-04 6:40 ` Frank Wunderlich
2026-02-04 13:53 ` Tom Rini
2026-02-04 14:48 ` Frank Wunderlich
2026-02-04 14:51 ` Tom Rini
2026-01-25 13:12 ` [PATCH v6 3/3] doc: cmd: add usage doc " Frank Wunderlich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260125131254.23210-2-linux@fw-web.de \
--to=linux@fw-web.de \
--cc=daniel@makrotopia.org \
--cc=frank-w@public-files.de \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.