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.17k stars 6.23k forks source link

runners:jlink: fail to flash board with protected sector when erase requested #40201

Closed Zzzwierzak closed 2 years ago

Zzzwierzak commented 2 years ago

Describe the bug After change #39734 it is not possible to flash board with protected memory area. When erase of board is requested in jlink runner args, protection of memory cause error during mass erase and flash procedure stops. Issue is visible on stm32wb55 when part of memory that is used by second core is protected against erase.

To Reproduce Try to flash board with part of memory configured as protected with erase option enabled for jlink runner. board_runner_args(jlink "--device=STM32WB55xx" "--speed=4000" "--reset-after-load" "--erase")

Expected behavior Board flashed successfully.

Environment (please complete the following information):)

Log J-Link>connect Device "STM32WB55XX" selected.

Connecting to target via SWD Found SW-DP with ID 0x6BA02477 DPIDR: 0x6BA02477 Scanning AP map to find all available APs AP[2]: Stopped AP scan as end of AP map has been reached AP[0]: AHB-AP (IDR: 0x24770011) AP[1]: AHB-AP (IDR: 0x84770001) Iterating through AP map to find AHB-AP to use AP[0]: Core found AP[0]: AHB-AP ROM base: 0xE00FF000 CPUID register: 0x410FC241. Implementer code: 0x41 (ARM) Found Cortex-M4 r0p1, Little endian. FPUnit: 6 code (BP) slots and 2 literal slots CoreSight components: ROMTbl[0] @ E00FF000 ROMTbl[0][0]: E000E000, CID: B105E00D, PID: 000BB00C SCS-M7 ROMTbl[0][1]: E0001000, CID: B105E00D, PID: 003BB002 DWT ROMTbl[0][2]: E0002000, CID: B105E00D, PID: 002BB003 FPB ROMTbl[0][3]: E0000000, CID: B105E00D, PID: 003BB001 ITM ROMTbl[0][4]: E0040000, CID: B105900D, PID: 000BB9A1 TPIU ROMTbl[0][5]: E0041000, CID: B105900D, PID: 000BB925 ETM ROMTbl[0][6]: E0043000, CID: B105900D, PID: 005BB906 CTI SetupTarget() start WARNING: Secure Firmware detected @ 0x080CA000 Connecting to target AP[0]/Cortex-M4 CORE ID AP[0]:0x410FC241 CORE ID AP[0]/Cortex-M4 halted! SetupTarget() end Cortex-M4 identified. J-Link>erase Erasing device... Comparing flash [100%] Done. Erasing flash [100%] Done.

** Error: Failed to erase chip @ address 0x08000000 (sector is locked) Failed to erase chip. Failed to execute RAMCode for chip erase! J-Link: Flash download: Total time needed: 4.494s (Prepare: 0.025s, Compare: 0.000s, Erase: 4.461s, Program: 0.000s, Verify: 0.000s, Restore: 0.007s) ERROR: Erase returned with error code -5. J-Link>

carlescufi commented 2 years ago

@bbilas @JordanYates FYI

bbilas commented 2 years ago

Please revert this commit and put the log without this change + return code of the flash command. Basically that change shouldn't have an impact on that.

cfriedt commented 2 years ago

@bbilas - can you send a PR to fix?

bbilas commented 2 years ago

@cfriedt I don't have such hardware to reproduce that error so I'll try to use MIMXRT1060-EVK with JLink BASE instead. Any information related to it would be appreciated.

github-actions[bot] commented 2 years 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.

erwango commented 2 years ago

@bbilas Did you had a chance to make some progress on this ?

bbilas commented 2 years ago

No, I didn't. It seems that I need that HW to be able to reproduce that issue but I'm lacking that.

Zzzwierzak commented 2 years ago

@bbilas, @erwango I've checked on 25e6803705b25602eb0b730a03a254c354bfae9e and issue still exist.

erwango commented 2 years ago

@Zzzwierzak Would you mind a try to provide what was suggested in https://github.com/zephyrproject-rtos/zephyr/issues/40201#issuecomment-964219844 ?

erwango commented 2 years ago

My 2 cents on this issue:

Based on this, I don't think that present behavior is an actual issue. There are 2 options:

Zzzwierzak commented 2 years ago

@erwango Output from Jlink without change is same( Error -5), but error from erase is discarded silently, after change it is breaking west flash in CI, that cause test fail with flash error. Unfortunately testing without erase is not stable, and using STM32CubeProgrammer is not possible.

erwango commented 2 years ago

@erwango Output from Jlink without change is same( Error -5), but error from erase is discarded silently, after change it is breaking west flash in CI, that cause test fail with flash error.

I understand the problem on your side, but this doesn't sounds like an actual issue as returning an error on erase error is a sound behavior. Support for your use case would likely require an enhancement :

Zzzwierzak commented 2 years ago

@erwango Both options are good for me.

bbilas commented 2 years ago

@erwango Output from Jlink without change is same( Error -5), but error from erase is discarded silently, after change it is breaking west flash in CI, that cause test fail with flash error.

I understand the problem on your side, but this doesn't sounds like an actual issue as returning an error on erase error is a sound behavior. Support for your use case would likely require an enhancement :

* add support for sector erase

* add option not to fail on erase issue

Support for sector erasing is the most suitable solution in my opinion only if it's supported by jlink.

bbilas commented 2 years ago

@Zzzwierzak Would you mind testing this https://github.com/zephyrproject-rtos/zephyr/pull/42144 MR? It introduces erasing specified flash range but due to lack of hardware, I'm not able to test it.

Example: west flash -d build --erase-range 0x60000000 0x607FFFFF

Zzzwierzak commented 2 years ago

@bbilas Yes, it's working with stm32wb55.

bbilas commented 2 years ago

I guess we can close it?

Zzzwierzak commented 2 years ago

@bbilas Yes.

bbilas commented 2 years ago

@Zzzwierzak I don't have any permission to manage this issue, so could you do that as the author?