Patchwork Print total size of large chips in Megabytes

login
register
about
Submitter Boris Baykov
Date 2015-01-21 09:57:47
Message ID <1778951138.20150121125747@borisbaykov.com>
Download mbox | patch
Permalink /patch/4279/
State New
Headers show

Comments

Boris Baykov - 2015-01-21 09:57:47
Print total size of large chips in Megabytes.

Signed-off-by: Boris Baykov <dev@borisbaykov.com>
---
Print total size of large chips in Megabytes.

Signed-off-by: Boris Baykov <dev@borisbaykov.com>
---

Patch

Index: cli_common.c
===================================================================
--- cli_common.c	(revision 1869)
+++ cli_common.c	(working copy)
@@ -55,10 +55,23 @@ 
 	ret[strlen(ret) - 2] = '\0';
 	ret = realloc(ret, strlen(ret) + 1);
 	return ret;
 }
 
+char *flashsize_to_text(unsigned int chip_size)
+{
+	char *ret = malloc(100);
+	if(chip_size < 1024) {
+		sprintf(ret, "%d kB", chip_size);
+	} else if(chip_size % 1024 == 0){
+		sprintf(ret, "%d MB", chip_size / 1024);
+	} else {
+		sprintf(ret, "%1.1f MB", (double)chip_size / 1024);
+	}
+	ret = realloc(ret, strlen(ret) + 1);
+	return ret;
+}
 
 void print_chip_support_status(const struct flashchip *chip)
 {
 	if (chip->feature_bits & FEATURE_OTP) {
 		msg_cdbg("This chip may contain one-time programmable memory. flashrom cannot read\n"
Index: flash.h
===================================================================
--- flash.h	(revision 1869)
+++ flash.h	(working copy)
@@ -295,10 +295,11 @@ 
  */
 #define ERROR_FLASHROM_LIMIT -201
 
 /* cli_common.c */
 char *flashbuses_to_text(enum chipbustype bustype);
+char *flashsize_to_text(unsigned int chip_size);
 void print_chip_support_status(const struct flashchip *chip);
 
 /* cli_output.c */
 extern int verbose_screen;
 extern int verbose_logfile;
Index: flashrom.c
===================================================================
--- flashrom.c	(revision 1869)
+++ flashrom.c	(working copy)
@@ -1121,18 +1121,21 @@ 
 int probe_flash(struct registered_master *mst, int startchip, struct flashctx *flash, int force)
 {
 	const struct flashchip *chip;
 	enum chipbustype buses_common;
 	char *tmp;
+	char *tmp2;
 
 	for (chip = flashchips + startchip; chip && chip->name; chip++) {
 		if (chip_to_probe && strcmp(chip->name, chip_to_probe) != 0)
 			continue;
 		buses_common = mst->buses_supported & chip->bustype;
 		if (!buses_common)
 			continue;
-		msg_gdbg("Probing for %s %s, %d kB: ", chip->vendor, chip->name, chip->total_size);
+		tmp2 = flashsize_to_text(chip->total_size);
+		msg_gdbg("Probing for %s %s, %s: ", chip->vendor, chip->name, tmp2);
+		free(tmp2);
 		if (!chip->probe && !force) {
 			msg_gdbg("failed! flashrom has no probe function for this flash chip.\n");
 			continue;
 		}
 
@@ -1202,14 +1205,16 @@ 
 
 	if (!flash->chip)
 		return -1;
 
 
+	tmp2 = flashsize_to_text(flash->chip->total_size);
 	tmp = flashbuses_to_text(flash->chip->bustype);
-	msg_cinfo("%s %s flash chip \"%s\" (%d kB, %s) ", force ? "Assuming" : "Found",
-		  flash->chip->vendor, flash->chip->name, flash->chip->total_size, tmp);
+	msg_cinfo("%s %s flash chip \"%s\" (%s, %s) ", force ? "Assuming" : "Found",
+		  flash->chip->vendor, flash->chip->name, tmp2, tmp);
 	free(tmp);
+	free(tmp2);
 #if CONFIG_INTERNAL == 1
 	if (programmer_table[programmer].map_flash_region == physmap)
 		msg_cinfo("mapped at physical address 0x%0*" PRIxPTR ".\n",
 			  PRIxPTR_WIDTH, flash->physical_memory);
 	else