public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Lukasz Majewski <lukma@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 3/6] GPT: add accessor function for disk GUID
Date: Wed, 31 May 2017 09:44:43 +0200	[thread overview]
Message-ID: <20170531094443.7a57e48d@jawa> (raw)
In-Reply-To: <1496076573-14495-4-git-send-email-alison@peloton-tech.com>

Hi Alison,

> From: Alison Chaiken <alison@she-devel.com>
> 
> In order to read the GPT, modify the partition name strings, and then
> write out a new GPT, the disk GUID is needed.  While there is an
> existing accessor for the partition UUIDs, there is none yet for the
> disk GUID.

Acked-by: Lukasz Majewski <lukma@denx.de>

> 
> Signed-off-by: Alison Chaiken <alison@peloton-tech.com>
> ---
>  cmd/gpt.c       | 30 +++++++++++++++++++++++++++++-
>  disk/part_efi.c | 31 +++++++++++++++++++++++++++++++
>  doc/README.gpt  |  3 ++-
>  include/part.h  | 15 +++++++++++++++
>  4 files changed, 77 insertions(+), 2 deletions(-)
> 
> diff --git a/cmd/gpt.c b/cmd/gpt.c
> index 3e98821..3b7d929 100644
> --- a/cmd/gpt.c
> +++ b/cmd/gpt.c
> @@ -398,6 +398,23 @@ static int gpt_verify(struct blk_desc
> *blk_dev_desc, const char *str_part) return ret;
>  }
>  
> +static int do_disk_guid(struct blk_desc *dev_desc, char * const
> namestr) +{
> +	int ret;
> +	char disk_guid[UUID_STR_LEN + 1];
> +
> +	ret = get_disk_guid(dev_desc, disk_guid);
> +	if (ret < 0)
> +		return 1;
> +
> +	if (namestr)
> +		setenv(namestr, disk_guid);
> +	else
> +		printf("%s\n", disk_guid);
> +
> +	return 0;
> +}
> +
>  /**
>   * do_gpt(): Perform GPT operations
>   *
> @@ -412,7 +429,7 @@ static int do_gpt(cmd_tbl_t *cmdtp, int flag, int
> argc, char * const argv[]) {
>  	int ret = CMD_RET_SUCCESS;
>  	int dev = 0;
> -	char *ep;
> +	char *ep, *varname = NULL;
>  	struct blk_desc *blk_dev_desc = NULL;
>  
>  	if (argc < 4 || argc > 5)
> @@ -436,6 +453,10 @@ static int do_gpt(cmd_tbl_t *cmdtp, int flag,
> int argc, char * const argv[]) } else if ((strcmp(argv[1], "verify")
> == 0)) { ret = gpt_verify(blk_dev_desc, argv[4]);
>  		printf("Verify GPT: ");
> +	} else if (strcmp(argv[1], "guid") == 0) {
> +		if (argc == 5)
> +		       strcpy(varname, argv[4]);
> +		return do_disk_guid(blk_dev_desc, varname);
>  	} else {
>  		return CMD_RET_USAGE;
>  	}
> @@ -458,4 +479,11 @@ U_BOOT_CMD(gpt, CONFIG_SYS_MAXARGS, 1, do_gpt,
>  	" Example usage:\n"
>  	" gpt write mmc 0 $partitions\n"
>  	" gpt verify mmc 0 $partitions\n"
> +	" guid <interface> <dev>\n"
> +	"    - print disk GUID\n"
> +	" guid <interface> <dev> <varname>\n"
> +	"    - set environment variable to disk GUID\n"
> +	" Example usage:\n"
> +	" gpt guid mmc 0\n"
> +	" gpt guid mmc 0 varname\n"
>  );
> diff --git a/disk/part_efi.c b/disk/part_efi.c
> index 20d33ef..ff9f408 100644
> --- a/disk/part_efi.c
> +++ b/disk/part_efi.c
> @@ -178,6 +178,37 @@ static void prepare_backup_gpt_header(gpt_header
> *gpt_h)
>   * Public Functions (include/part.h)
>   */
>  
> +/*
> + * UUID is displayed as 32 hexadecimal digits, in 5 groups,
> + * separated by hyphens, in the form 8-4-4-4-12 for a total of 36
> characters
> + */
> +int get_disk_guid(struct blk_desc * dev_desc, char *guid)
> +{
> +	ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1,
> dev_desc->blksz);
> +	gpt_entry *gpt_pte = NULL;
> +	unsigned char *guid_bin;
> +
> +	/* This function validates AND fills in the GPT header and
> PTE */
> +	if (is_gpt_valid(dev_desc, GPT_PRIMARY_PARTITION_TABLE_LBA,
> +			 gpt_head, &gpt_pte) != 1) {
> +		printf("%s: *** ERROR: Invalid GPT ***\n", __func__);
> +		if (is_gpt_valid(dev_desc, (dev_desc->lba - 1),
> +				 gpt_head, &gpt_pte) != 1) {
> +			printf("%s: *** ERROR: Invalid Backup GPT
> ***\n",
> +			       __func__);
> +			return -1;
> +		} else {
> +			printf("%s: ***        Using Backup GPT
> ***\n",
> +			       __func__);
> +		}
> +	}
> +
> +	guid_bin = (unsigned char *)(gpt_head->disk_guid.b);
> +	uuid_bin_to_str(guid_bin, guid, UUID_STR_FORMAT_GUID);
> +
> +	return 0;
> +}
> +
>  void part_print_efi(struct blk_desc *dev_desc)
>  {
>  	ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1,
> dev_desc->blksz); diff --git a/doc/README.gpt b/doc/README.gpt
> index 3fcd835..c0779a4 100644
> --- a/doc/README.gpt
> +++ b/doc/README.gpt
> @@ -171,7 +171,8 @@ To restore GUID partition table one needs to:
>     The fields 'uuid' and 'uuid_disk' are optional if
> CONFIG_RANDOM_UUID is enabled. A random uuid will be used if omitted
> or they point to an empty/ non-existent environment variable. The
> environment variable will be set to
> -   the generated UUID.
> +   the generated UUID.  The 'gpt guid' command reads the current
> value of the
> +   uuid_disk from the GPT.
>  
>     The field 'bootable' is optional, it is used to mark the GPT
> partition bootable (set attribute flags "Legacy BIOS bootable").
> diff --git a/include/part.h b/include/part.h
> index 87b1111..16c4a46 100644
> --- a/include/part.h
> +++ b/include/part.h
> @@ -371,6 +371,21 @@ int gpt_verify_headers(struct blk_desc
> *dev_desc, gpt_header *gpt_head, int gpt_verify_partitions(struct
> blk_desc *dev_desc, disk_partition_t *partitions, int parts,
>  			  gpt_header *gpt_head, gpt_entry **gpt_pte);
> +
> +
> +/**
> + * get_disk_guid() - Function to read the GUID string from a
> device's GPT
> + *
> + * This function reads the GUID string from a block device whose
> descriptor
> + * is provided.
> + *
> + * @param dev_desc - block device descriptor
> + * @param guid - pre-allocated string in which to return the GUID
> + *
> + * @return - '0' on success, otherwise error
> + */
> +int get_disk_guid(struct blk_desc *dev_desc, char *guid);
> +
>  #endif
>  
>  #if CONFIG_IS_ENABLED(DOS_PARTITION)




Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
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

  parent reply	other threads:[~2017-05-31  7:44 UTC|newest]

Thread overview: 116+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-21  2:27 [U-Boot] [PATCH 0/3] add support for GPT partition name manipulation alison at peloton-tech.com
2017-05-21  2:27 ` [U-Boot] [PATCH 1/3] GPT: add accessor function for disk GUID alison at peloton-tech.com
2017-05-26 12:38   ` Tom Rini
2017-05-21  2:27 ` [U-Boot] [PATCH 2/3] GPT: read partition table from device into a data structure alison at peloton-tech.com
2017-05-26 12:39   ` Tom Rini
2017-05-21  2:27 ` [U-Boot] [PATCH 3/3] rename GPT partitions to detect boot failure alison at peloton-tech.com
2017-05-26 12:39   ` Tom Rini
2017-05-29  9:25   ` Lothar Waßmann
2017-05-26 12:38 ` [U-Boot] [PATCH 0/3] add support for GPT partition name manipulation Tom Rini
2017-05-29 16:49   ` [U-Boot] [PATCH v2 0/6] " alison at peloton-tech.com
2017-05-29 16:49     ` [U-Boot] [PATCH v2 1/6] EFI: replace number with UUID_STR_LEN macro alison at peloton-tech.com
2017-05-31  2:07       ` Tom Rini
2017-05-31  7:37       ` Lukasz Majewski
2017-05-29 16:49     ` [U-Boot] [PATCH v2 2/6] disk_partition: introduce macros for description string lengths alison at peloton-tech.com
2017-05-31  7:37       ` Lukasz Majewski
2017-05-31 13:50       ` Tom Rini
2017-05-29 16:49     ` [U-Boot] [PATCH v2 3/6] GPT: add accessor function for disk GUID alison at peloton-tech.com
2017-05-30  6:46       ` Lothar Waßmann
2017-06-03  2:22         ` [U-Boot] [PATCH v3 0/5] add support for GPT partition name manipulation alison at peloton-tech.com
2017-06-03  2:22           ` [U-Boot] [PATCH v3 1/5] GPT: add accessor function for disk GUID alison at peloton-tech.com
2017-06-06  8:20             ` Lothar Waßmann
2017-06-10  5:27               ` [U-Boot] [PATCH v5 1/3] " alison at peloton-tech.com
2017-06-11 13:38                 ` Tom Rini
2017-06-03  2:22           ` [U-Boot] [PATCH v3 2/5] partitions: increase MAX_SEARCH_PARTITIONS and move to part.h alison at peloton-tech.com
2017-06-03 11:52             ` Lukasz Majewski
2017-06-03  2:22           ` [U-Boot] [PATCH v3 3/5] GPT: read partition table from device into a data structure alison at peloton-tech.com
2017-06-06  8:28             ` Lothar Waßmann
2017-06-10  5:30               ` [U-Boot] [PATCH v5 2/3] " alison at peloton-tech.com
2017-06-11 13:38                 ` Tom Rini
2017-06-06 10:43             ` [U-Boot] [PATCH v3 3/5] " Lothar Waßmann
2017-06-03  2:22           ` [U-Boot] [PATCH v3 4/5] rename GPT partitions to detect boot failure alison at peloton-tech.com
2017-06-06  8:20             ` Lothar Waßmann
2017-06-10  5:35               ` [U-Boot] [PATCH v5 3/3] " alison at peloton-tech.com
2017-06-10  6:51                 ` Wolfgang Denk
2017-06-10 23:27                   ` Alison Chaiken
2017-06-10 23:33                   ` [U-Boot] [PATCH v6 3/3] GPT: provide commands to selectively rename partitions alison at peloton-tech.com
2017-06-11 13:38                     ` Tom Rini
2017-06-11 16:03                       ` [U-Boot] [PATCH v7] " alison at peloton-tech.com
2017-06-12  7:45                     ` [U-Boot] [PATCH v6 3/3] " Wolfgang Denk
2017-06-12 14:24                       ` Alison Chaiken
2017-06-12 14:56                         ` Tom Rini
2017-06-18 11:08                           ` Wolfgang Denk
2017-06-25 23:43                             ` [U-Boot] [PATCH v7 0/9] add support for GPT partition name manipulation alison at peloton-tech.com
2017-06-25 23:43                               ` [U-Boot] [PATCH v7 1/9] EFI: replace number with UUID_STR_LEN macro alison at peloton-tech.com
2017-08-07 13:54                                 ` [U-Boot] [U-Boot, v7, " Tom Rini
2017-06-25 23:43                               ` [U-Boot] [PATCH v7 2/9] disk_partition: introduce macros for description string lengths alison at peloton-tech.com
2017-08-07 13:54                                 ` [U-Boot] [U-Boot, v7, " Tom Rini
2017-06-25 23:43                               ` [U-Boot] [PATCH v7 3/9] GPT: fix error in partitions string doc alison at peloton-tech.com
2017-08-07 13:54                                 ` [U-Boot] [U-Boot, v7, " Tom Rini
2017-06-25 23:43                               ` [U-Boot] [PATCH v7 4/9] sandbox: README: fix partition command invocation alison at peloton-tech.com
2017-08-07 13:54                                 ` [U-Boot] [U-Boot, v7, " Tom Rini
2017-06-25 23:43                               ` [U-Boot] [PATCH v7 5/9] cmd gpt: test in sandbox alison at peloton-tech.com
2017-08-07 13:54                                 ` [U-Boot] [U-Boot,v7,5/9] " Tom Rini
2017-06-25 23:43                               ` [U-Boot] [PATCH v7 6/9] partitions: increase MAX_SEARCH_PARTITIONS and move to part.h alison at peloton-tech.com
2017-08-07 13:54                                 ` [U-Boot] [U-Boot, v7, " Tom Rini
2017-06-25 23:43                               ` [U-Boot] [PATCH v7 7/9] GPT: add accessor function for disk GUID alison at peloton-tech.com
2017-08-07 13:55                                 ` [U-Boot] [U-Boot, v7, " Tom Rini
2017-06-25 23:43                               ` [U-Boot] [PATCH v7 8/9] GPT: read partition table from device into a data structure alison at peloton-tech.com
2017-06-26  7:34                                 ` Lothar Waßmann
2017-07-01 22:42                                   ` [U-Boot] [PATCH v8 8/10] " alison at peloton-tech.com
2017-07-03  6:52                                     ` Lothar Waßmann
2017-07-04 18:18                                       ` [U-Boot] [PATCH v8 08/10] " alison at peloton-tech.com
2017-08-07 13:55                                         ` [U-Boot] [U-Boot, v8, " Tom Rini
2017-06-25 23:43                               ` [U-Boot] [PATCH v7 9/9] GPT: provide commands to selectively rename partitions alison at peloton-tech.com
2017-06-26  1:52                                 ` Bin Meng
2017-06-26  2:11                                   ` alison at peloton-tech.com
2017-06-26  7:55                                 ` Lothar Waßmann
2017-07-01 22:44                                   ` [U-Boot] [PATCH 09/10] " alison at peloton-tech.com
2017-06-18 11:03                         ` [U-Boot] [PATCH v6 3/3] " Wolfgang Denk
2017-06-25 21:54                           ` Alison Chaiken
2017-06-26 22:47                             ` Tom Rini
2017-06-27  7:05                             ` Lothar Waßmann
2017-06-27  9:12                               ` Lothar Waßmann
2017-07-01 22:44                                 ` [U-Boot] [PATCH 10/10] gpt: harden set_gpt_info() against non NULL-terminated strings alison at peloton-tech.com
2017-07-03  6:37                                   ` Lothar Waßmann
2017-07-04 18:19                                     ` [U-Boot] [PATCH v2 " alison at peloton-tech.com
2017-08-07 13:55                                       ` [U-Boot] [U-Boot, v2, " Tom Rini
2017-07-01 22:36                               ` [U-Boot] [PATCH v6 3/3] GPT: provide commands to selectively rename partitions Alison Chaiken
2017-07-03  6:40                                 ` Lothar Waßmann
2017-07-04 18:19                                   ` [U-Boot] [PATCH v8 09/10] " alison at peloton-tech.com
2017-08-07 13:55                                     ` [U-Boot] [U-Boot, v8, " Tom Rini
2017-06-03  2:22           ` [U-Boot] [PATCH v3 5/5] GPT: fix error in partitions string doc alison at peloton-tech.com
2017-06-03 11:48           ` [U-Boot] [PATCH v3 0/5] add support for GPT partition name manipulation Lukasz Majewski
2017-05-31  7:44       ` Lukasz Majewski [this message]
2017-05-31  8:47         ` [U-Boot] [PATCH v2 3/6] GPT: add accessor function for disk GUID Lothar Waßmann
2017-05-29 16:49     ` [U-Boot] [PATCH v2 4/6] GPT: read partition table from device into a data structure alison at peloton-tech.com
2017-05-30  7:37       ` Lothar Waßmann
2017-06-01  6:34         ` Chaiken, Alison
2017-06-01  9:48           ` Lothar Waßmann
2017-05-31  7:48       ` Lukasz Majewski
2017-05-31  8:48         ` Lothar Waßmann
2017-05-31 11:11           ` Lukasz Majewski
2017-05-31 13:42             ` Lothar Waßmann
2017-05-31 14:07         ` Lukasz Majewski
2017-05-29 16:49     ` [U-Boot] [PATCH v2 5/6] rename GPT partitions to detect boot failure alison at peloton-tech.com
2017-05-30  7:38       ` Lothar Waßmann
2017-05-31  8:12       ` Lukasz Majewski
2017-06-01  7:04         ` Chaiken, Alison
2017-06-01  8:21           ` Lukasz Majewski
2017-06-01 15:06             ` Chaiken, Alison
2017-06-01 18:20               ` Lukasz Majewski
2017-06-04 22:11         ` [U-Boot] [PATCH v4 0/5] add support for GPT partition name manipulation alison at peloton-tech.com
2017-06-04 22:11           ` [U-Boot] [PATCH v4 1/5] GPT: read partition table from device into a data structure alison at peloton-tech.com
2017-06-04 22:11           ` [U-Boot] [PATCH v4 2/5] rename GPT partitions to detect boot failure alison at peloton-tech.com
2017-06-04 22:11           ` [U-Boot] [PATCH v4 3/5] GPT: fix error in partitions string doc alison at peloton-tech.com
2017-06-04 22:11           ` [U-Boot] [PATCH 4/5] sandbox: README: fix partition command invocation alison at peloton-tech.com
2017-06-09 12:28             ` Simon Glass
2017-06-15 19:21               ` sjg at google.com
2017-06-04 22:11           ` [U-Boot] [PATCH 5/5] cmd gpt: test in sandbox alison at peloton-tech.com
2017-06-15 19:21             ` sjg at google.com
2017-08-27 23:02         ` [U-Boot] [PATCH v2 5/6] rename GPT partitions to detect boot failure Chaiken, Alison
2017-08-28  7:54           ` Łukasz Majewski
2017-08-28 11:16             ` Tom Rini
2017-05-29 16:49     ` [U-Boot] [PATCH v2 6/6] GPT: fix error in partitions string doc alison at peloton-tech.com
2017-05-31  8:14       ` Lukasz Majewski
2017-05-31 11:21         ` Lukasz Majewski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170531094443.7a57e48d@jawa \
    --to=lukma@denx.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox