feat: only allow flash when target matches (#4770)

This commit is contained in:
3djc
2024-03-25 10:42:29 +10:00
committed by GitHub
parent d055b8045d
commit 4628ccce9e
5 changed files with 88 additions and 45 deletions
@@ -52,6 +52,19 @@ void bootloaderDrawFilename(const char *str, uint8_t line, bool selected)
bootloaderDrawMsg(INDENT_WIDTH, str, line, selected);
}
bool checkFirmwareFlavor(const char * vers)
{
if (strncmp(vers,FLAVOUR, sizeof(FLAVOUR) - 1) != 0)
return false;
char * tmp = (char *) vers;
while (*tmp != '-') tmp++;
if ((tmp - vers) != (sizeof(FLAVOUR) - 1))
return false;
return true;
}
void bootloaderDrawScreen(BootloaderState st, int opt, const char *str)
{
lcdClear();
@@ -98,16 +111,24 @@ void bootloaderDrawScreen(BootloaderState st, int opt, const char *str)
bootloaderDrawMsg(0, TR_BL_INVALID_EEPROM, 2, false);
}
else if (opt == FC_OK) {
bool flavorCheck = false;
if (memoryType == MEM_FLASH) {
const char * vers = getFirmwareVersion((const char *)Block_buffer);
#if LCD_W < 212
// Remove "edgetx-" from string
if (strncmp(vers, "edgetx-", 7) == 0)
vers += 7;
flavorCheck = checkFirmwareFlavor(vers);
#else
flavorCheck = checkFirmwareFlavor(vers + 7);
#endif
bootloaderDrawMsg(INDENT_WIDTH, vers, 0, false);
}
bootloaderDrawMsg(0, TR_BL_HOLD_ENTER_TO_START, 2, false);
if (flavorCheck)
bootloaderDrawMsg(0, TR_BL_HOLD_ENTER_TO_START, 2, false);
else
bootloaderDrawMsg(0, TR_BL_INVALID_FIRMWARE, 2, false);
}
}
else if (st == ST_FLASHING) {