Updater: Add safety memory to updater
This commit is contained in:
@@ -13,13 +13,15 @@ set(ELFFILE "${PROJECT_NAME}.elf")
|
||||
aux_source_directory("." SRCS)
|
||||
aux_source_directory("fatfs" FATFS_SRCS)
|
||||
aux_source_directory("fatfs/shimatta_sdio_driver" SDIO_SRCS)
|
||||
aux_source_directory("../../stm-periph" STM_PERIPH_SRCS)
|
||||
set(SAFETY_MEMORY_SRCS "../../safety/safety-memory.c")
|
||||
|
||||
add_executable(${ELFFILE} ${SRCS} ${FATFS_SRCS} ${SDIO_SRCS})
|
||||
add_executable(${ELFFILE} ${SRCS} ${FATFS_SRCS} ${SDIO_SRCS} ${STM_PERIPH_SRCS} ${SAFETY_MEMORY_SRCS})
|
||||
|
||||
target_include_directories(${ELFFILE} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||
target_include_directories(${ELFFILE} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include ../../include)
|
||||
target_compile_options(${ELFFILE} PRIVATE -Wall -Wextra -Wold-style-declaration -Wuninitialized -Wmaybe-uninitialized -Wunused-parameter)
|
||||
target_compile_options(${ELFFILE} PRIVATE -mlittle-endian -mthumb -mcpu=cortex-m4 -mthumb-interwork -mfloat-abi=hard -mfpu=fpv4-sp-d16 -nostartfiles -Wimplicit-fallthrough=3 -Wsign-compare -Os -g3)
|
||||
target_compile_definitions(${ELFFILE} PRIVATE -DBASE64_LOOKUP_TABLE_SECTION=\".ccm.bss\" -DSHELLMATTA_HELP_ALIAS=\"?\" -DGIT_VER=${GIT_DESCRIBE} -DHSE_VALUE=8000000UL -DSTM32F407xx -DSTM32F4XX -DARM_MATH_CM4)
|
||||
target_compile_definitions(${ELFFILE} PRIVATE -DGIT_VER=${GIT_DESCRIBE} -DHSE_VALUE=8000000UL -DSTM32F407xx -DSTM32F4XX -DARM_MATH_CM4 -DSAFETY_MEMORY_STRIPOUT_DUMP)
|
||||
target_link_options(${ELFFILE} PRIVATE -mlittle-endian -mthumb -mcpu=cortex-m4 -mthumb-interwork -mfloat-abi=hard -mfpu=fpv4-sp-d16 --disable-newlib-supplied-syscalls -nostartfiles -T${LINKER_SCRIPT} -Wl,--print-memory-usage)
|
||||
set(GEN_HEADER_PATH "${CMAKE_CURRENT_BINARY_DIR}/include/generated")
|
||||
set(GEN_HEADER_FILE "${GEN_HEADER_PATH}/${PROJECT_NAME}.bin.h")
|
||||
|
@@ -3,6 +3,14 @@
|
||||
#include <cmsis/core_cm4.h>
|
||||
#include "hex-parser.h"
|
||||
#include <fatfs/ff.h>
|
||||
|
||||
/* This is used to get the defines for the external watchdog */
|
||||
#include <reflow-controller/safety/safety-config.h>
|
||||
#include <helper-macros/helper-macros.h>
|
||||
#include <stm-periph/stm32-gpio-macros.h>
|
||||
|
||||
#include <reflow-controller/safety/safety-memory.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
static volatile unsigned int wait_tick;
|
||||
@@ -12,6 +20,14 @@ static void watchdog_ack(void)
|
||||
IWDG->KR = 0xAAAA;
|
||||
}
|
||||
|
||||
static void external_watchdog_disable(void)
|
||||
{
|
||||
RCC->AHB1ENR |= SAFETY_EXT_WATCHDOG_RCC_MASK;
|
||||
__DSB();
|
||||
/* Set Pin to input. This disables the external watchdog. */
|
||||
SAFETY_EXT_WATCHDOG_PORT->MODER &= MODER_DELETE(SAFETY_EXT_WATCHDOG_PIN);
|
||||
}
|
||||
|
||||
void sdio_wait_ms(unsigned int ms)
|
||||
{
|
||||
wait_tick = 0;
|
||||
@@ -23,7 +39,11 @@ static FATFS _fs;
|
||||
|
||||
static void __attribute__((noreturn)) ram_code_exit(bool updated)
|
||||
{
|
||||
(void)updated;
|
||||
struct safety_memory_boot_status boot_status;
|
||||
safety_memory_get_boot_status(&boot_status);
|
||||
boot_status.code_updated = updated ? 0xFFFFFFFFUL : 0x0UL;
|
||||
boot_status.reboot_to_bootloader = 0x0UL;
|
||||
safety_memory_set_boot_status(&boot_status);
|
||||
|
||||
NVIC_SystemReset();
|
||||
while(1);
|
||||
@@ -32,15 +52,30 @@ static void __attribute__((noreturn)) ram_code_exit(bool updated)
|
||||
int ram_code_main(void)
|
||||
{
|
||||
FRESULT fres;
|
||||
int res;
|
||||
enum safety_memory_state safety_mem_state;
|
||||
enum hex_parser_ret hex_ret;
|
||||
struct hex_parser parser;
|
||||
|
||||
SysTick_Config(168000UL);
|
||||
external_watchdog_disable();
|
||||
__enable_irq();
|
||||
|
||||
res = safety_memory_init(&safety_mem_state);
|
||||
if (res || safety_mem_state != SAFETY_MEMORY_INIT_VALID_MEMORY) {
|
||||
ram_code_exit(false);
|
||||
}
|
||||
|
||||
fres = f_mount(fs, "0:/", 1);
|
||||
if (fres != FR_OK) {
|
||||
ram_code_exit(false);
|
||||
}
|
||||
|
||||
hex_ret = hex_parser_open(&parser, "update.hex");
|
||||
if (hex_ret != HEX_PARSER_OK) {
|
||||
ram_code_exit(false);
|
||||
}
|
||||
|
||||
while(1) {
|
||||
__WFI();
|
||||
}
|
||||
|
@@ -260,28 +260,28 @@ extern unsigned int __ld_vector_start;
|
||||
extern unsigned int __ld_sbss;
|
||||
extern unsigned int __ld_ebss;
|
||||
|
||||
|
||||
#ifdef CPACR
|
||||
#undef CPACR
|
||||
#endif
|
||||
|
||||
#define CPACR (*((volatile uint32_t *)0xE000ED88))
|
||||
|
||||
void Reset_Handler(void)
|
||||
void Reset_Handler()
|
||||
{
|
||||
|
||||
|
||||
/* The first thing we do here, is to initialize the FPU
|
||||
* When this code is compiled optimized with hardfpu abi,
|
||||
* GCC tends to generate FPU instructions for data copying
|
||||
*/
|
||||
CPACR |= (0xF << 20);
|
||||
/* Reset the stack pointer to top of stack. SP is not required to be inside the clobber list! */
|
||||
__asm__ __volatile__ ("mov sp, %0\n\t" :: "r"(&__ld_top_of_stack) :);
|
||||
|
||||
|
||||
/* Fill bss with zero */
|
||||
__fill_zero(&__ld_sbss, &__ld_ebss);
|
||||
/* Fill Heap with zero */
|
||||
|
||||
/* Reset the stack pointer to top of stack. SP is not required to be inside the clobber list! */
|
||||
__asm__ __volatile__ ("mov sp, %0\n\t" :: "r"(&__ld_top_of_stack) :);
|
||||
|
||||
|
||||
|
||||
ram_code_main();
|
||||
|
||||
|
Reference in New Issue
Block a user