Skip to contentSkip to conversation

add EFI GUID Partition Table support

PATCH In review Jean-Christophe PLAGNIOL-VILLARD 3 participants 17 messages Feb 14, 2013 – Feb 15, 2013 EFI

lore
Share & tools
lore
#0 lore raw

cover add EFI GUID Partition Table support

HI,

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 af822258f8dd08f8d8aab9e5e70e84033028b26d:

disk: partitions: add EFI GUID Partition Table (2013-02-13 22:49:30 +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          |    4 ++
 common/partitions.c        |  181 ++++++++++++++++++++++++++++++++++++++------------------------------------------
 common/partitions/Makefile |    2 +
 common/partitions/dos.c    |   87 +++++++++++++++++++++++++++++++++++++++
 common/partitions/efi.c    |  508 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 common/partitions/efi.h    |  123 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 common/partitions/parser.h |   37 +++++++++++++++++
 include/filetype.h         |    1 +
 include/linux/efi.h        |  547 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/types.h      |   13 ++++++
 12 files changed, 1409 insertions(+), 110 deletions(-)
 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  |    4 ++++
 include/filetype.h |    1 +
 2 files changed, 5 insertions(+)
common/filetype.c +4 -0
index 22fc621..6563ecc 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)
@@ -159,6 +160,9 @@ enum filetype file_detect_type(const void *_buf, size_t bufsize)
 	if (bufsize < 512)
 		return filetype_unknown;
 
+	if (bufsize >= 520 && strncmp(&buf8[512], "EFI PART", 8) == 0)
+		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 22 lines · Jean-Christophe PLAGNIOL-VILLARD

GPT need to be check before MBR

---
 common/filetype.c  |    4 ++++
 include/filetype.h |    1 +
 2 files changed, 5 insertions(+)
common/filetype.c +1 -0
index 22fc621..6563ecc 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)

common/filetype.c enum filetype file_detect_type(const void *_buf, size_t bufsize) · line 165

Quoted 6 lines
common/filetype.c +3 -0
@@ -159,6 +160,9 @@ enum filetype file_detect_type(const void *_buf, size_t bufsize)
 	if (bufsize < 512)
 		return filetype_unknown;
 
+	if (bufsize >= 520 && strncmp(&buf8[512], "EFI PART", 8) == 0)
+		return filetype_gpt;
+

The list is sorted by size, so please move this below:

	if (bufsize < 1536)
		return filetype_unknown;

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
#4 lore raw

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

Quoted 26 lines · Sascha Hauer
Quoted 25 lines · Jean-Christophe PLAGNIOL-VILLARD

GPT need to be check before MBR

---
 common/filetype.c  |    4 ++++
 include/filetype.h |    1 +
 2 files changed, 5 insertions(+)
common/filetype.c +1 -0
index 22fc621..6563ecc 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)
@@ -159,6 +160,9 @@ enum filetype file_detect_type(const void *_buf, size_t bufsize)
 	if (bufsize < 512)
 		return filetype_unknown;
 
Quoted 5 lines

common/filetype.c enum filetype file_detect_type(const void *_buf, size_t bufsize) · line 165

Quoted 3 lines
common/filetype.c +3 -0
+	if (bufsize >= 520 && strncmp(&buf8[512], "EFI PART", 8) == 0)
+		return filetype_gpt;
+

The list is sorted by size, so please move this below:

on purpose

EFI need to be detect before mbr

Best Regards,
J.

Quoted 12 lines
	if (bufsize < 1536)
		return filetype_unknown;

Sascha

Signature · 4 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 27 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 26 lines · Sascha Hauer
Quoted 25 lines · Jean-Christophe PLAGNIOL-VILLARD

GPT need to be check before MBR

---
 common/filetype.c  |    4 ++++
 include/filetype.h |    1 +
 2 files changed, 5 insertions(+)
common/filetype.c +1 -0
index 22fc621..6563ecc 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)
@@ -159,6 +160,9 @@ enum filetype file_detect_type(const void *_buf, size_t bufsize)
 	if (bufsize < 512)
 		return filetype_unknown;
 
Quoted 8 lines
Quoted 5 lines

common/filetype.c enum filetype file_detect_type(const void *_buf, size_t bufsize) · line 165

Quoted 3 lines
common/filetype.c +3 -0
+	if (bufsize >= 520 && strncmp(&buf8[512], "EFI PART", 8) == 0)
+		return filetype_gpt;
+

The list is sorted by size, so please move this below:

on purpose

EFI need to be detect before mbr

IMHO the check is too simple, it will give false positive if GPT is replaced by DOS MBR and not zeroed out. Need to check for protective MBR.

Johannes

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

#6 lore raw

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

Quoted 33 lines · Johannes Stezenbach
Quoted 32 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 31 lines · Sascha Hauer
Quoted 22 lines · Jean-Christophe PLAGNIOL-VILLARD

GPT need to be check before MBR

---
 common/filetype.c  |    4 ++++
 include/filetype.h |    1 +
 2 files changed, 5 insertions(+)
common/filetype.c +1 -0
index 22fc621..6563ecc 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)

common/filetype.c enum filetype file_detect_type(const void *_buf, size_t bufsize) · line 165

Quoted 6 lines
common/filetype.c +3 -0
@@ -159,6 +160,9 @@ enum filetype file_detect_type(const void *_buf, size_t bufsize)
 	if (bufsize < 512)
 		return filetype_unknown;
 
+	if (bufsize >= 520 && strncmp(&buf8[512], "EFI PART", 8) == 0)
+		return filetype_gpt;
+

The list is sorted by size, so please move this below:

Quoted 7 lines
Quoted 3 lines

on purpose

EFI need to be detect before mbr

IMHO the check is too simple, it will give false positive if GPT is replaced by DOS MBR and not zeroed out. Need to check for protective MBR.

So is_fat_or_mbr() should test if the MBR is a protective MBR and return false in this case?

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

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

Quoted 36 lines · Sascha Hauer
Quoted 35 lines · Johannes Stezenbach
Quoted 34 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 26 lines · Sascha Hauer
Quoted 25 lines · Jean-Christophe PLAGNIOL-VILLARD

GPT need to be check before MBR

---
 common/filetype.c  |    4 ++++
 include/filetype.h |    1 +
 2 files changed, 5 insertions(+)
common/filetype.c +1 -0
index 22fc621..6563ecc 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)
@@ -159,6 +160,9 @@ enum filetype file_detect_type(const void *_buf, size_t bufsize)
 	if (bufsize < 512)
 		return filetype_unknown;
 
Quoted 5 lines

common/filetype.c enum filetype file_detect_type(const void *_buf, size_t bufsize) · line 165

Quoted 3 lines
common/filetype.c +3 -0
+	if (bufsize >= 520 && strncmp(&buf8[512], "EFI PART", 8) == 0)
+		return filetype_gpt;
+

The list is sorted by size, so please move this below:

on purpose

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

EFI need to be detect before mbr

IMHO the check is too simple, it will give false positive if GPT is replaced by DOS MBR and not zeroed out. Need to check for protective MBR.

So is_fat_or_mbr() should test if the MBR is a protective MBR and return false in this case?

no as the efi is more I do the check in efi.c protective bit and right type

I move the code to filetype

but efi need to be before MBR as you could have both for retro compatibility

Nest Regards,
J.

Quoted 8 lines

Sascha

Signature · 4 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

#8 lore raw

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

Quoted 6 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 5 lines · Sascha Hauer
Quoted 4 lines · Johannes Stezenbach
Quoted 3 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 2 lines · Sascha Hauer
Quoted 1 line · Jean-Christophe PLAGNIOL-VILLARD

GPT need to be check before MBR

...

Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 8 lines
Quoted 5 lines

common/filetype.c enum filetype file_detect_type(const void *_buf, size_t bufsize) · line 165

Quoted 3 lines
common/filetype.c +3 -0
+	if (bufsize >= 520 && strncmp(&buf8[512], "EFI PART", 8) == 0)
+		return filetype_gpt;
+

The list is sorted by size, so please move this below:

on purpose

EFI need to be detect before mbr

IMHO the check is too simple, it will give false positive if GPT is replaced by DOS MBR and not zeroed out. Need to check for protective MBR.

Quoted 8 lines
Quoted 2 lines

So is_fat_or_mbr() should test if the MBR is a protective MBR and return false in this case?

no as the efi is more I do the check in efi.c protective bit and right type

I move the code to filetype

but efi need to be before MBR as you could have both for retro compatibility

Yes, Wikipedia says Apple Bootcamp creates hybrid MBR. But if you run fdisk to create DOS MBR it will only replace the first sector and leave the GPT alone. Thus I think for usability it is important to check MBR (for 0xAA55 marker and one of the part types must be 0xee).

