400-block-fit-partition-parser.patch 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. +config FIT_PARTITION
  7. + bool "Flattened-Image-Tree (FIT) partition support" if PARTITION_ADVANCED
  8. + default n
  9. + help
  10. + Say Y here if your system needs to mount the filesystem part of
  11. + a Flattened-Image-Tree (FIT) image commonly used with Das U-Boot.
  12. +
  13. config IBM_PARTITION
  14. bool "IBM disk label and partition support"
  15. depends on PARTITION_ADVANCED && S390
  16. --- a/block/partitions/Makefile
  17. +++ b/block/partitions/Makefile
  18. @@ -9,6 +9,7 @@ obj-$(CONFIG_ACORN_PARTITION) += acorn.o
  19. obj-$(CONFIG_AMIGA_PARTITION) += amiga.o
  20. obj-$(CONFIG_ATARI_PARTITION) += atari.o
  21. obj-$(CONFIG_AIX_PARTITION) += aix.o
  22. +obj-$(CONFIG_FIT_PARTITION) += fit.o
  23. obj-$(CONFIG_CMDLINE_PARTITION) += cmdline.o
  24. obj-$(CONFIG_MAC_PARTITION) += mac.o
  25. obj-$(CONFIG_LDM_PARTITION) += ldm.o
  26. --- a/drivers/mtd/ubi/block.c
  27. +++ b/drivers/mtd/ubi/block.c
  28. @@ -396,7 +396,7 @@ int ubiblock_create(struct ubi_volume_in
  29. dev->leb_size = vi->usable_leb_size;
  30. /* Initialize the gendisk of this ubiblock device */
  31. - gd = alloc_disk(1);
  32. + gd = alloc_disk(0);
  33. if (!gd) {
  34. pr_err("UBI: block: alloc_disk failed\n");
  35. ret = -ENODEV;
  36. @@ -413,6 +413,7 @@ int ubiblock_create(struct ubi_volume_in
  37. goto out_put_disk;
  38. }
  39. gd->private_data = dev;
  40. + gd->flags |= GENHD_FL_EXT_DEVT;
  41. sprintf(gd->disk_name, "ubiblock%d_%d", dev->ubi_num, dev->vol_id);
  42. set_capacity(gd, disk_capacity);
  43. dev->gd = gd;
  44. --- a/block/partition-generic.c
  45. +++ b/block/partition-generic.c
  46. @@ -18,6 +18,10 @@
  47. #include <linux/ctype.h>
  48. #include <linux/genhd.h>
  49. #include <linux/blktrace_api.h>
  50. +#ifdef CONFIG_FIT_PARTITION
  51. +#include <linux/root_dev.h>
  52. +#endif
  53. +
  54. #include "partitions/check.h"
  55. @@ -180,6 +184,18 @@ ssize_t part_fail_store(struct device *d
  56. }
  57. #endif
  58. +static ssize_t part_name_show(struct device *dev,
  59. + struct device_attribute *attr, char *buf)
  60. +{
  61. + struct hd_struct *p = dev_to_part(dev);
  62. +
  63. + if (p->info && p->info->volname)
  64. + return sprintf(buf, "%s\n", p->info->volname);
  65. +
  66. + buf[0] = '\0';
  67. + return 0;
  68. +}
  69. +
  70. static DEVICE_ATTR(partition, 0444, part_partition_show, NULL);
  71. static DEVICE_ATTR(start, 0444, part_start_show, NULL);
  72. static DEVICE_ATTR(size, 0444, part_size_show, NULL);
  73. @@ -188,6 +204,7 @@ static DEVICE_ATTR(alignment_offset, 044
  74. static DEVICE_ATTR(discard_alignment, 0444, part_discard_alignment_show, NULL);
  75. static DEVICE_ATTR(stat, 0444, part_stat_show, NULL);
  76. static DEVICE_ATTR(inflight, 0444, part_inflight_show, NULL);
  77. +static DEVICE_ATTR(name, 0444, part_name_show, NULL);
  78. #ifdef CONFIG_FAIL_MAKE_REQUEST
  79. static struct device_attribute dev_attr_fail =
  80. __ATTR(make-it-fail, 0644, part_fail_show, part_fail_store);
  81. @@ -202,6 +219,7 @@ static struct attribute *part_attrs[] =
  82. &dev_attr_discard_alignment.attr,
  83. &dev_attr_stat.attr,
  84. &dev_attr_inflight.attr,
  85. + &dev_attr_name.attr,
  86. #ifdef CONFIG_FAIL_MAKE_REQUEST
  87. &dev_attr_fail.attr,
  88. #endif
  89. @@ -634,6 +652,10 @@ rescan:
  90. if (state->parts[p].flags & ADDPART_FLAG_RAID)
  91. md_autodetect_dev(part_to_dev(part)->devt);
  92. #endif
  93. +#ifdef CONFIG_FIT_PARTITION
  94. + if ((state->parts[p].flags & ADDPART_FLAG_ROOTDEV) && ROOT_DEV == 0)
  95. + ROOT_DEV = part_to_dev(part)->devt;
  96. +#endif
  97. }
  98. free_partitions(state);
  99. return 0;
  100. --- a/block/partitions/check.c
  101. +++ b/block/partitions/check.c
  102. @@ -33,6 +33,7 @@
  103. #include "ibm.h"
  104. #include "ultrix.h"
  105. #include "efi.h"
  106. +#include "fit.h"
  107. #include "karma.h"
  108. #include "sysv68.h"
  109. #include "cmdline.h"
  110. @@ -73,6 +74,9 @@ static int (*check_part[])(struct parsed
  111. #ifdef CONFIG_EFI_PARTITION
  112. efi_partition, /* this must come before msdos */
  113. #endif
  114. +#ifdef CONFIG_FIT_PARTITION
  115. + fit_partition,
  116. +#endif
  117. #ifdef CONFIG_SGI_PARTITION
  118. sgi_partition,
  119. #endif
  120. --- a/include/linux/genhd.h
  121. +++ b/include/linux/genhd.h
  122. @@ -614,6 +614,7 @@ struct unixware_disklabel {
  123. #define ADDPART_FLAG_NONE 0
  124. #define ADDPART_FLAG_RAID 1
  125. #define ADDPART_FLAG_WHOLEDISK 2
  126. +#define ADDPART_FLAG_ROOTDEV 4
  127. extern int blk_alloc_devt(struct hd_struct *part, dev_t *devt);
  128. extern void blk_free_devt(dev_t devt);
  129. --- /dev/null
  130. +++ b/block/partitions/fit.h
  131. @@ -0,0 +1,3 @@
  132. +/* SPDX-License-Identifier: GPL-2.0-only */
  133. +int fit_partition(struct parsed_partitions *);
  134. +int parse_fit_partitions(struct parsed_partitions *state, u64 start_sector, u64 nr_sectors, int *slot, int add_remain);
  135. --- a/block/partitions/efi.c
  136. +++ b/block/partitions/efi.c
  137. @@ -681,6 +681,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. @@ -722,6 +725,11 @@ int efi_partition(struct parsed_partitio
  147. label_count++;
  148. }
  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;