build: remove sgid permission from tar
[openwrt/openwrt.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)/version.mk
12 include $(INCLUDE_DIR)/image-commands.mk
13
14 ifndef IB
15 ifdef CONFIG_TARGET_PER_DEVICE_ROOTFS
16 TARGET_PER_DEVICE_ROOTFS := 1
17 endif
18 endif
19
20 include $(INCLUDE_DIR)/image-legacy.mk
21 include $(INCLUDE_DIR)/feeds.mk
22 include $(INCLUDE_DIR)/rootfs.mk
23
24 override MAKE:=$(_SINGLE)$(SUBMAKE)
25 override NO_TRACE_MAKE:=$(_SINGLE)$(NO_TRACE_MAKE)
26
27 target_params = $(subst +,$(space),$*)
28 param_get = $(patsubst $(1)=%,%,$(filter $(1)=%,$(2)))
29 param_get_default = $(firstword $(call param_get,$(1),$(2)) $(3))
30 param_mangle = $(subst $(space),_,$(strip $(1)))
31 param_unmangle = $(subst _,$(space),$(1))
32
33 mkfs_packages_id = $(shell echo $(sort $(1)) | mkhash md5 | head -c 8)
34 mkfs_target_dir = $(if $(call param_get,pkg,$(1)),$(KDIR)/target-dir-$(call param_get,pkg,$(1)),$(TARGET_DIR))
35
36 KDIR=$(KERNEL_BUILD_DIR)
37 KDIR_TMP=$(KDIR)/tmp
38 DTS_DIR:=$(LINUX_DIR)/arch/$(LINUX_KARCH)/boot/dts
39
40 IMG_PREFIX_EXTRA:=$(if $(EXTRA_IMAGE_NAME),$(call sanitize,$(EXTRA_IMAGE_NAME))-)
41 IMG_PREFIX_VERNUM:=$(if $(CONFIG_VERSION_FILENAMES),$(call sanitize,$(VERSION_NUMBER))-)
42 IMG_PREFIX_VERCODE:=$(if $(CONFIG_VERSION_CODE_FILENAMES),$(call sanitize,$(VERSION_CODE))-)
43
44 IMG_PREFIX:=$(VERSION_DIST_SANITIZED)-$(IMG_PREFIX_VERNUM)$(IMG_PREFIX_VERCODE)$(IMG_PREFIX_EXTRA)$(BOARD)$(if $(SUBTARGET),-$(SUBTARGET))
45
46 MKFS_DEVTABLE_OPT := -D $(INCLUDE_DIR)/device_table.txt
47
48 ifneq ($(CONFIG_BIG_ENDIAN),)
49 JFFS2OPTS := --big-endian --squash-uids -v
50 else
51 JFFS2OPTS := --little-endian --squash-uids -v
52 endif
53
54 ifeq ($(CONFIG_JFFS2_RTIME),y)
55 JFFS2OPTS += -X rtime
56 endif
57 ifeq ($(CONFIG_JFFS2_ZLIB),y)
58 JFFS2OPTS += -X zlib
59 endif
60 ifeq ($(CONFIG_JFFS2_LZMA),y)
61 JFFS2OPTS += -X lzma --compression-mode=size
62 endif
63 ifneq ($(CONFIG_JFFS2_RTIME),y)
64 JFFS2OPTS += -x rtime
65 endif
66 ifneq ($(CONFIG_JFFS2_ZLIB),y)
67 JFFS2OPTS += -x zlib
68 endif
69 ifneq ($(CONFIG_JFFS2_LZMA),y)
70 JFFS2OPTS += -x lzma
71 endif
72
73 JFFS2OPTS += $(MKFS_DEVTABLE_OPT)
74
75 SQUASHFS_BLOCKSIZE := $(CONFIG_TARGET_SQUASHFS_BLOCK_SIZE)k
76 SQUASHFSOPT := -b $(SQUASHFS_BLOCKSIZE)
77 SQUASHFSOPT += -p '/dev d 755 0 0' -p '/dev/console c 600 0 0 5 1'
78 SQUASHFSCOMP := gzip
79 LZMA_XZ_OPTIONS := -Xpreset 9 -Xe -Xlc 0 -Xlp 2 -Xpb 2
80 ifeq ($(CONFIG_SQUASHFS_XZ),y)
81 ifneq ($(filter arm x86 powerpc sparc,$(LINUX_KARCH)),)
82 BCJ_FILTER:=-Xbcj $(LINUX_KARCH)
83 endif
84 SQUASHFSCOMP := xz $(LZMA_XZ_OPTIONS) $(BCJ_FILTER)
85 endif
86
87 JFFS2_BLOCKSIZE ?= 64k 128k
88
89 fs-types-$(CONFIG_TARGET_ROOTFS_SQUASHFS) += squashfs
90 fs-types-$(CONFIG_TARGET_ROOTFS_JFFS2) += $(addprefix jffs2-,$(JFFS2_BLOCKSIZE))
91 fs-types-$(CONFIG_TARGET_ROOTFS_JFFS2_NAND) += $(addprefix jffs2-nand-,$(NAND_BLOCKSIZE))
92 fs-types-$(CONFIG_TARGET_ROOTFS_EXT4FS) += ext4
93 fs-types-$(CONFIG_TARGET_ROOTFS_ISO) += iso
94 fs-types-$(CONFIG_TARGET_ROOTFS_UBIFS) += ubifs
95 fs-subtypes-$(CONFIG_TARGET_ROOTFS_JFFS2) += $(addsuffix -raw,$(addprefix jffs2-,$(JFFS2_BLOCKSIZE)))
96
97 TARGET_FILESYSTEMS := $(fs-types-y)
98
99 FS_64K := $(filter-out jffs2-%,$(TARGET_FILESYSTEMS)) jffs2-64k
100 FS_128K := $(filter-out jffs2-%,$(TARGET_FILESYSTEMS)) jffs2-128k
101 FS_256K := $(filter-out jffs2-%,$(TARGET_FILESYSTEMS)) jffs2-256k
102
103 define add_jffs2_mark
104 echo -ne '\xde\xad\xc0\xde' >> $(1)
105 endef
106
107 PROFILE_SANITIZED := $(call sanitize,$(PROFILE))
108
109 define split_args
110 $(foreach data, \
111 $(subst |,$(space),\
112 $(subst $(space),^,$(1))), \
113 $(call $(2),$(strip $(subst ^,$(space),$(data)))))
114 endef
115
116 define build_cmd
117 $(if $(Build/$(word 1,$(1))),,$(error Missing Build/$(word 1,$(1))))
118 $(call Build/$(word 1,$(1)),$(wordlist 2,$(words $(1)),$(1)))
119
120 endef
121
122 define concat_cmd
123 $(call split_args,$(1),build_cmd)
124 endef
125
126 # pad to 4k, 8k, 16k, 64k, 128k, 256k and add jffs2 end-of-filesystem mark
127 define prepare_generic_squashfs
128 $(STAGING_DIR_HOST)/bin/padjffs2 $(1) 4 8 16 64 128 256
129 endef
130
131 define Image/BuildKernel/Initramfs
132 $(call Image/Build/Initramfs)
133 endef
134
135 define Image/BuildKernel/MkuImage
136 mkimage -A $(ARCH) -O linux -T kernel -C $(1) -a $(2) -e $(3) \
137 -n '$(call toupper,$(ARCH)) $(VERSION_DIST) Linux-$(LINUX_VERSION)' -d $(4) $(5)
138 endef
139
140 define Image/BuildKernel/MkFIT
141 $(TOPDIR)/scripts/mkits.sh \
142 -D $(1) -o $(KDIR)/fit-$(1).its -k $(2) $(if $(3),-d $(3)) -C $(4) -a $(5) -e $(6) \
143 -c $(if $(DEVICE_DTS_CONFIG),$(DEVICE_DTS_CONFIG),"config@1") \
144 -A $(LINUX_KARCH) -v $(LINUX_VERSION)
145 PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage -f $(KDIR)/fit-$(1).its $(KDIR)/fit-$(1)$(7).itb
146 endef
147
148 ifdef CONFIG_TARGET_IMAGES_GZIP
149 define Image/Gzip
150 rm -f $(1).gz
151 gzip -9n $(1)
152 endef
153 endif
154
155
156 # Disable noisy checks by default as in upstream
157 ifeq ($(strip $(call kernel_patchver_ge,4.7.0)),1)
158 DTC_FLAGS += -Wno-unit_address_vs_reg
159 endif
160 ifeq ($(strip $(call kernel_patchver_ge,4.12.0)),1)
161 DTC_FLAGS += \
162 -Wno-unit_address_vs_reg \
163 -Wno-simple_bus_reg \
164 -Wno-unit_address_format \
165 -Wno-pci_bridge \
166 -Wno-pci_device_bus_num \
167 -Wno-pci_device_reg
168 endif
169 ifeq ($(strip $(call kernel_patchver_ge,4.17.0)),1)
170 DTC_FLAGS += \
171 -Wno-avoid_unnecessary_addr_size \
172 -Wno-alias_paths
173 endif
174 ifeq ($(strip $(call kernel_patchver_ge,4.18.0)),1)
175 DTC_FLAGS += \
176 -Wno-graph_child_address \
177 -Wno-graph_port \
178 -Wno-unique_unit_address
179 endif
180
181 # $(1) source dts file
182 # $(2) target dtb file
183 # $(3) extra CPP flags
184 # $(4) extra DTC flags
185 define Image/BuildDTB
186 $(TARGET_CROSS)cpp -nostdinc -x assembler-with-cpp \
187 -I$(DTS_DIR) \
188 -I$(DTS_DIR)/include \
189 -I$(LINUX_DIR)/include/ \
190 -undef -D__DTS__ $(3) \
191 -o $(2).tmp $(1)
192 $(LINUX_DIR)/scripts/dtc/dtc -O dtb \
193 -i$(dir $(1)) $(DTC_FLAGS) $(4) \
194 -o $(2) $(2).tmp
195 $(RM) $(2).tmp
196 endef
197
198 define Image/mkfs/jffs2/sub-raw
199 $(STAGING_DIR_HOST)/bin/mkfs.jffs2 \
200 $(2) \
201 -e $(patsubst %k,%KiB,$(1)) \
202 -o $@ -d $(call mkfs_target_dir,$(3)) \
203 -v 2>&1 1>/dev/null | awk '/^.+$$$$/'
204 endef
205
206 define Image/mkfs/jffs2/sub
207 $(call Image/mkfs/jffs2/sub-raw,$(1),--pad $(2),$(3))
208 $(call add_jffs2_mark,$@)
209 endef
210
211 define Image/mkfs/jffs2/template
212 Image/mkfs/jffs2-$(1) = $$(call Image/mkfs/jffs2/sub,$(1),$(JFFS2OPTS),$$(1))
213 Image/mkfs/jffs2-$(1)-raw = $$(call Image/mkfs/jffs2/sub-raw,$(1),$(JFFS2OPTS),$$(1))
214
215 endef
216
217 define Image/mkfs/jffs2-nand/template
218 Image/mkfs/jffs2-nand-$(1) = \
219 $$(call Image/mkfs/jffs2/sub, \
220 $(word 2,$(subst -, ,$(1))), \
221 $(JFFS2OPTS) --no-cleanmarkers --pagesize=$(word 1,$(subst -, ,$(1))),$$(1))
222
223 endef
224
225 $(eval $(foreach S,$(JFFS2_BLOCKSIZE),$(call Image/mkfs/jffs2/template,$(S))))
226 $(eval $(foreach S,$(NAND_BLOCKSIZE),$(call Image/mkfs/jffs2-nand/template,$(S))))
227
228 define Image/mkfs/squashfs
229 $(STAGING_DIR_HOST)/bin/mksquashfs4 $(call mkfs_target_dir,$(1)) $@ \
230 -nopad -noappend -root-owned \
231 -comp $(SQUASHFSCOMP) $(SQUASHFSOPT) \
232 -processors 1
233 endef
234
235 # $(1): board name
236 # $(2): rootfs type
237 # $(3): kernel image
238 # $(4): compat string
239 ifneq ($(CONFIG_NAND_SUPPORT),)
240 define Image/Build/SysupgradeNAND
241 mkdir -p "$(KDIR_TMP)/sysupgrade-$(if $(4),$(4),$(1))/"
242 echo "BOARD=$(if $(4),$(4),$(1))" > "$(KDIR_TMP)/sysupgrade-$(if $(4),$(4),$(1))/CONTROL"
243 [ -z "$(2)" ] || $(CP) "$(KDIR)/root.$(2)" "$(KDIR_TMP)/sysupgrade-$(if $(4),$(4),$(1))/root"
244 [ -z "$(3)" ] || $(CP) "$(3)" "$(KDIR_TMP)/sysupgrade-$(if $(4),$(4),$(1))/kernel"
245 (cd "$(KDIR_TMP)"; $(TAR) cvf \
246 "$(BIN_DIR)/$(IMG_PREFIX)-$(1)-$(2)-sysupgrade.tar" sysupgrade-$(if $(4),$(4),$(1)) \
247 $(if $(SOURCE_DATE_EPOCH),--mtime="@$(SOURCE_DATE_EPOCH)") \
248 )
249 endef
250
251 # $(1) board name
252 # $(2) ubinize-image options (e.g. --uboot-env and/or --kernel kernelimage)
253 # $(3) rootfstype (e.g. squashfs or ubifs)
254 # $(4) options to pass-through to ubinize (i.e. $($(PROFILE)_UBI_OPTS)))
255 define Image/Build/UbinizeImage
256 sh $(TOPDIR)/scripts/ubinize-image.sh $(2) \
257 "$(KDIR)/root.$(3)" \
258 "$(KDIR)/$(IMG_PREFIX)-$(1)-$(3)-ubinized.bin" \
259 $(4)
260 endef
261
262 endif
263
264 define Image/mkfs/ubifs
265 $(STAGING_DIR_HOST)/bin/mkfs.ubifs \
266 $(UBIFS_OPTS) $(call param_unmangle,$(call param_get,fs,$(1))) \
267 $(if $(CONFIG_TARGET_UBIFS_FREE_SPACE_FIXUP),--space-fixup) \
268 $(if $(CONFIG_TARGET_UBIFS_COMPRESSION_NONE),--compr=none) \
269 $(if $(CONFIG_TARGET_UBIFS_COMPRESSION_LZO),--compr=lzo) \
270 $(if $(CONFIG_TARGET_UBIFS_COMPRESSION_ZLIB),--compr=zlib) \
271 $(if $(shell echo $(CONFIG_TARGET_UBIFS_JOURNAL_SIZE)),--jrn-size=$(CONFIG_TARGET_UBIFS_JOURNAL_SIZE)) \
272 --squash-uids \
273 -o $@ -d $(call mkfs_target_dir,$(1))
274 endef
275
276 E2SIZE=$(shell echo $$(($(CONFIG_TARGET_ROOTFS_PARTSIZE)*1024*1024)))
277
278 define Image/mkfs/ext4
279 $(STAGING_DIR_HOST)/bin/make_ext4fs \
280 -l $(E2SIZE) -b $(CONFIG_TARGET_EXT4_BLOCKSIZE) \
281 $(if $(CONFIG_TARGET_EXT4_RESERVED_PCT),-m $(CONFIG_TARGET_EXT4_RESERVED_PCT)) \
282 $(if $(CONFIG_TARGET_EXT4_JOURNAL),,-J) \
283 $(if $(SOURCE_DATE_EPOCH),-T $(SOURCE_DATE_EPOCH)) \
284 $@ $(call mkfs_target_dir,$(1))/
285 endef
286
287 define Image/Manifest
288 $(call opkg,$(TARGET_DIR_ORIG)) list-installed > \
289 $(BIN_DIR)/$(IMG_PREFIX)$(if $(PROFILE_SANITIZED),-$(PROFILE_SANITIZED)).manifest
290 endef
291
292 ifdef CONFIG_TARGET_ROOTFS_TARGZ
293 define Image/Build/targz
294 $(TAR) -cp --numeric-owner --owner=0 --group=0 --mode=a-s --sort=name \
295 $(if $(SOURCE_DATE_EPOCH),--mtime="@$(SOURCE_DATE_EPOCH)") \
296 -C $(TARGET_DIR)/ . | gzip -9n > $(BIN_DIR)/$(IMG_PREFIX)$(if $(PROFILE_SANITIZED),-$(PROFILE_SANITIZED))-rootfs.tar.gz
297 endef
298 endif
299
300 ifdef CONFIG_TARGET_ROOTFS_CPIOGZ
301 define Image/Build/cpiogz
302 ( cd $(TARGET_DIR); find . | cpio -o -H newc -R root:root | gzip -9n >$(BIN_DIR)/$(IMG_PREFIX)-rootfs.cpio.gz )
303 endef
304 endif
305
306 mkfs_packages = $(filter-out @%,$(PACKAGES_$(call param_get,pkg,pkg=$(target_params))))
307 mkfs_packages_add = $(foreach pkg,$(filter-out -%,$(mkfs_packages)),$(pkg)$(call GetABISuffix,$(pkg)))
308 mkfs_packages_remove = $(foreach pkg,$(patsubst -%,%,$(filter -%,$(mkfs_packages))),$(pkg)$(call GetABISuffix,$(pkg)))
309 mkfs_cur_target_dir = $(call mkfs_target_dir,pkg=$(target_params))
310
311 opkg_target = \
312 $(call opkg,$(mkfs_cur_target_dir)) \
313 -f $(mkfs_cur_target_dir).conf
314
315 target-dir-%: FORCE
316 rm -rf $(mkfs_cur_target_dir) $(mkfs_cur_target_dir).opkg
317 $(CP) $(TARGET_DIR_ORIG) $(mkfs_cur_target_dir)
318 -mv $(mkfs_cur_target_dir)/etc/opkg $(mkfs_cur_target_dir).opkg
319 echo 'src default file://$(PACKAGE_DIR_ALL)' > $(mkfs_cur_target_dir).conf
320 $(if $(mkfs_packages_remove), \
321 -$(call opkg,$(mkfs_cur_target_dir)) remove \
322 $(mkfs_packages_remove))
323 $(if $(call opkg_package_files,$(mkfs_packages_add)), \
324 $(opkg_target) update && \
325 $(opkg_target) install \
326 $(call opkg_package_files,$(mkfs_packages_add)))
327 -$(CP) -T $(mkfs_cur_target_dir).opkg/ $(mkfs_cur_target_dir)/etc/opkg/
328 rm -rf $(mkfs_cur_target_dir).opkg $(mkfs_cur_target_dir).conf
329 $(call prepare_rootfs,$(mkfs_cur_target_dir),$(TOPDIR)/files)
330
331 $(KDIR)/root.%: kernel_prepare
332 $(call Image/mkfs/$(word 1,$(target_params)),$(target_params))
333
334 define Device/InitProfile
335 PROFILES := $(PROFILE)
336 DEVICE_TITLE :=
337 DEVICE_PACKAGES :=
338 DEVICE_DESCRIPTION = Build firmware images for $$(DEVICE_TITLE)
339 endef
340
341 define Device/Init
342 DEVICE_NAME := $(1)
343 KERNEL:=
344 KERNEL_INITRAMFS = $$(KERNEL)
345 KERNEL_SIZE:=
346 CMDLINE:=
347
348 IMAGES :=
349 ARTIFACTS :=
350 IMAGE_PREFIX := $(IMG_PREFIX)-$(1)
351 IMAGE_NAME = $$(IMAGE_PREFIX)-$$(1)-$$(2)
352 KERNEL_PREFIX = $$(IMAGE_PREFIX)
353 KERNEL_SUFFIX := -kernel.bin
354 KERNEL_INITRAMFS_SUFFIX = $$(KERNEL_SUFFIX)
355 KERNEL_IMAGE = $$(KERNEL_PREFIX)$$(KERNEL_SUFFIX)
356 KERNEL_INITRAMFS_PREFIX = $$(IMAGE_PREFIX)-initramfs
357 KERNEL_INITRAMFS_IMAGE = $$(KERNEL_INITRAMFS_PREFIX)$$(KERNEL_INITRAMFS_SUFFIX)
358 KERNEL_INITRAMFS_NAME = $$(KERNEL_NAME)-initramfs
359 KERNEL_INSTALL :=
360 KERNEL_NAME := vmlinux
361 KERNEL_DEPENDS :=
362 KERNEL_SIZE :=
363
364 UBOOTENV_IN_UBI :=
365 KERNEL_IN_UBI :=
366 BLOCKSIZE :=
367 PAGESIZE :=
368 SUBPAGESIZE :=
369 VID_HDR_OFFSET :=
370 UBINIZE_OPTS :=
371 UBINIZE_PARTS :=
372 MKUBIFS_OPTS :=
373
374 FS_OPTIONS/ubifs = $$(MKUBIFS_OPTS)
375
376 DEVICE_DTS :=
377 DEVICE_DTS_CONFIG :=
378 DEVICE_DTS_DIR :=
379
380 BOARD_NAME :=
381 UIMAGE_NAME :=
382 SUPPORTED_DEVICES :=
383 IMAGE_METADATA :=
384
385 FILESYSTEMS := $(TARGET_FILESYSTEMS)
386 endef
387
388 DEFAULT_DEVICE_VARS := \
389 DEVICE_NAME KERNEL KERNEL_INITRAMFS KERNEL_INITRAMFS_IMAGE KERNEL_SIZE \
390 CMDLINE UBOOTENV_IN_UBI KERNEL_IN_UBI BLOCKSIZE PAGESIZE SUBPAGESIZE \
391 VID_HDR_OFFSET UBINIZE_OPTS UBINIZE_PARTS MKUBIFS_OPTS DEVICE_DTS \
392 DEVICE_DTS_CONFIG DEVICE_DTS_DIR BOARD_NAME UIMAGE_NAME SUPPORTED_DEVICES \
393 IMAGE_METADATA KERNEL_ENTRY KERNEL_LOADADDR
394
395 define Device/ExportVar
396 $(1) : $(2):=$$($(2))
397
398 endef
399 define Device/Export
400 $(foreach var,$(DEVICE_VARS) $(DEFAULT_DEVICE_VARS),$(call Device/ExportVar,$(1),$(var)))
401 $(1) : FILESYSTEM:=$(2)
402 endef
403
404 ifdef IB
405 DEVICE_CHECK_PROFILE = $(filter $(1),DEVICE_$(PROFILE) $(PROFILE))
406 else
407 DEVICE_CHECK_PROFILE = $(CONFIG_TARGET_$(if $(CONFIG_TARGET_MULTI_PROFILE),DEVICE_)$(call target_conf,$(BOARD)$(if $(SUBTARGET),_$(SUBTARGET)))_$(1))
408 endif
409
410 DEVICE_EXTRA_PACKAGES = $(call qstrip,$(CONFIG_TARGET_DEVICE_PACKAGES_$(call target_conf,$(BOARD)$(if $(SUBTARGET),_$(SUBTARGET)))_DEVICE_$(1)))
411
412 define merge_packages
413 $(1) :=
414 $(foreach pkg,$(2),
415 $(1) := $$(strip $$(filter-out -$$(patsubst -%,%,$(pkg)) $$(patsubst -%,%,$(pkg)),$$($(1))) $(pkg))
416 )
417 endef
418
419 define Device/Check/Common
420 _PROFILE_SET = $$(strip $$(foreach profile,$$(PROFILES) DEVICE_$(1),$$(call DEVICE_CHECK_PROFILE,$$(profile))))
421 DEVICE_PACKAGES += $$(call extra_packages,$$(DEVICE_PACKAGES))
422 ifdef TARGET_PER_DEVICE_ROOTFS
423 $$(eval $$(call merge_packages,_PACKAGES,$$(DEVICE_PACKAGES) $$(call DEVICE_EXTRA_PACKAGES,$(1))))
424 ROOTFS_ID/$(1) := $$(if $$(_PROFILE_SET),$$(call mkfs_packages_id,$$(_PACKAGES)))
425 PACKAGES_$$(ROOTFS_ID/$(1)) := $$(_PACKAGES)
426 endif
427 endef
428
429 define Device/Check
430 $(Device/Check/Common)
431 KDIR_KERNEL_IMAGE := $(KDIR)/$(1)$$(KERNEL_SUFFIX)
432 _TARGET := $$(if $$(_PROFILE_SET),install-images,install-disabled)
433 ifndef IB
434 _COMPILE_TARGET := $$(if $(CONFIG_IB)$$(_PROFILE_SET),compile,compile-disabled)
435 endif
436 endef
437
438 ifndef IB
439 define Device/Build/initramfs
440 $(call Device/Export,$(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE),$(1))
441 $$(_TARGET): $$(if $$(KERNEL_INITRAMFS),$(BIN_DIR)/$$(KERNEL_INITRAMFS_IMAGE))
442
443 $(KDIR)/$$(KERNEL_INITRAMFS_NAME):: image_prepare
444 $(BIN_DIR)/$$(KERNEL_INITRAMFS_IMAGE): $(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE)
445 cp $$^ $$@
446
447 $(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE): $(KDIR)/$$(KERNEL_INITRAMFS_NAME) $(CURDIR)/Makefile $$(KERNEL_DEPENDS) image_prepare
448 @rm -f $$@
449 $$(call concat_cmd,$$(KERNEL_INITRAMFS))
450 endef
451 endif
452
453 define Device/Build/compile
454 $$(_COMPILE_TARGET): $(KDIR)/$(1)
455 $(eval $(call Device/Export,$(KDIR)/$(1)))
456 $(KDIR)/$(1):
457 $$(call concat_cmd,$(COMPILE/$(1)))
458
459 endef
460
461 ifndef IB
462 define Device/Build/dtb
463 ifndef BUILD_DTS_$(1)
464 BUILD_DTS_$(1) := 1
465 $(KDIR)/image-$(1).dtb: FORCE
466 $(call Image/BuildDTB,$(strip $(2))/$(strip $(3)).dts,$$@)
467
468 image_prepare: $(KDIR)/image-$(1).dtb
469 endif
470
471 endef
472 endif
473
474 define Device/Build/kernel
475 $$(eval $$(foreach dts,$$(DEVICE_DTS), \
476 $$(call Device/Build/dtb,$$(notdir $$(dts)), \
477 $$(if $$(DEVICE_DTS_DIR),$$(DEVICE_DTS_DIR),$$(DTS_DIR)), \
478 $$(dts) \
479 ) \
480 ))
481
482 $(KDIR)/$$(KERNEL_NAME):: image_prepare
483 $$(_TARGET): $$(if $$(KERNEL_INSTALL),$(BIN_DIR)/$$(KERNEL_IMAGE))
484 $(call Device/Export,$$(KDIR_KERNEL_IMAGE),$(1))
485 $(BIN_DIR)/$$(KERNEL_IMAGE): $$(KDIR_KERNEL_IMAGE)
486 cp $$^ $$@
487 ifndef IB
488 ifdef CONFIG_IB
489 install: $$(KDIR_KERNEL_IMAGE)
490 endif
491 $$(KDIR_KERNEL_IMAGE): $(KDIR)/$$(KERNEL_NAME) $(CURDIR)/Makefile $$(KERNEL_DEPENDS) image_prepare
492 @rm -f $$@
493 $$(call concat_cmd,$$(KERNEL))
494 $$(if $$(KERNEL_SIZE),$$(call Build/check-size,$$(KERNEL_SIZE)))
495 endif
496 endef
497
498 define Device/Build/image
499 GZ_SUFFIX := $(if $(filter %dtb %gz,$(2)),,$(if $(and $(findstring ext4,$(1)),$(CONFIG_TARGET_IMAGES_GZIP)),.gz))
500 $$(_TARGET): $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2))$$(GZ_SUFFIX)
501 $(eval $(call Device/Export,$(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2)),$(1)))
502 ROOTFS/$(1)/$(3) := \
503 $(KDIR)/root.$(1)$$(strip \
504 $$(if $$(FS_OPTIONS/$(1)),+fs=$$(call param_mangle,$$(FS_OPTIONS/$(1)))) \
505 )$$(strip \
506 $(if $(TARGET_PER_DEVICE_ROOTFS),+pkg=$$(ROOTFS_ID/$(3))) \
507 )
508 ifndef IB
509 $$(ROOTFS/$(1)/$(3)): $(if $(TARGET_PER_DEVICE_ROOTFS),target-dir-$$(ROOTFS_ID/$(3)))
510 endif
511 $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2)): $$(KDIR_KERNEL_IMAGE) $$(ROOTFS/$(1)/$(3))
512 @rm -f $$@
513 [ -f $$(word 1,$$^) -a -f $$(word 2,$$^) ]
514 $$(call concat_cmd,$(if $(IMAGE/$(2)/$(1)),$(IMAGE/$(2)/$(1)),$(IMAGE/$(2))))
515
516 .IGNORE: $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2))
517
518 $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2)).gz: $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2))
519 gzip -c -9n $$^ > $$@
520
521 $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2)): $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2))
522 cp $$^ $$@
523
524 endef
525
526 define Device/Build/artifact
527 $$(_TARGET): $(BIN_DIR)/$(IMAGE_PREFIX)-$(1)
528 $(eval $(call Device/Export,$(KDIR)/tmp/$(IMAGE_PREFIX)-$(1)))
529 $(KDIR)/tmp/$(IMAGE_PREFIX)-$(1): $$(KDIR_KERNEL_IMAGE)
530 @rm -f $$@
531 $$(call concat_cmd,$(ARTIFACT/$(1)))
532
533 .IGNORE: $(BIN_DIR)/$(IMAGE_PREFIX)-$(1)
534
535 $(BIN_DIR)/$(IMAGE_PREFIX)-$(1): $(KDIR)/tmp/$(IMAGE_PREFIX)-$(1)
536 cp $$^ $$@
537
538 endef
539
540 define Device/Build
541 $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),$(call Device/Build/initramfs,$(1)))
542 $(call Device/Build/kernel,$(1))
543
544 $$(eval $$(foreach compile,$$(COMPILE), \
545 $$(call Device/Build/compile,$$(compile),$(1))))
546
547 $$(eval $$(foreach image,$$(IMAGES), \
548 $$(foreach fs,$$(filter $(TARGET_FILESYSTEMS),$$(FILESYSTEMS)), \
549 $$(call Device/Build/image,$$(fs),$$(image),$(1)))))
550
551 $$(eval $$(foreach artifact,$$(ARTIFACTS), \
552 $$(call Device/Build/artifact,$$(artifact))))
553
554 endef
555
556 define Device/DumpInfo
557 Target-Profile: DEVICE_$(1)
558 Target-Profile-Name: $(DEVICE_TITLE)
559 Target-Profile-Packages: $(DEVICE_PACKAGES)
560 Target-Profile-hasImageMetadata: $(if $(foreach image,$(IMAGES),$(findstring append-metadata,$(IMAGE/$(image)))),1,0)
561 Target-Profile-SupportedDevices: $(SUPPORTED_DEVICES)
562 Target-Profile-Description:
563 $(DEVICE_DESCRIPTION)
564 @@
565
566 endef
567
568 define Device/Dump
569 $$(eval $$(if $$(DEVICE_TITLE),$$(info $$(call Device/DumpInfo,$(1)))))
570 endef
571
572 define Device
573 $(call Device/InitProfile,$(1))
574 $(call Device/Init,$(1))
575 $(call Device/Default,$(1))
576 $(call Device/$(1),$(1))
577 $(call Device/Check,$(1))
578 $(call Device/$(if $(DUMP),Dump,Build),$(1))
579
580 endef
581
582 define BuildImage
583
584 ifneq ($(DUMP),)
585 all: dumpinfo
586 dumpinfo: FORCE
587 @true
588 endif
589
590 download:
591 prepare:
592 compile:
593 clean:
594 legacy-images-prepare:
595 legacy-images:
596 image_prepare:
597
598 ifeq ($(IB),)
599 .PHONY: download prepare compile clean image_prepare kernel_prepare install install-images
600 compile:
601 $(call Build/Compile)
602
603 clean:
604 $(call Build/Clean)
605
606 image_prepare: compile
607 mkdir -p $(BIN_DIR) $(KDIR)/tmp
608 $(call Image/Prepare)
609
610 legacy-images-prepare-make: image_prepare
611 $(MAKE) legacy-images-prepare BIN_DIR="$(BIN_DIR)"
612
613 else
614 image_prepare:
615 mkdir -p $(BIN_DIR) $(KDIR)/tmp
616 endif
617
618 kernel_prepare: image_prepare
619 $(call Image/Build/targz)
620 $(call Image/Build/cpiogz)
621 $(call Image/BuildKernel)
622 $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),$(if $(IB),,$(call Image/BuildKernel/Initramfs)))
623 $(call Image/InstallKernel)
624
625 $(foreach device,$(TARGET_DEVICES),$(call Device,$(device)))
626 $(foreach device,$(LEGACY_DEVICES),$(call LegacyDevice,$(device)))
627
628 install-images: kernel_prepare $(foreach fs,$(filter-out $(if $(UBIFS_OPTS),,ubifs),$(TARGET_FILESYSTEMS) $(fs-subtypes-y)),$(KDIR)/root.$(fs))
629 $(foreach fs,$(TARGET_FILESYSTEMS),
630 $(call Image/Build,$(fs))
631 )
632
633 legacy-images-make: install-images
634 $(call Image/mkfs/ubifs/legacy)
635 $(MAKE) legacy-images BIN_DIR="$(BIN_DIR)"
636
637 install: install-images
638 $(call Image/Manifest)
639
640 endef