* [PATCH 1/2] sandbox: add --command line support
@ 2024-10-16 8:55 Ahmad Fatoum
2024-10-16 8:55 ` [PATCH 2/2] sandbox: add cpuinfo command Ahmad Fatoum
2024-10-16 9:54 ` [PATCH 1/2] sandbox: add --command line support Yann Sionneau
0 siblings, 2 replies; 7+ messages in thread
From: Ahmad Fatoum @ 2024-10-16 8:55 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum, Yann Sionneau
For easier non-interactive use of sandbox, let's add support to execute
arbitrary commands from the command line directly.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
Cc: Yann Sionneau <ysionneau@kalrayinc.com>
---
arch/sandbox/Kconfig | 1 +
arch/sandbox/os/common.c | 18 +++++++++++++++++-
common/Kconfig | 7 +++++++
common/startup.c | 13 ++++++++++++-
include/shell.h | 9 +++++++++
5 files changed, 46 insertions(+), 2 deletions(-)
diff --git a/arch/sandbox/Kconfig b/arch/sandbox/Kconfig
index d82027e75047..52915490ca98 100644
--- a/arch/sandbox/Kconfig
+++ b/arch/sandbox/Kconfig
@@ -20,6 +20,7 @@ config SANDBOX
select HAS_DEBUG_LL
select ARCH_DMA_DEFAULT_COHERENT
select ARCH_WANT_FRAME_POINTERS
+ select BAREBOX_CMDLINE
default y
config ARCH_TEXT_BASE
diff --git a/arch/sandbox/os/common.c b/arch/sandbox/os/common.c
index 3446074f99d0..14018b2a63b0 100644
--- a/arch/sandbox/os/common.c
+++ b/arch/sandbox/os/common.c
@@ -492,12 +492,20 @@ static int add_dtb(const char *file)
return -1;
}
+static char *cmdline;
+
+const char *barebox_cmdline_get(void)
+{
+ return cmdline;
+}
+
static void print_usage(const char*);
static struct option long_options[] = {
{"help", 0, 0, 'h'},
{"malloc", 1, 0, 'm'},
{"image", 1, 0, 'i'},
+ {"command", 1, 0, 'c'},
{"env", 1, 0, 'e'},
{"dtb", 1, 0, 'd'},
{"stdout", 1, 0, 'O'},
@@ -508,7 +516,7 @@ static struct option long_options[] = {
{0, 0, 0, 0},
};
-static const char optstring[] = "hm:i:e:d:O:I:B:x:y:";
+static const char optstring[] = "hm:i:c:e:d:O:I:B:x:y:";
int main(int argc, char *argv[])
{
@@ -516,6 +524,7 @@ int main(int argc, char *argv[])
int opt, ret, fd, fd2;
int malloc_size = CONFIG_MALLOC_SIZE;
int fdno = 0, envno = 0, option_index = 0;
+ char *new_cmdline;
char *aux;
#ifdef CONFIG_ASAN
@@ -539,6 +548,12 @@ int main(int argc, char *argv[])
break;
case 'i':
break;
+ case 'c':
+ if (asprintf(&new_cmdline, "%s%s\n", cmdline ?: "", optarg) < 0)
+ exit(1);
+ free(cmdline);
+ cmdline = new_cmdline;
+ break;
case 'e':
break;
case 'd':
@@ -669,6 +684,7 @@ static void print_usage(const char *prgname)
" -i, --image=<dev>=<file>\n"
" Same as above, the files will show up as\n"
" /dev/<dev>\n"
+" -c, --command=<cmd> Run extra command after init scripts\n"
" -e, --env=<file> Map a file with an environment to barebox. With this \n"
" option, files are mapped as /dev/env0 ... /dev/envx\n"
" and thus are used as the default environment.\n"
diff --git a/common/Kconfig b/common/Kconfig
index 859356038386..f2245c464056 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -406,6 +406,13 @@ config SIMPLE_READLINE
default y
depends on !CMDLINE_EDITING
+config BAREBOX_CMDLINE
+ bool
+ help
+ Support a barebox command line when running virtualized.
+ The commands are appended onto /cmdline, which is sourced
+ after sourcing all init scripts.
+
config CBSIZE
int
prompt "Buffer size for input from the Console"
diff --git a/common/startup.c b/common/startup.c
index 47b70a7756cb..e8bc90aa7f66 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -30,6 +30,7 @@
#include <magicvar.h>
#include <linux/reboot-mode.h>
#include <asm/sections.h>
+#include <libfile.h>
#include <uncompress.h>
#include <globalvar.h>
#include <console_countdown.h>
@@ -240,7 +241,7 @@ postcore_initcall(register_autoboot_vars);
static int run_init(void)
{
- const char *bmode;
+ const char *bmode, *cmdline;
bool env_bin_init_exists;
enum autoboot_state autoboot;
struct stat s;
@@ -289,6 +290,16 @@ static int run_init(void)
globfree(&g);
}
+ cmdline = barebox_cmdline_get();
+ if (cmdline) {
+ ret = write_file("/cmdline", cmdline, strlen(cmdline));
+ if (ret)
+ return ret;
+
+ console_ctrlc_allow();
+ run_command("source /cmdline");
+ }
+
/* source matching script in /env/bmode/ */
bmode = reboot_mode_get();
if (bmode) {
diff --git a/include/shell.h b/include/shell.h
index 073f18102b45..b399564ff391 100644
--- a/include/shell.h
+++ b/include/shell.h
@@ -19,4 +19,13 @@ static inline char *shell_expand(char *str)
}
#endif
+#ifdef CONFIG_BAREBOX_CMDLINE
+const char *barebox_cmdline_get(void);
+#else
+static inline const char *barebox_cmdline_get(void)
+{
+ return NULL;
+}
+#endif
+
#endif /* __SHELL_H__ */
--
2.39.5
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 2/2] sandbox: add cpuinfo command
2024-10-16 8:55 [PATCH 1/2] sandbox: add --command line support Ahmad Fatoum
@ 2024-10-16 8:55 ` Ahmad Fatoum
2024-10-16 9:32 ` Yann Sionneau
2024-10-16 9:54 ` [PATCH 1/2] sandbox: add --command line support Yann Sionneau
1 sibling, 1 reply; 7+ messages in thread
From: Ahmad Fatoum @ 2024-10-16 8:55 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
We have stack dump support in sandbox via AddressSanitizer, if it's
compiled in. To make it easier to test proper operation, let's a cpuinfo
command like we already do on ARM and give it the same -s option.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/sandbox/Kconfig | 7 +++++++
arch/sandbox/board/Makefile | 1 +
arch/sandbox/board/cpuinfo.c | 40 ++++++++++++++++++++++++++++++++++++
3 files changed, 48 insertions(+)
create mode 100644 arch/sandbox/board/cpuinfo.c
diff --git a/arch/sandbox/Kconfig b/arch/sandbox/Kconfig
index 52915490ca98..caff3a138fea 100644
--- a/arch/sandbox/Kconfig
+++ b/arch/sandbox/Kconfig
@@ -58,6 +58,13 @@ config SANDBOX_REEXEC
The normal reset handler hangs barebox. On Linux, barebox
instead can exec itself to simulate a reset.
+config CMD_SANDBOX_CPUINFO
+ bool "cpuinfo command"
+ depends on COMMAND_SUPPORT
+ default y
+ help
+ Say yes here to get a dummy cpuinfo command.
+
config SDL
bool
diff --git a/arch/sandbox/board/Makefile b/arch/sandbox/board/Makefile
index 8e6e1d2d8843..029bfe7ff163 100644
--- a/arch/sandbox/board/Makefile
+++ b/arch/sandbox/board/Makefile
@@ -10,6 +10,7 @@ obj-y += dtb.o
obj-y += power.o
obj-y += dev-random.o
obj-y += watchdog.o
+obj-$(CONFIG_CMD_SANDBOX_CPUINFO) += cpuinfo.o
obj-$(CONFIG_LED) += led.o
extra-y += barebox.lds
diff --git a/arch/sandbox/board/cpuinfo.c b/arch/sandbox/board/cpuinfo.c
new file mode 100644
index 000000000000..ce2762e607fd
--- /dev/null
+++ b/arch/sandbox/board/cpuinfo.c
@@ -0,0 +1,40 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <common.h>
+#include <getopt.h>
+#include <command.h>
+#include <complete.h>
+
+static int do_cpuinfo(int argc, char *argv[])
+{
+ int opt;
+
+ while ((opt = getopt(argc, argv, "s")) > 0) {
+ switch (opt) {
+ case 's':
+ if (!IS_ENABLED(CONFIG_ARCH_HAS_STACK_DUMP))
+ return -ENOSYS;
+
+ dump_stack();
+ return 0;
+ default:
+ return COMMAND_ERROR_USAGE;
+ }
+ }
+
+ return 0;
+}
+
+BAREBOX_CMD_HELP_START(cpuinfo)
+BAREBOX_CMD_HELP_TEXT("Shows misc info about CPU")
+BAREBOX_CMD_HELP_OPT ("-s", "print call stack info (if supported)")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(cpuinfo)
+ .cmd = do_cpuinfo,
+ BAREBOX_CMD_DESC("show info about CPU")
+ BAREBOX_CMD_OPTS("[-s]")
+ BAREBOX_CMD_GROUP(CMD_GRP_INFO)
+ BAREBOX_CMD_COMPLETE(empty_complete)
+ BAREBOX_CMD_HELP(cmd_cpuinfo_help)
+BAREBOX_CMD_END
--
2.39.5
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] sandbox: add cpuinfo command
2024-10-16 8:55 ` [PATCH 2/2] sandbox: add cpuinfo command Ahmad Fatoum
@ 2024-10-16 9:32 ` Yann Sionneau
2024-10-18 9:06 ` Sascha Hauer
0 siblings, 1 reply; 7+ messages in thread
From: Yann Sionneau @ 2024-10-16 9:32 UTC (permalink / raw)
To: barebox
Hi Ahmad,
On 16/10/2024 10:55, Ahmad Fatoum wrote:
> We have stack dump support in sandbox via AddressSanitizer, if it's
> compiled in. To make it easier to test proper operation, let's a cpuinfo
Small typo in the commit msg
> command like we already do on ARM and give it the same -s option.
>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>
> +BAREBOX_CMD_START(cpuinfo)
> + .cmd = do_cpuinfo,
> + BAREBOX_CMD_DESC("show info about CPU")
> + BAREBOX_CMD_OPTS("[-s]")
It seems the -s option here is mandatory, maybe remove the [ ] brackets? Not sure if it means "optional" here...
Regards,
--
Yann
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] sandbox: add --command line support
2024-10-16 8:55 [PATCH 1/2] sandbox: add --command line support Ahmad Fatoum
2024-10-16 8:55 ` [PATCH 2/2] sandbox: add cpuinfo command Ahmad Fatoum
@ 2024-10-16 9:54 ` Yann Sionneau
2024-10-16 9:56 ` Ahmad Fatoum
1 sibling, 1 reply; 7+ messages in thread
From: Yann Sionneau @ 2024-10-16 9:54 UTC (permalink / raw)
To: Ahmad Fatoum, barebox
Hi Ahmad,
On 16/10/2024 10:55, Ahmad Fatoum wrote:
> For easier non-interactive use of sandbox, let's add support to execute
> arbitrary commands from the command line directly.
>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> Cc: Yann Sionneau <ysionneau@kalrayinc.com>
> ---
Reviewed-by: Yann Sionneau <ysionneau@kalrayinc.com>
Thanks, good idea, this could allow arch or drivers to implement a cmdline mechanism.
--
Yann
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] sandbox: add --command line support
2024-10-16 9:54 ` [PATCH 1/2] sandbox: add --command line support Yann Sionneau
@ 2024-10-16 9:56 ` Ahmad Fatoum
0 siblings, 0 replies; 7+ messages in thread
From: Ahmad Fatoum @ 2024-10-16 9:56 UTC (permalink / raw)
To: Yann Sionneau, barebox
Hello Yann,
On 16.10.24 11:54, Yann Sionneau wrote:
> Hi Ahmad,
>
> On 16/10/2024 10:55, Ahmad Fatoum wrote:
>> For easier non-interactive use of sandbox, let's add support to execute
>> arbitrary commands from the command line directly.
>>
>> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
>> ---
>> Cc: Yann Sionneau <ysionneau@kalrayinc.com>
>> ---
> Reviewed-by: Yann Sionneau <ysionneau@kalrayinc.com>
>
> Thanks, good idea, this could allow arch or drivers to implement a cmdline mechanism.
It would be cool to have this for qemu-system-* -append, but I haven't figured out yet
how to access that in barebox yet.
Glad you like it,
Ahmad
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] sandbox: add cpuinfo command
2024-10-16 9:32 ` Yann Sionneau
@ 2024-10-18 9:06 ` Sascha Hauer
2024-10-21 7:35 ` Ahmad Fatoum
0 siblings, 1 reply; 7+ messages in thread
From: Sascha Hauer @ 2024-10-18 9:06 UTC (permalink / raw)
To: Yann Sionneau; +Cc: barebox
On Wed, Oct 16, 2024 at 11:32:40AM +0200, Yann Sionneau wrote:
> Hi Ahmad,
>
> On 16/10/2024 10:55, Ahmad Fatoum wrote:
> > We have stack dump support in sandbox via AddressSanitizer, if it's
> > compiled in. To make it easier to test proper operation, let's a cpuinfo
> Small typo in the commit msg
> > command like we already do on ARM and give it the same -s option.
> >
> > Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> > ---
> >
> > +BAREBOX_CMD_START(cpuinfo)
> > + .cmd = do_cpuinfo,
> > + BAREBOX_CMD_DESC("show info about CPU")
> > + BAREBOX_CMD_OPTS("[-s]")
>
> It seems the -s option here is mandatory, maybe remove the [ ] brackets? Not sure if it means "optional" here...
The ARM cpuinfo command shows information about the CPU when called
without options, so on ARM -s is really optional and I think Ahmad
wanted the same behaviour here. It's a bit unfortunate that the sandbox
command doesn't have any information to show when called without
options.
Sascha
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] sandbox: add cpuinfo command
2024-10-18 9:06 ` Sascha Hauer
@ 2024-10-21 7:35 ` Ahmad Fatoum
0 siblings, 0 replies; 7+ messages in thread
From: Ahmad Fatoum @ 2024-10-21 7:35 UTC (permalink / raw)
To: Sascha Hauer, Yann Sionneau; +Cc: barebox
Hello Sascha,
On 18.10.24 11:06, Sascha Hauer wrote:
> On Wed, Oct 16, 2024 at 11:32:40AM +0200, Yann Sionneau wrote:
>> Hi Ahmad,
>>
>> On 16/10/2024 10:55, Ahmad Fatoum wrote:
>>> We have stack dump support in sandbox via AddressSanitizer, if it's
>>> compiled in. To make it easier to test proper operation, let's a cpuinfo
>> Small typo in the commit msg
>>> command like we already do on ARM and give it the same -s option.
>>>
>>> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
>>> ---
>>>
>>> +BAREBOX_CMD_START(cpuinfo)
>>> + .cmd = do_cpuinfo,
>>> + BAREBOX_CMD_DESC("show info about CPU")
>>> + BAREBOX_CMD_OPTS("[-s]")
>>
>> It seems the -s option here is mandatory, maybe remove the [ ] brackets? Not sure if it means "optional" here...
>
> The ARM cpuinfo command shows information about the CPU when called
> without options, so on ARM -s is really optional and I think Ahmad
> wanted the same behaviour here. It's a bit unfortunate that the sandbox
> command doesn't have any information to show when called without
> options.
I can output host system uname -a output in the argumentless case.
I will prepare a v2 in a few days.
Cheers,
Ahmad
>
> Sascha
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-10-21 7:43 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-16 8:55 [PATCH 1/2] sandbox: add --command line support Ahmad Fatoum
2024-10-16 8:55 ` [PATCH 2/2] sandbox: add cpuinfo command Ahmad Fatoum
2024-10-16 9:32 ` Yann Sionneau
2024-10-18 9:06 ` Sascha Hauer
2024-10-21 7:35 ` Ahmad Fatoum
2024-10-16 9:54 ` [PATCH 1/2] sandbox: add --command line support Yann Sionneau
2024-10-16 9:56 ` Ahmad Fatoum
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox