[Bash] Automated flashing OpenWrt - problem with tty connection

Hello, I want to build a piece of hard- and software, that could flash a target fully automated by running a bash script.

Currently I am working with the Xiaomi Mi Router 4A, but later on it should be some kind of universal flashing tool. So that the user does not need to know much about how to flash a target with OpenWrt.

It takes 3 Steps for getting OpenWrt running on the Xiaomi.

  1. Unlock bootloader by changing the "bootmenu-show-delay-time" from '0' to n seconds. This part is working.

  2. Listen to the UART communication, wait for the bootmenu to appear and choose the tftp-bootoption.
    This is the part where I am struggling on...

  3. When tftp boot is done, just do a sysupgrade.
    That part is also done.

My Problem:
I am trying to capture the ttyUSB / UART input with stty + exec and send commands when the bootmenu is showing. Im able to "detect" the bootmenu-string.

But the weird thing is, that the xiaomi does not care about my input-commands. It also does not wait until the bootmenu-show-delay-time is over. It just runs through with the standard boot option.

But when using minicom, it does count down the bootmenu-show-delay-time and I am able to input data.

Does anyone know, what I´m doing wrong? I suppose that it has something to do with stty but I have no clue, maybe a special option is missing?

the code:

A long, long time ago, I used a program called "expect" to automate some "dialoguing with a device".

1 Like

Thank you.

At the end, It worked like this for me:

echo -n "1" >&5 # echo '1' for taking boot option 1