-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Description
Describe the bug
To better understand the issues surrounding #99164 and #98866, I created a function that outputs the current MPU region configuration and then compared these. Attached are the outputs of the following MPU configurations:
- mpu_regions_0_mcuboot.txt: Bootloader
- mpu_regions_1_with_mcuboot.txt: Sample with_mcuboot original
- mpu_regions_2_with_mcuboot_ethernet.txt: Sample with_mcuboot with enabled ethernet (like in STM32: H7S3L8 does not boot when networking is enabled #98866)
- mpu_regions_2_with_mcuboot_ethernet_sram2.txt: Sample with_mcuboot with enabled ethernet and sram2
zephyr,memory-attr = <DT_MEM_ARM(ATTR_MPU_RAM)>set in dt (like proposed in STM32H7S78-DK Ethernet support #99164)
The first regions come from mpu_regions.c, then from the nodes with zephyr,memory-attr-property, and the last one is set dynamically and protects some memory (comes from CONFIG_HW_STACK_PROTECTION).
I noticed the following:
-
Output 0 (mcuboot): Region 2 points out that
mcuboot/blob/main/boot/zephyr/boards/nucleo_h7s3l8.conf#L1 sets CONFIG_BOOT_DIRECT_XIP=y. This is the only board in mcuboot's board folder with this configuration set and I think this configuration should not be active for the bootloader.CONFIG_XIPis set for mcuboot also. I think it shouldn't be set, but I don't know where it comes from. However, if we remove this, the MPU region for the internal flash0x0800 0000is not created. It should be created either viazephyr, memory-attrin theflash0-node of the SoC, or inmpu_regions.cas always RO. -
Output 1 (with_mcuboot): Region 2 is the external flash @
0x7000 000with 32MB, but its size is set to the 64k of the internal flash. The entry comes from mpu_regions. c#L23 andI don't understand the reason, sincethis is caused byCONFIG_FLASH_SIZEis set to 32768 (kB) inautoconf.hCONFIG_FLASH_SIZEbeeing set to 0. Not absolutely sure why, but has to do with the size/reg properties of the external flash node. I found out that with the changes from PR boards: st: nucleo_h7s3l8: Introduce App in Ext Flash variant #99647 this is fixed.
But this region gets overlayed by another region, see my point 4 and the code could be removed frommpu_regions. cat all. -
Output 0 / 1: Region 4 (read-only area in flash with unique device ID, ADC calibration data, etc.) is marked as RW in mcuboot, but correctly as RO in the sample. The reason is that CONFIG_MPU_ALLOW_FLASH_WRITE is set in mcuboot.
Would it be better to set (MPU_RASR_C_Msk | REGION_2K | P_RO_U_RO_Msk) here instead of REGION_FLASH_ATTR(REGION_2K)?
Edit: The type should be changed toREGION_IO_ATTR(same as region 1 "PERIPH") and size can be reduced to 512 bytes (see RM0477 table 28 and chapter 5.3.12)
This gets fixed in soc: st: stm32: h7rsxx: Fix MPU region for read-only id flash region #99745 -
Output 1: Region 6 is the external flash @
0x7000 000the correct size of 32MB coming from theproperties likezephyr, memory-attrof the ext_memory-node.zephyr,memory-regionandzephyr,memory-attrare set in the soc and the boards (nucleo_h7s3l8, stm32h7s78_dk) - I think we can remove it from the SoC and have it only in the boards soc (same as with the sram config).
This gets fixed in STM32: Fix h7rs MPU memory type for XSPI external flash #99668 -
Output 2 / 3: This is to show why we disabled sram2 per default to not overlay the ethernet dma memory regions defined earlier. I still don't know why ethernet is working if we do it anyway.
-
Output 0-3: Region 6 is configured as device memory (TEX2 S0 C0 B0) which means unaligned access is not allowed. But this happens quite often. @bklaric1 reported and @mariopaja reported such a behaviour and I get it when not building with
CONFIG_DEBUG_OPTIMIZATIONS=y. In the mem fault prints you can see register values starting with 0x7000xxxx and having an odd LSB most likely pointing to a unaligned memory in the external flash. The external XiP flash should be configured as Normal, Write-back, no write allocate memory (TEX0 S0 C1 B1) which corresponds to<DT_MEM_ARM(ATTR_MPU_FLASH)>.
This gets fixed in STM32: Fix h7rs MPU memory type for XSPI external flash #99668 -
The comment
/* The ATTR_MPU_EXTMEM attribute causing a MPU FAULT */in theext_memory-node of the SoC is definitley correct, becauseATTR_MPU_EXTMEMresults in:STRONGLY_ORDERED_SHAREABLE | size | NO_ACCESS_Mskwhich means to no access at all - whats the purpose of this define?
Regression
- This is a regression.
Steps to reproduce
Use the my branch https://github.com/JB-Lighting/zephyr/tree/jb_mpu_print and apply mcuboot-extra.diff.txt to your mcuboot repo.
This will give you 2 complete MPU region configuration debug prints, one from mcuboot and one frome the chain-loaded application. See the output called from to check if it is coming from mcuboot (0x08000 xxxx) or the app (0x7000 xxxx)
I used the nucleo_h7s3l8 board, but there are only a few changes needed to run it on the stm32h7s78-dk.
Relevant log output
Impact
Functional Limitation – Some features not working as expected, but system usable.
Environment
- OS: Windows
- Toolchain: VScode with Zephyr IDE extension, SDK 17.3
- Zephyr 4.3, see branch url above
Additional Context
No response