flash.sh 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #!/bin/bash
  2. ####################################################################################
  3. # flash.sh
  4. #
  5. # Copyright (C) 2012 Gregory Nutt. All rights reserved.
  6. # Author: Gregory Nutt <gnutt@nuttx.org>
  7. #
  8. # Redistribution and use in source and binary forms, with or without
  9. # modification, are permitted provided that the following conditions
  10. # are met:
  11. #
  12. # 1. Redistributions of source code must retain the above copyright
  13. # notice, this list of conditions and the following disclaimer.
  14. # 2. Redistributions in binary form must reproduce the above copyright
  15. # notice, this list of conditions and the following disclaimer in
  16. # the documentation and/or other materials provided with the
  17. # distribution.
  18. # 3. Neither the name NuttX nor the names of its contributors may be
  19. # used to endorse or promote products derived from this software
  20. # without specific prior written permission.
  21. #
  22. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  23. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  24. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  25. # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  26. # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  27. # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  28. # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  29. # OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  30. # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  31. # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  32. # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  33. # POSSIBILITY OF SUCH DAMAGE.
  34. #
  35. ####################################################################################
  36. set -x
  37. USAGE="$0 <nuttx-path>"
  38. # LPCXpresso 3.6 installed at /cygdrive/c/nxp/lpcxpresso_3.6"
  39. BINDIR="/cygdrive/c/nxp/LPCXpresso_4.2.3_292/lpcxpresso/bin"
  40. # RedSuite with LPC4330 support installed at /cygdrive/c/code_red/RedSuite_4.2.3_379 "
  41. #BINDIR="/cygdrive/c/code_red/RedSuite_4.2.3_379/redsuite/bin"
  42. TARGET=LPC4330
  43. echo "############################################################################"
  44. echo "# Assumptions:"
  45. echo "#"
  46. echo "# - Windows 7"
  47. echo "# - Binaries installed at ${BINDIR}"
  48. echo "# - AXF image built with Code Red"
  49. echo "# - ${TARGET}"
  50. echo "#"
  51. echo "# You will need to edit this is any of the above are false"
  52. echo "#"
  53. echo "############################################################################"
  54. echo ""
  55. # This is the default install location for binaries on Windows (note that this
  56. # path could change with the Code Red version number)
  57. if [ ! -d "${BINDIR}" ]; then
  58. echo "Directory ${BINDIR} does not exist"
  59. exit 1
  60. fi
  61. # This is the relative path to the booLPCXpresso utility.
  62. BOOTLPC="Scripts/bootLPCXpresso.cmd"
  63. if [ ! -x "${BINDIR}/${BOOTLPC}" ]; then
  64. echo "No executable at ${BINDIR}/${BOOTLPC}"
  65. exit 1
  66. fi
  67. # bootLPCXpresso arguments
  68. BOOTLPC_ARG=winusb # Win7
  69. # Use the LPC18xx/LPC43xx flash utility
  70. FLASHUTIL="crt_emu_lpc18_43_nxp" # for LPC18xx/LPC43xx parts
  71. if [ ! -x "${BINDIR}/${FLASHUTIL}" ]; then
  72. echo "No executable file at ${BINDIR}/${FLASHUTIL}"
  73. exit 1
  74. fi
  75. # FLUSHUTIL arguements
  76. WIRE="-wire=winusb" # for LPC-Link on Windows Vista/Windows 7)
  77. # The nuttx directory must be provided as an argument
  78. NUTTX=$1
  79. if [ -z "${NUTTX}" ]; then
  80. echo "Missing argument"
  81. echo $USAGE
  82. exit 1
  83. fi
  84. if [ ! -d "${NUTTX}" ]; then
  85. echo "Directory ${NUTTX} does not exist"
  86. echo $USAGE
  87. exit 1
  88. fi
  89. # The binary to download:
  90. if [ ! -f "${NUTTX}/nuttx.axf" ]; then
  91. if [ -f "${NUTTX}/nuttx" ]; then
  92. echo "Renaming ${NUTTX}/nuttx to ${NUTTX}/nuttx.axf"
  93. mv ${NUTTX}/nuttx ${NUTTX}/nuttx.axf
  94. fi
  95. else
  96. if [ -f "${NUTTX}/nuttx" ]; then
  97. echo "Both ${NUTTX}/nuttx ${NUTTX}/nuttx.axf exist.."
  98. echo " Deleting ${NUTTX}/nuttx.axf"
  99. rm -f ${NUTTX}/nuttx.axf
  100. echo "Renaming ${NUTTX}/nuttx to ${NUTTX}/nuttx.axf"
  101. mv ${NUTTX}/nuttx ${NUTTX}/nuttx.axf
  102. fi
  103. fi
  104. NUTTXPATH=`cygpath -w "${NUTTX}/nuttx.axf"`
  105. # First of all boot the LPC-Link using the script: ${BINDIR}/${BOOTLPC}
  106. cd ${BINDIR} || \
  107. { echo "Failed to CD to ${BINDIR}"; exit 1; }
  108. ./${BOOTLPC} ${BOOTLPC_ARG} || \
  109. { echo "'${BOOTLPC} ${BOOTLPC_ARG}' Failed"; }
  110. echo ""
  111. echo "Wait a bit"
  112. echo "5..."
  113. sleep 1
  114. echo "4..."
  115. sleep 1
  116. echo "3..."
  117. sleep 1
  118. echo "2..."
  119. sleep 1
  120. echo "1..."
  121. sleep 1
  122. echo "0..."
  123. echo ""
  124. # Then program the FLASH
  125. cd ${BINDIR} || \
  126. { echo "Failed to CD to ${BINDIR}"; exit 1; }
  127. ./${FLASHUTIL} ${WIRE} -p${TARGET} -flash-load-exec="${NUTTXPATH}"