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