1*4549e789STom Rini /* SPDX-License-Identifier: GPL 2.0+ OR BSD-3-Clause */ 26f4e7d3cSThomas Gleixner /* 36f4e7d3cSThomas Gleixner * Copyright (c) Thomas Gleixner <tglx@linutronix.de> 46f4e7d3cSThomas Gleixner */ 56f4e7d3cSThomas Gleixner 66f4e7d3cSThomas Gleixner #ifndef _UBOOT_MTD_UBISPL_H 76f4e7d3cSThomas Gleixner #define _UBOOT_MTD_UBISPL_H 86f4e7d3cSThomas Gleixner 96f4e7d3cSThomas Gleixner #include "../ubi/ubi-media.h" 106f4e7d3cSThomas Gleixner #include "ubi-wrapper.h" 116f4e7d3cSThomas Gleixner 126f4e7d3cSThomas Gleixner /* 136f4e7d3cSThomas Gleixner * The maximum number of volume ids we scan. So you can load volume id 146f4e7d3cSThomas Gleixner * 0 to (CONFIG_SPL_UBI_VOL_ID_MAX - 1) 156f4e7d3cSThomas Gleixner */ 166f4e7d3cSThomas Gleixner #define UBI_SPL_VOL_IDS CONFIG_SPL_UBI_VOL_IDS 176f4e7d3cSThomas Gleixner /* 186f4e7d3cSThomas Gleixner * The size of the read buffer for the fastmap blocks. In theory up to 196f4e7d3cSThomas Gleixner * UBI_FM_MAX_BLOCKS * CONFIG_SPL_MAX_PEB_SIZE. In practice today 206f4e7d3cSThomas Gleixner * one or two blocks. 216f4e7d3cSThomas Gleixner */ 226f4e7d3cSThomas Gleixner #define UBI_FM_BUF_SIZE (UBI_FM_MAX_BLOCKS*CONFIG_SPL_UBI_MAX_PEB_SIZE) 236f4e7d3cSThomas Gleixner /* 246f4e7d3cSThomas Gleixner * The size of the bitmaps for the attach/ scan 256f4e7d3cSThomas Gleixner */ 266f4e7d3cSThomas Gleixner #define UBI_FM_BM_SIZE ((CONFIG_SPL_UBI_MAX_PEBS / BITS_PER_LONG) + 1) 276f4e7d3cSThomas Gleixner /* 286f4e7d3cSThomas Gleixner * The maximum number of logical erase blocks per loadable volume 296f4e7d3cSThomas Gleixner */ 306f4e7d3cSThomas Gleixner #define UBI_MAX_VOL_LEBS CONFIG_SPL_UBI_MAX_VOL_LEBS 316f4e7d3cSThomas Gleixner /* 326f4e7d3cSThomas Gleixner * The bitmap size for the above to denote the found blocks inside the volume 336f4e7d3cSThomas Gleixner */ 346f4e7d3cSThomas Gleixner #define UBI_VOL_BM_SIZE ((UBI_MAX_VOL_LEBS / BITS_PER_LONG) + 1) 356f4e7d3cSThomas Gleixner 366f4e7d3cSThomas Gleixner /** 376f4e7d3cSThomas Gleixner * struct ubi_vol_info - UBISPL internal volume represenation 386f4e7d3cSThomas Gleixner * @last_block: The last block (highest LEB) found for this volume 396f4e7d3cSThomas Gleixner * @found: Bitmap to mark found LEBS 406f4e7d3cSThomas Gleixner * @lebs_to_pebs: LEB to PEB translation table 416f4e7d3cSThomas Gleixner */ 426f4e7d3cSThomas Gleixner struct ubi_vol_info { 436f4e7d3cSThomas Gleixner u32 last_block; 446f4e7d3cSThomas Gleixner unsigned long found[UBI_VOL_BM_SIZE]; 456f4e7d3cSThomas Gleixner u32 lebs_to_pebs[UBI_MAX_VOL_LEBS]; 466f4e7d3cSThomas Gleixner }; 476f4e7d3cSThomas Gleixner 486f4e7d3cSThomas Gleixner /** 496f4e7d3cSThomas Gleixner * struct ubi_scan_info - UBISPL internal data for FM attach and full scan 506f4e7d3cSThomas Gleixner * 516f4e7d3cSThomas Gleixner * @read: Read function to access the flash provided by the caller 526f4e7d3cSThomas Gleixner * @peb_count: Number of physical erase blocks in the UBI FLASH area 536f4e7d3cSThomas Gleixner * aka MTD partition. 546f4e7d3cSThomas Gleixner * @peb_offset: Offset of PEB0 in the UBI FLASH area (aka MTD partition) 556f4e7d3cSThomas Gleixner * to the real start of the FLASH in erase blocks. 566f4e7d3cSThomas Gleixner * @fsize_mb: Size of the scanned FLASH area in MB (stats only) 576f4e7d3cSThomas Gleixner * @vid_offset: Offset from the start of a PEB to the VID header 586f4e7d3cSThomas Gleixner * @leb_start: Offset from the start of a PEB to the data area 596f4e7d3cSThomas Gleixner * @leb_size: Size of the data area 606f4e7d3cSThomas Gleixner * 616f4e7d3cSThomas Gleixner * @fastmap_pebs: Counter of PEBs "attached" by fastmap 626f4e7d3cSThomas Gleixner * @fastmap_anchor: The anchor PEB of the fastmap 636f4e7d3cSThomas Gleixner * @fm_sb: The fastmap super block data 646f4e7d3cSThomas Gleixner * @fm_vh: The fastmap VID header 656f4e7d3cSThomas Gleixner * @fm: Pointer to the fastmap layout 666f4e7d3cSThomas Gleixner * @fm_layout: The fastmap layout itself 676f4e7d3cSThomas Gleixner * @fm_pool: The pool of PEBs to scan at fastmap attach time 686f4e7d3cSThomas Gleixner * @fm_wl_pool: The pool of PEBs scheduled for wearleveling 696f4e7d3cSThomas Gleixner * 706f4e7d3cSThomas Gleixner * @fm_enabled: Indicator whether fastmap attachment is enabled. 716f4e7d3cSThomas Gleixner * @fm_used: Bitmap to indicate the PEBS covered by fastmap 726f4e7d3cSThomas Gleixner * @scanned: Bitmap to indicate the PEBS of which the VID header 736f4e7d3cSThomas Gleixner * hase been physically scanned. 746f4e7d3cSThomas Gleixner * @corrupt: Bitmap to indicate corrupt blocks 756f4e7d3cSThomas Gleixner * @toload: Bitmap to indicate the volumes which should be loaded 766f4e7d3cSThomas Gleixner * 776f4e7d3cSThomas Gleixner * @blockinfo: The vid headers of the scanned blocks 786f4e7d3cSThomas Gleixner * @volinfo: The volume information of the interesting (toload) 796f4e7d3cSThomas Gleixner * volumes 806f4e7d3cSThomas Gleixner * 816f4e7d3cSThomas Gleixner * @fm_buf: The large fastmap attach buffer 826f4e7d3cSThomas Gleixner */ 836f4e7d3cSThomas Gleixner struct ubi_scan_info { 846f4e7d3cSThomas Gleixner ubispl_read_flash read; 856f4e7d3cSThomas Gleixner unsigned int fsize_mb; 866f4e7d3cSThomas Gleixner unsigned int peb_count; 876f4e7d3cSThomas Gleixner unsigned int peb_offset; 886f4e7d3cSThomas Gleixner 896f4e7d3cSThomas Gleixner unsigned long vid_offset; 906f4e7d3cSThomas Gleixner unsigned long leb_start; 916f4e7d3cSThomas Gleixner unsigned long leb_size; 926f4e7d3cSThomas Gleixner 936f4e7d3cSThomas Gleixner /* Fastmap: The upstream required fields */ 946f4e7d3cSThomas Gleixner int fastmap_pebs; 956f4e7d3cSThomas Gleixner int fastmap_anchor; 966f4e7d3cSThomas Gleixner size_t fm_size; 976f4e7d3cSThomas Gleixner struct ubi_fm_sb fm_sb; 986f4e7d3cSThomas Gleixner struct ubi_vid_hdr fm_vh; 996f4e7d3cSThomas Gleixner struct ubi_fastmap_layout *fm; 1006f4e7d3cSThomas Gleixner struct ubi_fastmap_layout fm_layout; 1016f4e7d3cSThomas Gleixner struct ubi_fm_pool fm_pool; 1026f4e7d3cSThomas Gleixner struct ubi_fm_pool fm_wl_pool; 1036f4e7d3cSThomas Gleixner 1046f4e7d3cSThomas Gleixner /* Fastmap: UBISPL specific data */ 1056f4e7d3cSThomas Gleixner int fm_enabled; 1066f4e7d3cSThomas Gleixner unsigned long fm_used[UBI_FM_BM_SIZE]; 1076f4e7d3cSThomas Gleixner unsigned long scanned[UBI_FM_BM_SIZE]; 1086f4e7d3cSThomas Gleixner unsigned long corrupt[UBI_FM_BM_SIZE]; 1096f4e7d3cSThomas Gleixner unsigned long toload[UBI_FM_BM_SIZE]; 1106f4e7d3cSThomas Gleixner 1116f4e7d3cSThomas Gleixner /* Data for storing the VID and volume information */ 1126f4e7d3cSThomas Gleixner struct ubi_vol_info volinfo[UBI_SPL_VOL_IDS]; 1136f4e7d3cSThomas Gleixner struct ubi_vid_hdr blockinfo[CONFIG_SPL_UBI_MAX_PEBS]; 1146f4e7d3cSThomas Gleixner 1156f4e7d3cSThomas Gleixner /* The large buffer for the fastmap */ 1166f4e7d3cSThomas Gleixner uint8_t fm_buf[UBI_FM_BUF_SIZE]; 1176f4e7d3cSThomas Gleixner }; 1186f4e7d3cSThomas Gleixner 1196f4e7d3cSThomas Gleixner #ifdef CFG_DEBUG 1206f4e7d3cSThomas Gleixner #define ubi_dbg(fmt, ...) printf("UBI: debug:" fmt "\n", ##__VA_ARGS__) 1216f4e7d3cSThomas Gleixner #else 1226f4e7d3cSThomas Gleixner #define ubi_dbg(fmt, ...) 1236f4e7d3cSThomas Gleixner #endif 1246f4e7d3cSThomas Gleixner 1256f4e7d3cSThomas Gleixner #ifdef CONFIG_UBI_SILENCE_MSG 1266f4e7d3cSThomas Gleixner #define ubi_msg(fmt, ...) 1276f4e7d3cSThomas Gleixner #else 1286f4e7d3cSThomas Gleixner #define ubi_msg(fmt, ...) printf("UBI: " fmt "\n", ##__VA_ARGS__) 1296f4e7d3cSThomas Gleixner #endif 1306f4e7d3cSThomas Gleixner /* UBI warning messages */ 1316f4e7d3cSThomas Gleixner #define ubi_warn(fmt, ...) printf("UBI warning: " fmt "\n", ##__VA_ARGS__) 1326f4e7d3cSThomas Gleixner /* UBI error messages */ 1336f4e7d3cSThomas Gleixner #define ubi_err(fmt, ...) printf("UBI error: " fmt "\n", ##__VA_ARGS__) 1346f4e7d3cSThomas Gleixner 1356f4e7d3cSThomas Gleixner #endif 136