dm: Print device name in dev_xxx() like Linux
Subsystems (2)
cover dm: Print device name in dev_xxx() like Linux
This series adds some additional information to dev_dbg. With this series, and the following options applied in addition to sandbox_defconfig
CONFIG_LOGLEVEL=8CONFIG_LOG=nCONFIG_CMD_LOG=nCONFIG_CMD_TPM=n
the output of U-Boot is
U-Boot 2020.10-rc4-00006-g19b641dddd-dirty (Sep 12 2020 - 18:15:00 -0400)
Model: sandbox DRAM: 128 MiB pinctrl-gpio sandbox_pinctrl_gpio: set_state_simple op missing leds gpio_led: set_state_simple op missing default_on gpio_led: set_state_simple op missing base-gpios sandbox_gpio: set_state_simple op missing default_off gpio_led: set_state_simple op missing wdt at 0 wdt_sandbox: set_state_simple op missing WDT: Started with servicing (60s timeout) MMC: mmc0 mmc_sandbox: set_state_simple op missing mmc1 mmc_sandbox: set_state_simple op missing mmc2 mmc_sandbox: set_state_simple op missing mmc2: 2 (SD), mmc1: 1 (SD), mmc0: 0 (SD) lcd sandbox_lcd_sdl: set_state_simple op missing In: serial Out: vidconsole Err: vidconsole Model: sandbox hog_input_active_low gpio_hog: set_state_simple op missing hog_input_active_high gpio_hog: set_state_simple op missing hog_output_low gpio_hog: set_state_simple op missing hog_output_high gpio_hog: set_state_simple op missing cros-ec google_cros_ec_sandbox: set_state_simple op missing
SCSI:pci_ep pci_ep_sandbox: set_state_simple op missing
Net: eth at 10002000 eth_sandbox: set_state_simple op missing
eth0: eth at 10002000eth@10003000 eth_sandbox: set_state_simple op missing , eth5: eth at 10003000sbe5 eth_sandbox: set_state_simple op missing , eth3: sbe5eth at 10004000 eth_sandbox: set_state_simple op missing , eth6: eth at 10004000
bootcount at 0 bootcount-rtc: set_state_simple op missing
i2c at 0 i2c_sandbox: set_state_simple op missing
rtc at 61 rtc-sandbox: set_state_simple op missing
emul i2c_emul_parent_drv: set_state_simple op missing
emull sandbox_i2c_rtc_emul: set_state_simple op missing
Hit any key to stop autoboot:
When using CONFIG_LOG the output of U-Boot is too verbose to fit in this email. Note that there is a soft dependency on [1] if you would like to test this patch with CONFIG_LOG and a higher LOG_LEVEL than LOGL_INFO.
[1] https://patchwork.ozlabs.org/project/uboot/list/?series=201343
Sean Anderson (4):
remoteproc: Remove unused function rproc_elf_sanity_check
net: mdio: Supply appropriate devices for dev_dgb calls
dm: Use symbolic constants for log levels in dev_xxx()
dm: Print device name in dev_xxx() like Linux
drivers/remoteproc/rproc-elf-loader.c | 16 ------ include/dm/device_compat.h | 75 +++++++++++++-------------- include/remoteproc.h | 13 ----- net/mdio-uclass.c | 4 +- 4 files changed, 39 insertions(+), 69 deletions(-)
Signature · 1 line
2.28.0
PATCH 1/4 remoteproc: Remove unused function rproc_elf_sanity_check
This function is never used anywhere, and it also tries to log with a nonexistant device.
---
drivers/remoteproc/rproc-elf-loader.c | 16 ---------------- include/remoteproc.h | 13 ------------- 2 files changed, 29 deletions(-)
drivers/remoteproc/rproc-elf-loader.c +0 -16
@@ -158,22 +158,6 @@ int rproc_elf64_sanity_check(ulong addr, ulong size)return 0 ; } -/* Basic function to verify ELF image format */ -int rproc_elf_sanity_check (ulong addr,ulong size) -{ -Elf32_Ehdr *ehdr = (Elf32_Ehdr *)addr; - -if (!addr) { -dev_err (dev,"Invalid firmware address\n" ); -return -EFAULT ; - } - -if (ehdr->e_ident[EI_CLASS ] ==ELFCLASS64 ) -return rproc_elf64_sanity_check (addr, size); -else -return rproc_elf32_sanity_check (addr, size); -} -int rproc_elf32_load_image (struct udevice *dev,unsigned long addr,ulong size) {Elf32_Ehdr *ehdr;/* Elf header structure pointer */
include/remoteproc.h +0 -13
@@ -226,19 +226,6 @@ int rproc_elf32_sanity_check(ulong addr, ulong size);*/ int rproc_elf64_sanity_check (ulong addr,ulong size); -/** -* rproc_elf_sanity_check() - Verify if an image is a valid ELF one -* -* Check if a valid ELF image exists at the given memory location. Auto -* detects ELF32/ELF64 and verifies basic ELF64/ELF32 format requirements -* like magic number and sections size. -* -* @addr: address of the image to verify -* @size: size of the image -* @return 0 if the image looks good, else appropriate error value. -*/ -int rproc_elf_sanity_check (ulong addr,ulong size); -/** * rproc_elf32_load_image() - load an ELF32 image * @dev: device loading the ELF32 image
Signature · 1 line
2.28.0
PATCH 1/4 remoteproc: Remove unused function rproc_elf_sanity_check
Quoted 10 lines · Sean Anderson
This function is never used anywhere, and it also tries to log with a nonexistant device.
Signed-off-by Sean Anderson <[email protected]>---
drivers/remoteproc/rproc-elf-loader.c | 16 ---------------- include/remoteproc.h | 13 ------------- 2 files changed, 29 deletions(-)
PATCH 2/4 net: mdio: Supply appropriate devices for dev_dgb calls
In reply to Sean AndersonThe name of the device we are working on is ethdev and not just dev.
---
net/mdio-uclass.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/mdio-uclass.c +2 -2
@@ -145,7 +145,7 @@ static struct phy_device *dm_eth_connect_phy_handle(struct udevice *ethdev,break ;if (!ofnode_valid (phandle.node)) { -dev_dbg (dev,"can't find PHY node\n" ); +dev_dbg (ethdev,"can't find PHY node\n" );return NULL ; }
@@ -161,7 +161,7 @@ static struct phy_device *dm_eth_connect_phy_handle(struct udevice *ethdev,if (uclass_get_device_by_ofnode (UCLASS_MDIO ,ofnode_get_parent (phandle.node), &mdiodev)) { -dev_dbg (dev,"can't find MDIO bus for node %s\n" , +dev_dbg (ethdev,"can't find MDIO bus for node %s\n" ,ofnode_get_name (ofnode_get_parent (phandle.node)));return NULL ; }
Signature · 1 line
2.28.0
PATCH 2/4 net: mdio: Supply appropriate devices for dev_dgb calls
Quoted 8 lines · Sean Anderson
The name of the device we are working on is
ethdevand not justdev.Signed-off-by Sean Anderson <[email protected]>---
net/mdio-uclass.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
BTW I really like using 'dev' for the struct udevice if there is only one, and other names for other things (e.g. edev for Ethernet, udev for USB).
PATCH 2/4 net: mdio: Supply appropriate devices for dev_dgb calls
Quoted 7 lines · Simon Glass
Quoted 6 lines · Sean Anderson
The name of the device we are working on is
ethdevand not justdev.Signed-off-by Sean Anderson <[email protected]>---
Quoted 9 lines
Quoted 2 lines
net/mdio-uclass.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)Reviewed-by Simon Glass <[email protected]>BTW I really like using 'dev' for the struct udevice if there is only one, and other names for other things (e.g. edev for Ethernet, udev for USB).
Yeah, I think it is only really necessary when disambiguating between several different devices. However, I am trying to make these patches as minimal as possible, so I would like to keep the variable names the same where possible.
--Sean
PATCH 2/4 net: mdio: Supply appropriate devices for dev_dgb calls
Hi Sean,
Quoted 20 lines · Sean Anderson
Quoted 7 lines · Simon Glass
Quoted 6 lines · Sean Anderson
The name of the device we are working on is
ethdevand not justdev.Signed-off-by Sean Anderson <[email protected]>---
Quoted 9 lines
Quoted 2 lines
net/mdio-uclass.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)Reviewed-by Simon Glass <[email protected]>BTW I really like using 'dev' for the struct udevice if there is only one, and other names for other things (e.g. edev for Ethernet, udev for USB).
Quoted 4 lines
Yeah, I think it is only really necessary when disambiguating between several different devices. However, I am trying to make these patches as minimal as possible, so I would like to keep the variable names the same where possible.
Yes definitely better the way you have the patches now.
PATCH 3/4 dm: Use symbolic constants for log levels in dev_xxx()
In reply to Sean AndersonThis substitutes literal log levels with their symbolic constants.
---
include/dm/device_compat.h | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
include/dm/device_compat.h +11 -10
@@ -10,6 +10,7 @@#ifndef _DM_DEVICE_COMPAT_H#define _DM_DEVICE_COMPAT_H +#include <log.h> #include <linux/compat.h> /*
@@ -48,28 +49,28 @@ })#define dev_emerg (dev, fmt, ...) \ - __dev_printk(0, dev, fmt, ##__VA_ARGS__) + __dev_printk(LOGL_EMERG, dev, fmt, ##__VA_ARGS__)#define dev_alert (dev, fmt, ...) \ - __dev_printk(1, dev, fmt, ##__VA_ARGS__) + __dev_printk(LOGL_ALERT, dev, fmt, ##__VA_ARGS__)#define dev_crit (dev, fmt, ...) \ - __dev_printk(2, dev, fmt, ##__VA_ARGS__) + __dev_printk(LOGL_CRIT, dev, fmt, ##__VA_ARGS__)#define dev_err (dev, fmt, ...) \ - __dev_printk(3, dev, fmt, ##__VA_ARGS__) + __dev_printk(LOGL_ERR, dev, fmt, ##__VA_ARGS__)#define dev_warn (dev, fmt, ...) \ - __dev_printk(4, dev, fmt, ##__VA_ARGS__) + __dev_printk(LOGL_WARNING, dev, fmt, ##__VA_ARGS__)#define dev_notice (dev, fmt, ...) \ - __dev_printk(5, dev, fmt, ##__VA_ARGS__) + __dev_printk(LOGL_NOTICE, dev, fmt, ##__VA_ARGS__)#define dev_info (dev, fmt, ...) \ - __dev_printk(6, dev, fmt, ##__VA_ARGS__) + __dev_printk(LOGL_INFO, dev, fmt, ##__VA_ARGS__)#ifdef DEBUG #define dev_dbg (dev, fmt, ...) \ - __dev_printk(7, dev, fmt, ##__VA_ARGS__) + __dev_printk(LOGL_DEBUG, dev, fmt, ##__VA_ARGS__)#else #define dev_dbg (dev, fmt, ...) \ ({ \ if (0) \ - __dev_printk(7, dev, fmt, ##__VA_ARGS__); \ + __dev_printk(LOGL_DEBUG, dev, fmt, ##__VA_ARGS__); \ })#endif
@@ -79,7 +80,7 @@#define dev_vdbg (dev, fmt, ...) \ ({ \ if (0) \ - __dev_printk(7, dev, fmt, ##__VA_ARGS__); \ + __dev_printk(LOGL_DEBUG, dev, fmt, ##__VA_ARGS__); \ })#endif
Signature · 1 line
2.28.0
PATCH 3/4 dm: Use symbolic constants for log levels in dev_xxx()
Quoted 9 lines · Sean Anderson
This substitutes literal log levels with their symbolic constants.
Signed-off-by Sean Anderson <[email protected]>---
include/dm/device_compat.h | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
PATCH 4/4 dm: Print device name in dev_xxx() like Linux
In reply to Sean AndersonThis adorns messages generated by dev_xxx() with the device and driver names. It also redirects dev_xxx() to log() when it is available. The names of these functions very roughly take inspiration from Linux, but there is no deeper correlation.
---
include/dm/device_compat.h | 58 ++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 30 deletions(-)
include/dm/device_compat.h +28 -30
@@ -1,5 +1,6 @@/* SPDX-License-Identifier: GPL-2.0+ */ /* +* Copyright (C) 2020 Sean Anderson <[email protected]> * Copyright (c) 2013 Google, Inc * * (C) Copyright 2012
@@ -33,19 +34,33 @@#undef dev_warn#endif -/* -* REVISIT: -* print device name like Linux -*/ -#define dev_printk (dev, fmt, ...) \ -({ \ - printk(fmt, ##__VA_ARGS__); \ +#ifdef VERBOSE_DEBUG +#define _VERBOSE_DEBUG 1 +#else +#define _VERBOSE_DEBUG 0 +#endif + +#define dev_printk_emit (cat, level, fmt, ...) \ +({ \ + if ((_DEBUG && level == LOGL_DEBUG) || \ + (_VERBOSE_DEBUG && level == LOGL_DEBUG_CONTENT)) \ + printf(fmt, ##__VA_ARGS__); \ + else if (CONFIG_IS_ENABLED(LOG)) \ + log(cat, level, fmt, ##__VA_ARGS__); \ + else if (level < CONFIG_VAL(LOGLEVEL)) \ + printf(fmt, ##__VA_ARGS__); \ }) -#define __dev_printk (level, dev, fmt, ...) \ -({ \ - if (level < CONFIG_VAL(LOGLEVEL)) \ - dev_printk(dev, fmt, ##__VA_ARGS__); \ +#define __dev_printk (level, dev, fmt, ...) \ +({ \ + struct udevice *__dev = dev; \ + if (__dev) \ + dev_printk_emit(__dev->driver->id, level, "%s %s: " fmt, \ + __dev->name, __dev->driver->name, \ + ##__VA_ARGS__); \ + else \ + dev_printk_emit(LOG_CATEGORY, level, \ + "(NULL udevice *): " fmt, ##__VA_ARGS__); \ })#define dev_emerg (dev, fmt, ...) \
@@ -62,26 +77,9 @@ __dev_printk(LOGL_NOTICE, dev, fmt, ##__VA_ARGS__)#define dev_info (dev, fmt, ...) \ __dev_printk(LOGL_INFO, dev, fmt, ##__VA_ARGS__) - -#ifdef DEBUG #define dev_dbg (dev, fmt, ...) \ __dev_printk(LOGL_DEBUG, dev, fmt, ##__VA_ARGS__) -#else -#define dev_dbg (dev, fmt, ...) \ -({ \ - if (0) \ - __dev_printk(LOGL_DEBUG, dev, fmt, ##__VA_ARGS__); \ -}) -#endif - -#ifdef VERBOSE_DEBUG -#define dev_vdbg dev_dbg -#else -#define dev_vdbg (dev, fmt, ...) \ -({ \ - if (0) \ - __dev_printk(LOGL_DEBUG, dev, fmt, ##__VA_ARGS__); \ -}) -#endif +#define dev_vdbg (dev, fmt, ...) \ + __dev_printk(LOGL_DEBUG_CONTENT, dev, fmt, ##__VA_ARGS__)#endif
Signature · 1 line
2.28.0
cover dm: Print device name in dev_xxx() like Linux
In reply to Sean AndersonQuoted 62 lines · Sean Anderson
This series adds some additional information to
dev_dbg. With this series, and the following options applied in addition tosandbox_defconfig
CONFIG_LOGLEVEL=8CONFIG_LOG=nCONFIG_CMD_LOG=nCONFIG_CMD_TPM=nthe output of U-Boot is
U-Boot 2020.10-rc4-00006-g19b641dddd-dirty (Sep 12 2020 - 18:15:00 -0400)
Model: sandbox DRAM: 128 MiB pinctrl-gpio sandbox_pinctrl_gpio: set_state_simple op missing leds gpio_led: set_state_simple op missing default_on gpio_led: set_state_simple op missing base-gpios sandbox_gpio: set_state_simple op missing default_off gpio_led: set_state_simple op missing wdt at 0 wdt_sandbox: set_state_simple op missing WDT: Started with servicing (60s timeout) MMC: mmc0 mmc_sandbox: set_state_simple op missing mmc1 mmc_sandbox: set_state_simple op missing mmc2 mmc_sandbox: set_state_simple op missing mmc2: 2 (SD), mmc1: 1 (SD), mmc0: 0 (SD) lcd sandbox_lcd_sdl: set_state_simple op missing In: serial Out: vidconsole Err: vidconsole Model: sandbox hog_input_active_low gpio_hog: set_state_simple op missing hog_input_active_high gpio_hog: set_state_simple op missing hog_output_low gpio_hog: set_state_simple op missing hog_output_high gpio_hog: set_state_simple op missing cros-ec google_cros_ec_sandbox: set_state_simple op missingSCSI:
pci_eppci_ep_sandbox:set_state_simpleop missing
Net: eth at 10002000eth_sandbox:set_state_simpleop missing
eth0: eth at 10002000eth@10003000eth_sandbox:set_state_simpleop missing , eth5: eth at 10003000sbe5eth_sandbox:set_state_simpleop missing , eth3: sbe5eth at 10004000eth_sandbox:set_state_simpleop missing , eth6: eth at 10004000
bootcount at 0 bootcount-rtc:set_state_simpleop missing
i2c at 0i2c_sandbox:set_state_simpleop missing
rtc at 61 rtc-sandbox:set_state_simpleop missing
emuli2c_emul_parent_drv:set_state_simpleop missing
emullsandbox_i2c_rtc_emul:set_state_simpleop missing
Hit any key to stop autoboot:When using
CONFIG_LOGthe output of U-Boot is too verbose to fit in this email. Note that there is a soft dependency on [1] if you would like to test this patch withCONFIG_LOGand a higherLOG_LEVELthanLOGL_INFO.[1] https://patchwork.ozlabs.org/project/uboot/list/?series=201343
Sean Anderson (4):
remoteproc: Remove unused functionrproc_elf_sanity_check
net: mdio: Supply appropriate devices fordev_dgbcalls
dm: Use symbolic constants for log levels indev_xxx()
dm: Print device name indev_xxx()like Linux
Quoted 6 lines
drivers/remoteproc/rproc-elf-loader.c | 16 ------ include/dm/device_compat.h | 75 +++++++++++++-------------- include/remoteproc.h | 13 ----- net/mdio-uclass.c | 4 +- 4 files changed, 39 insertions(+), 69 deletions(-)
In my haste I may have forgotten to run CI and make many more patches like the first two to fix drivers calling a dev_ log function without an actual device. So this series breaks a lot of things at the moment [1]. Consider it an RFC I guess for after I fix all those build failures.
--Sean