Skip to content

Commit 8f4dc00

Browse files
committed
save
1 parent 314721f commit 8f4dc00

File tree

5 files changed

+265
-19
lines changed

5 files changed

+265
-19
lines changed

Bootloader/Adapters/Inc/flash_adapter.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@
4040

4141
#ifdef EXTERNAL_FLASH // Selecting where will firmware go
4242

43-
// TODO: add support for external flash chip
44-
#define FIRMWARE_FLASH_SIZE_LIMIT (100000U)
45-
#define PACKET_SIZE 256U //TODO: this time size is 256 and 64 byte package can fit in, Check in the future.
43+
#define FIRMWARE_FLASH_SIZE_LIMIT (100000U)
44+
#define PACKET_SIZE (256U)
4645

4746
#else
4847
#define FIRMWARE_FLASH_SIZE_LIMIT (FLASH_SIZE - 0x8000u) //!< Max available flash size for firmware. Flash bank size - FW start address
@@ -68,8 +67,8 @@
6867
#define MAGIC_KEY_ADDRESS_FLASH (0x08020200UL) //!< Flash address in internal flash for communication between bootloader and firmware
6968
#define MAGIC_KEY_ADDRESS_RAM (0x20070000UL) //!< Flash address in ram for communication between bootloader and firmware
7069
#elif defined(STM32N6xx)
71-
#define FLASH_FIRMWARE_ADDRESS (0x08020000UL) //!< Flash address where firmware will be written
72-
#define FLASH_BOOTLOADER_ADDRESS (0x08000000UL) //!< Flash address where bootloader will be written
70+
#define FLASH_FIRMWARE_ADDRESS (0x70000000UL) //!< Flash address where firmware will be written
71+
#define FLASH_BOOTLOADER_ADDRESS (0x70010000UL) //!< Flash address where bootloader will be written
7372
#define RAM_FIRMWARE_ADDRESS (0x34000000UL) //!< RAM address where firmware will be written
7473
#else // UnitTest
7574
#define FLASH_FIRMWARE_ADDRESS (0x08020000UL) //!< Flash address where firmware will be written
@@ -93,7 +92,7 @@ bool FlashAdapter_setReadProtection(bool enable);
9392
bool FlashAdapter_setPCROP(bool enable, uint32_t protect_address_start, uint32_t protect_address_end);
9493

9594
#ifdef EXTERNAL_FLASH
96-
void FlashAdapter_initXSPI(void);
95+
void FlashAdapter_init(void);
9796
#endif
9897

9998
#endif /* BOOTLOADER_INC_FLASH_ADAPTER_H_ */

