Skip to contentSkip to conversation

Support linux boot protocol >= 2.02 long command-lines

PATCH/DRAFT New Alon Bar-Lev 2 participants 15 messages May 2, 2008

lore
Share & tools
lore
#0 lore raw

Hello,

Continue from bug#13606 [1]

cmd_line_ptr should not be truncated to 256.

A draft patch is provided. I could not test it as grub-2 does not work in my VMWare (ATA) configuration. It enters rescue prompt and when I set root (hd0, 1) I get "error: unknown device".
I tried adding many modules (lspci for example) but not see any command when typing help.

Please review this patch or apply something better.
For EFI I did not understand what the lh.cl_offset = 0 is for, but as only recent boot protocols are supported I am not sure it is required.

[1] https://savannah.gnu.org/bugs/?13606

---

include/grub/i386/linux.h +3 -1
diff -urNp grub-1.96.org/include/grub/i386/linux.h grub-1.96/include/grub/i386/linux.h
@@ -41,7 +41,9 @@
 
 #define GRUB_LINUX_CL_OFFSET		0x9000
 #define GRUB_LINUX_CL_END_OFFSET	0x90FF
-#define GRUB_LINUX_SETUP_MOVE_SIZE	0x9100
+#define GRUB_LINUX_CL_0202_OFFSET	0x9100
+#define GRUB_LINUX_CL_0202_END_OFFSET	0x9FFF
+#define GRUB_LINUX_SETUP_MOVE_SIZE	0xA000
 #define GRUB_LINUX_CL_MAGIC		0xA33F
 
 #define GRUB_LINUX_EFI_SIGNATURE	\
loader/i386/efi/linux.c +4 -4
diff -urNp grub-1.96.org/loader/i386/efi/linux.c grub-1.96/loader/i386/efi/linux.c
@@ -391,8 +391,8 @@ grub_rescue_cmd_linux (int argc, char *a
   lh.type_of_loader = 0x50;
 
   lh.cl_magic = GRUB_LINUX_CL_MAGIC;
-  lh.cl_offset = GRUB_LINUX_CL_END_OFFSET;
-  lh.cmd_line_ptr = (char *) real_mode_mem + GRUB_LINUX_CL_OFFSET;
+  lh.cl_offset = 0;
+  lh.cmd_line_ptr = (char *) real_mode_mem + GRUB_LINUX_CL_0202_OFFSET;
   lh.ramdisk_image = 0;
   lh.ramdisk_size = 0;
 
@@ -531,7 +531,7 @@ grub_rescue_cmd_linux (int argc, char *a
       }
 
   /* Specify the boot file.  */
-  dest = grub_stpcpy ((char *) real_mode_mem + GRUB_LINUX_CL_OFFSET,
+  dest = grub_stpcpy ((char *) real_mode_mem + GRUB_LINUX_CL_0202_OFFSET,
 		      "BOOT_IMAGE=");
   dest = grub_stpcpy (dest, argv[0]);
   
@@ -539,7 +539,7 @@ grub_rescue_cmd_linux (int argc, char *a
   for (i = 1;
        i < argc
 	 && dest + grub_strlen (argv[i]) + 1 < ((char *) real_mode_mem
-						+ GRUB_LINUX_CL_END_OFFSET);
+						+ GRUB_LINUX_CL_0202_END_OFFSET);
        i++)
     {
       *dest++ = ' ';
loader/i386/pc/linux.c +8 -3
diff -urNp grub-1.96.org/loader/i386/pc/linux.c grub-1.96/loader/i386/pc/linux.c
@@ -117,7 +117,7 @@ grub_rescue_cmd_linux (int argc, char *a
 	}
       
       if (grub_le_to_cpu16 (lh.version) >= 0x0202)
-	lh.cmd_line_ptr = grub_linux_real_addr + GRUB_LINUX_CL_OFFSET;
+	lh.cmd_line_ptr = grub_linux_real_addr + GRUB_LINUX_CL_OFFSET;
       else
 	{
 	  lh.cl_magic = grub_cpu_to_le16 (GRUB_LINUX_CL_MAGIC);
@@ -244,7 +244,7 @@ grub_rescue_cmd_linux (int argc, char *a
 		  << GRUB_DISK_SECTOR_BITS));
 
   /* Specify the boot file.  */
-  dest = grub_stpcpy (grub_linux_tmp_addr + GRUB_LINUX_CL_OFFSET,
+  dest = grub_stpcpy (grub_linux_tmp_addr + GRUB_LINUX_CL_0202_OFFSET,
 		      "BOOT_IMAGE=");
   dest = grub_stpcpy (dest, argv[0]);
   
@@ -252,13 +252,18 @@ grub_rescue_cmd_linux (int argc, char *a
   for (i = 1;
        i < argc
 	 && dest + grub_strlen (argv[i]) + 1 < (grub_linux_tmp_addr
-						+ GRUB_LINUX_CL_END_OFFSET);
+						+ GRUB_LINUX_CL_0202_END_OFFSET);
        i++)
     {
       *dest++ = ' ';
       dest = grub_stpcpy (dest, argv[i]);
     }
 
+  grub_strncpy (grub_linux_tmp_addr + GRUB_LINUX_CL_OFFSET,
+                grub_linux_tmp_addr + GRUB_LINUX_CL_0202_OFFSET,
+		GRUB_LINUX_CL_END_OFFSET - GRUB_LINUX_CL_OFFSET - 1);
+  *(grub_linux_tmp_addr + GRUB_LINUX_CL_END_OFFSET) = '\0';
+
   len = prot_size;
   if (grub_file_read (file, (char *) GRUB_LINUX_BZIMAGE_ADDR, len) != len)
     grub_error (GRUB_ERR_FILE_READ_ERROR, "Couldn't read file");
#1 lore raw
Quoted 3 lines · Alon Bar-Lev

A draft patch is provided. I could not test it as grub-2 does not work in my VMWare (ATA) configuration. It enters rescue prompt and when I set root (hd0, 1) I get "error: unknown device".
I tried adding many modules (lspci for example) but not see any command when typing help.

Hi Alon,

So when did vmware stop working? Can you tell me what you did try to do to get it working? I have one vmware here handy so I could try it out.

Thanks,
Vesa Jääskeläinen

#2 lore raw
Quoted 7 lines · Vesa Jääskeläinen

Hi Alon,

So when did vmware stop working? Can you tell me what you did try to do to
get it working? I have one vmware here handy so I could try it out.

Thanks,
Vesa Jääskeläinen

Hi!

Stopped working when I installed grub-2 :)
Working fine with grub-1.

I am using vmware-server-1.0.5.80187, with ide configuration also for disks.

But anyway... Why don't I get lspci command available if I added this to grub-install and see it loaded in lsmod output?

Alon.

#3 lore raw
Quoted 11 lines · Alon Bar-Lev
Quoted 7 lines · Vesa Jääskeläinen

Hi Alon,

So when did vmware stop working? Can you tell me what you did try to do to
get it working? I have one vmware here handy so I could try it out.

Thanks,
Vesa Jääskeläinen

Hi!

Quoted 7 lines

Stopped working when I installed grub-2 :)
Working fine with grub-1.

I am using vmware-server-1.0.5.80187, with ide configuration also for disks.

But anyway... Why don't I get lspci command available if I added this to grub-install and see it loaded in lsmod output?

Hi Alon,

Actually I meant that I have used it before in vmware desktop and it worked fine. So I was wondering when it got broken and how did exactly you try it out to reproduce the issue here. Because grub 2 "has to" work in vmware too :)

Eg. tell that you ran this and this. And then did that.

I think lspci might also need some device database. So if it cannot load it may fail. But lets first tackle this vmware problem :)

Thanks,
Vesa Jääskeläinen

#4 lore raw
Quoted 9 lines · Vesa Jääskeläinen

Hi Alon,

Actually I meant that I have used it before in vmware desktop and it worked
fine. So I was wondering when it got broken and how did exactly you try it out to reproduce the issue here. Because grub 2 "has to" work in vmware too :)

Eg. tell that you ran this and this. And then did that.

I run:
grub-install /dev/hda

Nothing special... on boot I grub starts and goes into rescue prompt. There is no proper documentation... So I don't know what else I can do. I think I have a proper grub.cfg but I don't think I got to the stage it actually can be read. As ls command command shows empty output.

Quoted 2 lines

I think lspci might also need some device database. So if it cannot load it
may fail. But lets first tackle this vmware problem :)

But this is basic... the module is loaded... I understand that the disk may not be detected, but I expect command to be available.

Alon.

