xref: /openbmc/u-boot/drivers/mtd/ubispl/ubispl.h (revision dd1033e4)
1 /* SPDX-License-Identifier: GPL 2.0+ OR BSD-3-Clause */
2 /*
3  * Copyright (c) Thomas Gleixner <tglx@linutronix.de>
4  */
5 
6 #ifndef _UBOOT_MTD_UBISPL_H
7 #define _UBOOT_MTD_UBISPL_H
8 
9 #include "../ubi/ubi-media.h"
10 #include "ubi-wrapper.h"
11 
12 /*
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)
15  */
16 #define UBI_SPL_VOL_IDS		CONFIG_SPL_UBI_VOL_IDS
17 /*
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
20  * one or two blocks.
21  */
22 #define UBI_FM_BUF_SIZE		(UBI_FM_MAX_BLOCKS*CONFIG_SPL_UBI_MAX_PEB_SIZE)
23 /*
24  * The size of the bitmaps for the attach/ scan
25  */
26 #define UBI_FM_BM_SIZE		((CONFIG_SPL_UBI_MAX_PEBS / BITS_PER_LONG) + 1)
27 /*
28  * The maximum number of logical erase blocks per loadable volume
29  */
30 #define UBI_MAX_VOL_LEBS	CONFIG_SPL_UBI_MAX_VOL_LEBS
31 /*
32  * The bitmap size for the above to denote the found blocks inside the volume
33  */
34 #define UBI_VOL_BM_SIZE		((UBI_MAX_VOL_LEBS / BITS_PER_LONG) + 1)
35 
36 /**
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
41  */
42 struct ubi_vol_info {
43 	u32				last_block;
44 	unsigned long			found[UBI_VOL_BM_SIZE];
45 	u32				lebs_to_pebs[UBI_MAX_VOL_LEBS];
46 };
47 
48 /**
49  * struct ubi_scan_info - UBISPL internal data for FM attach and full scan
50  *
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
53  *			aka MTD partition.
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
60  *
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
69  *
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
76  *
77  * @blockinfo:		The vid headers of the scanned blocks
78  * @volinfo:		The volume information of the interesting (toload)
79  *			volumes
80  *
81  * @fm_buf:		The large fastmap attach buffer
82  */
83 struct ubi_scan_info {
84 	ubispl_read_flash		read;
85 	unsigned int			fsize_mb;
86 	unsigned int			peb_count;
87 	unsigned int			peb_offset;
88 
89 	unsigned long			vid_offset;
90 	unsigned long			leb_start;
91 	unsigned long			leb_size;
92 
93 	/* Fastmap: The upstream required fields */
94 	int				fastmap_pebs;
95 	int				fastmap_anchor;
96 	size_t				fm_size;
97 	struct ubi_fm_sb		fm_sb;
98 	struct ubi_vid_hdr		fm_vh;
99 	struct ubi_fastmap_layout	*fm;
100 	struct ubi_fastmap_layout	fm_layout;
101 	struct ubi_fm_pool		fm_pool;
102 	struct ubi_fm_pool		fm_wl_pool;
103 
104 	/* Fastmap: UBISPL specific data */
105 	int				fm_enabled;
106 	unsigned long			fm_used[UBI_FM_BM_SIZE];
107 	unsigned long			scanned[UBI_FM_BM_SIZE];
108 	unsigned long			corrupt[UBI_FM_BM_SIZE];
109 	unsigned long			toload[UBI_FM_BM_SIZE];
110 
111 	/* Data for storing the VID and volume information */
112 	struct ubi_vol_info		volinfo[UBI_SPL_VOL_IDS];
113 	struct ubi_vid_hdr		blockinfo[CONFIG_SPL_UBI_MAX_PEBS];
114 
115 	/* The large buffer for the fastmap */
116 	uint8_t				fm_buf[UBI_FM_BUF_SIZE];
117 };
118 
119 #ifdef CFG_DEBUG
120 #define ubi_dbg(fmt, ...) printf("UBI: debug:" fmt "\n", ##__VA_ARGS__)
121 #else
122 #define ubi_dbg(fmt, ...)
123 #endif
124 
125 #ifdef CONFIG_UBI_SILENCE_MSG
126 #define ubi_msg(fmt, ...)
127 #else
128 #define ubi_msg(fmt, ...) printf("UBI: " fmt "\n", ##__VA_ARGS__)
129 #endif
130 /* UBI warning messages */
131 #define ubi_warn(fmt, ...) printf("UBI warning: " fmt "\n", ##__VA_ARGS__)
132 /* UBI error messages */
133 #define ubi_err(fmt, ...) printf("UBI error: " fmt "\n", ##__VA_ARGS__)
134 
135 #endif
136