Comments (6)
I might have found the issue.
readelf -Wl
for SAMV71 blink example:
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
LOAD 0x010000 0x00400000 0x00400000 0x01148 0x01148 RWE 0x10000
LOAD 0x020c00 0x20400c00 0x00401148 0x0000c 0x0000c RW 0x10000
LOAD 0x021154 0x00401154 0x00401154 0x00044 0x00044 RW 0x10000
LOAD 0x000c0c 0x20400c0c 0x00401154 0x00000 0x00108 RW 0x10000
LOAD 0x000d14 0x20400d14 0x00401154 0x00000 0x5f2ec RW 0x10000
LOAD 0x000000 0x20400000 0x20400000 0x00000 0x00c00 RW 0x10000
NOTE 0x010168 0x00400168 0x00400168 0x00024 0x00024 R 0x4
Section to Segment mapping:
Segment Sections...
00 .text .build_id .text .rodata
01 .data .fastdata
02 .rodata
03 .bss
04 .noinit .heap_ram
05 .stack
06 .build_id
.bss
has PhysAddr
of 0x00401154
which is in flash and also the start address of .rodata
. That makes no sense. The .bss
section should be in RAM only.
The change in openocd @rleh linked removes the code that ignores sections with zero file size (like .bss
) when loading flash sections from the elf file. Now openocd tries to load .bss
into flash.
.noinit
and .heap_ram
have similar issues.
When I move the .rodata
tables section before .bss
in the generated linker script the result looks more reasonable:
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
LOAD 0x010000 0x00400000 0x00400000 0x01148 0x01148 RWE 0x10000
LOAD 0x020c00 0x20400c00 0x00401148 0x0000c 0x0000c RW 0x10000
LOAD 0x021154 0x00401154 0x00401154 0x00044 0x00044 RW 0x10000
LOAD 0x000000 0x20400000 0x20400000 0x00000 0x60000 RW 0x10000
NOTE 0x010168 0x00400168 0x00400168 0x00024 0x00024 R 0x4
Section to Segment mapping:
Segment Sections...
00 .text .build_id .text .rodata
01 .data .fastdata
02 .rodata
03 .stack .bss .noinit .heap_ram
04 .build_id
from modm.
Interesting! It may be interesting to use pyelftools to write a test that actually validates the assumptions we make about our linkerscripts. Sections of certain naming schemes in the right place, alignment properties fulfilled, correct order of sections. We've had a number of these bugs already. I guess I'll put it on my TODO list…
from modm.
I have tried to fix the openocd programming issue with the development build but I suspect that the openocd development branch is currently broken. Even if all the addresses in the ELF file are correct it tries to program the NOLOAD sections which are correctly marked NOBITS
.
xPSR: 0x01000000 pc: 0x00400820 msp: 0x20400c00
** Programming Started **
Info : device id = 0xa1220e01
Info : erasing lock regions 0-0...
Info : erasing lock region 0
Warn : no flash bank found for address 0x20400000
** Programming Finished **
** Verify Started **
Error: checksum mismatch - attempting binary compare
Error: error reading data: (null)
Error: CMSIS-DAP command mismatch. Expected 0x6 received 0x5
Error: CMSIS-DAP command mismatch. Expected 0x5 received 0x6
Error: CMSIS-DAP command mismatch. Expected 0x6 received 0x5
Error: CMSIS-DAP command mismatch. Sent 0x3 received 0x6
Error: CMSIS-DAP command CMD_DISCONNECT failed.
Info : SWD DPIDR 0x0bd11477
Error: Failed to read memory at 0x20441f8c
embedded:startup.tcl:1510: Error: ** Verify Failed **
It skips programming the RAM sections with a warning because it knows there is no flash at these addresses but verification fails afterwards for the RAM sections.
EDIT: There must be something else wrong. I have found some other ELF files that work, but the one generated by the Rust toolchain also outputs Warn : no flash bank found for address 0x20000008
.
from modm.
I can confirm this bug for STM32G4 and SAMV71; and it's probably related to modm because programming *.elf
files produced from the stm32-rs framework work fine with the recent OpenOCD versions.
Details SAMV71
Linking········ /home/user/modm/build/samv71_xplained_ultra/blink/scons-release/blink.elf
╭────────────── /home/user/modm/build/samv71_xplained_ultra/blink/scons-release/blink.elf
╰───OpenOCD───> samv71q21b-aab
Open On-Chip Debugger 0.12.0+dev-snapshot (2023-03-26-22:51)
[...]
Info : [...]
Info : Listening on port 3333 for gdb connections
[samv71.cpu] halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x004019d0 msp: 0x20400c00
** Programming Started **
Info : device id = 0xa1220e01
Error: Section at 0x00401218 overlaps section ending at 0x0040125c
Error: Flash write aborted.
embedded:startup.tcl:1510: Error: ** Programming Failed **
in procedure 'modm_program'
in procedure 'program' called at file "/home/user/modm/examples/samv71_xplained_ultra/blink/modm/openocd.cfg", line 13
in procedure 'program_error' called at file "embedded:startup.tcl", line 1575
at file "embedded:startup.tcl", line 1510
scons: done building targets.
Details STM32G474 Rust-Toolchain
[rleh@rleh-pc stm32g4xx-hal]$ #cargo build --example blinky --features stm32g474
[rleh@rleh-pc stm32g4xx-hal]$ openocd -f interface/stlink.cfg -c "transport select hla_swd" -f target/stm32g4x.cfg -c "program target/thumbv7em-none-eabihf/debug/examples/blinky" -c "reset run" -c "exit"
Open On-Chip Debugger 0.12.0+dev-snapshot (2023-03-26-22:51)
[...]
Info: [...]
[stm32g4x.cpu] halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x080001d8 msp: 0x20008000
** Programming Started **
Info : device idcode = 0x20016469 (STM32G47/G48xx - Rev Z : 0x2001)
Info : RDP level 0 (0xAA)
Info : flash size = 512 KiB
Info : flash mode : dual-bank
Info : Padding image section 1 at 0x08001cec with 4 bytes
Warn : Adding extra erase range, 0x080022a8 .. 0x080027ff
Info : device idcode = 0x20016469 (STM32G47/G48xx - Rev Z : 0x2001)
Info : RDP level 0 (0xAA)
Info : OTP size is 1024 bytes, base address is 0x1fff7000
Warn : no flash bank found for address 0x20000008
** Programming Finished **
[...]
from modm.
The error does not depend on the GCC version, I can reproduce it with GCC10 and GCC12 (ARM and xPack variants).
The code section in OpenOCD that emits the error has not been touched in the last 5 years: https://github.com/openocd-org/openocd/blob/b6b4f9d46a48aadc1de6bb5152ff4913661c9059/src/flash/nor/core.c#L806-L818
I assume change 7513 (target/image: zero-initialize ELF segments up to p_memsz) in OpenOCD causes our issue.
from modm.
It must be an issue with our linkerscript, I just remembered that this sounded familiar: #922
from modm.
Related Issues (20)
- STM32F469I-DISCO display does not work on newer board revision (B-08) HOT 1
- [math] math::Matrix class size limitation HOT 1
- [math] MovingAverage with long history HOT 1
- STM32G4: modm interface hides some of Timer features HOT 3
- Resumable functions don't compile with gcc13 HOT 1
- Unittest failing fdcan_test on Nucleo-G474RE
- monochrome graphic display won't compile - vector ? HOT 4
- [fiber] multi stack size ? HOT 5
- SAMD51/SAME5x cache not enabled? HOT 5
- STM32G0B1 currently black listed HOT 2
- Disabling PLL on STM32 HOT 1
- STM32: I2C peripheral is not reset HOT 3
- stm32-extended I²C driver NACK handling broken
- macOS arm-gcc-bin@12 from osx-cross failes HOT 3
- [stm32] Interrupt handler indirection causes unnecessary latency HOT 1
- STM32F103 PB4 not accessible / remapping not part of modm HOT 3
- Debugger (arm-none-eabi-gdb) not working on up-to-date linux systems HOT 6
- Problem with SPI Mode 3 on STM32F469 HOT 3
- Update Website Installation Guide HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from modm.