disk: part_efi: range-check partition number
PATCH v2 1/4 disk: part_efi: range-check partition number
From: Stephen Warren <[email protected]>
Enhance get_partition_info_efi() to range-check the partition number. This prevents invalid partitions being accessed, and prevents access beyond the end of the gpt_pte[] array.
---
v2: New patch
--- disk/part_efi.c | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)
disk/part_efi.c +7 -0
@@ -173,6 +173,13 @@ int get_partition_info_efi(block_dev_desc_t * dev_desc, int part,return -1 ; } +if (part >le32_to_int (gpt_head->num_partition_entries) || + !is_pte_valid (&gpt_pte[part -1 ])) { +printf ("%s: *** ERROR: Invalid partition number %d ***\n" , + __func__, part); +return -1 ; + } +/* The ulong casting limits the maximum disk size to 2 TB */ info->start = (ulong )le64_to_int (gpt_pte[part -1 ].starting_lba);/* The ending LBA is inclusive, to calculate size, add 1 to it */
Signature · 1 line
1.7.0.4
PATCH v2 2/4 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.
---
v2: Add #ifdef CONFIG_PARTITION_UUIDS around all new code and struct fields.
--- disk/part.c | 5 +++++ disk/part_efi.c | 25 +++++++++++++++++++++++++ include/part.h | 3 +++ 3 files changed, 33 insertions(+), 0 deletions(-)
disk/part.c +5 -0
@@ -294,6 +294,11 @@ 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) { +#ifdef CONFIG_PARTITION_UUIDS +/* The common case is no UUID support */ + info->uuid[0 ] =0 ; +#endif +switch (dev_desc->part_type) {#ifdef CONFIG_MAC_PARTITION case PART_TYPE_MAC :
disk/part_efi.c +25 -0
@@ -154,6 +154,28 @@ void print_part_efi(block_dev_desc_t * dev_desc)return ; } +#ifdef CONFIG_PARTITION_UUIDS +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 ; + } + } +} +#endif +int get_partition_info_efi (block_dev_desc_t * dev_desc,int part,disk_partition_t * info) {
@@ -190,6 +212,9 @@ 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" ); +#ifdef CONFIG_PARTITION_UUIDS +uuid_string (gpt_pte[part -1 ].unique_partition_guid.b, info->uuid); +#endif debug ("%s: start 0x%lX, size 0x%lX, name %s" , __func__, info->start, info->size, info->name);
include/part.h +3 -0
@@ -93,6 +93,9 @@ typedef struct disk_partition {ulong blksz;/* block size in bytes */ uchar name[32 ];/* partition name */ uchar type[32 ];/* string type description */ +#ifdef CONFIG_PARTITION_UUIDS +char uuid[37 ];/* filesystem UUID as string, if exists */ +#endif } disk_partition_t;/* Misc _get_dev functions */
Signature · 1 line
1.7.0.4
PATCH v2 2/4 disk: part_efi: parse and store partition UUID
Quoted 7 lines · Stephen Warren
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.
Don't say "stolen", say borrowed and cite a release and file path. Thanks!
Signature · 1 line
Tom
PATCH v2 3/4 disk: part_msdos: parse and store partition UUID
In reply to Stephen WarrenFrom: Stephen Warren <[email protected]>
The MSDOS/MBR partition table includes a 32-bit unique ID, often referred to as the NT disk signature. When combined with a partition number within the table, this can form a unique ID similar in concept to EFI/GPT's partition UUID.
This patch generates UUIDs in the format 0002dd75-01, which matches the format expected by the Linux kernel.
---
v2: New patch.
--- disk/part_dos.c | 15 ++++++++++++--- disk/part_dos.h | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-)
disk/part_dos.c +12 -3
@@ -163,7 +163,8 @@ static void print_partition_extended (block_dev_desc_t *dev_desc, int ext_part_s*/ static int get_partition_info_extended (block_dev_desc_t *dev_desc,int ext_part_sector,int relative,int part_num, -int which_part,disk_partition_t *info) +int which_part,disk_partition_t *info, +unsigned int disksig) { ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, dev_desc->blksz);dos_partition_t *pt;
@@ -182,6 +183,11 @@ static int get_partition_info_extended (block_dev_desc_t *dev_desc, int ext_partreturn -1 ; } +#ifdef CONFIG_PARTITION_UUIDS +if (!ext_part_sector) + disksig =le32_to_int (&buffer[DOS_PART_DISKSIG_OFFSET ]); +#endif +/* Print all primary/logical partitions */ pt = (dos_partition_t *) (buffer +DOS_PART_TBL_OFFSET );for (i =0 ; i <4 ; i++, pt++) {
@@ -222,6 +228,9 @@ static int get_partition_info_extended (block_dev_desc_t *dev_desc, int ext_part }/* sprintf(info->type, "%d, pt->sys_ind); */ sprintf ((char *)info->type,"U-Boot" ); +#ifdef CONFIG_PARTITION_UUIDS +sprintf (info->uuid,"%08x-%02x" , disksig, part_num); +#endif return 0 ; }
@@ -240,7 +249,7 @@ static int get_partition_info_extended (block_dev_desc_t *dev_desc, int ext_partreturn get_partition_info_extended (dev_desc, lba_start, ext_part_sector ==0 ? lba_start : relative, - part_num, which_part, info); + part_num, which_part, info, disksig); } }return -1 ;
@@ -254,7 +263,7 @@ void print_part_dos (block_dev_desc_t *dev_desc)int get_partition_info_dos (block_dev_desc_t *dev_desc,int part,disk_partition_t * info) { -return get_partition_info_extended (dev_desc,0 ,0 ,1 , part, info); +return get_partition_info_extended (dev_desc,0 ,0 ,1 , part, info,0 ); }
disk/part_dos.h +1 -1
@@ -24,7 +24,7 @@#ifndef _DISK_PART_DOS_H#define _DISK_PART_DOS_H - +#define DOS_PART_DISKSIG_OFFSET 0x1b8#define DOS_PART_TBL_OFFSET 0x1be#define DOS_PART_MAGIC_OFFSET 0x1fe#define DOS_PBR_FSTYPE_OFFSET 0x36
Signature · 1 line
1.7.0.4
PATCH v2 4/4 cmd_part: add partition-related command
In reply to Stephen WarrenFrom: Stephen Warren <[email protected]>
This implements the following:
part uuid mmc 0:1
-> print partition UUID
part uuid mmc 0:1 uuid
-> set environment variable to partition 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.:
part uuid ${devtype} ${devnum}:${rootpart} uuid
setenv bootargs root=PARTUUID=${uuid} ...
It is expected that further part sub-commands will be added later, e.g. to find which partition on a disk is marked bootable, to write new partition tables to disk, etc.
---
v2: validate that CONFIG_PARTITION_UUID is defined when CONFIG_CMD_PART is
Note: If Rob Herring's proposed patch "disk/part: introduce get_device_and_partition" is applied, the body of do_partuuid() should be reworked to use Rob's new function get_device_and_partition().
--- common/Makefile | 1 + common/cmd_part.c | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+), 0 deletions(-) create mode 100644 common/cmd_part.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_PART) += cmd_part.o ifdef CONFIG_PCI COBJS-$(CONFIG_CMD_PCI) += cmd_pci.o endif
common/cmd_part.c new file +104 -0
104 lines not on this page · raw message
Signature · 1 line
1.7.0.4
PATCH v2 4/4 cmd_part: add partition-related command
Quoted 8 lines · Stephen Warren
From: Stephen Warren <[email protected]>
This implements the following:
part uuid mmc 0:1
-> print partition UUID
part uuid mmc 0:1 uuid
-> set environment variable to partition UUID
What's the reason to not always both print out and set the uuid env var?
Perhaps the env name should be partuuid or part_uuid as you could have uuid's for other purposes?
Quoted 11 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.:
part uuid ${devtype} ${devnum}:${rootpart} uuid
setenv bootargs root=PARTUUID=${uuid} ...It is expected that further part sub-commands will be added later, e.g. to find which partition on a disk is marked bootable, to write new partition tables to disk, etc.
A list command would be useful and would be better located here than under scsi or other interface commands. Perhaps instead of printing a single part uuid, you should make a list command that prints all partitions and their UUIDs. That would address my first question.
Rob
Quoted 137 lines
Signed-off-by Stephen Warren <[email protected]>---
v2: validate thatCONFIG_PARTITION_UUIDis defined whenCONFIG_CMD_PARTisNote: If Rob Herring's proposed patch "disk/part: introduce
get_device_and_partition" is applied, the body ofdo_partuuid()should be reworked to use Rob's new functionget_device_and_partition().--- common/Makefile | 1 + common/cmd_part.c | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+), 0 deletions(-) create mode 100644 common/cmd_part.ccommon/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_PART) += cmd_part.o ifdef CONFIG_PCI COBJS-$(CONFIG_CMD_PCI) += cmd_pci.o endifcommon/cmd_part.c new file +104
-0@@ -0,0 +1,104 @@ +/* +* Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved. +* +* made from cmd_ext2, which was: +* +* (C) Copyright 2004 +* esd gmbh <www.esd-electronics.com> +* Reinhard Arlt <[email protected]> +* +* made from cmd_reiserfs by +* +* (C) Copyright 2003 - 2004 +* Sysgo Real-Time Solutions, AG <www.elinos.com> +* Pavel Bartusek <[email protected]> +* +* See file CREDITS for list of people who contributed to this +* project. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <common.h> +#include <config.h> +#include <command.h> +#include <part.h> +#include <vsprintf.h> + +#ifndef CONFIG_PARTITION_UUIDS +#error CONFIG_PARTITION_UUIDS must be enabled for CONFIG_CMD_PART to be enabled +#endif + +int do_partuuid (int argc,char *const argv[]) +{ +int dev; +int part; +char *ep; +block_dev_desc_t *dev_desc; +disk_partition_t info; + +if (argc <2 ) +return CMD_RET_USAGE ; +if (argc >3 ) +return CMD_RET_USAGE ; + + dev = (int )simple_strtoul (argv[1 ], &ep,16 ); + dev_desc =get_dev (argv[0 ], dev); +if (dev_desc ==NULL ) { +printf ("Block device %s %d not supported\n" , argv[0 ], dev); +return 1 ; + } + +if (*ep) { +if (*ep !=':' ) { +puts ("Invalid device; use dev[:part]\n" ); +return 1 ; + } + part = (int )simple_strtoul (++ep,NULL ,16 ); + }else { + part =1 ; + } + +if (get_partition_info (dev_desc, part, &info)) { +printf ("Bad partition %d\n" , part); +return 1 ; + } + +if (argc >2 ) +setenv (argv[2 ], info.uuid); +else +printf ("%s\n" , info.uuid); + +return 0 ; +} + +int do_part (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) +{ +if (argc <2 ) +return CMD_RET_USAGE ; + +if (!strcmp (argv[1 ],"uuid" )) +return do_partuuid (argc -2 , argv +2 ); + +return CMD_RET_USAGE ; +} + +U_BOOT_CMD ( + part,5 ,1 , do_part, +"disk partition related commands" , +"part uuid <interface> <dev[:part]>\n" +" - print partition UUID\n" +"part uuid <interface> <dev[:part]> <varname>\n" +" - set environment variable to partition UUID" +);
PATCH v2 4/4 cmd_part: add partition-related command
Quoted 23 lines · Rob Herring
Quoted 8 lines · Stephen Warren
From: Stephen Warren <[email protected]>
This implements the following:
part uuid mmc 0:1
-> print partition UUID
part uuid mmc 0:1 uuid
-> set environment variable to partition UUIDWhat's the reason to not always both print out and set the uuid env var?
Perhaps the env name should be partuuid or
part_uuidas you could have uuid's for other purposes?Quoted 8 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.:
part uuid ${devtype} ${devnum}:${rootpart} uuid
setenv bootargs root=PARTUUID=${uuid} ...
Quoted 8 lines
Quoted 3 lines
It is expected that further part sub-commands will be added later, e.g. to find which partition on a disk is marked bootable, to write new partition tables to disk, etc.
A list command would be useful and would be better located here than under scsi or other interface commands. Perhaps instead of printing a single part uuid, you should make a list command that prints all partitions and their UUIDs. That would address my first question.
Sounds like a good idea to me as well.
[snip]
Quoted 7 lines
Quoted 7 lines
Signed-off-by Stephen Warren <[email protected]>---
v2: validate thatCONFIG_PARTITION_UUIDis defined whenCONFIG_CMD_PARTisNote: If Rob Herring's proposed patch "disk/part: introduce
get_device_and_partition" is applied, the body ofdo_partuuid()should be reworked to use Rob's new functionget_device_and_partition().
I think the best idea here would be to make the next version just depend on Rob's series.
Signature · 1 line
Tom
PATCH v2 4/4 cmd_part: add partition-related command
Quoted 28 lines · Tom Rini
Quoted 27 lines · Rob Herring
Quoted 8 lines · Stephen Warren
From: Stephen Warren <[email protected]>
This implements the following:
part uuid mmc 0:1
-> print partition UUID
part uuid mmc 0:1 uuid
-> set environment variable to partition UUIDWhat's the reason to not always both print out and set the uuid env var?
Perhaps the env name should be partuuid or
part_uuidas you could have uuid's for other purposes?Quoted 11 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.:
part uuid ${devtype} ${devnum}:${rootpart} uuid
setenv bootargs root=PARTUUID=${uuid} ...It is expected that further part sub-commands will be added later, e.g. to find which partition on a disk is marked bootable, to write new partition tables to disk, etc.
Quoted 6 lines
Quoted 4 lines
A list command would be useful and would be better located here than under scsi or other interface commands. Perhaps instead of printing a single part uuid, you should make a list command that prints all partitions and their UUIDs. That would address my first question.
Sounds like a good idea to me as well.
In order to avoid too much feature creep in this patch-set, would it be OK to implement a "part list" command that simply calls print_part(), without changing what print_part() does right now, and then later send patches to enhance print_part() to print the various partition UUIDs and attributes?
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
v2: validate that
CONFIG_PARTITION_UUIDis defined whenCONFIG_CMD_PARTisNote: If Rob Herring's proposed patch "disk/part: introduce
get_device_and_partition" is applied, the body ofdo_partuuid()should be reworked to use Rob's new functionget_device_and_partition().I think the best idea here would be to make the next version just depend on Rob's series.
OK. Is it fairly certain that Rob's patches will be accepted then? There hasn't been much feedback on them...
Rob, it sounds like we agreed to change the default partition specification to use "auto" to mean "select a default partition". Were you going to repost for that, or do you want me to make the modifications?
Thanks.
PATCH v2 4/4 cmd_part: add partition-related command
In reply to Tom RiniQuoted 40 lines · Tom Rini
Quoted 23 lines · Rob Herring
Quoted 8 lines · Stephen Warren
From: Stephen Warren <[email protected]>
This implements the following:
part uuid mmc 0:1
-> print partition UUID
part uuid mmc 0:1 uuid
-> set environment variable to partition UUIDWhat's the reason to not always both print out and set the uuid env var?
Perhaps the env name should be partuuid or
part_uuidas you could have uuid's for other purposes?Quoted 8 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.:
part uuid ${devtype} ${devnum}:${rootpart} uuid
setenv bootargs root=PARTUUID=${uuid} ...Quoted 8 lines
Quoted 3 lines
It is expected that further part sub-commands will be added later, e.g. to find which partition on a disk is marked bootable, to write new partition tables to disk, etc.
A list command would be useful and would be better located here than under scsi or other interface commands. Perhaps instead of printing a single part uuid, you should make a list command that prints all partitions and their UUIDs. That would address my first question.
Sounds like a good idea to me as well.
[snip]
Quoted 4 lines
Quoted 4 lines
Signed-off-by Stephen Warren <[email protected]>---
v2: validate thatCONFIG_PARTITION_UUIDis defined whenCONFIG_CMD_PARTis
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
Note: If Rob Herring's proposed patch "disk/part: introduce
get_device_and_partition" is applied, the body ofdo_partuuid()should be reworked to use Rob's new functionget_device_and_partition().I think the best idea here would be to make the next version just depend on Rob's series.
Tom,
Rob's series depends on Wolfgang(?)'s u-boot/ext4 branch at present. I'm not sure what the status of that branch is right now - is it something that's ready to be submitted, or is more work there needed, so the branch won't be pulled into u-boot/master in the near future? I'm mainly asking so Rob and I know if Rob's patches should be rebased first onto something else, before I rebase my patches on his.
Thanks.
PATCH v2 4/4 cmd_part: add partition-related command
Hi Stephen, Tom,
Quoted 8 lines
Rob's series depends on Wolfgang(?)'s u-boot/ext4 branch at present. I'm not sure what the status of that branch is right now - is it something that's ready to be submitted, or is more work there needed, so the branch won't be pulled into u-boot/master in the near future? I'm mainly asking so Rob and I know if Rob's patches should be rebased first onto something else, before I rebase my patches on his.
Thanks.
I'd also like to know if those patches will be accepted soon. I'm working on a GPT restoration support and those patches might be a pre-requisite for my development (if were pulled into u-boot/master).
Signature · 5 lines
Best regards, Lukasz Majewski Samsung Poland R&D Center | Linux Platform Group
PATCH v2 4/4 cmd_part: add partition-related command
Quoted 10 lines · Lukasz Majewski
Hi Stephen, Tom,
Quoted 7 lines
Rob's series depends on Wolfgang(?)'s u-boot/ext4 branch at present. I'm not sure what the status of that branch is right now - is it something that's ready to be submitted, or is more work there needed, so the branch won't be pulled into u-boot/master in the near future? I'm mainly asking so Rob and I know if Rob's patches should be rebased first onto something else, before I rebase my patches on his.
Quoted 5 lines
Quoted 1 line
Thanks.
I'd also like to know if those patches will be accepted soon. I'm working on a GPT restoration support and those patches might be a pre-requisite for my development (if were pulled into u-boot/master).
In short, yes, merged to master. In longer form, please see the other email I just sent in this thread.
Signature · 1 line
Tom
PATCH v2 4/4 cmd_part: add partition-related command
In reply to Stephen WarrenQuoted 48 lines · Stephen Warren
Quoted 40 lines · Tom Rini
Quoted 23 lines · Rob Herring
Quoted 8 lines · Stephen Warren
From: Stephen Warren <[email protected]>
This implements the following:
part uuid mmc 0:1
-> print partition UUID
part uuid mmc 0:1 uuid
-> set environment variable to partition UUIDWhat's the reason to not always both print out and set the uuid env var?
Perhaps the env name should be partuuid or
part_uuidas you could have uuid's for other purposes?Quoted 8 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.:
part uuid ${devtype} ${devnum}:${rootpart} uuid
setenv bootargs root=PARTUUID=${uuid} ...Quoted 8 lines
Quoted 3 lines
It is expected that further part sub-commands will be added later, e.g. to find which partition on a disk is marked bootable, to write new partition tables to disk, etc.
A list command would be useful and would be better located here than under scsi or other interface commands. Perhaps instead of printing a single part uuid, you should make a list command that prints all partitions and their UUIDs. That would address my first question.
Sounds like a good idea to me as well.
[snip]
Quoted 4 lines
Quoted 4 lines
Signed-off-by Stephen Warren <[email protected]>---
v2: validate thatCONFIG_PARTITION_UUIDis defined whenCONFIG_CMD_PARTisQuoted 6 lines
Quoted 3 lines
Quoted 3 lines
Note: If Rob Herring's proposed patch "disk/part: introduce
get_device_and_partition" is applied, the body ofdo_partuuid()should be reworked to use Rob's new functionget_device_and_partition().I think the best idea here would be to make the next version just depend on Rob's series.
Quoted 8 lines
Tom,
Rob's series depends on Wolfgang(?)'s u-boot/ext4 branch at present. I'm not sure what the status of that branch is right now - is it something that's ready to be submitted, or is more work there needed, so the branch won't be pulled into u-boot/master in the near future? I'm mainly asking so Rob and I know if Rob's patches should be rebased first onto something else, before I rebase my patches on his.
So, I want the ext4 work to make it into the next release. At this point I am aware there is an issue with large volumes but I need to research a little more and make sure it's localized to ext4 only. If so, my feeling is that it's good enough to start with and then yes, it will get merged to master, around -rc1 time.
Signature · 1 line
Tom
PATCH v2 4/4 cmd_part: add partition-related command
In reply to Rob HerringQuoted 10 lines · Rob Herring
Quoted 8 lines · Stephen Warren
From: Stephen Warren <[email protected]>
This implements the following:
part uuid mmc 0:1
-> print partition UUID
part uuid mmc 0:1 uuid
-> set environment variable to partition UUID
Quoted 4 lines
What's the reason to not always both print out and set the uuid env var?
Perhaps the env name should be partuuid or
part_uuidas you could have uuid's for other purposes?
The idea is that if you're running the command interactively, you won't pass a variable name on the command-line, so the command will print out the UUID for you to read. In this case, it's pointless to set any environment variable.
However, if you're writing a script, you want to capture the UUID into an environment variable, and it's quite unlikely you want to litter stdout with that content too. Hence, either-or, not both.
Note that in the second command above, the final parameter "uuid" is the environment variable name, so you can save as many UUIDs for different partitions into whatever variables you want; IIRC in the scripts I wrote to use this, I did name the variable root_uuid or somesuch.
Quoted 7 lines
Quoted 7 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.:
part uuid ${devtype} ${devnum}:${rootpart} uuid
setenv bootargs root=PARTUUID=${uuid} ...
Quoted 8 lines
Quoted 3 lines
It is expected that further part sub-commands will be added later, e.g. to find which partition on a disk is marked bootable, to write new partition tables to disk, etc.
A list command would be useful and would be better located here than under scsi or other interface commands. Perhaps instead of printing a single part uuid, you should make a list command that prints all partitions and their UUIDs. That would address my first question.
Yes, I wondered about "part list mmc 0", which would do essentially the same thing as e.g. "mmc dev 0; mmc part", and also expanding the partition printing functions to dump extra information, such as GPT's partition type UUID, partition UUID, and attributes.
PATCH v2 4/4 cmd_part: add partition-related command
Quoted 16 lines · Stephen Warren
Quoted 10 lines · Rob Herring
Quoted 8 lines · Stephen Warren
From: Stephen Warren <[email protected]>
This implements the following:
part uuid mmc 0:1
-> print partition UUID
part uuid mmc 0:1 uuid
-> set environment variable to partition UUIDQuoted 4 lines
What's the reason to not always both print out and set the uuid env var?
Perhaps the env name should be partuuid or
part_uuidas you could have uuid's for other purposes?
Quoted 8 lines
The idea is that if you're running the command interactively, you won't pass a variable name on the command-line, so the command will print out the UUID for you to read. In this case, it's pointless to set any environment variable.
However, if you're writing a script, you want to capture the UUID into an environment variable, and it's quite unlikely you want to litter stdout with that content too. Hence, either-or, not both.
Do other commands have a "I'm being scripted, probably, don't stdout" and "I'm being interactive, use stdout" distinction like this? IMHO, always printing out makes sense so you can "see" that your script is working as you expect.
Signature · 1 line
Tom
PATCH v2 4/4 cmd_part: add partition-related command
Quoted 22 lines · Tom Rini
Quoted 21 lines · Stephen Warren
Quoted 10 lines · Rob Herring
Quoted 8 lines · Stephen Warren
From: Stephen Warren <[email protected]>
This implements the following:
part uuid mmc 0:1
-> print partition UUID
part uuid mmc 0:1 uuid
-> set environment variable to partition UUIDQuoted 4 lines
What's the reason to not always both print out and set the uuid env var?
Perhaps the env name should be partuuid or
part_uuidas you could have uuid's for other purposes?The idea is that if you're running the command interactively, you won't pass a variable name on the command-line, so the command will print out the UUID for you to read. In this case, it's pointless to set any environment variable.
Quoted 8 lines
Quoted 3 lines
However, if you're writing a script, you want to capture the UUID into an environment variable, and it's quite unlikely you want to litter stdout with that content too. Hence, either-or, not both.
Do other commands have a "I'm being scripted, probably, don't stdout" and "I'm being interactive, use stdout" distinction like this? IMHO, always printing out makes sense so you can "see" that your script is working as you expect.
In general, as a script writer, yes you do have the ability to choose. Typically, I'd write:
part uuid ....
vs.
var=part uuid ....
in order to control this. However, U-Boot's shell doesn't support backticks. As a script writer, I certainly desire the ability to control what commands spam to the console, and really don't think it's useful to print the UUID from a script (does the user really care, and any script developer can just echo it for debugging if they need it).
I'm not aware of other U-Boot commands whose purpose it is to set environment variables, so can't really compare.
Still, if you're insistent on this point, I can change the code to always print, and optionally write an environment variable.
PATCH v2 4/4 cmd_part: add partition-related command
Quoted 47 lines · Stephen Warren
Quoted 22 lines · Tom Rini
Quoted 21 lines · Stephen Warren
Quoted 10 lines · Rob Herring
Quoted 8 lines · Stephen Warren
From: Stephen Warren <[email protected]>
This implements the following:
part uuid mmc 0:1
-> print partition UUID
part uuid mmc 0:1 uuid
-> set environment variable to partition UUIDQuoted 4 lines
What's the reason to not always both print out and set the uuid env var?
Perhaps the env name should be partuuid or
part_uuidas you could have uuid's for other purposes?The idea is that if you're running the command interactively, you won't pass a variable name on the command-line, so the command will print out the UUID for you to read. In this case, it's pointless to set any environment variable.
Quoted 8 lines
Quoted 3 lines
However, if you're writing a script, you want to capture the UUID into an environment variable, and it's quite unlikely you want to litter stdout with that content too. Hence, either-or, not both.
Do other commands have a "I'm being scripted, probably, don't stdout" and "I'm being interactive, use stdout" distinction like this? IMHO, always printing out makes sense so you can "see" that your script is working as you expect.
In general, as a script writer, yes you do have the ability to choose. Typically, I'd write:
part uuid ....
vs.
var=
part uuid ....in order to control this. However, U-Boot's shell doesn't support backticks. As a script writer, I certainly desire the ability to control what commands spam to the console, and really don't think it's useful to print the UUID from a script (does the user really care, and any script developer can just echo it for debugging if they need it).
Quoted 5 lines
I'm not aware of other U-Boot commands whose purpose it is to set environment variables, so can't really compare.
Still, if you're insistent on this point, I can change the code to always print, and optionally write an environment variable.
No, you make a good point. Thanks!
Signature · 1 line
Tom