-
Notifications
You must be signed in to change notification settings - Fork 1
/
motbin2srec.sh
executable file
·63 lines (45 loc) · 3.05 KB
/
motbin2srec.sh
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
#
# a script to convert a binary codeplug to an srecord codeplug which is able to be loaded in CPS
# Copyright Bryan Fields 2020
# Licensed under the GPLv2
# This is a PoC, likely a much better way to do this
#
#
CPSHEADER='30343030303002000000000054C18EE59D19D11180180060B03C8AFF66616B6566616B65666120202020202000000000427279616E4669656C6400000000000000000000125265717569726573204D4F544F524F4C4120526164696F205365727669636520536F6674776172652E20434F5059524947485420313939362D31393937204D4F544F524F4C41000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200D0A'
BINPADDING='80020000D8'
usage()
{
echo "used to convert a binary waris codeplug to a CPS srec file"
echo "Usage: motbin2srec input.bin output.srec"
}
while [ "$1" != "" ]; do
case $1 in
-i | --in ) shift
inputfilename=$1
;;
-o | --out) shift
outputfilename=$1
;;
-h | --help ) usage
exit
;;
* ) usage
exit 1
esac
shift
done
# calc the length of the progrmaing block
prgBlockLength=$((16#`dd if=$inputfilename bs=1 skip=770 count=2 | xxd -p` ))
endOfPrgBlock=$(($prgBlockLength + 768))
echo "end of prog block $endOfPrgBlock"
# first dd the input file to a temp file
dd if=$inputfilename of=tempmot1.bin bs=1 skip=640 count=$endOfPrgBlock
# then add the binpadding to the binary file
echo $BINPADDING | xxd -ps -r >tempmot2.bin && cat tempmot1.bin >>tempmot2.bin
#now convert binary file to srecord file
srec_cat -DISable Header tempmot2.bin -Binary -Output - -Line_Length 70 -Line_Termination Carriage_Return_Line_Feed -address-length=1 -DISable Data_Count -Execution_Start_Address 0 >tempmot2.srec
#add the header on and you're done
echo $CPSHEADER | xxd -ps -r > $outputfilename && cat tempmot2.srec >> $outputfilename
#clean up the temp files
rm tempmot2.srec tempmot2.bin tempmot1.bin