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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. From: Gabor Juhos <[email protected]>
  2. Subject: kernel/3.10: add separate rootfs partition parser
  3. lede-commit: daec7ad7688415156e2730e401503d09bd3acf91
  4. Signed-off-by: Gabor Juhos <[email protected]>
  5. ---
  6. drivers/mtd/mtdpart.c | 29 +++++++++++++++++++++++++++++
  7. include/linux/mtd/mtd.h | 18 ++++++++++++++++++
  8. include/linux/mtd/partitions.h | 2 ++
  9. 3 files changed, 49 insertions(+)
  10. --- a/drivers/mtd/mtdpart.c
  11. +++ b/drivers/mtd/mtdpart.c
  12. @@ -771,6 +771,17 @@ run_parsers_by_type(struct mtd_part *sla
  13. return nr_parts;
  14. }
  15. +static inline unsigned long
  16. +mtd_pad_erasesize(struct mtd_info *mtd, int offset, int len)
  17. +{
  18. + unsigned long mask = mtd->erasesize - 1;
  19. +
  20. + len += offset & mask;
  21. + len = (len + mask) & ~mask;
  22. + len -= offset & mask;
  23. + return len;
  24. +}
  25. +
  26. #ifdef CONFIG_MTD_SPLIT_FIRMWARE_NAME
  27. #define SPLIT_FIRMWARE_NAME CONFIG_MTD_SPLIT_FIRMWARE_NAME
  28. #else
  29. @@ -1223,6 +1234,24 @@ int mtd_is_partition(const struct mtd_in
  30. }
  31. EXPORT_SYMBOL_GPL(mtd_is_partition);
  32. +struct mtd_info *mtdpart_get_master(const struct mtd_info *mtd)
  33. +{
  34. + if (!mtd_is_partition(mtd))
  35. + return (struct mtd_info *)mtd;
  36. +
  37. + return mtd_to_part(mtd)->parent;
  38. +}
  39. +EXPORT_SYMBOL_GPL(mtdpart_get_master);
  40. +
  41. +uint64_t mtdpart_get_offset(const struct mtd_info *mtd)
  42. +{
  43. + if (!mtd_is_partition(mtd))
  44. + return 0;
  45. +
  46. + return mtd_to_part(mtd)->offset;
  47. +}
  48. +EXPORT_SYMBOL_GPL(mtdpart_get_offset);
  49. +
  50. /* Returns the size of the entire flash chip */
  51. uint64_t mtd_get_device_size(const struct mtd_info *mtd)
  52. {
  53. --- a/include/linux/mtd/mtd.h
  54. +++ b/include/linux/mtd/mtd.h
  55. @@ -493,6 +493,24 @@ static inline uint32_t mtd_mod_by_eb(uin
  56. return do_div(sz, mtd->erasesize);
  57. }
  58. +static inline uint64_t mtd_roundup_to_eb(uint64_t sz, struct mtd_info *mtd)
  59. +{
  60. + if (mtd_mod_by_eb(sz, mtd) == 0)
  61. + return sz;
  62. +
  63. + /* Round up to next erase block */
  64. + return (mtd_div_by_eb(sz, mtd) + 1) * mtd->erasesize;
  65. +}
  66. +
  67. +static inline uint64_t mtd_rounddown_to_eb(uint64_t sz, struct mtd_info *mtd)
  68. +{
  69. + if (mtd_mod_by_eb(sz, mtd) == 0)
  70. + return sz;
  71. +
  72. + /* Round down to the start of the current erase block */
  73. + return (mtd_div_by_eb(sz, mtd)) * mtd->erasesize;
  74. +}
  75. +
  76. static inline uint32_t mtd_div_by_ws(uint64_t sz, struct mtd_info *mtd)
  77. {
  78. if (mtd->writesize_shift)
  79. --- a/include/linux/mtd/partitions.h
  80. +++ b/include/linux/mtd/partitions.h
  81. @@ -115,6 +115,8 @@ int mtd_is_partition(const struct mtd_in
  82. int mtd_add_partition(struct mtd_info *master, const char *name,
  83. long long offset, long long length);
  84. int mtd_del_partition(struct mtd_info *master, int partno);
  85. +struct mtd_info *mtdpart_get_master(const struct mtd_info *mtd);
  86. +uint64_t mtdpart_get_offset(const struct mtd_info *mtd);
  87. uint64_t mtd_get_device_size(const struct mtd_info *mtd);
  88. extern void __weak arch_split_mtd_part(struct mtd_info *master,
  89. const char *name, int offset, int size);