Verifying Arduino machine instructions

Hello,

Hoping this is the right place for this question -- which is more about the IDE itself than programming per se.

The standard IDE can be set to verify programming written to the device, therefore it has some way of looking at the machine instructions in place on the device. The question is: is there a way to non-destructively have it compare a device's machine instructions with those that would be generated from the code currently displayed? In other words, suppose I have a Nano that I programmed 6 months ago. I've written several code versions, some experimental, but I've forgotten which one has been used to program the device. Is there a way to determining which of my versions corresponds to the instructions resident on the device? If the standard IDE can't do this, is there another way?

Thanks,
Steve

Yup. Use avrdude to read the Flash. Compare that dot-hex file to each dot-hex file built by the IDE.

Bear in mind there is flexibility in the dot-hex file format. The file downloaded may not be directly comparable to one built by the IDE.

You will probably need to make sure you use the exact same version of the IDE and of all the library code as was originally used, otherwise the resulting code could be quite different.

Thanks for the replies. I have occasionally run across avrdude in my reading but know zero about it. I guess it's time to learn. I ran across a Lady Ada tutorial which looks interesting, and I'd be glad to hear of others.

I'm sort of surprised that this function isn't built into the Arduino IDE, though I suppose there wouldn't be much demand for it.

The issue over IDE version is important, since I probably have different versions on my laptop and every one of the four RasPis that I have running... :confused:

Thanks...
S.

Even with the same version, it can be tricky. The hex file that is uploaded contains 16 data bytes per line and (from memory) the file that you get back from avrdude only contains 8 data bytes per line.

And that is using the same IDE and tools that come with it.

sterretje:
Even with the same version, it can be tricky. The hex file that is uploaded contains 16 data bytes per line and (from memory) the file that you get back from avrdude only contains 8 data bytes per line.

And that is using the same IDE and tools that come with it.

Another problem that can occur is the hex file from the IDE may skip over unused sections of memory, and will not contain data for the entire flash memory or bootloader section.

If the OP has a spare Nano, the easiest thing to do would be to upload the code then read it back, that would eliminate any file format differences.

david_2018:
If the OP has a spare Nano, the easiest thing to do would be to upload the code then read it back, that would eliminate any file format differences.

I have spare Nanos. It sounds as if the preferred approach will be to load each candidate sketch onto the Nano and then read it back using avrdude, then compare each of these files with the file lifted from the operating Nano. That sounds reasonable ... but unfortunately I don't recall what version of the IDE was used to program the "original" device and if it even still resides on any of my machines. I guess I can still hope for a match, but lack of a match won't tell me anything.
Thanks for the feedback -- it is appreciated.
S.

For the future there are ways you can get over this - such as having a print statement in your code that prints the version number , if you connect a monitor

Or you can write on a label on the processor

Or you can flash the built in led with a code

Or keep good records of what you have done in a separate notebook.

hammy:
For the future there are ways you can get over this - such as having a print statement in your code that prints the version number , if you connect a monitor

Or you can write on a label on the processor

Or you can flash the built in led with a code

Or keep good records of what you have done in a separate notebook.

Yes, absolutely. In fact, after realizing the problem I have begun keeping much better records. I have made every attempt to follow the first suggestion here -- a line of code which will print the version number to a serial monitor -- but of course that relies on my remembering to update that line of code with each version. That memory trick is a work in progress... :slight_smile:

of course that relies on my remembering to update that line of code with each version. That memory trick is a work in progress...

You could perhaps log an autogenerated string using the cpp TIME and DATE macros?

That does, however, merely kick the can down the road somewhat, since you still need some way of recalling what you actually did on that date/time.

More sophisticated still would be a build-process hack in order to insert the current hash or revision number from your SCM of choice (git or whatever). Easy enough using makefiles or what have you, but I've no idea if the Arduino IDE supports such a feature.

tomparkin:
You could perhaps log an autogenerated string using the cpp TIME and DATE macros?

There is also FILE for the full path and filename, although at that point you are using considerable memory storing all this information.

david_2018:
There is also FILE for the full path and filename, although at that point you are using considerable memory storing all this information.

As a matter of fact, so much do I detest the Arduino IDE's bizarre insistence that all .ino files be stored in a subdirectory of the same name, that I don't even save or open files from the IDE. Instead, I copy the entire text to the Linux clipboard and save it into a file, and vice versa to "open" a file. I have a couple of quick scripts to do this. But it does mean that the IDE has no idea what any filenames are.
(Does anyone know why the IDE has that weird requirement?)
Your other suggestion is interesting; thanks. I will give some thought into implementing this.
S.

.....my mistake.... the other suggestion was tomparkin's.... sorry for the error.
S.

srturner:
Instead, I copy the entire text to the Linux clipboard and save it into a file, and vice versa to "open" a file. I have a couple of quick scripts to do this.

I'm not a massive fan of the Arduino IDE either -- it's too far from my normal workflow (terminal + vim) to be comfortable. I actually use debian's arduino-mk package for building. The Arduino libraries it bundles are quite old unfortunately due to some licensing issue, but the makefile-based build process is good.

tomparkin:
I'm not a massive fan of the Arduino IDE either -- it's too far from my normal workflow (terminal + vim) to be comfortable. I actually use debian's arduino-mk package for building. The Arduino libraries it bundles are quite old unfortunately due to some licensing issue, but the makefile-based build process is good.

Well that's interesting. Another thing to add to my to-do pile. I know what you mean by workflow; I do everything possible in a command window in both Linux and Windows. That said, I actually do like the normal editing functions of the standard IDE, and the auto-format function is good at pointing out semicolon and bracketing goofs. I just cannot stand its silly and petulant insistence on the folder structure.
S.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.