405-mtd-add-more-helper-functions.patch 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. --- a/drivers/mtd/mtdpart.c
  2. +++ b/drivers/mtd/mtdpart.c
  3. @@ -445,14 +445,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. @@ -957,6 +955,24 @@ int mtd_is_partition(const struct mtd_in
  22. }
  23. EXPORT_SYMBOL_GPL(mtd_is_partition);
  24. +struct mtd_info *mtdpart_get_master(const struct mtd_info *mtd)
  25. +{
  26. + if (!mtd_is_partition(mtd))
  27. + return (struct mtd_info *)mtd;
  28. +
  29. + return PART(mtd)->master;
  30. +}
  31. +EXPORT_SYMBOL_GPL(mtdpart_get_master);
  32. +
  33. +uint64_t mtdpart_get_offset(const struct mtd_info *mtd)
  34. +{
  35. + if (!mtd_is_partition(mtd))
  36. + return 0;
  37. +
  38. + return PART(mtd)->offset;
  39. +}
  40. +EXPORT_SYMBOL_GPL(mtdpart_get_offset);
  41. +
  42. /* Returns the size of the entire flash chip */
  43. uint64_t mtd_get_device_size(const struct mtd_info *mtd)
  44. {
  45. --- a/include/linux/mtd/partitions.h
  46. +++ b/include/linux/mtd/partitions.h
  47. @@ -90,6 +90,8 @@ int mtd_is_partition(const struct mtd_in
  48. int mtd_add_partition(struct mtd_info *master, const char *name,
  49. long long offset, long long length);
  50. int mtd_del_partition(struct mtd_info *master, int partno);
  51. +struct mtd_info *mtdpart_get_master(const struct mtd_info *mtd);
  52. +uint64_t mtdpart_get_offset(const struct mtd_info *mtd);
  53. uint64_t mtd_get_device_size(const struct mtd_info *mtd);
  54. extern void __weak arch_split_mtd_part(struct mtd_info *master,
  55. const char *name, int offset, int size);
  56. --- a/include/linux/mtd/mtd.h
  57. +++ b/include/linux/mtd/mtd.h
  58. @@ -333,6 +333,24 @@ static inline uint32_t mtd_mod_by_eb(uin
  59. return do_div(sz, mtd->erasesize);
  60. }
  61. +static inline uint64_t mtd_roundup_to_eb(uint64_t sz, struct mtd_info *mtd)
  62. +{
  63. + if (mtd_mod_by_eb(sz, mtd) == 0)
  64. + return sz;
  65. +
  66. + /* Round up to next erase block */
  67. + return (mtd_div_by_eb(sz, mtd) + 1) * mtd->erasesize;
  68. +}
  69. +
  70. +static inline uint64_t mtd_rounddown_to_eb(uint64_t sz, struct mtd_info *mtd)
  71. +{
  72. + if (mtd_mod_by_eb(sz, mtd) == 0)
  73. + return sz;
  74. +
  75. + /* Round down to the start of the current erase block */
  76. + return (mtd_div_by_eb(sz, mtd)) * mtd->erasesize;
  77. +}
  78. +
  79. static inline uint32_t mtd_div_by_ws(uint64_t sz, struct mtd_info *mtd)
  80. {
  81. if (mtd->writesize_shift)