#5 lore raw
Quoted 10 lines · Alon Bar-Lev
Quoted 8 lines · Vesa Jääskeläinen

Hi Alon,

Actually I meant that I have used it before in vmware desktop and it worked
fine. So I was wondering when it got broken and how did exactly you try it out to reproduce the issue here. Because grub 2 "has to" work in vmware too :)

Eg. tell that you ran this and this. And then did that.

Quoted 7 lines

I run:
grub-install /dev/hda

Nothing special... on boot I grub starts and goes into rescue prompt. There is no proper documentation... So I don't know what else I can do. I think I have a proper grub.cfg but I don't think I got to the stage it actually can be read. As ls command command shows empty output.

I just built current CVS and tried it with my old scripts. Didn't install it to /dev/hda as cannot test it without reinstall ;)... but made core.img with modules: chain fat biosdisk. Installed it to floppy and then booted that floppy in vmware desktop 5.5.4.

Even graphics mode seem to work.

I can provide this test floppy if you want to test it out?

Quoted 5 lines
Quoted 2 lines

I think lspci might also need some device database. So if it cannot load it
may fail. But lets first tackle this vmware problem :)

But this is basic... the module is loaded... I understand that the disk may not be detected, but I expect command to be available.

insmod pci
insmod lspci
lspci

#6 lore raw
Quoted 4 lines · Vesa Jääskeläinen

I just built current CVS and tried it with my old scripts. Didn't install
it to /dev/hda as cannot test it without reinstall ;)... but made core.img with modules: chain fat biosdisk. Installed it to floppy and then booted that floppy in vmware desktop 5.5.4.

I use grub-1.96, should I use CVS.
Anyway, I need ext2 to make it work...

Quoted 1 line

I can provide this test floppy if you want to test it out?

Sure. But pleas add ext2 so it will be usable.

Quoted 4 lines

insmod pci
insmod lspci
lspci

I added this to the --modules at grub-install, I can see it is loaded using lsmod, but no command.

Alon.

#7 lore raw
Quoted 13 lines · Alon Bar-Lev
Quoted 4 lines · Vesa Jääskeläinen

I just built current CVS and tried it with my old scripts. Didn't install
it to /dev/hda as cannot test it without reinstall ;)... but made core.img with modules: chain fat biosdisk. Installed it to floppy and then booted that floppy in vmware desktop 5.5.4.

I use grub-1.96, should I use CVS.
Anyway, I need ext2 to make it work...

Quoted 1 line

I can provide this test floppy if you want to test it out?

Sure. But pleas add ext2 so it will be usable.

Quoted 7 lines
Quoted 4 lines

insmod pci
insmod lspci
lspci

I added this to the --modules at grub-install, I can see it is loaded using lsmod, but no command.

Did you load lspci module :)

Anyway... new list of modules:
chain fat biosdisk ext2 pci lspci

And I formatted floppy as ext2...

http://nokkau.net/~chaac/files/grub2/grub2_ext2_floppy.zip

#8 lore raw
Quoted 1 line · Vesa Jääskeläinen

Did you load lspci module :)

Already told you it appear in lsmod.
But from what I see this command is not available in rescue mode. I don't understand why if module is loaded it is not provided in rescue mode. How do you switch from rescue to normal mode?

Quoted 8 lines

Anyway... new list of modules:
chain fat biosdisk ext2 pci lspci

And I formatted floppy as ext2...

http://nokkau.net/~chaac/files/grub2/grub2_ext2_floppy.zip

OK... Now in rescue I can see hd0, hd1 I cannot do "ls (hd0, 1)" it writes unknown device.

I also tried the following configuration:

menuentry "linux" {
        set root=(hd0,1)
        kernel /kernel-x86-2.6.23-gentoo-r3
        initrd /initramfs-x86-2.6.23-gentoo-r3
}

It compains that initrd is not available, so I guess I needed to add insmod linux... But then I got "You need to load the kernel first".

????

Alon.

#9 lore raw
Quoted 7 lines · Alon Bar-Lev
Quoted 1 line · Vesa Jääskeläinen

Did you load lspci module :)

Already told you it appear in lsmod.
But from what I see this command is not available in rescue mode. I don't understand why if module is loaded it is not provided in rescue mode. How do you switch from rescue to normal mode?

You can type: normal

Quoted 12 lines
Quoted 7 lines

