050-revert_rootfs_splits.patch 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. --- a/drivers/mtd/mtdpart.c
  2. +++ b/drivers/mtd/mtdpart.c
  3. @@ -29,11 +29,9 @@
  4. #include <linux/kmod.h>
  5. #include <linux/mtd/mtd.h>
  6. #include <linux/mtd/partitions.h>
  7. -#include <linux/magic.h>
  8. #include <linux/err.h>
  9. #include "mtdcore.h"
  10. -#include "mtdsplit/mtdsplit.h"
  11. #define MTD_ERASE_PARTIAL 0x8000 /* partition only covers parts of an erase block */
  12. @@ -49,14 +47,13 @@ struct mtd_part {
  13. struct list_head list;
  14. };
  15. -static void mtd_partition_split(struct mtd_info *master, struct mtd_part *part);
  16. -
  17. /*
  18. * Given a pointer to the MTD object in the mtd_part structure, we can retrieve
  19. * the pointer to that structure with this macro.
  20. */
  21. #define PART(x) ((struct mtd_part *)(x))
  22. +
  23. /*
  24. * MTD methods which simply translate the effective address and pass through
  25. * to the _real_ device.
  26. @@ -520,12 +517,14 @@ static struct mtd_part *allocate_partiti
  27. if (slave->offset == MTDPART_OFS_APPEND)
  28. slave->offset = cur_offset;
  29. if (slave->offset == MTDPART_OFS_NXTBLK) {
  30. - /* Round up to next erasesize */
  31. - slave->offset = mtd_roundup_to_eb(cur_offset, master);
  32. - if (slave->offset != cur_offset)
  33. + slave->offset = cur_offset;
  34. + if (mtd_mod_by_eb(cur_offset, master) != 0) {
  35. + /* Round up to next erasesize */
  36. + slave->offset = (mtd_div_by_eb(cur_offset, master) + 1) * master->erasesize;
  37. printk(KERN_NOTICE "Moving partition %d: "
  38. "0x%012llx -> 0x%012llx\n", partno,
  39. (unsigned long long)cur_offset, (unsigned long long)slave->offset);
  40. + }
  41. }
  42. if (slave->offset == MTDPART_OFS_RETAIN) {
  43. slave->offset = cur_offset;
  44. @@ -626,10 +625,8 @@ out_register:
  45. return slave;
  46. }
  47. -
  48. -static int
  49. -__mtd_add_partition(struct mtd_info *master, const char *name,
  50. - long long offset, long long length, bool dup_check)
  51. +int mtd_add_partition(struct mtd_info *master, const char *name,
  52. + long long offset, long long length)
  53. {
  54. struct mtd_partition part;
  55. struct mtd_part *p, *new;
  56. @@ -661,24 +658,21 @@ __mtd_add_partition(struct mtd_info *mas
  57. end = offset + length;
  58. mutex_lock(&mtd_partitions_mutex);
  59. - if (dup_check) {
  60. - list_for_each_entry(p, &mtd_partitions, list)
  61. - if (p->master == master) {
  62. - if ((start >= p->offset) &&
  63. - (start < (p->offset + p->mtd.size)))
  64. - goto err_inv;
  65. -
  66. - if ((end >= p->offset) &&
  67. - (end < (p->offset + p->mtd.size)))
  68. - goto err_inv;
  69. - }
  70. - }
  71. + list_for_each_entry(p, &mtd_partitions, list)
  72. + if (p->master == master) {
  73. + if ((start >= p->offset) &&
  74. + (start < (p->offset + p->mtd.size)))
  75. + goto err_inv;
  76. +
  77. + if ((end >= p->offset) &&
  78. + (end < (p->offset + p->mtd.size)))
  79. + goto err_inv;
  80. + }
  81. list_add(&new->list, &mtd_partitions);
  82. mutex_unlock(&mtd_partitions_mutex);
  83. add_mtd_device(&new->mtd);
  84. - mtd_partition_split(master, new);
  85. return ret;
  86. err_inv:
  87. @@ -688,12 +682,6 @@ err_inv:
  88. }
  89. EXPORT_SYMBOL_GPL(mtd_add_partition);
  90. -int mtd_add_partition(struct mtd_info *master, const char *name,
  91. - long long offset, long long length)
  92. -{
  93. - return __mtd_add_partition(master, name, offset, length, true);
  94. -}
  95. -
  96. int mtd_del_partition(struct mtd_info *master, int partno)
  97. {
  98. struct mtd_part *slave, *next;
  99. @@ -717,166 +705,6 @@ int mtd_del_partition(struct mtd_info *m
  100. }
  101. EXPORT_SYMBOL_GPL(mtd_del_partition);
  102. -static int
  103. -run_parsers_by_type(struct mtd_part *slave, enum mtd_parser_type type)
  104. -{
  105. - struct mtd_partition *parts;
  106. - int nr_parts;
  107. - int i;
  108. -
  109. - nr_parts = parse_mtd_partitions_by_type(&slave->mtd, type, &parts,
  110. - NULL);
  111. - if (nr_parts <= 0)
  112. - return nr_parts;
  113. -
  114. - if (WARN_ON(!parts))
  115. - return 0;
  116. -
  117. - for (i = 0; i < nr_parts; i++) {
  118. - /* adjust partition offsets */
  119. - parts[i].offset += slave->offset;
  120. -
  121. - __mtd_add_partition(slave->master,
  122. - parts[i].name,
  123. - parts[i].offset,
  124. - parts[i].size,
  125. - false);
  126. - }
  127. -
  128. - kfree(parts);
  129. -
  130. - return nr_parts;
  131. -}
  132. -
  133. -static inline unsigned long
  134. -mtd_pad_erasesize(struct mtd_info *mtd, int offset, int len)
  135. -{
  136. - unsigned long mask = mtd->erasesize - 1;
  137. -
  138. - len += offset & mask;
  139. - len = (len + mask) & ~mask;
  140. - len -= offset & mask;
  141. - return len;
  142. -}
  143. -
  144. -static int split_squashfs(struct mtd_info *master, int offset, int *split_offset)
  145. -{
  146. - size_t squashfs_len;
  147. - int len, ret;
  148. -
  149. - ret = mtd_get_squashfs_len(master, offset, &squashfs_len);
  150. - if (ret)
  151. - return ret;
  152. -
  153. - len = mtd_pad_erasesize(master, offset, squashfs_len);
  154. - *split_offset = offset + len;
  155. -
  156. - return 0;
  157. -}
  158. -
  159. -static void split_rootfs_data(struct mtd_info *master, struct mtd_part *part)
  160. -{
  161. - unsigned int split_offset = 0;
  162. - unsigned int split_size;
  163. - int ret;
  164. -
  165. - ret = split_squashfs(master, part->offset, &split_offset);
  166. - if (ret)
  167. - return;
  168. -
  169. - if (split_offset <= 0)
  170. - return;
  171. -
  172. - if (config_enabled(CONFIG_MTD_SPLIT_SQUASHFS_ROOT))
  173. - pr_err("Dedicated partitioner didn't create \"rootfs_data\" partition, please fill a bug report!\n");
  174. - else
  175. - pr_warn("Support for built-in \"rootfs_data\" splitter will be removed, please use CONFIG_MTD_SPLIT_SQUASHFS_ROOT\n");
  176. -
  177. - split_size = part->mtd.size - (split_offset - part->offset);
  178. - printk(KERN_INFO "mtd: partition \"%s\" created automatically, ofs=0x%x, len=0x%x\n",
  179. - ROOTFS_SPLIT_NAME, split_offset, split_size);
  180. -
  181. - __mtd_add_partition(master, ROOTFS_SPLIT_NAME, split_offset,
  182. - split_size, false);
  183. -}
  184. -
  185. -#define UBOOT_MAGIC 0x27051956
  186. -
  187. -static void split_uimage(struct mtd_info *master, struct mtd_part *part)
  188. -{
  189. - struct {
  190. - __be32 magic;
  191. - __be32 pad[2];
  192. - __be32 size;
  193. - } hdr;
  194. - size_t len;
  195. -
  196. - if (mtd_read(master, part->offset, sizeof(hdr), &len, (void *) &hdr))
  197. - return;
  198. -
  199. - if (len != sizeof(hdr) || hdr.magic != cpu_to_be32(UBOOT_MAGIC))
  200. - return;
  201. -
  202. - len = be32_to_cpu(hdr.size) + 0x40;
  203. - len = mtd_pad_erasesize(master, part->offset, len);
  204. - if (len + master->erasesize > part->mtd.size)
  205. - return;
  206. -
  207. - if (config_enabled(CONFIG_MTD_SPLIT_UIMAGE_FW))
  208. - pr_err("Dedicated partitioner didn't split firmware partition, please fill a bug report!\n");
  209. - else
  210. - pr_warn("Support for built-in firmware splitter will be removed, please use CONFIG_MTD_SPLIT_UIMAGE_FW\n");
  211. -
  212. - __mtd_add_partition(master, "rootfs", part->offset + len,
  213. - part->mtd.size - len, false);
  214. -}
  215. -
  216. -#ifdef CONFIG_MTD_SPLIT_FIRMWARE_NAME
  217. -#define SPLIT_FIRMWARE_NAME CONFIG_MTD_SPLIT_FIRMWARE_NAME
  218. -#else
  219. -#define SPLIT_FIRMWARE_NAME "unused"
  220. -#endif
  221. -
  222. -static void split_firmware(struct mtd_info *master, struct mtd_part *part)
  223. -{
  224. - int ret;
  225. -
  226. - ret = run_parsers_by_type(part, MTD_PARSER_TYPE_FIRMWARE);
  227. - if (ret > 0)
  228. - return;
  229. -
  230. - if (config_enabled(CONFIG_MTD_UIMAGE_SPLIT))
  231. - split_uimage(master, part);
  232. -}
  233. -
  234. -void __weak arch_split_mtd_part(struct mtd_info *master, const char *name,
  235. - int offset, int size)
  236. -{
  237. -}
  238. -
  239. -static void mtd_partition_split(struct mtd_info *master, struct mtd_part *part)
  240. -{
  241. - static int rootfs_found = 0;
  242. -
  243. - if (rootfs_found)
  244. - return;
  245. -
  246. - if (!strcmp(part->mtd.name, "rootfs")) {
  247. - int num = run_parsers_by_type(part, MTD_PARSER_TYPE_ROOTFS);
  248. -
  249. - if (num <= 0 && config_enabled(CONFIG_MTD_ROOTFS_SPLIT))
  250. - split_rootfs_data(master, part);
  251. -
  252. - rootfs_found = 1;
  253. - }
  254. -
  255. - if (!strcmp(part->mtd.name, SPLIT_FIRMWARE_NAME) &&
  256. - config_enabled(CONFIG_MTD_SPLIT_FIRMWARE))
  257. - split_firmware(master, part);
  258. -
  259. - arch_split_mtd_part(master, part->mtd.name, part->offset,
  260. - part->mtd.size);
  261. -}
  262. /*
  263. * This function, given a master MTD object and a partition table, creates
  264. * and registers slave MTD objects which are bound to the master according to
  265. @@ -906,7 +734,6 @@ int add_mtd_partitions(struct mtd_info *
  266. mutex_unlock(&mtd_partitions_mutex);
  267. add_mtd_device(&slave->mtd);
  268. - mtd_partition_split(master, slave);
  269. cur_offset = slave->offset + slave->mtd.size;
  270. }
  271. @@ -936,30 +763,6 @@ static struct mtd_part_parser *get_parti
  272. #define put_partition_parser(p) do { module_put((p)->owner); } while (0)
  273. -static struct mtd_part_parser *
  274. -get_partition_parser_by_type(enum mtd_parser_type type,
  275. - struct mtd_part_parser *start)
  276. -{
  277. - struct mtd_part_parser *p, *ret = NULL;
  278. -
  279. - spin_lock(&part_parser_lock);
  280. -
  281. - p = list_prepare_entry(start, &part_parsers, list);
  282. - if (start)
  283. - put_partition_parser(start);
  284. -
  285. - list_for_each_entry_continue(p, &part_parsers, list) {
  286. - if (p->type == type && try_module_get(p->owner)) {
  287. - ret = p;
  288. - break;
  289. - }
  290. - }
  291. -
  292. - spin_unlock(&part_parser_lock);
  293. -
  294. - return ret;
  295. -}
  296. -
  297. void register_mtd_parser(struct mtd_part_parser *p)
  298. {
  299. spin_lock(&part_parser_lock);
  300. @@ -1033,38 +836,6 @@ int parse_mtd_partitions(struct mtd_info
  301. return ret;
  302. }
  303. -int parse_mtd_partitions_by_type(struct mtd_info *master,
  304. - enum mtd_parser_type type,
  305. - struct mtd_partition **pparts,
  306. - struct mtd_part_parser_data *data)
  307. -{
  308. - struct mtd_part_parser *prev = NULL;
  309. - int ret = 0;
  310. -
  311. - while (1) {
  312. - struct mtd_part_parser *parser;
  313. -
  314. - parser = get_partition_parser_by_type(type, prev);
  315. - if (!parser)
  316. - break;
  317. -
  318. - ret = (*parser->parse_fn)(master, pparts, data);
  319. -
  320. - if (ret > 0) {
  321. - put_partition_parser(parser);
  322. - printk(KERN_NOTICE
  323. - "%d %s partitions found on MTD device %s\n",
  324. - ret, parser->name, master->name);
  325. - break;
  326. - }
  327. -
  328. - prev = parser;
  329. - }
  330. -
  331. - return ret;
  332. -}
  333. -EXPORT_SYMBOL_GPL(parse_mtd_partitions_by_type);
  334. -
  335. int mtd_is_partition(const struct mtd_info *mtd)
  336. {
  337. struct mtd_part *part;