Skip to content

Commit 0d7be0f

Browse files
dgarskedanielinux
authored andcommitted
Improve SRAM partitioning for Ethernet DMA
1 parent 56a6b60 commit 0d7be0f

3 files changed

Lines changed: 37 additions & 8 deletions

File tree

src/port/stm32/stm32_eth.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,14 @@ struct eth_desc {
207207
#if defined(STM32H7) || defined(STM32N6)
208208
#define ETH_SECTION __attribute__((section(".eth_buffers")))
209209
#elif defined(STM32H5)
210-
/* H5 places ETH descriptors and buffers in the regular .bss region.
211-
* Both TZEN=0 (TrustZone disabled) and TZEN=1 (NS app under wolfBoot)
212-
* link RAM into a single NS-accessible region; no separate ETHMEM
213-
* alias is needed since the CPU and ETH DMA both run in NS world and
214-
* share the same NS view of physical SRAM. */
215-
#define ETH_SECTION
210+
/* H5 pins ETH descriptors and buffers into the .eth_buffers section.
211+
* Under TZEN=1, wolfBoot keeps SRAM3 non-secure but PRIVILEGED and
212+
* cedes SRAM2 as non-secure + UNPRIVILEGED. The H5 ETH DMA master is
213+
* unprivileged, so its descriptors/buffers must live in SRAM2; the
214+
* linker script places .eth_buffers at the base of NS RAM (SRAM2 at
215+
* 0x20040000). The same macro is used for TZEN=0, which has no
216+
* privilege constraint but maps .eth_buffers the same way. */
217+
#define ETH_SECTION __attribute__((section(".eth_buffers")))
216218
#endif
217219

218220
/* DMA descriptor / buffer addresses are taken as-is. NS pointers map

src/port/stm32h563/target.ld

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,17 @@ SECTIONS
6464
__fini_array_end = .;
6565
} > FLASH
6666

67+
/* ETH DMA arena. TrustZone is disabled here so there is no privilege
68+
* constraint, but stm32_eth.c emits descriptors/buffers into the
69+
* named .eth_buffers section for all STM32H5 builds, so give it an
70+
* explicit home in RAM. */
71+
.eth_buffers (NOLOAD) :
72+
{
73+
. = ALIGN(32);
74+
KEEP(*(.eth_buffers))
75+
. = ALIGN(32);
76+
} > RAM
77+
6778
.data :
6879
{
6980
. = ALIGN(4);

src/port/stm32h563/target_tzen.ld

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@
1111
* RAM: wolfBoot (patched hal_gtzc_init / hal_tz_sau_init) keeps SRAM1
1212
* secure for its own use and cedes SRAM2 + SRAM3 to NS:
1313
* NS RAM: 0x20040000 .. 0x2009FFFF (384 KB, SRAM2 + SRAM3)
14+
* SRAM2 (0x20040000, 64 KB) is non-secure + UNPRIVILEGED; SRAM3
15+
* (0x20050000, 320 KB) is non-secure + PRIVILEGED. The .eth_buffers
16+
* section is placed first so the ETH DMA descriptors/buffers land in
17+
* SRAM2: the H5 ETH DMA master is unprivileged and can only reach the
18+
* unprivileged window. The privileged NS CPU uses the rest of RAM.
1419
*
1520
* The NS app runs in Non-Secure world; plain LDR/STR carry HNONSEC=1,
1621
* matching the H5 product-default NS attribution for the ETH peripheral
17-
* and DMA. ETH descriptors and buffers live in the same NS RAM region
18-
* as everything else -- no separate ETHMEM alias is needed.
22+
* and DMA.
1923
*/
2024

2125
MEMORY
@@ -78,6 +82,18 @@ SECTIONS
7882
__fini_array_end = .;
7983
} > FLASH
8084

85+
/* ETH DMA arena: placed first in RAM (RAM ORIGIN = 0x20040000 =
86+
* SRAM2 base) so descriptors/buffers stay in the unprivileged SRAM2
87+
* window reachable by the unprivileged ETH DMA master. NOLOAD: no
88+
* FLASH load image, so LOADADDR(.data) below is unaffected. */
89+
.eth_buffers (NOLOAD) :
90+
{
91+
. = ALIGN(32);
92+
KEEP(*(.eth_buffers))
93+
. = ALIGN(32);
94+
} > RAM
95+
ASSERT(. <= 0x20050000, ".eth_buffers must fit within SRAM2 (0x20040000-0x2004FFFF)")
96+
8197
.data :
8298
{
8399
. = ALIGN(4);

0 commit comments

Comments
 (0)