cavravrdude

How to get program's version number through 10-pin ISP-connector with avrdude?


I'm making a printed circuit board and within the board there is a 10-pin ISP connector attached to the AVR microcontroller. So I can flash new code to the AVR.

I have several of these same boards, but with different code in it. I don't want to flash it every time I need to know what's inside that particular AVR. I just want to extract the version number of that code somehow through avrdude.
What's the easiest way to do this?


Solution

  • If you can read the content of the flash via a connector, you can have your build process compile and link that flash content in a well defined format which contains the version number, or some other version information.

    Then you can read using avrdude and write your own program to parse (part of) the content of the flash, and then maybe script that. This helps avoid cases where your EEPROM contains one version, but the Flash already contains a new one, or vice versa.

    You get bonus points for

    You need to extend your existing build system to do all the necessary steps. Those might involve linker scripts, linker sections, C or assembly language sources, and other things.

    Going on my AVR experience using an avr-libc and avr-gcc based toolchain, I would start by adding something like

            jmp     skip_version_number
    
            .global version_number
            .type   version_number, @object
            .balign 8
    version_number:
            .quad   0xdeadcafef00d0001
            .asciz  VERSION_STRING
            .asciz  GIT_BRANCH_NAME
            .asciz  GIT_DIRTY_FLAG
            .asciz  ""
            .size   version_number, . - version_number
    
    skip_version_number:
    

    to one of the .initN sections:

    Then verify the result from the disassembly dump and the map file.

    Adding the checksum might involve generating a binary file for the payload at build time, then calculate that file's checksum as a separate binary file, and replacing the above content definitions with

            .balign 8
    version_number:
            .incbin "version_number.bin"
            .balign 8
            .incbin "version_number_checksum.bin"
            .size   version_number, . - version_number
    

    This can be made arbitrarily complex, but I hope this gives a few ideas.