cli_classic: Use flashrom_flash_getsize() over raw access

Use native libflashrom entry-points for getting flash
size over accessing internal struct members within cli
code.

Tested: `sudo ./flashrom -p internal --get-size`.

flashrom-stable: Squashed fixup for format string

Change-Id: Iff70a0de1dee517c4e38c45b1540c42326a13340
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
Original-Reviewed-on: https://review.coreboot.org/c/flashrom/+/61583
Original-Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Reviewed-on: https://review.coreboot.org/c/flashrom-stable/+/72296
Reviewed-by: Nico Huber <nico.h@gmx.de>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
diff --git a/cli_classic.c b/cli_classic.c
index 0436b03..e26c343 100644
--- a/cli_classic.c
+++ b/cli_classic.c
@@ -122,7 +122,7 @@
 {
 	int ret;
 
-	unsigned long size = flash->chip->total_size * 1024;
+	unsigned long size = flashrom_flash_getsize(flash);
 	unsigned char *buf = calloc(size, sizeof(unsigned char));
 	if (!buf) {
 		msg_gerr("Memory allocation failed!\n");
@@ -142,7 +142,7 @@
 
 static int do_write(struct flashctx *const flash, const char *const filename, const char *const referencefile)
 {
-	const size_t flash_size = flash->chip->total_size * 1024;
+	const size_t flash_size = flashrom_flash_getsize(flash);
 	int ret = 1;
 
 	uint8_t *const newcontents = malloc(flash_size);
@@ -171,7 +171,7 @@
 
 static int do_verify(struct flashctx *const flash, const char *const filename)
 {
-	const size_t flash_size = flash->chip->total_size * 1024;
+	const size_t flash_size = flashrom_flash_getsize(flash);
 	int ret = 1;
 
 	uint8_t *const newcontents = malloc(flash_size);
@@ -683,7 +683,7 @@
 	}
 
 	if (flash_size) {
-		printf("%d\n", fill_flash->chip->total_size * 1024);
+		printf("%zu\n", flashrom_flash_getsize(fill_flash));
 		goto out_shutdown;
 	}
 
@@ -720,7 +720,7 @@
 		}
 		free(fmapfile_buffer);
 	} else if (fmap && (flashrom_layout_read_fmap_from_rom(&layout, fill_flash, 0,
-		       fill_flash->chip->total_size * 1024) || process_include_args(layout, include_args))) {
+				flashrom_flash_getsize(fill_flash)) || process_include_args(layout, include_args))) {
 		ret = 1;
 		goto out_shutdown;
 	}