kernel: add missing config options
[openwrt/staging/chunkeey.git] / include / image.mk
1 #
2 # Copyright (C) 2006-2010 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 override TARGET_BUILD=
9 include $(INCLUDE_DIR)/prereq.mk
10 include $(INCLUDE_DIR)/kernel.mk
11 include $(INCLUDE_DIR)/host.mk
12 include $(INCLUDE_DIR)/version.mk
13
14 override MAKE:=$(_SINGLE)$(SUBMAKE)
15 override NO_TRACE_MAKE:=$(_SINGLE)$(NO_TRACE_MAKE)
16
17 KDIR=$(KERNEL_BUILD_DIR)
18 KDIR_TMP=$(KDIR)/tmp
19 DTS_DIR:=$(LINUX_DIR)/arch/$(LINUX_KARCH)/boot/dts
20
21 sanitize = $(call tolower,$(subst _,-,$(1)))
22
23 DIST_SANITIZED:=$(call sanitize,$(VERSION_DIST))
24 EXTRA_NAME_SANITIZED=$(call sanitize,$(EXTRA_IMAGE_NAME))
25
26 IMG_PREFIX:=$(DIST_SANITIZED)-$(if $(CONFIG_VERSION_FILENAMES),$(VERSION_NUMBER)-)$(if $(EXTRA_NAME_SANITIZED),$(EXTRA_NAME_SANITIZED)-)$(BOARD)$(if $(SUBTARGET),-$(SUBTARGET))
27
28 MKFS_DEVTABLE_OPT := -D $(INCLUDE_DIR)/device_table.txt
29
30 ifneq ($(CONFIG_BIG_ENDIAN),)
31 JFFS2OPTS := --big-endian --squash-uids -v
32 else
33 JFFS2OPTS := --little-endian --squash-uids -v
34 endif
35
36 ifeq ($(CONFIG_JFFS2_RTIME),y)
37 JFFS2OPTS += -X rtime
38 endif
39 ifeq ($(CONFIG_JFFS2_ZLIB),y)
40 JFFS2OPTS += -X zlib
41 endif
42 ifeq ($(CONFIG_JFFS2_LZMA),y)
43 JFFS2OPTS += -X lzma --compression-mode=size
44 endif
45 ifneq ($(CONFIG_JFFS2_RTIME),y)
46 JFFS2OPTS += -x rtime
47 endif
48 ifneq ($(CONFIG_JFFS2_ZLIB),y)
49 JFFS2OPTS += -x zlib
50 endif
51 ifneq ($(CONFIG_JFFS2_LZMA),y)
52 JFFS2OPTS += -x lzma
53 endif
54
55 JFFS2OPTS += $(MKFS_DEVTABLE_OPT)
56
57 SQUASHFS_BLOCKSIZE := $(CONFIG_TARGET_SQUASHFS_BLOCK_SIZE)k
58 SQUASHFSOPT := -b $(SQUASHFS_BLOCKSIZE)
59 SQUASHFSOPT += -p '/dev d 755 0 0' -p '/dev/console c 600 0 0 5 1'
60 SQUASHFSCOMP := gzip
61 LZMA_XZ_OPTIONS := -Xpreset 9 -Xe -Xlc 0 -Xlp 2 -Xpb 2
62 ifeq ($(CONFIG_SQUASHFS_LZMA),y)
63 SQUASHFSCOMP := lzma $(LZMA_XZ_OPTIONS)
64 endif
65 ifeq ($(CONFIG_SQUASHFS_XZ),y)
66 ifneq ($(filter arm x86 powerpc sparc,$(LINUX_KARCH)),)
67 BCJ_FILTER:=-Xbcj $(LINUX_KARCH)
68 endif
69 SQUASHFSCOMP := xz $(LZMA_XZ_OPTIONS) $(BCJ_FILTER)
70 endif
71
72 JFFS2_BLOCKSIZE ?= 64k 128k
73
74 fs-types-$(CONFIG_TARGET_ROOTFS_SQUASHFS) += squashfs
75 fs-types-$(CONFIG_TARGET_ROOTFS_JFFS2) += $(addprefix jffs2-,$(JFFS2_BLOCKSIZE))
76 fs-types-$(CONFIG_TARGET_ROOTFS_JFFS2_NAND) += $(addprefix jffs2-nand-,$(NAND_BLOCKSIZE))
77 fs-types-$(CONFIG_TARGET_ROOTFS_EXT4FS) += ext4
78 fs-types-$(CONFIG_TARGET_ROOTFS_ISO) += iso
79 fs-subtypes-$(CONFIG_TARGET_ROOTFS_JFFS2) += $(addsuffix -raw,$(addprefix jffs2-,$(JFFS2_BLOCKSIZE)))
80 fs-subtypes-$(CONFIG_TARGET_ROOTFS_CPIOGZ) += cpiogz
81 fs-subtypes-$(CONFIG_TARGET_ROOTFS_TARGZ) += targz
82
83 TARGET_FILESYSTEMS := $(fs-types-y)
84
85 FS_64K := $(filter-out jffs2-%,$(TARGET_FILESYSTEMS)) jffs2-64k
86 FS_128K := $(filter-out jffs2-%,$(TARGET_FILESYSTEMS)) jffs2-128k
87 FS_256K := $(filter-out jffs2-%,$(TARGET_FILESYSTEMS)) jffs2-256k
88
89 define add_jffs2_mark
90 echo -ne '\xde\xad\xc0\xde' >> $(1)
91 endef
92
93 PROFILE_SANITIZED := $(call sanitize,$(PROFILE))
94
95 define split_args
96 $(foreach data, \
97 $(subst |,$(space),\
98 $(subst $(space),^,$(1))), \
99 $(call $(2),$(strip $(subst ^,$(space),$(data)))))
100 endef
101
102 define build_cmd
103 $(if $(Build/$(word 1,$(1))),,$(error Missing Build/$(word 1,$(1))))
104 $(call Build/$(word 1,$(1)),$(wordlist 2,$(words $(1)),$(1)))
105
106 endef
107
108 define concat_cmd
109 $(call split_args,$(1),build_cmd)
110 endef
111
112 # pad to 4k, 8k, 16k, 64k, 128k, 256k and add jffs2 end-of-filesystem mark
113 define prepare_generic_squashfs
114 $(STAGING_DIR_HOST)/bin/padjffs2 $(1) 4 8 16 64 128 256
115 endef
116
117 define Image/BuildKernel/Initramfs
118 $(call Image/Build/Initramfs)
119 endef
120
121 define Image/BuildKernel/MkuImage
122 mkimage -A $(ARCH) -O linux -T kernel -C $(1) -a $(2) -e $(3) \
123 -n '$(call toupper,$(ARCH)) OpenWrt Linux-$(LINUX_VERSION)' -d $(4) $(5)
124 endef
125
126 define Image/BuildKernel/MkFIT
127 $(TOPDIR)/scripts/mkits.sh \
128 -D $(1) -o $(KDIR)/fit-$(1).its -k $(2) $(if $(3),-d $(3)) -C $(4) -a $(5) -e $(6) \
129 -A $(ARCH) -v $(LINUX_VERSION)
130 PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage -f $(KDIR)/fit-$(1).its $(KDIR)/fit-$(1)$(7).itb
131 endef
132
133 # $(1) source dts file
134 # $(2) target dtb file
135 # $(3) extra CPP flags
136 # $(4) extra DTC flags
137 define Image/BuildDTB
138 $(TARGET_CROSS)cpp -nostdinc -x assembler-with-cpp \
139 -I$(DTS_DIR) \
140 -I$(DTS_DIR)/include \
141 -undef -D__DTS__ $(3) \
142 -o $(2).tmp $(1)
143 $(LINUX_DIR)/scripts/dtc/dtc -O dtb \
144 -i$(dir $(1)) $(4) \
145 -o $(2) $(2).tmp
146 $(RM) $(2).tmp
147 endef
148
149 define Image/mkfs/jffs2/sub
150 $(STAGING_DIR_HOST)/bin/mkfs.jffs2 $(3) --pad -e $(patsubst %k,%KiB,$(1)) -o $(KDIR)/root.jffs2-$(2) -d $(TARGET_DIR) -v 2>&1 1>/dev/null | awk '/^.+$$$$/'
151 $(call add_jffs2_mark,$(KDIR)/root.jffs2-$(2))
152 endef
153
154 define Image/mkfs/jffs2/sub-raw
155 $(STAGING_DIR_HOST)/bin/mkfs.jffs2 $(3) -e $(patsubst %k,%KiB,$(1)) -o $(KDIR)/root.jffs2-$(2)-raw -d $(TARGET_DIR) -v 2>&1 1>/dev/null | awk '/^.+$$$$/'
156 endef
157
158 define Image/mkfs/jffs2/template
159 Image/mkfs/jffs2-$(1) = $$(call Image/mkfs/jffs2/sub,$(1),$(1),$(JFFS2OPTS))
160 Image/mkfs/jffs2-$(1)-raw = $$(call Image/mkfs/jffs2/sub-raw,$(1),$(1),$(JFFS2OPTS))
161
162 endef
163
164 define Image/mkfs/jffs2-nand/template
165 Image/mkfs/jffs2-nand-$(1) = \
166 $$(call Image/mkfs/jffs2/sub, \
167 $(word 2,$(subst -, ,$(1))),nand-$(1), \
168 $(JFFS2OPTS) --no-cleanmarkers --pagesize=$(word 1,$(subst -, ,$(1))))
169
170 endef
171
172 $(eval $(foreach S,$(JFFS2_BLOCKSIZE),$(call Image/mkfs/jffs2/template,$(S))))
173 $(eval $(foreach S,$(NAND_BLOCKSIZE),$(call Image/mkfs/jffs2-nand/template,$(S))))
174
175 define Image/mkfs/squashfs
176 $(STAGING_DIR_HOST)/bin/mksquashfs4 $(TARGET_DIR) $(KDIR)/root.squashfs -nopad -noappend -root-owned -comp $(SQUASHFSCOMP) $(SQUASHFSOPT) -processors $(if $(CONFIG_PKG_BUILD_JOBS),$(CONFIG_PKG_BUILD_JOBS),1) $(if $(SOURCE_DATE_EPOCH),-fixed-time $(SOURCE_DATE_EPOCH))
177 endef
178
179 # $(1): board name
180 # $(2): rootfs type
181 # $(3): kernel image
182 ifneq ($(CONFIG_NAND_SUPPORT),)
183 define Image/Build/SysupgradeNAND
184 mkdir -p "$(KDIR_TMP)/sysupgrade-$(1)/"
185 echo "BOARD=$(1)" > "$(KDIR_TMP)/sysupgrade-$(1)/CONTROL"
186 [ -z "$(2)" ] || $(CP) "$(KDIR)/root.$(2)" "$(KDIR_TMP)/sysupgrade-$(1)/root"
187 [ -z "$(3)" ] || $(CP) "$(3)" "$(KDIR_TMP)/sysupgrade-$(1)/kernel"
188 (cd "$(KDIR_TMP)"; $(TAR) cvf \
189 "$(BIN_DIR)/$(IMG_PREFIX)-$(1)-$(2)-sysupgrade.tar" sysupgrade-$(1) \
190 $(if $(SOURCE_DATE_EPOCH),--mtime="@$(SOURCE_DATE_EPOCH)") \
191 )
192 endef
193
194 # $(1) board name
195 # $(2) ubinize-image options (e.g. --uboot-env and/or --kernel kernelimage)
196 # $(3) rootfstype (e.g. squashfs or ubifs)
197 # $(4) options to pass-through to ubinize (i.e. $($(PROFILE)_UBI_OPTS)))
198 define Image/Build/UbinizeImage
199 sh $(TOPDIR)/scripts/ubinize-image.sh $(2) \
200 "$(KDIR)/root.$(3)" \
201 "$(KDIR)/$(IMG_PREFIX)-$(1)-$(3)-ubinized.bin" \
202 $(4)
203 endef
204
205 endif
206
207 ifneq ($(CONFIG_TARGET_ROOTFS_UBIFS),)
208 define Image/mkfs/ubifs/generate
209 $(CP) ./ubinize$(1).cfg $(KDIR)
210 ( cd $(KDIR); \
211 $(STAGING_DIR_HOST)/bin/ubinize \
212 $(if $($(PROFILE)_UBI_OPTS), \
213 $(shell echo $($(PROFILE)_UBI_OPTS)), \
214 $(shell echo $(UBI_OPTS)) \
215 ) \
216 -o $(KDIR)/root$(1).ubi \
217 ubinize$(1).cfg \
218 )
219 endef
220
221 define Image/mkfs/ubifs
222
223 ifneq ($($(PROFILE)_UBIFS_OPTS)$(UBIFS_OPTS),)
224 $(STAGING_DIR_HOST)/bin/mkfs.ubifs \
225 $(if $($(PROFILE)_UBIFS_OPTS), \
226 $(shell echo $($(PROFILE)_UBIFS_OPTS)), \
227 $(shell echo $(UBIFS_OPTS)) \
228 ) \
229 $(if $(CONFIG_TARGET_UBIFS_FREE_SPACE_FIXUP),--space-fixup) \
230 $(if $(CONFIG_TARGET_UBIFS_COMPRESSION_NONE),--force-compr=none) \
231 $(if $(CONFIG_TARGET_UBIFS_COMPRESSION_LZO),--force-compr=lzo) \
232 $(if $(CONFIG_TARGET_UBIFS_COMPRESSION_ZLIB),--force-compr=zlib) \
233 $(if $(shell echo $(CONFIG_TARGET_UBIFS_JOURNAL_SIZE)),--jrn-size=$(CONFIG_TARGET_UBIFS_JOURNAL_SIZE)) \
234 --squash-uids \
235 -o $(KDIR)/root.ubifs \
236 -d $(TARGET_DIR)
237 endif
238 $(call Image/Build,ubifs)
239
240 ifneq ($($(PROFILE)_UBI_OPTS)$(UBI_OPTS),)
241 $(if $(wildcard ./ubinize.cfg),$(call Image/mkfs/ubifs/generate,))
242 $(if $(wildcard ./ubinize-overlay.cfg),$(call Image/mkfs/ubifs/generate,-overlay))
243 endif
244 $(if $(wildcard ./ubinize.cfg),$(call Image/Build,ubi))
245 endef
246 endif
247
248 define Image/mkfs/cpiogz
249 ( cd $(TARGET_DIR); find . | cpio -o -H newc | gzip -9n >$(BIN_DIR)/$(IMG_PREFIX)-rootfs.cpio.gz )
250 endef
251
252 define Image/mkfs/targz
253 $(TAR) -cp --numeric-owner --owner=0 --group=0 --sort=name \
254 $(if $(SOURCE_DATE_EPOCH),--mtime="@$(SOURCE_DATE_EPOCH)") \
255 -C $(TARGET_DIR)/ . | gzip -9n > $(BIN_DIR)/$(IMG_PREFIX)$(if $(PROFILE_SANITIZED),-$(PROFILE_SANITIZED))-rootfs.tar.gz
256 endef
257
258 E2SIZE=$(shell echo $$(($(CONFIG_TARGET_ROOTFS_PARTSIZE)*1024*1024)))
259
260 define Image/mkfs/ext4
261 $(STAGING_DIR_HOST)/bin/make_ext4fs \
262 -l $(E2SIZE) -b $(CONFIG_TARGET_EXT4_BLOCKSIZE) \
263 -i $(CONFIG_TARGET_EXT4_MAXINODE) \
264 -m $(CONFIG_TARGET_EXT4_RESERVED_PCT) \
265 $(if $(CONFIG_TARGET_EXT4_JOURNAL),,-J) \
266 $(if $(SOURCE_DATE_EPOCH),-T $(SOURCE_DATE_EPOCH)) \
267 $(KDIR)/root.ext4 $(TARGET_DIR)/
268 endef
269
270 define Image/mkfs/prepare/default
271 # Use symbolic permissions to avoid clobbering SUID/SGID/sticky bits
272 - $(FIND) $(TARGET_DIR) -type f -not -perm /0100 -not -name 'ssh_host*' -not -name 'shadow' -print0 | $(XARGS) -0 chmod u+rw,g+r,o+r
273 - $(FIND) $(TARGET_DIR) -type f -perm /0100 -print0 | $(XARGS) -0 chmod u+rwx,g+rx,o+rx
274 - $(FIND) $(TARGET_DIR) -type d -print0 | $(XARGS) -0 chmod u+rwx,g+rx,o+rx
275 $(INSTALL_DIR) $(TARGET_DIR)/tmp $(TARGET_DIR)/overlay
276 chmod 1777 $(TARGET_DIR)/tmp
277 endef
278
279 define Image/mkfs/prepare
280 $(call Image/mkfs/prepare/default)
281 endef
282
283
284 define Image/Checksum
285 ( cd ${BIN_DIR} ; \
286 $(FIND) -maxdepth 1 -type f \! -name 'md5sums' -printf "%P\n" | sort | xargs $1 > $2 \
287 )
288 endef
289
290 define BuildImage/mkfs
291 install: mkfs-$(1)
292 .PHONY: mkfs-$(1)
293 mkfs-$(1): kernel_prepare
294 $(Image/mkfs/$(1))
295 $(call Build/mkfs/default,$(1))
296 $(call Build/mkfs/$(1),$(1))
297 $(KDIR)/root.$(1): mkfs-$(1)
298
299 endef
300
301 # Build commands that can be called from Device/* templates
302 define Build/uImage
303 mkimage -A $(LINUX_KARCH) \
304 -O linux -T kernel \
305 -C $(1) -a $(KERNEL_LOADADDR) -e $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
306 -n '$(call toupper,$(LINUX_KARCH)) OpenWrt Linux-$(LINUX_VERSION)' -d $@ $@.new
307 @mv $@.new $@
308 endef
309
310 define Build/netgear-chk
311 $(STAGING_DIR_HOST)/bin/mkchkimg \
312 -o $@.new \
313 -k $@ \
314 -b $(NETGEAR_BOARD_ID) \
315 -r $(NETGEAR_REGION)
316 mv $@.new $@
317 endef
318
319 define Build/netgear-dni
320 $(STAGING_DIR_HOST)/bin/mkdniimg \
321 -B $(NETGEAR_BOARD_ID) -v OpenWrt.$(REVISION) \
322 $(if $(NETGEAR_HW_ID),-H $(NETGEAR_HW_ID)) \
323 -r "$(1)" \
324 -i $@ -o $@.new
325 mv $@.new $@
326 endef
327
328 define Build/fit
329 $(TOPDIR)/scripts/mkits.sh \
330 -D $(DEVICE_NAME) -o $@.its -k $@ \
331 $(if $(word 2,$(1)),-d $(word 2,$(1))) -C $(word 1,$(1)) \
332 -a $(KERNEL_LOADADDR) -e $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
333 -A $(ARCH) -v $(LINUX_VERSION)
334 PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage -f $@.its $@.new
335 @mv $@.new $@
336 endef
337
338 define Build/lzma
339 $(STAGING_DIR_HOST)/bin/lzma e $@ -lc1 -lp2 -pb2 $(1) $@.new
340 @mv $@.new $@
341 endef
342
343 define Build/gzip
344 gzip -9n -c $@ $(1) > $@.new
345 @mv $@.new $@
346 endef
347
348 define Build/jffs2
349 rm -rf $(KDIR_TMP)/$(DEVICE_NAME)/jffs2 && \
350 mkdir -p $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/$$(dirname $(1)) && \
351 cp $@ $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/$(1) && \
352 $(STAGING_DIR_HOST)/bin/mkfs.jffs2 --pad \
353 $(if $(CONFIG_BIG_ENDIAN),--big-endian,--little-endian) \
354 --squash-uids -v -e $(patsubst %k,%KiB,$(BLOCKSIZE)) \
355 -o $@.new \
356 -d $(KDIR_TMP)/$(DEVICE_NAME)/jffs2 \
357 2>&1 1>/dev/null | awk '/^.+$$$$/' && \
358 $(STAGING_DIR_HOST)/bin/padjffs2 $@.new -J $(patsubst %k,,$(BLOCKSIZE))
359 -rm -rf $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/
360 @mv $@.new $@
361 endef
362
363 define Build/kernel-bin
364 rm -f $@
365 cp $< $@
366 endef
367
368 define Build/patch-cmdline
369 $(STAGING_DIR_HOST)/bin/patch-cmdline $@ '$(CMDLINE)'
370 endef
371
372 define Build/append-kernel
373 dd if=$(word 1,$^) $(if $(1),bs=$(1) conv=sync) >> $@
374 endef
375
376 define Build/append-rootfs
377 dd if=$(word 2,$^) $(if $(1),bs=$(1) conv=sync) >> $@
378 endef
379
380 define Build/append-ubi
381 sh $(TOPDIR)/scripts/ubinize-image.sh \
382 $(if $(KERNEL_IN_UBI),--kernel $(word 1,$^)) \
383 $(word 2,$^) \
384 $@.tmp \
385 -p $(BLOCKSIZE) -m $(PAGESIZE) -E 5 \
386 $(if $(SUBPAGESIZE),-s $(SUBPAGESIZE))
387 cat $@.tmp >> $@
388 rm $@.tmp
389 endef
390
391 define Build/pad-to
392 dd if=$@ of=$@.new bs=$(1) conv=sync
393 mv $@.new $@
394 endef
395
396 define Build/pad-rootfs
397 $(call prepare_generic_squashfs,$@ $(1))
398 endef
399
400 define Build/pad-offset
401 let \
402 size="$$(stat -c%s $@)" \
403 pad="$(word 1, $(1))" \
404 offset="$(word 2, $(1))" \
405 pad="(pad - ((size + offset) % pad)) % pad" \
406 newsize='size + pad'; \
407 dd if=$@ of=$@.new bs=$$newsize count=1 conv=sync
408 mv $@.new $@
409 endef
410
411 define Build/check-size
412 @[ $$(($(subst k,* 1024,$(subst m, * 1024k,$(1))))) -ge "$$(stat -c%s $@)" ] || { \
413 echo "WARNING: Image file $@ is too big" >&2; \
414 rm -f $@; \
415 }
416 endef
417
418 define Build/combined-image
419 -sh $(TOPDIR)/scripts/combined-image.sh \
420 "$(word 1,$^)" \
421 "$@" \
422 "$@.new"
423 @mv $@.new $@
424 endef
425
426 define Build/sysupgrade-nand
427 sh $(TOPDIR)/scripts/sysupgrade-nand.sh \
428 --board $(if $(BOARD_NAME),$(BOARD_NAME),$(DEVICE_NAME)) \
429 --kernel $(word 1,$^) \
430 --rootfs $(word 2,$^) \
431 $@
432 endef
433
434 define Device/Init
435 PROFILES := $(PROFILE)
436 DEVICE_NAME := $(1)
437 KERNEL:=
438 KERNEL_INITRAMFS = $$(KERNEL)
439 KERNEL_SIZE:=
440 CMDLINE:=
441
442 IMAGE_PREFIX := $(IMG_PREFIX)-$(1)
443 IMAGE_NAME = $$(IMAGE_PREFIX)-$$(1)-$$(2)
444 KERNEL_PREFIX = $(1)
445 KERNEL_SUFFIX := -kernel.bin
446 KERNEL_IMAGE = $$(KERNEL_PREFIX)$$(KERNEL_SUFFIX)
447 KERNEL_INITRAMFS_PREFIX = $$(IMAGE_PREFIX)-initramfs
448 KERNEL_INITRAMFS_IMAGE = $$(KERNEL_INITRAMFS_PREFIX)$$(KERNEL_SUFFIX)
449 KERNEL_INITRAMFS_NAME = $$(KERNEL_NAME)-initramfs
450 KERNEL_INSTALL :=
451 KERNEL_NAME := vmlinux
452 KERNEL_DEPENDS :=
453 KERNEL_SIZE :=
454
455 FILESYSTEMS := $(TARGET_FILESYSTEMS)
456 endef
457
458 define Device/ExportVar
459 $(1) : $(2):=$$($(2))
460
461 endef
462 define Device/Export
463 $(foreach var,$(DEVICE_VARS) DEVICE_NAME KERNEL KERNEL_INITRAMFS KERNEL_INITRAMFS_IMAGE,$(call Device/ExportVar,$(1),$(var)))
464 $(1) : FILESYSTEM:=$(2)
465 endef
466
467 define Device/Check
468 _TARGET = $$(if $$(filter $(PROFILE),$$(PROFILES)),install,install-disabled)
469 _COMPILE_TARGET = $$(if $(if $(IB),,$(CONFIG_IB)$$(filter $(PROFILE),$$(PROFILES))),compile,compile-disabled)
470 endef
471
472 ifndef IB
473 define Device/Build/initramfs
474 $(call Device/Export,$(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE),$(1))
475 $$(_TARGET): $(BIN_DIR)/$$(KERNEL_INITRAMFS_IMAGE)
476
477 $(KDIR)/$$(KERNEL_INITRAMFS_NAME):: image_prepare
478 $(BIN_DIR)/$$(KERNEL_INITRAMFS_IMAGE): $(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE)
479 cp $$^ $$@
480
481 $(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE): $(KDIR)/$$(KERNEL_INITRAMFS_NAME) $(CURDIR)/Makefile $$(KERNEL_DEPENDS)
482 @rm -f $$@
483 $$(call concat_cmd,$$(KERNEL_INITRAMFS))
484 endef
485 endif
486
487 define Device/Build/check_size
488 @[ $$(($(subst k,* 1024,$(subst m, * 1024k,$(1))))) -ge "$$(stat -c%s $@)" ] || { \
489 echo "WARNING: Image file $@ is too big" >&2; \
490 rm -f $@; \
491 }
492 endef
493
494 define Device/Build/compile
495 $$(_COMPILE_TARGET): $(KDIR)/$(1)
496 $(eval $(call Device/Export,$(KDIR)/$(1)))
497 $(KDIR)/$(1):
498 $$(call concat_cmd,$(COMPILE/$(1)))
499
500 endef
501
502 define Device/Build/kernel
503 _KERNEL_IMAGES += $(KDIR)/$$(KERNEL_NAME)
504 $(KDIR)/$$(KERNEL_NAME):: image_prepare
505 $$(_TARGET): $$(if $$(KERNEL_INSTALL),$(BIN_DIR)/$$(KERNEL_IMAGE))
506 $(call Device/Export,$(KDIR)/$$(KERNEL_IMAGE),$(1))
507 $(BIN_DIR)/$$(KERNEL_IMAGE): $(KDIR)/$$(KERNEL_IMAGE)
508 cp $$^ $$@
509 ifndef IB
510 ifdef CONFIG_IB
511 install: $(KDIR)/$$(KERNEL_IMAGE)
512 endif
513 $(KDIR)/$$(KERNEL_IMAGE): $(KDIR)/$$(KERNEL_NAME) $(CURDIR)/Makefile $$(KERNEL_DEPENDS)
514 @rm -f $$@
515 $$(call concat_cmd,$$(KERNEL))
516 $$(if $$(KERNEL_SIZE),$$(call Device/Build/check_size,$$(KERNEL_SIZE)))
517 endif
518 endef
519
520 define Device/Build/image
521 $$(_TARGET): $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2))
522 $(eval $(call Device/Export,$(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2)),$(1)))
523 $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2)): $(KDIR)/$$(KERNEL_IMAGE) $(KDIR)/root.$(1)
524 @rm -f $$@
525 [ -f $$(word 1,$$^) -a -f $$(word 2,$$^) ]
526 $$(call concat_cmd,$(if $(IMAGE/$(2)/$(1)),$(IMAGE/$(2)/$(1)),$(IMAGE/$(2))))
527
528 .IGNORE: $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2))
529 $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2)): $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2))
530 cp $$^ $$@
531
532 endef
533
534 define Device/Build
535 $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),$(call Device/Build/initramfs,$(1)))
536 $(call Device/Build/kernel,$(1))
537
538 $$(eval $$(foreach compile,$$(COMPILE), \
539 $$(call Device/Build/compile,$$(compile),$(1))))
540
541 $$(eval $$(foreach image,$$(IMAGES), \
542 $$(foreach fs,$$(filter $(TARGET_FILESYSTEMS),$$(FILESYSTEMS)), \
543 $$(call Device/Build/image,$$(fs),$$(image),$(1)))))
544 endef
545
546 define Device
547 $(call Device/Init,$(1))
548 $(call Device/Default,$(1))
549 $(call Device/Check,$(1))
550 $(call Device/$(1),$(1))
551 $(call Device/Build,$(1))
552
553 endef
554
555 define BuildImage
556
557 download:
558 prepare:
559 compile:
560 clean:
561 image_prepare:
562
563 ifeq ($(IB),)
564 .PHONY: download prepare compile clean image_prepare mkfs_prepare kernel_prepare install
565 compile:
566 $(call Build/Compile)
567
568 clean:
569 $(call Build/Clean)
570
571 image_prepare: compile
572 mkdir -p $(KDIR)/tmp
573 $(call Image/Prepare)
574 else
575 image_prepare:
576 mkdir -p $(KDIR)/tmp
577 endif
578
579 mkfs_prepare: image_prepare
580 $(call Image/mkfs/prepare)
581
582 kernel_prepare: mkfs_prepare
583 $(call Image/BuildKernel)
584 $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),$(if $(IB),,$(call Image/BuildKernel/Initramfs)))
585 $(call Image/InstallKernel)
586
587 $(foreach device,$(TARGET_DEVICES),$(call Device,$(device)))
588 $(foreach fs,$(TARGET_FILESYSTEMS) $(fs-subtypes-y),$(call BuildImage/mkfs,$(fs)))
589
590 install: kernel_prepare
591 $(foreach fs,$(TARGET_FILESYSTEMS),
592 $(call Image/Build,$(fs))
593 )
594 $(call Image/mkfs/ubifs)
595 $(call Image/Checksum,md5sum --binary,md5sums)
596 $(call Image/Checksum,openssl dgst -sha256,sha256sums)
597
598 endef