UBOOT_CFG="${UBOOT_DEBUG_PREFIX}/etc/default/onie-u-boot"
UBOOT_ARCH="${UBOOT_ARCH:-$(dpkg --print-architecture)}" || :

if test -r "${UBOOT_CFG}"; then
. ${UBOOT_CFG}
fi

logerr()
{
	echo "ERROR: $@" 1>&2
}

logdbg()
{
	test "xyes" = "x${UBOOT_DEBUG}" && echo "Debug: $@" || true
}

get_grub_address()
{
	echo "${GRUB_ADDRESS:-0x70000000}"
}

get_uboot_path()
{
	echo "${UBOOT_PATH:-${UBOOT_DEBUG_PREFIX}/boot/uboot}"
}

get_uboot_grub_kernel()
{
	echo "$(get_uboot_path)/grub-core.img"
}

get_kernel_version()
{
	if test -z "${LINUX_KERNEL_VERSION}"; then
		linux-version list | linux-version sort | tail -1
	else
		echo "$LINUX_KERNEL_VERSION"
	fi
}

get_dtb_path()
{
	if test -n "${DTB_PATH}"; then
		echo "$DTB_PATH"
	else
		local platform="$(grep -q "cl_platform" ${UBOOT_DEBUG_PREFIX}/proc/cmdline && \
			sed -e 's|^.*cl_platform=\([^[:space:]]*\).*|\1|' \
			${UBOOT_DEBUG_PREFIX}/proc/cmdline || echo "unknown")"
		echo "${UBOOT_DEBUG_PREFIX}/usr/lib/linux-image-$(get_kernel_version)/${platform}.dtb"
	fi
}
