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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. From 69357074558daf6ff24c9f58714935e9e095a865 Mon Sep 17 00:00:00 2001
  2. From: OpenWrt community <[email protected]>
  3. Date: Wed, 13 Jul 2022 13:37:33 +0200
  4. Subject: [PATCH] kernel: add block fit partition parser
  5. ---
  6. block/blk.h | 2 ++
  7. block/partitions/Kconfig | 7 +++++++
  8. block/partitions/Makefile | 1 +
  9. block/partitions/check.h | 3 +++
  10. block/partitions/core.c | 17 +++++++++++++++++
  11. block/partitions/efi.c | 8 ++++++++
  12. block/partitions/efi.h | 3 +++
  13. block/partitions/msdos.c | 10 ++++++++++
  14. drivers/mtd/mtd_blkdevs.c | 2 ++
  15. drivers/mtd/ubi/block.c | 3 +++
  16. include/linux/msdos_partition.h | 1 +
  17. 11 files changed, 57 insertions(+)
  18. --- a/block/blk.h
  19. +++ b/block/blk.h
  20. @@ -423,6 +423,8 @@ void blk_free_ext_minor(unsigned int min
  21. #define ADDPART_FLAG_NONE 0
  22. #define ADDPART_FLAG_RAID 1
  23. #define ADDPART_FLAG_WHOLEDISK 2
  24. +#define ADDPART_FLAG_READONLY 4
  25. +#define ADDPART_FLAG_ROOTDEV 8
  26. int bdev_add_partition(struct gendisk *disk, int partno, sector_t start,
  27. sector_t length);
  28. int bdev_del_partition(struct gendisk *disk, int partno);
  29. --- a/block/partitions/Kconfig
  30. +++ b/block/partitions/Kconfig
  31. @@ -103,6 +103,13 @@ config ATARI_PARTITION
  32. Say Y here if you would like to use hard disks under Linux which
  33. were partitioned under the Atari OS.
  34. +config FIT_PARTITION
  35. + bool "Flattened-Image-Tree (FIT) partition support" if PARTITION_ADVANCED
  36. + default n
  37. + help
  38. + Say Y here if your system needs to mount the filesystem part of
  39. + a Flattened-Image-Tree (FIT) image commonly used with Das U-Boot.
  40. +
  41. config IBM_PARTITION
  42. bool "IBM disk label and partition support"
  43. depends on PARTITION_ADVANCED && S390
  44. --- a/block/partitions/Makefile
  45. +++ b/block/partitions/Makefile
  46. @@ -8,6 +8,7 @@ obj-$(CONFIG_ACORN_PARTITION) += acorn.o
  47. obj-$(CONFIG_AMIGA_PARTITION) += amiga.o
  48. obj-$(CONFIG_ATARI_PARTITION) += atari.o
  49. obj-$(CONFIG_AIX_PARTITION) += aix.o
  50. +obj-$(CONFIG_FIT_PARTITION) += fit.o
  51. obj-$(CONFIG_CMDLINE_PARTITION) += cmdline.o
  52. obj-$(CONFIG_MAC_PARTITION) += mac.o
  53. obj-$(CONFIG_LDM_PARTITION) += ldm.o
  54. --- a/block/partitions/check.h
  55. +++ b/block/partitions/check.h
  56. @@ -57,6 +57,7 @@ int amiga_partition(struct parsed_partit
  57. int atari_partition(struct parsed_partitions *state);
  58. int cmdline_partition(struct parsed_partitions *state);
  59. int efi_partition(struct parsed_partitions *state);
  60. +int fit_partition(struct parsed_partitions *state);
  61. int ibm_partition(struct parsed_partitions *);
  62. int karma_partition(struct parsed_partitions *state);
  63. int ldm_partition(struct parsed_partitions *state);
  64. @@ -67,3 +68,5 @@ int sgi_partition(struct parsed_partitio
  65. int sun_partition(struct parsed_partitions *state);
  66. int sysv68_partition(struct parsed_partitions *state);
  67. int ultrix_partition(struct parsed_partitions *state);
  68. +
  69. +int parse_fit_partitions(struct parsed_partitions *state, u64 start_sector, u64 nr_sectors, int *slot, int add_remain);
  70. --- a/block/partitions/core.c
  71. +++ b/block/partitions/core.c
  72. @@ -11,6 +11,9 @@
  73. #include <linux/vmalloc.h>
  74. #include <linux/raid/detect.h>
  75. #include <linux/property.h>
  76. +#ifdef CONFIG_FIT_PARTITION
  77. +#include <linux/root_dev.h>
  78. +#endif
  79. #include "check.h"
  80. @@ -48,6 +51,9 @@ static int (*const check_part[])(struct
  81. #ifdef CONFIG_EFI_PARTITION
  82. efi_partition, /* this must come before msdos */
  83. #endif
  84. +#ifdef CONFIG_FIT_PARTITION
  85. + fit_partition,
  86. +#endif
  87. #ifdef CONFIG_SGI_PARTITION
  88. sgi_partition,
  89. #endif
  90. @@ -433,6 +439,11 @@ static struct block_device *add_partitio
  91. goto out_del;
  92. }
  93. +#ifdef CONFIG_FIT_PARTITION
  94. + if (flags & ADDPART_FLAG_READONLY)
  95. + bdev->bd_read_only = true;
  96. +#endif
  97. +
  98. /* everything is up and running, commence */
  99. err = xa_insert(&disk->part_tbl, partno, bdev, GFP_KERNEL);
  100. if (err)
  101. @@ -625,6 +636,11 @@ static bool blk_add_partition(struct gen
  102. (state->parts[p].flags & ADDPART_FLAG_RAID))
  103. md_autodetect_dev(part->bd_dev);
  104. +#ifdef CONFIG_FIT_PARTITION
  105. + if ((state->parts[p].flags & ADDPART_FLAG_ROOTDEV) && ROOT_DEV == 0)
  106. + ROOT_DEV = part->bd_dev;
  107. +#endif
  108. +
  109. return true;
  110. }
  111. --- a/block/partitions/efi.c
  112. +++ b/block/partitions/efi.c
  113. @@ -716,6 +716,9 @@ int efi_partition(struct parsed_partitio
  114. gpt_entry *ptes = NULL;
  115. u32 i;
  116. unsigned ssz = queue_logical_block_size(state->disk->queue) / 512;
  117. +#ifdef CONFIG_FIT_PARTITION
  118. + u32 extra_slot = 64;
  119. +#endif
  120. if (!find_valid_gpt(state, &gpt, &ptes) || !gpt || !ptes) {
  121. kfree(gpt);
  122. @@ -749,6 +752,11 @@ int efi_partition(struct parsed_partitio
  123. ARRAY_SIZE(ptes[i].partition_name));
  124. utf16_le_to_7bit(ptes[i].partition_name, label_max, info->volname);
  125. state->parts[i + 1].has_info = true;
  126. +#ifdef CONFIG_FIT_PARTITION
  127. + /* If this is a U-Boot FIT volume it may have subpartitions */
  128. + if (!efi_guidcmp(ptes[i].partition_type_guid, PARTITION_LINUX_FIT_GUID))
  129. + (void) parse_fit_partitions(state, start * ssz, size * ssz, &extra_slot, 1);
  130. +#endif
  131. }
  132. kfree(ptes);
  133. kfree(gpt);
  134. --- a/block/partitions/efi.h
  135. +++ b/block/partitions/efi.h
  136. @@ -51,6 +51,9 @@
  137. #define PARTITION_LINUX_LVM_GUID \
  138. EFI_GUID( 0xe6d6d379, 0xf507, 0x44c2, \
  139. 0xa2, 0x3c, 0x23, 0x8f, 0x2a, 0x3d, 0xf9, 0x28)
  140. +#define PARTITION_LINUX_FIT_GUID \
  141. + EFI_GUID( 0xcae9be83, 0xb15f, 0x49cc, \
  142. + 0x86, 0x3f, 0x08, 0x1b, 0x74, 0x4a, 0x2d, 0x93)
  143. typedef struct _gpt_header {
  144. __le64 signature;
  145. --- a/block/partitions/msdos.c
  146. +++ b/block/partitions/msdos.c
  147. @@ -564,6 +564,15 @@ static void parse_minix(struct parsed_pa
  148. #endif /* CONFIG_MINIX_SUBPARTITION */
  149. }
  150. +static void parse_fit_mbr(struct parsed_partitions *state,
  151. + sector_t offset, sector_t size, int origin)
  152. +{
  153. +#ifdef CONFIG_FIT_PARTITION
  154. + u32 extra_slot = 64;
  155. + (void) parse_fit_partitions(state, offset, size, &extra_slot, 1);
  156. +#endif /* CONFIG_FIT_PARTITION */
  157. +}
  158. +
  159. static struct {
  160. unsigned char id;
  161. void (*parse)(struct parsed_partitions *, sector_t, sector_t, int);
  162. @@ -575,6 +584,7 @@ static struct {
  163. {UNIXWARE_PARTITION, parse_unixware},
  164. {SOLARIS_X86_PARTITION, parse_solaris_x86},
  165. {NEW_SOLARIS_X86_PARTITION, parse_solaris_x86},
  166. + {FIT_PARTITION, parse_fit_mbr},
  167. {0, NULL},
  168. };
  169. --- a/drivers/mtd/mtd_blkdevs.c
  170. +++ b/drivers/mtd/mtd_blkdevs.c
  171. @@ -359,7 +359,9 @@ int add_mtd_blktrans_dev(struct mtd_blkt
  172. } else {
  173. snprintf(gd->disk_name, sizeof(gd->disk_name),
  174. "%s%d", tr->name, new->devnum);
  175. - gd->flags |= GENHD_FL_NO_PART;
  176. +
  177. + if (!IS_ENABLED(CONFIG_FIT_PARTITION) || mtd_type_is_nand(new->mtd))
  178. + gd->flags |= GENHD_FL_NO_PART;
  179. }
  180. set_capacity(gd, ((u64)new->size * tr->blksize) >> 9);
  181. --- a/drivers/mtd/ubi/block.c
  182. +++ b/drivers/mtd/ubi/block.c
  183. @@ -411,7 +411,9 @@ int ubiblock_create(struct ubi_volume_in
  184. ret = -ENODEV;
  185. goto out_cleanup_disk;
  186. }
  187. - gd->flags |= GENHD_FL_NO_PART;
  188. + if (!IS_ENABLED(CONFIG_FIT_PARTITION))
  189. + gd->flags |= GENHD_FL_NO_PART;
  190. +
  191. gd->private_data = dev;
  192. sprintf(gd->disk_name, "ubiblock%d_%d", dev->ubi_num, dev->vol_id);
  193. set_capacity(gd, disk_capacity);
  194. --- a/include/linux/msdos_partition.h
  195. +++ b/include/linux/msdos_partition.h
  196. @@ -31,6 +31,7 @@ enum msdos_sys_ind {
  197. LINUX_LVM_PARTITION = 0x8e,
  198. LINUX_RAID_PARTITION = 0xfd, /* autodetect RAID partition */
  199. + FIT_PARTITION = 0x2e, /* U-Boot uImage.FIT */
  200. SOLARIS_X86_PARTITION = 0x82, /* also Linux swap partitions */
  201. NEW_SOLARIS_X86_PARTITION = 0xbf,