image: extend FIT partition parser for use on eMMC/SDcard
[openwrt/staging/wigyori.git] / target / linux / generic / hack-5.10 / 400-block-fit-partition-parser.patch
1 --- a/block/blk.h
2 +++ b/block/blk.h
3 @@ -357,6 +357,7 @@ 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_ROOTDEV 4
8 void delete_partition(struct hd_struct *part);
9 int bdev_add_partition(struct block_device *bdev, int partno,
10 sector_t start, sector_t length);
11 --- a/block/partitions/Kconfig
12 +++ b/block/partitions/Kconfig
13 @@ -101,6 +101,13 @@ config ATARI_PARTITION
14 Say Y here if you would like to use hard disks under Linux which
15 were partitioned under the Atari OS.
16
17 +config FIT_PARTITION
18 + bool "Flattened-Image-Tree (FIT) partition support" if PARTITION_ADVANCED
19 + default n
20 + help
21 + Say Y here if your system needs to mount the filesystem part of
22 + a Flattened-Image-Tree (FIT) image commonly used with Das U-Boot.
23 +
24 config IBM_PARTITION
25 bool "IBM disk label and partition support"
26 depends on PARTITION_ADVANCED && S390
27 --- a/block/partitions/Makefile
28 +++ b/block/partitions/Makefile
29 @@ -8,6 +8,7 @@ obj-$(CONFIG_ACORN_PARTITION) += acorn.o
30 obj-$(CONFIG_AMIGA_PARTITION) += amiga.o
31 obj-$(CONFIG_ATARI_PARTITION) += atari.o
32 obj-$(CONFIG_AIX_PARTITION) += aix.o
33 +obj-$(CONFIG_FIT_PARTITION) += fit.o
34 obj-$(CONFIG_CMDLINE_PARTITION) += cmdline.o
35 obj-$(CONFIG_MAC_PARTITION) += mac.o
36 obj-$(CONFIG_LDM_PARTITION) += ldm.o
37 --- a/block/partitions/check.h
38 +++ b/block/partitions/check.h
39 @@ -58,6 +58,7 @@ int amiga_partition(struct parsed_partit
40 int atari_partition(struct parsed_partitions *state);
41 int cmdline_partition(struct parsed_partitions *state);
42 int efi_partition(struct parsed_partitions *state);
43 +int fit_partition(struct parsed_partitions *state);
44 int ibm_partition(struct parsed_partitions *);
45 int karma_partition(struct parsed_partitions *state);
46 int ldm_partition(struct parsed_partitions *state);
47 @@ -68,3 +69,5 @@ int sgi_partition(struct parsed_partitio
48 int sun_partition(struct parsed_partitions *state);
49 int sysv68_partition(struct parsed_partitions *state);
50 int ultrix_partition(struct parsed_partitions *state);
51 +
52 +int parse_fit_partitions(struct parsed_partitions *state, u64 start_sector, u64 nr_sectors, int *slot, int add_remain);
53 --- a/block/partitions/core.c
54 +++ b/block/partitions/core.c
55 @@ -10,6 +10,10 @@
56 #include <linux/vmalloc.h>
57 #include <linux/blktrace_api.h>
58 #include <linux/raid/detect.h>
59 +#ifdef CONFIG_FIT_PARTITION
60 +#include <linux/root_dev.h>
61 +#endif
62 +
63 #include "check.h"
64
65 static int (*check_part[])(struct parsed_partitions *) = {
66 @@ -46,6 +50,9 @@ static int (*check_part[])(struct parsed
67 #ifdef CONFIG_EFI_PARTITION
68 efi_partition, /* this must come before msdos */
69 #endif
70 +#ifdef CONFIG_FIT_PARTITION
71 + fit_partition,
72 +#endif
73 #ifdef CONFIG_SGI_PARTITION
74 sgi_partition,
75 #endif
76 @@ -215,6 +222,18 @@ static ssize_t part_discard_alignment_sh
77 p->start_sect));
78 }
79
80 +static ssize_t part_name_show(struct device *dev,
81 + struct device_attribute *attr, char *buf)
82 +{
83 + struct hd_struct *p = dev_to_part(dev);
84 +
85 + if (p->info && p->info->volname)
86 + return sprintf(buf, "%s\n", p->info->volname);
87 +
88 + buf[0] = '\0';
89 + return 0;
90 +}
91 +
92 static DEVICE_ATTR(partition, 0444, part_partition_show, NULL);
93 static DEVICE_ATTR(start, 0444, part_start_show, NULL);
94 static DEVICE_ATTR(size, 0444, part_size_show, NULL);
95 @@ -223,6 +242,7 @@ static DEVICE_ATTR(alignment_offset, 044
96 static DEVICE_ATTR(discard_alignment, 0444, part_discard_alignment_show, NULL);
97 static DEVICE_ATTR(stat, 0444, part_stat_show, NULL);
98 static DEVICE_ATTR(inflight, 0444, part_inflight_show, NULL);
99 +static DEVICE_ATTR(name, 0444, part_name_show, NULL);
100 #ifdef CONFIG_FAIL_MAKE_REQUEST
101 static struct device_attribute dev_attr_fail =
102 __ATTR(make-it-fail, 0644, part_fail_show, part_fail_store);
103 @@ -237,6 +257,7 @@ static struct attribute *part_attrs[] =
104 &dev_attr_discard_alignment.attr,
105 &dev_attr_stat.attr,
106 &dev_attr_inflight.attr,
107 + &dev_attr_name.attr,
108 #ifdef CONFIG_FAIL_MAKE_REQUEST
109 &dev_attr_fail.attr,
110 #endif
111 @@ -694,6 +715,11 @@ static bool blk_add_partition(struct gen
112 (state->parts[p].flags & ADDPART_FLAG_RAID))
113 md_autodetect_dev(part_to_dev(part)->devt);
114
115 +#ifdef CONFIG_FIT_PARTITION
116 + if ((state->parts[p].flags & ADDPART_FLAG_ROOTDEV) && ROOT_DEV == 0)
117 + ROOT_DEV = part_to_dev(part)->devt;
118 +#endif
119 +
120 return true;
121 }
122
123 --- a/drivers/mtd/ubi/block.c
124 +++ b/drivers/mtd/ubi/block.c
125 @@ -396,7 +396,7 @@ int ubiblock_create(struct ubi_volume_in
126 dev->leb_size = vi->usable_leb_size;
127
128 /* Initialize the gendisk of this ubiblock device */
129 - gd = alloc_disk(1);
130 + gd = alloc_disk(0);
131 if (!gd) {
132 pr_err("UBI: block: alloc_disk failed\n");
133 ret = -ENODEV;
134 @@ -413,6 +413,7 @@ int ubiblock_create(struct ubi_volume_in
135 goto out_put_disk;
136 }
137 gd->private_data = dev;
138 + gd->flags |= GENHD_FL_EXT_DEVT;
139 sprintf(gd->disk_name, "ubiblock%d_%d", dev->ubi_num, dev->vol_id);
140 set_capacity(gd, disk_capacity);
141 dev->gd = gd;
142 --- a/block/partitions/efi.c
143 +++ b/block/partitions/efi.c
144 @@ -704,7 +704,7 @@ int efi_partition(struct parsed_partitio
145 {
146 gpt_header *gpt = NULL;
147 gpt_entry *ptes = NULL;
148 - u32 i;
149 + u32 i, slot = 0;
150 unsigned ssz = bdev_logical_block_size(state->bdev) / 512;
151
152 if (!find_valid_gpt(state, &gpt, &ptes) || !gpt || !ptes) {
153 @@ -722,23 +722,30 @@ int efi_partition(struct parsed_partitio
154 u64 size = le64_to_cpu(ptes[i].ending_lba) -
155 le64_to_cpu(ptes[i].starting_lba) + 1ULL;
156
157 - if (!is_pte_valid(&ptes[i], last_lba(state->bdev)))
158 + if (!is_pte_valid(&ptes[i], last_lba(state->bdev))) {
159 + ++slot;
160 continue;
161 + }
162
163 - put_partition(state, i+1, start * ssz, size * ssz);
164 + put_partition(state, ++slot, start * ssz, size * ssz);
165
166 /* If this is a RAID volume, tell md */
167 if (!efi_guidcmp(ptes[i].partition_type_guid, PARTITION_LINUX_RAID_GUID))
168 - state->parts[i + 1].flags = ADDPART_FLAG_RAID;
169 + state->parts[slot].flags = ADDPART_FLAG_RAID;
170
171 - info = &state->parts[i + 1].info;
172 + info = &state->parts[slot].info;
173 efi_guid_to_str(&ptes[i].unique_partition_guid, info->uuid);
174
175 /* Naively convert UTF16-LE to 7 bits. */
176 label_max = min(ARRAY_SIZE(info->volname) - 1,
177 ARRAY_SIZE(ptes[i].partition_name));
178 utf16_le_to_7bit(ptes[i].partition_name, label_max, info->volname);
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;