Skip to content

jlink: handle flashing at IMAGE_OFFSET#11200

Merged
cladmi merged 2 commits intoRIOT-OS:masterfrom
danpetry:tools/jlink_handle_image_offset
Mar 20, 2019
Merged

jlink: handle flashing at IMAGE_OFFSET#11200
cladmi merged 2 commits intoRIOT-OS:masterfrom
danpetry:tools/jlink_handle_image_offset

Conversation

@danpetry
Copy link
Copy Markdown
Contributor

@danpetry danpetry commented Mar 18, 2019

Contribution description

Currently, the IMAGE_OFFSET variable isn't handled in jlink.sh. riotboot.mk is currently the only place where this variable is exported. So, this is needed for riotboot to flash properly using jlink. It attempts to be a non-destructive change for everything else.

The contribution attempts to ensure that the flashing address handling in jlink.sh remains the same for all other modules - i.e., it doesn't break anything. Further PRs will clean up the wider handling of the FLASH_ADDR and IMAGE_OFFSET variables. Handling of flashing address is now similar to that in openocd, except FLASH_ADDR is not automatically determined. So, this PR goes in the direction of making the handling of these variables homogenous.

Testing procedure

Testing should cover all boards which use jlink and where riotboot is either currently supported or support is under development.

  • tests/riotboot with nrf52dk, with slot0 only

Needed for:
#11201
#11126

@cladmi
Copy link
Copy Markdown
Contributor

cladmi commented Mar 19, 2019

I will do a proper test with #11126

However, as you mentioned in #11201 JLink requires the address to be given as hexadecimal values, but it was currently not the case with boards/openmote-cc2538/Makefile.include: export FLASH_ADDR := 200000 so maybe this one should be tested and fixed as well before this pull request.

@cladmi
Copy link
Copy Markdown
Contributor

cladmi commented Mar 19, 2019

Indeed it will break the openmote-cc2538 as the address is given as hexadecimal without being prepended with 0x.

### Flashing at base address 200000 with offset 0 ###
DEBUG ADDR_TO_FLASH 0x00030d40

And the address is indeed 0x200000

rom (rx) : ORIGIN = 0x00200000, LENGTH = 512K - 44

@cladmi
Copy link
Copy Markdown
Contributor

cladmi commented Mar 19, 2019

So there is a need for a commit before this one to prepare the openmote:

diff --git a/boards/openmote-cc2538/Makefile.include b/boards/openmote-cc2538/Makefile.include
index bb8b52bf3..401a8fda8 100644
--- a/boards/openmote-cc2538/Makefile.include
+++ b/boards/openmote-cc2538/Makefile.include
@@ -12,7 +12,7 @@ export PROGRAMMER ?= cc2538-bsl
 ifeq ($(PROGRAMMER),jlink)
   # setup JLink for flashing
   export JLINK_DEVICE := cc2538sf53
-  export FLASH_ADDR := 200000
+  export FLASH_ADDR := 0x200000
   export JLINK_IF := JTAG
   export TUI := 1
   include $(RIOTMAKE)/tools/jlink.inc.mk

and then I get the correct flashing address with this pull request

### Flashing at base address 0x200000 with offset 0 ###
DEBUG ADDR_TO_FLASH 0x00200000

Then after this one, there are different places where IMAGE_OFFSET should be used instead of FLASH_ADDR but could come in upcoming pull requests.

@danpetry
Copy link
Copy Markdown
Contributor Author

Pushed the change, thanks very much for the fix

Copy link
Copy Markdown
Contributor

@cladmi cladmi left a comment

Choose a reason for hiding this comment

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

Some minor changes inline to add a comment and refactor the commit message.

The commit for the openmote states JLink is the default programmer but it is not and it does not matter.
Explaining why we change to 0x200000 instead of keeping 200000 would be better.
"Jlink interprets the address as hex, so be consistent with the declaration to allow evaluating it with bash arithmetic later." or something.
The commit title should also be prefixed by what it changes so boards/openmote-cc2538 or openmote-cc2538.
Note, before merging, I also would like to invert the commits and have the openmote fix before the JLink modification.

I tested #11126 (comment) so it makes riotboot work with nrf52dk and JLink as stated. Great !

I tested that mcuboot still works with this pr

BOARD=nrf52dk make -C tests/mcuboot/ clean mcuboot-flash

I did not test the openmote-cc2538 for the moment.

