Make knetbsd pass the root device
PATCH 1/1 Make knetbsd pass the root device
Hi,
The attached patch adds bootdisk and bootwedge to the bootinfo passed to NetBSD kernels by knetbsd. These fields indicate to the kernel which is the root device. The patch sets them to GRUB's root device.
This way, specifying --root for knetbsd is no longer necessary for common cases.
Examples:
- Root device is partition f: of the NetBSD label in hd0:
insmod part_bsd
set root=(hd0,netbsd6)
- Root device is partition a: of the NetBSD label in hd1 (*):
insmod part_bsd
set root=(hd1,netbsd1)
- Root device is first GPT partition of hd1:
insmod part_gpt
set root=(hd1,gpt1)
Here, the NetBSD kernel will detect the root device as a disk wedge.
- Root device is 2nd DOS partition of hd0:
set root=(hd0,msdos2)
As in the previous case, the kernel will detect the root device as a disk wedge (if it is built with the appropriate option).
(*) Assuming that a: is the root partition of the NetBSD slice contained in, say, (hd1,msdos3), one should specify (hd1,netbsd1) and not (hd1,msdos3). The latter would be ignored by the kernel (or, possibly, detected as a wedge).
Comments welcome.
Grégoire
=== modified file 'ChangeLog'
ChangeLog +12 -0
@@ -1,3 +1,15 @@ +2011-09-20 Grégoire Sutre <[email protected]> + + * include/grub/bsdlabel.h (grub_partition_bsd_disk_label): Add fields + type and packname. + * include/grub/i386/netbsd_bootinfo.h (NETBSD_BTINFO_BOOTDISK): + Resurrected. + (NETBSD_BTINFO_BOOTWEDGE): New definition. + (grub_netbsd_btinfo_bootwedge): New struct. + * grub-core/loader/i386/bsd.c (grub_netbsd_add_boot_disk_and_wedge): + New function. + (grub_cmd_netbsd): Call grub_netbsd_add_boot_disk_and_wedge. + 2011-09-17 Grégoire Sutre <[email protected]> * Makefile.util.def (grub-mkrelpath): Add LIBUTIL for getrawpartition(3)
=== modified file 'grub-core/loader/i386/bsd.c'
loader/i386/bsd.c +82 -0
100 lines not on this page · raw message
=== modified file 'include/grub/bsdlabel.h'
grub/bsdlabel.h +4 -1
@@ -80,7 +80,10 @@ struct grub_partition_bsd_entrystruct grub_partition_bsd_disk_label {grub_uint32_t magic; -grub_uint8_t padding[128 ]; +grub_uint16_t type; +grub_uint8_t unused1[18 ]; +grub_uint8_t packname[16 ]; +grub_uint8_t unused2[92 ];grub_uint32_t magic2;grub_uint16_t checksum;grub_uint16_t num_partitions;
=== modified file 'include/grub/i386/netbsd_bootinfo.h'
grub/i386/netbsd_bootinfo.h +11 -0
@@ -51,9 +51,11 @@#define NETBSD_BTINFO_BOOTPATH 0#define NETBSD_BTINFO_ROOTDEVICE 1 +#define NETBSD_BTINFO_BOOTDISK 3#define NETBSD_BTINFO_CONSOLE 6#define NETBSD_BTINFO_SYMTAB 8#define NETBSD_BTINFO_MEMMAP 9 +#define NETBSD_BTINFO_BOOTWEDGE 10#define NETBSD_BTINFO_MODULES 11#define NETBSD_BTINFO_FRAMEBUF 12
@@ -83,6 +85,15 @@ struct grub_netbsd_btinfo_bootdiskgrub_uint32_t partition; }; +struct grub_netbsd_btinfo_bootwedge { +grub_uint32_t biosdev; +grub_disk_addr_t startblk; +grub_uint64_t nblks; +grub_disk_addr_t matchblk; +grub_uint64_t matchnblks; +grub_uint8_t matchhash[16 ];/* MD5 hash */ +} __packed; +struct grub_netbsd_btinfo_symtab {grub_uint32_t nsyms;
loader/i386/bsd.c grub_netbsd_add_modules (void) · line 970
Quoted 3 lines · Grégoire Sutre
loader/i386/bsd.c +3
-0+ dev =grub_device_open (0 ); +if (! (dev&& dev->disk&& dev->disk->partition)) +return ;
This return' should be a goto fail'.
Grégoire
Following Vladimir's comments on IRC, here is the second version of the patch.
- Make sure that buffers are well-aligned.
- Check that partmap->name is "netbsd".
(I kept the magic test since it's cheap, but I won't fight over it :-)
Grégoire
=== modified file 'ChangeLog'
ChangeLog +12 -0
@@ -1,3 +1,15 @@ +2011-09-28 Grégoire Sutre <[email protected]> + + * include/grub/bsdlabel.h (grub_partition_bsd_disk_label): Add fields + type and packname. + * include/grub/i386/netbsd_bootinfo.h (NETBSD_BTINFO_BOOTDISK): + Resurrected. + (NETBSD_BTINFO_BOOTWEDGE): New definition. + (grub_netbsd_btinfo_bootwedge): New struct. + * grub-core/loader/i386/bsd.c (grub_netbsd_add_boot_disk_and_wedge): + New function. + (grub_cmd_netbsd): Call grub_netbsd_add_boot_disk_and_wedge. + 2011-09-28 Thomas Haller <[email protected]> * grub-core/loader/multiboot_elfxx.c (Elf_Shdr): Set according to
=== modified file 'grub-core/loader/i386/bsd.c'
loader/i386/bsd.c +84 -0
102 lines not on this page · raw message
=== modified file 'include/grub/bsdlabel.h'
grub/bsdlabel.h +4 -1
@@ -80,7 +80,10 @@ struct grub_partition_bsd_entrystruct grub_partition_bsd_disk_label {grub_uint32_t magic; -grub_uint8_t padding[128 ]; +grub_uint16_t type; +grub_uint8_t unused1[18 ]; +grub_uint8_t packname[16 ]; +grub_uint8_t unused2[92 ];grub_uint32_t magic2;grub_uint16_t checksum;grub_uint16_t num_partitions;
=== modified file 'include/grub/i386/netbsd_bootinfo.h'
grub/i386/netbsd_bootinfo.h +11 -0
@@ -51,9 +51,11 @@#define NETBSD_BTINFO_BOOTPATH 0#define NETBSD_BTINFO_ROOTDEVICE 1 +#define NETBSD_BTINFO_BOOTDISK 3#define NETBSD_BTINFO_CONSOLE 6#define NETBSD_BTINFO_SYMTAB 8#define NETBSD_BTINFO_MEMMAP 9 +#define NETBSD_BTINFO_BOOTWEDGE 10#define NETBSD_BTINFO_MODULES 11#define NETBSD_BTINFO_FRAMEBUF 12
@@ -83,6 +85,15 @@ struct grub_netbsd_btinfo_bootdiskgrub_uint32_t partition; }; +struct grub_netbsd_btinfo_bootwedge { +grub_uint32_t biosdev; +grub_disk_addr_t startblk; +grub_uint64_t nblks; +grub_disk_addr_t matchblk; +grub_uint64_t matchnblks; +grub_uint8_t matchhash[16 ];/* MD5 hash */ +} __packed; +struct grub_netbsd_btinfo_symtab {grub_uint32_t nsyms;
Quoted 1 line · Grégoire Sutre
+
grub_uint64_tbuf[(GRUB_DISK_SECTOR_SIZE + 7) / 8];
No need for + 7 since you know that GRUB_DISK_SECTOR_SIZE is divisible by 8. Other than this patch looks good. Go ahead (I assume that you checked that it works well with NetBSD)
Signature · 2 lines
Regards Vladimir 'φ-coder/phcoder' Serbinenko
Quoted 4 lines · Vladimir 'φ-coder/phcoder' Serbinenko
Quoted 1 line · Grégoire Sutre
+
grub_uint64_tbuf[(GRUB_DISK_SECTOR_SIZE + 7) / 8];No need for + 7 since you know that
GRUB_DISK_SECTOR_SIZEis divisible by 8. Other than this patch looks good. Go ahead
Thanks, committed.
Quoted 1 line
(I assume that you checked that it works well with NetBSD)
I made a number of tests, with various partitioning schemes, mainly with NetBSD -current, but I also made a few with the latest stable release.
Grégoire