Skip to content

Commit aec75a3

Browse files
committed
Merge branch '2022-04-18-dm-reducing-spl-memory-usage'
- Assorted DM cleanups from Simon. This results in some noticeable binary size savings in SPL.
2 parents 9859465 + cdd73e7 commit aec75a3

File tree

13 files changed

+31
-21
lines changed

13 files changed

+31
-21
lines changed

Makefile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1785,10 +1785,6 @@ quiet_cmd_u-boot__ ?= LTO $@
17851785
-Wl,-Map,u-boot.map; \
17861786
$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
17871787
else
1788-
# Note: Linking efi-x86_app64 causes a segfault in the linker at present
1789-
# when using x86_64-linux-gnu-ld.bfd
1790-
# For now, disable --whole-archive which makes things link, although not
1791-
# correctly
17921788
quiet_cmd_u-boot__ ?= LD $@
17931789
cmd_u-boot__ ?= $(LD) $(KBUILD_LDFLAGS) $(LDFLAGS_u-boot) -o $@ \
17941790
-T u-boot.lds $(u-boot-init) \

arch/sandbox/config.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ PLATFORM_CPPFLAGS += $(shell $(SDL_CONFIG) --cflags)
1616
endif
1717

1818
cmd_u-boot__ = $(CC) -o $@ -Wl,-T u-boot.lds $(u-boot-init) \
19-
$(LTO_FINAL_LDFLAGS) \
19+
$(KBUILD_LDFLAGS:%=-Wl,%)$(LTO_FINAL_LDFLAGS) \
2020
-Wl,--whole-archive \
2121
$(u-boot-main) \
2222
$(u-boot-keep-syms-lto) \
2323
-Wl,--no-whole-archive \
2424
$(PLATFORM_LIBS) -Wl,-Map -Wl,u-boot.map
2525

