Skip to content

jlink: get flash and debug files from cli#10528

Merged
aabadie merged 1 commit intoRIOT-OS:masterfrom
cladmi:pr/make/jlink/flashfile_from_cli
Dec 3, 2018
Merged

jlink: get flash and debug files from cli#10528
aabadie merged 1 commit intoRIOT-OS:masterfrom
cladmi:pr/make/jlink/flashfile_from_cli

Conversation

@cladmi
Copy link
Copy Markdown
Contributor

@cladmi cladmi commented Nov 30, 2018

Contribution description

Get BINFILE and ELFFILE from command line instead of environment variable.

Rename 'HEXFILE' to 'BINFILE' in the script as the binary file is used.
The documentation was already talking about 'BINFILE' but 'BINFILE'
was never exported by the build system and it was using 'HEXFILE' in the
implementation.

Testing procedure

I cannot test flashing as I do not have boards or a Jlink flasher.
A real verification would also be great.

A partial test is to compare the content of burn.seg that should be the same:

cat examples/hello-world/bin/ikea-tradfri/burn.seg
loadbin /home/harter/work/git/RIOT/examples/hello-world/bin/ikea-tradfri/hello-world.bin 0x0
r
g
exit

My test is to check the executed command:

BOARD=ikea-tradfri make --no-print-directory -C examples/hello-world/  flash-only FLASHER='bash -x $(RIOTTOOLS)/jlink/jlink.sh'
make[1]: Nothing to be done for 'Makefile.include'.
bash -x /home/harter/work/git/RIOT/dist/tools/jlink/jlink.sh flash /home/harter/work/git/RIOT/examples/hello-world/bin/ikea-tradfri/hello-world.bin
+ _GDB_PORT=3333
+ _TELNET_PORT=4444
+ _JLINK=JLinkExe
+ _JLINK_SERVER=JLinkGDBServer
+ _JLINK_IF=SWD
+ _JLINK_SPEED=2000
+ _JLINK_TERMPROG=/home/harter/work/git/RIOT/dist/tools/pyterm/pyterm
+ _JLINK_TERMFLAGS='-ts 19021'
+ ACTION=flash
+ shift
+ case "${ACTION}" in
+ echo '### Flashing Target ###'
### Flashing Target ###
+ echo '### Flashing at address 0x0 ###'
### Flashing at address 0x0 ###
+ do_flash /home/harter/work/git/RIOT/examples/hello-world/bin/ikea-tradfri/hello-world.bin
+ BINFILE=/home/harter/work/git/RIOT/examples/hello-world/bin/ikea-tradfri/hello-world.bin
+ test_config
+ '[' -z '' ']'
+ JLINK=JLinkExe
+ '[' -z '' ']'
+ JLINK_SERVER=JLinkGDBServer
+ '[' -z '' ']'
+ JLINK_IF=SWD
+ '[' -z '' ']'
+ JLINK_SPEED=2000
+ '[' -z EFR32MG1PxxxF256 ']'
+ '[' -z 0x0 ']'
+ test_serial
+ '[' -n '' ']'
+ test_binfile
+ '[' '!' -f /home/harter/work/git/RIOT/examples/hello-world/bin/ikea-tradfri/hello-world.bin ']'
+ /bin/echo -n ''
+ '[' '!' -z '' ']'
+ echo 'loadbin /home/harter/work/git/RIOT/examples/hello-world/bin/ikea-tradfri/hello-world.bin 0x0'
+ '[' '!' -z '' ']'
+ cat /home/harter/work/git/RIOT/dist/tools/jlink/reset.seg
+ sh -c 'JLinkExe                      -device '\''EFR32MG1PxxxF256'\''                     -speed '\''2000'\''                     -if '\''SWD'\''                     -jtagconf -1,-1                     -commandfile '\''/home/harter/work/git/RIOT/examples/hello-world/bin/ikea-tradfri/burn.seg'\'''
SEGGER J-Link Commander V6.40 (Compiled Oct 26 2018 15:08:38)
DLL version V6.40, compiled Oct 26 2018 15:08:28


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.

