grub-install: Use arm-efi target EFI-mode QEMU virt machines
cover grub-install: Use arm-efi target EFI-mode QEMU virt machines
Now that Leif has fixed up the arm-uefi target, I'm looking at adding that support into Debian/Ubuntu for virtual machines. One issue is that 'grub-install' errors out by default when only the arm-efi flavor is installed:
$ sudo grub-install grub-install: error: /usr/lib/grub/arm-uboot/modinfo.sh doesn't exist. Please specify --target or --directory
This series avoids that by whitelisting EFI-based linux/virt platforms.
dann frazier (2):
Factor out EFI detection into its own function
arm: grub-install: Default to arm-efi target in EFI-based QEMU virt
models
grub-core/osdep/basic/platform.c | 6 ++++ grub-core/osdep/linux/platform.c | 57 +++++++++++++++++++++++++++--- grub-core/osdep/windows/platform.c | 16 +++++++-- include/grub/util/install.h | 3 ++ util/grub-install.c | 2 +- 5 files changed, 77 insertions(+), 7 deletions(-)
Signature · 1 line
2.18.0
RFC PATCH 1/2 Factor out EFI detection into its own function
From: dann frazier <[email protected]>
No functional change. This will let us re-use the code for ARM.
--- grub-core/osdep/linux/platform.c | 20 ++++++++++++++++---- grub-core/osdep/windows/platform.c | 10 ++++++++-- 2 files changed, 24 insertions(+), 6 deletions(-)
grub-core/osdep/linux/platform.c +16 -4
@@ -97,9 +97,9 @@ read_platform_size (void)return ret; } -const char * -grub_install_get_default_x86_platform (void ) -{ +static int +is_efi (void ) +{/* On Linux, we need the efivars kernel modules. If no EFI is available this module just does nothing
@@ -114,13 +114,25 @@ grub_install_get_default_x86_platform (void)if (is_not_empty_directory ("/sys/firmware/efi" )) {grub_util_info ("...found" ); +return 1 ; + } + +grub_util_info ("... not found." ); +return 0 ; +} + +const char * +grub_install_get_default_x86_platform (void ) +{ +if (is_efi ()) + {if (read_platform_size () ==64 )return "x86_64-efi" ;else 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" )) {grub_util_info ("...found" );
grub-core/osdep/windows/platform.c +8 -2
@@ -109,13 +109,19 @@ get_platform (void)return ; } +static int +is_efi (void ) +{ +get_platform (); +return platform ==PLAT_EFI ; +} +const char *grub_install_get_default_x86_platform (void ) {SYSTEM_INFO si; -get_platform (); -if (platform !=PLAT_EFI ) +if (!is_efi ())return "i386-pc" ;/* EFI */
Signature · 1 line
2.18.0
RFC PATCH 2/2 arm: grub-install: Default to arm-efi target in EFI-based QEMU virt models
In reply to dann frazierFrom: dann frazier <[email protected]>
We currently default to the arm-uboot target in grub-install, but arm-efi should be used for some systems with UEFI firmware, such as Tianocore/EDK2-based QEMU models. We could change the default to arm-efi anytime we successfully probe for an EFI runtime. However, that would apparently do the wrong thing on U-Boot implementations that implement the UEFI spec, such as those compliant with the upcoming Embedded Base Boot Requirements specification, as they are not required to support SetVariable() in runtime services.
For now, whitelist QEMU linux/virt models with runtime EFI support, but otherwise continue to default to the arm-uboot target.
--- grub-core/osdep/basic/platform.c | 6 +++++ grub-core/osdep/linux/platform.c | 37 ++++++++++++++++++++++++++++++ grub-core/osdep/windows/platform.c | 6 +++++ include/grub/util/install.h | 3 +++ util/grub-install.c | 2 +- 5 files changed, 53 insertions(+), 1 deletion(-)
grub-core/osdep/basic/platform.c +6 -0
@@ -18,6 +18,12 @@#include <grub/util/install.h> +const char * +grub_install_get_default_arm_platform (void ) +{ +return "arm-uboot" ; +} +const char *grub_install_get_default_x86_platform (void ) {
grub-core/osdep/linux/platform.c +37 -0
@@ -121,6 +121,43 @@ is_efi (void)return 0 ; } +static int +is_virt (void ) +{ +FILE *fp; +char *buf =NULL ; +int ret =0 ; +size_t len =0 ; +const char qemu_virt[] ="linux,dummy-virt" ; + + fp =grub_util_fopen ("/sys/firmware/devicetree/base/compatible" ,"r" ); +if (fp ==NULL ) +return 0 ; + +if (getline (&buf, &len, fp) ==-1 ) + { +fclose (fp); +return 0 ; + } + +if (strncmp (buf, qemu_virt, len) ==0 ) + ret =1 ; + +free (buf); +fclose (fp); + +return ret; +} + +const char * +grub_install_get_default_arm_platform (void ) +{ +if (is_efi () &&is_virt ()) +return "arm-efi" ; + +return "arm-uboot" ; +} +const char *grub_install_get_default_x86_platform (void ) {
grub-core/osdep/windows/platform.c +6 -0
@@ -116,6 +116,12 @@ is_efi (void)return platform ==PLAT_EFI ; } +const char * +grub_install_get_default_arm_platform (void ) +{ +return "arm-uboot" ; +} +const char *grub_install_get_default_x86_platform (void ) {
include/grub/util/install.h +3 -0
@@ -207,6 +207,9 @@ grub_util_get_target_dirname (const struct grub_install_image_target_desc *t);void grub_install_create_envblk_file (const char *name); +const char * +grub_install_get_default_arm_platform (void ); +const char *grub_install_get_default_x86_platform (void );
util/grub-install.c +1 -1
@@ -319,7 +319,7 @@ get_default_platform (void)#elif defined (__ia64__)return "ia64-efi" ;#elif defined (__arm__) -return "arm-uboot" ; +return grub_install_get_default_arm_platform ();#elif defined (__aarch64__)return "arm64-efi" ;#elif defined (__amd64__) || defined (__x86_64__) || defined (__i386__)
Signature · 1 line
2.18.0
Re: [RFC][PATCH 2/2] arm: grub-install: Default to arm-efi target in EFI-based QEMU virt models
Quoted 46 lines · dann frazier
From: dann frazier <[email protected]>
We currently default to the arm-uboot target in grub-install, but arm-efi should be used for some systems with UEFI firmware, such as Tianocore/EDK2-based QEMU models. We could change the default to arm-efi anytime we successfully probe for an EFI runtime. However, that would apparently do the wrong thing on U-Boot implementations that implement the UEFI spec, such as those compliant with the upcoming Embedded Base Boot Requirements specification, as they are not required to support
SetVariable()in runtime services.For now, whitelist QEMU linux/virt models with runtime EFI support, but otherwise continue to default to the arm-uboot target.
Signed-off-by dann frazier <[email protected]>--- grub-core/osdep/basic/platform.c | 6 +++++ grub-core/osdep/linux/platform.c | 37 ++++++++++++++++++++++++++++++ grub-core/osdep/windows/platform.c | 6 +++++ include/grub/util/install.h | 3 +++ util/grub-install.c | 2 +- 5 files changed, 53 insertions(+), 1 deletion(-)grub-core/osdep/basic/platform.c +6
-0@@ -18,6 +18,12 @@#include <grub/util/install.h> +const char * +grub_install_get_default_arm_platform (void ) +{ +return "arm-uboot" ; +} +const char *grub_install_get_default_x86_platform (void ) {grub-core/osdep/linux/platform.c +0
-0@@ -121,6 +121,43 @@ is_efi (void)return 0 ;
grub-core/osdep/linux/platform.c is_efi (void) · line 131
Quoted 10 lines
grub-core/osdep/linux/platform.c +8
-0} +static int +is_virt (void ) +{ +FILE *fp; +char *buf =NULL ; +int ret =0 ; +size_t len =0 ; +const char qemu_virt[] ="linux,dummy-virt" ;
Do we really need qemu_virt variable? It is used only in one place.
Daniel
Re: [RFC][PATCH 2/2] arm: grub-install: Default to arm-efi target in EFI-based QEMU virt models
In reply to dann frazierQuoted 11 lines · dann frazier
From: dann frazier <[email protected]>
We currently default to the arm-uboot target in grub-install, but arm-efi should be used for some systems with UEFI firmware, such as Tianocore/EDK2-based QEMU models. We could change the default to arm-efi anytime we successfully probe for an EFI runtime. However, that would apparently do the wrong thing on U-Boot implementations that implement the UEFI spec, such as those compliant with the upcoming Embedded Base Boot Requirements specification, as they are not required to support
SetVariable()in runtime services.
Quoted 2 lines
For now, whitelist QEMU linux/virt models with runtime EFI support, but otherwise continue to default to the arm-uboot target.
I don't think this is correct. (And I'm probably the one who gave you the wrong impression - sorry!)
A U-Boot that implements (even part of) the UEFI specification SHOULD[1] use uboot-efi. It may well be that some things will not work as expected on these platforms, but EBBR will define how to detect the missing functionality and operating systems will need to work around it according to defined behaviour.
[1] rfc2119 definition.
I expect simply flipping the default to arm-efi _will_ make sense at some point after EBBR-compliant U-Boot becomes more widespread.
/
Leif
Quoted 121 lines
Signed-off-by dann frazier <[email protected]>--- grub-core/osdep/basic/platform.c | 6 +++++ grub-core/osdep/linux/platform.c | 37 ++++++++++++++++++++++++++++++ grub-core/osdep/windows/platform.c | 6 +++++ include/grub/util/install.h | 3 +++ util/grub-install.c | 2 +- 5 files changed, 53 insertions(+), 1 deletion(-)grub-core/osdep/basic/platform.c +6
-0@@ -18,6 +18,12 @@#include <grub/util/install.h> +const char * +grub_install_get_default_arm_platform (void ) +{ +return "arm-uboot" ; +} +const char *grub_install_get_default_x86_platform (void ) {grub-core/osdep/linux/platform.c +37
-0@@ -121,6 +121,43 @@ is_efi (void)return 0 ; } +static int +is_virt (void ) +{ +FILE *fp; +char *buf =NULL ; +int ret =0 ; +size_t len =0 ; +const char qemu_virt[] ="linux,dummy-virt" ; + + fp =grub_util_fopen ("/sys/firmware/devicetree/base/compatible" ,"r" ); +if (fp ==NULL ) +return 0 ; + +if (getline (&buf, &len, fp) ==-1 ) + { +fclose (fp); +return 0 ; + } + +if (strncmp (buf, qemu_virt, len) ==0 ) + ret =1 ; + +free (buf); +fclose (fp); + +return ret; +} + +const char * +grub_install_get_default_arm_platform (void ) +{ +if (is_efi () &&is_virt ()) +return "arm-efi" ; + +return "arm-uboot" ; +} +const char *grub_install_get_default_x86_platform (void ) {grub-core/osdep/windows/platform.c +6
-0@@ -116,6 +116,12 @@ is_efi (void)return platform ==PLAT_EFI ; } +const char * +grub_install_get_default_arm_platform (void ) +{ +return "arm-uboot" ; +} +const char *grub_install_get_default_x86_platform (void ) {include/grub/util/install.h +3
-0@@ -207,6 +207,9 @@ grub_util_get_target_dirname (const struct grub_install_image_target_desc *t);void grub_install_create_envblk_file (const char *name); +const char * +grub_install_get_default_arm_platform (void ); +const char *grub_install_get_default_x86_platform (void );util/grub-install.c +1
-1@@ -319,7 +319,7 @@ get_default_platform (void)#elif defined (__ia64__)return "ia64-efi" ;#elif defined (__arm__) -return "arm-uboot" ; +return grub_install_get_default_arm_platform ();#elif defined (__aarch64__)return "arm64-efi" ;#elif defined (__amd64__) || defined (__x86_64__) || defined (__i386__)Signature · 1 line
2.18.0
Quoted 9 lines · dann frazier
Now that Leif has fixed up the arm-uefi target, I'm looking at adding that support into Debian/Ubuntu for virtual machines. One issue is that 'grub-install' errors out by default when only the arm-efi flavor is installed:
$ sudo grub-install grub-install: error: /usr/lib/grub/arm-uboot/modinfo.sh doesn't exist. Please specify --target or --directoryThis series avoids that by whitelisting EFI-based linux/virt platforms.
In general LGTM except one nit pick. I will describe it in separate email.
Anyway, I am not ARM expert, so, I will push the patches if Leif is OK with them. Or at least dose not object.
Leif?
Daniel