generic: 5.15: get uImage.FIT partition parser ready
[openwrt/openwrt.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->bd_dev;
84 +
85 + if (state->parts[p].flags & ADDPART_FLAG_READONLY)
86 + set_disk_ro(disk, true);
87 +#endif
88 +
89 return true;
90 }
91
92 --- a/drivers/mtd/ubi/block.c
93 +++ b/drivers/mtd/ubi/block.c
94 @@ -413,6 +417,9 @@ int ubiblock_create(struct ubi_volume_in
95 goto out_cleanup_disk;
96 }
97 gd->private_data = dev;
98 +#ifdef CONFIG_FIT_PARTITION
99 + gd->flags |= GENHD_FL_EXT_DEVT;
100 +#endif
101 sprintf(gd->disk_name, "ubiblock%d_%d", dev->ubi_num, dev->vol_id);
102 set_capacity(gd, disk_capacity);
103 dev->gd = gd;
104 --- a/drivers/mtd/mtd_blkdevs.c
105 +++ b/drivers/mtd/mtd_blkdevs.c
106 @@ -345,6 +345,9 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)
107 gd->first_minor = (new->devnum) << tr->part_bits;
108 gd->minors = 1 << tr->part_bits;
109 gd->fops = &mtd_block_ops;
110 +#ifdef CONFIG_FIT_PARTITION
111 + gd->flags |= GENHD_FL_EXT_DEVT;
112 +#endif
113
114 if (tr->part_bits)
115 if (new->devnum < 26)
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/block/partitions/msdos.c
153 +++ b/block/partitions/msdos.c
154 @@ -563,6 +563,15 @@ static void parse_minix(struct parsed_pa
155 #endif /* CONFIG_MINIX_SUBPARTITION */
156 }
157
158 +static void parse_fit_mbr(struct parsed_partitions *state,
159 + sector_t offset, sector_t size, int origin)
160 +{
161 +#ifdef CONFIG_FIT_PARTITION
162 + u32 extra_slot = 64;
163 + (void) parse_fit_partitions(state, offset, size, &extra_slot, 1);
164 +#endif /* CONFIG_FIT_PARTITION */
165 +}
166 +
167 static struct {
168 unsigned char id;
169 void (*parse)(struct parsed_partitions *, sector_t, sector_t, int);
170 @@ -574,6 +583,7 @@ static struct {
171 {UNIXWARE_PARTITION, parse_unixware},
172 {SOLARIS_X86_PARTITION, parse_solaris_x86},
173 {NEW_SOLARIS_X86_PARTITION, parse_solaris_x86},
174 + {FIT_PARTITION, parse_fit_mbr},
175 {0, NULL},
176 };
177
178 --- a/include/linux/msdos_partition.h
179 +++ b/include/linux/msdos_partition.h
180 @@ -31,6 +31,7 @@ enum msdos_sys_ind {
181 LINUX_LVM_PARTITION = 0x8e,
182 LINUX_RAID_PARTITION = 0xfd, /* autodetect RAID partition */
183
184 + FIT_PARTITION = 0x2e, /* U-Boot uImage.FIT */
185 SOLARIS_X86_PARTITION = 0x82, /* also Linux swap partitions */
186 NEW_SOLARIS_X86_PARTITION = 0xbf,
187