From 159d6bf720a663b22f291dfbba337392a771d59a Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sat, 1 Apr 2023 08:24:52 +0200 Subject: sandbox: fix fall through in sandbox_flash_bulk() Handling of SANDBOX_FLASH_EP_OUT should never fall through to SANDBOX_FLASH_EP_IN. This addresses a warning shown when compiling with -Wimplicit-fallthrough. Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- drivers/usb/emul/sandbox_flash.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/usb/emul/sandbox_flash.c b/drivers/usb/emul/sandbox_flash.c index 01ccc4bc178..7c5c1ab3de7 100644 --- a/drivers/usb/emul/sandbox_flash.c +++ b/drivers/usb/emul/sandbox_flash.c @@ -266,6 +266,7 @@ static int sandbox_flash_bulk(struct udevice *dev, struct usb_device *udev, default: break; } + break; case SANDBOX_FLASH_EP_IN: switch (info->phase) { case SCSIPH_DATA: -- cgit v1.3.1 From 42175a70d1e85bf0e7949b3e27633fac0aa8d4b1 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sat, 1 Apr 2023 08:57:33 +0200 Subject: sandbox: fix sandbox_hub_submit_control_msg() Avoid incorrect fall through: A USB_RT_HUB request should not be treated as USB_RT_PORT. Simplify the coding: Avoid duplicate debug() statements. This fixes all -Wimplicit-fallthrough warnings. Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- drivers/usb/emul/sandbox_hub.c | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/drivers/usb/emul/sandbox_hub.c b/drivers/usb/emul/sandbox_hub.c index 041ec3772aa..084cc16cc68 100644 --- a/drivers/usb/emul/sandbox_hub.c +++ b/drivers/usb/emul/sandbox_hub.c @@ -220,13 +220,9 @@ static int sandbox_hub_submit_control_msg(struct udevice *bus, udev->status = 0; udev->act_len = sizeof(*hubsts); return 0; + } } - default: - debug("%s: rx ctl requesttype=%x, request=%x\n", - __func__, setup->requesttype, - setup->request); - break; - } + break; case USB_RT_PORT | USB_DIR_IN: switch (setup->request) { case USB_REQ_GET_STATUS: { @@ -239,13 +235,12 @@ static int sandbox_hub_submit_control_msg(struct udevice *bus, udev->status = 0; udev->act_len = sizeof(*portsts); return 0; + } } - } - default: - debug("%s: rx ctl requesttype=%x, request=%x\n", - __func__, setup->requesttype, setup->request); break; } + debug("%s: rx ctl requesttype=%x, request=%x\n", + __func__, setup->requesttype, setup->request); } else if (pipe == usb_sndctrlpipe(udev, 0)) { switch (setup->requesttype) { case USB_RT_PORT: @@ -263,7 +258,7 @@ static int sandbox_hub_submit_control_msg(struct udevice *bus, debug(" ** Invalid feature\n"); } return ret; - } + } case USB_REQ_CLEAR_FEATURE: { int port; @@ -279,18 +274,11 @@ static int sandbox_hub_submit_control_msg(struct udevice *bus, } udev->status = 0; return 0; + } } - default: - debug("%s: tx ctl requesttype=%x, request=%x\n", - __func__, setup->requesttype, - setup->request); - break; - } - default: - debug("%s: tx ctl requesttype=%x, request=%x\n", - __func__, setup->requesttype, setup->request); - break; } + debug("%s: tx ctl requesttype=%x, request=%x\n", + __func__, setup->requesttype, setup->request); } debug("pipe=%lx\n", pipe); -- cgit v1.3.1 From 278c9b22ba109a0c5aa946905dcd83caea85090f Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sat, 1 Apr 2023 09:38:05 +0200 Subject: sandbox: spi: sandbox_sf_process_cmd() missing fallthrough Add a missing fallthrough macro to avoid a -Wimplicit-fallthrough warning. Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- drivers/mtd/spi/sandbox.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/mtd/spi/sandbox.c b/drivers/mtd/spi/sandbox.c index 3c01e3b41c8..4fe547171a5 100644 --- a/drivers/mtd/spi/sandbox.c +++ b/drivers/mtd/spi/sandbox.c @@ -248,6 +248,7 @@ static int sandbox_sf_process_cmd(struct sandbox_spi_flash *sbsf, const u8 *rx, break; case SPINOR_OP_READ_FAST: sbsf->pad_addr_bytes = 1; + fallthrough; case SPINOR_OP_READ: case SPINOR_OP_PP: sbsf->state = SF_ADDR; -- cgit v1.3.1 From 9963b1f5b80ad3923ff5100a4b91ab1906521ff2 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sat, 1 Apr 2023 09:54:25 +0200 Subject: sandbox: mark sandbox_exit() as no return. Fix a -Wimplicit-fallthrough warning in sandbox_sysreset_request(). Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- arch/sandbox/cpu/cpu.c | 2 +- arch/sandbox/include/asm/u-boot-sandbox.h | 2 +- drivers/sysreset/sysreset_sandbox.c | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/arch/sandbox/cpu/cpu.c b/arch/sandbox/cpu/cpu.c index 248d17a85c8..51496338ad6 100644 --- a/arch/sandbox/cpu/cpu.c +++ b/arch/sandbox/cpu/cpu.c @@ -31,7 +31,7 @@ static struct udevice *map_dev; unsigned long map_len; #endif -void sandbox_exit(void) +void __noreturn sandbox_exit(void) { /* Do this here while it still has an effect */ os_fd_restore(); diff --git a/arch/sandbox/include/asm/u-boot-sandbox.h b/arch/sandbox/include/asm/u-boot-sandbox.h index 9eb19323ecf..e7027747b37 100644 --- a/arch/sandbox/include/asm/u-boot-sandbox.h +++ b/arch/sandbox/include/asm/u-boot-sandbox.h @@ -87,6 +87,6 @@ void sandbox_set_enable_pci_map(int enable); void sandbox_reset(void); /* Exit sandbox (quit U-Boot) */ -void sandbox_exit(void); +void __noreturn sandbox_exit(void); #endif /* _U_BOOT_SANDBOX_H_ */ diff --git a/drivers/sysreset/sysreset_sandbox.c b/drivers/sysreset/sysreset_sandbox.c index 0ee286cbb34..3750c60b9b9 100644 --- a/drivers/sysreset/sysreset_sandbox.c +++ b/drivers/sysreset/sysreset_sandbox.c @@ -65,7 +65,6 @@ static int sandbox_sysreset_request(struct udevice *dev, enum sysreset_t type) if (!state->sysreset_allowed[type]) return -EACCES; sandbox_exit(); - break; case SYSRESET_POWER: if (!state->sysreset_allowed[type]) return -EACCES; -- cgit v1.3.1 From 327883c3c93692cca32d20a7f59b07f5c3d0c5c8 Mon Sep 17 00:00:00 2001 From: Bin Meng Date: Mon, 3 Apr 2023 11:40:26 +0800 Subject: boot: vbe_simple: Fix vbe_simple_read_bootflow() dependency vbe_simple_read_bootflow() calls vbe_simple_read_bootflow_fw() which is only available when BOOTMETH_VBE_SIMPLE_FW is on. Signed-off-by: Bin Meng Reviewed-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- boot/vbe_simple.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/boot/vbe_simple.c b/boot/vbe_simple.c index 59676d8613f..12682abd399 100644 --- a/boot/vbe_simple.c +++ b/boot/vbe_simple.c @@ -148,11 +148,13 @@ static int vbe_simple_read_bootflow(struct udevice *dev, struct bootflow *bflow) { int ret; - if (vbe_phase() == VBE_PHASE_FIRMWARE) { - ret = vbe_simple_read_bootflow_fw(dev, bflow); - if (ret) - return log_msg_ret("fw", ret); - return 0; + if (CONFIG_IS_ENABLED(BOOTMETH_VBE_SIMPLE_FW)) { + if (vbe_phase() == VBE_PHASE_FIRMWARE) { + ret = vbe_simple_read_bootflow_fw(dev, bflow); + if (ret) + return log_msg_ret("fw", ret); + return 0; + } } return -EINVAL; -- cgit v1.3.1 From b52d6de20768ddba6b9e75d198179eca6ec66300 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Mon, 3 Apr 2023 20:46:50 +0200 Subject: common: static fdt_simplefb_enable_existing_node() Function fdt_simplefb_enable_existing_node() should be static as it is not used outside common/fdt_simplefb.c. Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- common/fdt_simplefb.c | 8 +++++++- include/fdt_simplefb.h | 1 - 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/common/fdt_simplefb.c b/common/fdt_simplefb.c index 282c34fe0b9..069ced75a7f 100644 --- a/common/fdt_simplefb.c +++ b/common/fdt_simplefb.c @@ -71,7 +71,13 @@ int fdt_simplefb_add_node(void *blob) return fdt_simplefb_configure_node(blob, off); } -int fdt_simplefb_enable_existing_node(void *blob) +/** + * fdt_simplefb_enable_existing_node() - enable simple-framebuffer DT node + * + * @blob: device-tree + * Return: 0 on success, non-zero otherwise + */ +static int fdt_simplefb_enable_existing_node(void *blob) { int off; diff --git a/include/fdt_simplefb.h b/include/fdt_simplefb.h index 41cd740ac05..af93e3be631 100644 --- a/include/fdt_simplefb.h +++ b/include/fdt_simplefb.h @@ -9,6 +9,5 @@ #ifndef _FDT_SIMPLEFB_H_ #define _FDT_SIMPLEFB_H_ int fdt_simplefb_add_node(void *blob); -int fdt_simplefb_enable_existing_node(void *blob); int fdt_simplefb_enable_and_mem_rsv(void *blob); #endif -- cgit v1.3.1 From c71ee7e163550069828b89247dd7228d35cf10c7 Mon Sep 17 00:00:00 2001 From: Andrew Davis Date: Tue, 4 Apr 2023 13:45:41 -0500 Subject: binman: Use unsigned long over typedef ulong The header binman_sym.h depends on ulong typedef but does not include types.h. This means the header must be included after including types.h or a header that includes it. We could include types.h but instead let's just switch from ulong to directly using unsigned long. This removes the need for typedef'ing it in some of the tests, so also remove those. Signed-off-by: Andrew Davis Reviewed-by: Simon Glass --- include/binman_sym.h | 8 ++++---- tools/binman/test/blob_syms.c | 2 -- tools/binman/test/u_boot_binman_syms.c | 2 -- tools/binman/test/u_boot_binman_syms_size.c | 2 -- 4 files changed, 4 insertions(+), 10 deletions(-) diff --git a/include/binman_sym.h b/include/binman_sym.h index 528d7e4e90e..49a95eafade 100644 --- a/include/binman_sym.h +++ b/include/binman_sym.h @@ -71,7 +71,7 @@ * value #defined above. This is used to check at runtime if the * symbol values were filled in and are OK to use. */ -extern ulong _binman_sym_magic; +extern unsigned long _binman_sym_magic; /** * DECLARE_BINMAN_MAGIC_SYM - Declare the internal magic symbol @@ -81,7 +81,7 @@ extern ulong _binman_sym_magic; * definitions of the symbol. */ #define DECLARE_BINMAN_MAGIC_SYM \ - ulong _binman_sym_magic \ + unsigned long _binman_sym_magic \ __attribute__((aligned(4), section(".binman_sym"))) /** @@ -93,14 +93,14 @@ extern ulong _binman_sym_magic; * Return: 1 if binman symbol values are usable, 0 if not */ #define BINMAN_SYMS_OK \ - (*(ulong *)&_binman_sym_magic == BINMAN_SYM_MAGIC_VALUE) + (*(unsigned long *)&_binman_sym_magic == BINMAN_SYM_MAGIC_VALUE) /** * binman_sym() - Access a previously declared symbol * * This is used to get the value of a symbol. E.g.: * - * ulong address = binman_sym(ulong, u_boot_spl, pos); + * unsigned long address = binman_sym(unsigned long, u_boot_spl, pos); * * @_type: Type f the symbol (e.g. unsigned long) * @entry_name: Name of the entry to look for (e.g. 'u_boot_spl') diff --git a/tools/binman/test/blob_syms.c b/tools/binman/test/blob_syms.c index d652c79aa98..1df8d64353f 100644 --- a/tools/binman/test/blob_syms.c +++ b/tools/binman/test/blob_syms.c @@ -5,8 +5,6 @@ * Simple program to create some binman symbols. This is used by binman tests. */ -typedef unsigned long ulong; - #include #include diff --git a/tools/binman/test/u_boot_binman_syms.c b/tools/binman/test/u_boot_binman_syms.c index ed761246aec..147c90230f8 100644 --- a/tools/binman/test/u_boot_binman_syms.c +++ b/tools/binman/test/u_boot_binman_syms.c @@ -5,8 +5,6 @@ * Simple program to create some binman symbols. This is used by binman tests. */ -typedef unsigned long ulong; - #include #include diff --git a/tools/binman/test/u_boot_binman_syms_size.c b/tools/binman/test/u_boot_binman_syms_size.c index fa41b3d9a33..f686892a4da 100644 --- a/tools/binman/test/u_boot_binman_syms_size.c +++ b/tools/binman/test/u_boot_binman_syms_size.c @@ -5,8 +5,6 @@ * Simple program to create some binman symbols. This is used by binman tests. */ -typedef unsigned long ulong; - #include #include -- cgit v1.3.1 From 86daa47c84ddb67d880f304b9cb22898f2687811 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Wed, 5 Apr 2023 11:26:38 +0200 Subject: MAINTAINERS: assign include/os.h os.h is only used by the sandbox. Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/MAINTAINERS b/MAINTAINERS index 0257526bc82..f752132a1fc 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1361,6 +1361,7 @@ F: arch/sandbox/ F: doc/arch/sandbox.rst F: drivers/*/*sandbox*.c F: include/dt-bindings/*/sandbox*.h +F: include/os.h SEAMA M: Linus Walleij -- cgit v1.3.1 From 1a07d395210cc0e9a114826e0b42106fd4336f46 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Wed, 5 Apr 2023 11:34:15 +0200 Subject: sandbox: fix return type of os_filesize() Given a file ../img of size 4294967296 with GPT partition table and partitions: => host bind 0 ../img => part list host 0 Disk host-0.blk not ready The cause is os_filesize() returning int. File sizes must use off_t. Correct all uses of os_filesize() too. Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- arch/sandbox/cpu/os.c | 8 ++++++-- drivers/block/host_dev.c | 3 ++- include/os.h | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c index 5e66304e2b9..9e93a0fa571 100644 --- a/arch/sandbox/cpu/os.c +++ b/arch/sandbox/cpu/os.c @@ -166,7 +166,7 @@ int os_write_file(const char *fname, const void *buf, int size) return 0; } -int os_filesize(int fd) +off_t os_filesize(int fd) { off_t size; @@ -218,7 +218,7 @@ err: int os_map_file(const char *pathname, int os_flags, void **bufp, int *sizep) { void *ptr; - int size; + off_t size; int ifd; ifd = os_open(pathname, os_flags); @@ -231,6 +231,10 @@ int os_map_file(const char *pathname, int os_flags, void **bufp, int *sizep) printf("Cannot get file size of '%s'\n", pathname); return -EIO; } + if ((unsigned long long)size > (unsigned long long)SIZE_MAX) { + printf("File '%s' too large to map\n", pathname); + return -EIO; + } ptr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, ifd, 0); if (ptr == MAP_FAILED) { diff --git a/drivers/block/host_dev.c b/drivers/block/host_dev.c index 5885fc358a5..64422417b74 100644 --- a/drivers/block/host_dev.c +++ b/drivers/block/host_dev.c @@ -24,7 +24,8 @@ static int host_sb_attach_file(struct udevice *dev, const char *filename) struct host_sb_plat *plat = dev_get_plat(dev); struct blk_desc *desc; struct udevice *blk; - int ret, fd, size; + int ret, fd; + off_t size; char *fname; if (!filename) diff --git a/include/os.h b/include/os.h index 0415f0f0e7a..968412b0a82 100644 --- a/include/os.h +++ b/include/os.h @@ -64,7 +64,7 @@ off_t os_lseek(int fd, off_t offset, int whence); * @fd: File descriptor as returned by os_open() * Return: file size or negative error code */ -int os_filesize(int fd); +off_t os_filesize(int fd); /** * Access to the OS open() system call -- cgit v1.3.1 From 7f1a4c9dd89b5bd5203988609fe3f9f9c0c0e4e8 Mon Sep 17 00:00:00 2001 From: Jorge Ramirez-Ortiz Date: Sat, 8 Apr 2023 17:35:31 +0200 Subject: drivers: tee: sandbox: Fix SCP03 control emulator Fix and document the Secure Channel Protocol03 emulator. Fixes: 5a8783c80c39 ("drivers: tee: sandbox: SCP03 control emulator") Signed-off-by: Jorge Ramirez-Ortiz Reviewed-by: Simon Glass Reviewed-by: Ilias Apalodimas --- drivers/tee/sandbox.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/tee/sandbox.c b/drivers/tee/sandbox.c index 35e8542fa37..86219a9bb1a 100644 --- a/drivers/tee/sandbox.c +++ b/drivers/tee/sandbox.c @@ -119,6 +119,7 @@ static u32 pta_scp03_invoke_func(struct udevice *dev, u32 func, uint num_params, { u32 res; static bool enabled; + static bool provisioned; switch (func) { case PTA_CMD_ENABLE_SCP03: @@ -130,12 +131,18 @@ static u32 pta_scp03_invoke_func(struct udevice *dev, u32 func, uint num_params, if (res) return res; - if (!enabled) { + /* If SCP03 was not enabled, enable it */ + if (!enabled) enabled = true; - } else { - } - if (params[0].u.value.a) + /* If SCP03 was not provisioned, provision new keys */ + if (params[0].u.value.a && !provisioned) + provisioned = true; + + /* + * Either way, we asume both operations succeeded and that + * the communication channel has now been stablished + */ return TEE_SUCCESS; default: -- cgit v1.3.1 From 86592af5369ae14fb3b273479beb430d7e88de10 Mon Sep 17 00:00:00 2001 From: Bin Meng Date: Wed, 5 Apr 2023 22:37:55 +0800 Subject: dm: core: Make aliases_lookup static aliases_lookup is only referenced in of_access.c Signed-off-by: Bin Meng Reviewed-by: Simon Glass --- drivers/core/of_access.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/core/of_access.c b/drivers/core/of_access.c index 85f7da5a499..81a307992c0 100644 --- a/drivers/core/of_access.c +++ b/drivers/core/of_access.c @@ -33,7 +33,7 @@ DECLARE_GLOBAL_DATA_PTR; /* list of struct alias_prop aliases */ -LIST_HEAD(aliases_lookup); +static LIST_HEAD(aliases_lookup); /* "/aliaes" node */ static struct device_node *of_aliases; -- cgit v1.3.1 From e0dda26c2e9fb4150a5ab0b8b5ad58da5dd355cd Mon Sep 17 00:00:00 2001 From: Tom Rini Date: Thu, 6 Apr 2023 10:03:33 -0400 Subject: bootflow: Rework do_bootflow_menu() slightly When building this with clang, we get a warning such as: cmd/bootflow.c:412:27: warning: variable 'bflow' is uninitialized when used here [-Wuninitialized] printf("Selected: %s\n", bflow->os_name ? bflow->os_name : bflow->name); ^~~~~ And a suggestion to just initialize bflow to NULL. This would however would be ensuring a bad dereference. Instead, looking at the function we rework things so that when CONFIG_EXPO is not enabled (and so, no UI) we error early and would never reach this point in the code. Simplify the rest slightly as well while at this. Signed-off-by: Tom Rini Reviewed-by: Simon Glass --- cmd/bootflow.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/cmd/bootflow.c b/cmd/bootflow.c index aa06999e3db..cfe34226989 100644 --- a/cmd/bootflow.c +++ b/cmd/bootflow.c @@ -390,6 +390,11 @@ static int do_bootflow_menu(struct cmd_tbl *cmdtp, int flag, int argc, bool text_mode = false; int ret; + if (!IS_ENABLED(CONFIG_EXPO)) { + printf("Menu not supported\n"); + return CMD_RET_FAILURE; + } + if (argc > 1 && *argv[1] == '-') text_mode = strchr(argv[1], 't'); @@ -397,20 +402,15 @@ static int do_bootflow_menu(struct cmd_tbl *cmdtp, int flag, int argc, if (ret) return CMD_RET_FAILURE; - if (IS_ENABLED(CONFIG_EXPO)) { - ret = bootflow_menu_run(std, text_mode, &bflow); - if (ret) { - if (ret == -EAGAIN) - printf("Nothing chosen\n"); - else - printf("Menu failed (err=%d)\n", ret); + ret = bootflow_menu_run(std, text_mode, &bflow); + if (ret) { + if (ret == -EAGAIN) + printf("Nothing chosen\n"); + else { + printf("Menu failed (err=%d)\n", ret); + return CMD_RET_FAILURE; } - } else { - printf("Menu not supported\n"); - ret = -ENOSYS; } - if (ret) - return CMD_RET_FAILURE; printf("Selected: %s\n", bflow->os_name ? bflow->os_name : bflow->name); std->cur_bootflow = bflow; -- cgit v1.3.1 From c383e85434f1f278a55134213cd1b7125185c429 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Mon, 17 Apr 2023 09:08:56 +0200 Subject: sandbox: correct posix_types.h define arch/arm/include/asm/posix_types.h and arch/sandbox/include/asm/posix_types.h should use different defines. Add SPDX header. Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- arch/sandbox/include/asm/posix_types.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/arch/sandbox/include/asm/posix_types.h b/arch/sandbox/include/asm/posix_types.h index ec18ed7e3c2..e1442c455bd 100644 --- a/arch/sandbox/include/asm/posix_types.h +++ b/arch/sandbox/include/asm/posix_types.h @@ -1,5 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0 */ /* - * linux/include/asm-arm/posix_types.h + * Based on linux/include/asm-arm/posix_types.h * * Copyright (C) 1996-1998 Russell King. * @@ -10,8 +11,8 @@ * Changelog: * 27-06-1996 RMK Created */ -#ifndef __ARCH_ARM_POSIX_TYPES_H -#define __ARCH_ARM_POSIX_TYPES_H +#ifndef __ARCH_SANDBOX_POSIX_TYPES_H +#define __ARCH_SANDBOX_POSIX_TYPES_H /* * This file is generally used by user-level software, so you need to -- cgit v1.3.1 From 763f0a1f0d2b3ee0b3f7248dee874c3e65e93345 Mon Sep 17 00:00:00 2001 From: Pavel Skripkin Date: Wed, 12 Apr 2023 21:55:44 +0300 Subject: sandbox: disable tracing before unmapping RAM Currently doing 'reset' command in sandbox with tracing enabled causes SIGSEV ``` Hit any key to stop autoboot: 0 => => => reset resetting ... Segmentation fault (core dumped) ``` Tracing callback uses RAM buffer for storing tracing reports, but state_uninit() function unmaps whole RAM, which causes SIGSEV on umapped memory inside tracing subsystem. Fix it by disabling tracing before unmapping memory Signed-off-by: Pavel Skripkin Reviewed-by: Simon Glass Add missing check for CONFIG_TRACE: Signed-off-by: Simon Glass --- arch/sandbox/cpu/state.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/sandbox/cpu/state.c b/arch/sandbox/cpu/state.c index 69da378ab59..d67834988fd 100644 --- a/arch/sandbox/cpu/state.c +++ b/arch/sandbox/cpu/state.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -525,6 +526,10 @@ int state_uninit(void) if (state->jumped_fname) os_unlink(state->jumped_fname); + /* Disable tracing before unmapping RAM */ + if (IS_ENABLED(CONFIG_TRACE)) + trace_set_enabled(0); + os_free(state->state_fdt); os_free(state->ram_buf); memset(state, '\0', sizeof(*state)); -- cgit v1.3.1 From 6ebb357a6a16fe4b61fae3866f80b967e8231f7e Mon Sep 17 00:00:00 2001 From: Rasmus Villemoes Date: Thu, 13 Apr 2023 17:16:11 +0200 Subject: uclass: add uclass_find_device_by_phandle_id() helper The functions uclass_find_device_by_phandle() and uclass_get_device_by_phandle_id() both loop over a given uclass looking for a device with a given phandle. Factor that out to a common helper. For now, there are no (known potential) users of the new helper outside uclass.c, so make it static. Signed-off-by: Rasmus Villemoes Reviewed-by: Simon Glass Fix warning on sandbox_spl; fix code style: Signed-off-by: Simon Glass --- drivers/core/uclass.c | 44 +++++++++++++++++++------------------------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c index 1762a0796db..009de74025b 100644 --- a/drivers/core/uclass.c +++ b/drivers/core/uclass.c @@ -411,18 +411,14 @@ done: } #if CONFIG_IS_ENABLED(OF_REAL) -int uclass_find_device_by_phandle(enum uclass_id id, struct udevice *parent, - const char *name, struct udevice **devp) +static int uclass_find_device_by_phandle_id(enum uclass_id id, + uint find_phandle, + struct udevice **devp) { struct udevice *dev; struct uclass *uc; - int find_phandle; int ret; - *devp = NULL; - find_phandle = dev_read_u32_default(parent, name, -1); - if (find_phandle <= 0) - return -ENOENT; ret = uclass_get(id, &uc); if (ret) return ret; @@ -440,6 +436,19 @@ int uclass_find_device_by_phandle(enum uclass_id id, struct udevice *parent, return -ENODEV; } + +int uclass_find_device_by_phandle(enum uclass_id id, struct udevice *parent, + const char *name, struct udevice **devp) +{ + int find_phandle; + + *devp = NULL; + find_phandle = dev_read_u32_default(parent, name, -1); + if (find_phandle <= 0) + return -ENOENT; + + return uclass_find_device_by_phandle_id(id, find_phandle, devp); +} #endif int uclass_get_device_by_driver(enum uclass_id id, @@ -535,31 +544,16 @@ int uclass_get_device_by_ofnode(enum uclass_id id, ofnode node, return uclass_get_device_tail(dev, ret, devp); } -#if CONFIG_IS_ENABLED(OF_CONTROL) +#if CONFIG_IS_ENABLED(OF_REAL) int uclass_get_device_by_phandle_id(enum uclass_id id, uint phandle_id, struct udevice **devp) { struct udevice *dev; - struct uclass *uc; int ret; *devp = NULL; - ret = uclass_get(id, &uc); - if (ret) - return ret; - - uclass_foreach_dev(dev, uc) { - uint phandle; - - phandle = dev_read_phandle(dev); - - if (phandle == phandle_id) { - *devp = dev; - return uclass_get_device_tail(dev, ret, devp); - } - } - - return -ENODEV; + ret = uclass_find_device_by_phandle_id(id, phandle_id, &dev); + return uclass_get_device_tail(dev, ret, devp); } int uclass_get_device_by_phandle(enum uclass_id id, struct udevice *parent, -- cgit v1.3.1 From ca031c082700631264d1e058f2f705438c2be8c2 Mon Sep 17 00:00:00 2001 From: Rasmus Villemoes Date: Thu, 13 Apr 2023 17:17:03 +0200 Subject: dm: core: introduce uclass_get_device_by_of_path() There's quite a few instances of board-specific code doing off = fdt_path_offset(gd->fdt_blob, ...); ... ret = uclass_get_device_by_of_offset(..., off, &dev); looking for an eeprom or a pmic via some alias. Such code can be simplified a little if we have a helper for directly getting a device via device tree path (including being given as an alias). Implement it in terms of ofnode rather than raw offsets so that this will work whether live tree is enabled or not. Signed-off-by: Rasmus Villemoes --- drivers/core/uclass.c | 6 ++++++ include/dm/uclass.h | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c index 009de74025b..e46d5717aa6 100644 --- a/drivers/core/uclass.c +++ b/drivers/core/uclass.c @@ -545,6 +545,12 @@ int uclass_get_device_by_ofnode(enum uclass_id id, ofnode node, } #if CONFIG_IS_ENABLED(OF_REAL) +int uclass_get_device_by_of_path(enum uclass_id id, const char *path, + struct udevice **devp) +{ + return uclass_get_device_by_ofnode(id, ofnode_path(path), devp); +} + int uclass_get_device_by_phandle_id(enum uclass_id id, uint phandle_id, struct udevice **devp) { diff --git a/include/dm/uclass.h b/include/dm/uclass.h index ee15c920633..5c5fb9acac0 100644 --- a/include/dm/uclass.h +++ b/include/dm/uclass.h @@ -264,6 +264,23 @@ int uclass_get_device_by_of_offset(enum uclass_id id, int node, int uclass_get_device_by_ofnode(enum uclass_id id, ofnode node, struct udevice **devp); +/** + * uclass_get_device_by_of_path() - Get a uclass device by device tree path + * + * This searches the devices in the uclass for one attached to the + * device tree node corresponding to the given path (which may also be + * an alias). + * + * The device is probed to activate it ready for use. + * + * @id: ID to look up + * @node: Device tree path to search for (if no such path then -ENODEV is returned) + * @devp: Returns pointer to device (there is only one for each node) + * Return: 0 if OK, -ve on error + */ +int uclass_get_device_by_of_path(enum uclass_id id, const char *path, + struct udevice **devp); + /** * uclass_get_device_by_phandle_id() - Get a uclass device by phandle id * -- cgit v1.3.1 From ad827e15b22ad370b5e548c12f58efcedf657740 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 19 Apr 2023 15:21:14 -0600 Subject: binman: Use expanduser instead of HOME There may not be a HOME environment variable, so use the os.expanduser() function instead. Signed-off-by: Simon Glass --- tools/binman/cmdline.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/binman/cmdline.py b/tools/binman/cmdline.py index 4b875a9dcda..9632ec115e5 100644 --- a/tools/binman/cmdline.py +++ b/tools/binman/cmdline.py @@ -95,7 +95,7 @@ controlled by a description in the board device tree.''' parser.add_argument('-H', '--full-help', action='store_true', default=False, help='Display the README file') parser.add_argument('--tooldir', type=str, - default=os.path.join(os.getenv('HOME'), '.binman-tools'), + default=os.path.join(os.path.expanduser('~/.binman-tools')), help='Set the directory to store tools') parser.add_argument('--toolpath', type=str, action='append', help='Add a path to the list of directories containing tools') -- cgit v1.3.1 From c25be4f3ace634f132e92ae651ed9fbd2aa44171 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Thu, 20 Apr 2023 20:07:29 +0200 Subject: patman: fix class TestFunctional Variable orig_dir cannot be used in the finally block if it has not be assigned outside of the try block. tools/patman/func_test.py:523:21: E0601: Using variable 'orig_dir' before assignment (used-before-assignment) tools/patman/func_test.py:691:21: E0601: Using variable 'orig_dir' before assignment (used-before-assignment) Fixes: fd70986a62af ("patman: Add a test that uses gitpython") Fixes: be051c0c7741 ("patman: Detect missing upstream in CountCommitsToBranch") Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- tools/patman/func_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/patman/func_test.py b/tools/patman/func_test.py index 42ac4ed77b7..e3918497cf4 100644 --- a/tools/patman/func_test.py +++ b/tools/patman/func_test.py @@ -489,8 +489,8 @@ complicated as possible''') # pylint: disable=E1101 self.repo.checkout(target, strategy=pygit2.GIT_CHECKOUT_FORCE) control.setup() + orig_dir = os.getcwd() try: - orig_dir = os.getcwd() os.chdir(self.gitdir) # Check that it can detect the current branch @@ -679,8 +679,8 @@ diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c self.repo.checkout(target, strategy=pygit2.GIT_CHECKOUT_FORCE) # Check that it can detect the current branch + orig_dir = os.getcwd() try: - orig_dir = os.getcwd() os.chdir(self.gitdir) with self.assertRaises(ValueError) as exc: gitutil.count_commits_to_branch(None) -- cgit v1.3.1 From f53e973b84d5b60439c8f0cc98099c020b3ab83a Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Sat, 22 Apr 2023 14:59:58 +0200 Subject: test: fdt: Fix copyright message Drop the map_to_sysmem() copy paste error. No functional change. Signed-off-by: Marek Vasut Reviewed-by: Simon Glass --- test/cmd/fdt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c index 7835da232d5..1f103a1d7eb 100644 --- a/test/cmd/fdt.c +++ b/test/cmd/fdt.c @@ -2,7 +2,7 @@ /* * Tests for fdt command * - * Copyright 2022 Google LLCmap_to_sysmem(fdt)); + * Copyright 2022 Google LLC */ #include -- cgit v1.3.1 From de65b122a2534a5bc61f7714f10125baee5d58f3 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Sat, 22 Apr 2023 16:42:48 +0200 Subject: tools: Fall back to importlib_resources on Python 3.6 importlib.resources became part of 3.7 only. Allow using distros with 3.6 and the importlib_resources backport. Signed-off-by: Jan Kiszka Reviewed-by: Simon Glass --- tools/binman/control.py | 6 +++++- tools/buildman/control.py | 6 +++++- tools/patman/__main__.py | 6 +++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/tools/binman/control.py b/tools/binman/control.py index 0febcb79a60..68597c4e779 100644 --- a/tools/binman/control.py +++ b/tools/binman/control.py @@ -7,7 +7,11 @@ from collections import OrderedDict import glob -import importlib.resources +try: + import importlib.resources +except ImportError: + # for Python 3.6 + import importlib_resources import os import pkg_resources import re diff --git a/tools/buildman/control.py b/tools/buildman/control.py index 35f44c0cf3d..09a11f25b3f 100644 --- a/tools/buildman/control.py +++ b/tools/buildman/control.py @@ -3,7 +3,11 @@ # import multiprocessing -import importlib.resources +try: + import importlib.resources +except ImportError: + # for Python 3.6 + import importlib_resources import os import shutil import subprocess diff --git a/tools/patman/__main__.py b/tools/patman/__main__.py index 48ffbc8eadf..8eba5d34864 100755 --- a/tools/patman/__main__.py +++ b/tools/patman/__main__.py @@ -7,7 +7,11 @@ """See README for more information""" from argparse import ArgumentParser -import importlib.resources +try: + import importlib.resources +except ImportError: + # for Python 3.6 + import importlib_resources import os import re import sys -- cgit v1.3.1 From 37937aba3518ed782fdaae9d3772c59fd1e05af8 Mon Sep 17 00:00:00 2001 From: Johan Jonker Date: Sun, 23 Apr 2023 11:19:41 +0200 Subject: core: fdtaddr: use map_sysmem() as cast for the return For the devfdt_get_addr_index_ptr() and devfdt_get_addr_size_index_ptr() function use map_sysmem() function as cast for the return for use in sandbox. Also fix sandbox test. Signed-off-by: Johan Jonker Reviewed-by: Simon Glass Drop second hunk: Signed-off-by: Simon Glass --- drivers/core/fdtaddr.c | 6 +++++- test/dm/test-fdt.c | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/core/fdtaddr.c b/drivers/core/fdtaddr.c index 91bcd1a2c21..b9b0c28852f 100644 --- a/drivers/core/fdtaddr.c +++ b/drivers/core/fdtaddr.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -97,7 +98,10 @@ void *devfdt_get_addr_index_ptr(const struct udevice *dev, int index) { fdt_addr_t addr = devfdt_get_addr_index(dev, index); - return (addr == FDT_ADDR_T_NONE) ? NULL : (void *)(uintptr_t)addr; + if (addr == FDT_ADDR_T_NONE) + return NULL; + + return map_sysmem(addr, 0); } fdt_addr_t devfdt_get_addr_size_index(const struct udevice *dev, int index, diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c index 8e6e42e46b4..eeecd1dc2de 100644 --- a/test/dm/test-fdt.c +++ b/test/dm/test-fdt.c @@ -617,6 +617,7 @@ static int dm_test_fdt_get_addr_ptr_flat(struct unit_test_state *uts) { struct udevice *gpio, *dev; void *ptr; + void *paddr; /* Test for missing reg property */ ut_assertok(uclass_first_device_err(UCLASS_GPIO, &gpio)); @@ -624,7 +625,9 @@ static int dm_test_fdt_get_addr_ptr_flat(struct unit_test_state *uts) ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, &dev)); ptr = devfdt_get_addr_ptr(dev); - ut_asserteq_ptr((void *)0x8000, ptr); + + paddr = map_sysmem(0x8000, 0); + ut_asserteq_ptr(paddr, ptr); return 0; } -- cgit v1.3.1 From ded112f24ca4078fa09dae181108f233657ec5fc Mon Sep 17 00:00:00 2001 From: Hugo Villeneuve Date: Mon, 24 Apr 2023 16:51:50 -0400 Subject: fdt_support: fix comments syntax error Fix comments syntax error in fdt_node_offset_by_compat_reg() description: compatiable -> compatible Signed-off-by: Hugo Villeneuve Reviewed-by: Simon Glass --- common/fdt_support.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/fdt_support.c b/common/fdt_support.c index dbceec6f2dc..2053fe3bad8 100644 --- a/common/fdt_support.c +++ b/common/fdt_support.c @@ -1486,11 +1486,11 @@ out: } /** - * fdt_node_offset_by_compat_reg: Find a node that matches compatiable and + * fdt_node_offset_by_compat_reg: Find a node that matches compatible and * who's reg property matches a physical cpu address * * @blob: ptr to device tree - * @compat: compatiable string to match + * @compat: compatible string to match * @compat_off: property name * */ -- cgit v1.3.1 From f43fc16812487289e98389f0f643d20c444f9c9c Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 25 Apr 2023 10:27:21 -0600 Subject: fdt: Indicate that people should use the ofnode API Add a note to the comment at the top of this file. Signed-off-by: Simon Glass --- lib/fdtdec.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/fdtdec.c b/lib/fdtdec.c index 0827e16859f..55cc95db5d0 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -1,6 +1,9 @@ // SPDX-License-Identifier: GPL-2.0+ /* * Copyright (c) 2011 The Chromium OS Authors. + * + * NOTE: Please do not add new devicetree-reading functionality into this file. + * Add it to the ofnode API instead, since that is compatible with livetree. */ #ifndef USE_HOSTCC -- cgit v1.3.1