How can I halt a boot over serial when a prompt is displayed?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












0














I have a computer that I'm connected to via serial. I want to stop it as it boots up as part of a bash script. The computer issues a prompt along with a short time window to push a key to halt the boot process and go to a uboot command line.



My current solution is to read lines from the serial device and stop reading when the prompt is displayed. I then echo a single character to the device like this.



prompt="any key to stop autoboot"
prompted=false
fline=""
while [ "$prompted" == "false" ] && read fline
do
echo $fline
if [[ "$fline" =~ "$prompt" ]]
then
prompted=true
fi
done < /dev/ttyUSB0

echo a > /dev/ttyUSB0


But when I use minicom to serial back in, I am unable to see the prompt or issue commands, and the computer boots anyway. I know the loop ends when the prompt is displayed as well, as the prompt is the last line displayed. If I start the whole process from a minicom terminal and respond to the prompt manually, then the boot stops and I can see the prompt and issue commands.



I have a workaround via the following code, but this isn't a very precise solution.



# start computer, then do
for i in `seq 1 1000`
do
echo hi > /dev/ttyUSB0
usleep 10000
done


But upon completion I can use minicom to see the uboot prompt and issue commands. I can also issue commands by echoing bytes to the serial device, and their results appear in my minicom session. So this approach proves I can halt the boot by echoing bytes to the serial device.



So how can I stop the boot when the prompt is displayed?










