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?