All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] log: Allow LOG_DEBUG to always enable log output
@ 2020-05-06 14:03 Simon Glass
  2020-05-06 14:03 ` [PATCH 2/3] lib: Allow MD5 to be enabled in SPL Simon Glass
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Simon Glass @ 2020-05-06 14:03 UTC (permalink / raw)
  To: u-boot

At present if CONFIG_LOG enabled, putting LOG_DEBUG at the top of a file
(before log.h inclusion) causes _log() to be executed for every log()
call, regardless of the build- or run-time logging level.

However there is no guarantee that the log record will actually be
displayed. If the current log level is lower than LOGL_DEBUG then it will
not be.

Add a way to signal that the log record should always be displayed and
update log_passes_filters() to handle this.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 common/log.c   |  6 +++++-
 doc/README.log |  7 ++-----
 include/log.h  | 16 ++++++++++++----
 3 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/common/log.c b/common/log.c
index c5b9b489ca..db7bb7d145 100644
--- a/common/log.c
+++ b/common/log.c
@@ -153,6 +153,9 @@ static bool log_passes_filters(struct log_device *ldev, struct log_rec *rec)
 {
 	struct log_filter *filt;
 
+	if (rec->force_debug)
+		return true;
+
 	/* If there are no filters, filter on the default log level */
 	if (list_empty(&ldev->filter_head)) {
 		if (rec->level > gd->default_log_level)
@@ -204,7 +207,8 @@ int _log(enum log_category_t cat, enum log_level_t level, const char *file,
 	va_list args;
 
 	rec.cat = cat;
-	rec.level = level;
+	rec.level = level & LOGL_LEVEL_MASK;
+	rec.force_debug = level & LOGL_FORCE_DEBUG;
 	rec.file = file;
 	rec.line = line;
 	rec.func = func;
diff --git a/doc/README.log b/doc/README.log
index 1057981f45..0df0336fb3 100644
--- a/doc/README.log
+++ b/doc/README.log
@@ -77,11 +77,8 @@ Sometimes it is useful to turn on logging just in one file. You can use this:
    #define LOG_DEBUG
 
 to enable building in of all logging statements in a single file. Put it at
-the top of the file, before any #includes.
-
-To actually get U-Boot to output this you need to also set the default logging
-level - e.g. set CONFIG_LOG_DEFAULT_LEVEL to 7 (LOGL_DEBUG) or more. Otherwise
-debug output is suppressed and will not be generated.
+the top of the file, before any #includes. This overrides any log-level setting
+in U-Boot, including CONFIG_LOG_DEFAULT_LEVEL, but just for that file.
 
 
 Convenience functions
diff --git a/include/log.h b/include/log.h
index cf32351134..2e6e06cae6 100644
--- a/include/log.h
+++ b/include/log.h
@@ -29,6 +29,9 @@ enum log_level_t {
 	LOGL_COUNT,
 	LOGL_NONE,
 
+	LOGL_LEVEL_MASK = 0xf,	/* Mask for valid log levels */
+	LOGL_FORCE_DEBUG = 0x10, /* Mask to force output due to LOG_DEBUG */
+
 	LOGL_FIRST = LOGL_EMERG,
 	LOGL_MAX = LOGL_DEBUG_IO,
 };
@@ -129,7 +132,7 @@ static inline int _log_nop(enum log_category_t cat, enum log_level_t level,
 
 #if CONFIG_IS_ENABLED(LOG)
 #ifdef LOG_DEBUG
-#define _LOG_DEBUG	1
+#define _LOG_DEBUG	LOGL_FORCE_DEBUG
 #else
 #define _LOG_DEBUG	0
 #endif
@@ -137,9 +140,9 @@ static inline int _log_nop(enum log_category_t cat, enum log_level_t level,
 /* Emit a log record if the level is less that the maximum */
 #define log(_cat, _level, _fmt, _args...) ({ \
 	int _l = _level; \
-	if (CONFIG_IS_ENABLED(LOG) && (_l <= _LOG_MAX_LEVEL || _LOG_DEBUG)) \
-		_log((enum log_category_t)(_cat), _l, __FILE__, __LINE__, \
-		      __func__, \
+	if (CONFIG_IS_ENABLED(LOG) && (_LOG_DEBUG || _l <= _LOG_MAX_LEVEL)) \
+		_log((enum log_category_t)(_cat), _l | _LOG_DEBUG, __FILE__, \
+		     __LINE__, __func__, \
 		      pr_fmt(_fmt), ##_args); \
 	})
 #else
@@ -275,8 +278,12 @@ void __assert_fail(const char *assertion, const char *file, unsigned int line,
  * Memebers marked as 'allocated' are allocated (e.g. via strdup()) by the log
  * system.
  *
+ * TODO(sjg@chromium.org): Compress this struct down a bit to reduce space, e.g.
+ * a single u32 for cat, level, line and force_debug
+ *
  * @cat: Category, representing a uclass or part of U-Boot
  * @level: Severity level, less severe is higher
+ * @force_debug: Force output of debug
  * @file: Name of file where the log record was generated (not allocated)
  * @line: Line number where the log record was generated
  * @func: Function where the log record was generated (not allocated)
@@ -285,6 +292,7 @@ void __assert_fail(const char *assertion, const char *file, unsigned int line,
 struct log_rec {
 	enum log_category_t cat;
 	enum log_level_t level;
+	bool force_debug;
 	const char *file;
 	int line;
 	const char *func;
-- 
2.26.2.645.ge9eca65c58-goog

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/3] lib: Allow MD5 to be enabled in SPL
  2020-05-06 14:03 [PATCH 1/3] log: Allow LOG_DEBUG to always enable log output Simon Glass
@ 2020-05-06 14:03 ` Simon Glass
  2020-05-15 20:53   ` Tom Rini
  2020-05-06 14:03 ` [PATCH 3/3] lib: Allow hexdump to be used " Simon Glass
  2020-05-15 18:47 ` [PATCH 1/3] log: Allow LOG_DEBUG to always enable log output Tom Rini
  2 siblings, 1 reply; 7+ messages in thread
From: Simon Glass @ 2020-05-06 14:03 UTC (permalink / raw)
  To: u-boot

At present the MD5 option cannot be enabled by board configs since it has
no Kconfig name. It is generally enabled, so long as FIT support is
present. But not all boards use FIT, particularly in SPL

Fix this and add an option for SPL as well. This allows board code to call
md5() even if FIT support is not enabled.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 lib/Kconfig  | 17 ++++++++++++++++-
 lib/Makefile |  2 +-
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/lib/Kconfig b/lib/Kconfig
index 868de3bf3b..c3f694afc0 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -363,7 +363,22 @@ config SHA_PROG_HW_ACCEL
 	  is performed in hardware.
 
 config MD5
-	bool
+	bool "Support MD5 algorithm"
+	help
+	  This option enables MD5 support. MD5 is an algorithm designed
+	  in 1991 that produces a 16-byte digest (or checksum) from its input
+	  data. It has a number of vulnerabilities which preclude its use in
+	  security applications, but it can be useful for providing a quick
+	  checksum of a block of data.
+
+config SPL_MD5
+	bool "Support MD5 algorithm in SPL"
+	help
+	  This option enables MD5 support in SPL. MD5 is an algorithm designed
+	  in 1991 that produces a 16-byte digest (or checksum) from its input
+	  data. It has a number of vulnerabilities which preclude its use in
+	  security applications, but it can be useful for providing a quick
+	  checksum of a block of data.
 
 config CRC32C
 	bool
diff --git a/lib/Makefile b/lib/Makefile
index c6f862b0c2..6e688afa68 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -40,7 +40,6 @@ obj-$(CONFIG_GZIP_COMPRESSED) += gzip.o
 obj-$(CONFIG_GENERATE_SMBIOS_TABLE) += smbios.o
 obj-$(CONFIG_IMAGE_SPARSE) += image-sparse.o
 obj-y += ldiv.o
-obj-$(CONFIG_MD5) += md5.o
 obj-$(CONFIG_XXHASH) += xxhash.o
 obj-y += net_utils.o
 obj-$(CONFIG_PHYSMEM) += physmem.o
@@ -59,6 +58,7 @@ obj-$(CONFIG_TPM_V2) += tpm-v2.o
 endif
 
 obj-$(CONFIG_$(SPL_)ACPIGEN) += acpi/
+obj-$(CONFIG_$(SPL_)MD5) += md5.o
 obj-$(CONFIG_$(SPL_)RSA) += rsa/
 obj-$(CONFIG_SHA1) += sha1.o
 obj-$(CONFIG_SHA256) += sha256.o
-- 
2.26.2.645.ge9eca65c58-goog

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/3] lib: Allow hexdump to be used in SPL
  2020-05-06 14:03 [PATCH 1/3] log: Allow LOG_DEBUG to always enable log output Simon Glass
  2020-05-06 14:03 ` [PATCH 2/3] lib: Allow MD5 to be enabled in SPL Simon Glass
@ 2020-05-06 14:03 ` Simon Glass
  2020-05-06 15:11   ` Stefan Roese
  2020-05-15 18:17   ` Tom Rini
  2020-05-15 18:47 ` [PATCH 1/3] log: Allow LOG_DEBUG to always enable log output Tom Rini
  2 siblings, 2 replies; 7+ messages in thread
From: Simon Glass @ 2020-05-06 14:03 UTC (permalink / raw)
  To: u-boot

It is sometimes useful to output hex dumps in SPL. Add a config option to
allow this.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 lib/Kconfig  | 6 ++++++
 lib/Makefile | 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/lib/Kconfig b/lib/Kconfig
index c3f694afc0..df052e1d59 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -491,6 +491,12 @@ config HEXDUMP
 	help
 	  This enables functions for printing dumps of binary data.
 
+config SPL_HEXDUMP
+	bool "Enable hexdump in SPL"
+	help
+	  This enables functions for printing dumps of binary data in
+	  SPL.
+
 config OF_LIBFDT
 	bool "Enable the FDT library"
 	default y if OF_CONTROL
diff --git a/lib/Makefile b/lib/Makefile
index 6e688afa68..a022fb9455 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -104,7 +104,7 @@ obj-$(CONFIG_REGEX) += slre.o
 obj-y += string.o
 obj-y += tables_csum.o
 obj-y += time.o
