nuttx/boards/arm
Nathan Hartman 4716fc929d arch/stm32h7 - Fix HEAP clobbering static data in SRAM4
Normally, statically allocated data goes in .bss, followed by the
initial stack, followed by HEAP. However, any data that is statically
allocated in SRAM4 with __attribute__ ((section (".sram4"))) will
clobber, and be clobbered by, the HEAP.

On STM32H7, BDMA can only access SRAM4. Therefore any BDMA buffers (or
any other data) placed in SRAM4 will expose this problem. In one case,
this manifested as a failure of NSH to start, because the SPI6 BDMA
buffers clobbered the /dev/console inode structs, which the OS
allocated earlier.

This PR ensures that only the rest of SRAM4, after any static data, is
added to the heap. This PR also allows SRAM4 to be completely excluded
from the heap by a new Kconfig, CONFIG_STM32H7_SRAM4EXCLUDE, similar
to what CONFIG_STM32H7_DTCMEXCLUDE does for the DTCM region.

Change required in linker scripts:

Every STM32H7 linker script must replace this:

    .sram4 :
    {
    } > sram4

with this:

    .sram4_reserve (NOLOAD) :
    {
        *(.sram4)
        . = ALIGN(4);
        _sram4_heap_start = ABSOLUTE(.);
    } > sram4

or link will fail with: undefined reference to '_sram4_heap_start'.

The Release Notes should document this for users with out-of-tree
boards.

arch/arm/src/stm32h7/Kconfig:

    * Add config STM32H7_SRAM4EXCLUDE to allow excluding all of SRAM4
      from the HEAP.

arch/arm/src/stm32h7/stm32_allocateheap.c:

    * Only when including SRAM4 in the heap, define HAVE_SRAM4,
      SRAM4_START, SRAM4_END, and SRAM4_HEAP_START.

    * Add "Private Data" section.

    * Add extern for_sram4_heap_start, which must be defined in the
      board's linker script.

    * arm_addregion(): Only add SRAM4 to the heap when configured to
      do so, i.e., unless CONFIG_STM32H7_SRAM4EXCLUDE is defined, and
      only add the portion of SRAM4 that is past any static data.

boards/arm/stm32h7/nucleo-h743zi/scripts/flash.ld:
boards/arm/stm32h7/nucleo-h743zi/scripts/kernel.space.ld:
boards/arm/stm32h7/nucleo-h743zi2/scripts/flash.ld:
boards/arm/stm32h7/stm32h747i-disco/scripts/flash.ld:
boards/arm/stm32h7/stm32h747i-disco/scripts/kernel.space.ld:

    * Update all in-tree STM32H7 board linker scripts as described in
      "Change required in linker scripts" above.

Testing:

    * Successfully built all of the following configurations:

      nucleo-h743zi2:jumbo
      nucleo-h743zi2:nsh
      nucleo-h743zi:nxlines_oled
      nucleo-h743zi:elf
      nucleo-h743zi:otg_fs_host
      nucleo-h743zi:nsh
      nucleo-h743zi:netnsh
      nucleo-h743zi:pwm
      stm32h747i-disco:nsh

    * Tested with custom board.

    * nxstyle.

References:

[1] See the dev@nuttx.a.o mailing list discussion started 2021/03/25:
    "How to ensure HEAP will not overlap static DMA buffer?"
    https://lists.apache.org/thread.html/recf2bb9043f8c9f53c10917e2adb2ec64fe35dc5e6f9a695a7ac6ecc%40%3Cdev.nuttx.apache.org%3E

[2] See arm_addregion() in arch/arm/src/stm32h7/stm32_allocateheap.c

