# Reference: <https://postmarketos.org/devicepkg>
# Maintainer: Dylan Van Assche <me@dylanvanassche.be>

pkgname=device-odroid-hc2
pkgdesc="ODROID HC2"
pkgver=0.7
pkgrel=2
url="https://postmarketos.org"
license="MIT"
arch="armv7"
options="!check !archcheck"
depends="linux-edge
	 postmarketos-base
	 u-boot-odroid
	 u-boot-tools
	"
makedepends="devicepkg-dev"
subpackages="$pkgname-nonfree-firmware:nonfree_firmware $pkgname-tools"
_commit="42ac93dcfbbb8a08c2bdc02e19f96eb35a81891a"
source="deviceinfo uboot-script.cmd install-rootfs-hdd.sh"

build() {
	devicepkg_build $startdir $pkgname
	mkimage \
		-A arm \
		-O linux \
		-T script \
		-C none \
		-a 0 \
		-e 0 \
		-n postmarketos \
		-d "$srcdir"/uboot-script.cmd \
		"$srcdir"/boot.scr
}

package() {
	devicepkg_package $startdir $pkgname
	install -Dm644 "$srcdir"/boot.scr \
		"$pkgdir"/boot/boot.scr
}

nonfree_firmware() {
	pkgdesc="U-Boot, Samsung JPEG encoder, and Realtek firmware, required for a bootable system"
	depends="firmware-odroid-hc2 linux-firmware-rtl_nic linux-firmware-other"
	mkdir "$subpkgdir"
}

tools() {
	pkgdesc="ODROID HC2 tools"
	depends="rsync e2fsprogs-extra"
	mkdir "$subpkgdir"
	install -Dm744 "$srcdir"/install-rootfs-hdd.sh \
		"$subpkgdir"/usr/bin/install-rootfs-hdd
}

sha512sums="
69b4fa44985adc3b2de5a516fa54448024973633d53130eee6d5055b1ccf9aa4b83fe0cf3ee30c69c5defcbe20e776995b8b4682e0503c76e0189a63cd582950  deviceinfo
f3e7a39d53c072f4ae68fcca241f88b05939052ff1c9bd8d45b47d2b336f3c239689857051ff3c7a96caefd5c10d2e34d9b921c62f993f80faca2999eb7beab8  uboot-script.cmd
09a2191dce5b5c8fdf80c4473d9773a51f2c633db51477f2f64983dd030d7800fd80999a228ec7efe3f9feafeba35902bff68cf95e6ae59048dc64424f402b63  install-rootfs-hdd.sh
"
