[U-Boot] [PATCH 16/22] sandbox: Add a new 'sb' command

Simon Glass sjg at chromium.org
Wed Sep 26 21:55:14 UTC 2018


The old 'sb' command was deprecated in 2015 and replaced with 'host'. It
is useful to be able to access some internal sandbox state, particularly
for testing.

Resurrect the old command and provide a way to print some basic state
information (currently just the arguments to sandbox).

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 arch/sandbox/cpu/start.c         | 10 +++++++
 arch/sandbox/include/asm/state.h |  7 +++++
 cmd/Makefile                     |  1 +
 cmd/host.c                       |  5 ----
 cmd/sb.c                         | 46 ++++++++++++++++++++++++++++++++
 5 files changed, 64 insertions(+), 5 deletions(-)
 create mode 100644 cmd/sb.c

diff --git a/arch/sandbox/cpu/start.c b/arch/sandbox/cpu/start.c
index 2879b438d25..2251ec4c53f 100644
--- a/arch/sandbox/cpu/start.c
+++ b/arch/sandbox/cpu/start.c
@@ -295,6 +295,16 @@ static void setup_ram_buf(struct sandbox_state *state)
 	gd->ram_size = state->ram_size;
 }
 
+void state_show(struct sandbox_state *state)
+{
+	char **p;
+
+	printf("Arguments:\n");
+	for (p = state->argv; *p; p++)
+		printf("%s ", *p);
+	printf("\n");
+}
+
 int main(int argc, char *argv[])
 {
 	struct sandbox_state *state;
diff --git a/arch/sandbox/include/asm/state.h b/arch/sandbox/include/asm/state.h
index 08d3e24d8ea..69f84c30387 100644
--- a/arch/sandbox/include/asm/state.h
+++ b/arch/sandbox/include/asm/state.h
@@ -221,6 +221,13 @@ bool state_get_skip_delays(void);
  */
 void state_reset_for_test(struct sandbox_state *state);
 
+/**
+ * state_show() - Show information about the sandbox state
+ *
+ * @param state		Sandbox state to show
+ */
+void state_show(struct sandbox_state *state);
+
 /**
  * Initialize the test system state
  */
diff --git a/cmd/Makefile b/cmd/Makefile
index a61fab6583d..355e2e0dd7d 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -112,6 +112,7 @@ obj-$(CONFIG_CMD_ROCKUSB) += rockusb.o
 obj-$(CONFIG_SANDBOX) += host.o
 obj-$(CONFIG_CMD_SATA) += sata.o
 obj-$(CONFIG_CMD_NVME) += nvme.o
+obj-$(CONFIG_SANDBOX) += sb.o
 obj-$(CONFIG_CMD_SF) += sf.o
 obj-$(CONFIG_CMD_SCSI) += scsi.o disk.o
 obj-$(CONFIG_CMD_SHA1SUM) += sha1sum.o
diff --git a/cmd/host.c b/cmd/host.c
index 645dba4de83..f7d3eae5b1a 100644
--- a/cmd/host.c
+++ b/cmd/host.c
@@ -167,11 +167,6 @@ static int do_host(cmd_tbl_t *cmdtp, int flag, int argc,
 		return CMD_RET_USAGE;
 }
 
-U_BOOT_CMD(
-	sb,	8,	1,	do_host,
-	"Deprecated: use 'host' command instead.", ""
-);
-
 U_BOOT_CMD(
 	host, 8, 1, do_host,
 	"Miscellaneous host commands",
diff --git a/cmd/sb.c b/cmd/sb.c
new file mode 100644
index 00000000000..6ca3361d7e3
--- /dev/null
+++ b/cmd/sb.c
@@ -0,0 +1,46 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2018, Google Inc.
+ * Written by Simon Glass <sjg at chromium.org>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <spl.h>
+#include <asm/state.h>
+
+static int do_sb_state(cmd_tbl_t *cmdtp, int flag, int argc,
+		       char * const argv[])
+{
+	struct sandbox_state *state;
+
+	state = state_get_current();
+	state_show(state);
+
+	return 0;
+}
+
+static cmd_tbl_t cmd_sb_sub[] = {
+	U_BOOT_CMD_MKENT(state, 1, 0, do_sb_state, "", ""),
+};
+
+static int do_sb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+	cmd_tbl_t *c;
+
+	/* Skip past 'sb' */
+	argc--;
+	argv++;
+
+	c = find_cmd_tbl(argv[0], cmd_sb_sub, ARRAY_SIZE(cmd_sb_sub));
+	if (c)
+		return c->cmd(cmdtp, flag, argc, argv);
+	else
+		return CMD_RET_USAGE;
+}
+
+U_BOOT_CMD(
+	sb,	8,	1,	do_sb,
+	"Sandbox status commands",
+	"state       - Show sandbox state"
+);
-- 
2.19.0.605.g01d371f741-goog



More information about the U-Boot mailing list