-
Notifications
You must be signed in to change notification settings - Fork 149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable stdin verification and display correct number of bytes written/verified #1053
Conversation
…/verified Counting the number of bytes written to a memory and/or verified is not trivial owing to potential holes in the input file and to potential trailing 0xff bytes in flash memory that are not written per default (but see -A). The new function memstats(), which is best called just after an input file has been read into mem->buf/mem->tags, computes the right number of bytes written and allows easy computation of the number of bytes verified. This commit also changes the strategy for the default verification after writing to a chip memory, so that the input file only needs reading once thus enabling successful verification of stdin input files. Other, minor changes: - Improving the grammar of AVRDUDE output, eg, 1 byte written instead of 1 bytes written - Better description of the input file structure in terms of its sections, the interval it spans, the number of pages, the number of padding bytes in pages, and the number of actually cut off trailing 0xff bytes for flash - Printing <stdin> or <stdout> instead of - in the -U routines - Option -V no longer needs to be specified before option -U in order to work As an aside this commit also provides useful helper functions for printing plural(), inname(), outname() and interval() all of which return strings fit for printing. $ avrdude -qp ATmega2560 -c usbtiny -U blink-mega2560+lext-test.hex avrdude: AVR device initialized and ready to accept instructions avrdude: Device signature = 0x1e9801 (probably m2560) avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed To disable this feature, specify the -D option. avrdude: erasing chip avrdude: input file blink-mega2560+lext-test.hex auto detected as Intel Hex avrdude: reading input file blink-mega2560+lext-test.hex for flash with 1346 bytes in 4 sections within [0, 0x3106d] using 7 pages and 446 pad bytes avrdude: writing 1346 bytes flash ... avrdude: 1346 bytes of flash written avrdude: verifying flash memory against blink-mega2560+lext-test.hex avrdude: 1346 bytes of flash verified avrdude done. Thank you. $ avrdude -qp ATmega328P -c usb-bub-ii -U sketch-ending-in-ff.hex avrdude: AVR device initialized and ready to accept instructions avrdude: Device signature = 0x1e950f (probably m328p) avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed To disable this feature, specify the -D option. avrdude: erasing chip avrdude: input file sketch-ending-in-ff.hex auto detected as Intel Hex avrdude: reading input file sketch-ending-in-ff.hex for flash with 2160 bytes in 1 section within [0, 0x888] using 17 pages and 16 pad bytes, cutting off 25 trailing 0xff bytes avrdude: writing 2160 bytes flash ... avrdude: 2160 bytes of flash written avrdude: verifying flash memory against sketch-ending-in-ff.hex avrdude: 2185 bytes of flash verified avrdude done. Thank you. $ echo "Hello, world..." | avrdude -qp ATmega328P -c ... -U eeprom:w:-:r avrdude: AVR device initialized and ready to accept instructions avrdude: Device signature = 0x1e950f (probably m328p) avrdude: reading input file <stdin> for eeprom avrdude: writing 16 bytes eeprom ... avrdude: 16 bytes of eeprom written avrdude: verifying eeprom memory against <stdin> avrdude: 16 bytes of eeprom verified avrdude done. Thank you.
$ avrdude -qp ATmega2560 -c usbtiny -U flesh:w:blink-mega2560+lext-test.hex:i avrdude: unknown memory type flesh avrdude: error parsing update operation 'flesh:w:blink-mega2560+lext-test.hex:i'
$ avrdude -qp m8 -c ... -U efuse:w:0xff:m && echo OK avrdude: AVR device initialized and ready to accept instructions avrdude: skipping -U efuse:... as memory not defined for part ATmega8 avrdude done. Thank you. OK
Thanks for bringing #1036 into this PR! However, It doesn't continue when an invalid memory is specified:
|
This PR is permissive for known memories that do not exist in this part, eg,
Notice the However, this PR also detects typos in memories at parse time and rejects the whole command if so. A typo is a memory that does not exist in any of the parts in
I could not think of a good use case for being permissive for typos in memories (whilst I accept there are good use cases for allowing sth like |
I see that now PR #1036 has been incorporated into this new PR.
I will agree with this.
That seems to be a good enhancement idea. Thanks. Testing results are good (to see if it can replace #1036 or not).
|
Great, I didn't realize that. However, it looks like the way this is implemented, Avrdude can't support memories with other names that specified in the const char *avr_mem_order[100] = {
"eeprom", "flash", "application", "apptable",
"boot", "lfuse", "hfuse", "efuse",
"fuse", "fuse0", "wdtcfg", "fuse1",
"bodcfg", "fuse2", "osccfg", "fuse3",
"fuse4", "tcd0cfg", "fuse5", "syscfg0",
"fuse6", "syscfg1", "fuse7", "append",
"codesize", "fuse8", "fuse9", "bootend",
"bootsize", "fuses", "lock", "lockbits",
"tempsense", "signature", "prodsig", "sernum",
"calibration", "osccal16", "osccal20", "osc16err",
"osc20err", "usersig", "userrow", "data",
}; As a test, I added this "new" fuse to the ATmega8 entry in avrdude.conf to see how it would handle new names. It's identical to
Shouldn't Avrdude be able to accept memories that's present in avrdude.conf? |
Yes, it should and (against my expectation) it doesn't. The reason is that I will move the check of |
Another detail that this PR "breaks" is the way you can use only part of a memorable name. AFAIK this is undocumented behavior, but I stumbled across this "feature" when working on memory name aliases. I don't think this will cause any issues. However, this "feature" prevented us from adding a memory name that was a substring of another name. Without this PR:
With this PR:
|
The check for typos in -U memory names against a list of known memory names now happens after the config files have been read, so newly declared memory names can be considered. This commit also weakens the check against existence of a known memory: it is now sufficent for a name to pass when it could be the initial string of any known memory of any part. Any -U memory that cannot possibly be matched up with a known memory is considered a typo and leads to an exit before the programmer is opened. This to protect users from typos that leave a device partially programmed. When every -U memory name might be matching one of the known memories, the programming is attempted. If the part to be programmed turns out not to have a particular -U memory, AVRDUDE warns the user and skips this -U update. This to support unifying interfaces that call AVRDUDE with potentially more memories than the actual part has (eg, efuse on ATmega8).
Thanks, @MCUdude, important insight and easy to fix: I replaced I also moved the typo check to after the config files have been read, so new memory names are actually considered. BTW, rwcheck.c is a draft for whether a given filename might be readable or writeable. This to check all |
@stefanrueger
|
The latest version seems to be fine now with PR #1036.
|
@MCUdude Thanks. I did not know that avrdude got so many memory types.
|
Thanks @stefanrueger! Now the PR works well with initial names like
|
It is possible to make AVRDUDE accept a memory name (eg, oscal16) as the correct one even if a longer memory name with the same start exists (eg, oscal16err). The three Lines 562 to 565 in 5f5002e
I would insert the lines
after In other words, specifying the full memory name would always be fine (no matter how the others are called), but in absence of that any shorter unique start is also accepted. |
IMO, this would definitely be the best option. This lets us name memories as we want, and not have to deal with Avrdude's naming quirks. |
(This is a recreated PR #1051 owing to a rebase gone astray.)
This PR fixes Issues #1044, #441 and #1005, and solves PR #1036
Counting the number of bytes written to a memory and/or verified is not trivial owing to potential holes in the input file and to potential trailing 0xff bytes in flash memory that are not written per default (but see -A). The new function memstats(), which is best called just after an input file has been read into mem->buf/mem->tags, computes the right number of bytes written and allows easy computation of the number of bytes verified.
This PR also changes the strategy for the default verification after writing to a chip memory, so that the input file only needs reading once thus enabling successful verification of stdin input files.
Other changes:
-U
memory is unknown for all parts-U
updates if memory is unknown for this part<stdin>
or<stdout>
instead of-
in the update routinesAs an aside this PR also provides useful helper functions for printing plural(), inname(), outname() and interval() all of which return strings fit for printing.
Examples using blink-mega2560+lext-test.hex and sketch-ending-in-ff.hex: