#!/bin/bash

# (C) Copyright 2020 - 2021 Xilinx, Inc.
# SPDX-License-Identifier: Apache-2.0

#!/bin/bash

SUP_PLATFORMS="vck190_mipiRxSingle_hdmiTx"

if [ ! -e ./.petalinux/metadata ]; then
	echo -e "This script must be run from the project top level"
	exit 4
fi

function print_list() {
	echo -e "Platforms:"
	for pfm in ${SUP_PLATFORMS}; do
		echo -e "  ${pfm}"
	done
}

function print_help() {
	echo -e "Usage:"
	echo -e "  $0 [-h|--help]"
	echo -e "Options:"
	echo -e "  -h, --help       Display this help and exit"
	echo -e "  -l, --list       List supported targets platforms and designs"
	echo -e "  -p, --platform   Target platform (default: vck190)"
}

while [ "$1" != "" ]; do
	case $1 in
	-h | --help )
		print_help $0
		exit 0
		;;
	-l | --list )
		print_list
		exit 0
		;;
	-p | --platform )
		shift
		PLATFORM=$1
		;;
	*)
		echo "invalid argument '$1'"
		exit 1
		;;
	esac
	shift
done

# symlink DT
pushd project-spec/meta-user/recipes-bsp/device-tree/files > /dev/null
dt=${PLATFORM}.dtsi
if [ ! -e ${dt} ]; then
	echo "device tree ${dt} not found"
	exit 6
fi
rm -f pl-custom.dtsi
ln -s ${dt} pl-custom.dtsi
popd > /dev/null

