2018-05-23 18:57:25 +00:00
|
|
|
#!/bin/sh
|
2018-05-26 19:24:42 +00:00
|
|
|
# postbuild.sh - multi-language support high-level script
|
|
|
|
# for generating binary with secondary language
|
|
|
|
#
|
|
|
|
# Input files:
|
|
|
|
# $OUTDIR/Firmware.ino.elf
|
|
|
|
# $OUTDIR/sketch/*.o (all object files)
|
|
|
|
#
|
|
|
|
# Output files:
|
|
|
|
# text.sym
|
|
|
|
# $PROGMEM.sym (progmem1.sym)
|
|
|
|
# $PROGMEM.lss (...)
|
2018-05-26 23:15:38 +00:00
|
|
|
# $PROGMEM.hex
|
2018-05-26 19:24:42 +00:00
|
|
|
# $PROGMEM.chr
|
|
|
|
# $PROGMEM.var
|
|
|
|
# $PROGMEM.txt
|
|
|
|
# textaddr.txt
|
2018-05-23 18:57:25 +00:00
|
|
|
#
|
|
|
|
# Output folder and elf file:
|
|
|
|
OUTDIR="../../output"
|
|
|
|
OUTELF="$OUTDIR/Firmware.ino.elf"
|
|
|
|
#
|
|
|
|
# AVR gcc tools used:
|
|
|
|
OBJCOPY=C:/arduino-1.6.8/hardware/tools/avr/bin/avr-objcopy.exe
|
2018-05-26 19:24:42 +00:00
|
|
|
#
|
|
|
|
# Selected language:
|
|
|
|
LANG=$1
|
|
|
|
#if [ -z "$LANG" ]; then LANG='cz'; fi
|
|
|
|
|
2018-05-23 18:57:25 +00:00
|
|
|
|
|
|
|
function finish
|
|
|
|
{
|
|
|
|
echo
|
2018-05-26 19:24:42 +00:00
|
|
|
if [ "$1" == "0" ]; then
|
|
|
|
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
|
2018-05-23 18:57:25 +00:00
|
|
|
}
|
|
|
|
|
2018-05-26 19:24:42 +00:00
|
|
|
echo "postbuild.sh started" >&2
|
2018-05-23 18:57:25 +00:00
|
|
|
|
|
|
|
#check input files
|
2018-05-26 19:24:42 +00:00
|
|
|
echo " checking files:" >&2
|
|
|
|
if [ ! -e $OUTDIR ]; then echo " folder '$OUTDIR' not found!" >&2; finish 1; fi
|
|
|
|
echo " folder OK" >&2
|
|
|
|
if [ ! -e $OUTELF ]; then echo " elf file '$OUTELF' not found!" >&2; finish 1; fi
|
|
|
|
echo " elf OK" >&2
|
|
|
|
if ! ls $OUTDIR/sketch/*.o >/dev/null 2>&1; then echo " no object files in '$OUTDIR/sketch/'!" >&2; finish 1; fi
|
|
|
|
echo " objects OK" >&2
|
2018-05-23 18:57:25 +00:00
|
|
|
|
2018-05-26 19:24:42 +00:00
|
|
|
#run progmem.sh - examine content of progmem1
|
|
|
|
echo -n " running progmem.sh..." >&2
|
|
|
|
./progmem.sh 1 2>progmem.out
|
|
|
|
if [ $? -ne 0 ]; then echo "NG! - check progmem.out file" >&2; finish 1; fi
|
|
|
|
echo "OK" >&2
|
2018-05-23 18:57:25 +00:00
|
|
|
|
2018-05-26 19:24:42 +00:00
|
|
|
#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
|
2018-05-23 18:57:25 +00:00
|
|
|
|
|
|
|
#check for messages declared in progmem1, but not found in lang_en.txt
|
2018-05-26 19:24:42 +00:00
|
|
|
echo -n " checking textaddr.txt..." >&2
|
|
|
|
if cat textaddr.txt | grep "^ADDR NF"; then echo "NG! - some strings not found in lang_en.txt!"; finish 1; fi
|
|
|
|
echo "OK" >&2
|
2018-05-23 18:57:25 +00:00
|
|
|
|
|
|
|
#update progmem1 id entries in binary file
|
2018-05-26 19:24:42 +00:00
|
|
|
echo -n " extracting binary..." >&2
|
2018-05-23 18:57:25 +00:00
|
|
|
$OBJCOPY -I ihex -O binary $OUTDIR/Firmware.ino.hex ./firmware.bin
|
2018-05-26 19:24:42 +00:00
|
|
|
echo "OK" >&2
|
|
|
|
|
|
|
|
#update binary file
|
|
|
|
echo " updating binary:" >&2
|
2018-05-23 18:57:25 +00:00
|
|
|
|
|
|
|
#update progmem1 id entries in binary file
|
2018-05-26 19:24:42 +00:00
|
|
|
echo -n " primary language ids..." >&2
|
|
|
|
cat textaddr.txt | grep "^ADDR OK" | cut -f3- -d' ' | sed "s/^0000/0x/" |\
|
2018-05-27 13:14:04 +00:00
|
|
|
awk '{ id = $2 - 1; hi = int(id / 256); lo = int(id - 256 * hi); printf("%d \\\\x%02x\\\\x%02x\n", strtonum($1), lo, hi); }' |\
|
2018-05-23 18:57:25 +00:00
|
|
|
while read addr data; do
|
|
|
|
echo -n -e $data | dd of=./firmware.bin bs=1 count=2 seek=$addr conv=notrunc oflag=nonblock 2>/dev/null
|
|
|
|
done
|
2018-05-26 19:24:42 +00:00
|
|
|
echo "OK" >&2
|
2018-05-23 18:57:25 +00:00
|
|
|
|
2018-05-26 19:24:42 +00:00
|
|
|
#update _SEC_LANG in binary file if language is selected
|
|
|
|
echo -n " secondary language data..." >&2
|
|
|
|
if [ ! -z "$LANG" ]; then
|
|
|
|
./update_lang.sh $LANG 2>./update_lang.out
|
|
|
|
if [ $? -ne 0 ]; then echo "NG! - check update_lang.out file" >&2; finish 1; fi
|
|
|
|
echo "OK" >&2
|
|
|
|
finish 0
|
|
|
|
else
|
|
|
|
echo "skipped" >&2
|
|
|
|
fi
|
|
|
|
|
|
|
|
#convert bin to hex
|
|
|
|
echo -n " converting to hex..." >&2
|
2018-05-23 18:57:25 +00:00
|
|
|
$OBJCOPY -I binary -O ihex ./firmware.bin ./firmware.hex
|
2018-05-26 19:24:42 +00:00
|
|
|
echo "OK" >&2
|
2018-05-23 18:57:25 +00:00
|
|
|
|
2018-05-26 19:24:42 +00:00
|
|
|
finish 0
|