I just discovered a typo in a bootloader application I wrote several years ago. I haven't seen any problems as a result, but I want to understand the implications better.
The bootloader uses a few bytes at the top of eeprom memory to blink an LED. If the application failed to load, the bootstrap codes blinks the LED as defined by the blink code.
Since the bootloader and application it loads are compiled separately, I had to hard code the addresses at the top of eeprom memory to use (at least that's the only way I could figure out how to do it).
The chip is an atmega328p which has 1K eeprom. So, the last byte of eeprom is 0x3ff.
Here's what I coded:
#define ADDR_APP_RUN (uint8_t *)0x3ff #define ADDR_BLINK_CODE (uint8_t *)0x3fe #define ADDR_BLINK_COUNT (uint8_t *)0xefd
The 0xefd for ADDR_BLINK_COUNT is a typo. It should have been 0x3fd.
The same code fragment is used in both the bootstrap loader and the application(s) it loads. After an application is loaded, it does things like check for expired license, clock tampering, etc, and writes a blink code to eeprom if something is not right.
This all seems to work (and has for several years), but I'm thinking the app is writing the "blink count" somewhere in the middle of eeprom memory, instead of 0x3fd. Maybe I haven't gotten "bit", since if a blink code gets written, the application will have to be reloaded anyway.
But, I'd like to know where the byte is actually getting written. Will the higher order bits of the address just get truncated somewhere in the eeprom_write_byte and eeprom_read_byte code? Or will the address be modulo 1K? Something else?
Thanks for any insight!