brcm63xx: add working lzma-loader and use it for initramfs
[openwrt/svn-archive/archive.git] / target / linux / brcm63xx / image / lzma-loader / src / Makefile
1 #
2 # Makefile for the LZMA compressed kernel loader for
3 # Atheros AR7XXX/AR9XXX based boards
4 #
5 # Copyright (C) 2011 Gabor Juhos <juhosg@openwrt.org>
6 #
7 # Some parts of this file was based on the OpenWrt specific lzma-loader
8 # for the BCM47xx and ADM5120 based boards:
9 # Copyright (C) 2004 Manuel Novoa III (mjn3@codepoet.org)
10 # Copyright (C) 2005 Mineharu Takahara <mtakahar@yahoo.com>
11 # Copyright (C) 2005 by Oleg I. Vdovikin <oleg@cs.msu.su>
12 #
13 # This program is free software; you can redistribute it and/or modify it
14 # under the terms of the GNU General Public License version 2 as published
15 # by the Free Software Foundation.
16 #
17
18 LOADADDR :=
19 LZMA_TEXT_START := 0x80a00000
20 LOADER_DATA :=
21
22 CC := $(CROSS_COMPILE)gcc
23 LD := $(CROSS_COMPILE)ld
24 OBJCOPY := $(CROSS_COMPILE)objcopy
25 OBJDUMP := $(CROSS_COMPILE)objdump
26
27 BIN_FLAGS := -O binary -R .reginfo -R .note -R .comment -R .mdebug -S
28
29 CFLAGS = -D__KERNEL__ -Wall -Wstrict-prototypes -Wno-trigraphs -Os \
30 -fno-strict-aliasing -fno-common -fomit-frame-pointer -G 0 \
31 -mno-abicalls -fno-pic -ffunction-sections -pipe \
32 -ffreestanding -fhonour-copts \
33 -mabi=32 -march=mips32 \
34 -Wa,-32 -Wa,-march=mips32 -Wa,-mips32 -Wa,--trap
35 CFLAGS += -D_LZMA_PROB32
36
37 ASFLAGS = $(CFLAGS) -D__ASSEMBLY__
38
39 LDFLAGS = -static --gc-sections -no-warn-mismatch
40 LDFLAGS += -e startup -T loader.lds -Ttext $(LZMA_TEXT_START)
41
42 O_FORMAT = $(shell $(OBJDUMP) -i | head -2 | grep elf32)
43
44 OBJECTS := head.o loader.o cache.o board.o printf.o LzmaDecode.o
45
46 ifneq ($(strip $(LOADER_DATA)),)
47 OBJECTS += data.o
48 CFLAGS += -DLZMA_WRAPPER=1 -DLOADADDR=$(LOADADDR)
49 endif
50
51
52 all: loader.elf
53
54 # Don't build dependencies, this may die if $(CC) isn't gcc
55 dep:
56
57 install:
58
59 %.o : %.c
60 $(CC) $(CFLAGS) -c -o $@ $<
61
62 %.o : %.S
63 $(CC) $(ASFLAGS) -c -o $@ $<
64
65 data.o: $(LOADER_DATA)
66 $(LD) -r -b binary --oformat $(O_FORMAT) -T lzma-data.lds -o $@ $<
67
68 loader: $(OBJECTS)
69 $(LD) $(LDFLAGS) -o $@ $(OBJECTS)
70
71 loader.bin: loader
72 $(OBJCOPY) $(BIN_FLAGS) $< $@
73
74 loader2.o: loader.bin
75 $(LD) -r -b binary --oformat $(O_FORMAT) -o $@ $<
76
77 loader.elf: loader2.o
78 $(LD) -e startup -T loader2.lds -Ttext $(LOADADDR) -o $@ $<
79
80 mrproper: clean
81
82 clean:
83 rm -f loader *.elf *.bin *.o
84
85
86