[PATCH v4 0/1] enable checkers on grub-module-verifierxx

2022-10-04 Thread Robbie Harwood
Address Daniel's comments on previous version.

In particular, gcc (Debian 12.2.0-3) only warns when the redefinition is
to a different value.  It gets confused by the space, so just remove it.
This causes

gcc -x c -fsyntax-only -Iinclude -I. util/grub-module-verifierXX.c

to build without warnings.

Interdiff attached.

Be well,
--Robbie

Peter Jones (1):
  grub-module-verifierxx.c: enable running standalone checkers

 util/grub-module-verifier32.c | 2 ++
 util/grub-module-verifier64.c | 2 ++
 util/grub-module-verifierXX.c | 9 +
 3 files changed, 13 insertions(+)

Interdiff against v3:
-- 
2.35.1


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v4 1/1] grub-module-verifierxx.c: enable running standalone checkers

2022-10-04 Thread Robbie Harwood
From: Peter Jones 

Allow treating grub-module-verifierxx.c as a file you can build directly
so syntax checkers like vim's "syntastic" plugin, which uses "gcc -x c
-fsyntax-only" to build it, will work.

One still has to do whatever setup is required to make it pick the right
include dirs, which -I options we use, etc., but this makes it so you
can do the checking on the file you're editing, rather than on a
different file.

Signed-off-by: Peter Jones 
Signed-off-by: Robbie Harwood 
---
 util/grub-module-verifier32.c | 2 ++
 util/grub-module-verifier64.c | 2 ++
 util/grub-module-verifierXX.c | 9 +
 3 files changed, 13 insertions(+)

diff --git a/util/grub-module-verifier32.c b/util/grub-module-verifier32.c
index 257229f8f0..ba7d41aafe 100644
--- a/util/grub-module-verifier32.c
+++ b/util/grub-module-verifier32.c
@@ -1,2 +1,4 @@
 #define MODULEVERIFIER_ELF32 1
+#ifndef GRUB_MODULE_VERIFIERXX
 #include "grub-module-verifierXX.c"
+#endif
diff --git a/util/grub-module-verifier64.c b/util/grub-module-verifier64.c
index 4db6b4bedd..fc23ef800b 100644
--- a/util/grub-module-verifier64.c
+++ b/util/grub-module-verifier64.c
@@ -1,2 +1,4 @@
 #define MODULEVERIFIER_ELF64 1
+#ifndef GRUB_MODULE_VERIFIERXX
 #include "grub-module-verifierXX.c"
+#endif
diff --git a/util/grub-module-verifierXX.c b/util/grub-module-verifierXX.c
index 8e0cd91d90..d5907f268e 100644
--- a/util/grub-module-verifierXX.c
+++ b/util/grub-module-verifierXX.c
@@ -1,3 +1,12 @@
+#define GRUB_MODULE_VERIFIERXX
+#if !defined(MODULEVERIFIER_ELF32) && !defined(MODULEVERIFIER_ELF64)
+#if __SIZEOF_POINTER__ == 8
+#include "grub-module-verifier64.c"
+#else
+#include "grub-module-verifier32.c"
+#endif
+#endif
+
 #include 
 
 #include 
-- 
2.35.1


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v4 1/1] Add support for grub-emu to kexec Linux menu entries

2022-10-04 Thread Robbie Harwood
From: Raymund Will 

The GRUB emulator is used as a debugging utility but it could also be
used as a user-space bootloader if there is support to boot an operating
system.

The Linux kernel is already able to (re)boot another kernel via the
kexec boot mechanism.  So the grub-emu tool could rely on this feature
and have linux and initrd commands that are used to pass a kernel,
initramfs image and command line parameters to kexec for booting a
selected menu entry.

By default the systemctl kexec option is used so systemd can shutdown
all of the running services before doing a reboot using kexec.  But if
this is not present, it can fall back to executing the kexec user-space
tool directly.  The ability to force a kexec-reboot when systemctl kexec
fails must only be used in controlled environments to avoid possible
filesystem corruption and data loss.

