generic: 5.15: fix FIT partition parser on block partitions
[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 @@ -354,6 +354,8 @@ void blk_free_ext_minor(unsigned int min
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 @@ -12,6 +12,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 @@ -48,6 +52,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 @@ -408,6 +415,11 @@ static struct block_device *add_partitio
78 goto out_del;
79 }
80
81 +#ifdef CONFIG_FIT_PARTITION
82 + if (flags & ADDPART_FLAG_READONLY)
83 + bdev->bd_read_only = true;
84 +#endif
85 +
86 /* everything is up and running, commence */
87 err = xa_insert(&disk->part_tbl, partno, bdev, GFP_KERNEL);
88 if (err)
89 @@ -598,6 +610,11 @@ static bool blk_add_partition(struct gen
90 (state->parts[p].flags & ADDPART_FLAG_RAID))
91 md_autodetect_dev(part->bd_dev);
92
93 +#ifdef CONFIG_FIT_PARTITION
94 + if ((state->parts[p].flags & ADDPART_FLAG_ROOTDEV) && ROOT_DEV == 0)
95 + ROOT_DEV = part->bd_dev;
96 +#endif
97 +
98 return true;
99 }
100
101 --- a/drivers/mtd/ubi/block.c
102 +++ b/drivers/mtd/ubi/block.c
103 @@ -428,6 +428,9 @@ int ubiblock_create(struct ubi_volume_in
104 goto out_cleanup_disk;
105 }
106 gd->private_data = dev;
107 +#ifdef CONFIG_FIT_PARTITION
108 + gd->flags |= GENHD_FL_EXT_DEVT;
109 +#endif
110 sprintf(gd->disk_name, "ubiblock%d_%d", dev->ubi_num, dev->vol_id);
111 set_capacity(gd, disk_capacity);
112 dev->gd = gd;
113 --- a/drivers/mtd/mtd_blkdevs.c
114 +++ b/drivers/mtd/mtd_blkdevs.c
115 @@ -345,6 +345,9 @@ int add_mtd_blktrans_dev(struct mtd_blkt
116 gd->first_minor = (new->devnum) << tr->part_bits;
117 gd->minors = 1 << tr->part_bits;
118 gd->fops = &mtd_block_ops;
119 +#ifdef CONFIG_FIT_PARTITION
120 + gd->flags |= GENHD_FL_EXT_DEVT;
121 +#endif
122
123 if (tr->part_bits)
124 if (new->devnum < 26)
125 --- a/block/partitions/efi.c
126 +++ b/block/partitions/efi.c
127 @@ -716,6 +716,9 @@ int efi_partition(struct parsed_partitio
128 gpt_entry *ptes = NULL;
129 u32 i;
130 unsigned ssz = queue_logical_block_size(state->disk->queue) / 512;
131 +#ifdef CONFIG_FIT_PARTITION
132 + u32 extra_slot = 64;
133 +#endif
134
135 if (!find_valid_gpt(state, &gpt, &ptes) || !gpt || !ptes) {
136 kfree(gpt);
137 @@ -749,6 +752,11 @@ int efi_partition(struct parsed_partitio
138 ARRAY_SIZE(ptes[i].partition_name));
139 utf16_le_to_7bit(ptes[i].partition_name, label_max, info->volname);
140 state->parts[i + 1].has_info = true;
141 +#ifdef CONFIG_FIT_PARTITION
142 + /* If this is a U-Boot FIT volume it may have subpartitions */
143 + if (!efi_guidcmp(ptes[i].partition_type_guid, PARTITION_LINUX_FIT_GUID))
144 + (void) parse_fit_partitions(state, start * ssz, size * ssz, &extra_slot, 1);
145 +#endif
146 }
147 kfree(ptes);
148 kfree(gpt);
149 --- a/block/partitions/efi.h
150 +++ b/block/partitions/efi.h
151 @@ -52,6 +52,9 @@
152 #define PARTITION_LINUX_LVM_GUID \
153 EFI_GUID( 0xe6d6d379, 0xf507, 0x44c2, \
154 0xa2, 0x3c, 0x23, 0x8f, 0x2a, 0x3d, 0xf9, 0x28)
155 +#define PARTITION_LINUX_FIT_GUID \
156 + EFI_GUID( 0xcae9be83, 0xb15f, 0x49cc, \
157 + 0x86, 0x3f, 0x08, 0x1b, 0x74, 0x4a, 0x2d, 0x93)
158
159 typedef struct _gpt_header {
160 __le64 signature;
161 --- a/block/partitions/msdos.c
162 +++ b/block/partitions/msdos.c
163 @@ -564,6 +564,15 @@ static void parse_minix(struct parsed_pa
164 #endif /* CONFIG_MINIX_SUBPARTITION */
165 }
166
167 +static void parse_fit_mbr(struct parsed_partitions *state,
168 + sector_t offset, sector_t size, int origin)
169 +{
170 +#ifdef CONFIG_FIT_PARTITION
171 + u32 extra_slot = 64;
172 + (void) parse_fit_partitions(state, offset, size, &extra_slot, 1);
173 +#endif /* CONFIG_FIT_PARTITION */
174 +}
175 +
176 static struct {
177 unsigned char id;
178 void (*parse)(struct parsed_partitions *, sector_t, sector_t, int);
179 @@ -575,6 +584,7 @@ static struct {
180 {UNIXWARE_PARTITION, parse_unixware},
181 {SOLARIS_X86_PARTITION, parse_solaris_x86},
182 {NEW_SOLARIS_X86_PARTITION, parse_solaris_x86},
183 + {FIT_PARTITION, parse_fit_mbr},
184 {0, NULL},
185 };
186
187 --- a/include/linux/msdos_partition.h
188 +++ b/include/linux/msdos_partition.h
189 @@ -31,6 +31,7 @@ enum msdos_sys_ind {
190 LINUX_LVM_PARTITION = 0x8e,
191 LINUX_RAID_PARTITION = 0xfd, /* autodetect RAID partition */
192
193 + FIT_PARTITION = 0x2e, /* U-Boot uImage.FIT */
194 SOLARIS_X86_PARTITION = 0x82, /* also Linux swap partitions */
195 NEW_SOLARIS_X86_PARTITION = 0xbf,
196