Commit 0e98b0a65092d6573eb17d07e04455f9cf545b21

Authored by Simon Glass
Committed by Tom Rini
1 parent 64e9b4f346

Move debug and logging support to a separate header

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>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

Showing 2 changed files with 60 additions and 45 deletions Side-by-side Diff

... ... @@ -45,51 +45,7 @@
45 45 #define CONFIG_SYS_SUPPORT_64BIT_DATA
46 46 #endif
47 47  
48   -#ifdef DEBUG
49   -#define _DEBUG 1
50   -#else
51   -#define _DEBUG 0
52   -#endif
53   -
54   -#ifdef CONFIG_SPL_BUILD
55   -#define _SPL_BUILD 1
56   -#else
57   -#define _SPL_BUILD 0
58   -#endif
59   -
60   -/*
61   - * Output a debug text when condition "cond" is met. The "cond" should be
62   - * computed by a preprocessor in the best case, allowing for the best
63   - * optimization.
64   - */
65   -#define debug_cond(cond, fmt, args...) \
66   - do { \
67   - if (cond) \
68   - printf(pr_fmt(fmt), ##args); \
69   - } while (0)
70   -
71   -/* Show a message if DEBUG is defined in a file */
72   -#define debug(fmt, args...) \
73   - debug_cond(_DEBUG, fmt, ##args)
74   -
75   -/* Show a message if not in SPL */
76   -#define warn_non_spl(fmt, args...) \
77   - debug_cond(!_SPL_BUILD, fmt, ##args)
78   -
79   -/*
80   - * An assertion is run-time check done in debug mode only. If DEBUG is not
81   - * defined then it is skipped. If DEBUG is defined and the assertion fails,
82   - * then it calls panic*( which may or may not reset/halt U-Boot (see
83   - * CONFIG_PANIC_HANG), It is hoped that all failing assertions are found
84   - * before release, and after release it is hoped that they don't matter. But
85   - * in any case these failing assertions cannot be fixed with a reset (which
86   - * may just do the same assertion again).
87   - */
88   -void __assert_fail(const char *assertion, const char *file, unsigned line,
89   - const char *function);
90   -#define assert(x) \
91   - ({ if (!(x) && _DEBUG) \
92   - __assert_fail(#x, __FILE__, __LINE__, __func__); })
  48 +#include <log.h>
93 49  
94 50 typedef void (interrupt_handler_t)(void *);
95 51  
  1 +/*
  2 + * Logging support
  3 + *
  4 + * Copyright (c) 2017 Google, Inc
  5 + * Written by Simon Glass <sjg@chromium.org>
  6 + *
  7 + * SPDX-License-Identifier: GPL-2.0+
  8 + */
  9 +
  10 +#ifndef __LOG_H
  11 +#define __LOG_H
  12 +
  13 +#ifdef DEBUG
  14 +#define _DEBUG 1
  15 +#else
  16 +#define _DEBUG 0
  17 +#endif
  18 +
  19 +#ifdef CONFIG_SPL_BUILD
  20 +#define _SPL_BUILD 1
  21 +#else
  22 +#define _SPL_BUILD 0
  23 +#endif
  24 +
  25 +/*
  26 + * Output a debug text when condition "cond" is met. The "cond" should be
  27 + * computed by a preprocessor in the best case, allowing for the best
  28 + * optimization.
  29 + */
  30 +#define debug_cond(cond, fmt, args...) \
  31 + do { \
  32 + if (cond) \
  33 + printf(pr_fmt(fmt), ##args); \
  34 + } while (0)
  35 +
  36 +/* Show a message if DEBUG is defined in a file */
  37 +#define debug(fmt, args...) \
  38 + debug_cond(_DEBUG, fmt, ##args)
  39 +
  40 +/* Show a message if not in SPL */
  41 +#define warn_non_spl(fmt, args...) \
  42 + debug_cond(!_SPL_BUILD, fmt, ##args)
  43 +
  44 +/*
  45 + * An assertion is run-time check done in debug mode only. If DEBUG is not
  46 + * defined then it is skipped. If DEBUG is defined and the assertion fails,
  47 + * then it calls panic*( which may or may not reset/halt U-Boot (see
  48 + * CONFIG_PANIC_HANG), It is hoped that all failing assertions are found
  49 + * before release, and after release it is hoped that they don't matter. But
  50 + * in any case these failing assertions cannot be fixed with a reset (which
  51 + * may just do the same assertion again).
  52 + */
  53 +void __assert_fail(const char *assertion, const char *file, unsigned int line,
  54 + const char *function);
  55 +#define assert(x) \
  56 + ({ if (!(x) && _DEBUG) \
  57 + __assert_fail(#x, __FILE__, __LINE__, __func__); })
  58 +
  59 +#endif