Skip to contentSkip to conversation

Allow running with non-terminated boot services in multiboot2

RFC PATCH In review Vladimir 'φ-coder/phcoder' Serbinenko 3 participants 6 messages Dec 7, 2013 – Dec 9, 2013

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 Allow running with non-terminated boot services in multiboot2

Patch to spec and GRUB attached.
@ xen: don't forget to put wlan card to sleep when you finish boot services

doc/multiboot.texi +27 -0
index a8f45e3..d251a51 100644
@@ -602,6 +602,21 @@ u32     | size = 8          |
 
 If this tag is present modules must be page aligned.
 
+@node EFI boot services
+@subsection EFI boot services
+
+@example
+@group
+        +-------------------+
+u16     | type = 7          |
+u16     | flags             |
+u32     | size = 8          |
+        +-------------------+
+@end group
+@end example
+
+This tag indicates that payload supports starting without
+terminating boot services
 
 @node Machine state
 @section MIPS machine state
@@ -1143,6 +1158,18 @@ u32     | descriptor version|
 This tag contains EFI memory map as per EFI specification.
 
 
+@subsection EFI boot services not terminated
+@example
+@group
+        +-------------------+
+u32     | type = 18         |
+u32     | size = 8          |
+        +-------------------+
+@end group
+@end example
+
+This tag indicates FinishBootServices wasn't called
+
 @node Examples
 @chapter Examples
 
doc/multiboot2.h +2 -0
index 58f2f68..272eeca 100644
@@ -59,6 +59,7 @@
 #define MULTIBOOT_TAG_TYPE_ACPI_NEW          15
 #define MULTIBOOT_TAG_TYPE_NETWORK           16
 #define MULTIBOOT_TAG_TYPE_EFI_MMAP          17
+#define MULTIBOOT_TAG_TYPE_EFI_BS            18
 
 #define MULTIBOOT_HEADER_TAG_END  0
 #define MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST  1
@@ -67,6 +68,7 @@
 #define MULTIBOOT_HEADER_TAG_CONSOLE_FLAGS  4
 #define MULTIBOOT_HEADER_TAG_FRAMEBUFFER  5
 #define MULTIBOOT_HEADER_TAG_MODULE_ALIGN  6
+#define MULTIBOOT_HEADER_TAG_EFI_BS        7
 
 #define MULTIBOOT_ARCHITECTURE_I386  0
 #define MULTIBOOT_ARCHITECTURE_MIPS32  4
