From e91c960a5ea9e9a516b81dad0fa79ae1164d72a5 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Thu, 7 Mar 2013 12:52:31 +0100 Subject: [PATCH 1/8] mips: initialize malloc pool before start_barebox() Signed-off-by: Sascha Hauer --- arch/mips/boot/main_entry.c | 5 +++++ arch/mips/lib/Makefile | 1 - arch/mips/lib/memory.c | 29 ----------------------------- 3 files changed, 5 insertions(+), 30 deletions(-) delete mode 100644 arch/mips/lib/memory.c diff --git a/arch/mips/boot/main_entry.c b/arch/mips/boot/main_entry.c index 0a33c4514..015150bfb 100644 --- a/arch/mips/boot/main_entry.c +++ b/arch/mips/boot/main_entry.c @@ -18,6 +18,8 @@ #include #include +#include +#include #include #include #include @@ -90,5 +92,8 @@ void main_entry(void) trap_init(); + mem_malloc_init((void *)MALLOC_BASE, + (void *)(MALLOC_BASE + MALLOC_SIZE - 1)); + start_barebox(); } diff --git a/arch/mips/lib/Makefile b/arch/mips/lib/Makefile index a31046b80..71c4f6b2f 100644 --- a/arch/mips/lib/Makefile +++ b/arch/mips/lib/Makefile @@ -3,7 +3,6 @@ obj-$(CONFIG_CSRC_R4K_LIB) += csrc-r4k.o obj-y += lshrdi3.o obj-y += ashldi3.o obj-y += ashrdi3.o -obj-y += memory.o obj-y += cpu-probe.o obj-y += traps.o obj-y += genex.o diff --git a/arch/mips/lib/memory.c b/arch/mips/lib/memory.c deleted file mode 100644 index 003fc008f..000000000 --- a/arch/mips/lib/memory.c +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (C) 2011 Antony Pavlov - * - * This file is part of barebox. - * See file CREDITS for list of people who contributed to this project. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ - -#include -#include -#include -#include - -static int mips_mem_malloc_init(void) -{ - mem_malloc_init((void *)MALLOC_BASE, - (void *)(MALLOC_BASE + MALLOC_SIZE - 1)); - return 0; -} -core_initcall(mips_mem_malloc_init); From bb80d9cd22b27d97fda2257a6dcdef1c3b67bfc7 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Thu, 7 Mar 2013 12:54:26 +0100 Subject: [PATCH 2/8] nios: initialize malloc pool before start_barebox() Signed-off-by: Sascha Hauer --- arch/nios2/cpu/start.S | 4 ++-- arch/nios2/lib/board.c | 8 ++------ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/arch/nios2/cpu/start.S b/arch/nios2/cpu/start.S index 42520d7cc..41f65ff70 100644 --- a/arch/nios2/cpu/start.S +++ b/arch/nios2/cpu/start.S @@ -150,8 +150,8 @@ _reloc: /* * Call board_init -- never returns */ - movhi r4, %hi(start_barebox@h) - ori r4, r4, %lo(start_barebox@h) + movhi r4, %hi(nios_start_barebox@h) + ori r4, r4, %lo(nios_start_barebox@h) callr r4 /* NEVER RETURNS -- but branch to the _start just diff --git a/arch/nios2/lib/board.c b/arch/nios2/lib/board.c index 624a4f86c..7c4dc76e8 100644 --- a/arch/nios2/lib/board.c +++ b/arch/nios2/lib/board.c @@ -18,23 +18,19 @@ #include #include -#include #include #include #include -int altera_mem_malloc_init(void) +void __noreturn nios_start_barebox(void) { mem_malloc_init((void *)(NIOS_SOPC_TEXT_BASE - MALLOC_SIZE), (void *)(NIOS_SOPC_TEXT_BASE - 1)); - return 0; + start_barebox(); } -core_initcall(altera_mem_malloc_init); - void arch_shutdown(void) { } - From a4c2d0259dd7f40c509e001e1ea2dfbeeac4cb99 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Thu, 7 Mar 2013 12:56:07 +0100 Subject: [PATCH 3/8] openrisc: initialize malloc pool before start_barebox() Signed-off-by: Sascha Hauer --- arch/openrisc/cpu/start.S | 2 +- arch/openrisc/lib/board.c | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/arch/openrisc/cpu/start.S b/arch/openrisc/cpu/start.S index 9109cceef..269abc0bf 100644 --- a/arch/openrisc/cpu/start.S +++ b/arch/openrisc/cpu/start.S @@ -245,7 +245,7 @@ _start: l.andi r30, r0, 0 l.andi r31, r0, 0 - l.j start_barebox + l.j openrisc_start_barebox l.nop .size _start, .-_start diff --git a/arch/openrisc/lib/board.c b/arch/openrisc/lib/board.c index f62fbaf4a..98033b42c 100644 --- a/arch/openrisc/lib/board.c +++ b/arch/openrisc/lib/board.c @@ -22,17 +22,14 @@ #include #include -int openrisc_mem_malloc_init(void) +void __noreturn openrisc_start_barebox(void) { - mem_malloc_init((void *)(OPENRISC_SOPC_TEXT_BASE - MALLOC_SIZE), (void *)(OPENRISC_SOPC_TEXT_BASE - 1)); - return 0; + start_barebox(); } -core_initcall(openrisc_mem_malloc_init); - void arch_shutdown(void) { } From 1d9547773cd0e39472760e1eab21c3ff86c08db7 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Thu, 7 Mar 2013 12:57:26 +0100 Subject: [PATCH 4/8] blackfin: initialize malloc pool before start_barebox() Signed-off-by: Sascha Hauer --- arch/blackfin/cpu-bf561/start.S | 4 ++-- arch/blackfin/lib/board.c | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/arch/blackfin/cpu-bf561/start.S b/arch/blackfin/cpu-bf561/start.S index 2664588d6..96da6b5dd 100644 --- a/arch/blackfin/cpu-bf561/start.S +++ b/arch/blackfin/cpu-bf561/start.S @@ -329,8 +329,8 @@ _clear_bss_skip: [p0] = r0; #endif - p0.l = _start_barebox; - p0.h = _start_barebox; + p0.l = _blackfin_start_barebox; + p0.h = _blackfin_start_barebox; jump (p0); reset_start: diff --git a/arch/blackfin/lib/board.c b/arch/blackfin/lib/board.c index e335d6cbd..88ad61871 100644 --- a/arch/blackfin/lib/board.c +++ b/arch/blackfin/lib/board.c @@ -31,15 +31,13 @@ #include #include -int blackfin_mem_malloc_init(void) +void __noreturn blackfin_start_barebox(void) { mem_malloc_init((void *)(MALLOC_BASE), (void *)(MALLOC_BASE + MALLOC_SIZE - 1)); - return 0; + start_barebox(); } -core_initcall(blackfin_mem_malloc_init); - void arch_shutdown(void) { icache_disable(); From 7a76f0607bef50e4439d162e577007aa74f51a5f Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Thu, 7 Mar 2013 12:58:39 +0100 Subject: [PATCH 5/8] x86: initialize malloc pool before start_barebox() Signed-off-by: Sascha Hauer --- arch/x86/boot/main_entry.c | 4 ++-- arch/x86/lib/memory.c | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/arch/x86/boot/main_entry.c b/arch/x86/boot/main_entry.c index f7f4710c4..afb7e32df 100644 --- a/arch/x86/boot/main_entry.c +++ b/arch/x86/boot/main_entry.c @@ -22,7 +22,7 @@ #include #include -extern void start_barebox(void); +extern void x86_start_barebox(void); /** * Called plainly from assembler that switches from real to flat mode @@ -33,5 +33,5 @@ void uboot_entry(void) { /* clear the BSS first */ memset(__bss_start, 0x00, __bss_stop - __bss_start); - start_barebox(); + x86_start_barebox(); } diff --git a/arch/x86/lib/memory.c b/arch/x86/lib/memory.c index 43b693125..de0e5d907 100644 --- a/arch/x86/lib/memory.c +++ b/arch/x86/lib/memory.c @@ -21,6 +21,7 @@ * @brief Memory management */ +#include #include #include #include @@ -36,7 +37,7 @@ * - memory above 0x100000 */ -static int x86_mem_malloc_init(void) +int x86_start_barebox(void) { #ifdef CONFIG_MEMORY_LAYOUT_DEFAULT unsigned long memory_size; @@ -57,7 +58,5 @@ static int x86_mem_malloc_init(void) mem_malloc_init((void *)MALLOC_BASE, (void *)(MALLOC_BASE + MALLOC_SIZE - 1)); #endif - return 0; + start_barebox(); } - -core_initcall(x86_mem_malloc_init); From 1a66a775674e3ae940e68c95e42dbad75af77523 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Wed, 6 Mar 2013 20:03:50 +0100 Subject: [PATCH 6/8] bus: Make struct device a pointer struct bus_type contains an embedded struct device_d which is quite a big structure. Dynamically allocate this instead to save the space in the binary. Signed-off-by: Sascha Hauer --- drivers/base/bus.c | 7 ++++--- drivers/base/driver.c | 2 +- include/driver.h | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/base/bus.c b/drivers/base/bus.c index e2204da4a..5251be6b2 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -30,10 +30,11 @@ int bus_register(struct bus_type *bus) if (get_bus_by_name(bus->name)) return -EEXIST; - strcpy(bus->dev.name, bus->name); - bus->dev.id = DEVICE_ID_SINGLE; + bus->dev = xzalloc(sizeof(*bus->dev)); + strcpy(bus->dev->name, bus->name); + bus->dev->id = DEVICE_ID_SINGLE; - ret = register_device(&bus->dev); + ret = register_device(bus->dev); if (ret) return ret; diff --git a/drivers/base/driver.c b/drivers/base/driver.c index fa30c6805..487f478d6 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c @@ -135,7 +135,7 @@ int register_device(struct device_d *new_device) if (new_device->bus) { if (!new_device->parent) - new_device->parent = &new_device->bus->dev; + new_device->parent = new_device->bus->dev; list_add_tail(&new_device->bus_list, &new_device->bus->device_list); diff --git a/include/driver.h b/include/driver.h index 46c56c0ac..2d107e1ca 100644 --- a/include/driver.h +++ b/include/driver.h @@ -368,7 +368,7 @@ struct bus_type { int (*probe)(struct device_d *dev); void (*remove)(struct device_d *dev); - struct device_d dev; + struct device_d *dev; struct list_head list; struct list_head device_list; From 32f8f583c9e11f85aa01e324b712e1fdd63fe797 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Thu, 7 Mar 2013 16:14:16 +0100 Subject: [PATCH 7/8] fs: allocate FILE table dynamically Some systems are runnignfrom a very limited SRAM, but have a huge malloc space in SDRAM. The bss normally is in SRAM, so we should avoid having big structures there. The FILE table is 5120 bytes big, so allocate it dynamically instead. Signed-off-by: Sascha Hauer --- fs/fs.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/fs/fs.c b/fs/fs.c index 6346112e5..7e2fb7884 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -119,14 +119,19 @@ EXPORT_SYMBOL(mkmodestr); static char *cwd; -static int init_cwd(void) +static FILE *files; + +static int init_fs(void) { cwd = xzalloc(PATH_MAX); *cwd = '/'; + + files = xzalloc(sizeof(FILE) * MAX_FILES); + return 0; } -postcore_initcall(init_cwd); +postcore_initcall(init_fs); char *normalise_link(const char *pathname, const char *symlink) { @@ -268,8 +273,6 @@ char *get_mounted_path(const char *path) return fdev->path; } -static FILE files[MAX_FILES]; - static FILE *get_file(void) { int i; From 6c370ee23010a441508ce91619ea0a7040251090 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Thu, 7 Mar 2013 16:14:16 +0100 Subject: [PATCH 8/8] gpio: allocate gpio_desc table dynamically Some systems are runnignfrom a very limited SRAM, but have a huge malloc space in SDRAM. The bss normally is in SRAM, so we should avoid having big structures there. The gpio_desc table is 3072 bytes big, so allocate it dynamically instead. Signed-off-by: Sascha Hauer --- drivers/gpio/gpio.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/gpio.c b/drivers/gpio/gpio.c index d37f5a0db..9d081c237 100644 --- a/drivers/gpio/gpio.c +++ b/drivers/gpio/gpio.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -13,7 +14,15 @@ struct gpio_info { char *label; }; -static struct gpio_info gpio_desc[ARCH_NR_GPIOS]; +static struct gpio_info *gpio_desc; + +static int gpio_desc_alloc(void) +{ + gpio_desc = xzalloc(sizeof(struct gpio_info) * ARCH_NR_GPIOS); + + return 0; +} +pure_initcall(gpio_desc_alloc); static int gpio_ensure_requested(struct gpio_info *gi, int gpio) {