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