image: extend FIT partition parser for use on eMMC/SDcard
[openwrt/staging/wigyori.git] / target / linux / generic / hack-5.4 / 400-block-fit-partition-parser.patch
1 --- a/block/partitions/Kconfig
2 +++ b/block/partitions/Kconfig
3 @@ -101,6 +101,13 @@ config ATARI_PARTITION
4 Say Y here if you would like to use hard disks under Linux which
5 were partitioned under the Atari OS.
6
7 +config FIT_PARTITION
8 + bool "Flattened-Image-Tree (FIT) partition support" if PARTITION_ADVANCED
9 + default n
10 + help
11 + Say Y here if your system needs to mount the filesystem part of
12 + a Flattened-Image-Tree (FIT) image commonly used with Das U-Boot.
13 +
14 config IBM_PARTITION
15 bool "IBM disk label and partition support"
16 depends on PARTITION_ADVANCED && S390
17 --- a/block/partitions/Makefile
18 +++ b/block/partitions/Makefile
19 @@ -9,6 +9,7 @@ obj-$(CONFIG_ACORN_PARTITION) += acorn.o
20 obj-$(CONFIG_AMIGA_PARTITION) += amiga.o
21 obj-$(CONFIG_ATARI_PARTITION) += atari.o
22 obj-$(CONFIG_AIX_PARTITION) += aix.o
23 +obj-$(CONFIG_FIT_PARTITION) += fit.o
24 obj-$(CONFIG_CMDLINE_PARTITION) += cmdline.o
25 obj-$(CONFIG_MAC_PARTITION) += mac.o
26 obj-$(CONFIG_LDM_PARTITION) += ldm.o
27 --- a/drivers/mtd/ubi/block.c
28 +++ b/drivers/mtd/ubi/block.c
29 @@ -396,7 +396,7 @@ int ubiblock_create(struct ubi_volume_in
30 dev->leb_size = vi->usable_leb_size;
31
32 /* Initialize the gendisk of this ubiblock device */
33 - gd = alloc_disk(1);
34 + gd = alloc_disk(0);
35 if (!gd) {
36 pr_err("UBI: block: alloc_disk failed\n");
37 ret = -ENODEV;
38 @@ -413,6 +413,7 @@ int ubiblock_create(struct ubi_volume_in
39 goto out_put_disk;
40 }
41 gd->private_data = dev;
42 + gd->flags |= GENHD_FL_EXT_DEVT;
43 sprintf(gd->disk_name, "ubiblock%d_%d", dev->ubi_num, dev->vol_id);
44 set_capacity(gd, disk_capacity);
45 dev->gd = gd;
46 --- a/block/partition-generic.c
47 +++ b/block/partition-generic.c
48 @@ -18,6 +18,10 @@
49 #include <linux/ctype.h>
50 #include <linux/genhd.h>
51 #include <linux/blktrace_api.h>
52 +#ifdef CONFIG_FIT_PARTITION
53 +#include <linux/root_dev.h>
54 +#endif
55 +
56
57 #include "partitions/check.h"
58
59 @@ -180,6 +184,18 @@ ssize_t part_fail_store(struct device *d
60 }
61 #endif
62
63 +static ssize_t part_name_show(struct device *dev,
64 + struct device_attribute *attr, char *buf)
65 +{
66 + struct hd_struct *p = dev_to_part(dev);
67 +
68 + if (p->info && p->info->volname)
69 + return sprintf(buf, "%s\n", p->info->volname);
70 +
71 + buf[0] = '\0';
72 + return 0;
73 +}
74 +
75 static DEVICE_ATTR(partition, 0444, part_partition_show, NULL);
76 static DEVICE_ATTR(start, 0444, part_start_show, NULL);
77 static DEVICE_ATTR(size, 0444, part_size_show, NULL);
78 @@ -188,6 +204,7 @@ static DEVICE_ATTR(alignment_offset, 044
79 static DEVICE_ATTR(discard_alignment, 0444, part_discard_alignment_show, NULL);
80 static DEVICE_ATTR(stat, 0444, part_stat_show, NULL);
81 static DEVICE_ATTR(inflight, 0444, part_inflight_show, NULL);
82 +static DEVICE_ATTR(name, 0444, part_name_show, NULL);
83 #ifdef CONFIG_FAIL_MAKE_REQUEST
84 static struct device_attribute dev_attr_fail =
85 __ATTR(make-it-fail, 0644, part_fail_show, part_fail_store);
86 @@ -202,6 +219,7 @@ static struct attribute *part_attrs[] =
87 &dev_attr_discard_alignment.attr,
88 &dev_attr_stat.attr,
89 &dev_attr_inflight.attr,
90 + &dev_attr_name.attr,
91 #ifdef CONFIG_FAIL_MAKE_REQUEST
92 &dev_attr_fail.attr,
93 #endif
94 @@ -634,6 +652,10 @@ rescan:
95 if (state->parts[p].flags & ADDPART_FLAG_RAID)
96 md_autodetect_dev(part_to_dev(part)->devt);
97 #endif
98 +#ifdef CONFIG_FIT_PARTITION
99 + if ((state->parts[p].flags & ADDPART_FLAG_ROOTDEV) && ROOT_DEV == 0)
100 + ROOT_DEV = part_to_dev(part)->devt;
101 +#endif
102 }
103 free_partitions(state);
104 return 0;
105 --- a/block/partitions/check.c
106 +++ b/block/partitions/check.c
107 @@ -33,6 +33,7 @@
108 #include "ibm.h"
109 #include "ultrix.h"
110 #include "efi.h"
111 +#include "fit.h"
112 #include "karma.h"
113 #include "sysv68.h"
114 #include "cmdline.h"
115 @@ -73,6 +74,9 @@ static int (*check_part[])(struct parsed
116 #ifdef CONFIG_EFI_PARTITION
117 efi_partition, /* this must come before msdos */
118 #endif
119 +#ifdef CONFIG_FIT_PARTITION
120 + fit_partition,
121 +#endif
122 #ifdef CONFIG_SGI_PARTITION
123 sgi_partition,
124 #endif
125 --- a/include/linux/genhd.h
126 +++ b/include/linux/genhd.h
127 @@ -614,6 +614,7 @@ struct unixware_disklabel {
128 #define ADDPART_FLAG_NONE 0
129 #define ADDPART_FLAG_RAID 1
130 #define ADDPART_FLAG_WHOLEDISK 2
131 +#define ADDPART_FLAG_ROOTDEV 4
132
133 extern int blk_alloc_devt(struct hd_struct *part, dev_t *devt);
134 extern void blk_free_devt(dev_t devt);
135 --- /dev/null
136 +++ b/block/partitions/fit.h
137 @@ -0,0 +1,3 @@
138 +/* SPDX-License-Identifier: GPL-2.0-only */
139 +int fit_partition(struct parsed_partitions *);
140 +int parse_fit_partitions(struct parsed_partitions *state, u64 start_sector, u64 nr_sectors, int *slot, int add_remain);
141 --- a/block/partitions/efi.c
142 +++ b/block/partitions/efi.c
143 @@ -679,7 +679,7 @@ int efi_partition(struct parsed_partitio
144 {
145 gpt_header *gpt = NULL;
146 gpt_entry *ptes = NULL;
147 - u32 i;
148 + u32 i, slot = 0;
149 unsigned ssz = bdev_logical_block_size(state->bdev) / 512;
150
151 if (!find_valid_gpt(state, &gpt, &ptes) || !gpt || !ptes) {
152 @@ -698,16 +698,18 @@ int efi_partition(struct parsed_partitio
153 u64 size = le64_to_cpu(ptes[i].ending_lba) -
154 le64_to_cpu(ptes[i].starting_lba) + 1ULL;
155
156 - if (!is_pte_valid(&ptes[i], last_lba(state->bdev)))
157 + if (!is_pte_valid(&ptes[i], last_lba(state->bdev))) {
158 + ++slot;
159 continue;
160 + }
161
162 - put_partition(state, i+1, start * ssz, size * ssz);
163 + put_partition(state, ++slot, start * ssz, size * ssz);
164
165 /* If this is a RAID volume, tell md */
166 if (!efi_guidcmp(ptes[i].partition_type_guid, PARTITION_LINUX_RAID_GUID))
167 - state->parts[i + 1].flags = ADDPART_FLAG_RAID;
168 + state->parts[slot].flags = ADDPART_FLAG_RAID;
169
170 - info = &state->parts[i + 1].info;
171 + info = &state->parts[slot].info;
172 efi_guid_to_str(&ptes[i].unique_partition_guid, info->uuid);
173
174 /* Naively convert UTF16-LE to 7 bits. */
175 @@ -721,7 +723,12 @@ int efi_partition(struct parsed_partitio
176 info->volname[label_count] = c;
177 label_count++;
178 }
179 - state->parts[i + 1].has_info = true;
180 + state->parts[slot].has_info = true;
181 +#ifdef CONFIG_FIT_PARTITION
182 + /* If this is a U-Boot FIT volume it may have subpartitions */
183 + if (!efi_guidcmp(ptes[i].partition_type_guid, PARTITION_LINUX_FIT_GUID))
184 + (void) parse_fit_partitions(state, start * ssz, size * ssz, &slot, 1);
185 +#endif
186 }
187 kfree(ptes);
188 kfree(gpt);
189 --- a/block/partitions/efi.h
190 +++ b/block/partitions/efi.h
191 @@ -52,6 +52,9 @@
192 #define PARTITION_LINUX_LVM_GUID \
193 EFI_GUID( 0xe6d6d379, 0xf507, 0x44c2, \
194 0xa2, 0x3c, 0x23, 0x8f, 0x2a, 0x3d, 0xf9, 0x28)
195 +#define PARTITION_LINUX_FIT_GUID \
196 + EFI_GUID( 0xcae9be83, 0xb15f, 0x49cc, \
197 + 0x86, 0x3f, 0x08, 0x1b, 0x74, 0x4a, 0x2d, 0x93)
198
199 typedef struct _gpt_header {
200 __le64 signature;