Anyway... new list of modules:
chain fat biosdisk ext2 pci lspci

And I formatted floppy as ext2...

http://nokkau.net/~chaac/files/grub2/grub2_ext2_floppy.zip

OK... Now in rescue I can see hd0, hd1 I cannot do "ls (hd0, 1)" it writes unknown device.

I also tried the following configuration:

Quoted 8 lines
menuentry "linux" {
        set root=(hd0,1)
        kernel /kernel-x86-2.6.23-gentoo-r3
        initrd /initramfs-x86-2.6.23-gentoo-r3
}

It compains that initrd is not available, so I guess I needed to add insmod linux... But then I got "You need to load the kernel first".

Did you use that floppy?... For me it displayed the menu. Then with 'C' you can go to normal mode shell.

You have to use linux command to load linux kernel:
http://grub.enbug.org/grub.cfg

#10 lore raw
Quoted 4 lines · Vesa Jääskeläinen
Quoted 2 lines

How do you switch from rescue to normal mode?

You can type: normal

Oh... It is available at your rescue, but not mine.

Quoted 2 lines

Did you use that floppy?... For me it displayed the menu. Then with 'C' you
can go to normal mode shell.

Sure!
This I know.

Quoted 2 lines

You have to use linux command to load linux kernel:
http://grub.enbug.org/grub.cfg

Tried that too...

menu->c->linux (hd0,1)/bla
error: unknown device
rescue->ls
(fd0) (hd0) (hd1)

I guess the partitions are missing?

Alon.

#11 lore raw
Quoted 6 lines · Alon Bar-Lev
Quoted 3 lines · Vesa Jääskeläinen
Quoted 2 lines

How do you switch from rescue to normal mode?

You can type: normal

Oh... It is available at your rescue, but not mine.

you can try : insmod normal

Quoted 9 lines
Quoted 2 lines

Did you use that floppy?... For me it displayed the menu. Then with 'C' you
can go to normal mode shell.

Sure!
This I know.

Quoted 2 lines

You have to use linux command to load linux kernel:
http://grub.enbug.org/grub.cfg

Quoted 8 lines

Tried that too...

menu->c->linux (hd0,1)/bla
error: unknown device
rescue->ls
(fd0) (hd0) (hd1)

I guess the partitions are missing?

Now that you said it... there wasn't pc partition table module there ;)

added "pc" to module list and updated that image:

http://nokkau.net/~chaac/files/grub2/grub2_ext2_floppy.zip

#12 lore raw
Quoted 6 lines · Vesa Jääskeläinen

Now that you said it... there wasn't pc partition table module there ;)

added "pc" to module list and updated that image:

http://nokkau.net/~chaac/files/grub2/grub2_ext2_floppy.zip

Success!!!
I had to insmod linux, boot

So I will try CVS now and see if I can build it my self, as pc module was loaded at my side.

Alon.

#13 lore raw
Quoted 7 lines · Alon Bar-Lev
Quoted 6 lines · Vesa Jääskeläinen

Now that you said it... there wasn't pc partition table module there ;)

added "pc" to module list and updated that image:

Quoted 8 lines
Quoted 1 line

http://nokkau.net/~chaac/files/grub2/grub2_ext2_floppy.zip

Success!!!
I had to insmod linux, boot

So I will try CVS now and see if I can build it my self, as pc module was loaded at my side.

OK. CVS works.

Alon

#14 lore raw

PATCH 1/1 Support linux boot protocol >= 2.02 long command-lines

Continue from bug#13606 [1]

cmd_line_ptr should not be truncated to 256.

Please review this patch or apply something better.
Tested for pc/linux, guess for efi/linux.
For EFI I did not understand what the lh.cl_offset = 0 is for, but as only recent boot protocols are supported I am not sure it is required.

---

Index: include/grub/i386/linux.h
===================================================================
RCS file: /sources/grub/grub2/include/grub/i386/linux.h,v retrieving revision 1.4

grub/i386/linux.h +3 -1
diff -u -B -r1.4 linux.h
@@ -41,7 +41,9 @@
 
 #define GRUB_LINUX_CL_OFFSET		0x9000
 #define GRUB_LINUX_CL_END_OFFSET	0x90FF
