add proper ar7 flash map driver and change image stuff to save more flash space
[openwrt.git] / 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 OUTPUT_FORMAT := elf32-tradlittlemips
9
10 CFLAGS := -D__KERNEL__ -Wall -Wstrict-prototypes -Wno-trigraphs -Os \
11         -fno-strict-aliasing -fno-common -fomit-frame-pointer -G 0 -mno-abicalls -fno-pic \
12         -pipe -mlong-calls -fno-common \
13         -mabi=32 -march=mips32 -Wa,-32 -Wa,-march=mips32 -Wa,-mips32 -Wa,--trap \
14
15
16 $(PKG_BUILD_DIR):
17         mkdir -p $(PKG_BUILD_DIR)
18
19 $(PKG_BUILD_DIR)/zimage.script: src/zimage.script.in
20         sed -e 's/@@OUTPUT_FORMAT@@/$(OUTPUT_FORMAT)/' \
21             -e 's/@@LOADADDR@@/$(LOADADDR)/' <$< >$@
22
23 $(PKG_BUILD_DIR)/ld.script: src/ld.script.in
24         sed -e 's/@@OUTPUT_FORMAT@@/$(OUTPUT_FORMAT)/' \
25             -e 's/@@LOADADDR@@/$(LOADADDR)/' <$< >$@
26
27 $(PKG_BUILD_DIR)/loader.o: src/loader.c
28         $(TARGET_CC) $(CFLAGS) -c -o $@ $<
29
30 $(PKG_BUILD_DIR)/srec2bin: src/srec2bin.c
31         $(HOSTCC) -o $@ $<
32
33 $(KDIR)/vmlinux.gz: $(KDIR)/vmlinux
34         gzip -c -vf9 < $< > $@
35
36 $(BIN_DIR)/openwrt-ar7-zimage.bin: $(KDIR)/vmlinux.gz compile
37         $(TARGET_CROSS)ld -T $(PKG_BUILD_DIR)/zimage.script -r -b binary $< -o $(KDIR)/zimage.o
38         $(TARGET_CROSS)ld -static -G 0 -no-warn-mismatch -R $(KDIR)/linux-$(KERNEL)*/vmlinux -T $(PKG_BUILD_DIR)/ld.script \
39                 $(PKG_BUILD_DIR)/loader.o \
40                 $(KDIR)/zimage.o \
41                 -o $(KDIR)/loader
42         $(TARGET_CROSS)objcopy -O srec $(KDIR)/loader $(KDIR)/ram_zimage.sre
43         $(PKG_BUILD_DIR)/srec2bin $(KDIR)/ram_zimage.sre $@
44         dd if=/dev/zero bs=1024 count=1 >> $@
45
46 ALIGN:=1024
47 ifeq ($(FS),jffs2-8MB)
48 ALIGN:=131072
49 endif
50 ifeq ($(FS),jffs2-4MB)
51 ALIGN:=65536
52 endif
53
54 $(BIN_DIR)/openwrt-ar7-$(KERNEL)-$(FS).bin:
55         dd if=$(BIN_DIR)/openwrt-ar7-zimage.bin bs=$(ALIGN) conv=sync | head -c -1024 > $@
56         $(STAGING_DIR)/bin/trx -a 1024 $(BUILD_DIR)/linux-$(KERNEL)-ar7/root.$(FS) >> $@
57
58 define pattern_template
59 $(BIN_DIR)/openwrt-ar7-$(KERNEL)-$(FS)-$(1).bin: $(BIN_DIR)/openwrt-ar7-$(KERNEL)-$(FS).bin
60         (dd if=/dev/zero bs=16 count=1; cat $(BIN_DIR)/openwrt-ar7-$(KERNEL)-$(FS).bin) | \
61                 $(STAGING_DIR)/bin/addpattern -p $(1) -o $(BIN_DIR)/openwrt-ar7-$(KERNEL)-$(FS)-$(1).bin
62         
63 install: $(BIN_DIR)/openwrt-ar7-$(KERNEL)-$(FS)-$(1).bin
64 endef
65
66 $(eval $(call pattern_template,WA22))
67 $(eval $(call pattern_template,WAG2))
68 $(eval $(call pattern_template,WA21))
69
70 clean:
71         rm -rf $(PKG_BUILD_DIR)
72         rm -f $(BIN_DIR)/openwrt-ar7*
73
74 prepare: $(PKG_BUILD_DIR) $(PKG_BUILD_DIR)/zimage.script $(PKG_BUILD_DIR)/ld.script
75 compile: prepare $(PKG_BUILD_DIR)/loader.o $(PKG_BUILD_DIR)/srec2bin
76 install: $(BIN_DIR)/openwrt-ar7-zimage.bin $(BIN_DIR)/openwrt-ar7-$(KERNEL)-$(FS).bin
77