cmd: gpt: Add option to write GPT partitions to environment variable
PATCH v2 1/1 cmd: gpt: Add option to write GPT partitions to environment variable
This change would enhance the existing 'gpt read' command to allow (optionally) writing of the read GPT partitions to an environment variable in the UBOOT partitions layout format. This would allow users to easily change the overall partition settings by editing said variable and then using the variable in the 'gpt write' and 'gpt verify' commands.
---
Changes for v2:
- Checked for argv[4] existence before calling do_get_gpt_info
- Added missing update to doc/README.gpt
--- cmd/gpt.c | 46 ++++++++++++++++++++++++++++++++++++++-------- doc/README.gpt | 17 +++++++++++++++++ 2 files changed, 55 insertions(+), 8 deletions(-)
cmd/gpt.c +38 -8
@@ -350,17 +350,46 @@ static int get_gpt_info(struct blk_desc *dev_desc) }/* a wrapper to test get_gpt_info */ -static int do_get_gpt_info (struct blk_desc *dev_desc) +static int do_get_gpt_info (struct blk_desc *dev_desc,char *const namestr) { -int ret; +int numparts; + + numparts =get_gpt_info (dev_desc); + +if (numparts >0 ) { +if (namestr) { +char disk_guid[UUID_STR_LEN +1 ]; +char *partitions_list; +int partlistlen; +int ret =-1 ; + + ret =get_disk_guid (dev_desc, disk_guid); +if (ret <0 ) +return ret; + + partlistlen =calc_parts_list_len (numparts); + partitions_list =malloc (partlistlen); +if (!partitions_list) { +del_gpt_info (); +return -ENOMEM ; + } +memset (partitions_list,'\0' , partlistlen); + + ret =create_gpt_partitions_list (numparts, disk_guid, + partitions_list); +if (ret <0 ) +printf ("Error: Could not create partition list string!\n" ); +else +env_set (namestr, partitions_list); - ret =get_gpt_info (dev_desc); -if (ret >0 ) { -print_gpt_info (); +free (partitions_list); + }else { +print_gpt_info (); + }del_gpt_info ();return 0 ; } -return ret; +return numparts; }#endif
@@ -982,7 +1011,7 @@ static int do_gpt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) ret =do_disk_guid (blk_dev_desc, argv[4 ]); #ifdef CONFIG_CMD_GPT_RENAME }else if (strcmp (argv[1 ],"read" ) ==0 ) { - ret =do_get_gpt_info (blk_dev_desc); + ret =do_get_gpt_info (blk_dev_desc, (argc ==5 ) ? argv[4 ] :NULL ); }else if ((strcmp (argv[1 ],"swap" ) ==0 ) || (strcmp (argv[1 ],"rename" ) ==0 )) { ret =do_rename_gpt_parts (blk_dev_desc, argv[1 ], argv[4 ], argv[5 ]);
@@ -1028,8 +1057,9 @@ U_BOOT_CMD(gpt, CONFIG_SYS_MAXARGS, 1, do_gpt," gpt guid mmc 0 varname\n" #ifdef CONFIG_CMD_GPT_RENAME"gpt partition renaming commands:\n" -" gpt read <interface> <dev>\n" +" gpt read <interface> <dev> [<varname>]\n" " - read GPT into a data structure for manipulation\n" +" - read GPT partitions into environment variable\n" " gpt swap <interface> <dev> <name1> <name2>\n" " - change all partitions named name1 to name2\n" " and vice-versa\n"
doc/README.gpt +17 -0
@@ -237,6 +237,23 @@ doc/arch/index.rst: => gpt swap host 0 name othername [ . . . ] +Modifying GPT partition layout from U-Boot: +=========================================== + +The entire GPT partition layout can be exported to an environment +variable and then modified enmasse. Users can change the partition +numbers, offsets, names and sizes. The resulting variable can used to +reformat the device. Here is an example of reading the GPT partitions +into a variable and then modifying them: + +U-BOOT> gpt read mmc 0 current_partitions +U-BOOT> env edit current_partitions +edit: uuid_disk=[...];name=part1,start=0x4000,size=0x4000,uuid=[...]; +name=part2,start=0xc000,size=0xc000,uuid=[...];[ . . . ] + +U-BOOT> gpt write mmc 0 $current_partitions +U-BOOT> gpt verify mmc 0 $current_partitions + Partition type GUID: ====================
Signature · 1 line
1.8.3.1
PATCH v2 1/1 cmd: gpt: Add option to write GPT partitions to environment variable
Quoted 14 lines · Farhan Ali
This change would enhance the existing 'gpt read' command to allow (optionally) writing of the read GPT partitions to an environment variable in the UBOOT partitions layout format. This would allow users to easily change the overall partition settings by editing said variable and then using the variable in the 'gpt write' and 'gpt verify' commands.
Signed-off-by Farhan Ali <[email protected]>Cc Simon Glass <[email protected]>Cc Heinrich Schuchardt <[email protected]>Cc Corneliu Doban <[email protected]>Cc Rayagonda Kokatanur <[email protected]>Cc Rasmus Villemoes <[email protected]>
Quoted 9 lines
---
Changes for v2:
- Checked for argv[4] existence before callingdo_get_gpt_info
- Added missing update to doc/README.gpt--- cmd/gpt.c | 46 ++++++++++++++++++++++++++++++++++++++-------- doc/README.gpt | 17 +++++++++++++++++ 2 files changed, 55 insertions(+), 8 deletions(-)
A message that is not in the archive (sent off-list or not yet received): CAF=haa6sBNPbAdUq4H9RM9m7gSqr-WrJx-fpszJhu0mpGsMiFg@mail.gmail.com
PATCH v2 1/1 cmd: gpt: Add option to write GPT partitions to environment variable
Quoted 3 lines · Farhan Ali
Hi Heinrich,
I was wondering if there are any other changes necessary?
Nothing on my side.
The patch was reviewed by Simon and now is is assigned to Tom.
https://patchwork.ozlabs.org/project/uboot/patch/20210226181733.19307-1-farhan.ali at broadcom.com/
He should be able to tell you why it wasn't merged yet.
Best regards
Heinrich
Quoted 42 lines
Thanks
Farhan
On Thu, Mar 4, 2021 at 8:08 PM Simon Glass <[email protected] <mailto:[email protected]>> wrote:
On Fri, 26 Feb 2021 at 13:17, Farhan Ali <[email protected] <mailto:[email protected]>> wrote:
>
> This change would enhance the existing 'gpt read' command to allow > (optionally) writing of the read GPT partitions to an environment > variable in the UBOOT partitions layout format. This would allow users > to easily change the overall partition settings by editing said variable
> and then using the variable in the 'gpt write' and 'gpt verify' commands.
>
> Signed-off-by: Farhan Ali <[email protected] <mailto:[email protected]>>
> Cc: Simon Glass <sjg at chromium.org <mailto:[email protected]>> > Cc: Heinrich Schuchardt <[email protected] <mailto:[email protected]>>
> Cc: Corneliu Doban <cdoban at broadcom.com <mailto:[email protected]>> > Cc: Rayagonda Kokatanur <[email protected] <mailto:[email protected]>>
> Cc: Rasmus Villemoes <[email protected] <mailto:[email protected]>>
>
> ---
> Changes for v2:
>? ? - Checked for argv[4] existence before callingdo_get_gpt_info>? ? - Added missing update to doc/README.gpt
> ---
>?cmd/gpt.c? ? ? | 46 ++++++++++++++++++++++++++++++++++++++-------- >? doc/README.gpt | 17 +++++++++++++++++
>? 2 files changed, 55 insertions(+), 8 deletions(-)
>Reviewed-by Simon Glass <sjg at chromium.org <mailto:[email protected]>>
PATCH v2 1/1 cmd: gpt: Add option to write GPT partitions to environment variable
In reply to Farhan AliQuoted 6 lines · Farhan Ali
This change would enhance the existing 'gpt read' command to allow (optionally) writing of the read GPT partitions to an environment variable in the UBOOT partitions layout format. This would allow users to easily change the overall partition settings by editing said variable and then using the variable in the 'gpt write' and 'gpt verify' commands.
Quoted 7 lines
Signed-off-by Farhan Ali <[email protected]>Cc Simon Glass <[email protected]>Cc Heinrich Schuchardt <[email protected]>Cc Corneliu Doban <[email protected]>Cc Rayagonda Kokatanur <[email protected]>Cc Rasmus Villemoes <[email protected]>Reviewed-by Simon Glass <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210506/e6ee7364/attachment.sig>