The difference with master is the following, which has nothing related to the actual flashing command but show binfile taken from argument.

2c2
< bash -x /home/harter/work/git/RIOT/dist/tools/jlink/jlink.sh flash
---
> bash -x /home/harter/work/git/RIOT/dist/tools/jlink/jlink.sh flash /home/harter/work/git/RIOT/examples/hello-world/bin/ikea-tradfri/hello-world.bin
18c18,19
< + do_flash
---
> + do_flash /home/harter/work/git/RIOT/examples/hello-world/bin/ikea-tradfri/hello-world.bin
> + BINFILE=/home/harter/work/git/RIOT/examples/hello-world/bin/ikea-tradfri/hello-world.bin
32c33
< + test_hexfile
---
> + test_binfile

Same check for debug:

BOARD=ikea-tradfri make --no-print-directory -C examples/hello-world/  debug DEBUGGER='bash -x $(RIOTTOOLS)/jlink/jlink.sh'
make[1]: Nothing to be done for 'Makefile.include'.
bash -x /home/harter/work/git/RIOT/dist/tools/jlink/jlink.sh debug /home/harter/work/git/RIOT/examples/hello-world/bin/ikea-tradfri/hello-world.elf
+ _GDB_PORT=3333
+ _TELNET_PORT=4444
+ _JLINK=JLinkExe
+ _JLINK_SERVER=JLinkGDBServer
+ _JLINK_IF=SWD
+ _JLINK_SPEED=2000
+ _JLINK_TERMPROG=/home/harter/work/git/RIOT/dist/tools/pyterm/pyterm
+ _JLINK_TERMFLAGS='-ts 19021'
+ ACTION=debug
+ shift
+ case "${ACTION}" in
+ echo '### Starting Debugging ###'
### Starting Debugging ###
+ do_debug /home/harter/work/git/RIOT/examples/hello-world/bin/ikea-tradfri/hello-world.elf
+ ELFFILE=/home/harter/work/git/RIOT/examples/hello-world/bin/ikea-tradfri/hello-world.elf
+ test_config
+ '[' -z '' ']'
+ JLINK=JLinkExe
+ '[' -z '' ']'
+ JLINK_SERVER=JLinkGDBServer
+ '[' -z '' ']'
+ JLINK_IF=SWD
+ '[' -z '' ']'
+ JLINK_SPEED=2000
+ '[' -z EFR32MG1PxxxF256 ']'
+ '[' -z 0x0 ']'
+ test_serial
+ '[' -n '' ']'
+ test_elffile
+ '[' '!' -f /home/harter/work/git/RIOT/examples/hello-world/bin/ikea-tradfri/hello-world.elf ']'
+ test_ports
+ '[' -z '' ']'
+ GDB_PORT=3333
+ '[' -z '' ']'
+ TELNET_PORT=4444
+ test_tui
+ '[' -n '' ']'
+ test_dbg
+ '[' -z '' ']'
+ DBG=arm-none-eabi-gdb
+ DBG_PID=0
+ arm-none-eabi-gdb -q -ex 'tar ext :3333' /home/harter/work/git/RIOT/examples/hello-world/bin/ikea-tradfri/hello-world.elf
+ sh -c 'JLinkGDBServer                             -device '\''EFR32MG1PxxxF256'\''                            -speed '\''2000'\''                            -if '\''SWD'\''                            -port '\''3333'\''                            -telnetport '\''4444'\'''
SEGGER J-Link GDB Server V6.40 Command Line Version

JLinkARM.dll V6.40 (DLL compiled Oct 26 2018 15:08:28)

Command line: -device EFR32MG1PxxxF256 -speed 2000 -if SWD -port 3333 -telnetport 4444
-----GDB Server start settings-----
GDBInit file:                  none
GDB Server Listening port:     3333
SWO raw output listening port: 2332
Terminal I/O port:             4444
Accept remote connection:      yes
Generate logfile:              off
Verify download:               off
Init regs on start:            off
Silent mode:                   off
Single run mode:               off
Target connection timeout:     0 ms
------J-Link related settings------
J-Link Host interface:         USB
J-Link script:                 none
J-Link settings file:          none
------Target related settings------
Target device:                 EFR32MG1PxxxF256
Target interface:              SWD
Target interface speed:        2000kHz
Target endian:                 little

Connecting to J-Link...
Reading symbols from /home/harter/work/git/RIOT/examples/hello-world/bin/ikea-tradfri/hello-world.elf...done.
Connecting to J-Link failed. Connected correctly?
GDBServer will be closed...
Shutting down...
Could not connect to J-Link.
Please check power, connection and settings.

And the output diff with master also has nothing related to the executed debug commands but show elffile taken from argument:

2c2
< bash -x /home/harter/work/git/RIOT/dist/tools/jlink/jlink.sh debug
---
> bash -x /home/harter/work/git/RIOT/dist/tools/jlink/jlink.sh debug /home/harter/work/git/RIOT/examples/hello-world/bin/ikea-tradfri/hello-world.elf
16c16,17
< + do_debug
---
> + do_debug /home/harter/work/git/RIOT/examples/hello-world/bin/ikea-tradfri/hello-world.elf
> + ELFFILE=/home/harter/work/git/RIOT/examples/hello-world/bin/ikea-tradfri/hello-world.elf

Issues/PRs references

#8838

Get BINFILE and ELFFILE from command line instead of environment variable.

Rename 'HEXFILE' to 'BINFILE' in the script as the binary file is used.
The documentation was already talking about 'BINFILE' but 'BINFILE'
was never exported by the build system and it was using 'HEXFILE' in the
implementation.
@cladmi cladmi added Area: build system Area: Build system CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Area: tools Area: Supplementary tools labels Nov 30, 2018
@cladmi cladmi added this to the Release 2019.01 milestone Nov 30, 2018
@cladmi cladmi requested review from aabadie and basilfx November 30, 2018 15:12
@aabadie
Copy link
Copy Markdown
Contributor

aabadie commented Dec 3, 2018

@cladmi, thanks for trying to cleanup this kind of things.

The changes proposed this PR make sense but doesn't work in all cases: I tried to flash several applications with nRF52dk, most of them can be flashed except the ones that embed the Nordic Softdevice blob.
See here for detail. There is something missing to handle that particular case.

@cladmi
Copy link
Copy Markdown
Contributor Author

cladmi commented Dec 3, 2018

@aabadie There should not be any issues with the way it was handled but I may be missing something.

Could you print both output from master and this PR when flashing with a command like:
(adapt the application to use if gnrc_networking is not a good one)

BOARD=nrf52dk make --no-print-directory -C examples/gnrc_networking/  flash-only FLASHER='bash -x $(RIOTTOOLS)/jlink/jlink.sh'

@aabadie
Copy link
Copy Markdown
Contributor

aabadie commented Dec 3, 2018

@cladmi, I compared with master (and the 3 previous release branches) and I get the same issue with Nordic softdevice. So that may be a problem on my side, or a more general issue.

To answer your request:

  • with this PR:
