[orion] generic: enhanced image Makefile
[openwrt/svn-archive/archive.git] / target / linux / orion / image / generic.mk
1 #
2 # Copyright (C) 2008-2012 OpenWrt.org
3 #
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
6 #
7
8 ### DO NOT INDENT LINES CONTAINING $(call xyz) AS THIS MAY CHANGE THE CONTEXT
9 ### OF THE FIRST LINE IN THE CALLED VARIABLE (NOTE: variable!)
10 ### see http://www.gnu.org/software/make/manual/html_node/Call-Function.html#Call-Function
11 ### ACTUALLY IT IS A SIMPLE MACRO EXPANSION
12
13 ### use round brackets for make variables, and curly brackets for shell variables
14
15
16 ## Kernel mtd partition size in KiB
17 KERNEL_MTD_SIZE:=1024
18
19 # Netgear WNR854T: erase size is 128KiB = 0x00020000 = 131072
20 ERASE_SIZE_WNR854T:=128
21 UIMAGE_FILE_NAME_WNR854T:=uImage
22
23 # Linksys WRT350N v2: erase size is 64KiB = 0x00010000 = 65536
24 ERASE_SIZE_WRT350Nv2:=64
25
26 # define JFFS2 sizes for include/image.mk
27 JFFS2_BLOCKSIZE:=64k 128k
28
29
30 ###
31 ### Image/Prepare
32 ###
33
34 define Image/Prepare
35 ### Dummy comment for indented calls of Image/Prepare
36 cp '$(LINUX_DIR)/arch/arm/boot/zImage' '$(BIN_DIR)/$(IMG_PREFIX)-zImage'
37 endef
38
39
40 ###
41 ### Image/BuildKernel
42 ###
43
44 define Image/BuildKernel
45 ### Dummy comment for indented calls of Image/BuildKernel
46
47 ## Netgear WNR854T: mach id 1801 (0x0709)
48 $(call Image/BuildKernel/ARM/zImage,wnr854t,"\x07\x1c\xa0\xe3\x09\x10\x81\xe3")
49 $(call Image/BuildKernel/ARM/uImage,wnr854t)
50 ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y) # nothing more to do for a ramdisk build
51 $(call Image/BuildKernel/JFFS2uImage,wnr854t,$(ERASE_SIZE_WNR854T),$(UIMAGE_FILE_NAME_WNR854T))
52 $(call Image/Default/FileSizeCheck,$(KDIR)/wnr854t-uImage.jffs2,$(shell expr $(KERNEL_MTD_SIZE) \* 1024))
53 endif
54
55 ## Linksys WRT350N v2: mach id 1633 (0x0661)
56 $(call Image/BuildKernel/ARM/zImage,wrt350nv2,"\x06\x1c\xa0\xe3\x61\x10\x81\xe3")
57 $(call Image/BuildKernel/ARM/uImage,wrt350nv2)
58 ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y) # nothing more to do for a ramdisk build
59 $(call Image/Default/FileSizeCheck,$(KDIR)/wrt350nv2-uImage,$(shell expr $(KERNEL_MTD_SIZE) \* 1024))
60 endif
61 endef
62
63 define Image/BuildKernel/ARM/zImage
64 # merge machine id and regular zImage into one file
65 # parameters: 1 = machine name, 2 = machine id as string in quotes
66 # $(BOARD) kernel zImage for $(1)
67 echo -en $(2) > '$(KDIR)/$(1)-zImage'
68 cat '$(LINUX_DIR)/arch/arm/boot/zImage' >> '$(KDIR)/$(1)-zImage'
69 cp '$(KDIR)/$(1)-zImage' '$(BIN_DIR)/openwrt-$(1)-zImage'
70 endef
71
72 define Image/BuildKernel/ARM/uImage
73 # create uImage from zImage
74 # parameters: 1 = machine name
75 # $(BOARD) kernel uImage for $(1)
76 '$(STAGING_DIR_HOST)/bin/mkimage' -A arm -O linux -T kernel \
77 -C none -a 0x00008000 -e 0x00008000 -n 'Linux-$(LINUX_VERSION)' \
78 -d '$(KDIR)/$(1)-zImage' '$(KDIR)/$(1)-uImage'
79 cp '$(KDIR)/$(1)-uImage' '$(BIN_DIR)/openwrt-$(1)-uImage'
80 endef
81
82 define Image/BuildKernel/JFFS2uImage
83 # create JFFS2 partition with uImage file (result is already padded to erase size)
84 # parameters: 1 = machine name, 2 = erase size in KiB, 3 = uImage file name
85 # $(BOARD) kernel uImage for $(1) in JFFS2-$(2)k partition
86 rm -rf '$(TMP_DIR)/$(1)_jffs2_uimage'
87 mkdir '$(TMP_DIR)/$(1)_jffs2_uimage'
88 cp '$(KDIR)/$(1)-uImage' '$(TMP_DIR)/$(1)_jffs2_uimage/$(3)'
89 $(STAGING_DIR_HOST)/bin/mkfs.jffs2 --compression-mode=none --pad --little-endian --squash -e $(2)KiB -o '$(KDIR)/$(1)-uImage.jffs2' -d '$(TMP_DIR)/$(1)_jffs2_uimage'
90 rm -rf '$(TMP_DIR)/$(1)_jffs2_uimage'
91 endef
92
93 define Image/Default/FileSizeCheck
94 # parameters: 1 = file path, 2 = maximum size in bytes
95 [ `stat -c %s '$(1)'` -le $(2) ] || { echo ' ERROR: $(1) too big (> $(2) bytes)'; exit 1; }
96 endef
97
98
99 ###
100 ### Image/Build
101 ###
102
103 define Image/Build
104 ### Dummy comment for indented calls of Image/Build with $(1)
105
106 ## Prepare rootfs
107 $(call Image/Build/$(1),$(1))
108
109 ## Netgear WNR854T
110 $(call Image/Build/Default,$(1),wnr854t,$(ERASE_SIZE_WNR854T),$(KERNEL_MTD_SIZE),.jffs2,NG_WNR854T)
111
112 ## Linksys WRT350N v2
113 $(call Image/Build/Linksys/wrt350nv2,$(1),wrt350nv2,$(ERASE_SIZE_WRT350Nv2),$(KERNEL_MTD_SIZE),)
114 endef
115
116 define Image/Build/squashfs
117 $(call prepare_generic_squashfs,$(KDIR)/root.squashfs)
118 cp '$(KDIR)/root.squashfs' '$(BIN_DIR)/$(IMG_PREFIX)-root.squashfs'
119 endef
120
121 ## generate defines for all JFFS2 block sizes
122 define Image/Build/jffs2/sub
123 $(eval define Image/Build/jffs2-$(1)
124 cp '$$(KDIR)/root.jffs2-$(1)' '$$(BIN_DIR)/$$(IMG_PREFIX)-root.jffs2-$(1)'
125 endef)
126 endef
127
128 $(foreach SZ,$(JFFS2_BLOCKSIZE),$(call Image/Build/jffs2/sub,$(SZ)))
129
130 define Image/Build/Default
131 # parameters: 1 = rootfs type, 2 = machine name, 3 = erase size in KiB, 4 = kernel mtd size in KiB, 5 = kernel file suffix, 6 = header
132 ifeq ($(findstring jffs2-,$(1)),jffs2-) # JFFS2: build only image fitting to erase size
133 ifeq ($(1),jffs2-$(3)k)
134 $(call Image/Build/Default/sysupgrade,$(1),$(2),$(4),$(5))
135 $(call Image/Build/Default/factory,$(1),$(2),$(6))
136 endif
137 else
138 ifeq ($(1),ext4) # EXT4: ignore
139 # do nothing
140 else # do all other images
141 $(call Image/Build/Default/sysupgrade,$(1),$(2),$(4),$(5))
142 $(call Image/Build/Default/factory,$(1),$(2),$(6))
143 endif
144 endif
145 endef
146
147 define Image/Build/Default/sysupgrade
148 # parameters: 1 = rootfs type, 2 = machine name, 3 = pad size in KiB (kernel mtd size or erase size), 4 = kernel file suffix
149 # $(BOARD) $(1) sysupgrade image for $(2)
150 ( \
151 dd if='$(KDIR)/$(2)-uImage$(4)' bs=$(3)k conv=sync; \
152 dd if='$(KDIR)/root.$(1)'; \
153 ) > '$(BIN_DIR)/openwrt-$(2)-$(1)-sysupgrade.img'
154 endef
155
156 define Image/Build/Default/factory
157 # parameters: 1 = rootfs type, 2 = machine name, 3 = header
158 # $(BOARD) $(1) factory upgrade image for $(2)
159 '$(STAGING_DIR_HOST)/bin/add_header' $(3) '$(BIN_DIR)/openwrt-$(2)-$(1)-sysupgrade.img' '$(BIN_DIR)/openwrt-$(2)-$(1)-factory.img'
160 endef
161
162 ##
163 ## Image/Build/Linksys
164 ##
165
166 define Image/Build/Linksys/wrt350nv2
167 # parameters: 1 = rootfs type, 2 = machine name, 3 = erase size in KiB, 4 = kernel mtd size in KiB, 5 = kernel file suffix
168 ifeq ($(findstring jffs2-,$(1)),jffs2-) # JFFS2: build only image fitting to erase size
169 ifeq ($(1),jffs2-$(3)k)
170 $(call Image/Build/Default/sysupgrade,$(1),$(2),$(4),$(5))
171 $(call Image/Build/Linksys/wrt350nv2-builder,$(1),$(2))
172 endif
173 else
174 ifeq ($(1),ext4) # EXT4: ignore
175 # do nothing
176 else # do all other images
177 $(call Image/Build/Default/sysupgrade,$(1),$(2),$(4),$(5))
178 $(call Image/Build/Linksys/wrt350nv2-builder,$(1),$(2))
179 endif
180 endif
181 endef
182
183 define Image/Build/Linksys/wrt350nv2-builder
184 # parameters: 1 = rootfs type, 2 = machine name
185 # $(BOARD) $(1) factory and recovery image for $(2) via wrt350nv2-builder
186 rm -rf '$(TMP_DIR)/$(2)_factory'
187 mkdir '$(TMP_DIR)/$(2)_factory'
188 # create parameter file
189 echo ':image 0 $(BIN_DIR)/openwrt-$(2)-$(1)-sysupgrade.img' > '$(TMP_DIR)/$(2)_factory/$(2).par'
190 [ ! -f '$(STAGING_DIR_HOST)/share/wrt350nv2-builder/u-boot.bin' ] || ( \
191 echo ':u-boot 0 $(STAGING_DIR_HOST)/share/wrt350nv2-builder/u-boot.bin' >> '$(TMP_DIR)/$(2)_factory/$(2).par'; \
192 )
193 echo '#version 0x2020' >> '$(TMP_DIR)/$(2)_factory/$(2).par'
194 # create bin file for recovery and factory image
195 ( \
196 cd '$(TMP_DIR)/$(2)_factory'; \
197 '$(STAGING_DIR_HOST)/bin/wrt350nv2-builder' -b '$(TMP_DIR)/$(2)_factory/$(2).par'; \
198 )
199 # copy bin file as recovery image
200 $(CP) '$(TMP_DIR)/$(2)_factory/wrt350n.bin' '$(BIN_DIR)/openwrt-$(2)-$(1)-recovery.bin'
201 # create factory image for stock firmware update mechanism
202 ( \
203 cd '$(TMP_DIR)/$(2)_factory'; \
204 zip 'wrt350n.zip' 'wrt350n.bin'; \
205 )
206 '$(STAGING_DIR_HOST)/bin/wrt350nv2-builder' -z '$(TMP_DIR)/$(2)_factory/wrt350n.zip' '$(BIN_DIR)/openwrt-$(2)-$(1)-factory.img'
207 rm -rf '$(TMP_DIR)/$(2)_factory'
208 endef
209
210
211 ###
212 ### Image/PreReq
213 ###
214
215 ## Dependency for WRT350N v2 factory image
216 $(eval $(call RequireCommand,zip, \
217 Please install zip. \
218 ))