update_lang.sh 2.7 KB

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