2019-07-26 15:53:08 +00:00
|
|
|
#!/bin/bash
|
2018-05-31 00:57:41 +00:00
|
|
|
#
|
2022-01-11 12:18:48 +00:00
|
|
|
# Version 1.0.2 Build 12
|
|
|
|
#
|
2018-05-31 00:57:41 +00:00
|
|
|
# postbuild.sh - multi-language support script
|
|
|
|
# Generate binary with secondary language.
|
2018-05-30 18:15:05 +00:00
|
|
|
#
|
|
|
|
# Input files:
|
|
|
|
# $OUTDIR/Firmware.ino.elf
|
|
|
|
# $OUTDIR/sketch/*.o (all object files)
|
|
|
|
#
|
|
|
|
# Output files:
|
|
|
|
# text.sym
|
|
|
|
# $PROGMEM.sym (progmem1.sym)
|
|
|
|
# $PROGMEM.lss (...)
|
|
|
|
# $PROGMEM.hex
|
|
|
|
# $PROGMEM.chr
|
|
|
|
# $PROGMEM.var
|
|
|
|
# $PROGMEM.txt
|
|
|
|
# textaddr.txt
|
|
|
|
#
|
2022-01-11 12:18:48 +00:00
|
|
|
#############################################################################
|
|
|
|
# Change log:
|
|
|
|
# 31 May 2018, XPila, Initial
|
|
|
|
# 17 Dec. 2021, 3d-gussner, Use one config file for all languages
|
|
|
|
# 11 Jan. 2022, 3d-gussner, Add check for not translated messages using a
|
|
|
|
# parameter
|
|
|
|
# Added version and Change log
|
|
|
|
# colored output
|
|
|
|
# Add Community language support
|
|
|
|
# Use `git rev-list --count HEAD fw-build.sh`
|
|
|
|
# to get Build Nr
|
|
|
|
#############################################################################
|
2018-05-30 18:15:05 +00:00
|
|
|
#
|
2018-05-31 00:57:41 +00:00
|
|
|
# Config:
|
|
|
|
if [ -z "$CONFIG_OK" ]; then eval "$(cat config.sh)"; fi
|
2022-01-11 12:18:48 +00:00
|
|
|
if [ -z "$CONFIG_OK" ] | [ $CONFIG_OK -eq 0 ]; then echo "$(tput setaf 1)Config NG!$(tput sgr0)" >&2; exit 1; fi
|
2018-05-30 18:15:05 +00:00
|
|
|
#
|
|
|
|
# Selected language:
|
2018-06-17 19:25:57 +00:00
|
|
|
LNG=$1
|
2022-01-11 12:18:48 +00:00
|
|
|
|
|
|
|
#Set default to ignore missing text
|
|
|
|
CHECK_MISSING_TEXT=0
|
|
|
|
#Check if script should check for missing messages in the source code aren't translated by using parameter "--check-missing-text"
|
|
|
|
if [ "$1" = "--check-missing-text" ]; then
|
|
|
|
CHECK_MISSING_TEXT=1
|
|
|
|
fi
|
2018-05-30 18:15:05 +00:00
|
|
|
|
2021-12-21 13:15:51 +00:00
|
|
|
# List of supported languages
|
|
|
|
if [ -z "$LANGUAGES" ]; then
|
|
|
|
LANGUAGES="cz de es fr it pl"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Community languages
|
|
|
|
if [ ! -z "$COMMUNITY_LANGUAGES" ]; then
|
|
|
|
LANGUAGES+=" $COMMUNITY_LANGUAGES"
|
|
|
|
fi
|
2022-01-11 12:18:48 +00:00
|
|
|
echo "$(tput setaf 2)fw-build.sh started$(tput sgr 0)" >&2
|
|
|
|
echo "fw-build languages:$(tput setaf 2)$LANGUAGES$(tput sgr 0)" >&2
|
2018-05-31 00:57:41 +00:00
|
|
|
|
2018-06-07 22:17:56 +00:00
|
|
|
finish()
|
2018-05-30 18:15:05 +00:00
|
|
|
{
|
|
|
|
echo
|
2018-06-07 22:17:56 +00:00
|
|
|
if [ "$1" = "0" ]; then
|
2022-01-11 12:18:48 +00:00
|
|
|
echo "$(tput setaf 2)fw-build.sh finished with success$(tput sgr 0)" >&2
|
2018-05-30 18:15:05 +00:00
|
|
|
else
|
2022-01-11 12:18:48 +00:00
|
|
|
echo "$(tput setaf 1)fw-build.sh finished with errors!$(tput sgr 0)" >&2
|
2018-05-30 18:15:05 +00:00
|
|
|
fi
|
|
|
|
case "$-" in
|
|
|
|
*i*) echo "press enter key"; read ;;
|
|
|
|
esac
|
|
|
|
exit $1
|
|
|
|
}
|
|
|
|
|
|
|
|
#check input files
|
|
|
|
echo " checking files:" >&2
|
2022-01-11 12:18:48 +00:00
|
|
|
if [ ! -e $OUTDIR ]; then echo "$(tput setaf 1) folder '$OUTDIR' not found!$(tput sgr 0)" >&2; finish 1; fi
|
|
|
|
echo "$(tput setaf 2) folder OK$(tput sgr 0)" >&2
|
|
|
|
if [ ! -e $INOELF ]; then echo "$(tput setaf 1) elf file '$INOELF' not found!$(tput sgr 0)" >&2; finish 1; fi
|
|
|
|
echo "$(tput setaf 2) elf OK$(tput sgr 0)" >&2
|
|
|
|
if ! ls $OBJDIR/*.o >/dev/null 2>&1; then echo "$(tput setaf 1) no object files in '$OBJDIR/'!$(tput sgr 0)" >&2; finish 1; fi
|
|
|
|
echo "$(tput setaf 2) objects OK$(tput sgr 0)" >&2
|
2018-05-30 18:15:05 +00:00
|
|
|
|
|
|
|
#run progmem.sh - examine content of progmem1
|
|
|
|
echo -n " running progmem.sh..." >&2
|
2018-10-18 11:10:11 +00:00
|
|
|
./progmem.sh 1 2>progmem.out
|
2022-01-11 12:18:48 +00:00
|
|
|
if [ $? -ne 0 ]; then echo "$(tput setaf 1)NG! - check progmem.out file$(tput sgr 0)" >&2; finish 1; fi
|
|
|
|
echo "$(tput setaf 2)OK$(tput sgr 0)" >&2
|
2018-05-30 18:15:05 +00:00
|
|
|
|
|
|
|
#run textaddr.sh - map progmem addreses to text identifiers
|
|
|
|
echo -n " running textaddr.sh..." >&2
|
|
|
|
./textaddr.sh 2>textaddr.out
|
2022-01-11 12:18:48 +00:00
|
|
|
if [ $? -ne 0 ]; then echo "$(tput setaf 1)NG! - check progmem.out file$(tput sgr 0)" >&2; finish 1; fi
|
|
|
|
echo "$(tput setaf 2)OK$(tput sgr 0)" >&2
|
2018-05-30 18:15:05 +00:00
|
|
|
|
|
|
|
#check for messages declared in progmem1, but not found in lang_en.txt
|
|
|
|
echo -n " checking textaddr.txt..." >&2
|
2018-11-01 15:30:42 +00:00
|
|
|
cat textaddr.txt | grep "^TEXT NF" | sed "s/[^\"]*\"//;s/\"$//" >not_used.txt
|
|
|
|
cat textaddr.txt | grep "^ADDR NF" | sed "s/[^\"]*\"//;s/\"$//" >not_tran.txt
|
2018-05-30 18:15:05 +00:00
|
|
|
if cat textaddr.txt | grep "^ADDR NF" >/dev/null; then
|
2022-01-11 12:18:48 +00:00
|
|
|
echo "$(tput setaf 1)NG! - some texts not found in lang_en.txt!$(tput sgr 0)"
|
|
|
|
if [ $CHECK_MISSING_TEXT -eq 1 ]; then
|
|
|
|
echo "$(tput setaf 1)Missing text found, please update the language files!$(tput setaf 6)" >&2
|
|
|
|
cat not_tran.txt >&2
|
2018-05-30 18:15:05 +00:00
|
|
|
finish 1
|
|
|
|
else
|
2022-01-11 12:18:48 +00:00
|
|
|
echo "$(tput setaf 3) missing text ignored!$(tput sgr 0)" >&2
|
2018-05-30 18:15:05 +00:00
|
|
|
fi
|
|
|
|
else
|
2022-01-11 12:18:48 +00:00
|
|
|
echo "$(tput setaf 2)OK$(tput sgr 0)" >&2
|
2018-05-30 18:15:05 +00:00
|
|
|
fi
|
|
|
|
|
2018-06-18 17:37:20 +00:00
|
|
|
#extract binary file
|
2018-05-30 18:15:05 +00:00
|
|
|
echo -n " extracting binary..." >&2
|
2018-06-07 22:17:56 +00:00
|
|
|
$OBJCOPY -I ihex -O binary $INOHEX ./firmware.bin
|
2022-01-11 12:18:48 +00:00
|
|
|
echo "$(tput setaf 2)OK$(tput sgr 0)" >&2
|
2018-05-30 18:15:05 +00:00
|
|
|
|
|
|
|
#update binary file
|
|
|
|
echo " updating binary:" >&2
|
|
|
|
|
|
|
|
#update progmem1 id entries in binary file
|
|
|
|
echo -n " primary language ids..." >&2
|
|
|
|
cat textaddr.txt | grep "^ADDR OK" | cut -f3- -d' ' | sed "s/^0000/0x/" |\
|
|
|
|
awk '{ id = $2 - 1; hi = int(id / 256); lo = int(id - 256 * hi); printf("%d \\\\x%02x\\\\x%02x\n", strtonum($1), lo, hi); }' |\
|
|
|
|
while read addr data; do
|
2018-06-07 22:17:56 +00:00
|
|
|
/bin/echo -n -e $data | dd of=./firmware.bin bs=1 count=2 seek=$addr conv=notrunc oflag=nonblock 2>/dev/null
|
2018-05-30 18:15:05 +00:00
|
|
|
done
|
2022-01-11 12:18:48 +00:00
|
|
|
echo "$(tput setaf 2)OK$(tput sgr 0)" >&2
|
2018-05-30 18:15:05 +00:00
|
|
|
|
2018-06-18 17:37:20 +00:00
|
|
|
#update primary language signature in binary file
|
|
|
|
echo -n " primary language signature..." >&2
|
|
|
|
if [ -e lang_en.bin ]; then
|
|
|
|
#find symbol _PRI_LANG_SIGNATURE in section '.text'
|
|
|
|
pri_lang=$(cat text.sym | grep -E "\b_PRI_LANG_SIGNATURE\b")
|
2022-01-11 12:18:48 +00:00
|
|
|
if [ -z "$pri_lang" ]; then echo "$(tput setaf 1)NG!\n symbol _PRI_LANG_SIGNATURE not found!$(tput sgr 0)" >&2; finish 1; fi
|
2018-06-18 17:37:20 +00:00
|
|
|
#get pri_lang address
|
|
|
|
pri_lang_addr='0x'$(echo $pri_lang | cut -f1 -d' ')
|
|
|
|
#read header from primary language binary file
|
|
|
|
header=$(dd if=lang_en.bin bs=1 count=16 2>/dev/null | xxd | cut -c11-49 | sed 's/\([0-9a-f][0-9a-f]\)[\ ]*/\1 /g')
|
|
|
|
#read checksum and count data as 4 byte signature
|
|
|
|
chscnt=$(echo $header | cut -c18-29 | sed "s/ /\\\\x/g")
|
|
|
|
/bin/echo -e -n "$chscnt" |\
|
|
|
|
dd of=firmware.bin bs=1 count=4 seek=$(($pri_lang_addr)) conv=notrunc 2>/dev/null
|
2022-01-11 12:18:48 +00:00
|
|
|
echo "$(tput setaf 2)OK$(tput sgr 0)" >&2
|
2018-06-18 17:37:20 +00:00
|
|
|
else
|
2022-01-11 12:18:48 +00:00
|
|
|
echo "$(tput setaf 1)NG! - file lang_en.bin not found!$(tput sgr 0)" >&2;
|
2018-06-18 17:37:20 +00:00
|
|
|
finish 1
|
|
|
|
fi
|
|
|
|
|
2018-06-21 16:59:11 +00:00
|
|
|
#convert bin to hex
|
2022-01-11 12:18:48 +00:00
|
|
|
echo -n " converting primary to hex..." >&2
|
2018-06-21 16:59:11 +00:00
|
|
|
$OBJCOPY -I binary -O ihex ./firmware.bin ./firmware.hex
|
2022-01-11 12:18:48 +00:00
|
|
|
echo "$(tput setaf 2)OK$(tput sgr 0)" >&2
|
2018-06-21 16:59:11 +00:00
|
|
|
|
2018-05-30 18:15:05 +00:00
|
|
|
#update _SEC_LANG in binary file if language is selected
|
2022-01-11 12:18:48 +00:00
|
|
|
echo -n " secondary language data..." >&2
|
2018-06-17 19:25:57 +00:00
|
|
|
if [ ! -z "$LNG" ]; then
|
|
|
|
./update_lang.sh $LNG 2>./update_lang.out
|
2022-01-11 12:18:48 +00:00
|
|
|
if [ $? -ne 0 ]; then echo "$(tput setaf 1)NG! - check update_lang.out file$(tput sgr 0)" >&2; finish 1; fi
|
|
|
|
echo "$(tput setaf 2)OK$(tput sgr 0)" >&2
|
2018-05-30 18:15:05 +00:00
|
|
|
finish 0
|
|
|
|
else
|
2022-01-11 12:18:48 +00:00
|
|
|
echo >&2
|
|
|
|
echo " Updating languages:" >&2
|
2021-12-21 13:15:51 +00:00
|
|
|
for lang in $LANGUAGES; do
|
|
|
|
if [ -e lang_$lang.bin ]; then
|
2022-01-11 12:18:48 +00:00
|
|
|
echo -n " $lang : " >&2
|
2021-12-21 13:15:51 +00:00
|
|
|
./update_lang.sh $lang 2>./update_lang_$lang.out 1>/dev/null
|
2022-01-11 12:18:48 +00:00
|
|
|
if [ $? -eq 0 ]; then echo "$(tput setaf 2)OK$(tput sgr 0)" >&2; else echo "$(tput setaf 1)NG!$(tput sgr 0)" >&2; finish 1; fi
|
2021-12-21 13:15:51 +00:00
|
|
|
fi
|
|
|
|
done
|
2018-05-30 18:15:05 +00:00
|
|
|
fi
|
|
|
|
|
2018-06-21 16:59:11 +00:00
|
|
|
#create binary file with all languages
|
|
|
|
rm -f lang.bin
|
2021-12-21 13:15:51 +00:00
|
|
|
for lang in $LANGUAGES; do
|
|
|
|
if [ -e lang_$lang.bin ]; then cat lang_$lang.bin >> lang.bin; fi
|
|
|
|
done
|
2018-06-21 16:59:11 +00:00
|
|
|
|
2021-06-08 13:30:05 +00:00
|
|
|
# Check that the language data doesn't exceed the reserved XFLASH space
|
|
|
|
echo " checking language data size:"
|
|
|
|
lang_size=$(wc -c lang.bin | cut -f1 -d' ')
|
2021-06-08 15:24:10 +00:00
|
|
|
lang_size_pad=$(( ($lang_size+4096-1) / 4096 * 4096 ))
|
2021-06-08 13:30:05 +00:00
|
|
|
|
|
|
|
# TODO: hard-coded! get value by preprocessing LANG_SIZE from xflash_layout.h!
|
|
|
|
lang_reserved=249856
|
|
|
|
|
2022-01-11 12:18:48 +00:00
|
|
|
echo -n " total size usage: " >&2
|
|
|
|
if [ $lang_size_pad -gt $lang_reserved ]; then
|
|
|
|
echo -n "$(tput setaf 1)" >&2
|
|
|
|
else
|
|
|
|
echo -n "$(tput setaf 2)" >&2
|
|
|
|
fi
|
|
|
|
echo "$lang_size_pad ($lang_size)$(tput sgr 0)" >&2
|
|
|
|
echo " reserved size: $(tput setaf 2)$lang_reserved$(tput sgr 0)" >&2
|
2021-06-08 13:30:05 +00:00
|
|
|
if [ $lang_size_pad -gt $lang_reserved ]; then
|
2022-01-11 12:18:48 +00:00
|
|
|
echo "$(tput setaf 1)NG! - language data too large$(tput sgr 0)" >&2
|
2021-06-08 13:30:05 +00:00
|
|
|
finish 1
|
|
|
|
fi
|
|
|
|
|
2018-06-21 16:59:11 +00:00
|
|
|
#convert lang.bin to lang.hex
|
2022-01-11 12:18:48 +00:00
|
|
|
echo -n " converting multi language to hex..." >&2
|
2018-06-21 16:59:11 +00:00
|
|
|
$OBJCOPY -I binary -O ihex ./lang.bin ./lang.hex
|
2022-01-11 12:18:48 +00:00
|
|
|
echo "$(tput setaf 2)OK$(tput sgr 0)" >&2
|
2018-06-21 16:59:11 +00:00
|
|
|
|
|
|
|
#append languages to hex file
|
|
|
|
cat ./lang.hex >> firmware.hex
|
2018-05-30 18:15:05 +00:00
|
|
|
|
|
|
|
finish 0
|