Skip to content

jlink.sh: Exit with an error on failure for JLinkExe commands#11303

Merged
miri64 merged 1 commit intoRIOT-OS:masterfrom
cladmi:pr/jlink/failonerror
Mar 28, 2019
Merged

jlink.sh: Exit with an error on failure for JLinkExe commands#11303
miri64 merged 1 commit intoRIOT-OS:masterfrom
cladmi:pr/jlink/failonerror

Conversation

@cladmi
Copy link
Copy Markdown
Contributor

@cladmi cladmi commented Mar 28, 2019

Contribution description

On error Jlink exits with a no error code by default.

From the JLink User Guide:

'-ExitOnError' has the same meaning as the 'exitonerror' command

'exitonerror' command
This command toggles whether J-Link Commander exits on error or not.

1: J-Link Commander will now exit on Error.
0: J-Link Commander will no longer exit on Error.

Executing 'flash/reset' without a board connected now correctly returns an
error. For 'term' it does not show an error due to the way it is handled
internally.

It also returns an error when the board fails to do an operation when it
is in a state where it cannot be flashed for example.

Testing procedure without board

Without a board connected run flash and reset for a board using jlink, it now fails correctly:

BOARD=nrf52dk make --no-print-directory -C examples/hello-world/ reset  && echo NO ERROR || echo ERROR
/home/harter/work/git/RIOT/dist/tools/jlink/jlink.sh reset
### Resetting Target ###
SEGGER J-Link Commander V6.42d (Compiled Feb 15 2019 13:56:53)
DLL version V6.42d, compiled Feb 15 2019 13:56:43

J-Link Commander will now exit on Error

J-Link Command File read successfully.
Processing script file...

J-Link connection not established yet but required for command.
Connecting to J-Link via USB...FAILED: Cannot connect to J-Link via USB.

Script processing completed.

/home/harter/work/git/RIOT/examples/hello-world/../../Makefile.include:569: recipe for target 'reset' failed
make: *** [reset] Error 1
ERROR
RIOT_CI_BUILD=1 BOARD=nrf52dk make --no-print-directory -C examples/hello-world/ flash && echo NO ERROR || echo ERROR
Building application "hello-world" for "nrf52dk" with MCU "nrf52".

   text    data     bss     dec     hex filename
   8048     136    2604   10788    2a24 /home/harter/work/git/RIOT/examples/hello-world/bin/nrf52dk/hello-world.elf
/home/harter/work/git/RIOT/dist/tools/jlink/jlink.sh flash /home/harter/work/git/RIOT/examples/hello-world/bin/nrf52dk/hello-world.bin
### Flashing Target ###
### Flashing at base address 0x0 with offset 0 ###
SEGGER J-Link Commander V6.42d (Compiled Feb 15 2019 13:56:53)
DLL version V6.42d, compiled Feb 15 2019 13:56:43

J-Link Commander will now exit on Error

J-Link Command File read successfully.
Processing script file...

J-Link connection not established yet but required for command.
Connecting to J-Link via USB...FAILED: Cannot connect to J-Link via USB.

Script processing completed.

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

In master it was not reporting any error:

BOARD=nrf52dk make --no-print-directory -C examples/hello-world/ reset  && echo NO ERROR || echo ERROR
/home/harter/work/git/RIOT/dist/tools/jlink/jlink.sh reset
### Resetting Target ###
SEGGER J-Link Commander V6.42d (Compiled Feb 15 2019 13:56:53)
DLL version V6.42d, compiled Feb 15 2019 13:56:43


J-Link Command File read successfully.
Processing script file...

J-Link connection not established yet but required for command.
Connecting to J-Link via USB...FAILED: Cannot connect to J-Link via USB.

J-Link connection not established yet but required for command.
Connecting to J-Link via USB...FAILED: Cannot connect to J-Link via USB.


Script processing completed.

