forked from alliedvision/linux_nvidia_jetson
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
executable file
·469 lines (423 loc) · 14.5 KB
/
deploy.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
#!/bin/bash
#==============================================================================
# Copyright (C) 2012 - 2019 Allied Vision Technologies. All Rights Reserved.
#
# Redistribution of this file, in original or modified form, without
# prior written consent of Allied Vision Technologies is prohibited.
#
#------------------------------------------------------------------------------
#
# File: deploy.sh
#
# Description: script for installing CSI-2 driver to NVIDIA Jetson boards.
#
#------------------------------------------------------------------------------
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
# NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#==============================================================================
# script settings
#==============================================================================
DEDICATED_VERSION="32.2.1"
DEDICATED_BOARD=""
DEDICATED_BOARD_TX2="TX2"
DEDICATED_BOARD_XAVIER="XAVIER"
DEDICATED_BOARD_NANO="NANO"
FLASH_TARGET_PARTITION=""
FLASH_BOARD_CONFIG=""
FLASH_BOARD_CONFIG_TX2="jetson-tx2"
FLASH_BOARD_CONFIG_XAVIER="jetson-xavier"
FLASH_BOARD_CONFIG_NANO="jetson-nano-qspi-sd"
#==============================================================================
# path settings
#==============================================================================
PATH_CURRENT=$(pwd)
#------------------------------------------------------------------------------
PATH_RESOURCES="${PATH_CURRENT}/resources"
#------------------------------------------------------------------------------
PATH_TARGET_ROOT="${PATH_CURRENT}/${1}"
PATH_TARGET_DEPLOY="$PATH_TARGET_ROOT/deploy"
PATH_TARGET_L4T="${PATH_TARGET_ROOT}/Linux_for_Tegra"
PATH_TARGET_KERNEL="${PATH_TARGET_L4T}/kernel"
PATH_ROOTFS_CHECK="${PATH_TARGET_L4T}/rootfs/etc"
INSTALL_MOD_PATH="~/test/modulesOut"
#==============================================================================
# deploy information
#==============================================================================
FNAME="AlliedVision_NVidia_${DEDICATED_BOARD}_L4T_${DEDICATED_VERSION}_"
KR=`cat ${PATH_CURRENT}/kerneltree/kernel/kernel-4.9/include/config/kernel.release`
FILE_DEVICE_TREE_BLOB_XAVIER="${PATH_TARGET_KERNEL}/dtb/tegra194-p2888-0001-p2822-0000.dtb"
FILE_DEVICE_TREE_BLOB_TX2="${PATH_TARGET_KERNEL}/dtb/tegra186-quill-p3310-1000-c03-00-base.dtb"
FILE_DEVICE_TREE_BLOB_NANO_DEVKIT="${PATH_TARGET_KERNEL}/dtb/tegra210-p3448-0000-p3449-0000-a02.dtb"
FILE_DEVICE_TREE_BLOB_NANO_PRODUCTION="${PATH_TARGET_KERNEL}/dtb/tegra210-p3448-0002-p3449-0000-b00.dtb"
FILE_NANO_DEVKIT_SIGNED_DTB="${PATH_TARGET_L4T}/bootloader/signed/tegra210-p3448-0000-p3449-0000-a02.dtb.encrypt"
FILE_NANO_PRODUCTION_SIGNED_DTB="${PATH_TARGET_L4T}/bootloader/signed/tegra210-p3448-0002-p3449-0000-b00.dtb.encrypt"
FILE_KERNEL_IMAGE="${PATH_TARGET_KERNEL}/Image"
FILE_INSTALL_SCRIPT="${PATH_CURRENT}/resources/deploy/install.sh"
RELATIVE_PATH_KERNEL_MODULES="lib/modules/${KR}"
FILE_DEPLOY_MODULES="modules.tar.gz"
PATH_TARGET_DEPLOY_TMP_FOLDER="${PATH_TARGET_DEPLOY}/${FNAME}${KR}"
#==============================================================================
# include helper scripts
#==============================================================================
source "${PATH_RESOURCES}/common/common.sh"
source "${PATH_RESOURCES}/common/logging.sh"
source "${PATH_RESOURCES}/common/error.sh"
source "${PATH_RESOURCES}/common/directory.sh"
#==============================================================================
# show script usage function
#==============================================================================
usage()
{
log info "Usage: ${SCRIPT_NAME} <L4T> <TARGET_BOARD> <cmd> [--<option>]"
log info "<L4T>.........location of Linux4Tegra setup"
log info "<TARGET_BOARD>....Target board. Possible options: nano, tx2, xavier"
log info "<cmd>.........command to executed"
log info " flash-all"
log info " flash-dtb"
log info " flash-kernel"
log info " tarball"
log info " sd-image <path-to-sd-card-image>"
log info "<option>......possible options:"
log info " --compress....compress SD card image"
log_raw "\n"
}
#==============================================================================
# create tarball from
#==============================================================================
createKernelTarball()
{
if sudo tar --owner root --group root -cjf "${PATH_TARGET_KERNEL}/kernel_supplements.tbz2" "${INSTALL_MOD_PATH}/lib/modules"
then
log debug "Kernel module tarball has been created"
SUCCESS_FLAG=$TRUE
else
log debug "Could not create tarball with kernel modules"
SUCCESS_FLAG=$FALSE
fi
}
#==============================================================================
# create tarball with kernel image and modules
#==============================================================================
createDeployTarball()
{
rm -rf "$PATH_TARGET_DEPLOY"
mkdir -p "$PATH_TARGET_DEPLOY_TMP_FOLDER"
cp "$FILE_INSTALL_SCRIPT" "$PATH_TARGET_DEPLOY_TMP_FOLDER"
cp "$FILE_KERNEL_IMAGE" "$PATH_TARGET_DEPLOY_TMP_FOLDER"
createEncryptedDtb
cp "$FILE_DEVICE_TREE_BLOB_TX2" "$PATH_TARGET_DEPLOY_TMP_FOLDER"
cp "$FILE_DEVICE_TREE_BLOB_XAVIER" "$PATH_TARGET_DEPLOY_TMP_FOLDER"
cp "${FILE_NANO_DEVKIT_SIGNED_DTB}" "$PATH_TARGET_DEPLOY_TMP_FOLDER"
cp "${FILE_NANO_PRODUCTION_SIGNED_DTB}" "$PATH_TARGET_DEPLOY_TMP_FOLDER"
cp "$FILE_DEVICE_TREE_BLOB_NANO_DEVKIT" "$PATH_TARGET_DEPLOY_TMP_FOLDER"
cp "$FILE_DEVICE_TREE_BLOB_NANO_PRODUCTION" "$PATH_TARGET_DEPLOY_TMP_FOLDER"
if ! (cd "${PATH_TARGET_L4T}/rootfs"; tar -zcvf "${PATH_TARGET_DEPLOY_TMP_FOLDER}/${FILE_DEPLOY_MODULES}" "${RELATIVE_PATH_KERNEL_MODULES}")
then
log error "Could not find modules folder!"
SUCCESS_FLAG=$FALSE
else
if (cd "$PATH_TARGET_DEPLOY" && tar -zcvf "${FNAME}${KR}".tar.gz $(basename "${PATH_TARGET_DEPLOY_TMP_FOLDER}"))
then
log debug "Deploy tarball has been created: ${PATH_TARGET_DEPLOY}/${FNAME}${KR}.tar.gz"
SUCCESS_FLAG=$TRUE
else
log error "Could not create tarball with kernel image and device tree files"
SUCCESS_FLAG=$FALSE
fi
fi
}
#==============================================================================
# mount sd card image
#==============================================================================
ROOTFS_PARTITION="1"
DTB_PARTITION="10"
ROOTFS_MNT="/tmp/nano_rootfs"
LOOP_DEVICE=""
mount()
{
img="$1"
LOOP_DEVICE="$(sudo losetup --show -f -P "$img")"
part="${LOOP_DEVICE}p${ROOTFS_PARTITION}"
sudo mkdir -p "$ROOTFS_MNT"
sudo mount "$part" "$ROOTFS_MNT"
}
#==============================================================================
# umount sd card image
#==============================================================================
unmount()
{
sync
sudo umount "$ROOTFS_MNT"
sudo rm -rf "$ROOTFS_MNT"
sleep 1
sudo losetup -d "$LOOP_DEVICE"
}
#==============================================================================
# function for flashing to jetson board
#==============================================================================
flashL4T()
{
PROMPT="+++++ WARNING: THIS WILL ERASE THE TARGET'S FILESYSTEM. CONTINUE? (y/n) +++++"
read -p "`echo $'\n \b' $PROMPT $'\n \b'`" user_input
if [ "$user_input" != "y" ]
then
log debug "User aborted."
SUCCESS_FLAG=$FALSE
return
fi
# go to to Linux4Tegra path
# note: flash.sh script is not running properly
# without being in same path
cd $PATH_TARGET_L4T
# execute NVIDIA flash script
if time sudo ./flash.sh $FLASH_BOARD_CONFIG $FLASH_TARGET_PARTITION
then
log debug "Files has benn flashed to ${3}"
SUCCESS_FLAG=$TRUE
else
log debug "Could not flash files to ${3}"
SUCCESS_FLAG=$FALSE
fi
cd $PATH_CURRENT
}
#==============================================================================
# function for flashing to jetson board
#==============================================================================
flashDtb()
{
# go to to Linux4Tegra path
# note: flash.sh script is not running properly
# without being in same path
cd $PATH_TARGET_L4T
# execute NVIDIA flash script
CMD=""
if [ "$DEDICATED_BOARD" = "$DEDICATED_BOARD_NANO" ]
then
CMD="sudo ./flash.sh -k DTB $FLASH_BOARD_CONFIG $FLASH_TARGET_PARTITION"
else
CMD="sudo ./flash.sh -k kernel-dtb $FLASH_BOARD_CONFIG $FLASH_TARGET_PARTITION"
fi
if time eval "${CMD}"
then
log debug "Dtb has been flashed to ${3}"
SUCCESS_FLAG=$TRUE
else
log debug "Could not flash files to ${3}"
SUCCESS_FLAG=$FALSE
fi
cd $PATH_CURRENT
}
#==============================================================================
# function for flashing to jetson board
#==============================================================================
flashKernel()
{
# go to to Linux4Tegra path
# note: flash.sh script is not running properly
# without being in same path
cd $PATH_TARGET_L4T
# execute NVIDIA flash script
if time eval "sudo ./flash.sh -k kernel $FLASH_BOARD_CONFIG $FLASH_TARGET_PARTITION"
then
log debug "Kernel image has been flashed to ${3}"
SUCCESS_FLAG=$TRUE
else
log debug "Could not flash files to ${3}"
SUCCESS_FLAG=$FALSE
fi
cd $PATH_CURRENT
}
#==============================================================================
# Create encrypted dtb for the Nano
#==============================================================================
createEncryptedDtb ()
{
TMP_SD_BLOB="/tmp/sd-blob.img"
if ! ( cd "${PATH_TARGET_L4T}" && sudo ./create-jetson-nano-sd-card-image.sh -o "${TMP_SD_BLOB}" -s 4G -r 200 )
then
log error "Failed to run Nvidia script \"create-jetson-nano-sd-card-image.sh\""
SUCCESS_FLAG=$FALSE
fi
sudo rm -rf "${TMP_SD_BLOB}"
if proceed && [ ! -f "${FILE_NANO_DEVKIT_SIGNED_DTB}" ]
then
log error "Failed to create encrypted dtb. Aborting."
SUCCESS_FLAG=$FALSE
else
SUCCESS_FLAG=$TRUE
fi
}
#==============================================================================
# running script
#==============================================================================
log info "Running script for flashing Linux4Tegra setup"
log debug "dedicated for L4T: ${DEDICATED_VERSION} and Jetson ${DEDICATED_BOARD}"
# parameter check
#------------------------------------------------------------------------------
if ! parameter_exist $1 || ! parameter_exist $2 || ! parameter_exist $3
then
log error "Missing parameter!"
SUCCESS_FLAG=$FALSE
usage
exit 1
fi
# check if help was called
#------------------------------------------------------------------------------
if proceed && check_parameter $1 "help"
then
usage
exit 1
fi
# check if given L4T parameter is valid setup directory
#------------------------------------------------------------------------------
if proceed && ! directory_exist $1
then
log error "Could not find L4T setup directory! Please run setup script first"
SUCCESS_FLAG=$FALSE
exit 1
fi
if proceed
then
if check_parameter $2 "tx2"
then
DEDICATED_BOARD="$DEDICATED_BOARD_TX2"
FLASH_BOARD_CONFIG="$FLASH_BOARD_CONFIG_TX2"
elif check_parameter $2 "xavier"
then
DEDICATED_BOARD="$DEDICATED_BOARD_XAVIER"
FLASH_BOARD_CONFIG="$FLASH_BOARD_CONFIG_XAVIER"
elif check_parameter $2 "nano"
then
DEDICATED_BOARD="$DEDICATED_BOARD_NANO"
FLASH_BOARD_CONFIG="$FLASH_BOARD_CONFIG_NANO"
else
log error "Invalid parameter for <TARGET_BOARD>!"
SUCCESS_FLAG=$FALSE
usage
fi
fi
#------------------------------------------------------------------------------
if proceed
then
if check_parameter $3 "flash-all"
then
# check if rootfs is present
if [ ! -d "$PATH_ROOTFS_CHECK" ]
then
log error "Could not find L4T rootfs! Please run setup script with param --rootfs first"
else
log info "Linux4Tegra will be flashed to target board"
FLASH_TARGET_PARTITION="mmcblk0p1"
flashL4T
if proceed
then
log success
else
log failed
fi
fi
elif check_parameter $3 "flash-dtb"
then
log info "Device tree blob will be flashed to target board"
FLASH_TARGET_PARTITION="mmcblk0p1"
flashDtb
if proceed
then
log success
else
log failed
fi
elif check_parameter $3 "flash-kernel"
then
log info "Kernel image will be flashed to target board"
FLASH_TARGET_PARTITION="mmcblk0p1"
flashKernel
if proceed
then
log success
else
log failed
fi
elif check_parameter $3 "tarball"
then
log info "Creating deployable tarball with kernel image and device tree files"
createDeployTarball
if proceed
then
log success
else
log failed
fi
elif check_parameter $3 "sd-image"
then
if ! check_parameter $2 "nano"
then
log error "SD card image creation only supported for the Nano! Aborting."
exit 1
fi
if ! parameter_exist $4
then
log error "No SD card image passed! Aborting."
usage
exit 1
fi
if [ ! -f "${4}" ]
then
log error "Invalid path to SD card image: \"${SD_CARD}\". Aborting."
exit 1
fi
mkdir "${PATH_TARGET_DEPLOY}"
log info "Copying SD card image..."
SD_CARD="${PATH_TARGET_DEPLOY}/${FNAME}${KR}.img"
if ! rsync -ah --info=progress2 "${4}" "${SD_CARD}"
then
log error "Error copying SD card image. Aborting."
exit 1
fi
mount "${SD_CARD}"
if [ "$?" != 0 ]
then
log error "Could not mount SD card image: \"${SD_CARD}\". Aborting."
rm -rf "${SD_CARD}"
exit 1
fi
# copy kernel image and modules
sudo cp "${FILE_KERNEL_IMAGE}" "${ROOTFS_MNT}/boot/Image"
sudo cp -r "${PATH_TARGET_L4T}/rootfs/${RELATIVE_PATH_KERNEL_MODULES}" "${ROOTFS_MNT}/lib/modules"
createEncryptedDtb
if ! proceed
then
rm -rf "${SD_CARD}"
unmount
log error
exit 1
fi
# copy encrypted dtb to sd card partition
sudo dd if="${FILE_NANO_DEVKIT_SIGNED_DTB}" of="${LOOP_DEVICE}p${DTB_PARTITION}"
unmount
if check_parameter $5 "--compress"
then
if hash pigz 2>/dev/null; then
pigz "${SD_CARD}"
else
tar -zcf "${SD_CARD}.tar.gz" "${SD_CARD}"
rm "${SD_CARD}"
fi
fi
log info "SD card image created: \"${SD_CARD}\""
log success
else
log error "Missing or invalid parameters"
usage
fi
fi