mirror of
https://github.com/avrdudes/avrdude.git
synced 2026-09-28 12:06:59 +03:00
Move cache flush/reset from -T/U parsing to -U/T execution
What happens is the same, just the code is crisper and clearer.
This commit is contained in:
@@ -2579,16 +2579,14 @@ example below burns a bootloader, uses a terminal line to write
|
||||
application data to flash, loads the application, configures the brownout
|
||||
detection level to 2.7 V and, finally, stores the full flash as new hex
|
||||
file. Note the use of different quotation marks in @code{bash} to pass the
|
||||
terminal command lines as single entity to AVRDUDE. Also note the extra
|
||||
@code{flush} terminal command that AVRDUDE inserted to ensure the terminal
|
||||
cache and @code{-U} update operations work seamlessly.
|
||||
terminal command lines as single entity to AVRDUDE.
|
||||
|
||||
@smallexample
|
||||
@cartouche
|
||||
|
||||
$ avrdude -qc dryrun -p m328p \
|
||||
-U urboot_m328p_1s_autobaud_uart0_pr_ee_ce.hex \
|
||||
-T 'write flash 0x7000 0xc0cac01a 0xcafe "secret Coca Cola recipe"' \
|
||||
-T 'write flash 0x7D00 0xc0cac01a 0xcafe "secret Coca Cola recipe"' \
|
||||
-U flash:w:cola-vending-machine.hex \
|
||||
-T "config -v bod=*2v7" \
|
||||
-U flash:r:app+data.hex:I
|
||||
@@ -2608,9 +2606,7 @@ avrdude: 368 bytes of flash written
|
||||
avrdude: verifying flash memory against urboot_m328p_1s_autobaud_uart0_pr_ee_ce.hex
|
||||
avrdude: 368 bytes of flash verified
|
||||
|
||||
avrdude: processing -T write flash 0x7000 0xc0cac01a 0xcafe "secret Coca Cola recipe"
|
||||
|
||||
avrdude: processing -T flush
|
||||
avrdude: processing -T write flash 0x7D00 0xc0cac01a 0xcafe "secret Coca Cola recipe"
|
||||
avrdude: synching cache to device ... done
|
||||
|
||||
avrdude: processing -U flash:w:cola-vending-machine.hex:i
|
||||
@@ -2625,8 +2621,6 @@ avrdude: 736 bytes of flash verified
|
||||
avrdude: processing -T config -v bod=*2v7
|
||||
config bodlevel=bod_2v7 # 5
|
||||
|
||||
avrdude: processing -T flush
|
||||
|
||||
avrdude: processing -U flash:r:app+data.hex:I
|
||||
avrdude: reading flash memory ...
|
||||
avrdude: writing output file app+data.hex
|
||||
|
||||
27
src/main.c
27
src/main.c
@@ -632,7 +632,6 @@ int main(int argc, char * argv [])
|
||||
/*
|
||||
* process command line arguments
|
||||
*/
|
||||
int memwrite = 0, memterminal = 0;
|
||||
while ((ch = getopt(argc,argv,"?Ab:B:c:C:DeE:Fi:l:np:OP:qstT:U:uvVx:yY:")) != -1) {
|
||||
|
||||
switch (ch) {
|
||||
@@ -774,14 +773,7 @@ int main(int argc, char * argv [])
|
||||
break;
|
||||
|
||||
case 'T':
|
||||
upd = (UPDATE *) cfg_malloc(__func__, sizeof *upd);
|
||||
upd->cmdline = optarg;
|
||||
if(memwrite) { // Invalidate cache if device was written to
|
||||
memwrite = 0;
|
||||
ladd(updates, cmd_update("abort # Reset cache"));
|
||||
}
|
||||
memterminal = 1;
|
||||
ladd(updates, upd);
|
||||
ladd(updates, cmd_update(optarg));
|
||||
break;
|
||||
|
||||
case 'U':
|
||||
@@ -790,11 +782,6 @@ int main(int argc, char * argv [])
|
||||
pmsg_error("unable to parse update operation '%s'\n", optarg);
|
||||
exit(1);
|
||||
}
|
||||
if(memterminal) { // Flush cache before any device memory access
|
||||
memterminal = 0;
|
||||
ladd(updates, cmd_update("flush"));
|
||||
}
|
||||
memwrite |= upd->op == DEVICE_WRITE;
|
||||
ladd(updates, upd);
|
||||
break;
|
||||
|
||||
@@ -832,9 +819,6 @@ int main(int argc, char * argv [])
|
||||
|
||||
}
|
||||
|
||||
if(memterminal)
|
||||
ladd(updates, cmd_update("flush"));
|
||||
|
||||
if (logfile != NULL) {
|
||||
FILE *newstderr = freopen(logfile, "w", stderr);
|
||||
if (newstderr == NULL) {
|
||||
@@ -1517,8 +1501,16 @@ int main(int argc, char * argv [])
|
||||
}
|
||||
|
||||
|
||||
int wrmem = 0;
|
||||
for (ln=lfirst(updates); ln; ln=lnext(ln)) {
|
||||
upd = ldata(ln);
|
||||
if(upd->cmdline && wrmem) { // Invalidate cache if device was written to
|
||||
wrmem = 0;
|
||||
pgm->reset_cache(pgm, p);
|
||||
} else if(!upd->cmdline) { // Flush cache before any device memory access
|
||||
pgm->flush_cache(pgm, p);
|
||||
wrmem |= upd->op == DEVICE_WRITE;
|
||||
}
|
||||
rc = do_op(pgm, p, upd, uflags);
|
||||
if (rc && rc != LIBAVRDUDE_SOFTFAIL) {
|
||||
exitrc = 1;
|
||||
@@ -1526,6 +1518,7 @@ int main(int argc, char * argv [])
|
||||
} else if(rc == 0 && upd->op == DEVICE_WRITE && avr_memtype_is_flash_type(upd->memtype))
|
||||
ce_delayed = 0; // Redeemed chip erase promise
|
||||
}
|
||||
pgm->flush_cache(pgm, p);
|
||||
|
||||
main_exit:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user