Xilinx FPGA_as_a_Service之Xilinx Base Runtime脚本分析 run.sh

看其中的usage函数,列出了脚本参数的使用

usage() {
    echo "Running run.sh to start a docker container for XRT runtime. "
    echo ""
    echo "Usage:"
    echo "./run.sh      --version  --os-version "
    echo "./run.sh       -v         -o          "
    echo "      : 2018.3 / 2019.1 / 2019.2"
    echo "   : ubuntu-18.04 / ubuntu-16.04 / centos"
    echo ""
    echo "Example:"
    echo "Start docker container whith 2019.2 XRT on Ubuntu 18.04"
    echo "  ./run.sh -v 2019.2 -o ubuntu-18.04"
    echo ""
    echo "Additional parameters: "
    echo "-c [command] : Execute specific command when start docker container"
    echo "--pull       : Pull docker image before run"

}

参数初始化和确认安装xrt并刷新shell

COMMAND="/bin/bash"
PLATFORM="alveo-u200"
UPDATE=0
/opt/xilinx/xrt/bin/xbutil list > /dev/null
if [ $? != 0 ] ; then
	echo "Please check XRT is installed and Shell is flashed on FPGA. See:"
	echo "/opt/xilinx/xrt/bin/xbutil list"
	echo ""
	echo "You can use host_setup.sh to install and flash. "
	exit 1
fi

确认安装docker

check_docker() {
    DOCKER_INFO=`docker info 2>/dev/null`
    if [ $? == 0 ] ; then
        return 0
    fi
    OSVERSION=`grep '^ID=' /etc/os-release | awk -F= '{print $2}' | tr -d '"'`

    if [[ "$OSVERSION" == "ubuntu" ]]; then
        DOCKER_INFO=`apt list --installed 2>/dev/null | grep docker-ce`
    elif [[ "$OSVERSION" == "centos" ]]; then
        DOCKER_INFO=`yum list installed 2>/dev/null | grep docker-ce`
    else
        return 0
    fi
    if [ $? == 0 ] ; then
        DOCKER_INFO=`docker info 2>/dev/null`
        if [ $? != 0 ] ; then
            docker info
            return 1
        fi
    else
        echo "Docker is NOT installed. Please run "
        echo "    ./utilities/docker_install.sh"
        echo "to install docker service. "
        return 1
    fi
}

参数解析

while true
do
case "$1" in
	-v|--version         ) VERSION="$2"      ; shift 2 ;;
	-o|--os-version      ) OSVERSION="$2"    ; shift 2 ;;
	-c                   ) COMMAND="$2"      ; shift 2 ;;
	--pull               ) UPDATE=1          ; shift 1 ;;
	-h|--help            ) usage             ; exit  1 ;;
*) break ;;
esac
done

if [ $? != 0 ] ; then echo "Failed parsing options." >&2 ; usage; exit 1 ; fi

确认板卡是否为需要特殊处理的u50

if [[ "$VERSION" == "2019.1" ]]; then
    read -r -p "${1:-Is this for U50? [y/n]:} " response
    case "$response" in
        [yY][eE][sS]|[yY]) 
            PLATFORM="alveo-u50"
            ;;
        *)
            ;;
    esac
fi

配置文件conf/spec.txt中查找对应的IMAGE TAG

COMB="${PLATFORM}_${VERSION}_${OSVERSION}"

if grep -q $COMB "conf/spec.txt"; then
    IMAGE_TAG=`grep ^$COMB: conf/spec.txt | awk -F':' '{print $2}' | awk -F';' '{print $5}' | awk -F= '{print $2}'`
else
    usage
    echo ""
    list
    exit 1
fi

Xilinx FPGA_as_a_Service之Xilinx Base Runtime脚本分析 run.sh_第1张图片

DOCKER_IMAGE="xilinx/xilinx_runtime_base:$IMAGE_TAG"   
# Mapping XRT user function and management function
DEVICES=""
for xclf in /dev/xclmgmt*
do
	DEVICES="$DEVICES --device=$xclf:$xclf"
done
for usrf in /dev/dri/renderD*
do
	DEVICES="$DEVICES --device=$usrf:$usrf"
done

if [[ "$UPDATE" == 1 ]]; then
	#Update docker image
	echo "Pull docker image: $DOCKER_IMAGE"
	docker pull $DOCKER_IMAGE
fi

运行docker,并且可以有附带的命令

echo "Run docker as:"
echo "docker run --rm $DEVICES -it $DOCKER_IMAGE"
docker run \
	--rm \
	$DEVICES \
	-it \
	$DOCKER_IMAGE \
	/bin/bash -c \
	"$COMMAND"

你可能感兴趣的:(FPGA开发,fpga)