aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/generic/hack-5.4
diff options
context:
space:
mode:
authorDaniel Golle <daniel@makrotopia.org>2021-02-15 14:37:17 +0000
committerDaniel Golle <daniel@makrotopia.org>2021-02-24 01:35:20 +0000
commite6aac8d98f5663be99163f9e61dad23ad657b7ed (patch)
treee380522a134bab0afe6d9058d5cd8613fb2d4cf7 /target/linux/generic/hack-5.4
parentfb83efb626491e4e0de79429041ea7792db337d4 (diff)
downloadupstream-e6aac8d98f5663be99163f9e61dad23ad657b7ed.tar.gz
upstream-e6aac8d98f5663be99163f9e61dad23ad657b7ed.tar.bz2
upstream-e6aac8d98f5663be99163f9e61dad23ad657b7ed.zip
image: add support for building FIT image with filesystem
Allow for single (external-data) FIT image to hold kernel, dtb and squashfs. In that way, the bootloader verifies the system integrity including the rootfs, because what's the point of checking that the hash of the kernel is correct if it won't boot in case of squashfs being corrupted? Better allow bootloader to check everything needed to make it at least up to failsafe mode. As a positive side effect this change also makes the sysupgrade process on nand potentially much easier as it is now. In short: mkimage has a parameter '-E' which allows generating FIT images with 'external' data rather than embedding the data into the device-tree blob itself. In this way, the FIT structure itself remains small and can be parsed easily (rather than having to page around megabytes of image content). This patch makes use of that and adds support for adding sub-images of type 'filesystem' which are used to store the squashfs. Now U-Boot can verify the whole OS and the new partition parsers added in the Linux kernel can detect the filesystem sub-images, create partitions for them, and select the active rootfs volume based on the configuration in FIT (passing configuration via device tree could be implemented easily at a later stage). This new FIT partition parser works for NOR flash (on top of mtdblock), NAND flash (on top of ubiblock) as well as classic block devices (ie. eMMC, SDcard, SATA, NVME, ...). It could even be used to mount such FIT images via `losetup -P` on a user PC if this patch gets included in Linux upstream one day ;) Signed-off-by: John Crispin <john@phrozen.org> Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Diffstat (limited to 'target/linux/generic/hack-5.4')
-rw-r--r--target/linux/generic/hack-5.4/400-block-fit-partition-parser.patch99
1 files changed, 99 insertions, 0 deletions
diff --git a/target/linux/generic/hack-5.4/400-block-fit-partition-parser.patch b/target/linux/generic/hack-5.4/400-block-fit-partition-parser.patch
new file mode 100644
index 0000000000..13cf5e8ca0
--- /dev/null
+++ b/target/linux/generic/hack-5.4/400-block-fit-partition-parser.patch
@@ -0,0 +1,99 @@
+--- a/block/partitions/Kconfig
++++ b/block/partitions/Kconfig
+@@ -101,6 +101,13 @@ config ATARI_PARTITION
+ Say Y here if you would like to use hard disks under Linux which
+ were partitioned under the Atari OS.
+
++config FIT_PARTITION
++ bool "Flattened-Image-Tree (FIT) partition support" if PARTITION_ADVANCED
++ default n
++ help
++ Say Y here if your system needs to mount the filesystem part of
++ a Flattened-Image-Tree (FIT) image commonly used with Das U-Boot.
++
+ config IBM_PARTITION
+ bool "IBM disk label and partition support"
+ depends on PARTITION_ADVANCED && S390
+--- a/block/partitions/Makefile
++++ b/block/partitions/Makefile
+@@ -9,6 +9,7 @@ obj-$(CONFIG_ACORN_PARTITION) += acorn.o
+ obj-$(CONFIG_AMIGA_PARTITION) += amiga.o
+ obj-$(CONFIG_ATARI_PARTITION) += atari.o
+ obj-$(CONFIG_AIX_PARTITION) += aix.o
++obj-$(CONFIG_FIT_PARTITION) += fit.o
+ obj-$(CONFIG_CMDLINE_PARTITION) += cmdline.o
+ obj-$(CONFIG_MAC_PARTITION) += mac.o
+ obj-$(CONFIG_LDM_PARTITION) += ldm.o
+--- a/drivers/mtd/ubi/block.c
++++ b/drivers/mtd/ubi/block.c
+@@ -396,7 +396,7 @@ int ubiblock_create(struct ubi_volume_in
+ dev->leb_size = vi->usable_leb_size;
+
+ /* Initialize the gendisk of this ubiblock device */
+- gd = alloc_disk(1);
++ gd = alloc_disk(0);
+ if (!gd) {
+ pr_err("UBI: block: alloc_disk failed\n");
+ ret = -ENODEV;
+@@ -413,6 +413,7 @@ int ubiblock_create(struct ubi_volume_in
+ goto out_put_disk;
+ }
+ gd->private_data = dev;
++ gd->flags |= GENHD_FL_EXT_DEVT;
+ sprintf(gd->disk_name, "ubiblock%d_%d", dev->ubi_num, dev->vol_id);
+ set_capacity(gd, disk_capacity);
+ dev->gd = gd;
+--- a/block/partition-generic.c
++++ b/block/partition-generic.c
+@@ -18,6 +18,7 @@
+ #include <linux/ctype.h>
+ #include <linux/genhd.h>
+ #include <linux/blktrace_api.h>
++#include <linux/root_dev.h>
+
+ #include "partitions/check.h"
+
+@@ -634,6 +635,8 @@ rescan:
+ if (state->parts[p].flags & ADDPART_FLAG_RAID)
+ md_autodetect_dev(part_to_dev(part)->devt);
+ #endif
++ if ((state->parts[p].flags & ADDPART_FLAG_ROOTDEV) && ROOT_DEV == 0)
++ ROOT_DEV = part_to_dev(part)->devt;
+ }
+ free_partitions(state);
+ return 0;
+--- a/block/partitions/check.c
++++ b/block/partitions/check.c
+@@ -33,6 +33,7 @@
+ #include "ibm.h"
+ #include "ultrix.h"
+ #include "efi.h"
++#include "fit.h"
+ #include "karma.h"
+ #include "sysv68.h"
+ #include "cmdline.h"
+@@ -73,6 +74,9 @@ static int (*check_part[])(struct parsed
+ #ifdef CONFIG_EFI_PARTITION
+ efi_partition, /* this must come before msdos */
+ #endif
++#ifdef CONFIG_FIT_PARTITION
++ fit_partition,
++#endif
+ #ifdef CONFIG_SGI_PARTITION
+ sgi_partition,
+ #endif
+--- a/include/linux/genhd.h
++++ b/include/linux/genhd.h
+@@ -614,6 +614,7 @@ struct unixware_disklabel {
+ #define ADDPART_FLAG_NONE 0
+ #define ADDPART_FLAG_RAID 1
+ #define ADDPART_FLAG_WHOLEDISK 2
++#define ADDPART_FLAG_ROOTDEV 4
+
+ extern int blk_alloc_devt(struct hd_struct *part, dev_t *devt);
+ extern void blk_free_devt(dev_t devt);
+--- /dev/null
++++ b/block/partitions/fit.h
+@@ -0,0 +1,2 @@
++/* SPDX-License-Identifier: GPL-2.0 */
++int fit_partition(struct parsed_partitions *);