grub-core/loader/multiboot.c +1 -1
index 54e4d24..4b71f33 100644
@@ -344,7 +344,7 @@ grub_cmd_module (grub_command_t cmd __attribute__ ((unused)),
     err = grub_relocator_alloc_chunk_align (grub_multiboot_relocator, &ch,
 					    lowest_addr, (0xffffffff - size) + 1,
 					    size, MULTIBOOT_MOD_ALIGN,
-					    GRUB_RELOCATOR_PREFERENCE_NONE, 0);
+					    GRUB_RELOCATOR_PREFERENCE_NONE, 1);
     if (err)
       {
 	grub_file_close (file);
grub-core/loader/multiboot_mbi2.c +29 -3
index 951988f..2f5aa62 100644
@@ -67,6 +67,7 @@ static grub_uint32_t biosdev, slice, part;
 static grub_size_t elf_sec_num, elf_sec_entsize;
 static unsigned elf_sec_shstrndx;
 static void *elf_sections;
+static int keep_bs = 0;
 
 void
 grub_multiboot_add_elfsyms (grub_size_t num, grub_size_t entsize,
@@ -127,6 +128,8 @@ grub_multiboot_load (grub_file_t file, const char *filename)
 
   COMPILE_TIME_ASSERT (MULTIBOOT_TAG_ALIGN % 4 == 0);
 
+  keep_bs = 0;
+
   for (tag = (struct multiboot_header_tag *) (header + 1);
        tag->type != MULTIBOOT_TAG_TYPE_END;
        tag = (struct multiboot_header_tag *) ((grub_uint32_t *) tag + ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN) / 4))
@@ -160,6 +163,7 @@ grub_multiboot_load (grub_file_t file, const char *filename)
 	      case MULTIBOOT_TAG_TYPE_ACPI_NEW:
 	      case MULTIBOOT_TAG_TYPE_NETWORK:
 	      case MULTIBOOT_TAG_TYPE_EFI_MMAP:
+	      case MULTIBOOT_TAG_TYPE_EFI_BS:
 		break;
 
 	      default:
@@ -198,6 +202,10 @@ grub_multiboot_load (grub_file_t file, const char *filename)
       case MULTIBOOT_HEADER_TAG_MODULE_ALIGN:
 	break;
 
+      case MULTIBOOT_HEADER_TAG_EFI_BS:
+	keep_bs = 1;
+	break;
+
       default:
 	if (! (tag->flags & MULTIBOOT_HEADER_TAG_OPTIONAL))
 	  {
@@ -362,6 +370,7 @@ grub_multiboot_get_mbi_size (void)
     find_efi_mmap_size ();    
 #endif
   return 2 * sizeof (grub_uint32_t) + sizeof (struct multiboot_tag)
+    + sizeof (struct multiboot_tag)
     + (sizeof (struct multiboot_tag_string)
        + ALIGN_UP (cmdline_size, MULTIBOOT_TAG_ALIGN))
     + (sizeof (struct multiboot_tag_string)
@@ -637,7 +646,7 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
   err = grub_relocator_alloc_chunk_align (grub_multiboot_relocator, &ch,
 					  0, 0xffffffff - bufsize,
 					  bufsize, MULTIBOOT_TAG_ALIGN,
-					  GRUB_RELOCATOR_PREFERENCE_NONE, 0);
+					  GRUB_RELOCATOR_PREFERENCE_NONE, 1);
   if (err)
     return err;
 
@@ -853,8 +862,16 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
     tag->type = MULTIBOOT_TAG_TYPE_EFI_MMAP;
     tag->size = sizeof (*tag) + efi_mmap_size;
 
-    err = grub_efi_finish_boot_services (&efi_mmap_size, tag->efi_mmap, NULL,
-					 &efi_desc_size, &efi_desc_version);
+    if (!keep_bs)
+      err = grub_efi_finish_boot_services (&efi_mmap_size, tag->efi_mmap, NULL,
+					   &efi_desc_size, &efi_desc_version);
+    else
+      {
+	if (grub_efi_get_memory_map (&efi_mmap_size, (void *) tag->efi_mmap,
+				     NULL,
+				     &efi_desc_size, &efi_desc_version) <= 0)
+	  err = grub_error (GRUB_ERR_IO, "couldn't retrieve memory map");
+      }
     if (err)
       return err;
     tag->descr_size = efi_desc_size;
@@ -864,6 +881,15 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
     ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
       / sizeof (grub_properly_aligned_t);
   }
+
+  if (keep_bs)
+    {
+      struct multiboot_tag *tag = (struct multiboot_tag *) ptrorig;
+      tag->type = MULTIBOOT_TAG_TYPE_EFI_BS;
+      tag->size = sizeof (struct multiboot_tag);
+      ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN)
+	/ sizeof (grub_properly_aligned_t);
+    }
 #endif
 
   {
include/multiboot2.h +2 -0
index 58f2f68..2e33cbf 100644
@@ -59,6 +59,7 @@
 #define MULTIBOOT_TAG_TYPE_ACPI_NEW          15
 #define MULTIBOOT_TAG_TYPE_NETWORK           16
 #define MULTIBOOT_TAG_TYPE_EFI_MMAP          17
+#define MULTIBOOT_TAG_TYPE_EFI_BS            18
 
 #define MULTIBOOT_HEADER_TAG_END  0
 #define MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST  1
@@ -67,6 +68,7 @@
 #define MULTIBOOT_HEADER_TAG_CONSOLE_FLAGS  4
 #define MULTIBOOT_HEADER_TAG_FRAMEBUFFER  5
 #define MULTIBOOT_HEADER_TAG_MODULE_ALIGN  6
+#define MULTIBOOT_HEADER_TAG_EFI_BS  7
 
 #define MULTIBOOT_ARCHITECTURE_I386  0
 #define MULTIBOOT_ARCHITECTURE_MIPS32  4
#1 lore raw
Quoted 2 lines · Vladimir '??-coder/phcoder' Serbinenko

Patch to spec and GRUB attached.
@ xen: don't forget to put wlan card to sleep when you finish boot services

Thank you for your work. At first sight it looks quite nice but I am not able to do tests right now. I am going to continue my work on GRUB2/EFI stuff for Xen at the beginning of next year.

Daniel

#2 lore raw
Quoted 8 lines · Daniel Kiper
Quoted 2 lines · Vladimir '??-coder/phcoder' Serbinenko

Patch to spec and GRUB attached.
@ xen: don't forget to put wlan card to sleep when you finish boot services

Thank you for your work. At first sight it looks quite nice but I am not able to do tests right now. I am going to continue my work on GRUB2/EFI stuff for Xen at the beginning of next year.

Can you confirm that that's what you want? I'd like it to make into 2.02 release but it would be useless if it's not what you want.

Quoted 2 lines

Daniel

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#3 lore raw
In reply to Daniel Kiper
Quoted 8 lines · Daniel Kiper
Quoted 2 lines · Vladimir '??-coder/phcoder' Serbinenko

Patch to spec and GRUB attached.
@ xen: don't forget to put wlan card to sleep when you finish boot services

Thank you for your work. At first sight it looks quite nice but I am not able to do tests right now. I am going to continue my work on GRUB2/EFI stuff for Xen at the beginning of next year.

Can you confirm that that's what you want? I'd like it to make into 2.02 release but it would be useless if it's not what you want.

Quoted 2 lines

Daniel

#4 lore raw
Quoted 11 lines · Vladimir 'φ-coder/phcoder' Serbinenko
Quoted 8 lines · Daniel Kiper
Quoted 2 lines · Vladimir '??-coder/phcoder' Serbinenko

Patch to spec and GRUB attached.
@ xen: don't forget to put wlan card to sleep when you finish boot services

Thank you for your work. At first sight it looks quite nice but I am not able to do tests right now. I am going to continue my work on GRUB2/EFI stuff for Xen at the beginning of next year.

Can you confirm that that's what you want? I'd like it to make into 2.02 release but it would be useless if it's not what you want.

Just one nitpick. FinishBootServices() should be replaced by ExitBootServices() in doc/multiboot.texi file.

Yes, it is what I want but I think that it will be nice to test this new feature. However, I am busy right now and I am not able to do that. When are you going to make 2.02 release?

Daniel

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#5 lore raw
In reply to Vladimir 'φ-coder/phcoder' Serbinenko
Quoted 11 lines · Vladimir 'φ-coder/phcoder' Serbinenko
Quoted 8 lines · Daniel Kiper
Quoted 2 lines · Vladimir '??-coder/phcoder' Serbinenko

Patch to spec and GRUB attached.
@ xen: don't forget to put wlan card to sleep when you finish boot services

Thank you for your work. At first sight it looks quite nice but I am not able to do tests right now. I am going to continue my work on GRUB2/EFI stuff for Xen at the beginning of next year.

Can you confirm that that's what you want? I'd like it to make into 2.02 release but it would be useless if it's not what you want.

Just one nitpick. FinishBootServices() should be replaced by ExitBootServices() in doc/multiboot.texi file.

Yes, it is what I want but I think that it will be nice to test this new feature. However, I am busy right now and I am not able to do that. When are you going to make 2.02 release?

Daniel