Patchwork [U-Boot] part: show efi partition name when print out partition info

login
register
mail settings
Submitter Lei Wen
Date Sept. 7, 2011, 11:17 a.m.
Message ID <1315394223-12399-1-git-send-email-leiwen@marvell.com>
Download mbox | patch
Permalink /patch/113741/
State Superseded
Headers show

Comments

Lei Wen - Sept. 7, 2011, 11:17 a.m.
Previous output:
Marvell>>  mmc part

Partition Map for MMC device 1  --   Partition Type: EFI

Part  Start LBA  End LBA
gpt1  0x8C00    0xCBFF
gpt2  0xCC00    0x57BFF
gpt3  0x57C00    0xA2BFF
gpt4  0xA2C00    0xECBFDE

With the patch, the output becomes:
Marvell>> mmc part

Partition Map for MMC device 1  --   Partition Type: EFI

Part            Name            Start LBA       End LBA
 1                 ramdisk      0x00008C00      0x0000CBFF
 2                  system      0x0000CC00      0x00057BFF
 3                userdata      0x00057C00      0x000A2BFF
 4               remaining      0x000A2C00      0x00ECBFDE

Signed-off-by: Lei Wen <leiwen@marvell.com>
---
 disk/part_efi.c |   24 ++++++++++++++++++++----
 1 files changed, 20 insertions(+), 4 deletions(-)
Marek Vasut - Sept. 7, 2011, 11:27 a.m.
On Wednesday, September 07, 2011 01:17:03 PM Lei Wen wrote:
> Previous output:
> Marvell>>  mmc part
> 
> Partition Map for MMC device 1  --   Partition Type: EFI
> 
> Part  Start LBA  End LBA
> gpt1  0x8C00    0xCBFF
> gpt2  0xCC00    0x57BFF
> gpt3  0x57C00    0xA2BFF
> gpt4  0xA2C00    0xECBFDE
> 
> With the patch, the output becomes:
> Marvell>> mmc part
> 
> Partition Map for MMC device 1  --   Partition Type: EFI
> 
> Part            Name            Start LBA       End LBA
>  1                 ramdisk      0x00008C00      0x0000CBFF
>  2                  system      0x0000CC00      0x00057BFF
>  3                userdata      0x00057C00      0x000A2BFF
>  4               remaining      0x000A2C00      0x00ECBFDE
> 
> Signed-off-by: Lei Wen <leiwen@marvell.com>
> ---

Hi Lei,

what about aligning the Name to the left ?

Cheers
Lei Wen - Sept. 7, 2011, 11:29 a.m.
Hi Marek,

On Wed, Sep 7, 2011 at 7:27 PM, Marek Vasut <marek.vasut@gmail.com> wrote:
> On Wednesday, September 07, 2011 01:17:03 PM Lei Wen wrote:
>> Previous output:
>> Marvell>>  mmc part
>>
>> Partition Map for MMC device 1  --   Partition Type: EFI
>>
>> Part  Start LBA  End LBA
>> gpt1  0x8C00    0xCBFF
>> gpt2  0xCC00    0x57BFF
>> gpt3  0x57C00    0xA2BFF
>> gpt4  0xA2C00    0xECBFDE
>>
>> With the patch, the output becomes:
>> Marvell>> mmc part
>>
>> Partition Map for MMC device 1  --   Partition Type: EFI
>>
>> Part            Name            Start LBA       End LBA
>>  1                 ramdisk      0x00008C00      0x0000CBFF
>>  2                  system      0x0000CC00      0x00057BFF
>>  3                userdata      0x00057C00      0x000A2BFF
>>  4               remaining      0x000A2C00      0x00ECBFDE
>>
>> Signed-off-by: Lei Wen <leiwen@marvell.com>
>> ---
>
> Hi Lei,
>
> what about aligning the Name to the left ?
>

You mean like below?
Name       Part     Start LBA       End LBA

