mrvl_uart.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-2.0
  3. #
  4. ######################################################
  5. # Copyright (C) 2016 Marvell International Ltd.
  6. #
  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. port=$1
  17. file=$2
  18. speed=$3
  19. pattern_repeat=1500
  20. default_baudrate=115200
  21. tmpfile=/tmp/xmodem.pattern
  22. tools=( dd stty sx minicom )
  23. case "$3" in
  24. 2)
  25. fast_baudrate=230400
  26. prefix="\xF2"
  27. ;;
  28. 4)
  29. fast_baudrate=460800
  30. prefix="\xF4"
  31. ;;
  32. 8)
  33. fast_baudrate=921600
  34. prefix="\xF8"
  35. ;;
  36. *)
  37. fast_baudrate=$default_baudrate
  38. prefix="\xBB"
  39. esac
  40. if [[ -z "$port" || -z "$file" ]]
  41. then
  42. echo -e "\nMarvell recovery image downloader for Armada SoC family."
  43. echo -e "Command syntax:"
  44. echo -e "\t$(basename $0) <port> <file> [2|4|8]"
  45. echo -e "\tport - serial port the target board is connected to"
  46. echo -e "\tfile - recovery boot image for target download"
  47. echo -e "\t2|4|8 - times to increase the default serial port speed by"
  48. echo -e "For example - load the image over ttyUSB0 @ 460800 baud:"
  49. echo -e "$(basename $0) /dev/ttyUSB0 /tmp/flash-image.bin 4\n"
  50. echo -e "=====WARNING====="
  51. echo -e "- The speed-up option is not available in SoC families prior to A8K+"
  52. echo -e "- This utility is not compatible with Armada 37xx SoC family\n"
  53. fi
  54. # Sanity checks
  55. if [ -c "$port" ]
  56. then
  57. echo -e "Using device connected on serial port \"$port\""
  58. else
  59. echo "Wrong serial port name!"
  60. exit 1
  61. fi
  62. if [ -f "$file" ]
  63. then
  64. echo -e "Loading flash image file \"$file\""
  65. else
  66. echo "File $file does not exist!"
  67. exit 1
  68. fi
  69. # Verify required tools installation
  70. for tool in ${tools[@]}
  71. do
  72. toolname=`which $tool`
  73. if [ -z "$toolname" ]
  74. then
  75. echo -e "Missing installation of \"$tool\" --> Exiting"
  76. exit 1
  77. fi
  78. done
  79. echo -e "Recovery will run at $fast_baudrate baud"
  80. echo -e "========================================"
  81. if [ -f "$tmpfile" ]
  82. then
  83. rm -f $tmpfile
  84. fi
  85. # Send the escape sequence to target board using default debug port speed
  86. stty -F $port raw ignbrk time 5 $default_baudrate
  87. counter=0
  88. while [ $counter -lt $pattern_repeat ]; do
  89. echo -n -e "$prefix\x11\x22\x33\x44\x55\x66\x77" >> $tmpfile
  90. let counter=counter+1
  91. done
  92. echo -en "Press the \"Reset\" button on the target board and "
  93. echo -en "the \"Enter\" key on the host keyboard simultaneously"
  94. read
  95. dd if=$tmpfile of=$port &>/dev/null
  96. # Speed up the binary image transfer
  97. stty -F $port raw ignbrk time 5 $fast_baudrate
  98. sx -vv $file > $port < $port
  99. #sx-at91 $port $file
  100. # Return the port to the default speed
  101. stty -F $port raw ignbrk time 5 $default_baudrate
  102. # Optional - fire up Minicom
  103. minicom -D $port -b $default_baudrate