update_lang.sh 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/bin/sh
  2. # update_lang.sh - multi-language support low level script
  3. # for updating secondary language in binary file
  4. #
  5. # AVR gcc tools used:
  6. OBJCOPY=C:/arduino-1.6.8/hardware/tools/avr/bin/avr-objcopy.exe
  7. #
  8. # Selected language:
  9. LANG=$1
  10. if [ -z "$LANG" ]; then LANG='cz'; fi
  11. #
  12. function finish
  13. {
  14. echo
  15. if [ "$1" == "0" ]; then
  16. echo "update_lang.sh finished with success" >&2
  17. else
  18. echo "update_lang.sh finished with errors!" >&2
  19. fi
  20. case "$-" in
  21. *i*) echo "press enter key"; read ;;
  22. esac
  23. exit $1
  24. }
  25. echo "update_lang.sh started" >&2
  26. echo "selected language=$LANG" >&2
  27. echo -n " checking files..." >&2
  28. if [ ! -e text.sym ]; then echo "NG! file text.sym not found!" >&2; finish 1; fi
  29. if [ ! -e lang_$LANG.bin ]; then echo "NG! file lang_$LANG.bin not found!" >&2; finish 1; fi
  30. if [ ! -e firmware.bin ]; then echo "NG! file firmware.bin not found!" >&2; finish 1; fi
  31. echo "OK" >&2
  32. echo -n " checking symbols..." >&2
  33. #find symbol _SEC_LANG in section '.text'
  34. sec_lang=$(cat text.sym | grep -E "\b_SEC_LANG\b")
  35. if [ -z "$sec_lang" ]; then echo "NG!\n symbol _SEC_LANG not found!" >&2; finish 1; fi
  36. echo "OK" >&2
  37. echo " calculating vars:" >&2
  38. #get addres and size
  39. sec_lang_addr='0x'$(echo $sec_lang | cut -f1 -d' ')
  40. sec_lang_size='0x'$(echo $sec_lang | cut -f2 -d' ')
  41. echo " sec_lang_addr =$sec_lang_addr" >&2
  42. echo " sec_lang_size =$sec_lang_size" >&2
  43. #calculate lang_table_addr (aligned to 256byte page)
  44. lang_table_addr=$((256*$((($sec_lang_addr + 255) / 256))))
  45. printf " lang_table_addr =0x%04x\n" $lang_table_addr >&2
  46. #calculate lang_table_size
  47. lang_table_size=$((256*$((($sec_lang_size - ($lang_table_addr - $sec_lang_addr))/256))))
  48. printf " lang_table_size =0x%04x (=%d bytes)\n" $lang_table_size $lang_table_size >&2
  49. #get lang_xx.bin file size
  50. lang_file_size=$(wc -c lang_$LANG.bin | cut -f1 -d' ')
  51. printf " lang_file_size =0x%04x (=%d bytes)\n" $lang_file_size $lang_file_size >&2
  52. if [ $lang_file_size -gt $lang_table_size ]; then echo "Lanaguage binary file size too big!"; finish 1; fi
  53. echo "updating 'firmware.bin'..." >&2
  54. dd if=lang_$LANG.bin of=firmware.bin bs=1 seek=$lang_table_addr conv=notrunc 2>/dev/null
  55. #convert bin to hex
  56. echo "converting to hex..." >&2
  57. $OBJCOPY -I binary -O ihex ./firmware.bin ./firmware.hex
  58. finish 0