From 62a05573822fc253a1ad5037482511347d6abaa5 Mon Sep 17 00:00:00 2001 From: Thomas Chou Date: Fri, 30 Jul 2010 14:12:12 +0800 Subject: nios2: fix bootm error on fdt args We should check argv[3] only if there are enough args. Otherwise, it might cause invalid memory access fault. Signed-off-by: Thomas Chou Signed-off-by: Scott McNutt --- arch/nios2/lib/bootm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/nios2/lib/bootm.c b/arch/nios2/lib/bootm.c index e25a1137f1..40a4d15027 100644 --- a/arch/nios2/lib/bootm.c +++ b/arch/nios2/lib/bootm.c @@ -42,7 +42,7 @@ int do_bootm_linux(int flag, int argc, char * const argv[], bootm_headers_t *ima if (boot_get_fdt(flag, argc, argv, images, &of_flat_tree, &of_size)) return 1; #endif - if (!of_flat_tree) + if (!of_flat_tree && argc > 3) of_flat_tree = (char *)simple_strtoul(argv[3], NULL, 16); if (of_flat_tree) initrd_end = (ulong)of_flat_tree; -- cgit v1.2.3 From 7a6a7d10e6b96ab4a5c0d8852802ec52be2b582e Mon Sep 17 00:00:00 2001 From: Thomas Chou Date: Mon, 16 Aug 2010 10:49:44 +0800 Subject: nios2: fix out of reach case for do_reset There is a limitation (or bug?) of nios2 toolchain. The nios2 gcc didn't generate correct code when the reset vector is passed as a constant. It just generated a direct "call", which was wrong when the reset vector was not located in the same 256MB span as u-boot. The "Nios II Processor Reference Handbook" said, "call can transfer execution anywhere within the 256 MByte range determined by PC31..28. The Nios II GNU linker does not automatically handle cases in which the address is out of this range." So we have to use registered "callr" instruction to do the job. Signed-off-by: Thomas Chou Signed-off-by: Scott McNutt --- arch/nios2/cpu/cpu.c | 11 +++++------ arch/nios2/include/asm/system.h | 5 +++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/arch/nios2/cpu/cpu.c b/arch/nios2/cpu/cpu.c index 6379534a0b..d9c654477d 100644 --- a/arch/nios2/cpu/cpu.c +++ b/arch/nios2/cpu/cpu.c @@ -40,11 +40,10 @@ int checkcpu (void) return (0); } - -int do_reset (void) +int do_reset(void) { - void (*rst)(void) = (void(*)(void))CONFIG_SYS_RESET_ADDR; - disable_interrupts (); - rst(); - return(0); + disable_interrupts(); + /* indirect call to go beyond 256MB limitation of toolchain */ + nios2_callr(CONFIG_SYS_RESET_ADDR); + return 0; } diff --git a/arch/nios2/include/asm/system.h b/arch/nios2/include/asm/system.h index bb03ca5316..086d92bb0c 100644 --- a/arch/nios2/include/asm/system.h +++ b/arch/nios2/include/asm/system.h @@ -56,4 +56,9 @@ ((flags & NIOS2_STATUS_PIE_MSK) == 0x0); \ }) +/* indirect call to go beyond 256MB limitation of toolchain */ +#define nios2_callr(addr) __asm__ __volatile__ ( \ + "callr %0" \ + : : "r" (addr)) + #endif /* __ASM_NIOS2_SYSTEM_H */ -- cgit v1.2.3