3 ######################################################
4 # Copyright (C) 2016 Marvell International Ltd.
6 # SPDX-License-Identifier: GPL-2.0
7 # https://spdx.org/licenses
9 # Author: Konstantin Porotchkin kostap@marvell.com
13 # UART recovery downloader for Armada SoCs
15 ######################################################
22 default_baudrate=115200
23 tmpfile=/tmp/xmodem.pattern
24 tools=( dd stty sx minicom )
40 fast_baudrate=$default_baudrate
44 if [[ -z "$port" || -z "$file" ]]
46 echo -e "\nMarvell recovery image downloader for Armada SoC family."
47 echo -e "Command syntax:"
48 echo -e "\t$(basename $0) <port> <file> [2|4|8]"
49 echo -e "\tport - serial port the target board connected to"
50 echo -e "\tfile - recovery boot image for target download"
51 echo -e "\t2|4|8 - times to increase the default serial port speed by"
52 echo -e "For example - load the image over ttyUSB0 @ 460800 baud:"
53 echo -e "$(basename $0) /dev/ttyUSB0 /tmp/flash-image.bin 4\n"
54 echo -e "=====WARNING====="
55 echo -e "- The speed-up option is not awailable in SoC families prior to A8K+"
56 echo -e "- This utility is not compatible with Armada 37xx SoC family\n"
62 echo -e "Using device connected on serial port \"$port\""
64 echo "Wrong serial port name!"
70 echo -e "Loading flash image file \"$file\""
72 echo "File $file does not exist!"
76 # Verify required tools installation
77 for tool in ${tools[@]}
79 toolname=`which $tool`
82 echo -e "Missing installation of \"$tool\" --> Exiting"
88 echo -e "Recovery will run at $fast_baudrate baud"
89 echo -e "========================================"
96 # Send the escape sequence to target board using default debug port speed
97 stty -F $port raw ignbrk time 5 $default_baudrate
99 while [ $counter -lt $pattern_repeat ]; do
100 echo -n -e "$prefix\x11\x22\x33\x44\x55\x66\x77" >> $tmpfile
101 let counter=counter+1
104 echo -en "Press the \"Reset\" button on the target board and "
105 echo -en "the \"Enter\" key on the host keyboard simultaneously"
107 dd if=$tmpfile of=$port &>/dev/null
109 # Speed up the binary image transfer
110 stty -F $port raw ignbrk time 5 $fast_baudrate
111 sx -vv $file > $port < $port
114 # return the port to the default speed
115 stty -F $port raw ignbrk time 5 $default_baudrate
117 # Optional - fire up Minicom