zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
10.36k stars 6.34k forks source link

Endless loop at startup for not optimized application started by bootloader #69789

Open GeorgeCGV opened 5 months ago

GeorgeCGV commented 5 months ago

Describe the bug The application freezes in an endless loop when the bootloader starts it.

The Zephyr calls z_arm_init_arch_hw_at_boot after the bootloader jumps to the application. It detects the enabled D-Cache and tries to disable it. That performs a call to SCB_DisableDCache that stucks in an endless loop.

The issue is related to https://github.com/ARM-software/CMSIS_5/issues/620. I confirm that applying https://github.com/ARM-software/CMSIS_5/pull/1426 to https://github.com/zephyrproject-rtos/cmsis fixes the problem.

The patch requires an addition:

#ifdef CONFIG_NO_OPTIMIZATIONS
#undef __OPTIMIZE__
#endif

Currently, Zephyr uses CMSISv5. The upstream fixes the issue in the develop branch that is not released (v5.9.0 won't fix the problem), and in CMSISv6 (not used).

It would be great to mention the issue in the docs.

To Reproduce

1 Build and flash bootloader with enabled D-Cache and I-Cache (CONFIG_CACHE_MANAGEMENT=y).

  1. Build and flash application with enabled D-Cache and I-Cache (CONFIG_CACHE_MANAGEMENT=y) and
    CONFIG_DEBUG=y
    CONFIG_NO_OPTIMIZATIONS=y

Expected behavior An application shall start.

Impact It might be a showstopper. Developers must be aware of the issue. Otherwise, they risk bricking their devices after an application update.

Environment (please complete the following information):

github-actions[bot] commented 3 months ago

This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time.

GeorgeCGV commented 3 months ago

Reproduction steps change after #1922:

Approach 1

The CONFIG_BOOT_DISABLE_CACHES must be set to n, then follow the "To Reproduce" steps from above.

Approach 2

Build and run the bootloader with CONFIG_NO_OPTIMIZATIONS and CONFIG_DEBUG if CONFIG_BOOT_DISABLE_CACHES is enabled to trigger the issue in the bootloader.

snalvc commented 3 months ago

This also happens in my setup. Board: sam_v71_xult (I detached onboard Xplained Pro board debugger and replaced it w/ picoprobe) App: samples/hello_world Toolchain: zephyr-sdk-0.16.5-1 Zephyr commit SHA: 0a8d03b95f prj.conf:

CONFIG_DEBUG=y
CONFIG_DEBUG_INFO=y
CONFIG_NO_OPTIMIZATIONS=y
CONFIG_CACHE_MANAGEMENT=y

Confirmed applying ARM-software/CMSIS_5#1426 to cachel1_armv7.h solves the problem

github-actions[bot] commented 3 weeks ago

This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time.