From aecd997d4b42a6258c2a95d7b10e3da74e8f744f Mon Sep 17 00:00:00 2001 From: Andrey G Date: Mon, 8 Aug 2022 02:33:19 +0300 Subject: [PATCH] OpenBLT shared params (#4417) * OpenBLT: linker file: use last 16 bytes of ram for shared area This area is used for communication between FW and OpenBLT. * OpenBLT: startup: invalidate only DFU breadcumb from startup code Same location (but different seed) is used for shared param's signature in OpenBLT. * OpenBLT: enable shared params * OpenBLT: enable hooks If 0x01 is stored in shared param idx=0, then stay in OpenBLT forever. * Jump to OpenBLT: store proper shared param when OpenBLT is requested TODO: calculate and store CRC too! * OpenBLT: move shared_params to start of RAM * Bootloader: Allocate 16 bytes at start of RAM for bootloader shared area * OpenBLT: shared_params: reuse same .c and .h file for main application * OpenBLT: shared_params: enable CRC check * OpenBLT: no need to manualy set breadcumb before reset * Revert "OpenBLT: startup: invalidate only DFU breadcumb from startup code" This reverts commit 6b064714b953560227ae53e38355332cf9f46f7f. * OpenBLT: guard for builds without OpenBLT * OpenBLT: reboot to OpenBLT on CAN request with ID=0x667 and DLC=2 * config: options to enable OpenBLT on CAN interfaces * OpenBLT: comments --- firmware/common.mk | 3 +- firmware/controllers/can/can_rx.cpp | 8 + firmware/hw_layer/hw_layer.mk | 10 +- firmware/hw_layer/openblt/blt_conf.h | 2 +- firmware/hw_layer/openblt/flash_layout.c | 2 +- firmware/hw_layer/openblt/hooks.c | 11 +- firmware/hw_layer/openblt/main_internal_osc.c | 3 + firmware/hw_layer/openblt/openblt.mk | 2 + firmware/hw_layer/openblt/shared_params.c | 250 ++++++++++++++++++ firmware/hw_layer/openblt/shared_params.h | 57 ++++ .../hw_layer/ports/stm32/stm32_common.cpp | 24 +- .../hw_layer/ports/stm32/stm32f4/STM32F4.ld | 26 +- .../ports/stm32/stm32f4/openblt/STM32F4xx.ld | 11 +- .../hw_layer/ports/stm32/stm32f7/STM32F7.ld | 21 +- .../ports/stm32/stm32f7/openblt/STM32F7xx.ld | 11 +- 15 files changed, 415 insertions(+), 26 deletions(-) create mode 100644 firmware/hw_layer/openblt/shared_params.c create mode 100644 firmware/hw_layer/openblt/shared_params.h diff --git a/firmware/common.mk b/firmware/common.mk index 5d8fcbdaa8..aa61efc3aa 100644 --- a/firmware/common.mk +++ b/firmware/common.mk @@ -10,8 +10,7 @@ include $(PROJECT_DIR)/hw_layer/sensors/sensors.mk include $(PROJECT_DIR)/hw_layer/drivers/drivers.mk ALLCSRC += \ - $(UTILSRC) \ - + $(UTILSRC) ALLCPPSRC += \ $(CONTROLLERS_CORE_SRC_CPP) \ diff --git a/firmware/controllers/can/can_rx.cpp b/firmware/controllers/can/can_rx.cpp index c4280b07f0..6bce4d3ade 100644 --- a/firmware/controllers/can/can_rx.cpp +++ b/firmware/controllers/can/can_rx.cpp @@ -226,6 +226,14 @@ void processCanRxMessage(const size_t busIndex, const CANRxFrame &frame, efitick handleWidebandBootloaderAck(); } #endif +#if EFI_USE_OPENBLT + if ((CAN_SID(frame) == 0x667) && (frame.DLC == 2)) { + /* TODO: gracefull shutdown? */ + /* TODO: settings option to allow restart on CAN message? */ + /* TODO: check can interface index? */ + jump_to_openblt(); + } +#endif } #endif // EFI_CAN_SUPPORT diff --git a/firmware/hw_layer/hw_layer.mk b/firmware/hw_layer/hw_layer.mk index 6ee1c6e057..96edd17130 100644 --- a/firmware/hw_layer/hw_layer.mk +++ b/firmware/hw_layer/hw_layer.mk @@ -30,9 +30,15 @@ HW_LAYER_EMS_CPP = \ $(PROJECT_DIR)/hw_layer/rtc_helper.cpp \ $(PROJECT_DIR)/hw_layer/cdm_ion_sense.cpp \ $(PROJECT_DIR)/hw_layer/debounce.cpp \ - $(PROJECT_DIR)/hw_layer/adc/mcp3208.cpp \ + $(PROJECT_DIR)/hw_layer/adc/mcp3208.cpp -ALLCSRC += $(PROJECT_DIR)/hw_layer/mc33816/rusefi/sample_code/PT2001_LoadData.c +ifeq ($(USE_OPENBLT),yes) + HW_LAYER_EMS += \ + $(PROJECT_DIR)/hw_layer/openblt/shared_params.c +endif + +ALLCSRC += \ + $(PROJECT_DIR)/hw_layer/mc33816/rusefi/sample_code/PT2001_LoadData.c # # '-include' is a magic kind of 'include' which would survive if file to be included is not found diff --git a/firmware/hw_layer/openblt/blt_conf.h b/firmware/hw_layer/openblt/blt_conf.h index 01cd474306..94b9473b2a 100644 --- a/firmware/hw_layer/openblt/blt_conf.h +++ b/firmware/hw_layer/openblt/blt_conf.h @@ -109,7 +109,7 @@ * also be implemented in a way that disables the backdoor entry altogether. */ /** \brief Enable/disable the backdoor override hook functions. */ -#define BOOT_BACKDOOR_HOOKS_ENABLE (0) +#define BOOT_BACKDOOR_HOOKS_ENABLE (1) /**************************************************************************************** diff --git a/firmware/hw_layer/openblt/flash_layout.c b/firmware/hw_layer/openblt/flash_layout.c index 09415482c1..d73189314e 100644 --- a/firmware/hw_layer/openblt/flash_layout.c +++ b/firmware/hw_layer/openblt/flash_layout.c @@ -1,7 +1,7 @@ /* Define STM32F4, STM32F7 or STM32F765 flash layout in dual bank mode. Only first bank is defined */ -// todo: document the magic which accesses this 'static' field?! +/* This file is included in another .c file. So it is ok to have static and no users here */ static const tFlashSector flashLayout[] = { /* space is reserved for a bootloader configuration with all supported communication diff --git a/firmware/hw_layer/openblt/hooks.c b/firmware/hw_layer/openblt/hooks.c index 3ef34c5b4f..4eae90210a 100644 --- a/firmware/hw_layer/openblt/hooks.c +++ b/firmware/hw_layer/openblt/hooks.c @@ -30,6 +30,7 @@ * Include files ****************************************************************************************/ #include "boot.h" /* bootloader generic header */ +#include "shared_params.h" /* Shared parameters header */ #include "led.h" /* LED driver header */ #ifdef STM32F429xx #include "stm32f4xx.h" /* STM32 CPU and HAL header */ @@ -63,8 +64,14 @@ void BackDoorInitHook(void) ****************************************************************************************/ blt_bool BackDoorEntryHook(void) { - /* default implementation always activates the bootloader after a reset */ - return BLT_TRUE; + uint8_t value = 0x00; + if (SharedParamsReadByIndex(0, &value) && + (value == 0x01)) { + /* clear */ + SharedParamsWriteByIndex(0, 0x00); + return BLT_TRUE; + } + return BLT_FALSE; } /*** end of BackDoorEntryHook ***/ #endif /* BOOT_BACKDOOR_HOOKS_ENABLE > 0 */ diff --git a/firmware/hw_layer/openblt/main_internal_osc.c b/firmware/hw_layer/openblt/main_internal_osc.c index 71f118fc24..abb58d2867 100644 --- a/firmware/hw_layer/openblt/main_internal_osc.c +++ b/firmware/hw_layer/openblt/main_internal_osc.c @@ -30,6 +30,7 @@ * Include files ****************************************************************************************/ #include "boot.h" /* bootloader generic header */ +#include "shared_params.h" /* Shared parameters header */ #ifdef STM32F429xx #include "stm32f4xx.h" /* STM32 CPU and HAL header */ #endif @@ -58,6 +59,8 @@ int main(void) { /* initialize the microcontroller */ Init(); + /* initialize the shared parameters module */ + SharedParamsInit(); /* initialize the bootloader */ BootInit(); diff --git a/firmware/hw_layer/openblt/openblt.mk b/firmware/hw_layer/openblt/openblt.mk index 01fe298414..4bee2813e5 100644 --- a/firmware/hw_layer/openblt/openblt.mk +++ b/firmware/hw_layer/openblt/openblt.mk @@ -82,6 +82,8 @@ PROJ_FILES += $(PROJECT_DIR)/hw_layer/openblt/blt_conf.h PROJ_FILES += $(PROJECT_DIR)/hw_layer/openblt/hooks.c PROJ_FILES += $(PROJECT_DIR)/hw_layer/openblt/led.c PROJ_FILES += $(PROJECT_DIR)/hw_layer/openblt/led.h +PROJ_FILES += $(PROJECT_DIR)/hw_layer/openblt/shared_params.c +PROJ_FILES += $(PROJECT_DIR)/hw_layer/openblt/shared_params.h # CPU-dependent sources ifeq ($(PROJECT_CPU),ARCH_STM32F4) diff --git a/firmware/hw_layer/openblt/shared_params.c b/firmware/hw_layer/openblt/shared_params.c new file mode 100644 index 0000000000..f8e154de8a --- /dev/null +++ b/firmware/hw_layer/openblt/shared_params.c @@ -0,0 +1,250 @@ +/************************************************************************************//** +* \file Demo/ARMCM4_STM32F4_Nucleo_F429ZI_GCC/Prog/shared_params.c +* \brief Shared RAM parameters source file. +* \ingroup Prog_ARMCM4_STM32F4_Nucleo_F429ZI_GCC +* \internal +*---------------------------------------------------------------------------------------- +* C O P Y R I G H T +*---------------------------------------------------------------------------------------- +* Copyright (c) 2021 by Feaser http://www.feaser.com All rights reserved +* +*---------------------------------------------------------------------------------------- +* L I C E N S E +*---------------------------------------------------------------------------------------- +* This file is part of OpenBLT. OpenBLT is free software: you can redistribute it and/or +* modify it under the terms of the GNU General Public License as published by the Free +* Software Foundation, either version 3 of the License, or (at your option) any later +* version. +* +* OpenBLT is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; +* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +* PURPOSE. See the GNU General Public License for more details. +* +* You have received a copy of the GNU General Public License along with OpenBLT. It +* should be located in ".\Doc\license.html". If not, contact Feaser to obtain a copy. +* +* \endinternal +****************************************************************************************/ + +/**************************************************************************************** +* Include files +****************************************************************************************/ +#include /* Standard definitions (NULL). */ +#include "shared_params.h" /* Shared parameters header. */ + + +/**************************************************************************************** +* Macro definitions +****************************************************************************************/ +/** \brief Constant parameter buffer identifier. This value is always located as the + * start of the buffer to validate the the RAM contains valid shared parameters. + */ +#define SHARED_PARAMS_BUFFER_ID (0xCAFEBABEu) + + +/**************************************************************************************** +* Type definitions +****************************************************************************************/ +/** \brief Layout of the shared parameters RAM buffer. */ +typedef struct t_shared_params_buffer +{ + /** \brief Fixed buffer identifier to validate that the RAM contains valid shared + * parameters. + */ + uint32_t identifier; + /** \brief Array for the actual parameter data. */ + uint8_t data[SHARED_PARAMS_CFG_BUFFER_DATA_LEN]; + /** \brief Checksum value of all the bytes in the buffer, excluding this checksum + * value of obvious reasons. The checksum is calculated as the Two's + * complement of the sum of the bytes. + */ + uint16_t checksum; +} tSharedParamsBuffer; + +static tSharedParamsBuffer sharedParamsBuffer __attribute__ ((section (".shared"))); + +/**************************************************************************************** +* Function prototypes +****************************************************************************************/ +static bool SharedParamsValidateBuffer(void); +static void SharedParamsWriteChecksum(void); +static bool SharedParamsVerifyChecksum(void); +static uint16_t SharedParamsCalculateChecksum(void); + + +/************************************************************************************//** +** \brief Initializes the shared RAM parameters module. +** \return none. +** +****************************************************************************************/ +void SharedParamsInit(void) +{ + uint32_t byteIdx; + + /* The shared parameter buffer does not get initialized by the C-startup code. Another + * previously running program could have initialized it, in which case it is ready + * for use and nothing more needs to be done. + */ + if (!SharedParamsValidateBuffer()) + { + /* The shared parameter buffer was not yet initialized by a running program. This + * typically happens after a cold reset where the RAM contents were lost. In this + * case we need to explicitly configure and initialize it, since the C-startup code + * was configured to not do this. + * + * The initialization consists of setting the buffer identifier, zeroing the + * actual parameter data and updating the checksum at the end. + */ + sharedParamsBuffer.identifier = SHARED_PARAMS_BUFFER_ID; + for (byteIdx=0; byteIdx < SHARED_PARAMS_CFG_BUFFER_DATA_LEN; byteIdx++) + { + sharedParamsBuffer.data[byteIdx] = 0; + } + SharedParamsWriteChecksum(); + } +} /*** end of SharedParamsInit ***/ + + +/************************************************************************************//** +** \brief Reads a data byte from the shared parameter buffer at the specified index. +** \param idx Index into the parameter data array. A valid value is between 0 and +** (SHARED_PARAMS_CFG_BUFFER_DATA_LEN - 1). +** \param value Pointer to where the read data value is stored. +** \return True if successful, false otherwise. +** +****************************************************************************************/ +bool SharedParamsReadByIndex(uint32_t idx, uint8_t * value) +{ + bool result = false; + + /* Only continue if the buffer and the specified parameters are valid. */ + if ( (SharedParamsValidateBuffer()) && + (idx < SHARED_PARAMS_CFG_BUFFER_DATA_LEN) && + (value != NULL) ) + { + /* Read the value and update the result. */ + *value = sharedParamsBuffer.data[idx]; + result = true; + } + /* Give the result back to the caller. */ + return result; +} /*** end of SharedParamsReadByIndex ***/ + + +/************************************************************************************//** +** \brief Writes a data byte to the shared parameter buffer at the specified index. +** \param idx Index into the parameter data array. A valid value is between 0 and +** (SHARED_PARAMS_CFG_BUFFER_DATA_LEN - 1). +** \param value Value to write. +** \return True if successful, false otherwise. +** +****************************************************************************************/ +bool SharedParamsWriteByIndex(uint32_t idx, uint8_t value) +{ + bool result = false; + + /* Only continue if the buffer and the specified parameters are valid. */ + if ( (SharedParamsValidateBuffer()) && + (idx < SHARED_PARAMS_CFG_BUFFER_DATA_LEN) ) + { + /* Write the value. */ + sharedParamsBuffer.data[idx] = value; + /* Update the checksum since the contents were just changed. */ + SharedParamsWriteChecksum(); + /* Update the result. */ + result = true; + } + /* Give the result back to the caller. */ + return result; +} /*** end of SharedParamsWriteByIndex ***/ + + +/************************************************************************************//** +** \brief Validates the shared parameter buffer contents by looking at the table +** identifier and verifying its checksum. +** \return True if successful, false otherwise. +** +****************************************************************************************/ +static bool SharedParamsValidateBuffer(void) +{ + bool result = false; + + /* Perform validation. */ + if ( (sharedParamsBuffer.identifier == SHARED_PARAMS_BUFFER_ID) && + (SharedParamsVerifyChecksum()) ) + { + /* The shared parameter buffer is valid, so update the result value. */ + result = true; + } + /* Give the result back to the caller. */ + return result; +} /*** end of SharedParamsValitabeTable ***/ + + +/************************************************************************************//** +** \brief Calculates and writes the checksum into the buffer. +** \return none. +** +****************************************************************************************/ +static void SharedParamsWriteChecksum(void) +{ + /* Calculate and write the checksum. */ + sharedParamsBuffer.checksum = SharedParamsCalculateChecksum(); +} /*** end of SharedParamsWriteChecksum ***/ + + +/************************************************************************************//** +** \brief Calculates and verifies the checksum that is currently present in the +** buffer. +** \return True is the checksum is correct, false otherwise. +** +****************************************************************************************/ +static bool SharedParamsVerifyChecksum(void) +{ + bool result = false; + + /* Calculate and verify the checksum. */ + if (SharedParamsCalculateChecksum() == sharedParamsBuffer.checksum) + { + /* Checksum is correct, so update the result value. */ + result = true; + } + /* Give the result back to the caller. */ + return result; +} /*** end of SharedParamsVerifyChecksum ***/ + + +/************************************************************************************//** +** \brief Calculates and returns the checksum value for the current contents in the +** buffer. The checksum is calculated by taking the sum of all bytes in the +** parameter buffer (excluding the checksum at the end) and them taking the +** two's complement value of it. +** \return The calculated checksum value. +** +****************************************************************************************/ +static uint16_t SharedParamsCalculateChecksum(void) +{ + uint16_t result = 0; + uint32_t byteIdx; + + /* Add the identifier bytes to the checksum. */ + result += (uint8_t)sharedParamsBuffer.identifier; + result += (uint8_t)(sharedParamsBuffer.identifier >> 8u); + result += (uint8_t)(sharedParamsBuffer.identifier >> 16u); + result += (uint8_t)(sharedParamsBuffer.identifier >> 24u); + /* Loop through the parameter data array. */ + for (byteIdx=0; byteIdx /* Standard integer types. */ +#include /* Standard boolean types. */ + + +/**************************************************************************************** +* Configuration macros +****************************************************************************************/ +/** \brief Configuration macro for specifying the size of the data inside the parameter + * buffer. This is the length in bytes of the actual parameter data, so + * excluding the bufferId and checksum. + */ +#define SHARED_PARAMS_CFG_BUFFER_DATA_LEN (16 - 4 - 2) + + +/**************************************************************************************** +* Function prototypes +****************************************************************************************/ +void SharedParamsInit(void); +bool SharedParamsReadByIndex(uint32_t idx, uint8_t * value); +bool SharedParamsWriteByIndex(uint32_t idx, uint8_t value); + + +#endif /* SHARED_PARAMS_H */ +/*********************************** end of shared_params.h ****************************/ diff --git a/firmware/hw_layer/ports/stm32/stm32_common.cpp b/firmware/hw_layer/ports/stm32/stm32_common.cpp index fe4b556a6d..d1c9e239a0 100644 --- a/firmware/hw_layer/ports/stm32/stm32_common.cpp +++ b/firmware/hw_layer/ports/stm32/stm32_common.cpp @@ -19,6 +19,13 @@ #include "stm32h7xx_hal_flash.h" #endif +#if EFI_USE_OPENBLT +/* communication with OpenBLT that is plain C, not to modify external file */ +extern "C" { + #include "openblt/shared_params.h" +}; +#endif + #define _2_MHZ 2'000'000 #if EFI_PROD_CODE @@ -326,7 +333,7 @@ stm32_hardware_pwm* getNextPwmDevice() { } #endif -static void reset_and_jump(uint32_t breadcrumb) { +static void reset_and_jump(void) { #ifdef STM32H7XX // H7 needs a forcible reset of the USB peripheral(s) in order for the bootloader to work properly. // If you don't do this, the bootloader will execute, but USB doesn't work (nobody knows why) @@ -334,18 +341,27 @@ static void reset_and_jump(uint32_t breadcrumb) { RCC->AHB1ENR &= ~(RCC_AHB1ENR_USB1OTGHSEN | RCC_AHB1ENR_USB2OTGFSEN); #endif - *((unsigned long *)0x2001FFF0) = breadcrumb; // End of RAM // and now reboot NVIC_SystemReset(); } void jump_to_bootloader() { // leave DFU breadcrumb which assembly startup code would check, see [rusefi][DFU] section in assembly code - reset_and_jump(0xDEADBEEF); + + *((unsigned long *)0x2001FFF0) = 0xDEADBEEF; // End of RAM + + reset_and_jump(); } void jump_to_openblt() { - reset_and_jump(0xCAFEBABE); +#if EFI_USE_OPENBLT + /* safe to call on already inited shares area */ + SharedParamsInit(); + /* Store sing to stay in OpenBLT */ + SharedParamsWriteByIndex(0, 0x01); + + reset_and_jump(); +#endif } #endif /* EFI_PROD_CODE */ diff --git a/firmware/hw_layer/ports/stm32/stm32f4/STM32F4.ld b/firmware/hw_layer/ports/stm32/stm32f4/STM32F4.ld index 9b06b82eaa..7fc0477a83 100644 --- a/firmware/hw_layer/ports/stm32/stm32f4/STM32F4.ld +++ b/firmware/hw_layer/ports/stm32/stm32f4/STM32F4.ld @@ -29,6 +29,9 @@ RAM3_SIZE = DEFINED(STM32F4_HAS_SRAM3) ? 64k : 0; /* Only STM32F429I-Discovery has external SDRAM */ SDRAM_SIZE = DEFINED(STM32_HAS_SDRAM) ? 8M : 0; +/* OpenBLT <-> main FW shared area */ +_OpenBLT_Shared_Params_Size = DEFINED(BOOTLOADER) ? 16 : 0; + MEMORY { bl : org = 0x08000000, len = 16k /* bootloader section */ @@ -40,8 +43,9 @@ MEMORY flash5 : org = 0x00000000, len = 0 flash6 : org = 0x00000000, len = 0 flash7 : org = 0x00000000, len = 0 - ram0 : org = 0x20000000, len = 128k + RAM3_SIZE /* SRAM1 + SRAM2 + SRAM3 (optionally) */ - ram1 : org = 0x20000000, len = 112k /* SRAM1 */ + shared : org = 0x20000000, len = _OpenBLT_Shared_Params_Size + ram0 : org = 0x20000000 + _OpenBLT_Shared_Params_Size, len = 128k + RAM3_SIZE - _OpenBLT_Shared_Params_Size /* SRAM1 + SRAM2 + SRAM3 (optionally) */ + ram1 : org = 0x20000000 + _OpenBLT_Shared_Params_Size, len = 112k - _OpenBLT_Shared_Params_Size /* SRAM1 */ ram2 : org = 0x2001C000, len = 16k /* SRAM2 */ ram3 : org = 0x20020000, len = RAM3_SIZE /* SRAM3 note: this will be 0 size on F40x devices */ ram4 : org = 0x10000000, len = 64k /* CCM SRAM */ @@ -99,16 +103,30 @@ REGION_ALIAS("HEAP_RAM", ram0); /* RAM region to be used for SDRAM segment.*/ REGION_ALIAS("SDRAM_RAM", ram7); -/* Bootloader section */ SECTIONS { -.bl : ALIGN(4) + /* Bootloader section */ + .bl : ALIGN(4) { . = ALIGN(4); *(.bl) *(.bl.*) . = ALIGN(4); } > bl AT > bl + + /* shared between main FW and OpenBLT */ + .shared (NOLOAD) : + { + . = ALIGN(4); + _sshared = .; + __shared_start__ = _sshared; + *(.shared) + *(.shared.*) + KEEP(*(.shared)) + . = ALIGN(4); + _eshared = .; + __shared_end__ = _eshared; + } > shared } /* Generic rules inclusion.*/ diff --git a/firmware/hw_layer/ports/stm32/stm32f4/openblt/STM32F4xx.ld b/firmware/hw_layer/ports/stm32/stm32f4/openblt/STM32F4xx.ld index a17cb65c7c..6f0629f537 100644 --- a/firmware/hw_layer/ports/stm32/stm32f4/openblt/STM32F4xx.ld +++ b/firmware/hw_layer/ports/stm32/stm32f4/openblt/STM32F4xx.ld @@ -3,10 +3,13 @@ ENTRY(Reset_Handler) /* This linker file is for OpenBLT bootloader. It compatible with any STM32F4xx * that used in RusEFI project. So no CCM memory is defined. Also Flash is - * limited by 32K and first 64bytes of RAM are reserved for shared region + * limited by 32K and last 16bytes of RAM are reserved for shared region * between FW and bootloader */ + +_OpenBLT_Shared_Params_Size = 16; + /* Highest address of the user mode stack */ -_estack = 0x20020000; /* end of RAM */ +_estack = 0x20020000 - _OpenBLT_Shared_Params_Size; /* end of RAM */ /* Generate a link error if heap and stack don't fit into RAM */ _Min_Heap_Size = 0x200; /* required amount of heap */ _Min_Stack_Size = 0x400; /* required amount of stack */ @@ -14,8 +17,8 @@ _Min_Stack_Size = 0x400; /* required amount of stack */ /* Specify the memory areas */ MEMORY { - SHARED (xrw) : ORIGIN = 0x20000000, LENGTH = 64 - RAM (xrw) : ORIGIN = 0x20000040, LENGTH = 128K - 64 + SHARED (xrw) : ORIGIN = 0x20000000, LENGTH = _OpenBLT_Shared_Params_Size + RAM (xrw) : ORIGIN = 0x20000000 + _OpenBLT_Shared_Params_Size, LENGTH = 128K - _OpenBLT_Shared_Params_Size FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 32K } diff --git a/firmware/hw_layer/ports/stm32/stm32f7/STM32F7.ld b/firmware/hw_layer/ports/stm32/stm32f7/STM32F7.ld index 18cc0c8610..bdd5237e6c 100644 --- a/firmware/hw_layer/ports/stm32/stm32f7/STM32F7.ld +++ b/firmware/hw_layer/ports/stm32/stm32f7/STM32F7.ld @@ -28,6 +28,9 @@ /* TODO: 512k flash limit is a mitigation for https://github.com/rusefi/rusefi/issues/3566 and https://github.com/rusefi/rusefi/issues/3775 */ flash_size = DEFINED(FLASH_SIZE) ? FLASH_SIZE : 512k; +/* OpenBLT <-> main FW shared area */ +_OpenBLT_Shared_Params_Size = DEFINED(BOOTLOADER) ? 16 : 0; + MEMORY { bl : org = 0x08000000, len = 16k /* bootloader section */ @@ -41,8 +44,8 @@ MEMORY flash5 (rx) : org = 0x00000000, len = 0 flash6 (rx) : org = 0x00000000, len = 0 flash7 (rx) : org = 0x00000000, len = 0 - ram0 (wx) : org = 0x20020000, len = 384k /* SRAM1 + SRAM2 */ - ram1 (wx) : org = 0x20020000, len = 368k /* SRAM1 */ + ram0 (wx) : org = 0x20020000 + _OpenBLT_Shared_Params_Size, len = 384k - _OpenBLT_Shared_Params_Size /* SRAM1 + SRAM2 */ + ram1 (wx) : org = 0x20020000 + _OpenBLT_Shared_Params_Size, len = 368k - _OpenBLT_Shared_Params_Size /* SRAM1 */ ram2 (wx) : org = 0x2007C000, len = 16k /* SRAM2 */ ram3 (wx) : org = 0x20000000, len = 128k /* DTCM-RAM */ ram4 (wx) : org = 0x00000000, len = 16k /* ITCM-RAM */ @@ -133,6 +136,20 @@ SECTIONS . = ALIGN(4); __eth_end__ = .; } > ETH_RAM + + /* shared between main FW and OpenBLT */ + .shared (NOLOAD) : + { + . = ALIGN(4); + _sshared = .; + __shared_start__ = _sshared; + *(.shared) + *(.shared.*) + KEEP(*(.shared)) + . = ALIGN(4); + _eshared = .; + __shared_end__ = _eshared; + } > shared } /* Code rules inclusion.*/ diff --git a/firmware/hw_layer/ports/stm32/stm32f7/openblt/STM32F7xx.ld b/firmware/hw_layer/ports/stm32/stm32f7/openblt/STM32F7xx.ld index 0c85153a7b..25ba7bd13d 100644 --- a/firmware/hw_layer/ports/stm32/stm32f7/openblt/STM32F7xx.ld +++ b/firmware/hw_layer/ports/stm32/stm32f7/openblt/STM32F7xx.ld @@ -3,10 +3,13 @@ ENTRY(Reset_Handler) /* This linker file is for OpenBLT bootloader. It compatible with any STM32F7xx * that used in RusEFI project. So no CCM memory is defined. Also Flash is - * limited by 32K and first 64bytes of RAM are reserved for shared region + * limited by 32K and last 16bytes of RAM are reserved for shared region * between FW and bootloader */ + +_OpenBLT_Shared_Params_Size = 16; + /* Highest address of the user mode stack */ -_estack = 0x20020000; /* end of RAM */ +_estack = 0x20020000 - _OpenBLT_Shared_Params_Size; /* end of RAM */ /* Generate a link error if heap and stack don't fit into RAM */ _Min_Heap_Size = 0x200; /* required amount of heap */ _Min_Stack_Size = 0x400; /* required amount of stack */ @@ -14,8 +17,8 @@ _Min_Stack_Size = 0x400; /* required amount of stack */ /* Specify the memory areas */ MEMORY { - SHARED (xrw) : ORIGIN = 0x20000000, LENGTH = 64 - RAM (xrw) : ORIGIN = 0x20000040, LENGTH = 128K - 64 + SHARED (xrw) : ORIGIN = 0x20000000, LENGTH = _OpenBLT_Shared_Params_Size + RAM (xrw) : ORIGIN = 0x20000000 + _OpenBLT_Shared_Params_Size, LENGTH = 128K - _OpenBLT_Shared_Params_Size FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 32K }