summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2021-10-30 16:17:37 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2021-11-01 10:08:38 +0100
commit23bb859cfcefe5225851b00deaf7b61189b8c06d (patch)
tree882de86cfbc9eab8e7e6803e28b42f91a84432dc /include
parent43cbf3f0b718a8c8b0cfc4bb351dde39c6ea9b05 (diff)
downloadbarebox-23bb859cfcefe5225851b00deaf7b61189b8c06d.tar.gz
barebox-23bb859cfcefe5225851b00deaf7b61189b8c06d.tar.xz
include: add dedicated header for printf/printk
Including <stdio.h> for printf is a bit problematic, because it pulls in other headers for <console.h>, which includes quite a few more headers as well. To make it easier to share code between barebox and host tools make <printk.h> the new minimal header for printf and move the extra logging stuff into <linux/printk.h>. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20211030141739.2207431-3-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'include')
-rw-r--r--include/common.h2
-rw-r--r--include/linux/barebox-wrapper.h15
-rw-r--r--include/linux/mtd/mtd.h2
-rw-r--r--include/linux/printk.h173
-rw-r--r--include/printk.h168
-rw-r--r--include/stdio.h8
6 files changed, 190 insertions, 178 deletions
diff --git a/include/common.h b/include/common.h
index 693f5bf970..083b76cfed 100644
--- a/include/common.h
+++ b/include/common.h
@@ -18,7 +18,7 @@
#include <linux/stddef.h>
#include <asm/common.h>
#include <asm/io.h>
-#include <printk.h>
+#include <linux/printk.h>
/*
* sanity check. The Linux Kernel defines only one of __LITTLE_ENDIAN and
diff --git a/include/linux/barebox-wrapper.h b/include/linux/barebox-wrapper.h
index 82c52dd933..83fa9223de 100644
--- a/include/linux/barebox-wrapper.h
+++ b/include/linux/barebox-wrapper.h
@@ -4,6 +4,7 @@
#include <malloc.h>
#include <xfuncs.h>
#include <linux/slab.h>
+#include <printk.h>
#define vmalloc(len) malloc(len)
#define __vmalloc(len, mode, pgsz) malloc(len)
@@ -13,20 +14,6 @@ static inline void vfree(const void *addr)
free((void *)addr);
}
-#define KERN_EMERG "" /* system is unusable */
-#define KERN_ALERT "" /* action must be taken immediately */
-#define KERN_CRIT "" /* critical conditions */
-#define KERN_ERR "" /* error conditions */
-#define KERN_WARNING "" /* warning conditions */
-#define KERN_NOTICE "" /* normal but significant condition */
-#define KERN_INFO "" /* informational */
-#define KERN_DEBUG "" /* debug-level messages */
-#define KERN_CONT ""
-
-#define printk printf
-
-#define pr_warn pr_warning
-
#define __init
#define MODULE_AUTHOR(x)
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index b17e590f5e..f9c4645180 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -11,7 +11,7 @@
#include <driver.h>
#include <errno.h>
-#include <printk.h>
+#include <linux/printk.h>
#include <linux/types.h>
#include <linux/list.h>
#include <linux/mtd/mtd-abi.h>
diff --git a/include/linux/printk.h b/include/linux/printk.h
new file mode 100644
index 0000000000..3f370adb90
--- /dev/null
+++ b/include/linux/printk.h
@@ -0,0 +1,173 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __LINUX_PRINTK_H
+#define __LINUX_PRINTK_H
+
+#include <linux/list.h>
+#include <printk.h>
+
+#define MSG_EMERG 0 /* system is unusable */
+#define MSG_ALERT 1 /* action must be taken immediately */
+#define MSG_CRIT 2 /* critical conditions */
+#define MSG_ERR 3 /* error conditions */
+#define MSG_WARNING 4 /* warning conditions */
+#define MSG_NOTICE 5 /* normal but significant condition */
+#define MSG_INFO 6 /* informational */
+#define MSG_DEBUG 7 /* debug-level messages */
+#define MSG_VDEBUG 8 /* verbose debug messages */
+
+#ifdef VERBOSE_DEBUG
+#define LOGLEVEL MSG_VDEBUG
+#elif defined DEBUG
+#define LOGLEVEL MSG_DEBUG
+#else
+#define LOGLEVEL CONFIG_COMPILE_LOGLEVEL
+#endif
+
+/* debugging and troubleshooting/diagnostic helpers. */
+struct device_d;
+
+#ifndef CONFIG_CONSOLE_NONE
+int dev_printf(int level, const struct device_d *dev, const char *format, ...)
+ __attribute__ ((format(__printf__, 3, 4)));
+#else
+static inline int dev_printf(int level, const struct device_d *dev, const char *format, ...)
+{
+ return 0;
+}
+#endif
+
+#if (!defined(__PBL__) && !defined(CONFIG_CONSOLE_NONE)) || \
+ (defined(__PBL__) && defined(CONFIG_PBL_CONSOLE))
+int pr_print(int level, const char *format, ...)
+ __attribute__ ((format(__printf__, 2, 3)));
+#else
+static int pr_print(int level, const char *format, ...)
+ __attribute__ ((format(__printf__, 2, 3)));
+static inline int pr_print(int level, const char *format, ...)
+{
+ return 0;
+}
+#endif
+
+#define __dev_printf(level, dev, format, args...) \
+ ({ \
+ (level) <= LOGLEVEL ? dev_printf((level), (dev), (format), ##args) : 0; \
+ })
+
+
+#define dev_emerg(dev, format, arg...) \
+ __dev_printf(0, (dev) , format , ## arg)
+#define dev_alert(dev, format, arg...) \
+ __dev_printf(1, (dev) , format , ## arg)
+#define dev_crit(dev, format, arg...) \
+ __dev_printf(2, (dev) , format , ## arg)
+#define dev_err(dev, format, arg...) \
+ __dev_printf(3, (dev) , format , ## arg)
+#define dev_warn(dev, format, arg...) \
+ __dev_printf(4, (dev) , format , ## arg)
+#define dev_notice(dev, format, arg...) \
+ __dev_printf(5, (dev) , format , ## arg)
+#define dev_info(dev, format, arg...) \
+ __dev_printf(6, (dev) , format , ## arg)
+#define dev_dbg(dev, format, arg...) \
+ __dev_printf(7, (dev) , format , ## arg)
+#define dev_vdbg(dev, format, arg...) \
+ __dev_printf(8, (dev) , format , ## arg)
+
+#define __pr_printk(level, format, args...) \
+ ({ \
+ (level) <= LOGLEVEL ? pr_print((level), (format), ##args) : 0; \
+ })
+
+#ifndef pr_fmt
+#define pr_fmt(fmt) fmt
+#endif
+
+#define pr_emerg(fmt, arg...) __pr_printk(0, pr_fmt(fmt), ##arg)
+#define pr_alert(fmt, arg...) __pr_printk(1, pr_fmt(fmt), ##arg)
+#define pr_crit(fmt, arg...) __pr_printk(2, pr_fmt(fmt), ##arg)
+#define pr_err(fmt, arg...) __pr_printk(3, pr_fmt(fmt), ##arg)
+#define pr_warning(fmt, arg...) __pr_printk(4, pr_fmt(fmt), ##arg)
+#define pr_notice(fmt, arg...) __pr_printk(5, pr_fmt(fmt), ##arg)
+#define pr_info(fmt, arg...) __pr_printk(6, pr_fmt(fmt), ##arg)
+#define pr_debug(fmt, arg...) __pr_printk(7, pr_fmt(fmt), ##arg)
+#define debug(fmt, arg...) __pr_printk(7, pr_fmt(fmt), ##arg)
+#define pr_vdebug(fmt, arg...) __pr_printk(8, pr_fmt(fmt), ##arg)
+#define pr_cont(fmt, arg...) __pr_printk(-1, fmt, ##arg)
+
+#define pr_warn pr_warning
+
+int memory_display(const void *addr, loff_t offs, unsigned nbytes, int size,
+ int swab);
+int __pr_memory_display(int level, const void *addr, loff_t offs, unsigned nbytes,
+ int size, int swab, const char *format, ...);
+
+#define pr_memory_display(level, addr, offs, nbytes, size, swab) \
+ ({ \
+ (level) <= LOGLEVEL ? __pr_memory_display((level), (addr), \
+ (offs), (nbytes), (size), (swab), pr_fmt("")) : 0; \
+ })
+
+struct log_entry {
+ struct list_head list;
+ char *msg;
+ void *dummy;
+ uint64_t timestamp;
+ int level;
+};
+
+extern struct list_head barebox_logbuf;
+
+extern void log_clean(unsigned int limit);
+
+#define BAREBOX_LOG_PRINT_RAW BIT(2)
+#define BAREBOX_LOG_DIFF_TIME BIT(1)
+#define BAREBOX_LOG_PRINT_TIME BIT(0)
+
+#define BAREBOX_LOG_PRINT_VDEBUG BIT(8)
+#define BAREBOX_LOG_PRINT_DEBUG BIT(7)
+#define BAREBOX_LOG_PRINT_INFO BIT(6)
+#define BAREBOX_LOG_PRINT_NOTICE BIT(5)
+#define BAREBOX_LOG_PRINT_WARNING BIT(4)
+#define BAREBOX_LOG_PRINT_ERR BIT(3)
+#define BAREBOX_LOG_PRINT_CRIT BIT(2)
+#define BAREBOX_LOG_PRINT_ALERT BIT(1)
+#define BAREBOX_LOG_PRINT_EMERG BIT(0)
+
+int log_writefile(const char *filepath);
+void log_print(unsigned flags, unsigned levels);
+
+struct va_format {
+ const char *fmt;
+ va_list *va;
+};
+
+#if LOGLEVEL >= MSG_DEBUG
+#define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
+ groupsize, buf, len, ascii) \
+ print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize, \
+ groupsize, buf, len, ascii)
+#else
+static inline void print_hex_dump_debug(const char *prefix_str, int prefix_type,
+ int rowsize, int groupsize,
+ const void *buf, size_t len, bool ascii)
+{
+}
+#endif
+
+/**
+ * print_hex_dump_bytes - shorthand form of print_hex_dump() with default params
+ * @prefix_str: string to prefix each line with;
+ * caller supplies trailing spaces for alignment if desired
+ * @prefix_type: controls whether prefix of an offset, address, or none
+ * is printed (%DUMP_PREFIX_OFFSET, %DUMP_PREFIX_ADDRESS, %DUMP_PREFIX_NONE)
+ * @buf: data blob to dump
+ * @len: number of bytes in the @buf
+ *
+ * Calls print_hex_dump(), with log level of KERN_DEBUG,
+ * rowsize of 16, groupsize of 1, and ASCII output included.
+ */
+#define print_hex_dump_bytes(prefix_str, prefix_type, buf, len) \
+ print_hex_dump_debug(prefix_str, prefix_type, 16, 1, buf, len, true)
+
+#endif
diff --git a/include/printk.h b/include/printk.h
index f83ad3bf07..0915efbadd 100644
--- a/include/printk.h
+++ b/include/printk.h
@@ -2,97 +2,28 @@
#ifndef __PRINTK_H
#define __PRINTK_H
-#include <linux/list.h>
-
-#define MSG_EMERG 0 /* system is unusable */
-#define MSG_ALERT 1 /* action must be taken immediately */
-#define MSG_CRIT 2 /* critical conditions */
-#define MSG_ERR 3 /* error conditions */
-#define MSG_WARNING 4 /* warning conditions */
-#define MSG_NOTICE 5 /* normal but significant condition */
-#define MSG_INFO 6 /* informational */
-#define MSG_DEBUG 7 /* debug-level messages */
-#define MSG_VDEBUG 8 /* verbose debug messages */
-
-#ifdef VERBOSE_DEBUG
-#define LOGLEVEL MSG_VDEBUG
-#elif defined DEBUG
-#define LOGLEVEL MSG_DEBUG
-#else
-#define LOGLEVEL CONFIG_COMPILE_LOGLEVEL
-#endif
-
-/* debugging and troubleshooting/diagnostic helpers. */
-struct device_d;
-
-#ifndef CONFIG_CONSOLE_NONE
-int dev_printf(int level, const struct device_d *dev, const char *format, ...)
- __attribute__ ((format(__printf__, 3, 4)));
-#else
-static inline int dev_printf(int level, const struct device_d *dev, const char *format, ...)
-{
- return 0;
-}
-#endif
+#define KERN_EMERG "" /* system is unusable */
+#define KERN_ALERT "" /* action must be taken immediately */
+#define KERN_CRIT "" /* critical conditions */
+#define KERN_ERR "" /* error conditions */
+#define KERN_WARNING "" /* warning conditions */
+#define KERN_NOTICE "" /* normal but significant condition */
+#define KERN_INFO "" /* informational */
+#define KERN_DEBUG "" /* debug-level messages */
+#define KERN_CONT ""
#if (!defined(__PBL__) && !defined(CONFIG_CONSOLE_NONE)) || \
(defined(__PBL__) && defined(CONFIG_PBL_CONSOLE))
-int pr_print(int level, const char *format, ...)
- __attribute__ ((format(__printf__, 2, 3)));
+int printf(const char *fmt, ...) __attribute__ ((format(__printf__, 1, 2)));
#else
-static int pr_print(int level, const char *format, ...)
- __attribute__ ((format(__printf__, 2, 3)));
-static inline int pr_print(int level, const char *format, ...)
+static int printf(const char *fmt, ...) __attribute__ ((format(__printf__, 1, 2)));
+static inline int printf(const char *fmt, ...)
{
return 0;
}
#endif
-#define __dev_printf(level, dev, format, args...) \
- ({ \
- (level) <= LOGLEVEL ? dev_printf((level), (dev), (format), ##args) : 0; \
- })
-
-
-#define dev_emerg(dev, format, arg...) \
- __dev_printf(0, (dev) , format , ## arg)
-#define dev_alert(dev, format, arg...) \
- __dev_printf(1, (dev) , format , ## arg)
-#define dev_crit(dev, format, arg...) \
- __dev_printf(2, (dev) , format , ## arg)
-#define dev_err(dev, format, arg...) \
- __dev_printf(3, (dev) , format , ## arg)
-#define dev_warn(dev, format, arg...) \
- __dev_printf(4, (dev) , format , ## arg)
-#define dev_notice(dev, format, arg...) \
- __dev_printf(5, (dev) , format , ## arg)
-#define dev_info(dev, format, arg...) \
- __dev_printf(6, (dev) , format , ## arg)
-#define dev_dbg(dev, format, arg...) \
- __dev_printf(7, (dev) , format , ## arg)
-#define dev_vdbg(dev, format, arg...) \
- __dev_printf(8, (dev) , format , ## arg)
-
-#define __pr_printk(level, format, args...) \
- ({ \
- (level) <= LOGLEVEL ? pr_print((level), (format), ##args) : 0; \
- })
-
-#ifndef pr_fmt
-#define pr_fmt(fmt) fmt
-#endif
-
-#define pr_emerg(fmt, arg...) __pr_printk(0, pr_fmt(fmt), ##arg)
-#define pr_alert(fmt, arg...) __pr_printk(1, pr_fmt(fmt), ##arg)
-#define pr_crit(fmt, arg...) __pr_printk(2, pr_fmt(fmt), ##arg)
-#define pr_err(fmt, arg...) __pr_printk(3, pr_fmt(fmt), ##arg)
-#define pr_warning(fmt, arg...) __pr_printk(4, pr_fmt(fmt), ##arg)
-#define pr_notice(fmt, arg...) __pr_printk(5, pr_fmt(fmt), ##arg)
-#define pr_info(fmt, arg...) __pr_printk(6, pr_fmt(fmt), ##arg)
-#define pr_debug(fmt, arg...) __pr_printk(7, pr_fmt(fmt), ##arg)
-#define debug(fmt, arg...) __pr_printk(7, pr_fmt(fmt), ##arg)
-#define pr_vdebug(fmt, arg...) __pr_printk(8, pr_fmt(fmt), ##arg)
-#define pr_cont(fmt, arg...) __pr_printk(-1, fmt, ##arg)
+#define printk printf
#define printk_once(fmt, ...) \
({ \
@@ -104,51 +35,6 @@ static inline int pr_print(int level, const char *format, ...)
} \
})
-int memory_display(const void *addr, loff_t offs, unsigned nbytes, int size,
- int swab);
-int __pr_memory_display(int level, const void *addr, loff_t offs, unsigned nbytes,
- int size, int swab, const char *format, ...);
-
-#define pr_memory_display(level, addr, offs, nbytes, size, swab) \
- ({ \
- (level) <= LOGLEVEL ? __pr_memory_display((level), (addr), \
- (offs), (nbytes), (size), (swab), pr_fmt("")) : 0; \
- })
-
-struct log_entry {
- struct list_head list;
- char *msg;
- void *dummy;
- uint64_t timestamp;
- int level;
-};
-
-extern struct list_head barebox_logbuf;
-
-extern void log_clean(unsigned int limit);
-
-#define BAREBOX_LOG_PRINT_RAW BIT(2)
-#define BAREBOX_LOG_DIFF_TIME BIT(1)
-#define BAREBOX_LOG_PRINT_TIME BIT(0)
-
-#define BAREBOX_LOG_PRINT_VDEBUG BIT(8)
-#define BAREBOX_LOG_PRINT_DEBUG BIT(7)
-#define BAREBOX_LOG_PRINT_INFO BIT(6)
-#define BAREBOX_LOG_PRINT_NOTICE BIT(5)
-#define BAREBOX_LOG_PRINT_WARNING BIT(4)
-#define BAREBOX_LOG_PRINT_ERR BIT(3)
-#define BAREBOX_LOG_PRINT_CRIT BIT(2)
-#define BAREBOX_LOG_PRINT_ALERT BIT(1)
-#define BAREBOX_LOG_PRINT_EMERG BIT(0)
-
-int log_writefile(const char *filepath);
-void log_print(unsigned flags, unsigned levels);
-
-struct va_format {
- const char *fmt;
- va_list *va;
-};
-
enum {
DUMP_PREFIX_NONE,
DUMP_PREFIX_ADDRESS,
@@ -161,32 +47,4 @@ extern void print_hex_dump(const char *level, const char *prefix_str,
int prefix_type, int rowsize, int groupsize,
const void *buf, size_t len, bool ascii);
-#if LOGLEVEL >= MSG_DEBUG
-#define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
- groupsize, buf, len, ascii) \
- print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize, \
- groupsize, buf, len, ascii)
-#else
-static inline void print_hex_dump_debug(const char *prefix_str, int prefix_type,
- int rowsize, int groupsize,
- const void *buf, size_t len, bool ascii)
-{
-}
-#endif
-
-/**
- * print_hex_dump_bytes - shorthand form of print_hex_dump() with default params
- * @prefix_str: string to prefix each line with;
- * caller supplies trailing spaces for alignment if desired
- * @prefix_type: controls whether prefix of an offset, address, or none
- * is printed (%DUMP_PREFIX_OFFSET, %DUMP_PREFIX_ADDRESS, %DUMP_PREFIX_NONE)
- * @buf: data blob to dump
- * @len: number of bytes in the @buf
- *
- * Calls print_hex_dump(), with log level of KERN_DEBUG,
- * rowsize of 16, groupsize of 1, and ASCII output included.
- */
-#define print_hex_dump_bytes(prefix_str, prefix_type, buf, len) \
- print_hex_dump_debug(prefix_str, prefix_type, 16, 1, buf, len, true)
-
#endif
diff --git a/include/stdio.h b/include/stdio.h
index 1cb11e88de..49f3d0cf77 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -4,6 +4,7 @@
#include <stdarg.h>
#include <console.h>
+#include <printk.h>
/*
* STDIO based functions (can always be used)
@@ -71,8 +72,6 @@ static inline int ctrlc (void)
#if (!defined(__PBL__) && !defined(CONFIG_CONSOLE_NONE)) || \
(defined(__PBL__) && defined(CONFIG_PBL_CONSOLE))
-int printf(const char *fmt, ...) __attribute__ ((format(__printf__, 1, 2)));
-
static inline int puts(const char *s)
{
return console_puts(CONSOLE_STDOUT, s);
@@ -83,11 +82,6 @@ static inline void putchar(char c)
console_putc(CONSOLE_STDOUT, c);
}
#else
-static int printf(const char *fmt, ...) __attribute__ ((format(__printf__, 1, 2)));
-static inline int printf(const char *fmt, ...)
-{
- return 0;
-}
static inline int puts(const char *s)
{
return 0;