1*6f4e7d3cSThomas Gleixner /* 2*6f4e7d3cSThomas Gleixner * Copyright (c) Thomas Gleixner <tglx@linutronix.de> 3*6f4e7d3cSThomas Gleixner * 4*6f4e7d3cSThomas Gleixner * SPDX-License-Identifier: GPL 2.0+ BSD-3-Clause 5*6f4e7d3cSThomas Gleixner */ 6*6f4e7d3cSThomas Gleixner #ifndef __UBOOT_UBISPL_H 7*6f4e7d3cSThomas Gleixner #define __UBOOT_UBISPL_H 8*6f4e7d3cSThomas Gleixner 9*6f4e7d3cSThomas Gleixner /* 10*6f4e7d3cSThomas Gleixner * The following CONFIG options are relevant for UBISPL 11*6f4e7d3cSThomas Gleixner * 12*6f4e7d3cSThomas Gleixner * #define CONFIG_SPL_UBI_MAX_VOL_LEBS 256 13*6f4e7d3cSThomas Gleixner * 14*6f4e7d3cSThomas Gleixner * Defines the maximum number of logical erase blocks per loadable 15*6f4e7d3cSThomas Gleixner * (static) volume to size the ubispl internal arrays. 16*6f4e7d3cSThomas Gleixner * 17*6f4e7d3cSThomas Gleixner * #define CONFIG_SPL_UBI_MAX_PEB_SIZE (256*1024) 18*6f4e7d3cSThomas Gleixner * 19*6f4e7d3cSThomas Gleixner * Defines the maximum physical erase block size to size the fastmap 20*6f4e7d3cSThomas Gleixner * buffer for ubispl. 21*6f4e7d3cSThomas Gleixner * 22*6f4e7d3cSThomas Gleixner * #define CONFIG_SPL_UBI_MAX_PEBS 4096 23*6f4e7d3cSThomas Gleixner * 24*6f4e7d3cSThomas Gleixner * Define the maximum number of physical erase blocks to size the 25*6f4e7d3cSThomas Gleixner * ubispl internal arrays. 26*6f4e7d3cSThomas Gleixner * 27*6f4e7d3cSThomas Gleixner * #define CONFIG_SPL_UBI_VOL_IDS 8 28*6f4e7d3cSThomas Gleixner * 29*6f4e7d3cSThomas Gleixner * Defines the maximum number of volumes in which UBISPL is 30*6f4e7d3cSThomas Gleixner * interested. Limits the amount of memory for the scan data and 31*6f4e7d3cSThomas Gleixner * speeds up the scan process as we simply ignore stuff which we dont 32*6f4e7d3cSThomas Gleixner * want to load from the SPL anyway. So the volumes which can be 33*6f4e7d3cSThomas Gleixner * loaded in the above example are ids 0 - 7 34*6f4e7d3cSThomas Gleixner */ 35*6f4e7d3cSThomas Gleixner 36*6f4e7d3cSThomas Gleixner /* 37*6f4e7d3cSThomas Gleixner * The struct definition is in drivers/mtd/ubispl/ubispl.h. It does 38*6f4e7d3cSThomas Gleixner * not fit into the BSS due to the large buffer requirement of the 39*6f4e7d3cSThomas Gleixner * upstream fastmap code. So the caller of ubispl_load_volumes needs 40*6f4e7d3cSThomas Gleixner * to hand in a pointer to a free memory area where ubispl will place 41*6f4e7d3cSThomas Gleixner * its data. The area is not required to be initialized. 42*6f4e7d3cSThomas Gleixner */ 43*6f4e7d3cSThomas Gleixner struct ubi_scan_info; 44*6f4e7d3cSThomas Gleixner 45*6f4e7d3cSThomas Gleixner typedef int (*ubispl_read_flash)(int pnum, int offset, int len, void *dst); 46*6f4e7d3cSThomas Gleixner 47*6f4e7d3cSThomas Gleixner /** 48*6f4e7d3cSThomas Gleixner * struct ubispl_info - description structure for fast ubi scan 49*6f4e7d3cSThomas Gleixner * @ubi: Pointer to memory space for ubi scan info structure 50*6f4e7d3cSThomas Gleixner * @peb_size: Physical erase block size 51*6f4e7d3cSThomas Gleixner * @vid_offset: Offset of the VID header 52*6f4e7d3cSThomas Gleixner * @leb_start: Start of the logical erase block, i.e. offset of data 53*6f4e7d3cSThomas Gleixner * @peb_count: Number of physical erase blocks in the UBI FLASH area 54*6f4e7d3cSThomas Gleixner * aka MTD partition. 55*6f4e7d3cSThomas Gleixner * @peb_offset: Offset of PEB0 in the UBI FLASH area (aka MTD partition) 56*6f4e7d3cSThomas Gleixner * to the real start of the FLASH in erase blocks. 57*6f4e7d3cSThomas Gleixner * @fastmap: Enable fastmap attachment 58*6f4e7d3cSThomas Gleixner * @read: Read function to access the flash 59*6f4e7d3cSThomas Gleixner */ 60*6f4e7d3cSThomas Gleixner struct ubispl_info { 61*6f4e7d3cSThomas Gleixner struct ubi_scan_info *ubi; 62*6f4e7d3cSThomas Gleixner u32 peb_size; 63*6f4e7d3cSThomas Gleixner u32 vid_offset; 64*6f4e7d3cSThomas Gleixner u32 leb_start; 65*6f4e7d3cSThomas Gleixner u32 peb_count; 66*6f4e7d3cSThomas Gleixner u32 peb_offset; 67*6f4e7d3cSThomas Gleixner int fastmap; 68*6f4e7d3cSThomas Gleixner ubispl_read_flash read; 69*6f4e7d3cSThomas Gleixner }; 70*6f4e7d3cSThomas Gleixner 71*6f4e7d3cSThomas Gleixner /** 72*6f4e7d3cSThomas Gleixner * struct ubispl_load - structure to describe a volume to load 73*6f4e7d3cSThomas Gleixner * @vol_id: Volume id 74*6f4e7d3cSThomas Gleixner * @load_addr: Load address of the volume 75*6f4e7d3cSThomas Gleixner */ 76*6f4e7d3cSThomas Gleixner struct ubispl_load { 77*6f4e7d3cSThomas Gleixner int vol_id; 78*6f4e7d3cSThomas Gleixner void *load_addr; 79*6f4e7d3cSThomas Gleixner }; 80*6f4e7d3cSThomas Gleixner 81*6f4e7d3cSThomas Gleixner /** 82*6f4e7d3cSThomas Gleixner * ubispl_load_volumes - Scan flash and load volumes 83*6f4e7d3cSThomas Gleixner * @info: Pointer to the ubi scan info structure 84*6f4e7d3cSThomas Gleixner * @lovls: Pointer to array of volumes to load 85*6f4e7d3cSThomas Gleixner * @nrvols: Array size of @lovls 86*6f4e7d3cSThomas Gleixner */ 87*6f4e7d3cSThomas Gleixner int ubispl_load_volumes(struct ubispl_info *info, 88*6f4e7d3cSThomas Gleixner struct ubispl_load *lvols, int nrvols); 89*6f4e7d3cSThomas Gleixner 90*6f4e7d3cSThomas Gleixner #endif 91