NO ERROR
RIOT_CI_BUILD=1 BOARD=nrf52dk make --no-print-directory -C examples/hello-world/ flash && echo NO ERROR || echo ERROR
Building application "hello-world" for "nrf52dk" with MCU "nrf52".

   text    data     bss     dec     hex filename
   8048     136    2604   10788    2a24 /home/harter/work/git/RIOT/examples/hello-world/bin/nrf52dk/hello-world.elf
/home/harter/work/git/RIOT/dist/tools/jlink/jlink.sh flash /home/harter/work/git/RIOT/examples/hello-world/bin/nrf52dk/hello-world.bin
### Flashing Target ###
### Flashing at base address 0x0 with offset 0 ###
SEGGER J-Link Commander V6.42d (Compiled Feb 15 2019 13:56:53)
DLL version V6.42d, compiled Feb 15 2019 13:56:43


J-Link Command File read successfully.
Processing script file...

J-Link connection not established yet but required for command.
Connecting to J-Link via USB...FAILED: Cannot connect to J-Link via USB.

J-Link connection not established yet but required for command.
Connecting to J-Link via USB...FAILED: Cannot connect to J-Link via USB.

J-Link connection not established yet but required for command.
Connecting to J-Link via USB...FAILED: Cannot connect to J-Link via USB.


Script processing completed.

NO ERROR

Checking term-rtt:

Term still does not return any error on failure but at least it is put in the right mode:

With this diff:

