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