generic: 5.15: get uImage.FIT partition parser ready

Prepare uImage.FIT partition parser for Linux 5.15

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
This commit is contained in:
Daniel Golle 2022-01-07 17:39:42 +00:00
parent 71efd34700
commit 30a5e07390
5 changed files with 31 additions and 149 deletions

View File

@ -20,6 +20,7 @@
#include <linux/of_device.h>
#include <linux/of_fdt.h>
#include <linux/libfdt.h>
#include <linux/version.h>
#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;
@ -116,7 +122,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;

View File

@ -1,84 +0,0 @@
From f9760b158f610b1792a222cc924073724c061bfb Mon Sep 17 00:00:00 2001
From: Daniel Golle <daniel@makrotopia.org>
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 <vigneshr@ti.com>,
Richard Weinberger <richard@nod.at>,
Miquel Raynal <miquel.raynal@bootlin.com>,
David Woodhouse <dwmw2@infradead.org>
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 <daniel@makrotopia.org>
---
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 <linux/mtd/super.h>
+#include <linux/mtd/blktrans.h>
#include <linux/namei.h>
#include <linux/export.h>
#include <linux/ctype.h>
@@ -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))

View File

@ -25,7 +25,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
--- a/drivers/mtd/mtd_blkdevs.c
+++ b/drivers/mtd/mtd_blkdevs.c
@@ -457,13 +457,6 @@ int add_mtd_blktrans_dev(struct mtd_blkt
@@ -384,13 +384,6 @@ int add_mtd_blktrans_dev(struct mtd_blkt
if (new->readonly)
set_disk_ro(gd, 1);
@ -37,9 +37,9 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
- WARN_ON(ret);
- }
return 0;
error4:
kfree(new->tag_set);
@@ -475,6 +468,27 @@ error1:
out_free_tag_set:
@@ -402,6 +395,27 @@ out_list_del:
return ret;
}
@ -77,9 +77,9 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
#include "mtdcore.h"
@@ -851,6 +852,8 @@ int mtd_device_parse_register(struct mtd
register_reboot_notifier(&mtd->reboot_notifier);
}
@@ -1000,6 +1001,8 @@ int mtd_device_parse_register(struct mtd
ret = mtd_otp_nvmem_add(mtd);
+ register_mtd_blktrans_devs();
+

View File

@ -80,10 +80,10 @@
+#ifdef CONFIG_FIT_PARTITION
+ if ((state->parts[p].flags & ADDPART_FLAG_ROOTDEV) && ROOT_DEV == 0)
+ ROOT_DEV = part_to_dev(part)->devt;
+ ROOT_DEV = part->bd_dev;
+
+ if (state->parts[p].flags & ADDPART_FLAG_READONLY)
+ part->policy = true;
+ set_disk_ro(disk, true);
+#endif
+
return true;
@ -91,20 +91,8 @@
--- a/drivers/mtd/ubi/block.c
+++ b/drivers/mtd/ubi/block.c
@@ -396,7 +396,11 @@ int ubiblock_create(struct ubi_volume_in
gd->fops = &ubiblock_ops;
gd->major = ubiblock_major;
+#ifdef CONFIG_FIT_PARTITION
+ gd->minors = 0;
+#else
gd->minors = 1;
+#endif
gd->first_minor = idr_alloc(&ubiblock_minor_idr, dev, 0, 0, GFP_KERNEL);
if (gd->first_minor < 0) {
dev_err(disk_to_dev(gd),
@@ -413,6 +417,9 @@ int ubiblock_create(struct ubi_volume_in
goto out_put_disk;
goto out_cleanup_disk;
}
gd->private_data = dev;
+#ifdef CONFIG_FIT_PARTITION
@ -113,6 +101,18 @@
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_blktrans_dev *new)
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
@@ -706,6 +706,9 @@ int efi_partition(struct parsed_partitio
@ -149,43 +149,6 @@
typedef struct _gpt_header {
__le64 signature;
--- a/drivers/mtd/mtdblock.c
+++ b/drivers/mtd/mtdblock.c
@@ -334,7 +334,11 @@ static void mtdblock_remove_dev(struct m
static struct mtd_blktrans_ops mtdblock_tr = {
.name = "mtdblock",
.major = MTD_BLOCK_MAJOR,
+#ifdef CONFIG_FIT_PARTITION
+ .part_bits = 2,
+#else
.part_bits = 0,
+#endif
.blksize = 512,
.open = mtdblock_open,
.flush = mtdblock_flush,
--- a/drivers/mtd/mtd_blkdevs.c
+++ b/drivers/mtd/mtd_blkdevs.c
@@ -407,18 +407,8 @@ int add_mtd_blktrans_dev(struct mtd_blkt
gd->first_minor = (new->devnum) << tr->part_bits;
gd->fops = &mtd_block_ops;
- if (tr->part_bits)
- if (new->devnum < 26)
- snprintf(gd->disk_name, sizeof(gd->disk_name),
- "%s%c", tr->name, 'a' + new->devnum);
- else
- snprintf(gd->disk_name, sizeof(gd->disk_name),
- "%s%c%c", tr->name,
- 'a' - 1 + new->devnum / 26,
- 'a' + new->devnum % 26);
- else
- snprintf(gd->disk_name, sizeof(gd->disk_name),
- "%s%d", tr->name, new->devnum);
+ snprintf(gd->disk_name, sizeof(gd->disk_name),
+ "%s%d", tr->name, new->devnum);
set_capacity(gd, ((u64)new->size * tr->blksize) >> 9);
--- a/block/partitions/msdos.c
+++ b/block/partitions/msdos.c
@@ -563,6 +563,15 @@ static void parse_minix(struct parsed_pa

View File

@ -20,7 +20,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
#include <linux/nvmem-provider.h>
#include <linux/mtd/mtd.h>
@@ -694,6 +695,19 @@ int add_mtd_device(struct mtd_info *mtd)
@@ -694,6 +695,16 @@ int add_mtd_device(struct mtd_info *mtd)
of this try_ nonsense, and no bitching about it
either. :) */
__module_get(THIS_MODULE);
@ -31,9 +31,6 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
+ unsigned int index = mtd->index;
+ pr_notice("mtd: device %d (%s) set to be root filesystem\n",
+ mtd->index, mtd->name);
+#ifdef CONFIG_FIT_PARTITION
+ index <<= 2;
+#endif
+ ROOT_DEV = MKDEV(MTD_BLOCK_MAJOR, index);
+ }
+