Skip to content

Commit 35c7311

Browse files
jciberlinIgor-Misic
authored andcommitted
Bootloader self-update feature for STM32F7xx
- bootloader self-update feature for STM32F7xx - update linker scripts - update ram firmware address and magic key ram address
1 parent fe1efb8 commit 35c7311

7 files changed

Lines changed: 92 additions & 79 deletions

File tree

Bootloader/Adapters/Inc/flash_adapter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@
6565
#elif defined(STM32F7xx)
6666
#define FLASH_FIRMWARE_ADDRESS (0x08020000UL) //!< Flash address where firmware will be written
6767
#define FLASH_BOOTLOADER_ADDRESS (0x08000000UL) //!< Flash address where bootloader will be written
68-
#define RAM_FIRMWARE_ADDRESS (0x20000040UL) //!< RAM address where firmware will be written
68+
#define RAM_FIRMWARE_ADDRESS (0x20020000UL) //!< RAM address where firmware will be written
6969
#define MAGIC_KEY_ADDRESS_FLASH (0x08020200UL) //!< Flash address in internal flash for communication between bootloader and firmware
70-
#define MAGIC_KEY_ADDRESS_RAM (0x20000000UL) //!< Flash address in ram for communication between bootloader and firmware
70+
#define MAGIC_KEY_ADDRESS_RAM (0x20070000UL) //!< Flash address in ram for communication between bootloader and firmware
7171
#endif
7272

7373
#define MAGIC_KEY_VALUE (0x28101987A5B5C5D5UL) //!< Hex value if written in flash bootloader will jump to firmware

Bootloader/Src/binary_update.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ BinaryUpdate_erase(uint32_t firmware_size) {
120120
success = FlashAdapter_erase(firmware_size, s_address);
121121
break;
122122
case detectedBinary_BOOTLOADER_FLASH:
123-
if (detectedBinary_BOOTLOADER_RAM != boot_info.previus_binary) {
123+
if (detectedBinary_BOOTLOADER_RAM == boot_info.previus_binary) {
124124
//Only allowed to erase if RAM version is running
125125
success = FlashAdapter_erase(firmware_size, s_address);
126126
}

Linker/STM32F7xx.ld

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,18 @@
2828
ENTRY(Reset_Handler)
2929

3030
/* Highest address of the user mode stack */
31-
_estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */
31+
_estack = ORIGIN(RAM1) + LENGTH(RAM1) + LENGTH(RAM2); /* end of "RAM" Ram type memory */
3232

3333
_Min_Heap_Size = 0x200 ; /* required amount of heap */
3434
_Min_Stack_Size = 0x400 ; /* required amount of stack */
3535

3636
/* Memories definition */
3737
MEMORY
3838
{
39-
BL_FLAG_RAM (xrw): ORIGIN = 0x20000000, LENGTH = 64 /* Bootloader flag in RAM */
40-
RAM (xrw) : ORIGIN = 0x20000040, LENGTH = 512K - 64
41-
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 128K
39+
RAM1 (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
40+
RAM2 (xrw) : ORIGIN = 0x20020000, LENGTH = 512K - 128K - 64K
41+
BL_FLAG_RAM (xrw): ORIGIN = 0x20070000, LENGTH = 64 /* Bootloader flag in RAM */
42+
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 128K
4243
}
4344

4445
/* Sections */
@@ -124,6 +125,11 @@ SECTIONS
124125
/* Used by the startup to initialize data */
125126
_sidata = LOADADDR(.data);
126127

128+
.restart_info : ALIGN(4)
129+
{
130+
KEEP(*(.restart_info))
131+
} >RAM1 AT> FLASH
132+
127133
/* Initialized data sections into "RAM" Ram type memory */
128134
.data :
129135
{
@@ -137,7 +143,7 @@ SECTIONS
137143
. = ALIGN(4);
138144
_edata = .; /* define a global symbol at data end */
139145

140-
} >RAM AT> FLASH
146+
} >RAM1 AT> FLASH
141147

142148
/* Uninitialized data section into "RAM" Ram type memory */
143149
. = ALIGN(4);
@@ -153,7 +159,7 @@ SECTIONS
153159
. = ALIGN(4);
154160
_ebss = .; /* define a global symbol at bss end */
155161
__bss_end__ = _ebss;
156-
} >RAM
162+
} >RAM1
157163

158164
/* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */
159165
._user_heap_stack :
@@ -164,7 +170,7 @@ SECTIONS
164170
. = . + _Min_Heap_Size;
165171
. = . + _Min_Stack_Size;
166172
. = ALIGN(8);
167-
} >RAM
173+
} >RAM1
168174

169175
/* Remove information from the compiler libraries */
170176
/DISCARD/ :

Linker/STM32F7xx_RAM.ld

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,32 +28,32 @@
2828
ENTRY(Reset_Handler)
2929

3030
/* Highest address of the user mode stack */
31-
_estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */
31+
_estack = ORIGIN(RAM1) + LENGTH(RAM1) + LENGTH(RAM2); /* end of "RAM" Ram type memory */
3232

33-
_Min_Heap_Size = 0x200 ; /* required amount of heap */
34-
_Min_Stack_Size = 0x400 ; /* required amount of stack */
33+
_Min_Heap_Size = 0x200; /* required amount of heap */
34+
_Min_Stack_Size = 0x400; /* required amount of stack */
3535

3636
/* Memories definition */
3737
MEMORY
3838
{
39-
BL_FLAG_RAM (xrw): ORIGIN = 0x20000000, LENGTH = 64 /* Bootloader flag in RAM */
40-
RAM (xrw) : ORIGIN = 0x20000040, LENGTH = 512K - 64
41-
SIGNATURE (rx) : ORIGIN = 0x07FFFFC0, LENGTH = 64 /* Never written to the FLASH, it is for binary signature. */
39+
RAM1 (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
40+
RAM2 (xrw) : ORIGIN = 0x20020000, LENGTH = 512K - 128K - 64K
41+
BL_FLAG_RAM (xrw): ORIGIN = 0x20070000, LENGTH = 64 /* Bootloader flag in RAM */
4242
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 128K
4343
}
4444

4545
/* Sections */
4646
SECTIONS
4747
{
48-
/* The startup code into "RAM" Rom type memory */
48+
/* The startup code into "RAM" Ram type memory */
4949
.isr_vector :
5050
{
5151
. = ALIGN(4);
5252
KEEP(*(.isr_vector)) /* Startup code */
5353
. = ALIGN(4);
54-
} >RAM
54+
} >RAM2
5555

56-
/* The program code and other data into "RAM" Rom type memory */
56+
/* The program code and other data into "RAM" Ram type memory */
5757
.text :
5858
{
5959
. = ALIGN(4);
@@ -62,36 +62,38 @@ SECTIONS
6262
*(.glue_7) /* glue arm to thumb code */
6363
*(.glue_7t) /* glue thumb to arm code */
6464
*(.eh_frame)
65+
*(.RamFunc) /* .RamFunc sections */
66+
*(.RamFunc*) /* .RamFunc* sections */
6567

6668
KEEP (*(.init))
6769
KEEP (*(.fini))
6870

6971
. = ALIGN(4);
7072
_etext = .; /* define a global symbols at end of code */
71-
} >RAM
73+
} >RAM2
7274

73-
/* Constant data into "RAM" Rom type memory */
75+
/* Constant data into "RAM" Ram type memory */
7476
.rodata :
7577
{
7678
. = ALIGN(4);
7779
*(.rodata) /* .rodata sections (constants, strings, etc.) */
7880
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
7981
. = ALIGN(4);
80-
} >RAM
82+
} >RAM2
8183

8284
.ARM.extab : {
8385
. = ALIGN(4);
8486
*(.ARM.extab* .gnu.linkonce.armextab.*)
8587
. = ALIGN(4);
86-
} >RAM
88+
} >RAM2
8789

8890
.ARM : {
8991
. = ALIGN(4);
9092
__exidx_start = .;
9193
*(.ARM.exidx*)
9294
__exidx_end = .;
9395
. = ALIGN(4);
94-
} >RAM
96+
} >RAM2
9597

9698
.preinit_array :
9799
{
@@ -100,7 +102,7 @@ SECTIONS
100102
KEEP (*(.preinit_array*))
101103
PROVIDE_HIDDEN (__preinit_array_end = .);
102104
. = ALIGN(4);
103-
} >RAM
105+
} >RAM2
104106

105107
.init_array :
106108
{
@@ -110,7 +112,7 @@ SECTIONS
110112
KEEP (*(.init_array*))
111113
PROVIDE_HIDDEN (__init_array_end = .);
112114
. = ALIGN(4);
113-
} >RAM
115+
} >RAM2
114116

115117
.fini_array :
116118
{
@@ -120,30 +122,28 @@ SECTIONS
120122
KEEP (*(.fini_array*))
121123
PROVIDE_HIDDEN (__fini_array_end = .);
122124
. = ALIGN(4);
123-
} >RAM
124-
125-
.restart_info : ALIGN(4)
126-
{
127-
KEEP(*(.restart_info))
128-
} >RAM AT> RAM
125+
} >RAM2
129126

130127
/* Used by the startup to initialize data */
131128
_sidata = LOADADDR(.data);
132129

130+
.restart_info : ALIGN(4)
131+
{
132+
KEEP(*(.restart_info))
133+
} >RAM1 AT> RAM2
134+
133135
/* Initialized data sections into "RAM" Ram type memory */
134136
.data :
135137
{
136138
. = ALIGN(4);
137139
_sdata = .; /* create a global symbol at data start */
138140
*(.data) /* .data sections */
139141
*(.data*) /* .data* sections */
140-
*(.RamFunc) /* .RamFunc sections */
141-
*(.RamFunc*) /* .RamFunc* sections */
142142

143143
. = ALIGN(4);
144144
_edata = .; /* define a global symbol at data end */
145145

146-
} >RAM AT> RAM
146+
} >RAM1 AT> RAM2
147147

148148
/* Uninitialized data section into "RAM" Ram type memory */
149149
. = ALIGN(4);
@@ -159,7 +159,7 @@ SECTIONS
159159
. = ALIGN(4);
160160
_ebss = .; /* define a global symbol at bss end */
161161
__bss_end__ = _ebss;
162-
} >RAM
162+
} >RAM1 AT> RAM2
163163

164164
/* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */
165165
._user_heap_stack :
@@ -170,7 +170,7 @@ SECTIONS
170170
. = . + _Min_Heap_Size;
171171
. = . + _Min_Stack_Size;
172172
. = ALIGN(8);
173-
} >RAM
173+
} >RAM1 AT> RAM2
174174

175175
/* Remove information from the compiler libraries */
176176
/DISCARD/ :

0 commit comments

Comments
 (0)