2
0

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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. @@ -414,6 +414,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. @@ -10,6 +10,10 @@
  73. #include <linux/ctype.h>
  74. #include <linux/vmalloc.h>
  75. #include <linux/raid/detect.h>
  76. +#ifdef CONFIG_FIT_PARTITION
  77. +#include <linux/root_dev.h>
  78. +#endif
  79. +
  80. #include "check.h"
  81. static int (*check_part[])(struct parsed_partitions *) = {
  82. @@ -46,6 +50,9 @@ static int (*check_part[])(struct parsed
  83. #ifdef CONFIG_EFI_PARTITION
  84. efi_partition, /* this must come before msdos */
  85. #endif
  86. +#ifdef CONFIG_FIT_PARTITION
  87. + fit_partition,
  88. +#endif
  89. #ifdef CONFIG_SGI_PARTITION
  90. sgi_partition,
  91. #endif
  92. @@ -398,6 +405,11 @@ static struct block_device *add_partitio
  93. goto out_del;
  94. }
  95. +#ifdef CONFIG_FIT_PARTITION
  96. + if (flags & ADDPART_FLAG_READONLY)
  97. + bdev->bd_read_only = true;
  98. +#endif
  99. +
  100. /* everything is up and running, commence */
  101. err = xa_insert(&disk->part_tbl, partno, bdev, GFP_KERNEL);
  102. if (err)
  103. @@ -590,6 +602,11 @@ static bool blk_add_partition(struct gen
  104. (state->parts[p].flags & ADDPART_FLAG_RAID))
  105. md_autodetect_dev(part->bd_dev);
  106. +#ifdef CONFIG_FIT_PARTITION
  107. + if ((state->parts[p].flags & ADDPART_FLAG_ROOTDEV) && ROOT_DEV == 0)
  108. + ROOT_DEV = part->bd_dev;
  109. +#endif
  110. +
  111. return true;
  112. }
  113. --- a/block/partitions/efi.c
  114. +++ b/block/partitions/efi.c
  115. @@ -716,6 +716,9 @@ int efi_partition(struct parsed_partitio
  116. gpt_entry *ptes = NULL;
  117. u32 i;
  118. unsigned ssz = queue_logical_block_size(state->disk->queue) / 512;
  119. +#ifdef CONFIG_FIT_PARTITION
  120. + u32 extra_slot = 64;
  121. +#endif
  122. if (!find_valid_gpt(state, &gpt, &ptes) || !gpt || !ptes) {
  123. kfree(gpt);
  124. @@ -749,6 +752,11 @@ int efi_partition(struct parsed_partitio
  125. ARRAY_SIZE(ptes[i].partition_name));
  126. utf16_le_to_7bit(ptes[i].partition_name, label_max, info->volname);
  127. state->parts[i + 1].has_info = true;
  128. +#ifdef CONFIG_FIT_PARTITION
  129. + /* If this is a U-Boot FIT volume it may have subpartitions */
  130. + if (!efi_guidcmp(ptes[i].partition_type_guid, PARTITION_LINUX_FIT_GUID))
  131. + (void) parse_fit_partitions(state, start * ssz, size * ssz, &extra_slot, 1);
  132. +#endif
  133. }
  134. kfree(ptes);
  135. kfree(gpt);
  136. --- a/block/partitions/efi.h
  137. +++ b/block/partitions/efi.h
  138. @@ -51,6 +51,9 @@
  139. #define PARTITION_LINUX_LVM_GUID \
  140. EFI_GUID( 0xe6d6d379, 0xf507, 0x44c2, \
  141. 0xa2, 0x3c, 0x23, 0x8f, 0x2a, 0x3d, 0xf9, 0x28)
  142. +#define PARTITION_LINUX_FIT_GUID \
  143. + EFI_GUID( 0xcae9be83, 0xb15f, 0x49cc, \
  144. + 0x86, 0x3f, 0x08, 0x1b, 0x74, 0x4a, 0x2d, 0x93)
  145. typedef struct _gpt_header {
  146. __le64 signature;
  147. --- a/block/partitions/msdos.c
  148. +++ b/block/partitions/msdos.c
  149. @@ -564,6 +564,15 @@ static void parse_minix(struct parsed_pa
  150. #endif /* CONFIG_MINIX_SUBPARTITION */
  151. }
  152. +static void parse_fit_mbr(struct parsed_partitions *state,
  153. + sector_t offset, sector_t size, int origin)
  154. +{
  155. +#ifdef CONFIG_FIT_PARTITION
  156. + u32 extra_slot = 64;
  157. + (void) parse_fit_partitions(state, offset, size, &extra_slot, 1);
  158. +#endif /* CONFIG_FIT_PARTITION */
  159. +}
  160. +
  161. static struct {
  162. unsigned char id;
  163. void (*parse)(struct parsed_partitions *, sector_t, sector_t, int);
  164. @@ -575,6 +584,7 @@ static struct {
  165. {UNIXWARE_PARTITION, parse_unixware},
  166. {SOLARIS_X86_PARTITION, parse_solaris_x86},
  167. {NEW_SOLARIS_X86_PARTITION, parse_solaris_x86},
  168. + {FIT_PARTITION, parse_fit_mbr},
  169. {0, NULL},
  170. };
  171. --- a/drivers/mtd/mtd_blkdevs.c
  172. +++ b/drivers/mtd/mtd_blkdevs.c
  173. @@ -359,7 +359,9 @@ int add_mtd_blktrans_dev(struct mtd_blkt
  174. } else {
  175. snprintf(gd->disk_name, sizeof(gd->disk_name),
  176. "%s%d", tr->name, new->devnum);
  177. - gd->flags |= GENHD_FL_NO_PART;
  178. +
  179. + if (!IS_ENABLED(CONFIG_FIT_PARTITION) || mtd_type_is_nand(new->mtd))
  180. + gd->flags |= GENHD_FL_NO_PART;
  181. }
  182. set_capacity(gd, ((u64)new->size * tr->blksize) >> 9);
  183. --- a/drivers/mtd/ubi/block.c
  184. +++ b/drivers/mtd/ubi/block.c
  185. @@ -431,7 +431,9 @@ int ubiblock_create(struct ubi_volume_in
  186. ret = -ENODEV;
  187. goto out_cleanup_disk;
  188. }
  189. - gd->flags |= GENHD_FL_NO_PART;
  190. + if (!IS_ENABLED(CONFIG_FIT_PARTITION))
  191. + gd->flags |= GENHD_FL_NO_PART;
  192. +
  193. gd->private_data = dev;
  194. sprintf(gd->disk_name, "ubiblock%d_%d", dev->ubi_num, dev->vol_id);
  195. set_capacity(gd, disk_capacity);
  196. --- a/include/linux/msdos_partition.h
  197. +++ b/include/linux/msdos_partition.h
  198. @@ -31,6 +31,7 @@ enum msdos_sys_ind {
  199. LINUX_LVM_PARTITION = 0x8e,
  200. LINUX_RAID_PARTITION = 0xfd, /* autodetect RAID partition */
  201. + FIT_PARTITION = 0x2e, /* U-Boot uImage.FIT */
  202. SOLARIS_X86_PARTITION = 0x82, /* also Linux swap partitions */
  203. NEW_SOLARIS_X86_PARTITION = 0xbf,