From 830d73b4de41a3bfd20bf0bfdfe0189214340ed4 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 27 Mar 2022 14:26:14 -0600 Subject: sandbox: Correct loss of early output in SPL At present fputc() is used before the console is available, then write() is used. These are not compatible. Since fputc() buffers internally it is better to use the write(), so that a partial line is immediately displayed. This has a slight effect on performance, but we are already using write() for the vast majority of the output with no obvious impacts. Signed-off-by: Simon Glass --- arch/sandbox/cpu/os.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c index d83c862..5ea5417 100644 --- a/arch/sandbox/cpu/os.c +++ b/arch/sandbox/cpu/os.c @@ -644,7 +644,7 @@ int os_get_filesize(const char *fname, long long *size) void os_putc(int ch) { - fputc(ch, stdout); + os_write(1, &ch, 1); } void os_puts(const char *str) -- cgit v1.1 From 55cbf5ad50a3b418ef1bb72fe2ec5f2aaebc0a00 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 27 Mar 2022 14:26:15 -0600 Subject: Makefile: Drop a stale comment about linking The bug mentioned here is fixed, so drop the comment. Signed-off-by: Simon Glass --- Makefile | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Makefile b/Makefile index 9b25536..7937a4c 100644 --- a/Makefile +++ b/Makefile @@ -1785,10 +1785,6 @@ quiet_cmd_u-boot__ ?= LTO $@ -Wl,-Map,u-boot.map; \ $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true) else -# Note: Linking efi-x86_app64 causes a segfault in the linker at present -# when using x86_64-linux-gnu-ld.bfd -# For now, disable --whole-archive which makes things link, although not -# correctly quiet_cmd_u-boot__ ?= LD $@ cmd_u-boot__ ?= $(LD) $(KBUILD_LDFLAGS) $(LDFLAGS_u-boot) -o $@ \ -T u-boot.lds $(u-boot-init) \ -- cgit v1.1 From 1ddda37bbea1b8dcc33fd05408c1ca887f02a3b6 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 27 Mar 2022 14:26:16 -0600 Subject: Makefile: Avoid resetting link flags in config.mk This makes it impossible to change them elsewhere. The default value is 'empty' anyway, so just drop it. Signed-off-by: Simon Glass --- config.mk | 1 - 1 file changed, 1 deletion(-) diff --git a/config.mk b/config.mk index 2595aed..b915c29 100644 --- a/config.mk +++ b/config.mk @@ -12,7 +12,6 @@ # If we did not have Tegra SoCs, build system would be much simpler...) PLATFORM_RELFLAGS := PLATFORM_CPPFLAGS := -KBUILD_LDFLAGS := LDFLAGS_FINAL := LDFLAGS_STANDALONE := OBJCOPYFLAGS := -- cgit v1.1 From 1b34719b615bee0528f3c3957134aad0fb3e6fb5 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 27 Mar 2022 14:26:17 -0600 Subject: sandbox: Allow link flags to be given At present the link flags are not used for sandbox. Update the command line to use them. Signed-off-by: Simon Glass --- arch/sandbox/config.mk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/sandbox/config.mk b/arch/sandbox/config.mk index 2b1b657..02a3ba0 100644 --- a/arch/sandbox/config.mk +++ b/arch/sandbox/config.mk @@ -16,7 +16,7 @@ PLATFORM_CPPFLAGS += $(shell $(SDL_CONFIG) --cflags) endif cmd_u-boot__ = $(CC) -o $@ -Wl,-T u-boot.lds $(u-boot-init) \ - $(LTO_FINAL_LDFLAGS) \ + $(KBUILD_LDFLAGS:%=-Wl,%)$(LTO_FINAL_LDFLAGS) \ -Wl,--whole-archive \ $(u-boot-main) \ $(u-boot-keep-syms-lto) \ @@ -24,7 +24,7 @@ cmd_u-boot__ = $(CC) -o $@ -Wl,-T u-boot.lds $(u-boot-init) \ $(PLATFORM_LIBS) -Wl,-Map -Wl,u-boot.map cmd_u-boot-spl = (cd $(obj) && $(CC) -o $(SPL_BIN) -Wl,-T u-boot-spl.lds \ - $(LTO_FINAL_LDFLAGS) \ + $(KBUILD_LDFLAGS:%=-Wl,%) $(LTO_FINAL_LDFLAGS) \ $(patsubst $(obj)/%,%,$(u-boot-spl-init)) \ -Wl,--whole-archive \ $(patsubst $(obj)/%,%,$(u-boot-spl-main)) \ -- cgit v1.1 From 0c6be933ffeb991c1b9b70bce9cf9e9cdb92c9ed Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 27 Mar 2022 14:26:18 -0600 Subject: sandbox: Align linker lists to a 32-byte boundary Use this larger boundary to ensure that linker lists at least start on the maximum possible alignment boundary. See also the CONFIG_LINKER_LIST_ALIGN setting, but that is host-arch-specific, so it seems better to use the largest value for every host architecture. Signed-off-by: Simon Glass --- arch/sandbox/cpu/u-boot-spl.lds | 2 +- arch/sandbox/cpu/u-boot.lds | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/sandbox/cpu/u-boot-spl.lds b/arch/sandbox/cpu/u-boot-spl.lds index 6754f4e..206e265 100644 --- a/arch/sandbox/cpu/u-boot-spl.lds +++ b/arch/sandbox/cpu/u-boot-spl.lds @@ -8,7 +8,7 @@ SECTIONS { - . = ALIGN(4); + . = ALIGN(32); .u_boot_list : { KEEP(*(SORT(.u_boot_list*))); } diff --git a/arch/sandbox/cpu/u-boot.lds b/arch/sandbox/cpu/u-boot.lds index 6d71061..92e834a 100644 --- a/arch/sandbox/cpu/u-boot.lds +++ b/arch/sandbox/cpu/u-boot.lds @@ -8,7 +8,7 @@ SECTIONS { - . = ALIGN(4); + . = ALIGN(32); .u_boot_list : { KEEP(*(SORT(.u_boot_list*))); } -- cgit v1.1 From 092d5c2a83b730844aeaa5ac300ddc7f13a75f49 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 27 Mar 2022 14:26:19 -0600 Subject: dm: core: Allow devres to be disabled in SPL At present if devres is enabled in U-Boot proper it is enabled in SPL. We don't normally want it there, so disable it. Signed-off-by: Simon Glass Tested-by: Angus Ainslie --- drivers/core/Makefile | 2 +- drivers/core/device.c | 2 +- include/dm/device-internal.h | 6 +++--- include/dm/device.h | 2 +- include/dm/devres.h | 4 ++-- test/dm/Makefile | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/core/Makefile b/drivers/core/Makefile index 3742e75..7099073 100644 --- a/drivers/core/Makefile +++ b/drivers/core/Makefile @@ -4,7 +4,7 @@ obj-y += device.o fdtaddr.o lists.o root.o uclass.o util.o tag.o obj-$(CONFIG_$(SPL_TPL_)ACPIGEN) += acpi.o -obj-$(CONFIG_DEVRES) += devres.o +obj-$(CONFIG_$(SPL_TPL_)DEVRES) += devres.o obj-$(CONFIG_$(SPL_)DM_DEVICE_REMOVE) += device-remove.o obj-$(CONFIG_$(SPL_)SIMPLE_BUS) += simple-bus.o obj-$(CONFIG_SIMPLE_PM_BUS) += simple-pm-bus.o diff --git a/drivers/core/device.c b/drivers/core/device.c index 1b356f1..b7ce854 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -68,7 +68,7 @@ static int device_bind_common(struct udevice *parent, const struct driver *drv, INIT_LIST_HEAD(&dev->sibling_node); INIT_LIST_HEAD(&dev->child_head); INIT_LIST_HEAD(&dev->uclass_node); -#ifdef CONFIG_DEVRES +#if CONFIG_IS_ENABLED(DEVRES) INIT_LIST_HEAD(&dev->devres_head); #endif dev_set_plat(dev, plat); diff --git a/include/dm/device-internal.h b/include/dm/device-internal.h index e24b033..94844d3 100644 --- a/include/dm/device-internal.h +++ b/include/dm/device-internal.h @@ -397,7 +397,7 @@ fdt_addr_t simple_bus_translate(struct udevice *dev, fdt_addr_t addr); #define DM_UCLASS_ROOT_S_NON_CONST (((gd_t *)gd)->uclass_root_s) /* device resource management */ -#ifdef CONFIG_DEVRES +#if CONFIG_IS_ENABLED(DEVRES) /** * devres_release_probe - Release managed resources allocated after probing @@ -417,7 +417,7 @@ void devres_release_probe(struct udevice *dev); */ void devres_release_all(struct udevice *dev); -#else /* ! CONFIG_DEVRES */ +#else /* ! DEVRES */ static inline void devres_release_probe(struct udevice *dev) { @@ -427,7 +427,7 @@ static inline void devres_release_all(struct udevice *dev) { } -#endif /* ! CONFIG_DEVRES */ +#endif /* DEVRES */ static inline int device_notify(const struct udevice *dev, enum event_t type) { diff --git a/include/dm/device.h b/include/dm/device.h index cb52a09..3d8961f 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -184,7 +184,7 @@ struct udevice { #if CONFIG_IS_ENABLED(OF_REAL) ofnode node_; #endif -#ifdef CONFIG_DEVRES +#if CONFIG_IS_ENABLED(DEVRES) struct list_head devres_head; #endif #if CONFIG_IS_ENABLED(DM_DMA) diff --git a/include/dm/devres.h b/include/dm/devres.h index 0ab277e..697534a 100644 --- a/include/dm/devres.h +++ b/include/dm/devres.h @@ -30,7 +30,7 @@ struct devres_stats { int total_size; }; -#ifdef CONFIG_DEVRES +#if CONFIG_IS_ENABLED(DEVRES) #ifdef CONFIG_DEBUG_DEVRES void *__devres_alloc(dr_release_t release, size_t size, gfp_t gfp, @@ -207,7 +207,7 @@ void devm_kfree(struct udevice *dev, void *ptr); /* Get basic stats on allocations */ void devres_get_stats(const struct udevice *dev, struct devres_stats *stats); -#else /* ! CONFIG_DEVRES */ +#else /* ! DEVRES */ static inline void *devres_alloc(dr_release_t release, size_t size, gfp_t gfp) { diff --git a/test/dm/Makefile b/test/dm/Makefile index d46552f..9a1a904 100644 --- a/test/dm/Makefile +++ b/test/dm/Makefile @@ -32,7 +32,7 @@ obj-$(CONFIG_CLK) += clk.o clk_ccf.o obj-$(CONFIG_CPU) += cpu.o obj-$(CONFIG_CROS_EC) += cros_ec.o obj-$(CONFIG_PWM_CROS_EC) += cros_ec_pwm.o -obj-$(CONFIG_DEVRES) += devres.o +obj-$(CONFIG_$(SPL_TPL_)DEVRES) += devres.o obj-$(CONFIG_DMA) += dma.o obj-$(CONFIG_VIDEO_MIPI_DSI) += dsi_host.o obj-$(CONFIG_DM_DSA) += dsa.o -- cgit v1.1 From cdd73e7215b838095984f02554fc1bc4186124af Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 27 Mar 2022 14:26:20 -0600 Subject: dm: core: Deal with a wrinkle with linker lists When every member of a linker list is aligned by the compiler, we can no longer rely on the sizeof of the struct to determine the number of entries. For example, if the struct size is 0x90 but every entry is aligned to 0xa0 by the compiler, the linker list entries takes more space in memory and the calculation of the number of entries is incorrect. For example, we may see 0x12 entries when there are only 0x11. This is a real problem. There may be a general solution, although I cannot currently think of one. So far it only bites with OF_PLATDATA_RT which creates a pointer to each entry of the 'struct udevice' linker_list. This does not happen without that option, so it only affects SPL. Work around it by manually calculating the aligned size of struct udevice, then using that for the n_ent calculation. Note: the alignment fix to linker list was here: 0b2fa98aa5e linker_lists: Fix alignment issue Signed-off-by: Simon Glass --- drivers/core/device.c | 3 ++- drivers/core/root.c | 8 +++++++- include/dm/device.h | 8 ++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/drivers/core/device.c b/drivers/core/device.c index b7ce854..3ab2583 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -1186,7 +1186,8 @@ int dev_enable_by_path(const char *path) static struct udevice_rt *dev_get_rt(const struct udevice *dev) { struct udevice *base = ll_entry_start(struct udevice, udevice); - int idx = dev - base; + uint each_size = dm_udevice_size(); + int idx = ((void *)dev - (void *)base) / each_size; struct udevice_rt *urt = gd_dm_udevice_rt() + idx; diff --git a/drivers/core/root.c b/drivers/core/root.c index 86b3884..e09c12f 100644 --- a/drivers/core/root.c +++ b/drivers/core/root.c @@ -136,12 +136,18 @@ static int dm_setup_inst(void) if (CONFIG_IS_ENABLED(OF_PLATDATA_RT)) { struct udevice_rt *urt; + void *start, *end; + int each_size; void *base; int n_ents; uint size; /* Allocate the udevice_rt table */ - n_ents = ll_entry_count(struct udevice, udevice); + each_size = dm_udevice_size(); + start = ll_entry_start(struct udevice, udevice); + end = ll_entry_end(struct udevice, udevice); + size = end - start; + n_ents = size / each_size; urt = calloc(n_ents, sizeof(struct udevice_rt)); if (!urt) return log_msg_ret("urt", -ENOMEM); diff --git a/include/dm/device.h b/include/dm/device.h index 3d8961f..e0f86f5 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -192,6 +192,14 @@ struct udevice { #endif }; +static inline int dm_udevice_size(void) +{ + if (CONFIG_IS_ENABLED(OF_PLATDATA_RT)) + return ALIGN(sizeof(struct udevice), CONFIG_LINKER_LIST_ALIGN); + + return sizeof(struct udevice); +} + /** * struct udevice_rt - runtime information set up by U-Boot * -- cgit v1.1