From f42f99023a8eed9815c88ae177cec6c6acf34c13 Mon Sep 17 00:00:00 2001 From: biliouriv Date: Fri, 4 Nov 2022 15:23:20 +0100 Subject: [PATCH 01/12] [Bootloader] boot modifications for Bootloader Updater --- engine/bootloader/bootloader_core.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/engine/bootloader/bootloader_core.c b/engine/bootloader/bootloader_core.c index 70ad9fe69..0fa1cb06e 100644 --- a/engine/bootloader/bootloader_core.c +++ b/engine/bootloader/bootloader_core.c @@ -41,8 +41,10 @@ bool load_flag = false; uint16_t source_id = 0; // used to save source_id, ie gate_id uint32_t tickstart = 0; + #ifndef BOOTLOADER_UPDATER // Create a variable of the size of mode flash value allowing to init the shared flash section const uint8_t __attribute__((used)) __attribute__((section(".boot_flags"))) sharedSection = BOOT_MODE; + #endif /******************************************************************************* * Function @@ -88,7 +90,11 @@ void LuosBootloader_JumpToBootloader(void) void LuosBootloader_Init(void) { revision_t version = {.major = 2, .minor = 0, .build = 0}; + #ifdef BOOTLOADER_UPDATER + Luos_CreateService(0, VOID_TYPE, "boot_updater", version); + #else Luos_CreateService(0, VOID_TYPE, "boot_service", version); + #endif // set ID node saved in flash LuosBootloader_SetNodeID(); @@ -161,7 +167,11 @@ void LuosBootloader_SetNodeID(void) ******************************************************************************/ uint8_t LuosBootloader_IsEnoughSpace(uint32_t binary_size) { + #ifdef BOOTLOADER_UPDATER + uint32_t free_space = BOOT_START_ADDRESS - APP_START_ADDRESS - 1; + #else uint32_t free_space = APP_END_ADDRESS - APP_START_ADDRESS; + #endif if (free_space > binary_size) { return SUCCEED; From 629ab085b6810dfcfc5fc23d01747da16274f707 Mon Sep 17 00:00:00 2001 From: biliouriv Date: Fri, 4 Nov 2022 15:24:30 +0100 Subject: [PATCH 02/12] [Bootloader example] Boot updater for NUCLEO-L432KC --- .../custom_bootloader_updater_script.ld | 182 ++++++++++++++++++ .../NUCLEO-L432KC/bootloader/node_config.h | 5 + .../NUCLEO-L432KC/bootloader/platformio.ini | 25 ++- 3 files changed, 211 insertions(+), 1 deletion(-) create mode 100644 examples/projects/NUCLEO-L432KC/bootloader/linker/custom_bootloader_updater_script.ld diff --git a/examples/projects/NUCLEO-L432KC/bootloader/linker/custom_bootloader_updater_script.ld b/examples/projects/NUCLEO-L432KC/bootloader/linker/custom_bootloader_updater_script.ld new file mode 100644 index 000000000..d924852f3 --- /dev/null +++ b/examples/projects/NUCLEO-L432KC/bootloader/linker/custom_bootloader_updater_script.ld @@ -0,0 +1,182 @@ +/** + ****************************************************************************** + * @file LinkerScript.ld + * @author Auto-generated by STM32CubeIDE + * @brief Linker script for STM32L432KCUx Device from STM32L4 series + * 256Kbytes FLASH + * 64Kbytes RAM + * + * Set heap size, stack size and stack location according + * to application requirements. + * + * Set memory bank area and size if external memory is used + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2020 STMicroelectronics. + * All rights reserved.

+ * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ + +/* Entry Point */ +ENTRY(Reset_Handler) + +/* Highest address of the user mode stack */ +_estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */ + +_Min_Heap_Size = 0x200; /* required amount of heap */ +_Min_Stack_Size = 0x400; /* required amount of stack */ + +/* Memories definition */ +MEMORY +{ + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 64K + FLASH (rx) : ORIGIN = 0x0800C800, LENGTH = 48K + SHRD_MEM (rw) : ORIGIN = 0x0800C000, LENGTH = 2K +} + +/* Sections */ +SECTIONS +{ + /* placing my boot flags section at given address: */ + .boot_flags : + { + KEEP(*(.boot_flags)) /* keep my variable even if not referenced */ + } > SHRD_MEM + + /* The startup code into "FLASH" Rom type memory */ + .isr_vector : + { + . = ALIGN(4); + KEEP(*(.isr_vector)) /* Startup code */ + . = ALIGN(4); + } >FLASH + + /* The program code and other data into "FLASH" Rom type memory */ + .text : + { + . = ALIGN(4); + *(.text) /* .text sections (code) */ + *(.text*) /* .text* sections (code) */ + *(.glue_7) /* glue arm to thumb code */ + *(.glue_7t) /* glue thumb to arm code */ + *(.eh_frame) + + KEEP (*(.init)) + KEEP (*(.fini)) + + . = ALIGN(4); + _etext = .; /* define a global symbols at end of code */ + } >FLASH + + /* Constant data into "FLASH" Rom type memory */ + .rodata : + { + . = ALIGN(4); + *(.rodata) /* .rodata sections (constants, strings, etc.) */ + *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ + . = ALIGN(4); + } >FLASH + + .ARM.extab : { + . = ALIGN(4); + *(.ARM.extab* .gnu.linkonce.armextab.*) + . = ALIGN(4); + } >FLASH + + .ARM : { + . = ALIGN(4); + __exidx_start = .; + *(.ARM.exidx*) + __exidx_end = .; + . = ALIGN(4); + } >FLASH + + .preinit_array : + { + . = ALIGN(4); + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array*)) + PROVIDE_HIDDEN (__preinit_array_end = .); + . = ALIGN(4); + } >FLASH + + .init_array : + { + . = ALIGN(4); + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array*)) + PROVIDE_HIDDEN (__init_array_end = .); + . = ALIGN(4); + } >FLASH + + .fini_array : + { + . = ALIGN(4); + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(SORT(.fini_array.*))) + KEEP (*(.fini_array*)) + PROVIDE_HIDDEN (__fini_array_end = .); + . = ALIGN(4); + } >FLASH + + /* Used by the startup to initialize data */ + _sidata = LOADADDR(.data); + + /* Initialized data sections into "RAM" Ram type memory */ + .data : + { + . = ALIGN(4); + _sdata = .; /* create a global symbol at data start */ + *(.data) /* .data sections */ + *(.data*) /* .data* sections */ + + . = ALIGN(4); + _edata = .; /* define a global symbol at data end */ + + } >RAM AT> FLASH + + /* Uninitialized data section into "RAM" Ram type memory */ + . = ALIGN(4); + .bss : + { + /* This is used by the startup in order to initialize the .bss section */ + _sbss = .; /* define a global symbol at bss start */ + __bss_start__ = _sbss; + *(.bss) + *(.bss*) + *(COMMON) + + . = ALIGN(4); + _ebss = .; /* define a global symbol at bss end */ + __bss_end__ = _ebss; + } >RAM + + /* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */ + ._user_heap_stack : + { + . = ALIGN(8); + PROVIDE ( end = . ); + PROVIDE ( _end = . ); + . = . + _Min_Heap_Size; + . = . + _Min_Stack_Size; + . = ALIGN(8); + } >RAM + + /* Remove information from the compiler libraries */ + /DISCARD/ : + { + libc.a ( * ) + libm.a ( * ) + libgcc.a ( * ) + } + + .ARM.attributes 0 : { *(.ARM.attributes) } +} diff --git a/examples/projects/NUCLEO-L432KC/bootloader/node_config.h b/examples/projects/NUCLEO-L432KC/bootloader/node_config.h index c2c242240..36f2f9fe9 100644 --- a/examples/projects/NUCLEO-L432KC/bootloader/node_config.h +++ b/examples/projects/NUCLEO-L432KC/bootloader/node_config.h @@ -91,5 +91,10 @@ * APP_START_ADDRESS | 0x0800C800 | Start address of application with bootloader * APP_END_ADDRESS | FLASH_END | End address of application with bootloader ******************************************************************************/ +#ifdef BOOTLOADER_UPDATER + #define BOOT_START_ADDRESS 0x800C800 + #define APP_START_ADDRESS 0x8000000 + #define APP_END_ADDRESS 0x800BFFF +#endif #endif /* _NODE_CONFIG_H_ */ diff --git a/examples/projects/NUCLEO-L432KC/bootloader/platformio.ini b/examples/projects/NUCLEO-L432KC/bootloader/platformio.ini index 5ff5a0d18..29596d0f6 100644 --- a/examples/projects/NUCLEO-L432KC/bootloader/platformio.ini +++ b/examples/projects/NUCLEO-L432KC/bootloader/platformio.ini @@ -8,11 +8,16 @@ ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html -[env:nucleo_l432kc] +[platformio] +default_envs = nucleo_l432kc + +[env] platform = ststm32 board = nucleo_l432kc lib_extra_dirs = $PROJECT_DIR/../../../../../ framework = stm32cube + +[env:nucleo_l432kc] board_build.ldscript = linker/custom_bootloader_script.ld build_unflags = -Os build_flags = @@ -27,3 +32,21 @@ lib_deps = debug_tool = stlink upload_protocol = stlink +[env:nucleo_l432kc_updater] +board_build.ldscript = linker/custom_bootloader_updater_script.ld +build_unflags = -Os +build_flags = + -O1 + -include node_config.h + -DUSE_HAL_DRIVER + -DUSE_FULL_LL_DRIVER + -DLUOSHAL=STM32L4 + -DBOOTLOADER + -DBOOTLOADER_UPDATER +lib_deps = + luos_engine@^2.6.4 +upload_protocol = custom +upload_flags = + -t2 +upload_command = pyluos-bootloader flash $UPLOAD_PORT $UPLOAD_FLAGS -b $SOURCE + From 8c6e69a00bc41d0f2b8adc7c5a11dedd5d2f57fd Mon Sep 17 00:00:00 2001 From: biliouriv Date: Fri, 4 Nov 2022 18:15:02 +0100 Subject: [PATCH 03/12] [Bootloader example] bootloader updater for NUCLEO-F072RB --- .../custom_bootloader_updater_script.ld | 189 ++++++++++++++++++ .../linker/custom_new_bootloader_script.ld | 189 ++++++++++++++++++ .../NUCLEO-F072RB/bootloader/node_config.h | 6 +- .../NUCLEO-F072RB/bootloader/platformio.ini | 42 +++- 4 files changed, 421 insertions(+), 5 deletions(-) create mode 100644 examples/projects/NUCLEO-F072RB/bootloader/linker/custom_bootloader_updater_script.ld create mode 100644 examples/projects/NUCLEO-F072RB/bootloader/linker/custom_new_bootloader_script.ld diff --git a/examples/projects/NUCLEO-F072RB/bootloader/linker/custom_bootloader_updater_script.ld b/examples/projects/NUCLEO-F072RB/bootloader/linker/custom_bootloader_updater_script.ld new file mode 100644 index 000000000..8a899f1dd --- /dev/null +++ b/examples/projects/NUCLEO-F072RB/bootloader/linker/custom_bootloader_updater_script.ld @@ -0,0 +1,189 @@ +/** + ****************************************************************************** + * @file LinkerScript.ld + * @author Auto-generated by STM32CubeIDE + * @brief Linker script for STM32F072RBTx Device from STM32F0 series + * 128Kbytes FLASH + * 16Kbytes RAM + * + * Set heap size, stack size and stack location according + * to application requirements. + * + * Set memory bank area and size if external memory is used + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2020 STMicroelectronics. + * All rights reserved.

+ * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ + +/* Entry Point */ +ENTRY(Reset_Handler) + +/* Highest address of the user mode stack */ +_estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */ + +_Min_Heap_Size = 0x200; /* required amount of heap */ +_Min_Stack_Size = 0x400; /* required amount of stack */ + +/* Memories definition */ +MEMORY +{ + RAM_RSVD (xrw) : ORIGIN = 0x20000000, LENGTH = 1K + RAM (xrw) : ORIGIN = 0x20000400, LENGTH = 15K + FLASH (rw) : ORIGIN = 0x800C800, LENGTH = 48K + SHRD_MEM (rx) : ORIGIN = 0x800C000, LENGTH = 2K +} + +/* Sections */ +SECTIONS +{ + /* placing my boot flags section at given address: */ + .boot_flags : + { + KEEP(*(.boot_flags)) /* keep my variable even if not referenced */ + } > SHRD_MEM + + /* The startup code into "FLASH" Rom type memory */ + .isr_vector : + { + . = ALIGN(4); + KEEP(*(.isr_vector)) /* Startup code */ + . = ALIGN(4); + } >FLASH + + /* The program code and other data into "FLASH" Rom type memory */ + .text : + { + . = ALIGN(4); + *(.text) /* .text sections (code) */ + *(.text*) /* .text* sections (code) */ + *(.glue_7) /* glue arm to thumb code */ + *(.glue_7t) /* glue thumb to arm code */ + *(.eh_frame) + + KEEP (*(.init)) + KEEP (*(.fini)) + + . = ALIGN(4); + _etext = .; /* define a global symbols at end of code */ + } >FLASH + + /* Constant data into "FLASH" Rom type memory */ + .rodata : + { + . = ALIGN(4); + *(.rodata) /* .rodata sections (constants, strings, etc.) */ + *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ + . = ALIGN(4); + } >FLASH + + .ARM.extab : { + . = ALIGN(4); + *(.ARM.extab* .gnu.linkonce.armextab.*) + . = ALIGN(4); + } >FLASH + + .ARM : { + . = ALIGN(4); + __exidx_start = .; + *(.ARM.exidx*) + __exidx_end = .; + . = ALIGN(4); + } >FLASH + + .preinit_array : + { + . = ALIGN(4); + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array*)) + PROVIDE_HIDDEN (__preinit_array_end = .); + . = ALIGN(4); + } >FLASH + + .init_array : + { + . = ALIGN(4); + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array*)) + PROVIDE_HIDDEN (__init_array_end = .); + . = ALIGN(4); + } >FLASH + + .fini_array : + { + . = ALIGN(4); + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(SORT(.fini_array.*))) + KEEP (*(.fini_array*)) + PROVIDE_HIDDEN (__fini_array_end = .); + . = ALIGN(4); + } >FLASH + + /* Used by the startup to initialize data */ + _sidata = LOADADDR(.data); + + /* Initialized data sections into "RAM" Ram type memory */ + .data : + { + . = ALIGN(4); + _sdata = .; /* create a global symbol at data start */ + *(.data) /* .data sections */ + *(.data*) /* .data* sections */ + + . = ALIGN(4); + _edata = .; /* define a global symbol at data end */ + + } >RAM AT> FLASH + + /* Uninitialized data section into "RAM" Ram type memory */ + . = ALIGN(4); + .bss : + { + /* This is used by the startup in order to initialize the .bss section */ + _sbss = .; /* define a global symbol at bss start */ + __bss_start__ = _sbss; + *(.bss) + *(.bss*) + *(COMMON) + + . = ALIGN(4); + _ebss = .; /* define a global symbol at bss end */ + __bss_end__ = _ebss; + } >RAM + + /* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */ + ._user_heap_stack : + { + . = ALIGN(8); + PROVIDE ( end = . ); + PROVIDE ( _end = . ); + . = . + _Min_Heap_Size; + . = . + _Min_Stack_Size; + . = ALIGN(8); + } >RAM + + .boot_data : + { + *(.rsvd.data) + *(.rsvd.data*) + } > RAM_RSVD + + /* Remove information from the compiler libraries */ + /DISCARD/ : + { + libc.a ( * ) + libm.a ( * ) + libgcc.a ( * ) + } + + .ARM.attributes 0 : { *(.ARM.attributes) } +} diff --git a/examples/projects/NUCLEO-F072RB/bootloader/linker/custom_new_bootloader_script.ld b/examples/projects/NUCLEO-F072RB/bootloader/linker/custom_new_bootloader_script.ld new file mode 100644 index 000000000..4baac8d22 --- /dev/null +++ b/examples/projects/NUCLEO-F072RB/bootloader/linker/custom_new_bootloader_script.ld @@ -0,0 +1,189 @@ +/** + ****************************************************************************** + * @file LinkerScript.ld + * @author Auto-generated by STM32CubeIDE + * @brief Linker script for STM32F072RBTx Device from STM32F0 series + * 128Kbytes FLASH + * 16Kbytes RAM + * + * Set heap size, stack size and stack location according + * to application requirements. + * + * Set memory bank area and size if external memory is used + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2020 STMicroelectronics. + * All rights reserved.

+ * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ + +/* Entry Point */ +ENTRY(Reset_Handler) + +/* Highest address of the user mode stack */ +_estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */ + +_Min_Heap_Size = 0x200; /* required amount of heap */ +_Min_Stack_Size = 0x400; /* required amount of stack */ + +/* Memories definition */ +MEMORY +{ + RAM_RSVD (xrw) : ORIGIN = 0x20000000, LENGTH = 1K + RAM (xrw) : ORIGIN = 0x20000400, LENGTH = 15K + FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 48K + SHRD_MEM (rx) : ORIGIN = 0x800C000, LENGTH = 2K +} + +/* Sections */ +SECTIONS +{ + /* placing my boot flags section at given address: */ + .boot_flags : + { + KEEP(*(.boot_flags)) /* keep my variable even if not referenced */ + } > SHRD_MEM + + /* The startup code into "FLASH" Rom type memory */ + .isr_vector : + { + . = ALIGN(4); + KEEP(*(.isr_vector)) /* Startup code */ + . = ALIGN(4); + } >FLASH + + /* The program code and other data into "FLASH" Rom type memory */ + .text : + { + . = ALIGN(4); + *(.text) /* .text sections (code) */ + *(.text*) /* .text* sections (code) */ + *(.glue_7) /* glue arm to thumb code */ + *(.glue_7t) /* glue thumb to arm code */ + *(.eh_frame) + + KEEP (*(.init)) + KEEP (*(.fini)) + + . = ALIGN(4); + _etext = .; /* define a global symbols at end of code */ + } >FLASH + + /* Constant data into "FLASH" Rom type memory */ + .rodata : + { + . = ALIGN(4); + *(.rodata) /* .rodata sections (constants, strings, etc.) */ + *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ + . = ALIGN(4); + } >FLASH + + .ARM.extab : { + . = ALIGN(4); + *(.ARM.extab* .gnu.linkonce.armextab.*) + . = ALIGN(4); + } >FLASH + + .ARM : { + . = ALIGN(4); + __exidx_start = .; + *(.ARM.exidx*) + __exidx_end = .; + . = ALIGN(4); + } >FLASH + + .preinit_array : + { + . = ALIGN(4); + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array*)) + PROVIDE_HIDDEN (__preinit_array_end = .); + . = ALIGN(4); + } >FLASH + + .init_array : + { + . = ALIGN(4); + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array*)) + PROVIDE_HIDDEN (__init_array_end = .); + . = ALIGN(4); + } >FLASH + + .fini_array : + { + . = ALIGN(4); + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(SORT(.fini_array.*))) + KEEP (*(.fini_array*)) + PROVIDE_HIDDEN (__fini_array_end = .); + . = ALIGN(4); + } >FLASH + + /* Used by the startup to initialize data */ + _sidata = LOADADDR(.data); + + /* Initialized data sections into "RAM" Ram type memory */ + .data : + { + . = ALIGN(4); + _sdata = .; /* create a global symbol at data start */ + *(.data) /* .data sections */ + *(.data*) /* .data* sections */ + + . = ALIGN(4); + _edata = .; /* define a global symbol at data end */ + + } >RAM AT> FLASH + + /* Uninitialized data section into "RAM" Ram type memory */ + . = ALIGN(4); + .bss : + { + /* This is used by the startup in order to initialize the .bss section */ + _sbss = .; /* define a global symbol at bss start */ + __bss_start__ = _sbss; + *(.bss) + *(.bss*) + *(COMMON) + + . = ALIGN(4); + _ebss = .; /* define a global symbol at bss end */ + __bss_end__ = _ebss; + } >RAM + + /* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */ + ._user_heap_stack : + { + . = ALIGN(8); + PROVIDE ( end = . ); + PROVIDE ( _end = . ); + . = . + _Min_Heap_Size; + . = . + _Min_Stack_Size; + . = ALIGN(8); + } >RAM + + .boot_data : + { + *(.rsvd.data) + *(.rsvd.data*) + } > RAM_RSVD + + /* Remove information from the compiler libraries */ + /DISCARD/ : + { + libc.a ( * ) + libm.a ( * ) + libgcc.a ( * ) + } + + .ARM.attributes 0 : { *(.ARM.attributes) } +} diff --git a/examples/projects/NUCLEO-F072RB/bootloader/node_config.h b/examples/projects/NUCLEO-F072RB/bootloader/node_config.h index b872e47f2..0e1ee0e81 100644 --- a/examples/projects/NUCLEO-F072RB/bootloader/node_config.h +++ b/examples/projects/NUCLEO-F072RB/bootloader/node_config.h @@ -96,5 +96,9 @@ * APP_START_ADDRESS | 0x0800C800 | Start address of application with bootloader * APP_END_ADDRESS | FLASH_BANK1_END=0x0801FFFF | End address of application with bootloader ******************************************************************************/ - +#ifdef BOOTLOADER_UPDATER + #define BOOT_START_ADDRESS 0x800C800 + #define APP_START_ADDRESS 0x8000000 + #define APP_END_ADDRESS 0x800BFFF +#endif #endif /* _NODE_CONFIG_H_ */ diff --git a/examples/projects/NUCLEO-F072RB/bootloader/platformio.ini b/examples/projects/NUCLEO-F072RB/bootloader/platformio.ini index 4aa945588..ee5630c05 100644 --- a/examples/projects/NUCLEO-F072RB/bootloader/platformio.ini +++ b/examples/projects/NUCLEO-F072RB/bootloader/platformio.ini @@ -7,12 +7,18 @@ ; ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html +[platformio] +default_envs = nucleo_f072rb -[env:nucleo_f072rb] +[env] platform = ststm32 board = nucleo_f072rb lib_extra_dirs = $PROJECT_DIR/../../../../../ framework = stm32cube +lib_deps = + luos_engine@^2.8.0 + +[env:nucleo_f072rb] board_build.ldscript = linker/custom_bootloader_script.ld build_unflags = -Os build_flags = @@ -22,8 +28,36 @@ build_flags = -DUSE_FULL_LL_DRIVER -DLUOSHAL=STM32F0 -O1 -debug_build_flags = -O0 -g -ggdb -lib_deps = - luos_engine@^2.8.0 debug_tool = stlink upload_protocol = stlink + +[env:nucleo_f072rb_updater] +board_build.ldscript = linker/custom_bootloader_updater_script.ld +build_unflags = -Os +build_flags = + -include node_config.h + -DBOOTLOADER + -DBOOTLOADER_UPDATER + -DUSE_HAL_DRIVER + -DUSE_FULL_LL_DRIVER + -DLUOSHAL=STM32F0 + -O1 +upload_protocol = custom +upload_flags = + -t2 +upload_command = pyluos-bootloader flash $UPLOAD_PORT $UPLOAD_FLAGS -b $SOURCE + +[env:nucleo_f072rb_new_boot] +board_build.ldscript = linker/custom_new_bootloader_script.ld +build_unflags = -Os +build_flags = + -include node_config.h + -DBOOTLOADER + -DUSE_HAL_DRIVER + -DUSE_FULL_LL_DRIVER + -DLUOSHAL=STM32F0 + -O1 +upload_protocol = custom +upload_flags = + -t2 +upload_command = pyluos-bootloader flash $UPLOAD_PORT $UPLOAD_FLAGS -b $SOURCE From c8b61ac65f7840dcaa06f9510538066b63a56799 Mon Sep 17 00:00:00 2001 From: biliouriv Date: Fri, 4 Nov 2022 18:16:20 +0100 Subject: [PATCH 04/12] [Bootloader] bootloader updater for l0 --- .../custom_bootloader_updater_script.ld | 190 ++++++++++++++++++ .../linker/custom_new_bootloader_script.ld | 190 ++++++++++++++++++ examples/projects/l0/bootloader/node_config.h | 5 + .../projects/l0/bootloader/platformio.ini | 37 +++- 4 files changed, 418 insertions(+), 4 deletions(-) create mode 100644 examples/projects/l0/bootloader/linker/custom_bootloader_updater_script.ld create mode 100644 examples/projects/l0/bootloader/linker/custom_new_bootloader_script.ld diff --git a/examples/projects/l0/bootloader/linker/custom_bootloader_updater_script.ld b/examples/projects/l0/bootloader/linker/custom_bootloader_updater_script.ld new file mode 100644 index 000000000..5c47e8dd8 --- /dev/null +++ b/examples/projects/l0/bootloader/linker/custom_bootloader_updater_script.ld @@ -0,0 +1,190 @@ +/** + ****************************************************************************** + * @file LinkerScript.ld + * @author Auto-generated by STM32CubeIDE + * @brief Linker script for STM32F072RBTx Device from STM32F0 series + * 128Kbytes FLASH + * 16Kbytes RAM + * + * Set heap size, stack size and stack location according + * to application requirements. + * + * Set memory bank area and size if external memory is used + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2020 STMicroelectronics. + * All rights reserved.

+ * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ + +/* Entry Point */ +ENTRY(Reset_Handler) + +/* Highest address of the user mode stack */ +_estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */ + +_Min_Heap_Size = 0x200; /* required amount of heap */ +_Min_Stack_Size = 0x400; /* required amount of stack */ + +/* Memories definition */ +MEMORY +{ + RAM_RSVD (xrw) : ORIGIN = 0x20000000, LENGTH = 1K + RAM (xrw) : ORIGIN = 0x20000400, LENGTH = 15K + FLASH (rw) : ORIGIN = 0x800C800, LENGTH = 48K + SHRD_MEM (rx) : ORIGIN = 0x800C000, LENGTH = 2K +} + +/* Sections */ + +SECTIONS +{ + /* placing my boot flags section at given address: */ + .boot_flags : + { + KEEP(*(.boot_flags)) /* keep my variable even if not referenced */ + } > SHRD_MEM + + /* The startup code into "FLASH" Rom type memory */ + .isr_vector : + { + . = ALIGN(4); + KEEP(*(.isr_vector)) /* Startup code */ + . = ALIGN(4); + } >FLASH + + /* The program code and other data into "FLASH" Rom type memory */ + .text : + { + . = ALIGN(4); + *(.text) /* .text sections (code) */ + *(.text*) /* .text* sections (code) */ + *(.glue_7) /* glue arm to thumb code */ + *(.glue_7t) /* glue thumb to arm code */ + *(.eh_frame) + + KEEP (*(.init)) + KEEP (*(.fini)) + + . = ALIGN(4); + _etext = .; /* define a global symbols at end of code */ + } >FLASH + + /* Constant data into "FLASH" Rom type memory */ + .rodata : + { + . = ALIGN(4); + *(.rodata) /* .rodata sections (constants, strings, etc.) */ + *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ + . = ALIGN(4); + } >FLASH + + .ARM.extab : { + . = ALIGN(4); + *(.ARM.extab* .gnu.linkonce.armextab.*) + . = ALIGN(4); + } >FLASH + + .ARM : { + . = ALIGN(4); + __exidx_start = .; + *(.ARM.exidx*) + __exidx_end = .; + . = ALIGN(4); + } >FLASH + + .preinit_array : + { + . = ALIGN(4); + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array*)) + PROVIDE_HIDDEN (__preinit_array_end = .); + . = ALIGN(4); + } >FLASH + + .init_array : + { + . = ALIGN(4); + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array*)) + PROVIDE_HIDDEN (__init_array_end = .); + . = ALIGN(4); + } >FLASH + + .fini_array : + { + . = ALIGN(4); + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(SORT(.fini_array.*))) + KEEP (*(.fini_array*)) + PROVIDE_HIDDEN (__fini_array_end = .); + . = ALIGN(4); + } >FLASH + + /* Used by the startup to initialize data */ + _sidata = LOADADDR(.data); + + /* Initialized data sections into "RAM" Ram type memory */ + .data : + { + . = ALIGN(4); + _sdata = .; /* create a global symbol at data start */ + *(.data) /* .data sections */ + *(.data*) /* .data* sections */ + + . = ALIGN(4); + _edata = .; /* define a global symbol at data end */ + + } >RAM AT> FLASH + + /* Uninitialized data section into "RAM" Ram type memory */ + . = ALIGN(4); + .bss : + { + /* This is used by the startup in order to initialize the .bss section */ + _sbss = .; /* define a global symbol at bss start */ + __bss_start__ = _sbss; + *(.bss) + *(.bss*) + *(COMMON) + + . = ALIGN(4); + _ebss = .; /* define a global symbol at bss end */ + __bss_end__ = _ebss; + } >RAM + + /* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */ + ._user_heap_stack : + { + . = ALIGN(8); + PROVIDE ( end = . ); + PROVIDE ( _end = . ); + . = . + _Min_Heap_Size; + . = . + _Min_Stack_Size; + . = ALIGN(8); + } >RAM + + .boot_data : + { + *(.rsvd.data) + *(.rsvd.data*) + } > RAM_RSVD + + /* Remove information from the compiler libraries */ + /DISCARD/ : + { + libc.a ( * ) + libm.a ( * ) + libgcc.a ( * ) + } + + .ARM.attributes 0 : { *(.ARM.attributes) } +} diff --git a/examples/projects/l0/bootloader/linker/custom_new_bootloader_script.ld b/examples/projects/l0/bootloader/linker/custom_new_bootloader_script.ld new file mode 100644 index 000000000..10aeffb7b --- /dev/null +++ b/examples/projects/l0/bootloader/linker/custom_new_bootloader_script.ld @@ -0,0 +1,190 @@ +/** + ****************************************************************************** + * @file LinkerScript.ld + * @author Auto-generated by STM32CubeIDE + * @brief Linker script for STM32F072RBTx Device from STM32F0 series + * 128Kbytes FLASH + * 16Kbytes RAM + * + * Set heap size, stack size and stack location according + * to application requirements. + * + * Set memory bank area and size if external memory is used + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2020 STMicroelectronics. + * All rights reserved.

+ * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ + +/* Entry Point */ +ENTRY(Reset_Handler) + +/* Highest address of the user mode stack */ +_estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */ + +_Min_Heap_Size = 0x200; /* required amount of heap */ +_Min_Stack_Size = 0x400; /* required amount of stack */ + +/* Memories definition */ +MEMORY +{ + RAM_RSVD (xrw) : ORIGIN = 0x20000000, LENGTH = 1K + RAM (xrw) : ORIGIN = 0x20000400, LENGTH = 15K + FLASH (rw) : ORIGIN = 0x8000000, LENGTH = 48K + SHRD_MEM (rx) : ORIGIN = 0x800C000, LENGTH = 2K +} + +/* Sections */ + +SECTIONS +{ + /* placing my boot flags section at given address: */ + .boot_flags : + { + KEEP(*(.boot_flags)) /* keep my variable even if not referenced */ + } > SHRD_MEM + + /* The startup code into "FLASH" Rom type memory */ + .isr_vector : + { + . = ALIGN(4); + KEEP(*(.isr_vector)) /* Startup code */ + . = ALIGN(4); + } >FLASH + + /* The program code and other data into "FLASH" Rom type memory */ + .text : + { + . = ALIGN(4); + *(.text) /* .text sections (code) */ + *(.text*) /* .text* sections (code) */ + *(.glue_7) /* glue arm to thumb code */ + *(.glue_7t) /* glue thumb to arm code */ + *(.eh_frame) + + KEEP (*(.init)) + KEEP (*(.fini)) + + . = ALIGN(4); + _etext = .; /* define a global symbols at end of code */ + } >FLASH + + /* Constant data into "FLASH" Rom type memory */ + .rodata : + { + . = ALIGN(4); + *(.rodata) /* .rodata sections (constants, strings, etc.) */ + *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ + . = ALIGN(4); + } >FLASH + + .ARM.extab : { + . = ALIGN(4); + *(.ARM.extab* .gnu.linkonce.armextab.*) + . = ALIGN(4); + } >FLASH + + .ARM : { + . = ALIGN(4); + __exidx_start = .; + *(.ARM.exidx*) + __exidx_end = .; + . = ALIGN(4); + } >FLASH + + .preinit_array : + { + . = ALIGN(4); + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array*)) + PROVIDE_HIDDEN (__preinit_array_end = .); + . = ALIGN(4); + } >FLASH + + .init_array : + { + . = ALIGN(4); + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array*)) + PROVIDE_HIDDEN (__init_array_end = .); + . = ALIGN(4); + } >FLASH + + .fini_array : + { + . = ALIGN(4); + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(SORT(.fini_array.*))) + KEEP (*(.fini_array*)) + PROVIDE_HIDDEN (__fini_array_end = .); + . = ALIGN(4); + } >FLASH + + /* Used by the startup to initialize data */ + _sidata = LOADADDR(.data); + + /* Initialized data sections into "RAM" Ram type memory */ + .data : + { + . = ALIGN(4); + _sdata = .; /* create a global symbol at data start */ + *(.data) /* .data sections */ + *(.data*) /* .data* sections */ + + . = ALIGN(4); + _edata = .; /* define a global symbol at data end */ + + } >RAM AT> FLASH + + /* Uninitialized data section into "RAM" Ram type memory */ + . = ALIGN(4); + .bss : + { + /* This is used by the startup in order to initialize the .bss section */ + _sbss = .; /* define a global symbol at bss start */ + __bss_start__ = _sbss; + *(.bss) + *(.bss*) + *(COMMON) + + . = ALIGN(4); + _ebss = .; /* define a global symbol at bss end */ + __bss_end__ = _ebss; + } >RAM + + /* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */ + ._user_heap_stack : + { + . = ALIGN(8); + PROVIDE ( end = . ); + PROVIDE ( _end = . ); + . = . + _Min_Heap_Size; + . = . + _Min_Stack_Size; + . = ALIGN(8); + } >RAM + + .boot_data : + { + *(.rsvd.data) + *(.rsvd.data*) + } > RAM_RSVD + + /* Remove information from the compiler libraries */ + /DISCARD/ : + { + libc.a ( * ) + libm.a ( * ) + libgcc.a ( * ) + } + + .ARM.attributes 0 : { *(.ARM.attributes) } +} diff --git a/examples/projects/l0/bootloader/node_config.h b/examples/projects/l0/bootloader/node_config.h index eed1766b3..4eb86040c 100644 --- a/examples/projects/l0/bootloader/node_config.h +++ b/examples/projects/l0/bootloader/node_config.h @@ -93,5 +93,10 @@ * APP_START_ADDRESS | 0x0800C800 | Start address of application with bootloader * APP_END_ADDRESS | FLASH_BANK1_END=0x0801FFFF | End address of application with bootloader ******************************************************************************/ +#ifdef BOOTLOADER_UPDATER + #define BOOT_START_ADDRESS 0x800C800 + #define APP_START_ADDRESS 0x8000000 + #define APP_END_ADDRESS 0x800BFFF +#endif #endif /* _NODE_CONFIG_H_ */ diff --git a/examples/projects/l0/bootloader/platformio.ini b/examples/projects/l0/bootloader/platformio.ini index a8c26deab..a0f342406 100644 --- a/examples/projects/l0/bootloader/platformio.ini +++ b/examples/projects/l0/bootloader/platformio.ini @@ -8,18 +8,47 @@ ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html -[env:l0] +[platformio] +default_envs = l0 + +[env] platform = ststm32 board = l0 framework = stm32cube lib_extra_dirs = $PROJECT_DIR/../../../../../ +lib_deps = + luos_engine@^2.8.0 + +[env:l0] board_build.ldscript = linker/custom_bootloader_script.ld build_unflags = -Os build_flags = -include node_config.h -D BOOTLOADER -O1 -debug_build_flags = -O0 -g -ggdb -lib_deps = - luos_engine@^2.8.0 debug_tool = stlink + +[env:l0_updater] +board_build.ldscript = linker/custom_bootloader_updater_script.ld +build_unflags = -Os +build_flags = + -include node_config.h + -D BOOTLOADER + -O1 + -D BOOTLOADER_UPDATER +upload_protocol = custom +upload_flags = + -t2 +upload_command = pyluos-bootloader flash $UPLOAD_PORT $UPLOAD_FLAGS -b $SOURCE + +[env:l0_new_boot] +board_build.ldscript = linker/custom_new_bootloader_script.ld +build_unflags = -Os +build_flags = + -include node_config.h + -D BOOTLOADER + -O1 +upload_protocol = custom +upload_flags = + -t2 +upload_command = pyluos-bootloader flash $UPLOAD_PORT $UPLOAD_FLAGS -b $SOURCE From a39b728aeeab42733c403c5f7cea437996a58fdd Mon Sep 17 00:00:00 2001 From: biliouriv Date: Mon, 7 Nov 2022 15:27:21 +0100 Subject: [PATCH 05/12] [Bootloader] bootloader updater for NUCLEO-G474RE --- .../custom_bootloader_updater_script.ld | 182 ++++++++++++++++++ .../NUCLEO-G474RE/bootloader/node_config.h | 6 +- .../NUCLEO-G474RE/bootloader/platformio.ini | 30 ++- 3 files changed, 212 insertions(+), 6 deletions(-) create mode 100644 examples/projects/NUCLEO-G474RE/bootloader/linker/custom_bootloader_updater_script.ld diff --git a/examples/projects/NUCLEO-G474RE/bootloader/linker/custom_bootloader_updater_script.ld b/examples/projects/NUCLEO-G474RE/bootloader/linker/custom_bootloader_updater_script.ld new file mode 100644 index 000000000..6d0fe8bb2 --- /dev/null +++ b/examples/projects/NUCLEO-G474RE/bootloader/linker/custom_bootloader_updater_script.ld @@ -0,0 +1,182 @@ +/** + ****************************************************************************** + * @file LinkerScript.ld + * @author Auto-generated by STM32CubeIDE + * @brief Linker script for STM32G431KBTx Device from STM32G4 series + * 128Kbytes FLASH + * 32Kbytes RAM + * + * Set heap size, stack size and stack location according + * to application requirements. + * + * Set memory bank area and size if external memory is used + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2020 STMicroelectronics. + * All rights reserved.

+ * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ + +/* Entry Point */ +ENTRY(Reset_Handler) + +/* Highest address of the user mode stack */ +_estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */ + +_Min_Heap_Size = 0x200; /* required amount of heap */ +_Min_Stack_Size = 0x400; /* required amount of stack */ + +/* Memories definition */ +MEMORY +{ + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K + FLASH (rx) : ORIGIN = 0x800C800, LENGTH = 48K + SHRD_MEM (rx) : ORIGIN = 0x0800C000, LENGTH = 2K +} + +/* Sections */ +SECTIONS +{ + /* placing my boot flags section at given address: */ + .boot_flags : + { + KEEP(*(.boot_flags)) /* keep my variable even if not referenced */ + } > SHRD_MEM + + /* The startup code into "FLASH" Rom type memory */ + .isr_vector : + { + . = ALIGN(4); + KEEP(*(.isr_vector)) /* Startup code */ + . = ALIGN(4); + } >FLASH + + /* The program code and other data into "FLASH" Rom type memory */ + .text : + { + . = ALIGN(4); + *(.text) /* .text sections (code) */ + *(.text*) /* .text* sections (code) */ + *(.glue_7) /* glue arm to thumb code */ + *(.glue_7t) /* glue thumb to arm code */ + *(.eh_frame) + + KEEP (*(.init)) + KEEP (*(.fini)) + + . = ALIGN(4); + _etext = .; /* define a global symbols at end of code */ + } >FLASH + + /* Constant data into "FLASH" Rom type memory */ + .rodata : + { + . = ALIGN(4); + *(.rodata) /* .rodata sections (constants, strings, etc.) */ + *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ + . = ALIGN(4); + } >FLASH + + .ARM.extab : { + . = ALIGN(4); + *(.ARM.extab* .gnu.linkonce.armextab.*) + . = ALIGN(4); + } >FLASH + + .ARM : { + . = ALIGN(4); + __exidx_start = .; + *(.ARM.exidx*) + __exidx_end = .; + . = ALIGN(4); + } >FLASH + + .preinit_array : + { + . = ALIGN(4); + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array*)) + PROVIDE_HIDDEN (__preinit_array_end = .); + . = ALIGN(4); + } >FLASH + + .init_array : + { + . = ALIGN(4); + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array*)) + PROVIDE_HIDDEN (__init_array_end = .); + . = ALIGN(4); + } >FLASH + + .fini_array : + { + . = ALIGN(4); + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(SORT(.fini_array.*))) + KEEP (*(.fini_array*)) + PROVIDE_HIDDEN (__fini_array_end = .); + . = ALIGN(4); + } >FLASH + + /* Used by the startup to initialize data */ + _sidata = LOADADDR(.data); + + /* Initialized data sections into "RAM" Ram type memory */ + .data : + { + . = ALIGN(4); + _sdata = .; /* create a global symbol at data start */ + *(.data) /* .data sections */ + *(.data*) /* .data* sections */ + + . = ALIGN(4); + _edata = .; /* define a global symbol at data end */ + + } >RAM AT> FLASH + + /* Uninitialized data section into "RAM" Ram type memory */ + . = ALIGN(4); + .bss : + { + /* This is used by the startup in order to initialize the .bss section */ + _sbss = .; /* define a global symbol at bss start */ + __bss_start__ = _sbss; + *(.bss) + *(.bss*) + *(COMMON) + + . = ALIGN(4); + _ebss = .; /* define a global symbol at bss end */ + __bss_end__ = _ebss; + } >RAM + + /* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */ + ._user_heap_stack : + { + . = ALIGN(8); + PROVIDE ( end = . ); + PROVIDE ( _end = . ); + . = . + _Min_Heap_Size; + . = . + _Min_Stack_Size; + . = ALIGN(8); + } >RAM + + /* Remove information from the compiler libraries */ + /DISCARD/ : + { + libc.a ( * ) + libm.a ( * ) + libgcc.a ( * ) + } + + .ARM.attributes 0 : { *(.ARM.attributes) } +} diff --git a/examples/projects/NUCLEO-G474RE/bootloader/node_config.h b/examples/projects/NUCLEO-G474RE/bootloader/node_config.h index c2c242240..114000d6a 100644 --- a/examples/projects/NUCLEO-G474RE/bootloader/node_config.h +++ b/examples/projects/NUCLEO-G474RE/bootloader/node_config.h @@ -91,5 +91,9 @@ * APP_START_ADDRESS | 0x0800C800 | Start address of application with bootloader * APP_END_ADDRESS | FLASH_END | End address of application with bootloader ******************************************************************************/ - +#ifdef BOOTLOADER_UPDATER + #define BOOT_START_ADDRESS 0x800C800 + #define APP_START_ADDRESS 0x8000000 + #define APP_END_ADDRESS 0x800BFFF +#endif #endif /* _NODE_CONFIG_H_ */ diff --git a/examples/projects/NUCLEO-G474RE/bootloader/platformio.ini b/examples/projects/NUCLEO-G474RE/bootloader/platformio.ini index 04b39ecc0..69c308bcc 100644 --- a/examples/projects/NUCLEO-G474RE/bootloader/platformio.ini +++ b/examples/projects/NUCLEO-G474RE/bootloader/platformio.ini @@ -7,12 +7,20 @@ ; ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html +[platformio] +default_envs = nucleo_g474re -[env:nucleo_g474re] +[env] platform = ststm32 board = nucleo_g474re lib_extra_dirs = $PROJECT_DIR/../../../../../ framework = stm32cube +lib_deps = + luos_engine@^2.8.0 +debug_tool = stlink +upload_protocol = stlink + +[env:nucleo_g474re] board_build.ldscript = linker/custom_bootloader_script.ld build_unflags = -Os build_flags = @@ -22,7 +30,19 @@ build_flags = -DUSE_HAL_DRIVER -DUSE_FULL_LL_DRIVER -DLUOSHAL=STM32G4 -lib_deps = - luos_engine@^2.8.0 -debug_tool = stlink -upload_protocol = stlink + +[env:nucleo_g474re_updater] +board_build.ldscript = linker/custom_bootloader_updater_script.ld +build_unflags = -Os +build_flags = + -O1 + -include node_config.h + -D BOOTLOADER + -D BOOTLOADER_UPDATER + -DUSE_HAL_DRIVER + -DUSE_FULL_LL_DRIVER + -DLUOSHAL=STM32G4 +upload_protocol = custom +upload_flags = + -t2 +upload_command = pyluos-bootloader flash $UPLOAD_PORT $UPLOAD_FLAGS -b $SOURCE From cf4522288dbc690cf6018c9cd65abc5127f7b323 Mon Sep 17 00:00:00 2001 From: biliouriv Date: Mon, 7 Nov 2022 18:09:45 +0100 Subject: [PATCH 06/12] [Bootloader] bootloader updater for STM32F4-discovery --- .../custom_bootloader_updater_script.ld | 216 ++++++++++++++++++ .../bootloader/node_config.h | 8 +- .../bootloader/platformio.ini | 26 ++- 3 files changed, 245 insertions(+), 5 deletions(-) create mode 100644 examples/projects/STM32F4-discovery/bootloader/linker/custom_bootloader_updater_script.ld diff --git a/examples/projects/STM32F4-discovery/bootloader/linker/custom_bootloader_updater_script.ld b/examples/projects/STM32F4-discovery/bootloader/linker/custom_bootloader_updater_script.ld new file mode 100644 index 000000000..2de846873 --- /dev/null +++ b/examples/projects/STM32F4-discovery/bootloader/linker/custom_bootloader_updater_script.ld @@ -0,0 +1,216 @@ +/* +****************************************************************************** +** +** @file : LinkerScript.ld +** +** @author : Auto-generated by STM32CubeIDE +** +** @brief : Linker script for STM32F407VGTx Device from STM32F4 series +** 1024Kbytes FLASH +** 64Kbytes CCMRAM +** 128Kbytes RAM +** +** Set heap size, stack size and stack location according +** to application requirements. +** +** Set memory bank area and size if external memory is used +** +** Target : STMicroelectronics STM32 +** +** Distribution: The file is distributed as is, without any warranty +** of any kind. +** +****************************************************************************** +** @attention +** +**

© Copyright (c) 2021 STMicroelectronics. +** All rights reserved.

+** +** This software component is licensed by ST under BSD 3-Clause license, +** the "License"; You may not use this file except in compliance with the +** License. You may obtain a copy of the License at: +** opensource.org/licenses/BSD-3-Clause +** +****************************************************************************** +*/ + +/* Entry Point */ +ENTRY(Reset_Handler) + +/* Highest address of the user mode stack */ +_estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */ + +_Min_Heap_Size = 0x200; /* required amount of heap */ +_Min_Stack_Size = 0x400; /* required amount of stack */ + +/* Memories definition */ +MEMORY +{ + CCMRAM (xrw) : ORIGIN = 0x10000000, LENGTH = 64K + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K + FLASH (rx) : ORIGIN = 0x08010000, LENGTH = 48K + SHRD_MEM (rw) : ORIGIN = 0x0800C000, LENGTH = 16K +} + +/* Sections */ +SECTIONS +{ + /* placing my boot flags section at given address: */ + .boot_flags : + { + KEEP(*(.boot_flags)) /* keep my variable even if not referenced */ + } >SHRD_MEM + + /* The startup code into "FLASH" Rom type memory */ + .isr_vector : + { + . = ALIGN(4); + KEEP(*(.isr_vector)) /* Startup code */ + . = ALIGN(4); + } >FLASH + + /* The program code and other data into "FLASH" Rom type memory */ + .text : + { + . = ALIGN(4); + *(.text) /* .text sections (code) */ + *(.text*) /* .text* sections (code) */ + *(.glue_7) /* glue arm to thumb code */ + *(.glue_7t) /* glue thumb to arm code */ + *(.eh_frame) + + KEEP (*(.init)) + KEEP (*(.fini)) + + . = ALIGN(4); + _etext = .; /* define a global symbols at end of code */ + } >FLASH + + /* Constant data into "FLASH" Rom type memory */ + .rodata : + { + . = ALIGN(4); + *(.rodata) /* .rodata sections (constants, strings, etc.) */ + *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ + . = ALIGN(4); + } >FLASH + + .ARM.extab : { + . = ALIGN(4); + *(.ARM.extab* .gnu.linkonce.armextab.*) + . = ALIGN(4); + } >FLASH + + .ARM : { + . = ALIGN(4); + __exidx_start = .; + *(.ARM.exidx*) + __exidx_end = .; + . = ALIGN(4); + } >FLASH + + .preinit_array : + { + . = ALIGN(4); + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array*)) + PROVIDE_HIDDEN (__preinit_array_end = .); + . = ALIGN(4); + } >FLASH + + .init_array : + { + . = ALIGN(4); + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array*)) + PROVIDE_HIDDEN (__init_array_end = .); + . = ALIGN(4); + } >FLASH + + .fini_array : + { + . = ALIGN(4); + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(SORT(.fini_array.*))) + KEEP (*(.fini_array*)) + PROVIDE_HIDDEN (__fini_array_end = .); + . = ALIGN(4); + } >FLASH + + /* Used by the startup to initialize data */ + _sidata = LOADADDR(.data); + + /* Initialized data sections into "RAM" Ram type memory */ + .data : + { + . = ALIGN(4); + _sdata = .; /* create a global symbol at data start */ + *(.data) /* .data sections */ + *(.data*) /* .data* sections */ + *(.RamFunc) /* .RamFunc sections */ + *(.RamFunc*) /* .RamFunc* sections */ + + . = ALIGN(4); + _edata = .; /* define a global symbol at data end */ + + } >RAM AT> FLASH + + _siccmram = LOADADDR(.ccmram); + + /* CCM-RAM section + * + * IMPORTANT NOTE! + * If initialized variables will be placed in this section, + * the startup code needs to be modified to copy the init-values. + */ + .ccmram : + { + . = ALIGN(4); + _sccmram = .; /* create a global symbol at ccmram start */ + *(.ccmram) + *(.ccmram*) + + . = ALIGN(4); + _eccmram = .; /* create a global symbol at ccmram end */ + } >CCMRAM AT> FLASH + + /* Uninitialized data section into "RAM" Ram type memory */ + . = ALIGN(4); + .bss : + { + /* This is used by the startup in order to initialize the .bss section */ + _sbss = .; /* define a global symbol at bss start */ + __bss_start__ = _sbss; + *(.bss) + *(.bss*) + *(COMMON) + + . = ALIGN(4); + _ebss = .; /* define a global symbol at bss end */ + __bss_end__ = _ebss; + } >RAM + + /* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */ + ._user_heap_stack : + { + . = ALIGN(8); + PROVIDE ( end = . ); + PROVIDE ( _end = . ); + . = . + _Min_Heap_Size; + . = . + _Min_Stack_Size; + . = ALIGN(8); + } >RAM + + /* placing my boot flags section at given address: */ + + /* Remove information from the compiler libraries */ + /DISCARD/ : + { + libc.a ( * ) + libm.a ( * ) + libgcc.a ( * ) + } + + .ARM.attributes 0 : { *(.ARM.attributes) } +} diff --git a/examples/projects/STM32F4-discovery/bootloader/node_config.h b/examples/projects/STM32F4-discovery/bootloader/node_config.h index 978f5deaa..c37fdf8be 100644 --- a/examples/projects/STM32F4-discovery/bootloader/node_config.h +++ b/examples/projects/STM32F4-discovery/bootloader/node_config.h @@ -96,5 +96,11 @@ * APP_START_SECTOR | FLASH_SECTOR_4 | Start sector of application with bootloader * APP_END_SECTOR | FLASH_SECTOR_TOTAL - 1 | last sector of application with bootloader ******************************************************************************/ - +#ifdef BOOTLOADER_UPDATER + #define BOOT_START_ADDRESS 0x08010000 + #define APP_START_ADDRESS 0x8000000 + #define APP_END_ADDRESS 0x0800BFFF + #define APP_START_SECTOR FLASH_SECTOR_0 + #define APP_END_SECTOR FLASH_SECTOR_2 +#endif #endif /* _NODE_CONFIG_H_ */ diff --git a/examples/projects/STM32F4-discovery/bootloader/platformio.ini b/examples/projects/STM32F4-discovery/bootloader/platformio.ini index 7ef158d45..86d03fd01 100644 --- a/examples/projects/STM32F4-discovery/bootloader/platformio.ini +++ b/examples/projects/STM32F4-discovery/bootloader/platformio.ini @@ -10,12 +10,16 @@ [platformio] default_envs = STM32F4-discovery -[env:STM32F4-discovery] +[env] platform = ststm32 -board_build.ldscript = linker/custom_bootloader_script.ld lib_extra_dirs = $PROJECT_DIR/../../../../../ board = disco_f407vg framework = stm32cube +lib_deps = + luos_engine@^2.8.0 + +[env:STM32F4-discovery] +board_build.ldscript = linker/custom_bootloader_script.ld build_unflags = -Os build_flags = -DBOOTLOADER @@ -24,6 +28,20 @@ build_flags = -DUSE_HAL_DRIVER -DUSE_FULL_LL_DRIVER -DLUOSHAL=STM32F4 -lib_deps = - luos_engine@^2.8.0 debug_tool = stlink + +[env:STM32F4-discovery_updater] +board_build.ldscript = linker/custom_bootloader_updater_script.ld +build_unflags = -Os +build_flags = + -DBOOTLOADER + -DBOOTLOADER_UPDATER + -include node_config.h + -O1 + -DUSE_HAL_DRIVER + -DUSE_FULL_LL_DRIVER + -DLUOSHAL=STM32F4 +upload_protocol = custom +upload_flags = + -t2 +upload_command = pyluos-bootloader flash $UPLOAD_PORT $UPLOAD_FLAGS -b $SOURCE From e57f50cb9635c79592f3e4077d33a2b7267f753d Mon Sep 17 00:00:00 2001 From: biliouriv Date: Tue, 8 Nov 2022 12:07:00 +0100 Subject: [PATCH 07/12] [Bootloader] bootloader updater for STM32L4-discovery --- .../custom_bootloader_updater_script.ld | 193 ++++++++++++++++++ .../bootloader/node_config.h | 8 +- .../bootloader/platformio.ini | 26 ++- 3 files changed, 223 insertions(+), 4 deletions(-) create mode 100644 examples/projects/STM32L4S5_discovery/bootloader/linker/custom_bootloader_updater_script.ld diff --git a/examples/projects/STM32L4S5_discovery/bootloader/linker/custom_bootloader_updater_script.ld b/examples/projects/STM32L4S5_discovery/bootloader/linker/custom_bootloader_updater_script.ld new file mode 100644 index 000000000..4964c2837 --- /dev/null +++ b/examples/projects/STM32L4S5_discovery/bootloader/linker/custom_bootloader_updater_script.ld @@ -0,0 +1,193 @@ +/* +****************************************************************************** +** +** @file : LinkerScript.ld +** +** @author : Auto-generated by STM32CubeIDE +** +** @brief : Linker script for STM32L4S5VITx Device from STM32L4PLUS series +** 2048Kbytes FLASH +** 640Kbytes RAM +** +** Set heap size, stack size and stack location according +** to application requirements. +** +** Set memory bank area and size if external memory is used +** +** Target : STMicroelectronics STM32 +** +** Distribution: The file is distributed as is, without any warranty +** of any kind. +** +****************************************************************************** +** @attention +** +**

