1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-23 00:05:17 +03:00

[X7] Bootloader fix

This commit is contained in:
Bertrand Songis 2019-05-13 14:20:44 +02:00
parent 8f6fc7cd50
commit 9c04f564df
4 changed files with 166 additions and 180 deletions

View file

@ -53,11 +53,7 @@ const uint8_t bootloaderVersion[] __attribute__ ((section(".version"), used)) =
volatile rotenc_t rotencValue = 0; volatile rotenc_t rotencValue = 0;
#endif #endif
/*---------------------------------------------------------------------------- uint32_t firmwareSize;
* Local variables
*----------------------------------------------------------------------------*/
uint32_t FirmwareSize;
uint32_t firmwareAddress = FIRMWARE_ADDRESS; uint32_t firmwareAddress = FIRMWARE_ADDRESS;
uint32_t firmwareWritten = 0; uint32_t firmwareWritten = 0;
@ -66,16 +62,16 @@ uint32_t eepromAddress = 0;
uint32_t eepromWritten = 0; uint32_t eepromWritten = 0;
#endif #endif
volatile uint8_t Tenms = 1; volatile uint8_t tenms = 1;
FlashCheckRes Valid; FlashCheckRes valid;
MemoryType memoryType; MemoryType memoryType;
uint32_t unlocked = 0; uint32_t unlocked = 0;
void interrupt10ms(void) void interrupt10ms(void)
{ {
Tenms |= 1; // 10 mS has passed tenms |= 1; // 10 mS has passed
uint8_t index = 0; uint8_t index = 0;
uint8_t in = readKeys(); uint8_t in = readKeys();
@ -145,10 +141,9 @@ FlashCheckRes checkFlashFile(unsigned int index, FlashCheckRes res)
int menuFlashFile(uint32_t index, event_t event) int menuFlashFile(uint32_t index, event_t event)
{ {
Valid = checkFlashFile(index, Valid); valid = checkFlashFile(index, valid);
if (Valid == FC_ERROR) {
if (valid == FC_ERROR) {
if (event == EVT_KEY_BREAK(KEY_EXIT) || event == EVT_KEY_BREAK(KEY_ENTER)) if (event == EVT_KEY_BREAK(KEY_EXIT) || event == EVT_KEY_BREAK(KEY_ENTER))
return 0; return 0;
@ -211,7 +206,7 @@ int main()
SERIAL_RCC_APB1Periph | SERIAL_RCC_APB1Periph |
SD_RCC_APB1Periph, ENABLE); SD_RCC_APB1Periph, ENABLE);
RCC_APB2PeriphClockCmd(LCD_RCC_APB2Periph | BACKLIGHT_RCC_APB2Periph, ENABLE); RCC_APB2PeriphClockCmd(LCD_RCC_APB2Periph | BACKLIGHT_RCC_APB2Periph | RCC_APB2Periph_SYSCFG, ENABLE);
keysInit(); keysInit();
@ -267,8 +262,8 @@ int main()
for (;;) { for (;;) {
wdt_reset(); wdt_reset();
if (Tenms) { if (tenms) {
Tenms = 0; tenms = 0;
if (state != ST_USB) { if (state != ST_USB) {
if (usbPlugged()) { if (usbPlugged()) {
@ -332,7 +327,6 @@ int main()
} }
} }
else if (state == ST_DIR_CHECK) { else if (state == ST_DIR_CHECK) {
fr = openBinDir(memoryType); fr = openBinDir(memoryType);
if (fr == FR_OK) { if (fr == FR_OK) {
@ -353,7 +347,6 @@ int main()
} }
if (state == ST_FILE_LIST) { if (state == ST_FILE_LIST) {
uint32_t limit = MAX_NAMES_ON_SCREEN; uint32_t limit = MAX_NAMES_ON_SCREEN;
if (nameCount < limit) { if (nameCount < limit) {
limit = nameCount; limit = nameCount;
@ -391,7 +384,7 @@ int main()
if (event == EVT_KEY_BREAK(KEY_ENTER)) { if (event == EVT_KEY_BREAK(KEY_ENTER)) {
// Select file to flash // Select file to flash
state = ST_FLASH_CHECK; state = ST_FLASH_CHECK;
Valid = FC_UNCHECKED; valid = FC_UNCHECKED;
continue; continue;
} }
else if (event == EVT_KEY_BREAK(KEY_EXIT)) { else if (event == EVT_KEY_BREAK(KEY_EXIT)) {
@ -401,8 +394,7 @@ int main()
} }
} }
else if (state == ST_FLASH_CHECK) { else if (state == ST_FLASH_CHECK) {
bootloaderDrawScreen(state, valid, binFiles[vpos].name);
bootloaderDrawScreen(state, Valid, binFiles[vpos].name);
int result = menuFlashFile(vpos, event); int result = menuFlashFile(vpos, event);
if (result == 0) { if (result == 0) {
@ -413,7 +405,7 @@ int main()
// confirmed // confirmed
if (memoryType == MEM_FLASH) { if (memoryType == MEM_FLASH) {
FirmwareSize = binFiles[vpos].size - BOOTLOADER_SIZE; firmwareSize = binFiles[vpos].size - BOOTLOADER_SIZE;
firmwareAddress = FIRMWARE_ADDRESS + BOOTLOADER_SIZE; firmwareAddress = FIRMWARE_ADDRESS + BOOTLOADER_SIZE;
firmwareWritten = 0; firmwareWritten = 0;
} }
@ -438,7 +430,7 @@ int main()
if (memoryType == MEM_FLASH) { if (memoryType == MEM_FLASH) {
flashWriteBlock(); flashWriteBlock();
firmwareWritten += sizeof(Block_buffer); firmwareWritten += sizeof(Block_buffer);
progress = (100*firmwareWritten) / FirmwareSize; progress = (100 * firmwareWritten) / firmwareSize;
} }
#if defined(EEPROM) #if defined(EEPROM)
else { else {
@ -454,13 +446,11 @@ int main()
if (BlockCount == 0) { if (BlockCount == 0) {
state = ST_FLASH_DONE; // EOF state = ST_FLASH_DONE; // EOF
} }
else if ((memoryType == MEM_FLASH) && else if (memoryType == MEM_FLASH && firmwareWritten >= FLASHSIZE - BOOTLOADER_SIZE) {
(firmwareWritten >= FLASHSIZE - BOOTLOADER_SIZE)) {
state = ST_FLASH_DONE; // Backstop state = ST_FLASH_DONE; // Backstop
} }
#if defined(EEPROM) #if defined(EEPROM)
else if ((memoryType == MEM_EEPROM) && else if (memoryType == MEM_EEPROM && eepromWritten >= EEPROM_SIZE) {
(eepromWritten >= EEPROM_SIZE)) {
state = ST_FLASH_DONE; // Backstop state = ST_FLASH_DONE; // Backstop
} }
#endif #endif
@ -482,7 +472,6 @@ int main()
if (event == EVT_KEY_LONG(KEY_EXIT)) { if (event == EVT_KEY_LONG(KEY_EXIT)) {
// Start the main application // Start the main application
state = ST_REBOOT; state = ST_REBOOT;
} }
@ -508,7 +497,6 @@ int main()
} }
if (state == ST_REBOOT) { if (state == ST_REBOOT) {
lcdClear(); lcdClear();
lcdRefresh(); lcdRefresh();
lcdRefreshWait(); lcdRefreshWait();

View file

@ -41,7 +41,7 @@ else()
set(TARGET_SRC set(TARGET_SRC
${TARGET_SRC} ${TARGET_SRC}
coproc_driver.cpp coproc_driver.cpp
rotenc_driver.cpp rotary_encoder_driver.cpp
rtc_driver.cpp rtc_driver.cpp
) )
set(OPENRC_BOOTLOADER bootflash4.lbm) set(OPENRC_BOOTLOADER bootflash4.lbm)

View file

@ -65,7 +65,6 @@ void bootloaderDrawScreen(BootloaderState st, int opt, const char* str)
bootloaderDrawMsg(0, STR_INVALID_EEPROM, 2, false); bootloaderDrawMsg(0, STR_INVALID_EEPROM, 2, false);
} }
else if (opt == FC_OK) { else if (opt == FC_OK) {
const char *vers = getOtherVersion((char *) Block_buffer); const char *vers = getOtherVersion((char *) Block_buffer);
#if LCD_W < 212 #if LCD_W < 212
// Remove opentx- from string // Remove opentx- from string
@ -85,7 +84,6 @@ void bootloaderDrawScreen(BootloaderState st, int opt, const char* str)
lcdDrawSolidHorizontalLine(5, 6 * FH + 8, (LCD_W - 12) * opt / 100, FORCE); lcdDrawSolidHorizontalLine(5, 6 * FH + 8, (LCD_W - 12) * opt / 100, FORCE);
} }
else if (st == ST_FLASH_DONE) { else if (st == ST_FLASH_DONE) {
lcdDrawTextAlignedLeft(4 * FH, CENTER "\007Writing complete"); lcdDrawTextAlignedLeft(4 * FH, CENTER "\007Writing complete");
} }
} }