sync with brcm
[openwrt.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 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 $(STAGING_DIR)/bin/srec2bin: src/srec2bin.c
35 $(HOSTCC) -o $@ $<
36
37 $(KDIR)/vmlinux.lzma: $(KDIR)/vmlinux
38 cat $^ | $(STAGING_DIR)/bin/lzma e -si -so -eos -lc1 -lp2 -pb2 > $@ || (rm -f $@ && false)
39
40 ifeq ($(IB),)
41 $(KDIR)/vmlinux.bin: $(KDIR)/vmlinux.lzma compile
42 $(TARGET_CROSS)ld -T $(PKG_BUILD_DIR)/zimage.script -r -b binary $< -o $(KDIR)/zimage.o
43 $(TARGET_CROSS)ld -static -G 0 --defsym kernel_entry=$(KERNEL_ENTRY) -T $(PKG_BUILD_DIR)/ld.script \
44 $(PKG_BUILD_DIR)/loader.o \
45 $(PKG_BUILD_DIR)/LzmaDecode.o \
46 $(KDIR)/zimage.o \
47 -o $(KDIR)/loader
48 $(TARGET_CROSS)objcopy -O srec $(KDIR)/loader $(KDIR)/ram_zimage.sre
49 $(STAGING_DIR)/bin/srec2bin $(KDIR)/ram_zimage.sre $@
50
51 $(BIN_DIR)/openwrt-$(BOARD)-$(KERNEL)-kernel.bin: $(KDIR)/vmlinux.bin
52 endif
53
54 $(BIN_DIR)/openwrt-$(BOARD)-$(KERNEL)-kernel.bin:
55 cp $< $@
56
57 ifeq ($(FS),jffs2-8MB)
58 ALIGN:=bs=131072 conv=sync
59 endif
60 ifeq ($(FS),jffs2-4MB)
61 ALIGN:=bs=65536 conv=sync
62 endif
63
64 $(BIN_DIR)/openwrt-$(BOARD)-$(KERNEL)-$(FS).bin: $(BIN_DIR)/openwrt-$(BOARD)-$(KERNEL)-kernel.bin
65 dd if=$< $(ALIGN) > $@
66 cat $(BUILD_DIR)/linux-$(KERNEL)-$(BOARD)/root.$(FS) >> $@
67
68 define pattern_template
69 $(BIN_DIR)/openwrt-$(BOARD)-$(KERNEL)-$(FS)-$(1).bin: $(BIN_DIR)/openwrt-$(BOARD)-$(KERNEL)-$(FS).bin
70 (dd if=/dev/zero bs=16 count=1; cat $(BIN_DIR)/openwrt-$(BOARD)-$(KERNEL)-$(FS).bin) | \
71 $(STAGING_DIR)/bin/addpattern -p $(1) $(2) -o $(BIN_DIR)/openwrt-$(BOARD)-$(KERNEL)-$(FS)-$(1).bin
72
73 install: $(BIN_DIR)/openwrt-$(BOARD)-$(KERNEL)-$(FS)-$(1).bin
74 endef
75
76 $(eval $(call pattern_template,AG1B))
77 $(eval $(call pattern_template,WA22))
78 $(eval $(call pattern_template,WAG2))
79 $(eval $(call pattern_template,WA21))
80 $(eval $(call pattern_template,WA32,-b))
81
82 ifeq ($(IB),)
83 clean:
84 rm -rf $(PKG_BUILD_DIR)
85 rm -f $(BIN_DIR)/openwrt-$(BOARD)*
86
87 prepare: $(PKG_BUILD_DIR) $(PKG_BUILD_DIR)/zimage.script $(PKG_BUILD_DIR)/ld.script
88 compile: prepare $(PKG_BUILD_DIR)/loader.o $(PKG_BUILD_DIR)/LzmaDecode.o $(STAGING_DIR)/bin/srec2bin
89 else
90 clean:
91 prepare:
92 compile:
93 endif
94
95 install: $(BIN_DIR)/openwrt-$(BOARD)-$(KERNEL)-kernel.bin $(BIN_DIR)/openwrt-$(BOARD)-$(KERNEL)-$(FS).bin
96 install-ib:
97 mkdir -p $(IB_DIR)/build_$(ARCH)/linux-$(KERNEL)-$(BOARD)
98 cp -fpR $(KDIR)/vmlinux.bin $(IB_DIR)/build_$(ARCH)/linux-$(KERNEL)-$(BOARD)/
99 mkdir -p $(IB_DIR)/staging_dir_$(ARCH)
100 cp -fpR $(STAGING_DIR)/bin/addpattern $(IB_DIR)/staging_dir_$(ARCH)/bin/
101
This page took 0.041196 seconds and 5 git commands to generate.