2626
cmd_u-boot-spl = (cd $(obj) && $(CC) -o $(SPL_BIN) -Wl,-T u-boot-spl.lds \
27-
$(LTO_FINAL_LDFLAGS) \
27+
$(KBUILD_LDFLAGS:%=-Wl,%) $(LTO_FINAL_LDFLAGS) \
2828
$(patsubst $(obj)/%,%,$(u-boot-spl-init)) \
2929
-Wl,--whole-archive \
3030
$(patsubst $(obj)/%,%,$(u-boot-spl-main)) \

arch/sandbox/cpu/os.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ int os_get_filesize(const char *fname, long long *size)
644644

645645
void os_putc(int ch)
646646
{
647-
fputc(ch, stdout);
647+
os_write(1, &ch, 1);
648648
}
649649

650650
void os_puts(const char *str)

arch/sandbox/cpu/u-boot-spl.lds

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
SECTIONS
99
{
1010

11-
. = ALIGN(4);
11+
. = ALIGN(32);
1212
.u_boot_list : {
1313
KEEP(*(SORT(.u_boot_list*)));
1414
}

arch/sandbox/cpu/u-boot.lds

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
SECTIONS
99
{
1010

11-
. = ALIGN(4);
11+
. = ALIGN(32);
1212
.u_boot_list : {
1313
KEEP(*(SORT(.u_boot_list*)));
1414
}

config.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
# If we did not have Tegra SoCs, build system would be much simpler...)
1313
PLATFORM_RELFLAGS :=
1414
PLATFORM_CPPFLAGS :=
15-
KBUILD_LDFLAGS :=
1615
LDFLAGS_FINAL :=
1716
LDFLAGS_STANDALONE :=
1817
OBJCOPYFLAGS :=

drivers/core/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
obj-y += device.o fdtaddr.o lists.o root.o uclass.o util.o tag.o
66
obj-$(CONFIG_$(SPL_TPL_)ACPIGEN) += acpi.o
7-
obj-$(CONFIG_DEVRES) += devres.o
7+
obj-$(CONFIG_$(SPL_TPL_)DEVRES) += devres.o
88
obj-$(CONFIG_$(SPL_)DM_DEVICE_REMOVE) += device-remove.o
99
obj-$(CONFIG_$(SPL_)SIMPLE_BUS) += simple-bus.o
1010
obj-$(CONFIG_SIMPLE_PM_BUS) += simple-pm-bus.o

drivers/core/device.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static int device_bind_common(struct udevice *parent, const struct driver *drv,
6868
INIT_LIST_HEAD(&dev->sibling_node);
6969
INIT_LIST_HEAD(&dev->child_head);
7070
INIT_LIST_HEAD(&dev->uclass_node);
71-
#ifdef CONFIG_DEVRES
71+
#if CONFIG_IS_ENABLED(DEVRES)
7272
INIT_LIST_HEAD(&dev->devres_head);
7373
#endif
7474
dev_set_plat(dev, plat);
@@ -1186,7 +1186,8 @@ int dev_enable_by_path(const char *path)
11861186
static struct udevice_rt *dev_get_rt(const struct udevice *dev)
11871187
{
11881188
struct udevice *base = ll_entry_start(struct udevice, udevice);
1189-
int idx = dev - base;
1189+
uint each_size = dm_udevice_size();
1190+
int idx = ((void *)dev - (void *)base) / each_size;
11901191

11911192
struct udevice_rt *urt = gd_dm_udevice_rt() + idx;
11921193

drivers/core/root.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,18 @@ static int dm_setup_inst(void)
136136

137137
if (CONFIG_IS_ENABLED(OF_PLATDATA_RT)) {
138138
struct udevice_rt *urt;
139+
void *start, *end;
140+
int each_size;
139141
void *base;
140142
int n_ents;
141143
uint size;
142144

143145
/* Allocate the udevice_rt table */
144-
n_ents = ll_entry_count(struct udevice, udevice);
146+
each_size = dm_udevice_size();
147+
start = ll_entry_start(struct udevice, udevice);
148+
end = ll_entry_end(struct udevice, udevice);
149+
size = end - start;
150+
n_ents = size / each_size;
145151
urt = calloc(n_ents, sizeof(struct udevice_rt));
146152
if (!urt)
147153
return log_msg_ret("urt", -ENOMEM);

include/dm/device-internal.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ fdt_addr_t simple_bus_translate(struct udevice *dev, fdt_addr_t addr);
397397
#define DM_UCLASS_ROOT_S_NON_CONST (((gd_t *)gd)->uclass_root_s)
398398

399399
/* device resource management */
400-
#ifdef CONFIG_DEVRES
400+
#if CONFIG_IS_ENABLED(DEVRES)
401401

402402
/**
403403
* devres_release_probe - Release managed resources allocated after probing
@@ -417,7 +417,7 @@ void devres_release_probe(struct udevice *dev);
417417
*/
418418
void devres_release_all(struct udevice *dev);
419419

420-
#else /* ! CONFIG_DEVRES */
420+
#else /* ! DEVRES */
421421

422422
static inline void devres_release_probe(struct udevice *dev)
423423
{
@@ -427,7 +427,7 @@ static inline void devres_release_all(struct udevice *dev)
427427
{
428428
}
429429

430-
#endif /* ! CONFIG_DEVRES */
430+
#endif /* DEVRES */
431431

432432
static inline int device_notify(const struct udevice *dev, enum event_t type)
433433
{

include/dm/device.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,22 @@ struct udevice {
184184
#if CONFIG_IS_ENABLED(OF_REAL)
185185
ofnode node_;
186186
#endif
187-
#ifdef CONFIG_DEVRES
187+
#if CONFIG_IS_ENABLED(DEVRES)
188188
struct list_head devres_head;
189189
#endif
190190
#if CONFIG_IS_ENABLED(DM_DMA)
191191
ulong dma_offset;
192192
#endif
193193
};
194194

195+
static inline int dm_udevice_size(void)
196+
{
197+
if (CONFIG_IS_ENABLED(OF_PLATDATA_RT))
198+
return ALIGN(sizeof(struct udevice), CONFIG_LINKER_LIST_ALIGN);
199+
200+
return sizeof(struct udevice);
201+
}
202+
195203
/**
196204
* struct udevice_rt - runtime information set up by U-Boot
197205
*

include/dm/devres.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct devres_stats {
3030
int total_size;
3131
};
3232

33-
#ifdef CONFIG_DEVRES
33+
#if CONFIG_IS_ENABLED(DEVRES)
3434

3535
#ifdef CONFIG_DEBUG_DEVRES
3636
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);
207207
/* Get basic stats on allocations */
208208
void devres_get_stats(const struct udevice *dev, struct devres_stats *stats);
209209

210-
#else /* ! CONFIG_DEVRES */
210+
#else /* ! DEVRES */
211211

212212
static inline void *devres_alloc(dr_release_t release, size_t size, gfp_t gfp)
213213
{

test/dm/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ obj-$(CONFIG_CLK) += clk.o clk_ccf.o
3232
obj-$(CONFIG_CPU) += cpu.o
3333
obj-$(CONFIG_CROS_EC) += cros_ec.o
3434
obj-$(CONFIG_PWM_CROS_EC) += cros_ec_pwm.o
35-
obj-$(CONFIG_DEVRES) += devres.o
35+
obj-$(CONFIG_$(SPL_TPL_)DEVRES) += devres.o
3636
obj-$(CONFIG_DMA) += dma.o
3737
obj-$(CONFIG_VIDEO_MIPI_DSI) += dsi_host.o
3838
obj-$(CONFIG_DM_DSA) += dsa.o

0 commit comments

Comments
 (0)