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