3a803cbd8bb7c65e49ea53ab0ade3799264da7e2
[openwrt/svn-archive/archive.git] / openwrt / target / linux / image / ar7 / Makefile
1 include $(TOPDIR)/rules.mk
2
3 KDIR:=$(BUILD_DIR)/linux-$(KERNEL)-$(BOARD)
4
5 PKG_BUILD_DIR:=$(BUILD_DIR)/ar7loader
6
7 ifeq ($(IB),)
8 LOADADDR := 0x94020000
9 KERNEL_ENTRY := 0x${shell nm $(KDIR)/linux-$(KERNEL)*/vmlinux | grep kernel_entry | cut -d' ' -f1}
10 OUTPUT_FORMAT := elf32-tradlittlemips
11
12 CFLAGS := -D__KERNEL__ -Wall -Wstrict-prototypes -Wno-trigraphs -Os \
13 -fno-strict-aliasing -fno-common -fomit-frame-pointer -G 0 -mno-abicalls -fno-pic \
14 -pipe -mlong-calls -fno-common \
15 -mabi=32 -march=mips32 -Wa,-32 -Wa,-march=mips32 -Wa,-mips32 -Wa,--trap \
16 -DLOADADDR=$(LOADADDR)
17
18
19 $(PKG_BUILD_DIR):
20 mkdir -p $(PKG_BUILD_DIR)
21
22 $(PKG_BUILD_DIR)/zimage.script: src/zimage.script.in
23 sed -e 's/@@OUTPUT_FORMAT@@/$(OUTPUT_FORMAT)/' \
24 -e 's/@@LOADADDR@@/$(LOADADDR)/' <$< >$@
25
26 $(PKG_BUILD_DIR)/ld.script: src/ld.script.in
27 sed -e 's/@@OUTPUT_FORMAT@@/$(OUTPUT_FORMAT)/' \
28 -e 's/@@LOADADDR@@/$(LOADADDR)/' <$< >$@
29
30 $(PKG_BUILD_DIR)/cksum.o: $(PKG_BUILD_DIR)/cksum.c
31 $(HOSTCC) -o $@ $<
32
33 $(PKG_BUILD_DIR)/ckmain.o: $(PKG_BUILD_DIR)/ckmain.c
34 $(HOSTCC) -o $@ $<
35
36 $(PKG_BUILD_DIR)/tichksum: $(PKG_BUILD_DIR)/ckmain.o $(PKG_BUILD_DIR)/cksum.o
37 $(HOSTCC) -o $@ $<
38
39 $(PKG_BUILD_DIR)/LzmaDecode.o: src/LzmaDecode.c
40 $(TARGET_CC) $(CFLAGS) -c -o $@ $<
41
42 $(PKG_BUILD_DIR)/loader.o: src/loader.c
43 $(TARGET_CC) $(CFLAGS) -c -o $@ $<
44
45 $(STAGING_DIR)/bin/srec2bin: src/srec2bin.c
46 $(HOSTCC) -o $@ $<
47
48 $(KDIR)/vmlinux.lzma: $(KDIR)/vmlinux
49 cat $^ | $(STAGING_DIR)/bin/lzma e -si -so -eos -lc1 -lp2 -pb2 > $@ || (rm -f $@ && false)
50
51 $(KDIR)/vmlinux.bin: $(KDIR)/vmlinux.lzma compile
52 $(TARGET_CROSS)ld -T $(PKG_BUILD_DIR)/zimage.script -r -b binary $< -o $(KDIR)/zimage.o
53 $(TARGET_CROSS)ld -static -G 0 --defsym kernel_entry=$(KERNEL_ENTRY) -T $(PKG_BUILD_DIR)/ld.script \
54 $(PKG_BUILD_DIR)/loader.o \
55 $(PKG_BUILD_DIR)/LzmaDecode.o \
56 $(KDIR)/zimage.o \
57 -o $(KDIR)/loader
58 $(TARGET_CROSS)objcopy -O srec $(KDIR)/loader $(KDIR)/ram_zimage.sre
59 $(STAGING_DIR)/bin/srec2bin $(KDIR)/ram_zimage.sre $@
60
61 $(BIN_DIR)/openwrt-$(BOARD)-$(KERNEL)-kernel.bin: $(KDIR)/vmlinux.bin
62 endif
63
64 $(BIN_DIR)/openwrt-$(BOARD)-$(KERNEL)-kernel.bin:
65 $(CP) $(KDIR)/vmlinux.bin $@
66
67 ifeq ($(FS),jffs2-8MB)
68 ALIGN:=bs=131072 conv=sync
69 endif
70 ifeq ($(FS),jffs2-4MB)
71 ALIGN:=bs=65536 conv=sync
72 endif
73
74 $(BIN_DIR)/openwrt-$(BOARD)-$(KERNEL)-$(FS).bin: $(BIN_DIR)/openwrt-$(BOARD)-$(KERNEL)-kernel.bin
75 dd if=$< $(ALIGN) > $@
76 cat $(BUILD_DIR)/linux-$(KERNEL)-$(BOARD)/root.$(FS) >> $@
77
78 define pattern_template
79 $(BIN_DIR)/openwrt-$(BOARD)-$(KERNEL)-$(FS)-$(1).bin: $(BIN_DIR)/openwrt-$(BOARD)-$(KERNEL)-$(FS).bin
80 (dd if=/dev/zero bs=16 count=1; cat $(BIN_DIR)/openwrt-$(BOARD)-$(KERNEL)-$(FS).bin) | \
81 $(STAGING_DIR)/bin/addpattern -p $(1) $(2) -o $(BIN_DIR)/openwrt-$(BOARD)-$(KERNEL)-$(FS)-$(1).bin
82
83 install: $(BIN_DIR)/openwrt-$(BOARD)-$(KERNEL)-$(FS)-$(1).bin
84 endef
85
86 define sercomm_template
87 $(BIN_DIR)/openwrt-$(1)-$(KERNEL)-$(FS).bin: $(BIN_DIR)/openwrt-$(BOARD)-$(KERNEL)-$(FS).bin
88 cat sercomm/adam2.bin "$$^" > "$$@.tmp"
89 dd if=sercomm/$(1) of="$$@.tmp" bs=$$$$((0x3e0000 - 80)) seek=1 conv=notrunc
90 $(STAGING_DIR)/bin/dgfirmware -f -w "$$@" "$$@.tmp"
91 rm -f "$$@.tmp"
92
93 install: $(BIN_DIR)/openwrt-$(1)-$(KERNEL)-$(FS).bin
94 endef
95
96 $(eval $(call sercomm_template,dg834))
97 $(eval $(call sercomm_template,jdr454wb))
98
99 $(eval $(call pattern_template,AG1B))
100 $(eval $(call pattern_template,WA22))
101 $(eval $(call pattern_template,WAG2))
102 $(eval $(call pattern_template,WA21))
103 $(eval $(call pattern_template,WA31,-b))
104 $(eval $(call pattern_template,WA32,-b))
105
106 ifeq ($(IB),)
107 clean:
108 rm -rf $(PKG_BUILD_DIR)
109 rm -f $(BIN_DIR)/openwrt-$(BOARD)*
110
111 prepare: $(PKG_BUILD_DIR) $(PKG_BUILD_DIR)/zimage.script $(PKG_BUILD_DIR)/ld.script
112 compile: prepare $(PKG_BUILD_DIR)/loader.o $(PKG_BUILD_DIR)/LzmaDecode.o $(STAGING_DIR)/bin/srec2bin
113 else
114 clean:
115 prepare:
116 compile:
117 endif
118
119 install: $(BIN_DIR)/openwrt-$(BOARD)-$(KERNEL)-kernel.bin $(BIN_DIR)/openwrt-$(BOARD)-$(KERNEL)-$(FS).bin
120 install-ib:
121 mkdir -p $(IB_DIR)/build_$(ARCH)/linux-$(KERNEL)-$(BOARD)
122 $(CP) $(KDIR)/vmlinux.bin $(IB_DIR)/build_$(ARCH)/linux-$(KERNEL)-$(BOARD)/
123 mkdir -p $(IB_DIR)/staging_dir_$(ARCH)
124 $(CP) $(STAGING_DIR)/bin/addpattern $(IB_DIR)/staging_dir_$(ARCH)/bin/
125