postbuild.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. #
  30. # Params:
  31. IGNORE_MISSING_TEXT=1
  32. function finish
  33. {
  34. echo
  35. if [ "$1" == "0" ]; then
  36. echo "postbuild.sh finished with success" >&2
  37. else
  38. echo "postbuild.sh finished with errors!" >&2
  39. fi
  40. case "$-" in
  41. *i*) echo "press enter key"; read ;;
  42. esac
  43. exit $1
  44. }
  45. echo "postbuild.sh started" >&2
  46. #check input files
  47. echo " checking files:" >&2
  48. if [ ! -e $OUTDIR ]; then echo " folder '$OUTDIR' not found!" >&2; finish 1; fi
  49. echo " folder OK" >&2
  50. if [ ! -e $OUTELF ]; then echo " elf file '$OUTELF' not found!" >&2; finish 1; fi
  51. echo " elf OK" >&2
  52. if ! ls $OUTDIR/sketch/*.o >/dev/null 2>&1; then echo " no object files in '$OUTDIR/sketch/'!" >&2; finish 1; fi
  53. echo " objects OK" >&2
  54. #run progmem.sh - examine content of progmem1
  55. echo -n " running progmem.sh..." >&2
  56. ./progmem.sh 1 2>progmem.out
  57. if [ $? -ne 0 ]; then echo "NG! - check progmem.out file" >&2; finish 1; fi
  58. echo "OK" >&2
  59. #run textaddr.sh - map progmem addreses to text identifiers
  60. echo -n " running textaddr.sh..." >&2
  61. ./textaddr.sh 2>textaddr.out
  62. if [ $? -ne 0 ]; then echo "NG! - check progmem.out file" >&2; finish 1; fi
  63. echo "OK" >&2
  64. #check for messages declared in progmem1, but not found in lang_en.txt
  65. echo -n " checking textaddr.txt..." >&2
  66. if cat textaddr.txt | grep "^ADDR NF" >/dev/null; then
  67. echo "NG! - some texts not found in lang_en.txt!"
  68. if [ $(("0$IGNORE_MISSING_TEXT")) -eq 0 ]; then
  69. finish 1
  70. else
  71. echo " missing text ignored!" >&2
  72. fi
  73. else
  74. echo "OK" >&2
  75. fi
  76. #update progmem1 id entries in binary file
  77. echo -n " extracting binary..." >&2
  78. $OBJCOPY -I ihex -O binary $OUTDIR/Firmware.ino.hex ./firmware.bin
  79. echo "OK" >&2
  80. #update binary file
  81. echo " updating binary:" >&2
  82. #update progmem1 id entries in binary file
  83. echo -n " primary language ids..." >&2
  84. cat textaddr.txt | grep "^ADDR OK" | cut -f3- -d' ' | sed "s/^0000/0x/" |\
  85. awk '{ id = $2 - 1; hi = int(id / 256); lo = int(id - 256 * hi); printf("%d \\\\x%02x\\\\x%02x\n", strtonum($1), lo, hi); }' |\
  86. while read addr data; do
  87. echo -n -e $data | dd of=./firmware.bin bs=1 count=2 seek=$addr conv=notrunc oflag=nonblock 2>/dev/null
  88. done
  89. echo "OK" >&2
  90. #update _SEC_LANG in binary file if language is selected
  91. echo -n " secondary language data..." >&2
  92. if [ ! -z "$LANG" ]; then
  93. ./update_lang.sh $LANG 2>./update_lang.out
  94. if [ $? -ne 0 ]; then echo "NG! - check update_lang.out file" >&2; finish 1; fi
  95. echo "OK" >&2
  96. finish 0
  97. else
  98. echo "skipped" >&2
  99. fi
  100. #convert bin to hex
  101. echo -n " converting to hex..." >&2
  102. $OBJCOPY -I binary -O ihex ./firmware.bin ./firmware.hex
  103. echo "OK" >&2
  104. finish 0