postbuild.sh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #!/bin/sh
  2. # postbuild.sh - multi-language support high-level script
  3. # for generating binary with secondary language
  4. #
  5. # Input files:
  6. # $OUTDIR/Firmware.ino.elf
  7. # $OUTDIR/sketch/*.o (all object files)
  8. #
  9. # Output files:
  10. # text.sym
  11. # $PROGMEM.sym (progmem1.sym)
  12. # $PROGMEM.lss (...)
  13. # $PROGMEM.hex
  14. # $PROGMEM.chr
  15. # $PROGMEM.var
  16. # $PROGMEM.txt
  17. # textaddr.txt
  18. #
  19. # Output folder and elf file:
  20. OUTDIR="../../output"
  21. OUTELF="$OUTDIR/Firmware.ino.elf"
  22. #
  23. # AVR gcc tools used:
  24. OBJCOPY=C:/arduino-1.6.8/hardware/tools/avr/bin/avr-objcopy.exe
  25. #
  26. # Selected language:
  27. LANG=$1
  28. #if [ -z "$LANG" ]; then LANG='cz'; fi
  29. function finish
  30. {
  31. echo
  32. if [ "$1" == "0" ]; then
  33. echo "postbuild.sh finished with success" >&2
  34. else
  35. echo "postbuild.sh finished with errors!" >&2
  36. fi
  37. case "$-" in
  38. *i*) echo "press enter key"; read ;;
  39. esac
  40. exit $1
  41. }
  42. echo "postbuild.sh started" >&2
  43. #check input files
  44. echo " checking files:" >&2
  45. if [ ! -e $OUTDIR ]; then echo " folder '$OUTDIR' not found!" >&2; finish 1; fi
  46. echo " folder OK" >&2
  47. if [ ! -e $OUTELF ]; then echo " elf file '$OUTELF' not found!" >&2; finish 1; fi
  48. echo " elf OK" >&2
  49. if ! ls $OUTDIR/sketch/*.o >/dev/null 2>&1; then echo " no object files in '$OUTDIR/sketch/'!" >&2; finish 1; fi
  50. echo " objects OK" >&2
  51. #run progmem.sh - examine content of progmem1
  52. echo -n " running progmem.sh..." >&2
  53. ./progmem.sh 1 2>progmem.out
  54. if [ $? -ne 0 ]; then echo "NG! - check progmem.out file" >&2; finish 1; fi
  55. echo "OK" >&2
  56. #run textaddr.sh - map progmem addreses to text identifiers
  57. echo -n " running textaddr.sh..." >&2
  58. ./textaddr.sh 2>textaddr.out
  59. if [ $? -ne 0 ]; then echo "NG! - check progmem.out file" >&2; finish 1; fi
  60. echo "OK" >&2
  61. #check for messages declared in progmem1, but not found in lang_en.txt
  62. echo -n " checking textaddr.txt..." >&2
  63. if cat textaddr.txt | grep "^ADDR NF"; then echo "NG! - some strings not found in lang_en.txt!"; finish 1; fi
  64. echo "OK" >&2
  65. #update progmem1 id entries in binary file
  66. echo -n " extracting binary..." >&2
  67. $OBJCOPY -I ihex -O binary $OUTDIR/Firmware.ino.hex ./firmware.bin
  68. echo "OK" >&2
  69. #update binary file
  70. echo " updating binary:" >&2
  71. #update progmem1 id entries in binary file
  72. echo -n " primary language ids..." >&2
  73. cat textaddr.txt | grep "^ADDR OK" | cut -f3- -d' ' | sed "s/^0000/0x/" |\
  74. awk '{ hi = int($2 / 256); lo = int($2 - 256 * hi); printf("%d \\\\x%02x\\\\x%02x\n", strtonum($1), lo, hi); }' |\
  75. while read addr data; do
  76. echo -n -e $data | dd of=./firmware.bin bs=1 count=2 seek=$addr conv=notrunc oflag=nonblock 2>/dev/null
  77. done
  78. echo "OK" >&2
  79. #update _SEC_LANG in binary file if language is selected
  80. echo -n " secondary language data..." >&2
  81. if [ ! -z "$LANG" ]; then
  82. ./update_lang.sh $LANG 2>./update_lang.out
  83. if [ $? -ne 0 ]; then echo "NG! - check update_lang.out file" >&2; finish 1; fi
  84. echo "OK" >&2
  85. finish 0
  86. else
  87. echo "skipped" >&2
  88. fi
  89. #convert bin to hex
  90. echo -n " converting to hex..." >&2
  91. $OBJCOPY -I binary -O ihex ./firmware.bin ./firmware.hex
  92. echo "OK" >&2
  93. finish 0