Menu

#335 OpenOCD does not recognize POSIX absolute path names on mingw

0.11.0
new
nobody
2022-03-02
2022-02-07
themole
No

OpenOCD seems to misinterpret absolute path names on Windows running with MSYS2 and mingw64.

I also asked for help on stackoverflow, where you could possibly find more details.

Here is the excerpt from the Q&A on Stackoverflow:
I traced down the problem to the point, where the absolute path to the stlink.cfg is somehow misinterpreted. While all command line tools can find the file /c/somepath/RIOT/dist/tools/openocd/adapters/stlink.cfg, openocd does not. OpenOCD is the mingw64 version residing in /mingw64/bin/openocd.

The command in question, executed by RIOTs Makefiles is:

sh -c "openocd \
    -c 'set stlink_version 2;source /c/somepath/RIOT/dist/tools/openocd/adapters/stlink.cfg' \
    -c 'transport select hla_swd' \
    -f '/c/somepath/RIOT/boards/common/stm32/dist/stm32f4.cfg' \
    -c 'tcl_port 0' \
    -c 'telnet_port 0' \
    -c 'gdb_port 0' \
    -c 'init' \
    -c 'targets' \
    -c 'reset halt' \
    -c 'flash write_image erase \"/c/somepath/RIOT/hello_world/bin/stm32f429i-disco/helloworld.elf\" 0 ' \
    -c 'verify_image "/c/somepath/RIOT/hello_world/bin/stm32f429i-disco/helloworld.elf" 0' \
    -c 'reset run' \
    -c 'shutdown'"

and also when I just execute:

openocd -d -c 'set stlink_version 2;source /c/somepath/RIOT/dist/tools/openocd/adapters/stlink.cfg'

Same error occurs:

Open On-Chip Debugger 0.11.0
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
User : 13 2 options.c:63 configuration_output_handler(): debug_level: 3
[...]
User : 24 3 command.c:694 command_run_line(): couldn't read file "/c/somepath/RIOT/dist/tools/openocd/adapters/stlink.cfg": No such file or directory

But when I execute:

openocd -d -c 'set stlink_version 2;source c:/somepath/RIOT/dist/tools/openocd/adapters/stlink.cfg'

it seems to work.

A simple cat /c/somepath/RIOT/dist/tools/openocd/adapters/stlink.cfg shows the correct content of the file, the same when I prepend c:/ instead of /c/.

I tried to dig into openocd's code, but since thissomehow involves the interpreter, there is no chance for me to dig deep enough.

Discussion

  • Tomas Vanek

    Tomas Vanek - 2022-03-02

    The conversion from /c/ to c:/ takes place somewhere in msys2 shell, before passing arguments to main.c
    Of course the shell does not convert the path if it is a part of a complex parameter.
    Neither stat() nor fopen() can use a path starting with /c/ as a disk name.
    https://www.msys2.org/docs/filesystem-paths/

    BTW I suspect you faked the results of your test program shown on stackoverflow

    PS The whole OpenOCD command is horrible and has more issues than useless usage of absolute file paths.
    See https://openocd.org/doc/html/Flash-Programming.html

     
  • themole

    themole - 2022-03-02

    Indeed, I faked the path names of the openOCD command, because the path name contained information, I did not want to show publically. But I did not fake the output of my test program. I edited the code part, pasted the output of the new version below the old one and marked it as "Edit 2"

     

Log in to post a comment.

Monday.com Logo