© Copyright (c) 2021 STMicroelectronics. +** All rights reserved.

+** +** This software component is licensed by ST under BSD 3-Clause license, +** the "License"; You may not use this file except in compliance with the +** License. You may obtain a copy of the License at: +** opensource.org/licenses/BSD-3-Clause +** +****************************************************************************** +*/ + +/* Entry Point */ +ENTRY(Reset_Handler) + +/* Highest address of the user mode stack */ +_estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */ + +_Min_Heap_Size = 0x200; /* required amount of heap */ +_Min_Stack_Size = 0x400; /* required amount of stack */ + +/* Memories definition */ +MEMORY +{ + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 640K + FLASH (rx) : ORIGIN = 0x800D000, LENGTH = 48K + SHRD_MEM (rw) : ORIGIN = 0x0800C000, LENGTH = 4K +} + +/* Sections */ +SECTIONS +{ + /* placing my boot flags section at given address: */ + .boot_flags : + { + KEEP(*(.boot_flags)) /* keep my variable even if not referenced */ + } > SHRD_MEM + + /* The startup code into "FLASH" Rom type memory */ + .isr_vector : + { + . = ALIGN(4); + KEEP(*(.isr_vector)) /* Startup code */ + . = ALIGN(4); + } >FLASH + + /* The program code and other data into "FLASH" Rom type memory */ + .text : + { + . = ALIGN(4); + *(.text) /* .text sections (code) */ + *(.text*) /* .text* sections (code) */ + *(.glue_7) /* glue arm to thumb code */ + *(.glue_7t) /* glue thumb to arm code */ + *(.eh_frame) + + KEEP (*(.init)) + KEEP (*(.fini)) + + . = ALIGN(4); + _etext = .; /* define a global symbols at end of code */ + } >FLASH + + /* Constant data into "FLASH" Rom type memory */ + .rodata : + { + . = ALIGN(4); + *(.rodata) /* .rodata sections (constants, strings, etc.) */ + *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ + . = ALIGN(4); + } >FLASH + + .ARM.extab : { + . = ALIGN(4); + *(.ARM.extab* .gnu.linkonce.armextab.*) + . = ALIGN(4); + } >FLASH + + .ARM : { + . = ALIGN(4); + __exidx_start = .; + *(.ARM.exidx*) + __exidx_end = .; + . = ALIGN(4); + } >FLASH + + .preinit_array : + { + . = ALIGN(4); + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array*)) + PROVIDE_HIDDEN (__preinit_array_end = .); + . = ALIGN(4); + } >FLASH + + .init_array : + { + . = ALIGN(4); + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array*)) + PROVIDE_HIDDEN (__init_array_end = .); + . = ALIGN(4); + } >FLASH + + .fini_array : + { + . = ALIGN(4); + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(SORT(.fini_array.*))) + KEEP (*(.fini_array*)) + PROVIDE_HIDDEN (__fini_array_end = .); + . = ALIGN(4); + } >FLASH + + /* Used by the startup to initialize data */ + _sidata = LOADADDR(.data); + + /* Initialized data sections into "RAM" Ram type memory */ + .data : + { + . = ALIGN(4); + _sdata = .; /* create a global symbol at data start */ + *(.data) /* .data sections */ + *(.data*) /* .data* sections */ + *(.RamFunc) /* .RamFunc sections */ + *(.RamFunc*) /* .RamFunc* sections */ + + . = ALIGN(4); + _edata = .; /* define a global symbol at data end */ + + } >RAM AT> FLASH + + /* Uninitialized data section into "RAM" Ram type memory */ + . = ALIGN(4); + .bss : + { + /* This is used by the startup in order to initialize the .bss section */ + _sbss = .; /* define a global symbol at bss start */ + __bss_start__ = _sbss; + *(.bss) + *(.bss*) + *(COMMON) + + . = ALIGN(4); + _ebss = .; /* define a global symbol at bss end */ + __bss_end__ = _ebss; + } >RAM + + /* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */ + ._user_heap_stack : + { + . = ALIGN(8); + PROVIDE ( end = . ); + PROVIDE ( _end = . ); + . = . + _Min_Heap_Size; + . = . + _Min_Stack_Size; + . = ALIGN(8); + } >RAM + + /* Remove information from the compiler libraries */ + /DISCARD/ : + { + libc.a ( * ) + libm.a ( * ) + libgcc.a ( * ) + } + + .ARM.attributes 0 : { *(.ARM.attributes) } +} diff --git a/examples/projects/STM32L4S5_discovery/bootloader/node_config.h b/examples/projects/STM32L4S5_discovery/bootloader/node_config.h index a42afcefd..155578137 100644 --- a/examples/projects/STM32L4S5_discovery/bootloader/node_config.h +++ b/examples/projects/STM32L4S5_discovery/bootloader/node_config.h @@ -154,6 +154,12 @@ * APP_START_ADDRESS | 0x0800C800 | Start address of application with bootloader * APP_END_ADDRESS | FLASH_END | End address of application with bootloader ******************************************************************************/ -#define APP_START_ADDRESS (uint32_t)0x0800D000 +#ifndef BOOTLOADER_UPDATER + #define APP_START_ADDRESS (uint32_t)0x0800D000 +#else + #define BOOT_START_ADDRESS (uint32_t)0x0800D000 + #define APP_START_ADDRESS (uint32_t)0x08000000 + #define APP_END_ADDRESS (uint32_t)0x0800BFFF +#endif #endif /* _NODE_CONFIG_H_ */ diff --git a/examples/projects/STM32L4S5_discovery/bootloader/platformio.ini b/examples/projects/STM32L4S5_discovery/bootloader/platformio.ini index 52c2f10f3..79150f58f 100644 --- a/examples/projects/STM32L4S5_discovery/bootloader/platformio.ini +++ b/examples/projects/STM32L4S5_discovery/bootloader/platformio.ini @@ -7,12 +7,18 @@ ; ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html +[platformio] +default_envs = disco_l4s5i_iot01a -[env:disco_l4s5i_iot01a] +[env] platform = ststm32 board = disco_l4s5i_iot01a lib_extra_dirs = $PROJECT_DIR/../../../../../ framework = stm32cube +lib_deps = + luos_engine@^2.8.0 + +[env:disco_l4s5i_iot01a] board_build.ldscript = linker/custom_bootloader_script.ld build_unflags = -Os build_flags = @@ -22,8 +28,22 @@ build_flags = -DUSE_FULL_LL_DRIVER -DLUOSHAL=STM32L4 -DBOOTLOADER -lib_deps = - luos_engine@^2.8.0 debug_tool = stlink upload_protocol = stlink +[env:disco_l4s5i_iot01a_updater] +board_build.ldscript = linker/custom_bootloader_updater_script.ld +build_unflags = -Os +build_flags = + -O1 + -include node_config.h + -DBOOTLOADER + -DBOOTLOADER_UPDATER + -DUSE_HAL_DRIVER + -DUSE_FULL_LL_DRIVER + -DLUOSHAL=STM32L4 +upload_protocol = custom +upload_flags = + -t2 +upload_command = pyluos-bootloader flash $UPLOAD_PORT $UPLOAD_FLAGS -b $SOURCE + From cb6563bb126f9aef37d4766148b15e991176902a Mon Sep 17 00:00:00 2001 From: biliouriv Date: Tue, 8 Nov 2022 14:44:50 +0100 Subject: [PATCH 08/12] [Bootloader] bootloader updater for NUCLEO-F401RE --- .../custom_bootloader_updater_script.ld | 182 ++++++++++++++++++ .../NUCLEO-F401RE/bootloader/node_config.h | 9 +- .../NUCLEO-F401RE/bootloader/platformio.ini | 27 ++- 3 files changed, 212 insertions(+), 6 deletions(-) create mode 100644 examples/projects/NUCLEO-F401RE/bootloader/linker/custom_bootloader_updater_script.ld diff --git a/examples/projects/NUCLEO-F401RE/bootloader/linker/custom_bootloader_updater_script.ld b/examples/projects/NUCLEO-F401RE/bootloader/linker/custom_bootloader_updater_script.ld new file mode 100644 index 000000000..63e3bc229 --- /dev/null +++ b/examples/projects/NUCLEO-F401RE/bootloader/linker/custom_bootloader_updater_script.ld @@ -0,0 +1,182 @@ +/** + ****************************************************************************** + * @file LinkerScript.ld + * @author Auto-generated by STM32CubeIDE + * @brief Linker script for STM32F401RETx Device from STM32F4 series + * 512Kbytes FLASH + * 96Kbytes RAM + * + * Set heap size, stack size and stack location according + * to application requirements. + * + * Set memory bank area and size if external memory is used + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2020 STMicroelectronics. + * All rights reserved.

+ * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ + +/* Entry Point */ +ENTRY(Reset_Handler) + +/* Highest address of the user mode stack */ +_estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */ + +_Min_Heap_Size = 0x200; /* required amount of heap */ +_Min_Stack_Size = 0x400; /* required amount of stack */ + +/* Memories definition */ +MEMORY +{ + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 96K + FLASH (rx) : ORIGIN = 0x08010000, LENGTH = 48K + SHRD_MEM (rw) : ORIGIN = 0x0800C000, LENGTH = 16K +} + +/* Sections */ +SECTIONS +{ + /* placing my boot flags section at given address: */ + .boot_flags : + { + KEEP(*(.boot_flags)) /* keep my variable even if not referenced */ + } > SHRD_MEM + + /* The startup code into "FLASH" Rom type memory */ + .isr_vector : + { + . = ALIGN(4); + KEEP(*(.isr_vector)) /* Startup code */ + . = ALIGN(4); + } >FLASH + + /* The program code and other data into "FLASH" Rom type memory */ + .text : + { + . = ALIGN(4); + *(.text) /* .text sections (code) */ + *(.text*) /* .text* sections (code) */ + *(.glue_7) /* glue arm to thumb code */ + *(.glue_7t) /* glue thumb to arm code */ + *(.eh_frame) + + KEEP (*(.init)) + KEEP (*(.fini)) + + . = ALIGN(4); + _etext = .; /* define a global symbols at end of code */ + } >FLASH + + /* Constant data into "FLASH" Rom type memory */ + .rodata : + { + . = ALIGN(4); + *(.rodata) /* .rodata sections (constants, strings, etc.) */ + *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ + . = ALIGN(4); + } >FLASH + + .ARM.extab : { + . = ALIGN(4); + *(.ARM.extab* .gnu.linkonce.armextab.*) + . = ALIGN(4); + } >FLASH + + .ARM : { + . = ALIGN(4); + __exidx_start = .; + *(.ARM.exidx*) + __exidx_end = .; + . = ALIGN(4); + } >FLASH + + .preinit_array : + { + . = ALIGN(4); + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array*)) + PROVIDE_HIDDEN (__preinit_array_end = .); + . = ALIGN(4); + } >FLASH + + .init_array : + { + . = ALIGN(4); + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array*)) + PROVIDE_HIDDEN (__init_array_end = .); + . = ALIGN(4); + } >FLASH + + .fini_array : + { + . = ALIGN(4); + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(SORT(.fini_array.*))) + KEEP (*(.fini_array*)) + PROVIDE_HIDDEN (__fini_array_end = .); + . = ALIGN(4); + } >FLASH + + /* Used by the startup to initialize data */ + _sidata = LOADADDR(.data); + + /* Initialized data sections into "RAM" Ram type memory */ + .data : + { + . = ALIGN(4); + _sdata = .; /* create a global symbol at data start */ + *(.data) /* .data sections */ + *(.data*) /* .data* sections */ + + . = ALIGN(4); + _edata = .; /* define a global symbol at data end */ + + } >RAM AT> FLASH + + /* Uninitialized data section into "RAM" Ram type memory */ + . = ALIGN(4); + .bss : + { + /* This is used by the startup in order to initialize the .bss section */ + _sbss = .; /* define a global symbol at bss start */ + __bss_start__ = _sbss; + *(.bss) + *(.bss*) + *(COMMON) + + . = ALIGN(4); + _ebss = .; /* define a global symbol at bss end */ + __bss_end__ = _ebss; + } >RAM + + /* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */ + ._user_heap_stack : + { + . = ALIGN(8); + PROVIDE ( end = . ); + PROVIDE ( _end = . ); + . = . + _Min_Heap_Size; + . = . + _Min_Stack_Size; + . = ALIGN(8); + } >RAM + + /* Remove information from the compiler libraries */ + /DISCARD/ : + { + libc.a ( * ) + libm.a ( * ) + libgcc.a ( * ) + } + + .ARM.attributes 0 : { *(.ARM.attributes) } +} diff --git a/examples/projects/NUCLEO-F401RE/bootloader/node_config.h b/examples/projects/NUCLEO-F401RE/bootloader/node_config.h index 44ef38e75..c3c3ffdf5 100644 --- a/examples/projects/NUCLEO-F401RE/bootloader/node_config.h +++ b/examples/projects/NUCLEO-F401RE/bootloader/node_config.h @@ -46,7 +46,6 @@ ******************************************************************************/ #define MSG_BUFFER_SIZE 512 - /******************************************************************************* * LUOS HAL LIBRARY DEFINITION ******************************************************************************* @@ -119,5 +118,11 @@ * APP_START_SECTOR | FLASH_SECTOR_4 | Start sector of application with bootloader * APP_END_SECTOR | FLASH_SECTOR_TOTAL - 1 | last sector of application with bootloader ******************************************************************************/ - +#ifdef BOOTLOADER_UPDATER + #define BOOT_START_ADDRESS (uint32_t)0x08010000 + #define APP_START_ADDRESS (uint32_t)0x08000000 + #define APP_END_ADDRESS (uint32_t)0x0800BFFF + #define APP_START_SECTOR FLASH_SECTOR_0 + #define APP_END_SECTOR FLASH_SECTOR_2 +#endif #endif /* _NODE_CONFIG_H_ */ diff --git a/examples/projects/NUCLEO-F401RE/bootloader/platformio.ini b/examples/projects/NUCLEO-F401RE/bootloader/platformio.ini index 5d03d6876..2e53a2b8a 100644 --- a/examples/projects/NUCLEO-F401RE/bootloader/platformio.ini +++ b/examples/projects/NUCLEO-F401RE/bootloader/platformio.ini @@ -7,12 +7,18 @@ ; ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html +[platformio] +default_envs = nucleo_f401re -[env:nucleo_f401re] +[env] platform = ststm32 board = nucleo_f401re lib_extra_dirs = $PROJECT_DIR/../../../../../ framework = stm32cube +lib_deps = + luos_engine@^2.8.0 + +[env:nucleo_f401re] board_build.ldscript = linker/custom_bootloader_script.ld build_unflags = -Os build_flags = @@ -22,8 +28,21 @@ build_flags = -DUSE_HAL_DRIVER -DUSE_FULL_LL_DRIVER -DLUOSHAL=STM32F4 -debug_build_flags = -O0 -g -ggdb -lib_deps = - luos_engine@^2.8.0 debug_tool = stlink upload_protocol = stlink + +[env:nucleo_f401re_updater] +board_build.ldscript = linker/custom_bootloader_updater_script.ld +build_unflags = -Os +build_flags = + -O1 + -include node_config.h + -DBOOTLOADER + -DBOOTLOADER_UPDATER + -DUSE_HAL_DRIVER + -DUSE_FULL_LL_DRIVER + -DLUOSHAL=STM32F4 +upload_protocol = custom +upload_flags = + -t2 +upload_command = pyluos-bootloader flash $UPLOAD_PORT $UPLOAD_FLAGS -b $SOURCE From 01c3261004df45a6aa31e61c4287aec97f0c0f2a Mon Sep 17 00:00:00 2001 From: biliouriv Date: Tue, 8 Nov 2022 14:46:25 +0100 Subject: [PATCH 09/12] [Bootloader] bootloader updater for NUCLEO-F410RB --- .../custom_bootloader_updater_script.ld | 193 ++++++++++++++++++ .../NUCLEO-F410RB/bootloader/node_config.h | 7 + .../NUCLEO-F410RB/bootloader/platformio.ini | 29 ++- 3 files changed, 224 insertions(+), 5 deletions(-) create mode 100644 examples/projects/NUCLEO-F410RB/bootloader/linker/custom_bootloader_updater_script.ld diff --git a/examples/projects/NUCLEO-F410RB/bootloader/linker/custom_bootloader_updater_script.ld b/examples/projects/NUCLEO-F410RB/bootloader/linker/custom_bootloader_updater_script.ld new file mode 100644 index 000000000..06dd4b442 --- /dev/null +++ b/examples/projects/NUCLEO-F410RB/bootloader/linker/custom_bootloader_updater_script.ld @@ -0,0 +1,193 @@ +/* +****************************************************************************** +** +** @file : LinkerScript.ld +** +** @author : Auto-generated by STM32CubeIDE +** +** @brief : Linker script for STM32F410RBTx Device from STM32F4 series +** 128Kbytes FLASH +** 32Kbytes RAM +** +** Set heap size, stack size and stack location according +** to application requirements. +** +** Set memory bank area and size if external memory is used +** +** Target : STMicroelectronics STM32 +** +** Distribution: The file is distributed as is, without any warranty +** of any kind. +** +****************************************************************************** +** @attention +** +**

© Copyright (c) 2021 STMicroelectronics. +** All rights reserved.

+** +** This software component is licensed by ST under BSD 3-Clause license, +** the "License"; You may not use this file except in compliance with the +** License. You may obtain a copy of the License at: +** opensource.org/licenses/BSD-3-Clause +** +****************************************************************************** +*/ + +/* Entry Point */ +ENTRY(Reset_Handler) + +/* Highest address of the user mode stack */ +_estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */ + +_Min_Heap_Size = 0x200; /* required amount of heap */ +_Min_Stack_Size = 0x400; /* required amount of stack */ + +/* Memories definition */ +MEMORY +{ + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K + FLASH (rx) : ORIGIN = 0x08010000, LENGTH = 48K + SHRD_MEM (rw) : ORIGIN = 0x0800C000, LENGTH = 2K +} + +/* Sections */ +SECTIONS +{ + /* placing my boot flags section at given address: */ + .boot_flags : + { + KEEP(*(.boot_flags)) /* keep my variable even if not referenced */ + } > SHRD_MEM + + /* The startup code into "FLASH" Rom type memory */ + .isr_vector : + { + . = ALIGN(4); + KEEP(*(.isr_vector)) /* Startup code */ + . = ALIGN(4); + } >FLASH + + /* The program code and other data into "FLASH" Rom type memory */ + .text : + { + . = ALIGN(4); + *(.text) /* .text sections (code) */ + *(.text*) /* .text* sections (code) */ + *(.glue_7) /* glue arm to thumb code */ + *(.glue_7t) /* glue thumb to arm code */ + *(.eh_frame) + + KEEP (*(.init)) + KEEP (*(.fini)) + + . = ALIGN(4); + _etext = .; /* define a global symbols at end of code */ + } >FLASH + + /* Constant data into "FLASH" Rom type memory */ + .rodata : + { + . = ALIGN(4); + *(.rodata) /* .rodata sections (constants, strings, etc.) */ + *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ + . = ALIGN(4); + } >FLASH + + .ARM.extab : { + . = ALIGN(4); + *(.ARM.extab* .gnu.linkonce.armextab.*) + . = ALIGN(4); + } >FLASH + + .ARM : { + . = ALIGN(4); + __exidx_start = .; + *(.ARM.exidx*) + __exidx_end = .; + . = ALIGN(4); + } >FLASH + + .preinit_array : + { + . = ALIGN(4); + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array*)) + PROVIDE_HIDDEN (__preinit_array_end = .); + . = ALIGN(4); + } >FLASH + + .init_array : + { + . = ALIGN(4); + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array*)) + PROVIDE_HIDDEN (__init_array_end = .); + . = ALIGN(4); + } >FLASH + + .fini_array : + { + . = ALIGN(4); + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(SORT(.fini_array.*))) + KEEP (*(.fini_array*)) + PROVIDE_HIDDEN (__fini_array_end = .); + . = ALIGN(4); + } >FLASH + + /* Used by the startup to initialize data */ + _sidata = LOADADDR(.data); + + /* Initialized data sections into "RAM" Ram type memory */ + .data : + { + . = ALIGN(4); + _sdata = .; /* create a global symbol at data start */ + *(.data) /* .data sections */ + *(.data*) /* .data* sections */ + *(.RamFunc) /* .RamFunc sections */ + *(.RamFunc*) /* .RamFunc* sections */ + + . = ALIGN(4); + _edata = .; /* define a global symbol at data end */ + + } >RAM AT> FLASH + + /* Uninitialized data section into "RAM" Ram type memory */ + . = ALIGN(4); + .bss : + { + /* This is used by the startup in order to initialize the .bss section */ + _sbss = .; /* define a global symbol at bss start */ + __bss_start__ = _sbss; + *(.bss) + *(.bss*) + *(COMMON) + + . = ALIGN(4); + _ebss = .; /* define a global symbol at bss end */ + __bss_end__ = _ebss; + } >RAM + + /* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */ + ._user_heap_stack : + { + . = ALIGN(8); + PROVIDE ( end = . ); + PROVIDE ( _end = . ); + . = . + _Min_Heap_Size; + . = . + _Min_Stack_Size; + . = ALIGN(8); + } >RAM + + /* Remove information from the compiler libraries */ + /DISCARD/ : + { + libc.a ( * ) + libm.a ( * ) + libgcc.a ( * ) + } + + .ARM.attributes 0 : { *(.ARM.attributes) } +} diff --git a/examples/projects/NUCLEO-F410RB/bootloader/node_config.h b/examples/projects/NUCLEO-F410RB/bootloader/node_config.h index 3f862729f..f2c1ff38d 100644 --- a/examples/projects/NUCLEO-F410RB/bootloader/node_config.h +++ b/examples/projects/NUCLEO-F410RB/bootloader/node_config.h @@ -120,5 +120,12 @@ * APP_START_SECTOR | FLASH_SECTOR_4 | Start sector of application with bootloader * APP_END_SECTOR | FLASH_SECTOR_TOTAL - 1 | last sector of application with bootloader ******************************************************************************/ +#ifdef BOOTLOADER_UPDATER + #define BOOT_START_ADDRESS (uint32_t)0x08010000 + #define APP_START_ADDRESS (uint32_t)0x08000000 + #define APP_END_ADDRESS (uint32_t)0x0800BFFF + #define APP_START_SECTOR FLASH_SECTOR_0 + #define APP_END_SECTOR FLASH_SECTOR_2 +#endif #endif /* _NODE_CONFIG_H_ */ diff --git a/examples/projects/NUCLEO-F410RB/bootloader/platformio.ini b/examples/projects/NUCLEO-F410RB/bootloader/platformio.ini index af280dd93..bc78817d5 100644 --- a/examples/projects/NUCLEO-F410RB/bootloader/platformio.ini +++ b/examples/projects/NUCLEO-F410RB/bootloader/platformio.ini @@ -7,13 +7,19 @@ ; ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html +[platformio] +default_envs = nucleo_f410rb -[env:nucleo_f410rb] +[env] platform = ststm32 board = nucleo_f410rb framework = stm32cube -board_build.ldscript = linker/custom_bootloader_script.ld lib_extra_dirs = $PROJECT_DIR/../../../../../ +lib_deps = + luos_engine@^2.8.0 + +[env:nucleo_f410rb] +board_build.ldscript = linker/custom_bootloader_script.ld build_unflags = -Os build_flags = -O1 @@ -22,11 +28,24 @@ build_flags = -DUSE_HAL_DRIVER -DUSE_FULL_LL_DRIVER -DLUOSHAL=STM32F4 -debug_build_flags = -O0 -g -ggdb -lib_deps = - luos_engine@^2.8.0 debug_tool = stlink upload_protocol = stlink +[env:nucleo_f410rb_updater] +board_build.ldscript = linker/custom_bootloader_updater_script.ld +build_unflags = -Os +build_flags = + -O1 + -include node_config.h + -DBOOTLOADER + -DBOOTLOADER_UPDATER + -DUSE_HAL_DRIVER + -DUSE_FULL_LL_DRIVER + -DLUOSHAL=STM32F4 +upload_protocol = custom +upload_flags = + -t2 +upload_command = pyluos-bootloader flash $UPLOAD_PORT $UPLOAD_FLAGS -b $SOURCE + From 027abd4fe0c28eb39794ff385c756edc832da527 Mon Sep 17 00:00:00 2001 From: biliouriv Date: Tue, 8 Nov 2022 14:47:43 +0100 Subject: [PATCH 10/12] [Bootloader] bootloader updater for NUCLEO-G431KB --- .../custom_bootloader_updater_script.ld | 182 ++++++++++++++++++ .../NUCLEO-G431KB/bootloader/node_config.h | 6 +- .../NUCLEO-G431KB/bootloader/platformio.ini | 27 ++- 3 files changed, 211 insertions(+), 4 deletions(-) create mode 100644 examples/projects/NUCLEO-G431KB/bootloader/linker/custom_bootloader_updater_script.ld diff --git a/examples/projects/NUCLEO-G431KB/bootloader/linker/custom_bootloader_updater_script.ld b/examples/projects/NUCLEO-G431KB/bootloader/linker/custom_bootloader_updater_script.ld new file mode 100644 index 000000000..55fe5d763 --- /dev/null +++ b/examples/projects/NUCLEO-G431KB/bootloader/linker/custom_bootloader_updater_script.ld @@ -0,0 +1,182 @@ +/** + ****************************************************************************** + * @file LinkerScript.ld + * @author Auto-generated by STM32CubeIDE + * @brief Linker script for STM32G431KBTx Device from STM32G4 series + * 128Kbytes FLASH + * 32Kbytes RAM + * + * Set heap size, stack size and stack location according + * to application requirements. + * + * Set memory bank area and size if external memory is used + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2020 STMicroelectronics. + * All rights reserved.

+ * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ + +/* Entry Point */ +ENTRY(Reset_Handler) + +/* Highest address of the user mode stack */ +_estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */ + +_Min_Heap_Size = 0x200; /* required amount of heap */ +_Min_Stack_Size = 0x400; /* required amount of stack */ + +/* Memories definition */ +MEMORY +{ + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K + FLASH (rx) : ORIGIN = 0x800C800, LENGTH = 48K + SHRD_MEM (rx) : ORIGIN = 0x800C000, LENGTH = 2K +} + +/* Sections */ +SECTIONS +{ + /* placing my boot flags section at given address: */ + .boot_flags : + { + KEEP(*(.boot_flags)) /* keep my variable even if not referenced */ + } > SHRD_MEM + + /* The startup code into "FLASH" Rom type memory */ + .isr_vector : + { + . = ALIGN(4); + KEEP(*(.isr_vector)) /* Startup code */ + . = ALIGN(4); + } >FLASH + + /* The program code and other data into "FLASH" Rom type memory */ + .text : + { + . = ALIGN(4); + *(.text) /* .text sections (code) */ + *(.text*) /* .text* sections (code) */ + *(.glue_7) /* glue arm to thumb code */ + *(.glue_7t) /* glue thumb to arm code */ + *(.eh_frame) + + KEEP (*(.init)) + KEEP (*(.fini)) + + . = ALIGN(4); + _etext = .; /* define a global symbols at end of code */ + } >FLASH + + /* Constant data into "FLASH" Rom type memory */ + .rodata : + { + . = ALIGN(4); + *(.rodata) /* .rodata sections (constants, strings, etc.) */ + *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ + . = ALIGN(4); + } >FLASH + + .ARM.extab : { + . = ALIGN(4); + *(.ARM.extab* .gnu.linkonce.armextab.*) + . = ALIGN(4); + } >FLASH + + .ARM : { + . = ALIGN(4); + __exidx_start = .; + *(.ARM.exidx*) + __exidx_end = .; + . = ALIGN(4); + } >FLASH + + .preinit_array : + { + . = ALIGN(4); + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array*)) + PROVIDE_HIDDEN (__preinit_array_end = .); + . = ALIGN(4); + } >FLASH + + .init_array : + { + . = ALIGN(4); + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array*)) + PROVIDE_HIDDEN (__init_array_end = .); + . = ALIGN(4); + } >FLASH + + .fini_array : + { + . = ALIGN(4); + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(SORT(.fini_array.*))) + KEEP (*(.fini_array*)) + PROVIDE_HIDDEN (__fini_array_end = .); + . = ALIGN(4); + } >FLASH + + /* Used by the startup to initialize data */ + _sidata = LOADADDR(.data); + + /* Initialized data sections into "RAM" Ram type memory */ + .data : + { + . = ALIGN(4); + _sdata = .; /* create a global symbol at data start */ + *(.data) /* .data sections */ + *(.data*) /* .data* sections */ + + . = ALIGN(4); + _edata = .; /* define a global symbol at data end */ + + } >RAM AT> FLASH + + /* Uninitialized data section into "RAM" Ram type memory */ + . = ALIGN(4); + .bss : + { + /* This is used by the startup in order to initialize the .bss section */ + _sbss = .; /* define a global symbol at bss start */ + __bss_start__ = _sbss; + *(.bss) + *(.bss*) + *(COMMON) + + . = ALIGN(4); + _ebss = .; /* define a global symbol at bss end */ + __bss_end__ = _ebss; + } >RAM + + /* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */ + ._user_heap_stack : + { + . = ALIGN(8); + PROVIDE ( end = . ); + PROVIDE ( _end = . ); + . = . + _Min_Heap_Size; + . = . + _Min_Stack_Size; + . = ALIGN(8); + } >RAM + + /* Remove information from the compiler libraries */ + /DISCARD/ : + { + libc.a ( * ) + libm.a ( * ) + libgcc.a ( * ) + } + + .ARM.attributes 0 : { *(.ARM.attributes) } +} diff --git a/examples/projects/NUCLEO-G431KB/bootloader/node_config.h b/examples/projects/NUCLEO-G431KB/bootloader/node_config.h index c2c242240..114000d6a 100644 --- a/examples/projects/NUCLEO-G431KB/bootloader/node_config.h +++ b/examples/projects/NUCLEO-G431KB/bootloader/node_config.h @@ -91,5 +91,9 @@ * APP_START_ADDRESS | 0x0800C800 | Start address of application with bootloader * APP_END_ADDRESS | FLASH_END | End address of application with bootloader ******************************************************************************/ - +#ifdef BOOTLOADER_UPDATER + #define BOOT_START_ADDRESS 0x800C800 + #define APP_START_ADDRESS 0x8000000 + #define APP_END_ADDRESS 0x800BFFF +#endif #endif /* _NODE_CONFIG_H_ */ diff --git a/examples/projects/NUCLEO-G431KB/bootloader/platformio.ini b/examples/projects/NUCLEO-G431KB/bootloader/platformio.ini index 46c8386dc..795981f25 100644 --- a/examples/projects/NUCLEO-G431KB/bootloader/platformio.ini +++ b/examples/projects/NUCLEO-G431KB/bootloader/platformio.ini @@ -7,12 +7,18 @@ ; ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html +[platformio] +default_envs = nucleo_g431kb -[env:nucleo_g431kb] +[env] platform = ststm32 board = nucleo_g431kb lib_extra_dirs = $PROJECT_DIR/../../../../../ framework = stm32cube +lib_deps = + luos_engine@^2.8.0 + +[env:nucleo_g431kb] board_build.ldscript = linker/custom_bootloader_script.ld build_unflags = -Os build_flags = @@ -22,7 +28,22 @@ build_flags = -DUSE_HAL_DRIVER -DUSE_FULL_LL_DRIVER -DLUOSHAL=STM32G4 -lib_deps = - luos_engine@^2.8.0 debug_tool = stlink upload_protocol = stlink + +[env:nucleo_g431kb_updater] +board_build.ldscript = linker/custom_bootloader_updater_script.ld +build_unflags = -Os +build_flags = + -O1 + -DBOOTLOADER + -DBOOTLOADER_UPDATER + -include node_config.h + -DUSE_HAL_DRIVER + -DUSE_FULL_LL_DRIVER + -DLUOSHAL=STM32G4 +upload_protocol = custom +upload_flags = + -t2 +upload_command = pyluos-bootloader flash $UPLOAD_PORT $UPLOAD_FLAGS -b $SOURCE + From 38e259080a88263e42dbd2d9ccbd8637f3fd3508 Mon Sep 17 00:00:00 2001 From: biliouriv Date: Wed, 9 Nov 2022 11:55:24 +0100 Subject: [PATCH 11/12] [Fix] Bootloader NUCLEO-L0 vector in ram rsvd --- engine/HAL/STM32L0/luos_hal.c | 22 +++++++++++++++++-- .../linker/custom_Luos_bootloader_script.ld | 9 +++++++- .../linker/custom_Luos_bootloader_script.ld | 9 +++++++- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/engine/HAL/STM32L0/luos_hal.c b/engine/HAL/STM32L0/luos_hal.c index e7ee0ba6f..d655faf69 100644 --- a/engine/HAL/STM32L0/luos_hal.c +++ b/engine/HAL/STM32L0/luos_hal.c @@ -17,6 +17,8 @@ /******************************************************************************* * Variables ******************************************************************************/ +#define RSVD_SECTION ".rsvd.data,\"aw\",%nobits//" +#define _RSVD __attribute__((used, section(RSVD_SECTION))) // timestamp variable static ll_timestamp_t ll_timestamp; /******************************************************************************* @@ -77,7 +79,23 @@ static void LuosHAL_SystickInit(void) ******************************************************************************/ static void LuosHAL_VectorTableRemap(void) { - SCB->VTOR = LUOS_VECT_TAB; + /* Copy the vector table from the Flash (mapped at the base of the application + load address 0x0800C800) to the base address of the SRAM at 0x20000000. */ + // check if we are at the beginning of flash + if (LUOS_VECT_TAB > FLASH_BASE) + { + static volatile _RSVD uint32_t VectorTable[48]; + + for (uint32_t i = 0; i < 48; i++) + { + VectorTable[i] = *(__IO uint32_t *)(LUOS_VECT_TAB + (i << 2)); + } + + /* Enable the SYSCFG peripheral clock*/ + __HAL_RCC_SYSCFG_CLK_ENABLE(); + /* Remap SRAM at 0x00000000 */ + __HAL_SYSCFG_REMAPMEMORY_SRAM(); + } } /****************************************************************************** * @brief Luos HAL general systick tick at 1ms @@ -307,7 +325,7 @@ void LuosHAL_EraseMemory(uint32_t address, uint16_t size) /****************************************************************************** * @brief Programm flash memory - * @param address : Start address + * @param address : Start address * @param size :: Data size * @param data : Pointer to data * @return diff --git a/examples/projects/NUCLEO-L073RZ/button/linker/custom_Luos_bootloader_script.ld b/examples/projects/NUCLEO-L073RZ/button/linker/custom_Luos_bootloader_script.ld index 3c8abb26b..52d8cef34 100644 --- a/examples/projects/NUCLEO-L073RZ/button/linker/custom_Luos_bootloader_script.ld +++ b/examples/projects/NUCLEO-L073RZ/button/linker/custom_Luos_bootloader_script.ld @@ -45,7 +45,8 @@ _Min_Stack_Size = 0x400; /* required amount of stack */ /* Memories definition */ MEMORY { - RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 20K + RAM_RSVD (xrw) : ORIGIN = 0x20000000, LENGTH = 1K + RAM (xrw) : ORIGIN = 0x20000400, LENGTH = 19K FLASH (rx) : ORIGIN = 0x800C800, LENGTH = 142K } @@ -174,6 +175,12 @@ SECTIONS . = ALIGN(8); } >RAM + .boot_data : + { + *(.rsvd.data) + *(.rsvd.data*) + } > RAM_RSVD + /* Remove information from the compiler libraries */ /DISCARD/ : { diff --git a/examples/projects/NUCLEO-L073RZ/gate_serialcom/linker/custom_Luos_bootloader_script.ld b/examples/projects/NUCLEO-L073RZ/gate_serialcom/linker/custom_Luos_bootloader_script.ld index 3c8abb26b..52d8cef34 100644 --- a/examples/projects/NUCLEO-L073RZ/gate_serialcom/linker/custom_Luos_bootloader_script.ld +++ b/examples/projects/NUCLEO-L073RZ/gate_serialcom/linker/custom_Luos_bootloader_script.ld @@ -45,7 +45,8 @@ _Min_Stack_Size = 0x400; /* required amount of stack */ /* Memories definition */ MEMORY { - RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 20K + RAM_RSVD (xrw) : ORIGIN = 0x20000000, LENGTH = 1K + RAM (xrw) : ORIGIN = 0x20000400, LENGTH = 19K FLASH (rx) : ORIGIN = 0x800C800, LENGTH = 142K } @@ -174,6 +175,12 @@ SECTIONS . = ALIGN(8); } >RAM + .boot_data : + { + *(.rsvd.data) + *(.rsvd.data*) + } > RAM_RSVD + /* Remove information from the compiler libraries */ /DISCARD/ : { From a65111d03e76f4e2cb1428358ea1343f7241714e Mon Sep 17 00:00:00 2001 From: biliouriv Date: Wed, 9 Nov 2022 11:57:09 +0100 Subject: [PATCH 12/12] [Bootloader] bootloader updater for NUCLEO-L073RZ --- .../custom_bootloader_updater_script.ld | 200 ++++++++++++++++++ .../linker/custom_new_bootloader_script.ld | 200 ++++++++++++++++++ .../NUCLEO-L073RZ/bootloader/node_config.h | 6 +- .../NUCLEO-L073RZ/bootloader/platformio.ini | 41 +++- 4 files changed, 443 insertions(+), 4 deletions(-) create mode 100644 examples/projects/NUCLEO-L073RZ/bootloader/linker/custom_bootloader_updater_script.ld create mode 100644 examples/projects/NUCLEO-L073RZ/bootloader/linker/custom_new_bootloader_script.ld diff --git a/examples/projects/NUCLEO-L073RZ/bootloader/linker/custom_bootloader_updater_script.ld b/examples/projects/NUCLEO-L073RZ/bootloader/linker/custom_bootloader_updater_script.ld new file mode 100644 index 000000000..5cc546675 --- /dev/null +++ b/examples/projects/NUCLEO-L073RZ/bootloader/linker/custom_bootloader_updater_script.ld @@ -0,0 +1,200 @@ +/* +****************************************************************************** +** +** @file : LinkerScript.ld +** +** @author : Auto-generated by STM32CubeIDE +** +** @brief : Linker script for STM32L073RZTx Device from STM32L0 series +** 192Kbytes FLASH +** 20Kbytes RAM +** +** Set heap size, stack size and stack location according +** to application requirements. +** +** Set memory bank area and size if external memory is used +** +** Target : STMicroelectronics STM32 +** +** Distribution: The file is distributed as is, without any warranty +** of any kind. +** +****************************************************************************** +** @attention +** +**

