diff mbox

[v2,4/6] external/pflash: show the partitions on the second side flash

Message ID 1431568959-19933-5-git-send-email-cyril.bur@au1.ibm.com
State Superseded
Headers show

Commit Message

Cyril Bur May 14, 2015, 2:02 a.m. UTC
Currently pflash is unaware that that some platforms can have two sides of
flash and therefore doesn't include the ability to print it.

The ffs TOC at the start of the flash may contain a partition called
"OTHER_SIDE" which will start with the TOC for the second side. If OTHER_SIDE
is found pflash will dump that flash information too.

Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com>
---
 external/pflash/pflash.c | 52 +++++++++++++++++++++++++++++-------------------
 1 file changed, 32 insertions(+), 20 deletions(-)

Comments

Alistair Popple May 22, 2015, 2:23 a.m. UTC | #1
On Thu, 14 May 2015 12:02:37 Cyril Bur wrote:
> Currently pflash is unaware that that some platforms can have two sides of
> flash and therefore doesn't include the ability to print it.
> 
> The ffs TOC at the start of the flash may contain a partition called
> "OTHER_SIDE" which will start with the TOC for the second side. If
> OTHER_SIDE is found pflash will dump that flash information too.
> 
> Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com>

<snip>

> ---
>  external/pflash/pflash.c | 52
>  	}
> +
> +	ffs_close(ffs_handle);
> +
> +	if (other_side_offset)
> +		print_ffs_info(other_side_offset);

This looks like it relies on the OTHER_SIDE partition offset eventually 
pointing to 0 to avoid infinite recursion.

Patrick can you confirm that if we follow the OTHER_SIDE TOC entries we will 
eventually find one that points back to a TOC at offset 0? Is there ever going 
to be a setup where this isn't the case?

> +}
> +
> +
> +static void print_flash_info(void)
> +{
> +	printf("Flash info:\n");
> +	printf("-----------\n");
> +	printf("Name          = %s\n", fl_name);
> +	printf("Total size    = %dMB \n", fl_total_size >> 20);
> +	printf("Erase granule = %dKB \n", fl_erase_granule >> 10);
> +
> +	if (bmc_flash)
> +		return;
> +
> +	print_ffs_info(0);
>  }
> 
>  static void lookup_partition(const char *name)
diff mbox

Patch

diff --git a/external/pflash/pflash.c b/external/pflash/pflash.c
index 29a2775..3fedac0 100644
--- a/external/pflash/pflash.c
+++ b/external/pflash/pflash.c
@@ -69,32 +69,21 @@  static void check_confirm(void)
 	must_confirm = false;
 }
 
-static void print_flash_info(void)
+static void print_ffs_info(uint32_t toc_offset)
 {
-	uint32_t i;
+	struct ffs_handle *ffs_handle;
+	uint32_t other_side_offset = 0;
 	int rc;
+	uint32_t i;
 
-	printf("Flash info:\n");
-	printf("-----------\n");
-	printf("Name          = %s\n", fl_name);
-	printf("Total size    = %dMB \n", fl_total_size >> 20);
-	printf("Erase granule = %dKB \n", fl_erase_granule >> 10);
-
-	if (bmc_flash)
+	rc = ffs_open_flash(fl_chip, toc_offset, 0, &ffs_handle);
+	if (rc) {
+		fprintf(stderr, "Error %d opening ffs !\n", rc);
 		return;
-
-	if (!ffsh) {
-		rc = ffs_open_flash(fl_chip, 0, 0, &ffsh);
-		if (rc) {
-			fprintf(stderr, "Error %d opening ffs !\n", rc);
-			ffsh = NULL;
-		}
 	}
-	if (!ffsh)
-		return;
 
 	printf("\n");
-	printf("Partitions:\n");
+	printf("TOC@0x%08x Partitions:\n", toc_offset);
 	printf("-----------\n");
 
 	for (i = 0;; i++) {
@@ -102,7 +91,7 @@  static void print_flash_info(void)
 		bool ecc;
 		char *name;
 
-		rc = ffs_part_info(ffsh, i, &name, &start, &size, &act, &ecc);
+		rc = ffs_part_info(ffs_handle, i, &name, &start, &size, &act, &ecc);
 		if (rc == FFS_ERR_PART_NOT_FOUND)
 			break;
 		if (rc) {
@@ -113,8 +102,31 @@  static void print_flash_info(void)
 		printf("ID=%02d %15s %08x..%08x (actual=%08x) %s\n",
 		       i, name, start, end, act, ecc ? "[ECC]" : "");
 
+		if (strcmp(name, "OTHER_SIDE") == 0)
+			other_side_offset = start;
+
 		free(name);
 	}
+
+	ffs_close(ffs_handle);
+
+	if (other_side_offset)
+		print_ffs_info(other_side_offset);
+}
+
+
+static void print_flash_info(void)
+{
+	printf("Flash info:\n");
+	printf("-----------\n");
+	printf("Name          = %s\n", fl_name);
+	printf("Total size    = %dMB \n", fl_total_size >> 20);
+	printf("Erase granule = %dKB \n", fl_erase_granule >> 10);
+
+	if (bmc_flash)
+		return;
+
+	print_ffs_info(0);
 }
 
 static void lookup_partition(const char *name)