Skip to contentSkip to conversation

add EFI GUID Partition Table support

PATCH Superseded Jean-Christophe PLAGNIOL-VILLARD 3 participants 10 messages Feb 14, 2013 – Feb 15, 2013 EFI

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

cover add EFI GUID Partition Table support

HI,

v2:
fix memory leak
filetype: full check
part name: comment
efi: make gpt primary and alternate check optional

this add the support of the EFI GPT and named partition

The following changes since commit a40e76cebcbe8b025bafdefdc6e27b7553209ed7:

Add warning above get_ram_size (2013-02-13 18:14:38 +0100)

are available in the git repository at:

git://git.jcrosoft.org/barebox.git delivery/efi_gpt

for you to fetch changes up to 7825a076660b34dd08e4041f820fcbeb6a301e67:

disk: partitions: add EFI GUID Partition Table (2013-02-14 05:59:31 +0800)

----------------------------------------------------------------
Jean-Christophe PLAGNIOL-VILLARD (5):
linux/types: import __aligned_x64 from the kernel
filetype: add GPT support
partitons: add framework
disk: introduce partition name
disk: partitions: add EFI GUID Partition Table

 common/Kconfig             |   14 +------
 common/Makefile            |    2 +-
 common/filetype.c          |   47 +++++++++++++++++++++
 common/partitions.c        |  179 +++++++++++++++++++++++++++++++++++++------------------------------------------
 common/partitions/Kconfig  |   32 +++++++++++++++
 common/partitions/Makefile |    2 +
 common/partitions/dos.c    |   88 +++++++++++++++++++++++++++++++++++++++
 common/partitions/efi.c    |  477 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 common/partitions/efi.h    |  123 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 common/partitions/parser.h |   37 +++++++++++++++++
 include/filetype.h         |    1 +
 include/linux/efi.h        |  547 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/types.h      |   13 ++++++
 13 files changed, 1452 insertions(+), 110 deletions(-)
 create mode 100644 common/partitions/Kconfig
 create mode 100644 common/partitions/Makefile
 create mode 100644 common/partitions/dos.c
 create mode 100644 common/partitions/efi.c
 create mode 100644 common/partitions/efi.h
 create mode 100644 common/partitions/parser.h
 create mode 100644 include/linux/efi.h

Best Regards,
J.

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#1 lore raw

PATCH 1/5 linux/types: import __aligned_x64 from the kernel

need it by upcoming EFI GPT support

---
 include/linux/types.h |   13 +++++++++++++
 1 file changed, 13 insertions(+)
include/linux/types.h +13 -0
index 76c6b67..14f8315 100644
@@ -142,6 +142,19 @@ typedef __u64 __bitwise __be64;
 typedef __u16 __bitwise __sum16;
 typedef __u32 __bitwise __wsum;
 
+/*
+ * aligned_u64 should be used in defining kernel<->userspace ABIs to avoid
+ * common 32/64-bit compat problems.
+ * 64-bit values align to 4-byte boundaries on x86_32 (and possibly other
+ * architectures) and to 8-byte boundaries on 64-bit architectures.  The new
+ * aligned_64 type enforces 8-byte alignment so that structs containing
+ * aligned_64 values have the same alignment on 32-bit and 64-bit architectures.
+ * No conversions are necessary between 32-bit user-space and a 64-bit kernel.
+ */
+#define __aligned_u64 __u64 __attribute__((aligned(8)))
+#define __aligned_be64 __be64 __attribute__((aligned(8)))
+#define __aligned_le64 __le64 __attribute__((aligned(8)))
+
 #ifdef CONFIG_PHYS_ADDR_T_64BIT
 typedef u64 phys_addr_t;
 typedef u64 phys_size_t;
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

PATCH 2/5 filetype: add GPT support

GPT need to be check before MBR

---
 common/filetype.c  |   47 +++++++++++++++++++++++++++++++++++++++++++++++
 include/filetype.h |    1 +
 2 files changed, 48 insertions(+)
common/filetype.c +47 -0
index 22fc621..a685ea5 100644
@@ -48,6 +48,7 @@ static const struct filetype_str filetype_str[] = {
 	[filetype_bmp] = { "BMP image", "bmp" },
 	[filetype_png] = { "PNG image", "png" },
 	[filetype_ext] = { "ext filesystem", "ext" },
+	[filetype_gpt] = { "GUID Partition Table", "gpt" },
 };
 
 const char *file_type_to_string(enum filetype f)
@@ -69,9 +70,52 @@ const char *file_type_to_short_string(enum filetype f)
 #define MBR_StartSector		8	/* MBR: Offset of Starting Sector in Partition Table Entry */
 #define BS_55AA			510	/* Boot sector signature (2) */
 #define MBR_Table		446	/* MBR: Partition table offset (2) */
+#define MBR_partition_size	16	/* MBR: Partition table offset (2) */
 #define BS_FilSysType32		82	/* File system type (1) */
 #define BS_FilSysType		54	/* File system type (1) */
 
+#define MBR_PART_sys_ind	4
+#define MBR_PART_start_sect	8
+#define MBR_OSTYPE_EFI_GPT	0xee
+
+static inline int pmbr_part_valid(const uint8_t *buf)
+{
+	if (buf[MBR_PART_sys_ind] == MBR_OSTYPE_EFI_GPT &&
+		get_unaligned_le32(&buf[MBR_PART_start_sect]) == 1UL) {
+		return 1;
+	}
+
+	return 0;
+}
+
+/**
+ * is_pmbr_valid(): test Protective MBR for validity
+ * @mbr: pointer to a legacy mbr structure
+ *
+ * Description: Returns 1 if PMBR is valid, 0 otherwise.
+ * Validity depends on two things:
+ *  1) MSDOS signature is in the last two bytes of the MBR
+ *  2) One partition of type 0xEE is found
+ */
+static int is_gpt_valid(const uint8_t *buf)
+{
+	int i;
+
+	if (get_unaligned_le16(&buf[BS_55AA]) != 0xAA55)
+		return 0;
+
+	if (strncmp(&buf[512], "EFI PART", 8))
+		return 0;
+
+	buf += MBR_Table;
+
+	for (i = 0; i < 4; i++, buf += MBR_partition_size) {
+		if (pmbr_part_valid(buf))
+			return 1;
+	}
+	return 0;
+}
+
 enum filetype is_fat_or_mbr(const unsigned char *sector, unsigned long *bootsec)
 {
 	/*
@@ -159,6 +203,9 @@ enum filetype file_detect_type(const void *_buf, size_t bufsize)
 	if (bufsize < 512)
 		return filetype_unknown;
 
+	if (bufsize >= 520 && is_gpt_valid(buf8))
+		return filetype_gpt;
+
 	type = is_fat_or_mbr(buf8, NULL);
 	if (type != filetype_unknown)
 		return type;
include/filetype.h +1 -0
index 4d43757..78ca5d2 100644
@@ -23,6 +23,7 @@ enum filetype {
 	filetype_bmp,
 	filetype_png,
 	filetype_ext,
+	filetype_gpt,
 	filetype_max,
 };
 
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw

Re: [PATCH 2/5] filetype: add GPT support

Quoted 29 lines · Jean-Christophe PLAGNIOL-VILLARD
common/filetype.c +29 -0
+#define MBR_OSTYPE_EFI_GPT	0xee
+
+static inline int pmbr_part_valid(const uint8_t *buf)
+{
+	if (buf[MBR_PART_sys_ind] == MBR_OSTYPE_EFI_GPT &&
+		get_unaligned_le32(&buf[MBR_PART_start_sect]) == 1UL) {
+		return 1;
+	}
+
+	return 0;
+}
+
+/**
+ * is_pmbr_valid(): test Protective MBR for validity
+ * @mbr: pointer to a legacy mbr structure
+ *
+ * Description: Returns 1 if PMBR is valid, 0 otherwise.
+ * Validity depends on two things:
+ *  1) MSDOS signature is in the last two bytes of the MBR
+ *  2) One partition of type 0xEE is found
+ */
+static int is_gpt_valid(const uint8_t *buf)
+{
+	int i;
+
+	if (get_unaligned_le16(&buf[BS_55AA]) != 0xAA55)
+		return 0;
+
+	if (strncmp(&buf[512], "EFI PART", 8))

common/filetype.c const char *file_type_to_short_string(enum filetype f) · line 117

Quoted 10 lines
common/filetype.c +10 -0
+		return 0;
+
+	buf += MBR_Table;
+
+	for (i = 0; i < 4; i++, buf += MBR_partition_size) {
+		if (pmbr_part_valid(buf))
+			return 1;
+	}
+	return 0;
+}

ACK, this is what I meant.

Thanks,
Johannes

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#4 lore raw

Re: [PATCH 2/5] filetype: add GPT support

In reply to Jean-Christophe PLAGNIOL-VILLARD
Quoted 43 lines · Jean-Christophe PLAGNIOL-VILLARD

GPT need to be check before MBR

---
 common/filetype.c  |   47 +++++++++++++++++++++++++++++++++++++++++++++++
 include/filetype.h |    1 +
 2 files changed, 48 insertions(+)
common/filetype.c +16 -0
index 22fc621..a685ea5 100644
@@ -48,6 +48,7 @@ static const struct filetype_str filetype_str[] = {
 	[filetype_bmp] = { "BMP image", "bmp" },
 	[filetype_png] = { "PNG image", "png" },
 	[filetype_ext] = { "ext filesystem", "ext" },
+	[filetype_gpt] = { "GUID Partition Table", "gpt" },
 };
 
 const char *file_type_to_string(enum filetype f)
@@ -69,9 +70,52 @@ const char *file_type_to_short_string(enum filetype f)
 #define MBR_StartSector		8	/* MBR: Offset of Starting Sector in Partition Table Entry */
 #define BS_55AA			510	/* Boot sector signature (2) */
 #define MBR_Table		446	/* MBR: Partition table offset (2) */
+#define MBR_partition_size	16	/* MBR: Partition table offset (2) */
 #define BS_FilSysType32		82	/* File system type (1) */
 #define BS_FilSysType		54	/* File system type (1) */
 
+#define MBR_PART_sys_ind	4
+#define MBR_PART_start_sect	8
+#define MBR_OSTYPE_EFI_GPT	0xee
+
+static inline int pmbr_part_valid(const uint8_t *buf)
+{
+	if (buf[MBR_PART_sys_ind] == MBR_OSTYPE_EFI_GPT &&
+		get_unaligned_le32(&buf[MBR_PART_start_sect]) == 1UL) {
+		return 1;
+	}
+
+	return 0;
+}
+

common/filetype.c const char *file_type_to_short_string(enum filetype f) · line 100

Quoted 10 lines
common/filetype.c +10 -0
+/**
+ * is_pmbr_valid(): test Protective MBR for validity
+ * @mbr: pointer to a legacy mbr structure
+ *
+ * Description: Returns 1 if PMBR is valid, 0 otherwise.
+ * Validity depends on two things:
+ *  1) MSDOS signature is in the last two bytes of the MBR
+ *  2) One partition of type 0xEE is found
+ */
+static int is_gpt_valid(const uint8_t *buf)

The function name doesn't match the description.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#5 lore raw

Re: [PATCH 2/5] filetype: add GPT support

Quoted 48 lines · Sascha Hauer
Quoted 47 lines · Jean-Christophe PLAGNIOL-VILLARD

GPT need to be check before MBR

---
 common/filetype.c  |   47 +++++++++++++++++++++++++++++++++++++++++++++++
 include/filetype.h |    1 +
 2 files changed, 48 insertions(+)
common/filetype.c +20 -0
index 22fc621..a685ea5 100644
@@ -48,6 +48,7 @@ static const struct filetype_str filetype_str[] = {
 	[filetype_bmp] = { "BMP image", "bmp" },
 	[filetype_png] = { "PNG image", "png" },
 	[filetype_ext] = { "ext filesystem", "ext" },
+	[filetype_gpt] = { "GUID Partition Table", "gpt" },
 };
 
 const char *file_type_to_string(enum filetype f)
@@ -69,9 +70,52 @@ const char *file_type_to_short_string(enum filetype f)
 #define MBR_StartSector		8	/* MBR: Offset of Starting Sector in Partition Table Entry */
 #define BS_55AA			510	/* Boot sector signature (2) */
 #define MBR_Table		446	/* MBR: Partition table offset (2) */
+#define MBR_partition_size	16	/* MBR: Partition table offset (2) */
 #define BS_FilSysType32		82	/* File system type (1) */
 #define BS_FilSysType		54	/* File system type (1) */
 
+#define MBR_PART_sys_ind	4
+#define MBR_PART_start_sect	8
+#define MBR_OSTYPE_EFI_GPT	0xee
+
+static inline int pmbr_part_valid(const uint8_t *buf)
+{
+	if (buf[MBR_PART_sys_ind] == MBR_OSTYPE_EFI_GPT &&
+		get_unaligned_le32(&buf[MBR_PART_start_sect]) == 1UL) {
+		return 1;
+	}
+
+	return 0;
+}
+
+/**
+ * is_pmbr_valid(): test Protective MBR for validity
+ * @mbr: pointer to a legacy mbr structure
+ *
Quoted 8 lines

common/filetype.c const char *file_type_to_short_string(enum filetype f) · line 100

Quoted 6 lines
common/filetype.c +6 -0
+ * Description: Returns 1 if PMBR is valid, 0 otherwise.
+ * Validity depends on two things:
+ *  1) MSDOS signature is in the last two bytes of the MBR
+ *  2) One partition of type 0xEE is found
+ */
+static int is_gpt_valid(const uint8_t *buf)

The function name doesn't match the description.

can you fix while applying?

Best Regards,
J.

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#6 lore raw

Re: [PATCH 2/5] filetype: add GPT support

Quoted 57 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 48 lines · Sascha Hauer
Quoted 47 lines · Jean-Christophe PLAGNIOL-VILLARD

GPT need to be check before MBR

---
 common/filetype.c  |   47 +++++++++++++++++++++++++++++++++++++++++++++++
 include/filetype.h |    1 +
 2 files changed, 48 insertions(+)
common/filetype.c +20 -0
index 22fc621..a685ea5 100644
@@ -48,6 +48,7 @@ static const struct filetype_str filetype_str[] = {
 	[filetype_bmp] = { "BMP image", "bmp" },
 	[filetype_png] = { "PNG image", "png" },
 	[filetype_ext] = { "ext filesystem", "ext" },
+	[filetype_gpt] = { "GUID Partition Table", "gpt" },
 };
 
 const char *file_type_to_string(enum filetype f)
@@ -69,9 +70,52 @@ const char *file_type_to_short_string(enum filetype f)
 #define MBR_StartSector		8	/* MBR: Offset of Starting Sector in Partition Table Entry */
 #define BS_55AA			510	/* Boot sector signature (2) */
 #define MBR_Table		446	/* MBR: Partition table offset (2) */
+#define MBR_partition_size	16	/* MBR: Partition table offset (2) */
 #define BS_FilSysType32		82	/* File system type (1) */
 #define BS_FilSysType		54	/* File system type (1) */
 
+#define MBR_PART_sys_ind	4
+#define MBR_PART_start_sect	8
+#define MBR_OSTYPE_EFI_GPT	0xee
+
+static inline int pmbr_part_valid(const uint8_t *buf)
+{
+	if (buf[MBR_PART_sys_ind] == MBR_OSTYPE_EFI_GPT &&
+		get_unaligned_le32(&buf[MBR_PART_start_sect]) == 1UL) {
+		return 1;
+	}
+
+	return 0;
+}
+
+/**
+ * is_pmbr_valid(): test Protective MBR for validity
+ * @mbr: pointer to a legacy mbr structure
+ *
Quoted 8 lines

common/filetype.c const char *file_type_to_short_string(enum filetype f) · line 100

Quoted 6 lines
common/filetype.c +6 -0
+ * Description: Returns 1 if PMBR is valid, 0 otherwise.
+ * Validity depends on two things:
+ *  1) MSDOS signature is in the last two bytes of the MBR
+ *  2) One partition of type 0xEE is found
+ */
+static int is_gpt_valid(const uint8_t *buf)

The function name doesn't match the description.

Quoted 1 line

can you fix while applying?

Nope, because I don't know whether the description or the implementation matches what you intend to do.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#7 lore raw

PATCH 3/5 partitons: add framework

In reply to Jean-Christophe PLAGNIOL-VILLARD

so we can support multiple format

use filetpye to detect the parser to use

---
 common/Kconfig             |   14 +----
 common/Makefile            |    2 +-
 common/partitions.c        |  129 +++++++++++++++-----------------------------
 common/partitions/Kconfig  |   13 +++++
 common/partitions/Makefile |    1 +
 common/partitions/dos.c    |   88 ++++++++++++++++++++++++++++++
 common/partitions/parser.h |   35 ++++++++++++
 7 files changed, 182 insertions(+), 100 deletions(-)
 create mode 100644 common/partitions/Kconfig
 create mode 100644 common/partitions/Makefile
 create mode 100644 common/partitions/dos.c
 create mode 100644 common/partitions/parser.h
common/Kconfig +1 -13
index 3f6c11e..3a55e01 100644
@@ -478,19 +478,7 @@ config PARTITION
 	bool
 	prompt "Enable Partitions"
 
-config PARTITION_DISK
-	depends on PARTITION
-	bool "DISK partition support"
-	help
-	  Add support for handling common partition tables on all kind of disk
-	  like devices (harddisks, CF cards, SD cards and so on)
-
-config PARTITION_DISK_DOS
-	depends on PARTITION_DISK
-	default y
-	bool "DOS partition support"
-	help
-	  Add support to handle partitions in DOS style.
+source common/partitions/Kconfig
 
 config DEFAULT_ENVIRONMENT
 	bool
common/Makefile +1 -1
index 7206eed..b264cb8 100644
@@ -7,7 +7,7 @@ obj-$(CONFIG_ENV_HANDLING)	+= environment.o
 obj-$(CONFIG_AUTO_COMPLETE)	+= complete.o
 obj-$(CONFIG_POLLER)		+= poller.o
 obj-$(CONFIG_BLOCK)		+= block.o
-obj-$(CONFIG_PARTITION_DISK)	+= partitions.o
+obj-$(CONFIG_PARTITION_DISK)	+= partitions.o partitions/
 
 obj-$(CONFIG_CMD_LOADS)		+= s_record.o
 obj-$(CONFIG_OFTREE)		+= oftree.o
common/partitions.c +43 -86

156 lines not on this page · raw message

common/partitions/Kconfig new file +13 -0
new file mode 100644
index 0000000..3f81c2f
@@ -0,0 +1,13 @@
+config PARTITION_DISK
+	depends on PARTITION
+	bool "DISK partition support"
+	help
+	  Add support for handling common partition tables on all kind of disk
+	  like devices (harddisks, CF cards, SD cards and so on)
+
+config PARTITION_DISK_DOS
+	depends on PARTITION_DISK
+	default y
+	bool "DOS partition support"
+	help
+	  Add support to handle partitions in DOS style.
common/partitions/Makefile new file +1 -0
new file mode 100644
index 0000000..0a5c70d
@@ -0,0 +1 @@
+obj-$(CONFIG_PARTITION_DISK_DOS)	+= dos.o
common/partitions/dos.c new file +88 -0

88 lines not on this page · raw message

common/partitions/parser.h new file +35 -0
new file mode 100644
index 0000000..13506c0
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2013 Jean-Christophe PLAGNIOL-VILLARD <[email protected]>
+ *
+ * Under GPLv2 only
+ */
+
+#ifndef __PARTITIONS_PARSER_H__
+#define __PARTITIONS_PARSER_H__
+
+#include <block.h>
+#include <filetype.h>
+#include <linux/list.h>
+
+#define MAX_PARTITION		8
+
+struct partition {
+	uint64_t first_sec;
+	uint64_t size;
+};
+
+struct partition_desc {
+	int used_entries;
+	struct partition parts[MAX_PARTITION];
+};
+
+struct partition_parser {
+	void (*parse)(void *buf, struct block_device *blk, struct partition_desc *pd);
+	enum filetype type;
+
+	struct list_head list;
+};
+
+int partition_parser_register(struct partition_parser *p);
+
+#endif /* __PARTITIONS_PARSER_H__ */
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#8 lore raw

PATCH 4/5 disk: introduce partition name

In reply to Jean-Christophe PLAGNIOL-VILLARD

so we can register partion with name as present in EFI GPT

---
 common/partitions.c        |   54 ++++++++++++++++++++++++++++++++++----------
 common/partitions/parser.h |    2 ++
 2 files changed, 44 insertions(+), 12 deletions(-)
common/partitions.c +42 -12
index 9ab06d3..86b0f66 100644
@@ -44,15 +44,43 @@ LIST_HEAD(partition_parser_list);
 static int register_one_partition(struct block_device *blk,
 					struct partition *part, int no)
 {
-	char partition_name[19];
+	char *partition_name;
+	int ret;
+	uint64_t start = part->first_sec * SECTOR_SIZE;
+	uint64_t size = part->size * SECTOR_SIZE;
+
+	partition_name = asprintf("%s.%d", blk->cdev.name, no);
+	if (!partition_name)
+		return -ENOMEM;
+	dev_dbg(blk->dev, "Registering partition %s on drive %s\n",
+				partition_name, blk->cdev.name);
+	ret = devfs_add_partition(blk->cdev.name,
+				start, size, 0, partition_name);
+	if (ret)
+		goto out;
+
+	free(partition_name);
+
+	if (!part->name[0])
+		return 0;
+
+	partition_name = asprintf("%s.%s", blk->cdev.name, part->name);
+	if (!partition_name)
+		return -ENOMEM;
 
-	sprintf(partition_name, "%s.%d", blk->cdev.name, no);
 	dev_dbg(blk->dev, "Registering partition %s on drive %s\n",
 				partition_name, blk->cdev.name);
-	return devfs_add_partition(blk->cdev.name,
-				part->first_sec * SECTOR_SIZE,
-				part->size * SECTOR_SIZE,
-				0, partition_name);
+	ret = devfs_add_partition(blk->cdev.name,
+				start, size, 0, partition_name);
+
+	if (ret)
+		dev_warn(blk->dev, "Registering partition %s on drive %s failled\n",
+				partition_name, blk->cdev.name);
+
+	ret = 0;
+out:
+	free(partition_name);
+	return 0;
 }
 
 static struct partition_parser *partition_parser_get_by_filetype(uint8_t *buf)
@@ -79,12 +107,13 @@ static struct partition_parser *partition_parser_get_by_filetype(uint8_t *buf)
  */
 int parse_partition_table(struct block_device *blk)
 {
-	struct partition_desc pdesc = { .used_entries = 0, };
+	struct partition_desc *pdesc;
 	int i;
 	int rc = 0;
 	struct partition_parser *parser;
 	uint8_t *buf;
 
+	pdesc = xzalloc(sizeof(*pdesc));
 	buf = dma_alloc(SECTOR_SIZE * 2);
 
 	rc = blk->ops->read(blk, buf, 0, 2);
@@ -97,14 +126,14 @@ int parse_partition_table(struct block_device *blk)
 	if (!parser)
 		goto on_error;
 
-	parser->parse(buf, blk, &pdesc);
+	parser->parse(buf, blk, pdesc);
 
-	if (!pdesc.used_entries)
-		return 0;
+	if (!pdesc->used_entries)
+		goto on_error;
 
 	/* at least one partition description found */
-	for (i = 0; i < pdesc.used_entries; i++) {
-		rc = register_one_partition(blk, &pdesc.parts[i], i);
+	for (i = 0; i < pdesc->used_entries; i++) {
+		rc = register_one_partition(blk, &pdesc->parts[i], i);
 		if (rc != 0)
 			dev_err(blk->dev,
 				"Failed to register partition %d on %s (%d)\n",
@@ -115,6 +144,7 @@ int parse_partition_table(struct block_device *blk)
 
 on_error:
 	dma_free(buf);
+	free(pdesc);
 	return rc;
 }
 
common/partitions/parser.h +2 -0
index 13506c0..f5bdbd1 100644
@@ -12,8 +12,10 @@
 #include <linux/list.h>
 
 #define MAX_PARTITION		8
+#define MAX_PARTITION_NAME	38
 
 struct partition {
+	char name[MAX_PARTITION_NAME];
 	uint64_t first_sec;
 	uint64_t size;
 };
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#9 lore raw

PATCH 5/5 disk: partitions: add EFI GUID Partition Table

In reply to Jean-Christophe PLAGNIOL-VILLARD

form linux 3.8

so you can have part by num or name
not by GUID as this is a non human reading name

     `---- ffe08000.sata
          `---- 0x00000000-0x3fffffff: /dev/ata0
          `---- 0x00100000-0x063fffff: /dev/ata0.0
          `---- 0x00100000-0x063fffff: /dev/ata0.boot
          `---- 0x06400000-0x3fefffff: /dev/ata0.1
          `---- 0x06400000-0x3fefffff: /dev/ata0.linux
---
 common/partitions/Kconfig  |   19 ++
 common/partitions/Makefile |    1 +
 common/partitions/efi.c    |  477 ++++++++++++++++++++++++++++++++++++++
 common/partitions/efi.h    |  123 ++++++++++
 include/linux/efi.h        |  547 ++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 1167 insertions(+)
 create mode 100644 common/partitions/efi.c
 create mode 100644 common/partitions/efi.h
 create mode 100644 include/linux/efi.h
common/partitions/Kconfig +19 -0
index 3f81c2f..ca4452b 100644
@@ -11,3 +11,22 @@ config PARTITION_DISK_DOS
 	bool "DOS partition support"
 	help
 	  Add support to handle partitions in DOS style.
+
+config PARTITION_DISK_EFI
+	depends on PARTITION_DISK
+	default y
+	bool "EFI: GPT partition support"
+	help
+	  Add support to handle partitions in GUID Partition Table style.
+
+config PARTITION_DISK_EFI_GPT_NO_FORCE
+	depends on PARTITION_DISK_EFI
+	default y
+	bool "EFI: GPT: force test Protective MBR for validity"
+	help
+	  This will be added to the EFI Spec. per Intel after v1.02
+
+config PARTITION_DISK_EFI_GPT_COMPARE
+	depends on PARTITION_DISK_EFI
+	default y
+	bool "EFI: GPT: compare primary and Alternate GPT header for validity"
common/partitions/Makefile +1 -0
index 0a5c70d..2b0c5b4 100644
@@ -1 +1,2 @@
 obj-$(CONFIG_PARTITION_DISK_DOS)	+= dos.o
+obj-$(CONFIG_PARTITION_DISK_EFI)	+= efi.o
common/partitions/efi.c new file +477 -0

477 lines not on this page · raw message

common/partitions/efi.h new file +123 -0

123 lines not on this page · raw message

include/linux/efi.h new file +547 -0

547 lines not on this page · raw message

Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox