disk: part_efi: parse and store partition UUID
PATCH 1/3 disk: part_efi: parse and store partition UUID
From: Stephen Warren <[email protected]>
Each EFI partition table entry contains a UUID. Extend U-Boot's struct disk_partition to be able to store this information, and modify get_partition_info_efi() to fill it in.
The implementation of uuid_string() was stolen from the Linux kernel.
---
Note: I made this field part of struct disk_partition, and wrote a generic command to retrieve it, rather than adding an EFI-/GPT-specific command, since I imagine the kernel's PARTUUID support could be extended to support e.g. NT disk signatures, or other partition types, in the future.
disk/part.c | 3 +++ disk/part_efi.c | 21 +++++++++++++++++++++ include/part.h | 1 + 3 files changed, 25 insertions(+), 0 deletions(-)
disk/part.c +3 -0
@@ -294,6 +294,9 @@ void init_part (block_dev_desc_t * dev_desc)int get_partition_info (block_dev_desc_t *dev_desc,int part ,disk_partition_t *info) { +/* The common case is no UUID support */ + info->uuid[0 ] =0 ; +switch (dev_desc->part_type) {#ifdef CONFIG_MAC_PARTITION case PART_TYPE_MAC :
disk/part_efi.c +21 -0
@@ -154,6 +154,26 @@ void print_part_efi(block_dev_desc_t * dev_desc)return ; } +static void uuid_string (unsigned char *uuid,char *str) +{ +static const u8 le[16 ] = {3 ,2 ,1 ,0 ,5 ,4 ,7 ,6 ,8 ,9 ,10 ,11 , +12 ,13 ,14 ,15 }; +int i; + +for (i =0 ; i <16 ; i++) { +sprintf (str,"%02x" , uuid[le[i]]); + str +=2 ; +switch (i) { +case 3 : +case 5 : +case 7 : +case 9 : + *str++ ='-' ; +break ; + } + } +} +int get_partition_info_efi (block_dev_desc_t * dev_desc,int part,disk_partition_t * info) {
@@ -183,6 +203,7 @@ int get_partition_info_efi(block_dev_desc_t * dev_desc, int part,sprintf ((char *)info->name,"%s" ,print_efiname (&gpt_pte[part -1 ]));sprintf ((char *)info->type,"U-Boot" ); +uuid_string (gpt_pte[part -1 ].unique_partition_guid.b, info->uuid);debug ("%s: start 0x%lX, size 0x%lX, name %s" , __func__, info->start, info->size, info->name);
include/part.h +1 -0
@@ -93,6 +93,7 @@ typedef struct disk_partition {ulong blksz;/* block size in bytes */ uchar name[32 ];/* partition name */ uchar type[32 ];/* string type description */ +char uuid[37 ];/* filesystem UUID as string, if exists */ } disk_partition_t;/* Misc _get_dev functions */
Signature · 1 line
1.7.0.4
PATCH 2/3 cmd_partuuid: add command to retrieve a partition's UUID
From: Stephen Warren <[email protected]>
This implements the following:
partuuid mmc 0:1
-> prints the partition's UUID.
partuuic mmc 0:1 uuid
-> sets environment variable "uuid" to the partition's UUID.
This can be useful when writing a bootcmd which searches all known devices for something bootable, and then wants the kernel to use the same partition as the root device, e.g.:
partuuid ${devtype} ${devnum}:${rootpart} uuid
setenv bootargs root=PARTUUID=${uuid} ...
--- common/Makefile | 1 + common/cmd_partuuid.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 0 deletions(-) create mode 100644 common/cmd_partuuid.c
common/Makefile +1 -0
@@ -129,6 +129,7 @@ COBJS-$(CONFIG_CMD_NAND) += cmd_nand.o COBJS-$(CONFIG_CMD_NET) += cmd_net.o COBJS-$(CONFIG_CMD_ONENAND) += cmd_onenand.o COBJS-$(CONFIG_CMD_OTP) += cmd_otp.o +COBJS-$(CONFIG_CMD_PARTUUID) += cmd_partuuid.o ifdef CONFIG_PCI COBJS-$(CONFIG_CMD_PCI) += cmd_pci.o endif
common/cmd_partuuid.c new file +87 -0
87 lines not on this page · raw message
Signature · 1 line
1.7.0.4
PATCH 2/3 cmd_partuuid: add command to retrieve a partition's UUID
Quoted 7 lines · Stephen Warren
This implements the following:
partuuid mmc 0:1
-> prints the partition's UUID.
partuuic mmc 0:1 uuid
-> sets environment variable "uuid" to the partition's UUID.
Quoted 6 lines
This can be useful when writing a bootcmd which searches all known devices for something bootable, and then wants the kernel to use the same partition as the root device, e.g.:
partuuid ${devtype} ${devnum}:${rootpart} uuid
setenv bootargs root=PARTUUID=${uuid} ...
I guess one thing I might mention here:
I can imagine other partition-oriented commands existing, e.g. a command to find the bootable partition on a particular storage device. I'm not sure if we should create a single "part" command with various sub-options for this, e.g.:
part uuid mmc 0:1
part get-bootable mmc 0
or create separate commands:
partuuid mmc 0:1
part-get-bootable mmc 0
PATCH 2/3 cmd_partuuid: add command to retrieve a partition's UUID
Hi Stephen,
Quoted 17 lines · Stephen Warren
Quoted 7 lines
This implements the following:
partuuid mmc 0:1
-> prints the partition's UUID.
partuuic mmc 0:1 uuid
-> sets environment variable "uuid" to the partition's UUID.Quoted 6 lines
This can be useful when writing a bootcmd which searches all known devices for something bootable, and then wants the kernel to use the same partition as the root device, e.g.:
partuuid ${devtype} ${devnum}:${rootpart} uuid
setenv bootargs root=PARTUUID=${uuid} ...I guess one thing I might mention here:
Quoted 8 lines
I can imagine other partition-oriented commands existing, e.g. a command to find the bootable partition on a particular storage device. I'm not sure if we should create a single "part" command with various sub-options for this, e.g.:
part uuid mmc 0:1
part get-bootable mmc 0
I'm now working at restoring the GPT (GUID Partition Table) at MMC in u-boot.
I plan to implement a separate command - gptrestore However, I think that one single command would be more suitable for this purpose.
Quoted 4 lines
or create separate commands:
partuuid mmc 0:1
part-get-bootable mmc 0
Signature · 5 lines
Best regards, Lukasz Majewski Samsung Poland R&D Center | Linux Platform Group
PATCH 2/3 cmd_partuuid: add command to retrieve a partition's UUID
Quoted 27 lines · Lukasz Majewski
Hi Stephen,
Quoted 17 lines · Stephen Warren
Quoted 7 lines
This implements the following:
partuuid mmc 0:1
-> prints the partition's UUID.
partuuic mmc 0:1 uuid
-> sets environment variable "uuid" to the partition's UUID.Quoted 6 lines
This can be useful when writing a bootcmd which searches all known devices for something bootable, and then wants the kernel to use the same partition as the root device, e.g.:
partuuid ${devtype} ${devnum}:${rootpart} uuid
setenv bootargs root=PARTUUID=${uuid} ...I guess one thing I might mention here:
Quoted 7 lines
I can imagine other partition-oriented commands existing, e.g. a command to find the bootable partition on a particular storage device. I'm not sure if we should create a single "part" command with various sub-options for this, e.g.:
part uuid mmc 0:1
part get-bootable mmc 0
Quoted 6 lines
I'm now working at restoring the GPT (GUID Partition Table) at MMC in u-boot.
I plan to implement a separate command - gptrestore However, I think that one single command would be more suitable for this purpose.
What will gptrestore do?
PATCH 2/3 cmd_partuuid: add command to retrieve a partition's UUID
Quoted 28 lines · On Fri, 17 Aug 2012 09:08:16 -0600 Stephen Warren <[email protected]> wrote:
Quoted 27 lines · Lukasz Majewski
Hi Stephen,
Quoted 24 lines · Stephen Warren
Quoted 7 lines
This implements the following:
partuuid mmc 0:1
-> prints the partition's UUID.
partuuic mmc 0:1 uuid
-> sets environment variable "uuid" to the partition's UUID.Quoted 6 lines
This can be useful when writing a bootcmd which searches all known devices for something bootable, and then wants the kernel to use the same partition as the root device, e.g.:
partuuid ${devtype} ${devnum}:${rootpart} uuid
setenv bootargs root=PARTUUID=${uuid} ...I guess one thing I might mention here:
I can imagine other partition-oriented commands existing, e.g. a command to find the bootable partition on a particular storage device. I'm not sure if we should create a single "part" command with various sub-options for this, e.g.:
part uuid mmc 0:1
part get-bootable mmc 0
Quoted 9 lines
Quoted 6 lines
I'm now working at restoring the GPT (GUID Partition Table) at MMC in u-boot.
I plan to implement a separate command - gptrestore However, I think that one single command would be more suitable for this purpose.
What will gptrestore do?
It will write a GPT table on the eMMC memory.
Definitions for partitions are read from u-boot environment variable.
Signature · 5 lines
Best regards, Lukasz Majewski Samsung Poland R&D Center | Linux Platform Group
PATCH 3/3 tegra: enable CONFIG_CMD_PARTUUID
In reply to Stephen WarrenFrom: Stephen Warren <[email protected]>
This is extremely likely to be used from the boot.scr that Tegra's default bootcmd locates and executes.
--- include/configs/tegra20-common-post.h | 5 +++++ include/configs/tegra20-common.h | 1 + 2 files changed, 6 insertions(+), 0 deletions(-)
include/configs/tegra20-common-post.h +5 -0
@@ -209,6 +209,11 @@#undef CONFIG_CMD_USB#endif +/* remove partuuid command support */ +#ifdef CONFIG_CMD_PARTUUID +#undef CONFIG_CMD_PARTUUID +#endif +#endif /* CONFIG_SPL_BUILD */ #endif /* __TEGRA20_COMMON_POST_H */
include/configs/tegra20-common.h +1 -0
@@ -113,6 +113,7 @@/* include default commands */ #include <config_cmd_default.h> +#define CONFIG_CMD_PARTUUID /* remove unused commands */ #undef CONFIG_CMD_FLASH/* flinfo, erase, protect */
Signature · 1 line
1.7.0.4
PATCH 3/3 tegra: enable CONFIG_CMD_PARTUUID
Quoted 6 lines · Stephen Warren
From: Stephen Warren <[email protected]>
This is extremely likely to be used from the boot.scr that Tegra's default bootcmd locates and executes.
Signed-off-by Stephen Warren <[email protected]>
Quoted 40 lines
--- include/configs/tegra20-common-post.h | 5 +++++ include/configs/tegra20-common.h | 1 + 2 files changed, 6 insertions(+), 0 deletions(-)include/configs/tegra20-common-post.h +5
-0@@ -209,6 +209,11 @@#undef CONFIG_CMD_USB#endif +/* remove partuuid command support */ +#ifdef CONFIG_CMD_PARTUUID +#undef CONFIG_CMD_PARTUUID +#endif +#endif /* CONFIG_SPL_BUILD */ #endif /* __TEGRA20_COMMON_POST_H */ include/configs/tegra20-common.h +1
-1@@ -113,6 +113,7 @@/* include default commands */ #include <config_cmd_default.h> +#define CONFIG_CMD_PARTUUID /* remove unused commands */ #undef CONFIG_CMD_FLASH/* flinfo, erase, protect */ --1.7.0.4
_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot
PATCH 1/3 disk: part_efi: parse and store partition UUID
In reply to Stephen WarrenDear Stephen Warren,
Quoted 9 lines · In message <[email protected]> you wrote:
From: Stephen Warren <[email protected]>
Each EFI partition table entry contains a UUID. Extend U-Boot's struct
disk_partitionto be able to store this information, and modifyget_partition_info_efi()to fill it in.The implementation of
uuid_string()was stolen from the Linux kernel.Signed-off-by Stephen Warren <[email protected]>
Can we please make this addition dependent on EFI support being enabled? Otherwise the increased memory footprint will hit all users, even if they never use EFI at all.
Best regards,
Wolfgang Denk
Signature · 5 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de Committee, n.: A group of men who individually can do nothing but as a group decide that nothing can be done. - Fred Allen
PATCH 1/3 disk: part_efi: parse and store partition UUID
Quoted 9 lines · Wolfgang Denk
Dear Stephen Warren,
Quoted 6 lines · In message <[email protected]> you wrote:
From: Stephen Warren <[email protected]>
Each EFI partition table entry contains a UUID. Extend U-Boot's struct
disk_partitionto be able to store this information, and modifyget_partition_info_efi()to fill it in.
Quoted 7 lines
Quoted 3 lines
The implementation of
uuid_string()was stolen from the Linux kernel.Signed-off-by Stephen Warren <[email protected]>Can we please make this addition dependent on EFI support being enabled? Otherwise the increased memory footprint will hit all users, even if they never use EFI at all.
(I assume you're talking about the change to the partition info structure, since IIRC all the other code was already in either the EFI partition code already, or a new command under its own ifdef).
I'm also planning a patch that fills in this UUID field for MBR/DOS partition tables too. That'd require the ifdef to check 2 different config symbols, and perhaps more in the future. It seems a little messy to ifdef this just to save 4 bytes. Are you sure you want to do this?