printf "${JLINK_PRE_FLASH}\n" >> ${BINDIR}/burn.seg
fi
echo "loadbin ${BINFILE} ${FLASH_ADDR}" >> ${BINDIR}/burn.seg
ADDR_TO_FLASH=$(printf "0x%08x\n" "$((${FLASH_ADDR} + ${IMAGE_OFFSET}))")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please add a comment saying that it is formatted as hexadecimal as JLink interprets the address as hex.

@danpetry danpetry force-pushed the tools/jlink_handle_image_offset branch from 9a2a813 to cc2bfd0 Compare March 20, 2019 11:46
@danpetry
Copy link
Copy Markdown
Contributor Author

I've changed the commit messages and switched the commits. I've added the comment change as a fixup for easier review.
Re testing of the openmote: I haven't managed to get it working with the jlink segger, either on this branch or in master. The segger won't connect to the target. worth getting it working before merge, or raising an issue?

@cladmi
Copy link
Copy Markdown
Contributor

cladmi commented Mar 20, 2019

@haukepetersen do you know how to test the openmote-cc2538 with PROGRAMMER=jlink ?

@cladmi
Copy link
Copy Markdown
Contributor

cladmi commented Mar 20, 2019

I tested on my machine and it worked for the openmote-cc2538. I first flashed examples/default with the cc2538-bsl as explained in the documentation (cable + reset button) and then flashed tests/shell with Jlink and could run the test:

RIOT_CI_BUILD=1 PROGRAMMER=jlink BOARD=openmote-cc2538 make -C tests/shell/ flash test

make: Entering directory '/home/harter/work/git/RIOT/tests/shell'
Building application "tests_shell" for "openmote-cc2538" with MCU "cc2538".

   text	   data	    bss	    dec	    hex	filename
   9884	    136	   2604	  12624	   3150	/home/harter/work/git/RIOT/tests/shell/bin/openmote-cc2538/tests_shell.elf
/home/harter/work/git/RIOT/dist/tools/jlink/jlink.sh flash /home/harter/work/git/RIOT/tests/shell/bin/openmote-cc2538/tests_shell.bin
### Flashing Target ###
### Flashing at base address 0x200000 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...O.K.
Firmware: J-Link V9 compiled Oct 25 2018 11:46:07
Hardware version: V9.30
S/N: 269307832
License(s): FlashBP, GDB
OEM: SEGGER-EDU
VTref=3.291V
Target connection not established yet but required for command.
Device "CC2538SF53" selected.


Connecting to target via JTAG
InitTarget: Found ICE-Pick with ID: 0x8B96402F
InitTarget: Found CPU TAP 0x4BA00477
Scanning AP map to find all available APs
AP[1]: Stopped AP scan as end of AP map has been reached
AP[0]: AHB-AP (IDR: 0x24770011)
Iterating through AP map to find AHB-AP to use
AP[0]: Core found
AP[0]: AHB-AP ROM base: 0xE00FF000
CPUID register: 0x412FC230. Implementer code: 0x41 (ARM)
Found Cortex-M3 r2p0, Little endian.
FPUnit: 6 code (BP) slots and 2 literal slots
CoreSight components:
ROMTbl[0] @ E00FF000
ROMTbl[0][0]: E000E000, CID: B105E00D, PID: 002BB000 SCS
ROMTbl[0][1]: E0001000, CID: B105E00D, PID: 002BB002 DWT
ROMTbl[0][2]: E0002000, CID: B105E00D, PID: 002BB003 FPB
ROMTbl[0][3]: E0000000, CID: B105E00D, PID: 002BB001 ITM
ROMTbl[0][4]: E0040000, CID: B105900D, PID: 002BB923 TPIU-Lite
Cortex-M3 identified.
Halting CPU for downloading file.
Downloading file [/home/harter/work/git/RIOT/tests/shell/bin/openmote-cc2538/tests_shell.bin]...
Comparing flash   [000%]�����000%]�����010%]�����010%]�����025%]�����025%]�����035%]�����035%]�����050%]�����050%]�����060%]�����060%]�����075%]�����075%]�����085%]�����085%]�����100%] Done.
Verifying flash   [000%]�����100%] Done.
J-Link: Flash download: Bank 0 @ 0x00200000: Skipped. Contents already match
O.K.

Reset delay: 0 ms
Reset type NORMAL: Resets core & peripherals via SYSRESETREQ & VECTRESET bit.
Reset: Halt core after reset via DEMCR.VC_CORERESET.
Reset: Reset device via AIRCR.SYSRESETREQ.



Script processing completed.

