From fe3a2808bb5f86c738d47a4158117e32c349db0d Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Tue, 20 Apr 2021 11:03:12 -0400 Subject: [PATCH 01/13] test: Alphabetize dm Makefile Recently, tests have been added primarily to the end of the dm Makefile. This results in merge conflicts when two people add new tests at the same time. To reduce these conflicts, alphabetize the makefile. Signed-off-by: Sean Anderson --- test/dm/Makefile | 70 ++++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/test/dm/Makefile b/test/dm/Makefile index 100e7701d2..52a8c932b8 100644 --- a/test/dm/Makefile +++ b/test/dm/Makefile @@ -21,26 +21,39 @@ ifneq ($(CONFIG_SANDBOX),) obj-$(CONFIG_ACPIGEN) += acpi.o obj-$(CONFIG_ACPIGEN) += acpigen.o obj-$(CONFIG_ACPIGEN) += acpi_dp.o +obj-$(CONFIG_ADC) += adc.o obj-$(CONFIG_SOUND) += audio.o +obj-$(CONFIG_AXI) += axi.o obj-$(CONFIG_BLK) += blk.o obj-$(CONFIG_BUTTON) += button.o obj-$(CONFIG_DM_BOOTCOUNT) += bootcount.o obj-$(CONFIG_CLK) += clk.o clk_ccf.o +obj-$(CONFIG_CPU) += cpu.o obj-$(CONFIG_CROS_EC) += cros_ec.o obj-$(CONFIG_DEVRES) += devres.o +obj-$(CONFIG_DMA) += dma.o obj-$(CONFIG_VIDEO_MIPI_DSI) += dsi_host.o obj-$(CONFIG_DM_DSA) += dsa.o obj-$(CONFIG_DM_ETH) += eth.o +ifneq ($(CONFIG_EFI_PARTITION),) +obj-$(CONFIG_FASTBOOT_FLASH_MMC) += fastboot.o +endif obj-$(CONFIG_FIRMWARE) += firmware.o obj-$(CONFIG_DM_GPIO) += gpio.o obj-$(CONFIG_DM_HWSPINLOCK) += hwspinlock.o obj-$(CONFIG_DM_I2C) += i2c.o obj-$(CONFIG_SOUND) += i2s.o obj-y += irq.o +obj-$(CONFIG_CLK_K210_SET_RATE) += k210_pll.o obj-$(CONFIG_LED) += led.o obj-$(CONFIG_DM_MAILBOX) += mailbox.o +obj-$(CONFIG_DM_MDIO) += mdio.o +obj-$(CONFIG_DM_MDIO_MUX) += mdio_mux.o +obj-$(CONFIG_MISC) += misc.o obj-$(CONFIG_DM_MMC) += mmc.o obj-$(CONFIG_CMD_MUX) += mux-cmd.o +obj-$(CONFIG_MULTIPLEXER) += mux-emul.o +obj-$(CONFIG_MUX_MMIO) += mux-mmio.o obj-y += fdtdec.o obj-$(CONFIG_UT_DM) += nop.o obj-y += ofnode.o @@ -53,53 +66,40 @@ obj-$(CONFIG_P2SB) += p2sb.o obj-$(CONFIG_PCI_ENDPOINT) += pci_ep.o obj-$(CONFIG_PCH) += pch.o obj-$(CONFIG_PHY) += phy.o +ifneq ($(CONFIG_PINMUX),) +obj-$(CONFIG_PINCONF) += pinmux.o +endif obj-$(CONFIG_POWER_DOMAIN) += power-domain.o obj-$(CONFIG_ACPI_PMC) += pmc.o +obj-$(CONFIG_DM_PMIC) += pmic.o obj-$(CONFIG_DM_PWM) += pwm.o +obj-$(CONFIG_QFW) += qfw.o obj-$(CONFIG_RAM) += ram.o obj-y += regmap.o obj-$(CONFIG_REMOTEPROC) += remoteproc.o obj-$(CONFIG_DM_RESET) += reset.o obj-$(CONFIG_SYSRESET) += sysreset.o -obj-$(CONFIG_DM_RTC) += rtc.o -obj-$(CONFIG_DM_SPI_FLASH) += sf.o -obj-$(CONFIG_SMEM) += smem.o -obj-$(CONFIG_DM_SPI) += spi.o -obj-y += syscon.o -obj-$(CONFIG_MUX_MMIO) += mux-mmio.o -obj-$(CONFIG_MULTIPLEXER) += mux-emul.o -obj-$(CONFIG_DM_USB) += usb.o -obj-$(CONFIG_DM_PMIC) += pmic.o obj-$(CONFIG_DM_REGULATOR) += regulator.o -obj-$(CONFIG_TIMER) += timer.o -obj-$(CONFIG_DM_VIDEO) += video.o -obj-$(CONFIG_ADC) += adc.o -obj-$(CONFIG_SPMI) += spmi.o -obj-$(CONFIG_WDT) += wdt.o -obj-$(CONFIG_AXI) += axi.o -obj-$(CONFIG_MISC) += misc.o -obj-$(CONFIG_DM_SERIAL) += serial.o -obj-$(CONFIG_CPU) += cpu.o -obj-$(CONFIG_SOC_DEVICE) += soc.o -obj-$(CONFIG_SOUND) += sound.o -obj-$(CONFIG_SYSINFO) += sysinfo.o -obj-$(CONFIG_TEE) += tee.o -obj-$(CONFIG_VIRTIO_SANDBOX) += virtio.o -obj-$(CONFIG_DMA) += dma.o -obj-$(CONFIG_DM_MDIO) += mdio.o -obj-$(CONFIG_DM_MDIO_MUX) += mdio_mux.o obj-$(CONFIG_DM_RNG) += rng.o -obj-$(CONFIG_CLK_K210_SET_RATE) += k210_pll.o +obj-$(CONFIG_DM_RTC) += rtc.o +obj-$(CONFIG_SCMI_FIRMWARE) += scmi.o +obj-$(CONFIG_DM_SERIAL) += serial.o +obj-$(CONFIG_DM_SPI_FLASH) += sf.o obj-$(CONFIG_SIMPLE_BUS) += simple-bus.o obj-$(CONFIG_SIMPLE_PM_BUS) += simple-pm-bus.o +obj-$(CONFIG_SMEM) += smem.o +obj-$(CONFIG_SOC_DEVICE) += soc.o +obj-$(CONFIG_SOUND) += sound.o +obj-$(CONFIG_DM_SPI) += spi.o +obj-$(CONFIG_SPMI) += spmi.o +obj-y += syscon.o obj-$(CONFIG_RESET_SYSCON) += syscon-reset.o -obj-$(CONFIG_SCMI_FIRMWARE) += scmi.o -ifneq ($(CONFIG_PINMUX),) -obj-$(CONFIG_PINCONF) += pinmux.o -endif -ifneq ($(CONFIG_EFI_PARTITION),) -obj-$(CONFIG_FASTBOOT_FLASH_MMC) += fastboot.o -endif -obj-$(CONFIG_QFW) += qfw.o +obj-$(CONFIG_SYSINFO) += sysinfo.o +obj-$(CONFIG_TEE) += tee.o +obj-$(CONFIG_TIMER) += timer.o +obj-$(CONFIG_DM_USB) += usb.o +obj-$(CONFIG_DM_VIDEO) += video.o +obj-$(CONFIG_VIRTIO_SANDBOX) += virtio.o +obj-$(CONFIG_WDT) += wdt.o endif endif # !SPL From 7194527b6a456abaa24198dc4b6c289905c4cffd Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Mon, 12 Apr 2021 18:53:05 -0400 Subject: [PATCH 02/13] cmd: fs: Use part_get_info_by_dev_and_name_or_num to parse partitions This allows using dev#partlabel syntax. Signed-off-by: Sean Anderson --- fs/fs.c | 4 ++-- include/part.h | 12 +++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/fs/fs.c b/fs/fs.c index 900928c394..b7936fd4cf 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -385,8 +385,8 @@ int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype) } #endif - part = blk_get_device_part_str(ifname, dev_part_str, &fs_dev_desc, - &fs_partition, 1); + part = part_get_info_by_dev_and_name_or_num(ifname, dev_part_str, &fs_dev_desc, + &fs_partition, 1); if (part < 0) return -1; diff --git a/include/part.h b/include/part.h index 7f78271a98..419c859708 100644 --- a/include/part.h +++ b/include/part.h @@ -230,7 +230,7 @@ int part_get_info_by_name(struct blk_desc *dev_desc, * @param[in] allow_whole_dev true to allow the user to select partition 0 * (which means the whole device), false to require a valid * partition number >= 1 - * @return 0 on success, or a negative on error + * @return the partition number on success, or negative errno on error */ int part_get_info_by_dev_and_name_or_num(const char *dev_iface, const char *dev_part_str, @@ -275,6 +275,16 @@ static inline int blk_get_device_part_str(const char *ifname, struct disk_partition *info, int allow_whole_dev) { *dev_desc = NULL; return -1; } +static inline int +part_get_info_by_dev_and_name_or_num(const char *dev_iface, + const char *dev_part_str, + struct blk_desc **dev_desc, + struct disk_partition *part_info, + int allow_whole_dev) +{ + *dev_desc = NULL; + return -ENOSYS; +} #endif /* From fe5a50910a64d8773fcd1454631d28da72319f28 Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Mon, 12 Apr 2021 18:53:06 -0400 Subject: [PATCH 03/13] part: Fix bogus return from part_get_info_by_dev_and_name blk_get_device_by_str returns the device number on success. So we must check if the return was negative to determine an error. Signed-off-by: Sean Anderson Reviewed-by: Simon Glass --- disk/part.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/disk/part.c b/disk/part.c index 80ced2ba88..5e7e59cf25 100644 --- a/disk/part.c +++ b/disk/part.c @@ -725,7 +725,7 @@ static int part_get_info_by_dev_and_name(const char *dev_iface, } ret = blk_get_device_by_str(dev_iface, dev_str, dev_desc); - if (ret) + if (ret < 0) goto cleanup; ret = part_get_info_by_name(*dev_desc, part_str, part_info); From 535e700b9db908e0b1afba7719090e315299b9c2 Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Mon, 12 Apr 2021 18:53:07 -0400 Subject: [PATCH 04/13] test: Add test for partitions This is technically a library function, but we use MMCs for testing, so it is easier to do it with DM. At the moment, the only block devices in sandbox are MMCs (AFAIK) so we just test with those. Signed-off-by: Sean Anderson --- test/dm/Makefile | 1 + test/dm/part.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 test/dm/part.c diff --git a/test/dm/Makefile b/test/dm/Makefile index 52a8c932b8..e7cb1eec96 100644 --- a/test/dm/Makefile +++ b/test/dm/Makefile @@ -61,6 +61,7 @@ obj-y += ofread.o obj-y += of_extra.o obj-$(CONFIG_OSD) += osd.o obj-$(CONFIG_DM_VIDEO) += panel.o +obj-$(CONFIG_EFI_PARTITION) += part.o obj-$(CONFIG_DM_PCI) += pci.o obj-$(CONFIG_P2SB) += p2sb.o obj-$(CONFIG_PCI_ENDPOINT) += pci_ep.o diff --git a/test/dm/part.c b/test/dm/part.c new file mode 100644 index 0000000000..051e9010b6 --- /dev/null +++ b/test/dm/part.c @@ -0,0 +1,76 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2020 Sean Anderson + */ + +#include +#include +#include +#include +#include +#include +#include + +static int dm_test_part(struct unit_test_state *uts) +{ + char str_disk_guid[UUID_STR_LEN + 1]; + struct blk_desc *mmc_dev_desc; + struct disk_partition part_info; + struct disk_partition parts[2] = { + { + .start = 48, /* GPT data takes up the first 34 blocks or so */ + .size = 1, + .name = "test1", + }, + { + .start = 49, + .size = 1, + .name = "test2", + }, + }; + + ut_asserteq(1, blk_get_device_by_str("mmc", "1", &mmc_dev_desc)); + if (CONFIG_IS_ENABLED(RANDOM_UUID)) { + gen_rand_uuid_str(parts[0].uuid, UUID_STR_FORMAT_STD); + gen_rand_uuid_str(parts[1].uuid, UUID_STR_FORMAT_STD); + gen_rand_uuid_str(str_disk_guid, UUID_STR_FORMAT_STD); + } + ut_assertok(gpt_restore(mmc_dev_desc, str_disk_guid, parts, + ARRAY_SIZE(parts))); + +#define test(expected, part_str, whole) \ + ut_asserteq(expected, \ + part_get_info_by_dev_and_name_or_num("mmc", part_str, \ + &mmc_dev_desc, \ + &part_info, whole)) + + test(-ENODEV, "", true); + env_set("bootdevice", "0"); + test(0, "", true); + env_set("bootdevice", "1"); + test(1, "", false); + test(1, "-", false); + env_set("bootdevice", ""); + test(-EPROTONOSUPPORT, "0", false); + test(0, "0", true); + test(0, ":0", true); + test(0, ".0", true); + test(0, ".0:0", true); + test(-EINVAL, "#test1", true); + test(1, "1", false); + test(1, "1", true); + test(-ENOENT, "1:0", false); + test(0, "1:0", true); + test(1, "1:1", false); + test(2, "1:2", false); + test(1, "1.0", false); + test(0, "1.0:0", true); + test(1, "1.0:1", false); + test(2, "1.0:2", false); + test(-EINVAL, "1#bogus", false); + test(1, "1#test1", false); + test(2, "1#test2", false); + + return 0; +} +DM_TEST(dm_test_part, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); From 6829d60702706b95a7271fbf3db1981c7ce9e6b5 Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Wed, 14 Apr 2021 22:02:21 -0400 Subject: [PATCH 05/13] checkpatch: Ignore ENOSYS warnings There are no system calls in U-Boot, but ENOSYS is still allowed (and preferred since 42a2668743 ("dm: core: Document the common error codes")). Silence this warning. Signed-off-by: Sean Anderson Reviewed-by: Simon Glass --- .checkpatch.conf | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.checkpatch.conf b/.checkpatch.conf index ed0c2150ba..9e40ea060b 100644 --- a/.checkpatch.conf +++ b/.checkpatch.conf @@ -26,6 +26,9 @@ # addresses are __aligned(2)". --ignore PREFER_ETHER_ADDR_COPY +# ENOSYS is a conventionally used error, even though U-Boot lacks system calls. +--ignore ENOSYS + # A bit shorter of a description is OK with us. --min-conf-desc-length=2 From 77b8cfef531f7758f35a8598bd474713cfc2c2ec Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Wed, 10 Mar 2021 10:16:25 +0100 Subject: [PATCH 06/13] lmb: move CONFIG_LMB in Kconfig Migrate CONFIG_LMB in Kconfig. Signed-off-by: Patrick Delaunay --- arch/arc/include/asm/config.h | 2 -- arch/arm/include/asm/config.h | 1 - arch/m68k/include/asm/config.h | 1 - arch/microblaze/include/asm/config.h | 2 -- arch/mips/include/asm/config.h | 1 - arch/nds32/include/asm/config.h | 1 - arch/powerpc/include/asm/config.h | 1 - arch/riscv/include/asm/config.h | 1 - arch/sh/include/asm/config.h | 2 -- arch/x86/include/asm/config.h | 1 - arch/xtensa/include/asm/config.h | 2 -- include/configs/10m50_devboard.h | 5 ----- include/configs/3c120_devboard.h | 5 ----- include/configs/sandbox.h | 2 -- include/configs/x86-common.h | 2 -- include/image.h | 2 +- lib/Kconfig | 7 +++++++ scripts/config_whitelist.txt | 1 - 18 files changed, 8 insertions(+), 31 deletions(-) diff --git a/arch/arc/include/asm/config.h b/arch/arc/include/asm/config.h index d88c361488..46e94be141 100644 --- a/arch/arc/include/asm/config.h +++ b/arch/arc/include/asm/config.h @@ -8,6 +8,4 @@ #define CONFIG_SYS_BOOT_RAMDISK_HIGH -#define CONFIG_LMB - #endif /*__ASM_ARC_CONFIG_H_ */ diff --git a/arch/arm/include/asm/config.h b/arch/arm/include/asm/config.h index bf692ce279..14860d89b6 100644 --- a/arch/arm/include/asm/config.h +++ b/arch/arm/include/asm/config.h @@ -6,7 +6,6 @@ #ifndef _ASM_CONFIG_H_ #define _ASM_CONFIG_H_ -#define CONFIG_LMB #define CONFIG_SYS_BOOT_RAMDISK_HIGH #if defined(CONFIG_ARCH_LS1021A) || \ diff --git a/arch/m68k/include/asm/config.h b/arch/m68k/include/asm/config.h index 7ea443673a..221eb93d58 100644 --- a/arch/m68k/include/asm/config.h +++ b/arch/m68k/include/asm/config.h @@ -6,7 +6,6 @@ #ifndef _ASM_CONFIG_H_ #define _ASM_CONFIG_H_ -#define CONFIG_LMB #define CONFIG_SYS_BOOT_RAMDISK_HIGH #endif diff --git a/arch/microblaze/include/asm/config.h b/arch/microblaze/include/asm/config.h index 3ae71b3e01..221eb93d58 100644 --- a/arch/microblaze/include/asm/config.h +++ b/arch/microblaze/include/asm/config.h @@ -6,8 +6,6 @@ #ifndef _ASM_CONFIG_H_ #define _ASM_CONFIG_H_ -#define CONFIG_LMB - #define CONFIG_SYS_BOOT_RAMDISK_HIGH #endif diff --git a/arch/mips/include/asm/config.h b/arch/mips/include/asm/config.h index 7ea443673a..221eb93d58 100644 --- a/arch/mips/include/asm/config.h +++ b/arch/mips/include/asm/config.h @@ -6,7 +6,6 @@ #ifndef _ASM_CONFIG_H_ #define _ASM_CONFIG_H_ -#define CONFIG_LMB #define CONFIG_SYS_BOOT_RAMDISK_HIGH #endif diff --git a/arch/nds32/include/asm/config.h b/arch/nds32/include/asm/config.h index 8964a58f27..6c1cbce7ef 100644 --- a/arch/nds32/include/asm/config.h +++ b/arch/nds32/include/asm/config.h @@ -7,6 +7,5 @@ #ifndef _ASM_CONFIG_H_ #define _ASM_CONFIG_H_ -#define CONFIG_LMB #endif diff --git a/arch/powerpc/include/asm/config.h b/arch/powerpc/include/asm/config.h index c9c9964630..99b410dc9b 100644 --- a/arch/powerpc/include/asm/config.h +++ b/arch/powerpc/include/asm/config.h @@ -18,7 +18,6 @@ #define HWCONFIG_BUFFER_SIZE 256 #endif -#define CONFIG_LMB #define CONFIG_SYS_BOOT_RAMDISK_HIGH #ifndef CONFIG_MAX_MEM_MAPPED diff --git a/arch/riscv/include/asm/config.h b/arch/riscv/include/asm/config.h index 156cb94dc0..d911007537 100644 --- a/arch/riscv/include/asm/config.h +++ b/arch/riscv/include/asm/config.h @@ -7,7 +7,6 @@ #ifndef _ASM_CONFIG_H_ #define _ASM_CONFIG_H_ -#define CONFIG_LMB #define CONFIG_SYS_BOOT_RAMDISK_HIGH #endif diff --git a/arch/sh/include/asm/config.h b/arch/sh/include/asm/config.h index e1cd322152..406156dff5 100644 --- a/arch/sh/include/asm/config.h +++ b/arch/sh/include/asm/config.h @@ -8,8 +8,6 @@ #include -#define CONFIG_LMB - /* Timer */ #define CONFIG_SYS_TIMER_COUNTS_DOWN #define CONFIG_SYS_TIMER_COUNTER (TMU_BASE + 0xc) /* TCNT0 */ diff --git a/arch/x86/include/asm/config.h b/arch/x86/include/asm/config.h index 7ea443673a..221eb93d58 100644 --- a/arch/x86/include/asm/config.h +++ b/arch/x86/include/asm/config.h @@ -6,7 +6,6 @@ #ifndef _ASM_CONFIG_H_ #define _ASM_CONFIG_H_ -#define CONFIG_LMB #define CONFIG_SYS_BOOT_RAMDISK_HIGH #endif diff --git a/arch/xtensa/include/asm/config.h b/arch/xtensa/include/asm/config.h index 5a95fc93f7..a1096ab196 100644 --- a/arch/xtensa/include/asm/config.h +++ b/arch/xtensa/include/asm/config.h @@ -9,8 +9,6 @@ #include -#define CONFIG_LMB - /* * Make boot parameters available in the MMUv2 virtual memory layout by * restricting used physical memory to the first 128MB. diff --git a/include/configs/10m50_devboard.h b/include/configs/10m50_devboard.h index 768b4a6dfc..3ffc744928 100644 --- a/include/configs/10m50_devboard.h +++ b/include/configs/10m50_devboard.h @@ -34,11 +34,6 @@ */ #define CONFIG_BOOTP_BOOTFILESIZE -/* - * FDT options - */ -#define CONFIG_LMB - /* * MEMORY ORGANIZATION * -Monitor at top of sdram. diff --git a/include/configs/3c120_devboard.h b/include/configs/3c120_devboard.h index 30bbd716b2..3f065ff315 100644 --- a/include/configs/3c120_devboard.h +++ b/include/configs/3c120_devboard.h @@ -34,11 +34,6 @@ */ #define CONFIG_BOOTP_BOOTFILESIZE -/* - * FDT options - */ -#define CONFIG_LMB - /* * MEMORY ORGANIZATION * -Monitor at top of sdram. diff --git a/include/configs/sandbox.h b/include/configs/sandbox.h index 6e79d3f56e..8eeccdd426 100644 --- a/include/configs/sandbox.h +++ b/include/configs/sandbox.h @@ -22,8 +22,6 @@ #define CONFIG_SYS_TIMER_RATE 1000000 #endif -#define CONFIG_LMB - #define CONFIG_HOST_MAX_DEVICES 4 /* diff --git a/include/configs/x86-common.h b/include/configs/x86-common.h index 641ed2c5ec..f186dd6b82 100644 --- a/include/configs/x86-common.h +++ b/include/configs/x86-common.h @@ -16,8 +16,6 @@ */ #define CONFIG_PHYSMEM -#define CONFIG_LMB - #define CONFIG_SYS_BOOTM_LEN (16 << 20) /* SATA AHCI storage */ diff --git a/include/image.h b/include/image.h index 3ff3c035a7..459685d4d4 100644 --- a/include/image.h +++ b/include/image.h @@ -434,7 +434,7 @@ typedef struct bootm_headers { #define BOOTM_STATE_OS_GO (0x00000400) int state; -#ifdef CONFIG_LMB +#if defined(CONFIG_LMB) && !defined(USE_HOSTCC) struct lmb lmb; /* for memory mgmt */ #endif } bootm_headers_t; diff --git a/lib/Kconfig b/lib/Kconfig index ab8c9ccd60..b7df9eb5d6 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -700,6 +700,13 @@ config LIB_ELF Support basic elf loading/validating functions. This supports for 32 bit and 64 bit versions. +config LMB + bool "Enable the logical memory blocks library (lmb)" + default y if ARC || ARM || M68K || MICROBLAZE || MIPS || NDS32 || \ + NIOS2 || PPC || RISCV || SANDBOX || SH || X86 || XTENSA + help + Support the library logical memory blocks. + endmenu config PHANDLE_CHECK_SEQ diff --git a/scripts/config_whitelist.txt b/scripts/config_whitelist.txt index a2fcafd2e6..3eda10efed 100644 --- a/scripts/config_whitelist.txt +++ b/scripts/config_whitelist.txt @@ -948,7 +948,6 @@ CONFIG_LEGACY_BOOTCMD_ENV CONFIG_LINUX CONFIG_LINUX_RESET_VEC CONFIG_LITTLETON_LCD -CONFIG_LMB CONFIG_LMS283GF05 CONFIG_LOADADDR CONFIG_LOADCMD From 8f167da9c572845782000075e092e63a8273032d Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Wed, 10 Mar 2021 10:16:26 +0100 Subject: [PATCH 07/13] lmb: remove lmb_region.size Remove the unused field size of struct lmb_region as it is initialized to 0 and never used after in lmb library. See Linux kernel commit 4734b594c6ca ("memblock: Remove memblock_type.size and add memblock.memory_size instead") Signed-off-by: Patrick Delaunay --- include/lmb.h | 1 - lib/lmb.c | 6 ------ 2 files changed, 7 deletions(-) diff --git a/include/lmb.h b/include/lmb.h index e9f19b16ea..a3247544c1 100644 --- a/include/lmb.h +++ b/include/lmb.h @@ -21,7 +21,6 @@ struct lmb_property { struct lmb_region { unsigned long cnt; - phys_size_t size; struct lmb_property region[MAX_LMB_REGIONS+1]; }; diff --git a/lib/lmb.c b/lib/lmb.c index d126f8dc04..5cf419f439 100644 --- a/lib/lmb.c +++ b/lib/lmb.c @@ -20,8 +20,6 @@ void lmb_dump_all_force(struct lmb *lmb) printf("lmb_dump_all:\n"); printf(" memory.cnt = 0x%lx\n", lmb->memory.cnt); - printf(" memory.size = 0x%llx\n", - (unsigned long long)lmb->memory.size); for (i = 0; i < lmb->memory.cnt; i++) { printf(" memory.reg[0x%lx].base = 0x%llx\n", i, (unsigned long long)lmb->memory.region[i].base); @@ -30,8 +28,6 @@ void lmb_dump_all_force(struct lmb *lmb) } printf("\n reserved.cnt = 0x%lx\n", lmb->reserved.cnt); - printf(" reserved.size = 0x%llx\n", - (unsigned long long)lmb->reserved.size); for (i = 0; i < lmb->reserved.cnt; i++) { printf(" reserved.reg[0x%lx].base = 0x%llx\n", i, (unsigned long long)lmb->reserved.region[i].base); @@ -100,9 +96,7 @@ static void lmb_coalesce_regions(struct lmb_region *rgn, unsigned long r1, void lmb_init(struct lmb *lmb) { lmb->memory.cnt = 0; - lmb->memory.size = 0; lmb->reserved.cnt = 0; - lmb->reserved.size = 0; } static void lmb_reserve_common(struct lmb *lmb, void *fdt_blob) From 00fd8dad4d2ed738d11f29d992dc106bbdf4d68f Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Wed, 10 Mar 2021 10:16:27 +0100 Subject: [PATCH 08/13] lmb: add a max parameter in the struct lmb_region Add a max parameter in lmb_region struct to handle test in lmb_add_region without using the MAX_LMB_REGIONS define. This patch allows to modify these size independently for memory of reserved regions in the next patches. Signed-off-by: Patrick Delaunay --- include/lmb.h | 1 + lib/lmb.c | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/lmb.h b/include/lmb.h index a3247544c1..f3397c7f73 100644 --- a/include/lmb.h +++ b/include/lmb.h @@ -21,6 +21,7 @@ struct lmb_property { struct lmb_region { unsigned long cnt; + unsigned long max; struct lmb_property region[MAX_LMB_REGIONS+1]; }; diff --git a/lib/lmb.c b/lib/lmb.c index 5cf419f439..a926198d48 100644 --- a/lib/lmb.c +++ b/lib/lmb.c @@ -95,6 +95,9 @@ static void lmb_coalesce_regions(struct lmb_region *rgn, unsigned long r1, void lmb_init(struct lmb *lmb) { + lmb->memory.max = MAX_LMB_REGIONS; + lmb->reserved.max = MAX_LMB_REGIONS; + lmb->memory.cnt = 0; lmb->reserved.cnt = 0; } @@ -179,7 +182,7 @@ static long lmb_add_region(struct lmb_region *rgn, phys_addr_t base, phys_size_t if (coalesced) return coalesced; - if (rgn->cnt >= MAX_LMB_REGIONS) + if (rgn->cnt >= rgn->max) return -1; /* Couldn't coalesce the LMB, so add it to the sorted table. */ From 4fa0150d6c9c252af6887c55cbacd6734a40e9ab Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Wed, 10 Mar 2021 10:16:28 +0100 Subject: [PATCH 09/13] lmb: move MAX_LMB_REGIONS value in Kconfig Move MAX_LMB_REGIONS value in Kconfig, the max number of the regions in lmb library. Signed-off-by: Patrick Delaunay --- include/lmb.h | 4 +--- lib/Kconfig | 10 +++++++++- lib/lmb.c | 4 ++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/include/lmb.h b/include/lmb.h index f3397c7f73..d3adf8ef69 100644 --- a/include/lmb.h +++ b/include/lmb.h @@ -12,8 +12,6 @@ * Copyright (C) 2001 Peter Bergner, IBM Corp. */ -#define MAX_LMB_REGIONS 8 - struct lmb_property { phys_addr_t base; phys_size_t size; @@ -22,7 +20,7 @@ struct lmb_property { struct lmb_region { unsigned long cnt; unsigned long max; - struct lmb_property region[MAX_LMB_REGIONS+1]; + struct lmb_property region[CONFIG_LMB_MAX_REGIONS + 1]; }; struct lmb { diff --git a/lib/Kconfig b/lib/Kconfig index b7df9eb5d6..e46c51f123 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -439,7 +439,7 @@ config LZ4 is included. The LZ4 algorithm can run in-place as long as the compressed image is loaded to the end of the output buffer, and trades lower compression ratios for much faster decompression. - + NOTE: This implements the release version of the LZ4 frame format as generated by default by the 'lz4' command line tool. This is not the same as the outdated, less efficient legacy @@ -707,6 +707,14 @@ config LMB help Support the library logical memory blocks. + +config LMB_MAX_REGIONS + int "Number of memory and reserved regions in lmb lib" + depends on LMB + default 8 + help + Define the number of supported regions, memory and reserved, in the + library logical memory blocks. endmenu config PHANDLE_CHECK_SEQ diff --git a/lib/lmb.c b/lib/lmb.c index a926198d48..9fbc56619b 100644 --- a/lib/lmb.c +++ b/lib/lmb.c @@ -95,8 +95,8 @@ static void lmb_coalesce_regions(struct lmb_region *rgn, unsigned long r1, void lmb_init(struct lmb *lmb) { - lmb->memory.max = MAX_LMB_REGIONS; - lmb->reserved.max = MAX_LMB_REGIONS; + lmb->memory.max = CONFIG_LMB_MAX_REGIONS; + lmb->reserved.max = CONFIG_LMB_MAX_REGIONS; lmb->memory.cnt = 0; lmb->reserved.cnt = 0; From cb1e619824f0c942ccd9b230b5f41caaf7cd91b4 Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Wed, 10 Mar 2021 10:16:29 +0100 Subject: [PATCH 10/13] lmb: correct size of the regions array As in lmb_region, cnt < max and in the lmb library use region[i] only with i in 0...cnt, this region array size can be reduced by 1 element without overflow. This patch allows to reduce the struct lmb size. Signed-off-by: Patrick Delaunay --- include/lmb.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/lmb.h b/include/lmb.h index d3adf8ef69..898ce15d07 100644 --- a/include/lmb.h +++ b/include/lmb.h @@ -20,7 +20,7 @@ struct lmb_property { struct lmb_region { unsigned long cnt; unsigned long max; - struct lmb_property region[CONFIG_LMB_MAX_REGIONS + 1]; + struct lmb_property region[CONFIG_LMB_MAX_REGIONS]; }; struct lmb { From a57b596e8b3eb3b24af31ce91b2fd6a57d8df0ba Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Wed, 10 Mar 2021 10:16:30 +0100 Subject: [PATCH 11/13] test: lmb: add test for overflow protection in lmb_add_region Add test for max number of memory regions and in reserved regions. Signed-off-by: Patrick Delaunay --- test/lib/lmb.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/test/lib/lmb.c b/test/lib/lmb.c index 644ee78758..0d8963fcbf 100644 --- a/test/lib/lmb.c +++ b/test/lib/lmb.c @@ -659,3 +659,67 @@ static int lib_test_lmb_get_free_size(struct unit_test_state *uts) DM_TEST(lib_test_lmb_get_free_size, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); + +static int lib_test_lmb_max_regions(struct unit_test_state *uts) +{ + const phys_addr_t ram = 0x00000000; + const phys_size_t ram_size = 0x8000000; + const phys_size_t blk_size = 0x10000; + phys_addr_t offset; + struct lmb lmb; + int ret, i; + + lmb_init(&lmb); + + ut_asserteq(lmb.memory.cnt, 0); + ut_asserteq(lmb.memory.max, 8); + ut_asserteq(lmb.reserved.cnt, 0); + ut_asserteq(lmb.reserved.max, 8); + + /* Add 8 memory regions */ + for (i = 0; i < 8; i++) { + offset = ram + 2 * i * ram_size; + ret = lmb_add(&lmb, offset, ram_size); + ut_asserteq(ret, 0); + } + ut_asserteq(lmb.memory.cnt, 8); + ut_asserteq(lmb.reserved.cnt, 0); + + /* error for the 9th memory regions */ + offset = ram + 2 * 8 * ram_size; + ret = lmb_add(&lmb, offset, ram_size); + ut_asserteq(ret, -1); + + ut_asserteq(lmb.memory.cnt, 8); + ut_asserteq(lmb.reserved.cnt, 0); + + /* reserve 8 regions */ + for (i = 0; i < 8; i++) { + offset = ram + 2 * i * blk_size; + ret = lmb_reserve(&lmb, offset, blk_size); + ut_asserteq(ret, 0); + } + + ut_asserteq(lmb.memory.cnt, 8); + ut_asserteq(lmb.reserved.cnt, 8); + + /* error for the 9th reserved blocks */ + offset = ram + 2 * 8 * blk_size; + ret = lmb_reserve(&lmb, offset, blk_size); + ut_asserteq(ret, -1); + + ut_asserteq(lmb.memory.cnt, 8); + ut_asserteq(lmb.reserved.cnt, 8); + + /* check each regions */ + for (i = 0; i < 8; i++) + ut_asserteq(lmb.memory.region[i].base, ram + 2 * i * ram_size); + + for (i = 0; i < 8; i++) + ut_asserteq(lmb.reserved.region[i].base, ram + 2 * i * blk_size); + + return 0; +} + +DM_TEST(lib_test_lmb_max_regions, + UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); From 6d66502bc74182105c7fc77efe7bf8d04ac4e345 Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Wed, 10 Mar 2021 10:16:31 +0100 Subject: [PATCH 12/13] lmb: Add 2 config to define the max number of regions Add 2 configs CONFIG_LMB_MEMORY_REGIONS and CONFIG_LMB_RESERVED_REGIONS to change independently the max number of the regions in lmb library. When CONFIG_LMB_USE_MAX_REGIONS=y, move the lmb property arrays to struct lmb and manage the array size with the element 'max' of struct lmb_region; their are still allocated in stack. When CONFIG_LMB_USE_MAX_REGIONS=n, keep the current location in struct lmb_region to allow compiler optimization. Increase CONFIG_LMB_RESERVED_REGIONS is useful to avoid lmb errors in bootm when the number of reserved regions (not adjacent) is reached: + 1 region for relocated U-Boot + 1 region for initrd + 1 region for relocated linux device tree + reserved memory regions present in Linux device tree. The current limit of 8 regions is reached with only 5 reserved regions in DT. see Linux kernel commit bf23c51f1f49 ("memblock: Move memblock arrays to static storage in memblock.c and make their size a variable") Signed-off-by: Patrick Delaunay --- include/lmb.h | 34 ++++++++++++++++++++++++++++++++++ lib/Kconfig | 29 ++++++++++++++++++++++++++++- lib/lmb.c | 8 +++++++- 3 files changed, 69 insertions(+), 2 deletions(-) diff --git a/include/lmb.h b/include/lmb.h index 898ce15d07..541e17093c 100644 --- a/include/lmb.h +++ b/include/lmb.h @@ -12,20 +12,54 @@ * Copyright (C) 2001 Peter Bergner, IBM Corp. */ +/** + * struct lmb_property - Description of one region. + * + * @base: Base address of the region. + * @size: Size of the region + */ struct lmb_property { phys_addr_t base; phys_size_t size; }; +/** + * struct lmb_region - Description of a set of region. + * + * @cnt: Number of regions. + * @max: Size of the region array, max value of cnt. + * @region: Array of the region properties + */ struct lmb_region { unsigned long cnt; unsigned long max; +#if IS_ENABLED(CONFIG_LMB_USE_MAX_REGIONS) struct lmb_property region[CONFIG_LMB_MAX_REGIONS]; +#else + struct lmb_property *region; +#endif }; +/** + * struct lmb - Logical memory block handle. + * + * Clients provide storage for Logical memory block (lmb) handles. + * The content of the structure is managed by the lmb library. + * A lmb struct is initialized by lmb_init() functions. + * The lmb struct is passed to all other lmb APIs. + * + * @memory: Description of memory regions. + * @reserved: Description of reserved regions. + * @memory_regions: Array of the memory regions (statically allocated) + * @reserved_regions: Array of the reserved regions (statically allocated) + */ struct lmb { struct lmb_region memory; struct lmb_region reserved; +#if !IS_ENABLED(CONFIG_LMB_USE_MAX_REGIONS) + struct lmb_property memory_regions[CONFIG_LMB_MEMORY_REGIONS]; + struct lmb_property reserved_regions[CONFIG_LMB_RESERVED_REGIONS]; +#endif }; extern void lmb_init(struct lmb *lmb); diff --git a/lib/Kconfig b/lib/Kconfig index e46c51f123..6d2d41de30 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -707,14 +707,41 @@ config LMB help Support the library logical memory blocks. +config LMB_USE_MAX_REGIONS + bool "Use a commun number of memory and reserved regions in lmb lib" + depends on LMB + default y + help + Define the number of supported memory regions in the library logical + memory blocks. + This feature allow to reduce the lmb library size by using compiler + optimization when LMB_MEMORY_REGIONS == LMB_RESERVED_REGIONS. config LMB_MAX_REGIONS int "Number of memory and reserved regions in lmb lib" - depends on LMB + depends on LMB && LMB_USE_MAX_REGIONS default 8 help Define the number of supported regions, memory and reserved, in the library logical memory blocks. + +config LMB_MEMORY_REGIONS + int "Number of memory regions in lmb lib" + depends on LMB && !LMB_USE_MAX_REGIONS + default 8 + help + Define the number of supported memory regions in the library logical + memory blocks. + The minimal value is CONFIG_NR_DRAM_BANKS. + +config LMB_RESERVED_REGIONS + int "Number of reserved regions in lmb lib" + depends on LMB && !LMB_USE_MAX_REGIONS + default 8 + help + Define the number of supported reserved regions in the library logical + memory blocks. + endmenu config PHANDLE_CHECK_SEQ diff --git a/lib/lmb.c b/lib/lmb.c index 9fbc56619b..c08c4d942b 100644 --- a/lib/lmb.c +++ b/lib/lmb.c @@ -95,9 +95,15 @@ static void lmb_coalesce_regions(struct lmb_region *rgn, unsigned long r1, void lmb_init(struct lmb *lmb) { +#if IS_ENABLED(CONFIG_LMB_USE_MAX_REGIONS) lmb->memory.max = CONFIG_LMB_MAX_REGIONS; lmb->reserved.max = CONFIG_LMB_MAX_REGIONS; - +#else + lmb->memory.max = CONFIG_LMB_MEMORY_REGIONS; + lmb->reserved.max = CONFIG_LMB_RESERVED_REGIONS; + lmb->memory.region = lmb->memory_regions; + lmb->reserved.region = lmb->reserved_regions; +#endif lmb->memory.cnt = 0; lmb->reserved.cnt = 0; } From 0089affee275e47047be8ae9deac6ca08a5da478 Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Wed, 10 Mar 2021 10:16:32 +0100 Subject: [PATCH 13/13] configs: stm32mp15: increase the number of reserved memory region in lmb For the latest kernel device tree the max number of reserved regions in lmb library is reached: 8 with 5 reserved regions in device tree. When a new region is added, the lmb allocation for the device tree relocation failed and boot with ramdisk failed. This patch avoids this issue by increasing the max number of supported reserved memory in lmb library to 16. Signed-off-by: Patrick Delaunay --- configs/stm32mp15_basic_defconfig | 3 +++ configs/stm32mp15_trusted_defconfig | 3 +++ 2 files changed, 6 insertions(+) diff --git a/configs/stm32mp15_basic_defconfig b/configs/stm32mp15_basic_defconfig index fbca482877..a60198f930 100644 --- a/configs/stm32mp15_basic_defconfig +++ b/configs/stm32mp15_basic_defconfig @@ -170,3 +170,6 @@ CONFIG_WDT_STM32MP=y CONFIG_ERRNO_STR=y # CONFIG_HEXDUMP is not set CONFIG_FDT_FIXUP_PARTITIONS=y +# CONFIG_LMB_USE_MAX_REGIONS is not set +CONFIG_LMB_MEMORY_REGIONS=2 +CONFIG_LMB_RESERVED_REGIONS=16 diff --git a/configs/stm32mp15_trusted_defconfig b/configs/stm32mp15_trusted_defconfig index ba9a660abf..8c71ca6b6d 100644 --- a/configs/stm32mp15_trusted_defconfig +++ b/configs/stm32mp15_trusted_defconfig @@ -152,3 +152,6 @@ CONFIG_WDT_STM32MP=y CONFIG_ERRNO_STR=y # CONFIG_HEXDUMP is not set CONFIG_FDT_FIXUP_PARTITIONS=y +# CONFIG_LMB_USE_MAX_REGIONS is not set +CONFIG_LMB_MEMORY_REGIONS=2 +CONFIG_LMB_RESERVED_REGIONS=16