blob: 824a9fe4c0ef5291a02e866cfacaee88be71b382 [file] [log] [blame]
#!/bin/bash
# Copyright 2019,2020 NXP
#
# SPDX-License-Identifier: Apache-2.0
#
# Pass zipped MW as argument to script.
# Filename of zip archive is supposed to as:
#
# se050_mw_v[NN].[NN].[NN].zip
#
# For example: se050_mw_v02.07.00.zip
#
# 2020-08-25
# - Initial version for Raspbian
#
# Global variables
# ----------------
root_dir="/home/pi"
# UTILITY FUNCTIONS
# -----------------
# execCommand will stop script execution when the program executed did not return OK (i.e. 0) to the shell
execCommand () {
local command="$*"
echo ">> ${command}"
${command}
local nRetProc="$?"
if [ ${nRetProc} -ne 0 ]
then
echo "\"${command}\" failed to run successfully, returned ${nRetProc}"
exit 2
fi
echo ""
}
dummyCommand () {
local command="$*"
echo ">> ${command}"
# ${command}
local nRetProc="$?"
if [ ${nRetProc} -ne 0 ]
then
echo "\"${command}\" failed to run successfully, returned ${nRetProc}"
exit 2
fi
echo ""
}
if [ -z "$1" ]; then
echo "Please provide zip archive containing MW as argument"
exit 2
else
mw_package="$1"
fi
# Cd to directory where script is stored
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
echo ${SCRIPT_DIR}
cd ${SCRIPT_DIR}
echo "Installing ${mw_package}"
mw_dir_name=${mw_package%.*} # Back delete
mw_build_area_dir_name="${mw_dir_name}/simw-top_build"
# This script is being modified so it is no longer tied to a specific revision.
# The initial version only worked for 02.07.00
mw_name=${mw_package%.zip} # strip .zip extension
mw_version=${mw_name#*_mw_} # only keep vNN.NN.NN
echo ${mw_version}
# Check on version (filename based) and only use with version 02.07.00
# if [ "${mw_version}" != "v02.07.00" ]; then
# echo "This MW installation script contains patches specific to version v02.07.00"
# echo "It cannot be used to install ${mw_package} (version=${mw_version})"
# echo "Error: Failed to install package ${mw_package}"
# exit 4
# fi
# Check for unlikely date (in case NTP server is not reacheable date defaults to build date of Yocto image)
atLeastDate=$(date -d 2020-01-12 +%s)
currentDate=$(date +%s)
if [ ${currentDate} -le ${atLeastDate} ]; then
echo "System date is not correct:"
date
echo "You can manually set the date like"
echo " date -s '2019-05-07 14:20'"
echo "and then rerun the script"
echo ""
echo "Note: a wrong system date may cause compilation and installation issues"
exit 5
fi
# Ensure target directory does not yet exist
if [ -d "${root_dir}/${mw_dir_name}" ]; then
echo "Installation error: ${root_dir}/${mw_dir_name} already exists"
echo "Error: Failed to install package ${mw_package}"
exit 3
fi
# Ensure build directory does not yet exist
if [ -d "${root_dir}/${mw_build_area_dir_name}" ]; then
echo "Installation error: ${root_dir}/${mw_build_area_dir_name} already exists"
echo "Error: Failed to install package ${mw_package}"
exit 3
fi
execCommand "mkdir -p ${root_dir}/mnt"
execCommand "mkdir ${root_dir}/${mw_dir_name}"
execCommand "cp ${mw_package} ${root_dir}/${mw_dir_name}"
execCommand "cd ${root_dir}/${mw_dir_name}"
execCommand "unzip ${mw_package}"
execCommand "cd ${root_dir}/${mw_dir_name}/simw-top"
execCommand "python3 scripts/create_cmake_projects.py"
execCommand "rm ${root_dir}/${mw_dir_name}/${mw_package}"
execCommand "cd ${root_dir}/${mw_build_area_dir_name}/raspbian_native_se050_t1oi2c"
execCommand "cmake -L ."
# execCommand "cmake -DSE05X_Auth:STRING=None -DHostCrypto:STRING=MBEDTLS -DmbedTLS_ALT:STRING=SSS ."
execCommand "cmake -DSE05X_Auth:STRING=None ."
execCommand "cmake $2 ."
execCommand "cmake --build ."
execCommand "sudo make install"
execCommand "sudo ldconfig /usr/local/lib"
execCommand "cd ${root_dir}/${mw_dir_name}/simw-top"
find . -name "*.sh" -exec chmod 755 {} \;
# sudo apt-get install python3-pip
# sudo apt-get install libffi-dev
execCommand "cd pycli"
execCommand "pip3 install -r requirements.txt"
execCommand "cd src"
execCommand "sudo python3 setup.py develop"
# The following won't work in case host crypto != OpenSSL
# #######################################################
# Compile TLS client
execCommand "cd ${root_dir}/${mw_dir_name}/simw-top/demos/linux/tls_client/build"
execCommand "cmake ../."
execCommand "cmake --build ."
# #########################################
# Verification (In case SE050 is connected)
# cd ../../sss/plugin/openssl/scripts
# python3 openssl_provisionEC.py prime192v1 t1oi2c none
# python3 openssl_EccSign.py prime192v1