upload_iar_elfs.sh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #!/bin/bash
  2. # You can test different download mode such as ilm,flashxip,sram
  3. DOWNLOAD=${1:-ilm}
  4. # TODO: Change CORE is not yet supported
  5. CORE=n300
  6. UPLOAD=${UPLOAD:-1}
  7. # TODO: Change this ROOTs according to your environment settings
  8. IAR_WORKBENCH_ROOT="/c/Program Files/IAR Systems/Embedded Workbench 9.2"
  9. NUCLEI_TOOLCHAIN_ROOT="/c/Software/NucleiStudio/toolchain"
  10. # TODO: you need to modify the default remote to your real machine gdb remote such as localhost:3333
  11. GDBREMOTE=${GDBREMOTE:-whss3.corp.nucleisys.com:20005}
  12. # Export riscv gdb and iarbuild into system PATH, please modify it according to your environment settings
  13. export PATH="${NUCLEI_TOOLCHAIN_ROOT}/gcc/bin/":$PATH
  14. export PATH="${IAR_WORKBENCH_ROOT}/common/bin":"${IAR_WORKBENCH_ROOT}/riscv/bin":$PATH
  15. SCRIPTDIR=$(dirname $(readlink -f $BASH_SOURCE))
  16. IARPRODIR=$(readlink -f ${SCRIPTDIR}/..)
  17. if which riscv64-unknown-elf-gdb > /dev/null ; then
  18. GDB=riscv64-unknown-elf-gdb
  19. else
  20. GDB=riscv-nuclei-elf-gdb
  21. fi
  22. function tool_check() {
  23. local tool=$1
  24. if ! which $tool > /dev/null ; then
  25. echo "$tool not found in PATH, please check!"
  26. exit 1
  27. fi
  28. }
  29. function upload_program() {
  30. local file=$1
  31. echo "Upload and test $file"
  32. $GDB -ex "set remotetimeout 240" -ex "target remote $GDBREMOTE" \
  33. --batch -ex 'thread apply all monitor reset halt' -ex 'thread apply all info reg pc' \
  34. -ex 'thread 1' -ex "load $file" -ex "file $file" \
  35. -ex 'thread apply all set $pc=__alias_hw_reset' -ex 'thread apply all info reg pc' \
  36. -ex 'thread 1' -ex 'monitor resume' -ex 'quit'
  37. }
  38. function build_iar_project() {
  39. local iarprj=$1
  40. local config=${2:-Debug}
  41. echo "Build project $iarprj, configuration $config"
  42. iarbuild $iarprj -build Debug -log errors -parallel 8
  43. }
  44. function disa_out() {
  45. local iarout=$1
  46. local iardis=${iarout}.dasm
  47. echo "Disassemble $iarout to ${iardis}"
  48. ielfdumpriscv -a $iarout > $iardis
  49. }
  50. function change_linkscript() {
  51. local iarprj=$1
  52. local download=${2:-flashxip}
  53. echo "Change download mode to $download"
  54. sed -i "s/IAR\\\\iar_evalsoc_.*\.icf/IAR\\\\iar_evalsoc_${download}.icf/g" $iarprj
  55. }
  56. # check tool existance
  57. tool_check $GDB
  58. tool_check iarbuild
  59. #upload_program rtos/Debug/Exe/freertos_demo.out
  60. #exit 0
  61. folders=(rtos baremetal)
  62. faillist=""
  63. # Push to iar project directory
  64. pushd $IARPRODIR
  65. for folder in "${folders[@]}"
  66. do
  67. for file in $(find $folder -type f -name "*.ewp")
  68. do
  69. change_linkscript $file $DOWNLOAD
  70. build_iar_project $file
  71. outfile="$(dirname $file)/Debug/Exe/$(basename $file ewp)out"
  72. if [ -f $outfile ] ; then
  73. disa_out $outfile
  74. if [ "x$UPLOAD" != "x1" ] ; then
  75. echo "Will not upload and test $file"
  76. else
  77. upload_program $outfile
  78. sleep 15
  79. fi
  80. else
  81. faillist=" $file"
  82. fi
  83. done
  84. done
  85. popd
  86. if [ "x$faillist" != "x" ] ; then
  87. echo "These cases are failing, please check the following items!"
  88. echo "$faillist"
  89. exit -1
  90. fi
  91. exit 0