share|improve this question


























    0














    I have a computer that I'm connected to via serial. I want to stop it as it boots up as part of a bash script. The computer issues a prompt along with a short time window to push a key to halt the boot process and go to a uboot command line.



    My current solution is to read lines from the serial device and stop reading when the prompt is displayed. I then echo a single character to the device like this.



    prompt="any key to stop autoboot"
    prompted=false
    fline=""
    while [ "$prompted" == "false" ] && read fline
    do
    echo $fline
    if [[ "$fline" =~ "$prompt" ]]
    then
    prompted=true
    fi
    done < /dev/ttyUSB0

    echo a > /dev/ttyUSB0


    But when I use minicom to serial back in, I am unable to see the prompt or issue commands, and the computer boots anyway. I know the loop ends when the prompt is displayed as well, as the prompt is the last line displayed. If I start the whole process from a minicom terminal and respond to the prompt manually, then the boot stops and I can see the prompt and issue commands.



    I have a workaround via the following code, but this isn't a very precise solution.



    # start computer, then do
    for i in `seq 1 1000`
    do
    echo hi > /dev/ttyUSB0
    usleep 10000
    done


    But upon completion I can use minicom to see the uboot prompt and issue commands. I can also issue commands by echoing bytes to the serial device, and their results appear in my minicom session. So this approach proves I can halt the boot by echoing bytes to the serial device.



    So how can I stop the boot when the prompt is displayed?










    share|improve this question
























      0












      0








      0







      I have a computer that I'm connected to via serial. I want to stop it as it boots up as part of a bash script. The computer issues a prompt along with a short time window to push a key to halt the boot process and go to a uboot command line.



      My current solution is to read lines from the serial device and stop reading when the prompt is displayed. I then echo a single character to the device like this.



      prompt="any key to stop autoboot"
      prompted=false
      fline=""
      while [ "$prompted" == "false" ] && read fline
      do
      echo $fline
      if [[ "$fline" =~ "$prompt" ]]
      then
      prompted=true
      fi
      done < /dev/ttyUSB0

      echo a > /dev/ttyUSB0


      But when I use minicom to serial back in, I am unable to see the prompt or issue commands, and the computer boots anyway. I know the loop ends when the prompt is displayed as well, as the prompt is the last line displayed. If I start the whole process from a minicom terminal and respond to the prompt manually, then the boot stops and I can see the prompt and issue commands.



      I have a workaround via the following code, but this isn't a very precise solution.



      # start computer, then do
      for i in `seq 1 1000`
      do
      echo hi > /dev/ttyUSB0
      usleep 10000
      done


      But upon completion I can use minicom to see the uboot prompt and issue commands. I can also issue commands by echoing bytes to the serial device, and their results appear in my minicom session. So this approach proves I can halt the boot by echoing bytes to the serial device.



      So how can I stop the boot when the prompt is displayed?










      share|improve this question













      I have a computer that I'm connected to via serial. I want to stop it as it boots up as part of a bash script. The computer issues a prompt along with a short time window to push a key to halt the boot process and go to a uboot command line.



      My current solution is to read lines from the serial device and stop reading when the prompt is displayed. I then echo a single character to the device like this.



      prompt="any key to stop autoboot"
      prompted=false
      fline=""
      while [ "$prompted" == "false" ] && read fline
      do
      echo $fline
      if [[ "$fline" =~ "$prompt" ]]
      then
      prompted=true
      fi
      done < /dev/ttyUSB0

      echo a > /dev/ttyUSB0


      But when I use minicom to serial back in, I am unable to see the prompt or issue commands, and the computer boots anyway. I know the loop ends when the prompt is displayed as well, as the prompt is the last line displayed. If I start the whole process from a minicom terminal and respond to the prompt manually, then the boot stops and I can see the prompt and issue commands.



      I have a workaround via the following code, but this isn't a very precise solution.



      # start computer, then do
      for i in `seq 1 1000`
      do
      echo hi > /dev/ttyUSB0
      usleep 10000
      done


      But upon completion I can use minicom to see the uboot prompt and issue commands. I can also issue commands by echoing bytes to the serial device, and their results appear in my minicom session. So this approach proves I can halt the boot by echoing bytes to the serial device.



      So how can I stop the boot when the prompt is displayed?







      serial-console minicom






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 27 '18 at 4:27









      DeepDeadpoolDeepDeadpool

      275311




      275311




















          1 Answer
          1






          active

          oldest

          votes


















          0














          I figured it out just as I was about to post the question.



          The "read" command as I have it in my first loop will only show the line after a newline appears on the console. This means my script couldn't respond to the prompt until after a new line appeared; meaning the window was now over.



          To fix this, I changed the check to look for the line that appeared above the actual prompt, followed by a 1/100th second sleep before issuing my write.



          This solution allows me to halt the boot processes automatically.






          share|improve this answer




















            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "106"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f491070%2fhow-can-i-halt-a-boot-over-serial-when-a-prompt-is-displayed%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            I figured it out just as I was about to post the question.



            The "read" command as I have it in my first loop will only show the line after a newline appears on the console. This means my script couldn't respond to the prompt until after a new line appeared; meaning the window was now over.



            To fix this, I changed the check to look for the line that appeared above the actual prompt, followed by a 1/100th second sleep before issuing my write.



            This solution allows me to halt the boot processes automatically.






            share|improve this answer

























              0














              I figured it out just as I was about to post the question.



              The "read" command as I have it in my first loop will only show the line after a newline appears on the console. This means my script couldn't respond to the prompt until after a new line appeared; meaning the window was now over.



              To fix this, I changed the check to look for the line that appeared above the actual prompt, followed by a 1/100th second sleep before issuing my write.



              This solution allows me to halt the boot processes automatically.






              share|improve this answer























                0












                0








                0






                I figured it out just as I was about to post the question.



                The "read" command as I have it in my first loop will only show the line after a newline appears on the console. This means my script couldn't respond to the prompt until after a new line appeared; meaning the window was now over.



                To fix this, I changed the check to look for the line that appeared above the actual prompt, followed by a 1/100th second sleep before issuing my write.



                This solution allows me to halt the boot processes automatically.






                share|improve this answer












                I figured it out just as I was about to post the question.



                The "read" command as I have it in my first loop will only show the line after a newline appears on the console. This means my script couldn't respond to the prompt until after a new line appeared; meaning the window was now over.



                To fix this, I changed the check to look for the line that appeared above the actual prompt, followed by a 1/100th second sleep before issuing my write.



                This solution allows me to halt the boot processes automatically.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 27 '18 at 4:29









                DeepDeadpoolDeepDeadpool

                275311




                275311



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Unix & Linux Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f491070%2fhow-can-i-halt-a-boot-over-serial-when-a-prompt-is-displayed%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown






                    Popular posts from this blog

                    Peggy Mitchell

                    Palaiologos

                    The Forum (Inglewood, California)