Skip to content
Snippets Groups Projects
Verified Commit 352b5a97 authored by rahix's avatar rahix
Browse files

chore(bootloader): Move all display code into main()


Signed-off-by: default avatarRahix <rahix@rahix.de>
parent 384fcfb1
No related branches found
No related tags found
1 merge request!55Refactor Bootloader & add a boot-splash
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include <stddef.h> #include <stddef.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <errno.h>
#define GPIO_PORT_IN PORT_1 #define GPIO_PORT_IN PORT_1
#define GPIO_PIN_IN PIN_6 #define GPIO_PIN_IN PIN_6
...@@ -30,25 +31,25 @@ ...@@ -30,25 +31,25 @@
DIR dir; DIR dir;
FATFS FatFs; FATFS FatFs;
bool mount(void) int mount(void)
{ {
FRESULT res; FRESULT res;
res = f_mount(&FatFs, "/", 0); res = f_mount(&FatFs, "/", 0);
if (res != FR_OK) { if (res != FR_OK) {
printf("f_mount error %d\n", res); printf("f_mount error %d\n", res);
return false; return -1;
} }
res = f_opendir(&dir, "0:"); res = f_opendir(&dir, "0:");
if (res != FR_OK) { if (res != FR_OK) {
printf("f_opendir error %d\n", res); printf("f_opendir error %d\n", res);
return false; return -1;
} }
return true; return 0;
} }
bool check_integrity(void) int check_integrity(void)
{ {
FIL file; FIL file;
UINT readbytes; UINT readbytes;
...@@ -58,9 +59,8 @@ bool check_integrity(void) ...@@ -58,9 +59,8 @@ bool check_integrity(void)
res = f_open(&file, filename, FA_OPEN_EXISTING | FA_READ); res = f_open(&file, filename, FA_OPEN_EXISTING | FA_READ);
if (res != FR_OK) { if (res != FR_OK) {
bootloader_display_line(2, "card10.bin not found", 0xffff);
printf("f_open error %d\n", res); printf("f_open error %d\n", res);
return false; return -ENOENT;
} }
uint16_t crcval = 0; uint16_t crcval = 0;
...@@ -76,13 +76,12 @@ bool check_integrity(void) ...@@ -76,13 +76,12 @@ bool check_integrity(void)
f_close(&file); f_close(&file);
if (crcval == 0) { if (crcval != 0) {
return true;
} else {
bootloader_display_line(2, "Integrity check failed", 0xffff);
printf("CRC check failed. Final CRC: %d\n", crcval); printf("CRC check failed. Final CRC: %d\n", crcval);
return false; return -EINVAL;
} }
return 0;
} }
bool is_update_needed(void) bool is_update_needed(void)
...@@ -221,8 +220,19 @@ int main(void) ...@@ -221,8 +220,19 @@ int main(void)
; ;
} }
if (mount()) { if (mount() == 0) {
if (check_integrity()) { int res = check_integrity();
if (res == -ENOENT) {
printf("card10.bin not found!\n");
bootloader_display_line(
2, "card10.bin not found", 0xffff
);
} else if (res == -EINVAL) {
printf("card10.bin CRC is invalid!\n");
bootloader_display_line(
2, "Integrity check failed", 0xffff
);
} else if (res == 0) {
printf("Found valid application image\n"); printf("Found valid application image\n");
if (is_update_needed()) { if (is_update_needed()) {
printf("Trying to update firmware from external flash\n"); printf("Trying to update firmware from external flash\n");
...@@ -234,8 +244,6 @@ int main(void) ...@@ -234,8 +244,6 @@ int main(void)
} else { } else {
printf("No update needed\n"); printf("No update needed\n");
} }
} else {
printf("Integrity check failed\n");
} }
} else { } else {
bootloader_display_line( bootloader_display_line(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment