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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. +config FIT_PARTITION
  17. + bool "Flattened-Image-Tree (FIT) partition support" if PARTITION_ADVANCED
  18. + default n
  19. + help
  20. + Say Y here if your system needs to mount the filesystem part of
  21. + a Flattened-Image-Tree (FIT) image commonly used with Das U-Boot.
  22. +
  23. config IBM_PARTITION
  24. bool "IBM disk label and partition support"
  25. depends on PARTITION_ADVANCED && S390
  26. --- a/block/partitions/Makefile
  27. +++ b/block/partitions/Makefile
  28. @@ -8,6 +8,7 @@ obj-$(CONFIG_ACORN_PARTITION) += acorn.o
  29. obj-$(CONFIG_AMIGA_PARTITION) += amiga.o
  30. obj-$(CONFIG_ATARI_PARTITION) += atari.o
  31. obj-$(CONFIG_AIX_PARTITION) += aix.o
  32. +obj-$(CONFIG_FIT_PARTITION) += fit.o
  33. obj-$(CONFIG_CMDLINE_PARTITION) += cmdline.o
  34. obj-$(CONFIG_MAC_PARTITION) += mac.o
  35. obj-$(CONFIG_LDM_PARTITION) += ldm.o
  36. --- a/block/partitions/check.h
  37. +++ b/block/partitions/check.h
  38. @@ -58,6 +58,7 @@ int amiga_partition(struct parsed_partit
  39. int atari_partition(struct parsed_partitions *state);
  40. int cmdline_partition(struct parsed_partitions *state);
  41. int efi_partition(struct parsed_partitions *state);
  42. +int fit_partition(struct parsed_partitions *state);
  43. int ibm_partition(struct parsed_partitions *);
  44. int karma_partition(struct parsed_partitions *state);
  45. int ldm_partition(struct parsed_partitions *state);
  46. @@ -68,3 +69,5 @@ int sgi_partition(struct parsed_partitio
  47. int sun_partition(struct parsed_partitions *state);
  48. int sysv68_partition(struct parsed_partitions *state);
  49. int ultrix_partition(struct parsed_partitions *state);
  50. +
  51. +int parse_fit_partitions(struct parsed_partitions *state, u64 start_sector, u64 nr_sectors, int *slot, int add_remain);
  52. --- a/block/partitions/core.c
  53. +++ b/block/partitions/core.c
  54. @@ -10,6 +10,10 @@
  55. #include <linux/vmalloc.h>
  56. #include <linux/blktrace_api.h>
  57. #include <linux/raid/detect.h>
  58. +#ifdef CONFIG_FIT_PARTITION
  59. +#include <linux/root_dev.h>
  60. +#endif
  61. +
  62. #include "check.h"
  63. static int (*check_part[])(struct parsed_partitions *) = {
  64. @@ -46,6 +50,9 @@ static int (*check_part[])(struct parsed
  65. #ifdef CONFIG_EFI_PARTITION
  66. efi_partition, /* this must come before msdos */
  67. #endif
  68. +#ifdef CONFIG_FIT_PARTITION
  69. + fit_partition,
  70. +#endif
  71. #ifdef CONFIG_SGI_PARTITION
  72. sgi_partition,
  73. #endif
  74. @@ -215,6 +222,18 @@ static ssize_t part_discard_alignment_sh
  75. p->start_sect));
  76. }
  77. +static ssize_t part_name_show(struct device *dev,
  78. + struct device_attribute *attr, char *buf)
  79. +{
  80. + struct hd_struct *p = dev_to_part(dev);
  81. +
  82. + if (p->info && p->info->volname)
  83. + return sprintf(buf, "%s\n", p->info->volname);
  84. +
  85. + buf[0] = '\0';
  86. + return 0;
  87. +}
  88. +
  89. static DEVICE_ATTR(partition, 0444, part_partition_show, NULL);
  90. static DEVICE_ATTR(start, 0444, part_start_show, NULL);
  91. static DEVICE_ATTR(size, 0444, part_size_show, NULL);
  92. @@ -223,6 +242,7 @@ static DEVICE_ATTR(alignment_offset, 044
  93. static DEVICE_ATTR(discard_alignment, 0444, part_discard_alignment_show, NULL);
  94. static DEVICE_ATTR(stat, 0444, part_stat_show, NULL);
  95. static DEVICE_ATTR(inflight, 0444, part_inflight_show, NULL);
  96. +static DEVICE_ATTR(name, 0444, part_name_show, NULL);
  97. #ifdef CONFIG_FAIL_MAKE_REQUEST
  98. static struct device_attribute dev_attr_fail =
  99. __ATTR(make-it-fail, 0644, part_fail_show, part_fail_store);
  100. @@ -237,6 +257,7 @@ static struct attribute *part_attrs[] =
  101. &dev_attr_discard_alignment.attr,
  102. &dev_attr_stat.attr,
  103. &dev_attr_inflight.attr,
  104. + &dev_attr_name.attr,
  105. #ifdef CONFIG_FAIL_MAKE_REQUEST
  106. &dev_attr_fail.attr,
  107. #endif
  108. @@ -694,6 +715,11 @@ static bool blk_add_partition(struct gen
  109. (state->parts[p].flags & ADDPART_FLAG_RAID))
  110. md_autodetect_dev(part_to_dev(part)->devt);
  111. +#ifdef CONFIG_FIT_PARTITION
  112. + if ((state->parts[p].flags & ADDPART_FLAG_ROOTDEV) && ROOT_DEV == 0)
  113. + ROOT_DEV = part_to_dev(part)->devt;
  114. +#endif
  115. +
  116. return true;
  117. }
  118. --- a/drivers/mtd/ubi/block.c
  119. +++ b/drivers/mtd/ubi/block.c
  120. @@ -396,7 +396,11 @@ int ubiblock_create(struct ubi_volume_in
  121. dev->leb_size = vi->usable_leb_size;
  122. /* Initialize the gendisk of this ubiblock device */
  123. +#ifdef CONFIG_FIT_PARTITION
  124. + gd = alloc_disk(0);
  125. +#else
  126. gd = alloc_disk(1);
  127. +#endif
  128. if (!gd) {
  129. pr_err("UBI: block: alloc_disk failed\n");
  130. ret = -ENODEV;
  131. @@ -413,6 +417,9 @@ int ubiblock_create(struct ubi_volume_in
  132. goto out_put_disk;
  133. }
  134. gd->private_data = dev;
  135. +#ifdef CONFIG_FIT_PARTITION
  136. + gd->flags |= GENHD_FL_EXT_DEVT;
  137. +#endif
  138. sprintf(gd->disk_name, "ubiblock%d_%d", dev->ubi_num, dev->vol_id);
  139. set_capacity(gd, disk_capacity);
  140. dev->gd = gd;
  141. --- a/block/partitions/efi.c
  142. +++ b/block/partitions/efi.c
  143. @@ -706,6 +706,9 @@ int efi_partition(struct parsed_partitio
  144. gpt_entry *ptes = NULL;
  145. u32 i;
  146. unsigned ssz = bdev_logical_block_size(state->bdev) / 512;
  147. +#ifdef CONFIG_FIT_PARTITION
  148. + u32 extra_slot = 64;
  149. +#endif
  150. if (!find_valid_gpt(state, &gpt, &ptes) || !gpt || !ptes) {
  151. kfree(gpt);
  152. @@ -739,6 +742,11 @@ int efi_partition(struct parsed_partitio
  153. ARRAY_SIZE(ptes[i].partition_name));
  154. utf16_le_to_7bit(ptes[i].partition_name, label_max, info->volname);
  155. state->parts[i + 1].has_info = true;
  156. +#ifdef CONFIG_FIT_PARTITION
  157. + /* If this is a U-Boot FIT volume it may have subpartitions */
  158. + if (!efi_guidcmp(ptes[i].partition_type_guid, PARTITION_LINUX_FIT_GUID))
  159. + (void) parse_fit_partitions(state, start * ssz, size * ssz, &extra_slot, 1);
  160. +#endif
  161. }
  162. kfree(ptes);
  163. kfree(gpt);
  164. --- a/block/partitions/efi.h
  165. +++ b/block/partitions/efi.h
  166. @@ -52,6 +52,9 @@
  167. #define PARTITION_LINUX_LVM_GUID \
  168. EFI_GUID( 0xe6d6d379, 0xf507, 0x44c2, \
  169. 0xa2, 0x3c, 0x23, 0x8f, 0x2a, 0x3d, 0xf9, 0x28)
  170. +#define PARTITION_LINUX_FIT_GUID \
  171. + EFI_GUID( 0xcae9be83, 0xb15f, 0x49cc, \
  172. + 0x86, 0x3f, 0x08, 0x1b, 0x74, 0x4a, 0x2d, 0x93)
  173. typedef struct _gpt_header {
  174. __le64 signature;
  175. --- a/drivers/mtd/mtdblock.c
  176. +++ b/drivers/mtd/mtdblock.c
  177. @@ -334,7 +334,11 @@ static void mtdblock_remove_dev(struct m
  178. static struct mtd_blktrans_ops mtdblock_tr = {
  179. .name = "mtdblock",
  180. .major = MTD_BLOCK_MAJOR,
  181. +#ifdef CONFIG_FIT_PARTITION
  182. + .part_bits = 1,
  183. +#else
  184. .part_bits = 0,
  185. +#endif
  186. .blksize = 512,
  187. .open = mtdblock_open,
  188. .flush = mtdblock_flush,
  189. --- a/drivers/mtd/mtd_blkdevs.c
  190. +++ b/drivers/mtd/mtd_blkdevs.c
  191. @@ -407,18 +407,8 @@ int add_mtd_blktrans_dev(struct mtd_blkt
  192. gd->first_minor = (new->devnum) << tr->part_bits;
  193. gd->fops = &mtd_block_ops;
  194. - if (tr->part_bits)
  195. - if (new->devnum < 26)
  196. - snprintf(gd->disk_name, sizeof(gd->disk_name),
  197. - "%s%c", tr->name, 'a' + new->devnum);
  198. - else
  199. - snprintf(gd->disk_name, sizeof(gd->disk_name),
  200. - "%s%c%c", tr->name,
  201. - 'a' - 1 + new->devnum / 26,
  202. - 'a' + new->devnum % 26);
  203. - else
  204. - snprintf(gd->disk_name, sizeof(gd->disk_name),
  205. - "%s%d", tr->name, new->devnum);
  206. + snprintf(gd->disk_name, sizeof(gd->disk_name),
  207. + "%s%d", tr->name, new->devnum);
  208. set_capacity(gd, ((u64)new->size * tr->blksize) >> 9);