Signed-off-by: Raymund Will 
Signed-off-by: John Jolly 
Signed-off-by: Javier Martinez Canillas 
Signed-off-by: Robbie Harwood 
---
 grub-core/Makefile.am|   1 +
 grub-core/Makefile.core.def  |   2 +-
 grub-core/kern/emu/main.c|   4 +
 grub-core/kern/emu/misc.c|  18 +++-
 grub-core/loader/emu/linux.c | 181 +++
 include/grub/emu/exec.h  |   4 +-
 include/grub/emu/hostfile.h  |   3 +-
 include/grub/emu/misc.h  |   3 +
 8 files changed, 212 insertions(+), 4 deletions(-)
 create mode 100644 grub-core/loader/emu/linux.c

diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am
index ee88e44e97..80e7a83edf 100644
--- a/grub-core/Makefile.am
+++ b/grub-core/Makefile.am
@@ -307,6 +307,7 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/net.h
 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/hostdisk.h
 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/hostfile.h
 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h
+KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/exec.h
 if COND_GRUB_EMU_SDL
 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/sdl.h
 endif
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
index 7159948721..5350408601 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -1816,9 +1816,9 @@ module = {
   arm64 = loader/arm64/linux.c;
   riscv32 = loader/riscv/linux.c;
   riscv64 = loader/riscv/linux.c;
+  emu = loader/emu/linux.c;
   common = loader/linux.c;
   common = lib/cmdline.c;
-  enable = noemu;
 };
 
 module = {
diff --git a/grub-core/kern/emu/main.c b/grub-core/kern/emu/main.c
index 44e087e988..855b11c3de 100644
--- a/grub-core/kern/emu/main.c
+++ b/grub-core/kern/emu/main.c
@@ -107,6 +107,7 @@ static struct argp_option options[] = {
N_("use GRUB files in the directory DIR [default=%s]"), 0},
   {"verbose", 'v', 0,  0, N_("print verbose messages."), 0},
   {"hold", 'H', N_("SECS"),  OPTION_ARG_OPTIONAL, N_("wait until a 
debugger will attach"), 0},
+  {"kexec",   'X', 0,  0, N_("use kexec to boot Linux kernels via 
systemctl (pass twice to enable dangerous fallback to non-systemctl)."), 0},
   { 0, 0, 0, 0, 0, 0 }
 };
 
@@ -164,6 +165,9 @@ argp_parser (int key, char *arg, struct argp_state *state)
 case 'v':
   verbosity++;
   break;
+case 'X':
+  grub_util_set_kexecute ();
+  break;
 
 case ARGP_KEY_ARG:
   {
diff --git a/grub-core/kern/emu/misc.c b/grub-core/kern/emu/misc.c
index d0e7a107e7..521220b49d 100644
--- a/grub-core/kern/emu/misc.c
+++ b/grub-core/kern/emu/misc.c
@@ -39,6 +39,7 @@
 #include 
 
 int verbosity;
+int kexecute;
 
 void
 grub_util_warn (const char *fmt, ...)
@@ -82,7 +83,7 @@ grub_util_error (const char *fmt, ...)
   vfprintf (stderr, fmt, ap);
   va_end (ap);
   fprintf (stderr, ".\n");
-  exit (1);
+  grub_exit ();
 }
 
 void *
@@ -153,6 +154,9 @@ xasprintf (const char *fmt, ...)
 void
 grub_exit (void)
 {
+#if defined (GRUB_KERNEL)
+  grub_reboot ();
+#endif
   exit (1);
 }
 #endif
@@ -214,3 +218,15 @@ grub_util_load_image (const char *path, char *buf)
 
   fclose (fp);
 }
+
+void
+grub_util_set_kexecute (void)
+{
+  kexecute++;
+}
+
+int
+grub_util_get_kexecute (void)
+{
+  return kexecute;
+}
diff --git a/grub-core/loader/emu/linux.c b/grub-core/loader/emu/linux.c
new file mode 100644
index 00..bdcdbb0ff4
--- /dev/null
+++ b/grub-core/loader/emu/linux.c
@@ -0,0 +1,181 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2006,2007,2008,2009,2010  Free Software Foundation, Inc.
+ *
+ *  GRUB 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.
+ *
+ *  GRUB 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 

[PATCH v4 0/1] Add support for grub-emu to kexec Linux menu entries

2022-10-04 Thread Robbie Harwood
Address feedback from Raymund's review.  Interdiff attached.

Be well,
--Robbie

Raymund Will (1):
  Add support for grub-emu to kexec Linux menu entries

 grub-core/Makefile.am|   1 +
 grub-core/Makefile.core.def  |   2 +-
 grub-core/kern/emu/main.c|   4 +
 grub-core/kern/emu/misc.c|  18 +++-
 grub-core/loader/emu/linux.c | 181 +++
 include/grub/emu/exec.h  |   4 +-
 include/grub/emu/hostfile.h  |   3 +-
 include/grub/emu/misc.h  |   3 +
 8 files changed, 212 insertions(+), 4 deletions(-)
 create mode 100644 grub-core/loader/emu/linux.c

Interdiff against v3:
diff --git a/grub-core/kern/emu/main.c b/grub-core/kern/emu/main.c
index b4da9d21cf..855b11c3de 100644
--- a/grub-core/kern/emu/main.c
+++ b/grub-core/kern/emu/main.c
@@ -107,7 +107,7 @@ static struct argp_option options[] = {
N_("use GRUB files in the directory DIR [default=%s]"), 0},
   {"verbose", 'v', 0,  0, N_("print verbose messages."), 0},
   {"hold", 'H', N_("SECS"),  OPTION_ARG_OPTIONAL, N_("wait until a 
debugger will attach"), 0},
-  {"kexec",   'X', 0,  0, N_("use kexec to boot Linux kernels."), 0},
+  {"kexec",   'X', 0,  0, N_("use kexec to boot Linux kernels via 
systemctl (pass twice to enable dangerous fallback to non-systemctl)."), 0},
   { 0, 0, 0, 0, 0, 0 }
 };
 
diff --git a/grub-core/loader/emu/linux.c b/grub-core/loader/emu/linux.c
index b5ea48a677..bdcdbb0ff4 100644
--- a/grub-core/loader/emu/linux.c
+++ b/grub-core/loader/emu/linux.c
@@ -77,9 +77,10 @@ grub_linux_boot (void)
   rc = grub_util_exec (systemctl);
 
   if (kexecute == 1)
-grub_error (rc, N_("Error trying to perform 'systemctl kexec'"));
+grub_fatal (N_("Error trying to perform 'systemctl kexec'"));
 
-  /* need to check read-only root before resetting hard!? */
+  /* WARNING: forcible reset should only be used in read-only environments.
+   * grub-emu cannot check for these - users beware. */
   grub_dprintf ("linux", "Performing 'kexec -e -x'");
   kexec[1] = "-e";
   kexec[2] = "-x";
-- 
2.35.1


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: Automatically detecting empty configuration variables

2022-10-04 Thread Didier Spaier
Le 04/10/2022 à 13:28, Alberto Salvia Novella a écrit :
> Greetings boyos!
> 
> I have developed a grub configuration file that, instead of asking the user
> manually setting all the grub variables, it figures them out by itself
> automatically.
> 
> The file looks like this:
> https://pastebin.com/CUGHnckJ 
> 
> I was wondering if that logic could be included in GRUB C code itself. As if 
> the
> configuration file misses a variable, GRUB assumes the variable shall be 
> guessed
> automatically as in that config file.
> 
> If you agree with this change, I can summit a patch.

Hi Alberto,

speaking as a packager and a Linux distribution maintainer, I do not agree with
such a change:
1) I would not make an assumption like "if os-prober is installed, there are
several OS" nor that os-prober should be enabled in that case.
2) More generally it is to the package maintainer or local admin what to include
 by default in /etc/default/grub and up to the user to customize it.
3) In case a distribution does not include grub, I would expect a user wanting
to install it to read "info grub" and edit /etc/default grub as he or she sees 
fit.

Best regards,
Didier

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Automatically detecting empty configuration variables

2022-10-04 Thread Alberto Salvia Novella
Greetings boyos!

I have developed a grub configuration file that, instead of asking the user
manually setting all the grub variables, it figures them out by itself
automatically.

The file looks like this:
https://pastebin.com/CUGHnckJ

I was wondering if that logic could be included in GRUB C code itself. As
if the configuration file misses a variable, GRUB assumes the variable
shall be guessed automatically as in that config file.

If you agree with this change, I can summit a patch.
___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel