;;; Copyright © 2022 Petr Hodina ;;; ;;; This program is free software: you can redistribute it and/or modify ;;; it under the terms of the GNU General Public License as published by ;;; the Free Software Foundation, either version 3 of the License, or ;;; (at your option) any later version. ;;; ;;; This program is distributed in the hope that it will be useful, ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;; GNU General Public License for more details. ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with this program. If not, see . (define-module (nongnu packages bootloaders) #:use-module (guix utils) #:use-module (guix packages) #:use-module (gnu bootloader) #:use-module (gnu bootloader extlinux) #:use-module (gnu packages) #:use-module (gnu packages base) #:use-module (gnu packages bash) #:use-module (gnu packages bootloaders) #:use-module (gnu packages compression) #:use-module (gnu packages python) #:use-module (gnu packages python-xyz) #:use-module (gnu packages tls) #:use-module (guix download) #:use-module (guix git-download) #:use-module (ice-9 ftw) #:use-module (guix gexp) #:use-module (nonguix build-system binary) #:use-module ((nonguix licenses) #:prefix license:) #:export (u-boot-quartz64a-rk3566-bootloader u-boot-pinephone-pro-rk3399-bootloader u-boot-pinenote-rk3566-bootloader)) (define %u-boot-quartz64-nvme-configs '("CONFIG_CMD_NVME=y" "CONFIG_CMD_PCI=y" "CONFIG_NVME=y" "CONFIG_NVME_PCI=y" "CONFIG_PCI=y" "CONFIG_PCI_PNP=y" "CONFIG_LOG_MAX_LEVEL=7" "CONFIG_LOG=y" "CONFIG_LOG_CONSOLE=y" ; "CONFIG_PCI_ENHANCED_ALLOCATION=y" "CONFIG_PCIE_DW_COMMON=y" "CONFIG_PCIE_DW_ROCKCHIP=y" "CONFIG_PHY=y" "CONFIG_PHY_ROCKCHIP_NANENG_COMBOPHY=y")) (define-public u-boot-pinephone-pro-rk3399 (make-u-boot-package "pinephone-pro-rk3399" "aarch64-linux-gnu")) (define (u-boot-rk3566 board configs) (let ((commit "58040d305147b8608f5766a49d63e863ba163937") (revision "1") (base (make-u-boot-package board "aarch64-linux-gnu" #:configs configs))) (package (inherit base) (version "2022.07") (source (origin (method git-fetch) (uri (git-reference ;; Using rebased version which is compatible with Guix disable ;; OpenSSL patch (url "https://gitlab.com/phodina/u-boot-quartz64") (commit commit))) (patches (search-patches "u-boot-allow-disabling-openssl.patch")) (sha256 (base32 "0w2yzvfvvydv26dm043jw24r7qkzc3j8jhcrc487pdm79icgfib8")))) (arguments (substitute-keyword-arguments (package-arguments base) ((#:phases phases) #~(modify-phases #$phases ; (add-after 'configure 'fix-config ; (lambda* _ ; (substitute* ".config" ; (("CONFIG_ARM=y") ; "CONFIG_ARM=y\nCONFIG_LOG_MAX_LEVEL=7\nCONFIG_LOG=y\nCONFIG_LOG_CONSOLE=y")))) (add-after 'unpack 'download-rockchip-firmware (lambda* _ (let* ((ram-init-dl #$(origin (method url-fetch) (uri "https://github.com/JeffyCN/rockchip_mirrors/raw/47404a141a1acb7555906b5e3b097b5f1045cc21/bin/rk35/rk3568_ddr_1560MHz_v1.11.bin") (file-name "ram_init.bin") (sha256 (base32 "02rj8spdbq250wcrkkscmjz4jmwba8yfmv90kkbd5wspmk9bq0cj")))) (bl31-dl #$(origin (method url-fetch) (uri "https://github.com/JeffyCN/rockchip_mirrors/raw/6186debcac95553f6b311cee10669e12c9c9963d/bin/rk35/rk3568_bl31_v1.28.elf") (file-name "rk3568_bl31_v1.28.elf") (sha256 (base32 "0ji53ggmmf9qwrvs06ashydvaw8d9w4byzsvypqy4imndxb1kgv7")))) (bl31 "rk3568_bl31_v1.28.elf") (ram-init "ram_init.bin")) (setenv "BL31" "rk3568_bl31_v1.28.elf") (for-each make-file-writable (find-files ".")) (copy-file ram-init-dl ram-init) (copy-file bl31-dl bl31))))))))))) (define-public u-boot-rk3566-quartz64-downstream (let ((commit "7df3eae9f756665e01016a182d33ddf9dd244b1d") (revision "1") (base (make-u-boot-package "rk3566-quartz64" "aarch64-linux-gnu"))) (package (inherit base) (version "2017") (source (origin (method url-fetch) (uri (string-append "https://github.com/JoshuaMulliken/u-boot-rockchip/archive/" commit ".tar.gz")) ; (patches ; (parameterize ; ((%patch-path ; (map (lambda (directory) ; (string-append directory "/nongnu/packages/patches")) ; %load-path))) ; (search-patches ;"u-boot-dont-block-reads-above-32mb.patch" ; ;"u-boot-pyelftools.patch" ; "u-boot-pyelftools.patch"))) (sha256 (base32 "0dsi48ay06ciqcvlrbjwm90wvvs3wf65nbgjsc46wkkx9c6r1rj2")))) (arguments (substitute-keyword-arguments (package-arguments base) ((#:phases phases) #~(modify-phases #$phases (add-after 'unpack 'download-rockchip-firmware (lambda* _ (let* ((rkbin-dl #$(origin (method url-fetch) (uri "https://github.com/JeffyCN/rockchip_mirrors/archive/refs/heads/rkbin.zip") (file-name "rkbin.zip") (sha256 (base32 "0wpli41046kppm873n5h410ljrvzjf219gzb7n0jc3qpghyl9cvw"))))) (invoke "unzip" "-q" rkbin-dl) (rename-file "rockchip_mirrors-rkbin" "../rkbin") ; (patch-shebang "make.sh") ;(substitute* "scripts/fit.sh" ;(("./make.sh loader") "bash -x ./make.sh loader")) ;(substitute* "scripts/loader.sh" ;(("set -e") "set -e\nset -x")) ; (("boot_merger") "boot_merger --verbose")) (substitute* "Makefile" (("HOSTCC = cc") (string-append "HOSTCC = " #$(cc-for-target)))) ;(substitute* "make.sh" ;(("python") "python3") ;(("..SCRIPT_LOADER. --ini ..INI_LOADER.") "bash -x ${SCRIPT_LOADER} --ini ;${INI_LOADER}") ;(("..SCRIPT_FIT. ..ARG_LIST_FIT.") "bash -x ${SCRIPT_FIT} ${ARG_LIST_FIT}")) ;(("^make.*") "make HOSTCC=gcc CROSS_COMPILE=aarch64-linux-gnu- all\n")) ))) (delete 'disable-tools-libcrypto) (delete 'configure) (replace 'build (lambda* (#:key outputs inputs make-flags #:allow-other-keys) ; (setenv "PATH" (string-append (dirname (which "sed")) ":" (dirname ; (which "grep")) ":" (dirname (which "awk")) ":" ; ;#$(this-package-input "coreutils") "/bin" ":" ; #$coreutils "/bin" ":" ; (getenv "PATH"))) ; (setenv "cc=" #$(cc-for-target)) ; (setenv "CROSS_COMPILE" "aarch64-linux-gnu-") (invoke "make" "clean") (invoke "make" "mrproper") (invoke "make" "V=1" ;(string-append "CC=" "gcc");#$(cc-for-target)) "rk3566-eink_defconfig") (invoke "./make.sh") (invoke "./make.sh" "trust"))) ;(invoke "make" "HOSTCC=gcc" "CROSS_COMPILE=aarch64-linux-gnu-" "rk3566-quartz64_defconfig"))) (add-after 'build 'build-binaries (lambda* (#:key outputs make-flags #:allow-other-keys) ;; Failing at ;; https://gitlab.com/pgwipeout/u-boot-rockchip/-/blob/quartz64/make.sh#L774 (invoke "bash" "-x" "./make.sh") (invoke "./tools/resource_tool" "--pack" "arch/arm/dts/rk3566-quartz64.dtb") )))))) (native-inputs `(("which" ,which) ("coreutils" ,coreutils) ("dtc" ,dtc) ("python-pyelftools" ,python-pyelftools) ("bash" ,bash-minimal) ("unzip" ,unzip) ,@(package-native-inputs base)))))) (define-public u-boot-rk3566-evb (u-boot-rk3566 "evb-rk3566" '())) (define-public u-boot-rk3566-pinenote (u-boot-rk3566 "pinenote-rk3566" '())) (define-public u-boot-rk3566-quartz64a (u-boot-rk3566 "quartz64-a-rk3566" %u-boot-quartz64-nvme-configs)) (define-public u-boot-rk3566-quartz64b (u-boot-rk3566 "quartz64-b-rk3566" '())) (define-public u-boot-rk3566-soquartz (u-boot-rk3566 "soquartz-rk3566" '())) (define install-u-boot #~(lambda (bootloader root-index image) (if bootloader (error "Failed to install U-Boot")))) (define install-rk3566-u-boot #~(lambda (bootloader root-index image) (let ((idb (string-append bootloader "/libexec/idbloader.img")) (u-boot (string-append bootloader "/libexec/u-boot.itb"))) (write-file-on-device idb (stat:size (stat idb)) image (* 64 512)) (write-file-on-device u-boot (stat:size (stat u-boot)) image (* 16384 512))))) (define install-pinephone-pro-rk3399-u-boot #~(lambda (bootloader root-index image) (let ((idb (string-append bootloader "/libexec/idbloader.img")) (u-boot (string-append bootloader "/libexec/u-boot.itb"))) (write-file-on-device idb (stat:size (stat idb)) image (* 64 512)) (write-file-on-device u-boot (stat:size (stat u-boot)) image (* 16384 512))))) (define u-boot-bootloader (bootloader (inherit extlinux-bootloader) (name 'u-boot) (package #f) (installer #f) (disk-image-installer install-u-boot))) (define u-boot-pinephone-pro-rk3399-bootloader ;; SD and eMMC use the same format (bootloader (inherit u-boot-bootloader) (package u-boot-pinephone-pro-rk3399) (disk-image-installer install-pinephone-pro-rk3399-u-boot))) (define u-boot-quartz64a-rk3566-bootloader ;; SD and eMMC use the same format (bootloader (inherit u-boot-bootloader) (package u-boot-rk3566-quartz64a) (disk-image-installer install-rk3566-u-boot))) (define u-boot-pinenote-rk3566-bootloader ;; SD and eMMC use the same format (bootloader (inherit u-boot-bootloader) (package u-boot-rk3566-pinenote) (disk-image-installer install-rk3566-u-boot)))