mediatek: copy patches-6.1 to patches-6.6
[openwrt/staging/stintel.git] / target / linux / mediatek / patches-6.6 / 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 @@ -414,6 +414,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 @@ -103,6 +103,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 @@ -57,6 +57,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 @@ -67,3 +68,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 @@ -11,6 +11,9 @@
76 #include <linux/vmalloc.h>
77 #include <linux/raid/detect.h>
78 #include <linux/property.h>
79 +#ifdef CONFIG_FIT_PARTITION
80 +#include <linux/root_dev.h>
81 +#endif
82
83 #include "check.h"
84
85 @@ -48,6 +51,9 @@ static int (*check_part[])(struct parsed
86 #ifdef CONFIG_EFI_PARTITION
87 efi_partition, /* this must come before msdos */
88 #endif
89 +#ifdef CONFIG_FIT_PARTITION
90 + fit_partition,
91 +#endif
92 #ifdef CONFIG_SGI_PARTITION
93 sgi_partition,
94 #endif
95 @@ -439,6 +445,11 @@ static struct block_device *add_partitio
96 goto out_del;
97 }
98
99 +#ifdef CONFIG_FIT_PARTITION
100 + if (flags & ADDPART_FLAG_READONLY)
101 + bdev->bd_read_only = true;
102 +#endif
103 +
104 /* everything is up and running, commence */
105 err = xa_insert(&disk->part_tbl, partno, bdev, GFP_KERNEL);
106 if (err)
107 @@ -631,6 +642,11 @@ static bool blk_add_partition(struct gen
108 (state->parts[p].flags & ADDPART_FLAG_RAID))
109 md_autodetect_dev(part->bd_dev);
110
111 +#ifdef CONFIG_FIT_PARTITION
112 + if ((state->parts[p].flags & ADDPART_FLAG_ROOTDEV) && ROOT_DEV == 0)
113 + ROOT_DEV = part->bd_dev;
114 +#endif
115 +
116 return true;
117 }
118
119 --- a/block/partitions/efi.c
120 +++ b/block/partitions/efi.c
121 @@ -716,6 +716,9 @@ int efi_partition(struct parsed_partitio
122 gpt_entry *ptes = NULL;
123 u32 i;
124 unsigned ssz = queue_logical_block_size(state->disk->queue) / 512;
125 +#ifdef CONFIG_FIT_PARTITION
126 + u32 extra_slot = 64;
127 +#endif
128
129 if (!find_valid_gpt(state, &gpt, &ptes) || !gpt || !ptes) {
130 kfree(gpt);
131 @@ -749,6 +752,11 @@ int efi_partition(struct parsed_partitio
132 ARRAY_SIZE(ptes[i].partition_name));
133 utf16_le_to_7bit(ptes[i].partition_name, label_max, info->volname);
134 state->parts[i + 1].has_info = true;
135 +#ifdef CONFIG_FIT_PARTITION
136 + /* If this is a U-Boot FIT volume it may have subpartitions */
137 + if (!efi_guidcmp(ptes[i].partition_type_guid, PARTITION_LINUX_FIT_GUID))
138 + (void) parse_fit_partitions(state, start * ssz, size * ssz, &extra_slot, 1);
139 +#endif
140 }
141 kfree(ptes);
142 kfree(gpt);
143 --- a/block/partitions/efi.h
144 +++ b/block/partitions/efi.h
145 @@ -51,6 +51,9 @@
146 #define PARTITION_LINUX_LVM_GUID \
147 EFI_GUID( 0xe6d6d379, 0xf507, 0x44c2, \
148 0xa2, 0x3c, 0x23, 0x8f, 0x2a, 0x3d, 0xf9, 0x28)
149 +#define PARTITION_LINUX_FIT_GUID \
150 + EFI_GUID( 0xcae9be83, 0xb15f, 0x49cc, \
151 + 0x86, 0x3f, 0x08, 0x1b, 0x74, 0x4a, 0x2d, 0x93)
152
153 typedef struct _gpt_header {
154 __le64 signature;
155 --- a/block/partitions/msdos.c
156 +++ b/block/partitions/msdos.c
157 @@ -564,6 +564,15 @@ static void parse_minix(struct parsed_pa
158 #endif /* CONFIG_MINIX_SUBPARTITION */
159 }
160
161 +static void parse_fit_mbr(struct parsed_partitions *state,
162 + sector_t offset, sector_t size, int origin)
163 +{
164 +#ifdef CONFIG_FIT_PARTITION
165 + u32 extra_slot = 64;
166 + (void) parse_fit_partitions(state, offset, size, &extra_slot, 1);
167 +#endif /* CONFIG_FIT_PARTITION */
168 +}
169 +
170 static struct {
171 unsigned char id;
172 void (*parse)(struct parsed_partitions *, sector_t, sector_t, int);
173 @@ -575,6 +584,7 @@ static struct {
174 {UNIXWARE_PARTITION, parse_unixware},
175 {SOLARIS_X86_PARTITION, parse_solaris_x86},
176 {NEW_SOLARIS_X86_PARTITION, parse_solaris_x86},
177 + {FIT_PARTITION, parse_fit_mbr},
178 {0, NULL},
179 };
180
181 --- a/drivers/mtd/mtd_blkdevs.c
182 +++ b/drivers/mtd/mtd_blkdevs.c
183 @@ -359,7 +359,9 @@ int add_mtd_blktrans_dev(struct mtd_blkt
184 } else {
185 snprintf(gd->disk_name, sizeof(gd->disk_name),
186 "%s%d", tr->name, new->devnum);
187 - gd->flags |= GENHD_FL_NO_PART;
188 +
189 + if (!IS_ENABLED(CONFIG_FIT_PARTITION) || mtd_type_is_nand(new->mtd))
190 + gd->flags |= GENHD_FL_NO_PART;
191 }
192
193 set_capacity(gd, ((u64)new->size * tr->blksize) >> 9);
194 --- a/drivers/mtd/ubi/block.c
195 +++ b/drivers/mtd/ubi/block.c
196 @@ -432,7 +432,9 @@ int ubiblock_create(struct ubi_volume_in
197 ret = -ENODEV;
198 goto out_cleanup_disk;
199 }
200 - gd->flags |= GENHD_FL_NO_PART;
201 + if (!IS_ENABLED(CONFIG_FIT_PARTITION))
202 + gd->flags |= GENHD_FL_NO_PART;
203 +
204 gd->private_data = dev;
205 sprintf(gd->disk_name, "ubiblock%d_%d", dev->ubi_num, dev->vol_id);
206 set_capacity(gd, disk_capacity);
207 --- a/include/linux/msdos_partition.h
208 +++ b/include/linux/msdos_partition.h
209 @@ -31,6 +31,7 @@ enum msdos_sys_ind {
210 LINUX_LVM_PARTITION = 0x8e,
211 LINUX_RAID_PARTITION = 0xfd, /* autodetect RAID partition */
212
213 + FIT_PARTITION = 0x2e, /* U-Boot uImage.FIT */
214 SOLARIS_X86_PARTITION = 0x82, /* also Linux swap partitions */
215 NEW_SOLARIS_X86_PARTITION = 0xbf,
216