-# 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)
-# convert it to ext4
- $(STAGING_DIR_HOST)/bin/tune2fs $(if $(CONFIG_TARGET_EXT4_JOURNAL),-j) -O extents,uninit_bg,dir_index $(KDIR)/root.ext4
-# fix it up
- $(STAGING_DIR_HOST)/bin/e2fsck -fy $(KDIR)/root.ext4
-endef
-
-define Image/mkfs/prepare/default
- # 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 -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
- $(INSTALL_DIR) $(TARGET_DIR)/tmp $(TARGET_DIR)/overlay
- chmod 1777 $(TARGET_DIR)/tmp
-endef
-
-define Image/mkfs/prepare
- $(call Image/mkfs/prepare/default)
-endef
-
-
-define Image/Checksum
- ( cd ${BIN_DIR} ; \
- $(FIND) -maxdepth 1 -type f \! -name 'md5sums' -printf "%P\n" | sort | xargs \
- md5sum --binary > md5sums \
- )
-endef
-
-define BuildImage/mkfs
- install: mkfs-$(1)
- .PHONY: mkfs-$(1)
- mkfs-$(1): mkfs_prepare
- $(Image/mkfs/$(1))
- $(call Build/mkfs/default,$(1))
- $(call Build/mkfs/$(1),$(1))
- $(KDIR)/root.$(1): mkfs-$(1)
-
-endef
-
-# Build commands that can be called from Device/* templates
-define Build/uImage
- mkimage -A $(LINUX_KARCH) \
- -O linux -T kernel \
- -C $(1) -a $(KERNEL_LOADADDR) -e $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
- -n '$(call toupper,$(LINUX_KARCH)) OpenWrt Linux-$(LINUX_VERSION)' -d $@ $@.new
- @mv $@.new $@
-endef
-
-define Build/lzma
- $(STAGING_DIR_HOST)/bin/lzma e $@ -lc1 -lp2 -pb2 $(1) $@.new
- @mv $@.new $@
-endef
-
-define Build/kernel-bin
- rm -f $@
- cp $^ $@
-endef
-
-define Build/patch-cmdline
- $(STAGING_DIR_HOST)/bin/patch-cmdline $@ '$(CMDLINE)'
-endef
-
-define Build/append-kernel
- dd if=$(word 1,$^) $(if $(1),bs=$(1) conv=sync) >> $@
-endef
-
-define Build/append-rootfs
- dd if=$(word 2,$^) $(if $(1),bs=$(1) conv=sync) >> $@
-endef
-
-define Build/pad-rootfs
- $(call prepare_generic_squashfs,$@ $(1))
-endef
+ $(STAGING_DIR_HOST)/bin/make_ext4fs \
+ -l $(E2SIZE) -b $(CONFIG_TARGET_EXT4_BLOCKSIZE) \
+ $(if $(CONFIG_TARGET_EXT4_RESERVED_PCT),-m $(CONFIG_TARGET_EXT4_RESERVED_PCT)) \
+ $(if $(CONFIG_TARGET_EXT4_JOURNAL),,-J) \
+ $(if $(SOURCE_DATE_EPOCH),-T $(SOURCE_DATE_EPOCH)) \
+ $@ $(call mkfs_target_dir,$(1))/
+endef
+
+define Image/Manifest
+ $(STAGING_DIR_HOST)/bin/opkg \
+ --offline-root $(TARGET_DIR) \
+ --add-arch all:100 \
+ --add-arch $(if $(ARCH_PACKAGES),$(ARCH_PACKAGES),$(BOARD)):200 list-installed > \
+ $(BIN_DIR)/$(IMG_PREFIX)$(if $(PROFILE_SANITIZED),-$(PROFILE_SANITIZED)).manifest
+endef
+
+ifdef CONFIG_TARGET_ROOTFS_TARGZ
+ define Image/Build/targz
+ $(TAR) -cp --numeric-owner --owner=0 --group=0 --sort=name \
+ $(if $(SOURCE_DATE_EPOCH),--mtime="@$(SOURCE_DATE_EPOCH)") \
+ -C $(TARGET_DIR)/ . | gzip -9n > $(BIN_DIR)/$(IMG_PREFIX)$(if $(PROFILE_SANITIZED),-$(PROFILE_SANITIZED))-rootfs.tar.gz
+ endef
+endif