From 24fd7e383da23adf785fc2d2b8bddfc29b85346b Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 3 Feb 2021 21:29:43 -0700 Subject: dm: core: Fix allocation of empty of-platdata With of-platdata we always have a dtv struct that holds the platform data provided by the driver_info record. However, this struct can be empty if there are no actual devicetree properties provided. The upshot of empty platform data is that it will end up as a zero-size member in the BSS section, which is fine. But if the driver specifies plat_auto then it expects the correct amount of space to be allocated. At present this does not happen, since device_bind() assumes that the platform-data size will always be >0. As a result we end up not allocating the space and just use the BSS region, overwriting whatever other contents are present. Fix this by removing the condition that platform data be non-empty, always allocating space if requested. This fixes a strange bug that has been lurking since of-platdata was implemented. It has likely never been noticed since devices normally have at least some devicetree properties, BSS is seldom used on SPL, the dtv structs are normally at the end of bss and the overwriting only happens if a driver changes its platform data. It was discovered using sandbox_spl, which exercises more features than a normal board might, and the critical global_data variable 'gd' happened to be at the end of BSS. Fixes: 9fa28190091 ("dm: core: Expand platdata for of-platdata devices") Signed-off-by: Simon Glass --- drivers/core/device.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/drivers/core/device.c b/drivers/core/device.c index 625134921d..d1098a3861 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -92,15 +92,19 @@ static int device_bind_common(struct udevice *parent, const struct driver *drv, if (auto_seq && !(uc->uc_drv->flags & DM_UC_FLAG_NO_AUTO_SEQ)) dev->seq_ = uclass_find_next_free_seq(uc); + /* Check if we need to allocate plat */ if (drv->plat_auto) { bool alloc = !plat; + /* + * For of-platdata, we try use the existing data, but if + * plat_auto is larger, we must allocate a new space + */ if (CONFIG_IS_ENABLED(OF_PLATDATA)) { - if (of_plat_size) { + if (of_plat_size) dev_or_flags(dev, DM_FLAG_OF_PLATDATA); - if (of_plat_size < drv->plat_auto) - alloc = true; - } + if (of_plat_size < drv->plat_auto) + alloc = true; } if (alloc) { dev_or_flags(dev, DM_FLAG_ALLOC_PDATA); @@ -109,6 +113,11 @@ static int device_bind_common(struct udevice *parent, const struct driver *drv, ret = -ENOMEM; goto fail_alloc1; } + + /* + * For of-platdata, copy the old plat into the new + * space + */ if (CONFIG_IS_ENABLED(OF_PLATDATA) && plat) memcpy(ptr, plat, of_plat_size); dev_set_plat(dev, ptr); -- cgit v1.2.1 From 15421b71bccc3a12e64cfa1e8089e50cc2a93fe4 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 3 Feb 2021 21:29:44 -0700 Subject: dm: core: Add DM_DEVICE_REMOVE condition to all exit paths At present device_bind() does some unnecessary work if a device fails to bind in SPL. Add the missing conditions. Also fix a style nit in the same function while we are here. Signed-off-by: Simon Glass --- drivers/core/device.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/drivers/core/device.c b/drivers/core/device.c index d1098a3861..81f6880eac 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -137,9 +137,8 @@ static int device_bind_common(struct udevice *parent, const struct driver *drv, if (parent) { size = parent->driver->per_child_plat_auto; - if (!size) { + if (!size) size = parent->uclass->uc_drv->per_child_plat_auto; - } if (size) { dev_or_flags(dev, DM_FLAG_ALLOC_PARENT_PDATA); ptr = calloc(1, size); @@ -209,14 +208,18 @@ fail_uclass_bind: } } fail_alloc3: - if (dev_get_flags(dev) & DM_FLAG_ALLOC_UCLASS_PDATA) { - free(dev_get_uclass_plat(dev)); - dev_set_uclass_plat(dev, NULL); + if (CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)) { + if (dev_get_flags(dev) & DM_FLAG_ALLOC_UCLASS_PDATA) { + free(dev_get_uclass_plat(dev)); + dev_set_uclass_plat(dev, NULL); + } } fail_alloc2: - if (dev_get_flags(dev) & DM_FLAG_ALLOC_PDATA) { - free(dev_get_plat(dev)); - dev_set_plat(dev, NULL); + if (CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)) { + if (dev_get_flags(dev) & DM_FLAG_ALLOC_PDATA) { + free(dev_get_plat(dev)); + dev_set_plat(dev, NULL); + } } fail_alloc1: devres_release_all(dev); -- cgit v1.2.1 From 939b04e9cf57a838be7e590340a4e84610e76433 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 3 Feb 2021 06:00:49 -0700 Subject: bootstage: Fix dependency for BOOTSTAGE_RECORD_COUNT At present these three Kconfigs exist even when bootstage is not enabled. This is not necessary since bootstage.c is only built if BOOTSTAGE is enabled. Make them conditional. Also fix up the overflow message to mention TPL. Signed-off-by: Simon Glass --- common/Kconfig.boot | 3 +++ common/bootstage.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/common/Kconfig.boot b/common/Kconfig.boot index 70c02b9e30..e650c605d1 100644 --- a/common/Kconfig.boot +++ b/common/Kconfig.boot @@ -449,6 +449,7 @@ config BOOTSTAGE_REPORT config BOOTSTAGE_RECORD_COUNT int "Number of boot stage records to store" + depends on BOOTSTAGE default 30 help This is the size of the bootstage record list and is the maximum @@ -456,6 +457,7 @@ config BOOTSTAGE_RECORD_COUNT config SPL_BOOTSTAGE_RECORD_COUNT int "Number of boot stage records to store for SPL" + depends on SPL_BOOTSTAGE default 5 help This is the size of the bootstage record list and is the maximum @@ -463,6 +465,7 @@ config SPL_BOOTSTAGE_RECORD_COUNT config TPL_BOOTSTAGE_RECORD_COUNT int "Number of boot stage records to store for TPL" + depends on TPL_BOOTSTAGE default 5 help This is the size of the bootstage record list and is the maximum diff --git a/common/bootstage.c b/common/bootstage.c index d5b78b9f48..2c0110c263 100644 --- a/common/bootstage.c +++ b/common/bootstage.c @@ -349,7 +349,7 @@ void bootstage_report(void) } if (data->rec_count > RECORD_COUNT) printf("Overflowed internal boot id table by %d entries\n" - "Please increase CONFIG_(SPL_)BOOTSTAGE_RECORD_COUNT\n", + "Please increase CONFIG_(SPL_TPL_)BOOTSTAGE_RECORD_COUNT\n", data->rec_count - RECORD_COUNT); puts("\nAccumulated time:\n"); -- cgit v1.2.1 From 67637d4b5ab70896c8a881022126f7c61f90a0f1 Mon Sep 17 00:00:00 2001 From: Bernhard Kirchen Date: Fri, 29 Jan 2021 15:10:08 +0100 Subject: fix patman --limit-cc option patman's --limit-cc option parses its argument to an integer and uses that to trim the list of CC recipients to a particular maximum. but that only works if the cc variable is a list, which it is not. Signed-off-by: Bernhard Kirchen Reviewed-by: Simon Glass --- tools/patman/series.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/patman/series.py b/tools/patman/series.py index a6746e87c4..41a11732fc 100644 --- a/tools/patman/series.py +++ b/tools/patman/series.py @@ -271,7 +271,7 @@ class Series(dict): cc += get_maintainer.GetMaintainer(dir_list, commit.patch) for x in set(cc) & set(settings.bounces): print(col.Color(col.YELLOW, 'Skipping "%s"' % x)) - cc = set(cc) - set(settings.bounces) + cc = list(set(cc) - set(settings.bounces)) if limit is not None: cc = cc[:limit] all_ccs += cc -- cgit v1.2.1 From 297b8b3ebfc2bdeb0b245b1dbe31ae8302d9b1b8 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Wed, 3 Feb 2021 00:21:56 +0100 Subject: sandbox: host bind must close file descriptor Each invocation of the 'host bind' command with a file name argument opens a file descriptor. The next invocation of the 'host bind' command destroys the block device but the file descriptor remains open. The same holds true for the 'unbind blk' command. Close the file descriptor when unbinding the host block device. Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- drivers/block/sandbox.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/block/sandbox.c b/drivers/block/sandbox.c index 9d7d68c007..e2f229b15d 100644 --- a/drivers/block/sandbox.c +++ b/drivers/block/sandbox.c @@ -231,6 +231,18 @@ int host_get_dev_err(int devnum, struct blk_desc **blk_devp) } #ifdef CONFIG_BLK + +int sandbox_host_unbind(struct udevice *dev) +{ + struct host_block_dev *host_dev; + + /* Data validity is checked in host_dev_bind() */ + host_dev = dev_get_plat(dev); + os_close(host_dev->fd); + + return 0; +} + static const struct blk_ops sandbox_host_blk_ops = { .read = host_block_read, .write = host_block_write, @@ -240,6 +252,7 @@ U_BOOT_DRIVER(sandbox_host_blk) = { .name = "sandbox_host_blk", .id = UCLASS_BLK, .ops = &sandbox_host_blk_ops, + .unbind = sandbox_host_unbind, .plat_auto = sizeof(struct host_block_dev), }; #else -- cgit v1.2.1 From 56e7257ca8bb7c4f1a2d720fe289d2b8b6508922 Mon Sep 17 00:00:00 2001 From: Bin Meng Date: Wed, 3 Feb 2021 21:20:02 +0800 Subject: lib: Fix BINMAN_FDT dependency lib/binman.c references the following 3 ofnode APIs: ofnode_first_subnode(), ofnode_path() and ofnode_read_bool(). These APIs get built only when DM is on. Fix the dependency then. Signed-off-by: Bin Meng Reviewed-by: Simon Glass --- lib/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Kconfig b/lib/Kconfig index b35a71ac36..7f4c30ec0d 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -22,7 +22,7 @@ config BCH config BINMAN_FDT bool "Allow access to binman information in the device tree" - depends on BINMAN && OF_CONTROL + depends on BINMAN && DM && OF_CONTROL default y help This enables U-Boot to access information about binman entries, -- cgit v1.2.1 From ced4c31e93d905694553fd1df7aeb4e7d7ef6112 Mon Sep 17 00:00:00 2001 From: Bin Meng Date: Wed, 3 Feb 2021 21:20:03 +0800 Subject: dts: Fix OF_LIVE dependency lib/of_live.c references the following 2 ofnode APIs: of_alias_scan() and of_get_property(). These APIs get built only when DM is on. Fix the dependency then. Signed-off-by: Bin Meng Reviewed-by: Simon Glass --- dts/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dts/Kconfig b/dts/Kconfig index 71f50552e4..00ac29a457 100644 --- a/dts/Kconfig +++ b/dts/Kconfig @@ -60,7 +60,7 @@ config TPL_OF_CONTROL config OF_LIVE bool "Enable use of a live tree" - depends on OF_CONTROL + depends on DM && OF_CONTROL help Normally U-Boot uses a flat device tree which saves space and avoids the need to unpack the tree before use. However a flat -- cgit v1.2.1 From 09bd08401a5ff2cdbf40fdc27a8add809ae11075 Mon Sep 17 00:00:00 2001 From: Bin Meng Date: Wed, 3 Feb 2021 21:22:40 +0800 Subject: serial: ns16550: Correct the base address type Currently ns16550_serial_assign_base() treats the argument 'base' with type `ulong`. This is incorrect because the base address was obtained from device tree with type `fdt_addr_t` that can represent a physical address larger than 32-bit in a 32-bit system. Fixes: 9e6ce62190b7 ("serial: ns16550: Fix ordering of getting base address") Signed-off-by: Bin Meng Reviewed-by: Simon Glass --- drivers/serial/ns16550.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/serial/ns16550.c b/drivers/serial/ns16550.c index b9e99babeb..1377c9a0e1 100644 --- a/drivers/serial/ns16550.c +++ b/drivers/serial/ns16550.c @@ -483,7 +483,7 @@ static int ns16550_serial_getinfo(struct udevice *dev, return 0; } -static int ns16550_serial_assign_base(struct ns16550_plat *plat, ulong base) +static int ns16550_serial_assign_base(struct ns16550_plat *plat, fdt_addr_t base) { if (base == FDT_ADDR_T_NONE) return -EINVAL; -- cgit v1.2.1 From 384b62c073f3aaccba0c917a8da7701a82441aec Mon Sep 17 00:00:00 2001 From: Bin Meng Date: Wed, 3 Feb 2021 22:42:25 +0800 Subject: serial: ns16550: Handle zero value A working device tree node of ns16550 should never be populated with value zero for the property. Unfortunately this is the case for the QEMU ppce500 target. Let's try to assign plat->clock to CONFIG_SYS_NS16550_CLK as the last resort to handle such case. This commit should be reverted when: - The following QEMU patch [1] is merged, and - U-Boot CI has upgraded its QEMU version that contains the fix [1] http://patchwork.ozlabs.org/project/qemu-devel/patch/1612362288-22216-2-git-send-email-bmeng.cn@gmail.com/ Signed-off-by: Bin Meng Reviewed-by: Simon Glass --- drivers/serial/ns16550.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/serial/ns16550.c b/drivers/serial/ns16550.c index 1377c9a0e1..cc121eee27 100644 --- a/drivers/serial/ns16550.c +++ b/drivers/serial/ns16550.c @@ -564,6 +564,8 @@ int ns16550_serial_of_to_plat(struct udevice *dev) if (!plat->clock) plat->clock = dev_read_u32_default(dev, "clock-frequency", CONFIG_SYS_NS16550_CLK); + if (!plat->clock) + plat->clock = CONFIG_SYS_NS16550_CLK; if (!plat->clock) { debug("ns16550 clock not defined\n"); return -EINVAL; -- cgit v1.2.1