Firmware control in Bootloader (when flashed from massstorage)

This commit is contained in:
bsongis
2014-04-10 13:18:07 +02:00
parent 1b34d178b0
commit aec13e3e97
+14 -8
View File
@@ -715,7 +715,8 @@ int32_t fat12Read( uint8_t *buffer, uint16_t sector, uint16_t count )
int32_t fat12Write(const uint8_t *buffer, uint16_t sector, uint32_t count ) int32_t fat12Write(const uint8_t *buffer, uint16_t sector, uint32_t count )
{ {
static int offset = 0; static uint8_t eepromOffset = 0;
static uint8_t firmwareAllowed = 0;
TRACE("FAT12 Write(sector=%d, count=%d)", sector, count); TRACE("FAT12 Write(sector=%d, count=%d)", sector, count);
@@ -724,19 +725,19 @@ int32_t fat12Write(const uint8_t *buffer, uint16_t sector, uint32_t count )
} }
else if (sector < 3 + (EESIZE/BLOCKSIZE)) { else if (sector < 3 + (EESIZE/BLOCKSIZE)) {
while (count) { while (count) {
if (offset == 0 && isEepromStart(buffer)) { if (eepromOffset == 0 && isEepromStart(buffer)) {
TRACE("EEPROM start found in sector %d", sector); TRACE("EEPROM start found in sector %d", sector);
offset = sector; eepromOffset = sector;
} }
if (offset && sector >= offset && (sector-offset) < EESIZE/BLOCKSIZE) { if (eepromOffset && sector >= eepromOffset && (sector-eepromOffset) < EESIZE/BLOCKSIZE) {
eeWriteBlockCmp((uint8_t *)buffer, (sector-offset)*BLOCKSIZE, BLOCKSIZE); eeWriteBlockCmp((uint8_t *)buffer, (sector-eepromOffset)*BLOCKSIZE, BLOCKSIZE);
} }
buffer += BLOCKSIZE; buffer += BLOCKSIZE;
sector++; sector++;
count--; count--;
if (sector-offset >= EESIZE/BLOCKSIZE) { if (sector-eepromOffset >= EESIZE/BLOCKSIZE) {
TRACE("EEPROM end written at sector %d", sector-1); TRACE("EEPROM end written at sector %d", sector-1);
offset = 0; eepromOffset = 0;
} }
} }
} }
@@ -750,7 +751,12 @@ int32_t fat12Write(const uint8_t *buffer, uint16_t sector, uint32_t count )
while (count) { while (count) {
for (uint32_t i=0; i<BLOCKSIZE/FLASH_PAGESIZE; i++) { for (uint32_t i=0; i<BLOCKSIZE/FLASH_PAGESIZE; i++) {
if (address >= FIRMWARE_ADDRESS+BOOTLOADER_SIZE/*protect bootloader*/ && address <= FIRMWARE_ADDRESS+FLASHSIZE-FLASH_PAGESIZE) { if (address >= FIRMWARE_ADDRESS+BOOTLOADER_SIZE/*protect bootloader*/ && address <= FIRMWARE_ADDRESS+FLASHSIZE-FLASH_PAGESIZE) {
writeFlash((uint32_t *)address, (uint32_t *)buffer); if (address == FIRMWARE_ADDRESS+BOOTLOADER_SIZE) {
firmwareAllowed = isFirmwareStart(buffer);
}
if (firmwareAllowed) {
writeFlash((uint32_t *)address, (uint32_t *)buffer);
}
} }
address += FLASH_PAGESIZE; address += FLASH_PAGESIZE;
buffer += FLASH_PAGESIZE; buffer += FLASH_PAGESIZE;