image.mk: clean up and parallelize mkfs calls

Signed-off-by: Felix Fietkau <nbd@openwrt.org>

SVN-Revision: 42878
This commit is contained in:
Felix Fietkau 2014-10-12 15:00:49 +00:00
parent d99a680230
commit 275cef6363
3 changed files with 51 additions and 47 deletions

View file

@ -10,8 +10,9 @@ include $(INCLUDE_DIR)/prereq.mk
include $(INCLUDE_DIR)/kernel.mk include $(INCLUDE_DIR)/kernel.mk
include $(INCLUDE_DIR)/host.mk include $(INCLUDE_DIR)/host.mk
override MAKEFLAGS= override MAKE:=$(_SINGLE)$(SUBMAKE)
override MAKE:=$(SUBMAKE) override NO_TRACE_MAKE:=$(_SINGLE)$(NO_TRACE_MAKE)
KDIR=$(KERNEL_BUILD_DIR) KDIR=$(KERNEL_BUILD_DIR)
DTS_DIR:=$(LINUX_DIR)/arch/$(ARCH)/boot/dts/ DTS_DIR:=$(LINUX_DIR)/arch/$(ARCH)/boot/dts/
@ -63,6 +64,13 @@ endif
JFFS2_BLOCKSIZE ?= 64k 128k JFFS2_BLOCKSIZE ?= 64k 128k
fs-types-$(CONFIG_TARGET_ROOTFS_SQUASHFS) += squashfs
fs-types-$(CONFIG_TARGET_ROOTFS_JFFS2) += $(addprefix jffs2-,$(JFFS2_BLOCKSIZE))
fs-types-$(CONFIG_TARGET_ROOTFS_JFFS2_NAND) += $(addprefix jffs2-nand-,$(NAND_BLOCKSIZE))
fs-types-$(CONFIG_TARGET_ROOTFS_EXT4FS) += ext4
fs-types-$(CONFIG_TARGET_ROOTFS_ISO) += iso
TARGET_FILESYSTEMS := $(fs-types-y)
define add_jffs2_mark define add_jffs2_mark
echo -ne '\xde\xad\xc0\xde' >> $(1) echo -ne '\xde\xad\xc0\xde' >> $(1)
endef endef
@ -98,31 +106,27 @@ define Image/mkfs/jffs2/sub
$(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 '/^.+$$$$/' $(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 '/^.+$$$$/'
$(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 '/^.+$$$$/' $(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 '/^.+$$$$/'
$(call add_jffs2_mark,$(KDIR)/root.jffs2-$(2)) $(call add_jffs2_mark,$(KDIR)/root.jffs2-$(2))
$(call Image/Build,jffs2-$(2))
endef endef
ifneq ($(CONFIG_TARGET_ROOTFS_JFFS2),) define Image/mkfs/jffs2/template
define Image/mkfs/jffs2 Image/mkfs/jffs2-$(1) = $$(call Image/mkfs/jffs2/sub,$(1),$(1),$(JFFS2OPTS))
$(foreach SZ,$(JFFS2_BLOCKSIZE),$(call Image/mkfs/jffs2/sub,$(SZ),$(SZ),$(JFFS2OPTS)))
endef
endif
ifneq ($(CONFIG_TARGET_ROOTFS_JFFS2_NAND),) endef
define Image/mkfs/jffs2_nand
$(foreach SZ,$(NAND_BLOCKSIZE), $(call Image/mkfs/jffs2/sub, \
$(word 2,$(subst :, ,$(SZ))),nand-$(subst :,-,$(SZ)), \
$(JFFS2OPTS) --no-cleanmarkers --pagesize=$(word 1,$(subst :, ,$(SZ)))) \
)
endef
endif
ifneq ($(CONFIG_TARGET_ROOTFS_SQUASHFS),) define Image/mkfs/jffs2-nand/template
define Image/mkfs/squashfs Image/mkfs/jffs2-nand-$(1) = \
@mkdir -p $(TARGET_DIR)/overlay $$(call Image/mkfs/jffs2/sub, \
$(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) $(word 2,$(subst -, ,$(1))),nand-$(1), \
$(call Image/Build,squashfs) $(JFFS2OPTS) --no-cleanmarkers --pagesize=$(word 1,$(subst -, ,$(1))))
endef
endif endef
$(eval $(foreach S,$(JFFS2_BLOCKSIZE),$(call Image/mkfs/jffs2/template,$(S))))
$(eval $(foreach S,$(NAND_BLOCKSIZE),$(call Image/mkfs/jffs2-nand/template,$(S))))
define Image/mkfs/squashfs
$(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)
endef
# $(1): board name # $(1): board name
# $(2): rootfs type # $(2): rootfs type
@ -203,33 +207,23 @@ ifneq ($(CONFIG_TARGET_ROOTFS_TARGZ),)
endef endef
endif endif
ifneq ($(CONFIG_TARGET_ROOTFS_EXT4FS),) E2SIZE=$(shell echo $$(($(CONFIG_TARGET_ROOTFS_PARTSIZE)*1024*1024/$(CONFIG_TARGET_EXT4_BLOCKSIZE))))
E2SIZE=$(shell echo $$(($(CONFIG_TARGET_ROOTFS_PARTSIZE)*1024*1024/$(CONFIG_TARGET_EXT4_BLOCKSIZE))))
define Image/mkfs/ext4 define Image/mkfs/ext4
# generate an ext2 fs # generate an ext2 fs
$(STAGING_DIR_HOST)/bin/genext2fs -U -B $(CONFIG_TARGET_EXT4_BLOCKSIZE) -b $(E2SIZE) -N $(CONFIG_TARGET_EXT4_MAXINODE) -d $(TARGET_DIR)/ $(KDIR)/root.ext4 -m $(CONFIG_TARGET_EXT4_RESERVED_PCT) $(MKFS_DEVTABLE_OPT) $(STAGING_DIR_HOST)/bin/genext2fs -U -B $(CONFIG_TARGET_EXT4_BLOCKSIZE) -b $(E2SIZE) -N $(CONFIG_TARGET_EXT4_MAXINODE) -d $(TARGET_DIR)/ $(KDIR)/root.ext4 -m $(CONFIG_TARGET_EXT4_RESERVED_PCT) $(MKFS_DEVTABLE_OPT)
# convert it to ext4 # convert it to ext4
$(STAGING_DIR_HOST)/bin/tune2fs $(if $(CONFIG_TARGET_EXT4_JOURNAL),-j) -O extents,uninit_bg,dir_index $(KDIR)/root.ext4 $(STAGING_DIR_HOST)/bin/tune2fs $(if $(CONFIG_TARGET_EXT4_JOURNAL),-j) -O extents,uninit_bg,dir_index $(KDIR)/root.ext4
# fix it up # fix it up
$(STAGING_DIR_HOST)/bin/e2fsck -fy $(KDIR)/root.ext4 $(STAGING_DIR_HOST)/bin/e2fsck -fy $(KDIR)/root.ext4
$(call Image/Build,ext4) endef
endef
endif
ifneq ($(CONFIG_TARGET_ROOTFS_ISO),)
define Image/mkfs/iso
$(call Image/Build,iso)
endef
endif
define Image/mkfs/prepare/default define Image/mkfs/prepare/default
# Use symbolic permissions to avoid clobbering SUID/SGID/sticky bits # Use symbolic permissions to avoid clobbering SUID/SGID/sticky bits
- $(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 - $(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
- $(FIND) $(TARGET_DIR) -type f -perm +0100 -print0 | $(XARGS) -0 chmod u+rwx,g+rx,o+rx - $(FIND) $(TARGET_DIR) -type f -perm +0100 -print0 | $(XARGS) -0 chmod u+rwx,g+rx,o+rx
- $(FIND) $(TARGET_DIR) -type d -print0 | $(XARGS) -0 chmod u+rwx,g+rx,o+rx - $(FIND) $(TARGET_DIR) -type d -print0 | $(XARGS) -0 chmod u+rwx,g+rx,o+rx
$(INSTALL_DIR) $(TARGET_DIR)/tmp $(INSTALL_DIR) $(TARGET_DIR)/tmp $(TARGET_DIR)/overlay
chmod 1777 $(TARGET_DIR)/tmp chmod 1777 $(TARGET_DIR)/tmp
endef endef
@ -245,6 +239,13 @@ define Image/Checksum
) )
endef endef
define BuildImage/mkfs
install: mkfs-$(1)
.PHONY: mkfs-$(1)
mkfs-$(1): mkfs_prepare
$(Image/mkfs/$(1))
endef
define BuildImage define BuildImage
@ -255,30 +256,33 @@ define BuildImage
image_prepare: image_prepare:
ifeq ($(IB),) ifeq ($(IB),)
compile: compile-targets FORCE .PHONY: download prepare compile clean image_prepare mkfs_prepare kernel_prepare install
compile: compile-targets
$(call Build/Compile) $(call Build/Compile)
clean: clean-targets clean: clean-targets
$(call Build/Clean) $(call Build/Clean)
image_prepare: compile FORCE image_prepare: compile
$(call Image/Prepare) $(call Image/Prepare)
endif endif
mkfs_prepare: image_prepare mkfs_prepare: image_prepare
$(call Image/mkfs/prepare) $(call Image/mkfs/prepare)
install: mkfs_prepare install-targets FORCE kernel_prepare: mkfs_prepare
$(call Image/BuildKernel) $(call Image/BuildKernel)
$(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),$(call Image/BuildKernel/Initramfs)) $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),$(call Image/BuildKernel/Initramfs))
$(call Image/InstallKernel) $(call Image/InstallKernel)
$(foreach fs,$(TARGET_FILESYSTEMS),$(call BuildImage/mkfs,$(fs)))
install: kernel_prepare install-targets
$(call Image/mkfs/cpiogz) $(call Image/mkfs/cpiogz)
$(call Image/mkfs/targz) $(call Image/mkfs/targz)
$(call Image/mkfs/ext4) $(foreach fs,$(TARGET_FILESYSTEMS),
$(call Image/mkfs/iso) $(call Image/Build,$(fs))
$(call Image/mkfs/jffs2) )
$(call Image/mkfs/jffs2_nand)
$(call Image/mkfs/squashfs)
$(call Image/mkfs/ubifs) $(call Image/mkfs/ubifs)
$(call Image/Checksum) $(call Image/Checksum)

View file

@ -7,7 +7,7 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/image.mk include $(INCLUDE_DIR)/image.mk
NAND_BLOCKSIZE := 2048:128k NAND_BLOCKSIZE := 2048-128k
define sanitize_profile_name define sanitize_profile_name
$(shell echo $(PROFILE) | tr '[:upper:]' '[:lower:]') $(shell echo $(PROFILE) | tr '[:upper:]' '[:lower:]')

View file

@ -7,7 +7,7 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/image.mk include $(INCLUDE_DIR)/image.mk
NAND_BLOCKSIZE=2048:128k NAND_BLOCKSIZE=2048-128k
define Image/BuildKernel define Image/BuildKernel
$(CP) $(KDIR)/zImage $(BIN_DIR)/$(IMG_PREFIX)-zImage $(CP) $(KDIR)/zImage $(BIN_DIR)/$(IMG_PREFIX)-zImage