Creating a copy of the /boot filesystem for an extra partition

This will be needed for Grub2.

Change-Id: Icc5a4e5652101e8746b6796f39ee4aeb5163d45a
diff --git a/package/Config.in b/package/Config.in
index 5b9950d..64d8537 100644
--- a/package/Config.in
+++ b/package/Config.in
@@ -1,3 +1,4 @@
 source "$BR2_EXTERNAL_CZECHLIGHT_PATH/package/cla-sysrepo/Config.in"
 source "$BR2_EXTERNAL_CZECHLIGHT_PATH/package/czechlight-cfg-fs/Config.in"
+source "$BR2_EXTERNAL_CZECHLIGHT_PATH/package/czechlight-separate-boot/Config.in"
 source "$BR2_EXTERNAL_CZECHLIGHT_PATH/package/grub2-tools/Config.in"
diff --git a/package/czechlight-separate-boot/Config.in b/package/czechlight-separate-boot/Config.in
new file mode 100644
index 0000000..0e1bf97
--- /dev/null
+++ b/package/czechlight-separate-boot/Config.in
@@ -0,0 +1,14 @@
+config BR2_TARGET_ROOTFS_CZECHLIGHT_SEPARATE_BOOT
+	bool "Separate /boot partition"
+	help
+	  Builds a standalone ext2 image with the /boot directory from the real rootfs.
+
+if BR2_TARGET_ROOTFS_CZECHLIGHT_SEPARATE_BOOT
+
+config CZECHLIGHT_SEPARATE_BOOT_SIZE
+	string "exact size"
+	default "4M"
+	help
+	  Size of the /boot filesystem image.
+
+endif # BR2_TARGET_ROOTFS_CZECHLIGHT_SEPARATE_BOOT
diff --git a/package/czechlight-separate-boot/czechlight-separate-boot.mk b/package/czechlight-separate-boot/czechlight-separate-boot.mk
new file mode 100644
index 0000000..a41172e
--- /dev/null
+++ b/package/czechlight-separate-boot/czechlight-separate-boot.mk
@@ -0,0 +1,20 @@
+define CZECHLIGHT_SEPARATE_BOOT_SYMLINK_BOOT
+	cd $(TARGET_DIR)/boot
+	ln -s . boot
+endef
+
+ROOTFS_CZECHLIGHT_SEPARATE_BOOT_PRE_GEN_HOOKS += CZECHLIGHT_SEPARATE_BOOT_SYMLINK_BOOT
+
+ROOTFS_CZECHLIGHT_SEPARATE_BOOT_DEPENDENCIES = host-e2fsprogs
+
+define ROOTFS_CZECHLIGHT_SEPARATE_BOOT_CMD
+	rm -f $@
+	$(HOST_DIR)/sbin/mkfs.ext2 -d $(TARGET_DIR)/boot -L /boot $@ \
+		$(call qstrip,$(CZECHLIGHT_SEPARATE_BOOT_SIZE))
+endef
+
+ifeq ($(BR2_TARGET_ROOTFS_CZECHLIGHT_SEPARATE_BOOT)-$(call qstrip,$(CZECHLIGHT_SEPARATE_BOOT_SIZE)),y-)
+$(error CZECHLIGHT_SEPARATE_BOOT_SIZE cannot be empty)
+endif
+
+$(eval $(rootfs))