Make knetbsd pass bootinfo bootdisk and bootwedge.
This commit is contained in:
parent
91a1a164d6
commit
e0b0dc837b
4 changed files with 111 additions and 1 deletions
|
@ -33,6 +33,8 @@
|
|||
#include <grub/extcmd.h>
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/ns8250.h>
|
||||
#include <grub/bsdlabel.h>
|
||||
#include <grub/crypto.h>
|
||||
|
||||
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 / 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 ctxt, int argc, char *argv[])
|
|||
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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue