[PATCH 3/4] lib: hexdump: make use of pr_debug

Marco Felsch m.felsch at pengutronix.de
Mon Oct 20 02:27:50 PDT 2025


On 25-10-20, Sascha Hauer wrote:
> On Mon, Oct 20, 2025 at 10:49:24AM +0200, Marco Felsch wrote:
> > On 25-10-20, Sascha Hauer wrote:
> > > On Fri, Oct 17, 2025 at 02:03:35PM +0200, Marco Felsch wrote:
> > > > The hexdump library was ported from Linux which supports different
> > > > printk() level. Because the barebox print* facility is different
> > > > compared to the one from Linux the barebox printk() doesn't support
> > > > levels. Therefore the level is always set to an empty string.
> > > > 
> > > > Furthermore all barebox printk() calls aren't recorded by the internal
> > > > barebox_logbuf because they are mostly used for command prints. Linux on
> > > > the other hand record each printk() print.
> > > > 
> > > > Not recording the output can be an issue on systems which don't have a
> > > > hw-console but a USB-ACM console, because the hexdump call may already
> > > > occurred before the console was ready.
> > > > 
> > > > Make use of pr_debug() instead to record the output within the
> > > > barebox_logbuf to be available later on via dmesg. Using pr_debug()
> > > > should be fine since it is mostly used for debugging/development
> > > > purpose.
> > > > 
> > > > Signed-off-by: Marco Felsch <m.felsch at pengutronix.de>
> > > > ---
> > > >  lib/hexdump.c | 9 +++------
> > > >  1 file changed, 3 insertions(+), 6 deletions(-)
> > > > 
> > > > diff --git a/lib/hexdump.c b/lib/hexdump.c
> > > > index 940c4eec64e9..ab5e3cf727ec 100644
> > > > --- a/lib/hexdump.c
> > > > +++ b/lib/hexdump.c
> > > > @@ -284,16 +284,13 @@ void dev_print_hex_dump(struct device *dev, const char *level,
> > > >  
> > > >  		switch (prefix_type) {
> > > >  		case DUMP_PREFIX_ADDRESS:
> > > > -			printk("%s%s%s%p: %s\n", level, name, prefix_str,
> > > > -			       ptr + i, linebuf);
> > > > +			pr_debug("%s%s%p: %s\n", name, prefix_str, ptr + i, linebuf);
> > > 
> > > pr_debug is only compiled in when DEBUG is defined. This means you have
> > > to add a "#define DEBUG" in lib/hexdump.c to make the messages visible
> > > printed in another file, or alternatively have to define DEBUG globally.
> > 
> > Yep, this is true and I forgot about that drawback :/
> > 
> > > I think we should rather replace the const char *level argument with a
> > > unsigned int level argument expecting one of MSG_* and use pr_print() here.
> > 
> > What about keeping the Linux API but converting it back to int?
> 
> Not possible:
> 
> #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                 */

I should have read my own commit message! Thanks again for the pointer.

Regards,
  Marco



More information about the barebox mailing list