Bootloader/Adapters/Src/flash_adapter.c

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,27 +59,64 @@ HAL_StatusTypeDef ActivateProtection(FLASH_OBProgramInitTypeDef* ob_struct, uint
5959

6060
#ifdef EXTERNAL_FLASH
6161

62+
#include "extmem_manager.h"
63+
#include "stm32_sfdp_driver_api.h"
64+
65+
extern BOOTStatus_TypeDef MapMemory(void);
66+
67+
extern EXTMEM_DefinitionTypeDef extmem_list_config[1];
68+
6269
XSPI_HandleTypeDef hxspi2;
6370

6471
bool
6572
FlashAdapter_erase(uint32_t firmware_size, uint32_t flash_address) {
66-
//return W25q_dynamicErase(firmware_size, flash_address);
67-
return true;
73+
74+
bool success = false;
75+
76+
EXTMEM_StatusTypeDef retr = EXTMEM_EraseSector(EXTMEMORY_1, flash_address, firmware_size);
77+
78+
if (EXTMEM_OK == retr) {
79+
success = false;
80+
}
81+
82+
return success;
6883
}
6984

7085
bool
7186
FlashAdapter_blockErase(uint32_t address) {
72-
return true;
87+
return false;
7388
}
7489

7590
bool
7691
FlashAdapter_program(uint32_t address, uint8_t* buffer, uint32_t length) {
77-
return true;
92+
93+
bool success = false;
94+
EXTMEM_DRIVER_NOR_SFDP_StatusTypeDef ret = EXTMEM_DRIVER_NOR_SFDP_OK;
95+
96+
ret = EXTMEM_DRIVER_NOR_SFDP_Disable_MemoryMappedMode(&(extmem_list_config->NorSfdpObject));
97+
98+
if (EXTMEM_DRIVER_NOR_SFDP_OK == ret) {
99+
ret = EXTMEM_DRIVER_NOR_SFDP_Write(&(extmem_list_config->NorSfdpObject), address, buffer, length);
100+
101+
if (EXTMEM_DRIVER_NOR_SFDP_OK == ret) {
102+
EXTMEM_DRIVER_NOR_SFDP_Enable_MemoryMappedMode(&(extmem_list_config->NorSfdpObject));
103+
}
104+
}
105+
106+
if (EXTMEM_DRIVER_NOR_SFDP_OK == ret) {
107+
success = true;
108+
}
109+
110+
return success;
78111
}
79112

80113
bool
81114
FlashAdapter_readBytes(uint32_t address, uint8_t* buffer, uint32_t length) {
82-
return true;
115+
bool success = true;
116+
// cppcheck-suppress misra-c2012-11.6; address is received as uint32_t
117+
(void*)memcpy((void*)buffer, (void*)address, length);
118+
119+
return success;
83120
}
84121

85122
bool
@@ -88,7 +125,7 @@ FlashAdapter_finish(void) {
88125
}
89126

90127
void
91-
FlashAdapter_initXSPI(void) {
128+
FlashAdapter_init(void) {
92129
XSPIM_CfgTypeDef sXspiManagerCfg = {0};
93130

94131
/* XSPI2 parameter configuration*/
@@ -117,6 +154,9 @@ FlashAdapter_initXSPI(void) {
117154
if (HAL_XSPIM_Config(&hxspi2, &sXspiManagerCfg, HAL_XSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK) {
118155
Error_Handler();
119156
}
157+
158+
MX_EXTMEM_MANAGER_Init();
159+
MapMemory();
120160
}
121161

122162
#else

Bootloader/Src/main.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@
4444
#include "communication.h"
4545
#include "security_adapter.h"
4646
#include "signature.h"
47-
#include "extmem_manager.h"
48-
49-
extern BOOTStatus_TypeDef MapMemory(void);
5047

5148
typedef void (*pFunction)(void);
5249

@@ -63,9 +60,7 @@ main(void) {
6360
bool enter_bootloader_loop = false;
6461

6562
#ifdef EXTERNAL_FLASH
66-
FlashAdapter_initXSPI();
67-
MX_EXTMEM_MANAGER_Init();
68-
MapMemory();
63+
FlashAdapter_init();
6964
#endif
7065

7166
#ifdef SECURED

Linker/STM32N6xx_EXT_FLASH.ld

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
/*
2+
******************************************************************************
3+
**
4+
** @file : STM32N657XX_AXISRAM2_fsbl.ld
5+
**
6+
** @author : GPM Application Team
7+
**
8+
** @brief : Linker script for STM32N657XX Device from STM32N6 series
9+
** 512 KBytes RAM
10+
**
11+
** Set heap size, stack size and stack location according
12+
** to application requirements.
13+
**
14+
** Set memory bank area and size if external memory is used
15+
**
16+
** Target : STMicroelectronics STM32
17+
**
18+
** Distribution: The file is distributed as is, without any warranty
19+
** of any kind.
20+
**
21+
******************************************************************************
22+
** @attention
23+
**
24+
** Copyright (c) 2023 STMicroelectronics.
25+
** All rights reserved.
26+
**
27+
** This software is licensed under terms that can be found in the LICENSE file
28+
** in the root directory of this software component.
29+
** If no LICENSE file comes with this software, it is provided AS-IS.
30+
**
31+
******************************************************************************
32+
*/
33+
34+
/* Entry Point */
35+
ENTRY(Reset_Handler)
36+
37+
/* Highest address of the user mode stack */
38+
_estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */
39+
_sstack = _estack - _Min_Stack_Size;
40+
41+
_Min_Heap_Size = 0x200; /* required amount of heap */
42+
_Min_Stack_Size = 0x1600; /* required amount of stack */
43+
44+
/* Memories definition */
45+
MEMORY
46+
{
47+
ROM (xrw) : ORIGIN = 0x70000000, LENGTH = 255K
48+
RAM (xrw) : ORIGIN = 0x341C0000, LENGTH = 256K
49+
}
50+
51+
/* Sections */
52+
SECTIONS
53+
{
54+
55+
.restart_info (NOLOAD) :
56+
{
57+
. = ALIGN(4);
58+
KEEP(*(.restart_info))
59+
. = ALIGN(4);
60+
} >RAM
61+
62+
/* The startup code into "RAM" Ram type memory */
63+
.isr_vector :
64+
{
65+
. = ALIGN(4);
66+
KEEP(*(.isr_vector)) /* Startup code */
67+
. = ALIGN(4);
68+
} >ROM
69+
70+
/* The program code and other data into "RAM" Ram type memory */
71+
.text :
72+
{
73+
. = ALIGN(4);
74+
*(.text) /* .text sections (code) */
75+
*(.text*) /* .text* sections (code) */
76+
*(.glue_7) /* glue arm to thumb code */
77+
*(.glue_7t) /* glue thumb to arm code */
78+
*(.eh_frame)
79+
*(.RamFunc) /* .RamFunc sections */
80+
*(.RamFunc*) /* .RamFunc* sections */
81+
82+
KEEP (*(.init))
83+
KEEP (*(.fini))
84+
85+
. = ALIGN(4);
86+
_etext = .; /* define a global symbols at end of code */
87+
} >ROM
88+
89+
/* Constant data into "RAM" Ram type memory */
90+
.rodata :
91+
{
92+
. = ALIGN(4);
93+
*(.rodata) /* .rodata sections (constants, strings, etc.) */
94+
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
95+
. = ALIGN(4);
96+
} >ROM
97+
98+
.ARM.extab (READONLY) : /* The READONLY keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */
99+
{
100+
. = ALIGN(4);
101+
*(.ARM.extab* .gnu.linkonce.armextab.*)
102+
. = ALIGN(4);
103+
} >ROM
104+
105+
.ARM (READONLY) : /* The READONLY keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */
106+
{
107+
. = ALIGN(4);
108+
__exidx_start = .;
109+
*(.ARM.exidx*)
110+
__exidx_end = .;
111+
. = ALIGN(4);
112+
} >ROM
113+
114+
.preinit_array (READONLY) : /* The READONLY keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */
115+
{
116+
. = ALIGN(4);
117+
PROVIDE_HIDDEN (__preinit_array_start = .);
118+
KEEP (*(.preinit_array*))
119+
PROVIDE_HIDDEN (__preinit_array_end = .);
120+
. = ALIGN(4);
121+
} >ROM
122+
123+
.init_array (READONLY) : /* The READONLY keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */
124+
{
125+
. = ALIGN(4);
126+
PROVIDE_HIDDEN (__init_array_start = .);
127+
KEEP (*(SORT(.init_array.*)))
128+
KEEP (*(.init_array*))
129+
PROVIDE_HIDDEN (__init_array_end = .);
130+
. = ALIGN(4);
131+
} >ROM
132+
133+
.fini_array (READONLY) : /* The READONLY keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */
134+
{
135+
. = ALIGN(4);
136+
PROVIDE_HIDDEN (__fini_array_start = .);
137+
KEEP (*(SORT(.fini_array.*)))
138+
KEEP (*(.fini_array*))
139+
PROVIDE_HIDDEN (__fini_array_end = .);
140+
. = ALIGN(4);
141+
} >ROM
142+
143+
/* Used by the startup to initialize data */
144+
_sidata = LOADADDR(.data);
145+
146+
/* Initialized data sections into "RAM" Ram type memory */
147+
.data :
148+
{
149+
. = ALIGN(4);
150+
_sdata = .; /* create a global symbol at data start */
151+
*(.data) /* .data sections */
152+
*(.data*) /* .data* sections */
153+
154+
. = ALIGN(4);
155+
_edata = .; /* define a global symbol at data end */
156+
157+
} >RAM AT> ROM
158+
159+
.noncacheable :
160+
{
161+
. = ALIGN(8);
162+
__snoncacheable = .;/* create symbol for start of section */
163+
KEEP(*(.noncacheable))
164+
. = ALIGN(8);
165+
__enoncacheable = .; /* create symbol for end of section */
166+
} > RAM
167+
168+
169+
.gnu.sgstubs :
170+
{
171+
. = ALIGN(4);
172+
*(.gnu.sgstubs*) /* Secure Gateway stubs */
173+
. = ALIGN(4);
174+
} >ROM
175+
/* Uninitialized data section into "RAM" Ram type memory */
176+
. = ALIGN(4);
177+
.bss :
178+
{
179+
/* This is used by the startup in order to initialize the .bss section */
180+
_sbss = .; /* define a global symbol at bss start */
181+
__bss_start__ = _sbss;
182+
*(.bss)
183+
*(.bss*)
184+
*(COMMON)
185+
186+
. = ALIGN(4);
187+
_ebss = .; /* define a global symbol at bss end */
188+
__bss_end__ = _ebss;
189+
} >RAM
190+
191+
/* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */
192+
._user_heap_stack :
193+
{
194+
. = ALIGN(8);
195+
PROVIDE ( end = . );
196+
PROVIDE ( _end = . );
197+
. = . + _Min_Heap_Size;
198+
. = . + _Min_Stack_Size;
199+
. = ALIGN(8);
200+
} >RAM
201+
202+
/* Remove information from the compiler libraries */
203+
/DISCARD/ :
204+
{
205+
libc.a ( * )
206+
libm.a ( * )
207+
libgcc.a ( * )
208+
}
209+
210+
.ARM.attributes 0 : { *(.ARM.attributes) }
211+
}

Makefile.common

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ ifeq ($(FLASH),EXTERNAL_FLASH)
5151

5252
C_INCLUDES += \
5353
-IBootloader/STM32/ExtMemManager \
54-
-IMiddlewares/ST/STM32_ExtMem_Manager
54+
-IMiddlewares/ST/STM32_ExtMem_Manager \
55+
-IMiddlewares/ST/STM32_ExtMem_Manager/nor_sfdp
5556
endif
5657

5758
# compile gcc flags

0 commit comments

Comments
 (0)