BOARD=nrf52dk make --no-print-directory -C examples/default  flash-only FLASHER='bash -x $(RIOTTOOLS)/jlink/jlink.sh'
make[1]: Nothing to be done for 'Makefile.include'.
bash -x /home/aabadie/softs/src/riot/RIOT/dist/tools/jlink/jlink.sh flash /home/aabadie/softs/src/riot/RIOT/examples/default/bin/nrf52dk/default.bin
+ _GDB_PORT=3333
+ _TELNET_PORT=4444
+ _JLINK=JLinkExe
+ _JLINK_SERVER=JLinkGDBServer
+ _JLINK_IF=SWD
+ _JLINK_SPEED=2000
+ _JLINK_TERMPROG=/home/aabadie/softs/src/riot/RIOT/dist/tools/pyterm/pyterm
+ _JLINK_TERMFLAGS='-ts 19021'
+ ACTION=flash
+ shift
+ case "${ACTION}" in
+ echo '### Flashing Target ###'
### Flashing Target ###
+ echo '### Flashing at address 0x1f000 ###'
### Flashing at address 0x1f000 ###
+ do_flash /home/aabadie/softs/src/riot/RIOT/examples/default/bin/nrf52dk/default.bin
+ BINFILE=/home/aabadie/softs/src/riot/RIOT/examples/default/bin/nrf52dk/default.bin
+ test_config
+ '[' -z '' ']'
+ JLINK=JLinkExe
+ '[' -z '' ']'
+ JLINK_SERVER=JLinkGDBServer
+ '[' -z '' ']'
+ JLINK_IF=SWD
+ '[' -z '' ']'
+ JLINK_SPEED=2000
+ '[' -z nrf52 ']'
+ '[' -z 0x1f000 ']'
+ test_serial
+ '[' -n '' ']'
+ test_binfile
+ '[' '!' -f /home/aabadie/softs/src/riot/RIOT/examples/default/bin/nrf52dk/default.bin ']'
+ /bin/echo -n ''
+ '[' '!' -z 'erase\nloadfile /home/aabadie/softs/src/riot/RIOT/examples/default/bin/nrf52dk/softdevice.hex' ']'
+ printf 'erase\nloadfile /home/aabadie/softs/src/riot/RIOT/examples/default/bin/nrf52dk/softdevice.hex\n'
+ echo 'loadbin /home/aabadie/softs/src/riot/RIOT/examples/default/bin/nrf52dk/default.bin 0x1f000'
+ '[' '!' -z '' ']'
+ cat /home/aabadie/softs/src/riot/RIOT/dist/tools/jlink/reset.seg
+ sh -c 'JLinkExe                      -device '\''nrf52'\''                     -speed '\''2000'\''                     -if '\''SWD'\''                     -jtagconf -1,-1                     -commandfile '\''/home/aabadie/softs/src/riot/RIOT/examples/default/bin/nrf52dk/burn.seg'\'''
SEGGER J-Link Commander V6.33g (Compiled Jun 28 2018 15:09:53)
DLL version V6.33g, compiled Jun 28 2018 15:09:48


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...O.K.
Firmware: J-Link OB-SAM3U128-V2-NordicSemi compiled Jan 12 2018 16:05:20
Hardware version: V1.00
S/N: 682770831
VTref=3.300V
Target connection not established yet but required for command.
Device "NRF52" selected.


Connecting to target via SWD
Found SW-DP with ID 0x2BA01477
Found SW-DP with ID 0x2BA01477
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]: JTAG-AP (IDR: 0x02880000)
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
Cortex-M4 identified.
Segmentation fault (core dumped)
/home/aabadie/softs/src/riot/RIOT/examples/default/../../Makefile.include:520: recipe for target 'flash' failed
make: *** [flash] Error 139
  • with master:
