diff options
author | Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> | 2012-07-28 01:25:56 +0800 |
---|---|---|
committer | Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> | 2012-08-03 18:09:13 +0800 |
commit | 78867e2bbd066df7d56e281e03a8cdbe82adf4e4 (patch) | |
tree | 311c827a5dc95a2d557f2c308a87f9808aede902 /arch | |
parent | d4c42fb33deb6c061e4410520a6601fb2d072a60 (diff) | |
download | barebox-78867e2bbd066df7d56e281e03a8cdbe82adf4e4.tar.gz barebox-78867e2bbd066df7d56e281e03a8cdbe82adf4e4.tar.xz |
Add pre-bootloader (pbl) image support
This allows for creating a pre-bootloader binary for
- nand boot
- mmc boot
- compressed image
The pbl will be incharge of the lowlevel init if needed.
The barebox will skip it.
Import string functions from linux 3.4 (arch/arm/boot/compressed/string.c) and
implement a dummy panic.
For now on introduce dummy zbarebox* targets and c code that will contain later
the decompressor. This only implemeted on ARM.
This patch is based on Sascha Hauer <s.hauer@pengutronix.de>
Add compressed image support patch
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Diffstat (limited to 'arch')
-rw-r--r-- | arch/arm/Kconfig | 1 | ||||
-rw-r--r-- | arch/arm/Makefile | 7 | ||||
-rw-r--r-- | arch/arm/cpu/Makefile | 3 | ||||
-rw-r--r-- | arch/arm/cpu/start-pbl.c | 80 | ||||
-rw-r--r-- | arch/arm/cpu/start-reset.c | 67 | ||||
-rw-r--r-- | arch/arm/cpu/start.c | 54 | ||||
-rw-r--r-- | arch/arm/lib/Makefile | 4 | ||||
-rw-r--r-- | arch/arm/lib/barebox.lds.S | 3 | ||||
-rw-r--r-- | arch/arm/pbl/Makefile | 25 | ||||
-rw-r--r-- | arch/arm/pbl/zbarebox.lds.S | 73 |
10 files changed, 277 insertions, 40 deletions
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 08c742bfb3..7932afc131 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -4,6 +4,7 @@ config ARM select HAS_MODULES select HAVE_CONFIGURABLE_MEMORY_LAYOUT select HAVE_CONFIGURABLE_TEXT_BASE + select HAVE_PBL_IMAGE default y config ARM_AMBA diff --git a/arch/arm/Makefile b/arch/arm/Makefile index 1b60261bc8..0ea050ebed 100644 --- a/arch/arm/Makefile +++ b/arch/arm/Makefile @@ -197,6 +197,13 @@ ifeq ($(CONFIG_ARCH_DAVINCI),y) KBUILD_IMAGE := barebox.ubl endif +pbl := arch/arm/pbl +zbarebox.S zbarebox.bin zbarebox: barebox.bin + $(Q)$(MAKE) $(build)=$(pbl) $(pbl)/$@ + +archclean: + $(MAKE) $(clean)=$(pbl) + all: $(KBUILD_IMAGE) archprepare: maketools diff --git a/arch/arm/cpu/Makefile b/arch/arm/cpu/Makefile index 93a34a9ff1..78d300dba8 100644 --- a/arch/arm/cpu/Makefile +++ b/arch/arm/cpu/Makefile @@ -1,7 +1,7 @@ obj-y += cpu.o obj-$(CONFIG_ARM_EXCEPTIONS) += exceptions.o obj-$(CONFIG_ARM_EXCEPTIONS) += interrupts.o -obj-y += start.o +obj-y += start.o start-reset.o # # Any variants can be called as start-armxyz.S @@ -15,3 +15,4 @@ obj-$(CONFIG_CPU_32v6) += cache-armv6.o obj-$(CONFIG_CPU_32v7) += cache-armv7.o obj-$(CONFIG_CACHE_L2X0) += cache-l2x0.o +pbl-y += start-pbl.o start-reset.o diff --git a/arch/arm/cpu/start-pbl.c b/arch/arm/cpu/start-pbl.c new file mode 100644 index 0000000000..28d6f34449 --- /dev/null +++ b/arch/arm/cpu/start-pbl.c @@ -0,0 +1,80 @@ +/* + * start-pbl.c + * + * Copyright (c) 2010-2012 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix + * Copyright (c) 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> + * + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include <common.h> +#include <init.h> +#include <asm/barebox-arm.h> +#include <asm/barebox-arm-head.h> +#include <asm-generic/memory_layout.h> +#include <asm/sections.h> + +void __naked __section(.text_head_entry) pbl_start(void) +{ + barebox_arm_head(); +} + +void barebox_pbl(uint32_t offset) +{ +} + +/* + * Board code can jump here by either returning from board_init_lowlevel + * or by calling this function directly. + */ +void __naked __section(.text_ll_return) board_init_lowlevel_return(void) +{ + uint32_t r, addr, offset; + + /* + * Get runtime address of this function. Do not + * put any code above this. + */ + __asm__ __volatile__("1: adr %0, 1b":"=r"(addr)); + + /* Setup the stack */ + r = STACK_BASE + STACK_SIZE - 16; + __asm__ __volatile__("mov sp, %0" : : "r"(r)); + + /* Get offset between linked address and runtime address */ + offset = (uint32_t)__ll_return - addr; + + /* relocate to link address if necessary */ + if (offset) + memcpy((void *)_text, (void *)(_text - offset), + __bss_start - _text); + + /* clear bss */ + memset(__bss_start, 0, __bss_stop - __bss_start); + + /* flush I-cache before jumping to the copied binary */ + __asm__ __volatile__("mcr p15, 0, %0, c7, c5, 0" : : "r" (0)); + + r = (unsigned int)&barebox_pbl; + /* call barebox_uncompress with its absolute address */ + __asm__ __volatile__( + "mov r0, %1\n" + "mov pc, %0\n" + : + : "r"(r), "r"(offset), + : "r0"); +} diff --git a/arch/arm/cpu/start-reset.c b/arch/arm/cpu/start-reset.c new file mode 100644 index 0000000000..e0df676274 --- /dev/null +++ b/arch/arm/cpu/start-reset.c @@ -0,0 +1,67 @@ +/* + * start-reset.c + * + * Copyright (c) 2010 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix + * + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include <common.h> +#include <init.h> +#include <asm/system.h> +#include <asm/barebox-arm.h> +#include <asm/sections.h> + +/* + * The actual reset vector. This code is position independent and usually + * does not run at the address it's linked at. + */ +void __naked __bare_init reset(void) +{ + uint32_t r; + + /* set the cpu to SVC32 mode */ + __asm__ __volatile__("mrs %0, cpsr":"=r"(r)); + r &= ~0x1f; + r |= 0xd3; + __asm__ __volatile__("msr cpsr, %0" : : "r"(r)); + +#ifdef CONFIG_ARCH_HAS_LOWLEVEL_INIT + arch_init_lowlevel(); +#endif + + /* disable MMU stuff and caches */ + r = get_cr(); + r &= ~(CR_M | CR_C | CR_B | CR_S | CR_R | CR_V); + r |= CR_I; + +#if __LINUX_ARM_ARCH__ >= 6 + r |= CR_U; +#else + r |= CR_A; +#endif + +#ifdef __ARMEB__ + r |= CR_B; +#endif + set_cr(r); + +#ifdef CONFIG_MACH_DO_LOWLEVEL_INIT + board_init_lowlevel(); +#endif + board_init_lowlevel_return(); +} diff --git a/arch/arm/cpu/start.c b/arch/arm/cpu/start.c index 112403e33e..8365a7516f 100644 --- a/arch/arm/cpu/start.c +++ b/arch/arm/cpu/start.c @@ -24,53 +24,31 @@ #include <init.h> #include <asm/barebox-arm.h> #include <asm/barebox-arm-head.h> -#include <asm/system.h> #include <asm-generic/memory_layout.h> #include <asm/sections.h> -void __naked __section(.text_entry) start(void) -{ - barebox_arm_head(); -} - +#ifdef CONFIG_PBL_IMAGE /* - * The actual reset vector. This code is position independent and usually - * does not run at the address it's linked at. + * First function in the pbl image. We get here from + * the pbl. */ -void __naked __bare_init reset(void) +void __naked __section(.text_entry) start(void) { - uint32_t r; + u32 r; - /* set the cpu to SVC32 mode */ - __asm__ __volatile__("mrs %0, cpsr":"=r"(r)); - r &= ~0x1f; - r |= 0xd3; - __asm__ __volatile__("msr cpsr, %0" : : "r"(r)); - -#ifdef CONFIG_ARCH_HAS_LOWLEVEL_INIT - arch_init_lowlevel(); -#endif - - /* disable MMU stuff and caches */ - r = get_cr(); - r &= ~(CR_M | CR_C | CR_B | CR_S | CR_R | CR_V); - r |= CR_I; + /* Setup the stack */ + r = STACK_BASE + STACK_SIZE - 16; + __asm__ __volatile__("mov sp, %0" : : "r"(r)); + /* clear bss */ + memset(__bss_start, 0, __bss_stop - __bss_start); -#if __LINUX_ARM_ARCH__ >= 6 - r |= CR_U; + start_barebox(); +} #else - r |= CR_A; -#endif - -#ifdef __ARMEB__ - r |= CR_B; -#endif - set_cr(r); -#ifdef CONFIG_MACH_DO_LOWLEVEL_INIT - board_init_lowlevel(); -#endif - board_init_lowlevel_return(); +void __naked __section(.text_entry) start(void) +{ + barebox_arm_head(); } /* @@ -109,4 +87,4 @@ void __naked __section(.text_ll_return) board_init_lowlevel_return(void) r = (unsigned int)&start_barebox; __asm__ __volatile__("mov pc, %0" : : "r"(r)); } - +#endif diff --git a/arch/arm/lib/Makefile b/arch/arm/lib/Makefile index 1eaf474911..9d0ff7a856 100644 --- a/arch/arm/lib/Makefile +++ b/arch/arm/lib/Makefile @@ -21,3 +21,7 @@ obj-$(CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS) += memset.o obj-$(CONFIG_ARM_UNWIND) += unwind.o obj-$(CONFIG_MODULES) += module.o extra-y += barebox.lds + +pbl-y += lib1funcs.o +pbl-y += ashldi3.o +pbl-y += div0.o diff --git a/arch/arm/lib/barebox.lds.S b/arch/arm/lib/barebox.lds.S index e0bae70f4f..a69013f7f5 100644 --- a/arch/arm/lib/barebox.lds.S +++ b/arch/arm/lib/barebox.lds.S @@ -31,8 +31,9 @@ SECTIONS { . = TEXT_BASE; +#ifndef CONFIG_PBL_IMAGE PRE_IMAGE - +#endif . = ALIGN(4); .text : { diff --git a/arch/arm/pbl/Makefile b/arch/arm/pbl/Makefile new file mode 100644 index 0000000000..9b364bb35a --- /dev/null +++ b/arch/arm/pbl/Makefile @@ -0,0 +1,25 @@ + +OBJCOPYFLAGS_zbarebox.bin = -O binary + +targets := zbarebox.lds zbarebox zbarebox.bin zbarebox.S + +$(obj)/zbarebox.bin: $(obj)/zbarebox FORCE + $(call if_changed,objcopy) + $(call cmd,check_file_size,$(CONFIG_BAREBOX_MAX_IMAGE_SIZE)) + @echo ' Barebox: $@ is ready' + +$(obj)/zbarebox.S: $(obj)/zbarebox FORCE + $(call if_changed,disasm) + +LDFLAGS_zbarebox := -Map zbarebox.map +zbarebox-common := $(barebox-pbl-common) +zbarebox-lds := $(obj)/zbarebox.lds + +quiet_cmd_zbarebox__ ?= LD $@ + cmd_zbarebox__ ?= $(LD) $(LDFLAGS) $(LDFLAGS_zbarebox) -o $@ \ + -T $(zbarebox-lds) \ + --start-group $(zbarebox-common) --end-group \ + $(filter-out $(zbarebox-lds) $(zbarebox-common) FORCE ,$^) + +$(obj)/zbarebox: $(zbarebox-lds) $(zbarebox-common) FORCE + $(call if_changed,zbarebox__) diff --git a/arch/arm/pbl/zbarebox.lds.S b/arch/arm/pbl/zbarebox.lds.S new file mode 100644 index 0000000000..b6e8028fd3 --- /dev/null +++ b/arch/arm/pbl/zbarebox.lds.S @@ -0,0 +1,73 @@ +/* + * (C) Copyright 2012 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix + * + * 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 as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + */ + +#include <asm-generic/barebox.lds.h> +#include <asm-generic/memory_layout.h> + +OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm") +OUTPUT_ARCH(arm) +ENTRY(pbl_start) +SECTIONS +{ + . = HEAD_TEXT_BASE; + + PRE_IMAGE + + . = ALIGN(4); + .text : + { + _stext = .; + _text = .; + *(.text_head_entry*) + __ll_return = .; + *(.text_ll_return*) + __bare_init_start = .; + *(.text_bare_init*) + __bare_init_end = .; + *(.text*) + } + BAREBOX_BARE_INIT_SIZE + + . = ALIGN(4); + .rodata : { *(.rodata*) } + + _etext = .; /* End of text and rodata section */ + + . = ALIGN(4); + .data : { *(.data*) } + + . = ALIGN(4); + __bss_start = .; + .bss : { *(.bss*) } + __bss_stop = .; + _end = .; + + . = ALIGN(4); + __piggydata_start = .; + .piggydata : { + *(.piggydata) + } + __piggydata_end = .; + + _barebox_image_size = __piggydata_end - HEAD_TEXT_BASE; +} |