From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id EMLuFgXMyl9hPAAA0tVLHw (envelope-from ) for ; Fri, 04 Dec 2020 23:53:41 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id YMS+EgXMyl8tTwAAB5/wlQ (envelope-from ) for ; Fri, 04 Dec 2020 23:53:41 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id A9EAE9403A2 for ; Fri, 4 Dec 2020 23:53:40 +0000 (UTC) Received: from localhost ([::1]:49244 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1klKtP-0004pn-Fx for larch@yhetil.org; Fri, 04 Dec 2020 18:53:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:60128) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1klKso-0004pP-4D for guix-patches@gnu.org; Fri, 04 Dec 2020 18:53:02 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:34614) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1klKsn-0002Uf-SA for guix-patches@gnu.org; Fri, 04 Dec 2020 18:53:01 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1klKsn-0000Vy-OW for guix-patches@gnu.org; Fri, 04 Dec 2020 18:53:01 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#45046] [PATCH] build/kconfig: New module to modify a defconfig file. Resent-From: Stefan Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 04 Dec 2020 23:53:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 45046 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 45046@debbugs.gnu.org X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.16071259471932 (code B ref -1); Fri, 04 Dec 2020 23:53:01 +0000 Received: (at submit) by debbugs.gnu.org; 4 Dec 2020 23:52:27 +0000 Received: from localhost ([127.0.0.1]:46160 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1klKs9-0000V1-Tk for submit@debbugs.gnu.org; Fri, 04 Dec 2020 18:52:27 -0500 Received: from lists.gnu.org ([209.51.188.17]:43380) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1klKs5-0000Uq-Lt for submit@debbugs.gnu.org; Fri, 04 Dec 2020 18:52:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:59964) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1klKs5-0004kA-Dd for guix-patches@gnu.org; Fri, 04 Dec 2020 18:52:17 -0500 Received: from mx009.vodafonemail.xion.oxcs.net ([153.92.174.39]:16214) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1klKs1-0002D5-Rg for guix-patches@gnu.org; Fri, 04 Dec 2020 18:52:16 -0500 Received: from vsmx002.vodafonemail.xion.oxcs.net (unknown [192.168.75.192]) by mta-6-out.mta.xion.oxcs.net (Postfix) with ESMTP id B70E1604B9B for ; Fri, 4 Dec 2020 23:52:07 +0000 (UTC) Received: from macbook-pro.kuh-wiese.my-router.de (unknown [92.212.12.230]) by mta-6-out.mta.xion.oxcs.net (Postfix) with ESMTPA id 749B06048E0 for ; Fri, 4 Dec 2020 23:52:05 +0000 (UTC) From: Stefan Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Message-Id: <8DAC4983-25B2-4919-89F2-F08B5C781EC1@vodafonemail.de> Date: Sat, 5 Dec 2020 00:52:04 +0100 Mime-Version: 1.0 (Mac OS X Mail 9.3 \(3124\)) X-Mailer: Apple Mail (2.3124) X-VADE-STATUS: LEGIT Received-SPF: pass client-ip=153.92.174.39; envelope-from=stefan-guix@vodafonemail.de; helo=mx009.vodafonemail.xion.oxcs.net X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -1.79 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: A9EAE9403A2 X-Spam-Score: -1.79 X-Migadu-Scanner: ns3122888.ip-94-23-21.eu X-TUID: pGhGFXf2zoSw * guix/build/kconfig.scm (modify-defconfig): New file with a new = function. * gnu/packages/bootloaders.scm (make-u-boot-package, make-u-boot-sunxi64-package): Adding new key arguments to pass and/or = modify a defconfig file. (u-boot-am335x-boneblack, u-boot-pinebook, u-boot-novena): Simplify = functions by using the new key arguments of the former functions. * Makefile.am: Adding guix/build/kconfig.scm to MODULES. --- Makefile.am | 1 + gnu/packages/bootloaders.scm | 89 +++++++++++------------- guix/build/kconfig.scm | 127 +++++++++++++++++++++++++++++++++++ 3 files changed, 167 insertions(+), 50 deletions(-) create mode 100644 guix/build/kconfig.scm diff --git a/Makefile.am b/Makefile.am index 1a3ca227a4..c08e7be3a2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -210,6 +210,7 @@ MODULES =3D \ guix/build/waf-build-system.scm \ guix/build/haskell-build-system.scm \ guix/build/julia-build-system.scm \ + guix/build/kconfig.scm \ guix/build/linux-module-build-system.scm \ guix/build/store-copy.scm \ guix/build/json.scm \ diff --git a/gnu/packages/bootloaders.scm b/gnu/packages/bootloaders.scm index 75ae8d919b..e72c1d41e8 100644 --- a/gnu/packages/bootloaders.scm +++ b/gnu/packages/bootloaders.scm @@ -13,6 +13,7 @@ ;;; Copyright =C2=A9 2020 Bj=C3=B6rn H=C3=B6fling = ;;; Copyright =C2=A9 2018, 2019, 2020 Vagrant Cascadian = ;;; Copyright =C2=A9 2020 Pierre Langlois +;;; Copyright =C2=A9 2020 Stefan ;;; ;;; This file is part of GNU Guix. ;;; @@ -70,6 +71,7 @@ #:use-module (guix utils) #:use-module (srfi srfi-1) #:use-module (srfi srfi-26) + #:use-module (ice-9 optargs) #:use-module (ice-9 regex)) =20 (define unifont @@ -602,8 +604,9 @@ def test_ctrl_c")) also initializes the boards (RAM etc). This package provides its board-independent tools."))) =20 -(define-public (make-u-boot-package board triplet) - "Returns a u-boot package for BOARD cross-compiled for TRIPLET." +(define*-public (make-u-boot-package board triplet #:key defconfig = configs) + "Returns a u-boot package for BOARD cross-compiled for TRIPLET with = the +optional DEFCONFIG file and optional configuration changes from = CONFIGS." (let ((same-arch? (lambda () (string=3D? (%current-system) (gnu-triplet->nix-system triplet))))) @@ -621,8 +624,11 @@ board-independent tools."))) (arguments `(#:modules ((ice-9 ftw) (srfi srfi-1) - (guix build utils) - (guix build gnu-build-system)) + (guix build gnu-build-system) + (guix build kconfig) + (guix build utils)) + #:imported-modules (,@%gnu-build-system-modules + (guix build kconfig)) #:test-target "test" #:make-flags (list "HOSTCC=3Dgcc" @@ -633,9 +639,18 @@ board-independent tools."))) (modify-phases %standard-phases (replace 'configure (lambda* (#:key outputs make-flags #:allow-other-keys) - (let ((config-name (string-append ,board "_defconfig"))) - (if (file-exists? (string-append "configs/" = config-name)) - (apply invoke "make" `(,@make-flags ,config-name)) + (let* ((config-name (string-append ,board "_defconfig")) + (config-file (string-append "configs/" = config-name)) + (defconfig ,defconfig) + (configs ',configs)) + (when defconfig + ;; Replace the board-specific defconfig with the = given one. + (copy-file defconfig config-file)) + (if (file-exists? config-file) + (begin + (when configs + (modify-defconfig config-file configs)) + (apply invoke "make" `(,@make-flags = ,config-name))) (begin (display "Invalid board name. Valid board names = are:" (current-error-port)) @@ -686,7 +701,11 @@ board-independent tools."))) (make-u-boot-package "malta" "mips64el-linux-gnuabi64")) =20 (define-public u-boot-am335x-boneblack - (let ((base (make-u-boot-package "am335x_evm" = "arm-linux-gnueabihf"))) + (let ((base (make-u-boot-package "am335x_evm" "arm-linux-gnueabihf" + ;; Patch out other device trees to build image small = enough to + ;; fit within typical partitioning schemes where the = first + ;; partition begins at sector 2048. + #:configs '("CONFIG_OF_LIST=3D\"am335x-evm = am335x-boneblack\"\n")))) (package (inherit base) (name "u-boot-am335x-boneblack") @@ -695,25 +714,13 @@ also initializes the boards (RAM etc). =20 This U-Boot is built for the BeagleBone Black, which was removed = upstream, adjusted from the am335x_evm build with several device trees removed so = that -it fits within common partitioning schemes.") - (arguments - (substitute-keyword-arguments (package-arguments base) - ((#:phases phases) - `(modify-phases ,phases - (add-after 'unpack 'patch-defconfig - ;; Patch out other devicetrees to build image small = enough to - ;; fit within typical partitioning schemes where the = first - ;; partition begins at sector 2048. - (lambda _ - (substitute* "configs/am335x_evm_defconfig" - (("CONFIG_OF_LIST=3D.*$") = "CONFIG_OF_LIST=3D\"am335x-evm am335x-boneblack\"\n")) - #t))))))))) +it fits within common partitioning schemes.")))) =20 (define-public u-boot-am335x-evm (make-u-boot-package "am335x_evm" "arm-linux-gnueabihf")) =20 -(define-public (make-u-boot-sunxi64-package board triplet) - (let ((base (make-u-boot-package board triplet))) +(define*-public (make-u-boot-sunxi64-package board triplet #:key = defconfig configs) + (let ((base (make-u-boot-package board triplet #:defconfig defconfig = #:configs configs))) (package (inherit base) (arguments @@ -743,20 +750,10 @@ it fits within common partitioning schemes.") (make-u-boot-sunxi64-package "pine64-lts" "aarch64-linux-gnu")) =20 (define-public u-boot-pinebook - (let ((base (make-u-boot-sunxi64-package "pinebook" = "aarch64-linux-gnu"))) - (package - (inherit base) - (arguments - (substitute-keyword-arguments (package-arguments base) - ((#:phases phases) - `(modify-phases ,phases - (add-after 'unpack 'patch-pinebook-config - ;; Fix regression with LCD video output introduced in = 2020.01 - ;; https://patchwork.ozlabs.org/patch/1225130/ - (lambda _ - (substitute* "configs/pinebook_defconfig" - (("CONFIG_VIDEO_BRIDGE_ANALOGIX_ANX6345=3Dy") = "CONFIG_VIDEO_BRIDGE_ANALOGIX_ANX6345=3Dy\nCONFIG_VIDEO_BPP32=3Dy")) - #t))))))))) + (make-u-boot-sunxi64-package "pinebook" "aarch64-linux-gnu" + ;; Fix regression with LCD video output introduced in 2020.01 + ;; https://patchwork.ozlabs.org/patch/1225130/ + #:configs '("CONFIG_VIDEO_BPP32=3Dy"))) =20 (define-public u-boot-bananapi-m2-ultra (make-u-boot-package "Bananapi_M2_Ultra" "arm-linux-gnueabihf")) @@ -780,25 +777,17 @@ it fits within common partitioning schemes.") (make-u-boot-package "mx6cuboxi" "arm-linux-gnueabihf")) =20 (define-public u-boot-novena - (let ((base (make-u-boot-package "novena" "arm-linux-gnueabihf"))) + (let ((base (make-u-boot-package "novena" "arm-linux-gnueabihf" + ;; Patch configuration to disable loading u-boot.img = from FAT + ;; partition, allowing it to be installed at a device = offset. + #:configs '("CONFIG_SPL_FS_FAT=3D")))) (package (inherit base) (description "U-Boot is a bootloader used mostly for ARM boards. = It also initializes the boards (RAM etc). =20 This U-Boot is built for Novena. Be advised that this version, = contrary -to Novena upstream, does not load u-boot.img from the first = partition.") - (arguments - (substitute-keyword-arguments (package-arguments base) - ((#:phases phases) - `(modify-phases ,phases - (add-after 'unpack 'patch-novena-defconfig - ;; Patch configuration to disable loading u-boot.img = from FAT partition, - ;; allowing it to be installed at a device offset. - (lambda _ - (substitute* "configs/novena_defconfig" - (("CONFIG_SPL_FS_FAT=3Dy") "# CONFIG_SPL_FS_FAT is = not set")) - #t))))))))) +to Novena upstream, does not load u-boot.img from the first = partition.")))) =20 (define-public u-boot-cubieboard (make-u-boot-package "Cubieboard" "arm-linux-gnueabihf")) diff --git a/guix/build/kconfig.scm b/guix/build/kconfig.scm new file mode 100644 index 0000000000..7554b76171 --- /dev/null +++ b/guix/build/kconfig.scm @@ -0,0 +1,127 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright =C2=A9 2020 Stefan +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix 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. +;;; +;;; GNU Guix 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 GNU Guix. If not, see . + +(define-module (guix build kconfig) + #:use-module (ice-9 rdelim) + #:use-module (srfi srfi-1) + #:use-module (srfi srfi-26) + #:export (modify-defconfig)) + +;; Commentary: +;; +;; Builder-side code to modify configurations for the Kconfig build = system as +;; used by Linux and U-Boot. +;; +;; Code: + +(define (modify-defconfig defconfig configs) + "This function can modify a given DEFCONFIG file by adding, changing = or +removing the list of strings in CONFIGS. This allows an easy = customization of +Kconfig based projects like the kernel Linux or the bootloader 'Das = U-Boot'. + +These are examples for CONFIGS to add (or change) and remove +configurations to/from DEFCONFIG: + +'(\"CONFIG_A=3D\\\"a\\\"\" + \"CONFIG_B=3D0\" + \"CONFIG_C=3Dy\" + \"CONFIG_D=3Dm\" + \"CONFIG_E=3D\" + \"CONFIG_F\")" + + (define (config-string->pair config-string) + "Parse a config-string like \"CONFIG_NET=3Dy\" into a key-value = pair. +Spaces get trimmed. +\"CONFIG_EXAMPLE=3Dy\" -> '(\"CONFIG_EXAMPLE\" . \"y\") +\"CONFIG_EXAMPLE=3D\\\"\\\"\" -> '(\"CONFIG_EXAMPLE\" . \"\"). +\"CONFIG_EXAMPLE=3D\" -> '(\"CONFIG_EXAMPLE\" . #f). +\"CONFIG_EXAMPLE\" -> '(\"CONFIG_EXAMPLE\" . #f)." + (let ((pair (map string-trim-both (string-split config-string = #\=3D)))) + (case (length pair) + ((2) + (cons (string-append (first pair)) + (if (string-null? (second pair)) + #f + (second pair)))) + (else (cons (first pair) #f))))) + + (define (pair->config-string pair) + "Convert a PAIR back to a config-string." + (let* ((key (car pair)) + (value (cdr pair))) + (if value + (string-append key "=3D" value) + key))) + + (define (disable-pair pair blacklist) + "Turn the key of a key-value PAIR into an disabled key, if listed = in +BLACKLIST." + (let* ((key (car pair))) + (if (member key blacklist) + (cons (string-append "# disabled " key) + (cdr pair)) + pair))) + + (define (disable-config-string config-string blacklist) + "Turn the CONFIG-STRING into a disabled one, if listed in = BLACKLIST." + (pair->config-string (disable-pair (config-string->pair = config-string) + blacklist))) + + (define (unset-pair pair) + "Turn the key of a key-value PAIR into an unset key, if its value = is #f." + (let* ((key (car pair)) + (value (cdr pair))) + (if value + pair + (cons (string-append "# unset " key) value)))) + + (define (unset-config-string config-string) + "Turn the CONFIG-STRING into a proper unset one, if there is no = assignment" + (pair->config-string (unset-pair (config-string->pair = config-string)))) + + (define (write-modified-lines input modify-line) + "Write all lines from the INPUT after applying MODIFY-LINE to the + current-output-port." + (let loop ((line (read-line input))) + (when (not (eof-object? line)) + (display (modify-line line)) + (newline) + (loop (read-line input))))) + + (let* ((modified-defconfig (string-append defconfig ".mod")) + ;; Generate a blacklist of config keys from configs. + (blacklist (map (lambda (config-string) + (first (config-string->pair config-string))) + configs)) + (disable-config-string (cut disable-config-string <> = blacklist))) + ;; Write to modified-defconfig file first the configs, and second + ;; the content of the defconfig file with disabled lines. + (call-with-output-file modified-defconfig + (lambda (output) + (with-output-to-port output + (lambda () + (call-with-input-string (string-join configs "\n") + (lambda (input) + (write-modified-lines input unset-config-string))) + (false-if-exception + (call-with-input-file defconfig + (lambda (input) + (write-modified-lines input = disable-config-string)))))))) + ;; Ensure the modified-defconfig file is used. + (false-if-exception (delete-file defconfig)) + (rename-file modified-defconfig defconfig))) --=20 2.29.2