Skip to content

tools/openocd: check if variable for extra reset_config is set#12157

Merged
fjmolinas merged 1 commit intoRIOT-OS:masterfrom
aabadie:pr/tools/openocd_default_connect_assert_srst_val
Sep 3, 2019
Merged

tools/openocd: check if variable for extra reset_config is set#12157
fjmolinas merged 1 commit intoRIOT-OS:masterfrom
aabadie:pr/tools/openocd_default_connect_assert_srst_val

Conversation

@aabadie
Copy link
Contributor

@aabadie aabadie commented Sep 3, 2019

Contribution description

This PR fixes a warning message raised by OpenOCD when flashing without OPENOCD_RESET_USE_CONNECT_ASSERT_SRST = 1 so on almost all boards flashed by OpenOCD except nucleo-f091rc.
The message is: openocd.sh: line 124: [: : integer expression expected

The fix is simply to also check if the variable is set.

Another solution could be to assign a default value of 0, e.g. here. I don't know what's best.

Testing procedure

  • Use OpenOCD to flash a board other than nucleo-f091. With this PR the mentioned warning message is not displayed.

Issues/PRs references

Cleanup of #11976

@aabadie aabadie added the Area: tools Area: Supplementary tools label Sep 3, 2019
@aabadie aabadie requested a review from fjmolinas September 3, 2019 06:22
@aabadie aabadie added the Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation label Sep 3, 2019
@fjmolinas
Copy link
Contributor

Tested this fixes the issue

master:

   text    data     bss     dec     hex filename
   8428     120    2568   11116    2b6c /home/francisco/workspace/RIOT/examples/hello-world/bin/iotlab-m3/hello-world.elf
/home/francisco/workspace/RIOT/dist/tools/openocd/openocd.sh flash /home/francisco/workspace/RIOT/examples/hello-world/bin/iotlab-m3/hello-world.elf
/home/francisco/workspace/RIOT/dist/tools/openocd/openocd.sh: line 124: [: : integer expression expected
### Flashing Target ###

PR

/home/francisco/workspace/RIOT/dist/tools/openocd/openocd.sh flash /home/francisco/workspace/RIOT/examples/hello-world/bin/iotlab-m3/hello-world.elf
### Flashing Target ###
Open On-Chip Debugger 0.10.0+dev-00703-g92bb76a4-dirty (2019-07-19-14:27)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "jtag". To override use 'transport select <transport>'.
adapter speed: 1000 kHz
adapter_nsrst_delay: 100

@fjmolinas fjmolinas added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines Reviewed: 3-testing The PR was tested according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines Reviewed: 5-documentation The documentation details of the PR were reviewed according to the maintainer guidelines and removed Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines labels Sep 3, 2019
@fjmolinas
Copy link
Contributor

Another solution could be to assign a default value of 0, e.g. here. I don't know what's best.

I don't have an argument against or in favor of any of the solutions. @cladmi do you have a preference?

@aabadie aabadie changed the title tools/openocd: check if to variable for extra reset_config is set tools/openocd: check if variable for extra reset_config is set Sep 3, 2019
@cladmi
Copy link
Contributor

cladmi commented Sep 3, 2019

Good catch.

We do not need to check for it being an integer, matching to a string also works and would remove the warning on an empty value:

diff --git a/dist/tools/openocd/openocd.sh b/dist/tools/openocd/openocd.sh
index 3a73038e0..e6776bbee 100755
--- a/dist/tools/openocd/openocd.sh
+++ b/dist/tools/openocd/openocd.sh
@@ -121,8 +121,7 @@
 # The single quotes are important on the line above, or it will not work.

 # Handle OPENOCD_RESET_USE_CONNECT_ASSERT_SRST
-if ([ ! -z "${OPENOCD_RESET_USE_CONNECT_ASSERT_SRST}" ] && \
-    [ "${OPENOCD_RESET_USE_CONNECT_ASSERT_SRST}" -eq 1 ]); then
+if [ "${OPENOCD_RESET_USE_CONNECT_ASSERT_SRST}" = "1" ]; then
   OPENOCD_EXTRA_RESET_INIT+="-c 'reset_config connect_assert_srst'"
 fi

This avoids the following warning message when running OpenOCD: 'openocd.sh: line 124: [: : integer expression expected'
@aabadie aabadie force-pushed the pr/tools/openocd_default_connect_assert_srst_val branch from 99d155d to 9065f83 Compare September 3, 2019 10:44
@aabadie
Copy link
Contributor Author

aabadie commented Sep 3, 2019

matching to a string also works and would remove the warning on an empty value

Indeed much better solution! I amended the commit with it.

@cladmi
Copy link
Contributor

cladmi commented Sep 3, 2019

Good, it works without warning:

nucleo-f091rc still uses connect_assert_srst
BOARD=nucleo-f091rc RIOT_CI_BUILD=1 make --no-print-directory -C examples/hello-world/ flash
Building application "hello-world" for "nucleo-f091rc" with MCU "stm32f0".

   text    data     bss     dec     hex filename
   8176     120    2568   10864    2a70 /home/harter/work/git/RIOT/examples/hello-world/bin/nucleo-f091rc/hello-world.elf
/home/harter/work/git/RIOT/dist/tools/openocd/openocd.sh flash /home/harter/work/git/RIOT/examples/hello-world/bin/nucleo-f091rc/hello-world.elf
### Flashing Target ###
GNU MCU Eclipse 64-bit Open On-Chip Debugger 0.10.0+dev-00462-gdd1d90111 (2019-01-18-11:37)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
WARNING: interface/stlink-v2-1.cfg is deprecated, please switch to interface/stlink.cfg
hla_swd
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
adapter speed: 1000 kHz
adapter_nsrst_delay: 100
none separate
srst_only separate srst_nogate srst_open_drain connect_deassert_srst
srst_only separate srst_nogate srst_open_drain connect_assert_srst
Info : clock speed 1000 kHz
Error: open failed


/home/harter/work/git/RIOT/examples/hello-world/../../Makefile.include:556: recipe for target 'flash' failed
make: *** [flash] Error 1
No warning on other boards, like `iotlab-m3`
BOARD=iotlab-m3 RIOT_CI_BUILD=1 make --no-print-directory -C examples/hello-world/ flash
Building application "hello-world" for "iotlab-m3" with MCU "stm32f1".

   text    data     bss     dec     hex filename
   8168     120    2556   10844    2a5c /home/harter/work/git/RIOT/examples/hello-world/bin/iotlab-m3/hello-world.elf
/home/harter/work/git/RIOT/dist/tools/openocd/openocd.sh flash /home/harter/work/git/RIOT/examples/hello-world/bin/iotlab-m3/hello-world.elf
### Flashing Target ###
GNU MCU Eclipse 64-bit Open On-Chip Debugger 0.10.0+dev-00462-gdd1d90111 (2019-01-18-11:37)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "jtag". To override use 'transport select <transport>'.
adapter speed: 1000 kHz
adapter_nsrst_delay: 100
jtag_ntrst_delay: 100
none separate
cortex_m reset_config sysresetreq
trst_and_srst separate srst_nogate trst_push_pull srst_open_drain connect_assert_srst
Error: no device found
Error: unable to open ftdi device with vid 0403, pid 6010, description '*', serial '*' at bus location '*'

/home/harter/work/git/RIOT/examples/hello-world/../../Makefile.include:556: recipe for target 'flash' failed
make: *** [flash] Error 1

@cladmi
Copy link
Contributor

cladmi commented Sep 3, 2019

And using `OPENOCD_RESET_USE_CONNECT_ASSERT_SRST=0` still disables using `connect_assert_srst` on `nucleo-f091rc`
OPENOCD_RESET_USE_CONNECT_ASSERT_SRST=0 BOARD=nucleo-f091rc RIOT_CI_BUILD=1 make --no-print-directory -C examples/hello-world/ flash
Building application "hello-world" for "nucleo-f091rc" with MCU "stm32f0".

   text    data     bss     dec     hex filename
   8176     120    2568   10864    2a70 /home/harter/work/git/RIOT/examples/hello-world/bin/nucleo-f091rc/hello-world.elf
/home/harter/work/git/RIOT/dist/tools/openocd/openocd.sh flash /home/harter/work/git/RIOT/examples/hello-world/bin/nucleo-f091rc/hello-world.elf
### Flashing Target ###
GNU MCU Eclipse 64-bit Open On-Chip Debugger 0.10.0+dev-00462-gdd1d90111 (2019-01-18-11:37)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
WARNING: interface/stlink-v2-1.cfg is deprecated, please switch to interface/stlink.cfg
hla_swd
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
adapter speed: 1000 kHz
adapter_nsrst_delay: 100
none separate
srst_only separate srst_nogate srst_open_drain connect_deassert_srst
Info : clock speed 1000 kHz
Error: open failed


/home/harter/work/git/RIOT/examples/hello-world/../../Makefile.include:556: recipe for target 'flash' failed
make: *** [flash] Error 1

@fjmolinas fjmolinas added the Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines label Sep 3, 2019
Copy link
Contributor

@fjmolinas fjmolinas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reproduced the testing procedure described, same result as before. ACK!

@fjmolinas fjmolinas merged commit 0bf2be4 into RIOT-OS:master Sep 3, 2019
@aabadie aabadie deleted the pr/tools/openocd_default_connect_assert_srst_val branch September 3, 2019 19:46
@kb2ma kb2ma added this to the Release 2019.10 milestone Sep 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: tools Area: Supplementary tools CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines Reviewed: 3-testing The PR was tested according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines Reviewed: 5-documentation The documentation details of the PR were reviewed according to the maintainer guidelines Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants