build: add support for per-device rootfs based on device profile packges

Signed-off-by: Felix Fietkau <nbd@nbd.name>
This commit is contained in:
Felix Fietkau 2016-07-22 14:27:52 +02:00
parent c0dceae4bb
commit 76341cfc5f
3 changed files with 101 additions and 13 deletions

View file

@ -45,6 +45,15 @@ define LegacyDevice/Check
endif endif
endef endef
ifdef TARGET_PER_DEVICE_ROOTFS
define Image/Build/Profile/Filesystem
cp $(KDIR)/root.$(2)+pkg=$(3) $(KDIR)/root.$(2)
$(call Image/Build/Profile,$(1),$(2))
endef
else
Image/Build/Profile/Filesystem = $(Image/Build/Profile)
endif
define LegacyDevice/Build define LegacyDevice/Build
$$(_TARGET): legacy-image-$(1) $$(_TARGET): legacy-image-$(1)
$$(_TARGET_PREPARE): legacy-image-prepare-$(1) $$(_TARGET_PREPARE): legacy-image-prepare-$(1)
@ -53,10 +62,21 @@ define LegacyDevice/Build
legacy-image-prepare-$(1): legacy-image-prepare-$(1):
$$(call Image/Prepare/Profile,$(1)) $$(call Image/Prepare/Profile,$(1))
ifndef IB
ifdef CONFIG_TARGET_PER_DEVICE_ROOTFS
ROOTFS/$(1) := $(foreach fs,$(TARGET_FILESYSTEMS), \
$(KDIR)/root.$(fs)$$(strip $(if $(CONFIG_TARGET_PER_DEVICE_ROOTFS),+pkg=$$(ROOTFS_ID/$(1))))
)
$$(ROOTFS/$(1)): target-dir-$$(ROOTFS_ID/$(1))
legacy-images-make: $$(if $$(_PROFILE_SET),$$(ROOTFS/$(1)))
endif
endif
legacy-image-$(1): legacy-image-$(1):
$$(call Image/BuildKernel/Profile,$(1)) $$(call Image/BuildKernel/Profile,$(1))
$(foreach fs,$(TARGET_FILESYSTEMS), $(foreach fs,$(TARGET_FILESYSTEMS),
$$(call Image/Build/Profile,$(1),$(fs)) $$(call Image/Build/Profile/Filesystem,$(1),$(fs),$$(ROOTFS_ID/$(1)))
) )
endef endef

View file

