Disallow writing running firmware (#5208)

Overwriting running firmware leads to crash and incompletely written firmware
This commit is contained in:
Arne Schwabe
2017-09-12 18:49:40 +02:00
committed by Bertrand Songis
parent 360a521f11
commit 7e21e13ec9
@@ -464,7 +464,11 @@ const FATDirEntry_t g_DIRroot[16] =
{ {
{ 'F', 'I', 'R', 'M', 'W', 'A', 'R', 'E'}, { 'F', 'I', 'R', 'M', 'W', 'A', 'R', 'E'},
{ 'B', 'I', 'N'}, { 'B', 'I', 'N'},
0x20, // Archive #if defined(BOOT)
0x20, // Archive
#else
0x21, // Readonly+Archive
#endif
0x00, 0x00,
0x3E, 0x3E,
0xA301, 0xA301,
@@ -739,6 +743,9 @@ int32_t fat12Write(const uint8_t * buffer, uint16_t sector, uint16_t count)
} }
} }
else if (sector < 3 + (EEPROM_SIZE/BLOCK_SIZE) + (FLASHSIZE/BLOCK_SIZE)) { else if (sector < 3 + (EEPROM_SIZE/BLOCK_SIZE) + (FLASHSIZE/BLOCK_SIZE)) {
#if !defined(BOOT) // Don't allow overwrite of running firmware
return -1;
#else
// firmware // firmware
uint32_t address; uint32_t address;
address = sector - 3 - (EEPROM_SIZE/BLOCK_SIZE); address = sector - 3 - (EEPROM_SIZE/BLOCK_SIZE);
@@ -765,6 +772,7 @@ int32_t fat12Write(const uint8_t * buffer, uint16_t sector, uint16_t count)
operation = FATWRITE_NONE; operation = FATWRITE_NONE;
} }
} }
#endif
} }
return 0 ; return 0 ;
} }