ee2b570eb7d3497539f3199a3f681d3a61d853a2
[openwrt.git] / openwrt / target / linux / image / ar7 / Makefile
1 include $(TOPDIR)/rules.mk
2
3 KDIR:=$(BUILD_DIR)/linux-$(KERNEL)-ar7
4
5 PKG_BUILD_DIR:=$(BUILD_DIR)/ar7loader
6
7 LOADADDR := 0x94020000
8 KERNEL_ENTRY := 0x${shell nm $(KDIR)/linux-$(KERNEL)*/vmlinux | grep kernel_entry | cut -d' ' -f1}
9 OUTPUT_FORMAT := elf32-tradlittlemips
10
11 CFLAGS := -D__KERNEL__ -Wall -Wstrict-prototypes -Wno-trigraphs -Os \
12 -fno-strict-aliasing -fno-common -fomit-frame-pointer -G 0 -mno-abicalls -fno-pic \
13 -pipe -mlong-calls -fno-common \
14 -mabi=32 -march=mips32 -Wa,-32 -Wa,-march=mips32 -Wa,-mips32 -Wa,--trap \
15 -DLOADADDR=$(LOADADDR)
16
17 $(PKG_BUILD_DIR):
18 mkdir -p $(PKG_BUILD_DIR)
19
20 $(PKG_BUILD_DIR)/zimage.script: src/zimage.script.in
21 sed -e 's/@@OUTPUT_FORMAT@@/$(OUTPUT_FORMAT)/' \
22 -e 's/@@LOADADDR@@/$(LOADADDR)/' <$< >$@
23
24 $(PKG_BUILD_DIR)/ld.script: src/ld.script.in
25 sed -e 's/@@OUTPUT_FORMAT@@/$(OUTPUT_FORMAT)/' \
26 -e 's/@@LOADADDR@@/$(LOADADDR)/' <$< >$@
27
28 $(PKG_BUILD_DIR)/LzmaDecode.o: src/LzmaDecode.c
29 $(TARGET_CC) $(CFLAGS) -c -o $@ $<
30
31 $(PKG_BUILD_DIR)/loader.o: src/loader.c
32 $(TARGET_CC) $(CFLAGS) -c -o $@ $<
33
34 $(PKG_BUILD_DIR)/srec2bin: src/srec2bin.c
35 $(HOSTCC) -o $@ $<
36
37 $(KDIR)/vmlinux.gz: $(KDIR)/vmlinux
38 gzip -c -vf9 < $< > $@
39
40 $(KDIR)/vmlinux.lzma: $(KDIR)/vmlinux
41 cat $^ | $(STAGING_DIR)/bin/lzma e -si -so -eos -lc1 -lp2 -pb2 > $@ || (rm -f $@ && false)
42
43 $(BIN_DIR)/openwrt-ar7-2.4-kernel.bin: $(KDIR)/vmlinux.lzma compile
44 $(TARGET_CROSS)ld -T $(PKG_BUILD_DIR)/zimage.script -r -b binary $< -o $(KDIR)/zimage.o
45 $(TARGET_CROSS)ld -static -G 0 --defsym kernel_entry=$(KERNEL_ENTRY) -T $(PKG_BUILD_DIR)/ld.script \
46 $(PKG_BUILD_DIR)/loader.o \
47 $(PKG_BUILD_DIR)/LzmaDecode.o \
48 $(KDIR)/zimage.o \
49 -o $(KDIR)/loader
50 $(TARGET_CROSS)objcopy -O srec $(KDIR)/loader $(KDIR)/ram_zimage.sre
51 $(PKG_BUILD_DIR)/srec2bin $(KDIR)/ram_zimage.sre $@
52
53 ifeq ($(FS),jffs2-8MB)
54 ALIGN:=bs=131072 conv=sync
55 endif
56 ifeq ($(FS),jffs2-4MB)
57 ALIGN:=bs=65536 conv=sync
58 endif
59
60 $(BIN_DIR)/openwrt-ar7-$(KERNEL)-$(FS).bin: $(BIN_DIR)/openwrt-ar7-2.4-kernel.bin
61 dd if=$< $(ALIGN) > $@
62 cat $(BUILD_DIR)/linux-$(KERNEL)-ar7/root.$(FS) >> $@
63
64 define pattern_template
65 $(BIN_DIR)/openwrt-ar7-$(KERNEL)-$(FS)-$(1).bin: $(BIN_DIR)/openwrt-ar7-$(KERNEL)-$(FS).bin
66 (dd if=/dev/zero bs=16 count=1; cat $(BIN_DIR)/openwrt-ar7-$(KERNEL)-$(FS).bin) | \
67 $(STAGING_DIR)/bin/addpattern -p $(1) -o $(BIN_DIR)/openwrt-ar7-$(KERNEL)-$(FS)-$(1).bin
68
69 install: $(BIN_DIR)/openwrt-ar7-$(KERNEL)-$(FS)-$(1).bin
70 endef
71
72 $(eval $(call pattern_template,WA22))
73 $(eval $(call pattern_template,WAG2))
74 $(eval $(call pattern_template,WA21))
75
76 clean:
77 rm -rf $(PKG_BUILD_DIR)
78 rm -f $(BIN_DIR)/openwrt-ar7*
79
80 prepare: $(PKG_BUILD_DIR) $(PKG_BUILD_DIR)/zimage.script $(PKG_BUILD_DIR)/ld.script
81 compile: prepare $(PKG_BUILD_DIR)/loader.o $(PKG_BUILD_DIR)/LzmaDecode.o $(PKG_BUILD_DIR)/srec2bin
82 install: $(BIN_DIR)/openwrt-ar7-2.4-kernel.bin $(BIN_DIR)/openwrt-ar7-$(KERNEL)-$(FS).bin
83
This page took 0.036213 seconds and 3 git commands to generate.