From 05a7cabf5b86fb283c887309746d98e416edcc64 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 18 Jul 2021 14:14:23 -0600 Subject: [PATCH 1/9] pci: swap_case: Allow compilation on 32-bit machines At present this driver assumes that ulong is 64-bits long. On 32-bit machines it is not. Use the 64-bit code only on 64-bit machines. This makes things work correctly on 32-bit machines. Signed-off-by: Simon Glass --- drivers/misc/swap_case.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/misc/swap_case.c b/drivers/misc/swap_case.c index 3cbc8f37ec5..7093ad1cd4f 100644 --- a/drivers/misc/swap_case.c +++ b/drivers/misc/swap_case.c @@ -302,7 +302,6 @@ static int sandbox_swap_case_write_io(struct udevice *dev, unsigned int addr, } static int pci_ea_bar2_magic = PCI_EA_BAR2_MAGIC; -static int pci_ea_bar4_magic = PCI_EA_BAR4_MAGIC; static int sandbox_swap_case_map_physmem(struct udevice *dev, phys_addr_t addr, unsigned long *lenp, void **ptrp) @@ -332,12 +331,22 @@ static int sandbox_swap_case_map_physmem(struct udevice *dev, *ptrp = &pci_ea_bar2_magic; *lenp = PCI_CAP_EA_SIZE_LO; break; +#ifdef CONFIG_HOST_64BIT + /* + * This cannot be work on a 32-bit machine since *lenp is ulong + * which is 32-bits, but it needs to have a 64-bit value + * assigned + */ case (phys_addr_t)((PCI_CAP_EA_BASE_HI4 << 32) | - PCI_CAP_EA_BASE_LO4): + PCI_CAP_EA_BASE_LO4): { + static int pci_ea_bar4_magic = PCI_EA_BAR4_MAGIC; + *ptrp = &pci_ea_bar4_magic; *lenp = (PCI_CAP_EA_SIZE_HI << 32) | PCI_CAP_EA_SIZE_LO; break; + } +#endif default: return -ENOENT; } From 6a2626a9d0f69b2e1158edc63319e43892600e9e Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 18 Jul 2021 14:14:24 -0600 Subject: [PATCH 2/9] doc: sandbox: Fix up dependencies These are out of date. Update them and point to the existing build instructions to avoid duplication. Add a few that are missing. Signed-off-by: Simon Glass --- doc/arch/sandbox.rst | 6 +----- doc/build/gcc.rst | 6 ++++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/doc/arch/sandbox.rst b/doc/arch/sandbox.rst index 9e23e1618c7..f8804e1f414 100644 --- a/doc/arch/sandbox.rst +++ b/doc/arch/sandbox.rst @@ -43,11 +43,7 @@ Note that standalone/API support is not available at present. Prerequisites ------------- -Here are some packages that are worth installing if you are doing sandbox or -tools development in U-Boot: - - python3-pytest lzma lzma-alone lz4 python3 python3-virtualenv - libssl1.0-dev +Install the dependencies noted in :doc:`../build/gcc`. Basic Operation diff --git a/doc/build/gcc.rst b/doc/build/gcc.rst index c51b3e73b83..8ffb4e3447b 100644 --- a/doc/build/gcc.rst +++ b/doc/build/gcc.rst @@ -26,8 +26,10 @@ Depending on the build targets further packages maybe needed sudo apt-get install bc bison build-essential coccinelle \ device-tree-compiler dfu-util efitools flex gdisk liblz4-tool \ libguestfs-tools libncurses-dev libpython3-dev libsdl2-dev libssl-dev \ - lzma-alone openssl python3 python3-coverage python3-pyelftools \ - python3-pytest python3-sphinxcontrib.apidoc python3-sphinx-rtd-theme swig + lz4 lzma lzma-alone openssl python3 python3-coverage \ + python3-pycryptodome python3-pyelftools python3-pytest \ + python3-sphinxcontrib.apidoc python3-sphinx-rtd-theme python3-virtualenv \ + swig SUSE based ~~~~~~~~~~ From 558e699d156ebe7f0b51e05a2e38f35fbaa78b0f Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Mon, 19 Jul 2021 11:21:50 +0200 Subject: [PATCH 3/9] arm: use the correct prototype for reset_cpu function Align reset_cpu function with the next prototypes in sysreset.h or in cpu_func.h to solve compilation issue: void reset_cpu(void); This patch solves the prototype conflict when cpu_func.h is included. Signed-off-by: Patrick Delaunay --- arch/arm/mach-mediatek/mt8183/init.c | 2 +- board/congatec/cgtqmx8/cgtqmx8.c | 2 +- board/hoperun/hihope-rzg2/hihope-rzg2.c | 2 +- board/silinux/ek874/ek874.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/arm/mach-mediatek/mt8183/init.c b/arch/arm/mach-mediatek/mt8183/init.c index 877f387102d..7496029705f 100644 --- a/arch/arm/mach-mediatek/mt8183/init.c +++ b/arch/arm/mach-mediatek/mt8183/init.c @@ -48,7 +48,7 @@ int mtk_soc_early_init(void) return 0; } -void reset_cpu(ulong addr) +void reset_cpu(void) { psci_system_reset(); } diff --git a/board/congatec/cgtqmx8/cgtqmx8.c b/board/congatec/cgtqmx8/cgtqmx8.c index fb0cf091389..a50a052df76 100644 --- a/board/congatec/cgtqmx8/cgtqmx8.c +++ b/board/congatec/cgtqmx8/cgtqmx8.c @@ -374,7 +374,7 @@ void detail_board_ddr_info(void) /* * Board specific reset that is system reset. */ -void reset_cpu(ulong addr) +void reset_cpu(void) { /* TODO */ } diff --git a/board/hoperun/hihope-rzg2/hihope-rzg2.c b/board/hoperun/hihope-rzg2/hihope-rzg2.c index c1bfdcbc1d1..c1db387b275 100644 --- a/board/hoperun/hihope-rzg2/hihope-rzg2.c +++ b/board/hoperun/hihope-rzg2/hihope-rzg2.c @@ -65,7 +65,7 @@ int board_init(void) return 0; } -void reset_cpu(ulong addr) +void reset_cpu(void) { unsigned long midr, cputype; diff --git a/board/silinux/ek874/ek874.c b/board/silinux/ek874/ek874.c index 5a219cd98d7..1e948489f36 100644 --- a/board/silinux/ek874/ek874.c +++ b/board/silinux/ek874/ek874.c @@ -24,7 +24,7 @@ int board_init(void) return 0; } -void reset_cpu(ulong addr) +void reset_cpu(void) { writel(RST_CA53_CODE, RST_CA53RESCNT); } From 268f6ac1f95c1734e7eea369e93062e52c4aa04a Mon Sep 17 00:00:00 2001 From: Patrice Chotard Date: Mon, 19 Jul 2021 11:21:51 +0200 Subject: [PATCH 4/9] arm64: Update memcpy_{from, to}io() helpers At early U-Boot stage, before relocation, MMU is not yet configured and disabled. DDR may not be configured with the correct memory attributes (can be configured in MT_DEVICE instead of MT_MEMORY). In this case, usage of memcpy_{from, to}io() may leads to synchronous abort in AARCH64 in case the normal memory address is not 64Bits aligned. To avoid such situation, forbid usage of normal memory cast to (u64 *) in case MMU is not enabled. Signed-off-by: Patrice Chotard Reviewed-by: Patrick Delaunay Cc: mark.kettenis@xs4all.nl Signed-off-by: Patrick Delaunay --- arch/arm/cpu/armv8/cache_v8.c | 10 ++++++++++ arch/arm/include/asm/io.h | 25 +++++++++++++++---------- include/cpu_func.h | 1 + 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/arch/arm/cpu/armv8/cache_v8.c b/arch/arm/cpu/armv8/cache_v8.c index 15cecb5e0b3..3de18c7675b 100644 --- a/arch/arm/cpu/armv8/cache_v8.c +++ b/arch/arm/cpu/armv8/cache_v8.c @@ -719,6 +719,11 @@ int icache_status(void) return (get_sctlr() & CR_I) != 0; } +int mmu_status(void) +{ + return (get_sctlr() & CR_M) != 0; +} + void invalidate_icache_all(void) { __asm_invalidate_icache_all(); @@ -740,6 +745,11 @@ int icache_status(void) return 0; } +int mmu_status(void) +{ + return 0; +} + void invalidate_icache_all(void) { } diff --git a/arch/arm/include/asm/io.h b/arch/arm/include/asm/io.h index df264a170b2..36b840378a9 100644 --- a/arch/arm/include/asm/io.h +++ b/arch/arm/include/asm/io.h @@ -338,6 +338,7 @@ extern void __readwrite_bug(const char *fn); /* Optimized copy functions to read from/write to IO sapce */ #ifdef CONFIG_ARM64 +#include /* * Copy data from IO memory space to "real" memory space. */ @@ -351,11 +352,13 @@ void __memcpy_fromio(void *to, const volatile void __iomem *from, size_t count) count--; } - while (count >= 8) { - *(u64 *)to = __raw_readq(from); - from += 8; - to += 8; - count -= 8; + if (mmu_status()) { + while (count >= 8) { + *(u64 *)to = __raw_readq(from); + from += 8; + to += 8; + count -= 8; + } } while (count) { @@ -379,11 +382,13 @@ void __memcpy_toio(volatile void __iomem *to, const void *from, size_t count) count--; } - while (count >= 8) { - __raw_writeq(*(u64 *)from, to); - from += 8; - to += 8; - count -= 8; + if (mmu_status()) { + while (count >= 8) { + __raw_writeq(*(u64 *)from, to); + from += 8; + to += 8; + count -= 8; + } } while (count) { diff --git a/include/cpu_func.h b/include/cpu_func.h index c3a66f04059..23cd5eca398 100644 --- a/include/cpu_func.h +++ b/include/cpu_func.h @@ -59,6 +59,7 @@ int dcache_status(void); void dcache_enable(void); void dcache_disable(void); void mmu_disable(void); +int mmu_status(void); /* arch/$(ARCH)/lib/cache.c */ void enable_caches(void); From 0eadb2b2da9ef7fccd39b22487a1de581f37330a Mon Sep 17 00:00:00 2001 From: Thomas Perrot Date: Mon, 19 Jul 2021 16:04:44 +0200 Subject: [PATCH 5/9] lib: rsa: rsa-verify: Fix a typo in a debug message Signed-off-by: Thomas Perrot --- lib/rsa/rsa-verify.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rsa/rsa-verify.c b/lib/rsa/rsa-verify.c index bb8cc61d94b..3840764e420 100644 --- a/lib/rsa/rsa-verify.c +++ b/lib/rsa/rsa-verify.c @@ -556,7 +556,7 @@ int rsa_verify(struct image_sign_info *info, */ if (info->checksum->checksum_len > info->crypto->key_len) { - debug("%s: invlaid checksum-algorithm %s for %s\n", + debug("%s: invalid checksum-algorithm %s for %s\n", __func__, info->checksum->name, info->crypto->name); return -EINVAL; } From 6d59ace988fdc1bb9f52ab70e21af0d40380c3f3 Mon Sep 17 00:00:00 2001 From: "Chan, Donald" Date: Mon, 19 Jul 2021 09:18:54 -0700 Subject: [PATCH 6/9] lib: rsa: rsa-sign: Minor bug in debug message *sig_size isn't set until later so use the correct variables. Signed-off-by: Donald Chan Reviewed-by: Simon Glass --- lib/rsa/rsa-sign.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rsa/rsa-sign.c b/lib/rsa/rsa-sign.c index f4ed11e74a4..c64deac31f4 100644 --- a/lib/rsa/rsa-sign.c +++ b/lib/rsa/rsa-sign.c @@ -473,7 +473,7 @@ static int rsa_sign_with_key(EVP_PKEY *pkey, struct padding_algo *padding_algo, #endif EVP_MD_CTX_destroy(context); - debug("Got signature: %d bytes, expected %zu\n", *sig_size, size); + debug("Got signature: %zu bytes, expected %d\n", size, EVP_PKEY_size(pkey)); *sigp = sig; *sig_size = size; From ff7852d5442ab48c71cce69e19bac3d6a5183496 Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Wed, 21 Jul 2021 09:56:07 +0200 Subject: [PATCH 7/9] build: remove the variable NM in gen_ll_addressable_symbols.sh With LTO activated, the buildman tools failed with an error on my configuration (Ubuntu 20.04, stm32mp15_trusted_defconfig) with the error: ../arm-linux-gnueabi/bin/nm: scripts/gen_ll_addressable_symbols.sh: file format not recognized It seems the shell variable initialization NM=$(NM) is not correctly interpreted when shell is started in the Makefile, but I have not this issue when I compile the same target without buildman. I don't found the root reason of the problem but I solve it by providing $(NM) as script parameter instead using a shell variable. The command executed is identical: cmd_keep-syms-lto.c := NM=arm-none-linux-gnueabihf-gcc-nm \ u-boot/scripts/gen_ll_addressable_symbols.sh arch/arm/cpu/built-in.o \ .... net/built-in.o >keep-syms-lto.c cmd_keep-syms-lto.c := u-boot/scripts/gen_ll_addressable_symbols.sh \ arm-none-linux-gnueabihf-gcc-nm arch/arm/cpu/built-in.o \ ... net/built-in.o > keep-syms-lto.c Reviewed-by: Simon Glass Signed-off-by: Patrick Delaunay --- Makefile | 2 +- scripts/Makefile.spl | 2 +- scripts/gen_ll_addressable_symbols.sh | 5 ++++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index b4ae66b2014..8c84c22b722 100644 --- a/Makefile +++ b/Makefile @@ -1735,7 +1735,7 @@ u-boot-keep-syms-lto_c := $(patsubst %.o,%.c,$(u-boot-keep-syms-lto)) quiet_cmd_keep_syms_lto = KSL $@ cmd_keep_syms_lto = \ - NM=$(NM) $(srctree)/scripts/gen_ll_addressable_symbols.sh $^ >$@ + $(srctree)/scripts/gen_ll_addressable_symbols.sh $(NM) $^ > $@ quiet_cmd_keep_syms_lto_cc = KSLCC $@ cmd_keep_syms_lto_cc = \ diff --git a/scripts/Makefile.spl b/scripts/Makefile.spl index 5be1a9ba1b1..25a3e7fa52e 100644 --- a/scripts/Makefile.spl +++ b/scripts/Makefile.spl @@ -459,7 +459,7 @@ u-boot-spl-keep-syms-lto_c := \ quiet_cmd_keep_syms_lto = KSL $@ cmd_keep_syms_lto = \ - NM=$(NM) $(srctree)/scripts/gen_ll_addressable_symbols.sh $^ >$@ + $(srctree)/scripts/gen_ll_addressable_symbols.sh $(NM) $^ > $@ quiet_cmd_keep_syms_lto_cc = KSLCC $@ cmd_keep_syms_lto_cc = \ diff --git a/scripts/gen_ll_addressable_symbols.sh b/scripts/gen_ll_addressable_symbols.sh index 3978a39d970..b8840dd0113 100755 --- a/scripts/gen_ll_addressable_symbols.sh +++ b/scripts/gen_ll_addressable_symbols.sh @@ -5,8 +5,11 @@ # Generate __ADDRESSABLE(symbol) for every linker list entry symbol, so that LTO # does not optimize these symbols away +# The expected parameter of this script is the command requested to have +# the U-Boot symbols to parse, for example: $(NM) $(u-boot-main) + set -e echo '#include ' -$NM "$@" 2>/dev/null | grep -oe '_u_boot_list_2_[a-zA-Z0-9_]*_2_[a-zA-Z0-9_]*' | \ +$@ 2>/dev/null | grep -oe '_u_boot_list_2_[a-zA-Z0-9_]*_2_[a-zA-Z0-9_]*' | \ sort -u | sed -e 's/^\(.*\)/extern char \1[];\n__ADDRESSABLE(\1);/' From 89795ef3b6b2d12cffb840a98ee374d2e806aa64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Beh=C3=BAn?= Date: Thu, 22 Jul 2021 22:52:05 +0200 Subject: [PATCH 8/9] test/py: Improve check for mksquashfs version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some builds of squashfs-tools append version string with "-git" or similar. The float() conversion will fail in this case. Improve the code to only convert to float() the string before the '-' character. Signed-off-by: Marek BehĂșn Reviewed-by: Simon Glass Reviewed-by: Joao Marcos Costa --- test/py/tests/test_fs/test_squashfs/sqfs_common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/py/tests/test_fs/test_squashfs/sqfs_common.py b/test/py/tests/test_fs/test_squashfs/sqfs_common.py index 267c4b57d1b..8b84c2cdca8 100644 --- a/test/py/tests/test_fs/test_squashfs/sqfs_common.py +++ b/test/py/tests/test_fs/test_squashfs/sqfs_common.py @@ -146,7 +146,7 @@ def get_mksquashfs_version(): out = subprocess.run(['mksquashfs -version'], shell=True, check=True, capture_output=True, text=True) # 'out' is: mksquashfs version X (yyyy/mm/dd) ... - return float(out.stdout.split()[2]) + return float(out.stdout.split()[2].split('-')[0]) def check_mksquashfs_version(): """ Checks if mksquashfs meets the required version. """ From 62b27a561c2868d95445905ad554297e43cc0f2b Mon Sep 17 00:00:00 2001 From: Marc Kleine-Budde Date: Fri, 23 Jul 2021 22:17:50 +0200 Subject: [PATCH 9/9] mkimage: use environment variable MKIMAGE_SIGN_PIN to set pin for OpenSSL Engine This patch adds the possibility to pass the PIN the OpenSSL Engine used during signing via the environment variable MKIMAGE_SIGN_PIN. This follows the approach used during kernel module signing ("KBUILD_SIGN_PIN") or UBIFS image signing ("MKIMAGE_SIGN_PIN"). Signed-off-by: Marc Kleine-Budde --- doc/uImage.FIT/signature.txt | 4 ++-- lib/rsa/rsa-sign.c | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/doc/uImage.FIT/signature.txt b/doc/uImage.FIT/signature.txt index 7cb1c15e5e1..61a72db3c74 100644 --- a/doc/uImage.FIT/signature.txt +++ b/doc/uImage.FIT/signature.txt @@ -533,8 +533,8 @@ Generic engine key ids: or "" -As mkimage does not at this time support prompting for passwords HSM may need -key preloading wrapper to be used when invoking mkimage. +In order to set the pin in the HSM, an environment variable "MKIMAGE_SIGN_PIN" +can be specified. The following examples use the Nitrokey Pro using pkcs11 engine. Instructions for other devices may vary. diff --git a/lib/rsa/rsa-sign.c b/lib/rsa/rsa-sign.c index c64deac31f4..085dc89bf7b 100644 --- a/lib/rsa/rsa-sign.c +++ b/lib/rsa/rsa-sign.c @@ -338,6 +338,7 @@ static int rsa_init(void) static int rsa_engine_init(const char *engine_id, ENGINE **pe) { + const char *key_pass; ENGINE *e; int ret; @@ -362,10 +363,20 @@ static int rsa_engine_init(const char *engine_id, ENGINE **pe) goto err_set_rsa; } + key_pass = getenv("MKIMAGE_SIGN_PIN"); + if (key_pass) { + if (!ENGINE_ctrl_cmd_string(e, "PIN", key_pass, 0)) { + fprintf(stderr, "Couldn't set PIN\n"); + ret = -1; + goto err_set_pin; + } + } + *pe = e; return 0; +err_set_pin: err_set_rsa: ENGINE_finish(e); err_engine_init: