-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·133 lines (115 loc) · 3.33 KB
/
run.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/bash
set -e
SCRIPT=$(readlink -f "$0")
BASEDIR=$(dirname "$SCRIPT")
CC="arm-none-eabi-ld"
TARGET="thumbv7em-none-eabihf"
INPUT_FIRMWARE="${BASEDIR}/../../firmware/edge130apac/380/firmware.gcd"
OUTPUT_FIRMWARE="GUPDATE.GCD"
INJECT_MAX_LEN="0x270"
INJECT_ADDR="0xbf9a0"
cat > ${BASEDIR}/firmware_payload/.cargo/firmware.ld <<EOF
MEMORY
{
FLASH : ORIGIN = ${INJECT_ADDR}, LENGTH = ${INJECT_MAX_LEN}
}
ENTRY(_start);
SECTIONS
{
.text :
{
*(.text .text.*);
} > FLASH
.rodata :
{
*(.rodata .rodata.*);
} > FLASH
/DISCARD/ :
{
*(.ARM.exidx .ARM.exidx.*);
}
}
EOF
cat > ${BASEDIR}/firmware_payload/.cargo/config.toml <<EOF
[target.${TARGET}]
linker = "arm-none-eabi-ld"
rustflags = [
"-C", "link-arg=-T${BASEDIR}/firmware_payload/.cargo/firmware.ld",
]
[profile.release]
opt-level = 'z'
lto = true
[stable]
build-std = ["core"]
[build]
target = "${TARGET}"
EOF
cd ${BASEDIR}/firmware_payload
cargo build --release
cd ${BASEDIR}
FW_INJECTS=()
for payload in $@
do
if [ "xmem_dump" == "x$payload" ]
then
INJECT_OFFSET="0x2000"
INJECT_ADDR="0xbf9a0"
INJECT_FW_ADDR=$(printf '%#x' "$((${INJECT_ADDR} - ${INJECT_OFFSET}))")
#INJECT_MAX_LEN="0x270"
INJECT_FW_ID="0x2bd"
PAYLOAD_FILE="${BASEDIR}/firmware_payload/target/thumbv7em-none-eabihf/release/mem_dump"
arm-none-eabi-objcopy -O binary \
-j .text \
-j .rodata \
"${PAYLOAD_FILE}" \
"${PAYLOAD_FILE}.bin"
FW_INJECTS+=("${PAYLOAD_FILE}.bin")
FW_INJECTS+=(${INJECT_FW_ADDR})
FW_INJECTS+=(${INJECT_FW_ID})
fi
if [ "xport_search" == "x$payload" ]
then
INJECT_OFFSET="0x2000"
INJECT_ADDR="0xbf9a0"
INJECT_FW_ADDR=$(printf '%#x' "$((${INJECT_ADDR} - ${INJECT_OFFSET}))")
#INJECT_MAX_LEN="0x270"
INJECT_FW_ID="0x2bd"
PAYLOAD_FILE="${BASEDIR}/firmware_payload/target/thumbv7em-none-eabihf/release/port_search"
arm-none-eabi-objcopy -O binary \
-j .text \
-j .rodata \
"${PAYLOAD_FILE}" \
"${PAYLOAD_FILE}.bin"
FW_INJECTS+=("${PAYLOAD_FILE}.bin")
FW_INJECTS+=(${INJECT_FW_ADDR})
FW_INJECTS+=(${INJECT_FW_ID})
fi
if [ "xnrf52_jtag_input" == "x$payload" ]
then
# don't enable port_a_21 port_a_22 pull resistor
INJECT_OFFSET="0x2000"
INJECT_ADDR="0x6786a"
INJECT_FW_ADDR=$(printf '%#x' "$((${INJECT_ADDR} - ${INJECT_OFFSET}))")
INJECT_FW_ID="0x2bd"
PAYLOAD_FILE="${BASEDIR}/bin/nrf52_jtag_input_p1.payload"
FW_INJECTS+=(${PAYLOAD_FILE})
FW_INJECTS+=(${INJECT_FW_ADDR})
FW_INJECTS+=(${INJECT_FW_ID})
# don't put port_a_20 into output mode
INJECT_ADDR="0x679f2"
INJECT_FW_ADDR=$(printf '%#x' "$((${INJECT_ADDR} - ${INJECT_OFFSET}))")
PAYLOAD_FILE="${BASEDIR}/bin/nrf52_jtag_input_p2.payload"
FW_INJECTS+=(${PAYLOAD_FILE})
FW_INJECTS+=(${INJECT_FW_ADDR})
FW_INJECTS+=(${INJECT_FW_ID})
fi
done
# compile and exec the firmware inject
cd ${BASEDIR}/firmware_inject
cargo run -- \
${INPUT_FIRMWARE} \
${OUTPUT_FIRMWARE} \
${FW_INJECTS[@]}
# unpack the firmware, in case a review is needed
#cd ${BASEDIR}/out
#/home/rbran/src/gcd-rs/target/release/examples/gcd_extract ../GUPDATE.GCD firmware.toml