log.printf("Image: %s %s\n", header->src, header->time);
//assert(sizeof(IMAGE)/sizeof(data_section_t) == 2); // two sections
- enum { PASSWORD_LEN = BSL::PASSWORD_LEN };
- uint8_t password_data[PASSWORD_LEN];
+ enum { PASS_LEN = BSL::PASSWORD_LEN };
+ enum { PASS_ADDR = 0x10000 - PASS_LEN };
+ uint8_t password_data[PASS_LEN];
const uint8_t * password = 0; // no password -> force erase
if (!force_erase) {
if (header->sec_number == 2) {
// old linker -> two sections: text + vector table
// select last part of vector table
- if ((IMAGE[1].address == (0x10000 - 0x20)) && (IMAGE[1].length == 0x20)) {
+ if ((IMAGE[1].address == PASS_ADDR) && (IMAGE[1].length == 0x20)) {
password = IMAGE[1].data;
} else
if ((IMAGE[1].address == (0x10000 - 0x40)) && (IMAGE[1].length == 0x40)) {
- password = &IMAGE[1].data[0x40 - PASSWORD_LEN];
+ password = &IMAGE[1].data[0x40 - PASS_LEN];
} else
if ((IMAGE[1].address == (0x10000 - 0x80)) && (IMAGE[1].length == 0x80)) {
- password = &IMAGE[1].data[0x80 - PASSWORD_LEN];
+ password = &IMAGE[1].data[0x80 - PASS_LEN];
} else
log.printf("no vector table?\n");
} else {
memset(password_data, 0xFF, sizeof(password_data));
for(unsigned i=0; i<header->sec_number; ++i) {
const struct data_section_t * sec = &header->sec[i];
- if ( (sec->address < (0x10000 - PASSWORD_LEN)) ||
- (sec->address > 0x10000) )
+ if (sec->address > (PASS_ADDR + PASS_LEN))
continue;
- unsigned offset = sec->address - (0x10000 - PASSWORD_LEN);
- assert(offset + sec->length <= PASSWORD_LEN);
+ if (sec->address < PASS_ADDR) {
+ assert((sec->address + sec->length) <= PASS_ADDR);
+ continue;
+ }
+ unsigned offset = sec->address - PASS_ADDR;
+ assert(offset + sec->length <= PASS_LEN);
memcpy(&password_data[offset], sec->data, sec->length);
}
password = password_data;