From 85f718f64d65390f385111e57cfa017abd12879d Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 22 Mar 2021 18:21:01 +1300 Subject: [PATCH 1/8] sandbox: Support signal handling only when requested At present if sandbox crashes it prints a message and tries to exit. But with the recently introduced signal handler, it often seems to get stuck in a loop until the stack overflows: Segmentation violation Segmentation violation Segmentation violation Segmentation violation Segmentation violation Segmentation violation Segmentation violation ... The signal handler is only useful for a few tests, as I understand it. Make it optional. Signed-off-by: Simon Glass --- arch/sandbox/cpu/start.c | 18 +++++++++++++++--- arch/sandbox/include/asm/state.h | 1 + 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/arch/sandbox/cpu/start.c b/arch/sandbox/cpu/start.c index 6bb94473f19..63b086dff80 100644 --- a/arch/sandbox/cpu/start.c +++ b/arch/sandbox/cpu/start.c @@ -390,6 +390,16 @@ static int sandbox_cmdline_cb_select_unittests(struct sandbox_state *state, } SANDBOX_CMDLINE_OPT_SHORT(select_unittests, 'k', 1, "Select unit tests to run"); +static int sandbox_cmdline_cb_signals(struct sandbox_state *state, + const char *arg) +{ + state->handle_signals = true; + + return 0; +} +SANDBOX_CMDLINE_OPT_SHORT(signals, 'S', 0, + "Handle signals (such as SIGSEGV) in sandbox"); + static void setup_ram_buf(struct sandbox_state *state) { /* Zero the RAM buffer if we didn't read it, to keep valgrind happy */ @@ -476,9 +486,11 @@ int main(int argc, char *argv[]) if (ret) goto err; - ret = os_setup_signal_handlers(); - if (ret) - goto err; + if (state->handle_signals) { + ret = os_setup_signal_handlers(); + if (ret) + goto err; + } #if CONFIG_VAL(SYS_MALLOC_F_LEN) gd->malloc_base = CONFIG_MALLOC_F_ADDR; diff --git a/arch/sandbox/include/asm/state.h b/arch/sandbox/include/asm/state.h index bca13069824..1c4c571e28d 100644 --- a/arch/sandbox/include/asm/state.h +++ b/arch/sandbox/include/asm/state.h @@ -93,6 +93,7 @@ struct sandbox_state { bool ram_buf_read; /* true if we read the RAM buffer */ bool run_unittests; /* Run unit tests */ const char *select_unittests; /* Unit test to run */ + bool handle_signals; /* Handle signals within sandbox */ /* Pointer to information for each SPI bus/cs */ struct sandbox_spi_info spi[CONFIG_SANDBOX_SPI_MAX_BUS] From b953ec2bca1ebe059366e870eb4bec5e7af9c36b Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Tue, 27 Apr 2021 11:02:19 +0200 Subject: [PATCH 2/8] dm: define LOG_CATEGORY for all uclass Define LOG_CATEGORY for all uclass to allow filtering with log command. Signed-off-by: Patrick Delaunay Reviewed-by: Simon Glass --- drivers/adc/adc-uclass.c | 2 ++ drivers/ata/ahci-uclass.c | 2 ++ drivers/axi/axi-emul-uclass.c | 2 ++ drivers/axi/axi-uclass.c | 2 ++ drivers/block/blk-uclass.c | 2 ++ drivers/block/ide.c | 2 ++ drivers/bootcount/bootcount-uclass.c | 2 ++ drivers/button/button-uclass.c | 2 ++ drivers/cache/cache-uclass.c | 2 ++ drivers/clk/clk-uclass.c | 2 ++ drivers/core/root.c | 2 ++ drivers/core/simple-bus.c | 2 ++ drivers/cpu/cpu-uclass.c | 2 ++ drivers/crypto/rsa_mod_exp/mod_exp_uclass.c | 2 ++ drivers/dma/dma-uclass.c | 2 ++ drivers/firmware/firmware-uclass.c | 2 ++ drivers/hwspinlock/hwspinlock-uclass.c | 2 ++ drivers/i2c/i2c-emul-uclass.c | 2 ++ drivers/i2c/i2c-uclass.c | 2 ++ drivers/i2c/muxes/i2c-mux-uclass.c | 2 ++ drivers/input/keyboard-uclass.c | 2 ++ drivers/led/led-uclass.c | 2 ++ drivers/mailbox/mailbox-uclass.c | 2 ++ drivers/misc/fs_loader.c | 3 +++ drivers/misc/i2c_eeprom.c | 2 ++ drivers/misc/misc-uclass.c | 2 ++ drivers/misc/p2sb-uclass.c | 2 ++ drivers/misc/pwrseq-uclass.c | 2 ++ drivers/mmc/mmc-uclass.c | 2 ++ drivers/mtd/mtd-uclass.c | 2 ++ drivers/mtd/spi/sf-uclass.c | 2 ++ drivers/mux/mux-uclass.c | 2 ++ drivers/nvme/nvme-uclass.c | 2 ++ drivers/pch/pch-uclass.c | 2 ++ drivers/pci/pci-uclass.c | 2 ++ drivers/pci_endpoint/pci_ep-uclass.c | 2 ++ drivers/phy/phy-uclass.c | 2 ++ drivers/pinctrl/pinctrl-uclass.c | 2 ++ drivers/power/domain/power-domain-uclass.c | 2 ++ drivers/power/pmic/pmic-uclass.c | 2 ++ drivers/power/regulator/regulator-uclass.c | 2 ++ drivers/pwm/pwm-uclass.c | 2 ++ drivers/ram/ram-uclass.c | 2 ++ drivers/remoteproc/rproc-uclass.c | 3 +++ drivers/reset/reset-uclass.c | 2 ++ drivers/rng/rng-uclass.c | 2 ++ drivers/rtc/rtc-uclass.c | 2 ++ drivers/scsi/scsi-uclass.c | 2 ++ drivers/serial/serial-uclass.c | 2 ++ drivers/smem/smem-uclass.c | 2 ++ drivers/soc/soc-uclass.c | 2 ++ drivers/sound/codec-uclass.c | 2 ++ drivers/sound/i2s-uclass.c | 2 ++ drivers/sound/sound-uclass.c | 2 ++ drivers/spi/spi-emul-uclass.c | 2 ++ drivers/spmi/spmi-uclass.c | 2 ++ drivers/sysinfo/sysinfo-uclass.c | 2 ++ drivers/tee/tee-uclass.c | 2 ++ drivers/thermal/thermal-uclass.c | 2 ++ drivers/timer/timer-uclass.c | 2 ++ drivers/ufs/ufs-uclass.c | 2 ++ drivers/usb/emul/usb-emul-uclass.c | 2 ++ drivers/usb/gadget/udc/udc-uclass.c | 2 ++ drivers/usb/host/usb-uclass.c | 2 ++ drivers/video/backlight-uclass.c | 2 ++ drivers/video/bridge/video-bridge-uclass.c | 2 ++ drivers/video/display-uclass.c | 2 ++ drivers/video/dsi-host-uclass.c | 2 ++ drivers/video/panel-uclass.c | 2 ++ drivers/video/vidconsole-uclass.c | 2 ++ drivers/video/video-uclass.c | 2 ++ drivers/video/video_osd-uclass.c | 2 ++ drivers/virtio/virtio-uclass.c | 2 ++ drivers/w1-eeprom/w1-eeprom-uclass.c | 2 ++ drivers/w1/w1-uclass.c | 2 ++ drivers/watchdog/wdt-uclass.c | 2 ++ drivers/xen/pvblock.c | 3 +++ 77 files changed, 157 insertions(+) diff --git a/drivers/adc/adc-uclass.c b/drivers/adc/adc-uclass.c index 8781f32855f..67137ffb341 100644 --- a/drivers/adc/adc-uclass.c +++ b/drivers/adc/adc-uclass.c @@ -4,6 +4,8 @@ * Przemyslaw Marczak */ +#define LOG_CATEGORY UCLASS_ADC + #include #include #include diff --git a/drivers/ata/ahci-uclass.c b/drivers/ata/ahci-uclass.c index c4c7a03fe74..d398b50b9a1 100644 --- a/drivers/ata/ahci-uclass.c +++ b/drivers/ata/ahci-uclass.c @@ -4,6 +4,8 @@ * Written by Simon Glass */ +#define LOG_CATEGORY UCLASS_AHCI + #include #include #include diff --git a/drivers/axi/axi-emul-uclass.c b/drivers/axi/axi-emul-uclass.c index b28351f1adb..793336d8c47 100644 --- a/drivers/axi/axi-emul-uclass.c +++ b/drivers/axi/axi-emul-uclass.c @@ -4,6 +4,8 @@ * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc */ +#define LOG_CATEGORY UCLASS_AXI_EMUL + #include #include #include diff --git a/drivers/axi/axi-uclass.c b/drivers/axi/axi-uclass.c index af8acd9f88b..afb4844ecbd 100644 --- a/drivers/axi/axi-uclass.c +++ b/drivers/axi/axi-uclass.c @@ -4,6 +4,8 @@ * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc */ +#define LOG_CATEGORY UCLASS_AXI + #include #include #include diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c index d0d91db540b..dfc0d469702 100644 --- a/drivers/block/blk-uclass.c +++ b/drivers/block/blk-uclass.c @@ -4,6 +4,8 @@ * Written by Simon Glass */ +#define LOG_CATEGORY UCLASS_BLK + #include #include #include diff --git a/drivers/block/ide.c b/drivers/block/ide.c index 862a85bc87b..c99076c6f45 100644 --- a/drivers/block/ide.c +++ b/drivers/block/ide.c @@ -4,6 +4,8 @@ * Wolfgang Denk, DENX Software Engineering, wd@denx.de. */ +#define LOG_CATEGORY UCLASS_IDE + #include #include #include diff --git a/drivers/bootcount/bootcount-uclass.c b/drivers/bootcount/bootcount-uclass.c index 34ac08d59a6..c747c9ab276 100644 --- a/drivers/bootcount/bootcount-uclass.c +++ b/drivers/bootcount/bootcount-uclass.c @@ -3,6 +3,8 @@ * (C) Copyright 2018 Theobroma Systems Design und Consulting GmbH */ +#define LOG_CATEGORY UCLASS_BOOTCOUNT + #include #include #include diff --git a/drivers/button/button-uclass.c b/drivers/button/button-uclass.c index e06d3eb7da5..e33ed7d01d1 100644 --- a/drivers/button/button-uclass.c +++ b/drivers/button/button-uclass.c @@ -5,6 +5,8 @@ * Based on led-uclass.c */ +#define LOG_CATEGORY UCLASS_BUTTON + #include #include #include diff --git a/drivers/cache/cache-uclass.c b/drivers/cache/cache-uclass.c index 3b20a10f087..0c13dbdb75c 100644 --- a/drivers/cache/cache-uclass.c +++ b/drivers/cache/cache-uclass.c @@ -3,6 +3,8 @@ * Copyright (C) 2019 Intel Corporation */ +#define LOG_CATEGORY UCLASS_CACHE + #include #include #include diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c index 14254212ca7..f049e36380f 100644 --- a/drivers/clk/clk-uclass.c +++ b/drivers/clk/clk-uclass.c @@ -6,6 +6,8 @@ * Copyright (c) 2018, Theobroma Systems Design und Consulting GmbH */ +#define LOG_CATEGORY UCLASS_CLK + #include #include #include diff --git a/drivers/core/root.c b/drivers/core/root.c index fe0562cd6f6..537e9daaf8a 100644 --- a/drivers/core/root.c +++ b/drivers/core/root.c @@ -6,6 +6,8 @@ * Pavel Herrmann */ +#define LOG_CATEGORY UCLASS_ROOT + #include #include #include diff --git a/drivers/core/simple-bus.c b/drivers/core/simple-bus.c index 18f52d26df2..abc55c21719 100644 --- a/drivers/core/simple-bus.c +++ b/drivers/core/simple-bus.c @@ -3,6 +3,8 @@ * Copyright (c) 2014 Google, Inc */ +#define LOG_CATEGORY UCLASS_SIMPLE_BUS + #include #include #include diff --git a/drivers/cpu/cpu-uclass.c b/drivers/cpu/cpu-uclass.c index 1c338bad9a1..a5cda6a62c4 100644 --- a/drivers/cpu/cpu-uclass.c +++ b/drivers/cpu/cpu-uclass.c @@ -4,6 +4,8 @@ * Written by Simon Glass */ +#define LOG_CATEGORY UCLASS_CPU + #include #include #include diff --git a/drivers/crypto/rsa_mod_exp/mod_exp_uclass.c b/drivers/crypto/rsa_mod_exp/mod_exp_uclass.c index f5ae35e1325..6a4d235d57b 100644 --- a/drivers/crypto/rsa_mod_exp/mod_exp_uclass.c +++ b/drivers/crypto/rsa_mod_exp/mod_exp_uclass.c @@ -4,6 +4,8 @@ * Author: Ruchika Gupta */ +#define LOG_CATEGORY UCLASS_MOD_EXP + #include #include #include diff --git a/drivers/dma/dma-uclass.c b/drivers/dma/dma-uclass.c index a93b0b7ba08..652ddbb62b8 100644 --- a/drivers/dma/dma-uclass.c +++ b/drivers/dma/dma-uclass.c @@ -9,6 +9,8 @@ * Author: Mugunthan V N */ +#define LOG_CATEGORY UCLASS_DMA + #include #include #include diff --git a/drivers/firmware/firmware-uclass.c b/drivers/firmware/firmware-uclass.c index 7fcd7fb9047..bfaf283eed5 100644 --- a/drivers/firmware/firmware-uclass.c +++ b/drivers/firmware/firmware-uclass.c @@ -1,5 +1,7 @@ // SPDX-License-Identifier: GPL-2.0+ +#define LOG_CATEGORY UCLASS_FIRMWARE + #include #include diff --git a/drivers/hwspinlock/hwspinlock-uclass.c b/drivers/hwspinlock/hwspinlock-uclass.c index 8997243421c..cbe72360117 100644 --- a/drivers/hwspinlock/hwspinlock-uclass.c +++ b/drivers/hwspinlock/hwspinlock-uclass.c @@ -3,6 +3,8 @@ * Copyright (C) 2018, STMicroelectronics - All Rights Reserved */ +#define LOG_CATEGORY UCLASS_HWSPINLOCK + #include #include #include diff --git a/drivers/i2c/i2c-emul-uclass.c b/drivers/i2c/i2c-emul-uclass.c index 7917b63c55b..aeec6aa9fa6 100644 --- a/drivers/i2c/i2c-emul-uclass.c +++ b/drivers/i2c/i2c-emul-uclass.c @@ -3,6 +3,8 @@ * Copyright (c) 2014 Google, Inc */ +#define LOG_CATEGORY UCLASS_I2C_EMUL + #include #include #include diff --git a/drivers/i2c/i2c-uclass.c b/drivers/i2c/i2c-uclass.c index be56785217c..04c88503a2f 100644 --- a/drivers/i2c/i2c-uclass.c +++ b/drivers/i2c/i2c-uclass.c @@ -3,6 +3,8 @@ * Copyright (c) 2014 Google, Inc */ +#define LOG_CATEGORY UCLASS_I2C + #include #include #include diff --git a/drivers/i2c/muxes/i2c-mux-uclass.c b/drivers/i2c/muxes/i2c-mux-uclass.c index dbca409ee3a..a5d1bb0576d 100644 --- a/drivers/i2c/muxes/i2c-mux-uclass.c +++ b/drivers/i2c/muxes/i2c-mux-uclass.c @@ -4,6 +4,8 @@ * Written by Simon Glass */ +#define LOG_CATEGORY UCLASS_I2C_MUX + #include #include #include diff --git a/drivers/input/keyboard-uclass.c b/drivers/input/keyboard-uclass.c index 2c6680337d9..aefc8e825e2 100644 --- a/drivers/input/keyboard-uclass.c +++ b/drivers/input/keyboard-uclass.c @@ -3,6 +3,8 @@ * Copyright (c) 2015 Google, Inc */ +#define LOG_CATEGORY UCLASS_KEYBOARD + #include #include #include diff --git a/drivers/led/led-uclass.c b/drivers/led/led-uclass.c index e15a2967ffe..7e298dbb06f 100644 --- a/drivers/led/led-uclass.c +++ b/drivers/led/led-uclass.c @@ -4,6 +4,8 @@ * Written by Simon Glass */ +#define LOG_CATEGORY UCLASS_LED + #include #include #include diff --git a/drivers/mailbox/mailbox-uclass.c b/drivers/mailbox/mailbox-uclass.c index c972d846089..01c9e75fa5b 100644 --- a/drivers/mailbox/mailbox-uclass.c +++ b/drivers/mailbox/mailbox-uclass.c @@ -3,6 +3,8 @@ * Copyright (c) 2016, NVIDIA CORPORATION. */ +#define LOG_CATEGORY UCLASS_MAILBOX + #include #include #include diff --git a/drivers/misc/fs_loader.c b/drivers/misc/fs_loader.c index e77b3af770e..0139bd66ba7 100644 --- a/drivers/misc/fs_loader.c +++ b/drivers/misc/fs_loader.c @@ -3,6 +3,9 @@ * Copyright (C) 2018-2019 Intel Corporation * */ + +#define LOG_CATEGORY UCLASS_FS_FIRMWARE_LOADER + #include #include #include diff --git a/drivers/misc/i2c_eeprom.c b/drivers/misc/i2c_eeprom.c index 5926c91a2ec..3b249842f8b 100644 --- a/drivers/misc/i2c_eeprom.c +++ b/drivers/misc/i2c_eeprom.c @@ -3,6 +3,8 @@ * Copyright (c) 2014 Google, Inc */ +#define LOG_CATEGORY UCLASS_I2C_EEPROM + #include #include #include diff --git a/drivers/misc/misc-uclass.c b/drivers/misc/misc-uclass.c index 55381edc980..72720b0e590 100644 --- a/drivers/misc/misc-uclass.c +++ b/drivers/misc/misc-uclass.c @@ -3,6 +3,8 @@ * Copyright (C) 2010 Thomas Chou */ +#define LOG_CATEGORY UCLASS_MISC + #include #include #include diff --git a/drivers/misc/p2sb-uclass.c b/drivers/misc/p2sb-uclass.c index ac2852559f5..94d273de9b3 100644 --- a/drivers/misc/p2sb-uclass.c +++ b/drivers/misc/p2sb-uclass.c @@ -6,6 +6,8 @@ * Written by Simon Glass */ +#define LOG_CATEGORY UCLASS_P2SB + #include #include #include diff --git a/drivers/misc/pwrseq-uclass.c b/drivers/misc/pwrseq-uclass.c index c8f6c46069b..a0f24e1bf3a 100644 --- a/drivers/misc/pwrseq-uclass.c +++ b/drivers/misc/pwrseq-uclass.c @@ -3,6 +3,8 @@ * Copyright (c) 2015 Google, Inc */ +#define LOG_CATEGORY UCLASS_PWRSEQ + #include #include #include diff --git a/drivers/mmc/mmc-uclass.c b/drivers/mmc/mmc-uclass.c index 579d7a1406b..0e13238c7e7 100644 --- a/drivers/mmc/mmc-uclass.c +++ b/drivers/mmc/mmc-uclass.c @@ -5,6 +5,8 @@ * Written by Simon Glass */ +#define LOG_CATEGORY UCLASS_MMC + #include #include #include diff --git a/drivers/mtd/mtd-uclass.c b/drivers/mtd/mtd-uclass.c index 4ab84de5531..0743fe7af9f 100644 --- a/drivers/mtd/mtd-uclass.c +++ b/drivers/mtd/mtd-uclass.c @@ -3,6 +3,8 @@ * Copyright (C) 2015 Thomas Chou */ +#define LOG_CATEGORY UCLASS_MTD + #include #include #include diff --git a/drivers/mtd/spi/sf-uclass.c b/drivers/mtd/spi/sf-uclass.c index cfce00ef548..63d16291ff1 100644 --- a/drivers/mtd/spi/sf-uclass.c +++ b/drivers/mtd/spi/sf-uclass.c @@ -3,6 +3,8 @@ * Copyright (c) 2014 Google, Inc */ +#define LOG_CATEGORY UCLASS_SPI_FLASH + #include #include #include diff --git a/drivers/mux/mux-uclass.c b/drivers/mux/mux-uclass.c index 6d28dbe4d14..91842c5539f 100644 --- a/drivers/mux/mux-uclass.c +++ b/drivers/mux/mux-uclass.c @@ -11,6 +11,8 @@ * Jean-Jacques Hiblot */ +#define LOG_CATEGORY UCLASS_MUX + #include #include #include diff --git a/drivers/nvme/nvme-uclass.c b/drivers/nvme/nvme-uclass.c index 610166d76ea..239a92abba6 100644 --- a/drivers/nvme/nvme-uclass.c +++ b/drivers/nvme/nvme-uclass.c @@ -4,6 +4,8 @@ * Copyright (C) 2017 Bin Meng */ +#define LOG_CATEGORY UCLASS_NVME + #include #include diff --git a/drivers/pch/pch-uclass.c b/drivers/pch/pch-uclass.c index ad4906aa58b..7bc2372e96d 100644 --- a/drivers/pch/pch-uclass.c +++ b/drivers/pch/pch-uclass.c @@ -4,6 +4,8 @@ * Written by Simon Glass */ +#define LOG_CATEGORY UCLASS_PCH + #include #include #include diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c index 22a033e6329..0bd604d061d 100644 --- a/drivers/pci/pci-uclass.c +++ b/drivers/pci/pci-uclass.c @@ -4,6 +4,8 @@ * Written by Simon Glass */ +#define LOG_CATEGORY UCLASS_PCI + #include #include #include diff --git a/drivers/pci_endpoint/pci_ep-uclass.c b/drivers/pci_endpoint/pci_ep-uclass.c index 5555cf5a8c9..6ee4cfbdb4a 100644 --- a/drivers/pci_endpoint/pci_ep-uclass.c +++ b/drivers/pci_endpoint/pci_ep-uclass.c @@ -9,6 +9,8 @@ * Written by Ramon Fried */ +#define LOG_CATEGORY UCLASS_PCI_EP + #include #include #include diff --git a/drivers/phy/phy-uclass.c b/drivers/phy/phy-uclass.c index 43ffbcee0f0..59683a080cd 100644 --- a/drivers/phy/phy-uclass.c +++ b/drivers/phy/phy-uclass.c @@ -4,6 +4,8 @@ * Written by Jean-Jacques Hiblot */ +#define LOG_CATEGORY UCLASS_PHY + #include #include #include diff --git a/drivers/pinctrl/pinctrl-uclass.c b/drivers/pinctrl/pinctrl-uclass.c index 6e68e52c32c..ea7275ca004 100644 --- a/drivers/pinctrl/pinctrl-uclass.c +++ b/drivers/pinctrl/pinctrl-uclass.c @@ -3,6 +3,8 @@ * Copyright (C) 2015 Masahiro Yamada */ +#define LOG_CATEGORY UCLASS_PINCTRL + #include #include #include diff --git a/drivers/power/domain/power-domain-uclass.c b/drivers/power/domain/power-domain-uclass.c index af829db9da1..00d1489ea20 100644 --- a/drivers/power/domain/power-domain-uclass.c +++ b/drivers/power/domain/power-domain-uclass.c @@ -3,6 +3,8 @@ * Copyright (c) 2016, NVIDIA CORPORATION. */ +#define LOG_CATEGORY UCLASS_POWER_DOMAIN + #include #include #include diff --git a/drivers/power/pmic/pmic-uclass.c b/drivers/power/pmic/pmic-uclass.c index 79166b8bbcd..5dcf6d8079d 100644 --- a/drivers/power/pmic/pmic-uclass.c +++ b/drivers/power/pmic/pmic-uclass.c @@ -4,6 +4,8 @@ * Przemyslaw Marczak */ +#define LOG_CATEGORY UCLASS_PMIC + #include #include #include diff --git a/drivers/power/regulator/regulator-uclass.c b/drivers/power/regulator/regulator-uclass.c index fac96068233..aca00e56bbe 100644 --- a/drivers/power/regulator/regulator-uclass.c +++ b/drivers/power/regulator/regulator-uclass.c @@ -4,6 +4,8 @@ * Przemyslaw Marczak */ +#define LOG_CATEGORY UCLASS_REGULATOR + #include #include #include diff --git a/drivers/pwm/pwm-uclass.c b/drivers/pwm/pwm-uclass.c index 027181c6465..648d0757ba6 100644 --- a/drivers/pwm/pwm-uclass.c +++ b/drivers/pwm/pwm-uclass.c @@ -4,6 +4,8 @@ * Written by Simon Glass */ +#define LOG_CATEGORY UCLASS_PWM + #include #include #include diff --git a/drivers/ram/ram-uclass.c b/drivers/ram/ram-uclass.c index f4d387fed1e..4e21240fd4c 100644 --- a/drivers/ram/ram-uclass.c +++ b/drivers/ram/ram-uclass.c @@ -4,6 +4,8 @@ * Written by Simon Glass */ +#define LOG_CATEGORY UCLASS_RAM + #include #include #include diff --git a/drivers/remoteproc/rproc-uclass.c b/drivers/remoteproc/rproc-uclass.c index 5919c8bb978..64c47c1e722 100644 --- a/drivers/remoteproc/rproc-uclass.c +++ b/drivers/remoteproc/rproc-uclass.c @@ -3,6 +3,9 @@ * (C) Copyright 2015 * Texas Instruments Incorporated - http://www.ti.com/ */ + +#define LOG_CATEGORY UCLASS_REMOTEPROC + #define pr_fmt(fmt) "%s: " fmt, __func__ #include #include diff --git a/drivers/reset/reset-uclass.c b/drivers/reset/reset-uclass.c index ac89eaf098a..8caa616ed9f 100644 --- a/drivers/reset/reset-uclass.c +++ b/drivers/reset/reset-uclass.c @@ -3,6 +3,8 @@ * Copyright (c) 2016, NVIDIA CORPORATION. */ +#define LOG_CATEGORY UCLASS_RESET + #include #include #include diff --git a/drivers/rng/rng-uclass.c b/drivers/rng/rng-uclass.c index b6af3b8606a..53108e1b319 100644 --- a/drivers/rng/rng-uclass.c +++ b/drivers/rng/rng-uclass.c @@ -3,6 +3,8 @@ * Copyright (c) 2019, Linaro Limited */ +#define LOG_CATEGORY UCLASS_RNG + #include #include #include diff --git a/drivers/rtc/rtc-uclass.c b/drivers/rtc/rtc-uclass.c index b406bab32d1..be6a2ddb667 100644 --- a/drivers/rtc/rtc-uclass.c +++ b/drivers/rtc/rtc-uclass.c @@ -4,6 +4,8 @@ * Written by Simon Glass */ +#define LOG_CATEGORY UCLASS_RTC + #include #include #include diff --git a/drivers/scsi/scsi-uclass.c b/drivers/scsi/scsi-uclass.c index 90a0adda479..a7c1eaf0cf5 100644 --- a/drivers/scsi/scsi-uclass.c +++ b/drivers/scsi/scsi-uclass.c @@ -8,6 +8,8 @@ * Based on ahci-uclass.c */ +#define LOG_CATEGORY UCLASS_SCSI + #include #include #include diff --git a/drivers/serial/serial-uclass.c b/drivers/serial/serial-uclass.c index 8a87eed6839..2b4feace53a 100644 --- a/drivers/serial/serial-uclass.c +++ b/drivers/serial/serial-uclass.c @@ -3,6 +3,8 @@ * Copyright (c) 2014 The Chromium OS Authors. */ +#define LOG_CATEGORY UCLASS_SERIAL + #include #include #include diff --git a/drivers/smem/smem-uclass.c b/drivers/smem/smem-uclass.c index ce7bf40656e..8469076915e 100644 --- a/drivers/smem/smem-uclass.c +++ b/drivers/smem/smem-uclass.c @@ -3,6 +3,8 @@ * Copyright (c) 2018 Ramon Fried */ +#define LOG_CATEGORY UCLASS_SMEM + #include #include #include diff --git a/drivers/soc/soc-uclass.c b/drivers/soc/soc-uclass.c index c32d647864f..dfad32d80db 100644 --- a/drivers/soc/soc-uclass.c +++ b/drivers/soc/soc-uclass.c @@ -4,6 +4,8 @@ * Dave Gerlach */ +#define LOG_CATEGORY UCLASS_SOC + #include #include #include diff --git a/drivers/sound/codec-uclass.c b/drivers/sound/codec-uclass.c index 1ec77acfc1c..2cb233bd306 100644 --- a/drivers/sound/codec-uclass.c +++ b/drivers/sound/codec-uclass.c @@ -4,6 +4,8 @@ * Written by Simon Glass */ +#define LOG_CATEGORY UCLASS_AUDIO_CODEC + #include #include #include diff --git a/drivers/sound/i2s-uclass.c b/drivers/sound/i2s-uclass.c index 2639c86ea21..fc4f686b516 100644 --- a/drivers/sound/i2s-uclass.c +++ b/drivers/sound/i2s-uclass.c @@ -4,6 +4,8 @@ * Written by Simon Glass */ +#define LOG_CATEGORY UCLASS_I2S + #include #include #include diff --git a/drivers/sound/sound-uclass.c b/drivers/sound/sound-uclass.c index 0c71e01f337..2ffc4fc7c1d 100644 --- a/drivers/sound/sound-uclass.c +++ b/drivers/sound/sound-uclass.c @@ -4,6 +4,8 @@ * Written by Simon Glass */ +#define LOG_CATEGORY UCLASS_SOUND + #include #include #include diff --git a/drivers/spi/spi-emul-uclass.c b/drivers/spi/spi-emul-uclass.c index 52f3f9a0115..64bc19c0011 100644 --- a/drivers/spi/spi-emul-uclass.c +++ b/drivers/spi/spi-emul-uclass.c @@ -3,6 +3,8 @@ * Copyright (c) 2014 Google, Inc */ +#define LOG_CATEGORY UCLASS_SPI_EMUL + #include #include #include diff --git a/drivers/spmi/spmi-uclass.c b/drivers/spmi/spmi-uclass.c index ff098731bb2..9d9f46a37d8 100644 --- a/drivers/spmi/spmi-uclass.c +++ b/drivers/spmi/spmi-uclass.c @@ -5,6 +5,8 @@ * (C) Copyright 2015 Mateusz Kulikowski */ +#define LOG_CATEGORY UCLASS_SPMI + #include #include #include diff --git a/drivers/sysinfo/sysinfo-uclass.c b/drivers/sysinfo/sysinfo-uclass.c index 4a660dfd157..c5cc3cb9596 100644 --- a/drivers/sysinfo/sysinfo-uclass.c +++ b/drivers/sysinfo/sysinfo-uclass.c @@ -4,6 +4,8 @@ * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc */ +#define LOG_CATEGORY UCLASS_SYSINFO + #include #include #include diff --git a/drivers/tee/tee-uclass.c b/drivers/tee/tee-uclass.c index 2cc6b6c407d..cb1b28e2f83 100644 --- a/drivers/tee/tee-uclass.c +++ b/drivers/tee/tee-uclass.c @@ -3,6 +3,8 @@ * Copyright (c) 2018 Linaro Limited */ +#define LOG_CATEGORY UCLASS_TEE + #include #include #include diff --git a/drivers/thermal/thermal-uclass.c b/drivers/thermal/thermal-uclass.c index a4ea1e29145..700df8af254 100644 --- a/drivers/thermal/thermal-uclass.c +++ b/drivers/thermal/thermal-uclass.c @@ -3,6 +3,8 @@ * (C) Copyright 2014 Freescale Semiconductor, Inc */ +#define LOG_CATEGORY UCLASS_THERMAL + #include #include #include diff --git a/drivers/timer/timer-uclass.c b/drivers/timer/timer-uclass.c index 73b4a5cd27f..c8e8419b22e 100644 --- a/drivers/timer/timer-uclass.c +++ b/drivers/timer/timer-uclass.c @@ -3,6 +3,8 @@ * Copyright (C) 2015 Thomas Chou */ +#define LOG_CATEGORY UCLASS_TIMER + #include #include #include diff --git a/drivers/ufs/ufs-uclass.c b/drivers/ufs/ufs-uclass.c index 034d14fd8da..ceea30c4a95 100644 --- a/drivers/ufs/ufs-uclass.c +++ b/drivers/ufs/ufs-uclass.c @@ -5,6 +5,8 @@ * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com */ +#define LOG_CATEGORY UCLASS_UFS + #include #include "ufs.h" #include diff --git a/drivers/usb/emul/usb-emul-uclass.c b/drivers/usb/emul/usb-emul-uclass.c index f5d98b917dc..05f6d3d9e2f 100644 --- a/drivers/usb/emul/usb-emul-uclass.c +++ b/drivers/usb/emul/usb-emul-uclass.c @@ -4,6 +4,8 @@ * Written by Simon Glass */ +#define LOG_CATEGORY UCLASS_USB_EMUL + #include #include #include diff --git a/drivers/usb/gadget/udc/udc-uclass.c b/drivers/usb/gadget/udc/udc-uclass.c index dbc354e84f9..de8861829c7 100644 --- a/drivers/usb/gadget/udc/udc-uclass.c +++ b/drivers/usb/gadget/udc/udc-uclass.c @@ -4,6 +4,8 @@ * Written by Jean-Jacques Hiblot */ +#define LOG_CATEGORY UCLASS_USB_GADGET_GENERIC + #include #include #include diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c index e3b616c3266..fd39c3345c3 100644 --- a/drivers/usb/host/usb-uclass.c +++ b/drivers/usb/host/usb-uclass.c @@ -6,6 +6,8 @@ * usb_match_device() modified from Linux kernel v4.0. */ +#define LOG_CATEGORY UCLASS_USB + #include #include #include diff --git a/drivers/video/backlight-uclass.c b/drivers/video/backlight-uclass.c index 0aadf8a1f97..c14996d003c 100644 --- a/drivers/video/backlight-uclass.c +++ b/drivers/video/backlight-uclass.c @@ -4,6 +4,8 @@ * Written by Simon Glass */ +#define LOG_CATEGORY UCLASS_PANEL_BACKLIGHT + #include #include #include diff --git a/drivers/video/bridge/video-bridge-uclass.c b/drivers/video/bridge/video-bridge-uclass.c index 08d38b244bd..f389bc6b147 100644 --- a/drivers/video/bridge/video-bridge-uclass.c +++ b/drivers/video/bridge/video-bridge-uclass.c @@ -4,6 +4,8 @@ * Written by Simon Glass */ +#define LOG_CATEGORY UCLASS_VIDEO_BRIDGE + #include #include #include diff --git a/drivers/video/display-uclass.c b/drivers/video/display-uclass.c index 068108e9155..2da3d1d14e9 100644 --- a/drivers/video/display-uclass.c +++ b/drivers/video/display-uclass.c @@ -3,6 +3,8 @@ * Copyright 2014 Google Inc. */ +#define LOG_CATEGORY UCLASS_DISPLAY + #include #include #include diff --git a/drivers/video/dsi-host-uclass.c b/drivers/video/dsi-host-uclass.c index 1db1f88a179..6e5256eb126 100644 --- a/drivers/video/dsi-host-uclass.c +++ b/drivers/video/dsi-host-uclass.c @@ -5,6 +5,8 @@ * */ +#define LOG_CATEGORY UCLASS_DSI_HOST + #include #include #include diff --git a/drivers/video/panel-uclass.c b/drivers/video/panel-uclass.c index 246d1b2836d..bb2eaae2e97 100644 --- a/drivers/video/panel-uclass.c +++ b/drivers/video/panel-uclass.c @@ -4,6 +4,8 @@ * Written by Simon Glass */ +#define LOG_CATEGORY UCLASS_PANEL + #include #include #include diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c index 81b65f5aaee..8f7d987cdd2 100644 --- a/drivers/video/vidconsole-uclass.c +++ b/drivers/video/vidconsole-uclass.c @@ -7,6 +7,8 @@ * Bernecker & Rainer Industrieelektronik GmbH - http://www.br-automation.com */ +#define LOG_CATEGORY UCLASS_VIDEO_CONSOLE + #include #include #include diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c index 96ec6f80af3..9f8cf6ef2a9 100644 --- a/drivers/video/video-uclass.c +++ b/drivers/video/video-uclass.c @@ -3,6 +3,8 @@ * Copyright (c) 2015 Google, Inc */ +#define LOG_CATEGORY UCLASS_VIDEO + #include #include #include diff --git a/drivers/video/video_osd-uclass.c b/drivers/video/video_osd-uclass.c index 82136a292bf..0d3aae4d827 100644 --- a/drivers/video/video_osd-uclass.c +++ b/drivers/video/video_osd-uclass.c @@ -4,6 +4,8 @@ * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc */ +#define LOG_CATEGORY UCLASS_VIDEO_OSD + #include #include #include diff --git a/drivers/virtio/virtio-uclass.c b/drivers/virtio/virtio-uclass.c index 0379536c542..9e2d0e06a1e 100644 --- a/drivers/virtio/virtio-uclass.c +++ b/drivers/virtio/virtio-uclass.c @@ -15,6 +15,8 @@ * the VirtIO specification v1.0. */ +#define LOG_CATEGORY UCLASS_VIRTIO + #include #include #include diff --git a/drivers/w1-eeprom/w1-eeprom-uclass.c b/drivers/w1-eeprom/w1-eeprom-uclass.c index 7a02af3dd6d..70ba537243f 100644 --- a/drivers/w1-eeprom/w1-eeprom-uclass.c +++ b/drivers/w1-eeprom/w1-eeprom-uclass.c @@ -10,6 +10,8 @@ * */ +#define LOG_CATEGORY UCLASS_W1_EEPROM + #include #include #include diff --git a/drivers/w1/w1-uclass.c b/drivers/w1/w1-uclass.c index b98927389f3..52b519c21d2 100644 --- a/drivers/w1/w1-uclass.c +++ b/drivers/w1/w1-uclass.c @@ -12,6 +12,8 @@ * */ +#define LOG_CATEGORY UCLASS_W1 + #include #include #include diff --git a/drivers/watchdog/wdt-uclass.c b/drivers/watchdog/wdt-uclass.c index 26871352960..a0c2429e5a4 100644 --- a/drivers/watchdog/wdt-uclass.c +++ b/drivers/watchdog/wdt-uclass.c @@ -3,6 +3,8 @@ * Copyright 2017 Google, Inc */ +#define LOG_CATEGORY UCLASS_WDT + #include #include #include diff --git a/drivers/xen/pvblock.c b/drivers/xen/pvblock.c index 1c5d039ef05..c25c3ea4fff 100644 --- a/drivers/xen/pvblock.c +++ b/drivers/xen/pvblock.c @@ -3,6 +3,9 @@ * (C) 2007-2008 Samuel Thibault. * (C) Copyright 2020 EPAM Systems Inc. */ + +#define LOG_CATEGORY UCLASS_PVBLOCK + #include #include #include From 3beba4ad34649e053b97c5a61cd7de55bc718866 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Tue, 11 May 2021 21:03:16 +0200 Subject: [PATCH 3/8] sandbox: ensure that state->ram_buf is in low memory Addresses in state->ram_buf must be in the low 4 GiB of the address space. Otherwise we cannot correctly fill SMBIOS tables. This shows up in warnings like: WARNING: SMBIOS table_address overflow 7f752735e020 Ensure that state->ram_buf is initialized by the first invocation of os_malloc(). Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- arch/sandbox/cpu/start.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/arch/sandbox/cpu/start.c b/arch/sandbox/cpu/start.c index 63b086dff80..ad17e17c59e 100644 --- a/arch/sandbox/cpu/start.c +++ b/arch/sandbox/cpu/start.c @@ -453,6 +453,14 @@ int main(int argc, char *argv[]) text_base = os_find_text_base(); + /* + * This must be the first invocation of os_malloc() to have + * state->ram_buf in the low 4 GiB. + */ + ret = state_init(); + if (ret) + goto err; + /* * Copy argv[] so that we can pass the arguments in the original * sequence when resetting the sandbox. @@ -467,10 +475,6 @@ int main(int argc, char *argv[]) gd = &data; gd->arch.text_base = text_base; - ret = state_init(); - if (ret) - goto err; - state = state_get_current(); if (os_parse_args(state, argc, argv)) return 1; From 825a9a94e1a5795e545156ead664a85403cda0e1 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Wed, 12 May 2021 18:38:51 +0200 Subject: [PATCH 4/8] sandbox: fix sandbox_reset() state_uninit() and dm_uninit() are mutually exclusive: state_uninit() prints via drivers. So it cannot be executed after dm_uninit(). dm_uninit() requires memory. So it cannot be executed after state_uninit() which releases all memory. Just skip dm_uninit() when resetting the sandbox. We will wake up in a new process and allocate new memory. So this cleanup is not required. We don't do it in sandbox_exit() either. This avoids a segmentation error when efi_reset_system_boottime() is invoked by a UEFI application. Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- arch/sandbox/cpu/start.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/arch/sandbox/cpu/start.c b/arch/sandbox/cpu/start.c index ad17e17c59e..777db4e9522 100644 --- a/arch/sandbox/cpu/start.c +++ b/arch/sandbox/cpu/start.c @@ -436,9 +436,6 @@ void sandbox_reset(void) if (state_uninit()) os_exit(2); - if (dm_uninit()) - os_exit(2); - /* Restart U-Boot */ os_relaunch(os_argv); } From 3c9fc23c44317be82be94e461ff260ec7f083523 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Wed, 19 May 2021 12:02:39 +0200 Subject: [PATCH 5/8] sandbox: don't refer to symbol _init GCC provides a symbol _init in crti.o on x86_64 and aarch64 but not on RISC-V. The following lines leads to a build error for sandbox_defconfig on RISC-V due to the missing symbol: common/board_f.c:269: #elif defined(CONFIG_SANDBOX) || defined(CONFIG_EFI_APP) gd->mon_len = (ulong)&_end - (ulong)_init; The sandbox code is not copied into the memory allocated using mmap(). Hence we can safely use gd->mon_len = 0 to avoid the reference to _init. Signed-off-by: Heinrich Schuchardt Reviewed-by: Bin Meng Reviewed-by: Rick Chen --- common/board_f.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/common/board_f.c b/common/board_f.c index 203e965799e..c1b8e63e560 100644 --- a/common/board_f.c +++ b/common/board_f.c @@ -265,7 +265,9 @@ static int setup_mon_len(void) { #if defined(__ARM__) || defined(__MICROBLAZE__) gd->mon_len = (ulong)&__bss_end - (ulong)_start; -#elif defined(CONFIG_SANDBOX) || defined(CONFIG_EFI_APP) +#elif defined(CONFIG_SANDBOX) + gd->mon_len = 0; +#elif defined(CONFIG_EFI_APP) gd->mon_len = (ulong)&_end - (ulong)_init; #elif defined(CONFIG_NIOS2) || defined(CONFIG_XTENSA) gd->mon_len = CONFIG_SYS_MONITOR_LEN; From 98c14ff019515ffcb1b40b550e56fe1dfbede51b Mon Sep 17 00:00:00 2001 From: Rasmus Villemoes Date: Wed, 19 May 2021 18:08:11 +0200 Subject: [PATCH 6/8] remove struct uclass_driver::ops Each _device_ belonging to a given uclass of course has its own ->ops, of a type determined by and known to the uclass. However, no instance of a uclass_driver seems to populate ->ops, and the only reference to it in code is this relocation. Moreover, it's not really clear what could sensibly be assigned; it would have to be some "struct uclass_ops *" providing a set of methods for the core to call on that particular uclass, but should the need for that ever arise, it would be better to have a member of that particular type instead of void*. Signed-off-by: Rasmus Villemoes Reviewed-by: Simon Glass --- drivers/core/root.c | 3 --- include/dm/uclass.h | 3 --- 2 files changed, 6 deletions(-) diff --git a/drivers/core/root.c b/drivers/core/root.c index 537e9daaf8a..78eee082c95 100644 --- a/drivers/core/root.c +++ b/drivers/core/root.c @@ -113,9 +113,6 @@ void fix_uclass(void) entry->init += gd->reloc_off; if (entry->destroy) entry->destroy += gd->reloc_off; - /* FIXME maybe also need to fix these ops */ - if (entry->ops) - entry->ops += gd->reloc_off; } } diff --git a/include/dm/uclass.h b/include/dm/uclass.h index 6752d8ee0be..2778818b528 100644 --- a/include/dm/uclass.h +++ b/include/dm/uclass.h @@ -84,8 +84,6 @@ struct udevice; * its children. If non-zero this is the size of this data, to be allocated * in the child device's parent_plat pointer. This value is only used as * a fallback if this member is 0 in the driver. - * @ops: Uclass operations, providing the consistent interface to devices - * within the uclass. * @flags: Flags for this uclass (DM_UC_...) */ struct uclass_driver { @@ -106,7 +104,6 @@ struct uclass_driver { int per_device_plat_auto; int per_child_auto; int per_child_plat_auto; - const void *ops; uint32_t flags; }; From e712245d08d95fac6467fd0d05a12d6506aeda2d Mon Sep 17 00:00:00 2001 From: Alper Nebi Yasak Date: Wed, 19 May 2021 19:33:31 +0300 Subject: [PATCH 7/8] sandbox: cros-ec: Add tests for the Chromium OS EC PWM driver This patch adds a limited pulse-width modulator to sandbox's Chromium OS Embedded Controller emulation. The emulated PWM device supports multiple channels but can only set a duty cycle for each, as the actual EC doesn't expose any functionality or information other than that. Though the EC supports specifying the PWM channel by its type (e.g. display backlight, keyboard backlight), this is not implemented in the emulation as nothing in U-Boot uses this type specification. This emulated PWM device is then used to test the Chromium OS PWM driver in sandbox. Adding the required device node to the sandbox test device-tree unfortunately makes it the first PWM device, so this also touches some other tests to make sure they still use the sandbox PWM. Signed-off-by: Alper Nebi Yasak Reviewed-by: Simon Glass --- arch/sandbox/dts/test.dts | 6 +++ arch/sandbox/include/asm/test.h | 10 +++++ configs/sandbox64_defconfig | 1 + configs/sandbox_defconfig | 1 + configs/sandbox_flattree_defconfig | 1 + configs/sandbox_noinst_defconfig | 1 + configs/sandbox_spl_defconfig | 1 + drivers/misc/cros_ec_sandbox.c | 47 +++++++++++++++++++++++ test/cmd/pwm.c | 32 +++++++++++++++- test/dm/Makefile | 1 + test/dm/cros_ec_pwm.c | 60 ++++++++++++++++++++++++++++++ test/dm/panel.c | 2 +- test/dm/pwm.c | 6 ++- 13 files changed, 164 insertions(+), 5 deletions(-) create mode 100644 test/dm/cros_ec_pwm.c diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index 8e7eaf2d150..d85bb46ceba 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -139,6 +139,12 @@ size = <0x10000>; }; }; + + cros_ec_pwm: cros-ec-pwm { + compatible = "google,cros-ec-pwm"; + #pwm-cells = <1>; + }; + }; dsi_host: dsi_host { diff --git a/arch/sandbox/include/asm/test.h b/arch/sandbox/include/asm/test.h index 1cb960ac240..dab1a4ea01b 100644 --- a/arch/sandbox/include/asm/test.h +++ b/arch/sandbox/include/asm/test.h @@ -275,4 +275,14 @@ void sandbox_set_enable_memio(bool enable); */ void sandbox_cros_ec_set_test_flags(struct udevice *dev, uint flags); +/** + * sandbox_cros_ec_get_pwm_duty() - Get EC PWM config for testing purposes + * + * @dev: Device to check + * @index: PWM channel index + * @duty: Current duty cycle in 0..EC_PWM_MAX_DUTY range. + * @return 0 if OK, -ENOSPC if the PWM number is invalid + */ +int sandbox_cros_ec_get_pwm_duty(struct udevice *dev, uint index, uint *duty); + #endif diff --git a/configs/sandbox64_defconfig b/configs/sandbox64_defconfig index a8bb5607245..674b6603910 100644 --- a/configs/sandbox64_defconfig +++ b/configs/sandbox64_defconfig @@ -188,6 +188,7 @@ CONFIG_REGULATOR_S5M8767=y CONFIG_DM_REGULATOR_SANDBOX=y CONFIG_REGULATOR_TPS65090=y CONFIG_DM_PWM=y +CONFIG_PWM_CROS_EC=y CONFIG_PWM_SANDBOX=y CONFIG_RAM=y CONFIG_REMOTEPROC_SANDBOX=y diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index f16e2d5d23d..df14506b09c 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -226,6 +226,7 @@ CONFIG_DM_REGULATOR_SANDBOX=y CONFIG_REGULATOR_TPS65090=y CONFIG_DM_REGULATOR_SCMI=y CONFIG_DM_PWM=y +CONFIG_PWM_CROS_EC=y CONFIG_PWM_SANDBOX=y CONFIG_RAM=y CONFIG_REMOTEPROC_SANDBOX=y diff --git a/configs/sandbox_flattree_defconfig b/configs/sandbox_flattree_defconfig index 1c39a545c85..aaa6720cf9b 100644 --- a/configs/sandbox_flattree_defconfig +++ b/configs/sandbox_flattree_defconfig @@ -165,6 +165,7 @@ CONFIG_REGULATOR_S5M8767=y CONFIG_DM_REGULATOR_SANDBOX=y CONFIG_REGULATOR_TPS65090=y CONFIG_DM_PWM=y +CONFIG_PWM_CROS_EC=y CONFIG_PWM_SANDBOX=y CONFIG_RAM=y CONFIG_REMOTEPROC_SANDBOX=y diff --git a/configs/sandbox_noinst_defconfig b/configs/sandbox_noinst_defconfig index 9f415cd8756..3dc3a361543 100644 --- a/configs/sandbox_noinst_defconfig +++ b/configs/sandbox_noinst_defconfig @@ -181,6 +181,7 @@ CONFIG_REGULATOR_S5M8767=y CONFIG_DM_REGULATOR_SANDBOX=y CONFIG_REGULATOR_TPS65090=y CONFIG_DM_PWM=y +CONFIG_PWM_CROS_EC=y CONFIG_PWM_SANDBOX=y CONFIG_RAM=y CONFIG_REMOTEPROC_SANDBOX=y diff --git a/configs/sandbox_spl_defconfig b/configs/sandbox_spl_defconfig index 8bc1373ec31..c7d15de9391 100644 --- a/configs/sandbox_spl_defconfig +++ b/configs/sandbox_spl_defconfig @@ -183,6 +183,7 @@ CONFIG_REGULATOR_S5M8767=y CONFIG_DM_REGULATOR_SANDBOX=y CONFIG_REGULATOR_TPS65090=y CONFIG_DM_PWM=y +CONFIG_PWM_CROS_EC=y CONFIG_PWM_SANDBOX=y CONFIG_RAM=y CONFIG_REMOTEPROC_SANDBOX=y diff --git a/drivers/misc/cros_ec_sandbox.c b/drivers/misc/cros_ec_sandbox.c index bc01df0904e..db5e3b0f51a 100644 --- a/drivers/misc/cros_ec_sandbox.c +++ b/drivers/misc/cros_ec_sandbox.c @@ -64,6 +64,7 @@ struct ec_keymatrix_entry { enum { VSTORE_SLOT_COUNT = 4, + PWM_CHANNEL_COUNT = 4, }; struct vstore_slot { @@ -71,6 +72,10 @@ struct vstore_slot { u8 data[EC_VSTORE_SLOT_SIZE]; }; +struct ec_pwm_channel { + uint duty; /* not ns, EC_PWM_MAX_DUTY = 100% */ +}; + /** * struct ec_state - Information about the EC state * @@ -85,6 +90,7 @@ struct vstore_slot { * @recovery_req: Keyboard recovery requested * @test_flags: Flags that control behaviour for tests * @slot_locked: Locked vstore slots (mask) + * @pwm: Information per PWM channel */ struct ec_state { u8 vbnv_context[EC_VBNV_BLOCK_SIZE_V2]; @@ -98,6 +104,7 @@ struct ec_state { bool recovery_req; uint test_flags; struct vstore_slot slot[VSTORE_SLOT_COUNT]; + struct ec_pwm_channel pwm[PWM_CHANNEL_COUNT]; } s_state, *g_state; /** @@ -554,6 +561,33 @@ static int process_cmd(struct ec_state *ec, len = sizeof(*resp); break; } + case EC_CMD_PWM_GET_DUTY: { + const struct ec_params_pwm_get_duty *req = req_data; + struct ec_response_pwm_get_duty *resp = resp_data; + struct ec_pwm_channel *pwm; + + if (req->pwm_type != EC_PWM_TYPE_GENERIC) + return -EINVAL; + if (req->index >= PWM_CHANNEL_COUNT) + return -EINVAL; + pwm = &ec->pwm[req->index]; + resp->duty = pwm->duty; + len = sizeof(*resp); + break; + } + case EC_CMD_PWM_SET_DUTY: { + const struct ec_params_pwm_set_duty *req = req_data; + struct ec_pwm_channel *pwm; + + if (req->pwm_type != EC_PWM_TYPE_GENERIC) + return -EINVAL; + if (req->index >= PWM_CHANNEL_COUNT) + return -EINVAL; + pwm = &ec->pwm[req->index]; + pwm->duty = req->duty; + len = 0; + break; + } default: printf(" ** Unknown EC command %#02x\n", req_hdr->command); return -1; @@ -619,6 +653,19 @@ void sandbox_cros_ec_set_test_flags(struct udevice *dev, uint flags) ec->test_flags = flags; } +int sandbox_cros_ec_get_pwm_duty(struct udevice *dev, uint index, uint *duty) +{ + struct ec_state *ec = dev_get_priv(dev); + struct ec_pwm_channel *pwm; + + if (index >= PWM_CHANNEL_COUNT) + return -ENOSPC; + pwm = &ec->pwm[index]; + *duty = pwm->duty; + + return 0; +} + int cros_ec_probe(struct udevice *dev) { struct ec_state *ec = dev_get_priv(dev); diff --git a/test/cmd/pwm.c b/test/cmd/pwm.c index 5343af83fa3..2fc0b5e4070 100644 --- a/test/cmd/pwm.c +++ b/test/cmd/pwm.c @@ -18,16 +18,20 @@ static int dm_test_pwm_cmd(struct unit_test_state *uts) { struct udevice *dev; + /* cros-ec-pwm */ ut_assertok(uclass_get_device(UCLASS_PWM, 0, &dev)); ut_assertnonnull(dev); ut_assertok(console_record_reset_enable()); /* pwm */ - ut_assertok(run_command("pwm invert 0 0 1", 0)); + /* cros-ec-pwm doesn't support invert */ + ut_asserteq(1, run_command("pwm invert 0 0 1", 0)); + ut_assert_nextline("error(-38)") ut_assert_console_end(); - ut_assertok(run_command("pwm invert 0 0 0", 0)); + ut_asserteq(1, run_command("pwm invert 0 0 0", 0)); + ut_assert_nextline("error(-38)") ut_assert_console_end(); /* pwm */ @@ -41,6 +45,30 @@ static int dm_test_pwm_cmd(struct unit_test_state *uts) ut_assertok(run_command("pwm disable 0 0", 0)); ut_assert_console_end(); + /* sandbox-pwm */ + ut_assertok(uclass_get_device(UCLASS_PWM, 1, &dev)); + ut_assertnonnull(dev); + + ut_assertok(console_record_reset_enable()); + + /* pwm */ + ut_assertok(run_command("pwm invert 1 0 1", 0)); + ut_assert_console_end(); + + ut_assertok(run_command("pwm invert 1 0 0", 0)); + ut_assert_console_end(); + + /* pwm */ + ut_assertok(run_command("pwm config 1 0 10 50", 0)); + ut_assert_console_end(); + + /* pwm */ + ut_assertok(run_command("pwm enable 1 0", 0)); + ut_assert_console_end(); + + ut_assertok(run_command("pwm disable 1 0", 0)); + ut_assert_console_end(); + return 0; } diff --git a/test/dm/Makefile b/test/dm/Makefile index c9644617a1f..9ef9171a1cb 100644 --- a/test/dm/Makefile +++ b/test/dm/Makefile @@ -30,6 +30,7 @@ obj-$(CONFIG_DM_BOOTCOUNT) += bootcount.o obj-$(CONFIG_CLK) += clk.o clk_ccf.o obj-$(CONFIG_CPU) += cpu.o obj-$(CONFIG_CROS_EC) += cros_ec.o +obj-$(CONFIG_PWM_CROS_EC) += cros_ec_pwm.o obj-$(CONFIG_DEVRES) += devres.o obj-$(CONFIG_DMA) += dma.o obj-$(CONFIG_VIDEO_MIPI_DSI) += dsi_host.o diff --git a/test/dm/cros_ec_pwm.c b/test/dm/cros_ec_pwm.c new file mode 100644 index 00000000000..f8d6e1e6c40 --- /dev/null +++ b/test/dm/cros_ec_pwm.c @@ -0,0 +1,60 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include +#include +#include +#include +#include +#include +#include +#include + +static int dm_test_cros_ec_pwm(struct unit_test_state *uts) +{ + struct udevice *pwm; + struct udevice *ec; + uint duty; + + ut_assertok(uclass_get_device_by_name(UCLASS_PWM, "cros-ec-pwm", &pwm)); + ut_assertnonnull(pwm); + ec = dev_get_parent(pwm); + ut_assertnonnull(ec); + + ut_assertok(pwm_set_config(pwm, 0, 100, 50)); + ut_assertok(pwm_set_enable(pwm, 0, true)); + ut_assertok(sandbox_cros_ec_get_pwm_duty(ec, 0, &duty)); + ut_asserteq(50 * EC_PWM_MAX_DUTY / 100, duty); + + ut_assertok(pwm_set_config(pwm, 0, 15721, 2719)); + ut_assertok(pwm_set_enable(pwm, 0, true)); + ut_assertok(sandbox_cros_ec_get_pwm_duty(ec, 0, &duty)); + ut_asserteq(2719 * EC_PWM_MAX_DUTY / 15721, duty); + + ut_assertok(pwm_set_enable(pwm, 0, false)); + ut_assertok(sandbox_cros_ec_get_pwm_duty(ec, 0, &duty)); + ut_asserteq(0, duty); + + ut_assertok(pwm_set_enable(pwm, 0, true)); + ut_assertok(sandbox_cros_ec_get_pwm_duty(ec, 0, &duty)); + ut_asserteq(2719 * EC_PWM_MAX_DUTY / 15721, duty); + + ut_assertok(pwm_set_config(pwm, 1, 1000, 0)); + ut_assertok(pwm_set_enable(pwm, 1, true)); + ut_assertok(sandbox_cros_ec_get_pwm_duty(ec, 1, &duty)); + ut_asserteq(0, duty); + + ut_assertok(pwm_set_config(pwm, 2, 1000, 1024)); + ut_assertok(pwm_set_enable(pwm, 2, true)); + ut_assertok(sandbox_cros_ec_get_pwm_duty(ec, 2, &duty)); + ut_asserteq(EC_PWM_MAX_DUTY, duty); + + ut_assertok(pwm_set_config(pwm, 3, EC_PWM_MAX_DUTY, 0xABCD)); + ut_assertok(pwm_set_enable(pwm, 3, true)); + ut_assertok(sandbox_cros_ec_get_pwm_duty(ec, 3, &duty)); + ut_asserteq(0xABCD, duty); + + ut_asserteq(-EINVAL, pwm_set_enable(pwm, 4, true)); + + return 0; +} +DM_TEST(dm_test_cros_ec_pwm, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); diff --git a/test/dm/panel.c b/test/dm/panel.c index 49f5ac7169d..4d435a0d255 100644 --- a/test/dm/panel.c +++ b/test/dm/panel.c @@ -28,7 +28,7 @@ static int dm_test_panel(struct unit_test_state *uts) bool polarity; ut_assertok(uclass_first_device_err(UCLASS_PANEL, &dev)); - ut_assertok(uclass_first_device_err(UCLASS_PWM, &pwm)); + ut_assertok(uclass_get_device_by_name(UCLASS_PWM, "pwm", &pwm)); ut_assertok(uclass_get_device(UCLASS_GPIO, 1, &gpio)); ut_assertok(regulator_get_by_platname("VDD_EMMC_1.8V", ®)); ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns, diff --git a/test/dm/pwm.c b/test/dm/pwm.c index b624cf3d655..dff626c771a 100644 --- a/test/dm/pwm.c +++ b/test/dm/pwm.c @@ -20,7 +20,7 @@ static int dm_test_pwm_base(struct unit_test_state *uts) bool enable; bool polarity; - ut_assertok(uclass_get_device(UCLASS_PWM, 0, &dev)); + ut_assertok(uclass_get_device_by_name(UCLASS_PWM, "pwm", &dev)); ut_assertnonnull(dev); ut_assertok(pwm_set_config(dev, 0, 100, 50)); ut_assertok(pwm_set_enable(dev, 0, true)); @@ -35,8 +35,10 @@ static int dm_test_pwm_base(struct unit_test_state *uts) ut_asserteq(period_ns, 4096); ut_asserteq(duty_ns, 50 * 4096 / 100); + ut_assertok(uclass_get_device(UCLASS_PWM, 0, &dev)); ut_assertok(uclass_get_device(UCLASS_PWM, 1, &dev)); - ut_asserteq(-ENODEV, uclass_get_device(UCLASS_PWM, 2, &dev)); + ut_assertok(uclass_get_device(UCLASS_PWM, 2, &dev)); + ut_asserteq(-ENODEV, uclass_get_device(UCLASS_PWM, 3, &dev)); return 0; } From 880e4768c20b99b1f9a50f35c180f8522dd82c9a Mon Sep 17 00:00:00 2001 From: Alper Nebi Yasak Date: Mon, 7 Jun 2021 21:11:37 +0300 Subject: [PATCH 8/8] tools: Fix default target compile tools in Python tools In commit 1e4687aa47ed ("binman: Use target-specific tools when cross-compiling"), a utility function was implemented to get preferred compilation tools using environment variables like CC and CROSS_COMPILE. Although it intended to provide custom default tools (same as those in the global Makefile) when no relevant variables were set (for example using "gcc" for "cc"), it is only doing so when CROSS_COMPILE is set and returning the literal name of the tool otherwise. Remove the check for an empty CROSS_COMPILE, which makes the function use it as an empty prefix to the custom defaults and return the intended executables. Fixes: 1e4687aa47ed ("binman: Use target-specific tools when cross-compiling") Signed-off-by: Alper Nebi Yasak --- tools/patman/tools.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tools/patman/tools.py b/tools/patman/tools.py index e5f391b7aa9..ec95a543bd9 100644 --- a/tools/patman/tools.py +++ b/tools/patman/tools.py @@ -292,8 +292,6 @@ def GetTargetCompileTool(name, cross_compile=None): if cross_compile is None: cross_compile = env.get('CROSS_COMPILE', '') - if not cross_compile: - return name, [] if name in ('as', 'ar', 'nm', 'ldr', 'strip', 'objcopy', 'objdump'): target_name = cross_compile + name