File: split_combined_hex

package info (click to toggle)
hostap-utils 1%3A0.4.7-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, lenny, squeeze, stretch, wheezy
  • size: 288 kB
  • ctags: 1,164
  • sloc: ansic: 4,482; sh: 316; makefile: 27
file content (44 lines) | stat: -rwxr-xr-x 1,029 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/sh

# Split combined S3 image file into separate hex files"

set -e

TOOL="`dirname $0`/prism2_srec"

if [ ! -x "$TOOL" ]; then
    echo "Could not find compiled prism2_srec tool using path '$TOOL'"
    exit 1
fi

TMPDIR=`mktemp -d srec_temp.XXXXXX` || exit 1
IN=$TMPDIR/data
PART=$TMPDIR/part
cat > $IN

num=0
while [ -s $IN ]; do
    num=$(($num+1))
    echo "Image $num"
    eline=`grep -n ^S6 $IN | head -n 1 | cut -f1 -d:`
    if [ -n "$eline" ]; then
	head -n $eline $IN | grep -vE '^S6|^S4' > $PART
	tail -n +$(($eline+1)) $IN > $IN.tmp && mv $IN.tmp $IN
    else
	grep -vE '^S6|^S4' $IN > $PART
	rm $IN
    fi

    fname=`$TOOL dummydev $PART 2> /dev/null | grep "^Included file name" | head -n 1 | colrm 1 20`
    if [ -z "$fname" ] || echo "$fname" | grep -q /; then
	fname=image-$num.hex
    fi
    mv $PART $TMPDIR/$fname
    echo "  ==> $fname"
    $TOOL dummydev $TMPDIR/$fname 2> /dev/null | grep -E '^Component|0x8' || true
    echo
done

rm -f $IN $PART
echo "Resulting files in '$TMPDIR':"
ls -l $TMPDIR