GRUB2 does not provide Multiboot Legacy memory map
PATCH 1/1 GRUB2 does not provide Multiboot Legacy memory map
Hi,
I'm developing a small kernel and I've been using GRUB2 with the Legacy Multiboot Specification for some time now. I've noticed that it does not provide some of the things in the Multiboot Information structure that GRUB Legacy does, like the memory map. So I've created a small patch which works in QEMU and real hardware so that GRUB2 will pass the memory map to my kernel or any multiboot-compliant kernel for the i386-pc.
Since I've never actually contributed code to a GNU project before, are there certain rules and regulations of some sort that I have to comply with before I can send my patch here?
Thanks.
Hello!
Quoted 6 lines · Julian Salazar
I'm developing a small kernel and I've been using GRUB2 with the Legacy Multiboot Specification for some time now. I've noticed that it does not provide some of the things in the Multiboot Information structure that GRUB Legacy does, like the memory map. So I've created a small patch which works in QEMU and real hardware so that GRUB2 will pass the memory map to my kernel or any multiboot-compliant kernel for the i386-pc.
Now this is interesting as I've just today seen an incompatibility between booting a multiboot kernel with GRUB legacy and GRUB2. It might actually be the same issue, but I didn't fully investigate yet. Therefore I'm quite interested in seeing your patch.
Quoted 1 line
Since I've never actually contributed code to a GNU project before, are
Welcome!
Quoted 1 line
there certain rules and regulations of some sort that I have to comply with
Your guessed right: sure there are :-). See, for example, (parts of) the GNU Coding Standards, <http://www.gnu.org/prep/standards/html_node/>.
Not everything is relevant in your case, though.
Quoted 1 line
before I can send my patch here?
Feel free to simply send it here and we'll tell you what needs to be changed.
Regards,
Thomas
Attached is the patch. Since I'm not completely familiar with GRUB2's internals, there might be a more efficient way of implementing this.
Thoughts/improvements?
Quoted 37 lines
-----Original Message-----
From: [email protected] [mailto:grub- [email protected]] On Behalf Of Thomas Schwinge
Sent: April-19-08 3:32 PM
To: Julian Salazar
Cc: [email protected]
Subject: Re: [PATCH] GRUB2 does not provide Multiboot Legacy memory mapHello!
Quoted 3 lines · Julian Salazar
I'm developing a small kernel and I've been using GRUB2 with the Legacy Multiboot Specification for some time now. I've noticed that it does not provide some of the things in the Multiboot Information structure that
GRUB
Quoted 1 line
Legacy does, like the memory map. So I've created a small patch which
works
Quoted 2 lines
in QEMU and real hardware so that GRUB2 will pass the memory map to my kernel or any multiboot-compliant kernel for the i386-pc.
Now this is interesting as I've just today seen an incompatibility between booting a multiboot kernel with GRUB legacy and GRUB2. It might actually be the same issue, but I didn't fully investigate yet. Therefore I'm quite interested in seeing your patch.
Quoted 1 line
Since I've never actually contributed code to a GNU project before, are
Welcome!
Quoted 1 line
there certain rules and regulations of some sort that I have to comply
with
Your guessed right: sure there are :-). See, for example, (parts of) the GNU Coding Standards, <http://www.gnu.org/prep/standards/html_node/>.
Not everything is relevant in your case, though.
Quoted 8 lines
Quoted 1 line
before I can send my patch here?
Feel free to simply send it here and we'll tell you what needs to be changed.
Regards,
Thomas
Index: loader/i386/pc/multiboot.c
===================================================================
RCS file: /sources/grub/grub2/loader/i386/pc/multiboot.c,v retrieving revision 1.19
i386/pc/multiboot.c +27 -1
@@ -24,7 +24,6 @@* - a.out support * - boot device * - symbol table -* - memory map * - drives table * - ROM configuration table * - APM table
@@ -74,6 +73,7 @@ grub_multiboot_unload (void) }grub_free ((void *) mbi->mods_addr);grub_free ((void *) mbi->cmdline); +grub_free ((void *) mbi->mmap_addr);grub_free (mbi); }
@@ -314,6 +314,10 @@ grub_multiboot (int argc, char *argv[])char buffer[MULTIBOOT_SEARCH ], *cmdline =0 , *p;struct grub_multiboot_header *header;grub_ssize_t len; +struct grub_machine_mmap_entry *mmap_entry + = (struct grub_machine_mmap_entry *)GRUB_MEMORY_MACHINE_SCRATCH_ADDR ; +struct grub_machine_mmap_entry *mmap; +grub_uint32_t cont;int i;grub_loader_unset ();
@@ -411,6 +415,26 @@ grub_multiboot (int argc, char *argv[]) mbi->flags |=MULTIBOOT_INFO_CMDLINE ; mbi->cmdline = (grub_uint32_t ) cmdline; +/* Create memory map */ + cont =grub_get_mmap_entry (mmap_entry,0 ); + +if (mmap_entry->size) + { +/* Allocate space for 32 memory map entries */ + mmap =grub_malloc (sizeof (struct grub_machine_mmap_entry ) *32 ); +if (! mmap) + goto fail; + mmap[0 ] = *mmap_entry; +for (i =1 ; cont; i++) + { + cont =grub_get_mmap_entry (mmap_entry, cont); + mmap[i] = *mmap_entry; + } + mbi->flags |=MULTIBOOT_INFO_MEM_MAP ; + mbi->mmap_length =sizeof (struct grub_machine_mmap_entry ) * i; + mbi->mmap_addr = (grub_uint32_t ) mmap; + } + mbi->flags |=MULTIBOOT_INFO_BOOT_LOADER_NAME ; mbi->boot_loader_name = (grub_uint32_t )grub_strdup (PACKAGE_STRING );
@@ -426,6 +450,8 @@ grub_multiboot (int argc, char *argv[])if (grub_errno !=GRUB_ERR_NONE ) {grub_free (cmdline); +if (mbi->flags &MULTIBOOT_INFO_MEM_MAP ) +grub_free (mmap);grub_free (mbi);grub_dl_unref (my_mod); }
Quoted 4 lines · Julian Salazar
Attached is the patch. Since I'm not completely familiar with GRUB2's internals, there might be a more efficient way of implementing this.
Thoughts/improvements?
Thanks for the patch. It'd be interesting if it was done portably. The coreboot (aka LinuxBIOS) target also uses this code, and the memory map is obtained differently there (see kern/i386/linuxbios/init.c).
At least, it could be #ifdef'ed, although it'd be nice to have something more ellegant (e.g. an isolated, generic function to probe for memory map arch-dependantly that arch-independant code can use).
Signature · 5 lines
Robert Millan <GPLv2> I know my rights; I want my phone call! <DRM> What use is a phone call… if you are unable to speak? (as seen on /.)