summaryrefslogtreecommitdiff
path: root/tct/minnow_prepare_flash_conf.sh
blob: 8f7308d6531bdd2ce0a89ebbe608e2cb02f7deb6 (plain)
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
#!/bin/sh

# Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Script used to flash, prepare and configure Minnowboard MAX.
# Compatibile with both (32-bit and 64-bit) versions.
# Configuration file in $TL_IP_CONF is required; format is:
#   <IP address> <SDMUX>
# It leaves CONNECT_CNT in sysctl.result to be later used by minnow_run.sh
#
# Synatx is: minnow_prepare_conf_flash.sh $SDMUX $IMAGE
#
# Author: Aleksander Mistewicz <a.mistewicz@samsung.com>

export TESTLAB_SCRIPTS="$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd -P)"

. "${TESTLAB_SCRIPTS}/common.sh"
. "${TESTLAB_SCRIPTS}/flash/flash.sh"
. "${TESTLAB_SCRIPTS}/conf/conf.sh"

SDMUX="$1"
IMAGE="$2"

test -n "${SDMUX}" || die "Missing argument: sdmux!"
test -n "${IMAGE}" || die "Missing argument: image!"
test -f "${IMAGE}" || die "Image file does not exist or is not a regular file: ${IMAGE}!"

IP="$(get_ip "${SDMUX}")" || die "Error: get_ip failed!"

echo "### prepare ###"

switch2testserver "${SDMUX}"

echo "### flash ###"

UUID_FILE="/var/tmp/uuid-${SDMUX}"
DEV_SDCARD=$(uuid2dev "${UUID_FILE}" "${SDMUX}")

echo "Bmaptool: start"
test -b "${DEV_SDCARD}" || die "File does not exist or is not block special"
sudo bmaptool -q copy "${IMAGE}" "${DEV_SDCARD}"
RET=$?
echo "Bmaptool: finish"

change_uuid "${UUID_FILE}" "${DEV_SDCARD}"
if [ $RET -ne 0 ]; then
    die "Bmaptool exited with an error" "$RET"
fi
switch2device "${SDMUX}"
restart_device "${SDMUX}"

echo "### conf ###"

CONNECT_CNT=0
SLEEP=${INIT_SLEEP}

sleep "${SLEEP}"

while ! ping -c 1 "${IP}" -W 1 | grep -q icmp_seq
do
    printf ","
    if [ ${SLEEP} -ge ${MAX_SLEEP} ]
    then
        die "Timeout: host not found in the network!"
    fi
    if [ ${SLEEP} -ge ${RESTART_SLEEP} ]
    then
        echo "Restarting MINNOW" >&2
        restart_device "${SDMUX}"
    fi
    sleep "${SLEEP}"
    SLEEP=$((SLEEP+INC_SLEEP))
    CONNECT_CNT=$((CONNECT_CNT+1))
done

printf "\n"

SLEEP=10

while ! nc -q 1 "${IP}" 22 </dev/null
do
    printf "."
    if [ ${SLEEP} -ge 60 ]
    then
        die "Timeout: ssh port not open!"
    fi
    SLEEP=$((SLEEP+10))
    CONNECT_CNT=$((CONNECT_CNT+1))
done
printf "\n"

echo "CONNECT_CNT $CONNECT_CNT" > sysctl.result