blob: 62e6247e748f695a7872f431b6994bd44f67df4f [file] [log] [blame]
From 834b0793bae1e72d483dd2dccb74e2c81d35b0b1 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/2] 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
Change-Id: Ie865f3d5ab0ecd8e9138bfd5b576a8147a205757
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>
---
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 5d2400f66..760f482e7 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
{
@@ -882,6 +883,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.17.0