From: Detlev Casanova <detlev.casanova@collabora.com>
To: u-boot@lists.denx.de
Cc: Marek Vasut <marek.vasut+renesas@mailbox.org>,
Hai Pham <hai.pham.ud@renesas.com>,
Tam Nguyen <tam.nguyen.xa@renesas.com>,
Simon Glass <sjg@chromium.org>,
Detlev Casanova <detlev.casanova@collabora.com>
Subject: [PATCH v5 2/6] cmd: Add a sysinfo command
Date: Mon, 2 Oct 2023 11:20:06 -0400 [thread overview]
Message-ID: <20231002152142.76516-3-detlev.casanova@collabora.com> (raw)
In-Reply-To: <20231002152142.76516-1-detlev.casanova@collabora.com>
The command is able to show different information for the running
system:
* Model name
* Board ID
* Revision
This command can be used by boot shell scripts to select configurations
depending on the specific running system.
Reviewed-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
Signed-off-by: Detlev Casanova <detlev.casanova@collabora.com>
---
cmd/Kconfig | 6 +++
cmd/Makefile | 1 +
cmd/sysinfo.c | 133 ++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 140 insertions(+)
create mode 100644 cmd/sysinfo.c
diff --git a/cmd/Kconfig b/cmd/Kconfig
index 43ca10f69cc..67d019aa795 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -218,6 +218,12 @@ config CMD_SBI
help
Display information about the SBI implementation.
+config CMD_SYSINFO
+ bool "sysinfo"
+ depends on SYSINFO
+ help
+ Display information about the system.
+
endmenu
menu "Boot commands"
diff --git a/cmd/Makefile b/cmd/Makefile
index 9bebf321c39..972f3a4720e 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -167,6 +167,7 @@ obj-$(CONFIG_CMD_SPI) += spi.o
obj-$(CONFIG_CMD_STRINGS) += strings.o
obj-$(CONFIG_CMD_SMC) += smccc.o
obj-$(CONFIG_CMD_SYSBOOT) += sysboot.o
+obj-$(CONFIG_CMD_SYSINFO) += sysinfo.o
obj-$(CONFIG_CMD_STACKPROTECTOR_TEST) += stackprot_test.o
obj-$(CONFIG_CMD_TEMPERATURE) += temperature.o
obj-$(CONFIG_CMD_TERMINAL) += terminal.o
diff --git a/cmd/sysinfo.c b/cmd/sysinfo.c
new file mode 100644
index 00000000000..46369ff9ac7
--- /dev/null
+++ b/cmd/sysinfo.c
@@ -0,0 +1,133 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2023
+ * Detlev Casanova <detlev.casanova@collabora.com>
+ */
+
+#include <command.h>
+#include <env.h>
+#include <sysinfo.h>
+#include <exports.h>
+
+static int get_sysinfo(struct udevice **devp)
+{
+ int ret = sysinfo_get(devp);
+
+ if (ret) {
+ printf("Cannot get sysinfo: %d\n", ret);
+ return ret;
+ }
+
+ ret = sysinfo_detect(*devp);
+ if (ret) {
+ printf("Cannot detect sysinfo: %d\n", ret);
+ return ret;
+ }
+
+ return 0;
+}
+
+static int do_sysinfo_model(struct cmd_tbl *cmdtp, int flag, int argc,
+ char *const argv[])
+{
+ struct udevice *dev;
+ char model[64];
+ int ret = get_sysinfo(&dev);
+
+ if (ret)
+ return CMD_RET_FAILURE;
+
+ ret = sysinfo_get_str(dev,
+ SYSINFO_ID_BOARD_MODEL,
+ sizeof(model),
+ model);
+ if (ret) {
+ printf("Cannot get sysinfo str: %d\n", ret);
+ return CMD_RET_FAILURE;
+ }
+
+ if (argc == 2)
+ ret = env_set(argv[1], model);
+ else
+ printf("%s\n", model);
+
+ if (ret)
+ return CMD_RET_FAILURE;
+ else
+ return CMD_RET_SUCCESS;
+}
+
+static int do_sysinfo_id(struct cmd_tbl *cmdtp, int flag, int argc,
+ char *const argv[])
+{
+ struct udevice *dev;
+ u32 board_id;
+ int ret = get_sysinfo(&dev);
+
+ if (ret)
+ return CMD_RET_FAILURE;
+
+ ret = sysinfo_get_int(dev, SYSINFO_ID_BOARD_ID, &board_id);
+ if (ret) {
+ printf("Cannot get sysinfo int: %d\n", ret);
+ return CMD_RET_FAILURE;
+ }
+
+ if (argc == 2)
+ ret = env_set_hex(argv[1], board_id);
+ else
+ printf("0x%02x\n", board_id);
+
+ if (ret)
+ return CMD_RET_FAILURE;
+ else
+ return CMD_RET_SUCCESS;
+}
+
+static int do_sysinfo_revision(struct cmd_tbl *cmdtp, int flag, int argc,
+ char *const argv[])
+{
+ struct udevice *dev;
+ int rev_major;
+ int rev_minor;
+ char rev[64];
+ int ret = get_sysinfo(&dev);
+
+ if (ret)
+ return CMD_RET_FAILURE;
+
+ ret = sysinfo_get_int(dev, SYSINFO_ID_BOARD_REV_MAJOR, &rev_major);
+ if (ret) {
+ printf("Cannot get sysinfo int: %d\n", ret);
+ return CMD_RET_FAILURE;
+ }
+
+ ret = sysinfo_get_int(dev, SYSINFO_ID_BOARD_REV_MINOR, &rev_minor);
+ if (ret) {
+ printf("Cannot get sysinfo int: %d\n", ret);
+ return CMD_RET_FAILURE;
+ }
+
+ snprintf(rev, sizeof(rev), "%d.%d", rev_major, rev_minor);
+
+ if (argc == 2)
+ ret = env_set(argv[1], rev);
+ else
+ printf("%s\n", rev);
+
+ if (ret)
+ return CMD_RET_FAILURE;
+ else
+ return CMD_RET_SUCCESS;
+}
+
+static char sysinfo_help_text[] =
+ "model <varname> - Show or set the board model in varname\n"
+ "sysinfo id <varname> - Show or set the board id in varname (in format 0xHH)\n"
+ "sysinfo revision <varname> - Show or set the board revision in varname";
+
+U_BOOT_CMD_WITH_SUBCMDS(sysinfo, "System information", sysinfo_help_text,
+ U_BOOT_SUBCMD_MKENT(model, 2, 1, do_sysinfo_model),
+ U_BOOT_SUBCMD_MKENT(id, 2, 1, do_sysinfo_id),
+ U_BOOT_SUBCMD_MKENT(revision, 2, 1, do_sysinfo_revision),
+);
--
2.41.0
next prev parent reply other threads:[~2023-10-02 15:22 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-02 15:20 [PATCH v5 0/6] Introduce the sysinfo command Detlev Casanova
2023-10-02 15:20 ` [PATCH v5 1/6] sysinfo: Add IDs for board id and revision Detlev Casanova
2023-10-02 18:56 ` Simon Glass
2023-10-16 17:37 ` Heinrich Schuchardt
2023-10-16 18:11 ` Marek Vasut
2023-10-18 17:00 ` Detlev Casanova
2023-10-02 15:20 ` Detlev Casanova [this message]
2023-10-02 18:56 ` [PATCH v5 2/6] cmd: Add a sysinfo command Simon Glass
2023-10-16 14:21 ` Detlev Casanova
2023-10-16 21:54 ` Simon Glass
2023-10-02 15:20 ` [PATCH v5 3/6] sysinfo: Add a test Detlev Casanova
2023-10-02 18:56 ` Simon Glass
2023-10-02 15:20 ` [PATCH v5 4/6] sysinfo: Add documentation Detlev Casanova
2023-10-02 18:56 ` Simon Glass
2023-10-16 18:02 ` Heinrich Schuchardt
2023-10-02 15:20 ` [PATCH v5 5/6] sysinfo: rcar3: Use int instead of char for revision Detlev Casanova
2023-10-07 21:32 ` Marek Vasut
2023-10-02 15:20 ` [PATCH v5 6/6] sysinfo: rcar3: Implement BOARD_ID and BOARD_REV_* Detlev Casanova
2023-10-07 21:35 ` Marek Vasut
2023-10-16 17:03 ` Detlev Casanova
2023-10-16 18:12 ` Marek Vasut
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=20231002152142.76516-3-detlev.casanova@collabora.com \
--to=detlev.casanova@collabora.com \
--cc=hai.pham.ud@renesas.com \
--cc=marek.vasut+renesas@mailbox.org \
--cc=sjg@chromium.org \
--cc=tam.nguyen.xa@renesas.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox