Skip to content

Commit eda8bc8

Browse files
committed
generic: backport BLOCK OF support patch
Backport BLOCK OF support patch merged upstream and refresh pending BLOCK patches. This is a new way to declare partition table for BLOCK device (eMMC currently supported) with the use of DTS. Current pending patch are adapted to not cause regression with current downstream implementation of a similar functionality. Also enable the new OF_PARTITION config by default. Signed-off-by: Christian Marangi <[email protected]>
1 parent 343d814 commit eda8bc8

10 files changed

+469
-28
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
From 03cb793b26834ddca170ba87057c8f883772dd45 Mon Sep 17 00:00:00 2001
2+
From: Christian Marangi <[email protected]>
3+
Date: Thu, 3 Oct 2024 00:11:41 +0200
4+
Subject: [PATCH 1/5] block: add support for defining read-only partitions
5+
6+
Add support for defining read-only partitions and complete support for
7+
it in the cmdline partition parser as the additional "ro" after a
8+
partition is scanned but never actually applied.
9+
10+
Signed-off-by: Christian Marangi <[email protected]>
11+
Reviewed-by: Christoph Hellwig <[email protected]>
12+
Link: https://lore.kernel.org/r/[email protected]
13+
Signed-off-by: Jens Axboe <[email protected]>
14+
---
15+
block/blk.h | 1 +
16+
block/partitions/cmdline.c | 3 +++
17+
block/partitions/core.c | 3 +++
18+
3 files changed, 7 insertions(+)
19+
20+
--- a/block/blk.h
21+
+++ b/block/blk.h
22+
@@ -424,6 +424,7 @@ void blk_free_ext_minor(unsigned int min
23+
#define ADDPART_FLAG_NONE 0
24+
#define ADDPART_FLAG_RAID 1
25+
#define ADDPART_FLAG_WHOLEDISK 2
26+
+#define ADDPART_FLAG_READONLY 4
27+
int bdev_add_partition(struct gendisk *disk, int partno, sector_t start,
28+
sector_t length);
29+
int bdev_del_partition(struct gendisk *disk, int partno);
30+
--- a/block/partitions/cmdline.c
31+
+++ b/block/partitions/cmdline.c
32+
@@ -237,6 +237,9 @@ static int add_part(int slot, struct cmd
33+
put_partition(state, slot, subpart->from >> 9,
34+
subpart->size >> 9);
35+
36+
+ if (subpart->flags & PF_RDONLY)
37+
+ state->parts[slot].flags |= ADDPART_FLAG_READONLY;
38+
+
39+
info = &state->parts[slot].info;
40+
41+
strscpy(info->volname, subpart->name, sizeof(info->volname));
42+
--- a/block/partitions/core.c
43+
+++ b/block/partitions/core.c
44+
@@ -392,6 +392,9 @@ static struct block_device *add_partitio
45+
goto out_del;
46+
}
47+
48+
+ if (flags & ADDPART_FLAG_READONLY)
49+
+ bdev->bd_read_only = true;
50+
+
51+
/* everything is up and running, commence */
52+
err = xa_insert(&disk->part_tbl, partno, bdev, GFP_KERNEL);
53+
if (err)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
From e5f587242b6072ffab4f4a084a459a59f3035873 Mon Sep 17 00:00:00 2001
2+
From: Christian Marangi <[email protected]>
3+
Date: Thu, 3 Oct 2024 00:11:43 +0200
4+
Subject: [PATCH 3/5] block: introduce add_disk_fwnode()
5+
6+
Introduce add_disk_fwnode() as a replacement of device_add_disk() that
7+
permits to pass and attach a fwnode to disk dev.
8+
9+
This variant can be useful for eMMC that might have the partition table
10+
for the disk defined in DT. A parser can later make use of the attached
11+
fwnode to parse the related table and init the hardcoded partition for
12+
the disk.
13+
14+
device_add_disk() is converted to a simple wrapper of add_disk_fwnode()
15+
with the fwnode entry set as NULL.
16+
17+
Signed-off-by: Christian Marangi <[email protected]>
18+
Reviewed-by: Christoph Hellwig <[email protected]>
19+
Link: https://lore.kernel.org/r/[email protected]
20+
Signed-off-by: Jens Axboe <[email protected]>
21+
---
22+
block/genhd.c | 28 ++++++++++++++++++++++++----
23+
include/linux/blkdev.h | 3 +++
24+
2 files changed, 27 insertions(+), 4 deletions(-)
25+
26+
--- a/block/genhd.c
27+
+++ b/block/genhd.c
28+
@@ -383,16 +383,18 @@ int disk_scan_partitions(struct gendisk
29+
}
30+
31+
/**
32+
- * device_add_disk - add disk information to kernel list
33+
+ * add_disk_fwnode - add disk information to kernel list with fwnode
34+
* @parent: parent device for the disk
35+
* @disk: per-device partitioning information
36+
* @groups: Additional per-device sysfs groups
37+
+ * @fwnode: attached disk fwnode
38+
*
39+
* This function registers the partitioning information in @disk
40+
- * with the kernel.
41+
+ * with the kernel. Also attach a fwnode to the disk device.
42+
*/
43+
-int __must_check device_add_disk(struct device *parent, struct gendisk *disk,
44+
- const struct attribute_group **groups)
45+
+int __must_check add_disk_fwnode(struct device *parent, struct gendisk *disk,
46+
+ const struct attribute_group **groups,
47+
+ struct fwnode_handle *fwnode)
48+
49+
{
50+
struct device *ddev = disk_to_dev(disk);
51+
@@ -451,6 +453,8 @@ int __must_check device_add_disk(struct
52+
ddev->parent = parent;
53+
ddev->groups = groups;
54+
dev_set_name(ddev, "%s", disk->disk_name);
55+
+ if (fwnode)
56+
+ device_set_node(ddev, fwnode);
57+
if (!(disk->flags & GENHD_FL_HIDDEN))
58+
ddev->devt = MKDEV(disk->major, disk->first_minor);
59+
ret = device_add(ddev);
60+
@@ -552,6 +556,22 @@ out_exit_elevator:
61+
elevator_exit(disk->queue);
62+
return ret;
63+
}
64+
+EXPORT_SYMBOL_GPL(add_disk_fwnode);
65+
+
66+
+/**
67+
+ * device_add_disk - add disk information to kernel list
68+
+ * @parent: parent device for the disk
69+
+ * @disk: per-device partitioning information
70+
+ * @groups: Additional per-device sysfs groups
71+
+ *
72+
+ * This function registers the partitioning information in @disk
73+
+ * with the kernel.
74+
+ */
75+
+int __must_check device_add_disk(struct device *parent, struct gendisk *disk,
76+
+ const struct attribute_group **groups)
77+
+{
78+
+ return add_disk_fwnode(parent, disk, groups, NULL);
79+
+}
80+
EXPORT_SYMBOL(device_add_disk);
81+
82+
static void blk_report_disk_dead(struct gendisk *disk, bool surprise)
83+
--- a/include/linux/blkdev.h
84+
+++ b/include/linux/blkdev.h
85+
@@ -741,6 +741,9 @@ static inline unsigned int blk_queue_dep
86+
#define for_each_bio(_bio) \
87+
for (; _bio; _bio = _bio->bi_next)
88+
89+
+int __must_check add_disk_fwnode(struct device *parent, struct gendisk *disk,
90+
+ const struct attribute_group **groups,
91+
+ struct fwnode_handle *fwnode);
92+
int __must_check device_add_disk(struct device *parent, struct gendisk *disk,
93+
const struct attribute_group **groups);
94+
static inline int __must_check add_disk(struct gendisk *disk)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
From 45ff6c340ddfc2dade74d5b7a8962c778ab7042c Mon Sep 17 00:00:00 2001
2+
From: Christian Marangi <[email protected]>
3+
Date: Thu, 3 Oct 2024 00:11:44 +0200
4+
Subject: [PATCH 4/5] mmc: block: attach partitions fwnode if found in mmc-card
5+
6+
Attach partitions fwnode if found in mmc-card and register disk with it.
7+
8+
This permits block partition to reference the node and register a
9+
partition table defined in DT for the special case for embedded device
10+
that doesn't have a partition table flashed but have an hardcoded
11+
partition table passed from the system.
12+
13+
JEDEC BOOT partition boot0/boot1 are supported but in DT we refer with
14+
the JEDEC name of boot1 and boot2 to better adhere to documentation.
15+
16+
Also JEDEC GP partition gp0/1/2/3 are supported but in DT we refer with
17+
the JEDEC name of gp1/2/3/4 to better adhere to documentration.
18+
19+
Signed-off-by: Christian Marangi <[email protected]>
20+
Reviewed-by: Linus Walleij <[email protected]>
21+
Link: https://lore.kernel.org/r/[email protected]
22+
Signed-off-by: Jens Axboe <[email protected]>
23+
---
24+
drivers/mmc/core/block.c | 55 +++++++++++++++++++++++++++++++++++++++-
25+
1 file changed, 54 insertions(+), 1 deletion(-)
26+
27+
--- a/drivers/mmc/core/block.c
28+
+++ b/drivers/mmc/core/block.c
29+
@@ -2455,6 +2455,56 @@ static inline int mmc_blk_readonly(struc
30+
!(card->csd.cmdclass & CCC_BLOCK_WRITE);
31+
}
32+
33+
+/*
34+
+ * Search for a declared partitions node for the disk in mmc-card related node.
35+
+ *
36+
+ * This is to permit support for partition table defined in DT in special case
37+
+ * where a partition table is not written in the disk and is expected to be
38+
+ * passed from the running system.
39+
+ *
40+
+ * For the user disk, "partitions" node is searched.
41+
+ * For the special HW disk, "partitions-" node with the appended name is used
42+
+ * following this conversion table (to adhere to JEDEC naming)
43+
+ * - boot0 -> partitions-boot1
44+
+ * - boot1 -> partitions-boot2
45+
+ * - gp0 -> partitions-gp1
46+
+ * - gp1 -> partitions-gp2
47+
+ * - gp2 -> partitions-gp3
48+
+ * - gp3 -> partitions-gp4
49+
+ */
50+
+static struct fwnode_handle *mmc_blk_get_partitions_node(struct device *mmc_dev,
51+
+ const char *subname)
52+
+{
53+
+ const char *node_name = "partitions";
54+
+
55+
+ if (subname) {
56+
+ mmc_dev = mmc_dev->parent;
57+
+
58+
+ /*
59+
+ * Check if we are allocating a BOOT disk boot0/1 disk.
60+
+ * In DT we use the JEDEC naming boot1/2.
61+
+ */
62+
+ if (!strcmp(subname, "boot0"))
63+
+ node_name = "partitions-boot1";
64+
+ if (!strcmp(subname, "boot1"))
65+
+ node_name = "partitions-boot2";
66+
+ /*
67+
+ * Check if we are allocating a GP disk gp0/1/2/3 disk.
68+
+ * In DT we use the JEDEC naming gp1/2/3/4.
69+
+ */
70+
+ if (!strcmp(subname, "gp0"))
71+
+ node_name = "partitions-gp1";
72+
+ if (!strcmp(subname, "gp1"))
73+
+ node_name = "partitions-gp2";
74+
+ if (!strcmp(subname, "gp2"))
75+
+ node_name = "partitions-gp3";
76+
+ if (!strcmp(subname, "gp3"))
77+
+ node_name = "partitions-gp4";
78+
+ }
79+
+
80+
+ return device_get_named_child_node(mmc_dev, node_name);
81+
+}
82+
+
83+
static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card,
84+
struct device *parent,
85+
sector_t size,
86+
@@ -2463,6 +2513,7 @@ static struct mmc_blk_data *mmc_blk_allo
87+
int area_type,
88+
unsigned int part_type)
89+
{
90+
+ struct fwnode_handle *disk_fwnode;
91+
struct mmc_blk_data *md;
92+
int devidx, ret;
93+
char cap_str[10];
94+
@@ -2568,7 +2619,9 @@ static struct mmc_blk_data *mmc_blk_allo
95+
/* used in ->open, must be set before add_disk: */
96+
if (area_type == MMC_BLK_DATA_AREA_MAIN)
97+
dev_set_drvdata(&card->dev, md);
98+
- ret = device_add_disk(md->parent, md->disk, mmc_disk_attr_groups);
99+
+ disk_fwnode = mmc_blk_get_partitions_node(parent, subname);
100+
+ ret = add_disk_fwnode(md->parent, md->disk, mmc_disk_attr_groups,
101+
+ disk_fwnode);
102+
if (ret)
103+
goto err_put_disk;
104+
return md;

0 commit comments

Comments
 (0)