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