Skip to content
Snippets Groups Projects
Commit 19ca6393 authored by Nikolay Amiantov's avatar Nikolay Amiantov
Browse files

Implement bootloader updates

parent 57ddb643
Branches genofire
No related tags found
No related merge requests found
...@@ -29,7 +29,11 @@ ...@@ -29,7 +29,11 @@
#define PARTITION_START (0x10000000 + 64 * 1024) #define PARTITION_START (0x10000000 + 64 * 1024)
#define PARTITION_END (0x10000000 + 1024 * 1024 - 1) #define PARTITION_END (0x10000000 + 1024 * 1024 - 1)
#define MSC_MAGIC 0x6E697807
struct bootloader_version __attribute__((section(".bootloader_version"))) __bootloader_version = {
.magic = BOOTLOADER_MAGIC,
.version = BOOTLOADER_VERSION,
};
DIR dir; DIR dir;
FATFS FatFs; FATFS FatFs;
......
Source diff could not be displayed: it is too large. Options to address this: view the blob.
#include "card10.h"
#include "bootloader.h"
#include "card10-platform.h"
#include "modules/log.h"
#include "epicardium.h"
#include "flc.h"
#include "icc.h"
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
extern char _isr_vector_end;
extern char _text;
void update_bootloader(void)
{
/* Look at the first symbol after the ISV in the bootloader image. */
struct bootloader_version* VERSION_STRUCT =
(struct bootloader_version*)(0x10000000 + (&_isr_vector_end - &_text));
uint32_t current_version =
(VERSION_STRUCT->magic == BOOTLOADER_MAGIC)
? VERSION_STRUCT->version
: 0;
LOG_DEBUG("startup", "Current bootloader version: %lu", current_version);
if (current_version == BOOTLOADER_VERSION) {
return;
}
epic_disp_print(0, 5, "bl update", 0xffff, 0x0000);
epic_disp_print(0, 24, "version " TOSTRING(BOOTLOADER_VERSION), 0xffff, 0x0000);
epic_disp_update();
ICC_Disable();
LOG_INFO("startup", "Erasing old bootloader");
int ret = FLC_MultiPageErase(0x10000000, 0x10000000 + 1024 * 64 - 1);
if (ret != E_NO_ERROR) {
LOG_DEBUG("startup", "FLC_MultiPageErase failed with %d", ret);
epic_disp_print(0, 45, "failed", 0xffff, 0x0000);
epic_disp_update();
while (1);
}
LOG_INFO("startup", "Updating bootloader to version %u", BOOTLOADER_VERSION);
ret = FLC_Write(
0x10000000,
bootloader_bootloader_bin_len,
(uint32_t *)bootloader_bootloader_bin
);
if (ret != E_NO_ERROR) {
LOG_DEBUG("startup", "FLC_Write failed with %d", ret);
epic_disp_print(0, 45, "failed", 0xffff, 0x0000);
epic_disp_update();
while (1);
}
ICC_Enable();
LOG_INFO("startup", "Bootloader update finished");
card10_reset();
}
#ifndef BOOTLOADER_UPDATE_H
#define BOOTLOADER_UPDATE_H
void update_bootloader(void);
#endif
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include "modules/log.h" #include "modules/log.h"
#include "modules/filesystem.h" #include "modules/filesystem.h"
#include "card10-version.h" #include "card10-version.h"
#include "bootloader_update.h"
#include "FreeRTOS.h" #include "FreeRTOS.h"
#include "task.h" #include "task.h"
...@@ -20,6 +21,8 @@ int main(void) ...@@ -20,6 +21,8 @@ int main(void)
LOG_DEBUG("startup", "Initializing hardware ..."); LOG_DEBUG("startup", "Initializing hardware ...");
hardware_early_init(); hardware_early_init();
update_bootloader();
/* /*
* Version Splash * Version Splash
*/ */
......
...@@ -83,6 +83,7 @@ elf = executable( ...@@ -83,6 +83,7 @@ elf = executable(
'cdcacm.c', 'cdcacm.c',
'main.c', 'main.c',
'support.c', 'support.c',
'bootloader_update.c',
'fs/filesystem_fat.c', 'fs/filesystem_fat.c',
module_sources, module_sources,
l0der_sources, l0der_sources,
......
#ifndef CARD10_PLATFORM_H #ifndef CARD10_PLATFORM_H
#define CARD10_PLATFORM_H
#define MSC_MAGIC 0x6E697807 #define MSC_MAGIC 0x6E697807
#define BOOTLOADER_MAGIC 0xBADC0FFE
#define BOOTLOADER_VERSION 1
/* TODO: Make this address part of the linker script */ /* TODO: Make this address part of the linker script */
#define API_CALL_MEM_ADDRESS ((void*)0x20080000) #define API_CALL_MEM_ADDRESS ((void*)0x20080000)
/* Bootloader version struct. */
struct bootloader_version {
uint32_t magic;
uint32_t version;
};
#endif #endif
...@@ -48,6 +48,7 @@ SECTIONS { ...@@ -48,6 +48,7 @@ SECTIONS {
{ {
_text = .; _text = .;
KEEP(*(.isr_vector)) KEEP(*(.isr_vector))
KEEP(*(.bootloader_version))
*(.text*) /* program code */ *(.text*) /* program code */
*(.rodata*) /* read-only data: "const" */ *(.rodata*) /* read-only data: "const" */
......
...@@ -48,6 +48,7 @@ SECTIONS { ...@@ -48,6 +48,7 @@ SECTIONS {
{ {
_text = .; _text = .;
KEEP(*(.isr_vector)) KEEP(*(.isr_vector))
_isr_vector_end = .;
*(.text*) /* program code */ *(.text*) /* program code */
*(.rodata*) /* read-only data: "const" */ *(.rodata*) /* read-only data: "const" */
...@@ -85,7 +86,6 @@ SECTIONS { ...@@ -85,7 +86,6 @@ SECTIONS {
*(.spix_config*) /* SPIX configuration functions need to be run from SRAM */ *(.spix_config*) /* SPIX configuration functions need to be run from SRAM */
*(.flashprog*) /* Flash program */ *(.flashprog*) /* Flash program */
/* These array sections are used by __libc_init_array to call static C++ constructors */ /* These array sections are used by __libc_init_array to call static C++ constructors */
. = ALIGN(4); . = ALIGN(4);
/* preinit data */ /* preinit data */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment