From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH 4/8] RISC-V: cpuinfo: enable structured I/O
Date: Thu, 14 Aug 2025 22:28:01 +0200 [thread overview]
Message-ID: <20250814202805.354827-4-a.fatoum@barebox.org> (raw)
In-Reply-To: <20250814202805.354827-1-a.fatoum@barebox.org>
This will allow us to easily consume the information in the bfetch
command.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
arch/riscv/lib/cpuinfo.c | 43 ++++++++++++++++++++++++----------------
1 file changed, 26 insertions(+), 17 deletions(-)
diff --git a/arch/riscv/lib/cpuinfo.c b/arch/riscv/lib/cpuinfo.c
index 2d9cee2a6270..f984fd68a9e8 100644
--- a/arch/riscv/lib/cpuinfo.c
+++ b/arch/riscv/lib/cpuinfo.c
@@ -3,14 +3,15 @@
#include <command.h>
#include <asm/sbi.h>
#include <asm/system.h>
+#include <structio.h>
static const char *implementations[] = {
- [0] = "\"Berkeley Boot Loader (BBL)\" ",
- [1] = "\"OpenSBI\" ",
- [2] = "\"Xvisor\" ",
- [3] = "\"KVM\" ",
- [4] = "\"RustSBI\" ",
- [5] = "\"Diosix\" ",
+ [0] = "Berkeley Boot Loader (BBL)",
+ [1] = "OpenSBI",
+ [2] = "Xvisor",
+ [3] = "KVM",
+ [4] = "RustSBI",
+ [5] = "Diosix",
};
static const char *modes[] = {
@@ -22,22 +23,22 @@ static const char *modes[] = {
static int do_cpuinfo(int argc, char *argv[])
{
- const char *implementation = "";
+ const char *implementation = NULL;
enum riscv_mode mode;
unsigned long impid;
mode = riscv_mode() & RISCV_MODE_MASK;
- printf("%s barebox for %s-Mode\n",
- IS_ENABLED(CONFIG_ARCH_RV64I) ? "RV64I" : "RV32I",
- modes[mode]);
+ stprintf("Architecture", "%s",
+ IS_ENABLED(CONFIG_ARCH_RV64I) ? "RV64I" : "RV32I");
+ stprintf("Mode", "%s", modes[mode]);
switch (mode) {
case RISCV_S_MODE:
- printf("Hart ID=%lu\n", riscv_hartid());
+ stprintf("Hart ID", "%lu", riscv_hartid());
if (!IS_ENABLED(CONFIG_RISCV_SBI))
break;
- printf("SBI specification v%lu.%lu detected\n",
+ stprintf("SBI version", "v%lu.%lu",
sbi_major_version(), sbi_minor_version());
if (sbi_spec_is_0_1())
@@ -47,12 +48,20 @@ static int do_cpuinfo(int argc, char *argv[])
if (impid < ARRAY_SIZE(implementations))
implementation = implementations[impid];
- printf("SBI implementation ID=0x%lx %sVersion=0x%lx\n",
- impid, implementation, __sbi_base_ecall(SBI_EXT_BASE_GET_IMP_VERSION));
+ stprintf("SBI implementation ID", "0x%lx", impid);
+ if (implementation)
+ stprintf("SBI implementation name", "%s", implementation);
- printf("SBI Machine VENDORID=0x%lx ARCHID=0x%lx MIMPID=0x%lx\n",
- __sbi_base_ecall(SBI_EXT_BASE_GET_MVENDORID),
- __sbi_base_ecall(SBI_EXT_BASE_GET_MARCHID),
+ stprintf("SBI implementation version", "0x%lx",
+ __sbi_base_ecall(SBI_EXT_BASE_GET_IMP_VERSION));
+
+ stprintf("SBI machine VENDORID", "0x%lx",
+ __sbi_base_ecall(SBI_EXT_BASE_GET_MVENDORID));
+
+ stprintf("SBI machine ARCHID", "0x%lx",
+ __sbi_base_ecall(SBI_EXT_BASE_GET_MARCHID));
+
+ stprintf("SBI machine MIMPID", "0x%lx",
__sbi_base_ecall(SBI_EXT_BASE_GET_MIMPID));
break;
default:
--
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 ` Ahmad Fatoum [this message]
2025-08-14 20:28 ` [PATCH 5/8] commands: bfetch: add RISC-V cpu/firmware info Ahmad Fatoum
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-4-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