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 * @vtbl_corrupted: Flag to indicate status of volume table 81 * @vtbl: Volume table 82 * 83 * @fm_buf: The large fastmap attach buffer 84 */ 85 struct ubi_scan_info { 86 ubispl_read_flash read; 87 unsigned int fsize_mb; 88 unsigned int peb_count; 89 unsigned int peb_offset; 90 91 unsigned long vid_offset; 92 unsigned long leb_start; 93 unsigned long leb_size; 94 95 /* Fastmap: The upstream required fields */ 96 int fastmap_pebs; 97 int fastmap_anchor; 98 size_t fm_size; 99 struct ubi_fm_sb fm_sb; 100 struct ubi_vid_hdr fm_vh; 101 struct ubi_fastmap_layout *fm; 102 struct ubi_fastmap_layout fm_layout; 103 struct ubi_fm_pool fm_pool; 104 struct ubi_fm_pool fm_wl_pool; 105 106 /* Fastmap: UBISPL specific data */ 107 int fm_enabled; 108 unsigned long fm_used[UBI_FM_BM_SIZE]; 109 unsigned long scanned[UBI_FM_BM_SIZE]; 110 unsigned long corrupt[UBI_FM_BM_SIZE]; 111 unsigned long toload[UBI_FM_BM_SIZE]; 112 113 /* Data for storing the VID and volume information */ 114 struct ubi_vol_info volinfo[UBI_SPL_VOL_IDS]; 115 struct ubi_vid_hdr blockinfo[CONFIG_SPL_UBI_MAX_PEBS]; 116 117 #ifdef CONFIG_SPL_UBI_LOAD_BY_VOLNAME 118 /* Volume table */ 119 int vtbl_valid; 120 struct ubi_vtbl_record vtbl[UBI_SPL_VOL_IDS]; 121 #endif 122 /* The large buffer for the fastmap */ 123 uint8_t fm_buf[UBI_FM_BUF_SIZE]; 124 }; 125 126 #ifdef CFG_DEBUG 127 #define ubi_dbg(fmt, ...) printf("UBI: debug:" fmt "\n", ##__VA_ARGS__) 128 #else 129 #define ubi_dbg(fmt, ...) 130 #endif 131 132 #ifdef CONFIG_UBI_SPL_SILENCE_MSG 133 #define ubi_msg(fmt, ...) 134 #else 135 #define ubi_msg(fmt, ...) printf("UBI: " fmt "\n", ##__VA_ARGS__) 136 #endif 137 /* UBI warning messages */ 138 #define ubi_warn(fmt, ...) printf("UBI warning: " fmt "\n", ##__VA_ARGS__) 139 /* UBI error messages */ 140 #define ubi_err(fmt, ...) printf("UBI error: " fmt "\n", ##__VA_ARGS__) 141 142 #endif 143