123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- #!/bin/bash
- if [ -z "$CONFIG_OK" ]; then eval "$(cat config.sh)"; fi
- if [ -z "$OUTDIR" ]; then echo "$(tput setaf 1)variable OUTDIR not set!$(tput sgr0)" >&2; exit 1; fi
- if [ -z "$OBJDIR" ]; then echo "$(tput setaf 1)variable OBJDIR not set!$(tput sgr0)" >&2; exit 1; fi
- if [ -z "$INOELF" ]; then echo "$(tput setaf 1)variable INOELF not set!$(tput sgr0)" >&2; exit 1; fi
- if [ -z "$OBJDUMP" ]; then echo "$(tput setaf 1)variable OBJDUMP not set!$(tput sgr0)" >&2; exit 1; fi
- if [ -z "$CONFIG_OK" ] | [ $CONFIG_OK -eq 0 ]; then echo "$(tput setaf 1)Config NG!$(tput sgr0)" >&2; exit 1; fi
- PROGMEM=progmem$1
- if [ -z "$1" ]; then PROGMEM=progmem1; fi
- echo "$(tput setaf 2)progmem.sh started$(tput sgr0)" >&2
- echo " progmem.sh (0) - checking input files" >&2
- if [ ! -e $OUTDIR ]; then echo "progmem.sh - file $(tput setaf 2)"$INOELF"$(tput sgr 0) not found!" >&2; exit 1; fi
- echo " progmem.sh (1) - removing output files" >&2
- if [ -e text.sym ]; then rm text.sym; fi
- if [ -e $PROGMEM.sym ]; then rm $PROGMEM.sym; fi
- if [ -e $PROGMEM.lss ]; then rm $PROGMEM.lss; fi
- if [ -e $PROGMEM.hex ]; then rm $PROGMEM.hex; fi
- if [ -e $PROGMEM.chr ]; then rm $PROGMEM.chr; fi
- if [ -e $PROGMEM.var ]; then rm $PROGMEM.var; fi
- if [ -e $PROGMEM.txt ]; then rm $PROGMEM.txt; fi
- echo " progmem.sh (2) - listing symbol table of section '.text'" >&2
- $OBJDUMP -t -j ".text" $INOELF | tail -n +5 | grep -E "^[0-9a-f]{8} [gl] [O ]" | cut -c1-9,28-36,37- | sed "/^$/d" | sort > text.sym
- echo " progmem.sh (3) - calculating start and end address" >&2
- PROGMEM_BEG=$(cat text.sym | grep "__loc_pri_start" | while read offs size name; do echo "0x"$offs; done)
- PROGMEM_END=$(cat text.sym | grep "__loc_pri_end" | while read offs size name; do echo "0x"$offs; done)
- echo " START address = "$PROGMEM_BEG >&2
- echo " STOP address = "$PROGMEM_END >&2
- echo " progmem.sh (4) - extracting string data from elf" >&2
- $OBJDUMP -D -j ".text" -w -z --start-address=$PROGMEM_BEG --stop-address=$PROGMEM_END $INOELF |\
- tail -n +7 | sed "s/ \t.*$//" > $PROGMEM.lss
- cat $PROGMEM.lss | sed -E 's/^$/|/;s/^ ....:\t//;s/[ ]*$/ /' | tr -d '\n' | tr '|' '\n' |\
- sed "s/^ //;s/<//;s/>:/ /;s/00 [1-9a-f][1-9a-f] $/00 /; s/ $//" > $PROGMEM.hex
- echo " progmem.sh (5) - preparing string data" >&2
- cat $PROGMEM.hex | sed 's/ /\t/;s/ /\t /;s/ /\\x/g;s/\t/ /g' > $PROGMEM.chr
- echo " progmem.sh (6) - converting string data" >&2
- (\
- echo "/bin\/echo -e \\"; \
- cat $PROGMEM.chr | \
- sed 's/ \\xff\\xff/ /;' | \
- sed 's/\\x22/\\\\\\x22/g;' | \
- sed 's/\\x1b/\\\\\\x1b/g;' | \
- sed 's/\\x01/\\\\\\x01/g;' | \
- sed 's/\\xf8/\\\\\\xf8/g;' | \
- sed 's/\\x0a/\\\\\\x0a/g;' | \
- sed 's/\\x00$/\n/;s/^/\"/;s/$/\"\\/'; \
- ) | sh > $PROGMEM.var
- cat $PROGMEM.var | sed 's/\r/\n/g' | sed -E 's/^[0-9a-f]{8} [^ ]* //' >$PROGMEM.txt
- echo "$(tput setaf 2)progmem.sh finished$(tput sgr0)" >&2
- exit 0
|