diff loadtools/ltflash.c @ 56:d98137625c0d

fc-loadtool flash: total_size logic implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 23 Jun 2013 20:50:41 +0000
parents 278052b6afda
children 1f9302b6f342
line wrap: on
line diff
--- a/loadtools/ltflash.c	Sun Jun 23 20:13:59 2013 +0000
+++ b/loadtools/ltflash.c	Sun Jun 23 20:50:41 2013 +0000
@@ -54,6 +54,7 @@
 	char *cp, *np, *ep;
 	struct flash_device_desc *tp;
 	int bank;
+	struct flash_bank_info *bi;
 
 	if (selected_flash_device) {
 		fprintf(stderr, "%s line %d: duplicate flash setting\n",
@@ -93,7 +94,8 @@
 			;
 		if (*cp)
 			*cp++ = '\0';
-		flash_bank_info[bank].base_addr = strtoul(np, &ep, 16);
+		bi = flash_bank_info + bank;
+		bi->base_addr = strtoul(np, &ep, 16);
 		if (*ep) {
 			fprintf(stderr,
 "%s line %d: syntax error (base addr expected after flash device type)\n",
@@ -101,9 +103,21 @@
 			exit(1);
 		}
 		/* the rest comes from the flash device type */
-		flash_bank_info[bank].bank_desc =
-				selected_flash_device->bank_desc + bank;
-		/* TODO: call function to init total_size and nsectors */
+		bi->bank_desc = selected_flash_device->bank_desc + bank;
+		compute_flash_totsize_nsecs(bank);
+		if (count_ones(bi->total_size) != 1) {
+			fprintf(stderr,
+"fc-loadtool internal bug: flash bank %d size for %s is not a power of 2\n",
+				bank, selected_flash_device->name);
+			exit(1);
+		}
+		if (bi->base_addr & (bi->total_size - 1)) {
+			fprintf(stderr,
+"%s line %d: flash bank %d base addr is not aligned to the bank size (0x%lx)\n",
+				filename_for_errs, lineno_for_errs, bank,
+				(u_long) bi->total_size);
+			exit(1);
+		}
 	}
 	while (isspace(*cp))
 		cp++;