forked from Demon000/work-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
copy-to-board.sh
executable file
·197 lines (164 loc) · 3.65 KB
/
copy-to-board.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/bin/bash
POSITIONAL_ARGS=()
DTBS=()
OVERLAYS=()
while [[ $# -gt 0 ]]; do
case $1 in
-d|--dtb)
DTBS+=("$2")
shift
shift
;;
-v|--overlay)
OVERLAYS+=("$2")
shift
shift
;;
-m|--modules)
MODULES_PATH="$2"
shift
shift
;;
-o|--out)
KERNEL_OUT_PATH="$2"
shift
shift
;;
-*|--*)
echo "Unknown option $1"
exit 1
;;
*)
POSITIONAL_ARGS+=("$1")
shift
;;
esac
done
set -- "${POSITIONAL_ARGS[@]}"
print_usage() {
echo "usage: $0 <xil|rpi3|rpi4|rpi4-64|nv> [-d <dtb>] [-o <overlay>] [-m <modules_path>] <scp <ip>>"
exit 1
}
if [[ $# -lt 2 ]]; then
print_usage
fi
BOARD_TYPE="$1"
TRANSFER_MODE="$2"
KERNEL_VERSION_PATH=include/config/kernel.release
if [[ "$BOARD_TYPE" = "xil" ]]; then
KERNEL_SRC="arch/arm/boot/uImage"
KERNEL_TARGET="/boot/uImage"
DTB_SINGLE=1
DTB_SRC="arch/arm/boot/dts"
DTB_TARGET="/boot"
DTB_TARGET_NAME="devicetree.dtb"
elif [[ "$BOARD_TYPE" = "rpi3" ]]; then
KERNEL_SRC="arch/arm/boot/zImage"
KERNEL_TARGET="/boot/kernel7.img"
DTB_SRC="arch/arm/boot/dts/"
DTB_TARGET="/boot"
OVERLAYS_SRC="arch/arm/boot/dts/overlays"
OVERLAYS_TARGET="/boot/overlays"
elif [[ "$BOARD_TYPE" = "rpi4" ]]; then
KERNEL_SRC="arch/arm/boot/zImage"
KERNEL_TARGET="/boot/kernel7l.img"
DTB_SRC="arch/arm/boot/dts/"
DTB_TARGET="/boot"
OVERLAYS_SRC="arch/arm/boot/dts/overlays"
OVERLAYS_TARGET="/boot/overlays"
elif [[ "$BOARD_TYPE" = "rpi4-64" ]]; then
KERNEL_SRC="arch/arm/boot/Image"
KERNEL_TARGET="/boot/kernel8.img"
DTB_SRC="arch/arm64/boot/dts/"
DTB_TARGET="/boot"
OVERLAYS_SRC="arch/arm64/boot/dts/overlays"
OVERLAYS_TARGET="/boot/overlays"
elif [[ "$BOARD_TYPE" = "nv" ]]; then
KERNEL_SRC="arch/arm64/boot/Image"
KERNEL_TARGET="/boot/Image"
DTB_PREFIX=kernel_
DTB_SRC="arch/arm64/boot/dts/nvidia"
DTB_TARGET="/boot/dtb"
OVERLAYS_SRC="$DTB_SRC"
OVERLAYS_TARGET="/boot"
elif [[ "$BOARD_TYPE" = "tb-rk3399-vendor-u-boot" ]]; then
KERNEL_SRC="arch/arm64/boot/Image"
KERNEL_TARGET="/boot/extlinux/Image"
DTB_SINGLE=1
DTB_SRC="arch/arm64/boot/dts/rockchip"
DTB_TARGET="/boot/extlinux"
DTB_TARGET_NAME="toybrick.dtb"
else
print_usage
fi
if [[ "$DTB_SINGLE" -eq "1" ]] && [[ "${#DTBS[@]}" -ne "1" ]]; then
echo "Board does not support multiple DTBs"
exit 1
fi
if [[ "$TRANSFER_MODE" = "scp" ]]; then
if [[ $# -lt 3 ]]; then
print_usage
exit 1
fi
IS_SCP=1
IP="$3"
cp_transfer() {
SRC="$1"
TARGET="$2"
echo "Copy $SRC to $TARGET"
scp "$SRC" "root@$IP:$TARGET"
if [[ $? -ne 0 ]]; then
exit 1
fi
}
cmd() {
ssh "root@$IP" "$1"
}
rsync_transfer() {
SRC="$1"
TARGET="$2"
rsync -av --checksum --omit-dir-times --delete "$SRC" "root@$IP":"$TARGET"
}
else
echo "invalid transfer mode"
exit 1
fi
if [[ -z "$KERNEL_OUT_PATH" ]]; then
KERNEL_OUT_PATH="$SOURCE_PATH"
fi
KERNEL_VERSION_PATH="$KERNEL_OUT_PATH/$KERNEL_VERSION_PATH"
KERNEL_SRC="$KERNEL_OUT_PATH/$KERNEL_SRC"
OVERLAYS_SRC="$KERNEL_OUT_PATH/$OVERLAYS_SRC"
DTB_SRC="$KERNEL_OUT_PATH/$DTB_SRC"
cp_transfer "$KERNEL_SRC" "$KERNEL_TARGET"
for OVERLAY in "${OVERLAYS[@]}"; do
cp_transfer "$OVERLAYS_SRC"/"$OVERLAY" "$OVERLAYS_TARGET"
done
for DTB in "${DTBS[@]}"; do
if [[ -n "$DTB_PREFIX" ]]; then
cp_transfer "$DTB_SRC"/"$DTB" "$DTB_TARGET"/"$DTB_PREFIX""$DTB"
else
cp_transfer "$DTB_SRC"/"$DTB" "$DTB_TARGET"/"$DTB_TARGET_NAME"
fi
done
if [[ -n "$IS_SCP" ]] && [[ -n "$MODULES_PATH" ]]; then
KERNEL_VERSION=$(cat "$KERNEL_VERSION_PATH")
rsync_transfer "$MODULES_PATH/lib/modules/$KERNEL_VERSION" "/lib/modules/"
fi
if [[ -n "$IS_SCP" ]]; then
echo "Syncing..."
cmd sync
echo "Reboot?"
select yn in "Yes" "No"; do
case $yn in
Yes)
echo "Rebooting..."
cmd reboot
exit
;;
No)
exit
;;
esac
done
fi