[syslinux] [PATCH] chain.c32: add support for loading GRUB stage2

Gert Hulselmans gerth at zytor.com
Mon Jun 28 03:03:16 PDT 2010


Paul Bolle wrote:
> 1) The code in stage2/asm.S seems to hold all (or most?) information
> available for GRUB's stage2 (which can be found at 0x820:0x0 and up once
> stage2 is loaded).
>
> 2) For this discussion install_partition and config_file are the most
> relevant.
>
> 3)install_partition somehow stores a value for GRUB's "root" (but I
> haven't yet figured out how it does that, so the current code is hard
> coded to use a value meaning "(hd0)" in GRUB's syntax).
>
> 4) config_file might be interesting. It allows to store a string with
> the path of GRUB's configuration file (eg, "(hd0,1)/menu.lst", at
> 0x820:0x17, with a maximum length of 89 bytes). So, if chain.c32 knows
> about the disk and partition it is reading its files from (and it is
> possible to reliably translate that information to GRUB's syntax) it
> might be an idea to add another option to chain.c32. Say, something
> like:
>     menu=foo
> which would set the config_file string (in the copy of stage2 in memory)
> with a valid GRUB path to the file "foo" in the syslinux file system.
>
> Would that be feasible?
>
>
> Paul
>
I added support for passing the install_partition to chain.c32.

It is already committed (and available in Syslinux-4.00-pe64.

>From 4be5c7c1de0cdfdd0c5f42c116e240112a9af8cc Mon Sep 17 00:00:00 2001
From: Gert Hulselmans <gerth at zytor.com>
Date: Mon, 28 Jun 2010 03:11:48 +0200
Subject: [PATCH] chain.c32: pass partition number to stage2 of Grub Legacy

Grub Legacy stage2 will read the install_partition variable from
memory address 0x8208.
We only need to change the value at 0x820a to the correct partition
number:
  -1:   whole drive (default)
  0-3:  primary partitions
  4-*:  logical partitions

Signed-off-by: Gert Hulselmans <gerth at zytor.com>
---
 com32/modules/chain.c |   13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/com32/modules/chain.c b/com32/modules/chain.c
index a76d275..4f5baf1 100644
--- a/com32/modules/chain.c
+++ b/com32/modules/chain.c
@@ -123,11 +123,11 @@ static struct options {
     uint16_t seg;
     bool isolinux;
     bool cmldr;
+    bool grub;
     bool grldr;
     bool swap;
     bool hide;
     bool sethidden;
-    bool grub;
 } opt;

 struct data_area {
@@ -1585,10 +1585,13 @@ int main(int argc, char *argv[])
 	if (opt.grub) {
 	    regs.ip = 0x200;	/* jump 0x200 bytes into the loadfile */

-	    /* 0xffffff00 seems to be GRUB ways to record that it's
-	       "root" is the whole disk (and not a partition). */
-	    *(uint32_t *) ((unsigned char *)data[ndata].data + 0x208) =
-		0xffffff00ul;
+	    /* GRUB's stage2 wants the partition number in the install_partition
+	     * variable, located at memory address 0x8208.
+	     * We only need to change the value of memory address 0x820a too:
+	     *   -1:   whole drive (default)
+	     *   0-3:  primary partitions
+	     *   4-*:  logical partitions */
+	    ((uint8_t*) data[ndata].data)[0x20a] = (uint8_t)(whichpart - 1);
 	}

 	ndata++;
-- 
1.6.3.3




More information about the Syslinux mailing list