add EFI GUID Partition Table support
v3 cover add EFI GUID Partition Table support
HI,
v3:
fix function name
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 c572474854bf97ea8c91ea3602950bd352d9a3b4:
disk: partitions: add EFI GUID Partition Table (2013-02-14 18:50:16 +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 | 187 +++++++++++++++++++++++++++++++++++++++++------------------------------------------ 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, 1462 insertions(+), 108 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
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
PATCH v3 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
@@ -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
PATCH v3 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
@@ -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_gpt_valid(): test Protective MBR for validity and EFI PART +* @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
@@ -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
Re: [PATCH 2/5] filetype: add GPT support
Quoted 41 lines · Jean-Christophe PLAGNIOL-VILLARD
GPT need to be check before MBR
Cc Rob Herring <[email protected]>Signed-off-by Jean-Christophe PLAGNIOL-VILLARD <[email protected]>--- common/filetype.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ include/filetype.h | 1 + 2 files changed, 48 insertions(+)common/filetype.c +14
-0@@ -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 98
Quoted 10 lines
common/filetype.c +10
-0+} + +/** +* is_gpt_valid(): test Protective MBR for validity and EFI PART +* @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
Still wrong. This describes is_pmbr_valid, but the function is named and implements is_gpt_valid. I suggest implemting a real is_pmbr_valid function and call it from is_gpt_valid which additionally checks for the gpt header.
Sascha
Quoted 54 lines
common/filetype.c +23
-0+*/ +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@@ -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
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
Re: [PATCH 2/5] filetype: add GPT support
Quoted 49 lines · Sascha Hauer
Quoted 48 lines · Jean-Christophe PLAGNIOL-VILLARD
GPT need to be check before MBR
Cc Rob Herring <[email protected]>Signed-off-by Jean-Christophe PLAGNIOL-VILLARD <[email protected]>--- common/filetype.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ include/filetype.h | 1 + 2 files changed, 48 insertions(+)common/filetype.c +21
-0@@ -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_gpt_valid(): test Protective MBR for validity and EFI PART +* @mbr: pointer to a legacy mbr structure +* +* Description: Returns 1 if PMBR is valid, 0 otherwise.
Quoted 8 lines
common/filetype.c const char *file_type_to_short_string(enum filetype f) · line 98
Quoted 3 lines
common/filetype.c +3
-0+* 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 Still wrong. This describes
is_pmbr_valid, but the function is named and implementsis_gpt_valid. I suggest implemting a realis_pmbr_validfunction and call it fromis_gpt_validwhich additionally checks for the gpt header.
we test both pmr and EFI PART fo this is right
test Protective MBR for validity and EFI PART
so the comment is correct
Best Regards,
J.
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 2/5] filetype: add GPT support
Quoted 59 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 49 lines · Sascha Hauer
Quoted 48 lines · Jean-Christophe PLAGNIOL-VILLARD
GPT need to be check before MBR
Cc Rob Herring <[email protected]>Signed-off-by Jean-Christophe PLAGNIOL-VILLARD <[email protected]>--- common/filetype.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ include/filetype.h | 1 + 2 files changed, 48 insertions(+)common/filetype.c +21
-0@@ -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_gpt_valid(): test Protective MBR for validity and EFI PART +* @mbr: pointer to a legacy mbr structure +* +* Description: Returns 1 if PMBR is valid, 0 otherwise. Quoted 8 lines
common/filetype.c const char *file_type_to_short_string(enum filetype f) · line 98
Quoted 3 lines
common/filetype.c +3
-0+* 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 Still wrong. This describes
is_pmbr_valid, but the function is named and implementsis_gpt_valid. I suggest implemting a realis_pmbr_validfunction and call it fromis_gpt_validwhich additionally checks for the gpt header.
Quoted 5 lines
we test both pmr and EFI PART fo this is right
test Protective MBR for validity and EFI PART
so the comment is correct
The comment says: "Returns 1 if PMBR is valid, 0 otherwise", but the function implements "Returns 1 if PBMR is valid *and* an EFI header is found, 0 otherwise"
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
PATCH v3 3/5 partitons: add framework
In reply to Jean-Christophe PLAGNIOL-VILLARDso we can support multiple format
use filetpye to detect the parser to use
--- common/Kconfig | 14 +---- common/Makefile | 2 +- common/partitions.c | 141 +++++++++++++++++--------------------------- common/partitions/Kconfig | 13 ++++ common/partitions/Makefile | 1 + common/partitions/dos.c | 88 +++++++++++++++++++++++++++ common/partitions/parser.h | 35 +++++++++++ 7 files changed, 194 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
@@ -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
@@ -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 +55 -86
168 lines not on this page · raw message
common/partitions/Kconfig new file +13 -0
@@ -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
@@ -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
@@ -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
Re: [PATCH 3/5] partitons: add framework
common/partitions.c line 35
Quoted 6 lines · Jean-Christophe PLAGNIOL-VILLARD
common/partitions.c +2
-3+#include "partitions/parser.h" -on_error: -dma_free (buffer); -} +LIST_HEAD (partition_parser_list);
static
Quoted 13 lines
/**
* Register one partition on the given block devicecommon/partitions.c +6
-0@@ -135,6 +55,33 @@ static int register_one_partition(struct block_device *blk, 0, partition_name); } +static struct partition_parser *partition_parser_get_by_filetype (uint8_t *buf) +{ +enum filetype type; +struct partition_parser *parser; + +/* first new partition table as EFI GPT */
common/partitions.c static int register_one_partition(struct block_device *blk, · line 73
Quoted 10 lines
common/partitions.c +10
-0+ type =file_detect_type (buf,SECTOR_SIZE *2 ); + +list_for_each_entry (parser, &partition_parser_list, list) { +if (parser->type == type) +return parser; + } + +/* if not parser found search for old one +* so if EFI GPT not enable take it as MBR +* usefull for compatibility
1 Cent for each time you write useful with double l...
common/partitions/dos.c line 82
Quoted 5 lines
common/partitions/dos.c new file +5
-0+ +struct partition_parser dos = { + .parse = dos_partition, + .type = filetype_mbr, +};
static
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
PATCH v3 4/5 disk: introduce partition name
In reply to Jean-Christophe PLAGNIOL-VILLARDso 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
@@ -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)
@@ -91,12 +119,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 );
@@ -109,14 +138,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",
@@ -127,6 +156,7 @@ int parse_partition_table(struct block_device *blk) on_error:dma_free (buf); +free (pdesc);return rc; }
common/partitions/parser.h +2 -0
@@ -12,8 +12,10 @@#include <linux/list.h> #define MAX_PARTITION 8 +#define MAX_PARTITION_NAME 38struct 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
Re: [PATCH 4/5] disk: introduce partition name
Quoted 27 lines · Jean-Christophe PLAGNIOL-VILLARD
so we can register partion with name as present in EFI GPT
Cc Rob Herring <[email protected]>Signed-off-by Jean-Christophe PLAGNIOL-VILLARD <[email protected]>--- common/partitions.c | 54 ++++++++++++++++++++++++++++++++++---------- common/partitions/parser.h | 2 ++ 2 files changed, 44 insertions(+), 12 deletions(-)common/partitions.c +9
-1@@ -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",
common/partitions.c LIST_HEAD(partition_parser_list); · line 65
Quoted 10 lines
common/partitions.c +10
-0+ 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 ;
So when a name is not given then you also don't register the partition with a number?
Quoted 8 lines
common/partitions.c +4
-1+ + 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);
common/partitions.c LIST_HEAD(partition_parser_list); · line 78
Quoted 10 lines
common/partitions.c +6
-4-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);
s/failled/failed/
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
Re: [PATCH 4/5] disk: introduce partition name
Quoted 33 lines · Sascha Hauer
Quoted 32 lines · Jean-Christophe PLAGNIOL-VILLARD
so we can register partion with name as present in EFI GPT
Cc Rob Herring <[email protected]>Signed-off-by Jean-Christophe PLAGNIOL-VILLARD <[email protected]>--- common/partitions.c | 54 ++++++++++++++++++++++++++++++++++---------- common/partitions/parser.h | 2 ++ 2 files changed, 44 insertions(+), 12 deletions(-)common/partitions.c +14
-1@@ -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;
Quoted 8 lines
common/partitions.c LIST_HEAD(partition_parser_list); · line 65
Quoted 5 lines
common/partitions.c +5
-0+ +free (partition_name); + +if (!part->name[0 ]) +return 0 ;So when a name is not given then you also don't register the partition with a number?
we register with number first and only register with name if present
Best Regards,
J.
Quoted 22 lines
Quoted 9 lines
common/partitions.c +4
-1+ + 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);common/partitions.c LIST_HEAD(partition_parser_list); · line 78
Quoted 10 lines
common/partitions.c +6
-4-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);s/failled/failed/
Quoted 7 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
PATCH v3 5/5 disk: partitions: add EFI GUID Partition Table
In reply to Jean-Christophe PLAGNIOL-VILLARDform 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
@@ -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
@@ -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
Re: [PATCH 5/5] disk: partitions: add EFI GUID Partition Table
common/partitions/efi.c line 471
Quoted 7 lines · Jean-Christophe PLAGNIOL-VILLARD
form linux 3.8
common/partitions/efi.c new file +5
-0+ +struct partition_parser efi_partition_parser = { + .parse = efi_partition, + .type = filetype_gpt, +};
static
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