© Copyright (c) 2021 STMicroelectronics. +** All rights reserved.

+** +** This software component is licensed by ST under BSD 3-Clause license, +** the "License"; You may not use this file except in compliance with the +** License. You may obtain a copy of the License at: +** opensource.org/licenses/BSD-3-Clause +** +****************************************************************************** +*/ + +/* Entry Point */ +ENTRY(Reset_Handler) + +/* Highest address of the user mode stack */ +_estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */ + +_Min_Heap_Size = 0x200; /* required amount of heap */ +_Min_Stack_Size = 0x400; /* required amount of stack */ + +/* Memories definition */ +MEMORY +{ + RAM_RSVD (xrw) : ORIGIN = 0x20000000, LENGTH = 1K + RAM (xrw) : ORIGIN = 0x20000400, LENGTH = 19K + FLASH (rx) : ORIGIN = 0x800C800, LENGTH = 48K + SHRD_MEM (rw) : ORIGIN = 0x0800C000, LENGTH = 2K +} + +/* Sections */ +SECTIONS +{ + /* placing my boot flags section at given address: */ + .boot_flags : + { + KEEP(*(.boot_flags)) /* keep my variable even if not referenced */ + } > SHRD_MEM + + /* The startup code into "FLASH" Rom type memory */ + .isr_vector : + { + . = ALIGN(4); + KEEP(*(.isr_vector)) /* Startup code */ + . = ALIGN(4); + } >FLASH + + /* The program code and other data into "FLASH" Rom type memory */ + .text : + { + . = ALIGN(4); + *(.text) /* .text sections (code) */ + *(.text*) /* .text* sections (code) */ + *(.glue_7) /* glue arm to thumb code */ + *(.glue_7t) /* glue thumb to arm code */ + *(.eh_frame) + + KEEP (*(.init)) + KEEP (*(.fini)) + + . = ALIGN(4); + _etext = .; /* define a global symbols at end of code */ + } >FLASH + + /* Constant data into "FLASH" Rom type memory */ + .rodata : + { + . = ALIGN(4); + *(.rodata) /* .rodata sections (constants, strings, etc.) */ + *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ + . = ALIGN(4); + } >FLASH + + .ARM.extab : { + . = ALIGN(4); + *(.ARM.extab* .gnu.linkonce.armextab.*) + . = ALIGN(4); + } >FLASH + + .ARM : { + . = ALIGN(4); + __exidx_start = .; + *(.ARM.exidx*) + __exidx_end = .; + . = ALIGN(4); + } >FLASH + + .preinit_array : + { + . = ALIGN(4); + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array*)) + PROVIDE_HIDDEN (__preinit_array_end = .); + . = ALIGN(4); + } >FLASH + + .init_array : + { + . = ALIGN(4); + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array*)) + PROVIDE_HIDDEN (__init_array_end = .); + . = ALIGN(4); + } >FLASH + + .fini_array : + { + . = ALIGN(4); + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(SORT(.fini_array.*))) + KEEP (*(.fini_array*)) + PROVIDE_HIDDEN (__fini_array_end = .); + . = ALIGN(4); + } >FLASH + + /* Used by the startup to initialize data */ + _sidata = LOADADDR(.data); + + /* Initialized data sections into "RAM" Ram type memory */ + .data : + { + . = ALIGN(4); + _sdata = .; /* create a global symbol at data start */ + *(.data) /* .data sections */ + *(.data*) /* .data* sections */ + *(.RamFunc) /* .RamFunc sections */ + *(.RamFunc*) /* .RamFunc* sections */ + + . = ALIGN(4); + _edata = .; /* define a global symbol at data end */ + + } >RAM AT> FLASH + + /* Uninitialized data section into "RAM" Ram type memory */ + . = ALIGN(4); + .bss : + { + /* This is used by the startup in order to initialize the .bss section */ + _sbss = .; /* define a global symbol at bss start */ + __bss_start__ = _sbss; + *(.bss) + *(.bss*) + *(COMMON) + + . = ALIGN(4); + _ebss = .; /* define a global symbol at bss end */ + __bss_end__ = _ebss; + } >RAM + + /* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */ + ._user_heap_stack : + { + . = ALIGN(8); + PROVIDE ( end = . ); + PROVIDE ( _end = . ); + . = . + _Min_Heap_Size; + . = . + _Min_Stack_Size; + . = ALIGN(8); + } >RAM + + .boot_data : + { + *(.rsvd.data) + *(.rsvd.data*) + } > RAM_RSVD + + /* Remove information from the compiler libraries */ + /DISCARD/ : + { + libc.a ( * ) + libm.a ( * ) + libgcc.a ( * ) + } + + .ARM.attributes 0 : { *(.ARM.attributes) } +} diff --git a/examples/projects/NUCLEO-L073RZ/bootloader/linker/custom_new_bootloader_script.ld b/examples/projects/NUCLEO-L073RZ/bootloader/linker/custom_new_bootloader_script.ld new file mode 100644 index 000000000..95ca5cec1 --- /dev/null +++ b/examples/projects/NUCLEO-L073RZ/bootloader/linker/custom_new_bootloader_script.ld @@ -0,0 +1,200 @@ +/* +****************************************************************************** +** +** @file : LinkerScript.ld +** +** @author : Auto-generated by STM32CubeIDE +** +** @brief : Linker script for STM32L073RZTx Device from STM32L0 series +** 192Kbytes FLASH +** 20Kbytes RAM +** +** Set heap size, stack size and stack location according +** to application requirements. +** +** Set memory bank area and size if external memory is used +** +** Target : STMicroelectronics STM32 +** +** Distribution: The file is distributed as is, without any warranty +** of any kind. +** +****************************************************************************** +** @attention +** +**

© Copyright (c) 2021 STMicroelectronics. +** All rights reserved.

+** +** This software component is licensed by ST under BSD 3-Clause license, +** the "License"; You may not use this file except in compliance with the +** License. You may obtain a copy of the License at: +** opensource.org/licenses/BSD-3-Clause +** +****************************************************************************** +*/ + +/* Entry Point */ +ENTRY(Reset_Handler) + +/* Highest address of the user mode stack */ +_estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */ + +_Min_Heap_Size = 0x200; /* required amount of heap */ +_Min_Stack_Size = 0x400; /* required amount of stack */ + +/* Memories definition */ +MEMORY +{ + RAM_RSVD (xrw) : ORIGIN = 0x20000000, LENGTH = 1K + RAM (xrw) : ORIGIN = 0x20000400, LENGTH = 19K + FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 48K + SHRD_MEM (rw) : ORIGIN = 0x0800C000, LENGTH = 2K +} + +/* Sections */ +SECTIONS +{ + /* placing my boot flags section at given address: */ + .boot_flags : + { + KEEP(*(.boot_flags)) /* keep my variable even if not referenced */ + } > SHRD_MEM + + /* The startup code into "FLASH" Rom type memory */ + .isr_vector : + { + . = ALIGN(4); + KEEP(*(.isr_vector)) /* Startup code */ + . = ALIGN(4); + } >FLASH + + /* The program code and other data into "FLASH" Rom type memory */ + .text : + { + . = ALIGN(4); + *(.text) /* .text sections (code) */ + *(.text*) /* .text* sections (code) */ + *(.glue_7) /* glue arm to thumb code */ + *(.glue_7t) /* glue thumb to arm code */ + *(.eh_frame) + + KEEP (*(.init)) + KEEP (*(.fini)) + + . = ALIGN(4); + _etext = .; /* define a global symbols at end of code */ + } >FLASH + + /* Constant data into "FLASH" Rom type memory */ + .rodata : + { + . = ALIGN(4); + *(.rodata) /* .rodata sections (constants, strings, etc.) */ + *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ + . = ALIGN(4); + } >FLASH + + .ARM.extab : { + . = ALIGN(4); + *(.ARM.extab* .gnu.linkonce.armextab.*) + . = ALIGN(4); + } >FLASH + + .ARM : { + . = ALIGN(4); + __exidx_start = .; + *(.ARM.exidx*) + __exidx_end = .; + . = ALIGN(4); + } >FLASH + + .preinit_array : + { + . = ALIGN(4); + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array*)) + PROVIDE_HIDDEN (__preinit_array_end = .); + . = ALIGN(4); + } >FLASH + + .init_array : + { + . = ALIGN(4); + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array*)) + PROVIDE_HIDDEN (__init_array_end = .); + . = ALIGN(4); + } >FLASH + + .fini_array : + { + . = ALIGN(4); + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(SORT(.fini_array.*))) + KEEP (*(.fini_array*)) + PROVIDE_HIDDEN (__fini_array_end = .); + . = ALIGN(4); + } >FLASH + + /* Used by the startup to initialize data */ + _sidata = LOADADDR(.data); + + /* Initialized data sections into "RAM" Ram type memory */ + .data : + { + . = ALIGN(4); + _sdata = .; /* create a global symbol at data start */ + *(.data) /* .data sections */ + *(.data*) /* .data* sections */ + *(.RamFunc) /* .RamFunc sections */ + *(.RamFunc*) /* .RamFunc* sections */ + + . = ALIGN(4); + _edata = .; /* define a global symbol at data end */ + + } >RAM AT> FLASH + + /* Uninitialized data section into "RAM" Ram type memory */ + . = ALIGN(4); + .bss : + { + /* This is used by the startup in order to initialize the .bss section */ + _sbss = .; /* define a global symbol at bss start */ + __bss_start__ = _sbss; + *(.bss) + *(.bss*) + *(COMMON) + + . = ALIGN(4); + _ebss = .; /* define a global symbol at bss end */ + __bss_end__ = _ebss; + } >RAM + + /* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */ + ._user_heap_stack : + { + . = ALIGN(8); + PROVIDE ( end = . ); + PROVIDE ( _end = . ); + . = . + _Min_Heap_Size; + . = . + _Min_Stack_Size; + . = ALIGN(8); + } >RAM + + .boot_data : + { + *(.rsvd.data) + *(.rsvd.data*) + } > RAM_RSVD + + /* Remove information from the compiler libraries */ + /DISCARD/ : + { + libc.a ( * ) + libm.a ( * ) + libgcc.a ( * ) + } + + .ARM.attributes 0 : { *(.ARM.attributes) } +} diff --git a/examples/projects/NUCLEO-L073RZ/bootloader/node_config.h b/examples/projects/NUCLEO-L073RZ/bootloader/node_config.h index 5198bceb5..159752726 100644 --- a/examples/projects/NUCLEO-L073RZ/bootloader/node_config.h +++ b/examples/projects/NUCLEO-L073RZ/bootloader/node_config.h @@ -92,5 +92,9 @@ * APP_START_ADDRESS | 0x0800C800 | Start address of application with bootloader * APP_END_ADDRESS | FLASH_END | End address of application with bootloader ******************************************************************************/ - +#ifdef BOOTLOADER_UPDATER + #define BOOT_START_ADDRESS (uint32_t)0x0800C800 + #define APP_START_ADDRESS (uint32_t)0x08000000 + #define APP_END_ADDRESS (uint32_t)0x0800BFFF +#endif #endif /* _NODE_CONFIG_H_ */ diff --git a/examples/projects/NUCLEO-L073RZ/bootloader/platformio.ini b/examples/projects/NUCLEO-L073RZ/bootloader/platformio.ini index 7bc8cd024..60bc3b3e5 100644 --- a/examples/projects/NUCLEO-L073RZ/bootloader/platformio.ini +++ b/examples/projects/NUCLEO-L073RZ/bootloader/platformio.ini @@ -7,12 +7,18 @@ ; ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html +[platformio] +default_envs = nucleo_l073rz -[env:nucleo_l073rz] +[env] platform = ststm32 board = nucleo_l073rz lib_extra_dirs = $PROJECT_DIR/../../../../../ framework = stm32cube +lib_deps = + luos_engine@^2.8.0 + +[env:nucleo_l073rz] board_build.ldscript = linker/custom_bootloader_script.ld build_unflags = -Os build_flags = @@ -22,8 +28,37 @@ build_flags = -DUSE_FULL_LL_DRIVER -DLUOSHAL=STM32L0 -DBOOTLOADER -lib_deps = - luos_engine@^2.8.0 debug_tool = stlink upload_protocol = stlink +[env:nucleo_l073rz_updater] +board_build.ldscript = linker/custom_bootloader_updater_script.ld +build_unflags = -Os +build_flags = + -O1 + -include node_config.h + -DUSE_HAL_DRIVER + -DUSE_FULL_LL_DRIVER + -DLUOSHAL=STM32L0 + -DBOOTLOADER + -DBOOTLOADER_UPDATER +upload_protocol = custom +upload_flags = + -t2 +upload_command = pyluos-bootloader flash $UPLOAD_PORT $UPLOAD_FLAGS -b $SOURCE + +[env:nucleo_l073rz_new_boot] +board_build.ldscript = linker/custom_new_bootloader_script.ld +build_unflags = -Os +build_flags = + -O1 + -include node_config.h + -DUSE_HAL_DRIVER + -DUSE_FULL_LL_DRIVER + -DLUOSHAL=STM32L0 + -DBOOTLOADER +upload_protocol = custom +upload_flags = + -t2 +upload_command = pyluos-bootloader flash $UPLOAD_PORT $UPLOAD_FLAGS -b $SOURCE +