]> git.pld-linux.org Git - packages/grub2.git/commitdiff
add boot loader specification support
authorElan Ruusamäe <glen@delfi.ee>
Sat, 23 May 2015 20:11:34 +0000 (23:11 +0300)
committerElan Ruusamäe <glen@delfi.ee>
Sat, 23 May 2015 20:11:34 +0000 (23:11 +0300)
http://www.freedesktop.org/wiki/Specifications/BootLoaderSpec/

patch from fedora

blscfg.patch [new file with mode: 0644]
grub2.spec

diff --git a/blscfg.patch b/blscfg.patch
new file mode 100644 (file)
index 0000000..407e832
--- /dev/null
@@ -0,0 +1,251 @@
+From ddfb160353df14e9f88affe7498512a553146872 Mon Sep 17 00:00:00 2001
+From: Fedora Ninjas <grub2-owner@fedoraproject.org>
+Date: Tue, 22 Jan 2013 06:31:38 +0100
+Subject: [PATCH 101/152] blscfg: add blscfg module to parse Boot Loader
+ Specification snippets
+
+http://www.freedesktop.org/wiki/Specifications/BootLoaderSpec
+
+Works like this:
+
+ insmod blscfg
+ bls_import
+
+Done! You should now have menu items for your snippets in place.
+
+Signed-off-by: Peter Jones <grub2-owner@fedoraproject.org>
+---
+ grub-core/Makefile.core.def |   8 ++
+ grub-core/commands/blscfg.c | 201 ++++++++++++++++++++++++++++++++++++++++++++
+ 2 files changed, 209 insertions(+)
+ create mode 100644 grub-core/commands/blscfg.c
+
+diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
+index ec46506..7bf1c8a 100644
+--- a/grub-core/Makefile.core.def
++++ b/grub-core/Makefile.core.def
+@@ -747,6 +747,14 @@ module = {
+ };
+ module = {
++  name = blscfg;
++  common = commands/blscfg.c;
++  enable = i386_efi;
++  enable = x86_64_efi;
++  enable = i386_pc;
++};
++
++module = {
+   name = boot;
+   common = commands/boot.c;
+   i386_pc = lib/i386/pc/biosnum.c;
+diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c
+new file mode 100644
+index 0000000..4274aca
+--- /dev/null
++++ b/grub-core/commands/blscfg.c
+@@ -0,0 +1,201 @@
++/*-*- Mode: C; c-basic-offset: 2; indent-tabs-mode: t -*-*/
++
++/* bls.c - implementation of the boot loader spec */
++
++/*
++ *  GRUB  --  GRand Unified Bootloader
++ *
++ *  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/>.
++ */
++
++#include <grub/types.h>
++#include <grub/misc.h>
++#include <grub/mm.h>
++#include <grub/err.h>
++#include <grub/dl.h>
++#include <grub/extcmd.h>
++#include <grub/i18n.h>
++#include <grub/fs.h>
++#include <grub/env.h>
++#include <grub/file.h>
++#include <grub/normal.h>
++
++GRUB_MOD_LICENSE ("GPLv3+");
++
++#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)))
++{
++  grub_size_t n;
++  char *p;
++  grub_file_t f = NULL;
++  grub_off_t sz;
++  char *title = NULL, *options = NULL, *clinux = NULL, *initrd = NULL, *src = NULL;
++  const char *args[2] = { NULL, NULL };
++
++  if (filename[0] == '.')
++    return 0;
++
++  n = grub_strlen (filename);
++  if (n <= 5)
++    return 0;
++
++  if (grub_strcmp (filename + n - 5, ".conf") != 0)
++    return 0;
++
++  p = grub_xasprintf (GRUB_BLS_CONFIG_PATH "%s", filename);
++
++  f = grub_file_open (p);
++  if (!f)
++    goto finish;
++
++  sz = grub_file_size (f);
++  if (sz == GRUB_FILE_SIZE_UNKNOWN || sz > 1024*1024)
++    goto finish;
++
++  for (;;)
++    {
++      char *buf;
++
++      buf = grub_file_getline (f);
++      if (!buf)
++      break;
++
++      if (grub_strncmp (buf, "title ", 6) == 0)
++      {
++        grub_free (title);
++        title = grub_strdup (buf + 6);
++        if (!title)
++          goto finish;
++      }
++      else if (grub_strncmp (buf, "options ", 8) == 0)
++      {
++        grub_free (options);
++        options = grub_strdup (buf + 8);
++        if (!options)
++          goto finish;
++      }
++      else if (grub_strncmp (buf, "linux ", 6) == 0)
++      {
++        grub_free (clinux);
++        clinux = grub_strdup (buf + 6);
++        if (!clinux)
++          goto finish;
++      }
++      else if (grub_strncmp (buf, "initrd ", 7) == 0)
++      {
++        grub_free (initrd);
++        initrd = grub_strdup (buf + 7);
++        if (!initrd)
++          goto finish;
++      }
++
++      grub_free(buf);
++    }
++
++  if (!linux)
++    {
++      grub_printf ("Skipping file %s with no 'linux' key.", p);
++      goto finish;
++    }
++
++  args[0] = title ? title : filename;
++
++  src = grub_xasprintf ("load_video\n"
++                      "set gfx_payload=keep\n"
++                      "insmod gzio\n"
++                      GRUB_LINUX_CMD " %s%s%s%s\n"
++                      "%s%s%s%s",
++                      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);
++
++finish:
++  grub_free (p);
++  grub_free (title);
++  grub_free (options);
++  grub_free (clinux);
++  grub_free (initrd);
++  grub_free (src);
++
++  if (f)
++    grub_file_close (f);
++
++  return 0;
++}
++
++static grub_err_t
++grub_cmd_bls_import (grub_extcmd_context_t ctxt __attribute__ ((unused)),
++                   int argc __attribute__ ((unused)),
++                   char **args __attribute__ ((unused)))
++{
++  grub_fs_t fs;
++  grub_device_t dev;
++  static grub_err_t r;
++  const char *devid;
++
++  devid = grub_env_get ("root");
++  if (!devid)
++    return grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("variable `%s' isn't set"), "root");
++
++  dev = grub_device_open (devid);
++  if (!dev)
++    return grub_errno;
++
++  fs = grub_fs_probe (dev);
++  if (!fs)
++    {
++      r = grub_errno;
++      goto finish;
++    }
++
++  r = fs->dir (dev, GRUB_BLS_CONFIG_PATH, parse_entry, NULL);
++
++finish:
++  if (dev)
++    grub_device_close (dev);
++
++  return r;
++}
++
++static grub_extcmd_t cmd;
++
++GRUB_MOD_INIT(bls)
++{
++  cmd = grub_register_extcmd ("bls_import",
++                            grub_cmd_bls_import,
++                            0,
++                            NULL,
++                            N_("Import Boot Loader Specification snippets."),
++                            NULL);
++}
++
++GRUB_MOD_FINI(bls)
++{
++  grub_unregister_extcmd (cmd);
++}
+-- 
+1.9.3
+
index c8ce67d8eaef84dc938371c925cfdbf4fd6fdc6f..c6d333eef202d5269e81e4c8fb3a54c7efd951df 100644 (file)
@@ -80,6 +80,7 @@ Patch14:      grub2-xfs-Add-helper-for-inode-size.patch
 Patch15:       grub2-xfs-Convert-inode-numbers-to-cpu-endianity-immediate.patch
 Patch16:       grub2-xfs-Fix-termination-loop-for-directory-iteration.patch
 Patch17:       grub2-xfs-V5-filesystem-format-support.patch
+Patch18:       blscfg.patch
 URL:           http://www.gnu.org/software/grub/
 BuildRequires: autoconf >= 2.53
 BuildRequires: automake >= 1:1.11.1-1
@@ -311,6 +312,7 @@ Motyw starfield dla GRUB-a.
 %patch15 -p1
 %patch16 -p1
 %patch17 -p1
+%patch18 -p1
 
 # we don't have C.utf-8 and need an UTF-8 locale for build
 sed -i -e 's/LC_ALL=C.UTF-8/LC_ALL=en_US.utf-8/g' po/Makefile* po/Rules*
This page took 0.103005 seconds and 4 git commands to generate.