Introduce FVP docker file generator
Scripts that creates dockerfile/dockerimages with FVP models installed
to be consumed by a FVP LAVA device. Instructions to create docker
images are located on the README file
Change-Id: If2b0767b387a9530238d13239afbd6e249533be4
Signed-off-by: Leonardo Sandoval <leonardo.sandoval@linaro.org>
diff --git a/script/docker/fvp/Makefile b/script/docker/fvp/Makefile
new file mode 100644
index 0000000..8ffc9c1
--- /dev/null
+++ b/script/docker/fvp/Makefile
@@ -0,0 +1,47 @@
+#
+# Copyright (c) 2020, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+# Makefile rules to help creating docker images based on a fvp model tarballs
+
+# allow user to possible define other dir for model tarballs
+TGZ_DIR ?= .
+
+# directory for docker build work
+WORKSPACE ?= workspace
+
+# find all tarballs located at TGZ_DIR
+tgzs=$(shell ls $(TGZ_DIR)/F*.tgz 2>/dev/null)
+
+define create-docker-image
+# tag varible is used so uniquely identify a model
+# and it is used to workspace directory and docker tag
+ tag=$(shell ./create-model-tag.sh $@) && \
+ tarball=$(shell basename $@) && \
+ rm -rf $(WORKSPACE)/$${tag} && \
+ mkdir -p $(WORKSPACE)/$${tag} && \
+ cp $@ $(WORKSPACE)/$${tag} && \
+ ./create-model-dockerfile.sh $${tarball} $(WORKSPACE)/$${tag} && \
+ docker build --tag fvp:$${tag} $(WORKSPACE)/$${tag} > /dev/null && \
+ echo "Docker image created" && \
+ echo "Docker image name: (fvp:$${tag})" && \
+ echo "Docker Model files:" && \
+ echo "$$(docker run fvp:$${tag} ls)" && \
+ echo "Dockerfile: $(WORKSPACE)/$${tag}/Dockerfile"
+endef
+
+ifeq ($(tgzs),)
+all:
+ @echo No model tarballs found && exit 0
+else
+all: $(tgzs)
+$(tgzs):
+ $(create-docker-image)
+endif
+
+clean:
+ rm -rf $(WORKSPACE)
+
+.PHONY: $(tgzs)
diff --git a/script/docker/fvp/README.md b/script/docker/fvp/README.md
new file mode 100644
index 0000000..e82e790
--- /dev/null
+++ b/script/docker/fvp/README.md
@@ -0,0 +1,83 @@
+
+Copyright (c) 2020, Arm Limited. All rights reserved.
+
+SPDX-License-Identifier: BSD-3-Clause
+
+
+LAVA FVP containers
+==============
+
+Scripts that create dockerfile/dockerimages with FVP models installed to be consumed by a FVP LAVA device.
+
+Build
+=====
+
+Fetch any FVP model from [ARM sites][2][4] and either place the tarballs either inside current project and
+type `make`. This will create new docker images.
+
+For example, lets assume that we download the model `FVP_Base_Cortex-A35x124_11.11_34.tgz` and store at current
+directory as seen below:
+
+```bash
+ls -la
+total 46858
+drwxrwxr-x 3 lsandov1 lsandov1 4096 2020-08-28 13:33 .
+drwxrwxr-x 9 lsandov1 lsandov1 4096 2020-08-28 13:13 ..
+-rw-rw-r-- 1 lsandov1 lsandov1 47966029 2020-08-28 13:29 FVP_Base_Cortex-A35x124_11.11_34.tgz
+-rw-rw-r-- 1 lsandov1 lsandov1 540 2020-07-03 11:49 Makefile
+-rw-rw-r-- 1 lsandov1 lsandov1 2405 2020-08-28 13:32 README.md
+-rwxrwxr-x 1 lsandov1 lsandov1 691 2020-07-03 11:36 create_fvp_dockerfile.sh
+-rw-rw-r-- 1 lsandov1 lsandov1 753 2020-08-05 22:21 dockerfile-template
+-rwxrwxr-x 1 lsandov1 lsandov1 171 2020-07-03 10:56 tag.sh
+drwxrwxr-x 3 lsandov1 lsandov1 4096 2020-08-28 13:33 ws
+```
+
+then execute `make`
+
+```bash
+make
+base=FVP_Base_Cortex-A35x124_11.11_34.tgz && \
+tag=fvp_base_cortex-a35x124_11.11_34 && \
+mkdir -p ws/${tag} && \
+cp FVP_Base_Cortex-A35x124_11.11_34.tgz ws/${tag} && \
+./create_fvp_dockerfile.sh ws/${tag} ${base} && \
+docker build --tag fvp:${tag} ws/${tag}/
+Sending build context to Docker daemon 47.97MB
+Step 1/6 : FROM ubuntu:bionic
+ ---> 6526a1858e5d
+Step 2/6 : RUN apt-get update && apt-get install --no-install-recommends --yes bc libatomic1 telnet libdbus-1-3 xterm && rm -rf /var/cache/apt
+ ---> Using cache
+ ---> 822600bee149
+Step 3/6 : RUN mkdir /opt/model
+ ---> Using cache
+ ---> 58db835c0b3c
+Step 4/6 : ADD FVP_Base_Cortex-A35x124_11.11_34.tgz /opt/model
+ ---> Using cache
+ ---> bb634f5def64
+Step 5/6 : RUN cd /opt/model && /opt/model/FVP_Base_Cortex-A35x124.sh --i-agree-to-the-contained-eula --verbose --destination /opt/model/FVP_Base_Cortex-A35x124
+ ---> Using cache
+ ---> 49989d166049
+Step 6/6 : WORKDIR /fvp
+ ---> Using cache
+ ---> cc3a4494599a
+Successfully built cc3a4494599a
+Successfully tagged fvp:fvp_base_cortex-a35x124_11.11_34
+~/repos/tf/dockerfiles/fvp $
+```
+
+as seen in the log above, a new docker image has been created `fvp:fvp_base_cortex-a35x124_11.11_34`.
+In case you want to see the `Dockerfile` for this particular model, check the following directory
+`$PWD/ws/fvp_base_cortex-a35x124_11.11_34/Dockerfile`
+
+Rerefence dockerfile
+====================
+
+The [dockerfile](./dockerfile-template) use on this project is similar to the [reference dockerfile][1]
+but the former also installs the model. The reason to this extra step is that [LAVA][3] expects the
+container with the model installed.
+
+
+[1]: https://validation.linaro.org/static/docs/v2/fvp.html?highlight=fvp
+[2]: https://developer.arm.com/tools-and-software/simulation-models/fixed-virtual-platforms
+[3]: https://git.lavasoftware.org/lava/lava
+[4]: https://silver.arm.com/browse/FM000
diff --git a/script/docker/fvp/create-model-dockerfile.sh b/script/docker/fvp/create-model-dockerfile.sh
new file mode 100755
index 0000000..8b561eb
--- /dev/null
+++ b/script/docker/fvp/create-model-dockerfile.sh
@@ -0,0 +1,59 @@
+#!/bin/bash
+#
+# Copyright (c) 2020, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+# Creates a dockerfile based on a fvp model (model).
+
+# The scripts takes two argument: the model tarball's filename (first argument)
+# and target directory to store the created Dockerfile (second argument)
+#
+
+# globals
+OS="${OS:-ubuntu}"
+OS_VER="${OS_VERSION:-bionic}"
+MODEL_DIR="${MODEL_DIR:-/opt/model}"
+
+function usage() {
+ echo "Usage: $0 model-tarball target-dir" 1>&2
+ exit 1
+}
+
+function get_model_model_ver() {
+ local tgz=$1
+ local arr_model=(${tgz//./ })
+ local x=${arr_model[0]##*_}
+ local y=${arr_model[1]}
+ local z=${arr_model[2]}
+ if [ -n "$z" -a "$z" != "tgz" ]; then
+ MODEL_VER="${x}.${y}.${z}"
+ else
+ MODEL_VER="${x}.${y}"
+ fi
+ MODEL=$(echo $tgz | sed "s/_${MODEL_VER}.tgz//")
+}
+
+function main() {
+ local tarball=$1
+ local target_dir=$2
+
+ # get MODEL and MODEL_VER
+ get_model_model_ver $tarball
+
+ # check variables are populated
+ MODEL="${MODEL:?}"
+ MODEL_VER="${MODEL_VER:?}"
+
+ # replace template macros with real model values
+ sed -e "s|\${OS}|${OS}|g" \
+ -e "s|\${OS_VER}|${OS_VER}|g" \
+ -e "s|\${MODEL}|${MODEL}|g" \
+ -e "s|\${MODEL_VER}|${MODEL_VER}|g" \
+ -e "s|\${MODEL_DIR}|${MODEL_DIR}|g" < dockerfile-template > $target_dir/Dockerfile
+}
+
+[ $# -ne 2 ] && usage
+
+tarball=$1; target_dir=$2; main ${tarball} ${target_dir}
diff --git a/script/docker/fvp/create-model-tag.sh b/script/docker/fvp/create-model-tag.sh
new file mode 100755
index 0000000..7a02f45
--- /dev/null
+++ b/script/docker/fvp/create-model-tag.sh
@@ -0,0 +1,37 @@
+#!/bin/bash
+#
+# Copyright (c) 2010, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+# Creates a 'tag' based on a fvp model (model).
+#
+# The script takes a single argument: the model tarball's filename (first argument)
+#
+
+function usage() {
+ echo "Usage: $0 model-tarball" 1>&2
+ exit 1
+}
+
+# Create a tag based a on fvp model
+function create-tag() {
+ local model=$1
+ local tag
+
+ # get model basename
+ tag=$(basename $model)
+
+ # remove any extension (tgz expected)
+ tag=${tag%.*}
+
+ # finally lowercase
+ tag=${tag,,}
+
+ echo $tag
+}
+
+[ $# -ne 1 ] && usage
+
+tarball=$1; create-tag ${tarball}
diff --git a/script/docker/fvp/dockerfile-template b/script/docker/fvp/dockerfile-template
new file mode 100644
index 0000000..e124865
--- /dev/null
+++ b/script/docker/fvp/dockerfile-template
@@ -0,0 +1,23 @@
+FROM ${OS}:${OS_VER}
+
+ENV ARMLMD_LICENSE_FILE=27000@ci.trustedfirmware.org
+
+# Install package required
+RUN apt-get update && \
+ apt-get install --no-install-recommends --yes bc libatomic1 telnet libdbus-1-3 xterm && \
+ rm -rf /var/cache/apt
+
+# Create model directory
+RUN mkdir ${MODEL_DIR}
+
+# Add FVP Binaries
+ADD ${MODEL}_${MODEL_VER}.tgz ${MODEL_DIR}
+
+# Install the model
+RUN cd ${MODEL_DIR} && \
+ ${MODEL_DIR}/${MODEL}.sh \
+ --i-agree-to-the-contained-eula \
+ --verbose \
+ --destination ${MODEL_DIR}/${MODEL}
+
+WORKDIR /opt/model/${MODEL}/models/Linux64_GCC-6.4/
\ No newline at end of file