Best regards,
Lei
Marek Vasut - Sept. 7, 2011, 12:29 p.m.
On Wednesday, September 07, 2011 01:29:35 PM Lei Wen wrote:
> Hi Marek,
> 
> On Wed, Sep 7, 2011 at 7:27 PM, Marek Vasut <marek.vasut@gmail.com> wrote:
> > On Wednesday, September 07, 2011 01:17:03 PM Lei Wen wrote:
> >> Previous output:
> >> Marvell>>  mmc part
> >> 
> >> Partition Map for MMC device 1  --   Partition Type: EFI
> >> 
> >> Part  Start LBA  End LBA
> >> gpt1  0x8C00    0xCBFF
> >> gpt2  0xCC00    0x57BFF
> >> gpt3  0x57C00    0xA2BFF
> >> gpt4  0xA2C00    0xECBFDE
> >> 
> >> With the patch, the output becomes:
> >> Marvell>> mmc part
> >> 
> >> Partition Map for MMC device 1  --   Partition Type: EFI
> >> 
> >> Part            Name            Start LBA       End LBA
> >>  1                 ramdisk      0x00008C00      0x0000CBFF
> >>  2                  system      0x0000CC00      0x00057BFF
> >>  3                userdata      0x00057C00      0x000A2BFF
> >>  4               remaining      0x000A2C00      0x00ECBFDE
> >> 
> >> Signed-off-by: Lei Wen <leiwen@marvell.com>
> >> ---
> > 
> > Hi Lei,
> > 
> > what about aligning the Name to the left ?
> 
> You mean like below?
> Name       Part     Start LBA       End LBA

Like "ramdisk" "system" etc. starting at the same column

> 
> Best regards,
> Lei
Wolfgang Denk - Sept. 7, 2011, 7:21 p.m.
Dear Lei Wen,

In message <1315394223-12399-1-git-send-email-leiwen@marvell.com> you wrote:
...
> +static char *print_efiname(gpt_entry *pte)
> +{
> +	static char name[37];

I hate these magic constants where nobody knows where they are coming
from.  Please use the size of the partition_name[] array for reference
instead.

> +	int i;
> +	for (i = 0; i < 37; i++) {

Again, drop this magic constant.  Also note that 37 is actually wrong
here - you are accessing an element beyond the end of partition_name[]

> +		u8 c;
> +		c = pte->partition_name[i] & 0xff;
> +		c = (c && !isprint(c)) ? '!' : c;

Why do you use '!' to mark nonprinting characters?  Most memory dump
tools atc. use '.' instead.

> +		name[i] = c;
> +	}
> +	name[36] = 0;

And again: get rid of this constant.

Best regards,

Wolfgang Denk

Patch

diff --git a/disk/part_efi.c b/disk/part_efi.c
index 1b04c27..9e2a0dd 100644
--- a/disk/part_efi.c
+++ b/disk/part_efi.c
@@ -35,6 +35,7 @@ 
 #include <ide.h>
 #include <malloc.h>
 #include "part_efi.h"
+#include <linux/ctype.h>
 
 #if defined(CONFIG_CMD_IDE) || \
     defined(CONFIG_CMD_MG_DISK) || \
@@ -99,6 +100,20 @@  static gpt_entry *alloc_read_gpt_entries(block_dev_desc_t * dev_desc,
 
 static int is_pte_valid(gpt_entry * pte);
 
+static char *print_efiname(gpt_entry *pte)
+{
+	static char name[37];
+	int i;
+	for (i = 0; i < 37; i++) {
+		u8 c;
+		c = pte->partition_name[i] & 0xff;
+		c = (c && !isprint(c)) ? '!' : c;
+		name[i] = c;
+	}
+	name[36] = 0;
+	return name;
+}
+
 /*
  * Public Functions (include/part.h)
  */
@@ -122,12 +137,12 @@  void print_part_efi(block_dev_desc_t * dev_desc)
 
 	debug("%s: gpt-entry at 0x%08X\n", __FUNCTION__, (unsigned int)*pgpt_pte);
 
-	printf("Part  Start LBA  End LBA\n");
+	printf("Part\t\tName\t\tStart LBA\tEnd LBA\n");
 	for (i = 0; i < le32_to_int(gpt_head.num_partition_entries); i++) {
 
 		if (is_pte_valid(&(*pgpt_pte)[i])) {
-			printf("%s%d  0x%llX    0x%llX\n", GPT_ENTRY_NAME,
-				(i + 1),
+			printf("%2d\t%18s\t0x%08llX\t0x%08llX\n", (i + 1),
+				print_efiname(&(*pgpt_pte)[i]),
 				le64_to_int((*pgpt_pte)[i].starting_lba),
 				le64_to_int((*pgpt_pte)[i].ending_lba));
 		} else {
@@ -169,7 +184,8 @@  int get_partition_info_efi(block_dev_desc_t * dev_desc, int part,
 		     - info->start;
 	info->blksz = GPT_BLOCK_SIZE;
 
-	sprintf((char *)info->name, "%s%d", GPT_ENTRY_NAME, part);
+	sprintf((char *)info->name, "%s",
+			print_efiname(&(*pgpt_pte)[part - 1]));
 	sprintf((char *)info->type, "U-Boot");
 
 	debug("%s: start 0x%lX, size 0x%lX, name %s", __FUNCTION__,