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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. @@ -1165,6 +1165,24 @@ int mtd_is_partition(const struct mtd_in
  13. }
  14. EXPORT_SYMBOL_GPL(mtd_is_partition);
  15. +struct mtd_info *mtd_get_master(const struct mtd_info *mtd)
  16. +{
  17. + if (!mtd_is_partition(mtd))
  18. + return (struct mtd_info *)mtd;
  19. +
  20. + return mtd_to_part(mtd)->parent;
  21. +}
  22. +EXPORT_SYMBOL_GPL(mtd_get_master);
  23. +
  24. +uint64_t mtdpart_get_offset(const struct mtd_info *mtd)
  25. +{
  26. + if (!mtd_is_partition(mtd))
  27. + return 0;
  28. +
  29. + return mtd_to_part(mtd)->offset;
  30. +}
  31. +EXPORT_SYMBOL_GPL(mtdpart_get_offset);
  32. +
  33. /* Returns the size of the entire flash chip */
  34. uint64_t mtd_get_device_size(const struct mtd_info *mtd)
  35. {
  36. --- a/include/linux/mtd/mtd.h
  37. +++ b/include/linux/mtd/mtd.h
  38. @@ -504,6 +504,24 @@ static inline void mtd_align_erase_req(s
  39. req->len += mtd->erasesize - mod;
  40. }
  41. +static inline uint64_t mtd_roundup_to_eb(uint64_t sz, struct mtd_info *mtd)
  42. +{
  43. + if (mtd_mod_by_eb(sz, mtd) == 0)
  44. + return sz;
  45. +
  46. + /* Round up to next erase block */
  47. + return (mtd_div_by_eb(sz, mtd) + 1) * mtd->erasesize;
  48. +}
  49. +
  50. +static inline uint64_t mtd_rounddown_to_eb(uint64_t sz, struct mtd_info *mtd)
  51. +{
  52. + if (mtd_mod_by_eb(sz, mtd) == 0)
  53. + return sz;
  54. +
  55. + /* Round down to the start of the current erase block */
  56. + return (mtd_div_by_eb(sz, mtd)) * mtd->erasesize;
  57. +}
  58. +
  59. static inline uint32_t mtd_div_by_ws(uint64_t sz, struct mtd_info *mtd)
  60. {
  61. if (mtd->writesize_shift)
  62. --- a/include/linux/mtd/partitions.h
  63. +++ b/include/linux/mtd/partitions.h
  64. @@ -116,6 +116,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 *mtd_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. #endif