xref: /rk3399_rockchip-uboot/include/part.h (revision 82198b5ccd31ca903c84f3d16e015ca704af852c)
1012771d8Swdenk /*
242dfe7a1Swdenk  * (C) Copyright 2000-2004
3012771d8Swdenk  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4012771d8Swdenk  *
51a459660SWolfgang Denk  * SPDX-License-Identifier:	GPL-2.0+
6012771d8Swdenk  */
7012771d8Swdenk #ifndef _PART_H
8012771d8Swdenk #define _PART_H
9735dd97bSGrant Likely 
101a73661bSSimon Glass #include <blk.h>
116e592385Swdenk #include <ide.h>
12db9b6200SAlison Chaiken #include <uuid.h>
1309a49930SAlison Chaiken #include <linux/list.h>
14012771d8Swdenk 
15d96a9804SAlexander Graf struct block_drvr {
16d96a9804SAlexander Graf 	char *name;
17d96a9804SAlexander Graf 	int (*select_hwpart)(int dev_num, int hwpart);
18d96a9804SAlexander Graf };
19d96a9804SAlexander Graf 
200472fbfdSEgbert Eich #define LOG2(x) (((x & 0xaaaaaaaa) ? 1 : 0) + ((x & 0xcccccccc) ? 2 : 0) + \
210472fbfdSEgbert Eich 		 ((x & 0xf0f0f0f0) ? 4 : 0) + ((x & 0xff00ff00) ? 8 : 0) + \
220472fbfdSEgbert Eich 		 ((x & 0xffff0000) ? 16 : 0))
230472fbfdSEgbert Eich #define LOG2_INVALID(type) ((type)((sizeof(type)<<3)-1))
24ae1768a7SEgbert Eich 
25012771d8Swdenk /* Part types */
26012771d8Swdenk #define PART_TYPE_UNKNOWN	0x00
27012771d8Swdenk #define PART_TYPE_MAC		0x01
28012771d8Swdenk #define PART_TYPE_DOS		0x02
29012771d8Swdenk #define PART_TYPE_ISO		0x03
30c7de829cSwdenk #define PART_TYPE_AMIGA		0x04
3107f3d789Srichardretanubun #define PART_TYPE_EFI		0x05
32*82198b5cSKever Yang #define PART_TYPE_RKPARM	0x06
33c7de829cSwdenk 
3487b8530fSPetr Kulhavy /* maximum number of partition entries supported by search */
3587b8530fSPetr Kulhavy #define DOS_ENTRY_NUMBERS	8
3687b8530fSPetr Kulhavy #define ISO_ENTRY_NUMBERS	64
3787b8530fSPetr Kulhavy #define MAC_ENTRY_NUMBERS	64
3887b8530fSPetr Kulhavy #define AMIGA_ENTRY_NUMBERS	8
39b0fce99bSwdenk /*
40b0fce99bSwdenk  * Type string for U-Boot bootable partitions
41b0fce99bSwdenk  */
42b0fce99bSwdenk #define BOOT_PART_TYPE	"U-Boot"	/* primary boot partition type	*/
43b0fce99bSwdenk #define BOOT_PART_COMP	"PPCBoot"	/* PPCBoot compatibility type	*/
44b0fce99bSwdenk 
45012771d8Swdenk /* device types */
46012771d8Swdenk #define DEV_TYPE_UNKNOWN	0xff	/* not connected */
47012771d8Swdenk #define DEV_TYPE_HARDDISK	0x00	/* harddisk */
48012771d8Swdenk #define DEV_TYPE_TAPE		0x01	/* Tape */
49012771d8Swdenk #define DEV_TYPE_CDROM		0x05	/* CD-ROM */
50012771d8Swdenk #define DEV_TYPE_OPDISK		0x07	/* optical disk */
51012771d8Swdenk 
5292856b48SAlison Chaiken #define PART_NAME_LEN 32
5392856b48SAlison Chaiken #define PART_TYPE_LEN 32
54e6faf21fSAlison Chaiken #define MAX_SEARCH_PARTITIONS 64
5592856b48SAlison Chaiken 
56012771d8Swdenk typedef struct disk_partition {
5704735e9cSFrederic Leroy 	lbaint_t	start;	/* # of first block in partition	*/
5804735e9cSFrederic Leroy 	lbaint_t	size;	/* number of blocks in partition	*/
59012771d8Swdenk 	ulong	blksz;		/* block size in bytes			*/
6092856b48SAlison Chaiken 	uchar	name[PART_NAME_LEN];	/* partition name			*/
6192856b48SAlison Chaiken 	uchar	type[PART_TYPE_LEN];	/* string type description		*/
6240e0e568SRob Herring 	int	bootable;	/* Active/Bootable flag is set		*/
63b331cd62SPatrick Delaunay #if CONFIG_IS_ENABLED(PARTITION_UUIDS)
64db9b6200SAlison Chaiken 	char	uuid[UUID_STR_LEN + 1];	/* filesystem UUID as string, if exists	*/
65894bfbbfSStephen Warren #endif
667561b258SPatrick Delaunay #ifdef CONFIG_PARTITION_TYPE_GUID
67db9b6200SAlison Chaiken 	char	type_guid[UUID_STR_LEN + 1];	/* type GUID as string, if exists	*/
687561b258SPatrick Delaunay #endif
69f0fb4fa7SDalon Westergreen #ifdef CONFIG_DOS_PARTITION
70f0fb4fa7SDalon Westergreen 	uchar	sys_ind;	/* partition type 			*/
71f0fb4fa7SDalon Westergreen #endif
72012771d8Swdenk } disk_partition_t;
73012771d8Swdenk 
7409a49930SAlison Chaiken struct disk_part {
7509a49930SAlison Chaiken 	int partnum;
7609a49930SAlison Chaiken 	disk_partition_t gpt_part_info;
7709a49930SAlison Chaiken 	struct list_head list;
7809a49930SAlison Chaiken };
7909a49930SAlison Chaiken 
80735dd97bSGrant Likely /* Misc _get_dev functions */
81df3fc526SMatthew McClintock #ifdef CONFIG_PARTITIONS
82fb1b7be9SSimon Glass /**
83db1d9e78SSimon Glass  * blk_get_dev() - get a pointer to a block device given its type and number
84fb1b7be9SSimon Glass  *
85fb1b7be9SSimon Glass  * Each interface allocates its own devices and typically struct blk_desc is
86fb1b7be9SSimon Glass  * contained with the interface's data structure. There is no global
87fb1b7be9SSimon Glass  * numbering for block devices, so the interface name must be provided.
88fb1b7be9SSimon Glass  *
89fb1b7be9SSimon Glass  * @ifname:	Interface name (e.g. "ide", "scsi")
90fb1b7be9SSimon Glass  * @dev:	Device number (0 for first device on that interface, 1 for
91fb1b7be9SSimon Glass  *		second, etc.
92fb1b7be9SSimon Glass  * @return pointer to the block device, or NULL if not available, or an
93fb1b7be9SSimon Glass  *	   error occurred.
94fb1b7be9SSimon Glass  */
95db1d9e78SSimon Glass struct blk_desc *blk_get_dev(const char *ifname, int dev);
96fb1b7be9SSimon Glass 
974101f687SSimon Glass struct blk_desc *mg_disk_get_dev(int dev);
984101f687SSimon Glass int host_get_dev_err(int dev, struct blk_desc **blk_devp);
99735dd97bSGrant Likely 
100012771d8Swdenk /* disk/part.c */
1013e8bd469SSimon Glass int part_get_info(struct blk_desc *dev_desc, int part, disk_partition_t *info);
1023e8bd469SSimon Glass void part_print(struct blk_desc *dev_desc);
1033e8bd469SSimon Glass void part_init(struct blk_desc *dev_desc);
1044101f687SSimon Glass void dev_print(struct blk_desc *dev_desc);
105ebac37cfSSimon Glass 
106ebac37cfSSimon Glass /**
107ebac37cfSSimon Glass  * blk_get_device_by_str() - Get a block device given its interface/hw partition
108ebac37cfSSimon Glass  *
109ebac37cfSSimon Glass  * Each interface allocates its own devices and typically struct blk_desc is
110ebac37cfSSimon Glass  * contained with the interface's data structure. There is no global
111ebac37cfSSimon Glass  * numbering for block devices, so the interface name must be provided.
112ebac37cfSSimon Glass  *
113ebac37cfSSimon Glass  * The hardware parition is not related to the normal software partitioning
114ebac37cfSSimon Glass  * of a device - each hardware partition is effectively a separately
115ebac37cfSSimon Glass  * accessible block device. When a hardware parition is selected on MMC the
116ebac37cfSSimon Glass  * other hardware partitions become inaccessible. The same block device is
117ebac37cfSSimon Glass  * used to access all hardware partitions, but its capacity may change when a
118ebac37cfSSimon Glass  * different hardware partition is selected.
119ebac37cfSSimon Glass  *
120ebac37cfSSimon Glass  * When a hardware partition number is given, the block device switches to
121ebac37cfSSimon Glass  * that hardware partition.
122ebac37cfSSimon Glass  *
123ebac37cfSSimon Glass  * @ifname:	Interface name (e.g. "ide", "scsi")
124ebac37cfSSimon Glass  * @dev_str:	Device and optional hw partition. This can either be a string
125ebac37cfSSimon Glass  *		containing the device number (e.g. "2") or the device number
126ebac37cfSSimon Glass  *		and hardware partition number (e.g. "2.4") for devices that
127ebac37cfSSimon Glass  *		support it (currently only MMC).
128ebac37cfSSimon Glass  * @dev_desc:	Returns a pointer to the block device on success
129ebac37cfSSimon Glass  * @return block device number (local to the interface), or -1 on error
130ebac37cfSSimon Glass  */
131ebac37cfSSimon Glass int blk_get_device_by_str(const char *ifname, const char *dev_str,
1324101f687SSimon Glass 			  struct blk_desc **dev_desc);
133e35929e4SSimon Glass 
134e35929e4SSimon Glass /**
135e35929e4SSimon Glass  * blk_get_device_part_str() - Get a block device and partition
136e35929e4SSimon Glass  *
137e35929e4SSimon Glass  * This calls blk_get_device_by_str() to look up a device. It also looks up
138e35929e4SSimon Glass  * a partition and returns information about it.
139e35929e4SSimon Glass  *
140e35929e4SSimon Glass  * @dev_part_str is in the format:
141e35929e4SSimon Glass  *	<dev>.<hw_part>:<part> where <dev> is the device number,
142e35929e4SSimon Glass  *	<hw_part> is the optional hardware partition number and
143e35929e4SSimon Glass  *	<part> is the partition number
144e35929e4SSimon Glass  *
145e35929e4SSimon Glass  * If ifname is "hostfs" then this function returns the sandbox host block
146e35929e4SSimon Glass  * device.
147e35929e4SSimon Glass  *
148e35929e4SSimon Glass  * If ifname is ubi, then this function returns 0, with @info set to a
149e35929e4SSimon Glass  * special UBI device.
150e35929e4SSimon Glass  *
151e35929e4SSimon Glass  * If @dev_part_str is NULL or empty or "-", then this function looks up
152e35929e4SSimon Glass  * the "bootdevice" environment variable and uses that string instead.
153e35929e4SSimon Glass  *
154e35929e4SSimon Glass  * If the partition string is empty then the first partition is used. If the
155e35929e4SSimon Glass  * partition string is "auto" then the first bootable partition is used.
156e35929e4SSimon Glass  *
157e35929e4SSimon Glass  * @ifname:	Interface name (e.g. "ide", "scsi")
158e35929e4SSimon Glass  * @dev_part_str:	Device and partition string
159e35929e4SSimon Glass  * @dev_desc:	Returns a pointer to the block device on success
160e35929e4SSimon Glass  * @info:	Returns partition information
161e35929e4SSimon Glass  * @allow_whole_dev:	true to allow the user to select partition 0
162e35929e4SSimon Glass  *		(which means the whole device), false to require a valid
163e35929e4SSimon Glass  *		partition number >= 1
164e35929e4SSimon Glass  * @return partition number, or -1 on error
165e35929e4SSimon Glass  *
166e35929e4SSimon Glass  */
167e35929e4SSimon Glass int blk_get_device_part_str(const char *ifname, const char *dev_part_str,
1684101f687SSimon Glass 			    struct blk_desc **dev_desc,
16910a37fd7SStephen Warren 			    disk_partition_t *info, int allow_whole_dev);
17087b8530fSPetr Kulhavy 
17187b8530fSPetr Kulhavy /**
17287b8530fSPetr Kulhavy  * part_get_info_by_name() - Search for a partition by name
17387b8530fSPetr Kulhavy  *                           among all available registered partitions
17487b8530fSPetr Kulhavy  *
17587b8530fSPetr Kulhavy  * @param dev_desc - block device descriptor
17687b8530fSPetr Kulhavy  * @param gpt_name - the specified table entry name
17787b8530fSPetr Kulhavy  * @param info - returns the disk partition info
17887b8530fSPetr Kulhavy  *
17988b6329cSAlex Deymo  * @return - the partition number on match (starting on 1), -1 on no match,
18088b6329cSAlex Deymo  * otherwise error
18187b8530fSPetr Kulhavy  */
18287b8530fSPetr Kulhavy int part_get_info_by_name(struct blk_desc *dev_desc,
18387b8530fSPetr Kulhavy 			      const char *name, disk_partition_t *info);
18487b8530fSPetr Kulhavy 
185da2ee24dSPetr Kulhavy /**
186da2ee24dSPetr Kulhavy  * part_set_generic_name() - create generic partition like hda1 or sdb2
187da2ee24dSPetr Kulhavy  *
188da2ee24dSPetr Kulhavy  * Helper function for partition tables, which don't hold partition names
189da2ee24dSPetr Kulhavy  * (DOS, ISO). Generates partition name out of the device type and partition
190da2ee24dSPetr Kulhavy  * number.
191da2ee24dSPetr Kulhavy  *
192da2ee24dSPetr Kulhavy  * @dev_desc:	pointer to the block device
193da2ee24dSPetr Kulhavy  * @part_num:	partition number for which the name is generated
194da2ee24dSPetr Kulhavy  * @name:	buffer where the name is written
195da2ee24dSPetr Kulhavy  */
196da2ee24dSPetr Kulhavy void part_set_generic_name(const struct blk_desc *dev_desc,
197da2ee24dSPetr Kulhavy 	int part_num, char *name);
198da2ee24dSPetr Kulhavy 
199d96a9804SAlexander Graf extern const struct block_drvr block_drvr[];
200df3fc526SMatthew McClintock #else
201db1d9e78SSimon Glass static inline struct blk_desc *blk_get_dev(const char *ifname, int dev)
20299d2c205SRob Herring { return NULL; }
2034101f687SSimon Glass static inline struct blk_desc *mg_disk_get_dev(int dev) { return NULL; }
204012771d8Swdenk 
2053e8bd469SSimon Glass static inline int part_get_info(struct blk_desc *dev_desc, int part,
206df3fc526SMatthew McClintock 				disk_partition_t *info) { return -1; }
2073e8bd469SSimon Glass static inline void part_print(struct blk_desc *dev_desc) {}
2083e8bd469SSimon Glass static inline void part_init(struct blk_desc *dev_desc) {}
2094101f687SSimon Glass static inline void dev_print(struct blk_desc *dev_desc) {}
210ebac37cfSSimon Glass static inline int blk_get_device_by_str(const char *ifname, const char *dev_str,
2114101f687SSimon Glass 					struct blk_desc **dev_desc)
2122023e608SStephen Warren { return -1; }
213e35929e4SSimon Glass static inline int blk_get_device_part_str(const char *ifname,
21410a37fd7SStephen Warren 					   const char *dev_part_str,
2154101f687SSimon Glass 					   struct blk_desc **dev_desc,
21610a37fd7SStephen Warren 					   disk_partition_t *info,
21710a37fd7SStephen Warren 					   int allow_whole_dev)
21899d2c205SRob Herring { *dev_desc = NULL; return -1; }
219df3fc526SMatthew McClintock #endif
220012771d8Swdenk 
22196e5b03cSSimon Glass /*
22296e5b03cSSimon Glass  * We don't support printing partition information in SPL and only support
22396e5b03cSSimon Glass  * getting partition information in a few cases.
22496e5b03cSSimon Glass  */
22596e5b03cSSimon Glass #ifdef CONFIG_SPL_BUILD
22696e5b03cSSimon Glass # define part_print_ptr(x)	NULL
227d9b2678eSMichal Simek # if defined(CONFIG_SPL_EXT_SUPPORT) || defined(CONFIG_SPL_FAT_SUPPORT) || \
22896e5b03cSSimon Glass 	defined(CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION)
22996e5b03cSSimon Glass #  define part_get_info_ptr(x)	x
23096e5b03cSSimon Glass # else
23196e5b03cSSimon Glass #  define part_get_info_ptr(x)	NULL
23296e5b03cSSimon Glass # endif
23396e5b03cSSimon Glass #else
23496e5b03cSSimon Glass #define part_print_ptr(x)	x
23596e5b03cSSimon Glass #define part_get_info_ptr(x)	x
236012771d8Swdenk #endif
237012771d8Swdenk 
238012771d8Swdenk 
23996e5b03cSSimon Glass struct part_driver {
24096e5b03cSSimon Glass 	const char *name;
24196e5b03cSSimon Glass 	int part_type;
24287b8530fSPetr Kulhavy 	const int max_entries;	/* maximum number of entries to search */
243012771d8Swdenk 
24496e5b03cSSimon Glass 	/**
24596e5b03cSSimon Glass 	 * get_info() - Get information about a partition
24696e5b03cSSimon Glass 	 *
24796e5b03cSSimon Glass 	 * @dev_desc:	Block device descriptor
24896e5b03cSSimon Glass 	 * @part:	Partition number (1 = first)
24996e5b03cSSimon Glass 	 * @info:	Returns partition information
25096e5b03cSSimon Glass 	 */
25196e5b03cSSimon Glass 	int (*get_info)(struct blk_desc *dev_desc, int part,
2524101f687SSimon Glass 			disk_partition_t *info);
25396e5b03cSSimon Glass 
25496e5b03cSSimon Glass 	/**
25596e5b03cSSimon Glass 	 * print() - Print partition information
25696e5b03cSSimon Glass 	 *
25796e5b03cSSimon Glass 	 * @dev_desc:	Block device descriptor
25896e5b03cSSimon Glass 	 */
25996e5b03cSSimon Glass 	void (*print)(struct blk_desc *dev_desc);
26096e5b03cSSimon Glass 
26196e5b03cSSimon Glass 	/**
26296e5b03cSSimon Glass 	 * test() - Test if a device contains this partition type
26396e5b03cSSimon Glass 	 *
26496e5b03cSSimon Glass 	 * @dev_desc:	Block device descriptor
26596e5b03cSSimon Glass 	 * @return 0 if the block device appears to contain this partition
26696e5b03cSSimon Glass 	 *	   type, -ve if not
26796e5b03cSSimon Glass 	 */
26896e5b03cSSimon Glass 	int (*test)(struct blk_desc *dev_desc);
26996e5b03cSSimon Glass };
27096e5b03cSSimon Glass 
27196e5b03cSSimon Glass /* Declare a new U-Boot partition 'driver' */
27296e5b03cSSimon Glass #define U_BOOT_PART_TYPE(__name)					\
27396e5b03cSSimon Glass 	ll_entry_declare(struct part_driver, __name, part_driver)
274c7de829cSwdenk 
275bd42a942SPatrick Delaunay #if CONFIG_IS_ENABLED(EFI_PARTITION)
27640684ddbSLukasz Majewski #include <part_efi.h>
27707f3d789Srichardretanubun /* disk/part_efi.c */
27860bf9416SSteve Rae /**
27940684ddbSLukasz Majewski  * write_gpt_table() - Write the GUID Partition Table to disk
28040684ddbSLukasz Majewski  *
28140684ddbSLukasz Majewski  * @param dev_desc - block device descriptor
28240684ddbSLukasz Majewski  * @param gpt_h - pointer to GPT header representation
28340684ddbSLukasz Majewski  * @param gpt_e - pointer to GPT partition table entries
28440684ddbSLukasz Majewski  *
28540684ddbSLukasz Majewski  * @return - zero on success, otherwise error
28640684ddbSLukasz Majewski  */
2874101f687SSimon Glass int write_gpt_table(struct blk_desc *dev_desc,
28840684ddbSLukasz Majewski 		  gpt_header *gpt_h, gpt_entry *gpt_e);
28940684ddbSLukasz Majewski 
29040684ddbSLukasz Majewski /**
29140684ddbSLukasz Majewski  * gpt_fill_pte(): Fill the GPT partition table entry
29240684ddbSLukasz Majewski  *
29347d7ee47SMaxime Ripard  * @param dev_desc - block device descriptor
29440684ddbSLukasz Majewski  * @param gpt_h - GPT header representation
29540684ddbSLukasz Majewski  * @param gpt_e - GPT partition table entries
29640684ddbSLukasz Majewski  * @param partitions - list of partitions
29740684ddbSLukasz Majewski  * @param parts - number of partitions
29840684ddbSLukasz Majewski  *
29940684ddbSLukasz Majewski  * @return zero on success
30040684ddbSLukasz Majewski  */
30147d7ee47SMaxime Ripard int gpt_fill_pte(struct blk_desc *dev_desc,
30247d7ee47SMaxime Ripard 		 gpt_header *gpt_h, gpt_entry *gpt_e,
30340684ddbSLukasz Majewski 		 disk_partition_t *partitions, int parts);
30440684ddbSLukasz Majewski 
30540684ddbSLukasz Majewski /**
30640684ddbSLukasz Majewski  * gpt_fill_header(): Fill the GPT header
30740684ddbSLukasz Majewski  *
30840684ddbSLukasz Majewski  * @param dev_desc - block device descriptor
30940684ddbSLukasz Majewski  * @param gpt_h - GPT header representation
31040684ddbSLukasz Majewski  * @param str_guid - disk guid string representation
31140684ddbSLukasz Majewski  * @param parts_count - number of partitions
31240684ddbSLukasz Majewski  *
31340684ddbSLukasz Majewski  * @return - error on str_guid conversion error
31440684ddbSLukasz Majewski  */
3154101f687SSimon Glass int gpt_fill_header(struct blk_desc *dev_desc, gpt_header *gpt_h,
31640684ddbSLukasz Majewski 		char *str_guid, int parts_count);
31740684ddbSLukasz Majewski 
31840684ddbSLukasz Majewski /**
31940684ddbSLukasz Majewski  * gpt_restore(): Restore GPT partition table
32040684ddbSLukasz Majewski  *
32140684ddbSLukasz Majewski  * @param dev_desc - block device descriptor
32240684ddbSLukasz Majewski  * @param str_disk_guid - disk GUID
32340684ddbSLukasz Majewski  * @param partitions - list of partitions
32440684ddbSLukasz Majewski  * @param parts - number of partitions
32540684ddbSLukasz Majewski  *
32640684ddbSLukasz Majewski  * @return zero on success
32740684ddbSLukasz Majewski  */
3284101f687SSimon Glass int gpt_restore(struct blk_desc *dev_desc, char *str_disk_guid,
32940684ddbSLukasz Majewski 		disk_partition_t *partitions, const int parts_count);
3300ff7e585SSteve Rae 
3310ff7e585SSteve Rae /**
3320ff7e585SSteve Rae  * is_valid_gpt_buf() - Ensure that the Primary GPT information is valid
3330ff7e585SSteve Rae  *
3340ff7e585SSteve Rae  * @param dev_desc - block device descriptor
3350ff7e585SSteve Rae  * @param buf - buffer which contains the MBR and Primary GPT info
3360ff7e585SSteve Rae  *
3370ff7e585SSteve Rae  * @return - '0' on success, otherwise error
3380ff7e585SSteve Rae  */
3394101f687SSimon Glass int is_valid_gpt_buf(struct blk_desc *dev_desc, void *buf);
3400ff7e585SSteve Rae 
3410ff7e585SSteve Rae /**
3420ff7e585SSteve Rae  * write_mbr_and_gpt_partitions() - write MBR, Primary GPT and Backup GPT
3430ff7e585SSteve Rae  *
3440ff7e585SSteve Rae  * @param dev_desc - block device descriptor
3450ff7e585SSteve Rae  * @param buf - buffer which contains the MBR and Primary GPT info
3460ff7e585SSteve Rae  *
3470ff7e585SSteve Rae  * @return - '0' on success, otherwise error
3480ff7e585SSteve Rae  */
3494101f687SSimon Glass int write_mbr_and_gpt_partitions(struct blk_desc *dev_desc, void *buf);
350cef68bf9SLukasz Majewski 
351cef68bf9SLukasz Majewski /**
352cef68bf9SLukasz Majewski  * gpt_verify_headers() - Function to read and CRC32 check of the GPT's header
353cef68bf9SLukasz Majewski  *                        and partition table entries (PTE)
354cef68bf9SLukasz Majewski  *
355cef68bf9SLukasz Majewski  * As a side effect if sets gpt_head and gpt_pte so they point to GPT data.
356cef68bf9SLukasz Majewski  *
357cef68bf9SLukasz Majewski  * @param dev_desc - block device descriptor
358cef68bf9SLukasz Majewski  * @param gpt_head - pointer to GPT header data read from medium
359cef68bf9SLukasz Majewski  * @param gpt_pte - pointer to GPT partition table enties read from medium
360cef68bf9SLukasz Majewski  *
361cef68bf9SLukasz Majewski  * @return - '0' on success, otherwise error
362cef68bf9SLukasz Majewski  */
3634101f687SSimon Glass int gpt_verify_headers(struct blk_desc *dev_desc, gpt_header *gpt_head,
364cef68bf9SLukasz Majewski 		       gpt_entry **gpt_pte);
365cef68bf9SLukasz Majewski 
366cef68bf9SLukasz Majewski /**
367cef68bf9SLukasz Majewski  * gpt_verify_partitions() - Function to check if partitions' name, start and
368cef68bf9SLukasz Majewski  *                           size correspond to '$partitions' env variable
369cef68bf9SLukasz Majewski  *
370cef68bf9SLukasz Majewski  * This function checks if on medium stored GPT data is in sync with information
371cef68bf9SLukasz Majewski  * provided in '$partitions' environment variable. Specificially, name, start
372cef68bf9SLukasz Majewski  * and size of the partition is checked.
373cef68bf9SLukasz Majewski  *
374cef68bf9SLukasz Majewski  * @param dev_desc - block device descriptor
375cef68bf9SLukasz Majewski  * @param partitions - partition data read from '$partitions' env variable
376cef68bf9SLukasz Majewski  * @param parts - number of partitions read from '$partitions' env variable
377cef68bf9SLukasz Majewski  * @param gpt_head - pointer to GPT header data read from medium
378cef68bf9SLukasz Majewski  * @param gpt_pte - pointer to GPT partition table enties read from medium
379cef68bf9SLukasz Majewski  *
380cef68bf9SLukasz Majewski  * @return - '0' on success, otherwise error
381cef68bf9SLukasz Majewski  */
3824101f687SSimon Glass int gpt_verify_partitions(struct blk_desc *dev_desc,
383cef68bf9SLukasz Majewski 			  disk_partition_t *partitions, int parts,
384cef68bf9SLukasz Majewski 			  gpt_header *gpt_head, gpt_entry **gpt_pte);
38573d6d18bSAlison Chaiken 
38673d6d18bSAlison Chaiken 
38773d6d18bSAlison Chaiken /**
38873d6d18bSAlison Chaiken  * get_disk_guid() - Function to read the GUID string from a device's GPT
38973d6d18bSAlison Chaiken  *
39073d6d18bSAlison Chaiken  * This function reads the GUID string from a block device whose descriptor
39173d6d18bSAlison Chaiken  * is provided.
39273d6d18bSAlison Chaiken  *
39373d6d18bSAlison Chaiken  * @param dev_desc - block device descriptor
39473d6d18bSAlison Chaiken  * @param guid - pre-allocated string in which to return the GUID
39573d6d18bSAlison Chaiken  *
39673d6d18bSAlison Chaiken  * @return - '0' on success, otherwise error
39773d6d18bSAlison Chaiken  */
39873d6d18bSAlison Chaiken int get_disk_guid(struct blk_desc *dev_desc, char *guid);
39973d6d18bSAlison Chaiken 
40007f3d789Srichardretanubun #endif
40107f3d789Srichardretanubun 
402b0cf7339SPatrick Delaunay #if CONFIG_IS_ENABLED(DOS_PARTITION)
403b6dd69a4SPetr Kulhavy /**
404b6dd69a4SPetr Kulhavy  * is_valid_dos_buf() - Ensure that a DOS MBR image is valid
405b6dd69a4SPetr Kulhavy  *
406b6dd69a4SPetr Kulhavy  * @param buf - buffer which contains the MBR
407b6dd69a4SPetr Kulhavy  *
408b6dd69a4SPetr Kulhavy  * @return - '0' on success, otherwise error
409b6dd69a4SPetr Kulhavy  */
410b6dd69a4SPetr Kulhavy int is_valid_dos_buf(void *buf);
411b6dd69a4SPetr Kulhavy 
412b6dd69a4SPetr Kulhavy /**
413b6dd69a4SPetr Kulhavy  * write_mbr_partition() - write DOS MBR
414b6dd69a4SPetr Kulhavy  *
415b6dd69a4SPetr Kulhavy  * @param dev_desc - block device descriptor
416b6dd69a4SPetr Kulhavy  * @param buf - buffer which contains the MBR
417b6dd69a4SPetr Kulhavy  *
418b6dd69a4SPetr Kulhavy  * @return - '0' on success, otherwise error
419b6dd69a4SPetr Kulhavy  */
420b6dd69a4SPetr Kulhavy int write_mbr_partition(struct blk_desc *dev_desc, void *buf);
421b6dd69a4SPetr Kulhavy 
422b6dd69a4SPetr Kulhavy #endif
423b6dd69a4SPetr Kulhavy 
424b6dd69a4SPetr Kulhavy 
425012771d8Swdenk #endif /* _PART_H */
426