ubispl.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * Copyright (c) Thomas Gleixner <tglx@linutronix.de>
  3. *
  4. * SPDX-License-Identifier: GPL 2.0+ BSD-3-Clause
  5. */
  6. #ifndef _UBOOT_MTD_UBISPL_H
  7. #define _UBOOT_MTD_UBISPL_H
  8. #include "../ubi/ubi-media.h"
  9. #include "ubi-wrapper.h"
  10. /*
  11. * The maximum number of volume ids we scan. So you can load volume id
  12. * 0 to (CONFIG_SPL_UBI_VOL_ID_MAX - 1)
  13. */
  14. #define UBI_SPL_VOL_IDS CONFIG_SPL_UBI_VOL_IDS
  15. /*
  16. * The size of the read buffer for the fastmap blocks. In theory up to
  17. * UBI_FM_MAX_BLOCKS * CONFIG_SPL_MAX_PEB_SIZE. In practice today
  18. * one or two blocks.
  19. */
  20. #define UBI_FM_BUF_SIZE (UBI_FM_MAX_BLOCKS*CONFIG_SPL_UBI_MAX_PEB_SIZE)
  21. /*
  22. * The size of the bitmaps for the attach/ scan
  23. */
  24. #define UBI_FM_BM_SIZE ((CONFIG_SPL_UBI_MAX_PEBS / BITS_PER_LONG) + 1)
  25. /*
  26. * The maximum number of logical erase blocks per loadable volume
  27. */
  28. #define UBI_MAX_VOL_LEBS CONFIG_SPL_UBI_MAX_VOL_LEBS
  29. /*
  30. * The bitmap size for the above to denote the found blocks inside the volume
  31. */
  32. #define UBI_VOL_BM_SIZE ((UBI_MAX_VOL_LEBS / BITS_PER_LONG) + 1)
  33. /**
  34. * struct ubi_vol_info - UBISPL internal volume represenation
  35. * @last_block: The last block (highest LEB) found for this volume
  36. * @found: Bitmap to mark found LEBS
  37. * @lebs_to_pebs: LEB to PEB translation table
  38. */
  39. struct ubi_vol_info {
  40. u32 last_block;
  41. unsigned long found[UBI_VOL_BM_SIZE];
  42. u32 lebs_to_pebs[UBI_MAX_VOL_LEBS];
  43. };
  44. /**
  45. * struct ubi_scan_info - UBISPL internal data for FM attach and full scan
  46. *
  47. * @read: Read function to access the flash provided by the caller
  48. * @peb_count: Number of physical erase blocks in the UBI FLASH area
  49. * aka MTD partition.
  50. * @peb_offset: Offset of PEB0 in the UBI FLASH area (aka MTD partition)
  51. * to the real start of the FLASH in erase blocks.
  52. * @fsize_mb: Size of the scanned FLASH area in MB (stats only)
  53. * @vid_offset: Offset from the start of a PEB to the VID header
  54. * @leb_start: Offset from the start of a PEB to the data area
  55. * @leb_size: Size of the data area
  56. *
  57. * @fastmap_pebs: Counter of PEBs "attached" by fastmap
  58. * @fastmap_anchor: The anchor PEB of the fastmap
  59. * @fm_sb: The fastmap super block data
  60. * @fm_vh: The fastmap VID header
  61. * @fm: Pointer to the fastmap layout
  62. * @fm_layout: The fastmap layout itself
  63. * @fm_pool: The pool of PEBs to scan at fastmap attach time
  64. * @fm_wl_pool: The pool of PEBs scheduled for wearleveling
  65. *
  66. * @fm_enabled: Indicator whether fastmap attachment is enabled.
  67. * @fm_used: Bitmap to indicate the PEBS covered by fastmap
  68. * @scanned: Bitmap to indicate the PEBS of which the VID header
  69. * hase been physically scanned.
  70. * @corrupt: Bitmap to indicate corrupt blocks
  71. * @toload: Bitmap to indicate the volumes which should be loaded
  72. *
  73. * @blockinfo: The vid headers of the scanned blocks
  74. * @volinfo: The volume information of the interesting (toload)
  75. * volumes
  76. *
  77. * @fm_buf: The large fastmap attach buffer
  78. */
  79. struct ubi_scan_info {
  80. ubispl_read_flash read;
  81. unsigned int fsize_mb;
  82. unsigned int peb_count;
  83. unsigned int peb_offset;
  84. unsigned long vid_offset;
  85. unsigned long leb_start;
  86. unsigned long leb_size;
  87. /* Fastmap: The upstream required fields */
  88. int fastmap_pebs;
  89. int fastmap_anchor;
  90. size_t fm_size;
  91. struct ubi_fm_sb fm_sb;
  92. struct ubi_vid_hdr fm_vh;
  93. struct ubi_fastmap_layout *fm;
  94. struct ubi_fastmap_layout fm_layout;
  95. struct ubi_fm_pool fm_pool;
  96. struct ubi_fm_pool fm_wl_pool;
  97. /* Fastmap: UBISPL specific data */
  98. int fm_enabled;
  99. unsigned long fm_used[UBI_FM_BM_SIZE];
  100. unsigned long scanned[UBI_FM_BM_SIZE];
  101. unsigned long corrupt[UBI_FM_BM_SIZE];
  102. unsigned long toload[UBI_FM_BM_SIZE];
  103. /* Data for storing the VID and volume information */
  104. struct ubi_vol_info volinfo[UBI_SPL_VOL_IDS];
  105. struct ubi_vid_hdr blockinfo[CONFIG_SPL_UBI_MAX_PEBS];
  106. /* The large buffer for the fastmap */
  107. uint8_t fm_buf[UBI_FM_BUF_SIZE];
  108. };
  109. #ifdef CFG_DEBUG
  110. #define ubi_dbg(fmt, ...) printf("UBI: debug:" fmt "\n", ##__VA_ARGS__)
  111. #else
  112. #define ubi_dbg(fmt, ...)
  113. #endif
  114. #ifdef CONFIG_UBI_SILENCE_MSG
  115. #define ubi_msg(fmt, ...)
  116. #else
  117. #define ubi_msg(fmt, ...) printf("UBI: " fmt "\n", ##__VA_ARGS__)
  118. #endif
  119. /* UBI warning messages */
  120. #define ubi_warn(fmt, ...) printf("UBI warning: " fmt "\n", ##__VA_ARGS__)
  121. /* UBI error messages */
  122. #define ubi_err(fmt, ...) printf("UBI error: " fmt "\n", ##__VA_ARGS__)
  123. #endif