* [PATCH master 1/3] console: move full ctrl+c implementation into separate file
@ 2025-09-01 14:12 Ahmad Fatoum
2025-09-01 14:12 ` [PATCH master 2/3] console: simple: use common ctrl+c implementation Ahmad Fatoum
2025-09-01 14:12 ` [PATCH master 3/3] sandbox: add simpleconsole_defconfig Ahmad Fatoum
0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2025-09-01 14:12 UTC (permalink / raw)
To: barebox; +Cc: fpg, Ahmad Fatoum
There is no reason to keep different ctrl+c implementations for the full
and simple console case. In preparation for unifying them, move the
implementation into its own file.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
common/Makefile | 2 +-
common/console.c | 60 -------------------------------------
common/console_ctrlc.c | 67 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 68 insertions(+), 61 deletions(-)
create mode 100644 common/console_ctrlc.c
diff --git a/common/Makefile b/common/Makefile
index 7a91ef21f79b..9f98de72854f 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -32,7 +32,7 @@ obj-$(CONFIG_BOOTM) += bootm.o booti.o
obj-$(CONFIG_CMD_LOADS) += s_record.o
obj-$(CONFIG_MEMTEST) += memtest.o
obj-$(CONFIG_COMMAND_SUPPORT) += command.o
-obj-$(CONFIG_CONSOLE_FULL) += console.o
+obj-$(CONFIG_CONSOLE_FULL) += console.o console_ctrlc.o
obj-$(CONFIG_CONSOLE_SIMPLE) += console_simple.o
obj-y += console_countdown.o
obj-pbl-$(CONFIG_DDR_SPD) += ddr_spd.o
diff --git a/common/console.c b/common/console.c
index dc552e4c5dac..a31433a659e2 100644
--- a/common/console.c
+++ b/common/console.c
@@ -635,65 +635,5 @@ void console_flush(void)
}
EXPORT_SYMBOL(console_flush);
-static int ctrlc_abort;
-static int ctrlc_allowed;
-
-void ctrlc_handled(void)
-{
- ctrlc_abort = 0;
-}
-
-int ctrlc_non_interruptible(void)
-{
- int ret = 0;
-
- if (!ctrlc_allowed)
- return 0;
-
- if (ctrlc_abort)
- return 1;
-
-#ifdef CONFIG_ARCH_HAS_CTRLC
- ret = arch_ctrlc();
-#else
- if (tstc() && getchar() == 3)
- ret = 1;
-#endif
-
- if (ret)
- ctrlc_abort = 1;
-
- return ret;
-}
-EXPORT_SYMBOL(ctrlc_non_interruptible);
-
-/* test if ctrl-c was pressed */
-int ctrlc(void)
-{
- resched();
- return ctrlc_non_interruptible();
-}
-EXPORT_SYMBOL(ctrlc);
-
-static int console_ctrlc_init(void)
-{
- globalvar_add_simple_bool("console.ctrlc_allowed", &ctrlc_allowed);
- return 0;
-}
-device_initcall(console_ctrlc_init);
-
-void console_ctrlc_allow(void)
-{
- ctrlc_allowed = 1;
-}
-
-void console_ctrlc_forbid(void)
-{
- ctrlc_allowed = 0;
-}
-
-BAREBOX_MAGICVAR(global.console.ctrlc_allowed,
- "If true, scripts can be aborted with ctrl-c");
-
BAREBOX_MAGICVAR(global.linux.bootargs.console,
"console= argument for Linux from the stdout-path property in /chosen node");
diff --git a/common/console_ctrlc.c b/common/console_ctrlc.c
new file mode 100644
index 000000000000..0272eec280d1
--- /dev/null
+++ b/common/console_ctrlc.c
@@ -0,0 +1,67 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include <stdio.h>
+#include <console.h>
+#include <sched.h>
+#include <globalvar.h>
+#include <magicvar.h>
+
+static int ctrlc_abort;
+static int ctrlc_allowed;
+
+void ctrlc_handled(void)
+{
+ ctrlc_abort = 0;
+}
+
+int ctrlc_non_interruptible(void)
+{
+ int ret = 0;
+
+ if (!ctrlc_allowed)
+ return 0;
+
+ if (ctrlc_abort)
+ return 1;
+
+#ifdef CONFIG_ARCH_HAS_CTRLC
+ ret = arch_ctrlc();
+#else
+ if (tstc() && getchar() == 3)
+ ret = 1;
+#endif
+
+ if (ret)
+ ctrlc_abort = 1;
+
+ return ret;
+}
+EXPORT_SYMBOL(ctrlc_non_interruptible);
+
+/* test if ctrl-c was pressed */
+int ctrlc(void)
+{
+ resched();
+ return ctrlc_non_interruptible();
+}
+EXPORT_SYMBOL(ctrlc);
+
+static int console_ctrlc_init(void)
+{
+ globalvar_add_simple_bool("console.ctrlc_allowed", &ctrlc_allowed);
+ return 0;
+}
+device_initcall(console_ctrlc_init);
+
+void console_ctrlc_allow(void)
+{
+ ctrlc_allowed = 1;
+}
+
+void console_ctrlc_forbid(void)
+{
+ ctrlc_allowed = 0;
+}
+
+BAREBOX_MAGICVAR(global.console.ctrlc_allowed,
+ "If true, scripts can be aborted with ctrl-c");
--
2.47.2
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH master 2/3] console: simple: use common ctrl+c implementation
2025-09-01 14:12 [PATCH master 1/3] console: move full ctrl+c implementation into separate file Ahmad Fatoum
@ 2025-09-01 14:12 ` Ahmad Fatoum
2025-09-01 14:12 ` [PATCH master 3/3] sandbox: add simpleconsole_defconfig Ahmad Fatoum
1 sibling, 0 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2025-09-01 14:12 UTC (permalink / raw)
To: barebox; +Cc: fpg, Ahmad Fatoum
The simple console ctrl+c implementation doesn't define ctrlc_handled()
leading to build errors in some configurations.
Just reuse the normal ctrl+c implementation to fix this.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
common/Makefile | 2 +-
common/console_simple.c | 14 --------------
include/console.h | 8 --------
include/stdio.h | 4 ++++
4 files changed, 5 insertions(+), 23 deletions(-)
diff --git a/common/Makefile b/common/Makefile
index 9f98de72854f..d501a6a2755a 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -33,7 +33,7 @@ obj-$(CONFIG_CMD_LOADS) += s_record.o
obj-$(CONFIG_MEMTEST) += memtest.o
obj-$(CONFIG_COMMAND_SUPPORT) += command.o
obj-$(CONFIG_CONSOLE_FULL) += console.o console_ctrlc.o
-obj-$(CONFIG_CONSOLE_SIMPLE) += console_simple.o
+obj-$(CONFIG_CONSOLE_SIMPLE) += console_simple.o console_ctrlc.o
obj-y += console_countdown.o
obj-pbl-$(CONFIG_DDR_SPD) += ddr_spd.o
obj-pbl-$(CONFIG_DDR_SPD) += ddr1_dimm_params.o
diff --git a/common/console_simple.c b/common/console_simple.c
index 702087bd23d7..d2feb58ea3e2 100644
--- a/common/console_simple.c
+++ b/common/console_simple.c
@@ -66,20 +66,6 @@ void console_flush(void)
}
EXPORT_SYMBOL(console_flush);
-/* test if ctrl-c was pressed */
-int ctrlc (void)
-{
- int ret = 0;
-#ifdef CONFIG_ARCH_HAS_CTRLC
- ret = arch_ctrlc();
-#else
- if (tstc() && getchar() == 3)
- ret = 1;
-#endif
- return ret;
-}
-EXPORT_SYMBOL(ctrlc);
-
int console_register(struct console_device *newcdev)
{
if (console)
diff --git a/include/console.h b/include/console.h
index 8d3ec33bfac6..590a78110d04 100644
--- a/include/console.h
+++ b/include/console.h
@@ -222,14 +222,6 @@ static inline int barebox_set_loglevel(int loglevel)
}
#endif
-#ifdef CONFIG_CONSOLE_FULL
-void console_ctrlc_allow(void);
-void console_ctrlc_forbid(void);
-#else
-static inline void console_ctrlc_allow(void) { }
-static inline void console_ctrlc_forbid(void) { }
-#endif
-
/**
* clk_get_for_console - get clock, ignoring known unavailable clock controller
* @dev: device for clock "consumer"
diff --git a/include/stdio.h b/include/stdio.h
index 62a0748e8edc..cecb97ea1a26 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -57,6 +57,8 @@ int vprintf(const char *fmt, va_list args);
int ctrlc(void);
int ctrlc_non_interruptible(void);
void ctrlc_handled(void);
+void console_ctrlc_allow(void);
+void console_ctrlc_forbid(void);
#else
static inline int tstc(void)
{
@@ -97,6 +99,8 @@ static inline void ctrlc_handled(void)
{
}
+static inline void console_ctrlc_allow(void) { }
+static inline void console_ctrlc_forbid(void) { }
#endif
const char *size_human_readable(unsigned long long size);
--
2.47.2
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH master 3/3] sandbox: add simpleconsole_defconfig
2025-09-01 14:12 [PATCH master 1/3] console: move full ctrl+c implementation into separate file Ahmad Fatoum
2025-09-01 14:12 ` [PATCH master 2/3] console: simple: use common ctrl+c implementation Ahmad Fatoum
@ 2025-09-01 14:12 ` Ahmad Fatoum
1 sibling, 0 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2025-09-01 14:12 UTC (permalink / raw)
To: barebox; +Cc: fpg, Ahmad Fatoum
We only tested in CI the build with hush and full console and the
headless build with neither. Missing is a build with a simple console
and a simple shell, so breakage in the simple console went unnoticed.
Add a new configuration, so CI can test it.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/sandbox/Makefile | 4 +++-
common/boards/configs/simpleconsole.config | 2 ++
2 files changed, 5 insertions(+), 1 deletion(-)
create mode 100644 common/boards/configs/simpleconsole.config
diff --git a/arch/sandbox/Makefile b/arch/sandbox/Makefile
index f9d79e9a7d15..55b8ca1780df 100644
--- a/arch/sandbox/Makefile
+++ b/arch/sandbox/Makefile
@@ -3,13 +3,15 @@
KBUILD_DEFCONFIG := sandbox_defconfig
generated_configs += headless_defconfig noshell_defconfig lockdown_defconfig \
- libfuzzer_defconfig
+ simpleconsole_defconfig libfuzzer_defconfig
headless_defconfig:
$(call merge_into_defconfig,sandbox_defconfig,headless)
noshell_defconfig:
$(call merge_into_defconfig,sandbox_defconfig,noshell)
lockdown_defconfig:
$(call merge_into_defconfig,sandbox_defconfig,headless noshell)
+simpleconsole_defconfig:
+ $(call merge_into_defconfig,sandbox_defconfig,simpleconsole)
libfuzzer_defconfig:
$(call merge_into_defconfig,sandbox_defconfig,libfuzzer)
diff --git a/common/boards/configs/simpleconsole.config b/common/boards/configs/simpleconsole.config
new file mode 100644
index 000000000000..1ac5f27a9644
--- /dev/null
+++ b/common/boards/configs/simpleconsole.config
@@ -0,0 +1,2 @@
+CONFIG_CONSOLE_SIMPLE=y
+CONFIG_SHELL_SIMPLE=y
--
2.47.2
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-09-01 17:29 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-01 14:12 [PATCH master 1/3] console: move full ctrl+c implementation into separate file Ahmad Fatoum
2025-09-01 14:12 ` [PATCH master 2/3] console: simple: use common ctrl+c implementation Ahmad Fatoum
2025-09-01 14:12 ` [PATCH master 3/3] sandbox: add simpleconsole_defconfig Ahmad Fatoum
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox