Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: disk/efi/efidisk.c

Issue 2113004: Add variables to grub2 for Chrome OS bringup workarounds. (Closed) Base URL: ssh://git@chromiumos-git//grub2.git
Patch Set: respond to feedback Created 10 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * GRUB -- GRand Unified Bootloader 2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2006,2007,2008 Free Software Foundation, Inc. 3 * Copyright (C) 2006,2007,2008 Free Software Foundation, Inc.
4 * 4 *
5 * GRUB is free software: you can redistribute it and/or modify 5 * GRUB is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by 6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or 7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version. 8 * (at your option) any later version.
9 * 9 *
10 * GRUB is distributed in the hope that it will be useful, 10 * GRUB is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details. 13 * GNU General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU General Public License 15 * You should have received a copy of the GNU General Public License
16 * along with GRUB. If not, see <http://www.gnu.org/licenses/>. 16 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
17 */ 17 */
18 18
19 #include <grub/disk.h> 19 #include <grub/disk.h>
20 #include <grub/partition.h> 20 #include <grub/partition.h>
21 #include <grub/mm.h> 21 #include <grub/mm.h>
22 #include <grub/types.h> 22 #include <grub/types.h>
23 #include <grub/misc.h> 23 #include <grub/misc.h>
24 #include <grub/err.h> 24 #include <grub/err.h>
25 #include <grub/term.h> 25 #include <grub/term.h>
26 #include <grub/efi/api.h> 26 #include <grub/efi/api.h>
27 #include <grub/efi/efi.h> 27 #include <grub/efi/efi.h>
28 #include <grub/efi/disk.h> 28 #include <grub/efi/disk.h>
29 #include <grub/env.h>
29 30
30 struct grub_efidisk_data 31 struct grub_efidisk_data
31 { 32 {
32 grub_efi_handle_t handle; 33 grub_efi_handle_t handle;
33 grub_efi_device_path_t *device_path; 34 grub_efi_device_path_t *device_path;
34 grub_efi_device_path_t *last_device_path; 35 grub_efi_device_path_t *last_device_path;
35 grub_efi_block_io_t *block_io; 36 grub_efi_block_io_t *block_io;
36 grub_efi_disk_io_t *disk_io; 37 grub_efi_disk_io_t *disk_io;
37 struct grub_efidisk_data *next; 38 struct grub_efidisk_data *next;
38 }; 39 };
(...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 808
808 device_name = grub_malloc (grub_strlen (parent->name) + 1 809 device_name = grub_malloc (grub_strlen (parent->name) + 1
809 + grub_strlen (partition_name) + 1); 810 + grub_strlen (partition_name) + 1);
810 if (! device_name) 811 if (! device_name)
811 { 812 {
812 grub_free (partition_name); 813 grub_free (partition_name);
813 grub_disk_close (parent); 814 grub_disk_close (parent);
814 return 0; 815 return 0;
815 } 816 }
816 817
818 {
819 // This block is a temporary workaround used by Chrome OS. We set
820 // some variables that we can use in the grub.cfg file to ensure that
821 // we get the kernel and rootfs from the boot device, regardless of
822 // which device that is.
823 char *tmpbuf = grub_malloc (grub_strlen (parent->name) + 5);
824 if (! tmpbuf)
825 {
826 grub_free (device_name);
827 grub_free (partition_name);
828 grub_disk_close (parent);
829 return 0;
830 }
831
832 grub_sprintf (tmpbuf, "(%s,3)", parent->name);
833 grub_env_set ("grubpartA", tmpbuf);
834 grub_env_export ("grubpartA");
835 grub_sprintf (tmpbuf, "(%s,5)", parent->name);
836 grub_env_set ("grubpartB", tmpbuf);
837 grub_env_export ("grubpartB");
838 grub_free (tmpbuf);
839
840 // Translate hd0 to sda, hd1 to sdb, etc. parent->name is always
841 // either "fdN", "hdN", or "cdN". This trick won't work if N is > 9.
842 int index = parent->name[2] - '0';
843 // The Chrome OS BIOS doesn't enumerate the hard disk in recovery
844 // mode, so the first removable drive is hd0, not hd1. Linux always
845 // sees it though.
846 struct grub_efidisk_data *d = parent->data;
847 if (d->block_io->media->removable_media)
848 index++;
849
850 char devname[] = "sdXN";
851 devname[2] = 'a' + index;
852 devname[3] = '3';
853 grub_env_set ("linuxpartA", devname);
854 grub_env_export ("linuxpartA");
855 devname[3] = '5';
856 grub_env_set ("linuxpartB", devname);
857 grub_env_export ("linuxpartB");
858 }
859
817 grub_sprintf (device_name, "%s,%s", parent->name, partition_name); 860 grub_sprintf (device_name, "%s,%s", parent->name, partition_name);
818 grub_free (partition_name); 861 grub_free (partition_name);
819 grub_disk_close (parent); 862 grub_disk_close (parent);
820 return device_name; 863 return device_name;
821 } 864 }
822 else 865 else
823 { 866 {
824 /* This should be an entire disk. */ 867 /* This should be an entire disk. */
825 auto int find_disk (const char *name); 868 auto int find_disk (const char *name);
826 char *device_name = 0; 869 char *device_name = 0;
(...skipping 23 matching lines...) Expand all
850 return 0; 893 return 0;
851 894
852 } 895 }
853 896
854 grub_efidisk_iterate (find_disk); 897 grub_efidisk_iterate (find_disk);
855 return device_name; 898 return device_name;
856 } 899 }
857 900
858 return 0; 901 return 0;
859 } 902 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698