From: Anonymous
Bug-Report: dfu-util 0.10 is broken (flashing DFuse-Files (.dfu) not working)
Error-Message: dfu-util: Error File ID xxxx:011a does not match device (xxxx:df11 or 0483:df11)
Description: It seems dfu-util 0.10 is not able to parsing the correct vendor-id from the DFuse-File (.dfu)
If you compare the first four bytes of the CRC (infos from dfu-suffix) with the parsed vendor-id,
it will match: Match vendor ID from file: xxxx
With other words, dfu-util 0.10 is parsing the first four bytes of the CRC instead of the vendor-id from the DFuse-File (.dfu). Flashing will be denied, because there is no Match.
I hope this Info will help the developers for fixing the new version dfu-util with DFuse-Files (.dfu)
Anonymous
I stepped through it in gdb and found that all the way through
dfu_load_file(), everything seems fine, but as soon as that function exits, thedfu_filestruct fromsize.prefixonwards gets magically shifted over by four bytes. In other words, immediately before the end ofdfu_load_file(), the struct is correct, and immediately afterwards, it is somehow incorrect.I believe this has something to do with commit
4a18c61, in which the type of size.total was changed frominttooff_t. Reverting it seems to resolve the issue.Thanks for digging deeper into this. It looks like a mismatch between the struct types which shouldn't happen because it is the same, defined in dfu_file.h. Are you sure you are rebuilding everything from scratch and that there is no stale main.o or something? What platform is this (full details please), and what build environment do you use?
In gdb you can use
ptype /o fileinside both main() and dfu_load_file() to see the field sizes and if there is a difference. Note that I am not sure if gdb will show a difference if there is a mismatch. Maybeinfo scope mainandinfo scope dfu_load_filetells something but in one case "file" is a pointer and not the struct itself.Last edit: Tormod Volden 2021-02-04
Indeed,
ptype /o fileshowssize.totalat 4 bytes beforedfu_load_file(), and 8 bytes once I step in.I'm on Windows 10, building inside MSYS2 with GCC 10.2.0, simply following the instructions in the INSTALL file. Definitely no stale object files.
The bug does not appear to be present in the macOS (Homebrew) build, though I'm not sure what version it was built with.
I figured it out! The issue is that main.c does not include config.h, because (at least in mingw)
_FILE_OFFSET_BITSis defined to 64. Oddly though, nowoff_tis only 4 bytes wide instead of the 8 that I would expect from the above define... but at least they match now.Actually, looks like config.h is included through portable.h, but it's included too late for the
_FILE_OFFSET_BITSdefine to make any difference. Simply moving it up gives an 8 byteoff_tin both scopes now:Ah, great! Right, this is the newly introduced _FILE_OFFSET_BITS fun which affects everywhere off_t end up being used, it all makes sense now. portable.h is getting a bit tricky because most of it should be evaluated early (only based on config.h) but for instance the O_BINARY part should probably only be checked after system headers. I think we need to properly add the early ifdef HAVE_CONFIG stanza to practically all files because they end up including dfu_file.h one way or another.
Should be fixed in master now, with commit ff17547.
Thanks again for chasing this down.