Skip to content

Commit c7bbebc

Browse files
committed
add additional checks to program_isp, tidy up page erase sequence
1 parent 12b5d4c commit c7bbebc

File tree

1 file changed

+11
-12
lines changed
  • hardware/pinoccio/avr/bootloaders/STK500RFR2/src

1 file changed

+11
-12
lines changed

hardware/pinoccio/avr/bootloaders/STK500RFR2/src/main.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,20 +1122,19 @@ int main(void)
11221122
if ( msgBuffer[0] == CMD_PROGRAM_FLASH_ISP )
11231123
{
11241124
// erase only main section (bootloader protection)
1125-
if (address + size <= APP_END )
1125+
if ((!(size % 2)) && (!(address % SPM_PAGESIZE)) && (size <= SPM_PAGESIZE) && (address + size <= APP_END))
11261126
{
1127-
if (address % SPM_PAGESIZE == 0)
1128-
{
1129-
boot_page_erase(address); // Perform page erase
1130-
boot_spm_busy_wait(); // Wait until the memory is erased.
1131-
}
1132-
1127+
1128+
boot_page_erase(address); // Perform page erase
1129+
boot_spm_busy_wait(); // Wait until the memory is erased.
1130+
11331131
/* Write FLASH */
11341132
tempAddress = address;
11351133
do {
1134+
11361135
lowByte = *p++;
11371136
highByte = *p++;
1138-
1137+
11391138
data = (highByte << 8) | lowByte;
11401139
boot_page_fill(tempAddress,data);
11411140

@@ -1162,10 +1161,10 @@ int main(void)
11621161
uint16_t ii = address >> 1;
11631162
/* write EEPROM */
11641163
while (size) {
1165-
eeprom_write_byte((uint8_t*)ii, *p++);
1166-
address+=2; // Select next EEPROM byte
1167-
ii++;
1168-
size--;
1164+
eeprom_write_byte((uint8_t*)ii, *p++);
1165+
address+=2; // Select next EEPROM byte
1166+
ii++;
1167+
size--;
11691168
}
11701169
msgLength = 2;
11711170
msgBuffer[1] = STATUS_CMD_OK;

0 commit comments

Comments
 (0)