Skip to contentSkip to conversation

netboot and memory problem : solved ?

DISCUSSION Vincent Guffens 4 participants 5 messages Jun 18, 2005 – Jul 31, 2005 VFS

lore
Share & tools
lore
#0 lore raw

hi !

what do you think about the following change in grub_free ?

Instead of (at the end of the function)

if (p + p->size == p->next)

  {
    p->next->magic = 0;
    p->size += p->next->size;
    p->next = p->next->next;

}
[...]
r->first = q;

I tried the following

  if (p + p->size == p->next)
  {
    p->next->magic = 0;
    p->size += p->next->size;
    p->next = p->next->next;
    r->first = p;
    return;
  }

as a reminder, my problem was that sometimes, grub2 would fataly print (error message from grub_free):

free magic is broken at 0x37e50: 0x0

I'm quite sure that my problem is linked with that region of the code, but I'm not too sure about the consequences of that possible fix.

At least, I can't repoduce the problem on my pc but I'll do some more testing on monday as this problem is kind of "volatile".

I hope it's the one ! Have a good week-end !

Signature · 6 lines
				Vincent Guffens
				PhD Student UCL/CESAME
				tel:   +32 10 47 80 30
Value your freedom, or you will lose it, teaches history.
"Don't bother us with politics," respond those who don't want to learn.
	      	-- Richard M. Stallman
#1 lore raw

Ext2fs support bug

I create grub image like:
I have: /home/vova/grub/mnt is a mount point of /home/vova/grub/grub.img $prefix=/home/vova/grub/inst

I run:
from $prefix/sbin:

../bin/grub-mkimage -v -o ./core.img chain ext2
mount /home/vova/grub/mnt/
cp ../share/grub/i386-pc/* ../../mnt/boot/grub/
cp ./core.img ../../mnt/boot/grub
umount /home/vova/grub/mnt/
mount /home/vova/grub/mnt/
sync && ./grub-setup -m ./device.map --root-device=\(fd0\) \(fd0\) -d /home/vova/grub/mnt/boot/grub/ && sync
umount /home/vova/grub/mnt

And from /home/vova/grub:
qemu -fda ./grub.img
And I recieve:
Welcome to GRUB

unaligned pointer 0x7fef8

When I reformat my image file like fat and replace ext2 with fat it works fine so I suppose it's ext2fs bug.

Vladimir

P.S. I use GRUB2 CVS

#2 lore raw

Re: Ext2fs support bug

Quoted 9 lines · Serbinenko Vladimir

And from /home/vova/grub:
qemu -fda ./grub.img
And I recieve:
Welcome to GRUB

unaligned pointer 0x7fef8

When I reformat my image file like fat and replace ext2 with fat it works fine so I suppose it's ext2fs bug.

There was a bug in mm.c, perhaps it was related. Can you check if this was the problem by trying with current CVS? Otherwise, please send me the floppy image.

Thanks,
Marco

#3 lore raw

Bug-fixing and keystroke

I wrote some bugfixing patch + new feature.

Bug-fixing was mainly about FAT bug (unalloc magic on not-fat fs).

The new feature is sending keystroke to OS (imitating keypress + changing keyboard flags).
it works like:
keystroke [flags] [keys]

[flags] are like
--capslock=0 --rshift=1 ... (documentation in patch in keystroke.c at the end)
0 - means set flag to 0, 1 to 1 and 2 means keep value.
Some flags are the modes (like caps, num, scroll). Others are keys (like ctrl and shift)
If you set 0/1 to mode it will result like turning off/on the mode If you set key to 1 it will imitate keypressing until you really press it [keys] are key1 key2 ... like
h e l l o or
down down enter.
keylist is taken from GRUB Legacy + some new keys.

Known bugs (can smb help fix them):
LEDs in qemu are not set
help doesn't contain all useful informations.

Serbinenko Vladimir

2005-07-30 Vladimir Serbinenko <[email protected]>

Some bugfixes

* commands/ls.c (grub_ls_list_disks): fixed segmentation fault when fs == 0 or fs->label == 0
(grub_ls_list_files): Added label showing
* kern/disk.c (grub_print_partinfo): fixed segmentation fault when fs->label == 0
* fs/fat.c (grub_fat_dir): fixed segmentetaion fault by freeing

Keystroke module(pc) and preboots

* commands/boot.c: Added support for preboot functions
* conf/i386.rmk: new module keystroke
* include/grub/normal.h: new headers and types for preboots
* keystroke/keystroke.c: new file

commands/boot.c +50 -0
diff -urN grub2um/commands/boot.c grub2m/commands/boot.c
@@ -23,13 +23,23 @@
 #include <grub/arg.h>
 #include <grub/misc.h>
 #include <grub/loader.h>
+#include <grub/mm.h>
+#include <grub/err.h>
+
+static grub_prebootfn_t *grub_preboots = 0;
+static int grub_preboot_cnt = 0;
 
 static grub_err_t
 grub_cmd_boot (struct grub_arg_list *state __attribute__ ((unused)),
 	       int argc, char **args __attribute__ ((unused)))
 {
+  int i;
+
   if (argc)
     return grub_error (GRUB_ERR_BAD_ARGUMENT, "too many arguments");
+
+  for (i = 0; i < grub_preboot_cnt; i++)
+    grub_preboots[i] ();
   
   grub_loader_boot ();
   
@@ -38,6 +48,46 @@
 
 
 
+grub_err_t
+grub_preboot_add (grub_prebootfn_t fn)
+{
+  grub_prebootfn_t *tmp;
+  tmp = (grub_prebootfn_t *) grub_realloc (grub_preboots, (grub_preboot_cnt + 1) * sizeof(grub_prebootfn_t));
+  if (!tmp)
+    return grub_errno;
+  grub_preboots = tmp;
+  grub_preboots[grub_preboot_cnt] = fn;
+  grub_preboot_cnt++;
+
+  return 0;
+}
+
+
+
+grub_err_t
+grub_preboot_remove (grub_prebootfn_t fn)
+{
+  int i;
+  for (i = 0; i < grub_preboot_cnt; i++)
+    if (grub_preboots[i] == fn)
+      break;
+
+  if (i == grub_preboot_cnt)
+    {
+      return grub_error (GRUB_ERR_BAD_ARGUMENT, "fn not found");
+    }
+
+  for (; i < grub_preboot_cnt - 1; i++)
+    grub_preboots[i] = grub_preboots[i + 1];
+
+  grub_preboots = (grub_prebootfn_t *) grub_realloc (grub_preboots, (--grub_preboot_cnt) * sizeof(grub_prebootfn_t));
+
+  return 0;
+
+}
+
+
+
 #ifdef GRUB_UTIL
 void
 grub_boot_init (void)
commands/ls.c +25 -8
diff -urN grub2um/commands/ls.c grub2m/commands/ls.c
@@ -84,16 +84,18 @@
 
 		  grub_printf (", Filesystem type %s",
 			       fs ? fs->name : "Unknown");
-		  
-		  (fs->label) (dev, &label);
-		  if (grub_errno == GRUB_ERR_NONE)
+		  if (fs && fs->label)
 		    {
-		      if (label && grub_strlen (label))
-			grub_printf (", Label: %s", label);
-		      grub_free (label);
+		      (fs->label) (dev, &label);
+		      if (grub_errno == GRUB_ERR_NONE)
+			{
+			  if (label && grub_strlen (label))
+			    grub_printf (", Label: %s", label);
+			  grub_free (label);
+			}
+		      else
+			grub_errno = GRUB_ERR_NONE;
 		    }
-		  else
-		    grub_errno = GRUB_ERR_NONE;
 		}
 
 	      grub_putchar ('\n');
@@ -108,6 +110,7 @@
 	    }
 
 	  grub_device_close (dev);
+	 
 	}
   
       return 0;
@@ -223,6 +226,19 @@
 	  
       grub_printf ("(%s): Filesystem is %s.\n",
 		   device_name, fs ? fs->name : "unknown");
+      if (fs && fs->label)
+	{
+	  char *label;
+	  (fs->label) (dev, &label);
+	  if (grub_errno == GRUB_ERR_NONE)
+	    {
+	      if (label && grub_strlen (label))
+		grub_printf (", Label: %s", label);
+	      grub_free (label);
+	    }
+	  else
+	    grub_errno = GRUB_ERR_NONE;
+	}
     }
   else if (fs)
     {
@@ -267,6 +283,7 @@
     }
 
  fail:
+
   if (dev)
     grub_device_close (dev);
       
conf/i386-pc.mk +46 -1

59 lines not on this page · raw message

conf/i386-pc.rmk +5 -1
diff -urN grub2um/conf/i386-pc.rmk grub2m/conf/i386-pc.rmk
@@ -102,7 +102,7 @@
 	font.mod _multiboot.mod ls.mod boot.mod cmp.mod cat.mod		\
 	terminal.mod fshelp.mod chain.mod multiboot.mod amiga.mod	\
 	apple.mod pc.mod sun.mod loopback.mod reboot.mod halt.mod	\
-	help.mod default.mod timeout.mod configfile.mod
+	help.mod default.mod timeout.mod configfile.mod keystroke.mod
 
 # For _chain.mod.
 _chain_mod_SOURCES = loader/i386/pc/chainloader.c
@@ -163,6 +163,10 @@
 hello_mod_SOURCES = hello/hello.c
 hello_mod_CFLAGS = $(COMMON_CFLAGS)
 
+# For keystroke.mod.
+keystroke_mod_SOURCES = keystroke/keystroke.c
+keystroke_mod_CFLAGS = $(COMMON_CFLAGS)
+
 # For boot.mod.
 boot_mod_SOURCES = commands/boot.c
 boot_mod_CFLAGS = $(COMMON_CFLAGS)
fs/fat.c +5 -3
diff -urN grub2um/fs/fat.c grub2m/fs/fat.c
@@ -629,7 +629,7 @@
   struct grub_fat_data *data = 0;
   grub_disk_t disk = device->disk;
   grub_size_t len;
-  char *dirname;
+  char *dirname = 0;
   char *p;
 
 #ifndef GRUB_UTIL
@@ -660,8 +660,10 @@
 
  fail:
 
-  grub_free (dirname);
-  grub_free (data);
+  if (dirname)
+    grub_free (dirname);
+  if (data)
+    grub_free (data);
   
 #ifndef GRUB_UTIL
   grub_dl_unref (my_mod);
include/grub/normal.h +5 -0
diff -urN grub2um/include/grub/normal.h grub2m/include/grub/normal.h
@@ -44,6 +44,9 @@
 /* Not loaded yet. Used for auto-loading.  */
 #define GRUB_COMMAND_FLAG_NOT_LOADED	0x20
 
