xref: /OK3568_Linux_fs/u-boot/include/part.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * (C) Copyright 2000-2004
3*4882a593Smuzhiyun  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * SPDX-License-Identifier:	GPL-2.0+
6*4882a593Smuzhiyun  */
7*4882a593Smuzhiyun #ifndef _PART_H
8*4882a593Smuzhiyun #define _PART_H
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun #include <blk.h>
11*4882a593Smuzhiyun #include <ide.h>
12*4882a593Smuzhiyun #include <uuid.h>
13*4882a593Smuzhiyun #include <linux/list.h>
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun struct block_drvr {
16*4882a593Smuzhiyun 	char *name;
17*4882a593Smuzhiyun 	int (*select_hwpart)(int dev_num, int hwpart);
18*4882a593Smuzhiyun };
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun #define LOG2(x) (((x & 0xaaaaaaaa) ? 1 : 0) + ((x & 0xcccccccc) ? 2 : 0) + \
21*4882a593Smuzhiyun 		 ((x & 0xf0f0f0f0) ? 4 : 0) + ((x & 0xff00ff00) ? 8 : 0) + \
22*4882a593Smuzhiyun 		 ((x & 0xffff0000) ? 16 : 0))
23*4882a593Smuzhiyun #define LOG2_INVALID(type) ((type)((sizeof(type)<<3)-1))
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun /* Part types */
26*4882a593Smuzhiyun #define PART_TYPE_UNKNOWN	0x00
27*4882a593Smuzhiyun #define PART_TYPE_MAC		0x01
28*4882a593Smuzhiyun #define PART_TYPE_DOS		0x02
29*4882a593Smuzhiyun #define PART_TYPE_ISO		0x03
30*4882a593Smuzhiyun #define PART_TYPE_AMIGA		0x04
31*4882a593Smuzhiyun #define PART_TYPE_EFI		0x05
32*4882a593Smuzhiyun #define PART_TYPE_RKPARM	0x06
33*4882a593Smuzhiyun #define PART_TYPE_RKRAM		0x07
34*4882a593Smuzhiyun #define PART_TYPE_ENV		0x08
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun /* maximum number of partition entries supported by search */
37*4882a593Smuzhiyun #define DOS_ENTRY_NUMBERS	8
38*4882a593Smuzhiyun #define ISO_ENTRY_NUMBERS	64
39*4882a593Smuzhiyun #define MAC_ENTRY_NUMBERS	64
40*4882a593Smuzhiyun #define AMIGA_ENTRY_NUMBERS	8
41*4882a593Smuzhiyun #define RKPARM_ENTRY_NUMBERS	128
42*4882a593Smuzhiyun #define RKRAM_ENTRY_NUMBERS	6
43*4882a593Smuzhiyun #define ENV_ENTRY_NUMBERS	64
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun /*
46*4882a593Smuzhiyun  * Type string for U-Boot bootable partitions
47*4882a593Smuzhiyun  */
48*4882a593Smuzhiyun #define BOOT_PART_TYPE	"U-Boot"	/* primary boot partition type	*/
49*4882a593Smuzhiyun #define BOOT_PART_COMP	"PPCBoot"	/* PPCBoot compatibility type	*/
50*4882a593Smuzhiyun 
51*4882a593Smuzhiyun /* device types */
52*4882a593Smuzhiyun #define DEV_TYPE_UNKNOWN	0xff	/* not connected */
53*4882a593Smuzhiyun #define DEV_TYPE_HARDDISK	0x00	/* harddisk */
54*4882a593Smuzhiyun #define DEV_TYPE_TAPE		0x01	/* Tape */
55*4882a593Smuzhiyun #define DEV_TYPE_CDROM		0x05	/* CD-ROM */
56*4882a593Smuzhiyun #define DEV_TYPE_OPDISK		0x07	/* optical disk */
57*4882a593Smuzhiyun 
58*4882a593Smuzhiyun #define PART_NAME_LEN 32
59*4882a593Smuzhiyun #define PART_TYPE_LEN 32
60*4882a593Smuzhiyun #define MAX_SEARCH_PARTITIONS 64
61*4882a593Smuzhiyun 
62*4882a593Smuzhiyun typedef struct disk_partition {
63*4882a593Smuzhiyun 	lbaint_t	start;	/* # of first block in partition	*/
64*4882a593Smuzhiyun 	lbaint_t	size;	/* number of blocks in partition	*/
65*4882a593Smuzhiyun 	ulong	blksz;		/* block size in bytes			*/
66*4882a593Smuzhiyun 	uchar	name[PART_NAME_LEN];	/* partition name			*/
67*4882a593Smuzhiyun 	uchar	type[PART_TYPE_LEN];	/* string type description		*/
68*4882a593Smuzhiyun 	int	bootable;	/* Active/Bootable flag is set		*/
69*4882a593Smuzhiyun #if CONFIG_IS_ENABLED(PARTITION_UUIDS)
70*4882a593Smuzhiyun 	char	uuid[UUID_STR_LEN + 1];	/* filesystem UUID as string, if exists	*/
71*4882a593Smuzhiyun #endif
72*4882a593Smuzhiyun #ifdef CONFIG_PARTITION_TYPE_GUID
73*4882a593Smuzhiyun 	char	type_guid[UUID_STR_LEN + 1];	/* type GUID as string, if exists	*/
74*4882a593Smuzhiyun #endif
75*4882a593Smuzhiyun #ifdef CONFIG_DOS_PARTITION
76*4882a593Smuzhiyun 	uchar	sys_ind;	/* partition type 			*/
77*4882a593Smuzhiyun #endif
78*4882a593Smuzhiyun } disk_partition_t;
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun struct disk_part {
81*4882a593Smuzhiyun 	int partnum;
82*4882a593Smuzhiyun 	disk_partition_t gpt_part_info;
83*4882a593Smuzhiyun 	struct list_head list;
84*4882a593Smuzhiyun };
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun /* Misc _get_dev functions */
87*4882a593Smuzhiyun #ifdef CONFIG_PARTITIONS
88*4882a593Smuzhiyun /**
89*4882a593Smuzhiyun  * blk_get_dev() - get a pointer to a block device given its type and number
90*4882a593Smuzhiyun  *
91*4882a593Smuzhiyun  * Each interface allocates its own devices and typically struct blk_desc is
92*4882a593Smuzhiyun  * contained with the interface's data structure. There is no global
93*4882a593Smuzhiyun  * numbering for block devices, so the interface name must be provided.
94*4882a593Smuzhiyun  *
95*4882a593Smuzhiyun  * @ifname:	Interface name (e.g. "ide", "scsi")
96*4882a593Smuzhiyun  * @dev:	Device number (0 for first device on that interface, 1 for
97*4882a593Smuzhiyun  *		second, etc.
98*4882a593Smuzhiyun  * @return pointer to the block device, or NULL if not available, or an
99*4882a593Smuzhiyun  *	   error occurred.
100*4882a593Smuzhiyun  */
101*4882a593Smuzhiyun struct blk_desc *blk_get_dev(const char *ifname, int dev);
102*4882a593Smuzhiyun 
103*4882a593Smuzhiyun struct blk_desc *mg_disk_get_dev(int dev);
104*4882a593Smuzhiyun int host_get_dev_err(int dev, struct blk_desc **blk_devp);
105*4882a593Smuzhiyun 
106*4882a593Smuzhiyun /* disk/part.c */
107*4882a593Smuzhiyun int part_get_info(struct blk_desc *dev_desc, int part, disk_partition_t *info);
108*4882a593Smuzhiyun /**
109*4882a593Smuzhiyun  * part_get_info_whole_disk() - get partition info for the special case of
110*4882a593Smuzhiyun  * a partition occupying the entire disk.
111*4882a593Smuzhiyun  */
112*4882a593Smuzhiyun int part_get_info_whole_disk(struct blk_desc *dev_desc, disk_partition_t *info);
113*4882a593Smuzhiyun const char *part_get_type(struct blk_desc *dev_desc);
114*4882a593Smuzhiyun void part_print(struct blk_desc *dev_desc);
115*4882a593Smuzhiyun void part_init(struct blk_desc *dev_desc);
116*4882a593Smuzhiyun void dev_print(struct blk_desc *dev_desc);
117*4882a593Smuzhiyun 
118*4882a593Smuzhiyun /**
119*4882a593Smuzhiyun  * blk_get_device_by_str() - Get a block device given its interface/hw partition
120*4882a593Smuzhiyun  *
121*4882a593Smuzhiyun  * Each interface allocates its own devices and typically struct blk_desc is
122*4882a593Smuzhiyun  * contained with the interface's data structure. There is no global
123*4882a593Smuzhiyun  * numbering for block devices, so the interface name must be provided.
124*4882a593Smuzhiyun  *
125*4882a593Smuzhiyun  * The hardware parition is not related to the normal software partitioning
126*4882a593Smuzhiyun  * of a device - each hardware partition is effectively a separately
127*4882a593Smuzhiyun  * accessible block device. When a hardware parition is selected on MMC the
128*4882a593Smuzhiyun  * other hardware partitions become inaccessible. The same block device is
129*4882a593Smuzhiyun  * used to access all hardware partitions, but its capacity may change when a
130*4882a593Smuzhiyun  * different hardware partition is selected.
131*4882a593Smuzhiyun  *
132*4882a593Smuzhiyun  * When a hardware partition number is given, the block device switches to
133*4882a593Smuzhiyun  * that hardware partition.
134*4882a593Smuzhiyun  *
135*4882a593Smuzhiyun  * @ifname:	Interface name (e.g. "ide", "scsi")
136*4882a593Smuzhiyun  * @dev_str:	Device and optional hw partition. This can either be a string
137*4882a593Smuzhiyun  *		containing the device number (e.g. "2") or the device number
138*4882a593Smuzhiyun  *		and hardware partition number (e.g. "2.4") for devices that
139*4882a593Smuzhiyun  *		support it (currently only MMC).
140*4882a593Smuzhiyun  * @dev_desc:	Returns a pointer to the block device on success
141*4882a593Smuzhiyun  * @return block device number (local to the interface), or -1 on error
142*4882a593Smuzhiyun  */
143*4882a593Smuzhiyun int blk_get_device_by_str(const char *ifname, const char *dev_str,
144*4882a593Smuzhiyun 			  struct blk_desc **dev_desc);
145*4882a593Smuzhiyun 
146*4882a593Smuzhiyun /**
147*4882a593Smuzhiyun  * blk_get_device_part_str() - Get a block device and partition
148*4882a593Smuzhiyun  *
149*4882a593Smuzhiyun  * This calls blk_get_device_by_str() to look up a device. It also looks up
150*4882a593Smuzhiyun  * a partition and returns information about it.
151*4882a593Smuzhiyun  *
152*4882a593Smuzhiyun  * @dev_part_str is in the format:
153*4882a593Smuzhiyun  *	<dev>.<hw_part>:<part> where <dev> is the device number,
154*4882a593Smuzhiyun  *	<hw_part> is the optional hardware partition number and
155*4882a593Smuzhiyun  *	<part> is the partition number
156*4882a593Smuzhiyun  *
157*4882a593Smuzhiyun  * If ifname is "hostfs" then this function returns the sandbox host block
158*4882a593Smuzhiyun  * device.
159*4882a593Smuzhiyun  *
160*4882a593Smuzhiyun  * If ifname is ubi, then this function returns 0, with @info set to a
161*4882a593Smuzhiyun  * special UBI device.
162*4882a593Smuzhiyun  *
163*4882a593Smuzhiyun  * If @dev_part_str is NULL or empty or "-", then this function looks up
164*4882a593Smuzhiyun  * the "bootdevice" environment variable and uses that string instead.
165*4882a593Smuzhiyun  *
166*4882a593Smuzhiyun  * If the partition string is empty then the first partition is used. If the
167*4882a593Smuzhiyun  * partition string is "auto" then the first bootable partition is used.
168*4882a593Smuzhiyun  *
169*4882a593Smuzhiyun  * @ifname:	Interface name (e.g. "ide", "scsi")
170*4882a593Smuzhiyun  * @dev_part_str:	Device and partition string
171*4882a593Smuzhiyun  * @dev_desc:	Returns a pointer to the block device on success
172*4882a593Smuzhiyun  * @info:	Returns partition information
173*4882a593Smuzhiyun  * @allow_whole_dev:	true to allow the user to select partition 0
174*4882a593Smuzhiyun  *		(which means the whole device), false to require a valid
175*4882a593Smuzhiyun  *		partition number >= 1
176*4882a593Smuzhiyun  * @return partition number, or -1 on error
177*4882a593Smuzhiyun  *
178*4882a593Smuzhiyun  */
179*4882a593Smuzhiyun int blk_get_device_part_str(const char *ifname, const char *dev_part_str,
180*4882a593Smuzhiyun 			    struct blk_desc **dev_desc,
181*4882a593Smuzhiyun 			    disk_partition_t *info, int allow_whole_dev);
182*4882a593Smuzhiyun 
183*4882a593Smuzhiyun /**
184*4882a593Smuzhiyun  * part_get_info_by_name() - Search for a partition by name
185*4882a593Smuzhiyun  *                           among all available registered partitions
186*4882a593Smuzhiyun  *
187*4882a593Smuzhiyun  * @param dev_desc - block device descriptor
188*4882a593Smuzhiyun  * @param gpt_name - the specified table entry name
189*4882a593Smuzhiyun  * @param info - returns the disk partition info
190*4882a593Smuzhiyun  *
191*4882a593Smuzhiyun  * @return - the partition number on match (starting on 1), -1 on no match,
192*4882a593Smuzhiyun  * otherwise error
193*4882a593Smuzhiyun  */
194*4882a593Smuzhiyun int part_get_info_by_name(struct blk_desc *dev_desc,
195*4882a593Smuzhiyun 			      const char *name, disk_partition_t *info);
196*4882a593Smuzhiyun 
197*4882a593Smuzhiyun /**
198*4882a593Smuzhiyun  * part_get_info_by_name_strict() - Search for a partition by name
199*4882a593Smuzhiyun  *                                  among all available registered partitions
200*4882a593Smuzhiyun  *				    with strict name match
201*4882a593Smuzhiyun  *
202*4882a593Smuzhiyun  * @param dev_desc - block device descriptor
203*4882a593Smuzhiyun  * @param gpt_name - the specified table entry name to be match strictly
204*4882a593Smuzhiyun  * @param info - returns the disk partition info
205*4882a593Smuzhiyun  *
206*4882a593Smuzhiyun  * @return - the partition number on match (starting on 1), -1 on no match,
207*4882a593Smuzhiyun  * otherwise error
208*4882a593Smuzhiyun  */
209*4882a593Smuzhiyun int part_get_info_by_name_strict(struct blk_desc *dev_desc, const char *name,
210*4882a593Smuzhiyun 				 disk_partition_t *info);
211*4882a593Smuzhiyun /**
212*4882a593Smuzhiyun  * part_set_generic_name() - create generic partition like hda1 or sdb2
213*4882a593Smuzhiyun  *
214*4882a593Smuzhiyun  * Helper function for partition tables, which don't hold partition names
215*4882a593Smuzhiyun  * (DOS, ISO). Generates partition name out of the device type and partition
216*4882a593Smuzhiyun  * number.
217*4882a593Smuzhiyun  *
218*4882a593Smuzhiyun  * @dev_desc:	pointer to the block device
219*4882a593Smuzhiyun  * @part_num:	partition number for which the name is generated
220*4882a593Smuzhiyun  * @name:	buffer where the name is written
221*4882a593Smuzhiyun  */
222*4882a593Smuzhiyun void part_set_generic_name(const struct blk_desc *dev_desc,
223*4882a593Smuzhiyun 	int part_num, char *name);
224*4882a593Smuzhiyun 
225*4882a593Smuzhiyun extern const struct block_drvr block_drvr[];
226*4882a593Smuzhiyun #else
blk_get_dev(const char * ifname,int dev)227*4882a593Smuzhiyun static inline struct blk_desc *blk_get_dev(const char *ifname, int dev)
228*4882a593Smuzhiyun { return NULL; }
mg_disk_get_dev(int dev)229*4882a593Smuzhiyun static inline struct blk_desc *mg_disk_get_dev(int dev) { return NULL; }
230*4882a593Smuzhiyun 
part_get_info(struct blk_desc * dev_desc,int part,disk_partition_t * info)231*4882a593Smuzhiyun static inline int part_get_info(struct blk_desc *dev_desc, int part,
232*4882a593Smuzhiyun 				disk_partition_t *info) { return -1; }
part_get_info_whole_disk(struct blk_desc * dev_desc,disk_partition_t * info)233*4882a593Smuzhiyun static inline int part_get_info_whole_disk(struct blk_desc *dev_desc,
234*4882a593Smuzhiyun 					   disk_partition_t *info)
235*4882a593Smuzhiyun { return -1; }
236*4882a593Smuzhiyun 
part_get_type(struct blk_desc * dev_desc)237*4882a593Smuzhiyun static inline const char *part_get_type(struct blk_desc *dev_desc) { return NULL; }
part_print(struct blk_desc * dev_desc)238*4882a593Smuzhiyun static inline void part_print(struct blk_desc *dev_desc) {}
part_init(struct blk_desc * dev_desc)239*4882a593Smuzhiyun static inline void part_init(struct blk_desc *dev_desc) {}
dev_print(struct blk_desc * dev_desc)240*4882a593Smuzhiyun static inline void dev_print(struct blk_desc *dev_desc) {}
blk_get_device_by_str(const char * ifname,const char * dev_str,struct blk_desc ** dev_desc)241*4882a593Smuzhiyun static inline int blk_get_device_by_str(const char *ifname, const char *dev_str,
242*4882a593Smuzhiyun 					struct blk_desc **dev_desc)
243*4882a593Smuzhiyun { return -1; }
blk_get_device_part_str(const char * ifname,const char * dev_part_str,struct blk_desc ** dev_desc,disk_partition_t * info,int allow_whole_dev)244*4882a593Smuzhiyun static inline int blk_get_device_part_str(const char *ifname,
245*4882a593Smuzhiyun 					   const char *dev_part_str,
246*4882a593Smuzhiyun 					   struct blk_desc **dev_desc,
247*4882a593Smuzhiyun 					   disk_partition_t *info,
248*4882a593Smuzhiyun 					   int allow_whole_dev)
249*4882a593Smuzhiyun { *dev_desc = NULL; return -1; }
250*4882a593Smuzhiyun #endif
251*4882a593Smuzhiyun 
252*4882a593Smuzhiyun /*
253*4882a593Smuzhiyun  * We don't support printing partition information in SPL.
254*4882a593Smuzhiyun  */
255*4882a593Smuzhiyun #ifdef CONFIG_SPL_BUILD
256*4882a593Smuzhiyun #define part_print_ptr(x)	NULL
257*4882a593Smuzhiyun #else
258*4882a593Smuzhiyun #define part_print_ptr(x)       x
259*4882a593Smuzhiyun #endif
260*4882a593Smuzhiyun 
261*4882a593Smuzhiyun #define part_get_info_ptr(x)	x
262*4882a593Smuzhiyun 
263*4882a593Smuzhiyun 
264*4882a593Smuzhiyun struct part_driver {
265*4882a593Smuzhiyun 	const char *name;
266*4882a593Smuzhiyun 	int part_type;
267*4882a593Smuzhiyun 	const int max_entries;	/* maximum number of entries to search */
268*4882a593Smuzhiyun 
269*4882a593Smuzhiyun 	/**
270*4882a593Smuzhiyun 	 * get_info() - Get information about a partition
271*4882a593Smuzhiyun 	 *
272*4882a593Smuzhiyun 	 * @dev_desc:	Block device descriptor
273*4882a593Smuzhiyun 	 * @part:	Partition number (1 = first)
274*4882a593Smuzhiyun 	 * @info:	Returns partition information
275*4882a593Smuzhiyun 	 */
276*4882a593Smuzhiyun 	int (*get_info)(struct blk_desc *dev_desc, int part,
277*4882a593Smuzhiyun 			disk_partition_t *info);
278*4882a593Smuzhiyun 
279*4882a593Smuzhiyun 	/**
280*4882a593Smuzhiyun 	 * print() - Print partition information
281*4882a593Smuzhiyun 	 *
282*4882a593Smuzhiyun 	 * @dev_desc:	Block device descriptor
283*4882a593Smuzhiyun 	 */
284*4882a593Smuzhiyun 	void (*print)(struct blk_desc *dev_desc);
285*4882a593Smuzhiyun 
286*4882a593Smuzhiyun 	/**
287*4882a593Smuzhiyun 	 * test() - Test if a device contains this partition type
288*4882a593Smuzhiyun 	 *
289*4882a593Smuzhiyun 	 * @dev_desc:	Block device descriptor
290*4882a593Smuzhiyun 	 * @return 0 if the block device appears to contain this partition
291*4882a593Smuzhiyun 	 *	   type, -ve if not
292*4882a593Smuzhiyun 	 */
293*4882a593Smuzhiyun 	int (*test)(struct blk_desc *dev_desc);
294*4882a593Smuzhiyun };
295*4882a593Smuzhiyun 
296*4882a593Smuzhiyun /* Declare a new U-Boot partition 'driver' */
297*4882a593Smuzhiyun #define U_BOOT_PART_TYPE(__name)					\
298*4882a593Smuzhiyun 	ll_entry_declare(struct part_driver, __name, part_driver)
299*4882a593Smuzhiyun 
300*4882a593Smuzhiyun #include <part_efi.h>
301*4882a593Smuzhiyun 
302*4882a593Smuzhiyun #if CONFIG_IS_ENABLED(EFI_PARTITION)
303*4882a593Smuzhiyun /* disk/part_efi.c */
304*4882a593Smuzhiyun /**
305*4882a593Smuzhiyun  * write_gpt_table() - Write the GUID Partition Table to disk
306*4882a593Smuzhiyun  *
307*4882a593Smuzhiyun  * @param dev_desc - block device descriptor
308*4882a593Smuzhiyun  * @param gpt_h - pointer to GPT header representation
309*4882a593Smuzhiyun  * @param gpt_e - pointer to GPT partition table entries
310*4882a593Smuzhiyun  *
311*4882a593Smuzhiyun  * @return - zero on success, otherwise error
312*4882a593Smuzhiyun  */
313*4882a593Smuzhiyun int write_gpt_table(struct blk_desc *dev_desc,
314*4882a593Smuzhiyun 		  gpt_header *gpt_h, gpt_entry *gpt_e);
315*4882a593Smuzhiyun 
316*4882a593Smuzhiyun /**
317*4882a593Smuzhiyun  * gpt_fill_pte(): Fill the GPT partition table entry
318*4882a593Smuzhiyun  *
319*4882a593Smuzhiyun  * @param dev_desc - block device descriptor
320*4882a593Smuzhiyun  * @param gpt_h - GPT header representation
321*4882a593Smuzhiyun  * @param gpt_e - GPT partition table entries
322*4882a593Smuzhiyun  * @param partitions - list of partitions
323*4882a593Smuzhiyun  * @param parts - number of partitions
324*4882a593Smuzhiyun  *
325*4882a593Smuzhiyun  * @return zero on success
326*4882a593Smuzhiyun  */
327*4882a593Smuzhiyun int gpt_fill_pte(struct blk_desc *dev_desc,
328*4882a593Smuzhiyun 		 gpt_header *gpt_h, gpt_entry *gpt_e,
329*4882a593Smuzhiyun 		 disk_partition_t *partitions, int parts);
330*4882a593Smuzhiyun 
331*4882a593Smuzhiyun /**
332*4882a593Smuzhiyun  * gpt_fill_header(): Fill the GPT header
333*4882a593Smuzhiyun  *
334*4882a593Smuzhiyun  * @param dev_desc - block device descriptor
335*4882a593Smuzhiyun  * @param gpt_h - GPT header representation
336*4882a593Smuzhiyun  * @param str_guid - disk guid string representation
337*4882a593Smuzhiyun  * @param parts_count - number of partitions
338*4882a593Smuzhiyun  *
339*4882a593Smuzhiyun  * @return - error on str_guid conversion error
340*4882a593Smuzhiyun  */
341*4882a593Smuzhiyun int gpt_fill_header(struct blk_desc *dev_desc, gpt_header *gpt_h,
342*4882a593Smuzhiyun 		char *str_guid, int parts_count);
343*4882a593Smuzhiyun 
344*4882a593Smuzhiyun /**
345*4882a593Smuzhiyun  * gpt_restore(): Restore GPT partition table
346*4882a593Smuzhiyun  *
347*4882a593Smuzhiyun  * @param dev_desc - block device descriptor
348*4882a593Smuzhiyun  * @param str_disk_guid - disk GUID
349*4882a593Smuzhiyun  * @param partitions - list of partitions
350*4882a593Smuzhiyun  * @param parts - number of partitions
351*4882a593Smuzhiyun  *
352*4882a593Smuzhiyun  * @return zero on success
353*4882a593Smuzhiyun  */
354*4882a593Smuzhiyun int gpt_restore(struct blk_desc *dev_desc, char *str_disk_guid,
355*4882a593Smuzhiyun 		disk_partition_t *partitions, const int parts_count);
356*4882a593Smuzhiyun 
357*4882a593Smuzhiyun /**
358*4882a593Smuzhiyun  * is_valid_gpt_buf() - Ensure that the Primary GPT information is valid
359*4882a593Smuzhiyun  *
360*4882a593Smuzhiyun  * @param dev_desc - block device descriptor
361*4882a593Smuzhiyun  * @param buf - buffer which contains the MBR and Primary GPT info
362*4882a593Smuzhiyun  *
363*4882a593Smuzhiyun  * @return - '0' on success, otherwise error
364*4882a593Smuzhiyun  */
365*4882a593Smuzhiyun int is_valid_gpt_buf(struct blk_desc *dev_desc, void *buf);
366*4882a593Smuzhiyun 
367*4882a593Smuzhiyun /**
368*4882a593Smuzhiyun  * write_mbr_and_gpt_partitions() - write MBR, Primary GPT and Backup GPT
369*4882a593Smuzhiyun  *
370*4882a593Smuzhiyun  * @param dev_desc - block device descriptor
371*4882a593Smuzhiyun  * @param buf - buffer which contains the MBR and Primary GPT info
372*4882a593Smuzhiyun  *
373*4882a593Smuzhiyun  * @return - '0' on success, otherwise error
374*4882a593Smuzhiyun  */
375*4882a593Smuzhiyun int write_mbr_and_gpt_partitions(struct blk_desc *dev_desc, void *buf);
376*4882a593Smuzhiyun 
377*4882a593Smuzhiyun /**
378*4882a593Smuzhiyun  * gpt_verify_headers() - Function to read and CRC32 check of the GPT's header
379*4882a593Smuzhiyun  *                        and partition table entries (PTE)
380*4882a593Smuzhiyun  *
381*4882a593Smuzhiyun  * As a side effect if sets gpt_head and gpt_pte so they point to GPT data.
382*4882a593Smuzhiyun  *
383*4882a593Smuzhiyun  * @param dev_desc - block device descriptor
384*4882a593Smuzhiyun  * @param gpt_head - pointer to GPT header data read from medium
385*4882a593Smuzhiyun  * @param gpt_pte - pointer to GPT partition table enties read from medium
386*4882a593Smuzhiyun  *
387*4882a593Smuzhiyun  * @return - '0' on success, otherwise error
388*4882a593Smuzhiyun  */
389*4882a593Smuzhiyun int gpt_verify_headers(struct blk_desc *dev_desc, gpt_header *gpt_head,
390*4882a593Smuzhiyun 		       gpt_entry **gpt_pte);
391*4882a593Smuzhiyun 
392*4882a593Smuzhiyun /**
393*4882a593Smuzhiyun  * gpt_verify_partitions() - Function to check if partitions' name, start and
394*4882a593Smuzhiyun  *                           size correspond to '$partitions' env variable
395*4882a593Smuzhiyun  *
396*4882a593Smuzhiyun  * This function checks if on medium stored GPT data is in sync with information
397*4882a593Smuzhiyun  * provided in '$partitions' environment variable. Specificially, name, start
398*4882a593Smuzhiyun  * and size of the partition is checked.
399*4882a593Smuzhiyun  *
400*4882a593Smuzhiyun  * @param dev_desc - block device descriptor
401*4882a593Smuzhiyun  * @param partitions - partition data read from '$partitions' env variable
402*4882a593Smuzhiyun  * @param parts - number of partitions read from '$partitions' env variable
403*4882a593Smuzhiyun  * @param gpt_head - pointer to GPT header data read from medium
404*4882a593Smuzhiyun  * @param gpt_pte - pointer to GPT partition table enties read from medium
405*4882a593Smuzhiyun  *
406*4882a593Smuzhiyun  * @return - '0' on success, otherwise error
407*4882a593Smuzhiyun  */
408*4882a593Smuzhiyun int gpt_verify_partitions(struct blk_desc *dev_desc,
409*4882a593Smuzhiyun 			  disk_partition_t *partitions, int parts,
410*4882a593Smuzhiyun 			  gpt_header *gpt_head, gpt_entry **gpt_pte);
411*4882a593Smuzhiyun 
412*4882a593Smuzhiyun 
413*4882a593Smuzhiyun /**
414*4882a593Smuzhiyun  * get_disk_guid() - Function to read the GUID string from a device's GPT
415*4882a593Smuzhiyun  *
416*4882a593Smuzhiyun  * This function reads the GUID string from a block device whose descriptor
417*4882a593Smuzhiyun  * is provided.
418*4882a593Smuzhiyun  *
419*4882a593Smuzhiyun  * @param dev_desc - block device descriptor
420*4882a593Smuzhiyun  * @param guid - pre-allocated string in which to return the GUID
421*4882a593Smuzhiyun  *
422*4882a593Smuzhiyun  * @return - '0' on success, otherwise error
423*4882a593Smuzhiyun  */
424*4882a593Smuzhiyun int get_disk_guid(struct blk_desc *dev_desc, char *guid);
425*4882a593Smuzhiyun 
426*4882a593Smuzhiyun #endif
427*4882a593Smuzhiyun 
428*4882a593Smuzhiyun #if CONFIG_IS_ENABLED(DOS_PARTITION)
429*4882a593Smuzhiyun /**
430*4882a593Smuzhiyun  * is_valid_dos_buf() - Ensure that a DOS MBR image is valid
431*4882a593Smuzhiyun  *
432*4882a593Smuzhiyun  * @param buf - buffer which contains the MBR
433*4882a593Smuzhiyun  *
434*4882a593Smuzhiyun  * @return - '0' on success, otherwise error
435*4882a593Smuzhiyun  */
436*4882a593Smuzhiyun int is_valid_dos_buf(void *buf);
437*4882a593Smuzhiyun 
438*4882a593Smuzhiyun /**
439*4882a593Smuzhiyun  * write_mbr_partition() - write DOS MBR
440*4882a593Smuzhiyun  *
441*4882a593Smuzhiyun  * @param dev_desc - block device descriptor
442*4882a593Smuzhiyun  * @param buf - buffer which contains the MBR
443*4882a593Smuzhiyun  *
444*4882a593Smuzhiyun  * @return - '0' on success, otherwise error
445*4882a593Smuzhiyun  */
446*4882a593Smuzhiyun int write_mbr_partition(struct blk_desc *dev_desc, void *buf);
447*4882a593Smuzhiyun 
448*4882a593Smuzhiyun #endif
449*4882a593Smuzhiyun 
450*4882a593Smuzhiyun #if CONFIG_IS_ENABLED(ENV_PARTITION)
451*4882a593Smuzhiyun /**
452*4882a593Smuzhiyun  * env_part_list_init() - pass partitons list to env part
453*4882a593Smuzhiyun  *
454*4882a593Smuzhiyun  * @param list - partitons list
455*4882a593Smuzhiyun  */
456*4882a593Smuzhiyun void env_part_list_init(const char *list);
457*4882a593Smuzhiyun #endif
458*4882a593Smuzhiyun 
459*4882a593Smuzhiyun #endif /* _PART_H */
460