From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 03/13] Move debug and logging support to a separate header
Date: Sat, 16 Sep 2017 15:23:16 -0600 [thread overview]
Message-ID: <20170916212331.170463-4-sjg@chromium.org> (raw)
In-Reply-To: <20170916212331.170463-1-sjg@chromium.org>
Before adding new features, move these definitions to a separate header
to avoid further cluttering common.h.
Signed-off-by: Simon Glass <sjg@chromium.org>
---
include/common.h | 64 +--------------------------------------------
include/log.h | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 80 insertions(+), 63 deletions(-)
create mode 100644 include/log.h
diff --git a/include/common.h b/include/common.h
index aaed131671..459d273389 100644
--- a/include/common.h
+++ b/include/common.h
@@ -42,69 +42,7 @@ typedef volatile unsigned char vu_char;
#define CONFIG_SYS_SUPPORT_64BIT_DATA
#endif
-#ifdef DEBUG
-#define _DEBUG 1
-#else
-#define _DEBUG 0
-#endif
-
-#ifdef CONFIG_SPL_BUILD
-#define _SPL_BUILD 1
-#else
-#define _SPL_BUILD 0
-#endif
-
-/* Define this at the top of a file to add a prefix to debug messages */
-#ifndef pr_fmt
-#define pr_fmt(fmt) fmt
-#endif
-
-/*
- * Output a debug text when condition "cond" is met. The "cond" should be
- * computed by a preprocessor in the best case, allowing for the best
- * optimization.
- */
-#define debug_cond(cond, fmt, args...) \
- do { \
- if (cond) \
- printf(pr_fmt(fmt), ##args); \
- } while (0)
-
-/* Show a message if DEBUG is defined in a file */
-#define debug(fmt, args...) \
- debug_cond(_DEBUG, fmt, ##args)
-
-/* Show a message if not in SPL */
-#define warn_non_spl(fmt, args...) \
- debug_cond(!_SPL_BUILD, fmt, ##args)
-
-/*
- * An assertion is run-time check done in debug mode only. If DEBUG is not
- * defined then it is skipped. If DEBUG is defined and the assertion fails,
- * then it calls panic*( which may or may not reset/halt U-Boot (see
- * CONFIG_PANIC_HANG), It is hoped that all failing assertions are found
- * before release, and after release it is hoped that they don't matter. But
- * in any case these failing assertions cannot be fixed with a reset (which
- * may just do the same assertion again).
- */
-void __assert_fail(const char *assertion, const char *file, unsigned line,
- const char *function);
-#define assert(x) \
- ({ if (!(x) && _DEBUG) \
- __assert_fail(#x, __FILE__, __LINE__, __func__); })
-
-#define error(fmt, args...) do { \
- printf("ERROR: " pr_fmt(fmt) "\nat %s:%d/%s()\n", \
- ##args, __FILE__, __LINE__, __func__); \
-} while (0)
-
-#ifndef BUG
-#define BUG() do { \
- printf("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __FUNCTION__); \
- panic("BUG!"); \
-} while (0)
-#define BUG_ON(condition) do { if (unlikely((condition)!=0)) BUG(); } while(0)
-#endif /* BUG */
+#include <log.h>
typedef void (interrupt_handler_t)(void *);
diff --git a/include/log.h b/include/log.h
new file mode 100644
index 0000000000..4101a74161
--- /dev/null
+++ b/include/log.h
@@ -0,0 +1,79 @@
+/*
+ * Logging support
+ *
+ * Copyright (c) 2017 Google, Inc
+ * Written by Simon Glass <sjg@chromium.org>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#ifndef __LOG_H
+#define __LOG_H
+
+#ifdef DEBUG
+#define _DEBUG 1
+#else
+#define _DEBUG 0
+#endif
+
+#ifdef CONFIG_SPL_BUILD
+#define _SPL_BUILD 1
+#else
+#define _SPL_BUILD 0
+#endif
+
+/* Define this at the top of a file to add a prefix to debug messages */
+#ifndef pr_fmt
+#define pr_fmt(fmt) fmt
+#endif
+
+/*
+ * Output a debug text when condition "cond" is met. The "cond" should be
+ * computed by a preprocessor in the best case, allowing for the best
+ * optimization.
+ */
+#define debug_cond(cond, fmt, args...) \
+ do { \
+ if (cond) \
+ printf(pr_fmt(fmt), ##args); \
+ } while (0)
+
+/* Show a message if DEBUG is defined in a file */
+#define debug(fmt, args...) \
+ debug_cond(_DEBUG, fmt, ##args)
+
+/* Show a message if not in SPL */
+#define warn_non_spl(fmt, args...) \
+ debug_cond(!_SPL_BUILD, fmt, ##args)
+
+/*
+ * An assertion is run-time check done in debug mode only. If DEBUG is not
+ * defined then it is skipped. If DEBUG is defined and the assertion fails,
+ * then it calls panic*( which may or may not reset/halt U-Boot (see
+ * CONFIG_PANIC_HANG), It is hoped that all failing assertions are found
+ * before release, and after release it is hoped that they don't matter. But
+ * in any case these failing assertions cannot be fixed with a reset (which
+ * may just do the same assertion again).
+ */
+void __assert_fail(const char *assertion, const char *file, unsigned int line,
+ const char *function);
+#define assert(x) \
+ ({ if (!(x) && _DEBUG) \
+ __assert_fail(#x, __FILE__, __LINE__, __func__); })
+
+#define error(fmt, args...) do { \
+ printf("ERROR: " pr_fmt(fmt) "\nat %s:%d/%s()\n", \
+ ##args, __FILE__, __LINE__, __func__); \
+} while (0)
+
+#ifndef BUG
+#define BUG() do { \
+ printf("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, \
+ __func__); \
+ panic("BUG!"); \
+} while (0)
+#define BUG_ON(condition) do { if (unlikely((condition) != 0)) BUG(); } \
+ while (0)
+#endif /* BUG */
+
+#endif
--
2.14.1.690.gbb1197296e-goog
next prev parent reply other threads:[~2017-09-16 21:23 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-16 21:23 [U-Boot] [PATCH 00/13] log: Add a new logging feature Simon Glass
2017-09-16 21:23 ` [U-Boot] [PATCH 01/13] Revert "sandbox: remove os_putc() and os_puts()" Simon Glass
2017-09-17 12:48 ` Bin Meng
2017-09-17 17:55 ` Simon Glass
2017-09-16 21:23 ` [U-Boot] [PATCH 02/13] Revert "sandbox: Drop special case console code for sandbox" Simon Glass
2017-09-17 12:50 ` Bin Meng
2017-09-17 17:55 ` Simon Glass
2017-09-16 21:23 ` Simon Glass [this message]
2017-09-17 12:52 ` [U-Boot] [PATCH 03/13] Move debug and logging support to a separate header Bin Meng
2017-09-16 21:23 ` [U-Boot] [PATCH 04/13] mtdparts: Correct use of debug() Simon Glass
2017-09-17 12:54 ` Bin Meng
2017-09-16 21:23 ` [U-Boot] [PATCH 05/13] Drop the log buffer Simon Glass
2017-09-17 12:58 ` Bin Meng
2017-09-16 21:23 ` [U-Boot] [PATCH 06/13] log: Add an implemention of logging Simon Glass
2017-09-18 3:45 ` Bin Meng
2017-09-20 13:50 ` Simon Glass
2017-09-20 14:41 ` Bin Meng
2017-09-20 14:51 ` Dr. Philipp Tomsich
2017-09-21 4:58 ` Simon Glass
2017-09-22 13:37 ` Bin Meng
2017-09-25 2:14 ` Simon Glass
2017-09-20 2:51 ` Masahiro Yamada
2017-09-20 13:49 ` Simon Glass
2017-09-20 14:37 ` Dr. Philipp Tomsich
2017-09-20 17:34 ` Masahiro Yamada
2017-09-20 17:51 ` Dr. Philipp Tomsich
2017-09-27 16:19 ` Masahiro Yamada
2017-09-20 17:19 ` Masahiro Yamada
2017-09-26 19:10 ` Simon Glass
2017-09-27 17:11 ` Masahiro Yamada
2017-09-28 12:39 ` Simon Glass
2017-09-16 21:23 ` [U-Boot] [PATCH 07/13] log: Add a console driver Simon Glass
2017-09-18 3:45 ` Bin Meng
2017-09-26 19:10 ` Simon Glass
2017-09-16 21:23 ` [U-Boot] [PATCH 08/13] log: Add a 'log level' command Simon Glass
2017-09-18 3:46 ` Bin Meng
2017-09-16 21:23 ` [U-Boot] [PATCH 09/13] log: Add a test command Simon Glass
2017-09-18 3:47 ` Bin Meng
2017-09-16 21:23 ` [U-Boot] [PATCH 10/13] log: Plumb logging into the init sequence Simon Glass
2017-09-18 3:47 ` Bin Meng
2017-09-16 21:23 ` [U-Boot] [PATCH 11/13] log: sandbox: Enable logging Simon Glass
2017-09-18 3:47 ` Bin Meng
2017-09-16 21:23 ` [U-Boot] [PATCH 12/13] log: test: Add a pytest for logging Simon Glass
2017-09-16 21:23 ` [U-Boot] [PATCH 13/13] log: Add documentation Simon Glass
2017-09-18 3:47 ` Bin Meng
2017-09-20 3:04 ` Masahiro Yamada
2017-09-20 13:49 ` Simon Glass
2017-09-20 2:32 ` [U-Boot] [PATCH 00/13] log: Add a new logging feature Masahiro Yamada
2017-09-20 20:20 ` Heinrich Schuchardt
2017-09-21 4:58 ` Simon Glass
2017-09-20 19:55 ` Wolfgang Denk
2017-09-21 4:58 ` Simon Glass
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170916212331.170463-4-sjg@chromium.org \
--to=sjg@chromium.org \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox