ubispl.h 4.5 KB

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