410-block-fit-partition-parser.patch 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. From: Daniel Golle <[email protected]>
  2. Subject: [PATCH] kernel: fix FIT partition parser compatibility issues
  3. The uImage.FIT partition parser used to squeeze in FIT partitions in
  4. the range where partition editor tools (fdisk and such) expect the
  5. regular partition. This is confusing people and tools when adding
  6. additional partitions on top of the partition used for OpenWrt's
  7. uImage.FIT.
  8. Instead of squeezing in the additional partitions, rather start with
  9. all uImage.FIT partitions at offset 64.
  10. Submitted-by: Daniel Golle <[email protected]>
  11. ---
  12. block/blk.h | 2 ++
  13. block/partitions/Kconfig | 7 +++
  14. block/partitions/Makefile | 1 +
  15. block/partitions/check.h | 3 ++
  16. block/partitions/core.c | 15 +++++++
  17. drivers/mtd/ubi/block.c | 7 +++
  18. block/partitions/efi.c | 8 +++++++
  19. block/partitions/efi.h | 3 ++
  20. drivers/mtd/mtdblock.c | 4 +++
  21. drivers/mtd/mtd_blkdevs.c | 14 +------
  22. block/partitions/msdos.c | 10 ++++++
  23. include/linux/msdos_partition.h | 1 +
  24. 12 files changed, 52 insertions(+), 13 deletions(-)
  25. --- a/block/blk.h
  26. +++ b/block/blk.h
  27. @@ -361,6 +361,8 @@ char *disk_name(struct gendisk *hd, int
  28. #define ADDPART_FLAG_NONE 0
  29. #define ADDPART_FLAG_RAID 1
  30. #define ADDPART_FLAG_WHOLEDISK 2
  31. +#define ADDPART_FLAG_READONLY 4
  32. +#define ADDPART_FLAG_ROOTDEV 8
  33. void delete_partition(struct hd_struct *part);
  34. int bdev_add_partition(struct block_device *bdev, int partno,
  35. sector_t start, sector_t length);
  36. --- a/block/partitions/Kconfig
  37. +++ b/block/partitions/Kconfig
  38. @@ -101,6 +101,13 @@ config ATARI_PARTITION
  39. Say Y here if you would like to use hard disks under Linux which
  40. were partitioned under the Atari OS.
  41. +config FIT_PARTITION
  42. + bool "Flattened-Image-Tree (FIT) partition support" if PARTITION_ADVANCED
  43. + default n
  44. + help
  45. + Say Y here if your system needs to mount the filesystem part of
  46. + a Flattened-Image-Tree (FIT) image commonly used with Das U-Boot.
  47. +
  48. config IBM_PARTITION
  49. bool "IBM disk label and partition support"
  50. depends on PARTITION_ADVANCED && S390
  51. --- a/block/partitions/Makefile
  52. +++ b/block/partitions/Makefile
  53. @@ -8,6 +8,7 @@ obj-$(CONFIG_ACORN_PARTITION) += acorn.o
  54. obj-$(CONFIG_AMIGA_PARTITION) += amiga.o
  55. obj-$(CONFIG_ATARI_PARTITION) += atari.o
  56. obj-$(CONFIG_AIX_PARTITION) += aix.o
  57. +obj-$(CONFIG_FIT_PARTITION) += fit.o
  58. obj-$(CONFIG_CMDLINE_PARTITION) += cmdline.o
  59. obj-$(CONFIG_MAC_PARTITION) += mac.o
  60. obj-$(CONFIG_LDM_PARTITION) += ldm.o
  61. --- a/block/partitions/check.h
  62. +++ b/block/partitions/check.h
  63. @@ -58,6 +58,7 @@ int amiga_partition(struct parsed_partit
  64. int atari_partition(struct parsed_partitions *state);
  65. int cmdline_partition(struct parsed_partitions *state);
  66. int efi_partition(struct parsed_partitions *state);
  67. +int fit_partition(struct parsed_partitions *state);
  68. int ibm_partition(struct parsed_partitions *);
  69. int karma_partition(struct parsed_partitions *state);
  70. int ldm_partition(struct parsed_partitions *state);
  71. @@ -68,3 +69,5 @@ int sgi_partition(struct parsed_partitio
  72. int sun_partition(struct parsed_partitions *state);
  73. int sysv68_partition(struct parsed_partitions *state);
  74. int ultrix_partition(struct parsed_partitions *state);
  75. +
  76. +int parse_fit_partitions(struct parsed_partitions *state, u64 start_sector, u64 nr_sectors, int *slot, int add_remain);
  77. --- a/block/partitions/core.c
  78. +++ b/block/partitions/core.c
  79. @@ -10,6 +10,10 @@
  80. #include <linux/vmalloc.h>
  81. #include <linux/blktrace_api.h>
  82. #include <linux/raid/detect.h>
  83. +#ifdef CONFIG_FIT_PARTITION
  84. +#include <linux/root_dev.h>
  85. +#endif
  86. +
  87. #include "check.h"
  88. static int (*check_part[])(struct parsed_partitions *) = {
  89. @@ -46,6 +50,9 @@ static int (*check_part[])(struct parsed
  90. #ifdef CONFIG_EFI_PARTITION
  91. efi_partition, /* this must come before msdos */
  92. #endif
  93. +#ifdef CONFIG_FIT_PARTITION
  94. + fit_partition,
  95. +#endif
  96. #ifdef CONFIG_SGI_PARTITION
  97. sgi_partition,
  98. #endif
  99. @@ -701,6 +708,14 @@ static bool blk_add_partition(struct gen
  100. (state->parts[p].flags & ADDPART_FLAG_RAID))
  101. md_autodetect_dev(part_to_dev(part)->devt);
  102. +#ifdef CONFIG_FIT_PARTITION
  103. + if ((state->parts[p].flags & ADDPART_FLAG_ROOTDEV) && ROOT_DEV == 0)
  104. + ROOT_DEV = part_to_dev(part)->devt;
  105. +
  106. + if (state->parts[p].flags & ADDPART_FLAG_READONLY)
  107. + part->policy = true;
  108. +#endif
  109. +
  110. return true;
  111. }
  112. --- a/drivers/mtd/ubi/block.c
  113. +++ b/drivers/mtd/ubi/block.c
  114. @@ -396,7 +396,11 @@ int ubiblock_create(struct ubi_volume_in
  115. dev->leb_size = vi->usable_leb_size;
  116. /* Initialize the gendisk of this ubiblock device */
  117. +#ifdef CONFIG_FIT_PARTITION
  118. + gd = alloc_disk(0);
  119. +#else
  120. gd = alloc_disk(1);
  121. +#endif
  122. if (!gd) {
  123. pr_err("UBI: block: alloc_disk failed\n");
  124. ret = -ENODEV;
  125. @@ -413,6 +417,9 @@ int ubiblock_create(struct ubi_volume_in
  126. goto out_put_disk;
  127. }
  128. gd->private_data = dev;
  129. +#ifdef CONFIG_FIT_PARTITION
  130. + gd->flags |= GENHD_FL_EXT_DEVT;
  131. +#endif
  132. sprintf(gd->disk_name, "ubiblock%d_%d", dev->ubi_num, dev->vol_id);
  133. set_capacity(gd, disk_capacity);
  134. dev->gd = gd;
  135. --- a/block/partitions/efi.c
  136. +++ b/block/partitions/efi.c
  137. @@ -706,6 +706,9 @@ int efi_partition(struct parsed_partitio
  138. gpt_entry *ptes = NULL;
  139. u32 i;
  140. unsigned ssz = bdev_logical_block_size(state->bdev) / 512;
  141. +#ifdef CONFIG_FIT_PARTITION
  142. + u32 extra_slot = 64;
  143. +#endif
  144. if (!find_valid_gpt(state, &gpt, &ptes) || !gpt || !ptes) {
  145. kfree(gpt);
  146. @@ -739,6 +742,11 @@ int efi_partition(struct parsed_partitio
  147. ARRAY_SIZE(ptes[i].partition_name));
  148. utf16_le_to_7bit(ptes[i].partition_name, label_max, info->volname);
  149. state->parts[i + 1].has_info = true;
  150. +#ifdef CONFIG_FIT_PARTITION
  151. + /* If this is a U-Boot FIT volume it may have subpartitions */
  152. + if (!efi_guidcmp(ptes[i].partition_type_guid, PARTITION_LINUX_FIT_GUID))
  153. + (void) parse_fit_partitions(state, start * ssz, size * ssz, &extra_slot, 1);
  154. +#endif
  155. }
  156. kfree(ptes);
  157. kfree(gpt);
  158. --- a/block/partitions/efi.h
  159. +++ b/block/partitions/efi.h
  160. @@ -52,6 +52,9 @@
  161. #define PARTITION_LINUX_LVM_GUID \
  162. EFI_GUID( 0xe6d6d379, 0xf507, 0x44c2, \
  163. 0xa2, 0x3c, 0x23, 0x8f, 0x2a, 0x3d, 0xf9, 0x28)
  164. +#define PARTITION_LINUX_FIT_GUID \
  165. + EFI_GUID( 0xcae9be83, 0xb15f, 0x49cc, \
  166. + 0x86, 0x3f, 0x08, 0x1b, 0x74, 0x4a, 0x2d, 0x93)
  167. typedef struct _gpt_header {
  168. __le64 signature;
  169. --- a/drivers/mtd/mtdblock.c
  170. +++ b/drivers/mtd/mtdblock.c
  171. @@ -334,7 +334,11 @@ static void mtdblock_remove_dev(struct m
  172. static struct mtd_blktrans_ops mtdblock_tr = {
  173. .name = "mtdblock",
  174. .major = MTD_BLOCK_MAJOR,
  175. +#ifdef CONFIG_FIT_PARTITION
  176. + .part_bits = 2,
  177. +#else
  178. .part_bits = 0,
  179. +#endif
  180. .blksize = 512,
  181. .open = mtdblock_open,
  182. .flush = mtdblock_flush,
  183. --- a/drivers/mtd/mtd_blkdevs.c
  184. +++ b/drivers/mtd/mtd_blkdevs.c
  185. @@ -407,18 +407,8 @@ int add_mtd_blktrans_dev(struct mtd_blkt
  186. gd->first_minor = (new->devnum) << tr->part_bits;
  187. gd->fops = &mtd_block_ops;
  188. - if (tr->part_bits)
  189. - if (new->devnum < 26)
  190. - snprintf(gd->disk_name, sizeof(gd->disk_name),
  191. - "%s%c", tr->name, 'a' + new->devnum);
  192. - else
  193. - snprintf(gd->disk_name, sizeof(gd->disk_name),
  194. - "%s%c%c", tr->name,
  195. - 'a' - 1 + new->devnum / 26,
  196. - 'a' + new->devnum % 26);
  197. - else
  198. - snprintf(gd->disk_name, sizeof(gd->disk_name),
  199. - "%s%d", tr->name, new->devnum);
  200. + snprintf(gd->disk_name, sizeof(gd->disk_name),
  201. + "%s%d", tr->name, new->devnum);
  202. set_capacity(gd, ((u64)new->size * tr->blksize) >> 9);
  203. --- a/block/partitions/msdos.c
  204. +++ b/block/partitions/msdos.c
  205. @@ -563,6 +563,15 @@ static void parse_minix(struct parsed_pa
  206. #endif /* CONFIG_MINIX_SUBPARTITION */
  207. }
  208. +static void parse_fit_mbr(struct parsed_partitions *state,
  209. + sector_t offset, sector_t size, int origin)
  210. +{
  211. +#ifdef CONFIG_FIT_PARTITION
  212. + u32 extra_slot = 64;
  213. + (void) parse_fit_partitions(state, offset, size, &extra_slot, 1);
  214. +#endif /* CONFIG_FIT_PARTITION */
  215. +}
  216. +
  217. static struct {
  218. unsigned char id;
  219. void (*parse)(struct parsed_partitions *, sector_t, sector_t, int);
  220. @@ -574,6 +583,7 @@ static struct {
  221. {UNIXWARE_PARTITION, parse_unixware},
  222. {SOLARIS_X86_PARTITION, parse_solaris_x86},
  223. {NEW_SOLARIS_X86_PARTITION, parse_solaris_x86},
  224. + {FIT_PARTITION, parse_fit_mbr},
  225. {0, NULL},
  226. };
  227. --- a/include/linux/msdos_partition.h
  228. +++ b/include/linux/msdos_partition.h
  229. @@ -31,6 +31,7 @@ enum msdos_sys_ind {
  230. LINUX_LVM_PARTITION = 0x8e,
  231. LINUX_RAID_PARTITION = 0xfd, /* autodetect RAID partition */
  232. + FIT_PARTITION = 0x2e, /* U-Boot uImage.FIT */
  233. SOLARIS_X86_PARTITION = 0x82, /* also Linux swap partitions */
  234. NEW_SOLARIS_X86_PARTITION = 0xbf,