@ -11,8 +11,19 @@ include $(INCLUDE_DIR)/kernel.mk
include $(INCLUDE_DIR)/host.mk include $(INCLUDE_DIR)/host.mk
include $(INCLUDE_DIR)/version.mk include $(INCLUDE_DIR)/version.mk
include $(INCLUDE_DIR)/image-commands.mk include $(INCLUDE_DIR)/image-commands.mk
ifndef IB
ifdef CONFIG_TARGET_PER_DEVICE_ROOTFS
TARGET_PER_DEVICE_ROOTFS := 1
endif
endif
include $(INCLUDE_DIR)/image-legacy.mk include $(INCLUDE_DIR)/image-legacy.mk
ifdef TARGET_PER_DEVICE_ROOTFS
include $(INCLUDE_DIR)/rootfs.mk
endif
override MAKE:=$(_SINGLE)$(SUBMAKE) override MAKE:=$(_SINGLE)$(SUBMAKE)
override NO_TRACE_MAKE:=$(_SINGLE)$(NO_TRACE_MAKE) override NO_TRACE_MAKE:=$(_SINGLE)$(NO_TRACE_MAKE)
@ -21,7 +32,8 @@ param_get = $(patsubst $(1)=%,%,$(filter $(1)=%,$(2)))
param_mangle = $(subst $(space),_,$(strip $(1))) param_mangle = $(subst $(space),_,$(strip $(1)))
param_unmangle = $(subst _,$(space),$(1)) param_unmangle = $(subst _,$(space),$(1))
mkfs_target_dir = $(TARGET_DIR) mkfs_packages_id = $(shell echo $(sort $(1)) | md5sum | head -c 8)
mkfs_target_dir = $(if $(call param_get,pkg,$(1)),$(KDIR)/target-dir-$(call param_get,pkg,$(1)),$(TARGET_DIR))
KDIR=$(KERNEL_BUILD_DIR) KDIR=$(KERNEL_BUILD_DIR)
KDIR_TMP=$(KDIR)/tmp KDIR_TMP=$(KDIR)/tmp
@ -240,15 +252,15 @@ endef
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) $(1) -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) $(1) -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) $(1) -type d -print0 | $(XARGS) -0 chmod u+rwx,g+rx,o+rx
$(INSTALL_DIR) $(TARGET_DIR)/tmp $(TARGET_DIR)/overlay $(INSTALL_DIR) $(1)/tmp $(1)/overlay
chmod 1777 $(TARGET_DIR)/tmp chmod 1777 $(1)/tmp
endef endef
define Image/mkfs/prepare define Image/mkfs/prepare
$(call Image/mkfs/prepare/default) $(call Image/mkfs/prepare/default,$(1))
endef endef
@ -272,6 +284,23 @@ ifdef CONFIG_TARGET_ROOTFS_CPIOGZ
endef endef
endif endif
mkfs_packages = $(filter-out @%,$(PACKAGES_$(call param_get,pkg,pkg=$(target_params))))
mkfs_packages_add = $(filter-out -%,$(mkfs_packages))
mkfs_packages_remove = $(patsubst -%,%,$(filter -%,$(mkfs_packages)))
mkfs_cur_target_dir = $(call mkfs_target_dir,pkg=$(target_params))
target-dir-%: FORCE
rm -rf $(mkfs_cur_target_dir)
$(CP) $(TARGET_DIR) $(mkfs_cur_target_dir)
$(if $(mkfs_packages_add), \
$(call opkg,$(mkfs_cur_target_dir)) install \
$(call opkg_package_files,$(mkfs_packages_add)))
$(if $(mkfs_packages_remove), \
$(call opkg,$(mkfs_cur_target_dir)) remove \
$(mkfs_packages_remove))
$(call Image/mkfs/prepare,$(mkfs_cur_target_dir))
$(call prepare_rootfs,$(mkfs_cur_target_dir))
$(KDIR)/root.%: kernel_prepare $(KDIR)/root.%: kernel_prepare
$(call Image/mkfs/$(word 1,$(target_params)),$(target_params)) $(call Image/mkfs/$(word 1,$(target_params)),$(target_params))
@ -347,6 +376,10 @@ endif
define Device/Check/Common define Device/Check/Common
_PROFILE_SET = $$(strip $$(foreach profile,$$(PROFILES) DEVICE_$(1),$$(call DEVICE_CHECK_PROFILE,$$(profile)))) _PROFILE_SET = $$(strip $$(foreach profile,$$(PROFILES) DEVICE_$(1),$$(call DEVICE_CHECK_PROFILE,$$(profile))))
ifdef TARGET_PER_DEVICE_ROOTFS
ROOTFS_ID/$(1) := $$(if $$(_PROFILE_SET),$$(call mkfs_packages_id,$$(DEVICE_PACKAGES)))
PACKAGES_$$(ROOTFS_ID/$(1)) := $$(DEVICE_PACKAGES)
endif
endef endef
define Device/Check define Device/Check
@ -409,7 +442,16 @@ endef
define Device/Build/image define Device/Build/image
$$(_TARGET): $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2)) $$(_TARGET): $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2))
$(eval $(call Device/Export,$(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2)),$(1))) $(eval $(call Device/Export,$(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2)),$(1)))
$(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2)): $$(KDIR_KERNEL_IMAGE) $(KDIR)/root.$(1)$$(if $$(FS_OPTIONS/$(1)),+fs=$$(call param_mangle,$$(FS_OPTIONS/$(1)))) ROOTFS/$(1)/$(3) := \
$(KDIR)/root.$(1)$$(strip \
$$(if $$(FS_OPTIONS/$(1)),+fs=$$(call param_mangle,$$(FS_OPTIONS/$(1)))) \
)$$(strip \
$(if $(TARGET_PER_DEVICE_ROOTFS),+pkg=$$(ROOTFS_ID/$(3))) \
)
ifndef IB
$$(ROOTFS/$(1)/$(3)): $(if $(TARGET_PER_DEVICE_ROOTFS),target-dir-$$(ROOTFS_ID/$(3)))
endif
$(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2)): $$(KDIR_KERNEL_IMAGE) $$(ROOTFS/$(1)/$(3))
@rm -f $$@ @rm -f $$@
[ -f $$(word 1,$$^) -a -f $$(word 2,$$^) ] [ -f $$(word 1,$$^) -a -f $$(word 2,$$^) ]
$$(call concat_cmd,$(if $(IMAGE/$(2)/$(1)),$(IMAGE/$(2)/$(1)),$(IMAGE/$(2)))) $$(call concat_cmd,$(if $(IMAGE/$(2)/$(1)),$(IMAGE/$(2)/$(1)),$(IMAGE/$(2))))
@ -493,7 +535,7 @@ define BuildImage
endif endif
mkfs_prepare: image_prepare mkfs_prepare: image_prepare
$(call Image/mkfs/prepare) $(call Image/mkfs/prepare,$(TARGET_DIR))
kernel_prepare: mkfs_prepare kernel_prepare: mkfs_prepare
$(call Image/Build/targz) $(call Image/Build/targz)

View file

@ -151,6 +151,18 @@ sub gen_target_config() {
target_name($a) cmp target_name($b); target_name($a) cmp target_name($b);
} @target; } @target;
foreach my $target (@target_sort) {
next if @{$target->{subtargets}} > 0;
print <<EOF;
config DEFAULT_TARGET_$target->{conf}
bool
depends on TARGET_PER_DEVICE_ROOTFS
default y if TARGET_$target->{conf}
EOF
foreach my $pkg (@{$target->{packages}}) {
print "\tselect DEFAULT_$pkg if TARGET_PER_DEVICE_ROOTFS\n";
}
}
print <<EOF; print <<EOF;
choice choice
@ -238,6 +250,9 @@ endchoice
menu "Target Devices" menu "Target Devices"
depends on TARGET_MULTI_PROFILE depends on TARGET_MULTI_PROFILE
config TARGET_PER_DEVICE_ROOTFS
bool "Use a per-device root filesystem that adds profile packages"
EOF EOF
foreach my $target (@target) { foreach my $target (@target) {
my $profiles = $target->{profiles}; my $profiles = $target->{profiles};
@ -250,7 +265,8 @@ config TARGET_DEVICE_$target->{conf}_$profile->{id}
EOF EOF
my @pkglist = merge_package_lists($target->{packages}, $profile->{packages}); my @pkglist = merge_package_lists($target->{packages}, $profile->{packages});
foreach my $pkg (@pkglist) { foreach my $pkg (@pkglist) {
print "\tselect DEFAULT_$pkg\n"; print "\tselect DEFAULT_$pkg if !TARGET_PER_DEVICE_ROOTFS\n";
print "\tselect MODULE_DEFAULT_$pkg if TARGET_PER_DEVICE_ROOTFS\n";
$defaults{$pkg} = 1; $defaults{$pkg} = 1;
} }
} }
@ -340,8 +356,18 @@ config LINUX_$v
EOF EOF
} }
foreach my $def (sort keys %defaults) { foreach my $def (sort keys %defaults) {
print "\tconfig DEFAULT_".$def."\n"; print <<EOF;
print "\t\tbool\n\n"; config DEFAULT_$def
bool
config MODULE_DEFAULT_$def
tristate
depends on TARGET_PER_DEVICE_ROOTFS
depends on m
default m if DEFAULT_$def
select PACKAGE_$def
EOF
} }
} }