aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/generic/hack-5.10/410-block-fit-partition-parser.patch
blob: 405cc9d0d439226adc3608564fe9243eedd5e86e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
From: Daniel Golle <daniel@makrotopia.org>
Subject: [PATCH] kernel: fix FIT partition parser compatibility issues

The uImage.FIT partition parser used to squeeze in FIT partitions in
the range where partition editor tools (fdisk and such) expect the
regular partition. This is confusing people and tools when adding
additional partitions on top of the partition used for OpenWrt's
uImage.FIT.
Instead of squeezing in the additional partitions, rather start with
all uImage.FIT partitions at offset 64.

Submitted-by: Daniel Golle <daniel@makrotopia.org>
---
 block/blk.h                                            |  2 ++
 block/partitions/Kconfig                               |  7 +++
 block/partitions/Makefile                              |  1 +
 block/partitions/check.h                               |  3 ++
 block/partitions/core.c                                | 15 +++++++
 drivers/mtd/ubi/block.c                                |  7 +++
 block/partitions/efi.c                                 |  8 +++++++
 block/partitions/efi.h                                 |  3 ++
 drivers/mtd/mtdblock.c                                 |  4 +++
 drivers/mtd/mtd_blkdevs.c                              | 14 +------
 block/partitions/msdos.c                               | 10 ++++++
 include/linux/msdos_partition.h                        |  1 +
 12 files changed, 52 insertions(+), 13 deletions(-)

--- a/block/blk.h
+++ b/block/blk.h
@@ -361,6 +361,8 @@ char *disk_name(struct gendisk *hd, int
 #define ADDPART_FLAG_NONE	0
 #define ADDPART_FLAG_RAID	1
 #define ADDPART_FLAG_WHOLEDISK	2
+#define ADDPART_FLAG_READONLY	4
+#define ADDPART_FLAG_ROOTDEV	8
 void delete_partition(struct hd_struct *part);
 int bdev_add_partition(struct block_device *bdev, int partno,
 		sector_t start, sector_t length);
--- a/block/partitions/Kconfig
+++ b/block/partitions/Kconfig
@@ -101,6 +101,13 @@ config ATARI_PARTITION
 	  Say Y here if you would like to use hard disks under Linux which
 	  were partitioned under the Atari OS.
 
+config FIT_PARTITION
+	bool "Flattened-Image-Tree (FIT) partition support" if PARTITION_ADVANCED
+	default n
+	help
+	  Say Y here if your system needs to mount the filesystem part of
+	  a Flattened-Image-Tree (FIT) image commonly used with Das U-Boot.
+
 config IBM_PARTITION
 	bool "IBM disk label and partition support"
 	depends on PARTITION_ADVANCED && S390
--- a/block/partitions/Makefile
+++ b/block/partitions/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_ACORN_PARTITION) += acorn.o
 obj-$(CONFIG_AMIGA_PARTITION) += amiga.o
 obj-$(CONFIG_ATARI_PARTITION) += atari.o
 obj-$(CONFIG_AIX_PARTITION) += aix.o
+obj-$(CONFIG_FIT_PARTITION) += fit.o
 obj-$(CONFIG_CMDLINE_PARTITION) += cmdline.o
 obj-$(CONFIG_MAC_PARTITION) += mac.o
 obj-$(CONFIG_LDM_PARTITION) += ldm.o
