blob: 9dd38f3ed87cf3ef814a737410b99ee6bbdd04a8 [file] [log] [blame]
From 1cb5fbe57f9b4c6eb05e9b87ca120cb0a647c466 Mon Sep 17 00:00:00 2001
From: Josh Triplett <josh@joshtriplett.org>
Date: Wed, 31 Jul 2013 13:54:36 -0700
Subject: [PATCH 1/7] grub-lakitu: CHROMIUM: Forward-port ChromeOS-specific
GRUB environment variables for boot disk and partitions
This commit forward-ports the following changes previously applied in the
ChromeOS version of GRUB, with updates for changes to the surrounding code and
GRUB API changes:
144e40aca61589db1d286c82508f9328ec861158 Add variables to grub2 for Chrome OS bringup workarounds.
as modified by e63c2ee074c3c0abb5717fc8b7df62cf32066782 Support standard EFI ordering
and 5dfc8e1ae8c7d6836f2faef2545e4c5e6d516dff Add variable 'grubdisk' to export boot disk
In particular, grub2 now has a grub_snprintf, and no longer has a grub_sprintf.
BUG=chromium:265918
TEST=With the complete patch series, built a complete x86-generic image,
and booted it via UEFI on both 32-bit and 64-bit UEFI platforms.
CQ-DEPEND=I8d4cdde878efe73e15fddb250b10cfd4b88d88d1
Reviewed-on: https://gerrit.chromium.org/gerrit/63985
Tested-by: Josh Triplett <josh@joshtriplett.org>
Reviewed-by: Liam McLoughlin <lmcloughlin@chromium.org>
Commit-Queue: Josh Triplett <josh@joshtriplett.org>
(cherry picked from commit 0b2d29898512e97045bec6103efd283762b8a241)
(from https://chromium.googlesource.com/chromiumos/third_party/grub2)
BUG=b:69569602
TEST=TBD
Change-Id: I9793e93409f6405b0df779c9937988c6213962bc
Reviewed-on: https://chromium-review.googlesource.com/945882
Reviewed-by: Edward Jee <edjee@google.com>
Commit-Queue: Edward Jee <edjee@google.com>
Tested-by: Edward Jee <edjee@google.com>
Trybot-Ready: Edward Jee <edjee@google.com>
---
grub-core/disk/efi/efidisk.c | 41 ++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
diff --git a/grub-core/disk/efi/efidisk.c b/grub-core/disk/efi/efidisk.c
index 54c227b1c..1ad84192f 100644
--- a/grub-core/disk/efi/efidisk.c
+++ b/grub-core/disk/efi/efidisk.c
@@ -26,6 +26,7 @@
#include <grub/efi/api.h>
#include <grub/efi/efi.h>
#include <grub/efi/disk.h>
+#include <grub/env.h>
struct grub_efidisk_data
{
@@ -892,6 +893,46 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle)
ctx.partition_name);
grub_free (ctx.partition_name);
}
+
+ {
+ // This block is a temporary workaround used by Chrome OS. We set
+ // some variables that we can use in the grub.cfg file to ensure that
+ // we get the kernel and rootfs from the boot device, regardless of
+ // which device that is.
+ grub_size_t tmpbuf_len = grub_strlen (parent->name) + 5;
+ char *tmpbuf = grub_malloc (tmpbuf_len);
+ if (! tmpbuf)
+ {
+ grub_free (dev_name);
+ grub_disk_close (parent);
+ return 0;
+ }
+
+ grub_snprintf (tmpbuf, tmpbuf_len, "(%s,3)", parent->name);
+ grub_env_set ("grubpartA", tmpbuf);
+ grub_env_export ("grubpartA");
+ grub_snprintf (tmpbuf, tmpbuf_len, "(%s,5)", parent->name);
+ grub_env_set ("grubpartB", tmpbuf);
+ grub_env_export ("grubpartB");
+ grub_free (tmpbuf);
+
+ grub_env_set ("grubdisk", parent->name);
+ grub_env_export ("grubdisk");
+
+ // Translate hd0 to sda, hd1 to sdb, etc. parent->name is always
+ // either "fdN", "hdN", or "cdN". This trick won't work if N is > 9.
+ int index = parent->name[2] - '0';
+
+ char devname[] = "sdXN";
+ devname[2] = 'a' + index;
+ devname[3] = '3';
+ grub_env_set ("linuxpartA", devname);
+ grub_env_export ("linuxpartA");
+ devname[3] = '5';
+ grub_env_set ("linuxpartB", devname);
+ grub_env_export ("linuxpartB");
+ }
+
grub_disk_close (parent);
return dev_name;
--
2.30.0.478.g8a0d178c01-goog