mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[bootloader/storage] new bootloader and fix python issue
This commit is contained in:
129
bootloader/boot/isr.c
Normal file
129
bootloader/boot/isr.c
Normal file
@@ -0,0 +1,129 @@
|
||||
#include "isr.h"
|
||||
extern const void * _stack_start;
|
||||
|
||||
/* Interrupt Service Routines are void->void functions */
|
||||
typedef void(*ISR)(void);
|
||||
|
||||
/* Notice: The Cortex-M4 expects all jumps to be made at an odd address when
|
||||
* jumping to Thumb code. For example, if you want to execute Thumb code at
|
||||
* address 0x100, you'll have to jump to 0x101. Luckily, this idiosyncrasy is
|
||||
* properly handled by the C compiler that will generate proper addresses when
|
||||
* using function pointers. */
|
||||
|
||||
#define INITIALISATION_VECTOR_SIZE 0x71
|
||||
|
||||
ISR InitialisationVector[INITIALISATION_VECTOR_SIZE]
|
||||
__attribute__((section(".isr_vector_table")))
|
||||
__attribute__((used))
|
||||
= {
|
||||
(ISR)&_stack_start, // Stack start
|
||||
start, // Reset service routine,
|
||||
0, // NMI service routine,
|
||||
hard_fault_handler, // HardFault service routine,
|
||||
mem_fault_handler, // MemManage service routine,
|
||||
bus_fault_handler, // BusFault service routine,
|
||||
usage_fault_handler, // UsageFault service routine,
|
||||
0, 0, 0, 0, // Reserved
|
||||
0, // SVCall service routine,
|
||||
0, // DebugMonitor service routine,
|
||||
0, // Reserved
|
||||
0, // PendSV service routine,
|
||||
isr_systick, // SysTick service routine
|
||||
0, // WWDG service routine
|
||||
0, // PVD service routine
|
||||
0, // TampStamp service routine
|
||||
0, // RtcWakeup service routine
|
||||
0, // Flash service routine
|
||||
0, // RCC service routine
|
||||
0, // EXTI0 service routine
|
||||
0, // EXTI1 service routine
|
||||
0, // EXTI2 service routine
|
||||
0, // EXTI3 service routine
|
||||
0, // EXTI4 service routine
|
||||
0, // DMA1Stream0 service routine
|
||||
0, // DMA1Stream1 service routine
|
||||
0, // DMA1Stream2 service routine
|
||||
0, // DMA1Stream3 service routine
|
||||
0, // DMA1Stream4 service routine
|
||||
0, // DMA1Stream5 service routine
|
||||
0, // DMA1Stream6 service routine
|
||||
0, // ADC1 global interrupt
|
||||
0, // CAN1 TX interrupt
|
||||
0, // CAN1 RX0 interrupt
|
||||
0, // CAN1 RX1 interrupt
|
||||
0, // CAN1 SCE interrupt
|
||||
0, // EXTI Line[9:5] interrupts
|
||||
0, // TIM1 Break interrupt and TIM9 global interrupt
|
||||
0, // TIM1 update interrupt and TIM10 global interrupt
|
||||
0, // TIM1 Trigger & Commutation interrupts and TIM11 global interrupt
|
||||
0, // TIM1 Capture Compare interrupt
|
||||
0, // TIM2 global interrupt
|
||||
0, // TIM3 global interrupt
|
||||
0, // TIM4 global interrupt
|
||||
0, // I2C1 global event interrupt
|
||||
0, // I2C1 global error interrupt
|
||||
0, // I2C2 global event interrupt
|
||||
0, // I2C2 global error interrupt
|
||||
0, // SPI1 global interrupt
|
||||
0, // SPI2 global interrupt
|
||||
0, // USART1 global interrupt
|
||||
0, // USART2 global interrupt
|
||||
0, // USART3 global interrupt
|
||||
0, // EXTI Line[15:10] interrupts
|
||||
0, // EXTI Line 17 interrupt RTC Alarms (A and B) through EXTI line interrupt
|
||||
0, // EXTI Line 18 interrupt / USB On-The-Go FS Wakeup through EXTI line interrupt
|
||||
0, // TIM8 Break interrupt TIM12 global interrupt
|
||||
0, // TIM8 Update interrupt TIM13 global interrupt
|
||||
0, // TIM8 Trigger & Commutation interrupt TIM14 global interrupt
|
||||
0, // TIM8 Cap/Com interrupt
|
||||
0, // DMA1 global interrupt Channel 7
|
||||
0, // FSMC global interrupt
|
||||
0, // SDIO global interrupt
|
||||
0, // TIM5 global interrupt
|
||||
0, // SPI3 global interrupt
|
||||
0, // ?
|
||||
0, // ?
|
||||
0, // TIM6 global interrupt
|
||||
0, // TIM7 global interrupt
|
||||
0, // DMA2 Stream0 global interrupt
|
||||
0, // DMA2 Stream1 global interrupt
|
||||
0, // DMA2 Stream2 global interrupt
|
||||
0, // DMA2 Stream3 global interrupt
|
||||
0, // DMA2 Stream4 global interrupt
|
||||
0, // SD filter0 global interrupt
|
||||
0, // SD filter1 global interrupt
|
||||
0, // CAN2 TX interrupt
|
||||
0, // BXCAN2 RX0 interrupt
|
||||
0, // BXCAN2 RX1 interrupt
|
||||
0, // CAN2 SCE interrupt
|
||||
0, // USB On The Go FS global interrupt
|
||||
0, // DMA2 Stream5 global interrupts
|
||||
0, // DMA2 Stream6 global interrupt
|
||||
0, // DMA2 Stream7 global interrupt
|
||||
0, // USART6 global interrupt
|
||||
0, // I2C3 event interrupt
|
||||
0, // I2C3 error interrupt
|
||||
0, // ?
|
||||
0, // ?
|
||||
0, // ?
|
||||
0, // ?
|
||||
0, // ?
|
||||
0, // ?
|
||||
0, // RNG global interrupt
|
||||
0, // FPU global interrupt
|
||||
0, // ?
|
||||
0, // ?
|
||||
0, // SPI4 global interrupt
|
||||
0, // SPI5 global interrupt
|
||||
0, // ?
|
||||
0, // ?
|
||||
0, // ?
|
||||
0, // ?
|
||||
0, // ?
|
||||
0, // ?
|
||||
0, // Quad-SPI global interrupt
|
||||
0, // ?
|
||||
0, // ?
|
||||
0, // I2CFMP1 event interrupt
|
||||
0 // I2CFMP1 error interrupt
|
||||
};
|
||||
23
bootloader/boot/isr.h
Normal file
23
bootloader/boot/isr.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef ION_DEVICE_BOOT_ISR_H
|
||||
#define ION_DEVICE_BOOT_ISR_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void start();
|
||||
void abort();
|
||||
void isr_systick();
|
||||
|
||||
// Fault handlers
|
||||
|
||||
void hard_fault_handler();
|
||||
void mem_fault_handler();
|
||||
void usage_fault_handler();
|
||||
void bus_fault_handler();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
146
bootloader/boot/rt0.cpp
Normal file
146
bootloader/boot/rt0.cpp
Normal file
@@ -0,0 +1,146 @@
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <ion.h>
|
||||
#include <bootloader/boot/isr.h>
|
||||
#include <drivers/board.h>
|
||||
#include <drivers/rtc.h>
|
||||
#include <drivers/reset.h>
|
||||
#include <drivers/timing.h>
|
||||
#include <bootloader/recovery.h>
|
||||
|
||||
typedef void (*cxx_constructor)();
|
||||
|
||||
extern "C" {
|
||||
extern char _data_section_start_flash;
|
||||
extern char _data_section_start_ram;
|
||||
extern char _data_section_end_ram;
|
||||
extern char _bss_section_start_ram;
|
||||
extern char _bss_section_end_ram;
|
||||
extern cxx_constructor _init_array_start;
|
||||
extern cxx_constructor _init_array_end;
|
||||
}
|
||||
|
||||
void __attribute__((noinline)) abort() {
|
||||
#ifdef NDEBUG
|
||||
Ion::Device::Reset::core();
|
||||
#else
|
||||
while (1) {
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void __attribute__((interrupt, noinline)) isr_systick() {
|
||||
auto t = Ion::Device::Timing::MillisElapsed;
|
||||
t++;
|
||||
Ion::Device::Timing::MillisElapsed = t;
|
||||
}
|
||||
|
||||
void __attribute__((noinline)) hard_fault_handler() {
|
||||
Bootloader::Recovery::crash_handler("HardFault");
|
||||
}
|
||||
|
||||
void __attribute__((noinline)) mem_fault_handler() {
|
||||
Bootloader::Recovery::crash_handler("MemoryFault");
|
||||
}
|
||||
|
||||
void __attribute__((noinline)) usage_fault_handler() {
|
||||
Bootloader::Recovery::crash_handler("UsageFault");
|
||||
}
|
||||
|
||||
void __attribute__((noinline)) bus_fault_handler() {
|
||||
Bootloader::Recovery::crash_handler("BusFault");
|
||||
}
|
||||
|
||||
/* In order to ensure that this method is execute from the external flash, we
|
||||
* forbid inlining it.*/
|
||||
|
||||
static void __attribute__((noinline)) external_flash_start() {
|
||||
/* Init the peripherals. We do not initialize the backlight in case there is
|
||||
* an on boarding app: indeed, we don't want the user to see the LCD tests
|
||||
* happening during the on boarding app. The backlight will be initialized
|
||||
* after the Power-On Self-Test if there is one or before switching to the
|
||||
* home app otherwise. */
|
||||
Ion::Device::Board::initPeripherals(false);
|
||||
|
||||
return ion_main(0, nullptr);
|
||||
}
|
||||
|
||||
/* This additional function call 'jump_to_external_flash' serves two purposes:
|
||||
* - By default, the compiler is free to inline any function call he wants. If
|
||||
* the compiler decides to inline some functions that make use of VFP
|
||||
* registers, it will need to push VFP them onto the stack in calling
|
||||
* function's prologue.
|
||||
* Problem: in start()'s prologue, we would never had a chance to enable the
|
||||
* FPU since this function is the first thing called after reset.
|
||||
* We can safely assume that neither memcpy, memset, nor any Ion::Device::init*
|
||||
* method will use floating-point numbers, but ion_main very well can.
|
||||
* To make sure ion_main's potential usage of VFP registers doesn't bubble-up to
|
||||
* start(), we isolate it in its very own non-inlined function call.
|
||||
* - To avoid jumping on the external flash when it is shut down, we ensure
|
||||
* there is no symbol references from the internal flash to the external
|
||||
* flash except this jump. In order to do that, we isolate this
|
||||
* jump in a symbol that we link in a special section separated from the
|
||||
* internal flash section. We can than forbid cross references from the
|
||||
* internal flash to the external flash. */
|
||||
|
||||
static void __attribute__((noinline)) jump_to_external_flash() {
|
||||
external_flash_start();
|
||||
}
|
||||
|
||||
/* When 'start' is executed, the external flash is supposed to be shutdown. We
|
||||
* thus forbid inlining to prevent executing this code from external flash
|
||||
* (just in case 'start' was to be called from the external flash). */
|
||||
|
||||
void __attribute__((noinline)) start() {
|
||||
/* This is where execution starts after reset.
|
||||
* Many things are not initialized yet so the code here has to pay attention. */
|
||||
|
||||
/* Initialize the FPU as early as possible.
|
||||
* For example, static C++ objects are very likely to manipulate float values */
|
||||
Ion::Device::Board::initFPU();
|
||||
|
||||
|
||||
|
||||
/* Copy data section to RAM
|
||||
* The data section is R/W but its initialization value matters. It's stored
|
||||
* in Flash, but linked as if it were in RAM. Now's our opportunity to copy
|
||||
* it. Note that until then the data section (e.g. global variables) contains
|
||||
* garbage values and should not be used. */
|
||||
size_t dataSectionLength = (&_data_section_end_ram - &_data_section_start_ram);
|
||||
memcpy(&_data_section_start_ram, &_data_section_start_flash, dataSectionLength);
|
||||
|
||||
/* Zero-out the bss section in RAM
|
||||
* Until we do, any uninitialized global variable will be unusable. */
|
||||
size_t bssSectionLength = (&_bss_section_end_ram - &_bss_section_start_ram);
|
||||
memset(&_bss_section_start_ram, 0, bssSectionLength);
|
||||
|
||||
|
||||
/* Call static C++ object constructors
|
||||
* The C++ compiler creates an initialization function for each static object.
|
||||
* The linker then stores the address of each of those functions consecutively
|
||||
* between _init_array_start and _init_array_end. So to initialize all C++
|
||||
* static objects we just have to iterate between theses two addresses and
|
||||
* call the pointed function. */
|
||||
#define SUPPORT_CPP_GLOBAL_CONSTRUCTORS 0
|
||||
#if SUPPORT_CPP_GLOBAL_CONSTRUCTORS
|
||||
for (cxx_constructor * c = &_init_array_start; c<&_init_array_end; c++) {
|
||||
(*c)();
|
||||
}
|
||||
#else
|
||||
/* In practice, static initialized objects are a terrible idea. Since the init
|
||||
* order is not specified, most often than not this yields the dreaded static
|
||||
* init order fiasco. How about bypassing the issue altogether? */
|
||||
if (&_init_array_start != &_init_array_end) {
|
||||
abort();
|
||||
}
|
||||
#endif
|
||||
|
||||
/* At this point, we initialized clocks and the external flash but no other
|
||||
* peripherals. */
|
||||
Ion::Device::Board::init();
|
||||
|
||||
jump_to_external_flash();
|
||||
|
||||
abort();
|
||||
}
|
||||
Reference in New Issue
Block a user