Johannes

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

#9 lore raw

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

Quoted 28 lines · Johannes Stezenbach
Quoted 6 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 5 lines · Sascha Hauer
Quoted 4 lines · Johannes Stezenbach
Quoted 3 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 2 lines · Sascha Hauer
Quoted 1 line · Jean-Christophe PLAGNIOL-VILLARD

GPT need to be check before MBR

...

Quoted 20 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+	if (bufsize >= 520 && strncmp(&buf8[512], "EFI PART", 8) == 0)
+		return filetype_gpt;
+

The list is sorted by size, so please move this below:

on purpose

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

EFI need to be detect before mbr

IMHO the check is too simple, it will give false positive if GPT is replaced by DOS MBR and not zeroed out. Need to check for protective MBR.

So is_fat_or_mbr() should test if the MBR is a protective MBR and return false in this case?

no as the efi is more I do the check in efi.c protective bit and right type

I move the code to filetype

Quoted 7 lines
Quoted 1 line

but efi need to be before MBR as you could have both for retro compatibility

Yes, Wikipedia says Apple Bootcamp creates hybrid MBR. But if you run fdisk to create DOS MBR it will only replace the first sector and leave the GPT alone. Thus I think for usability it is important to check MBR (for 0xAA55 marker and one of the part types must be 0xee).

Do not take Wikipedia for the bible

We implemenb the EFI spec

Best Regards,
J.

Quoted 2 lines

Johannes

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

#10 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        |  132 +++++++++++++++-----------------------------
 common/partitions/Makefile |    1 +
 common/partitions/dos.c    |   87 +++++++++++++++++++++++++++++
 common/partitions/parser.h |   35 ++++++++++++
 6 files changed, 171 insertions(+), 100 deletions(-)
 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 +46 -86

159 lines not on this page · raw message

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 +87 -0

87 lines not on this page · raw message

common/partitions/parser.h new file +35 -0
new file mode 100644
index 0000000..61b1cf5
@@ -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)(uint8_t *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
#11 lore raw

Re: [PATCH 3/5] partitons: add framework

Quoted 6 lines · Jean-Christophe PLAGNIOL-VILLARD

so we can support multiple format

use filetpye to detect the parser to use

Quoted 7 lines
---
 common/Kconfig             |   14 +----
 common/Makefile            |    2 +-
 common/partitions.c        |  132 +++++++++++++++-----------------------------
 common/partitions/Makefile |    1 +
 common/partitions/dos.c    |   87 +++++++++++++++++++++++++++++
 common/partitions/parser.h |   35 ++++++++++++

common/partitions/Kconfig is missing in this patch.

common/partitions.c int parse_partition_table(struct block_device *blk) · line 124

Quoted 4 lines
common/partitions.c +4 -0
+int partition_parser_register(struct partition_parser *p)
+{
+	if (!p || !p->parse)
+		return -EINVAL;

Please drop these stupid checks. Everyone calling this with a NULL pointer really deserves a stack dump.

Quoted 12 lines
common/partitions/parser.h new file +12 -0
+
+#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;

common/partitions/parser.h line 27

Quoted 10 lines
common/partitions/parser.h new file +10 -0
+	uint64_t size;
+};
+
+struct partition_desc {
+	int used_entries;
+	struct partition parts[MAX_PARTITION];
+};
+
+struct partition_parser {
+	void (*parse)(uint8_t *buf, struct block_device *blk, struct partition_desc *pd);

use void * for passing buffers please.

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
#12 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        |   51 ++++++++++++++++++++++++++++++++++----------
 common/partitions/parser.h |    2 ++
 2 files changed, 42 insertions(+), 11 deletions(-)
common/partitions.c +40 -11
index 7cb8399..51a0fc2 100644
@@ -44,15 +44,42 @@ 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);
+	partition_name = asprintf("%s.%s", blk->cdev.name, part->name);
+	if (!partition_name) {
+		dev_warn(blk->dev, "Registering partition %s on drive %s failled\n",
+				part->name, blk->cdev.name);
+		return 0;
+	}
 
-	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 +106,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 +125,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)
+	if (!pdesc->used_entries)
 		return 0;
 
 	/* 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 +143,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 61b1cf5..083c143 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
#13 lore raw

Re: [PATCH 4/5] disk: introduce partition name

Quoted 28 lines · Jean-Christophe PLAGNIOL-VILLARD

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

---
 common/partitions.c        |   51 ++++++++++++++++++++++++++++++++++----------
 common/partitions/parser.h |    2 ++
 2 files changed, 42 insertions(+), 11 deletions(-)
common/partitions.c +10 -1
index 7cb8399..51a0fc2 100644
@@ -44,15 +44,42 @@ 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);

common/partitions.c LIST_HEAD(partition_parser_list); · line 66

Quoted 10 lines
common/partitions.c +10 -0
+	ret = devfs_add_partition(blk->cdev.name,
+				start, size, 0, partition_name);
+	if (ret)
+		goto out;
+
+	free(partition_name);
+	partition_name = asprintf("%s.%s", blk->cdev.name, part->name);
+	if (!partition_name) {
+		dev_warn(blk->dev, "Registering partition %s on drive %s failled\n",
+				part->name, blk->cdev.name);

You are in -ENOMEM here, not in partitiion register fai*l*ed.

Quoted 25 lines
common/partitions.c +13 -5
+		return 0;
+	}
 
-	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)

common/partitions.c static struct partition_parser *partition_parser_get_by_filetype(uint8_t *buf) · line 107

Quoted 2 lines
common/partitions.c +0 -0
@@ -79,12 +106,13 @@ static struct partition_parser *partition_parser_get_by_filetype(uint8_t *buf)
  */
 int parse_partition_table(struct block_device *blk)

The changes to this function seem unrelated to the topic of this patch.

Quoted 13 lines
common/partitions.c +2 -1
 {
-	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);

common/partitions.c int parse_partition_table(struct block_device *blk) · line 131

Quoted 9 lines
common/partitions.c +2 -2
@@ -97,14 +125,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)
+	if (!pdesc->used_entries)
 		return 0;

You lose memory here.

Quoted 22 lines
common/partitions.c +3 -2
 	/* 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 +143,7 @@ int parse_partition_table(struct block_device *blk)
 
 on_error:
 	dma_free(buf);
+	free(pdesc);
 	return rc;
 }
 
common/partitions/parser.h +0 -0
index 61b1cf5..083c143 100644

common/partitions/parser.h line 18

Quoted 7 lines
common/partitions/parser.h +2 -0
@@ -12,8 +12,10 @@
 #include <linux/list.h>
 
 #define MAX_PARTITION		8
+#define MAX_PARTITION_NAME	38
 
 struct partition {
+	char name[MAX_PARTITION_NAME];

is this used?

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
#14 lore raw

Re: [PATCH 4/5] disk: introduce partition name

Quoted 121 lines · Sascha Hauer
Quoted 28 lines · Jean-Christophe PLAGNIOL-VILLARD

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

---
 common/partitions.c        |   51 ++++++++++++++++++++++++++++++++++----------
 common/partitions/parser.h |    2 ++
 2 files changed, 42 insertions(+), 11 deletions(-)
common/partitions.c +10 -1
index 7cb8399..51a0fc2 100644
@@ -44,15 +44,42 @@ 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);

common/partitions.c LIST_HEAD(partition_parser_list); · line 66

Quoted 10 lines
common/partitions.c +10 -0
+	ret = devfs_add_partition(blk->cdev.name,
+				start, size, 0, partition_name);
+	if (ret)
+		goto out;
+
+	free(partition_name);
+	partition_name = asprintf("%s.%s", blk->cdev.name, part->name);
+	if (!partition_name) {
+		dev_warn(blk->dev, "Registering partition %s on drive %s failled\n",
+				part->name, blk->cdev.name);

You are in -ENOMEM here, not in partitiion register fai*l*ed.

Quoted 25 lines
common/partitions.c +13 -5
+		return 0;
+	}
 
-	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)

common/partitions.c static struct partition_parser *partition_parser_get_by_filetype(uint8_t *buf) · line 107

Quoted 2 lines
common/partitions.c +0 -0
@@ -79,12 +106,13 @@ static struct partition_parser *partition_parser_get_by_filetype(uint8_t *buf)
  */
 int parse_partition_table(struct block_device *blk)

The changes to this function seem unrelated to the topic of this patch.

Quoted 13 lines
common/partitions.c +2 -1
 {
-	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);

common/partitions.c int parse_partition_table(struct block_device *blk) · line 131

Quoted 9 lines
common/partitions.c +2 -2
@@ -97,14 +125,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)
+	if (!pdesc->used_entries)
 		return 0;

You lose memory here.

Quoted 24 lines
common/partitions.c +3 -2
 	/* 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 +143,7 @@ int parse_partition_table(struct block_device *blk)
 
 on_error:
 	dma_free(buf);
+	free(pdesc);
 	return rc;
 }
 
common/partitions/parser.h +0 -0
index 61b1cf5..083c143 100644
@@ -12,8 +12,10 @@
 #include <linux/list.h>
 
Quoted 7 lines

common/partitions/parser.h line 18

Quoted 5 lines
common/partitions/parser.h +2 -0
 #define MAX_PARTITION		8
+#define MAX_PARTITION_NAME	38
 
 struct partition {
+	char name[MAX_PARTITION_NAME];

is this used?

yes by efi

in GPT you have a partname so you will have this

     `---- 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.root

so you do not care where is the boot partition just that the partition exist

and just mount root as rootfs

Best Regards,
J.

Quoted 8 lines

Sascha

Signature · 4 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

#15 lore raw

Re: [PATCH 4/5] disk: introduce partition name

Quoted 122 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 121 lines · Sascha Hauer
Quoted 28 lines · Jean-Christophe PLAGNIOL-VILLARD

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

---
 common/partitions.c        |   51 ++++++++++++++++++++++++++++++++++----------
 common/partitions/parser.h |    2 ++
 2 files changed, 42 insertions(+), 11 deletions(-)
common/partitions.c +10 -1
index 7cb8399..51a0fc2 100644
@@ -44,15 +44,42 @@ 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);

common/partitions.c LIST_HEAD(partition_parser_list); · line 66

Quoted 10 lines
common/partitions.c +10 -0
+	ret = devfs_add_partition(blk->cdev.name,
+				start, size, 0, partition_name);
+	if (ret)
+		goto out;
+
+	free(partition_name);
+	partition_name = asprintf("%s.%s", blk->cdev.name, part->name);
+	if (!partition_name) {
+		dev_warn(blk->dev, "Registering partition %s on drive %s failled\n",
+				part->name, blk->cdev.name);

You are in -ENOMEM here, not in partitiion register fai*l*ed.

Quoted 25 lines
common/partitions.c +13 -5
+		return 0;
+	}
 
-	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)

common/partitions.c static struct partition_parser *partition_parser_get_by_filetype(uint8_t *buf) · line 107

Quoted 2 lines
common/partitions.c +0 -0
@@ -79,12 +106,13 @@ static struct partition_parser *partition_parser_get_by_filetype(uint8_t *buf)
  */
 int parse_partition_table(struct block_device *blk)

The changes to this function seem unrelated to the topic of this patch.

Quoted 13 lines
common/partitions.c +2 -1
 {
-	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);

common/partitions.c int parse_partition_table(struct block_device *blk) · line 131

Quoted 9 lines
common/partitions.c +2 -2
@@ -97,14 +125,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)
+	if (!pdesc->used_entries)
 		return 0;

You lose memory here.

Quoted 24 lines
common/partitions.c +3 -2
 	/* 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 +143,7 @@ int parse_partition_table(struct block_device *blk)
 
 on_error:
 	dma_free(buf);
+	free(pdesc);
 	return rc;
 }
 
common/partitions/parser.h +0 -0
index 61b1cf5..083c143 100644
@@ -12,8 +12,10 @@
 #include <linux/list.h>
 
Quoted 9 lines
Quoted 7 lines

common/partitions/parser.h line 18

Quoted 5 lines
common/partitions/parser.h +2 -0
 #define MAX_PARTITION		8
+#define MAX_PARTITION_NAME	38
 
 struct partition {
+	char name[MAX_PARTITION_NAME];

is this used?

yes by efi

Ok, I see. It's not used by DOS partitions though and never check for part->name being valid, so for DOS partitions you end up trying to register multiple partitions with:

	asprintf("%s.%s", blk->cdev.name, "");

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
#16 lore raw

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

In reply to Jean-Christophe PLAGNIOL-VILLARD

form linux 3.8

---
 common/partitions/Makefile |    1 +
 common/partitions/efi.c    |  508 ++++++++++++++++++++++++++++++++++++++++
 common/partitions/efi.h    |  123 ++++++++++
 include/linux/efi.h        |  547 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 1179 insertions(+)
 create mode 100644 common/partitions/efi.c
 create mode 100644 common/partitions/efi.h
 create mode 100644 include/linux/efi.h
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 +508 -0

508 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