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