dist/tools/openocd: add the possibility to do a reset before halt in openocd debug command#8856
Conversation
kYc0o
left a comment
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
I think the variable should be declared somewhere more general, then set it to one here. Maybe makefiles/vars.inc.mk ?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
this anyways it will be refactored for all the ST boards embedding a ST-Link debugger
Are you referring to #8475 ?
There was a problem hiding this comment.
Yes, I think a global variable for this debugger should be available for all boards embedding it.
dist/tools/openocd/openocd.sh
Outdated
| if [ -n "${PRE_DEBUG_RESET_HALT}" ]; then | ||
| PRE_RESET_HALT='reset' | ||
| fi | ||
|
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
I don't understand this comment. PRE_RESET_HALT is only meant for the debug command.
There was a problem hiding this comment.
I mean you can do the check inline in the code below, no need to declare a variable and then do the check.
There was a problem hiding this comment.
To be more clear, to reuse the variable you just exported before.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
But in this case it has to be defined globally and that's exactly what I wanted to avoid.
There was a problem hiding this comment.
By the way, I changed the previous code by using a local variable. Still works.
There was a problem hiding this comment.
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.
c91540a to
a60fc8c
Compare
dist/tools/openocd/openocd.sh
Outdated
| test_elffile | ||
|
|
||
| # Configure halt command: prepend a reset if required by the board config | ||
| local _pre_reset_halt='' |
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
By the way, this strategy was inspired by the use of PRE_FLASH_CHECK_SCRIPT. The idea is exactly the same.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Looks like we disagree
cladmi
left a comment
There was a problem hiding this comment.
I would like to have a namespaced variable and homogenous in the way OPENOCD_..._CMDS work in flash.
dist/tools/openocd/openocd.sh
Outdated
|
|
||
| # Configure halt command: prepend a reset if required by the board config | ||
| local _pre_reset_halt='' | ||
| if [ -n "${PRE_DEBUG_RESET_HALT}" ]; then |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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'
|
@cladmi, I re-read the openocd commands documentation. |
I tested on an Arduino Zero board and the current debug target doesn't work for me with just |
5c33b4c to
47ddc1c
Compare
dist/tools/openocd/openocd.sh
Outdated
| # 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'} |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Same here, it is not a reset before halt but a reset halt openocd command.
http://openocd.org/doc/html/General-Commands.html#resetcommand
There was a problem hiding this comment.
Indeed "The optional parameter specifies what should happen after the reset" so there's a reset before halt (halt is an optional parameter) :)
|
Renamed and moved the variable as suggested by @cladmi |
ada64e1 to
e87aa52
Compare
cladmi
left a comment
There was a problem hiding this comment.
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.
|
@aabadie Reviewing this PR made me find something you will like :) I will do a PR |
e87aa52 to
ea255f5
Compare
It does work :)
Done |
|
@kYc0o do you ACK ? |
|
I'd like to change the title though, it doesn't really reflect what it was done here. |
Again, it does, see this comment. |
|
IMHO you're not adding the possibility to make a reset before halt, but rather you add a different command called |
Have you read the documentation ? I can put what I wrote there (again):
so there's a reset before halt since halt is the optional parameter when using "reset halt".
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. |
|
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. |
dist/tools/openocd: add the possibility to do a reset before halt in openocd debug command
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.