From patchwork Thu Nov 4 08:35:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Sundberg X-Patchwork-Id: 34236 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 CC5D227BBE1; Thu, 4 Nov 2021 08:36:10 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,T_DKIM_INVALID, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id D723827BBE3 for ; Thu, 4 Nov 2021 08:36:09 +0000 (GMT) Received: from localhost ([::1]:32808 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1miYEC-0007qc-SN for patchwork@mira.cbaines.net; Thu, 04 Nov 2021 04:36:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46722) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1miYE6-0007q7-V5 for guix-patches@gnu.org; Thu, 04 Nov 2021 04:36:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:58654) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1miYE6-0008Jq-Lu for guix-patches@gnu.org; Thu, 04 Nov 2021 04:36:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1miYE6-00074J-Ji for guix-patches@gnu.org; Thu, 04 Nov 2021 04:36:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#51598] [PATCH 2/2] image: Support generating GPT images via `partition-table-type` Resent-From: Ryan Sundberg Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 04 Nov 2021 08:36:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 51598 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 51598@debbugs.gnu.org Cc: Ryan Sundberg X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.163601494327132 (code B ref -1); Thu, 04 Nov 2021 08:36:02 +0000 Received: (at submit) by debbugs.gnu.org; 4 Nov 2021 08:35:43 +0000 Received: from localhost ([127.0.0.1]:41965 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1miYDn-00073X-G2 for submit@debbugs.gnu.org; Thu, 04 Nov 2021 04:35:43 -0400 Received: from lists.gnu.org ([209.51.188.17]:34464) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1miYDl-00073J-81 for submit@debbugs.gnu.org; Thu, 04 Nov 2021 04:35:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46676) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1miYDl-0007pU-1U for guix-patches@gnu.org; Thu, 04 Nov 2021 04:35:41 -0400 Received: from mail.arctype.co ([138.68.9.245]:34821) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1miYDi-0008D8-QD for guix-patches@gnu.org; Thu, 04 Nov 2021 04:35:40 -0400 Received: from authenticated-user (mail.arctype.co [138.68.9.245]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by mail.arctype.co (Postfix) with ESMTPSA id BB12A13B2C3; Thu, 4 Nov 2021 08:35:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=arctype.co; s=mail; t=1636014936; bh=y8vSCv5cSARs+crGZYQcuABaxFTaajtzRyI5NOSw0ls=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A5TnX29DcEeidieBrQ6qxr5EyUf5+qoRmAGU25QnaUhWf+VMfb2bVX8uw/wUd6ZRG 1s1/Pg3UngQATlwsIG8HD3h3gSZLTeG1g33NoxGNMZVCw/n/i6cHUcvBWgRCNHsOQ2 Fm+KXJu9OlcXCPfkDaEBHB0COxfj/2ikekKqc4p1VQY4wqhUKI8AMaa9ieE+zk6F97 y/SDBkjkNDtTMAH3SwRunj5TnCKsJsEYPPIVW6teWKe1JNiwwli4tEpkltwfgkdpVY FDywvE5YV4e8JJjCf8QLxe1iWLrHMF60dDXUtHk108P6f7RCH92zw84b+XYSpek+86 dvpVLZa44uVhw== Date: Thu, 4 Nov 2021 01:35:11 -0700 Message-Id: <20211104083511.11852-2-ryan@arctype.co> In-Reply-To: <20211104083511.11852-1-ryan@arctype.co> References: <20211104083511.11852-1-ryan@arctype.co> MIME-Version: 1.0 Received-SPF: pass client-ip=138.68.9.245; envelope-from=ryan@arctype.co; helo=mail.arctype.co X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" Reply-to: Ryan Sundberg X-ACL-Warn: , Ryan Sundberg via Guix-patches X-Patchwork-Original-From: Ryan Sundberg via Guix-patches via From: Ryan Sundberg X-getmail-retrieved-from-mailbox: Patches * gnu/image.scm: Add partition-table-type field to image * gnu/system/image.scm: Implement partition-table-type logic for genimage. --- gnu/image.scm | 3 +++ gnu/system/image.scm | 59 +++++++++++++++++++++++++++++++------------- 2 files changed, 45 insertions(+), 17 deletions(-) diff --git a/gnu/image.scm b/gnu/image.scm index 75d489490d..b83c4275da 100644 --- a/gnu/image.scm +++ b/gnu/image.scm @@ -37,6 +37,7 @@ image-target image-size image-operating-system + image-partition-table-type image-partitions image-compression? image-volatile-root? @@ -84,6 +85,8 @@ (default 'guess)) (operating-system image-operating-system ; (default #f)) + (partition-table-type image-partition-table-type ; 'mbr or 'gpt + (default 'mbr)) (partitions image-partitions ;list of (default '())) (compression? image-compression? ;boolean diff --git a/gnu/system/image.scm b/gnu/system/image.scm index 7a3a637e47..ed22484a62 100644 --- a/gnu/system/image.scm +++ b/gnu/system/image.scm @@ -309,6 +309,14 @@ used in the image." ((member 'esp flags) "0xEF") (else "0x83")))) + (define (partition->gpt-type partition) + ;; Return the genimage GPT partition type code corresponding to PARTITION. + ;; See https://github.com/pengutronix/genimage/blob/master/README.rst + (let ((flags (partition-flags partition))) + (cond + ((member 'esp flags) "U") + (else "L")))) + (define (partition-image partition) ;; Return as a file-like object, an image of the given PARTITION. A ;; directory, filled by calling the PARTITION initializer procedure, is @@ -358,26 +366,43 @@ used in the image." #:local-build? #f #:options `(#:references-graphs ,inputs)))) - (define (partition->config partition) + (define (gpt-image? image) + (eq? 'gpt (image-partition-table-type image))) + + (define (partition-type-values image partition) + (if (gpt-image? image) + (values "partition-type-uuid" (partition->gpt-type partition)) + (values "partition-type" (partition->dos-type partition)))) + + (define (partition->config image partition) ;; Return the genimage partition configuration for PARTITION. - (let ((label (partition-label partition)) - (dos-type (partition->dos-type partition)) - (image (partition-image partition)) - (offset (partition-offset partition))) - #~(format #f "~/partition ~a { -~/~/partition-type = ~a -~/~/image = \"~a\" -~/~/offset = \"~a\" -~/}" - #$label - #$dos-type - #$image - #$offset))) + (let-values (((partition-type-attribute partition-type-value) (partition-type-values image partition))) + (let ((label (partition-label partition)) + (image (partition-image partition)) + (offset (partition-offset partition))) + #~(format #f "~/partition ~a { + ~/~/~a = ~a + ~/~/image = \"~a\" + ~/~/offset = \"~a\" + ~/}" + #$label + #$partition-type-attribute + #$partition-type-value + #$image + #$offset)))) + + (define (genimage-type-options image-type image) + (cond + ((equal? image-type "hdimage") + (format #f "~%~/~/gpt = ~a~%~/" + (if (gpt-image? image) "true" "false"))) + (else ""))) (let* ((format (image-format image)) (image-type (format->image-type format)) + (image-type-options (genimage-type-options image-type image)) (partitions (image-partitions image)) - (partitions-config (map partition->config partitions)) + (partitions-config (map (cut partition->config image <>) partitions)) (builder #~(begin (let ((format (@ (ice-9 format) format))) @@ -386,9 +411,9 @@ used in the image." (format port "\ image ~a { -~/~a {} +~/~a {~a} ~{~a~^~%~} -}~%" #$genimage-name #$image-type (list #$@partitions-config)))))))) +}~%" #$genimage-name #$image-type #$image-type-options (list #$@partitions-config)))))))) (computed-file "genimage.cfg" builder))) (let* ((image-name (image-name image))