mirror of
https://github.com/stnolting/neorv32.git
synced 2025-04-24 06:07:52 -04:00
[sw/image_gen] added script to directly upload an executable to the bootloader from the console
This commit is contained in:
parent
c18d564c6c
commit
c31cf18680
1 changed files with 58 additions and 0 deletions
58
sw/image_gen/uart_upload.sh
Normal file
58
sw/image_gen/uart_upload.sh
Normal file
|
@ -0,0 +1,58 @@
|
|||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
# Simple script to upload executable to bootloader
|
||||
|
||||
if [ $# -ne 2 ]
|
||||
then
|
||||
echo "Upload image via serial port (UART) to the NEORV32 bootloader."
|
||||
echo "Reset processor before starting the upload."
|
||||
echo "Usage: [sudo] sh uart_upload.sh <tty> <file>"
|
||||
echo "Example: sh uart_upload.sh /dev/ttyS6 neorv32_exe.bin"
|
||||
exit
|
||||
fi
|
||||
|
||||
# configure serial port
|
||||
stty -F "$1" 19200 -hup raw -echo -echoe -echok -echoctl -echoke -crtscts cs8 -cstopb noflsh
|
||||
|
||||
# trigger fast upload mode and get response
|
||||
exec 3<$1 # redirect serial output to fd 3
|
||||
cat <&3 > uart_upload.response.dat & # redirect serial output to file
|
||||
PID=$! # save pid to kill cat
|
||||
printf "#" > $1 # send fast/silent upload to serial port
|
||||
sleep 0.5s # wait for bootloader response
|
||||
kill $PID # kill cat process
|
||||
|
||||
exec 3<&- # free fd 3
|
||||
|
||||
# check response
|
||||
if ! grep -Fq "Awaiting neorv32_exe.bin" uart_upload.response.dat;
|
||||
then
|
||||
echo "Bootloader response error."
|
||||
echo "Reset processor before starting the upload."
|
||||
rm -f uart_upload.response.dat
|
||||
exit
|
||||
fi
|
||||
|
||||
# send executable and get repsonse
|
||||
echo -n "Uploading... "
|
||||
exec 3<$1 # redirect serial output to fd 3
|
||||
cat <&3 > uart_upload.response.dat & # redirect serial output to file
|
||||
PID=$! # save pid to kill cat
|
||||
cat "$2" > "$1" # send executable to serial port
|
||||
sleep 0.5s # wait for bootloader response
|
||||
kill $PID # kill cat process
|
||||
|
||||
exec 3<&- # free fd 3
|
||||
|
||||
# check response
|
||||
if ! grep -Fq "OK" uart_upload.response.dat;
|
||||
then
|
||||
echo "Upload error."
|
||||
rm -f uart_upload.response.dat
|
||||
exit
|
||||
fi
|
||||
|
||||
rm -f uart_upload.response.dat
|
||||
echo "Done."
|
Loading…
Add table
Add a link
Reference in a new issue