BOARD=nrf52dk make --no-print-directory -C examples/default  flash-only FLASHER='bash -x $(RIOTTOOLS)/jlink/jlink.sh'
make[1]: Nothing to be done for 'Makefile.include'.
bash -x /home/aabadie/softs/src/riot/RIOT/dist/tools/jlink/jlink.sh flash
+ _GDB_PORT=3333
+ _TELNET_PORT=4444
+ _JLINK=JLinkExe
+ _JLINK_SERVER=JLinkGDBServer
+ _JLINK_IF=SWD
+ _JLINK_SPEED=2000
+ _JLINK_TERMPROG=/home/aabadie/softs/src/riot/RIOT/dist/tools/pyterm/pyterm
+ _JLINK_TERMFLAGS='-ts 19021'
+ ACTION=flash
+ shift
+ case "${ACTION}" in
+ echo '### Flashing Target ###'
### Flashing Target ###
+ echo '### Flashing at address 0x1f000 ###'
### Flashing at address 0x1f000 ###
+ do_flash
+ test_config
+ '[' -z '' ']'
+ JLINK=JLinkExe
+ '[' -z '' ']'
+ JLINK_SERVER=JLinkGDBServer
+ '[' -z '' ']'
+ JLINK_IF=SWD
+ '[' -z '' ']'
+ JLINK_SPEED=2000
+ '[' -z nrf52 ']'
+ '[' -z 0x1f000 ']'
+ test_serial
+ '[' -n '' ']'
+ test_hexfile
+ '[' '!' -f /home/aabadie/softs/src/riot/RIOT/examples/default/bin/nrf52dk/default.bin ']'
+ /bin/echo -n ''
+ '[' '!' -z 'erase\nloadfile /home/aabadie/softs/src/riot/RIOT/examples/default/bin/nrf52dk/softdevice.hex' ']'
+ printf 'erase\nloadfile /home/aabadie/softs/src/riot/RIOT/examples/default/bin/nrf52dk/softdevice.hex\n'
+ echo 'loadbin /home/aabadie/softs/src/riot/RIOT/examples/default/bin/nrf52dk/default.bin 0x1f000'
+ '[' '!' -z '' ']'
+ cat /home/aabadie/softs/src/riot/RIOT/dist/tools/jlink/reset.seg
+ sh -c 'JLinkExe                      -device '\''nrf52'\''                     -speed '\''2000'\''                     -if '\''SWD'\''                     -jtagconf -1,-1                     -commandfile '\''/home/aabadie/softs/src/riot/RIOT/examples/default/bin/nrf52dk/burn.seg'\'''
SEGGER J-Link Commander V6.33g (Compiled Jun 28 2018 15:09:53)
DLL version V6.33g, compiled Jun 28 2018 15:09:48


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...O.K.
Firmware: J-Link OB-SAM3U128-V2-NordicSemi compiled Jan 12 2018 16:05:20
Hardware version: V1.00
S/N: 682770831
VTref=3.300V
Target connection not established yet but required for command.
Device "NRF52" selected.


Connecting to target via SWD
Found SW-DP with ID 0x2BA01477
Found SW-DP with ID 0x2BA01477
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]: JTAG-AP (IDR: 0x02880000)
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
Cortex-M4 identified.
Segmentation fault (core dumped)
/home/aabadie/softs/src/riot/RIOT/examples/default/../../Makefile.include:520: recipe for target 'flash' failed
make: *** [flash] Error 139

@cladmi
Copy link
Copy Markdown
Contributor Author

cladmi commented Dec 3, 2018

The diff between both looks the same as my example without softdevice.hex.

I think the Segmentation fault here does not help :D
If you compiled jlink yourself maybe try recompiling it or something, or find a newer version, could be an issue with some library version ABI compatibility.

I found another way of comparing with master by checking the content of burn.seg which should stay the same:

cat examples/hello-world/bin/ikea-tradfri/burn.seg
loadbin /home/harter/work/git/RIOT/examples/hello-world/bin/ikea-tradfri/hello-world.bin 0x0
r
g
exit

@aabadie
Copy link
Copy Markdown
Contributor

aabadie commented Dec 3, 2018

So that may be a problem on my side

It was indeed this. Reinstalling jlink fixed the problem...

And this PR works like a charm: I tried using make flash and make debug.

Copy link
Copy Markdown
Contributor

@aabadie aabadie left a comment

Choose a reason for hiding this comment

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

ACK

@aabadie aabadie merged commit 963d06c into RIOT-OS:master Dec 3, 2018
@cladmi
Copy link
Copy Markdown
Contributor Author

cladmi commented Dec 3, 2018

Thanks for the review ! :)

@cladmi cladmi deleted the pr/make/jlink/flashfile_from_cli branch December 3, 2018 12:51
@miri64 miri64 added the Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation label Dec 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: build system Area: Build system 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 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.

3 participants