xref: /openbmc/u-boot/tools/mrvl_uart.sh (revision 83d290c56fab2d38cd1ab4c4cc7099559c1d5046)
1eee4835dSKonstantin Porotchkin#!/bin/bash
2*83d290c5STom Rini# SPDX-License-Identifier: GPL-2.0
3eee4835dSKonstantin Porotchkin#
4eee4835dSKonstantin Porotchkin######################################################
5eee4835dSKonstantin Porotchkin# Copyright (C) 2016 Marvell International Ltd.
6eee4835dSKonstantin Porotchkin#
7eee4835dSKonstantin Porotchkin# https://spdx.org/licenses
8eee4835dSKonstantin Porotchkin#
9eee4835dSKonstantin Porotchkin# Author: Konstantin Porotchkin kostap@marvell.com
10eee4835dSKonstantin Porotchkin#
11eee4835dSKonstantin Porotchkin# Version 0.3
12eee4835dSKonstantin Porotchkin#
13eee4835dSKonstantin Porotchkin# UART recovery downloader for Armada SoCs
14eee4835dSKonstantin Porotchkin#
15eee4835dSKonstantin Porotchkin######################################################
16eee4835dSKonstantin Porotchkin
17eee4835dSKonstantin Porotchkinport=$1
18eee4835dSKonstantin Porotchkinfile=$2
19eee4835dSKonstantin Porotchkinspeed=$3
20eee4835dSKonstantin Porotchkin
21eee4835dSKonstantin Porotchkinpattern_repeat=1500
22eee4835dSKonstantin Porotchkindefault_baudrate=115200
23eee4835dSKonstantin Porotchkintmpfile=/tmp/xmodem.pattern
24eee4835dSKonstantin Porotchkintools=( dd stty sx minicom )
25eee4835dSKonstantin Porotchkin
26eee4835dSKonstantin Porotchkincase "$3" in
27eee4835dSKonstantin Porotchkin    2)
28eee4835dSKonstantin Porotchkin        fast_baudrate=230400
29eee4835dSKonstantin Porotchkin        prefix="\xF2"
30eee4835dSKonstantin Porotchkin        ;;
31eee4835dSKonstantin Porotchkin    4)
32eee4835dSKonstantin Porotchkin        fast_baudrate=460800
33eee4835dSKonstantin Porotchkin        prefix="\xF4"
34eee4835dSKonstantin Porotchkin        ;;
35eee4835dSKonstantin Porotchkin    8)
36eee4835dSKonstantin Porotchkin    	fast_baudrate=921600
37eee4835dSKonstantin Porotchkin        prefix="\xF8"
38eee4835dSKonstantin Porotchkin        ;;
39eee4835dSKonstantin Porotchkin    *)
40eee4835dSKonstantin Porotchkin    	fast_baudrate=$default_baudrate
41eee4835dSKonstantin Porotchkin        prefix="\xBB"
42eee4835dSKonstantin Porotchkinesac
43eee4835dSKonstantin Porotchkin
44eee4835dSKonstantin Porotchkinif [[ -z "$port" || -z "$file" ]]
45eee4835dSKonstantin Porotchkinthen
46eee4835dSKonstantin Porotchkin    echo -e "\nMarvell recovery image downloader for Armada SoC family."
47eee4835dSKonstantin Porotchkin    echo -e "Command syntax:"
48eee4835dSKonstantin Porotchkin    echo -e "\t$(basename $0) <port> <file> [2|4|8]"
49ceb32818SAndreas Färber    echo -e "\tport  - serial port the target board is connected to"
50eee4835dSKonstantin Porotchkin    echo -e "\tfile  - recovery boot image for target download"
51eee4835dSKonstantin Porotchkin    echo -e "\t2|4|8 - times to increase the default serial port speed by"
52eee4835dSKonstantin Porotchkin    echo -e "For example - load the image over ttyUSB0 @ 460800 baud:"
53eee4835dSKonstantin Porotchkin    echo -e "$(basename $0) /dev/ttyUSB0 /tmp/flash-image.bin 4\n"
54eee4835dSKonstantin Porotchkin    echo -e "=====WARNING====="
55ceb32818SAndreas Färber    echo -e "- The speed-up option is not available in SoC families prior to A8K+"
56eee4835dSKonstantin Porotchkin    echo -e "- This utility is not compatible with Armada 37xx SoC family\n"
57eee4835dSKonstantin Porotchkinfi
58eee4835dSKonstantin Porotchkin
59eee4835dSKonstantin Porotchkin# Sanity checks
60eee4835dSKonstantin Porotchkinif [ -c "$port" ]
61eee4835dSKonstantin Porotchkinthen
62eee4835dSKonstantin Porotchkin   echo -e "Using device connected on serial port \"$port\""
63eee4835dSKonstantin Porotchkinelse
64eee4835dSKonstantin Porotchkin   echo "Wrong serial port name!"
65eee4835dSKonstantin Porotchkin   exit 1
66eee4835dSKonstantin Porotchkinfi
67eee4835dSKonstantin Porotchkin
68eee4835dSKonstantin Porotchkinif [ -f "$file" ]
69eee4835dSKonstantin Porotchkinthen
70eee4835dSKonstantin Porotchkin   echo -e "Loading flash image file \"$file\""
71eee4835dSKonstantin Porotchkinelse
72eee4835dSKonstantin Porotchkin   echo "File $file does not exist!"
73eee4835dSKonstantin Porotchkin   exit 1
74eee4835dSKonstantin Porotchkinfi
75eee4835dSKonstantin Porotchkin
76eee4835dSKonstantin Porotchkin# Verify required tools installation
77eee4835dSKonstantin Porotchkinfor tool in ${tools[@]}
78eee4835dSKonstantin Porotchkindo
79eee4835dSKonstantin Porotchkin    toolname=`which $tool`
80eee4835dSKonstantin Porotchkin    if [ -z "$toolname" ]
81eee4835dSKonstantin Porotchkin    then
82eee4835dSKonstantin Porotchkin        echo -e "Missing installation of \"$tool\" --> Exiting"
83eee4835dSKonstantin Porotchkin        exit 1
84eee4835dSKonstantin Porotchkin    fi
85eee4835dSKonstantin Porotchkindone
86eee4835dSKonstantin Porotchkin
87eee4835dSKonstantin Porotchkin
88eee4835dSKonstantin Porotchkinecho -e "Recovery will run at $fast_baudrate baud"
89eee4835dSKonstantin Porotchkinecho -e "========================================"
90eee4835dSKonstantin Porotchkin
91eee4835dSKonstantin Porotchkinif [ -f "$tmpfile" ]
92eee4835dSKonstantin Porotchkinthen
93eee4835dSKonstantin Porotchkin    rm -f $tmpfile
94eee4835dSKonstantin Porotchkinfi
95eee4835dSKonstantin Porotchkin
96eee4835dSKonstantin Porotchkin# Send the escape sequence to target board using default debug port speed
97eee4835dSKonstantin Porotchkinstty -F $port raw ignbrk time 5 $default_baudrate
98eee4835dSKonstantin Porotchkincounter=0
99eee4835dSKonstantin Porotchkinwhile [ $counter -lt $pattern_repeat ]; do
100eee4835dSKonstantin Porotchkin    echo -n -e "$prefix\x11\x22\x33\x44\x55\x66\x77" >> $tmpfile
101eee4835dSKonstantin Porotchkin    let counter=counter+1
102eee4835dSKonstantin Porotchkindone
103eee4835dSKonstantin Porotchkin
104eee4835dSKonstantin Porotchkinecho -en "Press the \"Reset\" button on the target board and "
105eee4835dSKonstantin Porotchkinecho -en "the \"Enter\" key on the host keyboard simultaneously"
106eee4835dSKonstantin Porotchkinread
107eee4835dSKonstantin Porotchkindd if=$tmpfile of=$port &>/dev/null
108eee4835dSKonstantin Porotchkin
109eee4835dSKonstantin Porotchkin# Speed up the binary image transfer
110eee4835dSKonstantin Porotchkinstty -F $port raw ignbrk time 5 $fast_baudrate
111eee4835dSKonstantin Porotchkinsx -vv $file > $port < $port
112eee4835dSKonstantin Porotchkin#sx-at91 $port $file
113eee4835dSKonstantin Porotchkin
114ceb32818SAndreas Färber# Return the port to the default speed
115eee4835dSKonstantin Porotchkinstty -F $port raw ignbrk time 5 $default_baudrate
116eee4835dSKonstantin Porotchkin
117eee4835dSKonstantin Porotchkin# Optional - fire up Minicom
1183e00c48eSAndreas Färberminicom -D $port -b $default_baudrate
119eee4835dSKonstantin Porotchkin
120