postbuild.sh 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #!/bin/sh
  2. #
  3. # postbuild.sh - multi-language support script
  4. # Generate binary with secondary language.
  5. #
  6. # Input files:
  7. # $OUTDIR/Firmware.ino.elf
  8. # $OUTDIR/sketch/*.o (all object files)
  9. #
  10. # Output files:
  11. # text.sym
  12. # $PROGMEM.sym (progmem1.sym)
  13. # $PROGMEM.lss (...)
  14. # $PROGMEM.hex
  15. # $PROGMEM.chr
  16. # $PROGMEM.var
  17. # $PROGMEM.txt
  18. # textaddr.txt
  19. #
  20. #
  21. # Config:
  22. if [ -z "$CONFIG_OK" ]; then eval "$(cat config.sh)"; fi
  23. if [ -z "$CONFIG_OK" ] | [ $CONFIG_OK -eq 0 ]; then echo 'Config NG!' >&2; exit 1; fi
  24. #
  25. # Selected language:
  26. LANG=$1
  27. #if [ -z "$LANG" ]; then LANG='cz'; fi
  28. #
  29. # Params:
  30. IGNORE_MISSING_TEXT=1
  31. function finish
  32. {
  33. echo
  34. if [ "$1" == "0" ]; then
  35. echo "postbuild.sh finished with success" >&2
  36. else
  37. echo "postbuild.sh finished with errors!" >&2
  38. fi
  39. case "$-" in
  40. *i*) echo "press enter key"; read ;;
  41. esac
  42. exit $1
  43. }
  44. echo "postbuild.sh started" >&2
  45. #check input files
  46. echo " checking files:" >&2
  47. if [ ! -e $OUTDIR ]; then echo " folder '$OUTDIR' not found!" >&2; finish 1; fi
  48. echo " folder OK" >&2
  49. if [ ! -e $INOELF ]; then echo " elf file '$INOELF' not found!" >&2; finish 1; fi
  50. echo " elf OK" >&2
  51. if ! ls $OBJDIR/*.o >/dev/null 2>&1; then echo " no object files in '$OBJDIR/'!" >&2; finish 1; fi
  52. echo " objects OK" >&2
  53. #run progmem.sh - examine content of progmem1
  54. echo -n " running progmem.sh..." >&2
  55. ./progmem.sh 1 2>progmem.out
  56. if [ $? -ne 0 ]; then echo "NG! - check progmem.out file" >&2; finish 1; fi
  57. echo "OK" >&2
  58. #run textaddr.sh - map progmem addreses to text identifiers
  59. echo -n " running textaddr.sh..." >&2
  60. ./textaddr.sh 2>textaddr.out
  61. if [ $? -ne 0 ]; then echo "NG! - check progmem.out file" >&2; finish 1; fi
  62. echo "OK" >&2
  63. #check for messages declared in progmem1, but not found in lang_en.txt
  64. echo -n " checking textaddr.txt..." >&2
  65. if cat textaddr.txt | grep "^ADDR NF" >/dev/null; then
  66. echo "NG! - some texts not found in lang_en.txt!"
  67. if [ $(("0$IGNORE_MISSING_TEXT")) -eq 0 ]; then
  68. finish 1
  69. else
  70. echo " missing text ignored!" >&2
  71. fi
  72. else
  73. echo "OK" >&2
  74. fi
  75. #update progmem1 id entries in binary file
  76. echo -n " extracting binary..." >&2
  77. $OBJCOPY -I ihex -O binary $OUTDIR/Firmware.ino.hex ./firmware.bin
  78. echo "OK" >&2
  79. #update binary file
  80. echo " updating binary:" >&2
  81. #update progmem1 id entries in binary file
  82. echo -n " primary language ids..." >&2
  83. cat textaddr.txt | grep "^ADDR OK" | cut -f3- -d' ' | sed "s/^0000/0x/" |\
  84. awk '{ id = $2 - 1; hi = int(id / 256); lo = int(id - 256 * hi); printf("%d \\\\x%02x\\\\x%02x\n", strtonum($1), lo, hi); }' |\
  85. while read addr data; do
  86. echo -n -e $data | dd of=./firmware.bin bs=1 count=2 seek=$addr conv=notrunc oflag=nonblock 2>/dev/null
  87. done
  88. echo "OK" >&2
  89. #update _SEC_LANG in binary file if language is selected
  90. echo -n " secondary language data..." >&2
  91. if [ ! -z "$LANG" ]; then
  92. ./update_lang.sh $LANG 2>./update_lang.out
  93. if [ $? -ne 0 ]; then echo "NG! - check update_lang.out file" >&2; finish 1; fi
  94. echo "OK" >&2
  95. finish 0
  96. else
  97. echo "Updating languages:" >&2
  98. if [ -e lang_cz.bin ]; then
  99. echo -n " Czech : " >&2
  100. ./update_lang.sh cz 2>./update_lang_cz.out 1>/dev/null
  101. if [ $? -eq 0 ]; then echo 'OK' >&2; else echo 'NG!' >&2; fi
  102. fi
  103. if [ -e lang_de.bin ]; then
  104. echo -n " German : " >&2
  105. ./update_lang.sh de 2>./update_lang_de.out 1>/dev/null
  106. if [ $? -eq 0 ]; then echo 'OK' >&2; else echo 'NG!' >&2; fi
  107. fi
  108. if [ -e lang_it.bin ]; then
  109. echo -n " Italian: " >&2
  110. ./update_lang.sh it 2>./update_lang_it.out 1>/dev/null
  111. if [ $? -eq 0 ]; then echo 'OK' >&2; else echo 'NG!' >&2; fi
  112. fi
  113. if [ -e lang_es.bin ]; then
  114. echo -n " Spanish: " >&2
  115. ./update_lang.sh es 2>./update_lang_es.out 1>/dev/null
  116. if [ $? -eq 0 ]; then echo 'OK' >&2; else echo 'NG!' >&2; fi
  117. fi
  118. if [ -e lang_pl.bin ]; then
  119. echo -n " Polish : " >&2
  120. ./update_lang.sh pl 2>./update_lang_pl.out 1>/dev/null
  121. if [ $? -eq 0 ]; then echo 'OK' >&2; else echo 'NG!' >&2; fi
  122. fi
  123. # echo "skipped" >&2
  124. fi
  125. #convert bin to hex
  126. #echo -n " converting to hex..." >&2
  127. #$OBJCOPY -I binary -O ihex ./firmware.bin ./firmware.hex
  128. #echo "OK" >&2
  129. finish 0