[sw] add exit codes to uart_upload script

This commit is contained in:
stnolting 2024-06-14 14:49:16 +02:00
parent 035753b5cb
commit fbc73ae4bf

View file

@ -10,7 +10,7 @@ then
printf "Reset processor before starting the upload.\n\n"
printf "Usage: sh uart_upload.sh <serial port> <NEORV32 executable>\n"
printf "Example: sh uart_upload.sh /dev/ttyS6 path/to/project/neorv32_exe.bin\n"
exit
exit 0
fi
# configure serial port
@ -20,12 +20,12 @@ stty -F "$1" 19200 -hup raw -echo -echoe -echok -echoctl -echoke -ixon cs8 -csto
printf " " > $1 # send any char that triggers no command
# execute upload command and get response
exec 3<$1 # redirect serial output to fd 3
cat <&3 > uart_upload.response.tmp & # redirect serial output to file
PID=$! # save pid to kill cat
printf "u" > $1 # send upload command to serial port
sleep 0.5s # wait for bootloader response
kill $PID # kill cat process
exec 3<$1 # redirect serial output to fd 3
cat <&3 > uart_upload.response.tmp & # redirect serial output to file
PID=$! # save pid to kill cat later
printf "u" > $1 # send upload command to serial port
sleep 0.5s # wait for bootloader response
kill $PID # kill cat process
exec 3<&- # free fd 3
@ -35,17 +35,17 @@ then
printf "Bootloader response error!\n"
printf "Reset processor before starting the upload.\n"
rm -f uart_upload.response.tmp
exit
exit 1
fi
# send executable and get response
printf "Uploading executable..."
exec 3<$1 # redirect serial output to fd 3
cat <&3 > uart_upload.response.tmp & # redirect serial output to file
PID=$! # save pid to kill cat
cat "$2" > "$1" # send executable to serial port
sleep 3s # wait for bootloader response
kill $PID # kill cat process
exec 3<$1 # redirect serial output to fd 3
cat <&3 > uart_upload.response.tmp & # redirect serial output to file
PID=$! # save pid to kill cat later
cat "$2" > "$1" # send executable to serial port
sleep 3s # wait for bootloader response
kill $PID # kill cat process
exec 3<&- # free fd 3
@ -53,11 +53,12 @@ exec 3<&- # free fd 3
if ! grep -Fq "OK" uart_upload.response.tmp;
then
printf " FAILED!\n"
rm -f uart_upload.response.tmp
exit 1
else
printf " OK\n"
echo "Starting application..."
printf "e" > $1
rm -f uart_upload.response.tmp
exit 0
fi
rm -f uart_upload.response.tmp
exit