* [PATCH 2/4] bug: add support for CONFIG_DEBUG_BUGVERBOSE
2025-11-28 12:50 [PATCH 1/4] printf: define printk/no_printk in terms of prints Ahmad Fatoum
@ 2025-11-28 12:50 ` Ahmad Fatoum
2025-11-28 12:50 ` [PATCH 3/4] include: move sprintf prototypes to new linux/sprintf.h Ahmad Fatoum
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2025-11-28 12:50 UTC (permalink / raw)
To: barebox
From: Ahmad Fatoum <a.fatoum@barebox.org>
This can be used to remove panic strings from barebox, when there is no
way to look at them anyway.
Also add a CONFIG_BUG symbol as it will make it easier to port kernel
code that checks for the symbol without having to patch it.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
common/Kconfig | 11 +++++++++++
include/asm-generic/bug.h | 26 +++++++++++++++++++-------
2 files changed, 30 insertions(+), 7 deletions(-)
diff --git a/common/Kconfig b/common/Kconfig
index 7c9b28543ffa..7442e24026e0 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -902,6 +902,17 @@ config PBL_CONSOLE
must be running at the address it's linked at and bss must
be cleared. On ARM that would be after setup_c().
+config BUG
+ def_bool y
+
+config DEBUG_BUGVERBOSE
+ bool "Verbose BUG() reporting"
+ depends on BUG
+ default y
+ help
+ Say Y here to make WARN_ONCE() and BUG() panics output the file name
+ and line number of the BUG/WARN call as well as the EIP and oops trace.
+
source "common/ratp/Kconfig"
config PARTITION
diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h
index 389327adfc5d..ca75b1c7646e 100644
--- a/include/asm-generic/bug.h
+++ b/include/asm-generic/bug.h
@@ -6,15 +6,27 @@
#include <linux/compiler.h>
#include <printf.h>
-#define BUG() do { \
- printf("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __FUNCTION__); \
- panic("BUG!"); \
+#ifdef CONFIG_DEBUG_BUGVERBOSE
+#define __bug_printf printf
+#define __bug_panic panic
+#define __bug_dump_stack dump_stack
+#else
+#define __bug_printf no_printf
+#define __bug_panic panic_no_stacktrace
+#define __bug_dump_stack (void)0
+#endif
+
+#define BUG() do { \
+ __bug_printf("BUG: failure at %s:%d/%s()!\n", \
+ __FILE__, __LINE__, __FUNCTION__); \
+ __bug_panic("BUG!"); \
} while (0)
#define BUG_ON(condition) do { if (unlikely((condition)!=0)) BUG(); } while(0)
-#define __WARN() do { \
- printf("WARNING: at %s:%d/%s()!\n", __FILE__, __LINE__, __FUNCTION__); \
+#define __WARN() do { \
+ __bug_printf("WARNING: at %s:%d/%s()!\n", \
+ __FILE__, __LINE__, __FUNCTION__); \
} while (0)
#ifndef WARN_ON
@@ -31,7 +43,7 @@
int __ret_warn_on = !!(condition); \
if (unlikely(__ret_warn_on)) { \
__WARN(); \
- printf("WARNING: " format); \
+ __bug_printf("WARNING: " format); \
} \
unlikely(__ret_warn_on); \
})
@@ -44,7 +56,7 @@
if (unlikely(__ret_warn_once)) { \
if (WARN(!__warned, format)) { \
__warned = 1; \
- dump_stack(); \
+ __bug_dump_stack(); \
} \
} \
unlikely(__ret_warn_once); \
--
2.47.3
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH 3/4] include: move sprintf prototypes to new linux/sprintf.h
2025-11-28 12:50 [PATCH 1/4] printf: define printk/no_printk in terms of prints Ahmad Fatoum
2025-11-28 12:50 ` [PATCH 2/4] bug: add support for CONFIG_DEBUG_BUGVERBOSE Ahmad Fatoum
@ 2025-11-28 12:50 ` Ahmad Fatoum
2025-11-28 12:50 ` [PATCH 4/4] console: move non-stdio elements to console.h Ahmad Fatoum
2025-12-01 10:22 ` [PATCH 1/4] printf: define printk/no_printk in terms of prints Sascha Hauer
3 siblings, 0 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2025-11-28 12:50 UTC (permalink / raw)
To: barebox
From: Ahmad Fatoum <a.fatoum@barebox.org>
The <stdio.h> header mixes console and sprintf functionality. Get a
little closer to the Linux split by moving the sprintf family of
functions to <linux/sprintf.h>.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
include/linux/sprintf.h | 48 +++++++++++++++++++++++++++++++++++++++++
include/stdio.h | 39 +--------------------------------
2 files changed, 49 insertions(+), 38 deletions(-)
create mode 100644 include/linux/sprintf.h
diff --git a/include/linux/sprintf.h b/include/linux/sprintf.h
new file mode 100644
index 000000000000..349773d3e16a
--- /dev/null
+++ b/include/linux/sprintf.h
@@ -0,0 +1,48 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_KERNEL_SPRINTF_H_
+#define _LINUX_KERNEL_SPRINTF_H_
+
+#include <linux/types.h>
+#include <stdarg.h>
+
+int sprintf(char *buf, const char *fmt, ...) __printf(2, 3);
+int snprintf(char *buf, size_t size, const char *fmt, ...) __printf(3, 4);
+int scnprintf(char *buf, size_t size, const char *fmt, ...) __printf(3, 4);
+int vsprintf(char *buf, const char *fmt, va_list args);
+int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
+int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
+
+#if IN_PROPER || defined(CONFIG_PBL_CONSOLE)
+int asprintf(char **strp, const char *fmt, ...) __printf(2, 3);
+char *bvasprintf(const char *fmt, va_list ap);
+int vasprintf(char **strp, const char *fmt, va_list ap);
+int vrasprintf(char **strp, const char *fmt, va_list ap);
+int rasprintf(char **strp, const char *fmt, ...) __printf(2, 3);
+#else
+static inline __printf(2, 3) int asprintf(char **strp, const char *fmt, ...)
+{
+ return -1;
+}
+static inline char *bvasprintf(const char *fmt, va_list ap)
+{
+ return NULL;
+}
+static inline int vasprintf(char **strp, const char *fmt, va_list ap)
+{
+ return -1;
+}
+static inline int vrasprintf(char **strp, const char *fmt, va_list ap)
+{
+ return -1;
+}
+static inline __printf(2, 3) int rasprintf(char **strp, const char *fmt, ...)
+{
+ return -1;
+}
+#endif
+
+#define basprintf xasprintf
+
+const char *size_human_readable(unsigned long long size);
+
+#endif /* _LINUX_KERNEL_SPRINTF_H */
diff --git a/include/stdio.h b/include/stdio.h
index f3e430b3b3d5..c0043b08bcc5 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -6,47 +6,11 @@
#include <console.h>
#include <printf.h>
#include <xfuncs.h>
+#include <linux/sprintf.h>
/*
* STDIO based functions (can always be used)
*/
-int sprintf(char *buf, const char *fmt, ...) __printf(2, 3);
-int snprintf(char *buf, size_t size, const char *fmt, ...) __printf(3, 4);
-int scnprintf(char *buf, size_t size, const char *fmt, ...) __printf(3, 4);
-int vsprintf(char *buf, const char *fmt, va_list args);
-int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
-int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
-
-#if IN_PROPER || defined(CONFIG_PBL_CONSOLE)
-int asprintf(char **strp, const char *fmt, ...) __printf(2, 3);
-char *bvasprintf(const char *fmt, va_list ap);
-int vasprintf(char **strp, const char *fmt, va_list ap);
-int vrasprintf(char **strp, const char *fmt, va_list ap);
-int rasprintf(char **strp, const char *fmt, ...) __printf(2, 3);
-#else
-static inline __printf(2, 3) int asprintf(char **strp, const char *fmt, ...)
-{
- return -1;
-}
-static inline char *bvasprintf(const char *fmt, va_list ap)
-{
- return NULL;
-}
-static inline int vasprintf(char **strp, const char *fmt, va_list ap)
-{
- return -1;
-}
-static inline int vrasprintf(char **strp, const char *fmt, va_list ap)
-{
- return -1;
-}
-static inline __printf(2, 3) int rasprintf(char **strp, const char *fmt, ...)
-{
- return -1;
-}
-#endif
-
-#define basprintf xasprintf
#ifdef CONFIG_ARCH_HAS_CTRLC
int arch_ctrlc(void);
@@ -113,7 +77,6 @@ static inline void console_ctrlc_allow(void) { }
static inline void console_ctrlc_forbid(void) { }
#endif
-const char *size_human_readable(unsigned long long size);
int readline(const char *prompt, char *buf, int len);
#if (IN_PROPER && !defined(CONFIG_CONSOLE_NONE)) || \
--
2.47.3
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH 4/4] console: move non-stdio elements to console.h
2025-11-28 12:50 [PATCH 1/4] printf: define printk/no_printk in terms of prints Ahmad Fatoum
2025-11-28 12:50 ` [PATCH 2/4] bug: add support for CONFIG_DEBUG_BUGVERBOSE Ahmad Fatoum
2025-11-28 12:50 ` [PATCH 3/4] include: move sprintf prototypes to new linux/sprintf.h Ahmad Fatoum
@ 2025-11-28 12:50 ` Ahmad Fatoum
2025-12-01 10:22 ` [PATCH 1/4] printf: define printk/no_printk in terms of prints Sascha Hauer
3 siblings, 0 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2025-11-28 12:50 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
To prepare addition of more functions that hosted implementations
provide in stdio.h, let's move existing console functionality into the
console.h header, where they belong.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/console.h | 33 +++++++++++++++++
include/stdio.h | 93 +++++------------------------------------------
2 files changed, 42 insertions(+), 84 deletions(-)
diff --git a/include/console.h b/include/console.h
index 37e127e175c9..149378fc2839 100644
--- a/include/console.h
+++ b/include/console.h
@@ -222,6 +222,39 @@ static inline int barebox_set_loglevel(int loglevel)
}
#endif
+#ifdef CONFIG_ARCH_HAS_CTRLC
+int arch_ctrlc(void);
+#endif
+
+#ifndef CONFIG_CONSOLE_NONE
+/* stdout */
+void console_putc(unsigned int ch, const char c);
+int console_puts(unsigned int ch, const char *s);
+void console_flush(void);
+
+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 console_puts(unsigned int ch, const char *str) { return 0; }
+static inline void console_putc(unsigned int ch, char c) {}
+static inline void console_flush(void) {}
+
+/* test if ctrl-c was pressed */
+static inline int ctrlc (void) { return 0; }
+static inline int ctrlc_non_interruptible(void) { return 0; }
+static inline void ctrlc_handled(void) { }
+static inline void console_ctrlc_allow(void) { }
+static inline void console_ctrlc_forbid(void) { }
+#endif
+
+#define STDIN_FILENO 0
+#define STDOUT_FILENO 1
+#define STDERR_FILENO 2
+#define MAX_FILES 128
+
/**
* 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 c0043b08bcc5..945ec4692609 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -8,100 +8,30 @@
#include <xfuncs.h>
#include <linux/sprintf.h>
-/*
- * STDIO based functions (can always be used)
- */
-
-#ifdef CONFIG_ARCH_HAS_CTRLC
-int arch_ctrlc(void);
-#endif
-
#ifndef CONFIG_CONSOLE_NONE
/* stdin */
int tstc(void);
-
-/* stdout */
-void console_putc(unsigned int ch, const char c);
int getchar(void);
-int console_puts(unsigned int ch, const char *s);
-void console_flush(void);
-
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)
-{
- return 0;
-}
-
-static inline int console_puts(unsigned int ch, const char *str)
-{
- return 0;
-}
-
-static inline int getchar(void)
-{
- return -EINVAL;
-}
-
-static inline void console_putc(unsigned int ch, char c) {}
-
-static inline void console_flush(void) {}
-
-static inline int vprintf(const char *fmt, va_list args)
-{
- return 0;
-}
-
-/* test if ctrl-c was pressed */
-static inline int ctrlc (void)
-{
- return 0;
-}
-
-static inline int ctrlc_non_interruptible(void)
-{
- return 0;
-}
-
-static inline void ctrlc_handled(void)
-{
-}
-
-static inline void console_ctrlc_allow(void) { }
-static inline void console_ctrlc_forbid(void) { }
+static inline int tstc(void) { return 0; }
+static inline int vprintf(const char *fmt, va_list args) { return 0; }
+static inline int getchar(void) { return -EINVAL; }
#endif
int readline(const char *prompt, char *buf, int len);
#if (IN_PROPER && !defined(CONFIG_CONSOLE_NONE)) || \
(IN_PBL && defined(CONFIG_PBL_CONSOLE))
-static inline int puts(const char *s)
-{
- return console_puts(CONSOLE_STDOUT, s);
-}
-
-static inline void putchar(char c)
-{
- console_putc(CONSOLE_STDOUT, c);
-}
+static inline int puts(const char *s) { return console_puts(CONSOLE_STDOUT, s); }
+static inline void putchar(char c) { console_putc(CONSOLE_STDOUT, c); }
#else
-static inline int puts(const char *s)
-{
- return 0;
-}
-
-static inline void putchar(char c)
-{
- return;
-}
+static inline int puts(const char *s) { return 0; }
+static inline void putchar(char c) {}
#endif
+int readline(const char *prompt, char *buf, int len);
+
/*
* FILE based functions
*/
@@ -116,11 +46,6 @@ static inline void putchar(char c)
#define eputchar(ch) dputc(STDERR_FILENO, ch)
#endif
-#define STDIN_FILENO 0
-#define STDOUT_FILENO 1
-#define STDERR_FILENO 2
-#define MAX_FILES 128
-
int vdprintf(int fd, const char *fmt, va_list args) ;
int dprintf(int file, const char *fmt, ...) __printf(2, 3);
int dputs(int file, const char *s);
--
2.47.3
^ permalink raw reply [flat|nested] 5+ messages in thread