summaryrefslogtreecommitdiffstats
path: root/scripts/habv4/gencsf.sh
blob: 2c1c34add43afe9e038a7b0ba33010eb3fa5a4bf (plain)
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
45
46
47
#!/bin/sh

set -e

while getopts "f:c:i:o:" opt; do
    case $opt in
	f)
	    file=$OPTARG
	    ;;
	c)
	    cfg=$OPTARG
	    ;;
	i)
	    in=$OPTARG
	    ;;
	o)
	    out=$OPTARG
	    ;;
	\?)
	    echo "Invalid option: -$OPTARG" >&2
	    exit 1
	;;
    esac
done

if [ ! -e $file -o ! -e $cfg -o ! -e $in ]; then
    echo "file not found!"
    exit 1
fi

#
# extract and set as shell vars:
# loadaddr=
# dcdofs=
#
eval $(sed -n -e "s/^[[:space:]]*\(loadaddr\|dcdofs\)[[:space:]]*\(0x[0-9]*\)/\1=\2/p" $cfg)

length=$(stat -c '%s' $file)

sed -e "s:@TABLE_BIN@:$TABLE_BIN:" \
    -e "s:@CSF_CRT_PEM@:$CSF_CRT_PEM:" \
    -e "s:@IMG_CRT_PEM@:$IMG_CRT_PEM:" \
    -e "s:@LOADADDR@:$loadaddr:" \
    -e "s:@OFFSET@:0:" \
    -e "s:@LENGTH@:$length:" \
    -e "s:@FILE@:$file:" \
    $in > $out