[ABANDONED] JLinkExe vs JFlash command line arguments and exit codes.

  • [ABANDONED] JLinkExe vs JFlash command line arguments and exit codes.

    Good morning!

    We have recently made the switch from an STLink flasher that was VERY unstable to a Flasher ARM and so far our initial testing leaves us very satisfied, thank you for a solid product.

    Now, here is the steps we took since receiving the Flasher ARM :

    -Program via JFlash. Worked.
    -Program via JLinkExe, in console. Worked.
    -Program via JLinkExe with a batch file and argument -commanderscript. Worked.
    -Program via JLinkExe with argument -commanderscript launched by C# code. Not Working.

    I am about certain the code i wrote to launch and handle the process, not open a console window, redirect its output, etc. is working as i have tested it with other executables (notably STLink CLI).
    But I will accept you doubting this and so i went ahead and tried with the bare minimum code i could use to start the process, and it still does not program.

    I am using the exact same arguments and jlink script as the batch file scenario which works.

    Its hard to identify possible causes of the problem since every exitcode has been 1. Even when trying to introduce different errors such as unplugging the Flasher or unplugging the target.
    For this issue refer to this post : JLinkExe return code 1 when executing script


    The script.jlink file is the same used for both this and the batch file , it contains only an "r" to shut the target board down for now.
    The batch file that works :

    Source Code

    1. JLink.exe -device stm32f030cc -if swd -speed 50000 -commanderscript script.jlink


    Here is the test method with code as simple as possible to start the process :
    ok i give up trying to keep this sample formatted right, previewing the post keeps messing it up, im sorry...
    i left it visible in the screenshot of the batch file output.

    Source Code

    1. private static readonly string DIRECTORY = Path.Combine(Environment.CurrentDirectory, @"JLink\");private static readonly string JLINKPATH = Path.Combine(DIRECTORY, "Jlink.exe");
    2. private static int Test(){ using (var process = new Process {EnableRaisingEvents = true}) { process.StartInfo = new ProcessStartInfo(JLINKPATH) { Arguments = "-device stm32f030cc -if swd -speed 50000 -commanderscript script.jlink" }; process.Start(); process.WaitForExit(); return process.ExitCode; }}


    I added a screenshot of the batch file console output, the test method only flashes the screen but does not shut down the target board.
    I will try switching the procress to cmd.exe with a /K argument to keep window open today and report back but here is the output i get when running my other method which redirects the JLinkExe output :
    [DEBUG]Launching Jlink.exe
    SEGGER J-Link Commander V5.12j (Compiled Jul 18 2016 18:52:07)
    DLL version V5.12j, compiled Jul 18 2016 18:51:28


    [DEBUG]Process ended, exit code : 1

    I have seen similar posts where you suggest using JFlash in production instead of JLinkExe, we do have a license that came with the Flasher ARM but my problem with using JFlash in command line is that the GUI still opens according to documentation, and i would like to keep the end user on a single GUI , my custom production software's GUI. For similar reasons, we are not using the StandAlone mode because the firmware programming is a step incorporated in a series of steps taken to test every board produced and my custom software needs to handle when and where that firmware programming step is executed. If it was up to me i would get the SDK and work from there but i was not able to convince my superiors since the batch file is working fine. :P

    Quick suggestion semi off-topic : i saw some pretty heavy jlink script while reading the forums but for somethings as simple as -r -g and -loadfile , i would love to see those commands as viable command line arguments for jlink.exe, completly removing the need for a script file, thus the need to write the firmware file path every time in the script text file!


    If there is any information missing let me know ill update asap :)
    Thank you!



    Phil~
    Images
    • batoutput.png

      67.53 kB, 1,425×667, viewed 2,836 times

    The post was edited 1 time, last by Philippe.Lahaie ().

  • Hi,

    thanks for your inquiry.

    I am using the exact same arguments and jlink script as the batch file scenario which works.

    Can you please verify this by using MS Process Explorer (standalone / portable tool, enhanced task manager) ?

    If you double click on a processes, it gives you this window, which contains the command line arguments.


    PS:
    Additionally, could you try if this issue also occurs if you specify a full, not a relative path? e.g. "C:\temp\script.jlink" instead of "script.jlink" .
    PPS:
    I am out of the office for today, I will be back tomorrow .

    Best regards,
    Niklas
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • Hi Niklas,

    I have downloaded the software as advised and could never get a hit on the process ran programatically because it would exit instantly.

    But once i added the absolute path for the script file it finally started staying open and i noticed that the "current directory" is set to my software exe's directory instead of \JLink\ one step deeper!

    So it is now working but isn't it counter intuitive that i have to give JLinkExe arguments relative as to where the current directory is rather than where IT is when launched? oO

    Please also note that after i added exit to my script to keep it from staying open it started returning an exit code of 0 :D

    So I am glad that this is fixed, but is there anywhere we can see the error code list for JLinkExe?





    Once again, thank you for a very fast and effective answer!
    Phil~
    Images
    • batprocess.png

      121.92 kB, 1,337×578, viewed 1,352 times
    • csharpprocess.png

      51.43 kB, 802×584, viewed 1,049 times
  • One more thing,

    even if parts of the script fail, as soon as jlinkExe reaches exit he gracefully stops and returns and exit code of zero.

    This is problematic because it means there is no way to know if the board was actually programmed or not.

    The script i was running was "r loadfile ~~~ r g exit". Which i would've expected to break instantly considering the Flasher was not connected to the target board.
  • Hi Phil,

    So it is now working but isn't it counter intuitive that i have to give JLinkExe arguments relative as to where the current directory is rather than where IT is when launched? oO

    Relative Paths are interpreted as relative to the current working directory, not the location of the application launched.
    As for as I know, this has been the default for all programs I know, for all "important" operating Systems (MS Windows, macOS, Linux/Unix, FreeBSD).

    The script i was running was "r loadfile ~~~ r g exit". Which i would've expected to break instantly considering the Flasher was not connected to the target board.

    J-Link Commander is a development tool. We know that it is used in some automated / production scenarios, but we can not "endorse" this and strongly recommend to use J-Flash for production grade programming.
    J-Link Commander's return value depends on whether the last action executed(which sometimes is not the last command given by the user) returned success or fail.

    However, we introduced a command "eoe 1"/ command line switch "-ExitonError". When set, J-Link Commander will exit if an action fails and return 1 in order to indicate that an error has occurred.


    Best regards,
    Niklas
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • Sorry for the late reply,

    I accidently fried the Flasher ARM AND my motherboard yesterday :(

    So no further testing until we receive the replacement we ordered...

    I had started testing and saw the eoe command line argument, looks promising, but you say it will always return 1 on error?

    There is no exit code list to give us a bit more details on the error?

    the post i linked to in my original post has an answer saying it was a planned feature a year and a half ago!
  • Alright!

    Finally got around to ordering a replacement flasher and everything is working well with the -exitonerror 1 argument.

    It does however always return 1 whatever the error is, if the syntax of the script is wrong, the .hex's path or if i unplug the device halfway through the programming sequence.

    Is a more elaborate set of exit codes ever planned for JLink? like mentioned in the other forum post from 2015? Please? :)
  • Hi Phil,


    I am sorry, but for know, it has been decided not to put time into this in the near future.
    J-Link Commander is a handy tool for development and can be used for self-written scripts etc, but is not meant to be used in production.

    BTW: J-Link Commander's Source code is also included in the J-Link SDK.

    Best regards,
    Niklas
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • Alright thank you,

    Is there any product that include the SDK or it absolutely has to be bought separately?

    We currently have a Flasher ARM and a JLink Base, and will be ordering somewhere between 2-5 more JLink Base in a near future. Would this amount of business warrant supplying us with the SDK by any chance? (just taking a chance here :D )

    Another option I guess would be to ask, would it be possible to suggest a feature for JFlash to run completely in command line, without opening the GUI? The GUI is the only reason so far why I opted for JLink over JFlash for production.
  • Hi Phil,


    Another option I guess would be to ask, would it be possible to suggest a feature for JFlash to run completely in command line, without opening the GUI? The GUI is the only reason so far why I opted for JLink over JFlash for production.

    You can pass "/min" as a command line parameter to J-Flash.

    2-5 more JLink Base

    Please note that J-Link Base (unlike J-Link Plus / Ultra or Pro) does not include a license for J-Flash.

    Best regards,
    Niklas
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • From what I read though, /min simply keeps the GUI minimized but still opens it or am I mistaken?

    I have not tested the JLink Base with JFlash but having a license through the Flasher ARM won't allow us to run JFlash with all our segger products? JFlash will only run when connected to the Flasher but not the JLinks? If that is the case then I feel even more justified to use JLink instead since the price difference with the Flasher is substantial and we will not be using the stand alone function on most production stations.
  • Hi Phil,


    From what I read though, /min simply keeps the GUI minimized but still opens it or am I mistaken?

    That is correct.
    Could you please tell me what is the major drawback between minimized and "invisible" for your scenario?

    JFlash will only run when connected to the Flasher but not the JLinks?

    J-Flash will work with every J-Link or Flasher except J-Link Base and J-Link EDU.

    Therefore, at least J-Link PLUS is required to use J-Flash.

    Best regards,
    Niklas
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • The reason I need a full CLI is that I am implementing a production software in C# that handles all our production process, from programming the firmware to running tests on the pcb and validating those test results, printing labels with the product serial number, then saving product info with test results and serial number to a MySQL database. The handling of these steps is sequential and so I need to be able to launch the executable to program the firmware, redirect its output to my software's window, display meaningful error messages in the events of failure, or confirm success via exit code to proceed to the following steps.

    Simply starting JFlash minimized with arguments telling it what to program, does not provide me with an exit code upon completion , and does not close itself after its done its task.

    JLink provides most of these functionalities minus meaningful exit codes on failures. I am also not a fan of programmatically having to write the JScript file that it runs instead of giving it the hex's path via arguments but I can live with it, although with the SDK I would add support for the few script commands I use via arguments and completely skip the scripting process.

    As for JFlash licenses, I see in the web store that it is possible to purchase it on it's own, possibly to assign it to a JLink Base? In the event that this item was purchased , would it allow a single JLink Base to be used with JFlash , or all JLink Base devices? If its the latter , then why would the license provided with our Flasher ARM not be valid for those devices?



    Anyways, I do not mean to offend anyone at Segger by not wanting to use JFlash software, JLink simply fit my needs better. :)
  • Hi Phil,


    Simply starting JFlash minimized with arguments telling it what to program, does not provide me with an exit code upon completion , and does not close itself after its done its task.

    J-Flash quits automatically after the job is done if the parameter "-exit" is passed in the command line. J-Flash returns 0 for success. In case of Error, J-Flash sets ErrorLevel to 1 and returns a value >= 1.

    For further information, please refer to UM8003 J-Flash.

    As for JFlash licenses, I see in the web store that it is possible to purchase it on it's own, possibly to assign it to a JLink Base?

    J-Flash licenses can only be bought for a J-Link (you will be asked for the S/N of your J-Link Base if you order a J-Flash License).
    A J-Link Base + J-Flash license is more expensive than a J-Link PLUS, therefore ordering a J-Flash license only makes sense if you already own a J-Link Base.

    Best regards,
    Niklas
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • Alright so, single device per license, understood! :P

    Also good to know about the -exit argument for JFlash, but since it is running its GUI , is there any output text i can redirect to my software before it exits? And does it implement different exit codes representing more specific reasons for failures?

    Also , even though it would run minimized, would the small popup with 4 loading bars appear showing the erase/program/verify status & times? I like that it still appears in my current implementation with JLink even though i programmatically hide the console window and redirect its output. It is a nice visual queue that something is going on since the output redirected slightly differs from the output when ran via batch file.

    When ran via batch file the console window will display messages that includes erase time and programming time. The same(ish) script produces slightly shorter output when redirected to my C# software, I will add some screenshots to this post.

    Any idea why the output would be different when the command line arguments and JScript are the same?


    These are the arguments C# calls JLink with :

    -- once again code blocks completely destroy formatting so I added a third attachement --
    Images
    • batoutput_with_timers.png

      114.28 kB, 1,328×1,046, viewed 1,842 times
    • csharpoutput_no_timers.png

      80.36 kB, 797×726, viewed 1,345 times
    • processController.png

      48.85 kB, 1,047×943, viewed 1,142 times

    The post was edited 2 times, last by Philippe.Lahaie ().

  • Hi Phil,


    is there any output text i can redirect to my software before it exits? And does it implement different exit codes representing more specific reasons for failures?

    No, J-Flash only returns if an Error happened or not, since usually in production it does not immediately matter what exactly failed, but if it failed or succeeded.
    You can use the -jflashlog<FILENAME> " and the -jlinklog<FILENAME> parameter for failure analyses, pseudo code example:

    C Source Code

    1. while(Tasks) {
    2. TaskNR = getTaskInfo();
    3. [...] // Get other Task info like ProjectFile, Datafile etc.
    4. call ....../jflash.exe -openprj<FILENAME> -open<FILENAME> -jflashlogC:\Production\Temp\jflashlog.txt -auto /min -exit
    5. IF ERRORLEVEL (
    6. hError = open("C:\Production\ErrorLogs\FailedTasks.txt");
    7. hError.append("%s Task %d failed!", GetTime(), TaskNR);
    8. close(hError);
    9. copyfile(C:\Production\ErrorLogs\FailedTasks\JFlashLog_%TaskNR%.txt, C:\Production\Temp\jflashlog.txt)
    10. )
    11. Tasks--;
    12. }
    Display All


    Also , even though it would run minimized, would the small popup with 4 loading bars appear showing the erase/program/verify status & times? I like that it still appears in my current implementation with JLink even though i programmatically hide the console window and redirect its output. It is a nice visual queue that something is going on since the output redirected slightly differs from the output when ran via batch file.

    No, the progress bar is also minimized if "\min" is passed to J-Flash.


    When ran via batch file the console window will display messages that includes erase time and programming time. The same(ish) script produces slightly shorter output when redirected to my C# software, I will add some screenshots to this post.
    Any idea why the output would be different when the command line arguments and JScript are the same?

    Well, not only the timers are missing, but the complete output after "Found SWD-DP[...]" seems to be omitted.
    Unfortunately, I have no experience with C# at all, so I can only guess that you need to double check your output processing code.

    Best regards,
    Niklas
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • Thank you Niklas,

    I might do some testing with JFlash but so far JLink really suits my needs better, that error file definitely would be a plus though.

    The C# function to execute the process is pretty generalized, i can run it without redirecting the output and see if the omitted parts show up on the console that's launched, but the first part and the omitted parts should both be coming from the same source and thus redirected in the same way so it's hard to understand what could be wrong.

    Thanks again, I will report back in a bit :)