From patchwork Sat Dec 4 13:23:48 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: luigi.mantellini@idf-hit.com X-Patchwork-Id: 74268 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 06A1BB70D6 for ; Sun, 5 Dec 2010 00:31:11 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id D80E92825B; Sat, 4 Dec 2010 14:30:23 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id GEHudQBqhBwV; Sat, 4 Dec 2010 14:30:23 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 7332F2822C; Sat, 4 Dec 2010 14:30:17 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 8B3A6281F0 for ; Sat, 4 Dec 2010 14:30:13 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id fLsph9DJnMnN for ; Sat, 4 Dec 2010 14:30:12 +0100 (CET) Received: from mx102.fabbricadigitale.it (mx2.fabbricadigitale.it [217.169.111.37]) by theia.denx.de (Postfix) with ESMTPS id 177DE281F7 for ; Sat, 4 Dec 2010 14:30:03 +0100 (CET) Received: from localhost (mx102.fabbricadigitale.it [127.0.0.1]) by mx102.fabbricadigitale.it (MM4Csmtpd) with ESMTP id 0810DE00023B for ; Sat, 4 Dec 2010 14:24:21 +0100 (CET) X-Virus-Scanned: amavisd-new at fabbricadigitale.it Received: from mx102.fabbricadigitale.it ([127.0.0.1]) by localhost (mx102.fabbricadigitale.it [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id A0htmSQahIzX for ; Sat, 4 Dec 2010 14:24:20 +0100 (CET) Received: from EX02MailShare.fdmsha.local (unknown [172.16.26.10]) by mx102.fabbricadigitale.it (MM4Csmtpd) with ESMTPS id D910AE000266 for ; Sat, 4 Dec 2010 14:24:20 +0100 (CET) Received: from abel.dialface.net (85.40.213.226) by EX02MailShare.fdmsha.local (172.16.26.10) with Microsoft SMTP Server id 8.1.340.0; Sat, 4 Dec 2010 14:24:18 +0100 From: Luigi 'Comio' Mantellini To: Date: Sat, 4 Dec 2010 14:23:48 +0100 Message-ID: <1291469030-24984-5-git-send-email-luigi.mantellini@idf-hit.com> X-Mailer: git-send-email 1.7.2.3 In-Reply-To: <1291469030-24984-1-git-send-email-luigi.mantellini@idf-hit.com> References: <1291469030-24984-1-git-send-email-luigi.mantellini@idf-hit.com> MIME-Version: 1.0 Cc: Luigi 'Comio' Mantellini Subject: [U-Boot] [PATCH 4/6 v2] Add support for Bootstrap infrastructure. X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.9 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de From: Luigi 'Comio' Mantellini See README file for details regarding ho bootstrap code works. Signed-off-by: Luigi 'Comio' Mantellini --- .gitignore | 25 ++++++- Makefile | 174 +++++++++++++++++++++++++++++++++++++++++++- README | 47 ++++++++++++ common/Makefile | 16 ++++- common/console_bootstrap.c | 85 +++++++++++++++++++++ config.mk | 16 ++++ include/bootstrap.h | 59 +++++++++++++++ include/common.h | 21 +++++ lib/Makefile | 29 +++++++- lib/bootstrap.c | 97 ++++++++++++++++++++++++ lib/lzma/Makefile | 4 +- lib/lzo/Makefile | 4 +- lib/xz/Makefile | 4 +- tools/xz_wrap.sh | 45 +++++++++++ 14 files changed, 618 insertions(+), 8 deletions(-) create mode 100644 common/console_bootstrap.c create mode 100644 include/bootstrap.h create mode 100644 lib/bootstrap.c create mode 100755 tools/xz_wrap.sh diff --git a/.gitignore b/.gitignore index e71f6ac..8db8f0f 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,12 @@ /u-boot.hex /u-boot.map /u-boot.bin +/u-boot.bin.bz2 +/u-boot.bin.gz +/u-boot.bin.lzma +/u-boot.bin.lzo +/u-boot.bin.xz +/u-boot.dis /u-boot.srec /u-boot.ldr /u-boot.ldr.hex @@ -30,6 +36,20 @@ /u-boot.lds /u-boot-onenand.bin /u-boot-flexonenand.bin +/u-boot-bootstrap +/u-boot-bootstrap.hex +/u-boot-bootstrap.map +/u-boot-bootstrap.bin +/u-boot-bootstrap.bin.bz2 +/u-boot-bootstrap.bin.gz +/u-boot-bootstrap.bin.lzma +/u-boot-bootstrap.bin.lzo +/u-boot-bootstrap.dis +/u-boot-bootstrap.srec +/u-boot-bootstrap.ldr +/u-boot-bootstrap.ldr.hex +/u-boot-bootstrap.ldr.srec +/u-boot-bootstrap.lds # # Generated files @@ -39,7 +59,7 @@ /LOG /errlog /reloc_off - +/.payload.s /include/generated/ /lib/asm-offsets.s @@ -66,3 +86,6 @@ cscope.* /onenand_ipl/onenand-ipl* /onenand_ipl/board/*/onenand* /onenand_ipl/board/*/*.S +examples/standalone/ + +setvars diff --git a/Makefile b/Makefile index ba832a4..cbd9a57 100644 --- a/Makefile +++ b/Makefile @@ -180,6 +180,13 @@ endif OBJS := $(addprefix $(obj),$(OBJS)) +ifeq ($(CONFIG_BOOTSTRAP),y) +BOOTSTRAP_OBJS = $(CPUDIR)/start_bootstrap.o + +BOOTSTRAP_OBJS := $(addprefix $(obj),$(BOOTSTRAP_OBJS)) +endif + + LIBS = lib/libgeneric.o LIBS += lib/lzma/liblzma.o LIBS += lib/lzo/liblzo.o @@ -270,6 +277,24 @@ LIBS := $(addprefix $(obj),$(sort $(LIBS))) LIBBOARD = board/$(BOARDDIR)/lib$(BOARD).o LIBBOARD := $(addprefix $(obj),$(LIBBOARD)) +ifeq ($(CONFIG_BOOTSTRAP),y) +BOOTSTRAP_LIBS = lib/libgeneric_bootstrap.o +BOOTSTRAP_LIBS += arch/$(ARCH)/cpu/lib$(ARCH)_bootstrap.o +BOOTSTRAP_LIBS += arch/$(ARCH)/lib/lib$(ARCH)_bootstrap.o +BOOTSTRAP_LIBS += common/libcommon_bootstrap.o +BOOTSTRAP_LIBS += drivers/serial/libserial.o + +BOOTSTRAP_LIBS-$(CONFIG_BOOTSTRAP_LZMA) += lib/lzma/liblzma.o +BOOTSTRAP_LIBS-$(CONFIG_BOOTSTRAP_LZO) += lib/lzo/liblzo.o +BOOTSTRAP_LIBS-$(CONFIG_BOOTSTRAP_XZ) += lib/xz/libxz.o +BOOTSTRAP_LIBS += $(BOOTSTRAP_LIBS-y) + +.PHONY : $(BOOTSTRAP_LIBS) + +BOOTSTRAP_LIBBOARD = board/$(BOARDDIR)/lib$(BOARD)_bootstrap.o +BOOTSTRAP_LIBBOARD := $(addprefix $(obj),$(BOOTSTRAP_LIBBOARD)) +endif + # Add GCC lib ifdef USE_PRIVATE_LIBGCC ifeq ("$(USE_PRIVATE_LIBGCC)", "yes") @@ -283,6 +308,9 @@ endif PLATFORM_LIBS += $(PLATFORM_LIBGCC) export PLATFORM_LIBS +BOOTSTRAP_PLATFORM_LIBS += $(PLATFORM_LIBGCC) +export BOOTSTRAP_PLATFORM_LIBS + # Special flags for CPP when processing the linker script. # Pass the version down so we can handle backwards compatibility # on the fly. @@ -305,6 +333,9 @@ endif __OBJS := $(subst $(obj),,$(OBJS)) __LIBS := $(subst $(obj),,$(LIBS)) $(subst $(obj),,$(LIBBOARD)) +__BOOTSTRAP_OBJS := $(subst $(obj),,$(BOOTSTRAP_OBJS)) +__BOOTSTRAP_LIBS := $(subst $(obj),,$(BOOTSTRAP_LIBS)) $(subst $(obj),,$(BOOTSTRAP_LIBBOARD)) + ######################################################################### ######################################################################### @@ -326,6 +357,10 @@ endif # Always append ALL so that arch config.mk's can add custom ones ALL += $(obj)u-boot.srec $(obj)u-boot.bin $(obj)System.map $(U_BOOT_NAND) $(U_BOOT_ONENAND) +ifeq ($(CONFIG_BOOTSTRAP),y) +ALL += $(obj)u-boot-bootstrap.srec $(obj)u-boot-bootstrap.bin +endif + all: $(ALL) $(obj)u-boot.hex: $(obj)u-boot @@ -338,6 +373,21 @@ $(obj)u-boot.bin: $(obj)u-boot $(OBJCOPY) ${OBJCFLAGS} -O binary $< $@ $(BOARD_SIZE_CHECK) +$(obj)u-boot.bin.gz: $(obj)u-boot.bin + gzip -c $< > $@ + +$(obj)u-boot.bin.lzma: $(obj)u-boot.bin + lzma -e -z -c $< > $@ + +$(obj)u-boot.bin.xz: $(obj)u-boot.bin + tools/xz_wrap.sh misc < $< > $@ + +$(obj)u-boot.bin.lzo: $(obj)u-boot.bin + lzop -9 -c $< > $@ + +$(obj)u-boot.bin.bz2: $(obj)u-boot.bin + bzip2 --best -z -c $< > $@ + $(obj)u-boot.ldr: $(obj)u-boot $(CREATE_LDR_ENV) $(LDR) -T $(CONFIG_BFIN_CPU) -c $@ $< $(LDR_FLAGS) @@ -373,7 +423,7 @@ $(obj)u-boot.dis: $(obj)u-boot GEN_UBOOT = \ UNDEF_SYM=`$(OBJDUMP) -x $(LIBBOARD) $(LIBS) | \ sed -n -e 's/.*\($(SYM_PREFIX)__u_boot_cmd_.*\)/-u\1/p'|sort|uniq`;\ - cd $(LNDIR) && $(LD) $(LDFLAGS) $$UNDEF_SYM $(__OBJS) \ + cd $(LNDIR) && $(LD) --gc-sections $(LDFLAGS) $$UNDEF_SYM $(__OBJS) \ --start-group $(__LIBS) --end-group $(PLATFORM_LIBS) \ -Map u-boot.map -o u-boot $(obj)u-boot: depend \ @@ -396,6 +446,118 @@ $(LIBS): depend $(SUBDIRS) $(LIBBOARD): depend $(LIBS) $(MAKE) -C $(dir $(subst $(obj),,$@)) +# Bootstrap targets + +ifeq ($(CONFIG_BOOTSTRAP),y) +$(obj)u-boot-bootstrap.hex: $(obj)u-boot-bootstrap + $(OBJCOPY) ${OBJCFLAGS} -O ihex $< $@ + +$(obj)u-boot-bootstrap.srec: $(obj)u-boot-bootstrap + $(OBJCOPY) -O srec $< $@ + +$(obj)u-boot-bootstrap.bin: $(obj)u-boot-bootstrap + $(OBJCOPY) ${OBJCFLAGS} -O binary $< $@ + $(BOARD_SIZE_CHECK) + +$(obj)u-boot-bootstrap.bin.gz: $(obj)u-boot-bootstrap.bin + gzip -c $< > $@ + +$(obj)u-boot-bootstrap.bin.lzma: $(obj)u-boot-bootstrap.bin + lzma -e -z -c $< > $@ + +$(obj)u-boot.bin-bootstrap.lzo: $(obj)u-boot-bootstrap.bin + lzop -9 -c $< > $@ + +$(obj)u-boot.bin-bootstrap.bz2: $(obj)u-boot-bootstrap.bin + bzip2 --best -z -c $< > $@ + +$(obj)u-boot-bootstrap.ldr: $(obj)u-boot-bootstrap + $(CREATE_LDR_ENV) + $(LDR) -T $(CONFIG_BFIN_CPU) -c $@ $< $(LDR_FLAGS) + $(BOARD_SIZE_CHECK) + +$(obj)u-boot-bootstrap.ldr.hex: $(obj)u-boot-bootstrap.ldr + $(OBJCOPY) ${OBJCFLAGS} -O ihex $< $@ -I binary + +$(obj)u-boot-bootstrap.ldr.srec: $(obj)u-boot-bootstrap.ldr + $(OBJCOPY) ${OBJCFLAGS} -O srec $< $@ -I binary + +$(obj)u-boot-bootstrap.img: $(obj)u-boot-bootstrap.bin + $(obj)tools/mkimage -A $(ARCH) -T firmware -C none \ + -a $(CONFIG_BOOTSTRAP_BASE) -e 0 \ + -n $(shell sed -n -e 's/.*U_BOOT_VERSION//p' $(VERSION_FILE) | \ + sed -e 's/"[ ]*$$/ for $(BOARD) board"/') \ + -d $< $@ + +$(obj)u-boot-bootstrap.imx: $(obj)u-boot-bootstrap.bin + $(obj)tools/mkimage -n $(IMX_CONFIG) -T imximage \ + -e $(CONFIG_BOOTSTRAP_BASE) -d $< $@ + +$(obj)u-boot-bootstrap.kwb: $(obj)u-boot-bootstrap.bin + $(obj)tools/mkimage -n $(CONFIG_SYS_KWD_CONFIG) -T kwbimage \ + -a $(CONFIG_SYS_TEXT_BASE) -e $(CONFIG_SYS_TEXT_BASE) -d $< $@ + +$(obj)u-boot-bootstrap.sha1: $(obj)u-boot-bootstrap.bin + $(obj)tools/ubsha1 $(obj)u-boot-bootstrap.bin + +$(obj)u-boot-bootstrap.dis: $(obj)u-boot-bootstrap + $(OBJDUMP) -d $< > $@ + +PAYLOAD_FILE_BASE=$(obj)u-boot.bin +ifeq ($(CONFIG_BOOTSTRAP_GZIP),y) +PAYLOAD_FILE_EXT:=.gz +endif +ifeq ($(CONFIG_BOOTSTRAP_LZMA),y) +PAYLOAD_FILE_EXT:=.lzma +endif +ifeq ($(CONFIG_BOOTSTRAP_LZO),y) +PAYLOAD_FILE_EXT:=.lzo +endif +ifeq ($(CONFIG_BOOTSTRAP_BZIP2),y) +PAYLOAD_FILE_EXT:=.bz2 +endif +ifeq ($(CONFIG_BOOTSTRAP_XZ),y) +PAYLOAD_FILE_EXT:=.xz +endif + +PAYLOAD_FILE := $(PAYLOAD_FILE_BASE)$(PAYLOAD_FILE_EXT) + +$(obj).payload.s: $(PAYLOAD_FILE) + echo ".globl payload_start" > $@ + echo ".globl payload_end" >> $@ + echo ".globl payload_size" >> $@ + echo ".globl payload_uncsize" >> $@ + echo .section .payload,\"a\",@progbits >> $@ + echo "payload_size:" >> $@ + echo -n ".word " >> $@ + wc -c $(PAYLOAD_FILE) | cut -f1 -d' ' >> $@ + echo "payload_uncsize:" >> $@ + echo -n ".word " >> $@ + wc -c $(obj)u-boot.bin | cut -f1 -d' ' >> $@ + echo "payload_start:" >> $@ + echo .incbin \"$(PAYLOAD_FILE)\" >> $@ + echo "payload_end:" >> $@ + +GEN_UBOOT_BOOTSTRAP = \ + UNDEF_SYM=`$(OBJDUMP) -x $(BOOTSTRAP_LIBBOARD) $(BOOTSTRAP_LIBS) | \ + sed -n -e 's/.*\($(SYM_PREFIX)__u_boot_cmd_.*\)/-u\1/p'|sort|uniq`;\ + cd $(LNDIR) && $(LD) --gc-sections $(BOOTSTRAP_LDFLAGS) $$UNDEF_SYM $(obj).payload.o $(__BOOTSTRAP_OBJS) \ + --start-group $(__BOOTSTRAP_LIBS) --end-group $(BOOTSTRAP_PLATFORM_LIBS) \ + -Map u-boot-bootstrap.map -o u-boot-bootstrap +$(obj)u-boot-bootstrap: depend $(SUBDIRS) $(BOOTSTRAP_OBJS) $(BOOTSTRAP_LIBBOARD) $(BOOTSTRAP_LIBS) $(BOOTSTRAP_LDSCRIPT) $(obj)u-boot-bootstrap.lds $(obj).payload.o + $(GEN_UBOOT_BOOTSTRAP) +ifeq ($(CONFIG_KALLSYMS),y) + smap=`$(call SYSTEM_MAP,u-boot-bootstrap) | \ + awk '$$2 ~ /[tTwW]/ {printf $$1 $$3 "\\\\000"}'` ; \ + $(CC) $(CFLAGS) -DSYSTEM_MAP="\"$${smap}\"" \ + -c common/system_map.c -o $(obj)common/system_map.o + $(GEN_UBOOT_BOOTSTRAP) $(obj)common/system_map.o +endif + +$(BOOTSTRAP_LIBBOARD): depend $(BOOTSTRAP_LIBS) + $(MAKE) -C $(dir $(subst $(obj),,$@)) $(notdir $@) +endif + $(SUBDIRS): depend $(MAKE) -C $@ all @@ -405,6 +567,9 @@ $(LDSCRIPT): depend $(obj)u-boot.lds: $(LDSCRIPT) $(CPP) $(CPPFLAGS) $(LDPPFLAGS) -ansi -D__ASSEMBLY__ -P - <$^ >$@ +$(obj)u-boot-bootstrap.lds: $(BOOTSTRAP_LDSCRIPT) + $(CPP) $(CPPFLAGS) $(BOOTSTRAP_LDPPFLAGS) -ansi -D__ASSEMBLY__ -P - <$^ >$@ + $(NAND_SPL): $(TIMESTAMP_FILE) $(VERSION_FILE) depend $(MAKE) -C nand_spl/board/$(BOARDDIR) all @@ -1222,6 +1387,7 @@ clean: $(obj)board/trab/trab_fkt $(obj)board/voiceblue/eeprom \ $(obj)board/armltd/{integratorap,integratorcp}/u-boot.lds \ $(obj)u-boot.lds \ + $(obj)u-boot-bootstrap.lds \ $(obj)arch/blackfin/cpu/bootrom-asm-offsets.[chs] @rm -f $(obj)include/bmp_logo.h @rm -f $(obj)lib/asm-offsets.s @@ -1245,6 +1411,12 @@ clobber: clean @rm -f $(obj)u-boot $(obj)u-boot.map $(obj)u-boot.hex $(ALL) @rm -f $(obj)u-boot.kwb @rm -f $(obj)u-boot.imx + @rm -f $(obj)u-boot.bin{.gz,.lzma,.lzo,.bz2,.xz} + @rm -f $(obj)u-boot-bootstrap $(obj)u-boot-bootstrap.map $(obj)u-boot-bootstrap.hex + @rm -f $(obj)u-boot-bootstrap.kwb + @rm -f $(obj)u-boot-bootstrap.imx + @rm -f $(obj)u-boot-bootstrap.bin{.gz,.lzma,.lzo,.bz2,.xz} + @rm -f $(obj).payload.s @rm -f $(obj)tools/{env/crc32.c,inca-swap-bytes} @rm -f $(obj)arch/powerpc/cpu/mpc824x/bedbug_603e.c @rm -f $(obj)include/asm/proc $(obj)include/asm/arch $(obj)include/asm diff --git a/README b/README index 90c19a9..3b27e2f 100644 --- a/README +++ b/README @@ -1945,6 +1945,53 @@ The following options need to be configured: example, some LED's) on your board. At the moment, the following checkpoints are implemented: +- Compressed U-Boot support: + CONFIG_BOOTSTRAP_BASE + + This option enables the Boostrap infrastructure. + The bootstrap code consists of a small binary that is able + to decompress an attached payload (a full U-Boot image), + allowing to have a small but also full featured U-Boot + bootloader. + + The bootstrap supports BZIP2, GZIP, LZMA, LZO and XZ payload + formats as well as flat/uncompressed payload (useful for debug). + + The boot sequence will be divided in the following stages: + + 1) bootstrap: + - Lowlevel initiliazation + - Bootstrap code relocation (if needed) + - Dynamic memory initialization (if needed) + - Payload uncompression or copy to RAM + 2) Jump to uncompressed full U-Boot (into RAM) + + CONFIG_BOOTSTRAP_SKIP_LOWLEVEL_INIT + + Skip lowlevel initialization. + + CONFIG_BOOTSTRAP_TEXT_BASE + + TEXT_BASE address of the bootstrap code. + + CONFIG_BOOTSTRAP_BAUDRATE + + Serial port baudrate at bootstrap. + + CONFIG_BOOTSTRAP_BZIP2 + CONFIG_BOOTSTRAP_GZIP + CONFIG_BOOTSTRAP_LZMA + CONFIG_BOOTSTRAP_LZO + CONFIG_BOOTSTRAP_XZ + + Enable BZIP2, GZIP, LZMA, LZO or XZ payload support. If anyone is defined, + an uncompressed payload will used. + + BOOTSTRAP_LDSCRIPT + + LD script for bootstrap code. If not defined, a board specific script will be + used. + Legacy uImage format: Arg Where When diff --git a/common/Makefile b/common/Makefile index abea91c..ec1c6e9 100644 --- a/common/Makefile +++ b/common/Makefile @@ -24,6 +24,9 @@ include $(TOPDIR)/config.mk LIB = $(obj)libcommon.o +BOOTSTRAP_LIB = $(obj)libcommon_bootstrap.o + +BOOTSTRAP_LIB-$(CONFIG_BOOTSTRAP) = $(BOOTSTRAP_LIB) # core COBJS-y += main.o @@ -165,20 +168,29 @@ COBJS-$(CONFIG_MODEM_SUPPORT) += modem.o COBJS-$(CONFIG_UPDATE_TFTP) += update.o COBJS-$(CONFIG_USB_KEYBOARD) += usb_kbd.o +BOOTSTRAP_COBJS-$(CONFIG_BOOTSTRAP_GZIP) += dlmalloc.o +BOOTSTRAP_COBJS-$(CONFIG_BOOTSTRAP_BZIP2) += dlmalloc.o +BOOTSTRAP_COBJS-$(CONFIG_BOOTSTRAP) += console_bootstrap.o + +BOOTSTRAP_COBJS := $(sort $(BOOTSTRAP_COBJS-y)) +BOOTSTRAP_OBJS := $(addprefix $(obj),$(BOOTSTRAP_COBJS)) COBJS := $(sort $(COBJS-y)) XCOBJS := $(sort $(XCOBJS-y)) -SRCS := $(COBJS:.o=.c) $(XCOBJS:.o=.c) +SRCS := $(sort $(COBJS:.o=.c) $(XCOBJS:.o=.c) $(BOOTSTRAP_COBJS:.o=.c)) OBJS := $(addprefix $(obj),$(COBJS)) XOBJS := $(addprefix $(obj),$(XCOBJS)) CPPFLAGS += -I.. -all: $(LIB) $(XOBJS) +all: $(LIB) $(BOOTSTRAP_LIB-y) $(XOBJS) $(LIB): $(obj).depend $(OBJS) $(call cmd_link_o_target, $(OBJS)) +$(BOOTSTRAP_LIB): $(obj).depend $(BOOTSTRAP_OBJS) + $(call cmd_link_o_target, $(BOOTSTRAP_OBJS)) + $(obj)env_embedded.o: $(src)env_embedded.c $(obj)../tools/envcrc $(CC) $(AFLAGS) -Wa,--no-warn \ -DENV_CRC=$(shell $(obj)../tools/envcrc) \ diff --git a/common/console_bootstrap.c b/common/console_bootstrap.c new file mode 100644 index 0000000..cdd4a62 --- /dev/null +++ b/common/console_bootstrap.c @@ -0,0 +1,85 @@ +/* + * (C) Copyright 2000 + * Paolo Scaffardi, AIRVENT SAM s.p.a - RIMINI(ITALY), arsenio@tin.it + * + * 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 +#include +#include + +/** U-Boot INITIAL CONSOLE-COMPATIBLE FUNCTION *****************************/ + +int getc(void) +{ + /* Send directly to the handler */ + return serial_getc(); +} + +int tstc(void) +{ + /* Send directly to the handler */ + return serial_tstc(); +} + +void putc(const char c) +{ + /* Send directly to the handler */ + serial_putc(c); +} + +void puts(const char *s) +{ + serial_puts(s); +} + +int printf(const char *fmt, ...) +{ + va_list args; + uint i; + char printbuffer[CONFIG_SYS_PBSIZE]; + + va_start(args, fmt); + + /* For this to work, printbuffer must be larger than + * anything we ever want to print. + */ + i = vsprintf(printbuffer, fmt, args); + va_end(args); + + /* Print the string */ + puts(printbuffer); + return i; +} + +int vprintf(const char *fmt, va_list args) +{ + uint i; + char printbuffer[CONFIG_SYS_PBSIZE]; + + /* For this to work, printbuffer must be larger than + * anything we ever want to print. + */ + i = vsprintf(printbuffer, fmt, args); + + /* Print the string */ + puts(printbuffer); + return i; +} diff --git a/config.mk b/config.mk index 591b490..81a4efb 100644 --- a/config.mk +++ b/config.mk @@ -166,6 +166,11 @@ else LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot.lds endif endif +ifeq ($(CONFIG_BOOTSTRAP),y) +ifndef BOOTSTRAP_LDSCRIPT +BOOTSTRAP_LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot-bootstrap.lds +endif +endif OBJCFLAGS += --gap-fill=0xff gccincdir := $(shell $(CC) -print-file-name=include) @@ -176,6 +181,10 @@ ifneq ($(CONFIG_SYS_TEXT_BASE),) CPPFLAGS += -DCONFIG_SYS_TEXT_BASE=$(CONFIG_SYS_TEXT_BASE) endif +ifneq ($(CONFIG_BOOTSTRAP_TEXT_BASE),) +CPPFLAGS += -DCONFIG_BOOTSTRAP_TEXT_BASE=$(CONFIG_BOOTSTRAP_TEXT_BASE) +endif + ifneq ($(RESET_VECTOR_ADDRESS),) CPPFLAGS += -DRESET_VECTOR_ADDRESS=$(RESET_VECTOR_ADDRESS) endif @@ -222,6 +231,13 @@ ifneq ($(CONFIG_SYS_TEXT_BASE),) LDFLAGS += -Ttext $(CONFIG_SYS_TEXT_BASE) endif +ifeq ($(CONFIG_BOOTSTRAP),y) +BOOTSTRAP_LDFLAGS += -Bstatic -T $(obj)u-boot-bootstrap.lds $(PLATFORM_LDFLAGS) +ifneq ($(CONFIG_BOOTSTRAP_TEXT_BASE),) +BOOTSTRAP_LDFLAGS += -Ttext $(CONFIG_BOOTSTRAP_TEXT_BASE) +endif +endif + # Location of a usable BFD library, where we define "usable" as # "built for ${HOST}, supports ${TARGET}". Sensible values are # - When cross-compiling: the root of the cross-environment diff --git a/include/bootstrap.h b/include/bootstrap.h new file mode 100644 index 0000000..f49045d --- /dev/null +++ b/include/bootstrap.h @@ -0,0 +1,59 @@ +/* + * (C) Copyright 2000-2009 + * Wolfgang Denk, DENX Software Engineering, wd@denx.de. + * + * 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 + */ + +#ifndef __BOOTSTRAP_H_ +#define __BOOTSTRAP_H_ 1 + +#include + +#ifdef CONFIG_BOOTSTRAP_BZIP2 +#define _CONFIG_BOOTSTRAP_RELOCATE +#define _CONFIG_BOOTSTRAP_MALLOC +// #define _CONFIG_BOOTSTRAP_FAKEMALLOC +#endif + +#ifdef CONFIG_BOOTSTRAP_GZIP +// #define _CONFIG_BOOTSTRAP_RELOCATE +#define _CONFIG_BOOTSTRAP_MALLOC +#define _CONFIG_BOOTSTRAP_FAKEMALLOC +#endif + +#ifdef CONFIG_BOOTSTRAP_LZMA +// #define _CONFIG_BOOTSTRAP_RELOCATE +#define _CONFIG_BOOTSTRAP_MALLOC +#define _CONFIG_BOOTSTRAP_FAKEMALLOC +#endif + +#ifdef CONFIG_BOOTSTRAP_LZO +// #define _CONFIG_BOOTSTRAP_RELOCATE +// #define _CONFIG_BOOTSTRAP_MALLOC +// #define _CONFIG_BOOTSTRAP_FAKEMALLOC +#endif + +#ifdef CONFIG_BOOTSTRAP_XZ +// #define _CONFIG_BOOTSTRAP_RELOCATE +#define _CONFIG_BOOTSTRAP_MALLOC +#define _CONFIG_BOOTSTRAP_FAKEMALLOC +#endif + +#endif /* __BOOTSTRAP_H_ */ diff --git a/include/common.h b/include/common.h index 189ad81..690cba2 100644 --- a/include/common.h +++ b/include/common.h @@ -723,6 +723,27 @@ int cpu_disable(int nr); int cpu_release(int nr, int argc, char * const argv[]); #endif +/* Bootstrap specific code */ +#ifdef CONFIG_BOOTSTRAP +void bootstrap_hang(void) __attribute__ ((noreturn)); +void bootstrap_board_init_f(ulong) __attribute__ ((noreturn)); +void bootstrap_board_init_r(gd_t *, ulong) __attribute__ ((noreturn)); +int bootstrap_checkboard(void); + +int bootstrap_serial_init(void); +void bootstrap_serial_exit(void); +void bootstrap_serial_setbrg(void); +void bootstrap_serial_putc(const char); +void bootstrap_serial_putc_raw(const char); +void bootstrap_serial_puts(const char *); +int bootstrap_serial_getc(void); +int bootstrap_serial_tstc(void); + +phys_size_t bootstrap_initdram (int); + +int copy_uboot(void *dst, size_t unc_size, void *src, size_t size); +#endif + #endif /* __ASSEMBLY__ */ /* Put only stuff here that the assembler can digest */ diff --git a/lib/Makefile b/lib/Makefile index ffdee7d..3795ed3 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -24,6 +24,9 @@ include $(TOPDIR)/config.mk LIB = $(obj)libgeneric.o +BOOTSTRAP_LIB = $(obj)libgeneric_bootstrap.o + +BOOTSTRAP_LIB-$(CONFIG_BOOTSTRAP) = $(BOOTSTRAP_LIB) COBJS-$(CONFIG_ADDR_MAP) += addr_map.o COBJS-$(CONFIG_BZIP2) += bzlib.o @@ -54,13 +57,37 @@ COBJS-y += vsprintf.o COBJS-$(CONFIG_ZLIB) += zlib.o COBJS-$(CONFIG_RBTREE) += rbtree.o +BOOTSTRAP_COBJS-$(CONFIG_BOOTSTRAP) += string.o +BOOTSTRAP_COBJS-$(CONFIG_BOOTSTRAP) += vsprintf.o +BOOTSTRAP_COBJS-$(CONFIG_BOOTSTRAP) += div64.o +BOOTSTRAP_COBJS-$(CONFIG_BOOTSTRAP) += ctype.o +BOOTSTRAP_COBJS-$(CONFIG_BOOTSTRAP) += time.o +BOOTSTRAP_COBJS-$(CONFIG_BOOTSTRAP) += bootstrap.o +BOOTSTRAP_COBJS-$(CONFIG_BOOTSTRAP_GZIP) += zlib.o +BOOTSTRAP_COBJS-$(CONFIG_BOOTSTRAP_GZIP) += gunzip.o +BOOTSTRAP_COBJS-$(CONFIG_BOOTSTRAP_GZIP) += crc32.o +BOOTSTRAP_COBJS-$(CONFIG_BOOTSTRAP_BZIP2) += bzlib.o +BOOTSTRAP_COBJS-$(CONFIG_BOOTSTRAP_BZIP2) += bzlib_crctable.o +BOOTSTRAP_COBJS-$(CONFIG_BOOTSTRAP_BZIP2) += bzlib_decompress.o +BOOTSTRAP_COBJS-$(CONFIG_BOOTSTRAP_BZIP2) += bzlib_randtable.o +BOOTSTRAP_COBJS-$(CONFIG_BOOTSTRAP_BZIP2) += bzlib_huffman.o +BOOTSTRAP_COBJS-$(CONFIG_BOOTSTRAP_XZ) += crc32.o + +BOOTSTRAP_COBJS := $(BOOTSTRAP_COBJS-y) +BOOTSTRAP_OBJS := $(addprefix $(obj),$(BOOTSTRAP_COBJS)) + COBJS := $(COBJS-y) -SRCS := $(COBJS:.o=.c) +SRCS := $(COBJS:.o=.c) $(BOOTSTRAP_COBJS:.o=.c) OBJS := $(addprefix $(obj),$(COBJS)) +all: $(LIB) $(BOOTSTRAP_LIB-y) + $(LIB): $(obj).depend $(OBJS) $(call cmd_link_o_target, $(OBJS)) +$(BOOTSTRAP_LIB): $(obj).depend $(BOOTSTRAP_OBJS) + $(call cmd_link_o_target, $(BOOTSTRAP_OBJS)) + ######################################################################### # defines $(obj).depend target diff --git a/lib/bootstrap.c b/lib/bootstrap.c new file mode 100644 index 0000000..1ae5cfc --- /dev/null +++ b/lib/bootstrap.c @@ -0,0 +1,97 @@ +/* + * (C) Copyright 2010 Industrie Dial Face S.p.A. + * Luigi 'Comio' Mantellini, luigi.mantellini@idf-hit.com + * + * (C) Copyright 2003 + * Wolfgang Denk, DENX Software Engineering, wd@denx.de. + * + * 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 +#include +#include + +#ifdef CONFIG_BOOTSTRAP_LZMA +#include +#include +#include +#endif /* CONFIG_BOOTSTRAP_LZMA */ + +#ifdef CONFIG_BOOTSTRAP_LZO +#include +#endif /* CONFIG_BOOTSTRAP_LZO */ + +#ifdef CONFIG_BOOTSTRAP_BZIP2 +#include +#endif + +#ifdef CONFIG_BOOTSTRAP_XZ +#include +#endif + +DECLARE_GLOBAL_DATA_PTR; + +static const char *algo = +#if defined(CONFIG_BOOTSTRAP_GZIP) + "gzip"; +#elif defined(CONFIG_BOOTSTRAP_LZMA) + "lzma"; +#elif defined(CONFIG_BOOTSTRAP_LZO) + "lzo"; +#elif defined(CONFIG_BOOTSTRAP_BZIP2) + "bzip2"; +#elif defined(CONFIG_BOOTSTRAP_XZ) + "xz"; +#else + "flat"; +#endif + + +int copy_uboot(void *dst, size_t unc_size, void *src, size_t size) +{ + int ret; + debug("copy from %p (%d) to %p (%d)\n", src, size, dst, unc_size); + + printf("Uncompressing payload (%s)...", algo); +#if defined(CONFIG_BOOTSTRAP_GZIP) + ret = gunzip(dst, unc_size, src, &size); +#elif defined(CONFIG_BOOTSTRAP_LZMA) + SizeT outsize = unc_size; + ret = lzmaBuffToBuffDecompress(dst, &outsize, src, size); +#elif defined(CONFIG_BOOTSTRAP_LZO) + uint unc_len = unc_size; + ret = lzop_decompress(src, size, dst, &unc_len); +#elif defined(CONFIG_BOOTSTRAP_BZIP2) + uint unc_len = unc_size; + ret = BZ2_bzBuffToBuffDecompress ((char*)dst, &unc_len, (char *)src, size, CONFIG_SYS_MALLOC_LEN < (4096 * 1024), 0); +#elif defined(CONFIG_BOOTSTRAP_XZ) + ret = unxz(src, size, dst, &unc_size); +#else + memcpy(dst, src, size); + ret = 0; +#endif + if (ret) { + printf("failed with error %d.\n", ret); + bootstrap_hang(); + } else { + puts("done.\n"); + } + return ret; +} \ No newline at end of file diff --git a/lib/lzma/Makefile b/lib/lzma/Makefile index 4d3401d..395b8dc 100644 --- a/lib/lzma/Makefile +++ b/lib/lzma/Makefile @@ -32,7 +32,9 @@ SOBJS = CFLAGS += -D_LZMA_PROB32 -COBJS-$(CONFIG_LZMA) += LzmaDec.o LzmaTools.o +COBJS-$(CONFIG_LZMA)$(CONFIG_BOOTSTRAP_LZMA) += LzmaDec.o LzmaTools.o + +COBJS-y += $(COBJS-yy) COBJS = $(COBJS-y) SRCS := $(SOBJS:.o=.S) $(COBJS:.o=.c) diff --git a/lib/lzo/Makefile b/lib/lzo/Makefile index 69bc839..c8d7fa5 100644 --- a/lib/lzo/Makefile +++ b/lib/lzo/Makefile @@ -27,7 +27,9 @@ LIB = $(obj)liblzo.o SOBJS = -COBJS-$(CONFIG_LZO) += lzo1x_decompress.o +COBJS-$(CONFIG_LZO)$(CONFIG_BOOTSTRAP_LZO) += lzo1x_decompress.o + +COBJS-y += $(OBJS-yy) COBJS = $(COBJS-y) SRCS := $(SOBJS:.o=.S) $(COBJS:.o=.c) diff --git a/lib/xz/Makefile b/lib/xz/Makefile index 3cfeab4..b71fb97 100644 --- a/lib/xz/Makefile +++ b/lib/xz/Makefile @@ -32,7 +32,9 @@ SOBJS = CFLAGS += -COBJS-$(CONFIG_XZ) += decompress_unxz.o +COBJS-$(CONFIG_XZ)$(CONFIG_BOOTSTRAP_XZ) += decompress_unxz.o + +COBJS-y += $(COBJS-yy) COBJS = $(COBJS-y) SRCS := $(SOBJS:.o=.S) $(COBJS:.o=.c) diff --git a/tools/xz_wrap.sh b/tools/xz_wrap.sh new file mode 100755 index 0000000..dbe5e55 --- /dev/null +++ b/tools/xz_wrap.sh @@ -0,0 +1,45 @@ +#!/bin/sh +# +# This is a wrapper for xz to use appropriate compression options depending +# on what is being compressed. The only argument to this script should be +# "kernel" or "misc" to indicate what is being compressed. +# +# Author: Lasse Collin +# +# This file has been put into the public domain. +# You can do whatever you want with this file. +# + +# Defaults: No BCJ filter and no extra LZMA2 options. +BCJ= +LZMA2OPTS= + +# Big dictionary is OK for the kernel image, but it's not OK +# for other things. +# +# BCJ filter is used only for the kernel, at least for now. +# It could be useful for non-trivial initramfs too, but it +# depends on the exact content of the initramfs image. +case $1 in + kernel) + DICT=16MiB + case $ARCH in + x86|x86_64) BCJ=--x86 ;; + powerpc) BCJ=--powerpc ;; + ia64) BCJ=--ia64; LZMA2OPTS=pb=4 ;; + arm) BCJ=--arm ;; + sparc) BCJ=--sparc ;; + esac + ;; + misc) + DICT=1MiB + ;; + *) + echo "xz_wrap.sh: Invalid argument \`$1'" >&2 + exit 1 + ;; +esac + +# This is very slow, but it should give very good compression too. +exec xz --stdout --quiet --threads=1 --check=crc32 \ + $BCJ --lzma2=preset=6e,$LZMA2OPTS,dict=$DICT