1
0

406-mtd-old-rootfs-squashfs-splitter.patch 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. --- a/drivers/mtd/Kconfig
  2. +++ b/drivers/mtd/Kconfig
  3. @@ -18,6 +18,11 @@ config MTD_ROOTFS_ROOT_DEV
  4. bool "Automatically set 'rootfs' partition to be root filesystem"
  5. default y
  6. +config MTD_ROOTFS_SPLIT
  7. + bool "Automatically split 'rootfs' partition for squashfs"
  8. + select MTD_SPLIT
  9. + default y
  10. +
  11. config MTD_SPLIT_FIRMWARE
  12. bool "Automatically split firmware partition for kernel+rootfs"
  13. default y
  14. --- a/drivers/mtd/mtdpart.c
  15. +++ b/drivers/mtd/mtdpart.c
  16. @@ -682,6 +682,47 @@ mtd_pad_erasesize(struct mtd_info *mtd,
  17. return len;
  18. }
  19. +static int split_squashfs(struct mtd_info *master, int offset, int *split_offset)
  20. +{
  21. + size_t squashfs_len;
  22. + int len, ret;
  23. +
  24. + ret = mtd_get_squashfs_len(master, offset, &squashfs_len);
  25. + if (ret)
  26. + return ret;
  27. +
  28. + len = mtd_pad_erasesize(master, offset, squashfs_len);
  29. + *split_offset = offset + len;
  30. +
  31. + return 0;
  32. +}
  33. +
  34. +static void split_rootfs_data(struct mtd_info *master, struct mtd_part *part)
  35. +{
  36. + unsigned int split_offset = 0;
  37. + unsigned int split_size;
  38. + int ret;
  39. +
  40. + ret = split_squashfs(master, part->offset, &split_offset);
  41. + if (ret)
  42. + return;
  43. +
  44. + if (split_offset <= 0)
  45. + return;
  46. +
  47. + if (config_enabled(CONFIG_MTD_SPLIT_SQUASHFS_ROOT))
  48. + pr_err("Dedicated partitioner didn't create \"rootfs_data\" partition, please fill a bug report!\n");
  49. + else
  50. + pr_warn("Support for built-in \"rootfs_data\" splitter will be removed, please use CONFIG_MTD_SPLIT_SQUASHFS_ROOT\n");
  51. +
  52. + split_size = part->mtd.size - (split_offset - part->offset);
  53. + printk(KERN_INFO "mtd: partition \"%s\" created automatically, ofs=0x%x, len=0x%x\n",
  54. + ROOTFS_SPLIT_NAME, split_offset, split_size);
  55. +
  56. + __mtd_add_partition(master, ROOTFS_SPLIT_NAME, split_offset,
  57. + split_size, false);
  58. +}
  59. +
  60. #define UBOOT_MAGIC 0x27051956
  61. static void split_uimage(struct mtd_info *master, struct mtd_part *part)
  62. @@ -744,7 +785,10 @@ static void mtd_partition_split(struct m
  63. return;
  64. if (!strcmp(part->mtd.name, "rootfs")) {
  65. - run_parsers_by_type(part, MTD_PARSER_TYPE_ROOTFS);
  66. + int num = run_parsers_by_type(part, MTD_PARSER_TYPE_ROOTFS);
  67. +
  68. + if (num <= 0 && config_enabled(CONFIG_MTD_ROOTFS_SPLIT))
  69. + split_rootfs_data(master, part);
  70. rootfs_found = 1;
  71. }