Skip to content

dist/tools/openocd: add the possibility to do a reset before halt in openocd debug command#8856

Merged
kYc0o merged 2 commits intoRIOT-OS:masterfrom
aabadie:pr/openocd_debug_reset
Apr 24, 2018
Merged

dist/tools/openocd: add the possibility to do a reset before halt in openocd debug command#8856
kYc0o merged 2 commits intoRIOT-OS:masterfrom
aabadie:pr/openocd_debug_reset

Conversation

@aabadie
Copy link
Copy Markdown
Contributor

@aabadie aabadie commented Mar 30, 2018

Contribution description

This PR tries to address this comment by using an environment variable to trigger a reset before halt in the openocd debug command.

It's required for the b-l072z-lrwan1 board (at least), so the config of this board is updated accordingly.

Issues/PRs references

Addresses the same issue than #8790 but in a cleaner way.

@aabadie aabadie added 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 Area: boards Area: Board ports labels Mar 30, 2018
@aabadie aabadie requested a review from miri64 March 30, 2018 10:30
@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented Mar 30, 2018

Maybe @gebart or @kYc0o could also help here.

Copy link
Copy Markdown
Contributor

@kYc0o kYc0o left a comment

Choose a reason for hiding this comment

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

It looks legit, but needs some adaptation IMHO.

export STLINK_VERSION ?= 2-1

# do a reset before halt when starting debugger
export PRE_DEBUG_RESET_HALT ?= 1
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.

I think the variable should be declared somewhere more general, then set it to one here. Maybe makefiles/vars.inc.mk ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The idea is to check if the variable exists in openocd.sh. So one has just to declare it to enable the reset before halt in debug command.

Copy link
Copy Markdown
Contributor

@kYc0o kYc0o Apr 9, 2018

Choose a reason for hiding this comment

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

Well I guess this anyways it will be refactored for all the ST boards embedding a ST-Link debugger, so it's fine for now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this anyways it will be refactored for all the ST boards embedding a ST-Link debugger

Are you referring to #8475 ?

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.

Yes, I think a global variable for this debugger should be available for all boards embedding it.

if [ -n "${PRE_DEBUG_RESET_HALT}" ]; then
PRE_RESET_HALT='reset'
fi

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.

I think instead of doing this you can evaluate the variable directly on the code, since it's used only there. Each command anyways gets executed separately.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't understand this comment. PRE_RESET_HALT is only meant for the debug command.

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.

I mean you can do the check inline in the code below, no need to declare a variable and then do the check.

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.

To be more clear, to reuse the variable you just exported before.

Copy link
Copy Markdown
Contributor Author

@aabadie aabadie Apr 10, 2018

Choose a reason for hiding this comment

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

I prefer keeping it this way. The command prefix is defined before, so there's no inline bash code added when the openocd command is built. I think it's nicer the way it's done here.

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.

I mean that you can use your first variable directly in the shell script. You might need to change the name though, something like PRE_DEBUG_COND and then add something like PRE_DEBUG_COND += reset or whatever is needed, in the Makefile.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

But in this case it has to be defined globally and that's exactly what I wanted to avoid.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

By the way, I changed the previous code by using a local variable. Still works.

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.

But in this case it has to be defined globally and that's exactly what I wanted to avoid.

All the variables that are used in this script are global, they are available because they're exported since this script is out of the scope of the Makefiles. Thus, there's no real concept of "global" variable here, all of them are.

@aabadie aabadie force-pushed the pr/openocd_debug_reset branch from c91540a to a60fc8c Compare April 11, 2018 13:28
test_elffile

# Configure halt command: prepend a reset if required by the board config
local _pre_reset_halt=''
Copy link
Copy Markdown
Contributor Author

@aabadie aabadie Apr 12, 2018

Choose a reason for hiding this comment

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

@kYc0o, that's why I changed my code so that now it updates a local variable by checking if the global variable PRE_DEBUG_RESET_HALT is set.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

By the way, this strategy was inspired by the use of PRE_FLASH_CHECK_SCRIPT. The idea is exactly the same.

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.

By the way, this strategy was inspired by the use of PRE_FLASH_CHECK_SCRIPT. The idea is exactly the same.

That's a condition to execute a whole script and analysing its output, not just setting a variable. What I'm trying to avoid here is the declaration of variables and conditions which are IMHO not necessary, and by simply declaring the variable in makefiles/vars.inc.mk and setting it in your board Makefile it's enough. It's even more flexible since for other boards (which we might not be aware of yet) other commands might be necessary, thus you can just set this variable for your needs e.g. PRE_DEBUG_RESET_HALT += reset halt reset if you need to reset twice or whatever.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Looks like we disagree

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.

I would like to have a namespaced variable and homogenous in the way OPENOCD_..._CMDS work in flash.


# Configure halt command: prepend a reset if required by the board config
local _pre_reset_halt=''
if [ -n "${PRE_DEBUG_RESET_HALT}" ]; then
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.

For me, the PRE here is wrong, because it changes the command from halt to reset halt it's not a previous command. Also, introducing a new really specific variable only for this specific way of handling the case seems bad to me.

Copy link
Copy Markdown
Contributor

@cladmi cladmi Apr 12, 2018

Choose a reason for hiding this comment

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

I would prefer the following at the beginning of openocd.sh

# A meaningful comment on what this is :p
: ${OPENOCD_EXTRA_INIT:=-c 'halt'}

And in the given board set

export OPENOCD_DEBUG_HALT_CMD = -c 'reset halt'

@miri64 miri64 removed their request for review April 12, 2018 18:00
@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented Apr 13, 2018

@cladmi, I re-read the openocd commands documentation.
You are right thathalt and reset halt are 2 different commands: the former just halt the target (which doesn't work with stm32l0 when used with some reset_options) while the latter performs a reset and then a halt (this is why I used PRE prefix).
Now I'm wondering if halt should just be replaced by reset halt like I did initially since reset halt seems more robust.

@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented Apr 13, 2018

Now I'm wondering if halt should just be replaced by reset halt like I did initially since reset halt seems more robust.

I tested on an Arduino Zero board and the current debug target doesn't work for me with just halt, reset halt works. samr21-xpro might have the same problem.
I'm using openocd 0.10 (master version). Can someone confirm ?

@aabadie aabadie force-pushed the pr/openocd_debug_reset branch from 5c33b4c to 47ddc1c Compare April 13, 2018 06:34
@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented Apr 13, 2018

@cladmi @kYc0o I updated the code following your suggestions. Let's move forward.

# Initial target state when using debug, by default a 'halt' request is sent to
# the target when starting a debug session. 'reset halt' can also be used
# depending on the type of target.
: ${OPENOCD_EXTRA_DEBUG_INIT_CMD:=-c 'halt'}
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.

Some naming remarks, in that case it is not an EXTRA command like the other one as it's mandatory, so this EXTRA part should be removed.
To match your comment, maybe put more START_CMD as the name INIT means something with openocd (reset init, init)

Also I would prefer it defined along the DBG variables, but that's personal taste.

export DEBUG_ADAPTER ?= stlink
export STLINK_VERSION ?= 2-1

# do a reset before halt when starting debugger
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.

Copy link
Copy Markdown
Contributor Author

@aabadie aabadie Apr 18, 2018

Choose a reason for hiding this comment

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

Indeed "The optional parameter specifies what should happen after the reset" so there's a reset before halt (halt is an optional parameter) :)

@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented Apr 18, 2018

Renamed and moved the variable as suggested by @cladmi

@aabadie aabadie force-pushed the pr/openocd_debug_reset branch from ada64e1 to e87aa52 Compare April 18, 2018 14:52
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.

ACK

I checked the output difference between iotlab-m3 and b-l072z-lrwan1 by doing sh -xc in the debug function.

For the fact that it's working I trust you.

Please squash.

@cladmi
Copy link
Copy Markdown
Contributor

cladmi commented Apr 18, 2018

@aabadie Reviewing this PR made me find something you will like :) I will do a PR

@aabadie aabadie force-pushed the pr/openocd_debug_reset branch from e87aa52 to ea255f5 Compare April 18, 2018 15:33
@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented Apr 18, 2018

For the fact that it's working I trust you.

It does work :)

Please squash.

Done

@cladmi
Copy link
Copy Markdown
Contributor

cladmi commented Apr 20, 2018

@kYc0o do you ACK ?

Copy link
Copy Markdown
Contributor

@kYc0o kYc0o left a comment

Choose a reason for hiding this comment

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

Excellent! ACK.

@kYc0o
Copy link
Copy Markdown
Contributor

kYc0o commented Apr 20, 2018

I'd like to change the title though, it doesn't really reflect what it was done here.

@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented Apr 24, 2018

I'd like to change the title though, it doesn't really reflect what it was done here.

Again, it does, see this comment.

@kYc0o
Copy link
Copy Markdown
Contributor

kYc0o commented Apr 24, 2018

IMHO you're not adding the possibility to make a reset before halt, but rather you add a different command called reset halt. So maybe something like "openocd: replace halt command by OPENOCD_DBG_START_CMD", or something like that. Also, I'd say you should squash your commits into one, to allow a proper bisect if needed.

@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented Apr 24, 2018

Again, it does, see this comment.

Have you read the documentation ? I can put what I wrote there (again):

"The optional parameter specifies what should happen after the reset"

so there's a reset before halt since halt is the optional parameter when using "reset halt".

Also, I'd say you should squash your commits into one, to allow a proper bisect if needed.

I don't understand the purpose of your comment. The first commit updates the openocd script by introducing a parametrizable variable. The second commit set this variable to what works with the b-l072z-lrwan1 board. The 2 commits touch 2 different things (tools and boards) and this is very common practice into RIOT.

@kYc0o
Copy link
Copy Markdown
Contributor

kYc0o commented Apr 24, 2018

Well, I still don't agree about the title (I had problems to recognise what actually PRs are doing by the title, even merging something that was already PRed before just because the title was misleading), but let's go. About the commits is ok because they are in the good order, I just want to enforce working commits because I also recently ran in a big hassle doing bisect.

@kYc0o kYc0o merged commit 4e872e6 into RIOT-OS:master Apr 24, 2018
maxvankessel pushed a commit to maxvankessel/RIOT that referenced this pull request May 8, 2018
dist/tools/openocd: add the possibility to do a reset before halt in openocd debug command
@aabadie aabadie deleted the pr/openocd_debug_reset branch June 1, 2018 18:58
@cladmi cladmi added this to the Release 2018.07 milestone Jul 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: boards Area: Board ports 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants