13a16b6fa0824044f19073e8b3ae495f286b45b3
[openwrt/staging/jow.git] / target / linux / mediatek / patches-5.15 / 041-block-fit-partition-parser.patch
1 From 69357074558daf6ff24c9f58714935e9e095a865 Mon Sep 17 00:00:00 2001
2 From: OpenWrt community <openwrt-devel@lists.openwrt.org>
3 Date: Wed, 13 Jul 2022 13:37:33 +0200
4 Subject: [PATCH] kernel: add block fit partition parser
5
6 ---
7 block/blk.h | 2 ++
8 block/partitions/Kconfig | 7 +++++++
9 block/partitions/Makefile | 1 +
10 block/partitions/check.h | 3 +++
11 block/partitions/core.c | 17 +++++++++++++++++
12 block/partitions/efi.c | 8 ++++++++
13 block/partitions/efi.h | 3 +++
14 block/partitions/msdos.c | 10 ++++++++++
15 drivers/mtd/mtd_blkdevs.c | 2 ++
16 drivers/mtd/ubi/block.c | 3 +++
17 include/linux/msdos_partition.h | 1 +
18 11 files changed, 57 insertions(+)
19
20 --- a/block/blk.h
21 +++ b/block/blk.h
22 @@ -354,6 +354,8 @@ 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 +#define ADDPART_FLAG_ROOTDEV 8
28 int bdev_add_partition(struct gendisk *disk, int partno, sector_t start,
29 sector_t length);
30 int bdev_del_partition(struct gendisk *disk, int partno);
31 --- a/block/partitions/Kconfig
32 +++ b/block/partitions/Kconfig
33 @@ -101,6 +101,13 @@ config ATARI_PARTITION
34 Say Y here if you would like to use hard disks under Linux which
35 were partitioned under the Atari OS.
36
37 +config FIT_PARTITION
38 + bool "Flattened-Image-Tree (FIT) partition support" if PARTITION_ADVANCED
39 + default n
40 + help
41 + Say Y here if your system needs to mount the filesystem part of
42 + a Flattened-Image-Tree (FIT) image commonly used with Das U-Boot.
43 +
44 config IBM_PARTITION
45 bool "IBM disk label and partition support"
46 depends on PARTITION_ADVANCED && S390
47 --- a/block/partitions/Makefile
48 +++ b/block/partitions/Makefile
49 @@ -8,6 +8,7 @@ obj-$(CONFIG_ACORN_PARTITION) += acorn.o
50 obj-$(CONFIG_AMIGA_PARTITION) += amiga.o
51 obj-$(CONFIG_ATARI_PARTITION) += atari.o
52 obj-$(CONFIG_AIX_PARTITION) += aix.o
53 +obj-$(CONFIG_FIT_PARTITION) += fit.o
54 obj-$(CONFIG_CMDLINE_PARTITION) += cmdline.o
55 obj-$(CONFIG_MAC_PARTITION) += mac.o
56 obj-$(CONFIG_LDM_PARTITION) += ldm.o
57 --- a/block/partitions/check.h
58 +++ b/block/partitions/check.h
59 @@ -58,6 +58,7 @@ int amiga_partition(struct parsed_partit
60 int atari_partition(struct parsed_partitions *state);
61 int cmdline_partition(struct parsed_partitions *state);
62 int efi_partition(struct parsed_partitions *state);
63 +int fit_partition(struct parsed_partitions *state);
64 int ibm_partition(struct parsed_partitions *);
65 int karma_partition(struct parsed_partitions *state);
66 int ldm_partition(struct parsed_partitions *state);
67 @@ -68,3 +69,5 @@ int sgi_partition(struct parsed_partitio
68 int sun_partition(struct parsed_partitions *state);
69 int sysv68_partition(struct parsed_partitions *state);
70 int ultrix_partition(struct parsed_partitions *state);
71 +
72 +int parse_fit_partitions(struct parsed_partitions *state, u64 start_sector, u64 nr_sectors, int *slot, int add_remain);
73 --- a/block/partitions/core.c
74 +++ b/block/partitions/core.c
75 @@ -12,6 +12,10 @@
76 #include <linux/vmalloc.h>
77 #include <linux/blktrace_api.h>
78 #include <linux/raid/detect.h>
79 +#ifdef CONFIG_FIT_PARTITION
80 +#include <linux/root_dev.h>
81 +#endif
82 +
83 #include "check.h"
84
85 static int (*check_part[])(struct parsed_partitions *) = {
86 @@ -48,6 +52,9 @@ static int (*check_part[])(struct parsed
87 #ifdef CONFIG_EFI_PARTITION
88 efi_partition, /* this must come before msdos */
89 #endif
90 +#ifdef CONFIG_FIT_PARTITION
91 + fit_partition,
92 +#endif
93 #ifdef CONFIG_SGI_PARTITION
94 sgi_partition,
95 #endif
96 @@ -408,6 +415,11 @@ static struct block_device *add_partitio
97 goto out_del;
98 }
99
100 +#ifdef CONFIG_FIT_PARTITION
101 + if (flags & ADDPART_FLAG_READONLY)
102 + bdev->bd_read_only = true;
103 +#endif
104 +
105 /* everything is up and running, commence */
106 err = xa_insert(&disk->part_tbl, partno, bdev, GFP_KERNEL);
107 if (err)
108 @@ -595,6 +607,11 @@ static bool blk_add_partition(struct gen
109 (state->parts[p].flags & ADDPART_FLAG_RAID))
110 md_autodetect_dev(part->bd_dev);
111
112 +#ifdef CONFIG_FIT_PARTITION
113 + if ((state->parts[p].flags & ADDPART_FLAG_ROOTDEV) && ROOT_DEV == 0)
114 + ROOT_DEV = part->bd_dev;
115 +#endif
116 +
117 return true;
118 }
119
120 --- a/block/partitions/efi.c
121 +++ b/block/partitions/efi.c
122 @@ -716,6 +716,9 @@ int efi_partition(struct parsed_partitio
123 gpt_entry *ptes = NULL;
124 u32 i;
125 unsigned ssz = queue_logical_block_size(state->disk->queue) / 512;
126 +#ifdef CONFIG_FIT_PARTITION
127 + u32 extra_slot = 64;
128 +#endif
129
130 if (!find_valid_gpt(state, &gpt, &ptes) || !gpt || !ptes) {
131 kfree(gpt);
132 @@ -749,6 +752,11 @@ int efi_partition(struct parsed_partitio
133 ARRAY_SIZE(ptes[i].partition_name));
134 utf16_le_to_7bit(ptes[i].partition_name, label_max, info->volname);
135 state->parts[i + 1].has_info = true;
136 +#ifdef CONFIG_FIT_PARTITION
137 + /* If this is a U-Boot FIT volume it may have subpartitions */
138 + if (!efi_guidcmp(ptes[i].partition_type_guid, PARTITION_LINUX_FIT_GUID))
139 + (void) parse_fit_partitions(state, start * ssz, size * ssz, &extra_slot, 1);
140 +#endif
141 }
142 kfree(ptes);
143 kfree(gpt);
144 --- a/block/partitions/efi.h
145 +++ b/block/partitions/efi.h
146 @@ -52,6 +52,9 @@
147 #define PARTITION_LINUX_LVM_GUID \
148 EFI_GUID( 0xe6d6d379, 0xf507, 0x44c2, \
149 0xa2, 0x3c, 0x23, 0x8f, 0x2a, 0x3d, 0xf9, 0x28)
150 +#define PARTITION_LINUX_FIT_GUID \
151 + EFI_GUID( 0xcae9be83, 0xb15f, 0x49cc, \
152 + 0x86, 0x3f, 0x08, 0x1b, 0x74, 0x4a, 0x2d, 0x93)
153
154 typedef struct _gpt_header {
155 __le64 signature;
156 --- a/block/partitions/msdos.c
157 +++ b/block/partitions/msdos.c
158 @@ -564,6 +564,15 @@ static void parse_minix(struct parsed_pa
159 #endif /* CONFIG_MINIX_SUBPARTITION */
160 }
161
162 +static void parse_fit_mbr(struct parsed_partitions *state,
163 + sector_t offset, sector_t size, int origin)
164 +{
165 +#ifdef CONFIG_FIT_PARTITION
166 + u32 extra_slot = 64;
167 + (void) parse_fit_partitions(state, offset, size, &extra_slot, 1);
168 +#endif /* CONFIG_FIT_PARTITION */
169 +}
170 +
171 static struct {
172 unsigned char id;
173 void (*parse)(struct parsed_partitions *, sector_t, sector_t, int);
174 @@ -575,6 +584,7 @@ static struct {
175 {UNIXWARE_PARTITION, parse_unixware},
176 {SOLARIS_X86_PARTITION, parse_solaris_x86},
177 {NEW_SOLARIS_X86_PARTITION, parse_solaris_x86},
178 + {FIT_PARTITION, parse_fit_mbr},
179 {0, NULL},
180 };
181
182 --- a/drivers/mtd/mtd_blkdevs.c
183 +++ b/drivers/mtd/mtd_blkdevs.c
184 @@ -345,6 +345,8 @@ int add_mtd_blktrans_dev(struct mtd_blkt
185 gd->first_minor = (new->devnum) << tr->part_bits;
186 gd->minors = 1 << tr->part_bits;
187 gd->fops = &mtd_block_ops;
188 + if (IS_ENABLED(CONFIG_FIT_PARTITION) && !mtd_type_is_nand(new->mtd))
189 + gd->flags |= GENHD_FL_EXT_DEVT;
190
191 if (tr->part_bits)
192 if (new->devnum < 26)
193 --- a/drivers/mtd/ubi/block.c
194 +++ b/drivers/mtd/ubi/block.c
195 @@ -428,6 +428,9 @@ int ubiblock_create(struct ubi_volume_in
196 goto out_cleanup_disk;
197 }
198 gd->private_data = dev;
199 +#ifdef CONFIG_FIT_PARTITION
200 + gd->flags |= GENHD_FL_EXT_DEVT;
201 +#endif
202 sprintf(gd->disk_name, "ubiblock%d_%d", dev->ubi_num, dev->vol_id);
203 set_capacity(gd, disk_capacity);
204 dev->gd = gd;
205 --- a/include/linux/msdos_partition.h
206 +++ b/include/linux/msdos_partition.h
207 @@ -31,6 +31,7 @@ enum msdos_sys_ind {
208 LINUX_LVM_PARTITION = 0x8e,
209 LINUX_RAID_PARTITION = 0xfd, /* autodetect RAID partition */
210
211 + FIT_PARTITION = 0x2e, /* U-Boot uImage.FIT */
212 SOLARIS_X86_PARTITION = 0x82, /* also Linux swap partitions */
213 NEW_SOLARIS_X86_PARTITION = 0xbf,
214