Hi Antonio, thank you for the concise explanation, it is now all clear to me :)
So yes, it seems that the concrete examples I ran into (load_image, verify_image) could use some form of (optional) progress info. I'd be happy to submit a patch, as time permits. Regards, Jan On Wed, Apr 28, 2021 at 4:29 PM Antonio Borneo <[email protected]> wrote: > On Tue, Apr 27, 2021 at 11:18 AM Jan Matyáš <[email protected]> wrote: > > > > Hello, > > > > I have noticed that when TCL commands are being issued from OpenOCD's > startup scripts, their output (produced by command_print()) is not actually > visible on the output, apart from the last print. The preceding prints seem > to be dropped - not visible to the user. > > > > This can be demonstrated e.g. on load_image / verify_image commands, > that are supposed to print both progress info ("XX bytes written to address > YY") and the overall summary ("Written XX bytes"). However, only the last > printed line - the summary - is visible. > > > > From a gerrit discussion, I understand this is a known issue, and I have > been pointed to http://openocd.zylin.com/#/c/1815/7 > > > > Could you please explain how this issue came to being, or point me to an > earlier thread, if this has already been discussed? Is there any plan to > change this, so that the user can be informed in real-time e.g. about the > progress of load_image and similar commands? > > Hi Jan, > > the former code in OpenCD was quite messy regarding command output and > TCL compatibility. > The patch you point above is part of a long series to clean up those > old inconsistencies > http://openocd.zylin.com/#/q/topic:Tcl_return_values > > In TCL the "result" of a command is never printed by default, but it's > provided as TCL result to be used by other commands. > A TCL shell will print only the "result" of the last command to show > it interactively to the user. > You can try running the TCL shell of jimtcl or of the "full" tcl > > $ ./jimtcl/jimsh > Welcome to Jim version 0.80 > . expr 1;expr 3;expr 5 > 5 > . puts [expr 1];puts [expr 3];puts [expr 5] > 1 > 3 > 5 > > $ tclsh > % expr 1;expr 3;expr 5 > 5 > % puts [expr 1];puts [expr 3];puts [expr 5] > 1 > 3 > 5 > > As you can see, in both cases only the last "result" is printed, in > the example above "5". > If a user needs to print out some intermediate value, he/she has to > print it using the TCL command "puts" or, in OpenOCD, "echo" (maybe > another inconsistency that should be fixed). > The telnet console of OpenOCD is now aligned with the TCL behavior. > The problem is that not all the commands cooperate well; they have to > be fixed one-by-one. > > Now your question becomes: > Should some command print an output, or they should only provide > "result" and the user has to use the TCL way "echo [command]" to print > it out ? > > My answer (not "the" answer but "my" answer) is: it depends! > If it is an OpenOCD error (not a command's error, but an OpenOCD > error, like "out of memory" or JTAG suddenly disconnected), it should > be printed unconditionally! > If it is an "interactive or dynamic" content, it should be printed, > but only if requested. > All the rest should go in "result". > > The command "svf" has an option "progress" to show during the download > the percentage of execution. > This percentage has sense to be printed out immediately, and there is > no reason to put it in the "result" of the command. What the sense of > printing it at the end when it is 100%! > But it is "optional"! So if in a script I don't want this output I can > silent it by removing the "progress" option. > > Maybe "load_image" should do something similar. Adding a "progress" or > "statistics" to enable some output. > Patches are welcome! > In OpenOCD code the output goes through LOG_USER()/LOG_USER_N(), while > the "result" goes through command_print()/command_print_sameline(). > > Antonio >
