diff mbox series

[U-Boot] tools: Add Marvell recovery image download script

Message ID 1512051009-13641-1-git-send-email-kostap@marvell.com
State Accepted
Commit eee4835d22e96d517f60a8260f002abe4a5d16d8
Delegated to: Stefan Roese
Headers show
Series [U-Boot] tools: Add Marvell recovery image download script | expand

Commit Message

Kostya Porotchkin Nov. 30, 2017, 2:10 p.m. UTC
From: Konstantin Porotchkin <kostap@marvell.com>

Introduce the recovery image download script for usage with
Marvell Armada SoC families (excepting 37xx family).
Since Marvell BootROM uses a sliding window in UART buffer
for detecting escape sequence during the boot, it's easier
to interrupt the normal boot flow by sending a long stream
of chained escape sequences to the serial port instead of
periodically sending a single escape sequence as it is done
by kwboot utility.
Additional benefit of using this script is the ability to
adjust the escape sequence stream length withoiut need for
compilation.

Signed-off-by: Konstantin Porotchkin <kostap@marvell.com>
Cc: Stefan Roese <sr@denx.de>
Cc: Igal Liberman <igall@marvell.com>
---
 tools/mrvl_uart.sh | 119 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 119 insertions(+)
 create mode 100755 tools/mrvl_uart.sh

Comments

Stefan Roese Jan. 10, 2018, 11:31 a.m. UTC | #1
On 30.11.2017 15:10, kostap@marvell.com wrote:
> From: Konstantin Porotchkin <kostap@marvell.com>
> 
> Introduce the recovery image download script for usage with
> Marvell Armada SoC families (excepting 37xx family).
> Since Marvell BootROM uses a sliding window in UART buffer
> for detecting escape sequence during the boot, it's easier
> to interrupt the normal boot flow by sending a long stream
> of chained escape sequences to the serial port instead of
> periodically sending a single escape sequence as it is done
> by kwboot utility.
> Additional benefit of using this script is the ability to
> adjust the escape sequence stream length withoiut need for
> compilation.
> 
> Signed-off-by: Konstantin Porotchkin <kostap@marvell.com>
> Cc: Stefan Roese <sr@denx.de>
> Cc: Igal Liberman <igall@marvell.com>

Applied to u-boot-marvell/master

Thanks,
Stefan
diff mbox series

Patch

diff --git a/tools/mrvl_uart.sh b/tools/mrvl_uart.sh
new file mode 100755
index 0000000..6b04d7a
--- /dev/null
+++ b/tools/mrvl_uart.sh
@@ -0,0 +1,119 @@ 
+#!/bin/bash
+#
+######################################################
+# Copyright (C) 2016 Marvell International Ltd.
+#
+# SPDX-License-Identifier:	GPL-2.0
+# https://spdx.org/licenses
+#
+# Author: Konstantin Porotchkin kostap@marvell.com
+#
+# Version 0.3
+#
+# UART recovery downloader for Armada SoCs
+#
+######################################################
+
+port=$1
+file=$2
+speed=$3
+
+pattern_repeat=1500
+default_baudrate=115200
+tmpfile=/tmp/xmodem.pattern
+tools=( dd stty sx minicom )
+
+case "$3" in
+    2)
+        fast_baudrate=230400
+        prefix="\xF2"
+        ;;
+    4)
+        fast_baudrate=460800
+        prefix="\xF4"
+        ;;
+    8)
+    	fast_baudrate=921600
+        prefix="\xF8"
+        ;;
+    *)
+    	fast_baudrate=$default_baudrate
+        prefix="\xBB"
+esac
+
+if [[ -z "$port" || -z "$file" ]]
+then
+    echo -e "\nMarvell recovery image downloader for Armada SoC family."
+    echo -e "Command syntax:"
+    echo -e "\t$(basename $0) <port> <file> [2|4|8]"
+    echo -e "\tport  - serial port the target board connected to"
+    echo -e "\tfile  - recovery boot image for target download"
+    echo -e "\t2|4|8 - times to increase the default serial port speed by"
+    echo -e "For example - load the image over ttyUSB0 @ 460800 baud:"
+    echo -e "$(basename $0) /dev/ttyUSB0 /tmp/flash-image.bin 4\n"
+    echo -e "=====WARNING====="
+    echo -e "- The speed-up option is not awailable in SoC families prior to A8K+"
+    echo -e "- This utility is not compatible with Armada 37xx SoC family\n"
+fi
+
+# Sanity checks
+if [ -c "$port" ]
+then
+   echo -e "Using device connected on serial port \"$port\""
+else
+   echo "Wrong serial port name!"
+   exit 1
+fi
+
+if [ -f "$file" ]
+then
+   echo -e "Loading flash image file \"$file\""
+else
+   echo "File $file does not exist!"
+   exit 1
+fi
+
+# Verify required tools installation
+for tool in ${tools[@]}
+do
+    toolname=`which $tool`
+    if [ -z "$toolname" ]
+    then
+        echo -e "Missing installation of \"$tool\" --> Exiting"
+        exit 1
+    fi
+done
+
+
+echo -e "Recovery will run at $fast_baudrate baud"
+echo -e "========================================"
+
+if [ -f "$tmpfile" ]
+then
+    rm -f $tmpfile
+fi
+
+# Send the escape sequence to target board using default debug port speed
+stty -F $port raw ignbrk time 5 $default_baudrate
+counter=0
+while [ $counter -lt $pattern_repeat ]; do
+    echo -n -e "$prefix\x11\x22\x33\x44\x55\x66\x77" >> $tmpfile
+    let counter=counter+1
+done
+
+echo -en "Press the \"Reset\" button on the target board and "
+echo -en "the \"Enter\" key on the host keyboard simultaneously"
+read
+dd if=$tmpfile of=$port &>/dev/null
+
+# Speed up the binary image transfer
+stty -F $port raw ignbrk time 5 $fast_baudrate
+sx -vv $file > $port < $port
+#sx-at91 $port $file
+
+# return the port to the default speed
+stty -F $port raw ignbrk time 5 $default_baudrate
+
+# Optional - fire up Minicom
+minicom -D $port
+