--- a/block/partitions/check.h
+++ b/block/partitions/check.h
@@ -58,6 +58,7 @@ int amiga_partition(struct parsed_partit
 int atari_partition(struct parsed_partitions *state);
 int cmdline_partition(struct parsed_partitions *state);
 int efi_partition(struct parsed_partitions *state);
+int fit_partition(struct parsed_partitions *state);
 int ibm_partition(struct parsed_partitions *);
 int karma_partition(struct parsed_partitions *state);
 int ldm_partition(struct parsed_partitions *state);
@@ -68,3 +69,5 @@ int sgi_partition(struct parsed_partitio
 int sun_partition(struct parsed_partitions *state);
 int sysv68_partition(struct parsed_partitions *state);
 int ultrix_partition(struct parsed_partitions *state);
+
+int parse_fit_partitions(struct parsed_partitions *state, u64 start_sector, u64 nr_sectors, int *slot, int add_remain);
--- a/block/partitions/core.c
+++ b/block/partitions/core.c
@@ -10,6 +10,10 @@
 #include <linux/vmalloc.h>
 #include <linux/blktrace_api.h>
 #include <linux/raid/detect.h>
+#ifdef CONFIG_FIT_PARTITION
+#include <linux/root_dev.h>
+#endif
+
 #include "check.h"
 
 static int (*check_part[])(struct parsed_partitions *) = {
@@ -46,6 +50,9 @@ static int (*check_part[])(struct parsed
 #ifdef CONFIG_EFI_PARTITION
 	efi_partition,		/* this must come before msdos */
 #endif
+#ifdef CONFIG_FIT_PARTITION
+	fit_partition,
+#endif
 #ifdef CONFIG_SGI_PARTITION
 	sgi_partition,
 #endif
@@ -694,6 +701,14 @@ static bool blk_add_partition(struct gen
 	    (state->parts[p].flags & ADDPART_FLAG_RAID))
 		md_autodetect_dev(part_to_dev(part)->devt);
 
+#ifdef CONFIG_FIT_PARTITION
+	if ((state->parts[p].flags & ADDPART_FLAG_ROOTDEV) && ROOT_DEV == 0)
+		ROOT_DEV = part_to_dev(part)->devt;
+
+	if (state->parts[p].flags & ADDPART_FLAG_READONLY)
+		part->policy = true;
+#endif
+
 	return true;
 }
 
--- a/drivers/mtd/ubi/block.c
+++ b/drivers/mtd/ubi/block.c
@@ -396,7 +396,11 @@ int ubiblock_create(struct ubi_volume_in
 	dev->leb_size = vi->usable_leb_size;
 
 	/* Initialize the gendisk of this ubiblock device */
+#ifdef CONFIG_FIT_PARTITION
+	gd = alloc_disk(0);
+#else
 	gd = alloc_disk(1);
+#endif
 	if (!gd) {
 		pr_err("UBI: block: alloc_disk failed\n");
 		ret = -ENODEV;
@@ -413,6 +417,9 @@ int ubiblock_create(struct ubi_volume_in
 		goto out_put_disk;
 	}
 	gd->private_data = dev;
+#ifdef CONFIG_FIT_PARTITION
+	gd->flags |= GENHD_FL_EXT_DEVT;
+#endif
 	sprintf(gd->disk_name, "ubiblock%d_%d", dev->ubi_num, dev->vol_id);
 	set_capacity(gd, disk_capacity);
 	dev->gd = gd;
--- a/block/partitions/efi.c
+++ b/block/partitions/efi.c
@@ -706,6 +706,9 @@ int efi_partition(struct parsed_partitio
 	gpt_entry *ptes = NULL;
 	u32 i;
 	unsigned ssz = bdev_logical_block_size(state->bdev) / 512;
+#ifdef CONFIG_FIT_PARTITION
+	u32 extra_slot = 64;
+#endif
 
 	if (!find_valid_gpt(state, &gpt, &ptes) || !gpt || !ptes) {
 		kfree(gpt);
@@ -739,6 +742,11 @@ int efi_partition(struct parsed_partitio
 				ARRAY_SIZE(ptes[i].partition_name));
 		utf16_le_to_7bit(ptes[i].partition_name, label_max, info->volname);
 		state->parts[i + 1].has_info = true;
+#ifdef CONFIG_FIT_PARTITION
+		/* If this is a U-Boot FIT volume it may have subpartitions */
+		if (!efi_guidcmp(ptes[i].partition_type_guid, PARTITION_LINUX_FIT_GUID))
+			(void) parse_fit_partitions(state, start * ssz, size * ssz, &extra_slot, 1);
+#endif
 	}
 	kfree(ptes);
 	kfree(gpt);
--- a/block/partitions/efi.h
+++ b/block/partitions/efi.h
@@ -52,6 +52,9 @@
 #define PARTITION_LINUX_LVM_GUID \
     EFI_GUID( 0xe6d6d379, 0xf507, 0x44c2, \
               0xa2, 0x3c, 0x23, 0x8f, 0x2a, 0x3d, 0xf9, 0x28)
+#define PARTITION_LINUX_FIT_GUID \
+    EFI_GUID( 0xcae9be83, 0xb15f, 0x49cc, \
+              0x86, 0x3f, 0x08, 0x1b, 0x74, 0x4a, 0x2d, 0x93)
 
 typedef struct _gpt_header {
 	__le64 signature;
--- a/drivers/mtd/mtdblock.c
+++ b/drivers/mtd/mtdblock.c
@@ -334,7 +334,11 @@ static void mtdblock_remove_dev(struct m
 static struct mtd_blktrans_ops mtdblock_tr = {
 	.name		= "mtdblock",
 	.major		= MTD_BLOCK_MAJOR,
+#ifdef CONFIG_FIT_PARTITION
+	.part_bits	= 2,
+#else
 	.part_bits	= 0,
+#endif
 	.blksize 	= 512,
 	.open		= mtdblock_open,
 	.flush		= mtdblock_flush,
--- a/drivers/mtd/mtd_blkdevs.c
+++ b/drivers/mtd/mtd_blkdevs.c
@@ -407,18 +407,8 @@ int add_mtd_blktrans_dev(struct mtd_blkt
 	gd->first_minor = (new->devnum) << tr->part_bits;
 	gd->fops = &mtd_block_ops;
 
-	if (tr->part_bits)
-		if (new->devnum < 26)
-			snprintf(gd->disk_name, sizeof(gd->disk_name),
-				 "%s%c", tr->name, 'a' + new->devnum);
-		else
-			snprintf(gd->disk_name, sizeof(gd->disk_name),
-				 "%s%c%c", tr->name,
-				 'a' - 1 + new->devnum / 26,
-				 'a' + new->devnum % 26);
-	else
-		snprintf(gd->disk_name, sizeof(gd->disk_name),
-			 "%s%d", tr->name, new->devnum);
+	snprintf(gd->disk_name, sizeof(gd->disk_name),
+		 "%s%d", tr->name, new->devnum);
 
 	set_capacity(gd, ((u64)new->size * tr->blksize) >> 9);
 
--- a/block/partitions/msdos.c
+++ b/block/partitions/msdos.c
@@ -563,6 +563,15 @@ static void parse_minix(struct parsed_pa
 #endif /* CONFIG_MINIX_SUBPARTITION */
 }
 
+static void parse_fit_mbr(struct parsed_partitions *state,
+			  sector_t offset, sector_t size, int origin)
+{
+#ifdef CONFIG_FIT_PARTITION
+	u32 extra_slot = 64;
+	(void) parse_fit_partitions(state, offset, size, &extra_slot, 1);
+#endif /* CONFIG_FIT_PARTITION */
+}
+
 static struct {
 	unsigned char id;
 	void (*parse)(struct parsed_partitions *, sector_t, sector_t, int);
@@ -574,6 +583,7 @@ static struct {
 	{UNIXWARE_PARTITION, parse_unixware},
 	{SOLARIS_X86_PARTITION, parse_solaris_x86},
 	{NEW_SOLARIS_X86_PARTITION, parse_solaris_x86},
+	{FIT_PARTITION, parse_fit_mbr},
 	{0, NULL},
 };
 
--- a/include/linux/msdos_partition.h
+++ b/include/linux/msdos_partition.h
@@ -31,6 +31,7 @@ enum msdos_sys_ind {
 	LINUX_LVM_PARTITION = 0x8e,
 	LINUX_RAID_PARTITION = 0xfd,	/* autodetect RAID partition */
 
+	FIT_PARTITION = 0x2e,		/* U-Boot uImage.FIT */
 	SOLARIS_X86_PARTITION =	0x82,	/* also Linux swap partitions */
 	NEW_SOLARIS_X86_PARTITION = 0xbf,