Patchwork patch Dynamic list Multiple chips

login
register
about
Submitter Николай Николаев
Date 2013-03-04 12:03:32
Message ID <CABSK2p=YbfD7SURWrKX1oS4A=vY7j-Gf=LdhMiSj_nvP8m77YA@mail.gmail.com>
Download mbox | patch
Permalink /patch/3875/
State Superseded
Headers show

Comments

Николай Николаев - 2013-03-04 12:03:32
Checked version
-- 
With best regards Nikolay Nikolaev
С Уважением Николаев Николай
commit 4d00b0697f386d08e0c1fc68b322a486ab4762d2
Author: Nikolay Nikolaev <evrinoma@gmail.com>
Date:   Mon Mar 4 10:59:42 2013 +0400

    if we detected Multiple flash chips than
    we can easy save all chips in dynamic list - pflashes.
    and we will not have a restrictions with number chips
    TODO:
    Sort Dynamic List by Volage. This chips has a equivalent the model_id
    but can have a different parameters like a name voltage probe function
    ...
    Probing
    ...
    Resolving chips names
    
Signed-off-by: Nikolay Nikolaev <evrinoma@gmail.com>

Patch

diff --git a/cli_classic.c b/cli_classic.c
index 14fb825..2e7b7e2 100644
--- a/cli_classic.c
+++ b/cli_classic.c
@@ -94,8 +94,9 @@  int main(int argc, char *argv[])
 	unsigned long size;
 	/* Probe for up to three flash chips. */
 	const struct flashchip *chip = NULL;
-	struct flashctx flashes[3] = {{0}};
-	struct flashctx *fill_flash;
+	struct flashctx flashes = {0};
+	struct flashctx *pflashes = NULL;
+	struct flashctx *paddress = NULL;
 	const char *name;
 	int namelen, opt, i, j;
 	int startchip = -1, chipcount = 0, option_index = 0, force = 0;
@@ -425,19 +426,36 @@  int main(int argc, char *argv[])
 
 	for (j = 0; j < registered_programmer_count; j++) {
 		startchip = 0;
-		while (chipcount < ARRAY_SIZE(flashes)) {
-			startchip = probe_flash(&registered_programmers[j], startchip, &flashes[chipcount], 0);
-			if (startchip == -1)
-				break;
+		while (1) {
+			if (chip_to_probe && chipcount)
+				break;
+			startchip = probe_flash(&registered_programmers[j], startchip, &flashes, 0);
+			if (startchip == -1)
+				break;
+			paddress = pflashes;
+			pflashes = calloc(1, sizeof(struct flashctx));
+			if (!pflashes) {
+				msg_gerr("Out of memory!\n");
+				exit(1);
+			}
+			memcpy(pflashes, &flashes, sizeof(struct flashctx));
+			pflashes->last = paddress;
+			pflashes->next = NULL;
+			if (paddress != NULL)
+				paddress->next = pflashes;
 			chipcount++;
 			startchip++;
 		}
 	}
 
 	if (chipcount > 1) {
-		msg_cinfo("Multiple flash chips were detected: \"%s\"", flashes[0].chip->name);
-		for (i = 1; i < chipcount; i++)
-			msg_cinfo(", \"%s\"", flashes[i].chip->name);
+		msg_cinfo("Multiple flash chips were detected: \n");
+		paddress = pflashes;
+		while (pflashes != NULL) {
+			(pflashes->last == NULL) ? msg_cinfo("\"%s\"", pflashes->chip->name) : msg_cinfo("\"%s\",", pflashes->chip->name);
+			pflashes = pflashes->last;
+		}
+		pflashes = paddress;
 		msg_cinfo("\nPlease specify which chip to use with the -c <chipname> option.\n");
 		ret = 1;
 		goto out_shutdown;
@@ -468,7 +486,7 @@  int main(int argc, char *argv[])
 					  "chip, using the first one.\n");
 			for (j = 0; j < registered_programmer_count; j++) {
 				pgm = &registered_programmers[j];
-				startchip = probe_flash(pgm, 0, &flashes[0], 1);
+				startchip = probe_flash(pgm, 0, pflashes, 1);
 				if (startchip != -1)
 					break;
 			}
@@ -479,26 +497,24 @@  int main(int argc, char *argv[])
 				goto out_shutdown;
 			}
 			msg_cinfo("Please note that forced reads most likely contain garbage.\n");
-			ret = read_flash_to_file(&flashes[0], filename);
-			free(flashes[0].chip);
+			ret = read_flash_to_file(pflashes, filename);
+			free(pflashes->chip);
 			goto out_shutdown;
 		}
 		ret = 1;
 		goto out_shutdown;
 	} else if (!chip_to_probe) {
 		/* repeat for convenience when looking at foreign logs */
-		tempstr = flashbuses_to_text(flashes[0].chip->bustype);
+		tempstr = flashbuses_to_text(pflashes->chip->bustype);
 		msg_gdbg("Found %s flash chip \"%s\" (%d kB, %s).\n",
-			 flashes[0].chip->vendor, flashes[0].chip->name, flashes[0].chip->total_size, tempstr);
+			pflashes->chip->vendor, pflashes->chip->name, pflashes->chip->total_size, tempstr);
 		free(tempstr);
 	}
 
-	fill_flash = &flashes[0];
-
-	check_chip_supported(fill_flash->chip);
+	check_chip_supported(pflashes->chip);
 
-	size = fill_flash->chip->total_size * 1024;
-	if (check_max_decode(fill_flash->pgm->buses_supported & fill_flash->chip->bustype, size) && (!force)) {
+	size = pflashes->chip->total_size * 1024;
+	if (check_max_decode(pflashes->pgm->buses_supported & pflashes->chip->bustype, size) && (!force)) {
 		msg_cerr("Chip is too big for this programmer (-V gives details). Use --force to override.\n");
 		ret = 1;
 		goto out_shutdown;
@@ -518,19 +534,18 @@  int main(int argc, char *argv[])
 	 * Give the chip time to settle.
 	 */
 	programmer_delay(100000);
-	ret |= doit(fill_flash, force, filename, read_it, write_it, erase_it, verify_it);
+	ret |= doit(pflashes, force, filename, read_it, write_it, erase_it, verify_it);
 	/* Note: doit() already calls programmer_shutdown(). */
 	goto out;
 
 out_shutdown:
 	programmer_shutdown();
 out:
-	for (i = 0; i < chipcount; i++)
-		free(flashes[i].chip);
-
+	free(flashes.chip);
 	free(filename);
 	free(layoutfile);
 	free(pparam);
+	free(pflashes);
 	/* clean up global variables */
 	free((char *)chip_to_probe); /* Silence! Freeing is not modifying contents. */
 	chip_to_probe = NULL;
diff --git a/flash.h b/flash.h
index 9c4b0ac..bbf2314 100644
--- a/flash.h
+++ b/flash.h
@@ -171,6 +171,9 @@  struct flashctx {
 	/* Some flash devices have an additional register space. */
 	chipaddr virtual_registers;
 	struct registered_programmer *pgm;
+	/*pointer dynamic list*/
+	struct flashctx *last;
+	struct flashctx *next;
 };
 
 #define TEST_UNTESTED	0