-obj-y += hexdump.o
+obj-$(CONFIG_$(SPL_)HEXDUMP) += hexdump.o
 obj-$(CONFIG_TRACE) += trace.o
 obj-$(CONFIG_LIB_UUID) += uuid.o
 obj-$(CONFIG_LIB_RAND) += rand.o
-- 
2.26.2.645.ge9eca65c58-goog

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/3] lib: Allow hexdump to be used in SPL
  2020-05-06 14:03 ` [PATCH 3/3] lib: Allow hexdump to be used " Simon Glass
@ 2020-05-06 15:11   ` Stefan Roese
  2020-05-15 18:17   ` Tom Rini
  1 sibling, 0 replies; 7+ messages in thread
From: Stefan Roese @ 2020-05-06 15:11 UTC (permalink / raw)
  To: u-boot

On 06.05.20 16:03, Simon Glass wrote:
> It is sometimes useful to output hex dumps in SPL. Add a config option to
> allow this.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>

Reviewed-by: Stefan Roese <sr@denx.de>

Thanks,
Stefan

> ---
> 
>   lib/Kconfig  | 6 ++++++
>   lib/Makefile | 2 +-
>   2 files changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/Kconfig b/lib/Kconfig
> index c3f694afc0..df052e1d59 100644
> --- a/lib/Kconfig
> +++ b/lib/Kconfig
> @@ -491,6 +491,12 @@ config HEXDUMP
>   	help
>   	  This enables functions for printing dumps of binary data.
>   
> +config SPL_HEXDUMP
> +	bool "Enable hexdump in SPL"
> +	help
> +	  This enables functions for printing dumps of binary data in
> +	  SPL.
> +
>   config OF_LIBFDT
>   	bool "Enable the FDT library"
>   	default y if OF_CONTROL
> diff --git a/lib/Makefile b/lib/Makefile
> index 6e688afa68..a022fb9455 100644
> --- a/lib/Makefile
> +++ b/lib/Makefile
> @@ -104,7 +104,7 @@ obj-$(CONFIG_REGEX) += slre.o
>   obj-y += string.o
>   obj-y += tables_csum.o
>   obj-y += time.o
> -obj-y += hexdump.o
> +obj-$(CONFIG_$(SPL_)HEXDUMP) += hexdump.o
>   obj-$(CONFIG_TRACE) += trace.o
>   obj-$(CONFIG_LIB_UUID) += uuid.o
>   obj-$(CONFIG_LIB_RAND) += rand.o
> 


Viele Gr??e,
Stefan

-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr at denx.de

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 3/3] lib: Allow hexdump to be used in SPL
  2020-05-06 14:03 ` [PATCH 3/3] lib: Allow hexdump to be used " Simon Glass
  2020-05-06 15:11   ` Stefan Roese
@ 2020-05-15 18:17   ` Tom Rini
  1 sibling, 0 replies; 7+ messages in thread
From: Tom Rini @ 2020-05-15 18:17 UTC (permalink / raw)
  To: u-boot

On Wed, May 06, 2020 at 08:03:57AM -0600, Simon Glass wrote:

> It is sometimes useful to output hex dumps in SPL. Add a config option to
> allow this.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>
> Reviewed-by: Stefan Roese <sr@denx.de>
> ---
> 
>  lib/Kconfig  | 6 ++++++
>  lib/Makefile | 2 +-
>  2 files changed, 7 insertions(+), 1 deletion(-)

This breaks some platforms such as:
       arm:  +   am335x_evm
+(am335x_evm) arm-linux-gnueabi-ld.bfd: lib/built-in.o: in function `efi_set_variable_common':
+(am335x_evm) lib/efi_loader/efi_variable.c:1077: undefined reference to `hex_asc'
+(am335x_evm) arm-linux-gnueabi-ld.bfd: lib/built-in.o: in function `vsnprintf_internal':
+(am335x_evm) lib/vsprintf.c:697: undefined reference to `hex_asc'
+(am335x_evm) make[1]: *** [u-boot] Error 1
+(am335x_evm) make: *** [sub-make] Error 2

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200515/c1a20e16/attachment.sig>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/3] log: Allow LOG_DEBUG to always enable log output
  2020-05-06 14:03 [PATCH 1/3] log: Allow LOG_DEBUG to always enable log output Simon Glass
  2020-05-06 14:03 ` [PATCH 2/3] lib: Allow MD5 to be enabled in SPL Simon Glass
  2020-05-06 14:03 ` [PATCH 3/3] lib: Allow hexdump to be used " Simon Glass
@ 2020-05-15 18:47 ` Tom Rini
  2 siblings, 0 replies; 7+ messages in thread
From: Tom Rini @ 2020-05-15 18:47 UTC (permalink / raw)
  To: u-boot

On Wed, May 06, 2020 at 08:03:55AM -0600, Simon Glass wrote:

> At present if CONFIG_LOG enabled, putting LOG_DEBUG at the top of a file
> (before log.h inclusion) causes _log() to be executed for every log()
> call, regardless of the build- or run-time logging level.
> 
> However there is no guarantee that the log record will actually be
> displayed. If the current log level is lower than LOGL_DEBUG then it will
> not be.
> 
> Add a way to signal that the log record should always be displayed and
> update log_passes_filters() to handle this.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
> 
>  common/log.c   |  6 +++++-
>  doc/README.log |  7 ++-----
>  include/log.h  | 16 ++++++++++++----
>  3 files changed, 19 insertions(+), 10 deletions(-)

Two levels of problems with (I believe) this patch:
https://gitlab.denx.de/u-boot/u-boot/-/jobs/94674 fails a unit test now
around logging.
https://gitlab.denx.de/u-boot/u-boot/-/jobs/94671 shows a ton of new
warnings with clang.

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200515/8bdd46a5/attachment.sig>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 2/3] lib: Allow MD5 to be enabled in SPL
  2020-05-06 14:03 ` [PATCH 2/3] lib: Allow MD5 to be enabled in SPL Simon Glass
@ 2020-05-15 20:53   ` Tom Rini
  0 siblings, 0 replies; 7+ messages in thread
From: Tom Rini @ 2020-05-15 20:53 UTC (permalink / raw)
  To: u-boot

On Wed, May 06, 2020 at 08:03:56AM -0600, Simon Glass wrote:

> At present the MD5 option cannot be enabled by board configs since it has
> no Kconfig name. It is generally enabled, so long as FIT support is
> present. But not all boards use FIT, particularly in SPL
> 
> Fix this and add an option for SPL as well. This allows board code to call
> md5() even if FIT support is not enabled.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>

Applied to u-boot/master, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200515/3ec4062f/attachment.sig>

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-05-15 20:53 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-06 14:03 [PATCH 1/3] log: Allow LOG_DEBUG to always enable log output Simon Glass
2020-05-06 14:03 ` [PATCH 2/3] lib: Allow MD5 to be enabled in SPL Simon Glass
2020-05-15 20:53   ` Tom Rini
2020-05-06 14:03 ` [PATCH 3/3] lib: Allow hexdump to be used " Simon Glass
2020-05-06 15:11   ` Stefan Roese
2020-05-15 18:17   ` Tom Rini
2020-05-15 18:47 ` [PATCH 1/3] log: Allow LOG_DEBUG to always enable log output Tom Rini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.