Thanks to Gregory Nutt and David Sidrane for suggestions and reviews.
2021-03-30 17:22:46 -03:00
..
a1x/pcduino-a10 boards: nxstyle fixes 2021-03-18 22:58:27 -07:00
am335x/beaglebone-black boards: nxstyle fixes 2021-03-18 22:58:27 -07:00
c5471/c5471evm boards: nxstyle fixes 2021-03-18 22:58:27 -07:00
cxd56xx boards: Remove SCHED_INSTRUMENTATION from all SMP related configs 2021-03-22 19:47:56 -07:00
dm320/ntosd-dm320 boards: nxstyle fixes 2021-03-18 22:58:27 -07:00
efm32 boards: nxstyle fixes 2021-03-18 22:58:27 -07:00
eoss3/quickfeather boards: nxstyle fixes 2021-03-18 22:58:27 -07:00
imx6/sabre-6quad boards: Remove SCHED_INSTRUMENTATION from all SMP related configs 2021-03-22 19:47:56 -07:00
imxrt boards/arm/imxrt: Fix nxstyle warning in imxrt1060-evk/src/imxrt_boot.c 2021-03-23 13:57:31 +01:00
kinetis boards: nxstyle fixes 2021-03-20 19:22:58 -07:00
kl boards: Alan Carvalho de Assis: update licenses to Apache 2021-03-20 19:22:58 -07:00
lc823450/lc823450-xgevk boards: Remove SCHED_INSTRUMENTATION from all SMP related configs 2021-03-22 19:47:56 -07:00
lpc17xx_40xx boards: Refresh configs to add CONFIG_BCH when necessary. 2021-03-23 21:01:56 -03:00
lpc31xx usbhost: Do not disable usb monitor if usb host is enabled but dev is not 2021-03-28 23:34:01 -05:00
lpc43xx boards: Alan Carvalho de Assis: update licenses to Apache 2021-03-20 19:22:58 -07:00
lpc54xx/lpcxpresso-lpc54628 boards: lpc54xx: fix Mixed case identifier error 2021-03-19 23:01:46 -07:00
lpc214x boards: nxstyle fixes 2021-03-18 22:58:27 -07:00
lpc2378/olimex-lpc2378 fs: delete NFILE_DESCRIPTORS for allocating dynamically 2021-03-17 06:46:42 -07:00
max326xx/max32660-evsys boards: nxstyle fixes 2021-03-18 22:58:27 -07:00
moxart/moxa boards: nxstyle fixes 2021-03-18 22:58:27 -07:00
nrf52 boards: nxstyle fixes 2021-03-18 22:58:27 -07:00
nuc1xx/nutiny-nuc120 boards: nxstyle fixes 2021-03-18 22:58:27 -07:00
rp2040 fs: delete NFILE_DESCRIPTORS for allocating dynamically 2021-03-17 06:46:42 -07:00
s32k1xx boards: nxstyle fixes 2021-03-18 22:58:27 -07:00
sam34 usbhost: Do not disable usb monitor if usb host is enabled but dev is not 2021-03-28 23:34:01 -05:00
sama5 boards: sama5: fix Mixed case identifier errors 2021-03-19 23:01:46 -07:00
samd2l2 boards: Alan Carvalho de Assis: update licenses to Apache 2021-03-19 23:01:46 -07:00
samd5e5 arch: arm: sam: fix Mixed Case Errors 2021-03-28 13:34:50 -07:00
samv7 usbhost: Do not disable usb monitor if usb host is enabled but dev is not 2021-03-28 23:34:01 -05:00
stm32 boards/nucleo-f446re: register button 2021-03-30 01:15:23 -05:00
stm32f0l0g0 boards: nxstyle fixes 2021-03-20 19:22:58 -07:00
stm32f7 Integration of pysimCoder with NUTTX 2021-03-29 21:38:58 -03:00
stm32h7 arch/stm32h7 - Fix HEAP clobbering static data in SRAM4 2021-03-30 17:22:46 -03:00
stm32l4 usbhost: Do not disable usb monitor if usb host is enabled but dev is not 2021-03-28 23:34:01 -05:00
stm32l5 boards: nxstyle fixes 2021-03-18 22:58:27 -07:00
str71x/olimex-strp711 boards: nxstyle fixes 2021-03-18 22:58:27 -07:00
tiva boards: Alan Carvalho de Assis: update licenses to Apache 2021-03-20 19:22:58 -07:00
tms570 boards: Alan Carvalho de Assis: update licenses to Apache 2021-03-19 23:01:46 -07:00
xmc4 boards: Alan Carvalho de Assis: update licenses to Apache 2021-03-19 23:01:46 -07:00