grub-install: Check for arm-efi as a default target

Much like on x86, we can work out if the system is running on top of EFI
firmware. If so, return "arm-efi". If not, fall back to "arm-uboot" as
previously.

Split out the code to (maybe) load the efivar module and check for
/sys/firmware/efi into a common helper routine is_efi_system().

Signed-off-by: Steve McIntyre <93sam@debian.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
This commit is contained in:
Steve McIntyre 2019-02-21 14:46:11 +00:00 committed by Vincent Batts
parent efdfac9e2f
commit c28c107e24
4 changed files with 43 additions and 10 deletions

View file

@ -18,6 +18,12 @@
#include <grub/util/install.h> #include <grub/util/install.h>
const char *
grub_install_get_default_arm_platform (void)
{
return "arm-uboot";
}
const char * const char *
grub_install_get_default_x86_platform (void) grub_install_get_default_x86_platform (void)
{ {

View file

@ -97,15 +97,16 @@ read_platform_size (void)
return ret; return ret;
} }
const char * /* Are we running on an EFI-based system? */
grub_install_get_default_x86_platform (void) static int
is_efi_system (void)
{ {
/* /*
On Linux, we need the efivars kernel modules. * Linux uses efivarfs (mounted on /sys/firmware/efi/efivars) to access the
If no EFI is available this module just does nothing * EFI variable store. Some legacy systems may still use the deprecated
besides a small hello and if we detect efi we'll load it * efivars interface (accessed through /sys/firmware/efi/vars). Where both
anyway later. So it should be safe to * are present, libefivar will use the former in preference, so attempting
try to load it here. * to load efivars will not interfere with later operations.
*/ */
grub_util_exec_redirect_all ((const char * []){ "modprobe", "efivars", NULL }, grub_util_exec_redirect_all ((const char * []){ "modprobe", "efivars", NULL },
NULL, NULL, "/dev/null"); NULL, NULL, "/dev/null");
@ -114,13 +115,36 @@ grub_install_get_default_x86_platform (void)
if (is_not_empty_directory ("/sys/firmware/efi")) if (is_not_empty_directory ("/sys/firmware/efi"))
{ {
grub_util_info ("...found"); grub_util_info ("...found");
return 1;
}
else
{
grub_util_info ("... not found");
return 0;
}
}
const char *
grub_install_get_default_arm_platform (void)
{
if (is_efi_system())
return "arm-efi";
else
return "arm-uboot";
}
const char *
grub_install_get_default_x86_platform (void)
{
if (is_efi_system())
{
if (read_platform_size() == 64) if (read_platform_size() == 64)
return "x86_64-efi"; return "x86_64-efi";
else else
return "i386-efi"; return "i386-efi";
} }
grub_util_info ("... not found. Looking for /proc/device-tree .."); grub_util_info ("Looking for /proc/device-tree ..");
if (is_not_empty_directory ("/proc/device-tree")) if (is_not_empty_directory ("/proc/device-tree"))
{ {
grub_util_info ("...found"); grub_util_info ("...found");

View file

@ -210,6 +210,9 @@ grub_util_get_target_dirname (const struct grub_install_image_target_desc *t);
void void
grub_install_create_envblk_file (const char *name); grub_install_create_envblk_file (const char *name);
const char *
grub_install_get_default_arm_platform (void);
const char * const char *
grub_install_get_default_x86_platform (void); grub_install_get_default_x86_platform (void);

View file

@ -319,7 +319,7 @@ get_default_platform (void)
#elif defined (__ia64__) #elif defined (__ia64__)
return "ia64-efi"; return "ia64-efi";
#elif defined (__arm__) #elif defined (__arm__)
return "arm-uboot"; return grub_install_get_default_arm_platform ();
#elif defined (__aarch64__) #elif defined (__aarch64__)
return "arm64-efi"; return "arm64-efi";
#elif defined (__amd64__) || defined (__x86_64__) || defined (__i386__) #elif defined (__amd64__) || defined (__x86_64__) || defined (__i386__)