~ubuntu-branches/ubuntu/trusty/grub2/trusty

« back to all changes in this revision

Viewing changes to .pc/install_efi_fallback.patch/grub-core/osdep/linux/platform.c

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2014-01-16 15:18:04 UTC
  • mfrom: (17.6.38 experimental)
  • Revision ID: package-import@ubuntu.com-20140116151804-3foouk7fpqcq3sxx
Tags: 2.02~beta2-2
* Convert patch handling to git-dpm.
* Add bi-endian support to ELF parser (Tomohiro B Berry).
* Adjust restore_mkdevicemap.patch to mark get_kfreebsd_version as static,
  to appease "gcc -Werror=missing-prototypes".
* Cherry-pick from upstream:
  - Change grub-macbless' manual page section to 8.
* Install grub-glue-efi, grub-macbless, grub-render-label, and
  grub-syslinux2cfg.
* grub-shell: Pass -no-pad to xorriso when building floppy images.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  GRUB  --  GRand Unified Bootloader
 
3
 *  Copyright (C) 2013 Free Software Foundation, Inc.
 
4
 *
 
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
 
7
 *  the Free Software Foundation, either version 3 of the License, or
 
8
 *  (at your option) any later version.
 
9
 *
 
10
 *  GRUB is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
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/>.
 
17
 */
 
18
 
 
19
#include <config.h>
 
20
 
 
21
#include <grub/util/install.h>
 
22
#include <grub/emu/exec.h>
 
23
#include <grub/emu/misc.h>
 
24
#include <sys/types.h>
 
25
#include <dirent.h>
 
26
#include <string.h>
 
27
 
 
28
#include <sys/utsname.h>
 
29
 
 
30
static int
 
31
is_not_empty_directory (const char *dir)
 
32
{
 
33
  DIR *d;
 
34
  struct dirent *de;
 
35
 
 
36
  d = opendir (dir);
 
37
  if (!d)
 
38
    return 0;
 
39
  while ((de = readdir (d)))
 
40
    {
 
41
      if (strcmp (de->d_name, ".") == 0
 
42
          || strcmp (de->d_name, "..") == 0)
 
43
        continue;
 
44
      closedir (d);
 
45
      return 1;
 
46
    }
 
47
 
 
48
  closedir (d);
 
49
  return 0;
 
50
}
 
51
 
 
52
static int
 
53
is_64_kernel (void)
 
54
{
 
55
  struct utsname un;
 
56
 
 
57
  if (uname (&un) < 0)
 
58
    return 0;
 
59
 
 
60
  return strcmp (un.machine, "x86_64") == 0;
 
61
}
 
62
 
 
63
const char *
 
64
grub_install_get_default_x86_platform (void)
 
65
 
66
  /*
 
67
     On Linux, we need the efivars kernel modules.
 
68
     If no EFI is available this module just does nothing
 
69
     besides a small hello and if we detect efi we'll load it
 
70
     anyway later. So it should be safe to
 
71
     try to load it here.
 
72
   */
 
73
  grub_util_exec_redirect_all ((const char * []){ "modprobe", "efivars", NULL },
 
74
                               NULL, NULL, "/dev/null");
 
75
 
 
76
  grub_util_info ("Looking for /sys/firmware/efi ..");
 
77
  if (is_not_empty_directory ("/sys/firmware/efi"))
 
78
    {
 
79
      grub_util_info ("...found");
 
80
      if (is_64_kernel ())
 
81
        return "x86_64-efi";
 
82
      else
 
83
        return "i386-efi";
 
84
    }
 
85
 
 
86
  grub_util_info ("... not found. Looking for /proc/device-tree ..");
 
87
  if (is_not_empty_directory ("/proc/device-tree"))
 
88
    {
 
89
      grub_util_info ("...found");
 
90
      return "i386-ieee1275";
 
91
    }
 
92
 
 
93
  grub_util_info ("... not found");
 
94
  return "i386-pc";
 
95
}