xref: /OK3568_Linux_fs/u-boot/drivers/mtd/ubispl/ubi-wrapper.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * The parts taken from the kernel implementation are:
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Copyright (c) International Business Machines Corp., 2006
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * UBISPL specific defines:
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  * Copyright (c) Thomas Gleixner <tglx@linutronix.de>
9*4882a593Smuzhiyun  *
10*4882a593Smuzhiyun  * SPDX-License-Identifier: GPL 2.0+ BSD-3-Clause
11*4882a593Smuzhiyun  */
12*4882a593Smuzhiyun 
13*4882a593Smuzhiyun /*
14*4882a593Smuzhiyun  * Contains various defines copy&pasted from ubi.h and ubi-user.h to make
15*4882a593Smuzhiyun  * the upstream fastboot code happy.
16*4882a593Smuzhiyun  */
17*4882a593Smuzhiyun #ifndef __UBOOT_UBI_WRAPPER_H
18*4882a593Smuzhiyun #define __UBOOT_UBI_WRAPPER_H
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun /*
21*4882a593Smuzhiyun  * Error codes returned by the I/O sub-system.
22*4882a593Smuzhiyun  *
23*4882a593Smuzhiyun  * UBI_IO_FF: the read region of flash contains only 0xFFs
24*4882a593Smuzhiyun  * UBI_IO_FF_BITFLIPS: the same as %UBI_IO_FF, but also also there was a data
25*4882a593Smuzhiyun  *                     integrity error reported by the MTD driver
26*4882a593Smuzhiyun  *                     (uncorrectable ECC error in case of NAND)
27*4882a593Smuzhiyun  * UBI_IO_BAD_HDR: the EC or VID header is corrupted (bad magic or CRC)
28*4882a593Smuzhiyun  * UBI_IO_BAD_HDR_EBADMSG: the same as %UBI_IO_BAD_HDR, but also there was a
29*4882a593Smuzhiyun  *                         data integrity error reported by the MTD driver
30*4882a593Smuzhiyun  *                         (uncorrectable ECC error in case of NAND)
31*4882a593Smuzhiyun  * UBI_IO_BITFLIPS: bit-flips were detected and corrected
32*4882a593Smuzhiyun  *
33*4882a593Smuzhiyun  * UBI_FASTMAP_ANCHOR:  u-boot SPL add on to tell the caller that the fastmap
34*4882a593Smuzhiyun  *			anchor block has been found
35*4882a593Smuzhiyun  *
36*4882a593Smuzhiyun  * Note, it is probably better to have bit-flip and ebadmsg as flags which can
37*4882a593Smuzhiyun  * be or'ed with other error code. But this is a big change because there are
38*4882a593Smuzhiyun  * may callers, so it does not worth the risk of introducing a bug
39*4882a593Smuzhiyun  */
40*4882a593Smuzhiyun enum {
41*4882a593Smuzhiyun 	UBI_IO_FF = 1,
42*4882a593Smuzhiyun 	UBI_IO_FF_BITFLIPS,
43*4882a593Smuzhiyun 	UBI_IO_BAD_HDR,
44*4882a593Smuzhiyun 	UBI_IO_BAD_HDR_EBADMSG,
45*4882a593Smuzhiyun 	UBI_IO_BITFLIPS,
46*4882a593Smuzhiyun 	UBI_FASTMAP_ANCHOR,
47*4882a593Smuzhiyun };
48*4882a593Smuzhiyun 
49*4882a593Smuzhiyun /*
50*4882a593Smuzhiyun  * UBI volume type constants.
51*4882a593Smuzhiyun  *
52*4882a593Smuzhiyun  * @UBI_DYNAMIC_VOLUME: dynamic volume
53*4882a593Smuzhiyun  * @UBI_STATIC_VOLUME:  static volume
54*4882a593Smuzhiyun  */
55*4882a593Smuzhiyun enum {
56*4882a593Smuzhiyun 	UBI_DYNAMIC_VOLUME = 3,
57*4882a593Smuzhiyun 	UBI_STATIC_VOLUME  = 4,
58*4882a593Smuzhiyun };
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun /*
61*4882a593Smuzhiyun  * Return codes of the fastmap sub-system
62*4882a593Smuzhiyun  *
63*4882a593Smuzhiyun  * UBI_NO_FASTMAP: No fastmap super block was found
64*4882a593Smuzhiyun  * UBI_BAD_FASTMAP: A fastmap was found but it's unusable
65*4882a593Smuzhiyun  */
66*4882a593Smuzhiyun enum {
67*4882a593Smuzhiyun 	UBI_NO_FASTMAP = 1,
68*4882a593Smuzhiyun 	UBI_BAD_FASTMAP,
69*4882a593Smuzhiyun };
70*4882a593Smuzhiyun 
71*4882a593Smuzhiyun /**
72*4882a593Smuzhiyun  * struct ubi_fastmap_layout - in-memory fastmap data structure.
73*4882a593Smuzhiyun  * @e: PEBs used by the current fastmap
74*4882a593Smuzhiyun  * @to_be_tortured: if non-zero tortured this PEB
75*4882a593Smuzhiyun  * @used_blocks: number of used PEBs
76*4882a593Smuzhiyun  * @max_pool_size: maximal size of the user pool
77*4882a593Smuzhiyun  * @max_wl_pool_size: maximal size of the pool used by the WL sub-system
78*4882a593Smuzhiyun  */
79*4882a593Smuzhiyun struct ubi_fastmap_layout {
80*4882a593Smuzhiyun 	struct ubi_wl_entry *e[UBI_FM_MAX_BLOCKS];
81*4882a593Smuzhiyun 	int to_be_tortured[UBI_FM_MAX_BLOCKS];
82*4882a593Smuzhiyun 	int used_blocks;
83*4882a593Smuzhiyun 	int max_pool_size;
84*4882a593Smuzhiyun 	int max_wl_pool_size;
85*4882a593Smuzhiyun };
86*4882a593Smuzhiyun 
87*4882a593Smuzhiyun /**
88*4882a593Smuzhiyun  * struct ubi_fm_pool - in-memory fastmap pool
89*4882a593Smuzhiyun  * @pebs: PEBs in this pool
90*4882a593Smuzhiyun  * @used: number of used PEBs
91*4882a593Smuzhiyun  * @size: total number of PEBs in this pool
92*4882a593Smuzhiyun  * @max_size: maximal size of the pool
93*4882a593Smuzhiyun  *
94*4882a593Smuzhiyun  * A pool gets filled with up to max_size.
95*4882a593Smuzhiyun  * If all PEBs within the pool are used a new fastmap will be written
96*4882a593Smuzhiyun  * to the flash and the pool gets refilled with empty PEBs.
97*4882a593Smuzhiyun  *
98*4882a593Smuzhiyun  */
99*4882a593Smuzhiyun struct ubi_fm_pool {
100*4882a593Smuzhiyun 	int pebs[UBI_FM_MAX_POOL_SIZE];
101*4882a593Smuzhiyun 	int used;
102*4882a593Smuzhiyun 	int size;
103*4882a593Smuzhiyun 	int max_size;
104*4882a593Smuzhiyun };
105*4882a593Smuzhiyun 
106*4882a593Smuzhiyun #endif
107