Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1kmpOY-00050C-K3 for mharc-grub-devel@gnu.org; Tue, 08 Dec 2020 21:39:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33486) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kmpOX-0004zr-6T for grub-devel@gnu.org; Tue, 08 Dec 2020 21:39:57 -0500 Received: from mail-il1-x144.google.com ([2607:f8b0:4864:20::144]:39954) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kmpOV-0004ml-5a for grub-devel@gnu.org; Tue, 08 Dec 2020 21:39:56 -0500 Received: by mail-il1-x144.google.com with SMTP id g1so179271ilk.7 for ; Tue, 08 Dec 2020 18:39:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=getseam-com.20150623.gappssmtp.com; s=20150623; h=from:content-transfer-encoding:mime-version:subject:message-id:date :to; bh=Wn1klDB2tIBS+JUtI0GTAYzyUziV0Xt24HOe4TyLUCA=; b=VU9sEnzofGaHy7QRnP4YxSeMTu/44XArFpxW0b+i8gp+PJW5TAaix8WlXrxk2Idd2I 19L+q27+xg7ivy2jx1Qe4ZvN5KA0RXGT5IfS6E9JP7odnJIjyQN9FOXKQtbPZOrZWbnX dIld+3gP7JnfYh2JyL0z8iHJtnte2c5ZzQetI1c1jGm/oZ9Ph75bhEzm1hKGrZJwYTh3 gmVXYj40Z8h5ws1CT8ORt7xLYJBTkXMJHSmWyh+6bObFDsxoVqnfJuewcaytLs23QaBG 6rxUqPZL/ecOwqtvm9yZG9Loj2Wi4oWbRG1Bjip/kWTeI/ys3Zzp0SuwvsLX2Pxza2bU EsFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:content-transfer-encoding:mime-version :subject:message-id:date:to; bh=Wn1klDB2tIBS+JUtI0GTAYzyUziV0Xt24HOe4TyLUCA=; b=tmIKK0urD8AtmVM2CuxFM4MnW8MLmYNoiuO2RXTdw4mMF0zOMUI65Q2kVUNBW6gaha dH1V8WRxuMGi9eruLzjiMVTc/Q8oQhVZgKrgc7FynK45w7I1hvevZCXQbvy0379zZMIT LRWo737KNK9k2dj4/k97zD7z6jM40NXyiNnDk2VQ4rNt3gOjvR2SEKkxwC8Y2fg0iBEt DG9uTH/HVY8oW3DrlD5dTlhGJ0cRIf98Ai8Fh3T18mpSOMDS9Sll6YUemg6S5Bv9GtJH xNccEZE0n0TEEiGgsuf9cBPS31qzo7FFZG/LWl+poVJLzfM62Ns2qMkxeUimz4vMxfH6 tTLg== X-Gm-Message-State: AOAM530p7oHJDWBMY+foodSG8pSbg7oeeBHalLbpfIkCuVkZgRJRM4lG buHQuhqJNtJJ1Iev2+0+qa3vwv4GrgIYHNsL X-Google-Smtp-Source: ABdhPJy/rIhNOuRsXMfRhtiVA2Ish4fQlaQAhTu/aTGe5tXpXXWWGOYT1ww9JFACSSmyEIg1oe5Uvw== X-Received: by 2002:a92:cccd:: with SMTP id u13mr200490ilq.273.1607481593275; Tue, 08 Dec 2020 18:39:53 -0800 (PST) Received: from dorothy.webb.haus ([24.148.31.157]) by smtp.gmail.com with ESMTPSA id l23sm24837iob.42.2020.12.08.18.39.51 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 Dec 2020 18:39:52 -0800 (PST) From: Jordan Webb Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.20.0.2.21\)) Subject: [PATCH] efi: Copy load_options into environment Message-Id: Date: Tue, 8 Dec 2020 20:39:50 -0600 To: grub-devel@gnu.org X-Mailer: Apple Mail (2.3654.20.0.2.21) Received-SPF: none client-ip=2607:f8b0:4864:20::144; envelope-from=jordan@getseam.com; helo=mail-il1-x144.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Dec 2020 02:39:57 -0000 When GRUB is loaded as an EFI application, it will copy the EFI LoadOptions into an environment variable called "efi_load_options" and export it. My use case for this is to pass along arguments generated by the Raspberry Pi's internal bootloader from U-Boot to GRUB to a Linux kernel, but I think it's something that could be generally useful to other people doing interesting things in EFI environments. --- grub-core/kern/efi/init.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/grub-core/kern/efi/init.c b/grub-core/kern/efi/init.c index 2c31847bf..29281c3c5 100644 --- a/grub-core/kern/efi/init.c +++ b/grub-core/kern/efi/init.c @@ -17,6 +17,7 @@ * along with GRUB. If not, see . */ =20 +#include #include #include #include @@ -31,6 +32,10 @@ grub_addr_t grub_modbase; void grub_efi_init (void) { + grub_efi_loaded_image_t *image =3D NULL; + int len; + char *load_options; + grub_modbase =3D grub_efi_modules_addr (); /* First of all, initialize the console so that GRUB can display messages. */ @@ -43,6 +48,14 @@ grub_efi_init (void) 0, 0, 0, NULL); =20 grub_efidisk_init (); + + /* Copy EFI load options into environment */ + image =3D grub_efi_get_loaded_image (grub_efi_image_handle); + len =3D image->load_options_size / sizeof (grub_efi_char16_t); + load_options =3D grub_malloc (len * sizeof (char)); + *grub_utf16_to_utf8 ((grub_uint8_t *) load_options, = image->load_options, len) =3D '\0'; + grub_env_set("efi_load_options", load_options); + grub_env_export("efi_load_options"); } =20 void (*grub_efi_net_config) (grub_efi_handle_t hnd, --=20 2.24.3 (Apple Git-128)