-#define GRUB_LINUX_SETUP_MOVE_SIZE	0x9100
+#define GRUB_LINUX_CL_0202_OFFSET	0x9100
+#define GRUB_LINUX_CL_0202_END_OFFSET	0x9FFF
+#define GRUB_LINUX_SETUP_MOVE_SIZE	0xA000
 #define GRUB_LINUX_CL_MAGIC		0xA33F
 
 #define GRUB_LINUX_EFI_SIGNATURE	\

Index: loader/i386/efi/linux.c
===================================================================
RCS file: /sources/grub/grub2/loader/i386/efi/linux.c,v retrieving revision 1.2

i386/efi/linux.c +4 -4
diff -u -B -r1.2 linux.c
@@ -391,8 +391,8 @@
   lh.type_of_loader = 0x50;
 
   lh.cl_magic = GRUB_LINUX_CL_MAGIC;
-  lh.cl_offset = GRUB_LINUX_CL_END_OFFSET;
-  lh.cmd_line_ptr = (char *) real_mode_mem + GRUB_LINUX_CL_OFFSET;
+  lh.cl_offset = 0;
+  lh.cmd_line_ptr = (char *) real_mode_mem + GRUB_LINUX_CL_0202_OFFSET;
   lh.ramdisk_image = 0;
   lh.ramdisk_size = 0;
 
@@ -531,7 +531,7 @@
       }
 
   /* Specify the boot file.  */
-  dest = grub_stpcpy ((char *) real_mode_mem + GRUB_LINUX_CL_OFFSET,
+  dest = grub_stpcpy ((char *) real_mode_mem + GRUB_LINUX_CL_0202_OFFSET,
 		      "BOOT_IMAGE=");
   dest = grub_stpcpy (dest, argv[0]);
   
@@ -539,7 +539,7 @@
   for (i = 1;
        i < argc
 	 && dest + grub_strlen (argv[i]) + 1 < ((char *) real_mode_mem
-						+ GRUB_LINUX_CL_END_OFFSET);
+						+ GRUB_LINUX_CL_0202_END_OFFSET);
        i++)
     {
       *dest++ = ' ';

Index: loader/i386/pc/linux.c
===================================================================
RCS file: /sources/grub/grub2/loader/i386/pc/linux.c,v retrieving revision 1.18

i386/pc/linux.c +8 -3
diff -u -B -r1.18 linux.c
@@ -117,7 +117,7 @@
 	}
       
       if (grub_le_to_cpu16 (lh.version) >= 0x0202)
-	lh.cmd_line_ptr = grub_linux_real_addr + GRUB_LINUX_CL_OFFSET;
+	lh.cmd_line_ptr = grub_linux_real_addr + GRUB_LINUX_CL_0202_OFFSET;
       else
 	{
 	  lh.cl_magic = grub_cpu_to_le16 (GRUB_LINUX_CL_MAGIC);
@@ -244,7 +244,7 @@
 		  << GRUB_DISK_SECTOR_BITS));
 
   /* Specify the boot file.  */
-  dest = grub_stpcpy (grub_linux_tmp_addr + GRUB_LINUX_CL_OFFSET,
+  dest = grub_stpcpy (grub_linux_tmp_addr + GRUB_LINUX_CL_0202_OFFSET,
 		      "BOOT_IMAGE=");
   dest = grub_stpcpy (dest, argv[0]);
   
@@ -252,13 +252,18 @@
   for (i = 1;
        i < argc
 	 && dest + grub_strlen (argv[i]) + 1 < (grub_linux_tmp_addr
-						+ GRUB_LINUX_CL_END_OFFSET);
+						+ GRUB_LINUX_CL_0202_END_OFFSET);
        i++)
     {
       *dest++ = ' ';
       dest = grub_stpcpy (dest, argv[i]);
     }
 
+  grub_strncpy (grub_linux_tmp_addr + GRUB_LINUX_CL_OFFSET,
+                grub_linux_tmp_addr + GRUB_LINUX_CL_0202_OFFSET,
+		GRUB_LINUX_CL_END_OFFSET - GRUB_LINUX_CL_OFFSET - 1);
+  *(grub_linux_tmp_addr + GRUB_LINUX_CL_END_OFFSET) = '\0';
+
   len = prot_size;
   if (grub_file_read (file, (char *) GRUB_LINUX_BZIMAGE_ADDR, len) != len)
     grub_error (GRUB_ERR_FILE_READ_ERROR, "Couldn't read file");