From 7a02e4d53c4a44a565cc9228bd1b78e0a2bdd6b5 Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Tue, 10 Mar 2020 16:05:43 +0100 Subject: [PATCH 01/58] stm32mp: update dependency for STM32_ETZPC Correct the dependency for STM32 ETZPC protection, linked to SOC STM32MP identified by CONFIG_STM32MP15x and not linked to CONFIG_TARGET_STM32MP1 (no more existing). This patch fix an issue introduced by commit 846254888e2e ("stm32mp1: split board and SOC support for STM32MP15x family"). Signed-off-by: Patrick Delaunay Acked-by: Patrice Chotard --- arch/arm/mach-stm32mp/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm/mach-stm32mp/Kconfig b/arch/arm/mach-stm32mp/Kconfig index e4d621dee8..96153693a7 100644 --- a/arch/arm/mach-stm32mp/Kconfig +++ b/arch/arm/mach-stm32mp/Kconfig @@ -119,7 +119,7 @@ config SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION_MMC2 config STM32_ETZPC bool "STM32 Extended TrustZone Protection" - depends on TARGET_STM32MP1 + depends on STM32MP15x default y help Say y to enable STM32 Extended TrustZone Protection From b484296f6fda23ab2c996892826ebcc12cbd2303 Mon Sep 17 00:00:00 2001 From: AKASHI Takahiro Date: Wed, 11 Mar 2020 15:18:18 +0900 Subject: [PATCH 02/58] efi_loader: get_memory_map: return parameters whenever possible Currently, if GetMemoryMap API returns EFI_BUFFER_TOO_SMALL, it doesn't set valid values to other parameters, descriptor_size and descriptor_version, except memory_map_size. Some efi applications, however, may use those value; in particular, xen uses descriptor_size to calculate a size of buffer to be allocated. While UEFI specification is ambiguous in this point, it would be better to address this issue proactively to maximize the compatibility with existing efi applications. With this patch, for example, xen.efi (and hence linux kernel) can be started via bootefi without modification. Signed-off-by: AKASHI Takahiro Reviewed-by: Heinrich Schuchardt --- lib/efi_loader/efi_memory.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c index 89adf20310..97d90f069a 100644 --- a/lib/efi_loader/efi_memory.c +++ b/lib/efi_loader/efi_memory.c @@ -627,18 +627,18 @@ efi_status_t efi_get_memory_map(efi_uintn_t *memory_map_size, *memory_map_size = map_size; - if (provided_map_size < map_size) - return EFI_BUFFER_TOO_SMALL; - - if (!memory_map) - return EFI_INVALID_PARAMETER; - if (descriptor_size) *descriptor_size = sizeof(struct efi_mem_desc); if (descriptor_version) *descriptor_version = EFI_MEMORY_DESCRIPTOR_VERSION; + if (provided_map_size < map_size) + return EFI_BUFFER_TOO_SMALL; + + if (!memory_map) + return EFI_INVALID_PARAMETER; + /* Copy list into array */ /* Return the list in ascending order */ memory_map = &memory_map[map_entries - 1]; From e8bced62b6be344dbc922d88b1b278e316e1585f Mon Sep 17 00:00:00 2001 From: AKASHI Takahiro Date: Fri, 28 Feb 2020 09:05:04 +0900 Subject: [PATCH 03/58] cmd: efidebug: fix a failure of "boot rm" sub-command There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and then it will end up with a failure of this command due to a wrong value of an interim variable ("var_name16"). Signed-off-by: AKASHI Takahiro Reviewed-by: Heinrich Schuchardt --- cmd/efidebug.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cmd/efidebug.c b/cmd/efidebug.c index 21dfd44fcc..056ebb1083 100644 --- a/cmd/efidebug.c +++ b/cmd/efidebug.c @@ -649,7 +649,7 @@ static int do_efi_boot_rm(cmd_tbl_t *cmdtp, int flag, int id, i; char *endp; char var_name[9]; - u16 var_name16[9]; + u16 var_name16[9], *p; efi_status_t ret; if (argc == 1) @@ -662,7 +662,8 @@ static int do_efi_boot_rm(cmd_tbl_t *cmdtp, int flag, return CMD_RET_FAILURE; sprintf(var_name, "Boot%04X", id); - utf8_utf16_strncpy((u16 **)&var_name16, var_name, 9); + p = var_name16; + utf8_utf16_strncpy(&p, var_name, 9); ret = EFI_CALL(RT->set_variable(var_name16, &guid, 0, 0, NULL)); if (ret) { From 30efb5dd43fdeb6173c61a55b537fcfba2c45f3f Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Mon, 2 Mar 2020 20:13:10 +0100 Subject: [PATCH 04/58] cmd: efidebug: correct error message Add the missing line feed at the error message if the variable referred to by 'efidebug boot rm' does not exist. Shorten the format string by using the variable name instead of the number of the boot variable. Signed-off-by: Heinrich Schuchardt --- cmd/efidebug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/efidebug.c b/cmd/efidebug.c index 056ebb1083..8c3681c37d 100644 --- a/cmd/efidebug.c +++ b/cmd/efidebug.c @@ -667,7 +667,7 @@ static int do_efi_boot_rm(cmd_tbl_t *cmdtp, int flag, ret = EFI_CALL(RT->set_variable(var_name16, &guid, 0, 0, NULL)); if (ret) { - printf("Cannot remove Boot%04X", id); + printf("Cannot remove %ls\n", var_name16); return CMD_RET_FAILURE; } } From 2b8568f461188e8bd14ebe9b6968c56baca7b142 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Fri, 6 Mar 2020 21:56:10 +0100 Subject: [PATCH 05/58] efi_loader: unnecessary assignment in efi_queue_event The assigned value NULL is never used. Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_boottime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index 1f598b357a..e533a185f8 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -208,7 +208,7 @@ static void efi_process_event_queue(void) */ static void efi_queue_event(struct efi_event *event) { - struct efi_event *item = NULL; + struct efi_event *item; if (!event->notify_function) return; From c312c4b4dcd0574b81ff2c0d543f42295305ffaa Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sun, 2 Feb 2020 19:45:35 +0100 Subject: [PATCH 06/58] drivers/rng: simplify Kconfig For all sandbox systems with DM_RNG we enable RNG_SANDBOX. So we can simply set the default to yes. All rng drivers depend on DM_RNG. Use a single 'if' instead of individual dependencies. Now 'make menuconfig' shows the individual drivers neatly indented under the DM_RNG entry. Signed-off-by: Heinrich Schuchardt Reviewed-by: Sughosh Ganu --- configs/sandbox64_defconfig | 1 - configs/sandbox_defconfig | 1 - drivers/rng/Kconfig | 9 +++++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/configs/sandbox64_defconfig b/configs/sandbox64_defconfig index d1c94b65a1..71a4d7fccb 100644 --- a/configs/sandbox64_defconfig +++ b/configs/sandbox64_defconfig @@ -169,7 +169,6 @@ CONFIG_REMOTEPROC_SANDBOX=y CONFIG_DM_RESET=y CONFIG_SANDBOX_RESET=y CONFIG_DM_RNG=y -CONFIG_RNG_SANDBOX=y CONFIG_DM_RTC=y CONFIG_RTC_RV8803=y CONFIG_SANDBOX_SERIAL=y diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 45b5475b79..f96891ecae 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -189,7 +189,6 @@ CONFIG_REMOTEPROC_SANDBOX=y CONFIG_DM_RESET=y CONFIG_SANDBOX_RESET=y CONFIG_DM_RNG=y -CONFIG_RNG_SANDBOX=y CONFIG_DM_RTC=y CONFIG_RTC_RV8803=y CONFIG_DEBUG_UART_SANDBOX=y diff --git a/drivers/rng/Kconfig b/drivers/rng/Kconfig index 893b89d49b..c1aa43b823 100644 --- a/drivers/rng/Kconfig +++ b/drivers/rng/Kconfig @@ -6,16 +6,21 @@ config DM_RNG This interface is used to initialise the rng device and to read the random seed from the device. +if DM_RNG + config RNG_SANDBOX bool "Sandbox random number generator" - depends on SANDBOX && DM_RNG + depends on SANDBOX + default y help Enable random number generator for sandbox. This is an emulation of a rng device. config RNG_STM32MP1 bool "Enable random number generator for STM32MP1" - depends on ARCH_STM32MP && DM_RNG + depends on ARCH_STM32MP default n help Enable STM32MP1 rng driver. + +endif From bc40eb278b0c14b990556eab34a57b2b8ed598f4 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sun, 2 Feb 2020 19:52:04 +0100 Subject: [PATCH 07/58] drivers/rng: add Amlogic hardware RNG driver Add support for the hardware random number generator of Amlogic SOCs. Signed-off-by: Heinrich Schuchardt Reviewed-by: Neil Armstrong Reviewed-by: Sughosh Ganu --- drivers/rng/Kconfig | 8 +++ drivers/rng/Makefile | 1 + drivers/rng/meson-rng.c | 120 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 129 insertions(+) create mode 100644 drivers/rng/meson-rng.c diff --git a/drivers/rng/Kconfig b/drivers/rng/Kconfig index c1aa43b823..edb6152bb9 100644 --- a/drivers/rng/Kconfig +++ b/drivers/rng/Kconfig @@ -8,6 +8,14 @@ config DM_RNG if DM_RNG +config RNG_MESON + bool "Amlogic Meson Random Number Generator support" + depends on ARCH_MESON + default y + help + Enable support for hardware random number generator + of Amlogic Meson SoCs. + config RNG_SANDBOX bool "Sandbox random number generator" depends on SANDBOX diff --git a/drivers/rng/Makefile b/drivers/rng/Makefile index 3517005541..6a8a66779b 100644 --- a/drivers/rng/Makefile +++ b/drivers/rng/Makefile @@ -4,5 +4,6 @@ # obj-$(CONFIG_DM_RNG) += rng-uclass.o +obj-$(CONFIG_RNG_MESON) += meson-rng.o obj-$(CONFIG_RNG_SANDBOX) += sandbox_rng.o obj-$(CONFIG_RNG_STM32MP1) += stm32mp1_rng.o diff --git a/drivers/rng/meson-rng.c b/drivers/rng/meson-rng.c new file mode 100644 index 0000000000..4b81a62353 --- /dev/null +++ b/drivers/rng/meson-rng.c @@ -0,0 +1,120 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright 2020, Heinrich Schuchardt + * + * Driver for Amlogic hardware random number generator + */ + +#include +#include +#include +#include +#include + +struct meson_rng_platdata { + fdt_addr_t base; + struct clk clk; +}; + +/** + * meson_rng_read() - fill buffer with random bytes + * + * @buffer: buffer to receive data + * @size: size of buffer + * + * Return: 0 + */ +static int meson_rng_read(struct udevice *dev, void *data, size_t len) +{ + struct meson_rng_platdata *pdata = dev_get_platdata(dev); + char *buffer = (char *)data; + + while (len) { + u32 rand = readl(pdata->base); + size_t step; + + if (len >= 4) + step = 4; + else + step = len; + memcpy(buffer, &rand, step); + buffer += step; + len -= step; + } + return 0; +} + +/** + * meson_rng_probe() - probe rng device + * + * @dev: device + * Return: 0 if ok + */ +static int meson_rng_probe(struct udevice *dev) +{ + struct meson_rng_platdata *pdata = dev_get_platdata(dev); + int err; + + err = clk_enable(&pdata->clk); + if (err) + return err; + + return 0; +} + +/** + * meson_rng_remove() - deinitialize rng device + * + * @dev: device + * Return: 0 if ok + */ +static int meson_rng_remove(struct udevice *dev) +{ + struct meson_rng_platdata *pdata = dev_get_platdata(dev); + + return clk_disable(&pdata->clk); +} + +/** + * meson_rng_ofdata_to_platdata() - transfer device tree data to plaform data + * + * @dev: device + * Return: 0 if ok + */ +static int meson_rng_ofdata_to_platdata(struct udevice *dev) +{ + struct meson_rng_platdata *pdata = dev_get_platdata(dev); + int err; + + pdata->base = dev_read_addr(dev); + if (!pdata->base) + return -ENODEV; + + err = clk_get_by_name(dev, "core", &pdata->clk); + if (err) + return err; + + return 0; +} + +static const struct dm_rng_ops meson_rng_ops = { + .read = meson_rng_read, +}; + +static const struct udevice_id meson_rng_match[] = { + { + .compatible = "amlogic,meson-rng", + }, + {}, +}; + +U_BOOT_DRIVER(meson_rng) = { + .name = "meson-rng", + .id = UCLASS_RNG, + .of_match = meson_rng_match, + .ops = &meson_rng_ops, + .probe = meson_rng_probe, + .remove = meson_rng_remove, + .platdata_auto_alloc_size = sizeof(struct meson_rng_platdata), + .ofdata_to_platdata = meson_rng_ofdata_to_platdata, +}; From ce5e3ea7995269a49a530284af25cc8cc44bb37d Mon Sep 17 00:00:00 2001 From: Angelo Durgehello Date: Sat, 29 Feb 2020 01:01:32 +0100 Subject: [PATCH 08/58] serial: mcfuart: fix uart port index Actually, using dev->seq value before probe to deduce the current serial port index leads to reading an invalid seq value (-1). So, getting dev->seq at probe time. Signed-off-by: Angelo Durgehello --- drivers/serial/mcfuart.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/serial/mcfuart.c b/drivers/serial/mcfuart.c index 066e5a18d8..b599064b48 100644 --- a/drivers/serial/mcfuart.c +++ b/drivers/serial/mcfuart.c @@ -85,6 +85,8 @@ static int coldfire_serial_probe(struct udevice *dev) { struct coldfire_serial_platdata *plat = dev->platdata; + plat->port = dev->seq; + return mcf_serial_init_common((uart_t *)plat->base, plat->port, plat->baudrate); } @@ -148,8 +150,6 @@ static int coldfire_ofdata_to_platdata(struct udevice *dev) return -ENODEV; plat->base = (uint32_t)addr_base; - - plat->port = dev->seq; plat->baudrate = gd->baudrate; return 0; From 1886024a0e17a37d86dce622e395e37262d7bc3a Mon Sep 17 00:00:00 2001 From: Angelo Durgehello Date: Sat, 29 Feb 2020 01:09:35 +0100 Subject: [PATCH 09/58] serial: mcfuart: renaming to a more appropriate name All drivers seems to align now to serial_xxx maning, so, aligning also this driver, to allow to be found easily. Signed-off-by: Angelo Durgehello --- drivers/serial/Makefile | 2 +- drivers/serial/{mcfuart.c => serial_mcf.c} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename drivers/serial/{mcfuart.c => serial_mcf.c} (100%) diff --git a/drivers/serial/Makefile b/drivers/serial/Makefile index e26b64494e..e4a92bbbb7 100644 --- a/drivers/serial/Makefile +++ b/drivers/serial/Makefile @@ -39,7 +39,7 @@ obj-$(CONFIG_COREBOOT_SERIAL) += serial_coreboot.o obj-$(CONFIG_CORTINA_UART) += serial_cortina.o obj-$(CONFIG_EFI_APP) += serial_efi.o obj-$(CONFIG_LPC32XX_HSUART) += lpc32xx_hsuart.o -obj-$(CONFIG_MCFUART) += mcfuart.o +obj-$(CONFIG_MCFUART) += serial_mcf.o obj-$(CONFIG_SYS_NS16550) += ns16550.o obj-$(CONFIG_S5P) += serial_s5p.o obj-$(CONFIG_MXC_UART) += serial_mxc.o diff --git a/drivers/serial/mcfuart.c b/drivers/serial/serial_mcf.c similarity index 100% rename from drivers/serial/mcfuart.c rename to drivers/serial/serial_mcf.c From dde1b75e9526d887a9aba9d4b30eb62ad2f22013 Mon Sep 17 00:00:00 2001 From: AKASHI Takahiro Date: Tue, 10 Mar 2020 09:20:43 +0900 Subject: [PATCH 10/58] Makefile: doesn't need check stack size when dtb is not built The commit 5fed97af20da ("Makefile: ensure DTB doesn't overflow into initial stack") adds an extra check for stack size in BSS if CONFIG_SYS_INIT_SP_BSS_OFFSET is enabled. This check, however, doesn't make sense under the configuration where control dtb won't be built in and it should be void in such cases. Signed-off-by: AKASHI Takahiro Fixes: 5fed97af20da ("Makefile: ensure DTB doesn't overflow into initial stack") Reviewed-by: Stephen Warren --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 07539ca596..fa687f13a5 100644 --- a/Makefile +++ b/Makefile @@ -903,7 +903,7 @@ ifneq ($(CONFIG_BUILD_TARGET),) ALL-y += $(CONFIG_BUILD_TARGET:"%"=%) endif -ifdef CONFIG_INIT_SP_RELATIVE +ifeq ($(CONFIG_INIT_SP_RELATIVE)$(CONFIG_OF_SEPARATE),yy) ALL-y += init_sp_bss_offset_check endif @@ -1208,7 +1208,7 @@ binary_size_check: u-boot-nodtb.bin FORCE fi \ fi -ifdef CONFIG_INIT_SP_RELATIVE +ifeq ($(CONFIG_INIT_SP_RELATIVE)$(CONFIG_OF_SEPARATE),yy) ifneq ($(CONFIG_SYS_MALLOC_F_LEN),) subtract_sys_malloc_f_len = space=$$(($${space} - $(CONFIG_SYS_MALLOC_F_LEN))) else From 4af2a33ee5b91223f993af9bb0de1a081090634b Mon Sep 17 00:00:00 2001 From: Alex Kiernan Date: Wed, 11 Mar 2020 08:46:29 +0000 Subject: [PATCH 11/58] cmd: gpio: Make `gpio input` return pin value again 4dbc107f4683 ("cmd: gpio: Correct do_gpio() return value") correctly changed the behaviour of the gpio command to return CMD_RET_SUCCESS or CMD_RET_FAILURE, but any existing script which expects the return value to be the pin value is broken by this change. Reinstate the legacy behaviour for `gpio input` only. Fixes: 4dbc107f4683 ("cmd: gpio: Correct do_gpio() return value") Signed-off-by: Alex Kiernan Signed-off-by: Alex Kiernan Reviewed-by: Simon Glass --- cmd/gpio.c | 7 ++++++- test/py/tests/test_gpio.py | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 test/py/tests/test_gpio.py diff --git a/cmd/gpio.c b/cmd/gpio.c index 16c2cebb3d..408a942455 100644 --- a/cmd/gpio.c +++ b/cmd/gpio.c @@ -248,7 +248,12 @@ static int do_gpio(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) if (ret != -EBUSY) gpio_free(gpio); - return CMD_RET_SUCCESS; + /* + * Whilst wrong, the legacy gpio input command returns the pin + * value, or CMD_RET_FAILURE (which is indistinguishable from a + * valid pin value). + */ + return (sub_cmd == GPIOC_INPUT) ? value : CMD_RET_SUCCESS; err: if (ret != -EBUSY) diff --git a/test/py/tests/test_gpio.py b/test/py/tests/test_gpio.py new file mode 100644 index 0000000000..8c64f686b0 --- /dev/null +++ b/test/py/tests/test_gpio.py @@ -0,0 +1,37 @@ +# SPDX-License-Identifier: GPL-2.0+ + +import pytest + +@pytest.mark.boardspec('sandbox') +@pytest.mark.buildconfigspec('cmd_gpio') +def test_gpio_input(u_boot_console): + """Test that gpio input correctly returns the value of a gpio pin.""" + + response = u_boot_console.run_command('gpio input 0; echo rc:$?') + expected_response = 'rc:0' + assert(expected_response in response) + response = u_boot_console.run_command('gpio toggle 0; gpio input 0; echo rc:$?') + expected_response = 'rc:1' + assert(expected_response in response) + +@pytest.mark.boardspec('sandbox') +@pytest.mark.buildconfigspec('cmd_gpio') +def test_gpio_exit_statuses(u_boot_console): + """Test that non-input gpio commands correctly return the command + success/failure status.""" + + expected_response = 'rc:0' + response = u_boot_console.run_command('gpio clear 0; echo rc:$?') + assert(expected_response in response) + response = u_boot_console.run_command('gpio set 0; echo rc:$?') + assert(expected_response in response) + response = u_boot_console.run_command('gpio toggle 0; echo rc:$?') + assert(expected_response in response) + response = u_boot_console.run_command('gpio status -a; echo rc:$?') + assert(expected_response in response) + + expected_response = 'rc:1' + response = u_boot_console.run_command('gpio nonexistent-command; echo rc:$?') + assert(expected_response in response) + response = u_boot_console.run_command('gpio input 200; echo rc:$?') + assert(expected_response in response) From 92a19be25889f1e1689146fedda562f39053bd56 Mon Sep 17 00:00:00 2001 From: Michal Simek Date: Wed, 11 Mar 2020 12:26:53 +0100 Subject: [PATCH 12/58] watchdog: Align Kconfig properties Just cleanup help indentation to be the same for all options. It means indentation. OMAP3 should be indented by tabs which is also fixed. Signed-off-by: Michal Simek --- drivers/watchdog/Kconfig | 56 ++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index d24c1e4835..cb4da2e3cf 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig @@ -24,15 +24,15 @@ config HW_WATCHDOG config WATCHDOG_RESET_DISABLE bool "Disable reset watchdog" help - Disable reset watchdog, which can let WATCHDOG_RESET invalid, so - that the watchdog will not be fed in u-boot. + Disable reset watchdog, which can let WATCHDOG_RESET invalid, so + that the watchdog will not be fed in u-boot. config IMX_WATCHDOG bool "Enable Watchdog Timer support for IMX and LSCH2 of NXP" select HW_WATCHDOG if !WDT help - Select this to enable the IMX and LSCH2 of Layerscape watchdog - driver. + Select this to enable the IMX and LSCH2 of Layerscape watchdog + driver. config OMAP_WATCHDOG bool "TI OMAP watchdog driver" @@ -50,8 +50,8 @@ config DESIGNWARE_WATCHDOG bool "Designware watchdog timer support" select HW_WATCHDOG if !WDT help - Enable this to support Designware Watchdog Timer IP, present e.g. - on Altera SoCFPGA SoCs. + Enable this to support Designware Watchdog Timer IP, present e.g. + on Altera SoCFPGA SoCs. config WDT bool "Enable driver model for watchdog timer drivers" @@ -68,10 +68,10 @@ config WDT_ARMADA_37XX bool "Marvell Armada 37xx watchdog timer support" depends on WDT && ARMADA_3700 help - Enable this to support Watchdog Timer on Marvell Armada 37xx SoC. - There are 4 possible clocks which can be used on these SoCs. This - driver uses the second clock (ID 1), assuming that so will also - Linux's driver. + Enable this to support Watchdog Timer on Marvell Armada 37xx SoC. + There are 4 possible clocks which can be used on these SoCs. This + driver uses the second clock (ID 1), assuming that so will also + Linux's driver. config WDT_ASPEED bool "Aspeed ast2400/ast2500 watchdog timer support" @@ -88,8 +88,8 @@ config WDT_AT91 bool "AT91 watchdog timer support" depends on WDT help - Select this to enable Microchip watchdog timer, which can be found on - some AT91 devices. + Select this to enable Microchip watchdog timer, which can be found on + some AT91 devices. config WDT_BCM6345 bool "BCM6345 watchdog timer support" @@ -105,8 +105,8 @@ config WDT_CDNS depends on WDT imply WATCHDOG help - Select this to enable Cadence watchdog timer, which can be found on some - Xilinx Microzed Platform. + Select this to enable Cadence watchdog timer, which can be found on some + Xilinx Microzed Platform. config WDT_CORTINA bool "Cortina Access CAxxxx watchdog timer support" @@ -114,21 +114,21 @@ config WDT_CORTINA help Cortina Access CAxxxx watchdog timer support. This driver support all CPU ISAs supported by Cortina - Access CAxxxx SoCs. + Access CAxxxx SoCs. config WDT_MPC8xx bool "MPC8xx watchdog timer support" depends on WDT && MPC8xx select HW_WATCHDOG help - Select this to enable mpc8xx watchdog timer + Select this to enable mpc8xx watchdog timer config WDT_MT7621 bool "MediaTek MT7621 watchdog timer support" depends on WDT && SOC_MT7628 help - Select this to enable Ralink / Mediatek watchdog timer, - which can be found on some MediaTek chips. + Select this to enable Ralink / Mediatek watchdog timer, + which can be found on some MediaTek chips. config WDT_MTK bool "MediaTek watchdog timer support" @@ -139,10 +139,10 @@ config WDT_MTK It performs full SoC reset. config WDT_OMAP3 - bool "TI OMAP watchdog timer support" - depends on WDT && ARCH_OMAP2PLUS - default y if AM33XX - help + bool "TI OMAP watchdog timer support" + depends on WDT && ARCH_OMAP2PLUS + default y if AM33XX + help This enables OMAP3+ watchdog timer driver, which can be found on some TI chipsets and inline with driver model. @@ -151,8 +151,8 @@ config WDT_ORION depends on WDT select CLK help - Select this to enable Orion watchdog timer, which can be found on some - Marvell Armada chips. + Select this to enable Orion watchdog timer, which can be found on some + Marvell Armada chips. config WDT_SANDBOX bool "Enable Watchdog Timer support for Sandbox" @@ -166,8 +166,8 @@ config WDT_SP805 bool "SP805 watchdog timer support" depends on WDT help - Select this to enable SP805 watchdog timer, which can be found on some - nxp layerscape chips. + Select this to enable SP805 watchdog timer, which can be found on some + nxp layerscape chips. config WDT_STM32MP bool "IWDG watchdog driver for STM32 MP's family" @@ -182,8 +182,8 @@ config XILINX_TB_WATCHDOG depends on WDT imply WATCHDOG help - Select this to enable Xilinx Axi watchdog timer, which can be found on some - Xilinx Microblaze Platforms. + Select this to enable Xilinx Axi watchdog timer, which can be found on some + Xilinx Microblaze Platforms. config WDT_TANGIER bool "Intel Tangier watchdog timer support" From 183780491f9b45da6bec9627304b2c26169e8801 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Wed, 11 Mar 2020 21:51:08 +0100 Subject: [PATCH 13/58] fit: check return value of fit_image_get_data_size() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GCC-10 reports: In file included from tools/common/image-fit.c:1: include/image.h: In function ‘fit_image_get_data_and_size’: ./tools/../common/image-fit.c:1015:9: warning: ‘len’ may be used uninitialized in this function [-Wmaybe-uninitialized] 1015 | *size = len; | ~~~~~~^~~~~ ./tools/../common/image-fit.c:996:6: note: ‘len’ was declared here 996 | int len; | ^~~ Add the missing check of the return value of fit_image_get_data_size(). Fixes: c3c863880479 ("add FIT data-position & data-offset property support") Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Goldschmidt --- common/image-fit.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/common/image-fit.c b/common/image-fit.c index f3bb00c98a..4435bc4f1d 100644 --- a/common/image-fit.c +++ b/common/image-fit.c @@ -1011,8 +1011,10 @@ int fit_image_get_data_and_size(const void *fit, int noffset, if (external_data) { debug("External Data\n"); ret = fit_image_get_data_size(fit, noffset, &len); - *data = fit + offset; - *size = len; + if (!ret) { + *data = fit + offset; + *size = len; + } } else { ret = fit_image_get_data(fit, noffset, data, size); } From d21ffa2a2ebc366b8ca644324d76bb2924947373 Mon Sep 17 00:00:00 2001 From: Patrice Chotard Date: Thu, 12 Mar 2020 11:11:18 +0100 Subject: [PATCH 14/58] MAINTAINERS: update entry for ARM STI Add STi drivers/include files and git tree. Signed-off-by: Patrice Chotard --- MAINTAINERS | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 2c43573ff5..92dda40a85 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -329,8 +329,21 @@ F: drivers/usb/host/ehci-msm.c ARM STI M: Patrice Chotard S: Maintained +T: git https://gitlab.denx.de/u-boot/custodians/u-boot-stm.git F: arch/arm/mach-sti/ F: arch/arm/include/asm/arch-sti*/ +F: drivers/phy/sti_usb_phy.c +F: drivers/pinctrl/pinctrl-sti.c +F: drivers/mmc/sti_sdhci.c +F: drivers/reset/sti-reset.c +F: drivers/serial/serial_sti_asc.c +F: drivers/sysreset/sysreset_sti.c +F: drivers/timer/sti-timer.c +F: drivers/usb/host/dwc3-sti-glue.c +F: include/dwc3-sti-glue.h +F: include/dt-bindings/clock/stih407-clks.h +F: include/dt-bindings/clock/stih410-clks.h +F: include/dt-bindings/reset/stih407-resets.h ARM STM SPEAR #M: Vipin Kumar From ed666fb12910f46cff73a3869058ea59aef4261b Mon Sep 17 00:00:00 2001 From: Walter Lozano Date: Thu, 23 Jan 2020 16:05:05 -0300 Subject: [PATCH 15/58] watchdog: Use dev_read only if OF_PLATDATA is not enabled Currently watchdog tries to use dev_read_u32_default to get timeout configuration in case OF_CONTROL is enabled. However, if SPL is built with OF_PLATDATA this has no sense as there is no device tree. This patch fixes this issue by only use dev_read_u32_default if OF_CONTROL is enabled but OF_PLATDATA is not. Signed-off-by: Walter Lozano Reviewed-by: Simon Glass --- include/wdt.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/wdt.h b/include/wdt.h index 5bcff24ab3..dd83dfdd32 100644 --- a/include/wdt.h +++ b/include/wdt.h @@ -130,11 +130,10 @@ static inline int initr_watchdog(void) } } - if (CONFIG_IS_ENABLED(OF_CONTROL)) { + if (CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)) { timeout = dev_read_u32_default(gd->watchdog_dev, "timeout-sec", WATCHDOG_TIMEOUT_SECS); } - wdt_start(gd->watchdog_dev, timeout * 1000, 0); gd->flags |= GD_FLG_WDT_READY; printf("WDT: Started with%s servicing (%ds timeout)\n", From 6d8eae9ab7d17ca3ce84c5e6e29bd452936ad407 Mon Sep 17 00:00:00 2001 From: Chris Packham Date: Mon, 24 Feb 2020 13:20:33 +1300 Subject: [PATCH 16/58] watchdog: Handle timer wrap around On some platforms/architectures the value from get_timer() can wrap. This is particularly problematic when long-running code needs to measure a time difference as is the case with watchdog_reset() which tries to avoid tickling the watchdog too frequently. Use time_after() from time.h instead of a plain > comparison to avoid any issues with the time wrapping on a system that has been sitting in u-boot for a long time. Signed-off-by: Chris Packham Reviewed-by: Stefan Roese --- drivers/watchdog/wdt-uclass.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/watchdog/wdt-uclass.c b/drivers/watchdog/wdt-uclass.c index cf1c527473..d9e4dc7cb8 100644 --- a/drivers/watchdog/wdt-uclass.c +++ b/drivers/watchdog/wdt-uclass.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -83,7 +84,7 @@ void watchdog_reset(void) /* Do not reset the watchdog too often */ now = get_timer(0); - if (now > next_reset) { + if (time_after(now, next_reset)) { next_reset = now + 1000; /* reset every 1000ms */ wdt_reset(gd->watchdog_dev); } From fe13692e23b3786d4de060a98c65c922385d6c70 Mon Sep 17 00:00:00 2001 From: Bin Meng Date: Fri, 6 Mar 2020 00:44:16 -0800 Subject: [PATCH 17/58] riscv: Fix sbi_remote_sfence_vma{,_asid} Currently sbi_remote_sfence_vma{,_asid} does not pass their arguments to SBI at all, which is semantically incorrect. This keeps in sync with Linux kernel commit: a21344dfc6ad: fix sbi_remote_sfence_vma{,_asid} Signed-off-by: Bin Meng Reviewed-by: Lukas Auer --- arch/riscv/include/asm/sbi.h | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h index ced57defdd..d5081f90e6 100644 --- a/arch/riscv/include/asm/sbi.h +++ b/arch/riscv/include/asm/sbi.h @@ -20,22 +20,27 @@ #define SBI_REMOTE_SFENCE_VMA_ASID 7 #define SBI_SHUTDOWN 8 -#define SBI_CALL(which, arg0, arg1, arg2) ({ \ +#define SBI_CALL(which, arg0, arg1, arg2, arg3) ({ \ register uintptr_t a0 asm ("a0") = (uintptr_t)(arg0); \ register uintptr_t a1 asm ("a1") = (uintptr_t)(arg1); \ register uintptr_t a2 asm ("a2") = (uintptr_t)(arg2); \ + register uintptr_t a3 asm ("a3") = (uintptr_t)(arg3); \ register uintptr_t a7 asm ("a7") = (uintptr_t)(which); \ asm volatile ("ecall" \ : "+r" (a0) \ - : "r" (a1), "r" (a2), "r" (a7) \ + : "r" (a1), "r" (a2), "r" (a3), "r" (a7) \ : "memory"); \ a0; \ }) /* Lazy implementations until SBI is finalized */ -#define SBI_CALL_0(which) SBI_CALL(which, 0, 0, 0) -#define SBI_CALL_1(which, arg0) SBI_CALL(which, arg0, 0, 0) -#define SBI_CALL_2(which, arg0, arg1) SBI_CALL(which, arg0, arg1, 0) +#define SBI_CALL_0(which) SBI_CALL(which, 0, 0, 0, 0) +#define SBI_CALL_1(which, arg0) SBI_CALL(which, arg0, 0, 0, 0) +#define SBI_CALL_2(which, arg0, arg1) SBI_CALL(which, arg0, arg1, 0, 0) +#define SBI_CALL_3(which, arg0, arg1, arg2) \ + SBI_CALL(which, arg0, arg1, arg2, 0) +#define SBI_CALL_4(which, arg0, arg1, arg2, arg3) \ + SBI_CALL(which, arg0, arg1, arg2, arg3) static inline void sbi_console_putchar(int ch) { @@ -80,7 +85,7 @@ static inline void sbi_remote_sfence_vma(const unsigned long *hart_mask, unsigned long start, unsigned long size) { - SBI_CALL_1(SBI_REMOTE_SFENCE_VMA, hart_mask); + SBI_CALL_3(SBI_REMOTE_SFENCE_VMA, hart_mask, start, size); } static inline void sbi_remote_sfence_vma_asid(const unsigned long *hart_mask, @@ -88,7 +93,7 @@ static inline void sbi_remote_sfence_vma_asid(const unsigned long *hart_mask, unsigned long size, unsigned long asid) { - SBI_CALL_1(SBI_REMOTE_SFENCE_VMA_ASID, hart_mask); + SBI_CALL_4(SBI_REMOTE_SFENCE_VMA_ASID, hart_mask, start, size, asid); } #endif From f295e00c61100960182b3bbcf5d823bd51487420 Mon Sep 17 00:00:00 2001 From: Bin Meng Date: Fri, 6 Mar 2020 00:44:17 -0800 Subject: [PATCH 18/58] riscv: Avoid calling sbi_clear_ipi() There is no need for S-mode U-Boot to call sbi_clear_ipi() as it can be cleared directly from S-mode. This saves some cycles. Signed-off-by: Bin Meng Reviewed-by: Lukas Auer --- arch/riscv/lib/sbi_ipi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/riscv/lib/sbi_ipi.c b/arch/riscv/lib/sbi_ipi.c index 9a698ce74e..abafca9e5c 100644 --- a/arch/riscv/lib/sbi_ipi.c +++ b/arch/riscv/lib/sbi_ipi.c @@ -5,6 +5,7 @@ */ #include +#include #include int riscv_send_ipi(int hart) @@ -19,7 +20,7 @@ int riscv_send_ipi(int hart) int riscv_clear_ipi(int hart) { - sbi_clear_ipi(); + csr_clear(CSR_SIP, SIP_SSIP); return 0; } From 215c3a7701913a12ba6727efb83be80ad8ed659b Mon Sep 17 00:00:00 2001 From: Bin Meng Date: Mon, 9 Mar 2020 19:35:27 -0700 Subject: [PATCH 19/58] riscv: Mark existing SBI as v0.1 SBI As per the new SBI specification, current SBI implementation version is defined as 0.1 and will be removed/replaced in future. Each of the function call in 0.1 is defined as a separate extension which makes easier to replace them one at a time. Rename existing implementation to reflect that. This patch is just a preparatory patch for SBI v0.2 and doesn't introduce any functional changes. This commit is inspired from Linux kernel patch: https://patchwork.kernel.org/patch/11407355/ Signed-off-by: Bin Meng Reviewed-by: Pragnesh Patel --- arch/riscv/include/asm/sbi.h | 40 +++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h index d5081f90e6..187ca58dc0 100644 --- a/arch/riscv/include/asm/sbi.h +++ b/arch/riscv/include/asm/sbi.h @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0 */ /* * Copyright (C) 2015 Regents of the University of California + * Copyright (c) 2020 Western Digital Corporation or its affiliates. * * Taken from Linux arch/riscv/include/asm/sbi.h */ @@ -10,15 +11,15 @@ #include -#define SBI_SET_TIMER 0 -#define SBI_CONSOLE_PUTCHAR 1 -#define SBI_CONSOLE_GETCHAR 2 -#define SBI_CLEAR_IPI 3 -#define SBI_SEND_IPI 4 -#define SBI_REMOTE_FENCE_I 5 -#define SBI_REMOTE_SFENCE_VMA 6 -#define SBI_REMOTE_SFENCE_VMA_ASID 7 -#define SBI_SHUTDOWN 8 +#define SBI_EXT_0_1_SET_TIMER 0x0 +#define SBI_EXT_0_1_CONSOLE_PUTCHAR 0x1 +#define SBI_EXT_0_1_CONSOLE_GETCHAR 0x2 +#define SBI_EXT_0_1_CLEAR_IPI 0x3 +#define SBI_EXT_0_1_SEND_IPI 0x4 +#define SBI_EXT_0_1_REMOTE_FENCE_I 0x5 +#define SBI_EXT_0_1_REMOTE_SFENCE_VMA 0x6 +#define SBI_EXT_0_1_REMOTE_SFENCE_VMA_ASID 0x7 +#define SBI_EXT_0_1_SHUTDOWN 0x8 #define SBI_CALL(which, arg0, arg1, arg2, arg3) ({ \ register uintptr_t a0 asm ("a0") = (uintptr_t)(arg0); \ @@ -44,48 +45,48 @@ static inline void sbi_console_putchar(int ch) { - SBI_CALL_1(SBI_CONSOLE_PUTCHAR, ch); + SBI_CALL_1(SBI_EXT_0_1_CONSOLE_PUTCHAR, ch); } static inline int sbi_console_getchar(void) { - return SBI_CALL_0(SBI_CONSOLE_GETCHAR); + return SBI_CALL_0(SBI_EXT_0_1_CONSOLE_GETCHAR); } static inline void sbi_set_timer(uint64_t stime_value) { #if __riscv_xlen == 32 - SBI_CALL_2(SBI_SET_TIMER, stime_value, stime_value >> 32); + SBI_CALL_2(SBI_EXT_0_1_SET_TIMER, stime_value, stime_value >> 32); #else - SBI_CALL_1(SBI_SET_TIMER, stime_value); + SBI_CALL_1(SBI_EXT_0_1_SET_TIMER, stime_value); #endif } static inline void sbi_shutdown(void) { - SBI_CALL_0(SBI_SHUTDOWN); + SBI_CALL_0(SBI_EXT_0_1_SHUTDOWN); } static inline void sbi_clear_ipi(void) { - SBI_CALL_0(SBI_CLEAR_IPI); + SBI_CALL_0(SBI_EXT_0_1_CLEAR_IPI); } static inline void sbi_send_ipi(const unsigned long *hart_mask) { - SBI_CALL_1(SBI_SEND_IPI, hart_mask); + SBI_CALL_1(SBI_EXT_0_1_SEND_IPI, hart_mask); } static inline void sbi_remote_fence_i(const unsigned long *hart_mask) { - SBI_CALL_1(SBI_REMOTE_FENCE_I, hart_mask); + SBI_CALL_1(SBI_EXT_0_1_REMOTE_FENCE_I, hart_mask); } static inline void sbi_remote_sfence_vma(const unsigned long *hart_mask, unsigned long start, unsigned long size) { - SBI_CALL_3(SBI_REMOTE_SFENCE_VMA, hart_mask, start, size); + SBI_CALL_3(SBI_EXT_0_1_REMOTE_SFENCE_VMA, hart_mask, start, size); } static inline void sbi_remote_sfence_vma_asid(const unsigned long *hart_mask, @@ -93,7 +94,8 @@ static inline void sbi_remote_sfence_vma_asid(const unsigned long *hart_mask, unsigned long size, unsigned long asid) { - SBI_CALL_4(SBI_REMOTE_SFENCE_VMA_ASID, hart_mask, start, size, asid); + SBI_CALL_4(SBI_EXT_0_1_REMOTE_SFENCE_VMA_ASID, hart_mask, + start, size, asid); } #endif From f58fc34a2b215a80adcf62c6e90793e23d6f915c Mon Sep 17 00:00:00 2001 From: Bin Meng Date: Mon, 9 Mar 2020 19:35:28 -0700 Subject: [PATCH 20/58] riscv: Add basic support for SBI v0.2 The SBI v0.2 introduces a base extension which is backward compatible with v0.1. Implement all helper functions and minimum required SBI calls from v0.2 for now. All other base extension function will be added later as per need. As v0.2 calling convention is backward compatible with v0.1, remove the v0.1 helper functions and just use v0.2 calling convention. Add a new Kconfig options CONFIG_SBI for the new SBI v0.2 codes, and let CONFIG_SBI_IPI depend on it. This commit is inspired from Linux kernel patch: https://patchwork.kernel.org/patch/11407363/ Signed-off-by: Bin Meng Reviewed-by: Pragnesh Patel --- arch/riscv/Kconfig | 5 + arch/riscv/include/asm/sbi.h | 135 +++++++++++--------------- arch/riscv/lib/Makefile | 1 + arch/riscv/lib/sbi.c | 181 +++++++++++++++++++++++++++++++++++ 4 files changed, 243 insertions(+), 79 deletions(-) create mode 100644 arch/riscv/lib/sbi.c diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 3338b788f8..09fff05f99 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -210,8 +210,13 @@ config NR_CPUS Stack memory is pre-allocated. U-Boot must therefore know the maximum number of CPUs that may be present. +config SBI + bool + default y if RISCV_SMODE || SPL_RISCV_SMODE + config SBI_IPI bool + depends on SBI default y if RISCV_SMODE || SPL_RISCV_SMODE depends on SMP diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h index 187ca58dc0..fc8637cb3c 100644 --- a/arch/riscv/include/asm/sbi.h +++ b/arch/riscv/include/asm/sbi.h @@ -11,91 +11,68 @@ #include -#define SBI_EXT_0_1_SET_TIMER 0x0 -#define SBI_EXT_0_1_CONSOLE_PUTCHAR 0x1 -#define SBI_EXT_0_1_CONSOLE_GETCHAR 0x2 -#define SBI_EXT_0_1_CLEAR_IPI 0x3 -#define SBI_EXT_0_1_SEND_IPI 0x4 -#define SBI_EXT_0_1_REMOTE_FENCE_I 0x5 -#define SBI_EXT_0_1_REMOTE_SFENCE_VMA 0x6 -#define SBI_EXT_0_1_REMOTE_SFENCE_VMA_ASID 0x7 -#define SBI_EXT_0_1_SHUTDOWN 0x8 +enum sbi_ext_id { + SBI_EXT_0_1_SET_TIMER = 0x0, + SBI_EXT_0_1_CONSOLE_PUTCHAR = 0x1, + SBI_EXT_0_1_CONSOLE_GETCHAR = 0x2, + SBI_EXT_0_1_CLEAR_IPI = 0x3, + SBI_EXT_0_1_SEND_IPI = 0x4, + SBI_EXT_0_1_REMOTE_FENCE_I = 0x5, + SBI_EXT_0_1_REMOTE_SFENCE_VMA = 0x6, + SBI_EXT_0_1_REMOTE_SFENCE_VMA_ASID = 0x7, + SBI_EXT_0_1_SHUTDOWN = 0x8, + SBI_EXT_BASE = 0x10, +}; -#define SBI_CALL(which, arg0, arg1, arg2, arg3) ({ \ - register uintptr_t a0 asm ("a0") = (uintptr_t)(arg0); \ - register uintptr_t a1 asm ("a1") = (uintptr_t)(arg1); \ - register uintptr_t a2 asm ("a2") = (uintptr_t)(arg2); \ - register uintptr_t a3 asm ("a3") = (uintptr_t)(arg3); \ - register uintptr_t a7 asm ("a7") = (uintptr_t)(which); \ - asm volatile ("ecall" \ - : "+r" (a0) \ - : "r" (a1), "r" (a2), "r" (a3), "r" (a7) \ - : "memory"); \ - a0; \ -}) +enum sbi_ext_base_fid { + SBI_EXT_BASE_GET_SPEC_VERSION = 0, + SBI_EXT_BASE_GET_IMP_ID, + SBI_EXT_BASE_GET_IMP_VERSION, + SBI_EXT_BASE_PROBE_EXT, + SBI_EXT_BASE_GET_MVENDORID, + SBI_EXT_BASE_GET_MARCHID, + SBI_EXT_BASE_GET_MIMPID, +}; -/* Lazy implementations until SBI is finalized */ -#define SBI_CALL_0(which) SBI_CALL(which, 0, 0, 0, 0) -#define SBI_CALL_1(which, arg0) SBI_CALL(which, arg0, 0, 0, 0) -#define SBI_CALL_2(which, arg0, arg1) SBI_CALL(which, arg0, arg1, 0, 0) -#define SBI_CALL_3(which, arg0, arg1, arg2) \ - SBI_CALL(which, arg0, arg1, arg2, 0) -#define SBI_CALL_4(which, arg0, arg1, arg2, arg3) \ - SBI_CALL(which, arg0, arg1, arg2, arg3) +#define SBI_SPEC_VERSION_DEFAULT 0x1 +#define SBI_SPEC_VERSION_MAJOR_SHIFT 24 +#define SBI_SPEC_VERSION_MAJOR_MASK 0x7f +#define SBI_SPEC_VERSION_MINOR_MASK 0xffffff -static inline void sbi_console_putchar(int ch) -{ - SBI_CALL_1(SBI_EXT_0_1_CONSOLE_PUTCHAR, ch); -} +/* SBI return error codes */ +#define SBI_SUCCESS 0 +#define SBI_ERR_FAILURE -1 +#define SBI_ERR_NOT_SUPPORTED -2 +#define SBI_ERR_INVALID_PARAM -3 +#define SBI_ERR_DENIED -4 +#define SBI_ERR_INVALID_ADDRESS -5 -static inline int sbi_console_getchar(void) -{ - return SBI_CALL_0(SBI_EXT_0_1_CONSOLE_GETCHAR); -} +extern unsigned long sbi_spec_version; +struct sbiret { + long error; + long value; +}; -static inline void sbi_set_timer(uint64_t stime_value) -{ -#if __riscv_xlen == 32 - SBI_CALL_2(SBI_EXT_0_1_SET_TIMER, stime_value, stime_value >> 32); -#else - SBI_CALL_1(SBI_EXT_0_1_SET_TIMER, stime_value); -#endif -} +struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0, + unsigned long arg1, unsigned long arg2, + unsigned long arg3, unsigned long arg4, + unsigned long arg5); -static inline void sbi_shutdown(void) -{ - SBI_CALL_0(SBI_EXT_0_1_SHUTDOWN); -} +void sbi_console_putchar(int ch); +int sbi_console_getchar(void); +void sbi_clear_ipi(void); +void sbi_shutdown(void); +void sbi_set_timer(uint64_t stime_value); +void sbi_send_ipi(const unsigned long *hart_mask); +void sbi_remote_fence_i(const unsigned long *hart_mask); +void sbi_remote_sfence_vma(const unsigned long *hart_mask, + unsigned long start, + unsigned long size); +void sbi_remote_sfence_vma_asid(const unsigned long *hart_mask, + unsigned long start, + unsigned long size, + unsigned long asid); -static inline void sbi_clear_ipi(void) -{ - SBI_CALL_0(SBI_EXT_0_1_CLEAR_IPI); -} - -static inline void sbi_send_ipi(const unsigned long *hart_mask) -{ - SBI_CALL_1(SBI_EXT_0_1_SEND_IPI, hart_mask); -} - -static inline void sbi_remote_fence_i(const unsigned long *hart_mask) -{ - SBI_CALL_1(SBI_EXT_0_1_REMOTE_FENCE_I, hart_mask); -} - -static inline void sbi_remote_sfence_vma(const unsigned long *hart_mask, - unsigned long start, - unsigned long size) -{ - SBI_CALL_3(SBI_EXT_0_1_REMOTE_SFENCE_VMA, hart_mask, start, size); -} - -static inline void sbi_remote_sfence_vma_asid(const unsigned long *hart_mask, - unsigned long start, - unsigned long size, - unsigned long asid) -{ - SBI_CALL_4(SBI_EXT_0_1_REMOTE_SFENCE_VMA_ASID, hart_mask, - start, size, asid); -} +int sbi_probe_extension(int ext); #endif diff --git a/arch/riscv/lib/Makefile b/arch/riscv/lib/Makefile index c9179a5ff8..adadbf4bcb 100644 --- a/arch/riscv/lib/Makefile +++ b/arch/riscv/lib/Makefile @@ -16,6 +16,7 @@ obj-$(CONFIG_ANDES_PLIC) += andes_plic.o obj-$(CONFIG_ANDES_PLMT) += andes_plmt.o else obj-$(CONFIG_RISCV_RDTIME) += rdtime.o +obj-$(CONFIG_SBI) += sbi.o obj-$(CONFIG_SBI_IPI) += sbi_ipi.o endif obj-y += interrupts.o diff --git a/arch/riscv/lib/sbi.c b/arch/riscv/lib/sbi.c new file mode 100644 index 0000000000..4b6a9e097e --- /dev/null +++ b/arch/riscv/lib/sbi.c @@ -0,0 +1,181 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * SBI initialilization and all extension implementation. + * + * Copyright (c) 2020 Western Digital Corporation or its affiliates. + * + * Taken from Linux arch/riscv/kernel/sbi.c + */ + +#include +#include +#include + +/* default SBI version is 0.1 */ +unsigned long sbi_spec_version = SBI_SPEC_VERSION_DEFAULT; + +struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0, + unsigned long arg1, unsigned long arg2, + unsigned long arg3, unsigned long arg4, + unsigned long arg5) +{ + struct sbiret ret; + + register uintptr_t a0 asm ("a0") = (uintptr_t)(arg0); + register uintptr_t a1 asm ("a1") = (uintptr_t)(arg1); + register uintptr_t a2 asm ("a2") = (uintptr_t)(arg2); + register uintptr_t a3 asm ("a3") = (uintptr_t)(arg3); + register uintptr_t a4 asm ("a4") = (uintptr_t)(arg4); + register uintptr_t a5 asm ("a5") = (uintptr_t)(arg5); + register uintptr_t a6 asm ("a6") = (uintptr_t)(fid); + register uintptr_t a7 asm ("a7") = (uintptr_t)(ext); + asm volatile ("ecall" + : "+r" (a0), "+r" (a1) + : "r" (a2), "r" (a3), "r" (a4), "r" (a5), "r" (a6), "r" (a7) + : "memory"); + ret.error = a0; + ret.value = a1; + + return ret; +} + +/** + * sbi_console_putchar() - Writes given character to the console device. + * @ch: The data to be written to the console. + * + * Return: None + */ +void sbi_console_putchar(int ch) +{ + sbi_ecall(SBI_EXT_0_1_CONSOLE_PUTCHAR, 0, ch, 0, 0, 0, 0, 0); +} + +/** + * sbi_console_getchar() - Reads a byte from console device. + * + * Returns the value read from console. + */ +int sbi_console_getchar(void) +{ + struct sbiret ret; + + ret = sbi_ecall(SBI_EXT_0_1_CONSOLE_GETCHAR, 0, 0, 0, 0, 0, 0, 0); + + return ret.error; +} + +/** + * sbi_clear_ipi() - Clear any pending IPIs for the calling hart. + * + * Return: None + */ +void sbi_clear_ipi(void) +{ + sbi_ecall(SBI_EXT_0_1_CLEAR_IPI, 0, 0, 0, 0, 0, 0, 0); +} + +/** + * sbi_shutdown() - Remove all the harts from executing supervisor code. + * + * Return: None + */ +void sbi_shutdown(void) +{ + sbi_ecall(SBI_EXT_0_1_SHUTDOWN, 0, 0, 0, 0, 0, 0, 0); +} + +/** + * sbi_set_timer() - Program the timer for next timer event. + * @stime_value: The value after which next timer event should fire. + * + * Return: None + */ +void sbi_set_timer(uint64_t stime_value) +{ +#if __riscv_xlen == 32 + sbi_ecall(SBI_EXT_0_1_SET_TIMER, 0, stime_value, + stime_value >> 32, 0, 0, 0, 0); +#else + sbi_ecall(SBI_EXT_0_1_SET_TIMER, 0, stime_value, 0, 0, 0, 0, 0); +#endif +} + +/** + * sbi_send_ipi() - Send an IPI to any hart. + * @hart_mask: A cpu mask containing all the target harts. + * + * Return: None + */ +void sbi_send_ipi(const unsigned long *hart_mask) +{ + sbi_ecall(SBI_EXT_0_1_SEND_IPI, 0, (unsigned long)hart_mask, + 0, 0, 0, 0, 0); +} + +/** + * sbi_remote_fence_i() - Execute FENCE.I instruction on given remote harts. + * @hart_mask: A cpu mask containing all the target harts. + * + * Return: None + */ +void sbi_remote_fence_i(const unsigned long *hart_mask) +{ + sbi_ecall(SBI_EXT_0_1_REMOTE_FENCE_I, 0, (unsigned long)hart_mask, + 0, 0, 0, 0, 0); +} + +/** + * sbi_remote_sfence_vma() - Execute SFENCE.VMA instructions on given remote + * harts for the specified virtual address range. + * @hart_mask: A cpu mask containing all the target harts. + * @start: Start of the virtual address + * @size: Total size of the virtual address range. + * + * Return: None + */ +void sbi_remote_sfence_vma(const unsigned long *hart_mask, + unsigned long start, + unsigned long size) +{ + sbi_ecall(SBI_EXT_0_1_REMOTE_SFENCE_VMA, 0, + (unsigned long)hart_mask, start, size, 0, 0, 0); +} + +/** + * sbi_remote_sfence_vma_asid() - Execute SFENCE.VMA instructions on given + * remote harts for a virtual address range belonging to a specific ASID. + * + * @hart_mask: A cpu mask containing all the target harts. + * @start: Start of the virtual address + * @size: Total size of the virtual address range. + * @asid: The value of address space identifier (ASID). + * + * Return: None + */ +void sbi_remote_sfence_vma_asid(const unsigned long *hart_mask, + unsigned long start, + unsigned long size, + unsigned long asid) +{ + sbi_ecall(SBI_EXT_0_1_REMOTE_SFENCE_VMA_ASID, 0, + (unsigned long)hart_mask, start, size, asid, 0, 0); +} + +/** + * sbi_probe_extension() - Check if an SBI extension ID is supported or not. + * @extid: The extension ID to be probed. + * + * Return: Extension specific nonzero value f yes, -ENOTSUPP otherwise. + */ +int sbi_probe_extension(int extid) +{ + struct sbiret ret; + + ret = sbi_ecall(SBI_EXT_BASE, SBI_EXT_BASE_PROBE_EXT, extid, + 0, 0, 0, 0, 0); + if (!ret.error) + if (ret.value) + return ret.value; + + return -ENOTSUPP; +} From 1e32715602d3da294eaf4e70542c4be65e77a839 Mon Sep 17 00:00:00 2001 From: Bin Meng Date: Mon, 9 Mar 2020 19:35:29 -0700 Subject: [PATCH 21/58] riscv: Add SBI v0.2 extension definitions Few v0.1 SBI calls are being replaced by new SBI calls that follows v0.2 calling convention. This patch just defines these new extensions. This commit is inspired from Linux kernel patch: https://patchwork.kernel.org/patch/11407359/ Signed-off-by: Bin Meng Reviewed-by: Pragnesh Patel --- arch/riscv/include/asm/sbi.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h index fc8637cb3c..6d3114c622 100644 --- a/arch/riscv/include/asm/sbi.h +++ b/arch/riscv/include/asm/sbi.h @@ -22,6 +22,9 @@ enum sbi_ext_id { SBI_EXT_0_1_REMOTE_SFENCE_VMA_ASID = 0x7, SBI_EXT_0_1_SHUTDOWN = 0x8, SBI_EXT_BASE = 0x10, + SBI_EXT_TIME = 0x54494D45, + SBI_EXT_IPI = 0x735049, + SBI_EXT_RFENCE = 0x52464E43, }; enum sbi_ext_base_fid { @@ -34,6 +37,20 @@ enum sbi_ext_base_fid { SBI_EXT_BASE_GET_MIMPID, }; +enum sbi_ext_time_fid { + SBI_EXT_TIME_SET_TIMER = 0, +}; + +enum sbi_ext_ipi_fid { + SBI_EXT_IPI_SEND_IPI = 0, +}; + +enum sbi_ext_rfence_fid { + SBI_EXT_RFENCE_REMOTE_FENCE_I = 0, + SBI_EXT_RFENCE_REMOTE_SFENCE_VMA, + SBI_EXT_RFENCE_REMOTE_SFENCE_VMA_ASID, +}; + #define SBI_SPEC_VERSION_DEFAULT 0x1 #define SBI_SPEC_VERSION_MAJOR_SHIFT 24 #define SBI_SPEC_VERSION_MAJOR_MASK 0x7f From 1b3c8d64020f835823aedc1c4d293e34a78bd1b8 Mon Sep 17 00:00:00 2001 From: Bin Meng Date: Mon, 9 Mar 2020 19:35:30 -0700 Subject: [PATCH 22/58] riscv: Introduce a new config for SBI v0.1 We now have SBI v0.2 which is more scalable and extendable to handle future needs for RISC-V supervisor interfaces. Introduce a new config and move all SBI v0.1 code under that config. This allows to implement the new replacement SBI extensions cleanly and remove v0.1 extensions easily in future. Currently, the config is enabled by default. Once all M-mode software, with v0.1, is no longer in use, this config option and all relevant code can be easily removed. This commit is inspired from Linux kernel patch: https://patchwork.kernel.org/patch/11407361/ Signed-off-by: Bin Meng Reviewed-by: Pragnesh Patel --- arch/riscv/Kconfig | 8 ++++++++ arch/riscv/include/asm/sbi.h | 4 ++++ arch/riscv/lib/sbi.c | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 09fff05f99..cc87da7e04 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -214,6 +214,14 @@ config SBI bool default y if RISCV_SMODE || SPL_RISCV_SMODE +config SBI_V01 + bool "SBI v0.1 support" + default y + depends on SBI + help + This config allows kernel to use SBI v0.1 APIs. This will be + deprecated in future once legacy M-mode software are no longer in use. + config SBI_IPI bool depends on SBI diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h index 6d3114c622..c65104f492 100644 --- a/arch/riscv/include/asm/sbi.h +++ b/arch/riscv/include/asm/sbi.h @@ -12,6 +12,7 @@ #include enum sbi_ext_id { +#ifdef CONFIG_SBI_V01 SBI_EXT_0_1_SET_TIMER = 0x0, SBI_EXT_0_1_CONSOLE_PUTCHAR = 0x1, SBI_EXT_0_1_CONSOLE_GETCHAR = 0x2, @@ -21,6 +22,7 @@ enum sbi_ext_id { SBI_EXT_0_1_REMOTE_SFENCE_VMA = 0x6, SBI_EXT_0_1_REMOTE_SFENCE_VMA_ASID = 0x7, SBI_EXT_0_1_SHUTDOWN = 0x8, +#endif SBI_EXT_BASE = 0x10, SBI_EXT_TIME = 0x54494D45, SBI_EXT_IPI = 0x735049, @@ -75,10 +77,12 @@ struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0, unsigned long arg3, unsigned long arg4, unsigned long arg5); +#ifdef CONFIG_SBI_V01 void sbi_console_putchar(int ch); int sbi_console_getchar(void); void sbi_clear_ipi(void); void sbi_shutdown(void); +#endif void sbi_set_timer(uint64_t stime_value); void sbi_send_ipi(const unsigned long *hart_mask); void sbi_remote_fence_i(const unsigned long *hart_mask); diff --git a/arch/riscv/lib/sbi.c b/arch/riscv/lib/sbi.c index 4b6a9e097e..604a3a84fe 100644 --- a/arch/riscv/lib/sbi.c +++ b/arch/riscv/lib/sbi.c @@ -39,6 +39,8 @@ struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0, return ret; } +#ifdef CONFIG_SBI_V01 + /** * sbi_console_putchar() - Writes given character to the console device. * @ch: The data to be written to the console. @@ -84,6 +86,8 @@ void sbi_shutdown(void) sbi_ecall(SBI_EXT_0_1_SHUTDOWN, 0, 0, 0, 0, 0, 0, 0); } +#endif /* CONFIG_SBI_V01 */ + /** * sbi_set_timer() - Program the timer for next timer event. * @stime_value: The value after which next timer event should fire. From 5bde2152d42515f7af46d210d7edf14e3b10d5f5 Mon Sep 17 00:00:00 2001 From: Bin Meng Date: Mon, 9 Mar 2020 19:35:31 -0700 Subject: [PATCH 23/58] riscv: Implement new SBI v0.2 extensions Few v0.1 SBI calls are being replaced by new SBI calls that follows v0.2 calling convention. Implement the replacement extensions and few additional new SBI function calls that makes way for a better SBI interface in future. Signed-off-by: Bin Meng Reviewed-by: Pragnesh Patel --- arch/riscv/include/asm/sbi.h | 24 ++++++++++++++++++++++++ arch/riscv/lib/sbi.c | 16 +++++++++------- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h index c65104f492..3595ee8bf7 100644 --- a/arch/riscv/include/asm/sbi.h +++ b/arch/riscv/include/asm/sbi.h @@ -53,6 +53,30 @@ enum sbi_ext_rfence_fid { SBI_EXT_RFENCE_REMOTE_SFENCE_VMA_ASID, }; +#ifdef CONFIG_SBI_V01 +#define SBI_EXT_SET_TIMER SBI_EXT_0_1_SET_TIMER +#define SBI_FID_SET_TIMER 0 +#define SBI_EXT_SEND_IPI SBI_EXT_0_1_SEND_IPI +#define SBI_FID_SEND_IPI 0 +#define SBI_EXT_REMOTE_FENCE_I SBI_EXT_0_1_REMOTE_FENCE_I +#define SBI_FID_REMOTE_FENCE_I 0 +#define SBI_EXT_REMOTE_SFENCE_VMA SBI_EXT_0_1_REMOTE_SFENCE_VMA +#define SBI_FID_REMOTE_SFENCE_VMA 0 +#define SBI_EXT_REMOTE_SFENCE_VMA_ASID SBI_EXT_0_1_REMOTE_SFENCE_VMA_ASID +#define SBI_FID_REMOTE_SFENCE_VMA_ASID 0 +#else +#define SBI_EXT_SET_TIMER SBI_EXT_TIME +#define SBI_FID_SET_TIMER SBI_EXT_TIME_SET_TIMER +#define SBI_EXT_SEND_IPI SBI_EXT_IPI +#define SBI_FID_SEND_IPI SBI_EXT_IPI_SEND_IPI +#define SBI_EXT_REMOTE_FENCE_I SBI_EXT_RFENCE +#define SBI_FID_REMOTE_FENCE_I SBI_EXT_RFENCE_REMOTE_FENCE_I +#define SBI_EXT_REMOTE_SFENCE_VMA SBI_EXT_RFENCE +#define SBI_FID_REMOTE_SFENCE_VMA SBI_EXT_RFENCE_REMOTE_SFENCE_VMA +#define SBI_EXT_REMOTE_SFENCE_VMA_ASID SBI_EXT_RFENCE +#define SBI_FID_REMOTE_SFENCE_VMA_ASID SBI_EXT_RFENCE_REMOTE_SFENCE_VMA_ASID +#endif + #define SBI_SPEC_VERSION_DEFAULT 0x1 #define SBI_SPEC_VERSION_MAJOR_SHIFT 24 #define SBI_SPEC_VERSION_MAJOR_MASK 0x7f diff --git a/arch/riscv/lib/sbi.c b/arch/riscv/lib/sbi.c index 604a3a84fe..7bdf071dbb 100644 --- a/arch/riscv/lib/sbi.c +++ b/arch/riscv/lib/sbi.c @@ -97,10 +97,11 @@ void sbi_shutdown(void) void sbi_set_timer(uint64_t stime_value) { #if __riscv_xlen == 32 - sbi_ecall(SBI_EXT_0_1_SET_TIMER, 0, stime_value, + sbi_ecall(SBI_EXT_SET_TIMER, SBI_FID_SET_TIMER, stime_value, stime_value >> 32, 0, 0, 0, 0); #else - sbi_ecall(SBI_EXT_0_1_SET_TIMER, 0, stime_value, 0, 0, 0, 0, 0); + sbi_ecall(SBI_EXT_SET_TIMER, SBI_FID_SET_TIMER, stime_value, + 0, 0, 0, 0, 0); #endif } @@ -112,7 +113,7 @@ void sbi_set_timer(uint64_t stime_value) */ void sbi_send_ipi(const unsigned long *hart_mask) { - sbi_ecall(SBI_EXT_0_1_SEND_IPI, 0, (unsigned long)hart_mask, + sbi_ecall(SBI_EXT_SEND_IPI, SBI_FID_SEND_IPI, (unsigned long)hart_mask, 0, 0, 0, 0, 0); } @@ -124,8 +125,8 @@ void sbi_send_ipi(const unsigned long *hart_mask) */ void sbi_remote_fence_i(const unsigned long *hart_mask) { - sbi_ecall(SBI_EXT_0_1_REMOTE_FENCE_I, 0, (unsigned long)hart_mask, - 0, 0, 0, 0, 0); + sbi_ecall(SBI_EXT_REMOTE_FENCE_I, SBI_FID_REMOTE_FENCE_I, + (unsigned long)hart_mask, 0, 0, 0, 0, 0); } /** @@ -141,7 +142,7 @@ void sbi_remote_sfence_vma(const unsigned long *hart_mask, unsigned long start, unsigned long size) { - sbi_ecall(SBI_EXT_0_1_REMOTE_SFENCE_VMA, 0, + sbi_ecall(SBI_EXT_REMOTE_SFENCE_VMA, SBI_FID_REMOTE_SFENCE_VMA, (unsigned long)hart_mask, start, size, 0, 0, 0); } @@ -161,7 +162,8 @@ void sbi_remote_sfence_vma_asid(const unsigned long *hart_mask, unsigned long size, unsigned long asid) { - sbi_ecall(SBI_EXT_0_1_REMOTE_SFENCE_VMA_ASID, 0, + sbi_ecall(SBI_EXT_REMOTE_SFENCE_VMA_ASID, + SBI_FID_REMOTE_SFENCE_VMA_ASID, (unsigned long)hart_mask, start, size, asid, 0, 0); } From fef907b2e4406da8addebd7fefb6fd87ca7875ab Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sat, 14 Mar 2020 10:59:34 +0100 Subject: [PATCH 24/58] efi_loader: create reservations after ft_board_setup Some memory reservations are made in ft_board_setup(). Ensure that we create reserved memory map entries after ft_board_setup(). The downside of this patch is that if bootefi is called multiple times with an devicetree argument superfluous reservations for the old copies of the device tree will exist. But that is still better than missing a reservation. Deleting the superfluous reservations is not possible because reservations in the memory map are rounded to page size and may be coallesced. Signed-off-by: Heinrich Schuchardt --- cmd/bootefi.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 24fc42ae89..522ed28d6a 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -263,9 +263,6 @@ efi_status_t efi_install_fdt(void *fdt) return EFI_LOAD_ERROR; } - /* Create memory reservations as indicated by the device tree */ - efi_carve_out_dt_rsv(fdt); - /* Prepare device tree for payload */ ret = copy_fdt(&fdt); if (ret) { @@ -278,6 +275,9 @@ efi_status_t efi_install_fdt(void *fdt) return EFI_LOAD_ERROR; } + /* Create memory reservations as indicated by the device tree */ + efi_carve_out_dt_rsv(fdt); + /* Install device tree as UEFI table */ ret = efi_install_configuration_table(&efi_guid_fdt, fdt); if (ret != EFI_SUCCESS) { From a415d61eac26a9108c26ef779f2009dc3062f5d8 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sat, 14 Mar 2020 08:44:07 +0100 Subject: [PATCH 25/58] cmd: map addresses to sysmem in efidebug memmap Addresses in the sandbox's device tree are in the sandbox's virtual address space. If we want to compare memory reservations in the device-tree with the output of 'efidebug memmap', we need to convert back to this address space. Adjust the output of the 'efidebug memmap' command. Signed-off-by: Heinrich Schuchardt --- cmd/efidebug.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cmd/efidebug.c b/cmd/efidebug.c index 8c3681c37d..bb7c13d6a1 100644 --- a/cmd/efidebug.c +++ b/cmd/efidebug.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -488,9 +489,10 @@ static int do_efi_show_memmap(cmd_tbl_t *cmdtp, int flag, printf("%-16s %.*llx-%.*llx", type, EFI_PHYS_ADDR_WIDTH, - map->physical_start, + (u64)map_to_sysmem((void *)map->physical_start), EFI_PHYS_ADDR_WIDTH, - map->physical_start + map->num_pages * EFI_PAGE_SIZE); + (u64)map_to_sysmem((void *)map->physical_start + + map->num_pages * EFI_PAGE_SIZE)); print_memory_attributes(map->attribute); putc('\n'); From 7be64b885a360d0b7e78a5f624698a67513be53f Mon Sep 17 00:00:00 2001 From: Atish Patra Date: Fri, 13 Mar 2020 17:11:30 -0700 Subject: [PATCH 26/58] cmd: bootefi: Parse reserved-memory node from DT Currently, bootefi only parses memory reservation block to setup EFI reserved memory mappings. However, it doesn't parse the reserved-memory[1] device tree node that also can contain the reserved memory regions. Add capability to parse reserved-memory node and update the EFI memory mappings accordingly. 1. /doc/device-tree-bindings/reserved-memory/reserved-memory.txt] Signed-off-by: Atish Patra Fix an endless loop. The /reserved-memory node may have children without reg property. Remove a superfluous debug statement. Signed-off-by: Heinrich Schuchardt --- cmd/bootefi.c | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 522ed28d6a..3bbe2d6a1a 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -149,6 +149,20 @@ done: return ret; } +static void efi_reserve_memory(u64 addr, u64 size) +{ + u64 pages; + + /* Convert from sandbox address space. */ + addr = (uintptr_t)map_sysmem(addr, 0); + pages = efi_size_in_pages(size + (addr & EFI_PAGE_MASK)); + addr &= ~EFI_PAGE_MASK; + if (efi_add_memory_map(addr, pages, EFI_RESERVED_MEMORY_TYPE, + false) != EFI_SUCCESS) + printf("Reserved memory mapping failed addr %llx size %llx\n", + addr, size); +} + /** * efi_carve_out_dt_rsv() - Carve out DT reserved memory ranges * @@ -161,7 +175,8 @@ done: static void efi_carve_out_dt_rsv(void *fdt) { int nr_rsv, i; - uint64_t addr, size, pages; + u64 addr, size; + int nodeoffset, subnode; nr_rsv = fdt_num_mem_rsv(fdt); @@ -169,15 +184,25 @@ static void efi_carve_out_dt_rsv(void *fdt) for (i = 0; i < nr_rsv; i++) { if (fdt_get_mem_rsv(fdt, i, &addr, &size) != 0) continue; + efi_reserve_memory(addr, size); + } - /* Convert from sandbox address space. */ - addr = (uintptr_t)map_sysmem(addr, 0); - - pages = efi_size_in_pages(size + (addr & EFI_PAGE_MASK)); - addr &= ~EFI_PAGE_MASK; - if (efi_add_memory_map(addr, pages, EFI_RESERVED_MEMORY_TYPE, - false) != EFI_SUCCESS) - printf("FDT memrsv map %d: Failed to add to map\n", i); + /* process reserved-memory */ + nodeoffset = fdt_subnode_offset(fdt, 0, "reserved-memory"); + if (nodeoffset >= 0) { + subnode = fdt_first_subnode(fdt, nodeoffset); + while (subnode >= 0) { + /* check if this subnode has a reg property */ + addr = fdtdec_get_addr_size(fdt, subnode, "reg", + (fdt_size_t *)&size); + /* + * The /reserved-memory node may have children with + * a size instead of a reg property. + */ + if (addr != FDT_ADDR_T_NONE) + efi_reserve_memory(addr, size); + subnode = fdt_next_subnode(fdt, subnode); + } } } From 7cceef7bde3d78dbd0f85794fbda0c431bac39c0 Mon Sep 17 00:00:00 2001 From: AKASHI Takahiro Date: Tue, 17 Mar 2020 11:12:34 +0900 Subject: [PATCH 27/58] efi_loader: define OsIndicationsSupported flags These flags are expected to be set in OsIndicationsSupported variable if corresponding features are supported. See UEFI specification, section 8.5.4. In particular, capsule-related flags will be used in my capsule update patch. Signed-off-by: AKASHI Takahiro Fix misspelled EFI_OS_INDICATIONS_BOOT_TO_FW_UI. Reviewed-by: Heinrich Schuchardt Signed-off-by: Heinrich Schuchardt --- include/efi_api.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/efi_api.h b/include/efi_api.h index 3d1a6beeea..9162a27d2e 100644 --- a/include/efi_api.h +++ b/include/efi_api.h @@ -57,6 +57,16 @@ typedef u16 efi_form_id_t; struct efi_event; +/* OsIndicationsSupported flags */ +#define EFI_OS_INDICATIONS_BOOT_TO_FW_UI 0x0000000000000001 +#define EFI_OS_INDICATIONS_TIMESTAMP_REVOCATION 0x0000000000000002 +#define EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED 0x0000000000000004 +#define EFI_OS_INDICATIONS_FMP_CAPSULE_SUPPORTED 0x0000000000000008 +#define EFI_OS_INDICATIONS_CAPSULE_RESULT_VAR_SUPPORTED 0x0000000000000010 +#define EFI_OS_INDICATIONS_START_OS_RECOVERY 0x0000000000000020 +#define EFI_OS_INDICATIONS_START_PLATFORM_RECOVERY 0x0000000000000040 +#define EFI_OS_INDICATIONS_JSON_CONFIG_DATA_REFRESH 0x0000000000000080 + /* EFI Boot Services table */ #define EFI_BOOT_SERVICES_SIGNATURE 0x56524553544f4f42 struct efi_boot_services { From b74d568d83689234f505726399e483d2dc509898 Mon Sep 17 00:00:00 2001 From: AKASHI Takahiro Date: Tue, 17 Mar 2020 11:12:35 +0900 Subject: [PATCH 28/58] efi_loader: define System Resource Table macros Some of those values will be used in an implementation of UEFI firmware management protocol as part of my capsule update patch. Signed-off-by: AKASHI Takahiro --- include/efi_api.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/include/efi_api.h b/include/efi_api.h index 9162a27d2e..3b0845aafd 100644 --- a/include/efi_api.h +++ b/include/efi_api.h @@ -1655,4 +1655,31 @@ struct efi_load_file_protocol { #define LOAD_OPTION_CATEGORY_BOOT 0x00000000 #define LOAD_OPTION_CATEGORY_APP 0x00000100 +/* + * System Resource Table + */ +/* Firmware Type Definitions */ +#define ESRT_FW_TYPE_UNKNOWN 0x00000000 +#define ESRT_FW_TYPE_SYSTEMFIRMWARE 0x00000001 +#define ESRT_FW_TYPE_DEVICEFIRMWARE 0x00000002 +#define ESRT_FW_TYPE_UEFIDRIVER 0x00000003 + +/* Last Attempt Status Values */ +#define LAST_ATTEMPT_STATUS_SUCCESS 0x00000000 +#define LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL 0x00000001 +#define LAST_ATTEMPT_STATUS_ERROR_INSUFFICIENT_RESOURCES 0x00000002 +#define LAST_ATTEMPT_STATUS_ERROR_INCORRECT_VERSION 0x00000003 +#define LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT 0x00000004 +#define LAST_ATTEMPT_STATUS_ERROR_AUTH_ERROR 0x00000005 +#define LAST_ATTEMPT_STATUS_ERROR_PWR_EVT_AC 0x00000006 +#define LAST_ATTEMPT_STATUS_ERROR_PWR_EVT_BATT 0x00000007 +#define LAST_ATTEMPT_STATUS_ERROR_UNSATISFIED_DEPENDENCIES 0x00000008 + +/* + * The LastAttemptStatus values of 0x1000 - 0x4000 are reserved for vendor + * usage. + */ +#define LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL_VENDOR_RANGE_MIN 0x00001000 +#define LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL_VENDOR_RANGE_MAX 0x00004000 + #endif From b51ec639788bdf8220de458f49498d9f19f65b2b Mon Sep 17 00:00:00 2001 From: AKASHI Takahiro Date: Tue, 17 Mar 2020 11:12:36 +0900 Subject: [PATCH 29/58] efi_loader: export a couple of protocol related functions This is a preparatory patch. Those functions will be used in an implementation of UEFI firmware management protocol as part of my capsule update patch. Signed-off-by: AKASHI Takahiro --- include/efi_loader.h | 14 ++++++++++++++ lib/efi_loader/efi_boottime.c | 16 ++++++++-------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/include/efi_loader.h b/include/efi_loader.h index 8e34379833..37c3f15da1 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -457,6 +457,20 @@ efi_status_t efi_remove_all_protocols(const efi_handle_t handle); /* Install multiple protocol interfaces */ efi_status_t EFIAPI efi_install_multiple_protocol_interfaces (efi_handle_t *handle, ...); +/* Get handles that support a given protocol */ +efi_status_t EFIAPI efi_locate_handle_buffer( + enum efi_locate_search_type search_type, + const efi_guid_t *protocol, void *search_key, + efi_uintn_t *no_handles, efi_handle_t **buffer); +/* Close an previously opened protocol interface */ +efi_status_t EFIAPI efi_close_protocol(efi_handle_t handle, + const efi_guid_t *protocol, + efi_handle_t agent_handle, + efi_handle_t controller_handle); +/* Open a protocol interface */ +efi_status_t EFIAPI efi_handle_protocol(efi_handle_t handle, + const efi_guid_t *protocol, + void **protocol_interface); /* Call this to create an event */ efi_status_t efi_create_event(uint32_t type, efi_uintn_t notify_tpl, void (EFIAPI *notify_function) ( diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index e533a185f8..3b79a88a48 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -2106,10 +2106,10 @@ static efi_status_t EFIAPI efi_set_watchdog_timer(unsigned long timeout, * * Return: status code */ -static efi_status_t EFIAPI efi_close_protocol(efi_handle_t handle, - const efi_guid_t *protocol, - efi_handle_t agent_handle, - efi_handle_t controller_handle) +efi_status_t EFIAPI efi_close_protocol(efi_handle_t handle, + const efi_guid_t *protocol, + efi_handle_t agent_handle, + efi_handle_t controller_handle) { struct efi_handler *handler; struct efi_open_protocol_info_item *item; @@ -2282,7 +2282,7 @@ static efi_status_t EFIAPI efi_protocols_per_handle( * * Return: status code */ -static efi_status_t EFIAPI efi_locate_handle_buffer( +efi_status_t EFIAPI efi_locate_handle_buffer( enum efi_locate_search_type search_type, const efi_guid_t *protocol, void *search_key, efi_uintn_t *no_handles, efi_handle_t **buffer) @@ -3182,9 +3182,9 @@ out: * * Return: status code */ -static efi_status_t EFIAPI efi_handle_protocol(efi_handle_t handle, - const efi_guid_t *protocol, - void **protocol_interface) +efi_status_t EFIAPI efi_handle_protocol(efi_handle_t handle, + const efi_guid_t *protocol, + void **protocol_interface) { return efi_open_protocol(handle, protocol, protocol_interface, efi_root, NULL, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL); From 74b44875357378c83e4bd150c0b759ca6ae6563a Mon Sep 17 00:00:00 2001 From: AKASHI Takahiro Date: Tue, 17 Mar 2020 11:12:37 +0900 Subject: [PATCH 30/58] efi_loader: correct a definition of struct efi_capsule_header See UEFI specification, section 8.5.3. In addition, the structure, efi_capsule_header, should be "packed" as it is a serialized binary format in a capsule file. Signed-off-by: AKASHI Takahiro --- include/efi_api.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/efi_api.h b/include/efi_api.h index 3b0845aafd..4713da2e1d 100644 --- a/include/efi_api.h +++ b/include/efi_api.h @@ -217,11 +217,11 @@ enum efi_reset_type { #define CAPSULE_FLAGS_INITIATE_RESET 0x00040000 struct efi_capsule_header { - efi_guid_t *capsule_guid; + efi_guid_t capsule_guid; u32 header_size; u32 flags; u32 capsule_image_size; -}; +} __packed; #define EFI_RT_SUPPORTED_GET_TIME 0x0001 #define EFI_RT_SUPPORTED_SET_TIME 0x0002 From 3586cb82277e8af9eae38b354bb8b2aee38ee377 Mon Sep 17 00:00:00 2001 From: Tomasz Duszynski Date: Sun, 16 Feb 2020 13:17:16 +0100 Subject: [PATCH 31/58] Revert "sunxi: psci: avoid error address-of-packed-member" Using memcpy() for some MMIO access is generally frowned upon and might break things on some platforms. Allwinner H3, which fails to boot, being an example here. Moreover, fields being accessed are naturally aligned and warnings produced by GCC have been quiesced for some time already by: 53dc8ae ("gcc-9: silence 'address-of-packed-member' warning") That said, it should be okay to revert this commit. This reverts commit 9bd34a69a453d409792e08c00953ce8862145e65. Cc: Heinrich Schuchardt Signed-off-by: Tomasz Duszynski Acked-by: Jagan Teki --- arch/arm/cpu/armv7/sunxi/psci.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/arch/arm/cpu/armv7/sunxi/psci.c b/arch/arm/cpu/armv7/sunxi/psci.c index 5b689004e8..2c5d99e9ac 100644 --- a/arch/arm/cpu/armv7/sunxi/psci.c +++ b/arch/arm/cpu/armv7/sunxi/psci.c @@ -75,7 +75,7 @@ static void __secure __mdelay(u32 ms) isb(); } -static void __secure clamp_release(void __maybe_unused *clamp) +static void __secure clamp_release(u32 __maybe_unused *clamp) { #if defined(CONFIG_MACH_SUN6I) || defined(CONFIG_MACH_SUN7I) || \ defined(CONFIG_MACH_SUN8I_H3) || \ @@ -90,7 +90,7 @@ static void __secure clamp_release(void __maybe_unused *clamp) #endif } -static void __secure clamp_set(void __maybe_unused *clamp) +static void __secure clamp_set(u32 __maybe_unused *clamp) { #if defined(CONFIG_MACH_SUN6I) || defined(CONFIG_MACH_SUN7I) || \ defined(CONFIG_MACH_SUN8I_H3) || \ @@ -99,28 +99,22 @@ static void __secure clamp_set(void __maybe_unused *clamp) #endif } -static void __secure sunxi_power_switch(void *clamp, void *pwroff_ptr, bool on, +static void __secure sunxi_power_switch(u32 *clamp, u32 *pwroff, bool on, int cpu) { - u32 pwroff; - - memcpy(&pwroff, pwroff_ptr, sizeof(u32)); - if (on) { /* Release power clamp */ clamp_release(clamp); /* Clear power gating */ - clrbits_le32(&pwroff, BIT(cpu)); + clrbits_le32(pwroff, BIT(cpu)); } else { /* Set power gating */ - setbits_le32(&pwroff, BIT(cpu)); + setbits_le32(pwroff, BIT(cpu)); /* Activate power clamp */ clamp_set(clamp); } - - memcpy(pwroff_ptr, &pwroff, sizeof(u32)); } #ifdef CONFIG_MACH_SUN8I_R40 From f0b0f7fe0eecde78a6e3e0f6760834ff12642375 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Thu, 19 Mar 2020 17:15:18 +0000 Subject: [PATCH 32/58] efi_loader: description of efi_variable.c Correct the file description. Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_variable.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c index c316bdfec0..99d2f01f57 100644 --- a/lib/efi_loader/efi_variable.c +++ b/lib/efi_loader/efi_variable.c @@ -1,8 +1,8 @@ // SPDX-License-Identifier: GPL-2.0+ /* - * EFI utils + * UEFI runtime variable services * - * Copyright (c) 2017 Rob Clark + * Copyright (c) 2017 Rob Clark */ #include From 47a9596354e074146596559ee7330e1941db43be Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Thu, 19 Mar 2020 13:49:34 +0100 Subject: [PATCH 33/58] efi_loader: fix function descriptions in efi_disk.c Use Sphinx style for function descriptions. Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_disk.c | 52 ++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c index ed7fb3f7d3..9563556691 100644 --- a/lib/efi_loader/efi_disk.c +++ b/lib/efi_loader/efi_disk.c @@ -222,15 +222,17 @@ static const struct efi_block_io block_io_disk_template = { .flush_blocks = &efi_disk_flush_blocks, }; -/* - * Get the simple file system protocol for a file device path. +/** + * efi_fs_from_path() - retrieve simple file system protocol + * + * Gets the simple file system protocol for a file device path. * * The full path provided is split into device part and into a file * part. The device part is used to find the handle on which the * simple file system protocol is installed. * - * @full_path device path including device and file - * @return simple file system protocol + * @full_path: device path including device and file + * Return: simple file system protocol */ struct efi_simple_file_system_protocol * efi_fs_from_path(struct efi_device_path *full_path) @@ -285,15 +287,15 @@ static int efi_fs_exists(struct blk_desc *desc, int part) } /* - * Create a handle for a partition or disk + * efi_disk_add_dev() - create a handle for a partition or disk * - * @parent parent handle - * @dp_parent parent device path - * @if_typename interface name for block device - * @desc internal block device - * @dev_index device index for block device - * @offset offset into disk for simple partitions - * @return disk object + * @parent: parent handle + * @dp_parent: parent device path + * @if_typename: interface name for block device + * @desc: internal block device + * @dev_index: device index for block device + * @offset: offset into disk for simple partitions + * Return: disk object */ static efi_status_t efi_disk_add_dev( efi_handle_t parent, @@ -373,15 +375,17 @@ static efi_status_t efi_disk_add_dev( return EFI_SUCCESS; } -/* - * Create handles and protocols for the partitions of a block device +/** + * efi_disk_create_partitions() - create handles and protocols for partitions * - * @parent handle of the parent disk - * @blk_desc block device - * @if_typename interface type - * @diskid device number - * @pdevname device name - * @return number of partitions created + * Create handles and protocols for the partitions of a block device. + * + * @parent: handle of the parent disk + * @blk_desc: block device + * @if_typename: interface type + * @diskid: device number + * @pdevname: device name + * Return: number of partitions created */ int efi_disk_create_partitions(efi_handle_t parent, struct blk_desc *desc, const char *if_typename, int diskid, @@ -418,16 +422,20 @@ int efi_disk_create_partitions(efi_handle_t parent, struct blk_desc *desc, return disks; } -/* +/** + * efi_disk_register() - register block devices + * * U-Boot doesn't have a list of all online disk devices. So when running our * EFI payload, we scan through all of the potentially available ones and * store them in our object pool. * + * This function is called in efi_init_obj_list(). + * * TODO(sjg@chromium.org): Actually with CONFIG_BLK, U-Boot does have this. * Consider converting the code to look up devices as needed. The EFI device * could be a child of the UCLASS_BLK block device, perhaps. * - * This gets called from do_bootefi_exec(). + * Return: status code */ efi_status_t efi_disk_register(void) { From 4d7f5af841c4622fb6c5d155e31c1072f3b052df Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Fri, 20 Mar 2020 19:04:34 +0100 Subject: [PATCH 34/58] efi_loader: correct reported length in GetNextVariable() The runtime service GetNextVariable() returns the length of the next variable including the closing 0x0000. This length should be in bytes. Comparing the output of EDK2 and U-Boot shows that this is currently not correctly implemented: EDK2: OsIndicationsSupported: 46 PlatformLang: 26 PlatformLangCodes: 36 U-Boot: OsIndicationsSupported: 23 PlatformLang: 13 PlatformLangCodes: 18 Provide correct length in GetNextVariable(). Fixes: d99a87f84b75 ("efi_loader: implement GetNextVariableName()") Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_variable.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c index 99d2f01f57..3bec2d0d17 100644 --- a/lib/efi_loader/efi_variable.c +++ b/lib/efi_loader/efi_variable.c @@ -273,7 +273,8 @@ static efi_status_t parse_uboot_variable(char *variable, u32 *attributes) { char *guid, *name, *end, c; - unsigned long name_len; + size_t name_len; + efi_uintn_t old_variable_name_size; u16 *p; guid = strchr(variable, '_'); @@ -289,17 +290,17 @@ static efi_status_t parse_uboot_variable(char *variable, return EFI_INVALID_PARAMETER; name_len = end - name; - if (*variable_name_size < (name_len + 1)) { - *variable_name_size = name_len + 1; + old_variable_name_size = *variable_name_size; + *variable_name_size = sizeof(u16) * (name_len + 1); + if (old_variable_name_size < *variable_name_size) return EFI_BUFFER_TOO_SMALL; - } + end++; /* point to value */ /* variable name */ p = variable_name; utf8_utf16_strncpy(&p, name, name_len); variable_name[name_len] = 0; - *variable_name_size = name_len + 1; /* guid */ c = *(name - 1); From e1089765b5964f35a426f3abe29ba164422f4165 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Fri, 20 Mar 2020 19:20:17 +0100 Subject: [PATCH 35/58] efi_selftest: check length reported by GetNextVariableName() GetNextVariableName should report the length of the variable including the final 0x0000 in bytes. Check this in the unit test. Increase the buffer size for variable names. 40 bytes is too short. Signed-off-by: Heinrich Schuchardt --- lib/efi_selftest/efi_selftest_variables.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/efi_selftest/efi_selftest_variables.c b/lib/efi_selftest/efi_selftest_variables.c index 5d98c029b8..2c16f3db6c 100644 --- a/lib/efi_selftest/efi_selftest_variables.c +++ b/lib/efi_selftest/efi_selftest_variables.c @@ -11,7 +11,7 @@ #include #define EFI_ST_MAX_DATA_SIZE 16 -#define EFI_ST_MAX_VARNAME_SIZE 40 +#define EFI_ST_MAX_VARNAME_SIZE 80 static struct efi_boot_services *boottime; static struct efi_runtime_services *runtime; @@ -155,8 +155,14 @@ static int execute(void) return EFI_ST_FAILURE; } if (!memcmp(&guid, &guid_vendor0, sizeof(efi_guid_t)) && - !efi_st_strcmp_16_8(varname, "efi_st_var0")) + !efi_st_strcmp_16_8(varname, "efi_st_var0")) { flag |= 1; + if (len != 24) { + efi_st_error("GetNextVariableName report wrong length %u, expected 24\n", + (unsigned int)len); + return EFI_ST_FAILURE; + } + } if (!memcmp(&guid, &guid_vendor1, sizeof(efi_guid_t)) && !efi_st_strcmp_16_8(varname, "efi_st_var1")) flag |= 2; From 9f888969fdd6ef11078b893639352ec57824c202 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Thu, 19 Mar 2020 15:45:52 +0100 Subject: [PATCH 36/58] efi_loader: simplify logical expression in efi_disk_add_dev() To check if a variable is non-zero there is no need for '!= 0'. Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_disk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c index 9563556691..fc0682bc48 100644 --- a/lib/efi_loader/efi_disk.c +++ b/lib/efi_loader/efi_disk.c @@ -367,7 +367,7 @@ static efi_status_t efi_disk_add_dev( diskobj->media.block_size = desc->blksz; diskobj->media.io_align = desc->blksz; diskobj->media.last_block = desc->lba - offset; - if (part != 0) + if (part) diskobj->media.logical_partition = 1; diskobj->ops.media = &diskobj->media; if (disk) From 7aeceffb2509ba700673fa125bbfe785c4c0be71 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sun, 22 Mar 2020 08:28:15 +0100 Subject: [PATCH 37/58] efi_loader: description efi_convert_pointer() Correct the description of function efi_convert_pointer(). Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_runtime.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/efi_loader/efi_runtime.c b/lib/efi_loader/efi_runtime.c index 4be51335bc..6a25acbbcd 100644 --- a/lib/efi_loader/efi_runtime.c +++ b/lib/efi_loader/efi_runtime.c @@ -483,7 +483,7 @@ static __efi_runtime efi_status_t EFIAPI efi_convert_pointer_runtime( } /** - * efi_convert_pointer_runtime() - convert from physical to virtual pointer + * efi_convert_pointer() - convert from physical to virtual pointer * * This function implements the ConvertPointer() runtime service until * the first call to SetVirtualAddressMap(). @@ -493,7 +493,7 @@ static __efi_runtime efi_status_t EFIAPI efi_convert_pointer_runtime( * * @debug_disposition: indicates if pointer may be converted to NULL * @address: pointer to be converted - * Return: status code EFI_UNSUPPORTED + * Return: status code */ static __efi_runtime efi_status_t EFIAPI efi_convert_pointer( efi_uintn_t debug_disposition, void **address) From 72291a9d83ec2fe50cc8fac304e8ecd5534daf5e Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sun, 22 Mar 2020 09:52:48 +0100 Subject: [PATCH 38/58] efi_loader: fix freestanding memmove() For EFI binaries we have to provide an implementation of memmove() in efi_freestanding.c. Before this patch the memmove() function was copying in the wrong direction. Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_freestanding.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_freestanding.c b/lib/efi_loader/efi_freestanding.c index dcf5d1c49a..bd0dff162f 100644 --- a/lib/efi_loader/efi_freestanding.c +++ b/lib/efi_loader/efi_freestanding.c @@ -47,7 +47,7 @@ void *memmove(void *dest, const void *src, size_t n) u8 *d = dest; const u8 *s = src; - if (d >= s) { + if (d <= s) { for (; n; --n) *d++ = *s++; } else { From cde162e76680c57e9756d937ff23c822249bc3af Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sun, 22 Mar 2020 09:32:55 +0100 Subject: [PATCH 39/58] efi_selftest: test CalculateCrc32, CopyMem, SetMem Provide unit tests for CalculateCrc32(), CopyMem(), SetMem(). Signed-off-by: Heinrich Schuchardt --- lib/efi_selftest/Makefile | 1 + lib/efi_selftest/efi_selftest_mem.c | 77 +++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 lib/efi_selftest/efi_selftest_mem.c diff --git a/lib/efi_selftest/Makefile b/lib/efi_selftest/Makefile index cf132c372e..e9baa64135 100644 --- a/lib/efi_selftest/Makefile +++ b/lib/efi_selftest/Makefile @@ -27,6 +27,7 @@ efi_selftest_exitbootservices.o \ efi_selftest_gop.o \ efi_selftest_loaded_image.o \ efi_selftest_manageprotocols.o \ +efi_selftest_mem.o \ efi_selftest_memory.o \ efi_selftest_open_protocol.o \ efi_selftest_register_notify.o \ diff --git a/lib/efi_selftest/efi_selftest_mem.c b/lib/efi_selftest/efi_selftest_mem.c new file mode 100644 index 0000000000..51f0fec39b --- /dev/null +++ b/lib/efi_selftest/efi_selftest_mem.c @@ -0,0 +1,77 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * efi_selftest_memory + * + * Copyright (c) 2018 Heinrich Schuchardt + * + * This unit test checks the following boottime services: + * CopyMem, SetMem, CalculateCrc32 + * + * The memory type used for the device tree is checked. + */ + +#include + +static struct efi_boot_services *boottime; + +/** + * setup() - setup unit test + * + * @handle: handle of the loaded image + * @systable: system table + * Return: EFI_ST_SUCCESS for success + */ +static int setup(const efi_handle_t handle, + const struct efi_system_table *systable) +{ + boottime = systable->boottime; + + return EFI_ST_SUCCESS; +} + +/* + * execute() - execute unit test + * + * Return: EFI_ST_SUCCESS for success + */ +static int execute(void) +{ + u8 c1[] = "abcdefghijklmnop"; + u8 c2[] = "abcdefghijklmnop"; + u32 crc32; + efi_status_t ret; + + ret = boottime->calculate_crc32(c1, 16, &crc32); + if (ret != EFI_SUCCESS) { + efi_st_error("CalculateCrc32 failed\n"); + return EFI_ST_FAILURE; + } + if (crc32 != 0x943ac093) { + efi_st_error("CalculateCrc32 returned wrong value\n"); + return EFI_ST_FAILURE; + } + boottime->copy_mem(&c1[5], &c1[3], 8); + if (memcmp(c1, "abcdedefghijknop", 16)) { + efi_st_error("CopyMem forward copy failed: %s\n", c1); + return EFI_ST_FAILURE; + } + boottime->copy_mem(&c2[3], &c2[5], 8); + if (memcmp(c2, "abcfghijklmlmnop", 16)) { + efi_st_error("CopyMem backward copy failed: %s\n", c2); + return EFI_ST_FAILURE; + } + boottime->set_mem(&c1[3], 8, 'x'); + if (memcmp(c1, "abcxxxxxxxxjknop", 16)) { + efi_st_error("SetMem failed: %s\n", c1); + return EFI_ST_FAILURE; + } + + return EFI_ST_SUCCESS; +} + +EFI_UNIT_TEST(mem) = { + .name = "mem", + .phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT, + .setup = setup, + .execute = execute, +}; From 7a4e717b9c0c255137a58f3ab90f002fc3aade2b Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sun, 22 Mar 2020 18:28:20 +0100 Subject: [PATCH 40/58] efi_loader: definition of GetNextVariableName() 'vendor' is both an input and an output parameter. So it cannot be constant. Fixes: 0bda81bfdc5c ("efi_loader: use const efi_guid_t * for variable services") Signed-off-by: Heinrich Schuchardt --- include/efi_api.h | 2 +- include/efi_loader.h | 2 +- lib/efi_loader/efi_variable.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/efi_api.h b/include/efi_api.h index 4713da2e1d..1c40ffc4f5 100644 --- a/include/efi_api.h +++ b/include/efi_api.h @@ -272,7 +272,7 @@ struct efi_runtime_services { efi_uintn_t *data_size, void *data); efi_status_t (EFIAPI *get_next_variable_name)( efi_uintn_t *variable_name_size, - u16 *variable_name, const efi_guid_t *vendor); + u16 *variable_name, efi_guid_t *vendor); efi_status_t (EFIAPI *set_variable)(u16 *variable_name, const efi_guid_t *vendor, u32 attributes, diff --git a/include/efi_loader.h b/include/efi_loader.h index 37c3f15da1..3f2792892f 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -645,7 +645,7 @@ efi_status_t EFIAPI efi_get_variable(u16 *variable_name, efi_uintn_t *data_size, void *data); efi_status_t EFIAPI efi_get_next_variable_name(efi_uintn_t *variable_name_size, u16 *variable_name, - const efi_guid_t *vendor); + efi_guid_t *vendor); efi_status_t EFIAPI efi_set_variable(u16 *variable_name, const efi_guid_t *vendor, u32 attributes, efi_uintn_t data_size, const void *data); diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c index 3bec2d0d17..fe2f264591 100644 --- a/lib/efi_loader/efi_variable.c +++ b/lib/efi_loader/efi_variable.c @@ -330,7 +330,7 @@ static efi_status_t parse_uboot_variable(char *variable, */ efi_status_t EFIAPI efi_get_next_variable_name(efi_uintn_t *variable_name_size, u16 *variable_name, - const efi_guid_t *vendor) + efi_guid_t *vendor) { char *native_name, *variable; ssize_t name_len, list_len; @@ -598,7 +598,7 @@ efi_get_variable_runtime(u16 *variable_name, const efi_guid_t *vendor, */ static efi_status_t __efi_runtime EFIAPI efi_get_next_variable_name_runtime(efi_uintn_t *variable_name_size, - u16 *variable_name, const efi_guid_t *vendor) + u16 *variable_name, efi_guid_t *vendor) { return EFI_UNSUPPORTED; } From af827140e5965e5bb2bcad1c53ca8419b428ff6d Mon Sep 17 00:00:00 2001 From: Kristian Amlie Date: Tue, 25 Feb 2020 18:22:16 +0100 Subject: [PATCH 41/58] vexpress_ca9x4: Enable use of correct DTB file and restore EFI loader. EFI was disabled in f95b8a4b5f64f because of the missing DTB file, and indeed, the DTB file is required to load recent versions of GRUB (2.04) correctly. Signed-off-by: Kristian Amlie --- configs/vexpress_ca9x4_defconfig | 2 +- include/configs/vexpress_common.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/configs/vexpress_ca9x4_defconfig b/configs/vexpress_ca9x4_defconfig index 2119df6b10..6bd1f253b6 100644 --- a/configs/vexpress_ca9x4_defconfig +++ b/configs/vexpress_ca9x4_defconfig @@ -34,4 +34,4 @@ CONFIG_SMC911X_32_BIT=y CONFIG_BAUDRATE=38400 CONFIG_CONS_INDEX=0 CONFIG_OF_LIBFDT=y -# CONFIG_EFI_LOADER is not set +CONFIG_DEFAULT_FDT_FILE="vexpress-v2p-ca9.dtb" diff --git a/include/configs/vexpress_common.h b/include/configs/vexpress_common.h index 7f215a6707..e73658a9e6 100644 --- a/include/configs/vexpress_common.h +++ b/include/configs/vexpress_common.h @@ -207,7 +207,8 @@ "devtmpfs.mount=0 vmalloc=256M\0" \ "bootflash=run flashargs; " \ "cp ${ramdisk_addr} ${ramdisk_addr_r} ${maxramdisk}; " \ - "bootm ${kernel_addr} ${ramdisk_addr_r}\0" + "bootm ${kernel_addr} ${ramdisk_addr_r}\0" \ + "fdtfile=" CONFIG_DEFAULT_FDT_FILE "\0" /* FLASH and environment organization */ #define PHYS_FLASH_SIZE 0x04000000 /* 64MB */ From 4aa33690fc9a225e7e35b5870e4c7378aae46e67 Mon Sep 17 00:00:00 2001 From: Kever Yang Date: Wed, 19 Feb 2020 09:46:05 +0800 Subject: [PATCH 42/58] rockchip: elgin-rv1108: Use syscon API to get grf base Use syscon API to get grf base instead of get from dts. Signed-off-by: Kever Yang Reviewed-by: Simon Glass Acked-by: Otavio Salvador --- board/elgin/elgin_rv1108/elgin_rv1108.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/board/elgin/elgin_rv1108/elgin_rv1108.c b/board/elgin/elgin_rv1108/elgin_rv1108.c index 607667ac63..06df25a326 100644 --- a/board/elgin/elgin_rv1108/elgin_rv1108.c +++ b/board/elgin/elgin_rv1108/elgin_rv1108.c @@ -5,8 +5,9 @@ */ #include +#include #include -#include +#include #include #include #include @@ -15,7 +16,6 @@ DECLARE_GLOBAL_DATA_PTR; int mach_cpu_init(void) { - int node; struct rv1108_grf *grf; enum { GPIO3C3_SHIFT = 6, @@ -35,8 +35,7 @@ int mach_cpu_init(void) GPIO2D1_UART2_SIN_M0, }; - node = fdt_node_offset_by_compatible(gd->fdt_blob, -1, "rockchip,rv1108-grf"); - grf = (struct rv1108_grf *)fdtdec_get_addr(gd->fdt_blob, node, "reg"); + grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF); /* Elgin board use UART2 m0 for debug*/ rk_clrsetreg(&grf->gpio2d_iomux, From 9cec3367087bcdcf6f583e60b95243d0d5e9ae92 Mon Sep 17 00:00:00 2001 From: Kever Yang Date: Wed, 19 Feb 2020 09:46:06 +0800 Subject: [PATCH 43/58] rockchip: evb-rv1108: Use syscon API to get grf base Use syscon API to get grf base instead of get from dts. Signed-off-by: Kever Yang Reviewed-by: Simon Glass --- board/rockchip/evb_rv1108/evb_rv1108.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/board/rockchip/evb_rv1108/evb_rv1108.c b/board/rockchip/evb_rv1108/evb_rv1108.c index 733f29376e..5d622c3737 100644 --- a/board/rockchip/evb_rv1108/evb_rv1108.c +++ b/board/rockchip/evb_rv1108/evb_rv1108.c @@ -5,8 +5,9 @@ */ #include +#include #include -#include +#include #include #include @@ -14,7 +15,6 @@ DECLARE_GLOBAL_DATA_PTR; int mach_cpu_init(void) { - int node; struct rv1108_grf *grf; enum { GPIO3C3_SHIFT = 6, @@ -34,8 +34,7 @@ int mach_cpu_init(void) GPIO2D1_UART2_SIN_M0, }; - node = fdt_node_offset_by_compatible(gd->fdt_blob, -1, "rockchip,rv1108-grf"); - grf = (struct rv1108_grf *)fdtdec_get_addr(gd->fdt_blob, node, "reg"); + grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF); /*evb board use UART2 m0 for debug*/ rk_clrsetreg(&grf->gpio2d_iomux, From 23cb61761b137f088ef8625a1c4e7d9af2cbd296 Mon Sep 17 00:00:00 2001 From: Peter Robinson Date: Mon, 2 Mar 2020 07:57:55 +0000 Subject: [PATCH 44/58] rockchip: Change keyboard input from CrOS EC keyboard to a USB keyboard These boards aren't ChromeOS devices so won't have a cros-ec-keyb input as it's the keyboard available via the ChromeOS Embedded Controller. Update them to use a USB keyboard which would actually be available. Also enable the usb keyboard option for those devices that don't have it enabled already. Signed-off-by: Peter Robinson Reviewed-by: Michael Trimarchi Reviewed-by: Simon Glass Reviewed-by: Kever Yang --- configs/miqi-rk3288_defconfig | 1 + configs/roc-pc-rk3399_defconfig | 1 + configs/rock2_defconfig | 1 + configs/tinker-rk3288_defconfig | 1 + configs/tinker-s-rk3288_defconfig | 1 + include/configs/miqi_rk3288.h | 2 +- include/configs/roc-pc-rk3399.h | 2 +- include/configs/rock2.h | 2 +- include/configs/tinker_rk3288.h | 2 +- include/configs/vyasa-rk3288.h | 2 +- 10 files changed, 10 insertions(+), 5 deletions(-) diff --git a/configs/miqi-rk3288_defconfig b/configs/miqi-rk3288_defconfig index edba9da31b..e3e205fd54 100644 --- a/configs/miqi-rk3288_defconfig +++ b/configs/miqi-rk3288_defconfig @@ -75,6 +75,7 @@ CONFIG_USB_GADGET_DWC2_OTG=y CONFIG_USB_HOST_ETHER=y CONFIG_USB_ETHER_ASIX=y CONFIG_USB_ETHER_SMSC95XX=y +CONFIG_USB_KEYBOARD=y CONFIG_DM_VIDEO=y # CONFIG_VIDEO_BPP8 is not set CONFIG_DISPLAY=y diff --git a/configs/roc-pc-rk3399_defconfig b/configs/roc-pc-rk3399_defconfig index 659c67a033..d540a17aeb 100644 --- a/configs/roc-pc-rk3399_defconfig +++ b/configs/roc-pc-rk3399_defconfig @@ -56,5 +56,6 @@ CONFIG_USB_ETHER_ASIX88179=y CONFIG_USB_ETHER_MCS7830=y CONFIG_USB_ETHER_RTL8152=y CONFIG_USB_ETHER_SMSC95XX=y +CONFIG_USB_KEYBOARD=y CONFIG_SPL_TINY_MEMSET=y CONFIG_ERRNO_STR=y diff --git a/configs/rock2_defconfig b/configs/rock2_defconfig index bb12b32a21..cf71c85927 100644 --- a/configs/rock2_defconfig +++ b/configs/rock2_defconfig @@ -74,6 +74,7 @@ CONFIG_USB_DWC2=y CONFIG_ROCKCHIP_USB2_PHY=y CONFIG_USB_GADGET=y CONFIG_USB_GADGET_DWC2_OTG=y +CONFIG_USB_KEYBOARD=y CONFIG_DM_VIDEO=y # CONFIG_VIDEO_BPP8 is not set CONFIG_DISPLAY=y diff --git a/configs/tinker-rk3288_defconfig b/configs/tinker-rk3288_defconfig index 50820ba08e..034d28ea2d 100644 --- a/configs/tinker-rk3288_defconfig +++ b/configs/tinker-rk3288_defconfig @@ -80,6 +80,7 @@ CONFIG_USB_GADGET_DWC2_OTG=y CONFIG_USB_HOST_ETHER=y CONFIG_USB_ETHER_ASIX=y CONFIG_USB_ETHER_SMSC95XX=y +CONFIG_USB_KEYBOARD=y CONFIG_DM_VIDEO=y CONFIG_DISPLAY=y CONFIG_VIDEO_ROCKCHIP=y diff --git a/configs/tinker-s-rk3288_defconfig b/configs/tinker-s-rk3288_defconfig index ab192cf4e4..06c5d9b507 100644 --- a/configs/tinker-s-rk3288_defconfig +++ b/configs/tinker-s-rk3288_defconfig @@ -80,6 +80,7 @@ CONFIG_USB_GADGET_DWC2_OTG=y CONFIG_USB_HOST_ETHER=y CONFIG_USB_ETHER_ASIX=y CONFIG_USB_ETHER_SMSC95XX=y +CONFIG_USB_KEYBOARD=y CONFIG_DM_VIDEO=y # CONFIG_VIDEO_BPP8 is not set CONFIG_DISPLAY=y diff --git a/include/configs/miqi_rk3288.h b/include/configs/miqi_rk3288.h index c9691a0392..e19fa90212 100644 --- a/include/configs/miqi_rk3288.h +++ b/include/configs/miqi_rk3288.h @@ -7,7 +7,7 @@ #define __CONFIG_H #define ROCKCHIP_DEVICE_SETTINGS \ - "stdin=serial,cros-ec-keyb\0" \ + "stdin=serial,usbkbd\0" \ "stdout=serial,vidconsole\0" \ "stderr=serial,vidconsole\0" diff --git a/include/configs/roc-pc-rk3399.h b/include/configs/roc-pc-rk3399.h index 3fd1062542..d4cbc3532e 100644 --- a/include/configs/roc-pc-rk3399.h +++ b/include/configs/roc-pc-rk3399.h @@ -7,7 +7,7 @@ #define __ROC_PC_RK3399_H #define ROCKCHIP_DEVICE_SETTINGS \ - "stdin=serial,cros-ec-keyb\0" \ + "stdin=serial,usbkbd\0" \ "stdout=serial,vidconsole\0" \ "stderr=serial,vidconsole\0" diff --git a/include/configs/rock2.h b/include/configs/rock2.h index 917caf4d53..9e4a66902b 100644 --- a/include/configs/rock2.h +++ b/include/configs/rock2.h @@ -7,7 +7,7 @@ #define __CONFIG_H #define ROCKCHIP_DEVICE_SETTINGS \ - "stdin=serial,cros-ec-keyb\0" \ + "stdin=serial,usbkbd\0" \ "stdout=serial,vidconsole\0" \ "stderr=serial,vidconsole\0" diff --git a/include/configs/tinker_rk3288.h b/include/configs/tinker_rk3288.h index f1095ccd0e..d239e3beb1 100644 --- a/include/configs/tinker_rk3288.h +++ b/include/configs/tinker_rk3288.h @@ -7,7 +7,7 @@ #define __CONFIG_H #define ROCKCHIP_DEVICE_SETTINGS \ - "stdin=serial,cros-ec-keyb\0" \ + "stdin=serial,usbkbd\0" \ "stdout=serial,vidconsole\0" \ "stderr=serial,vidconsole\0" diff --git a/include/configs/vyasa-rk3288.h b/include/configs/vyasa-rk3288.h index e31dc77720..c3521cac41 100644 --- a/include/configs/vyasa-rk3288.h +++ b/include/configs/vyasa-rk3288.h @@ -9,7 +9,7 @@ #define __CONFIG_H #define ROCKCHIP_DEVICE_SETTINGS \ - "stdin=serial,cros-ec-keyb\0" \ + "stdin=serial,usbkbd\0" \ "stdout=serial,vidconsole\0" \ "stderr=serial,vidconsole\0" From af84b3327ad269ffefcd66ddff2f5dea5eff38f8 Mon Sep 17 00:00:00 2001 From: Otavio Salvador Date: Fri, 13 Mar 2020 14:42:45 -0300 Subject: [PATCH 45/58] ARM: dts: Activate pullups in the console pins on rv1108-elgin-r1 In order to make the console pins more robust to noise, activate the pullups and increase its drive strength. Signed-off-by: Otavio Salvador Reviewed-by: Kever Yang --- arch/arm/dts/rv1108-elgin-r1.dts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/arch/arm/dts/rv1108-elgin-r1.dts b/arch/arm/dts/rv1108-elgin-r1.dts index 32b95940b0..83e8b31838 100644 --- a/arch/arm/dts/rv1108-elgin-r1.dts +++ b/arch/arm/dts/rv1108-elgin-r1.dts @@ -40,9 +40,20 @@ }; &uart2 { + pinctrl-names = "default"; + pinctrl-0 = <&uart2m0_xfer_pullup>; status = "okay"; }; &usb20_otg { status = "okay"; }; + +&pinctrl { + uart2m0 { + uart2m0_xfer_pullup: uart2m0-xfer-pullup { + rockchip,pins = <2 RK_PD2 RK_FUNC_1 &pcfg_pull_up_drv_8ma>, + <2 RK_PD1 RK_FUNC_1 &pcfg_pull_up_drv_8ma>; + }; + }; +}; From 1ac0d52a9bb2a20e07542ca54c526e35b0f2ffca Mon Sep 17 00:00:00 2001 From: Otavio Salvador Date: Fri, 13 Mar 2020 14:42:46 -0300 Subject: [PATCH 46/58] elgin-rv1108: Use rk_board_late_init() for GPIO settings Since commit 8e9a8d0d0c8c ("rockchip: elgin-rv1108: use board_early_init_f for per-boar init") the function that configure the board GPIOs is no longer called since CONFIG_BOARD_EARLY_INIT_F=y is not selected. These GPIOs do not need to be configured in such early stagem, so change it to rk_board_late_init() and also select CONFIG_BOARD_LATE_INIT=y to fix the regression. Signed-off-by: Otavio Salvador Signed-off-by: Fabio Berton Reviewed-by: Kever Yang --- board/elgin/elgin_rv1108/elgin_rv1108.c | 2 +- configs/elgin-rv1108_defconfig | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/board/elgin/elgin_rv1108/elgin_rv1108.c b/board/elgin/elgin_rv1108/elgin_rv1108.c index 06df25a326..c5a1cc95e4 100644 --- a/board/elgin/elgin_rv1108/elgin_rv1108.c +++ b/board/elgin/elgin_rv1108/elgin_rv1108.c @@ -49,7 +49,7 @@ int mach_cpu_init(void) #define MODEM_ENABLE_GPIO 111 -int board_early_init_f(void) +int rk_board_late_init(void) { gpio_request(MODEM_ENABLE_GPIO, "modem_enable"); gpio_direction_output(MODEM_ENABLE_GPIO, 0); diff --git a/configs/elgin-rv1108_defconfig b/configs/elgin-rv1108_defconfig index 62af7634a3..80d53f3c10 100644 --- a/configs/elgin-rv1108_defconfig +++ b/configs/elgin-rv1108_defconfig @@ -10,6 +10,7 @@ CONFIG_DEBUG_UART_CLOCK=24000000 CONFIG_DEBUG_UART=y # CONFIG_USE_BOOTCOMMAND is not set CONFIG_DEFAULT_FDT_FILE="rv1108-elgin-r1.dtb" +CONFIG_BOARD_LATE_INIT=y # CONFIG_DISPLAY_CPUINFO is not set CONFIG_DISPLAY_BOARDINFO_LATE=y CONFIG_CMD_GPIO=y From 2dcbeb3568e568846d572d8329442f41b4f60a53 Mon Sep 17 00:00:00 2001 From: Otavio Salvador Date: Fri, 13 Mar 2020 14:42:47 -0300 Subject: [PATCH 47/58] elgin-rv1108: Avoid adc_channel_single_shot error Currently the following error message is seen during boot: U-Boot 2020.01-08751-g55759ae141 (Mar 09 2020 - 14:44:52 -0300) Model: Elgin RV1108 R1 board DRAM: 128 MiB APLL: 600000000 DPLL:1200000000 GPLL:1188000000 ACLK_BUS: 148500000 ACLK_PERI:148500000 HCLK_PERI:148500000 PCLK_PERI:74250000 MMC: dwmmc@30110000: 0 Loading Environment from MMC... OK In: serial@10210000 Out: serial@10210000 Err: serial@10210000 Model: Elgin RV1108 R1 board rockchip_dnl_key_pressed: adc_channel_single_shot fail! .... Since the elgin-rv1108 does not use ADC to read the download key status, select CONFIG_ROCKCHIP_BOOT_MODE_REG=0 to avoid such error. Signed-off-by: Otavio Salvador Reviewed-by: Kever Yang --- configs/elgin-rv1108_defconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/configs/elgin-rv1108_defconfig b/configs/elgin-rv1108_defconfig index 80d53f3c10..b6682994f5 100644 --- a/configs/elgin-rv1108_defconfig +++ b/configs/elgin-rv1108_defconfig @@ -4,6 +4,7 @@ CONFIG_SYS_TEXT_BASE=0x60000000 CONFIG_ENV_OFFSET=0x3F8000 CONFIG_ROCKCHIP_RV1108=y CONFIG_TARGET_ELGIN_RV1108=y +CONFIG_ROCKCHIP_BOOT_MODE_REG=0 CONFIG_NR_DRAM_BANKS=1 CONFIG_DEBUG_UART_BASE=0x10210000 CONFIG_DEBUG_UART_CLOCK=24000000 From 99f946976e185f9c4d94edce6bb123c9c341913a Mon Sep 17 00:00:00 2001 From: Otavio Salvador Date: Fri, 13 Mar 2020 14:42:48 -0300 Subject: [PATCH 48/58] rv1108: Fix boot regression Since commit 79030a486128 ("rockchip: Add Single boot image (with binman, pad_cat)") the following boot regression is seen: U-Boot 2020.04-rc3-00050-gd16e18ca6c-dirty (Mar 09 2020 - 11:40:07 -0300) Model: Elgin RV1108 R1 board DRAM: 128 MiB initcall sequence 67fd12a0 failed at call 6000b927 (err=-22) This happens because the above commit missed to include the "rockchip-u-boot.dtsi" for rv1108, so include this file like it done for other Rockchip SoC dtsi's. Fixes: 79030a486128 ("rockchip: Add Single boot image (with binman, pad_cat)") Signed-off-by: Otavio Salvador Reviewed-by: Kever Yang --- arch/arm/dts/rv1108-u-boot.dtsi | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 arch/arm/dts/rv1108-u-boot.dtsi diff --git a/arch/arm/dts/rv1108-u-boot.dtsi b/arch/arm/dts/rv1108-u-boot.dtsi new file mode 100644 index 0000000000..41ac054b81 --- /dev/null +++ b/arch/arm/dts/rv1108-u-boot.dtsi @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2019 Jagan Teki + */ + +#include "rockchip-u-boot.dtsi" From e5a405583f5ce9576c5084a178622e2fdd49cb23 Mon Sep 17 00:00:00 2001 From: Miquel Raynal Date: Wed, 18 Mar 2020 17:22:55 +0100 Subject: [PATCH 49/58] rockchip: mkimage: Use an existing macro instead of a decimal value Depending on the SoC, a header of four characters is prepended to the image. There is already a macro defining the number of characters: RK_SPL_HDR_SIZE, so use it instead of hardcoding "4". Signed-off-by: Miquel Raynal Reviewed-by: Kever Yang --- tools/rkcommon.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/rkcommon.c b/tools/rkcommon.c index c2382dfe5a..8f281f5901 100644 --- a/tools/rkcommon.c +++ b/tools/rkcommon.c @@ -307,11 +307,13 @@ static int rkcommon_parse_header(const void *buf, struct header0_info *header0, rkcommon_offset_to_spi(hdr1_offset)); for (i = 0; i < ARRAY_SIZE(spl_infos); i++) { - if (!memcmp(&hdr1_sdmmc->magic, spl_infos[i].spl_hdr, 4)) { + if (!memcmp(&hdr1_sdmmc->magic, spl_infos[i].spl_hdr, + RK_SPL_HDR_SIZE)) { if (spl_info) *spl_info = &spl_infos[i]; return IH_TYPE_RKSD; - } else if (!memcmp(&hdr1_spi->magic, spl_infos[i].spl_hdr, 4)) { + } else if (!memcmp(&hdr1_spi->magic, spl_infos[i].spl_hdr, + RK_SPL_HDR_SIZE)) { if (spl_info) *spl_info = &spl_infos[i]; return IH_TYPE_RKSPI; From 39984d22138339fb2b14b21de635ef177cce0c7a Mon Sep 17 00:00:00 2001 From: Tom Rini Date: Fri, 27 Mar 2020 11:47:04 -0400 Subject: [PATCH 50/58] Revert "vexpress_ca9x4: Enable use of correct DTB file and restore EFI loader." Currently this causes failures of the platform when running the EFI loader tests, so disable it for now. This reverts commit af827140e5965e5bb2bcad1c53ca8419b428ff6d. Signed-off-by: Tom Rini --- configs/vexpress_ca9x4_defconfig | 2 +- include/configs/vexpress_common.h | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/configs/vexpress_ca9x4_defconfig b/configs/vexpress_ca9x4_defconfig index 6bd1f253b6..2119df6b10 100644 --- a/configs/vexpress_ca9x4_defconfig +++ b/configs/vexpress_ca9x4_defconfig @@ -34,4 +34,4 @@ CONFIG_SMC911X_32_BIT=y CONFIG_BAUDRATE=38400 CONFIG_CONS_INDEX=0 CONFIG_OF_LIBFDT=y -CONFIG_DEFAULT_FDT_FILE="vexpress-v2p-ca9.dtb" +# CONFIG_EFI_LOADER is not set diff --git a/include/configs/vexpress_common.h b/include/configs/vexpress_common.h index e73658a9e6..7f215a6707 100644 --- a/include/configs/vexpress_common.h +++ b/include/configs/vexpress_common.h @@ -207,8 +207,7 @@ "devtmpfs.mount=0 vmalloc=256M\0" \ "bootflash=run flashargs; " \ "cp ${ramdisk_addr} ${ramdisk_addr_r} ${maxramdisk}; " \ - "bootm ${kernel_addr} ${ramdisk_addr_r}\0" \ - "fdtfile=" CONFIG_DEFAULT_FDT_FILE "\0" + "bootm ${kernel_addr} ${ramdisk_addr_r}\0" /* FLASH and environment organization */ #define PHYS_FLASH_SIZE 0x04000000 /* 64MB */ From 6748a1f2a3e59a867a55487916167c4a676a884e Mon Sep 17 00:00:00 2001 From: Harald Seiler Date: Thu, 26 Mar 2020 18:07:27 +0100 Subject: [PATCH 51/58] test/py: mmc: Fix 'mmc info' testcase Commit 41e30dcf8796 ("cmd: mmc: Make Mode: printout consistent") fixed the layout of `mmc info` output. Reflect this change in the respective testcase. Also fix a typo in the documentation. Fixes: 41e30dcf8796 ("cmd: mmc: Make Mode: printout consistent") Signed-off-by: Harald Seiler Acked-by: Stephen Warren Reviewed-by: Simon Glass --- test/py/tests/test_mmc_rd.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/py/tests/test_mmc_rd.py b/test/py/tests/test_mmc_rd.py index a25aa5f6f7..ea652f9136 100644 --- a/test/py/tests/test_mmc_rd.py +++ b/test/py/tests/test_mmc_rd.py @@ -56,7 +56,7 @@ env__mmc_dev_configs = ( 'info_mode': ???, 'info_buswidth': ???. }, -} +) # Configuration data for test_mmc_rd; defines regions of the MMC (entire # devices, or ranges of sectors) which can be read: @@ -210,7 +210,7 @@ def test_mmc_info(u_boot_console, env__mmc_dev_config): assert good_response in response good_response = "Bus Speed: %s" % info_speed assert good_response in response - good_response = "Mode : %s" % info_mode + good_response = "Mode: %s" % info_mode assert good_response in response good_response = "Bus Width: %s" % info_buswidth assert good_response in response From cb11eed23d7215b6902d43f6273b562ee31e770a Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Wed, 25 Mar 2020 21:35:53 +0100 Subject: [PATCH 52/58] MAINTAINERS: Add usb.h entry to usb Add usb.h file into the USB list. Signed-off-by: Marek Vasut Cc: Tom Rini --- MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/MAINTAINERS b/MAINTAINERS index 92dda40a85..9c1543f17d 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -937,6 +937,7 @@ T: git https://gitlab.denx.de/u-boot/custodians/u-boot-usb.git F: drivers/usb/ F: common/usb.c F: common/usb_kbd.c +F: include/usb.h USB xHCI M: Bin Meng From 7b83060b1eab4456b3dfaef636dfd5c0ff705b17 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Wed, 25 Mar 2020 21:27:51 +0100 Subject: [PATCH 53/58] fs: ext4: Fix alignment of cache buffers We need to align the cache buffer to ARCH_DMA_MINALIGN in order to avoid access errors like CACHE: Misaligned operation at range [be0231e0, be0235e0] seen on the MCIMX7SABRE. Fixes: d5aee659f217 ("fs: ext4: cache extent data") Signed-off-by: Jan Kiszka Reviewed-by: Tom Rini Reviewed-by: Stephen Warren Tested-by: Peter Robinson --- fs/ext4/ext4fs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/ext4/ext4fs.c b/fs/ext4/ext4fs.c index 1c616a26a2..966b427a97 100644 --- a/fs/ext4/ext4fs.c +++ b/fs/ext4/ext4fs.c @@ -288,7 +288,7 @@ int ext_cache_read(struct ext_block_cache *cache, lbaint_t block, int size) if (cache->buf && cache->block == block && cache->size == size) return 1; ext_cache_fini(cache); - cache->buf = malloc(size); + cache->buf = memalign(ARCH_DMA_MINALIGN, size); if (!cache->buf) return 0; if (!ext4fs_devread(block, 0, size, cache->buf)) { From 3e29bd268d6361d7962db2c4a9cd4cf4d85abec2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Beh=C3=BAn?= Date: Wed, 25 Mar 2020 12:04:46 +0100 Subject: [PATCH 54/58] MAINTAINERS: add myself as maintainer of fs/btrfs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marek Behún --- MAINTAINERS | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 9c1543f17d..b50652bd85 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -527,6 +527,13 @@ M: Simon Glass S: Maintained F: tools/binman/ +BTRFS +M: Marek Behun +S: Maintained +F: cmd/btrfs.c +F: fs/btrfs/ +F: include/btrfs.h + BUILDMAN M: Simon Glass S: Maintained From 6cc8e545b79311de2dbf7f05291fc77a54ffea6b Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Mon, 23 Mar 2020 18:47:47 +0100 Subject: [PATCH 55/58] test: typo decompression %s/decopmression/decompression/ Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- test/compression.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/compression.c b/test/compression.c index cf040d7c86..63f929fa4b 100644 --- a/test/compression.c +++ b/test/compression.c @@ -451,7 +451,7 @@ static int compress_using_none(struct unit_test_state *uts, } /** - * run_bootm_test() - Run tests on the bootm decopmression function + * run_bootm_test() - Run tests on the bootm decompression function * * @comp_type: Compression type to test * @compress: Our function to compress data From eea4810804eb3646c5b7c531b1f4c54d385c6e82 Mon Sep 17 00:00:00 2001 From: Kever Yang Date: Wed, 4 Mar 2020 08:59:48 +0800 Subject: [PATCH 56/58] usb: dwc3-of-simple: Drop redundant inclding header file The fdtdec.h is no use in this file, remove the include code. Signed-off-by: Kever Yang --- drivers/usb/host/dwc3-of-simple.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/usb/host/dwc3-of-simple.c b/drivers/usb/host/dwc3-of-simple.c index 45df614b09..e4abc6f3b9 100644 --- a/drivers/usb/host/dwc3-of-simple.c +++ b/drivers/usb/host/dwc3-of-simple.c @@ -12,7 +12,6 @@ #include #include -#include #include #include From 2be1130a93059b4ca0af037b896bb998e9907f8b Mon Sep 17 00:00:00 2001 From: Kever Yang Date: Wed, 4 Mar 2020 08:59:49 +0800 Subject: [PATCH 57/58] usb: ehci-msm: Use dev interface to get device address Use dev_read_addr_ptr() instead of devfdt_get_addr() so that we can support live DT. Signed-off-by: Kever Yang Reviewed-by: Ramon Fried --- drivers/usb/host/ehci-msm.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/usb/host/ehci-msm.c b/drivers/usb/host/ehci-msm.c index 5c257ccf4d..dd92808ff7 100644 --- a/drivers/usb/host/ehci-msm.c +++ b/drivers/usb/host/ehci-msm.c @@ -10,8 +10,6 @@ #include #include #include -#include -#include #include #include #include @@ -108,7 +106,7 @@ static int ehci_usb_ofdata_to_platdata(struct udevice *dev) struct msm_ehci_priv *priv = dev_get_priv(dev); priv->ulpi_vp.port_num = 0; - priv->ehci = (void *)devfdt_get_addr(dev); + priv->ehci = dev_read_addr_ptr(dev); if (priv->ehci == (void *)FDT_ADDR_T_NONE) return -EINVAL; From ac28e59a574dd231a4787752d923f618587e3d10 Mon Sep 17 00:00:00 2001 From: Kever Yang Date: Wed, 4 Mar 2020 08:59:50 +0800 Subject: [PATCH 58/58] usb: Migrate to support live DT for some driver Use ofnode_ instead of fdt_ APIs so that the drivers can support live DT. This patch updates usb_get_dr_mode() and usb_get_maximum_speed() to use ofnode as parameter instead of fdt offset. And all the drivers who use these APIs update to use live dt APIs at the same time. Signed-off-by: Kever Yang --- drivers/usb/cdns3/core.c | 15 ++++++--------- drivers/usb/cdns3/gadget.c | 2 +- drivers/usb/common/common.c | 12 +++++------- drivers/usb/dwc3/dwc3-generic.c | 16 +++++++--------- drivers/usb/dwc3/dwc3-meson-g12a.c | 2 +- drivers/usb/gadget/dwc2_udc_otg.c | 5 ++--- drivers/usb/host/dwc3-sti-glue.c | 20 +++++++------------- drivers/usb/host/ehci-mx6.c | 2 +- drivers/usb/host/xhci-dwc3.c | 3 +-- drivers/usb/musb-new/ti-musb.c | 12 +++++------- include/linux/usb/otg.h | 10 ++++++---- 11 files changed, 42 insertions(+), 57 deletions(-) diff --git a/drivers/usb/cdns3/core.c b/drivers/usb/cdns3/core.c index f947e6983c..ce846488a8 100644 --- a/drivers/usb/cdns3/core.c +++ b/drivers/usb/cdns3/core.c @@ -108,7 +108,7 @@ static int cdns3_core_init_role(struct cdns3 *cdns) enum usb_dr_mode dr_mode; int ret = 0; - dr_mode = usb_get_dr_mode(dev_of_offset(dev)); + dr_mode = usb_get_dr_mode(dev->node); cdns->role = USB_ROLE_NONE; /* @@ -384,22 +384,20 @@ static const struct udevice_id cdns3_ids[] = { int cdns3_bind(struct udevice *parent) { - int from = dev_of_offset(parent); - const void *fdt = gd->fdt_blob; enum usb_dr_mode dr_mode; struct udevice *dev; const char *driver; const char *name; - int node; + ofnode node; int ret; - node = fdt_node_offset_by_compatible(fdt, from, "cdns,usb3"); - if (node < 0) { + node = ofnode_by_compatible(parent->node, "cdns,usb3"); + if (!ofnode_valid(node)) { ret = -ENODEV; goto fail; } - name = fdt_get_name(fdt, node, NULL); + name = ofnode_get_name(node); dr_mode = usb_get_dr_mode(node); switch (dr_mode) { @@ -422,8 +420,7 @@ int cdns3_bind(struct udevice *parent) goto fail; }; - ret = device_bind_driver_to_node(parent, driver, name, - offset_to_ofnode(node), &dev); + ret = device_bind_driver_to_node(parent, driver, name, node, &dev); if (ret) { printf("%s: not able to bind usb device mode\n", __func__); diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/gadget.c index 8377eb458b..caed27c32f 100644 --- a/drivers/usb/cdns3/gadget.c +++ b/drivers/usb/cdns3/gadget.c @@ -2579,7 +2579,7 @@ static int cdns3_gadget_start(struct cdns3 *cdns) if (!priv_dev->onchip_buffers) priv_dev->onchip_buffers = 256; - max_speed = usb_get_maximum_speed(dev_of_offset(cdns->dev)); + max_speed = usb_get_maximum_speed(dev_ofnode(cdns->dev)); /* Check the maximum_speed parameter */ switch (max_speed) { diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c index a55def5aba..0db281b970 100644 --- a/drivers/usb/common/common.c +++ b/drivers/usb/common/common.c @@ -7,7 +7,7 @@ */ #include -#include +#include #include #include @@ -20,13 +20,12 @@ static const char *const usb_dr_modes[] = { [USB_DR_MODE_OTG] = "otg", }; -enum usb_dr_mode usb_get_dr_mode(int node) +enum usb_dr_mode usb_get_dr_mode(ofnode node) { - const void *fdt = gd->fdt_blob; const char *dr_mode; int i; - dr_mode = fdt_getprop(fdt, node, "dr_mode", NULL); + dr_mode = ofnode_read_string(node, "dr_mode"); if (!dr_mode) { pr_err("usb dr_mode not found\n"); return USB_DR_MODE_UNKNOWN; @@ -48,13 +47,12 @@ static const char *const speed_names[] = { [USB_SPEED_SUPER] = "super-speed", }; -enum usb_device_speed usb_get_maximum_speed(int node) +enum usb_device_speed usb_get_maximum_speed(ofnode node) { - const void *fdt = gd->fdt_blob; const char *max_speed; int i; - max_speed = fdt_getprop(fdt, node, "maximum-speed", NULL); + max_speed = ofnode_read_string(node, "maximum-speed"); if (!max_speed) { pr_err("usb maximum-speed not found\n"); return USB_SPEED_UNKNOWN; diff --git a/drivers/usb/dwc3/dwc3-generic.c b/drivers/usb/dwc3/dwc3-generic.c index 3e116b2c5c..febcfc0f54 100644 --- a/drivers/usb/dwc3/dwc3-generic.c +++ b/drivers/usb/dwc3/dwc3-generic.c @@ -88,9 +88,9 @@ static int dwc3_generic_remove(struct udevice *dev, static int dwc3_generic_ofdata_to_platdata(struct udevice *dev) { struct dwc3_generic_plat *plat = dev_get_platdata(dev); - int node = dev_of_offset(dev); + ofnode node = dev->node; - plat->base = devfdt_get_addr(dev); + plat->base = dev_read_addr(dev); plat->maximum_speed = usb_get_maximum_speed(node); if (plat->maximum_speed == USB_SPEED_UNKNOWN) { @@ -284,13 +284,11 @@ struct dwc3_glue_ops ti_ops = { static int dwc3_glue_bind(struct udevice *parent) { - const void *fdt = gd->fdt_blob; - int node; + ofnode node; int ret; - for (node = fdt_first_subnode(fdt, dev_of_offset(parent)); node > 0; - node = fdt_next_subnode(fdt, node)) { - const char *name = fdt_get_name(fdt, node, NULL); + ofnode_for_each_subnode(node, parent->node) { + const char *name = ofnode_get_name(node); enum usb_dr_mode dr_mode; struct udevice *dev; const char *driver = NULL; @@ -322,7 +320,7 @@ static int dwc3_glue_bind(struct udevice *parent) continue; ret = device_bind_driver_to_node(parent, driver, name, - offset_to_ofnode(node), &dev); + node, &dev); if (ret) { debug("%s: not able to bind usb device mode\n", __func__); @@ -400,7 +398,7 @@ static int dwc3_glue_probe(struct udevice *dev) while (child) { enum usb_dr_mode dr_mode; - dr_mode = usb_get_dr_mode(dev_of_offset(child)); + dr_mode = usb_get_dr_mode(child->node); device_find_next_child(&child); if (ops && ops->select_dr_mode) ops->select_dr_mode(dev, index, dr_mode); diff --git a/drivers/usb/dwc3/dwc3-meson-g12a.c b/drivers/usb/dwc3/dwc3-meson-g12a.c index 832bcd70ff..d4453f8784 100644 --- a/drivers/usb/dwc3/dwc3-meson-g12a.c +++ b/drivers/usb/dwc3/dwc3-meson-g12a.c @@ -393,7 +393,7 @@ static int dwc3_meson_g12a_probe(struct udevice *dev) } #endif - priv->otg_mode = usb_get_dr_mode(dev_of_offset(dev)); + priv->otg_mode = usb_get_dr_mode(dev->node); ret = dwc3_meson_g12a_usb_init(priv); if (ret) diff --git a/drivers/usb/gadget/dwc2_udc_otg.c b/drivers/usb/gadget/dwc2_udc_otg.c index 496abf38e7..b9c814cf73 100644 --- a/drivers/usb/gadget/dwc2_udc_otg.c +++ b/drivers/usb/gadget/dwc2_udc_otg.c @@ -1039,13 +1039,12 @@ void dwc2_phy_shutdown(struct udevice *dev, struct phy *usb_phys, int num_phys) static int dwc2_udc_otg_ofdata_to_platdata(struct udevice *dev) { struct dwc2_plat_otg_data *platdata = dev_get_platdata(dev); - int node = dev_of_offset(dev); ulong drvdata; void (*set_params)(struct dwc2_plat_otg_data *data); int ret; - if (usb_get_dr_mode(node) != USB_DR_MODE_PERIPHERAL && - usb_get_dr_mode(node) != USB_DR_MODE_OTG) { + if (usb_get_dr_mode(dev->node) != USB_DR_MODE_PERIPHERAL && + usb_get_dr_mode(dev->node) != USB_DR_MODE_OTG) { dev_dbg(dev, "Invalid mode\n"); return -ENODEV; } diff --git a/drivers/usb/host/dwc3-sti-glue.c b/drivers/usb/host/dwc3-sti-glue.c index ad7cf6e6b5..c99a1985cc 100644 --- a/drivers/usb/host/dwc3-sti-glue.c +++ b/drivers/usb/host/dwc3-sti-glue.c @@ -10,8 +10,6 @@ #include #include #include -#include -#include #include #include #include @@ -109,8 +107,7 @@ static int sti_dwc3_glue_ofdata_to_platdata(struct udevice *dev) int ret; u32 reg[4]; - ret = fdtdec_get_int_array(gd->fdt_blob, dev_of_offset(dev), - "reg", reg, ARRAY_SIZE(reg)); + ret = ofnode_read_u32_array(dev->node, "reg", reg, ARRAY_SIZE(reg)); if (ret) { pr_err("unable to find st,stih407-dwc3 reg property(%d)\n", ret); return ret; @@ -153,18 +150,15 @@ static int sti_dwc3_glue_ofdata_to_platdata(struct udevice *dev) static int sti_dwc3_glue_bind(struct udevice *dev) { struct sti_dwc3_glue_platdata *plat = dev_get_platdata(dev); - int dwc3_node; + ofnode node, dwc3_node; - /* check if one subnode is present */ - dwc3_node = fdt_first_subnode(gd->fdt_blob, dev_of_offset(dev)); - if (dwc3_node <= 0) { - pr_err("Can't find subnode for %s\n", dev->name); - return -ENODEV; + /* Find snps,dwc3 node from subnode */ + ofnode_for_each_subnode(node, dev->node) { + if (ofnode_device_is_compatible(node, "snps,dwc3")) + dwc3_node = node; } - /* check if the subnode compatible string is the dwc3 one*/ - if (fdt_node_check_compatible(gd->fdt_blob, dwc3_node, - "snps,dwc3") != 0) { + if (!ofnode_valid(node)) { pr_err("Can't find dwc3 subnode for %s\n", dev->name); return -ENODEV; } diff --git a/drivers/usb/host/ehci-mx6.c b/drivers/usb/host/ehci-mx6.c index 1993ad620a..f2ceb51310 100644 --- a/drivers/usb/host/ehci-mx6.c +++ b/drivers/usb/host/ehci-mx6.c @@ -513,7 +513,7 @@ static int ehci_usb_ofdata_to_platdata(struct udevice *dev) struct usb_platdata *plat = dev_get_platdata(dev); enum usb_dr_mode dr_mode; - dr_mode = usb_get_dr_mode(dev_of_offset(dev)); + dr_mode = usb_get_dr_mode(dev->node); switch (dr_mode) { case USB_DR_MODE_HOST: diff --git a/drivers/usb/host/xhci-dwc3.c b/drivers/usb/host/xhci-dwc3.c index c1c681ca6c..9fcfa39d4b 100644 --- a/drivers/usb/host/xhci-dwc3.c +++ b/drivers/usb/host/xhci-dwc3.c @@ -9,7 +9,6 @@ #include #include -#include #include #include #include @@ -155,7 +154,7 @@ static int xhci_dwc3_probe(struct udevice *dev) writel(reg, &dwc3_reg->g_usb2phycfg[0]); - dr_mode = usb_get_dr_mode(dev_of_offset(dev)); + dr_mode = usb_get_dr_mode(dev->node); if (dr_mode == USB_DR_MODE_UNKNOWN) /* by default set dual role mode to HOST */ dr_mode = USB_DR_MODE_HOST; diff --git a/drivers/usb/musb-new/ti-musb.c b/drivers/usb/musb-new/ti-musb.c index 00759f3e83..608facefa3 100644 --- a/drivers/usb/musb-new/ti-musb.c +++ b/drivers/usb/musb-new/ti-musb.c @@ -285,14 +285,12 @@ U_BOOT_DRIVER(ti_musb_peripheral) = { #if CONFIG_IS_ENABLED(OF_CONTROL) static int ti_musb_wrapper_bind(struct udevice *parent) { - const void *fdt = gd->fdt_blob; - int node; + ofnode node; int ret; - for (node = fdt_first_subnode(fdt, dev_of_offset(parent)); node > 0; - node = fdt_next_subnode(fdt, node)) { + ofnode_for_each_subnode(node, parent->node) { struct udevice *dev; - const char *name = fdt_get_name(fdt, node, NULL); + const char *name = ofnode_get_name(node); enum usb_dr_mode dr_mode; struct driver *drv; @@ -306,7 +304,7 @@ static int ti_musb_wrapper_bind(struct udevice *parent) ret = device_bind_driver_to_node(parent, "ti-musb-peripheral", name, - offset_to_ofnode(node), + node, &dev); if (ret) pr_err("musb - not able to bind usb peripheral node\n"); @@ -316,7 +314,7 @@ static int ti_musb_wrapper_bind(struct udevice *parent) ret = device_bind_driver_to_node(parent, "ti-musb-host", name, - offset_to_ofnode(node), + node, &dev); if (ret) pr_err("musb - not able to bind usb host node\n"); diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h index d2604c5caf..c19b916be9 100644 --- a/include/linux/usb/otg.h +++ b/include/linux/usb/otg.h @@ -9,6 +9,8 @@ #ifndef __LINUX_USB_OTG_H #define __LINUX_USB_OTG_H +#include + enum usb_dr_mode { USB_DR_MODE_UNKNOWN, USB_DR_MODE_HOST, @@ -18,20 +20,20 @@ enum usb_dr_mode { /** * usb_get_dr_mode() - Get dual role mode for given device - * @node: Node offset to the given device + * @node: ofnode of the given device * * The function gets phy interface string from property 'dr_mode', * and returns the correspondig enum usb_dr_mode */ -enum usb_dr_mode usb_get_dr_mode(int node); +enum usb_dr_mode usb_get_dr_mode(ofnode node); /** * usb_get_maximum_speed() - Get maximum speed for given device - * @node: Node offset to the given device + * @node: ofnode of the given device * * The function gets phy interface string from property 'maximum-speed', * and returns the correspondig enum usb_device_speed */ -enum usb_device_speed usb_get_maximum_speed(int node); +enum usb_device_speed usb_get_maximum_speed(ofnode node); #endif /* __LINUX_USB_OTG_H */