From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH 5/8] commands: bfetch: add RISC-V cpu/firmware info
Date: Thu, 14 Aug 2025 22:28:02 +0200 [thread overview]
Message-ID: <20250814202805.354827-5-a.fatoum@barebox.org> (raw)
In-Reply-To: <20250814202805.354827-1-a.fatoum@barebox.org>
The RISC-V cpuinfo command has been switch to support structured I/O.
Use that to print CPU and SBI (RISC-V equivalent to ARM secure monitor)
version information.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
commands/bfetch.c | 45 +++++++++++++++++++++++++++++++++++----------
1 file changed, 35 insertions(+), 10 deletions(-)
diff --git a/commands/bfetch.c b/commands/bfetch.c
index c201c66b09ea..a44d5a000667 100644
--- a/commands/bfetch.c
+++ b/commands/bfetch.c
@@ -232,9 +232,9 @@ static void print_barebox_info(unsigned *line)
print_line("Architecture", "%s", CONFIG_ARCH_LINUX_NAME);
}
-static void print_cpu_mem_info(unsigned *line)
+static struct bobject *print_cpu_mem_info(unsigned *line)
{
- struct bobject *bret;
+ struct bobject *bret = NULL;
struct memory_bank *mem;
unsigned long memsize = 0;
int nbanks = 0;
@@ -250,8 +250,13 @@ static void print_cpu_mem_info(unsigned *line)
bobject_get_param(bret, "exception_level"));
else if (IS_ENABLED(CONFIG_ARM32))
print_line("CPU", "%s", bobject_get_param(bret, "core"));
-
- bobject_free(bret);
+ }
+ } else if (IS_ENABLED(CONFIG_RISCV)) {
+ ret = structio_run_command(&bret, "cpuinfo");
+ if (!ret) {
+ print_line("CPU", "%s in %s-Mode",
+ bobject_get_param(bret, "Architecture"),
+ bobject_get_param(bret, "Mode"));
}
} else if (IS_ENABLED(CONFIG_GLOBALVAR)) {
print_line("CPU", "%s-endian", globalvar_get("endianness"));
@@ -268,6 +273,8 @@ static void print_cpu_mem_info(unsigned *line)
else if (nbanks == 1)
print_line("Memory", "%s",
size_human_readable(memsize));
+
+ return bret;
}
static void print_shell_console(unsigned *line)
@@ -635,11 +642,12 @@ static int tee_devinfo(struct bobject **bret)
return -ENODEV;
}
-static void print_firmware(unsigned *line)
+static void print_firmware(unsigned *line, struct bobject *cpuinfo)
{
const char *psci_version;
struct bobject *bret;
bool have_scmi = false, have_tee = false;
+ const char *sbi_version = NULL;
psci_version = getenv("psci.version");
@@ -647,8 +655,11 @@ static void print_firmware(unsigned *line)
have_scmi = true;
if (tee_devinfo(&bret) == 0)
have_tee = true;
+ if (IS_ENABLED(CONFIG_RISCV_SBI))
+ sbi_version = bobject_get_param(cpuinfo, "SBI version");
- if (!psci_version && !have_scmi && !have_tee && !efi_is_payload())
+ if (!psci_version && !have_scmi && !have_tee && !efi_is_payload() &&
+ !sbi_version)
return;
print_line("Firmware", "");
@@ -660,7 +671,19 @@ static void print_firmware(unsigned *line)
if (have_scmi)
print_line(" SCMI", "yes");
- /* TODO: RISC-V SBI version */
+ if (sbi_version) {
+ const char *imp = bobject_get_param(cpuinfo, "SBI implementation name");
+
+ if (!imp)
+ imp = bobject_get_param(cpuinfo, "SBI implementation ID");
+
+ if (imp) {
+ print_line(" SBI", "%s by %s %s", sbi_version, imp,
+ bobject_get_param(cpuinfo, "SBI implementation version") ?: "");
+ } else {
+ print_line(" SBI", "%s", sbi_version);
+ }
+ }
if (have_tee) {
const char *name = bobject_get_param(bret, "impl.name");
@@ -680,11 +703,13 @@ static void print_firmware(unsigned *line)
dev_get_param(&efi_bus.dev, "fw_vendor"),
dev_get_param(&efi_bus.dev, "fw_revision"));
}
+
+ bobject_free(cpuinfo);
}
static int do_bfetch(int argc, char *argv[])
{
- struct bobject *bret;
+ struct bobject *bret, *cpuinfo;
unsigned _line, *line = &_line;
int opt;
int ret;
@@ -703,7 +728,7 @@ static int do_bfetch(int argc, char *argv[])
print_header(line);
print_barebox_info(line);
- print_cpu_mem_info(line);
+ cpuinfo = print_cpu_mem_info(line);
ret = structio_run_command(&bret, "uptime");
if (!ret) {
@@ -725,7 +750,7 @@ static int do_bfetch(int argc, char *argv[])
print_devices_drivers(line);
print_storage(line);
print_env(line);
- print_firmware(line);
+ print_firmware(line, cpuinfo);
while (logo(line))
putchar('\n');
--
2.39.5
next prev parent reply other threads:[~2025-08-14 20:28 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-14 20:27 [PATCH 1/8] common: fix outdated barebox_set_hostname comment Ahmad Fatoum
2025-08-14 20:27 ` [PATCH 2/8] RISC-V: virt: riscvemu: set better hostname/model Ahmad Fatoum
2025-08-14 20:28 ` [PATCH 3/8] netconsole: bump down ip/port not set messages to info Ahmad Fatoum
2025-08-14 20:28 ` [PATCH 4/8] RISC-V: cpuinfo: enable structured I/O Ahmad Fatoum
2025-08-14 20:28 ` Ahmad Fatoum [this message]
2025-08-14 20:28 ` [PATCH 6/8] RISC-V: riscvemu: update configs for web demo Ahmad Fatoum
2025-08-14 20:28 ` [PATCH 7/8] RISC-V: rv64i_defconfig: enable Virt I/O Ahmad Fatoum
2025-08-14 20:28 ` [PATCH 8/8] poller: allow suppressing overtime warnings Ahmad Fatoum
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=20250814202805.354827-5-a.fatoum@barebox.org \
--to=a.fatoum@barebox.org \
--cc=barebox@lists.infradead.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox