From a4a0faa74890a706e30c3fba74f865b73ac83087 Mon Sep 17 00:00:00 2001 From: Daniel Golle Date: Fri, 7 Jan 2022 17:39:42 +0000 Subject: [PATCH] generic: 5.15: get uImage.FIT partition parser ready Prepare uImage.FIT partition parser for Linux 5.15 Signed-off-by: Daniel Golle Signed-off-by: Ansuel Smith --- .../generic/files/block/partitions/fit.c | 10 ++- ...don-t-reply-on-mtdblock-device-minor.patch | 84 ------------------- .../410-block-fit-partition-parser.patch | 47 +++++------ 3 files changed, 31 insertions(+), 110 deletions(-) delete mode 100644 target/linux/generic/hack-5.15/401-mtd-super-don-t-reply-on-mtdblock-device-minor.patch diff --git a/target/linux/generic/files/block/partitions/fit.c b/target/linux/generic/files/block/partitions/fit.c index 823ee715d..3c9e36f1f 100644 --- a/target/linux/generic/files/block/partitions/fit.c +++ b/target/linux/generic/files/block/partitions/fit.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "check.h" @@ -72,7 +73,12 @@ int parse_fit_partitions(struct parsed_partitions *state, u64 fit_start_sector, u64 sectors, int *slot, int add_remain) { - struct address_space *mapping = state->bdev->bd_inode->i_mapping; +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 11, 0) + struct block_device *bdev = state->disk->part0; +#else + struct block_device *bdev = state->bdev; +#endif + struct address_space *mapping = bdev->bd_inode->i_mapping; struct page *page; void *fit, *init_fit; struct partition_meta_info *info; @@ -107,7 +113,7 @@ int parse_fit_partitions(struct parsed_partitions *state, u64 fit_start_sector, return 0; } - dsectors = get_capacity(state->bdev->bd_disk); + dsectors = get_capacity(bdev->bd_disk); if (sectors) dsectors = (dsectors>sectors)?sectors:dsectors; diff --git a/target/linux/generic/hack-5.15/401-mtd-super-don-t-reply-on-mtdblock-device-minor.patch b/target/linux/generic/hack-5.15/401-mtd-super-don-t-reply-on-mtdblock-device-minor.patch deleted file mode 100644 index 8f985c0b8..000000000 --- a/target/linux/generic/hack-5.15/401-mtd-super-don-t-reply-on-mtdblock-device-minor.patch +++ /dev/null @@ -1,84 +0,0 @@ -From f9760b158f610b1792a222cc924073724c061bfb Mon Sep 17 00:00:00 2001 -From: Daniel Golle -Date: Wed, 7 Apr 2021 22:37:57 +0100 -Subject: [PATCH 1/2] mtd: super: don't reply on mtdblock device minor -To: linux-mtd@lists.infradead.org -Cc: Vignesh Raghavendra , - Richard Weinberger , - Miquel Raynal , - David Woodhouse - -For blktrans devices with partitions (ie. part_bits != 0) the -assumption that the minor number of the mtdblock device matches -the mtdnum doesn't hold true. -Properly resolve mtd device from blktrans layer instead. - -Signed-off-by: Daniel Golle ---- - drivers/mtd/mtdsuper.c | 33 ++++++++++++++++++++++++++------- - 1 file changed, 26 insertions(+), 7 deletions(-) - ---- a/drivers/mtd/mtdsuper.c -+++ b/drivers/mtd/mtdsuper.c -@@ -9,6 +9,7 @@ - */ - - #include -+#include - #include - #include - #include -@@ -120,8 +121,9 @@ int get_tree_mtd(struct fs_context *fc, - struct fs_context *fc)) - { - #ifdef CONFIG_BLOCK -- dev_t dev; -- int ret; -+ struct mtd_blktrans_dev *blktrans_dev; -+ struct block_device *bdev; -+ int ret, part_bits; - #endif - int mtdnr; - -@@ -169,16 +171,36 @@ int get_tree_mtd(struct fs_context *fc, - /* try the old way - the hack where we allowed users to mount - * /dev/mtdblock$(n) but didn't actually _use_ the blockdev - */ -- ret = lookup_bdev(fc->source, &dev); -- if (ret) { -+ bdev = blkdev_get_by_path(fc->source, FMODE_READ, NULL); -+ if (IS_ERR(bdev)) { -+ ret = PTR_ERR(bdev); - errorf(fc, "MTD: Couldn't look up '%s': %d", fc->source, ret); - return ret; - } -- pr_debug("MTDSB: lookup_bdev() returned 0\n"); -+ pr_debug("MTDSB: blkdev_get_by_path() returned 0\n"); - -- if (MAJOR(dev) == MTD_BLOCK_MAJOR) -- return mtd_get_sb_by_nr(fc, MINOR(dev), fill_super); -+ if (MAJOR(bdev->bd_dev) == MTD_BLOCK_MAJOR) { -+ if (!bdev->bd_disk) { -+ blkdev_put(bdev, FMODE_READ); -+ BUG(); -+ return -EINVAL; -+ } - -+ blktrans_dev = (struct mtd_blktrans_dev *)(bdev->bd_disk->private_data); -+ if (!blktrans_dev || !blktrans_dev->tr) { -+ blkdev_put(bdev, FMODE_READ); -+ BUG(); -+ return -EINVAL; -+ } -+ mtdnr = blktrans_dev->devnum; -+ part_bits = blktrans_dev->tr->part_bits; -+ blkdev_put(bdev, FMODE_READ); -+ if (MINOR(bdev->bd_dev) != (mtdnr << part_bits)) -+ return -EINVAL; -+ -+ return mtd_get_sb_by_nr(fc, mtdnr, fill_super); -+ } -+ blkdev_put(bdev, FMODE_READ); - #endif /* CONFIG_BLOCK */ - - if (!(fc->sb_flags & SB_SILENT)) diff --git a/target/linux/generic/hack-5.15/410-block-fit-partition-parser.patch b/target/linux/generic/hack-5.15/410-block-fit-partition-parser.patch index 5edacd5ea..3b36bdee0 100644 --- a/target/linux/generic/hack-5.15/410-block-fit-partition-parser.patch +++ b/target/linux/generic/hack-5.15/410-block-fit-partition-parser.patch @@ -98,30 +98,6 @@ return true; } ---- a/drivers/mtd/ubi/block.c -+++ b/drivers/mtd/ubi/block.c -@@ -428,6 +428,9 @@ int ubiblock_create(struct ubi_volume_in - goto out_cleanup_disk; - } - gd->private_data = dev; -+#ifdef CONFIG_FIT_PARTITION -+ gd->flags |= GENHD_FL_EXT_DEVT; -+#endif - sprintf(gd->disk_name, "ubiblock%d_%d", dev->ubi_num, dev->vol_id); - set_capacity(gd, disk_capacity); - dev->gd = gd; ---- a/drivers/mtd/mtd_blkdevs.c -+++ b/drivers/mtd/mtd_blkdevs.c -@@ -345,6 +345,9 @@ int add_mtd_blktrans_dev(struct mtd_blkt - gd->first_minor = (new->devnum) << tr->part_bits; - gd->minors = 1 << tr->part_bits; - gd->fops = &mtd_block_ops; -+#ifdef CONFIG_FIT_PARTITION -+ gd->flags |= GENHD_FL_EXT_DEVT; -+#endif - - if (tr->part_bits) - if (new->devnum < 26) --- a/block/partitions/efi.c +++ b/block/partitions/efi.c @@ -716,6 +716,9 @@ int efi_partition(struct parsed_partitio @@ -184,6 +160,29 @@ {0, NULL}, }; +--- a/drivers/mtd/mtd_blkdevs.c ++++ b/drivers/mtd/mtd_blkdevs.c +@@ -345,6 +345,8 @@ int add_mtd_blktrans_dev(struct mtd_blkt + gd->first_minor = (new->devnum) << tr->part_bits; + gd->minors = 1 << tr->part_bits; + gd->fops = &mtd_block_ops; ++ if (IS_ENABLED(CONFIG_FIT_PARTITION) && !mtd_type_is_nand(new->mtd)) ++ gd->flags |= GENHD_FL_EXT_DEVT; + + if (tr->part_bits) + if (new->devnum < 26) +--- a/drivers/mtd/ubi/block.c ++++ b/drivers/mtd/ubi/block.c +@@ -428,6 +428,9 @@ int ubiblock_create(struct ubi_volume_in + goto out_cleanup_disk; + } + gd->private_data = dev; ++#ifdef CONFIG_FIT_PARTITION ++ gd->flags |= GENHD_FL_EXT_DEVT; ++#endif + sprintf(gd->disk_name, "ubiblock%d_%d", dev->ubi_num, dev->vol_id); + set_capacity(gd, disk_capacity); + dev->gd = gd; --- a/include/linux/msdos_partition.h +++ b/include/linux/msdos_partition.h @@ -31,6 +31,7 @@ enum msdos_sys_ind {