add lzma kernel compression support for au1000
[openwrt/openwrt.git] / target / image / generic / lzma-loader / src / Makefile
1 #
2 # Copyright (C) 2006 OpenWrt.org
3 #
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
6 #
7 LOADADDR = 0x80400000 # RAM start + 4M
8 KERNEL_ENTRY = 0x80001000
9 RAMSIZE = 0x00100000 # 1MB
10 IMAGE_COPY:=0
11
12 CROSS_COMPILE = mips-linux-
13
14 OBJCOPY:= $(CROSS_COMPILE)objcopy -O binary -R .reginfo -R .note -R .comment -R .mdebug -S
15 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
16 ifeq ($(IMAGE_COPY),1)
17 CFLAGS += -DLOADADDR=${LOADADDR} -DIMAGE_COPY=1
18 endif
19
20 .S.s:
21 $(CPP) $(CFLAGS) $< -o $*.s
22 .S.o:
23 $(CC) $(CFLAGS) -c $< -o $*.o
24 .c.o:
25 $(CC) $(CFLAGS) -c $< -o $*.o
26
27 CC = $(CROSS_COMPILE)gcc
28 LD = $(CROSS_COMPILE)ld
29 OBJDUMP = $(CROSS_COMPILE)objdump
30
31 O_FORMAT = $(shell $(OBJDUMP) -i | head -2 | grep elf32)
32
33 # Drop some uninteresting sections in the kernel.
34 # This is only relevant for ELF kernels but doesn't hurt a.out
35 drop-sections = .reginfo .mdebug .comment
36 strip-flags = $(addprefix --remove-section=,$(drop-sections))
37
38 all : lzma.elf
39
40 lzma.lds: lzma.lds.in
41 sed -e 's,@LOADADDR@,$(LOADADDR),g' -e 's,@ENTRY@,_start,g' $< >$@
42
43 kernel.o: vmlinux.lzma lzma.lds
44 $(LD) -r -b binary --oformat $(O_FORMAT) -o $@ $<
45
46 ifeq ($(IMAGE_COPY),1)
47 LOADER_ENTRY ?= $(KERNEL_ENTRY)
48 lzma.o: decompress.o LzmaDecode.o kernel.o
49 sed -e 's,@LOADADDR@,$(LOADADDR),g' -e 's,@ENTRY@,entry,g' lzma.lds.in >lzma-stage2.lds
50 $(LD) -static --no-warn-mismatch -e entry -Tlzma-stage2.lds -o temp-$@ $^
51 $(OBJCOPY) temp-$@ lzma.tmp
52 @echo "SECTIONS { .data : { code_start = .; *(.data) code_stop = .; }}" > lzma-data.lds
53 $(LD) -no-warn-mismatch -T lzma-data.lds -r -o $@ -b binary lzma.tmp --oformat $(O_FORMAT)
54
55 lzma.elf: start.o lzma.o
56 sed -e 's,@LOADADDR@,$(LOADER_ENTRY),g' lzma-copy.lds.in >lzma-copy.lds
57 $(LD) -s -Tlzma-copy.lds -o $@ $^
58 else
59 lzma.elf: start.o decompress.o LzmaDecode.o kernel.o
60 $(LD) -s -Tlzma.lds -o $@ $^
61 endif
62
63 clean:
64 rm -f *.o lzma.elf *.tmp *.lds