xref: /openbmc/u-boot/drivers/mtd/ubispl/ubi-wrapper.h (revision 4549e789c1d58a8c48e8a20f1b4bdb83e978c954)
1*4549e789STom Rini /* SPDX-License-Identifier: GPL 2.0+ OR BSD-3-Clause */
26f4e7d3cSThomas Gleixner /*
36f4e7d3cSThomas Gleixner  * The parts taken from the kernel implementation are:
46f4e7d3cSThomas Gleixner  *
56f4e7d3cSThomas Gleixner  * Copyright (c) International Business Machines Corp., 2006
66f4e7d3cSThomas Gleixner  *
76f4e7d3cSThomas Gleixner  * UBISPL specific defines:
86f4e7d3cSThomas Gleixner  *
96f4e7d3cSThomas Gleixner  * Copyright (c) Thomas Gleixner <tglx@linutronix.de>
106f4e7d3cSThomas Gleixner  */
116f4e7d3cSThomas Gleixner 
126f4e7d3cSThomas Gleixner /*
136f4e7d3cSThomas Gleixner  * Contains various defines copy&pasted from ubi.h and ubi-user.h to make
146f4e7d3cSThomas Gleixner  * the upstream fastboot code happy.
156f4e7d3cSThomas Gleixner  */
166f4e7d3cSThomas Gleixner #ifndef __UBOOT_UBI_WRAPPER_H
176f4e7d3cSThomas Gleixner #define __UBOOT_UBI_WRAPPER_H
186f4e7d3cSThomas Gleixner 
196f4e7d3cSThomas Gleixner /*
206f4e7d3cSThomas Gleixner  * Error codes returned by the I/O sub-system.
216f4e7d3cSThomas Gleixner  *
226f4e7d3cSThomas Gleixner  * UBI_IO_FF: the read region of flash contains only 0xFFs
236f4e7d3cSThomas Gleixner  * UBI_IO_FF_BITFLIPS: the same as %UBI_IO_FF, but also also there was a data
246f4e7d3cSThomas Gleixner  *                     integrity error reported by the MTD driver
256f4e7d3cSThomas Gleixner  *                     (uncorrectable ECC error in case of NAND)
266f4e7d3cSThomas Gleixner  * UBI_IO_BAD_HDR: the EC or VID header is corrupted (bad magic or CRC)
276f4e7d3cSThomas Gleixner  * UBI_IO_BAD_HDR_EBADMSG: the same as %UBI_IO_BAD_HDR, but also there was a
286f4e7d3cSThomas Gleixner  *                         data integrity error reported by the MTD driver
296f4e7d3cSThomas Gleixner  *                         (uncorrectable ECC error in case of NAND)
306f4e7d3cSThomas Gleixner  * UBI_IO_BITFLIPS: bit-flips were detected and corrected
316f4e7d3cSThomas Gleixner  *
326f4e7d3cSThomas Gleixner  * UBI_FASTMAP_ANCHOR:  u-boot SPL add on to tell the caller that the fastmap
336f4e7d3cSThomas Gleixner  *			anchor block has been found
346f4e7d3cSThomas Gleixner  *
356f4e7d3cSThomas Gleixner  * Note, it is probably better to have bit-flip and ebadmsg as flags which can
366f4e7d3cSThomas Gleixner  * be or'ed with other error code. But this is a big change because there are
376f4e7d3cSThomas Gleixner  * may callers, so it does not worth the risk of introducing a bug
386f4e7d3cSThomas Gleixner  */
396f4e7d3cSThomas Gleixner enum {
406f4e7d3cSThomas Gleixner 	UBI_IO_FF = 1,
416f4e7d3cSThomas Gleixner 	UBI_IO_FF_BITFLIPS,
426f4e7d3cSThomas Gleixner 	UBI_IO_BAD_HDR,
436f4e7d3cSThomas Gleixner 	UBI_IO_BAD_HDR_EBADMSG,
446f4e7d3cSThomas Gleixner 	UBI_IO_BITFLIPS,
456f4e7d3cSThomas Gleixner 	UBI_FASTMAP_ANCHOR,
466f4e7d3cSThomas Gleixner };
476f4e7d3cSThomas Gleixner 
486f4e7d3cSThomas Gleixner /*
496f4e7d3cSThomas Gleixner  * UBI volume type constants.
506f4e7d3cSThomas Gleixner  *
516f4e7d3cSThomas Gleixner  * @UBI_DYNAMIC_VOLUME: dynamic volume
526f4e7d3cSThomas Gleixner  * @UBI_STATIC_VOLUME:  static volume
536f4e7d3cSThomas Gleixner  */
546f4e7d3cSThomas Gleixner enum {
556f4e7d3cSThomas Gleixner 	UBI_DYNAMIC_VOLUME = 3,
566f4e7d3cSThomas Gleixner 	UBI_STATIC_VOLUME  = 4,
576f4e7d3cSThomas Gleixner };
586f4e7d3cSThomas Gleixner 
596f4e7d3cSThomas Gleixner /*
606f4e7d3cSThomas Gleixner  * Return codes of the fastmap sub-system
616f4e7d3cSThomas Gleixner  *
626f4e7d3cSThomas Gleixner  * UBI_NO_FASTMAP: No fastmap super block was found
636f4e7d3cSThomas Gleixner  * UBI_BAD_FASTMAP: A fastmap was found but it's unusable
646f4e7d3cSThomas Gleixner  */
656f4e7d3cSThomas Gleixner enum {
666f4e7d3cSThomas Gleixner 	UBI_NO_FASTMAP = 1,
676f4e7d3cSThomas Gleixner 	UBI_BAD_FASTMAP,
686f4e7d3cSThomas Gleixner };
696f4e7d3cSThomas Gleixner 
706f4e7d3cSThomas Gleixner /**
716f4e7d3cSThomas Gleixner  * struct ubi_fastmap_layout - in-memory fastmap data structure.
726f4e7d3cSThomas Gleixner  * @e: PEBs used by the current fastmap
736f4e7d3cSThomas Gleixner  * @to_be_tortured: if non-zero tortured this PEB
746f4e7d3cSThomas Gleixner  * @used_blocks: number of used PEBs
756f4e7d3cSThomas Gleixner  * @max_pool_size: maximal size of the user pool
766f4e7d3cSThomas Gleixner  * @max_wl_pool_size: maximal size of the pool used by the WL sub-system
776f4e7d3cSThomas Gleixner  */
786f4e7d3cSThomas Gleixner struct ubi_fastmap_layout {
796f4e7d3cSThomas Gleixner 	struct ubi_wl_entry *e[UBI_FM_MAX_BLOCKS];
806f4e7d3cSThomas Gleixner 	int to_be_tortured[UBI_FM_MAX_BLOCKS];
816f4e7d3cSThomas Gleixner 	int used_blocks;
826f4e7d3cSThomas Gleixner 	int max_pool_size;
836f4e7d3cSThomas Gleixner 	int max_wl_pool_size;
846f4e7d3cSThomas Gleixner };
856f4e7d3cSThomas Gleixner 
866f4e7d3cSThomas Gleixner /**
876f4e7d3cSThomas Gleixner  * struct ubi_fm_pool - in-memory fastmap pool
886f4e7d3cSThomas Gleixner  * @pebs: PEBs in this pool
896f4e7d3cSThomas Gleixner  * @used: number of used PEBs
906f4e7d3cSThomas Gleixner  * @size: total number of PEBs in this pool
916f4e7d3cSThomas Gleixner  * @max_size: maximal size of the pool
926f4e7d3cSThomas Gleixner  *
936f4e7d3cSThomas Gleixner  * A pool gets filled with up to max_size.
946f4e7d3cSThomas Gleixner  * If all PEBs within the pool are used a new fastmap will be written
956f4e7d3cSThomas Gleixner  * to the flash and the pool gets refilled with empty PEBs.
966f4e7d3cSThomas Gleixner  *
976f4e7d3cSThomas Gleixner  */
986f4e7d3cSThomas Gleixner struct ubi_fm_pool {
996f4e7d3cSThomas Gleixner 	int pebs[UBI_FM_MAX_POOL_SIZE];
1006f4e7d3cSThomas Gleixner 	int used;
1016f4e7d3cSThomas Gleixner 	int size;
1026f4e7d3cSThomas Gleixner 	int max_size;
1036f4e7d3cSThomas Gleixner };
1046f4e7d3cSThomas Gleixner 
1056f4e7d3cSThomas Gleixner #endif
106