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