Konstantin Porotchkin | 8c9012a | 2017-11-30 16:10:09 +0200 | [diff] [blame] | 1 | #!/bin/bash |
Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 2 | # SPDX-License-Identifier: GPL-2.0 |
Konstantin Porotchkin | 8c9012a | 2017-11-30 16:10:09 +0200 | [diff] [blame] | 3 | # |
| 4 | ###################################################### |
| 5 | # Copyright (C) 2016 Marvell International Ltd. |
| 6 | # |
Konstantin Porotchkin | 8c9012a | 2017-11-30 16:10:09 +0200 | [diff] [blame] | 7 | # https://spdx.org/licenses |
| 8 | # |
| 9 | # Author: Konstantin Porotchkin kostap@marvell.com |
| 10 | # |
| 11 | # Version 0.3 |
| 12 | # |
| 13 | # UART recovery downloader for Armada SoCs |
| 14 | # |
| 15 | ###################################################### |
| 16 | |
| 17 | port=$1 |
| 18 | file=$2 |
| 19 | speed=$3 |
| 20 | |
| 21 | pattern_repeat=1500 |
| 22 | default_baudrate=115200 |
| 23 | tmpfile=/tmp/xmodem.pattern |
| 24 | tools=( dd stty sx minicom ) |
| 25 | |
| 26 | case "$3" in |
| 27 | 2) |
| 28 | fast_baudrate=230400 |
| 29 | prefix="\xF2" |
| 30 | ;; |
| 31 | 4) |
| 32 | fast_baudrate=460800 |
| 33 | prefix="\xF4" |
| 34 | ;; |
| 35 | 8) |
| 36 | fast_baudrate=921600 |
| 37 | prefix="\xF8" |
| 38 | ;; |
| 39 | *) |
| 40 | fast_baudrate=$default_baudrate |
| 41 | prefix="\xBB" |
| 42 | esac |
| 43 | |
| 44 | if [[ -z "$port" || -z "$file" ]] |
| 45 | then |
| 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]" |
Andreas Färber | 88f89b1 | 2018-01-20 13:18:39 +0100 | [diff] [blame] | 49 | echo -e "\tport - serial port the target board is connected to" |
Konstantin Porotchkin | 8c9012a | 2017-11-30 16:10:09 +0200 | [diff] [blame] | 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=====" |
Andreas Färber | 88f89b1 | 2018-01-20 13:18:39 +0100 | [diff] [blame] | 55 | echo -e "- The speed-up option is not available in SoC families prior to A8K+" |
Konstantin Porotchkin | 8c9012a | 2017-11-30 16:10:09 +0200 | [diff] [blame] | 56 | echo -e "- This utility is not compatible with Armada 37xx SoC family\n" |
| 57 | fi |
| 58 | |
| 59 | # Sanity checks |
| 60 | if [ -c "$port" ] |
| 61 | then |
| 62 | echo -e "Using device connected on serial port \"$port\"" |
| 63 | else |
| 64 | echo "Wrong serial port name!" |
| 65 | exit 1 |
| 66 | fi |
| 67 | |
| 68 | if [ -f "$file" ] |
| 69 | then |
| 70 | echo -e "Loading flash image file \"$file\"" |
| 71 | else |
| 72 | echo "File $file does not exist!" |
| 73 | exit 1 |
| 74 | fi |
| 75 | |
| 76 | # Verify required tools installation |
| 77 | for tool in ${tools[@]} |
| 78 | do |
| 79 | toolname=`which $tool` |
| 80 | if [ -z "$toolname" ] |
| 81 | then |
| 82 | echo -e "Missing installation of \"$tool\" --> Exiting" |
| 83 | exit 1 |
| 84 | fi |
| 85 | done |
| 86 | |
| 87 | |
| 88 | echo -e "Recovery will run at $fast_baudrate baud" |
| 89 | echo -e "========================================" |
| 90 | |
| 91 | if [ -f "$tmpfile" ] |
| 92 | then |
| 93 | rm -f $tmpfile |
| 94 | fi |
| 95 | |
| 96 | # Send the escape sequence to target board using default debug port speed |
| 97 | stty -F $port raw ignbrk time 5 $default_baudrate |
| 98 | counter=0 |
| 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 |
| 102 | done |
| 103 | |
| 104 | echo -en "Press the \"Reset\" button on the target board and " |
| 105 | echo -en "the \"Enter\" key on the host keyboard simultaneously" |
| 106 | read |
| 107 | dd if=$tmpfile of=$port &>/dev/null |
| 108 | |
| 109 | # Speed up the binary image transfer |
| 110 | stty -F $port raw ignbrk time 5 $fast_baudrate |
| 111 | sx -vv $file > $port < $port |
| 112 | #sx-at91 $port $file |
| 113 | |
Andreas Färber | 88f89b1 | 2018-01-20 13:18:39 +0100 | [diff] [blame] | 114 | # Return the port to the default speed |
Konstantin Porotchkin | 8c9012a | 2017-11-30 16:10:09 +0200 | [diff] [blame] | 115 | stty -F $port raw ignbrk time 5 $default_baudrate |
| 116 | |
| 117 | # Optional - fire up Minicom |
Andreas Färber | fd6bbed | 2018-01-20 13:07:09 +0100 | [diff] [blame] | 118 | minicom -D $port -b $default_baudrate |
Konstantin Porotchkin | 8c9012a | 2017-11-30 16:10:09 +0200 | [diff] [blame] | 119 | |