LOADADDR = 0x80400000 # RAM start + 4M
KERNEL_ENTRY = 0x80001000
RAMSIZE = 0x00100000 # 1MB
+IMAGE_COPY:=0
CROSS_COMPILE = mips-linux-
+OBJCOPY:= $(CROSS_COMPILE)objcopy -O binary -R .reginfo -R .note -R .comment -R .mdebug -S
+CFLAGS := -fno-builtin -Os -G 0 -ffunction-sections -mno-abicalls -fno-pic -mabi=32 -march=mips32 -Wa,-32 -Wa,-march=mips32 -Wa,-mips32 -Wa,--trap -Wall -DRAMSIZE=${RAMSIZE} -DKERNEL_ENTRY=${KERNEL_ENTRY} -D_LZMA_IN_CB
+ifeq ($(IMAGE_COPY),1)
+CFLAGS += -DLOADADDR=${LOADADDR} -DIMAGE_COPY=1
+endif
+
.S.s:
$(CPP) $(CFLAGS) $< -o $*.s
.S.o:
CC = $(CROSS_COMPILE)gcc
LD = $(CROSS_COMPILE)ld
-OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
-CFLAGS = -fno-builtin -Os -G 0 -mno-abicalls -fno-pic -Wall -DRAMSIZE=${RAMSIZE} -DKERNEL_ENTRY=${KERNEL_ENTRY} -D_LZMA_IN_CB
-# CFLAGS = -fno-builtin -Os -G 0 -mno-abicalls -fno-pic -Wall -DRAMSIZE=${RAMSIZE}
-
O_FORMAT = $(shell $(OBJDUMP) -i | head -2 | grep elf32)
# Drop some uninteresting sections in the kernel.
drop-sections = .reginfo .mdebug .comment
strip-flags = $(addprefix --remove-section=,$(drop-sections))
-
all : lzma.elf
lzma.lds: lzma.lds.in
- sed -e 's,@LOADADDR@,$(LOADADDR),g' $< >$@
+ sed -e 's,@LOADADDR@,$(LOADADDR),g' -e 's,@ENTRY@,_start,g' $< >$@
kernel.o: vmlinux.lzma lzma.lds
$(LD) -r -b binary --oformat $(O_FORMAT) -o $@ $<
+ifeq ($(IMAGE_COPY),1)
+lzma.o: decompress.o LzmaDecode.o kernel.o
+ sed -e 's,@LOADADDR@,$(LOADADDR),g' -e 's,@ENTRY@,entry,g' lzma.lds.in >lzma-stage2.lds
+ $(LD) -static --no-warn-mismatch -e entry -Tlzma-stage2.lds -o temp-$@ $^
+ $(OBJCOPY) temp-$@ lzma.tmp
+ @echo "SECTIONS { .data : { code_start = .; *(.data) code_stop = .; }}" > lzma-data.lds
+ $(LD) -no-warn-mismatch -T lzma-data.lds -r -o $@ -b binary lzma.tmp --oformat $(O_FORMAT)
+
+lzma.elf: start.o lzma.o
+ sed -e 's,@LOADADDR@,$(KERNEL_ENTRY),g' lzma-copy.lds.in >lzma-copy.lds
+ $(LD) -s -Tlzma-copy.lds -o $@ $^
+else
lzma.elf: start.o decompress.o LzmaDecode.o kernel.o
$(LD) -s -Tlzma.lds -o $@ $^
+endif
clean:
- rm -f *.o lzma.elf
+ rm -f *.o lzma.elf *.tmp *.lds
{
unsigned int i; /* temp value */
unsigned int osize; /* uncompressed size */
+ volatile unsigned int arg0, arg1, arg2, arg3;
+
+ /* restore argument registers */
+ __asm__ __volatile__ ("ori %0, $12, 0":"=r"(arg0));
+ __asm__ __volatile__ ("ori %0, $13, 0":"=r"(arg1));
+ __asm__ __volatile__ ("ori %0, $14, 0":"=r"(arg2));
+ __asm__ __volatile__ ("ori %0, $15, 0":"=r"(arg3));
ILzmaInCallback callback;
CLzmaDecoderState vs;
blast_icache(icache_size, icache_lsize);
/* Jump to load address */
- ((void (*)(void)) KERNEL_ENTRY)();
+ ((void (*)(int a0, int a1, int a2, int a3)) KERNEL_ENTRY)(arg0, arg1, arg2, arg3);
}
}
.set mips32
.set noreorder
+ /* save argument registers */
+ move t4, a0
+ move t5, a1
+ move t6, a2
+ move t7, a3
+
/* set up stack */
li sp, 0xa0000000 + RAMSIZE - 16
-
-
+
+#ifdef IMAGE_COPY
+ /* Copy decompressor code to the right place */
+ li t2, LOADADDR
+ add a0, t2, 0
+ la a1, code_start
+ la a2, code_stop
+$L1:
+ lw t0, 0(a1)
+ sw t0, 0(a0)
+ add a1, 4
+ add a0, 4
+ blt a1, a2, $L1
+ nop
+#endif
+
/* At this point we need to invalidate dcache and */
/* icache before jumping to new code */
move a0,s3 /* icache line size */
move a1,s4 /* icache size */
move a2,s1 /* dcache line size */
+#ifdef IMAGE_COPY
+ jal t2
+#else
jal entry
+#endif
move a3,s2 /* dcache size */
.set reorder