From patchwork Thu Dec 12 21:07:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herman Rimm X-Patchwork-Id: 34845 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 227AD27BBE2; Thu, 12 Dec 2024 21:09:39 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-6.4 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE, SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 8CD2827BBE9 for ; Thu, 12 Dec 2024 21:09:38 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLqQm-0005t8-3Z; Thu, 12 Dec 2024 16:09:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLqQh-0005sV-Sh for guix-patches@gnu.org; Thu, 12 Dec 2024 16:09:05 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tLqQg-0007fS-MF for guix-patches@gnu.org; Thu, 12 Dec 2024 16:09:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:References:In-Reply-To:Date:From:To:Subject; bh=NQU/7gsM9r12YHNgXaYibpEq2xn/NSq/OiBjd4dy32I=; b=sOSDkbeVi+TA1EIcrxYxCQmH6R4WJhq3obzDmsUJXaQ2YVkgqAEs7CXn0q2qb0lPw84TvMcLwUNYrVPC6bllFGOKs6OvVNsw9ODYCjsTK/u2r/VejV9VQ09LGZ5TNw3/iLDBpZEjQInwR9sCoq2CI0lEKyyumCVDPBCECbxXqaboIJqobqungs9QrXg9HNHyY2jBKcSxiPzNFfYehYQMxNYSig6LMm3TKLB/ghuUQObCcAta9EvRhqBF9EqqnQQH4zFA/SzAmW5OjTdP03fw0qNcGAquP6GHsFPM6HxlUQV1MO0LQ8xn3hG+shwq9ojZ6HfdORLRxd6iRFBRvHRM/A==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tLqQg-0000wz-84 for guix-patches@gnu.org; Thu, 12 Dec 2024 16:09:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#74842] [PATCH 2/4] gnu: bootloader: u-boot: Add write-u-boot-image procedure. Resent-From: Herman Rimm Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 12 Dec 2024 21:09:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74842 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 74842@debbugs.gnu.org Received: via spool by 74842-submit@debbugs.gnu.org id=B74842.17340376913548 (code B ref 74842); Thu, 12 Dec 2024 21:09:02 +0000 Received: (at 74842) by debbugs.gnu.org; 12 Dec 2024 21:08:11 +0000 Received: from localhost ([127.0.0.1]:40603 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tLqPq-0000v4-Au for submit@debbugs.gnu.org; Thu, 12 Dec 2024 16:08:11 -0500 Received: from 81-205-150-117.fixed.kpn.net ([81.205.150.117]:37851 helo=email.rimm.ee) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tLqPm-0000uH-7a for 74842@debbugs.gnu.org; Thu, 12 Dec 2024 16:08:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rimm.ee; s=herman; t=1734037671; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NQU/7gsM9r12YHNgXaYibpEq2xn/NSq/OiBjd4dy32I=; b=NsanLdv6irU7OnmIjoTJ5EXVq5PgTs5WSZiP3uye4pkOEfZIPoSy2dzpsMK/zfm0bhrcZX O3iXRCmabFL/9Kz5KbuMDmC75i5WQt7/lU27qPS/rLi7VRnu+QdpuWh8iZxD/kdiBpjm54 MRKoTKzcyFr/F5VZjbLATWJDRg4B3w0TBZPJTyhKOFCcaMAhDnJt7i5MygWE8avyhKQx4n n8dtXL9/AOjtcTnWv8roqsL/p3Rh97ZA+hQKQKZfAen77+9P+BtmuYfgYIg6OQIHshgaVA x7+w8Zag2njK8eUpbFnuLyOyTxA+Ry5KnBbX9wRQudTyMeygbC1AAJrWnAKDMQ== Received: by 81-205-150-117.fixed.kpn.net (OpenSMTPD) with ESMTPSA id f8d8cfb7 (TLSv1.3:TLS_CHACHA20_POLY1305_SHA256:256:NO) for <74842@debbugs.gnu.org>; Thu, 12 Dec 2024 21:07:51 +0000 (UTC) Date: Thu, 12 Dec 2024 22:07:09 +0100 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: <6a1609d369654f967bdcb42bec27357b5f522ebf.1734037218.git.herman@rimm.ee> References: <6a1609d369654f967bdcb42bec27357b5f522ebf.1734037218.git.herman@rimm.ee> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Herman Rimm X-ACL-Warn: , Herman Rimm via Guix-patches X-Patchwork-Original-From: Herman Rimm via Guix-patches via From: Herman Rimm Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * gnu/bootloader/u-boot.scm (write-u-boot-image): Add procedure. (install-beaglebone-black-u-boot, install-allwinner-u-boot, install-allwinner64-u-boot, install-imx-u-boot, install-puma-rk3399-u-boot, install-rockchip-u-boot, install-sifive-unmatched-u-boot, install-starfive-visionfive2-u-boot): Use write-u-boot-image. Change-Id: Icb73534bfc5b9ab7c8874176f649c29275c388cf --- gnu/bootloader/u-boot.scm | 84 ++++++++++++++------------------------- 1 file changed, 29 insertions(+), 55 deletions(-) diff --git a/gnu/bootloader/u-boot.scm b/gnu/bootloader/u-boot.scm index 5ea5f418b4..5d5fc1bff2 100644 --- a/gnu/bootloader/u-boot.scm +++ b/gnu/bootloader/u-boot.scm @@ -66,6 +66,22 @@ (define (make-u-boot-installer file) (let ((install-dir (string-append mount-point "/boot"))) #$@file)))) +(define (write-u-boot-image files block-size) + "FILES is a list of (FILE COUNT OFFSET) tuples. Each FILE is written +to the target image at BLOCK-SIZE * OFFSET. The number of bytes written +is BLOCK-SIZE * COUNT, or FILE size if COUNT is not given." + (define (write-file-to-image file) + (match file + ((file count ... offset) + (let* ((file #~(string-append bootloader "/libexec/" #$file)) + (size (match count + (() #~(stat:size (stat #$file))) + ((count) (* count block-size))))) + #~(write-file-on-device #$file #$size image + #$(* offset block-size)))))) + #~(lambda (bootloader _ image) + #$@(map write-file-to-image files))) + (define install-u-boot #~(lambda (bootloader root-index image) (if bootloader @@ -78,75 +94,33 @@ (define install-beaglebone-black-u-boot ;; the MLO and is expected at 0x60000. Write both first stage ("MLO") and ;; second stage ("u-boot.img") images, read in BOOTLOADER directory, to the ;; specified DEVICE. - #~(lambda (bootloader root-index image) - (let ((mlo (string-append bootloader "/libexec/MLO")) - (u-boot (string-append bootloader "/libexec/u-boot.img"))) - (write-file-on-device mlo (* 256 512) - image (* 256 512)) - (write-file-on-device u-boot (* 1024 512) - image (* 768 512))))) + (write-u-boot-image '(("MLO" 256 256) ("u-boot.img" 768 1024)) 512)) (define install-allwinner-u-boot - #~(lambda (bootloader root-index image) - (let ((u-boot (string-append bootloader - "/libexec/u-boot-sunxi-with-spl.bin"))) - (write-file-on-device u-boot (stat:size (stat u-boot)) - image (* 8 1024))))) + (write-u-boot-image '(("u-boot-sunxi-with-spl.bin" 8)) 1024)) (define install-allwinner64-u-boot - #~(lambda (bootloader root-index image) - (let ((spl (string-append bootloader "/libexec/u-boot-sunxi-with-spl.bin")) - (u-boot (string-append bootloader "/libexec/u-boot-sunxi-with-spl.fit.itb"))) - (write-file-on-device spl (stat:size (stat spl)) - image (* 8 1024)) - (write-file-on-device u-boot (stat:size (stat u-boot)) - image (* 40 1024))))) + (write-u-boot-image '(("u-boot-sunxi-with-spl.bin" 8) + ("u-boot-sunxi-with-spl.fit.itb" 40)) + 1024)) (define install-imx-u-boot - #~(lambda (bootloader root-index image) - (let ((spl (string-append bootloader "/libexec/SPL")) - (u-boot (string-append bootloader "/libexec/u-boot.img"))) - (write-file-on-device spl (stat:size (stat spl)) - image (* 1 1024)) - (write-file-on-device u-boot (stat:size (stat u-boot)) - image (* 69 1024))))) + (write-u-boot-image '(("SPL" 1) ("u-boot.img" 69)) 1024)) (define install-puma-rk3399-u-boot - #~(lambda (bootloader root-index image) - (let ((spl (string-append bootloader "/libexec/idbloader.img")) - (u-boot (string-append bootloader "/libexec/u-boot.itb"))) - (write-file-on-device spl (stat:size (stat spl)) - image (* 64 512)) - (write-file-on-device u-boot (stat:size (stat u-boot)) - image (* 512 512))))) + (write-u-boot-image '(("idbloader.img" 64) ("u-boot.itb" 512)) 512)) (define install-rockchip-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))))) + (write-u-boot-image '(("idbloader.img" 64) ("u-boot.itb" 16384)) 512)) (define install-sifive-unmatched-u-boot - #~(lambda (bootloader root-index image) - (let ((spl (string-append bootloader "/libexec/spl/u-boot-spl.bin")) - (u-boot (string-append bootloader "/libexec/u-boot.itb"))) - (write-file-on-device spl (stat:size (stat spl)) - image (* 34 512)) - (write-file-on-device u-boot (stat:size (stat u-boot)) - image (* 2082 512))))) + (write-u-boot-image '(("spl/u-boot-spl.bin" 34) ("u-boot.itb" 2082)) + 512)) (define install-starfive-visionfive2-u-boot - #~(lambda (bootloader root-index image) - (let ((spl (string-append - bootloader "/libexec/spl/u-boot-spl.bin.normal.out")) - (u-boot (string-append bootloader "/libexec/u-boot.itb"))) - (write-file-on-device spl (stat:size (stat spl)) - image (* 34 512)) - (write-file-on-device u-boot (stat:size (stat u-boot)) - image (* 2082 512))))) + (write-u-boot-image '(("spl/u-boot-spl.bin.normal.out" 34) + ("u-boot.itb" 2082)) + 512)) (define install-starfive-visionfive2-uEnv.txt (make-u-boot-installer