/home/harter/work/git/RIOT/dist/tools/pyterm/pyterm -p "/dev/ttyUSB0" -b "115200"
Twisted not available, please install it if you want to use pyterm's JSON capabilities
2019-03-20 15:53:53,553 - INFO # Connect to serial port /dev/ttyUSB0
Welcome to pyterm!
Type '/exit' to exit.
2019-03-20 15:53:57,012 - INFO # main(): This is RIOT! (Version: buildtest)
2019-03-20 15:53:57,012 - INFO # test_shell.
> start_test
2019-03-20 15:53:57,075 - INFO #  start_test
2019-03-20 15:53:57,076 - INFO # [TEST_START]
> end_test
2019-03-20 15:53:57,139 - INFO #  end_test
2019-03-20 15:53:57,140 - INFO # [TEST_END]


> 123456789012345678901234567890123456789012345678901234567890
2019-03-20 15:53:57,203 - INFO #  end_test
2019-03-20 15:53:57,204 - INFO # [TEST_END]
> 2019-03-20 15:53:57,204 - INFO #  end_test
2019-03-20 15:53:57,204 - INFO # [TEST_END]
> 2019-03-20 15:53:57,269 - INFO #  123456789012345678901234567890123456789012345678901234567890
2019-03-20 15:53:57,270 - INFO # shell: command not found: 123456789012345678901234567890123456789012345678901234567890
> unknown_command
2019-03-20 15:53:57,332 - INFO #  unknown_command
2019-03-20 15:53:57,333 - INFO # shell: command not found: unknown_command
help
> 2019-03-20 15:53:57,427 - INFO #  help
2019-03-20 15:53:57,428 - INFO # Command              Description
2019-03-20 15:53:57,428 - INFO # ---------------------------------------
2019-03-20 15:53:57,429 - INFO # start_test           starts a test
2019-03-20 15:53:57,429 - INFO # end_test             ends a test
2019-03-20 15:53:57,430 - INFO # echo                 prints the input command
2019-03-20 15:53:57,430 - INFO # reboot               Reboot the node
2019-03-20 15:53:57,431 - INFO # ps                   Prints information about running threads.
2019-03-20 15:53:57,431 - INFO # app_metadata         Returns application metadata
echo a string
> 2019-03-20 15:53:57,491 - INFO #  echo a string
2019-03-20 15:53:57,492 - INFO # "echo""a""string"
> ps
2019-03-20 15:53:57,564 - INFO #  ps
2019-03-20 15:53:57,565 - INFO # 	pid | state    Q | pri 
2019-03-20 15:53:57,566 - INFO # 	  1 | pending  Q |  15
2019-03-20 15:53:57,567 - INFO # 	  2 | running  Q |   7
reboot
> 2019-03-20 15:53:57,640 - INFO #  reboot
2019-03-20 15:53:57,641 - INFO # main(): This is RIOT! (Version: buildtest)
2019-03-20 15:53:57,641 - INFO # test_shell.
> 
make: Leaving directory '/home/harter/work/git/RIOT/tests/shell'

We can note the address is correctly handled

### Flashing Target ###
### Flashing at base address 0x200000 with offset 0 ###

@cladmi cladmi added Area: build system Area: Build system Area: tools Area: Supplementary tools labels Mar 20, 2019
@cladmi cladmi added this to the Release 2019.04 milestone Mar 20, 2019
@cladmi
Copy link
Copy Markdown
Contributor

cladmi commented Mar 20, 2019

Please squash the fixup and add the "CI: ready for build" when done.

@cladmi cladmi added the CI: run tests If set, CI server will run tests on hardware for the labeled PR label Mar 20, 2019
danpetry added 2 commits March 20, 2019 16:07
Declaring the address in decimal format meant that it was being
interpreted as a decimal rather than hex address by the tooling
and the intermediate bash arithmetic. This fixes that bug.
- Handling of flashing address is now similar to that in openocd,
  except FLASH_ADDR is not automatically determined
@danpetry danpetry force-pushed the tools/jlink_handle_image_offset branch from cc2bfd0 to 80d4838 Compare March 20, 2019 15:08
@danpetry
Copy link
Copy Markdown
Contributor Author

Thanks for posting the test results, nice.

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

cladmi commented Mar 20, 2019

@cladmi cladmi merged commit 7d360fc into RIOT-OS:master Mar 20, 2019
@cladmi
Copy link
Copy Markdown
Contributor

cladmi commented Mar 20, 2019

Thank you for handling this one.

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 CI: run tests If set, CI server will run tests on hardware for the labeled PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants