blob: a82695c6346c6a2004c07c163722463bd2d263e7 [file] [log] [blame]
Leonardo Sandovalb0efb542021-05-31 11:43:27 -05001#!/usr/bin/env bash
2#
3# Copyright (c) 2021 Arm Limited. All rights reserved.
4#
5# SPDX-License-Identifier: BSD-3-Clause
6#
7
8# Given the name of the release (e.g., 18.04), this script downloads all
9# Linaro release archives to the current directory, verifies, extracts, and
10# finally removes the archive files.
11
12# FVP launcher: Script that generates docker and baremetal commands based on LAVA
13# log stored at [TF Open CI](http://ci.trustedfirmware.org/)
14#
15# Usage:
16# Run the `fvp-launcher.sh` script, providing a https://ci.trustedfirmware.org/view/TF-A/job/tf-a-builder/
17# job as parameter, for example
18#
19# $ ./fvp-launcher.sh https://ci.trustedfirmware.org/job/tf-a-builder/252606/
20#
21# executon will fetch all artefacts locally and finally generating the two commands: docker and baremetal commands,
22# any can be run depending on the scenario.
23
24
25# safe execution
26set -ue
27
28function r_curl(){
29 local target="$1"
30 local source="$2"
31 curl --connect-timeout 5 --retry 5 --retry-delay 1 -fsSLo "$1" "$2"
32}
33
34declare -A saveas
35declare -A urls
36
37## Must params
Saheer Babubdb0d652025-02-10 14:08:20 +000038JENKINS_PUBLIC_URL="${1:?}"
Leonardo Sandovalb0efb542021-05-31 11:43:27 -050039
40
41## Optional params passed through env variables
42USE_LOCAL_IMAGE="${USE_LOCAL_IMAGE:-false}"
43NO_ARM_LICENSE="${NO_ARM_LICENSE:-true}"
44NO_TTY="${NO_TTY:-true}"
45LAVA_LOG="${LAVA_LOG:-./lava.log}"
46DOCKER_CMDS_FILE="${DOCKER_CMDS_FILE:-./docker.txt}"
47BM_CMDS_FILE="${BM_CMDS_FILE:-./bm.txt}"
48
Saheer Babubdb0d652025-02-10 14:08:20 +000049JENKINS_PUBLIC_URL="${JENKINS_PUBLIC_URL}/artifact/lava.log"
Leonardo Sandovalb0efb542021-05-31 11:43:27 -050050
51
52# Fetch the LAVA log
Saheer Babubdb0d652025-02-10 14:08:20 +000053r_curl "${LAVA_LOG}" "${JENKINS_PUBLIC_URL}"
Leonardo Sandovalb0efb542021-05-31 11:43:27 -050054
55# Get download directories from the lava log
56i=1
57for sa in $(awk '/saving as/ {print $4}' $LAVA_LOG); do
58 # NOTE the leading dot, which modifies original LAVA paths
59 saveas[$i]=".$sa"
60 i=$((i + 1))
61done
62
63i=1
64# Get the artefacts from the lava log
65for url in $(awk '/downloading/ {print $3}' $LAVA_LOG); do
66 urls[$i]="$url"
67 i=$((i + 1))
68done
69
70total=$((i -1))
71
72# Fetch artefacts and place it under top dir
73mkdir -p $PWD/lava
74i=1
75for i in $(seq $total); do
76 u=${urls[$i]}
77 o=${saveas[$i]}
78
79 mkdir -p $(dirname $o)
80
81 # Just fetch in case artefact is not present
82 if [ ! -f $o ]; then
83 r_curl "$o" "$u"
84 fi
85 cp -f $o $PWD/lava
86done
87
88# allow docker to use local X windows
89xhost + > /dev/null
90
91rm -f ${DOCKER_CMDS_FILE} ${BM_CMDS_FILE}
92
93grep -o -E 'docker run .*' $LAVA_LOG | tail -1 | while read line; do
94 cmd="$line"
95 cmd="$(echo $cmd | sed -e 's;docker run;docker run --env="DISPLAY" --net=host ;g')"
96
97 if [[ "${NO_TTY}" == "true" ]]; then
98 cmd="$(echo $cmd | sed 's/--tty//g')"
99 fi
100
101 if [[ "${NO_ARM_LICENSE}" == "true" ]]; then
102 cmd="$(echo $cmd | sed 's/-e ARMLMD_LICENSE_FILE=27000@ci.trustedfirmware.org//g')"
103 fi
104
105 if [[ "${USE_LOCAL_IMAGE}" == "true" ]]; then
Arthur She37d95752025-02-03 21:48:10 -0800106 cmd="$(echo $cmd | sed 's/${PRIVATE_CONTAINER_REGISTRY}\///g')"
Leonardo Sandovalb0efb542021-05-31 11:43:27 -0500107 fi
108
109 docker_cmd="$(echo $cmd | sed "s;--volume /;--volume $PWD/;g")"
110
111 # Point model parameters to local lava folder
112 bm_cmd=""
113 for token in $docker_cmd; do
114 bm_token="$(echo $token | sed "s;=/lava.*/;=$PWD/lava/;g")"
115 bm_cmd="$bm_cmd $bm_token "
116 done
117
118 # trim the docker leading code
119 bm_cmd="$(echo "${bm_cmd}" | sed 's;.* /opt/model;/opt/model;g')"
120
121 echo "$docker_cmd" >> $DOCKER_CMDS_FILE
122 echo "$bm_cmd" >> $BM_CMDS_FILE
123
124done
125
126echo "Docker command"
127echo
128cat $DOCKER_CMDS_FILE
129echo
130
131echo "Baremetal command"
132echo
133cat $BM_CMDS_FILE
134echo
135