Skip to content

Commit

Permalink
build: add support for per-device rootfs based on device profile packges
Browse files Browse the repository at this point in the history
Signed-off-by: Felix Fietkau <[email protected]>
  • Loading branch information
nbd168 committed Jul 29, 2016
1 parent c0dceae commit 76341cf
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 13 deletions.
22 changes: 21 additions & 1 deletion include/image-legacy.mk
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ define LegacyDevice/Check
endif
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
$$(_TARGET): legacy-image-$(1)
$$(_TARGET_PREPARE): legacy-image-prepare-$(1)
Expand All @@ -53,10 +62,21 @@ define LegacyDevice/Build
legacy-image-prepare-$(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):
$$(call Image/BuildKernel/Profile,$(1))
$(foreach fs,$(TARGET_FILESYSTEMS),
$$(call Image/Build/Profile,$(1),$(fs))
$$(call Image/Build/Profile/Filesystem,$(1),$(fs),$$(ROOTFS_ID/$(1)))
)

endef
Expand Down
60 changes: 51 additions & 9 deletions include/image.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,19 @@ include $(INCLUDE_DIR)/kernel.mk
include $(INCLUDE_DIR)/host.mk
include $(INCLUDE_DIR)/version.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

ifdef TARGET_PER_DEVICE_ROOTFS
include $(INCLUDE_DIR)/rootfs.mk
endif

override MAKE:=$(_SINGLE)$(SUBMAKE)
override NO_TRACE_MAKE:=$(_SINGLE)$(NO_TRACE_MAKE)

Expand All @@ -21,7 +32,8 @@ param_get = $(patsubst $(1)=%,%,$(filter $(1)=%,$(2)))
param_mangle = $(subst $(space),_,$(strip $(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_TMP=$(KDIR)/tmp
Expand Down Expand Up @@ -240,15 +252,15 @@ 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
- $(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) $(1) -type f -perm /0100 -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) $(1)/tmp $(1)/overlay
chmod 1777 $(1)/tmp
endef

define Image/mkfs/prepare
$(call Image/mkfs/prepare/default)
$(call Image/mkfs/prepare/default,$(1))
endef


Expand All @@ -272,6 +284,23 @@ ifdef CONFIG_TARGET_ROOTFS_CPIOGZ
endef
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
$(call Image/mkfs/$(word 1,$(target_params)),$(target_params))

Expand Down Expand Up @@ -347,6 +376,10 @@ endif

define Device/Check/Common
_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

define Device/Check
Expand Down Expand Up @@ -409,7 +442,16 @@ endef
define Device/Build/image
$$(_TARGET): $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2))
$(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 $$@
[ -f $$(word 1,$$^) -a -f $$(word 2,$$^) ]
$$(call concat_cmd,$(if $(IMAGE/$(2)/$(1)),$(IMAGE/$(2)/$(1)),$(IMAGE/$(2))))
Expand Down Expand Up @@ -493,7 +535,7 @@ define BuildImage
endif

mkfs_prepare: image_prepare
$(call Image/mkfs/prepare)
$(call Image/mkfs/prepare,$(TARGET_DIR))

kernel_prepare: mkfs_prepare
$(call Image/Build/targz)
Expand Down
32 changes: 29 additions & 3 deletions scripts/target-metadata.pl
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,18 @@ ()
target_name($a) cmp target_name($b);
} @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;
choice
Expand Down Expand Up @@ -238,6 +250,9 @@ ()
menu "Target Devices"
depends on TARGET_MULTI_PROFILE
config TARGET_PER_DEVICE_ROOTFS
bool "Use a per-device root filesystem that adds profile packages"
EOF
foreach my $target (@target) {
my $profiles = $target->{profiles};
Expand All @@ -250,7 +265,8 @@ ()
EOF
my @pkglist = merge_package_lists($target->{packages}, $profile->{packages});
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;
}
}
Expand Down Expand Up @@ -340,8 +356,18 @@ ()
EOF
}
foreach my $def (sort keys %defaults) {
print "\tconfig DEFAULT_".$def."\n";
print "\t\tbool\n\n";
print <<EOF;
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
}
}

Expand Down

0 comments on commit 76341cf

Please sign in to comment.