mirror of
https://src.fedoraproject.org/rpms/grub2.git
synced 2024-11-24 06:22:43 +00:00
add bls stuff
Signed-off-by: Peter Jones <pjones@redhat.com>
This commit is contained in:
parent
b07c761d06
commit
bd638f8e8c
5 changed files with 753 additions and 3 deletions
86
0001-Make-blscfg-include-some-IDs-and-indices.patch
Normal file
86
0001-Make-blscfg-include-some-IDs-and-indices.patch
Normal file
|
@ -0,0 +1,86 @@
|
|||
From 3f2d8bc3a052c7ab6f89a7684ac93b0f8401a6b5 Mon Sep 17 00:00:00 2001
|
||||
From: Peter Jones <pjones@redhat.com>
|
||||
Date: Fri, 28 Oct 2016 10:55:56 -0400
|
||||
Subject: [PATCH] Make blscfg include some IDs and indices
|
||||
|
||||
Signed-off-by: Peter Jones <pjones@redhat.com>
|
||||
---
|
||||
grub-core/commands/blscfg.c | 27 +++++++++++++++++++++++----
|
||||
1 file changed, 23 insertions(+), 4 deletions(-)
|
||||
|
||||
diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c
|
||||
index af838d2..2a16858 100644
|
||||
--- a/grub-core/commands/blscfg.c
|
||||
+++ b/grub-core/commands/blscfg.c
|
||||
@@ -56,6 +56,9 @@ static int parse_entry (
|
||||
grub_file_t f = NULL;
|
||||
grub_off_t sz;
|
||||
char *title = NULL, *options = NULL, *clinux = NULL, *initrd = NULL, *src = NULL;
|
||||
+ char *id = NULL;
|
||||
+ char *class[] = { NULL, NULL };
|
||||
+ char **classes = class[0];
|
||||
const char *args[2] = { NULL, NULL };
|
||||
const char *dirname = (const char *)data;
|
||||
const char *devid = grub_env_get ("boot");
|
||||
@@ -120,6 +123,20 @@ static int parse_entry (
|
||||
if (!initrd)
|
||||
goto finish;
|
||||
}
|
||||
+ else if (grub_strncmp (buf, "id ", 3) == 0)
|
||||
+ {
|
||||
+ grub_free (id);
|
||||
+ id = grub_strdup (buf + 3);
|
||||
+ if (!id)
|
||||
+ goto finish;
|
||||
+ }
|
||||
+ else if (grub_strncmp (buf, "index ", 6) == 0)
|
||||
+ {
|
||||
+ grub_free (class[0]);
|
||||
+ class[0] = grub_strdup (buf + 6);
|
||||
+ if (!class[0])
|
||||
+ goto finish;
|
||||
+ }
|
||||
|
||||
grub_free(buf);
|
||||
}
|
||||
@@ -141,7 +158,7 @@ static int parse_entry (
|
||||
GRUB_BOOT_DEVICE, clinux, options ? " " : "", options ? options : "",
|
||||
initrd ? GRUB_INITRD_CMD " " : "", initrd ? GRUB_BOOT_DEVICE : "", initrd ? initrd : "", initrd ? "\n" : "");
|
||||
|
||||
- grub_normal_add_menu_entry (1, args, NULL, NULL, "bls", NULL, NULL, src, 0);
|
||||
+ grub_normal_add_menu_entry (1, args, classes, id, "bls", NULL, NULL, src, 0);
|
||||
|
||||
finish:
|
||||
grub_free (p);
|
||||
@@ -150,6 +167,8 @@ finish:
|
||||
grub_free (clinux);
|
||||
grub_free (initrd);
|
||||
grub_free (src);
|
||||
+ grub_free (id);
|
||||
+ grub_free (class[0]);
|
||||
|
||||
if (f)
|
||||
grub_file_close (f);
|
||||
@@ -333,7 +352,7 @@ finish:
|
||||
#endif
|
||||
|
||||
static grub_err_t
|
||||
-grub_cmd_bls_import (grub_extcmd_context_t ctxt __attribute__ ((unused)),
|
||||
+grub_cmd_blscfg (grub_extcmd_context_t ctxt __attribute__ ((unused)),
|
||||
int argc __attribute__ ((unused)),
|
||||
char **args __attribute__ ((unused)))
|
||||
{
|
||||
@@ -384,8 +403,8 @@ static grub_extcmd_t cmd;
|
||||
|
||||
GRUB_MOD_INIT(bls)
|
||||
{
|
||||
- cmd = grub_register_extcmd ("bls_import",
|
||||
- grub_cmd_bls_import,
|
||||
+ cmd = grub_register_extcmd ("blscfg",
|
||||
+ grub_cmd_blscfg,
|
||||
0,
|
||||
NULL,
|
||||
N_("Import Boot Loader Specification snippets."),
|
||||
--
|
||||
2.9.3
|
||||
|
531
0001-blscfg-make-the-bls_import-command-know-to-search-en.patch
Normal file
531
0001-blscfg-make-the-bls_import-command-know-to-search-en.patch
Normal file
|
@ -0,0 +1,531 @@
|
|||
From 00857b7fb451f2abf9e97229aef537dab3d56f6e Mon Sep 17 00:00:00 2001
|
||||
From: Peter Jones <pjones@redhat.com>
|
||||
Date: Mon, 24 Oct 2016 14:51:06 -0400
|
||||
Subject: [PATCH 1/2] blscfg: make the bls_import command know to search env
|
||||
files for blsdir
|
||||
|
||||
This makes it so when you do "bls_import" on EFI systems, it searches
|
||||
/EFI/*/ directories for a grubenv, and if it finds it, temporarily
|
||||
merges that environment into grub's env.
|
||||
|
||||
Once that is done, if there's a variable named "blsdir", it looks there
|
||||
for BLS config files. If that is absent, it tries to load them from
|
||||
/EFI/$DIR/loader/entries/
|
||||
---
|
||||
grub-core/commands/blscfg.c | 219 ++++++++++++++++++++++++++++++++++++++++---
|
||||
grub-core/commands/loadenv.c | 77 +--------------
|
||||
grub-core/commands/loadenv.h | 93 ++++++++++++++++++
|
||||
include/grub/compiler.h | 2 +
|
||||
4 files changed, 305 insertions(+), 86 deletions(-)
|
||||
create mode 100644 grub-core/commands/loadenv.h
|
||||
|
||||
diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c
|
||||
index 4274aca..af838d2 100644
|
||||
--- a/grub-core/commands/blscfg.c
|
||||
+++ b/grub-core/commands/blscfg.c
|
||||
@@ -30,25 +30,26 @@
|
||||
#include <grub/env.h>
|
||||
#include <grub/file.h>
|
||||
#include <grub/normal.h>
|
||||
+#include <grub/lib/envblk.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
+#include "loadenv.h"
|
||||
+
|
||||
+#define GRUB_BLS_CONFIG_PATH "/loader/entries/"
|
||||
+#define GRUB_BOOT_DEVICE "($root)"
|
||||
#ifdef GRUB_MACHINE_EFI
|
||||
#define GRUB_LINUX_CMD "linuxefi"
|
||||
#define GRUB_INITRD_CMD "initrdefi"
|
||||
-#define GRUB_BLS_CONFIG_PATH "/EFI/fedora/loader/entries/"
|
||||
-#define GRUB_BOOT_DEVICE "($boot)"
|
||||
#else
|
||||
#define GRUB_LINUX_CMD "linux"
|
||||
#define GRUB_INITRD_CMD "initrd"
|
||||
-#define GRUB_BLS_CONFIG_PATH "/loader/entries/"
|
||||
-#define GRUB_BOOT_DEVICE "($root)"
|
||||
#endif
|
||||
|
||||
static int parse_entry (
|
||||
const char *filename,
|
||||
- const struct grub_dirhook_info *info __attribute__ ((unused)),
|
||||
- void *data __attribute__ ((unused)))
|
||||
+ const struct grub_dirhook_info *info UNUSED,
|
||||
+ void *data)
|
||||
{
|
||||
grub_size_t n;
|
||||
char *p;
|
||||
@@ -56,6 +57,10 @@ static int parse_entry (
|
||||
grub_off_t sz;
|
||||
char *title = NULL, *options = NULL, *clinux = NULL, *initrd = NULL, *src = NULL;
|
||||
const char *args[2] = { NULL, NULL };
|
||||
+ const char *dirname = (const char *)data;
|
||||
+ const char *devid = grub_env_get ("boot");
|
||||
+
|
||||
+ grub_dprintf ("blscfg", "filename: \"%s\"\n", filename);
|
||||
|
||||
if (filename[0] == '.')
|
||||
return 0;
|
||||
@@ -67,12 +72,14 @@ static int parse_entry (
|
||||
if (grub_strcmp (filename + n - 5, ".conf") != 0)
|
||||
return 0;
|
||||
|
||||
- p = grub_xasprintf (GRUB_BLS_CONFIG_PATH "%s", filename);
|
||||
+ p = grub_xasprintf ("(%s)%s/%s", devid, dirname, filename);
|
||||
+ grub_dprintf ("blscfg", "entry path: \"%s\"\n", p);
|
||||
|
||||
f = grub_file_open (p);
|
||||
if (!f)
|
||||
goto finish;
|
||||
|
||||
+ grub_dprintf ("blscfg", "getting size\n");
|
||||
sz = grub_file_size (f);
|
||||
if (sz == GRUB_FILE_SIZE_UNKNOWN || sz > 1024*1024)
|
||||
goto finish;
|
||||
@@ -119,12 +126,13 @@ static int parse_entry (
|
||||
|
||||
if (!linux)
|
||||
{
|
||||
- grub_printf ("Skipping file %s with no 'linux' key.", p);
|
||||
+ grub_dprintf ("blscfg", "Skipping file %s with no 'linux' key.", p);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
args[0] = title ? title : filename;
|
||||
|
||||
+ grub_dprintf("blscfg", "adding menu entry for \"%s\"\n", clinux);
|
||||
src = grub_xasprintf ("load_video\n"
|
||||
"set gfx_payload=keep\n"
|
||||
"insmod gzio\n"
|
||||
@@ -149,6 +157,181 @@ finish:
|
||||
return 0;
|
||||
}
|
||||
|
||||
+#ifdef GRUB_MACHINE_EFI
|
||||
+static grub_envblk_t saved_env = NULL;
|
||||
+
|
||||
+static int
|
||||
+save_var (const char *name, const char *value, void *whitelist UNUSED)
|
||||
+{
|
||||
+ const char *val = grub_env_get (name);
|
||||
+ grub_dprintf("blscfg", "saving \"%s\"\n", name);
|
||||
+
|
||||
+ if (val)
|
||||
+ grub_envblk_set (saved_env, name, value);
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+static int
|
||||
+unset_var (const char *name, const char *value UNUSED, void *whitelist)
|
||||
+{
|
||||
+ grub_dprintf("blscfg", "restoring \"%s\"\n", name);
|
||||
+ if (! whitelist)
|
||||
+ {
|
||||
+ grub_env_unset (name);
|
||||
+ return 0;
|
||||
+ }
|
||||
+
|
||||
+ if (test_whitelist_membership (name,
|
||||
+ (const grub_env_whitelist_t *) whitelist))
|
||||
+ grub_env_unset (name);
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+struct find_entry_info {
|
||||
+ grub_device_t dev;
|
||||
+ grub_fs_t fs;
|
||||
+};
|
||||
+
|
||||
+/*
|
||||
+ * filename: if the directory is /EFI/something/ , filename is "something"
|
||||
+ * info: unused
|
||||
+ * data: the filesystem object the file is on.
|
||||
+ */
|
||||
+static int find_entry (const char *filename,
|
||||
+ const struct grub_dirhook_info *dirhook_info UNUSED,
|
||||
+ void *data)
|
||||
+{
|
||||
+ struct find_entry_info *info = (struct find_entry_info *)data;
|
||||
+ grub_file_t f = NULL;
|
||||
+ char *grubenv_path = NULL;
|
||||
+ grub_envblk_t env = NULL;
|
||||
+ char *default_blsdir = NULL;
|
||||
+ const char *blsdir = NULL;
|
||||
+ char *saved_env_buf = NULL;
|
||||
+ grub_size_t l;
|
||||
+ int r = 0;
|
||||
+ const char *devid = grub_env_get ("boot");
|
||||
+
|
||||
+ if (!grub_strcmp (filename, ".") ||
|
||||
+ !grub_strcmp (filename, "..") ||
|
||||
+ !grub_strcasecmp (filename, "boot"))
|
||||
+ return 0;
|
||||
+
|
||||
+ saved_env_buf = grub_malloc (512);
|
||||
+
|
||||
+ // set a default blsdir
|
||||
+ default_blsdir = grub_xasprintf ("/EFI/%s%s", filename,
|
||||
+ GRUB_BLS_CONFIG_PATH);
|
||||
+ grub_env_set ("blsdir", default_blsdir);
|
||||
+ grub_dprintf ("blscfg", "default_blsdir: \"%s\"\n", default_blsdir);
|
||||
+
|
||||
+ /*
|
||||
+ * try to load a grubenv from /EFI/wherever/grubenv
|
||||
+ */
|
||||
+ grubenv_path = grub_xasprintf ("(%s)/EFI/%s/grubenv", devid, filename);
|
||||
+ grub_dprintf ("blscfg", "looking for \"%s\"\n", grubenv_path);
|
||||
+ f = grub_file_open (grubenv_path);
|
||||
+
|
||||
+ grub_dprintf ("blscfg", "%s it\n", f ? "found" : "did not find");
|
||||
+ grub_free (grubenv_path);
|
||||
+ if (f)
|
||||
+ {
|
||||
+ grub_off_t sz;
|
||||
+
|
||||
+ grub_dprintf ("blscfg", "getting size\n");
|
||||
+ sz = grub_file_size (f);
|
||||
+ if (sz == GRUB_FILE_SIZE_UNKNOWN || sz > 1024*1024)
|
||||
+ goto finish;
|
||||
+
|
||||
+ grub_dprintf ("blscfg", "reading env\n");
|
||||
+ env = read_envblk_file (f);
|
||||
+ if (!env)
|
||||
+ goto finish;
|
||||
+ grub_dprintf ("blscfg", "read env file\n");
|
||||
+
|
||||
+ grub_memset (saved_env_buf, '#', 512);
|
||||
+ grub_memcpy (saved_env_buf, GRUB_ENVBLK_SIGNATURE,
|
||||
+ sizeof (GRUB_ENVBLK_SIGNATURE));
|
||||
+ grub_dprintf ("blscfg", "saving env\n");
|
||||
+ saved_env = grub_envblk_open (saved_env_buf, 512);
|
||||
+ if (!saved_env)
|
||||
+ goto finish;
|
||||
+
|
||||
+ // save everything listed in "env" with values from our existing grub env
|
||||
+ grub_envblk_iterate (env, NULL, save_var);
|
||||
+ // set everything from our loaded grubenv into the real grub env
|
||||
+ grub_envblk_iterate (env, NULL, set_var);
|
||||
+ }
|
||||
+ else
|
||||
+ {
|
||||
+ grub_err_t e;
|
||||
+ grub_dprintf ("blscfg", "no such file\n");
|
||||
+ do
|
||||
+ {
|
||||
+ e = grub_error_pop();
|
||||
+ } while (e);
|
||||
+
|
||||
+ }
|
||||
+
|
||||
+ blsdir = grub_env_get ("blsdir");
|
||||
+ if (!blsdir)
|
||||
+ goto finish;
|
||||
+
|
||||
+ grub_dprintf ("blscfg", "blsdir: \"%s\"\n", blsdir);
|
||||
+ if (blsdir[0] != '/')
|
||||
+ blsdir = grub_xasprintf ("/EFI/%s/%s/", filename, blsdir);
|
||||
+ else
|
||||
+ blsdir = grub_strdup (blsdir);
|
||||
+
|
||||
+ if (!blsdir)
|
||||
+ goto finish;
|
||||
+
|
||||
+ grub_dprintf ("blscfg", "blsdir: \"%s\"\n", blsdir);
|
||||
+ r = info->fs->dir (info->dev, blsdir, parse_entry, (char *)blsdir);
|
||||
+ if (r != 0) {
|
||||
+ grub_dprintf ("blscfg", "parse_entry returned error\n");
|
||||
+ grub_err_t e;
|
||||
+ do
|
||||
+ {
|
||||
+ e = grub_error_pop();
|
||||
+ } while (e);
|
||||
+ }
|
||||
+
|
||||
+finish:
|
||||
+ grub_free (blsdir);
|
||||
+
|
||||
+ grub_env_unset ("blsdir");
|
||||
+
|
||||
+ if (saved_env)
|
||||
+ {
|
||||
+ // remove everything from the real environment that's defined in env
|
||||
+ grub_envblk_iterate (env, NULL, unset_var);
|
||||
+
|
||||
+ // re-set the things from our original environment
|
||||
+ grub_envblk_iterate (saved_env, NULL, set_var);
|
||||
+ grub_envblk_close (saved_env);
|
||||
+ saved_env = NULL;
|
||||
+ }
|
||||
+ else if (saved_env_buf)
|
||||
+ {
|
||||
+ // if we have a saved environment, grub_envblk_close() freed this.
|
||||
+ grub_free (saved_env_buf);
|
||||
+ }
|
||||
+
|
||||
+ if (env)
|
||||
+ grub_envblk_close (env);
|
||||
+
|
||||
+ if (f)
|
||||
+ grub_file_close (f);
|
||||
+
|
||||
+ grub_free (default_blsdir);
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
static grub_err_t
|
||||
grub_cmd_bls_import (grub_extcmd_context_t ctxt __attribute__ ((unused)),
|
||||
int argc __attribute__ ((unused)),
|
||||
@@ -158,15 +341,22 @@ grub_cmd_bls_import (grub_extcmd_context_t ctxt __attribute__ ((unused)),
|
||||
grub_device_t dev;
|
||||
static grub_err_t r;
|
||||
const char *devid;
|
||||
+#ifdef GRUB_MACHINE_EFI
|
||||
+ struct find_entry_info info;
|
||||
+#endif
|
||||
|
||||
- devid = grub_env_get ("root");
|
||||
+ grub_dprintf ("blscfg", "finding boot\n");
|
||||
+ devid = grub_env_get ("boot");
|
||||
if (!devid)
|
||||
- return grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("variable `%s' isn't set"), "root");
|
||||
+ return grub_error (GRUB_ERR_FILE_NOT_FOUND,
|
||||
+ N_("variable `%s' isn't set"), "boot");
|
||||
|
||||
+ grub_dprintf ("blscfg", "opening %s\n", devid);
|
||||
dev = grub_device_open (devid);
|
||||
if (!dev)
|
||||
return grub_errno;
|
||||
|
||||
+ grub_dprintf ("blscfg", "probing fs\n");
|
||||
fs = grub_fs_probe (dev);
|
||||
if (!fs)
|
||||
{
|
||||
@@ -174,7 +364,14 @@ grub_cmd_bls_import (grub_extcmd_context_t ctxt __attribute__ ((unused)),
|
||||
goto finish;
|
||||
}
|
||||
|
||||
- r = fs->dir (dev, GRUB_BLS_CONFIG_PATH, parse_entry, NULL);
|
||||
+#ifdef GRUB_MACHINE_EFI
|
||||
+ info.dev = dev;
|
||||
+ info.fs = fs;
|
||||
+ grub_dprintf ("blscfg", "scanning /EFI/\n");
|
||||
+ r = fs->dir (dev, "/EFI/", find_entry, &info);
|
||||
+#else
|
||||
+ r = fs->dir (dev, GRUB_BLS_CONFIG_PATH, parse_entry, GRUB_BLS_CONFIG_PATH);
|
||||
+#endif
|
||||
|
||||
finish:
|
||||
if (dev)
|
||||
diff --git a/grub-core/commands/loadenv.c b/grub-core/commands/loadenv.c
|
||||
index acd93d1..91c9945 100644
|
||||
--- a/grub-core/commands/loadenv.c
|
||||
+++ b/grub-core/commands/loadenv.c
|
||||
@@ -28,6 +28,8 @@
|
||||
#include <grub/extcmd.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
+#include "loadenv.h"
|
||||
+
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static const struct grub_arg_option options[] =
|
||||
@@ -84,81 +86,6 @@ open_envblk_file (char *filename, int untrusted)
|
||||
return file;
|
||||
}
|
||||
|
||||
-static grub_envblk_t
|
||||
-read_envblk_file (grub_file_t file)
|
||||
-{
|
||||
- grub_off_t offset = 0;
|
||||
- char *buf;
|
||||
- grub_size_t size = grub_file_size (file);
|
||||
- grub_envblk_t envblk;
|
||||
-
|
||||
- buf = grub_malloc (size);
|
||||
- if (! buf)
|
||||
- return 0;
|
||||
-
|
||||
- while (size > 0)
|
||||
- {
|
||||
- grub_ssize_t ret;
|
||||
-
|
||||
- ret = grub_file_read (file, buf + offset, size);
|
||||
- if (ret <= 0)
|
||||
- {
|
||||
- grub_free (buf);
|
||||
- return 0;
|
||||
- }
|
||||
-
|
||||
- size -= ret;
|
||||
- offset += ret;
|
||||
- }
|
||||
-
|
||||
- envblk = grub_envblk_open (buf, offset);
|
||||
- if (! envblk)
|
||||
- {
|
||||
- grub_free (buf);
|
||||
- grub_error (GRUB_ERR_BAD_FILE_TYPE, "invalid environment block");
|
||||
- return 0;
|
||||
- }
|
||||
-
|
||||
- return envblk;
|
||||
-}
|
||||
-
|
||||
-struct grub_env_whitelist
|
||||
-{
|
||||
- grub_size_t len;
|
||||
- char **list;
|
||||
-};
|
||||
-typedef struct grub_env_whitelist grub_env_whitelist_t;
|
||||
-
|
||||
-static int
|
||||
-test_whitelist_membership (const char* name,
|
||||
- const grub_env_whitelist_t* whitelist)
|
||||
-{
|
||||
- grub_size_t i;
|
||||
-
|
||||
- for (i = 0; i < whitelist->len; i++)
|
||||
- if (grub_strcmp (name, whitelist->list[i]) == 0)
|
||||
- return 1; /* found it */
|
||||
-
|
||||
- return 0; /* not found */
|
||||
-}
|
||||
-
|
||||
-/* Helper for grub_cmd_load_env. */
|
||||
-static int
|
||||
-set_var (const char *name, const char *value, void *whitelist)
|
||||
-{
|
||||
- if (! whitelist)
|
||||
- {
|
||||
- grub_env_set (name, value);
|
||||
- return 0;
|
||||
- }
|
||||
-
|
||||
- if (test_whitelist_membership (name,
|
||||
- (const grub_env_whitelist_t *) whitelist))
|
||||
- grub_env_set (name, value);
|
||||
-
|
||||
- return 0;
|
||||
-}
|
||||
-
|
||||
static grub_err_t
|
||||
grub_cmd_load_env (grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
diff --git a/grub-core/commands/loadenv.h b/grub-core/commands/loadenv.h
|
||||
new file mode 100644
|
||||
index 0000000..952f461
|
||||
--- /dev/null
|
||||
+++ b/grub-core/commands/loadenv.h
|
||||
@@ -0,0 +1,93 @@
|
||||
+/* loadenv.c - command to load/save environment variable. */
|
||||
+/*
|
||||
+ * GRUB -- GRand Unified Bootloader
|
||||
+ * Copyright (C) 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 copy of the GNU General Public License
|
||||
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
+ */
|
||||
+
|
||||
+static grub_envblk_t UNUSED
|
||||
+read_envblk_file (grub_file_t file)
|
||||
+{
|
||||
+ grub_off_t offset = 0;
|
||||
+ char *buf;
|
||||
+ grub_size_t size = grub_file_size (file);
|
||||
+ grub_envblk_t envblk;
|
||||
+
|
||||
+ buf = grub_malloc (size);
|
||||
+ if (! buf)
|
||||
+ return 0;
|
||||
+
|
||||
+ while (size > 0)
|
||||
+ {
|
||||
+ grub_ssize_t ret;
|
||||
+
|
||||
+ ret = grub_file_read (file, buf + offset, size);
|
||||
+ if (ret <= 0)
|
||||
+ {
|
||||
+ grub_free (buf);
|
||||
+ return 0;
|
||||
+ }
|
||||
+
|
||||
+ size -= ret;
|
||||
+ offset += ret;
|
||||
+ }
|
||||
+
|
||||
+ envblk = grub_envblk_open (buf, offset);
|
||||
+ if (! envblk)
|
||||
+ {
|
||||
+ grub_free (buf);
|
||||
+ grub_error (GRUB_ERR_BAD_FILE_TYPE, "invalid environment block");
|
||||
+ return 0;
|
||||
+ }
|
||||
+
|
||||
+ return envblk;
|
||||
+}
|
||||
+
|
||||
+struct grub_env_whitelist
|
||||
+{
|
||||
+ grub_size_t len;
|
||||
+ char **list;
|
||||
+};
|
||||
+typedef struct grub_env_whitelist grub_env_whitelist_t;
|
||||
+
|
||||
+static int UNUSED
|
||||
+test_whitelist_membership (const char* name,
|
||||
+ const grub_env_whitelist_t* whitelist)
|
||||
+{
|
||||
+ grub_size_t i;
|
||||
+
|
||||
+ for (i = 0; i < whitelist->len; i++)
|
||||
+ if (grub_strcmp (name, whitelist->list[i]) == 0)
|
||||
+ return 1; /* found it */
|
||||
+
|
||||
+ return 0; /* not found */
|
||||
+}
|
||||
+
|
||||
+/* Helper for grub_cmd_load_env. */
|
||||
+static int UNUSED
|
||||
+set_var (const char *name, const char *value, void *whitelist)
|
||||
+{
|
||||
+ if (! whitelist)
|
||||
+ {
|
||||
+ grub_env_set (name, value);
|
||||
+ return 0;
|
||||
+ }
|
||||
+
|
||||
+ if (test_whitelist_membership (name,
|
||||
+ (const grub_env_whitelist_t *) whitelist))
|
||||
+ grub_env_set (name, value);
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
diff --git a/include/grub/compiler.h b/include/grub/compiler.h
|
||||
index c9e1d7a..9859ff4 100644
|
||||
--- a/include/grub/compiler.h
|
||||
+++ b/include/grub/compiler.h
|
||||
@@ -48,4 +48,6 @@
|
||||
# define WARN_UNUSED_RESULT
|
||||
#endif
|
||||
|
||||
+#define UNUSED __attribute__((__unused__))
|
||||
+
|
||||
#endif /* ! GRUB_COMPILER_HEADER */
|
||||
--
|
||||
2.9.3
|
||||
|
125
0002-Make-grub2-mkconfig-able-to-output-BLS-based-config-.patch
Normal file
125
0002-Make-grub2-mkconfig-able-to-output-BLS-based-config-.patch
Normal file
|
@ -0,0 +1,125 @@
|
|||
From 7d96844d560e9a4ce14f785abbb4b9d25ee49987 Mon Sep 17 00:00:00 2001
|
||||
From: Peter Jones <pjones@redhat.com>
|
||||
Date: Tue, 25 Oct 2016 13:26:38 -0400
|
||||
Subject: [PATCH 2/2] Make grub2-mkconfig able to output BLS based config file
|
||||
|
||||
Signed-off-by: Peter Jones <pjones@redhat.com>
|
||||
---
|
||||
util/grub-mkconfig.in | 3 ++-
|
||||
util/grub-mkconfig_lib.in | 24 +++++++++++++++---------
|
||||
util/grub.d/10_linux.in | 20 ++++++++++++++++++++
|
||||
3 files changed, 37 insertions(+), 10 deletions(-)
|
||||
|
||||
diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in
|
||||
index e32de5e..0e0475d 100644
|
||||
--- a/util/grub-mkconfig.in
|
||||
+++ b/util/grub-mkconfig.in
|
||||
@@ -239,7 +239,8 @@ export GRUB_DEFAULT \
|
||||
GRUB_BADRAM \
|
||||
GRUB_OS_PROBER_SKIP_LIST \
|
||||
GRUB_DISABLE_SUBMENU \
|
||||
- GRUB_DEFAULT_DTB
|
||||
+ GRUB_DEFAULT_DTB \
|
||||
+ GRUB_ENABLE_BLSCFG
|
||||
|
||||
if test "x${grub_cfg}" != "x"; then
|
||||
rm -f "${grub_cfg}.new"
|
||||
diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in
|
||||
index 9c410ea..54b3576 100644
|
||||
--- a/util/grub-mkconfig_lib.in
|
||||
+++ b/util/grub-mkconfig_lib.in
|
||||
@@ -123,10 +123,16 @@ EOF
|
||||
|
||||
prepare_grub_to_access_device ()
|
||||
{
|
||||
+ local device=$1 && shift
|
||||
+ if [ "$#" -gt 0 ]; then
|
||||
+ local variable=$1 && shift
|
||||
+ else
|
||||
+ local variable=root
|
||||
+ fi
|
||||
old_ifs="$IFS"
|
||||
IFS='
|
||||
'
|
||||
- partmap="`"${grub_probe}" --device $@ --target=partmap`"
|
||||
+ partmap="`"${grub_probe}" --device ${device} --target=partmap`"
|
||||
for module in ${partmap} ; do
|
||||
case "${module}" in
|
||||
netbsd | openbsd)
|
||||
@@ -137,34 +143,34 @@ prepare_grub_to_access_device ()
|
||||
done
|
||||
|
||||
# Abstraction modules aren't auto-loaded.
|
||||
- abstraction="`"${grub_probe}" --device $@ --target=abstraction`"
|
||||
+ abstraction="`"${grub_probe}" --device ${device} --target=abstraction`"
|
||||
for module in ${abstraction} ; do
|
||||
echo "insmod ${module}"
|
||||
done
|
||||
|
||||
- fs="`"${grub_probe}" --device $@ --target=fs`"
|
||||
+ fs="`"${grub_probe}" --device ${device} --target=fs`"
|
||||
for module in ${fs} ; do
|
||||
echo "insmod ${module}"
|
||||
done
|
||||
|
||||
if [ x$GRUB_ENABLE_CRYPTODISK = xy ]; then
|
||||
- for uuid in `"${grub_probe}" --device $@ --target=cryptodisk_uuid`; do
|
||||
+ for uuid in `"${grub_probe}" --device ${device} --target=cryptodisk_uuid`; do
|
||||
echo "cryptomount -u $uuid"
|
||||
done
|
||||
fi
|
||||
|
||||
# If there's a filesystem UUID that GRUB is capable of identifying, use it;
|
||||
# otherwise set root as per value in device.map.
|
||||
- fs_hint="`"${grub_probe}" --device $@ --target=compatibility_hint`"
|
||||
+ fs_hint="`"${grub_probe}" --device ${device} --target=compatibility_hint`"
|
||||
if [ "x$fs_hint" != x ]; then
|
||||
echo "set root='$fs_hint'"
|
||||
fi
|
||||
- if [ "x$GRUB_DISABLE_UUID" != "xtrue" ] && fs_uuid="`"${grub_probe}" --device $@ --target=fs_uuid 2> /dev/null`" ; then
|
||||
- hints="`"${grub_probe}" --device $@ --target=hints_string 2> /dev/null`" || hints=
|
||||
+ if [ "x$GRUB_DISABLE_UUID" != "xtrue" ] && fs_uuid="`"${grub_probe}" --device ${device} --target=fs_uuid 2> /dev/null`" ; then
|
||||
+ hints="`"${grub_probe}" --device ${device} --target=hints_string 2> /dev/null`" || hints=
|
||||
echo "if [ x\$feature_platform_search_hint = xy ]; then"
|
||||
- echo " search --no-floppy --fs-uuid --set=root ${hints} ${fs_uuid}"
|
||||
+ echo " search --no-floppy --fs-uuid --set=${variable} ${hints} ${fs_uuid}"
|
||||
echo "else"
|
||||
- echo " search --no-floppy --fs-uuid --set=root ${fs_uuid}"
|
||||
+ echo " search --no-floppy --fs-uuid --set=${variable} ${fs_uuid}"
|
||||
echo "fi"
|
||||
fi
|
||||
IFS="$old_ifs"
|
||||
diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in
|
||||
index 0c5b227..8d31b1d 100644
|
||||
--- a/util/grub.d/10_linux.in
|
||||
+++ b/util/grub.d/10_linux.in
|
||||
@@ -105,6 +105,26 @@ linux_entry ()
|
||||
if [ -z "$boot_device_id" ]; then
|
||||
boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
|
||||
fi
|
||||
+
|
||||
+ if [ "x${GRUB_ENABLE_BLSCFG}" = "xtrue" ]; then
|
||||
+ if [ x$dirname = x/ ]; then
|
||||
+ if [ -z "${prepare_root_cache}" ]; then
|
||||
+ prepare_grub_to_access_device ${GRUB_DEVICE}
|
||||
+ fi
|
||||
+ else
|
||||
+ if [ -z "${prepare_boot_cache}" ]; then
|
||||
+ prepare_grub_to_access_device ${GRUB_DEVICE_BOOT}
|
||||
+ fi
|
||||
+ fi
|
||||
+
|
||||
+ bootefi_device="`${grub_probe} --target=device /boot/efi/`"
|
||||
+ prepare_grub_to_access_device ${bootefi_device} boot
|
||||
+
|
||||
+ echo bls_import
|
||||
+
|
||||
+ exit 0
|
||||
+ fi
|
||||
+
|
||||
if [ x$type != xsimple ] ; then
|
||||
case $type in
|
||||
recovery)
|
||||
--
|
||||
2.9.3
|
||||
|
|
@ -89,3 +89,6 @@ Patch0087: 0087-Add-grub-get-kernel-settings-and-use-it-in-10_linux.patch
|
|||
Patch0088: 0088-Normalize-slashes-in-tftp-paths.patch
|
||||
Patch0089: 0089-efi-chainloader-fix-wrong-sanity-check-in-relocate_c.patch
|
||||
Patch0090: 0090-efi-chainloader-truncate-overlong-relocation-section.patch
|
||||
Patch0091: 0001-blscfg-make-the-bls_import-command-know-to-search-en.patch
|
||||
Patch0092: 0002-Make-grub2-mkconfig-able-to-output-BLS-based-config-.patch
|
||||
Patch0093: 0001-Make-blscfg-include-some-IDs-and-indices.patch
|
||||
|
|
11
grub2.spec
11
grub2.spec
|
@ -45,7 +45,7 @@
|
|||
Name: grub2
|
||||
Epoch: 1
|
||||
Version: 2.02
|
||||
Release: 0.38%{?dist}
|
||||
Release: 0.38%{?dist}.bls3
|
||||
Summary: Bootloader with support for Linux, Multiboot and more
|
||||
|
||||
Group: System Environment/Base
|
||||
|
@ -225,7 +225,7 @@ cd grub-efi-%{tarversion}
|
|||
--disable-werror
|
||||
make %{?_smp_mflags}
|
||||
|
||||
GRUB_MODULES=" all_video boot btrfs cat chain configfile echo \
|
||||
GRUB_MODULES=" all_video boot blscfg btrfs cat chain configfile echo \
|
||||
efifwsetup efinet ext2 fat font gfxmenu gfxterm gzio halt \
|
||||
hfsplus iso9660 jpeg loadenv loopback lvm mdraid09 mdraid1x \
|
||||
minicmd normal part_apple part_msdos part_gpt \
|
||||
|
@ -342,6 +342,9 @@ mkdir ${RPM_BUILD_ROOT}%{_sysconfdir}/sysconfig
|
|||
ln -sf %{_sysconfdir}/default/grub \
|
||||
${RPM_BUILD_ROOT}%{_sysconfdir}/sysconfig/grub
|
||||
|
||||
./grub-editenv ${RPM_BUILD_ROOT}/boot/efi/EFI/%{efidir}/grubenv create
|
||||
truncate -s 512 ${RPM_BUILD_ROOT}/boot/efi/EFI/%{efidir}/grubenv
|
||||
|
||||
cd ..
|
||||
%find_lang grub
|
||||
|
||||
|
@ -364,9 +367,10 @@ cat << EOF > ${RPM_BUILD_ROOT}%{_sysconfdir}/prelink.conf.d/grub2.conf
|
|||
-b /usr/sbin/grub2-sparc64-setup
|
||||
EOF
|
||||
|
||||
%ifarch %{efiarchs}
|
||||
mkdir -p boot/efi/EFI/%{efidir}/
|
||||
ln -s /boot/efi/EFI/%{efidir}/grubenv boot/grub2/grubenv
|
||||
%ifarch %{efiarchs}
|
||||
mkdir -p boot/efi/EFI/%{efidir}/loader/entries/
|
||||
%endif
|
||||
|
||||
# Don't run debuginfo on all the grub modules and whatnot; it just
|
||||
|
@ -467,6 +471,7 @@ fi
|
|||
%defattr(-,root,root,-)
|
||||
%config(noreplace) %{_sysconfdir}/%{name}-efi.cfg
|
||||
%attr(0755,root,root)/boot/efi/EFI/%{efidir}
|
||||
%attr(0755,root,root)/boot/efi/EFI/%{efidir}/loader/entries/
|
||||
%attr(0755,root,root)/boot/efi/EFI/%{efidir}/fonts
|
||||
%ghost %config(noreplace) /boot/efi/EFI/%{efidir}/grub.cfg
|
||||
%doc grub-%{tarversion}/COPYING
|
||||
|
|
Loading…
Reference in a new issue