#
# SPDX-License-Identifier: GPL-2.0
#
# Copyright (c) 2013-2023 Igor Pecovnik, igor@armbian.com
#
# This file is a part of the Armbian Build Framework
# https://github.com/armbian/build/
#

ARCH="arm64"

LINUXFAMILY="phytium-embedded"

case "${BRANCH}" in

	legacy)
		KERNELSOURCE='https://github.com/chainsx/phytium-linux-kernel'
		KERNELBRANCH="branch:linux-5.10"
		declare -g KERNEL_MAJOR_MINOR="5.10"
		KERNELPATCHDIR="${LINUXFAMILY}-${BRANCH}"
		LINUXCONFIG="linux-${LINUXFAMILY}-${BRANCH}"

		;;

esac

write_uboot_platform() {
	declare ptuboot_cache_dir="${SRC}/cache/phytiumpi-uboot"
	mkdir -p "${ptuboot_cache_dir}"
	
	sfdisk --dump "$2" > "${ptuboot_cache_dir}/part.txt"                              # Backup partition table, command sfdisk is belong to util-linux
	dd if="${SRC}/packages/blobs/phytiumpi/fip-all-sd-boot.bin" of="$2" conv=notrunc      # Write non-free u-boot file
	sfdisk --no-reread "$2" < "${ptuboot_cache_dir}/part.txt"                         # Recover partition table
	
	# Update u-boot env
	mkenvimage -s 0x1000 -o "${ptuboot_cache_dir}/env.bin" "${SRC}/packages/blobs/phytiumpi/env.txt"
	dd if="${ptuboot_cache_dir}/env.bin" of="$2" bs=1k seek=1472 conv=notrunc
	rm -rf "${ptuboot_cache_dir}"
}
