From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1R8yMu-0004w8-Dr for mharc-grub-devel@gnu.org; Wed, 28 Sep 2011 13:56:28 -0400 Received: from eggs.gnu.org ([140.186.70.92]:44233) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R8yMr-0004vL-5P for grub-devel@gnu.org; Wed, 28 Sep 2011 13:56:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R8yMp-00015z-Te for grub-devel@gnu.org; Wed, 28 Sep 2011 13:56:25 -0400 Received: from mail-bw0-f41.google.com ([209.85.214.41]:64966) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R8yMp-00015o-KE for grub-devel@gnu.org; Wed, 28 Sep 2011 13:56:23 -0400 Received: by bkbzs2 with SMTP id zs2so9647509bkb.0 for ; Wed, 28 Sep 2011 10:56:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type; bh=DS2VYW3PRXqXcJVq2AIUUCkP62eXbfXo0CO7XgxGHLo=; b=qILx7+P70fo3sCucyNBdzYYjoHxdOoThs9CsY0Gv4nYBAq16Z7m4knX2sFaEnZ+wqg J9n4bXBxImc5q0yIqfYN07sYBGh72DOGk7Q4V95UoOBkoves8a8HpjjOrVfcHqflow8W GV/UKBmipxzJrnJbGr7yXCUOT/adV5azEMTH4= Received: by 10.204.155.90 with SMTP id r26mr3256604bkw.391.1317232582050; Wed, 28 Sep 2011 10:56:22 -0700 (PDT) Received: from [147.210.128.166] (laptop-147-210-128-166.labri.fr. [147.210.128.166]) by mx.google.com with ESMTPS id s13sm18909886bkb.11.2011.09.28.10.56.21 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 28 Sep 2011 10:56:21 -0700 (PDT) Message-ID: <4E835FC3.90307@gmail.com> Date: Wed, 28 Sep 2011 19:56:19 +0200 From: =?ISO-8859-1?Q?Gr=E9goire_Sutre?= User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.21) Gecko/20110831 Iceowl/1.0b2 Icedove/3.1.13 MIME-Version: 1.0 To: The development of GNU GRUB Subject: Re: [patch] Make knetbsd pass the root device References: <4E7920D0.3090401@gmail.com> In-Reply-To: <4E7920D0.3090401@gmail.com> Content-Type: multipart/mixed; boundary="------------030404060307050303000800" X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.214.41 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 28 Sep 2011 17:56:26 -0000 This is a multi-part message in MIME format. --------------030404060307050303000800 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit 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 --------------030404060307050303000800 Content-Type: text/x-patch; name="netbsd-btinfo_v2.diff" Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename="netbsd-btinfo_v2.diff" === modified file 'ChangeLog' --- ChangeLog 2011-09-28 14:43:00 +0000 +++ ChangeLog 2011-09-28 16:33:40 +0000 @@ -1,3 +1,15 @@ +2011-09-28 Grégoire Sutre + + * 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 * grub-core/loader/multiboot_elfxx.c (Elf_Shdr): Set according to === modified file 'grub-core/loader/i386/bsd.c' --- grub-core/loader/i386/bsd.c 2011-06-27 11:57:03 +0000 +++ grub-core/loader/i386/bsd.c 2011-09-28 16:16:06 +0000 @@ -33,6 +33,8 @@ #include #include #include +#include +#include GRUB_MOD_LICENSE ("GPLv3+"); @@ -946,6 +948,86 @@ grub_netbsd_add_modules (void) return err; } +/* + * Adds NetBSD bootinfo bootdisk and bootwedge. The partition identified + * in these bootinfo fields is the root device. + */ +static void +grub_netbsd_add_boot_disk_and_wedge (void) +{ + grub_device_t dev; + grub_disk_t disk; + grub_partition_t part; + grub_uint32_t biosdev; + grub_uint32_t partmapsector; + struct grub_partition_bsd_disk_label *label; + grub_uint64_t buf[(GRUB_DISK_SECTOR_SIZE + 7) / 8]; + grub_uint8_t *hash; + grub_uint64_t ctx[(GRUB_MD_MD5->contextsize + 7) / 8]; + + dev = grub_device_open (0); + if (! (dev && dev->disk && dev->disk->partition)) + goto fail; + + disk = dev->disk; + part = disk->partition; + + if (disk->dev && disk->dev->id == GRUB_DISK_DEVICE_BIOSDISK_ID) + biosdev = (grub_uint32_t) disk->id & 0xff; + else + biosdev = 0xff; + + /* Absolute sector of the partition map describing this partition. */ + partmapsector = grub_partition_get_start (part->parent) + part->offset; + + disk->partition = part->parent; + if (grub_disk_read (disk, part->offset, 0, GRUB_DISK_SECTOR_SIZE, buf) != GRUB_ERR_NONE) + goto fail; + disk->partition = part; + + /* Fill bootwedge. */ + { + struct grub_netbsd_btinfo_bootwedge biw; + + grub_memset (&biw, 0, sizeof (biw)); + biw.biosdev = biosdev; + biw.startblk = grub_partition_get_start (part); + biw.nblks = part->len; + biw.matchblk = partmapsector; + biw.matchnblks = 1; + + GRUB_MD_MD5->init (&ctx); + GRUB_MD_MD5->write (&ctx, buf, GRUB_DISK_SECTOR_SIZE); + GRUB_MD_MD5->final (&ctx); + hash = GRUB_MD_MD5->read (&ctx); + memcpy (biw.matchhash, hash, 16); + + grub_bsd_add_meta (NETBSD_BTINFO_BOOTWEDGE, &biw, sizeof (biw)); + } + + /* Fill bootdisk if this a NetBSD disk label. */ + label = (struct grub_partition_bsd_disk_label *) &buf; + if (part->partmap != NULL && + (grub_strcmp (part->partmap->name, "netbsd") == 0) && + label->magic == grub_cpu_to_le32 (GRUB_PC_PARTITION_BSD_LABEL_MAGIC)) + { + struct grub_netbsd_btinfo_bootdisk bid; + + grub_memset (&bid, 0, sizeof (bid)); + bid.labelsector = partmapsector; + bid.label.type = label->type; + bid.label.checksum = label->checksum; + memcpy (bid.label.packname, label->packname, 16); + bid.biosdev = biosdev; + bid.partition = part->number; + grub_bsd_add_meta (NETBSD_BTINFO_BOOTDISK, &bid, sizeof (bid)); + } + +fail: + if (dev) + grub_device_close (dev); +} + static grub_err_t grub_netbsd_boot (void) { @@ -1607,6 +1689,8 @@ grub_cmd_netbsd (grub_extcmd_context_t c grub_bsd_add_meta (NETBSD_BTINFO_CONSOLE, &cons, sizeof (cons)); } + grub_netbsd_add_boot_disk_and_wedge (); + grub_loader_set (grub_netbsd_boot, grub_bsd_unload, 0); } === modified file 'include/grub/bsdlabel.h' --- include/grub/bsdlabel.h 2010-07-16 23:57:48 +0000 +++ include/grub/bsdlabel.h 2011-09-28 15:06:02 +0000 @@ -80,7 +80,10 @@ struct grub_partition_bsd_entry struct 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' --- include/grub/i386/netbsd_bootinfo.h 2010-01-18 22:37:11 +0000 +++ include/grub/i386/netbsd_bootinfo.h 2011-09-28 15:06:02 +0000 @@ -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_bootdisk grub_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; --------------030404060307050303000800--