Eval » set_hwinfo.sh
1 |
#!/bin/bash
|
---|---|
2 |
|
3 |
|
4 |
set -e |
5 |
set -u |
6 |
|
7 |
opwd=$PWD |
8 |
|
9 |
handleError()
|
10 |
{
|
11 |
echo "Error: Something went wrong here. $1" |
12 |
exit 22
|
13 |
}
|
14 |
|
15 |
|
16 |
cd /home/deseessm/obj/build-qhello-Desktop-Debug
|
17 |
|
18 |
month=$(date +"%m") |
19 |
day=$(date +"%d") |
20 |
year=$(date +"%y") |
21 |
|
22 |
|
23 |
echo -n "Please enter serial number in hex without leading zeros (e.g. 0x123): " |
24 |
read serial
|
25 |
|
26 |
serial=$(printf '0x%x\n' $serial) |
27 |
serialLong=$(printf '%08X\n' $serial) |
28 |
|
29 |
# echo -n "Please enter variant in hex without leading zeros (e.g. 0x123): "
|
30 |
# read serial
|
31 |
variant=0 |
32 |
|
33 |
if [ -z "$serial" ]; then hanleError "You did not specify an serial number."; fi |
34 |
|
35 |
|
36 |
echo << EOF > gdb.txt |
37 |
|
38 |
br loop
|
39 |
run
|
40 |
call (flash)(10,\"mmm\") |
41 |
clear loop
|
42 |
c
|
43 |
EOF
|
44 |
|
45 |
a=$(nm qhello | grep myStruct) |
46 |
addr=${a%% *} |
47 |
|
48 |
echo "Will try x/20xb 0x$addr" |
49 |
|
50 |
cat << EOF >gdb.txt |
51 |
|
52 |
br main:loop
|
53 |
run
|
54 |
set var \$new = (SMyStruct *)malloc(sizeof(struct SMyStruct)) |
55 |
set var \$new.version = 1 |
56 |
set var \$new.name="Script" |
57 |
set var \$new.day=$day |
58 |
set var \$new.month=$month |
59 |
set var \$new.year=$year |
60 |
set var \$new.serial=$serial |
61 |
call (writeHwInfo)(\$new) |
62 |
|
63 |
# target reset run
|
64 |
print/x bringupFirmware
|
65 |
|
66 |
set logging file serial.txt
|
67 |
set logging overwrite
|
68 |
set logging on
|
69 |
print/x myStruct.serial
|
70 |
set logging off
|
71 |
|
72 |
|
73 |
set logging file all.txt
|
74 |
set logging overwrite
|
75 |
set logging on
|
76 |
print/x myStruct
|
77 |
print &myStruct
|
78 |
x/32xb \$0 |
79 |
set logging off
|
80 |
|
81 |
EOF
|
82 |
|
83 |
gdb qhello -x gdb.txt -batch-silent -q || handleError "Could not write HwInfo. Is bringup firmware flashed?" |
84 |
|
85 |
|
86 |
echo -e "\n" |
87 |
|
88 |
echo "Serial: " |
89 |
a=$(cat serial.txt) |
90 |
isSerial="${a##* = }" |
91 |
|
92 |
if [ "$serial" == "$isSerial" ]; then |
93 |
cat all.txt |
94 |
echo "Serial is OK; $serial == $isSerial" |
95 |
else
|
96 |
handleError "Serial is NOT OK; $serial != $isSerial" |
97 |
fi
|
98 |
|
99 |
mv all.txt $opwd/hwinfo_${serialLong}.txt |
100 |
|
101 |
|
102 |
#cat << EOF > gdb.txt
|
103 |
#br main:loop
|
104 |
#run
|
105 |
#set logging file serial.txt
|
106 |
#set logging overwrite
|
107 |
#set logging on
|
108 |
#print/x myStruct.serial
|
109 |
#set logging off
|
110 |
#clear loop
|
111 |
#EOF
|
112 |
#gdb qhello -x gdb.txt -batch-silent -q
|
113 |
|
114 |
|
115 |
|
116 |
#---fin------------------------------------------------------------------------
|