+/* Preboot function declaration.  */
+typedef void (*grub_prebootfn_t) (void); 
+
 /* The command description.  */
 struct grub_command
 {
@@ -178,6 +181,8 @@
 grub_menu_t grub_context_get_current_menu (void);
 grub_menu_t grub_context_push_menu (grub_menu_t menu);
 void grub_context_pop_menu (void);
+grub_err_t grub_preboot_add (grub_prebootfn_t fn);
+grub_err_t grub_preboot_remove (grub_prebootfn_t fn);
 
 #ifdef GRUB_UTIL
 void grub_normal_init (void);
kern/disk.c +1 -1
diff -urN grub2um/kern/disk.c grub2m/kern/disk.c
@@ -535,7 +535,7 @@
       grub_printf ("\tPartition num:%s, Filesystem type %s",
 		   partname, fs ? fs->name : "Unknown");
 	  
-      if (fs)
+      if (fs && fs->label)
 	{
 	  (fs->label) (part, &label);
 	  if (grub_errno == GRUB_ERR_NONE)
keystroke/keystroke.c +406 -0

406 lines not on this page · raw message

#4 lore raw

Re: Bug-fixing and keystroke

Quoted 1 line · Serbinenko Vladimir

I wrote some bugfixing patch + new feature.

Thank you very much. I have applied only the bugfixes at the moment.

Quoted 4 lines

The new feature is sending keystroke to OS (imitating keypress + changing keyboard flags).
it works like:
keystroke [flags] [keys]

This is specific to i386-pc, so the source file should be put in commands/i386/pc.

I'm also wondering if this command name is good or not. In QEMU, the same feature is called "sendkey". I'm not sure which is better.

Another question I have is that it might be better to implement this as a variable rather than a command. Basically, this command just stores information rathen than executing something directly. So using a variable sounds intuitive for me.

What do you think?

Okuji