2019-07-26 15:53:08 +00:00
|
|
|
#!/bin/bash
|
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
|
|
|
|
#
|
|
|
|
#
|
2018-05-31 00:57:41 +00:00
|
|
|
# Config:
|
|
|
|
if [ -z "$CONFIG_OK" ]; then eval "$(cat config.sh)"; fi
|
|
|
|
if [ -z "$CONFIG_OK" ] | [ $CONFIG_OK -eq 0 ]; then echo 'Config NG!' >&2; exit 1; fi
|
2018-05-30 18:15:05 +00:00
|
|
|
#
|
|
|
|
# Selected language:
|
2018-06-17 19:25:57 +00:00
|
|
|
LNG=$1
|
|
|
|
#if [ -z "$LNG" ]; then LNG='cz'; fi
|
2018-05-30 18:15:05 +00:00
|
|
|
#
|
|
|
|
# Params:
|
|
|
|
IGNORE_MISSING_TEXT=1
|
|
|
|
|
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
|
2018-05-30 18:15:05 +00:00
|
|
|
echo "postbuild.sh finished with success" >&2
|
|
|
|
else
|
|
|
|
echo "postbuild.sh finished with errors!" >&2
|
|
|
|
fi
|
|
|
|
case "$-" in
|
|
|
|
*i*) echo "press enter key"; read ;;
|
|
|
|
esac
|
|
|
|
exit $1
|
|
|
|
}
|
|
|
|
|
|
|
|
echo "postbuild.sh started" >&2
|
|
|
|
|
|
|
|
#check input files
|
|
|
|
echo " checking files:" >&2
|
|
|
|
if [ ! -e $OUTDIR ]; then echo " folder '$OUTDIR' not found!" >&2; finish 1; fi
|
|
|
|
echo " folder OK" >&2
|
2018-05-31 00:57:41 +00:00
|
|
|
if [ ! -e $INOELF ]; then echo " elf file '$INOELF' not found!" >&2; finish 1; fi
|
2018-05-30 18:15:05 +00:00
|
|
|
echo " elf OK" >&2
|
2018-05-31 00:57:41 +00:00
|
|
|
if ! ls $OBJDIR/*.o >/dev/null 2>&1; then echo " no object files in '$OBJDIR/'!" >&2; finish 1; fi
|
2018-05-30 18:15:05 +00:00
|
|
|
echo " objects OK" >&2
|
|
|
|
|
|
|
|
#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
|
2018-05-30 18:15:05 +00:00
|
|
|
if [ $? -ne 0 ]; then echo "NG! - check progmem.out file" >&2; finish 1; fi
|
|
|
|
echo "OK" >&2
|
|
|
|
|
|
|
|
#run textaddr.sh - map progmem addreses to text identifiers
|
|
|
|
echo -n " running textaddr.sh..." >&2
|
|
|
|
./textaddr.sh 2>textaddr.out
|
|
|
|
if [ $? -ne 0 ]; then echo "NG! - check progmem.out file" >&2; finish 1; fi
|
|
|
|
echo "OK" >&2
|
|
|
|
|
|
|
|
#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
|
|
|
|
echo "NG! - some texts not found in lang_en.txt!"
|
2018-06-07 22:17:56 +00:00
|
|
|
if [ $IGNORE_MISSING_TEXT -eq 0 ]; then
|
2018-05-30 18:15:05 +00:00
|
|
|
finish 1
|
|
|
|
else
|
|
|
|
echo " missing text ignored!" >&2
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "OK" >&2
|
|
|
|
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
|
2018-05-30 18:15:05 +00:00
|
|
|
echo "OK" >&2
|
|
|
|
|
|
|
|
#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
|
|
|
|
echo "OK" >&2
|
|
|
|
|
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")
|
|
|
|
if [ -z "$pri_lang" ]; then echo "NG!\n symbol _PRI_LANG_SIGNATURE not found!" >&2; finish 1; fi
|
|
|
|
#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
|
|
|
|
echo "OK" >&2
|
|
|
|
else
|
|
|
|
echo "NG! - file lang_en.bin not found!" >&2;
|
|
|
|
finish 1
|
|
|
|
fi
|
|
|
|
|
2018-06-21 16:59:11 +00:00
|
|
|
#convert bin to hex
|
|
|
|
echo -n " converting to hex..." >&2
|
|
|
|
$OBJCOPY -I binary -O ihex ./firmware.bin ./firmware.hex
|
|
|
|
echo "OK" >&2
|
|
|
|
|
2018-05-30 18:15:05 +00:00
|
|
|
#update _SEC_LANG in binary file if language is selected
|
|
|
|
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
|
2018-05-30 18:15:05 +00:00
|
|
|
if [ $? -ne 0 ]; then echo "NG! - check update_lang.out file" >&2; finish 1; fi
|
|
|
|
echo "OK" >&2
|
|
|
|
finish 0
|
|
|
|
else
|
2018-05-31 00:57:41 +00:00
|
|
|
echo "Updating languages:" >&2
|
|
|
|
if [ -e lang_cz.bin ]; then
|
|
|
|
echo -n " Czech : " >&2
|
|
|
|
./update_lang.sh cz 2>./update_lang_cz.out 1>/dev/null
|
2019-05-06 13:29:57 +00:00
|
|
|
if [ $? -eq 0 ]; then echo 'OK' >&2; else echo 'NG!' >&2; finish 1; fi
|
2018-05-31 00:57:41 +00:00
|
|
|
fi
|
|
|
|
if [ -e lang_de.bin ]; then
|
|
|
|
echo -n " German : " >&2
|
|
|
|
./update_lang.sh de 2>./update_lang_de.out 1>/dev/null
|
2019-05-06 13:29:57 +00:00
|
|
|
if [ $? -eq 0 ]; then echo 'OK' >&2; else echo 'NG!' >&2; finish 1; fi
|
2018-05-31 00:57:41 +00:00
|
|
|
fi
|
|
|
|
if [ -e lang_it.bin ]; then
|
|
|
|
echo -n " Italian: " >&2
|
|
|
|
./update_lang.sh it 2>./update_lang_it.out 1>/dev/null
|
2019-05-06 13:29:57 +00:00
|
|
|
if [ $? -eq 0 ]; then echo 'OK' >&2; else echo 'NG!' >&2; finish 1; fi
|
2018-05-31 00:57:41 +00:00
|
|
|
fi
|
|
|
|
if [ -e lang_es.bin ]; then
|
|
|
|
echo -n " Spanish: " >&2
|
|
|
|
./update_lang.sh es 2>./update_lang_es.out 1>/dev/null
|
2019-05-06 13:29:57 +00:00
|
|
|
if [ $? -eq 0 ]; then echo 'OK' >&2; else echo 'NG!' >&2; finish 1; fi
|
2018-05-31 00:57:41 +00:00
|
|
|
fi
|
2018-09-11 01:43:05 +00:00
|
|
|
if [ -e lang_fr.bin ]; then
|
|
|
|
echo -n " French : " >&2
|
|
|
|
./update_lang.sh fr 2>./update_lang_fr.out 1>/dev/null
|
2019-05-06 13:29:57 +00:00
|
|
|
if [ $? -eq 0 ]; then echo 'OK' >&2; else echo 'NG!' >&2; finish 1; fi
|
2018-09-11 01:43:05 +00:00
|
|
|
fi
|
2018-05-31 00:57:41 +00:00
|
|
|
if [ -e lang_pl.bin ]; then
|
|
|
|
echo -n " Polish : " >&2
|
|
|
|
./update_lang.sh pl 2>./update_lang_pl.out 1>/dev/null
|
2019-05-06 13:29:57 +00:00
|
|
|
if [ $? -eq 0 ]; then echo 'OK' >&2; else echo 'NG!' >&2; finish 1; fi
|
2018-05-31 00:57:41 +00:00
|
|
|
fi
|
2021-03-01 07:28:08 +00:00
|
|
|
#Community language support
|
|
|
|
#Dutch
|
|
|
|
if [ -e lang_nl.bin ]; then
|
|
|
|
echo -n " Dutch : " >&2
|
|
|
|
./update_lang.sh nl 2>./update_lang_nl.out 1>/dev/null
|
|
|
|
if [ $? -eq 0 ]; then echo 'OK' >&2; else echo 'NG!' >&2; fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
#Use the 6 lines below as a template and replace 'qr' and 'New language'
|
|
|
|
#New language
|
|
|
|
# if [ -e lang_qr.bin ]; then
|
|
|
|
# echo -n " New language : " >&2
|
|
|
|
# ./update_lang.sh qr 2>./update_lang_qr.out 1>/dev/null
|
|
|
|
# if [ $? -eq 0 ]; then echo 'OK' >&2; else echo 'NG!' >&2; fi
|
|
|
|
# fi
|
|
|
|
|
2018-05-31 00:57:41 +00:00
|
|
|
# echo "skipped" >&2
|
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
|
|
|
|
if [ -e lang_cz.bin ]; then cat lang_cz.bin >> lang.bin; fi
|
|
|
|
if [ -e lang_de.bin ]; then cat lang_de.bin >> lang.bin; fi
|
|
|
|
if [ -e lang_es.bin ]; then cat lang_es.bin >> lang.bin; fi
|
2018-10-18 11:04:01 +00:00
|
|
|
if [ -e lang_fr.bin ]; then cat lang_fr.bin >> lang.bin; fi
|
2018-06-21 16:59:11 +00:00
|
|
|
if [ -e lang_it.bin ]; then cat lang_it.bin >> lang.bin; fi
|
|
|
|
if [ -e lang_pl.bin ]; then cat lang_pl.bin >> lang.bin; fi
|
2021-03-01 07:28:08 +00:00
|
|
|
#Community language support
|
|
|
|
# Dutch
|
|
|
|
if [ -e lang_nl.bin ]; then cat lang_nl.bin >> lang.bin; fi
|
|
|
|
|
|
|
|
#Use the 2 lines below as a template and replace 'qr'
|
|
|
|
## New language
|
|
|
|
#if [ -e lang_qr.bin ]; then cat lang_qr.bin >> lang.bin; fi
|
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
|
|
|
|
|
|
|
|
echo " total size usage: $lang_size_pad ($lang_size)"
|
|
|
|
echo " reserved size: $lang_reserved"
|
|
|
|
if [ $lang_size_pad -gt $lang_reserved ]; then
|
|
|
|
echo "NG! - language data too large" >&2
|
|
|
|
finish 1
|
|
|
|
fi
|
|
|
|
|
2018-06-21 16:59:11 +00:00
|
|
|
#convert lang.bin to lang.hex
|
|
|
|
echo -n " converting to hex..." >&2
|
|
|
|
$OBJCOPY -I binary -O ihex ./lang.bin ./lang.hex
|
|
|
|
echo "OK" >&2
|
|
|
|
|
|
|
|
#append languages to hex file
|
|
|
|
cat ./lang.hex >> firmware.hex
|
2018-05-30 18:15:05 +00:00
|
|
|
|
|
|
|
finish 0
|