From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id 4ExAM2q0E2M5cQAAbAwnHQ (envelope-from ) for ; Sat, 03 Sep 2022 22:09:14 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id KBZcM2q0E2ManQAA9RJhRA (envelope-from ) for ; Sat, 03 Sep 2022 22:09:14 +0200 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 39B011701F for ; Sat, 3 Sep 2022 22:09:14 +0200 (CEST) Received: from localhost ([::1]:50172 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oUZS5-00035B-3R for larch@yhetil.org; Sat, 03 Sep 2022 16:09:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51384) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oUZRu-0002uy-Ck for guix-patches@gnu.org; Sat, 03 Sep 2022 16:09:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:54415) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oUZRu-0003R7-2m for guix-patches@gnu.org; Sat, 03 Sep 2022 16:09:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oUZRt-00018b-Jr for guix-patches@gnu.org; Sat, 03 Sep 2022 16:09:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#57496] [PATCH 1/2] gnu: bootloader: Extend `' for chain-loader. Resent-From: Julien Lepiller Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 03 Sep 2022 20:09:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 57496 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: tiantian Cc: 57496@debbugs.gnu.org Received: via spool by 57496-submit@debbugs.gnu.org id=B57496.16622357244350 (code B ref 57496); Sat, 03 Sep 2022 20:09:01 +0000 Received: (at 57496) by debbugs.gnu.org; 3 Sep 2022 20:08:44 +0000 Received: from localhost ([127.0.0.1]:43114 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oUZRb-000186-Bt for submit@debbugs.gnu.org; Sat, 03 Sep 2022 16:08:44 -0400 Received: from lepiller.eu ([89.234.186.109]:53516) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oUZRX-00017u-UE for 57496@debbugs.gnu.org; Sat, 03 Sep 2022 16:08:42 -0400 Received: from lepiller.eu (localhost [127.0.0.1]) by lepiller.eu (OpenSMTPD) with ESMTP id 07141860; Sat, 3 Sep 2022 20:08:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=lepiller.eu; h=date:from :to:cc:subject:message-id:in-reply-to:references:mime-version :content-type:content-transfer-encoding; s=dkim; bh=1t/9SIIupQAM q/EXaQD9mV+JscEKh2n4SyZ5Sz72zLI=; b=iqO6UQ8+mfwM6+SXbeAfitUGFkqr 9p9cCSjh0KIJaUQ2e+u8lr8Rd76xk/JR46xg8yMmJZ7uRHgQ6PY3GmmL+yTFEjxL RxEhTboMDe9J4M9jy67cpjB8dJ+6a3iDn2uc8RF9rHtiDNTUkFMIGYpnp1bOJgKD AREdUXQydAhACeigwdADvNI9yZtWFluU4PKO5fLsh+DnbzFOJFwnzxHMAA6bUDEX ACwCp7tIYR3Jcukkpzgd9Ej4tSCD9Vo7A/Z8wfZ7bsud7DrFffUKzyTrTNjd+6wV v/tu84o4MtweyNn30dW0gNTJQjZozFjDv6m+eJfPsWr2VsteKe4bOwUSvg== Received: by lepiller.eu (OpenSMTPD) with ESMTPSA id ed258201 (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Sat, 3 Sep 2022 20:08:37 +0000 (UTC) Date: Sat, 3 Sep 2022 22:08:35 +0200 From: Julien Lepiller Message-ID: <20220903220835.52d60d1d@sybil.lepiller.eu> In-Reply-To: References: <55016216-84d9-e2e6-8bf5-0efdfa0e6ac1@foxmail.com> <20220831213406.3ec92474@sybil.lepiller.eu> <7xy1v37ny8.fsf@foxmail.com> X-Mailer: Claws Mail 4.1.0 (GTK 3.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1662235754; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=iYCD7olqbKEiOvC4fGnS3y337elPRY0n+8EXSmDxq/A=; b=pBww25sV8sxZ+zmeWdtzaXZ556p472boneCnZDdiMj8e/pdvqgGqdJVxxdtZ4WJaBJXiWA B01qeeD2e2qZdir8OsbF6FKy3F41WDYqqTAA/dinSMATpskbOLmjtjJmHAbQIxpRf/zN0O 1wQUZtS3qn8t1QL1CzqzYjnD9sQedoVj3t8GXB1O/jkA2B4QisC8p4zbrhWdSoQBcXLNv+ ux4zEkQvR6R2fXh8Z0TPhjb7jdo8oCquTsa8Ui7yHsvyk9qwJyysqLUryfcWtpnfnrnQDg nCTMRy4lK53Tfwl9/cz21yum51i4AoY7fXb0w6ceZ+7G/vwuJGhvgbrPgDLS9A== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1662235754; a=rsa-sha256; cv=none; b=Iov2l7Jy3x0rbU4Hie5KqcBCV4p2BFGrFwGrXxKR9xgQNkfGj2wsV4qcLf3QTBZA/DqbZI CGv9xzmpRz74AWT/N4OtMEW1HUgdpymqerKOTeoM/FqT9w/zRBOxNYWROabW35Q3asI64s jyHdAvCP4FBJMvAjKwnRpf7ZidBw8TbE0bkg95N4VJLqFOtbnD07yMCYgJemX5V7sI7cqb Pj98O76WtP4MqcXsNzaUiEXxPTZ9uF6oWlXnhLlzu89dVZaa+HEsQA3GgZ/nry4BqVf8wl ZqBU/BEtKOjqMAGjgW9rk1wXrRghQ0ncWtMaTAo69Y8MC1rMpypf6BHZUXBJuA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=lepiller.eu header.s=dkim header.b=iqO6UQ8+; dmarc=fail reason="SPF not aligned (relaxed)" header.from=lepiller.eu (policy=none); spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: 5.73 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=lepiller.eu header.s=dkim header.b=iqO6UQ8+; dmarc=fail reason="SPF not aligned (relaxed)" header.from=lepiller.eu (policy=none); spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 39B011701F X-Spam-Score: 5.73 X-Migadu-Scanner: scn0.migadu.com X-TUID: +01Ez/to1lEl Hi tiantian, Le Fri, 02 Sep 2022 09:04:15 +0800, tiantian a =C3=A9crit : > Hi Lepiller, Please call me Julien, I'm more used to being called by my first name. >=20 > After reviewing some documents of grub. How about changing > "linux-multiboot" to "multiboot" or "multiboot-kernel" in the > document? The first is because multiboot is used in grub manual. The > scecond is because multiboot-kernel is a field that appears in guix > manual. >=20 > like this: >=20 > @item @code{chain-loader} (default: @code{#f}) > A string that can be accepted by @code{grub}'s @code{chainloader} > directive. This has no effect if either @code{linux} or > @code{multiboot} fields are specified. The following is an > example of chainloading a different GNU/Linux system. >=20 > or >=20 > @item @code{chain-loader} (default: @code{#f}) > A string that can be accepted by @code{grub}'s @code{chainloader} > directive. This has no effect if either @code{linux} or > @code{multiboot-kernel} fields are specified. The following is an > example of chainloading a different GNU/Linux system. You're right, I made a mistake here, I meant the multiboot-kernel field, like that second example. I have no problem pushing the patches you have so far without any error message, although I can still see one issue. In the grub manual I see this example of chain-loading: menuentry "Windows" { insmod chain insmod ntfs set root=3D(hd0,1) chainloader +1 } which I cannot reproduce. I've used "chainloader +1" (by writing my own grub.cfg manually) with Haiku which is another free OS (though I think it uses nonfree blobs for hardware), so I think we should support this use case too, not just booting another EFI entry. When I=C2=A0set chain-loader "+1", I=C2=A0get the following grub config: menuentry "haiku" {=20 chainloader +1 } With no root. I think this is because of our grub-root-search procedure, which doesn't work in that case. Do you have any ideas how to support that use-case? If it's too complex I'm fine leaving it behind for now. It should not slow us down. >=20 > There are many situations that I need to check. I can't find a case in > menu-entry->sexp to solve it. So, I wrote a function alone. After I > have preliminarily completed the function that checks menu-entry, I > found that it seems that the explicit pattern is more readable than my > individual function. >=20 > The procedure that check menu-entry will check that there is no boot, > different fields of boot are mixed, and there are multiple boot > modes. I haven't tested it yet. The expected effect is as follows. >=20 > --- start examples ---- >=20 Those examples are nice :) >=20 > --- end examples --- >=20 > But the procedure lead more difficult to read and understand the > code. Maybe it's because my code level is not enough. For the current > code, I'm not sure if the error message is worth the performance it > consumes and the code that becomes difficult to understand. The check > of the procedure is not strong. It only checks whether some fields > are set, but not whether the contents of the fields are correct. >=20 > And I think the most important point is that the procedure just check > menu-entry. menu-entry->sexp still need to check linux, multiboot and > chain-loader. if not check, An incorrect match will occur in > menu-entry->sexp, and an error message that is not helpful may be > reported by 'guix system'. >=20 > I think it might be good to use the menu-entry->sexp in v2 patch. > Should I keep menu-entry->sexp of v2 in v3 patch, in addition to > adding some necessary comments? Let's keep the code from v2. >=20 > The code of the procedure is following. >=20 > --- >8 --- =20 >=20 > (define (check-menu-entry entry) > (define (all-correct? fields) > "Returns a pair according to the number of #t in the FIELDS. > If all of the FIELDS are #t, the pair is (#t . #t). If the part of > FIELDS is #t, the pair is (#t . #t). If all of the FIELDS aren't #t, > the pair is (#f . #f)." > (let ((total (length fields)) > (right (length (filter identity > fields)))) > (cond ((=3D right 0) (cons #f #f)) > ((< right total) (cons #t #f)) > ((=3D right total) (cons #t #t))))) > (define (get-all-correct-amount boot-methods right-number) > (match boot-methods > (((_ . #t) rest ...) > (get-all-correct-amount rest (1+ right-number))) > (((_ . #f) rest ...) > (get-all-correct-amount rest right-number)) > (() right-number))) > (define (get-part-correct-amount boot-methods number) > (match boot-methods > (((_ . #t) rest ...) > (get-part-correct-amount rest number)) > (((#t . #f) rest ...) > (get-part-correct-amount rest (1+ number))) > (((#f . #f) rest ...) > (get-part-correct-amount rest number)) > (() number))) > (match-record entry > (label > linux initrd multiboot-kernel multiboot-arguments > multiboot-modules chain-loader) > (let* ((linux-boot? > (all-correct? (list linux initrd))) > (multiboot? > (all-correct? > (list multiboot-kernel > (not (null? multiboot-arguments)) > (not (null? multiboot-modules))))) > (chain-loader? > (all-correct? (list chain-loader))) > (boot-method-all-amount > (get-all-correct-amount > (list linux-boot? > multiboot? > chain-loader?) > 0)) > (boot-method-part-amount > (get-part-correct-amount > (list linux-boot? > multiboot? > chain-loader?) 0)) > (selects " > 1. boot directly (linux + linux-arguments + linux-modules) > 2. multiboot (multiboot-kernel + multiboot-arguments + > multiboot-modules) 3. chain-loader(chain-loader)\n") > ((raise-message > (lambda (message) > (raise (condition > (&message > (format #f > (G_ "invalid menu-entry: ~a~%~a~%~a~%") > entry message selects)))))))) > (match (list boot-method-part-amount boot-method-all-amount) > ((0 0) > (raise-message "Please select one of following.")) > ((0 1) #t) > ((0 (? (lambda (n) (> n 1)) _)) > (raise-message "Plase don't have more than one boot > method.")) (((? (lambda (n) (> n 0)) _) _) > (raise-message "Plese don't mix them.")))))) >=20 > --- 8< --- Maybe it would be easier to have something like this: (define (check-menu-entry menu-entry) (define all-linux-fields (and (menu-entry-linux menu-entry) (menu-entry-linux-arguments menu-entry) (menu-entry-linux-modules menu-entry))) (define all-multiboot-fields ...) (define all-chainload-fields ...) (define count-methods (+ (if all-linux-fields 1 0) (if all-multiboot-fields 1 0) (if all-chainload-fields 1 0))) (define (report err) (raise (condition (&message (message (format #f (G_ "invalid menu-entry: ~a" err)))) (&fix-hint (hint (G_ "Please chose only one of: @enumerate @item direct boot by specifying fields @code{linux}, @code{linux-arguments} and @code{linux-modules}, @item multiboot by specifying fields @code{multiboot-kernel}, @code{multiboot-arguments} and @code{multiboot-modules}, @item chain-loader by specifying field @code{chain-loader}. @end enumerate")))))) (cond ((and (not all-linux-fields) (not all-multiboot-fields) (not all-chainload-fields)) (report (G_ "No boot method was chosen for this menu entry."))) ((> count-methods 1) (report (G_ "More than two boot methods were selected for this menu entry."))) (else #t))) This is untested, so there might be bugs :) Note that we need to have all strings translatable (with G_). In any case, that new code for error messages should go in a third, separate patch. >=20 > Without any exceptions, v3 patch may be the last version. So how can I > modify the submission information to record your help to me? You don't have to because I didn't contribute much to that patch, and I will sign it off when commiting. If you take the code above as is and don't modify it too much, then you can add something like this at the end of the commit message (only for the patch that contains my code): Co-Authored-By: Julien Lepiller >=20 > I would like to express my sincere thanks to you.I look forward to > your reply. >=20 > Thanks, > tiantian