diff --git a/dist/tools/jlink/jlink.sh b/dist/tools/jlink/jlink.sh
index 4c463b46d..cea7c90d1 100755
--- a/dist/tools/jlink/jlink.sh
+++ b/dist/tools/jlink/jlink.sh
@@ -252,7 +252,7 @@ do_term() {
             -speed '${JLINK_SPEED}' \
             -if '${JLINK_IF}' \
             -jtagconf -1,-1 \
-            -commandfile '${RIOTTOOLS}/jlink/term.seg' >/dev/null & \
+            -commandfile '${RIOTTOOLS}/jlink/term.seg' & \
             echo  \$! > $JLINK_PIDFILE" &
 
     sh -c "${JLINK_TERMPROG} ${JLINK_TERMFLAGS}"

We now get a "J-Link Commander will now exit on Error" message that is not there in master.
I must be run with a BOARD using stdio_rtt.

BOARD=thingy52 make -C examples/hello-world/ term
make: Entering directory '/home/harter/work/git/RIOT/examples/hello-world'
/home/harter/work/git/RIOT/dist/tools/jlink/jlink.sh term_rtt
### Starting RTT terminal ###
SEGGER J-Link Commander V6.42d (Compiled Feb 15 2019 13:56:53)
DLL version V6.42d, compiled Feb 15 2019 13:56:43

J-Link Commander will now exit on Error

J-Link Command File read successfully.
Processing script file...

J-Link connection not established yet but required for command.
Connecting to J-Link via USB...Twisted not available, please install it if you want to use pyterm's JSON capabilities
2019-03-28 11:37:39,592 - WARNING # Host name for TCP connection is missing, defaulting to "localhost"
2019-03-28 11:37:39,592 - INFO # Connect to localhost:19021
2019-03-28 11:37:39,594 - ERROR # Something went wrong connecting to localhost:19021
make: Leaving directory '/home/harter/work/git/RIOT/examples/hello-world'

Issues/PRs references

Split out of #10870
Confronted again while testing #9013

On error Jlink exits with a no error code by default.

From the JLink User Guide:

'-ExitOnError' has the same meaning as the 'exitonerror' command

    'exitonerror' command
    This command toggles whether J-Link Commander exits on error or not.

    1: J-Link Commander will now exit on Error.
    0: J-Link Commander will no longer exit on Error.

Executing 'flash/reset' without a board connected now correctly returns an
error. For 'term' it does not show an error due to the way it is handled
internally.

It also returns an error when the board fails to do an operation when it
is in a state where it cannot be flashed for example.
@cladmi cladmi added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Impact: minor The PR is small in size and might only require a quick look of a knowledgeable reviewer Area: tools Area: Supplementary tools labels Mar 28, 2019
@cladmi cladmi added this to the Release 2019.04 milestone Mar 28, 2019
@miri64
Copy link
Copy Markdown
Member

miri64 commented Mar 28, 2019

I can confirm that BOARD=nrf52dk make -C examples/hello-world flash now fails with an error code without a device attached.

  • master
    […]
    /home/mlenders/Repositories/RIOT-OS/RIOT/dist/tools/jlink/jlink.sh flash /home/mlenders/Repositories/RIOT-OS/RIOT/examples/hello-world/bin/nrf52dk/hello-world.bin
    ### Flashing Target ###
    ### Flashing at base address 0x0 with offset 0 ###
    SEGGER J-Link Commander V6.44c (Compiled Mar 22 2019 17:29:32)
    DLL version V6.44c, compiled Mar 22 2019 17:29:20
    
    
    J-Link Command File read successfully.
    Processing script file...
    
    J-Link connection not established yet but required for command.
    Connecting to J-Link via USB...FAILED: Cannot connect to J-Link via USB.
    
    J-Link connection not established yet but required for command.
    Connecting to J-Link via USB...FAILED: Cannot connect to J-Link via USB.
    
    J-Link connection not established yet but required for command.
    Connecting to J-Link via USB...FAILED: Cannot connect to J-Link via USB.
    
    
    Script processing completed.
    
  • vs this PR
    […]
    /home/mlenders/Repositories/RIOT-OS/RIOT/dist/tools/jlink/jlink.sh flash /home/mlenders/Repositories/RIOT-OS/RIOT/examples/hello-world/bin/nrf52dk/hello-world.bin
    ### Flashing Target ###
    ### Flashing at base address 0x0 with offset 0 ###
    SEGGER J-Link Commander V6.44c (Compiled Mar 22 2019 17:29:32)
    DLL version V6.44c, compiled Mar 22 2019 17:29:20
    
    J-Link Commander will now exit on Error
    
    J-Link Command File read successfully.
    Processing script file...
    
    J-Link connection not established yet but required for command.
    Connecting to J-Link via USB...FAILED: Cannot connect to J-Link via USB.
    
    Script processing completed.
    
    make: *** [/home/mlenders/Repositories/RIOT-OS/RIOT/examples/hello-world/../../Makefile.include:538: flash] Fehler 1
    

Sadly, I don't have the hardware at hand right now to test the positive case. But will do once I have some.

Copy link
Copy Markdown
Member

@miri64 miri64 left a comment

Choose a reason for hiding this comment

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

I can also still reset and flash with an nrf52dk attached, so ACK.

@miri64 miri64 added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Mar 28, 2019
@cladmi
Copy link
Copy Markdown
Contributor Author

cladmi commented Mar 28, 2019

Thank you for the review and testing :)

@cladmi cladmi closed this Mar 28, 2019
@cladmi cladmi deleted the pr/jlink/failonerror branch March 28, 2019 13:46
@cladmi cladmi restored the pr/jlink/failonerror branch March 28, 2019 13:48
@cladmi cladmi reopened this Mar 28, 2019
@miri64 miri64 merged commit b381c0b into RIOT-OS:master Mar 28, 2019
@miri64
Copy link
Copy Markdown
Member

miri64 commented Mar 28, 2019

Don't delete your branch prematurely ;-D

@cladmi
Copy link
Copy Markdown
Contributor Author

cladmi commented Mar 28, 2019

Sorry for the fail >< I need a coffe break.

@cladmi cladmi deleted the pr/jlink/failonerror branch March 28, 2019 13:53
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 Impact: minor The PR is small in size and might only require a quick look of a knowledgeable reviewer Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants