5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
23 bool isBootloader(const char * filename
)
26 f_open(&file
, filename
, FA_READ
);
30 if (f_read(&file
, buffer
, sizeof(buffer
), &count
) != FR_OK
|| count
!= sizeof(buffer
)) {
34 return isBootloaderStart(buffer
);
37 void bootloaderFlash(const char * filename
)
40 f_open(&file
, filename
, FA_READ
);
44 static uint8_t unlocked
= 0;
50 for (int i
= 0; i
< BOOTLOADER_SIZE
; i
+= 1024) {
51 watchdogSuspend(1000/*10s*/);
52 if (f_read(&file
, buffer
, sizeof(buffer
), &count
) != FR_OK
|| count
!= sizeof(buffer
)) {
53 POPUP_WARNING(STR_SDCARD_ERROR
);
56 if (i
== 0 && !isBootloaderStart(buffer
)) {
57 POPUP_WARNING(STR_INCOMPATIBLE
);
60 for (int j
= 0; j
< 1024; j
+= FLASH_PAGESIZE
) {
61 flashWrite(CONVERT_UINT_PTR(FIRMWARE_ADDRESS
+ i
+ j
), CONVERT_UINT_PTR(buffer
+ j
));
63 drawProgressScreen("Bootloader", STR_WRITING
, i
, BOOTLOADER_SIZE
);
65 // add an artificial delay and check for simu quit
66 if (SIMU_SLEEP_OR_EXIT_MS(30))