multiboot on EFI
PATCH 1/1 multiboot on EFI
Was successfully tested with qemu-tianocore with example multiboot kernel from multiboot specification. Since real EFI has no VGA video fields play a crucial feature and need to be supported. Patch is coming but it will surely rely on gfxsplit patch. I also have plans to extend it to x86-64 too
Signature · 4 lines
Regards Vladimir 'phcoder' Serbinenko Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
ChangeLog +19 -0
@@ -1,3 +1,22 @@ +2009-08-02 Vladimir Serbinenko <[email protected]> + + Multiboot support on i386-efi. + + * conf/i386-efi.rmk (pkglib_MODULES): Add multiboot.mod. + (multiboot_mod_SOURCES): New variable. + (multiboot_mod_CFLAGS): Likewise. + (multiboot_mod_LDFLAGS): Likewise. + (multiboot_mod_ASFLAGS): Likewise. + * include/grub/i386/multiboot.h (grub_multiboot_real_boot): Explicitly + declare as regparm (3). + (grub_multiboot2_real_boot): Likewise. + (grub_multiboot_boot): Finish boot services. + (grub_fill_multiboot_mmap): Explicitly parse memory map types. + (grub_multiboot): Declare as noreturn to avoid finishing console. + * loader/multiboot_loader.c (grub_cmd_multiboot_loader): Enable + multiboot1 on i386-efi and disable multiboot2 on this platform. + (grub_cmd_module_loader): Likewise. + 2009-08-01 Vladimir Serbinenko <[email protected]> * util/hostfs.c (grub_hostfs_dir): Don't use DT_DIR: It doesn't work
conf/i386-efi.rmk +9 -1
@@ -83,7 +83,15 @@ grub_install_SOURCES = util/i386/efi/grub-install.in pkglib_MODULES = kernel.mod chain.mod appleldr.mod \ linux.mod halt.mod reboot.mod pci.mod lspci.mod \ datetime.mod date.mod datehook.mod loadbios.mod \ - fixvideo.mod mmap.mod acpi.mod + fixvideo.mod mmap.mod acpi.mod multiboot.mod + +# For multiboot.mod. +multiboot_mod_SOURCES = loader/i386/multiboot.c \ + loader/i386/multiboot_helper.S \ + loader/multiboot_loader.c +multiboot_mod_CFLAGS = $(COMMON_CFLAGS) +multiboot_mod_LDFLAGS = $(COMMON_LDFLAGS) +multiboot_mod_ASFLAGS = $(COMMON_ASFLAGS) # For kernel.mod. kernel_mod_EXPORTS = no
include/grub/i386/multiboot.h +2 -2
@@ -22,10 +22,10 @@/* The asm part of the multiboot loader. */ void grub_multiboot_real_boot (grub_addr_t entry,struct grub_multiboot_info *mbi) - __attribute__ ((noreturn)); + __attribute__ ((noreturn,regparm (3 )));void grub_multiboot2_real_boot (grub_addr_t entry,struct grub_multiboot_info *mbi) - __attribute__ ((noreturn)); + __attribute__ ((noreturn,regparm (3 )));extern grub_addr_t grub_multiboot_payload_orig;extern grub_addr_t grub_multiboot_payload_dest;
loader/i386/multiboot.c +27 -3
@@ -30,8 +30,10 @@#include <grub/loader.h> #include <grub/machine/loader.h> #include <grub/multiboot.h> +#include <grub/machine/machine.h> #include <grub/machine/init.h> #include <grub/machine/memory.h> +#include <grub/memory.h> #include <grub/cpu/multiboot.h> #include <grub/elf.h> #include <grub/aout.h>
@@ -49,6 +51,13 @@#include <grub/partition.h> #endif +#include <grub/cpu/loader.h> +#include <grub/cpu/multiboot.h> + +#ifdef GRUB_MACHINE_EFI +#include <grub/efi/efi.h> +#endif +extern grub_dl_t my_mod;static struct grub_multiboot_info *mbi, *mbi_dest;static grub_addr_t entry;
@@ -59,6 +68,11 @@ static grub_size_t code_size;static grub_err_t grub_multiboot_boot (void ) { +#ifdef GRUB_MACHINE_EFI +if (!grub_efi_finish_boot_services ()) +grub_fatal ("cannot exit boot services" ); +#endif +grub_multiboot_real_boot (entry, mbi_dest);/* Not reached. */
@@ -114,14 +128,24 @@ grub_get_multiboot_mmap_len (void)static void grub_fill_multiboot_mmap (struct grub_multiboot_mmap_entry *first_entry) { -struct grub_multiboot_mmap_entry *mmap_entry = (struct grub_multiboot_mmap_entry *) first_entry; +struct grub_multiboot_mmap_entry *mmap_entry + = (struct grub_multiboot_mmap_entry *) first_entry; auto int NESTED_FUNC_ATTR hook (grub_uint64_t, grub_uint64_t, grub_uint32_t); int NESTED_FUNC_ATTR hook (grub_uint64_t addr, grub_uint64_t size, grub_uint32_t type) { mmap_entry->addr = addr; mmap_entry->len = size; - mmap_entry->type = type; +switch (type) + { +case GRUB_MACHINE_MEMORY_AVAILABLE : + mmap_entry->type =GRUB_MULTIBOOT_MEMORY_AVAILABLE ; +break ; + +default : + mmap_entry->type =GRUB_MULTIBOOT_MEMORY_RESERVED ; +break ; + } mmap_entry->size =sizeof (struct grub_multiboot_mmap_entry ) -sizeof (mmap_entry->size); mmap_entry++;
@@ -371,7 +395,7 @@ grub_multiboot (int argc, char *argv[])if (grub_multiboot_get_bootdev (&mbi->boot_device)) mbi->flags |=MULTIBOOT_INFO_BOOTDEV ; -grub_loader_set (grub_multiboot_boot, grub_multiboot_unload,1 ); +grub_loader_set (grub_multiboot_boot, grub_multiboot_unload,0 ); fail:if (file)
loader/multiboot_loader.c +6 -3
@@ -140,7 +140,7 @@ grub_cmd_multiboot_loader (grub_command_t cmd __attribute__ ((unused)),/* XXX Find a better way to identify this. This is for i386-pc */ #if defined(GRUB_MACHINE_PCBIOS ) || defined(GRUB_MACHINE_COREBOOT ) || \ - defined(GRUB_MACHINE_QEMU ) + defined(GRUB_MACHINE_QEMU ) || (defined(GRUB_MACHINE_EFI ) && !defined (__x86_64__))if (header_multi_ver_found ==1 ) { grub_dprintf ("multiboot_loader",
@@ -149,6 +149,7 @@ grub_cmd_multiboot_loader (grub_command_t cmd __attribute__ ((unused)), module_version_status =1 ; }#endif +#if !defined(GRUB_MACHINE_EFI )if (header_multi_ver_found ==0 || header_multi_ver_found ==2 ) { grub_dprintf ("multiboot_loader",
@@ -156,6 +157,7 @@ grub_cmd_multiboot_loader (grub_command_t cmd __attribute__ ((unused)),grub_multiboot2 (argc, argv); module_version_status = 2; } +#endif return grub_errno;
@@ -174,7 +176,7 @@ grub_cmd_module_loader (grub_command_t cmd __attribute__ ((unused)), {#if defined(GRUB_MACHINE_PCBIOS ) || defined(GRUB_MACHINE_COREBOOT ) || \ - defined(GRUB_MACHINE_QEMU ) + defined(GRUB_MACHINE_QEMU ) || (defined(GRUB_MACHINE_EFI ) && !defined (__x86_64__))if (module_version_status ==1 ) { grub_dprintf("multiboot_loader",
@@ -182,13 +184,14 @@ grub_cmd_module_loader (grub_command_t cmd __attribute__ ((unused)), grub_module (argc, argv); }#endif +#if !defined(GRUB_MACHINE_EFI )if (module_version_status ==2 ) {grub_dprintf ("multiboot_loader" ,"Launching multiboot 2 grub_module2() function\n" );grub_module2 (argc, argv); } - +#endif return grub_errno; }
Quoted 5 lines · Vladimir 'phcoder' Serbinenko
Was successfully tested with qemu-tianocore with example multiboot kernel from multiboot specification. Since real EFI has no VGA video fields play a crucial feature and need to be supported. Patch is coming but it will surely rely on gfxsplit patch. I also have plans to extend it to x86-64 too
Very nice.
loader/i386/multiboot.c static grub_size_t code_size; · line 74
Quoted 7 lines
static
grub_err_t
grub_multiboot_boot(void)
{loader/i386/multiboot.c +4
-0+#ifdef GRUB_MACHINE_EFI +if (!grub_efi_finish_boot_services ()) +grub_fatal ("cannot exit boot services" ); +#endif
grub_fatal() terminates GRUB. I suggest you just error out instead, so that user can try other things.
loader/i386/multiboot.c grub_get_multiboot_mmap_len (void) · line 147
Quoted 10 lines
loader/i386/multiboot.c +9
-1- mmap_entry->type = type; +switch (type) + { +case GRUB_MACHINE_MEMORY_AVAILABLE : + mmap_entry->type =GRUB_MULTIBOOT_MEMORY_AVAILABLE ; +break ; + +default : + mmap_entry->type =GRUB_MULTIBOOT_MEMORY_RESERVED ; +break ;
Is this going to be extended with more `case' stanzas later? If not, it'd be more readable with an if/else, or ?:.
loader/i386/multiboot.c grub_multiboot (int argc, char *argv[]) · line 398
Quoted 2 lines
loader/i386/multiboot.c +1
-1-grub_loader_set (grub_multiboot_boot, grub_multiboot_unload,1 ); +grub_loader_set (grub_multiboot_boot, grub_multiboot_unload,0 );
This breaks text-mode payloads when they're loaded from gfxterm.
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Quoted 8 lines · Robert Millan
Quoted 5 lines · Vladimir 'phcoder' Serbinenko
Was successfully tested with qemu-tianocore with example multiboot kernel from multiboot specification. Since real EFI has no VGA video fields play a crucial feature and need to be supported. Patch is coming but it will surely rely on gfxsplit patch. I also have plans to extend it to x86-64 too
Very nice.
Thanks. efiboot64 is available in my git but it requires allocator framework. (efi64-bit support in all bootloader is an authomatic advantage of using allocator framework)
Quoted 12 lines
loader/i386/multiboot.c static grub_size_t code_size; · line 74
Quoted 8 lines
static
grub_err_t
grub_multiboot_boot (void)
{loader/i386/multiboot.c +4
-0+#ifdef GRUB_MACHINE_EFI + if (! grub_efi_finish_boot_services ()) + grub_fatal ("cannot exit boot services"); +#endif
grub_fatal()terminates GRUB. I suggest you just error out instead, so that user can try other things.
It's how it's done in efi/linux.c and according to EFI spec it can't fail in this code. But I agree with you that both instances should be changed
Quoted 11 lines
Quoted 10 lines
- mmap_entry->type = type;
+ switch (type)
+ {
+ caseGRUB_MACHINE_MEMORY_AVAILABLE:
+mmap_entry->type=GRUB_MULTIBOOT_MEMORY_AVAILABLE;
+ break;
+
+ default:
+mmap_entry->type=GRUB_MULTIBOOT_MEMORY_RESERVED;
+ break;
Quoted 3 lines
Is this going to be extended with more `case' stanzas later? If not, it'd be more readable with an if/else, or ?:.
It will extend when we document ACPI memory types in multiboot specification.
Quoted 5 lines
Quoted 2 lines
- grub_loader_set (
grub_multiboot_boot,grub_multiboot_unload, 1);
+ grub_loader_set (grub_multiboot_boot,grub_multiboot_unload, 0);This breaks text-mode payloads when they're loaded from gfxterm.
Ok I will make it use the modesetting as linux.c does. text-mode only payloads are broken on EFI anyway since AFAIK no real EFI machine has VGA console available unless we find a way to load one without loading BIOS emulation. Bean may know more.
Quoted 13 lines
--
Robert MillanThe DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 4 lines
Regards Vladimir 'phcoder' Serbinenko Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
Quoted 11 lines · Vladimir 'phcoder' Serbinenko
Quoted 11 lines
loader/i386/multiboot.c static grub_size_t code_size; · line 74
Quoted 7 lines
static
grub_err_t
grub_multiboot_boot (void)
{loader/i386/multiboot.c +4
-0+#ifdef GRUB_MACHINE_EFI + if (! grub_efi_finish_boot_services ()) + grub_fatal ("cannot exit boot services"); +#endif
grub_fatal()terminates GRUB. I suggest you just error out instead, so that user can try other things.
Quoted 3 lines
It's how it's done in
efi/linux.cand according to EFI spec it can't fail in this code. But I agree with you that both instances should be changed
What does the spec say? If after grub_efi_finish_boot_services() exits with error EFI is inoperative, we wouldn't be able to print this message.
OTOH, sometimes specs are overzealous about what implementations can and can't do. If this requirement is gratuitous, we don't have to follow it.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
- grub_loader_set (
grub_multiboot_boot,grub_multiboot_unload, 1);
+ grub_loader_set (grub_multiboot_boot,grub_multiboot_unload, 0);This breaks text-mode payloads when they're loaded from gfxterm.
Ok I will make it use the modesetting as
linux.cdoes. text-mode only payloads are broken on EFI anyway
I was concerned with text-mode payloads on BIOS, coreboot, etc. When you pass 0, grub_machine_fini()/grub_console_fini() is not reached, so GRUB won't switch to text mode when loading them.
(Btw this API is so awkward because of the way it has evolved. I think it'd be a good idea to simply call grub_console_fini() from loaders when they have to)
Quoted 2 lines
since AFAIK no real EFI machine has
VGA console available
Does Tianocore/QEMU have VGA? I assume it is not forbidden to provide it in EFI systems, as it can be found in e.g. coreboot.
Quoted 2 lines
unless we find a way to load one without loading
BIOS emulation. Bean may know more.
VGA doesn't need BIOS calls. BIOS provides disk and keyboard, which the VGA ROM doesn't need, so the VGA ROM can be run standalone. This is already done by coreboot, and by GRUB in the i386-qemu port (it can be done by switching to real mode and call $0xc000, $0x3).
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."