Added scripts from lgcore
[debian6500.git] / simple-cdd / additional_scripts / flash_fe306.sh
1 #!/bin/bash
2
3 # parameters
4 #
5 # ============================================================================
6 #
7 # Copyright (C) THALES. All rights reserved
8 # Author: Laurent Mazet
9 #
10 # 2014-10-06 V1.0 : Creation
11 #
12 # ============================================================================
13
14 DRY=
15 FIRMWARE=/opt/trc6500/config/code_metier/libHwCtrl/Bitstream
16 LIST="application.out production.bin ts12_fp_pano.bin ts22_fp_pano.bin firmware.out"
17 HOST=
18 #TRC6500_SCRIPT_DIR=/opt/trc6500/script
19 TRC6500_SCRIPT_DIR=$(dirname $0)
20
21 # help function
22
23 function usage () {
24 echo "usage: $PROGNAME [-d] [-f dir] [-h] [-i host] [-l list]"
25 echo " -d: dry mode"
26 echo " -f: firmware directory ($FIRMWARE)"
27 echo " -h: help message"
28 echo " -i: board hostname (or ip)"
29 echo " -l: list of firmware ($LIST)"
30 exit $@
31 }
32
33 # formating functions
34
35 function title () { echo -e "\033[0;1m$*\033[0;0m"; }
36 function pass () { echo -e "\033[1;32m$*\033[0;0m"; }
37 function warn () { echo -e "\033[1;33m$*\033[0;0m"; }
38 function fail () { echo -e "\033[1;31m$*\033[0;0m"; }
39
40 # argument processing
41
42 while [ $# -gt 0 ]; do
43 case "$1" in
44 -d) DRY=yes;;
45 -f) shift; FIRMWARE=$1;;
46 -h) usage 0;;
47 -i) shift; HOST=$1;;
48 -l) shift; LIST=$1;;
49 *) usage 1;;
50 esac
51 shift
52 done
53
54 # check host
55
56 [ "$HOST" ] || ping -c 1 $HOST >&/dev/null || \
57 { fail "Can't connect '$HOST'"; exit 1; }
58
59 # check firmware
60
61 for f in $LIST; do
62 [ -f $FIRMWARE/$f ] || { fail "Can't find '$FIRMWARE/$f'"; exit 1; }
63 done
64
65 # check mode
66
67 protect=""
68 [ "$DRY" = yes ] && protect="!echo"
69
70 # flash firmware
71
72 title "flash fe306 '$HOST'"
73
74 ftp -n <<EOF
75 open $HOST
76 quote USER none
77 quote PASS none
78 binary
79 cd flash
80 $(for f in $LIST; do echo "$protect send $FIRMWARE/$f"; done)
81 bye
82 EOF
83
84 # vim:set tabstop=4 shiftwidth=4 softtabstop=4: