From 020a30be0d9a3b56a98c4e4094d13d3b4e3bd4eb Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Sat, 26 Nov 2011 21:33:59 +0100 Subject: add magicvar command The magicvar command gives an overview about all environment variables with a special meaning. Signed-off-by: Sascha Hauer --- arch/blackfin/boards/ipe337/barebox.lds.S | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'arch/blackfin') diff --git a/arch/blackfin/boards/ipe337/barebox.lds.S b/arch/blackfin/boards/ipe337/barebox.lds.S index 571eeb113b..25ca988815 100644 --- a/arch/blackfin/boards/ipe337/barebox.lds.S +++ b/arch/blackfin/boards/ipe337/barebox.lds.S @@ -71,6 +71,10 @@ SECTIONS .barebox_cmd : { BAREBOX_CMDS } ___barebox_cmd_end = .; + __barebox_magicvar_start = .; + .barebox_magicvar : { BAREBOX_MAGICVARS } + __barebox_magicvar_end = .; + ___barebox_initcalls_start = .; .barebox_initcalls : { INITCALLS } ___barebox_initcalls_end = .; -- cgit v1.2.3 From 351058fa51dbc010c37906b46ecf67a41dbbad8d Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Sun, 27 Nov 2011 17:51:22 +0100 Subject: bootm: push relocate_image up to the generic command All handlers used to just relocate the image without any checks, so we are doomed if we write outside of SDRAM or will overwrite ourselves. Move the relocation up to the generic part where we have a chance of catching these issues. Signed-off-by: Sascha Hauer --- arch/arm/lib/bootm.c | 7 ------- arch/blackfin/lib/blackfin_linux.c | 3 --- arch/nios2/lib/bootm.c | 3 --- arch/ppc/lib/ppclinux.c | 3 --- commands/bootm.c | 17 +++++++++++++++++ 5 files changed, 17 insertions(+), 16 deletions(-) (limited to 'arch/blackfin') diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c index a104aaa371..5b85ba9d31 100644 --- a/arch/arm/lib/bootm.c +++ b/arch/arm/lib/bootm.c @@ -29,13 +29,6 @@ static int do_bootm_linux(struct image_data *data) debug("## Transferring control to Linux (at address 0x%p) ...\n", theKernel); - if (relocate_image(data->os, (void *)image_get_load(os_header))) - return -1; - - if (data->initrd) - if (relocate_image(data->initrd, (void *)image_get_load(&data->initrd->header))) - return -1; - /* we assume that the kernel is in place */ printf("\nStarting kernel %s...\n\n", data->initrd ? "with initrd " : ""); diff --git a/arch/blackfin/lib/blackfin_linux.c b/arch/blackfin/lib/blackfin_linux.c index a20cf55748..9da9ec4e58 100644 --- a/arch/blackfin/lib/blackfin_linux.c +++ b/arch/blackfin/lib/blackfin_linux.c @@ -50,9 +50,6 @@ static int do_bootm_linux(struct image_data *idata) appl = (int (*)(char *))image_get_ep(os_header); printf("Starting Kernel at 0x%p\n", appl); - if (relocate_image(os_handle, (void *)image_get_load(os_header))) - return -1; - icache_disable(); strncpy(cmdlinedest, cmdline, 0x1000); diff --git a/arch/nios2/lib/bootm.c b/arch/nios2/lib/bootm.c index c38243f9a3..b5b344f499 100644 --- a/arch/nios2/lib/bootm.c +++ b/arch/nios2/lib/bootm.c @@ -43,9 +43,6 @@ static int do_bootm_linux(struct image_data *idata) kernel = (void (*)(int, int, int, const char *))ntohl(os_header->ih_ep); - if (relocate_image(idata->os, (void *)ntohl(os_header->ih_load))) - return -1; - /* kernel parameters passing * r4 : NIOS magic * r5 : initrd start diff --git a/arch/ppc/lib/ppclinux.c b/arch/ppc/lib/ppclinux.c index 531c215817..471b3037fe 100644 --- a/arch/ppc/lib/ppclinux.c +++ b/arch/ppc/lib/ppclinux.c @@ -200,9 +200,6 @@ static int do_bootm_linux(struct image_data *idata) kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))image_get_ep(os_header); /* FIXME */ - if (relocate_image(idata->os, (void *)image_get_load(os_header))) - return -1; - #if defined(CFG_INIT_RAM_LOCK) && !defined(CONFIG_E500) unlock_ram_in_cache(); #endif diff --git a/commands/bootm.c b/commands/bootm.c index ff9b18520f..cad7b21261 100644 --- a/commands/bootm.c +++ b/commands/bootm.c @@ -210,6 +210,23 @@ static int do_bootm(struct command *cmdtp, int argc, char *argv[]) puts ("OK\n"); + /* + * FIXME: we do not check at all whether + * - we will write the image to sdram + * - we overwrite ourselves + * - kernel and initrd overlap + */ + ret = relocate_image(data.os, (void *)image_get_load(os_header)); + if (ret) + goto err_out; + + if (data.initrd) { + ret = relocate_image(data.initrd, + (void *)image_get_load(&data.initrd->header)); + if (ret) + goto err_out; + } + /* loop through the registered handlers */ list_for_each_entry(handler, &handler_list, list) { if (image_get_os(os_header) == handler->image_type) { -- cgit v1.2.3 From 70f7691d4110c4384e058ae3e64003ca9ad963a6 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Thu, 1 Dec 2011 22:24:04 +0100 Subject: fix malloc space sizes end is start + size - 1, not start + size. Signed-off-by: Sascha Hauer --- arch/arm/lib/arm.c | 2 +- arch/blackfin/lib/board.c | 2 +- arch/mips/lib/memory.c | 2 +- arch/nios2/lib/board.c | 2 +- arch/ppc/lib/board.c | 2 +- arch/sandbox/os/common.c | 2 +- arch/x86/lib/memory.c | 4 ++-- 7 files changed, 8 insertions(+), 8 deletions(-) (limited to 'arch/blackfin') diff --git a/arch/arm/lib/arm.c b/arch/arm/lib/arm.c index c85aae14a0..80b62e988d 100644 --- a/arch/arm/lib/arm.c +++ b/arch/arm/lib/arm.c @@ -7,7 +7,7 @@ static int arm_mem_malloc_init(void) { mem_malloc_init((void *)MALLOC_BASE, - (void *)(MALLOC_BASE + MALLOC_SIZE)); + (void *)(MALLOC_BASE + MALLOC_SIZE - 1)); return 0; } diff --git a/arch/blackfin/lib/board.c b/arch/blackfin/lib/board.c index d1b39fa347..bf5c1b64a5 100644 --- a/arch/blackfin/lib/board.c +++ b/arch/blackfin/lib/board.c @@ -38,7 +38,7 @@ int blackfin_mem_malloc_init(void) { mem_malloc_init((void *)(MALLOC_BASE), - (void *)(MALLOC_BASE + MALLOC_SIZE)); + (void *)(MALLOC_BASE + MALLOC_SIZE - 1)); return 0; } diff --git a/arch/mips/lib/memory.c b/arch/mips/lib/memory.c index ad9f6a6a40..8d2d51b72b 100644 --- a/arch/mips/lib/memory.c +++ b/arch/mips/lib/memory.c @@ -26,7 +26,7 @@ static int mips_mem_malloc_init(void) { mem_malloc_init((void *)MALLOC_BASE, - (void *)(MALLOC_BASE + MALLOC_SIZE)); + (void *)(MALLOC_BASE + MALLOC_SIZE - 1)); return 0; } core_initcall(mips_mem_malloc_init); diff --git a/arch/nios2/lib/board.c b/arch/nios2/lib/board.c index d50f05adee..ed3af49a86 100644 --- a/arch/nios2/lib/board.c +++ b/arch/nios2/lib/board.c @@ -31,7 +31,7 @@ int altera_mem_malloc_init(void) { mem_malloc_init((void *)(NIOS_SOPC_TEXT_BASE - MALLOC_SIZE), - (void *)(NIOS_SOPC_TEXT_BASE)); + (void *)(NIOS_SOPC_TEXT_BASE - 1)); return 0; } diff --git a/arch/ppc/lib/board.c b/arch/ppc/lib/board.c index 0b610a5c95..0e839eb053 100644 --- a/arch/ppc/lib/board.c +++ b/arch/ppc/lib/board.c @@ -56,7 +56,7 @@ void board_init_r (ulong end_of_ram) debug("malloc_end: 0x%08x\n", malloc_end); debug("TEXT_BASE after relocation: 0x%08x\n", _text_base); - mem_malloc_init((void *)(malloc_end - MALLOC_SIZE), (void *)malloc_end); + mem_malloc_init((void *)(malloc_end - MALLOC_SIZE), (void *)(malloc_end - 1)); /* * Setup trap handlers diff --git a/arch/sandbox/os/common.c b/arch/sandbox/os/common.c index 1c5ae5d34b..9258c66156 100644 --- a/arch/sandbox/os/common.c +++ b/arch/sandbox/os/common.c @@ -262,7 +262,7 @@ int main(int argc, char *argv[]) printf("unable to get malloc space\n"); exit(1); } - mem_malloc_init(ram, ram + malloc_size); + mem_malloc_init(ram, ram + malloc_size - 1); while (1) { int option_index = 0; diff --git a/arch/x86/lib/memory.c b/arch/x86/lib/memory.c index fa7bc03962..1774ef34fd 100644 --- a/arch/x86/lib/memory.c +++ b/arch/x86/lib/memory.c @@ -54,12 +54,12 @@ static int x86_mem_malloc_init(void) */ if (memory_size >= (15 * 1024 * 1024 + MALLOC_SIZE)) mem_malloc_init((void*)(16 * 1024 * 1024), - (void*)(16 * 1024 * 1024) + MALLOC_SIZE); + (void*)(16 * 1024 * 1024 + MALLOC_SIZE - 1)); else return -1; #else mem_malloc_init((void *)MALLOC_BASE, - (void *)(MALLOC_BASE + MALLOC_SIZE)); + (void *)(MALLOC_BASE + MALLOC_SIZE - 1)); #endif return 0; } -- cgit v1.2.3