@@ -94,8 +94,11 @@ 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;
+/* struct flashctx flashes[3] = {{0}};
+ struct flashctx *fill_flash;*/
const char *name;
int namelen, opt, i, j;
int startchip = -1, chipcount = 0, option_index = 0, force = 0;
@@ -425,19 +428,48 @@ int main(int argc, char *argv[])
for (j = 0; j < registered_programmer_count; j++) {
startchip = 0;
- while (chipcount < ARRAY_SIZE(flashes)) {
+ while (1){
+ if (chip_to_probe && chipcount) break;
+ startchip = probe_flash(®istered_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++;
+ }
+ /*while (chipcount < ARRAY_SIZE(flashes)) {
startchip = probe_flash(®istered_programmers[j], startchip, &flashes[chipcount], 0);
if (startchip == -1)
break;
chipcount++;
startchip++;
- }
+ }*/
}
if (chipcount > 1) {
- msg_cinfo("Multiple flash chips were detected: \"%s\"", flashes[0].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("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(", \"%s\"", flashes[i].chip->name);*/
msg_cinfo("\nPlease specify which chip to use with the -c <chipname> option.\n");
ret = 1;
goto out_shutdown;
@@ -468,7 +500,8 @@ int main(int argc, char *argv[])
"chip, using the first one.\n");
for (j = 0; j < registered_programmer_count; j++) {
pgm = ®istered_programmers[j];
- startchip = probe_flash(pgm, 0, &flashes[0], 1);
+/* startchip = probe_flash(pgm, 0, &flashes[0], 1);*/
+ startchip = probe_flash(pgm, 0, pflashes, 1);
if (startchip != -1)
break;
}
@@ -479,20 +512,25 @@ 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(&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(flashes[0].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);*/
+ 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);
@@ -502,8 +540,17 @@ int main(int argc, char *argv[])
msg_cerr("Chip is too big for this programmer (-V gives details). Use --force to override.\n");
ret = 1;
goto out_shutdown;
- }
+ }*/
+
+ check_chip_supported(pflashes->chip);
+ 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;
+ }
+
if (!(read_it | write_it | verify_it | erase_it)) {
msg_ginfo("No operations were specified.\n");
goto out_shutdown;
@@ -518,19 +565,22 @@ 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(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++)
+/* 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;
@@ -170,6 +170,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