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?

1 Answer 1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .