404-mtd-add-more-helper-functions.patch 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. --- a/drivers/mtd/mtdpart.c
  2. +++ b/drivers/mtd/mtdpart.c
  3. @@ -454,14 +454,12 @@ static struct mtd_part *allocate_partiti
  4. if (slave->offset == MTDPART_OFS_APPEND)
  5. slave->offset = cur_offset;
  6. if (slave->offset == MTDPART_OFS_NXTBLK) {
  7. - slave->offset = cur_offset;
  8. - if (mtd_mod_by_eb(cur_offset, master) != 0) {
  9. - /* Round up to next erasesize */
  10. - slave->offset = (mtd_div_by_eb(cur_offset, master) + 1) * master->erasesize;
  11. + /* Round up to next erasesize */
  12. + slave->offset = mtd_roundup_to_eb(cur_offset, master);
  13. + if (slave->offset != cur_offset)
  14. printk(KERN_NOTICE "Moving partition %d: "
  15. "0x%012llx -> 0x%012llx\n", partno,
  16. (unsigned long long)cur_offset, (unsigned long long)slave->offset);
  17. - }
  18. }
  19. if (slave->offset == MTDPART_OFS_RETAIN) {
  20. slave->offset = cur_offset;
  21. @@ -679,6 +677,17 @@ run_parsers_by_type(struct mtd_part *sla
  22. return nr_parts;
  23. }
  24. +static inline unsigned long
  25. +mtd_pad_erasesize(struct mtd_info *mtd, int offset, int len)
  26. +{
  27. + unsigned long mask = mtd->erasesize - 1;
  28. +
  29. + len += offset & mask;
  30. + len = (len + mask) & ~mask;
  31. + len -= offset & mask;
  32. + return len;
  33. +}
  34. +
  35. #ifdef CONFIG_MTD_SPLIT_FIRMWARE_NAME
  36. #define SPLIT_FIRMWARE_NAME CONFIG_MTD_SPLIT_FIRMWARE_NAME
  37. #else
  38. @@ -978,6 +987,24 @@ int mtd_is_partition(const struct mtd_in
  39. }
  40. EXPORT_SYMBOL_GPL(mtd_is_partition);
  41. +struct mtd_info *mtdpart_get_master(const struct mtd_info *mtd)
  42. +{
  43. + if (!mtd_is_partition(mtd))
  44. + return (struct mtd_info *)mtd;
  45. +
  46. + return PART(mtd)->master;
  47. +}
  48. +EXPORT_SYMBOL_GPL(mtdpart_get_master);
  49. +
  50. +uint64_t mtdpart_get_offset(const struct mtd_info *mtd)
  51. +{
  52. + if (!mtd_is_partition(mtd))
  53. + return 0;
  54. +
  55. + return PART(mtd)->offset;
  56. +}
  57. +EXPORT_SYMBOL_GPL(mtdpart_get_offset);
  58. +
  59. /* Returns the size of the entire flash chip */
  60. uint64_t mtd_get_device_size(const struct mtd_info *mtd)
  61. {
  62. --- a/include/linux/mtd/partitions.h
  63. +++ b/include/linux/mtd/partitions.h
  64. @@ -90,6 +90,8 @@ int mtd_is_partition(const struct mtd_in
  65. int mtd_add_partition(struct mtd_info *master, const char *name,
  66. long long offset, long long length);
  67. int mtd_del_partition(struct mtd_info *master, int partno);
  68. +struct mtd_info *mtdpart_get_master(const struct mtd_info *mtd);
  69. +uint64_t mtdpart_get_offset(const struct mtd_info *mtd);
  70. uint64_t mtd_get_device_size(const struct mtd_info *mtd);
  71. extern void __weak arch_split_mtd_part(struct mtd_info *master,
  72. const char *name, int offset, int size);
  73. --- a/include/linux/mtd/mtd.h
  74. +++ b/include/linux/mtd/mtd.h
  75. @@ -334,6 +334,24 @@ static inline uint32_t mtd_mod_by_eb(uin
  76. return do_div(sz, mtd->erasesize);
  77. }
  78. +static inline uint64_t mtd_roundup_to_eb(uint64_t sz, struct mtd_info *mtd)
  79. +{
  80. + if (mtd_mod_by_eb(sz, mtd) == 0)
  81. + return sz;
  82. +
  83. + /* Round up to next erase block */
  84. + return (mtd_div_by_eb(sz, mtd) + 1) * mtd->erasesize;
  85. +}
  86. +
  87. +static inline uint64_t mtd_rounddown_to_eb(uint64_t sz, struct mtd_info *mtd)
  88. +{
  89. + if (mtd_mod_by_eb(sz, mtd) == 0)
  90. + return sz;
  91. +
  92. + /* Round down to the start of the current erase block */
  93. + return (mtd_div_by_eb(sz, mtd)) * mtd->erasesize;
  94. +}
  95. +
  96. static inline uint32_t mtd_div_by_ws(uint64_t sz, struct mtd_info *mtd)
  97. {
  98. if (mtd->writesize_shift)