Entry point is now configurable via a Makefile variable. Entry point is detected automatically (Gabor Juhos)

git-svn-id: svn://svn.openwrt.org/openwrt/trunk@6841 3c298f89-4303-0410-b956-a3cf2f4a3e73
master
Florian Fainelli 2007-04-02 17:14:23 +00:00
parent 5218d952cd
commit 75af0330e0
6 changed files with 113 additions and 94 deletions

View File

@ -8,6 +8,9 @@
include $(TOPDIR)/rules.mk
LOADER := loader
BZ_STARTUP_ORG := 0
PKG_NAME := lzma-loader
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
@ -16,18 +19,19 @@ $(PKG_BUILD_DIR)/.prepared:
$(CP) ./src/* $(PKG_BUILD_DIR)/
touch $@
$(PKG_BUILD_DIR)/loader.gz: $(PKG_BUILD_DIR)/.prepared
$(PKG_BUILD_DIR)/$(LOADER).gz: $(PKG_BUILD_DIR)/.prepared
$(MAKE) -C $(PKG_BUILD_DIR) CC="$(TARGET_CC)" \
LD="$(TARGET_CROSS)ld" CROSS_COMPILE="$(TARGET_CROSS)"
LD="$(TARGET_CROSS)ld" CROSS_COMPILE="$(TARGET_CROSS)" \
LOADER=$(LOADER) BZ_STARTUP_ORG=$(BZ_STARTUP_ORG)
download:
prepare: $(PKG_BUILD_DIR)/.prepared
compile: $(PKG_BUILD_DIR)/loader.gz
compile: $(PKG_BUILD_DIR)/$(LOADER).gz
install:
ifneq ($(TARGET),)
install: compile
$(CP) $(PKG_BUILD_DIR)/loader.gz $(PKG_BUILD_DIR)/loader.elf $(TARGET)/
$(CP) $(PKG_BUILD_DIR)/$(LOADER).gz $(PKG_BUILD_DIR)/$(LOADER).elf $(TARGET)/
endif
clean:

View File

@ -16,9 +16,15 @@
# Copyright 2005 Oleg I. Vdovikin <oleg@cs.msu.su>
# Cleaned up, modified for lzma support, removed from kernel
#
# Copyright 2007 Gabor Juhos <juhosg@freemail.hu>
# Modified to support user defined entry point address.
# Added support for make targets with different names
#
TEXT_START := 0x80001000
LOADADDR := 0x80001000
BZ_TEXT_START := 0x80300000
BZ_STARTUP_ORG := 0
LOADER := loader
OBJCOPY := $(CROSS_COMPILE)objcopy -O binary -R .reginfo -R .note -R .comment -R .mdebug -S
@ -26,52 +32,41 @@ CFLAGS = -D__KERNEL__ -Wall -Wstrict-prototypes -Wno-trigraphs -Os \
-fno-strict-aliasing -fno-common -fomit-frame-pointer -G 0 -mno-abicalls -fno-pic \
-ffunction-sections -pipe -mlong-calls -fno-common \
-mabi=32 -march=mips32 -Wa,-32 -Wa,-march=mips32 -Wa,-mips32 -Wa,--trap
CFLAGS += -DLOADADDR=$(TEXT_START) -D_LZMA_IN_CB
CFLAGS += -DLOADADDR=$(LOADADDR) -D_LZMA_IN_CB
ASFLAGS = $(CFLAGS) -D__ASSEMBLY__ -DBZ_TEXT_START=$(BZ_TEXT_START)
ASFLAGS = $(CFLAGS) -D__ASSEMBLY__ -DBZ_STARTUP_ORG=$(BZ_STARTUP_ORG)
SEDFLAGS := s/BZ_TEXT_START/$(BZ_TEXT_START)/;s/TEXT_START/$(TEXT_START)/
LDFLAGS = -static --gc-sections -no-warn-mismatch
LDFLAGS += -e startup -Ttext $(BZ_TEXT_START) -T loader.lds.in
OBJECTS := head.o data.o
OBJECTS := $(LOADER)-head.o decompress.o LzmaDecode.o
all: loader.gz loader.elf
all: $(LOADER).gz $(LOADER).elf
# Don't build dependencies, this may die if $(CC) isn't gcc
dep:
install:
loader.gz: loader
decompress.o:
$(CC) $(CFLAGS) -c decompress.c -o $@
$(LOADER)-head.o:
$(CC) $(ASFLAGS) -c head.S -o $@
$(LOADER).gz: $(LOADER).bin
gzip -nc9 $< > $@
loader.elf: loader.o
$(LOADER).elf: $(LOADER).o
cp $< $@
loader: loader.o
$(OBJCOPY) $< $@
$(LOADER).bin: $(LOADER).o
$(OBJCOPY) -O binary $< $@
loader.o: loader.lds $(OBJECTS)
$(LD) -static --gc-sections -no-warn-mismatch -T loader.lds -o $@ $(OBJECTS)
loader.lds: loader.lds.in Makefile
@sed "$(SEDFLAGS)" < $< > $@
data.o: data.lds decompress.image
$(LD) -no-warn-mismatch -T data.lds -r -o $@ -b binary decompress.image -b elf32-tradlittlemips
data.lds:
@echo "SECTIONS { .data : { code_start = .; *(.data) code_stop = .; }}" > $@
decompress.image: decompress
$(OBJCOPY) $< $@
decompress: decompress.lds decompress.o LzmaDecode.o
$(LD) -static --gc-sections -no-warn-mismatch -T decompress.lds -o $@ decompress.o LzmaDecode.o
decompress.lds: decompress.lds.in Makefile
@sed "$(SEDFLAGS)" < $< > $@
$(LOADER).o: $(OBJECTS)
$(LD) $(LDFLAGS) -o $@ $(OBJECTS)
mrproper: clean
clean:
rm -f loader.gz loader decompress *.lds *.o *.image
rm -f *.gz *.elf *.bin *.o

View File

@ -124,8 +124,10 @@ static __inline__ unsigned char get_byte(void)
return read_byte(0, &buffer, &fake), *buffer;
}
int uart_write_str(char * str);
/* should be the first function */
void entry(unsigned long reg_a0, unsigned long reg_a1,
void decompress_entry(unsigned long reg_a0, unsigned long reg_a1,
unsigned long reg_a2, unsigned long reg_a3,
unsigned long icache_size, unsigned long icache_lsize,
unsigned long dcache_size, unsigned long dcache_lsize)

View File

@ -1,20 +0,0 @@
OUTPUT_ARCH(mips)
ENTRY(entry)
SECTIONS {
. = BZ_TEXT_START;
.text : {
*(.text.entry)
*(.text)
*(.rodata)
}
.data : {
*(.data)
}
.bss : {
*(.bss)
}
workspace = .;
}

View File

@ -1,6 +1,6 @@
/* Copyright 2007 Gabor Juhos */
/* Copyright 2007 Gabor Juhos <juhosg@freemail.hu> */
/* keep original values of the a0,a1,a2,a3 registers */
/* cache manipulation adapted from Broadcom code */
/* modifed to support user defined entry point address */
/* Copyright 2005 Oleg I. Vdovikin (oleg@cs.msu.su) */
/* cache manipulation adapted from Broadcom code */
/* idea taken from original bunzip2 decompressor code */
@ -39,21 +39,44 @@
#define Index_Writeback_Inv_D 0x01
.text
LEAF(startup)
#if (BZ_STARTUP_ORG)
.set noreorder
/* Copy decompressor code to the right place */
li t0, BZ_TEXT_START
b startup
nop
la t1, code_start
la t2, code_stop
$L1:
lw t3, 0(t1)
sw t3, 0(t0)
.org BZ_STARTUP_ORG
#endif
LEAF(startup)
.set noreorder
move t1, ra # save return address
la t0, __reloc_label # get linked address of label
bal __reloc_label # branch and link to label to
nop # get actual address
__reloc_label:
subu t0, ra, t0 # get reloc_delta
move ra, t1 # restore return address
beqz t0, __reloc_end # if delta is 0 we are in the right place
nop
/* Copy our code to the right place */
la t1, _code_start # get linked address of _code_start
la t2, _code_end # get linked address of _code_end
addu t0, t0, t1 # calculate actual address of _code_start
__reloc_copy:
lw t3, 0(t0)
sw t3, 0(t1)
add t1, 4
blt t1, t2, $L1
blt t1, t2, __reloc_copy
add t0, 4
__reloc_end:
/* At this point we need to invalidate dcache and */
/* icache before jumping to new code */
@ -147,7 +170,8 @@ nodc:
addu t0,s3
noic:
li t0, BZ_TEXT_START
/* Setup new "C" stack */
la sp, _stack
addiu sp, -32 /* reserve stack for parameters */
#if 0
@ -159,8 +183,12 @@ noic:
sw s3, 16(sp) /* icache line size */
sw s4, 20(sp) /* icache size */
sw s1, 24(sp) /* dcache line size */
jr t0
sw s2, 28(sp) /* dcache size */
/* jump to the decompressor routine */
la t0, decompress_entry
jr t0
nop
.set reorder
END(startup)
END(startup)

View File

@ -1,17 +1,27 @@
OUTPUT_ARCH(mips)
ENTRY(startup)
SECTIONS {
. = TEXT_START;
.text : {
_code_start = .;
*(.text)
*(.text.*)
*(.rodata)
*(.rodata.*)
_code_end = .;
}
.data : {
*(.data)
*(.data.*)
}
.bss : {
*(.bss)
*(.bss.*)
}
. = ALIGN(16);
. = . + 8192;
_stack = .;
workspace = .;
}