# Copyright 2021 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 EAPI=7 META_SIFIVE="2021.07" UBOOT_COMMIT="840658b093976390e9537724f802281c9c8439f5" DESCRIPTION="U-Boot with meta-sifive-${META_SIFIVE} patches" HOMEPAGE="https://source.denx.de/u-boot/u-boot" SRC_URI="https://source.denx.de/u-boot/u-boot/-/archive/${UBOOT_COMMIT}/u-boot-${UBOOT_COMMIT}.tar.gz -> ${P}.tar.gz https://github.com/sifive/meta-sifive/archive/refs/heads/${META_SIFIVE}.zip -> meta-sifive-${META_SIFIVE}.zip" LICENSE="GPL-2+" SLOT="0" KEYWORDS="~riscv" DEPEND="sys-boot/opensbi sys-apps/dtc dev-lang/swig" RDEPEND="${DEPEND}" BDEPEND="" IUSE="-1000 -1100 +1200 -1300 -1400 -1500 -1600 -1700 efi-priority" REQUIRED_USE="^^ ( 1000 1100 1200 1300 1400 1500 1600 1700 )" src_unpack() { unpack ${P}.tar.gz unpack meta-sifive-${META_SIFIVE}.zip mv "${WORKDIR}/u-boot-${UBOOT_COMMIT}" "${WORKDIR}/${P}" } src_prepare() { eapply "${WORKDIR}/meta-sifive-${META_SIFIVE}/recipes-bsp/u-boot/files/unmatched" # A default, just to be sure CONFIG_SPEED=1200000000 # Check use flags use 1000 && CONFIG_SPEED=1000000000 use 1100 && CONFIG_SPEED=1100000000 use 1200 && CONFIG_SPEED=1200000000 use 1300 && CONFIG_SPEED=1300000000 use 1400 && CONFIG_SPEED=1400000000 use 1500 && CONFIG_SPEED=1500000000 use 1600 && CONFIG_SPEED=1600000000 use 1700 && CONFIG_SPEED=1700000000 # Actually modify the dtsi file sed -i -E -e "/cpus/,/cpu0/ s/assigned-clock-rates = <[0-9]+>/assigned-clock-rates = <${CONFIG_SPEED}>/" "${WORKDIR}/${P}/arch/riscv/dts/fu740-c000-u-boot.dtsi" elog "Set CPU frquency to $((CONFIG_SPEED/1000000)) Mhz" if use efi-priority; then eapply "${FILESDIR}/efi-priority.patch" fi eapply "${FILESDIR}/sifive-unmached-fdt-initrd-env.patch" eapply_user } src_configure() { # Apply Unmatched defconfig emake sifive_unmatched_defconfig } src_compile() { # Find opensbi export OPENSBI=`find /usr/share/opensbi-* -name fw_dynamic.bin | sort | tail -n 1` if [ -z "$OPENSBI" ]; then die "Can't find OpenSBI, is sys-boot/opensbi installed?" fi elog "Using OpenSBI at ${OPENSBI}" # Start the build emake } src_install() { mkdir -p "${D}/usr/share/${P}" cp "${WORKDIR}/${P}/u-boot.itb" "${D}/usr/share/${P}" cp "${WORKDIR}/${P}/spl/u-boot-spl.bin" "${D}/usr/share/${P}" } pkg_postinst() { einfo "U-Boot files have been installed in /usr/share/${P}. In order" einfo "to boot with this U-Boot you need to install it to the correct partitions with" einfo "dd. For example:" einfo "dd if=/usr/share/${P}/u-boot-spl.bin of=" einfo "dd if=/usr/share/${P}/u-boot.itb of=" }