Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions optiboot/bootloaders/optiboot/optiboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,15 @@
#define OPTIBOOT_CUSTOMVER 0
#endif

unsigned const int __attribute__((section(".version")))
optiboot_version = 256*(OPTIBOOT_MAJVER + OPTIBOOT_CUSTOMVER) + OPTIBOOT_MINVER;
struct OptibootVersion {
unsigned char minor; // minor first, for backward compatible memory layout
unsigned char major;
} __attribute__((packed));
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The packed attribute might be dropped, as avr-gcc packs everything anyway? Please advise...

const struct OptibootVersion __attribute__((section(".version")))
optiboot_version = {
.major = OPTIBOOT_MAJVER + OPTIBOOT_CUSTOMVER,
.minor = OPTIBOOT_MINVER
};


#define __AVR_LIBC_DEPRECATED_ENABLE__ 1 // don't poison MCUSR on some chips
Expand Down Expand Up @@ -929,12 +936,11 @@ int main(void) {
verifySpace();
/*
* Send optiboot version as "SW version"
* Note that the references to memory are optimized away.
*/
if (which == STK_SW_MINOR) {
putch(optiboot_version & 0xFF);
putch(pgm_read_byte_near(&optiboot_version.minor));
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alternatively, much easier fix is:

      if (which == STK_SW_MINOR) {
        putch(OPTIBOOT_MINVER);
      } else if (which == STK_SW_MAJOR) {
        putch(OPTIBOOT_MAJVER + OPTIBOOT_CUSTOMVER);

But then the question is why we need the optiboot_version in the .version section at all?

} else if (which == STK_SW_MAJOR) {
putch(optiboot_version >> 8);
putch(pgm_read_byte_near(&optiboot_version.major));
} else {
/*
* GET PARAMETER returns a generic 0x03 reply for
Expand Down