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-a3cf2f4a3e73master
parent
5218d952cd
commit
75af0330e0
|
@ -8,6 +8,9 @@
|
||||||
|
|
||||||
include $(TOPDIR)/rules.mk
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
|
LOADER := loader
|
||||||
|
BZ_STARTUP_ORG := 0
|
||||||
|
|
||||||
PKG_NAME := lzma-loader
|
PKG_NAME := lzma-loader
|
||||||
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
|
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
|
||||||
|
|
||||||
|
@ -16,18 +19,19 @@ $(PKG_BUILD_DIR)/.prepared:
|
||||||
$(CP) ./src/* $(PKG_BUILD_DIR)/
|
$(CP) ./src/* $(PKG_BUILD_DIR)/
|
||||||
touch $@
|
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)" \
|
$(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:
|
download:
|
||||||
prepare: $(PKG_BUILD_DIR)/.prepared
|
prepare: $(PKG_BUILD_DIR)/.prepared
|
||||||
compile: $(PKG_BUILD_DIR)/loader.gz
|
compile: $(PKG_BUILD_DIR)/$(LOADER).gz
|
||||||
install:
|
install:
|
||||||
|
|
||||||
ifneq ($(TARGET),)
|
ifneq ($(TARGET),)
|
||||||
install: compile
|
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
|
endif
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
|
|
@ -16,9 +16,15 @@
|
||||||
# Copyright 2005 Oleg I. Vdovikin <oleg@cs.msu.su>
|
# Copyright 2005 Oleg I. Vdovikin <oleg@cs.msu.su>
|
||||||
# Cleaned up, modified for lzma support, removed from kernel
|
# 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_TEXT_START := 0x80300000
|
||||||
|
BZ_STARTUP_ORG := 0
|
||||||
|
LOADER := loader
|
||||||
|
|
||||||
OBJCOPY := $(CROSS_COMPILE)objcopy -O binary -R .reginfo -R .note -R .comment -R .mdebug -S
|
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 \
|
-fno-strict-aliasing -fno-common -fomit-frame-pointer -G 0 -mno-abicalls -fno-pic \
|
||||||
-ffunction-sections -pipe -mlong-calls -fno-common \
|
-ffunction-sections -pipe -mlong-calls -fno-common \
|
||||||
-mabi=32 -march=mips32 -Wa,-32 -Wa,-march=mips32 -Wa,-mips32 -Wa,--trap
|
-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
|
# Don't build dependencies, this may die if $(CC) isn't gcc
|
||||||
dep:
|
dep:
|
||||||
|
|
||||||
install:
|
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 $< > $@
|
gzip -nc9 $< > $@
|
||||||
|
|
||||||
loader.elf: loader.o
|
$(LOADER).elf: $(LOADER).o
|
||||||
cp $< $@
|
cp $< $@
|
||||||
|
|
||||||
loader: loader.o
|
$(LOADER).bin: $(LOADER).o
|
||||||
$(OBJCOPY) $< $@
|
$(OBJCOPY) -O binary $< $@
|
||||||
|
|
||||||
loader.o: loader.lds $(OBJECTS)
|
$(LOADER).o: $(OBJECTS)
|
||||||
$(LD) -static --gc-sections -no-warn-mismatch -T loader.lds -o $@ $(OBJECTS)
|
$(LD) $(LDFLAGS) -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)" < $< > $@
|
|
||||||
|
|
||||||
mrproper: clean
|
mrproper: clean
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f loader.gz loader decompress *.lds *.o *.image
|
rm -f *.gz *.elf *.bin *.o
|
||||||
|
|
|
@ -124,8 +124,10 @@ static __inline__ unsigned char get_byte(void)
|
||||||
return read_byte(0, &buffer, &fake), *buffer;
|
return read_byte(0, &buffer, &fake), *buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int uart_write_str(char * str);
|
||||||
|
|
||||||
/* should be the first function */
|
/* 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 reg_a2, unsigned long reg_a3,
|
||||||
unsigned long icache_size, unsigned long icache_lsize,
|
unsigned long icache_size, unsigned long icache_lsize,
|
||||||
unsigned long dcache_size, unsigned long dcache_lsize)
|
unsigned long dcache_size, unsigned long dcache_lsize)
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
OUTPUT_ARCH(mips)
|
|
||||||
ENTRY(entry)
|
|
||||||
SECTIONS {
|
|
||||||
. = BZ_TEXT_START;
|
|
||||||
.text : {
|
|
||||||
*(.text.entry)
|
|
||||||
*(.text)
|
|
||||||
*(.rodata)
|
|
||||||
}
|
|
||||||
|
|
||||||
.data : {
|
|
||||||
*(.data)
|
|
||||||
}
|
|
||||||
|
|
||||||
.bss : {
|
|
||||||
*(.bss)
|
|
||||||
}
|
|
||||||
|
|
||||||
workspace = .;
|
|
||||||
}
|
|
|
@ -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 */
|
/* 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) */
|
/* Copyright 2005 Oleg I. Vdovikin (oleg@cs.msu.su) */
|
||||||
/* cache manipulation adapted from Broadcom code */
|
/* cache manipulation adapted from Broadcom code */
|
||||||
/* idea taken from original bunzip2 decompressor code */
|
/* idea taken from original bunzip2 decompressor code */
|
||||||
|
@ -39,21 +39,44 @@
|
||||||
#define Index_Writeback_Inv_D 0x01
|
#define Index_Writeback_Inv_D 0x01
|
||||||
|
|
||||||
.text
|
.text
|
||||||
LEAF(startup)
|
|
||||||
|
#if (BZ_STARTUP_ORG)
|
||||||
|
.set noreorder
|
||||||
|
|
||||||
|
b startup
|
||||||
|
nop
|
||||||
|
|
||||||
|
.org BZ_STARTUP_ORG
|
||||||
|
#endif
|
||||||
|
|
||||||
|
LEAF(startup)
|
||||||
.set noreorder
|
.set noreorder
|
||||||
|
|
||||||
/* Copy decompressor code to the right place */
|
move t1, ra # save return address
|
||||||
li t0, BZ_TEXT_START
|
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
|
||||||
|
|
||||||
la t1, code_start
|
beqz t0, __reloc_end # if delta is 0 we are in the right place
|
||||||
la t2, code_stop
|
nop
|
||||||
$L1:
|
|
||||||
lw t3, 0(t1)
|
/* Copy our code to the right place */
|
||||||
sw t3, 0(t0)
|
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
|
add t1, 4
|
||||||
blt t1, t2, $L1
|
blt t1, t2, __reloc_copy
|
||||||
add t0, 4
|
add t0, 4
|
||||||
|
|
||||||
|
__reloc_end:
|
||||||
|
|
||||||
/* At this point we need to invalidate dcache and */
|
/* At this point we need to invalidate dcache and */
|
||||||
/* icache before jumping to new code */
|
/* icache before jumping to new code */
|
||||||
|
|
||||||
|
@ -147,7 +170,8 @@ nodc:
|
||||||
addu t0,s3
|
addu t0,s3
|
||||||
|
|
||||||
noic:
|
noic:
|
||||||
li t0, BZ_TEXT_START
|
/* Setup new "C" stack */
|
||||||
|
la sp, _stack
|
||||||
|
|
||||||
addiu sp, -32 /* reserve stack for parameters */
|
addiu sp, -32 /* reserve stack for parameters */
|
||||||
#if 0
|
#if 0
|
||||||
|
@ -159,8 +183,12 @@ noic:
|
||||||
sw s3, 16(sp) /* icache line size */
|
sw s3, 16(sp) /* icache line size */
|
||||||
sw s4, 20(sp) /* icache size */
|
sw s4, 20(sp) /* icache size */
|
||||||
sw s1, 24(sp) /* dcache line size */
|
sw s1, 24(sp) /* dcache line size */
|
||||||
jr t0
|
|
||||||
sw s2, 28(sp) /* dcache size */
|
sw s2, 28(sp) /* dcache size */
|
||||||
|
|
||||||
|
/* jump to the decompressor routine */
|
||||||
|
la t0, decompress_entry
|
||||||
|
jr t0
|
||||||
|
nop
|
||||||
|
|
||||||
.set reorder
|
.set reorder
|
||||||
END(startup)
|
END(startup)
|
||||||
|
|
|
@ -1,17 +1,27 @@
|
||||||
OUTPUT_ARCH(mips)
|
OUTPUT_ARCH(mips)
|
||||||
ENTRY(startup)
|
|
||||||
SECTIONS {
|
SECTIONS {
|
||||||
. = TEXT_START;
|
|
||||||
.text : {
|
.text : {
|
||||||
|
_code_start = .;
|
||||||
*(.text)
|
*(.text)
|
||||||
|
*(.text.*)
|
||||||
*(.rodata)
|
*(.rodata)
|
||||||
|
*(.rodata.*)
|
||||||
|
_code_end = .;
|
||||||
}
|
}
|
||||||
|
|
||||||
.data : {
|
.data : {
|
||||||
*(.data)
|
*(.data)
|
||||||
|
*(.data.*)
|
||||||
}
|
}
|
||||||
|
|
||||||
.bss : {
|
.bss : {
|
||||||
*(.bss)
|
*(.bss)
|
||||||
|
*(.bss.*)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
. = ALIGN(16);
|
||||||
|
. = . + 8192;
|
||||||
|
_stack = .;
|
||||||
|
|
||||||
|
workspace = .;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue