kernel: don't parse FIT partition on NAND-backed mtdblock
[openwrt/staging/mkresin.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,8 @@ 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 + if (IS_ENABLED(CONFIG_FIT_PARTITION) && !mtd_type_is_nand(new->mtd))
120 + gd->flags |= GENHD_FL_EXT_DEVT;
121
122 if (tr->part_bits)
123 if (new->devnum < 26)
124 --- a/block/partitions/efi.c
125 +++ b/block/partitions/efi.c
126 @@ -716,6 +716,9 @@ int efi_partition(struct parsed_partitio
127 gpt_entry *ptes = NULL;
128 u32 i;
129 unsigned ssz = queue_logical_block_size(state->disk->queue) / 512;
130 +#ifdef CONFIG_FIT_PARTITION
131 + u32 extra_slot = 64;
132 +#endif
133
134 if (!find_valid_gpt(state, &gpt, &ptes) || !gpt || !ptes) {
135 kfree(gpt);
136 @@ -749,6 +752,11 @@ int efi_partition(struct parsed_partitio
137 ARRAY_SIZE(ptes[i].partition_name));
138 utf16_le_to_7bit(ptes[i].partition_name, label_max, info->volname);
139 state->parts[i + 1].has_info = true;
140 +#ifdef CONFIG_FIT_PARTITION
141 + /* If this is a U-Boot FIT volume it may have subpartitions */
142 + if (!efi_guidcmp(ptes[i].partition_type_guid, PARTITION_LINUX_FIT_GUID))
143 + (void) parse_fit_partitions(state, start * ssz, size * ssz, &extra_slot, 1);
144 +#endif
145 }
146 kfree(ptes);
147 kfree(gpt);
148 --- a/block/partitions/efi.h
149 +++ b/block/partitions/efi.h
150 @@ -52,6 +52,9 @@
151 #define PARTITION_LINUX_LVM_GUID \
152 EFI_GUID( 0xe6d6d379, 0xf507, 0x44c2, \
153 0xa2, 0x3c, 0x23, 0x8f, 0x2a, 0x3d, 0xf9, 0x28)
154 +#define PARTITION_LINUX_FIT_GUID \
155 + EFI_GUID( 0xcae9be83, 0xb15f, 0x49cc, \
156 + 0x86, 0x3f, 0x08, 0x1b, 0x74, 0x4a, 0x2d, 0x93)
157
158 typedef struct _gpt_header {
159 __le64 signature;
160 --- a/block/partitions/msdos.c
161 +++ b/block/partitions/msdos.c
162 @@ -564,6 +564,15 @@ static void parse_minix(struct parsed_pa
163 #endif /* CONFIG_MINIX_SUBPARTITION */
164 }
165
166 +static void parse_fit_mbr(struct parsed_partitions *state,
167 + sector_t offset, sector_t size, int origin)
168 +{
169 +#ifdef CONFIG_FIT_PARTITION
170 + u32 extra_slot = 64;
171 + (void) parse_fit_partitions(state, offset, size, &extra_slot, 1);
172 +#endif /* CONFIG_FIT_PARTITION */
173 +}
174 +
175 static struct {
176 unsigned char id;
177 void (*parse)(struct parsed_partitions *, sector_t, sector_t, int);
178 @@ -575,6 +584,7 @@ static struct {
179 {UNIXWARE_PARTITION, parse_unixware},
180 {SOLARIS_X86_PARTITION, parse_solaris_x86},
181 {NEW_SOLARIS_X86_PARTITION, parse_solaris_x86},
182 + {FIT_PARTITION, parse_fit_mbr},
183 {0, NULL},
184 };
185
186 --- a/include/linux/msdos_partition.h
187 +++ b/include/linux/msdos_partition.h
188 @@ -31,6 +31,7 @@ enum msdos_sys_ind {
189 LINUX_LVM_PARTITION = 0x8e,
190 LINUX_RAID_PARTITION = 0xfd, /* autodetect RAID partition */
191
192 + FIT_PARTITION = 0x2e, /* U-Boot uImage.FIT */
193 SOLARIS_X86_PARTITION = 0x82, /* also Linux swap partitions */
194 NEW_SOLARIS_X86_PARTITION = 0xbf,
195