2 * Copyright (c) 1998 Robert Nordier
5 * Redistribution and use in source and binary forms are freely
6 * permitted provided that the above copyright notice and this
7 * paragraph and the following disclaimer are duplicated in all
10 * This software is provided "AS IS" and without any express or
11 * implied warranties, including, without limitation, the implied
12 * warranties of merchantability and fitness for a particular
16 #include <sys/cdefs.h>
17 __FBSDID("$FreeBSD$");
19 #include <sys/param.h>
20 #include <sys/errno.h>
21 #include <sys/diskmbr.h>
25 #include <sys/reboot.h>
26 #include <sys/queue.h>
28 #include <machine/bootinfo.h>
29 #include <machine/elf.h>
30 #include <machine/pc/bios.h>
54 #define BIOS_NUMDRIVES 0x475
60 #define TYPE_MAXHARD TYPE_DA
63 #define DEV_GELIBOOT_BSIZE 4096
68 static const uuid_t freebsd_zfs_uuid = GPT_ENT_TYPE_FREEBSD_ZFS;
70 static const char optstr[NOPT] = "DhaCcdgmnpqrsv"; /* Also 'P', 'S' */
71 static const unsigned char flags[NOPT] = {
89 static const unsigned char dev_maj[NDEV] = {30, 4, 2};
92 static char cmddup[512];
93 static char kname[1024];
94 static char rootname[256];
95 static int comspeed = SIOSPD;
96 static struct bootinfo bootinfo;
97 static uint32_t bootdev;
98 static struct zfs_boot_args zfsargs;
99 static struct zfsmount zfsmount;
101 vm_offset_t high_heap_base;
102 uint32_t bios_basemem, bios_extmem, high_heap_size;
104 static struct bios_smap smap;
107 * The minimum amount of memory to reserve in bios_extmem for the heap.
109 #define HEAP_MIN (64 * 1024 * 1024)
111 static char *heap_next;
112 static char *heap_end;
114 /* Buffers that must not span a 64k boundary. */
115 #define READ_BUF_SIZE 8192
117 char rdbuf[READ_BUF_SIZE]; /* for reading large things */
118 char secbuf[READ_BUF_SIZE]; /* for MBR/disklabel */
120 static struct dmadat *dmadat;
124 static void load(void);
125 static int parse_cmd(void);
126 static void bios_getmem(void);
127 void *malloc(size_t n);
128 void free(void *ptr);
135 if (p + n > heap_end) {
136 printf("malloc failure\n");
154 strdup(const char *s)
156 char *p = malloc(strlen(s) + 1);
161 #ifdef LOADER_GELI_SUPPORT
162 #include "geliboot.c"
163 static char gelipw[GELI_PW_MAXLEN];
164 static struct keybuf *gelibuf;
170 * Read from a dnode (which must be from a ZPL filesystem).
173 zfs_read(spa_t *spa, const dnode_phys_t *dnode, off_t *offp, void *start, size_t size)
175 const znode_phys_t *zp = (const znode_phys_t *) dnode->dn_bonus;
180 if (*offp + n > zp->zp_size)
181 n = zp->zp_size - *offp;
183 rc = dnode_read(spa, dnode, *offp, start, n);
195 static spa_t *primary_spa;
196 static vdev_t *primary_vdev;
199 * A wrapper for dskread that doesn't have to worry about whether the
200 * buffer pointer crosses a 64k boundary.
203 vdev_read(vdev_t *vdev, void *priv, off_t off, void *buf, size_t bytes)
206 daddr_t lba, alignlba;
208 unsigned int nb, alignnb;
209 struct dsk *dsk = (struct dsk *) priv;
211 if ((off & (DEV_BSIZE - 1)) || (bytes & (DEV_BSIZE - 1)))
215 lba = off / DEV_BSIZE;
218 * Align reads to 4k else 4k sector GELIs will not decrypt.
219 * Round LBA down to nearest multiple of DEV_GELIBOOT_BSIZE bytes.
221 alignlba = rounddown2(off, DEV_GELIBOOT_BSIZE) / DEV_BSIZE;
223 * The read must be aligned to DEV_GELIBOOT_BSIZE bytes relative to the
224 * start of the GELI partition, not the start of the actual disk.
226 alignlba += dsk->start;
227 diff = (lba - alignlba) * DEV_BSIZE;
230 nb = bytes / DEV_BSIZE;
232 * Ensure that the read size plus the leading offset does not
233 * exceed the size of the read buffer.
235 if (nb > (READ_BUF_SIZE - diff) / DEV_BSIZE)
236 nb = (READ_BUF_SIZE - diff) / DEV_BSIZE;
238 * Round the number of blocks to read up to the nearest multiple
239 * of DEV_GELIBOOT_BSIZE.
241 alignnb = roundup2(nb * DEV_BSIZE + diff, DEV_GELIBOOT_BSIZE)
244 if (drvread(dsk, dmadat->rdbuf, alignlba, alignnb))
246 #ifdef LOADER_GELI_SUPPORT
248 if (is_geli(dsk) == 0) {
249 if (geli_read(dsk, ((alignlba - dsk->start) *
250 DEV_BSIZE), dmadat->rdbuf, alignnb * DEV_BSIZE))
254 memcpy(p, dmadat->rdbuf + diff, nb * DEV_BSIZE);
258 bytes -= nb * DEV_BSIZE;
259 /* Don't need the leading offset after the first block. */
267 vdev_write(vdev_t *vdev, void *priv, off_t off, void *buf, size_t bytes)
272 struct dsk *dsk = (struct dsk *) priv;
274 if ((off & (DEV_BSIZE - 1)) || (bytes & (DEV_BSIZE - 1)))
278 lba = off / DEV_BSIZE;
281 nb = bytes / DEV_BSIZE;
282 if (nb > READ_BUF_SIZE / DEV_BSIZE)
283 nb = READ_BUF_SIZE / DEV_BSIZE;
284 memcpy(dmadat->rdbuf, p, nb * DEV_BSIZE);
285 if (drvwrite(dsk, dmadat->rdbuf, lba, nb))
289 bytes -= nb * DEV_BSIZE;
296 xfsread(const dnode_phys_t *dnode, off_t *offp, void *buf, size_t nbyte)
298 if ((size_t)zfs_read(spa, dnode, offp, buf, nbyte) != nbyte) {
299 printf("Invalid format\n");
306 * Read Pad2 (formerly "Boot Block Header") area of the first
307 * vdev label of the given vdev.
310 vdev_read_pad2(vdev_t *vdev, char *buf, size_t size)
313 char *tmp = zap_scratch;
314 off_t off = offsetof(vdev_label_t, vl_pad2);
316 if (size > VDEV_PAD_SIZE)
317 size = VDEV_PAD_SIZE;
320 BP_SET_LSIZE(&bp, VDEV_PAD_SIZE);
321 BP_SET_PSIZE(&bp, VDEV_PAD_SIZE);
322 BP_SET_CHECKSUM(&bp, ZIO_CHECKSUM_LABEL);
323 BP_SET_COMPRESS(&bp, ZIO_COMPRESS_OFF);
324 DVA_SET_OFFSET(BP_IDENTITY(&bp), off);
325 if (vdev_read_phys(vdev, &bp, tmp, off, 0))
327 memcpy(buf, tmp, size);
332 vdev_clear_pad2(vdev_t *vdev)
334 char *zeroes = zap_scratch;
336 off_t off = offsetof(vdev_label_t, vl_pad2);
338 memset(zeroes, 0, VDEV_PAD_SIZE);
339 end = (uint64_t *)(zeroes + VDEV_PAD_SIZE);
340 /* ZIO_CHECKSUM_LABEL magic and pre-calcualted checksum for all zeros */
341 end[-5] = 0x0210da7ab10c7a11;
342 end[-4] = 0x97f48f807f6e2a3f;
343 end[-3] = 0xaf909f1658aacefc;
344 end[-2] = 0xcbd1ea57ff6db48b;
345 end[-1] = 0x6ec692db0d465fab;
346 if (vdev_write(vdev, vdev->v_read_priv, off, zeroes, VDEV_PAD_SIZE))
356 /* Parse system memory map */
360 v86.addr = 0x15; /* int 0x15 function 0xe820*/
362 v86.ecx = sizeof(struct bios_smap);
364 v86.es = VTOPSEG(&smap);
365 v86.edi = VTOPOFF(&smap);
367 if (V86_CY(v86.efl) || (v86.eax != SMAP_SIG))
369 /* look for a low-memory segment that's large enough */
370 if ((smap.type == SMAP_TYPE_MEMORY) && (smap.base == 0) &&
371 (smap.length >= (512 * 1024)))
372 bios_basemem = smap.length;
373 /* look for the first segment in 'extended' memory */
374 if ((smap.type == SMAP_TYPE_MEMORY) && (smap.base == 0x100000)) {
375 bios_extmem = smap.length;
379 * Look for the largest segment in 'extended' memory beyond
382 if ((smap.type == SMAP_TYPE_MEMORY) && (smap.base > 0x100000) &&
383 (smap.base < 0x100000000ull)) {
387 * If this segment crosses the 4GB boundary, truncate it.
389 if (smap.base + size > 0x100000000ull)
390 size = 0x100000000ull - smap.base;
392 if (size > high_heap_size) {
393 high_heap_size = size;
394 high_heap_base = smap.base;
397 } while (v86.ebx != 0);
399 /* Fall back to the old compatibility function for base memory */
400 if (bios_basemem == 0) {
402 v86.addr = 0x12; /* int 0x12 */
405 bios_basemem = (v86.eax & 0xffff) * 1024;
408 /* Fall back through several compatibility functions for extended memory */
409 if (bios_extmem == 0) {
411 v86.addr = 0x15; /* int 0x15 function 0xe801*/
414 if (!V86_CY(v86.efl)) {
415 bios_extmem = ((v86.ecx & 0xffff) + ((v86.edx & 0xffff) * 64)) * 1024;
418 if (bios_extmem == 0) {
420 v86.addr = 0x15; /* int 0x15 function 0x88*/
423 bios_extmem = (v86.eax & 0xffff) * 1024;
427 * If we have extended memory and did not find a suitable heap
428 * region in the SMAP, use the last 3MB of 'extended' memory as a
429 * high heap candidate.
431 if (bios_extmem >= HEAP_MIN && high_heap_size < HEAP_MIN) {
432 high_heap_size = HEAP_MIN;
433 high_heap_base = bios_extmem + 0x100000 - HEAP_MIN;
438 * Try to detect a device supported by the legacy int13 BIOS
441 int13probe(int drive)
449 if (!V86_CY(v86.efl) && /* carry clear */
450 ((v86.edx & 0xff) != (drive & DRV_MASK))) { /* unit # OK */
451 if ((v86.ecx & 0x3f) == 0) { /* absurd sector size */
452 return(0); /* skip device */
460 * We call this when we find a ZFS vdev - ZFS consumes the dsk
461 * structure so we must make a new one.
464 copy_dsk(struct dsk *dsk)
468 newdsk = malloc(sizeof(struct dsk));
474 * Get disk size from eax=0x800 and 0x4800. We need to probe both
475 * because 0x4800 may not be available and we would like to get more
476 * or less correct disk size - if it is possible at all.
477 * Note we do not really want to touch drv.c because that code is shared
478 * with boot2 and we can not afford to grow that code.
481 drvsize_ext(struct dsk *dskp)
489 v86.edx = dskp->drive;
492 /* Don't error out if we get bad sector number, try EDD as well */
493 if (V86_CY(v86.efl) || /* carry set */
494 (v86.edx & 0xff) <= (unsigned)(dskp->drive & 0x7f)) /* unit # bad */
497 cyl = ((v86.ecx & 0xc0) << 2) + ((v86.ecx & 0xff00) >> 8) + 1;
498 /* Convert max head # -> # of heads */
499 hds = ((v86.edx & 0xff00) >> 8) + 1;
500 sec = v86.ecx & 0x3f;
502 size = (uint64_t)cyl * hds * sec;
504 /* Determine if we can use EDD with this device. */
508 v86.edx = dskp->drive;
511 if (V86_CY(v86.efl) || /* carry set */
512 (v86.ebx & 0xffff) != 0xaa55 || /* signature */
513 (v86.ecx & EDD_INTERFACE_FIXED_DISK) == 0)
524 * The "layered" ioctl to read disk/partition size. Unfortunately
525 * the zfsboot case is hardest, because we do not have full software
526 * stack available, so we need to do some manual work here.
529 ldi_get_size(void *priv)
531 struct dsk *dskp = priv;
532 uint64_t size = dskp->size;
534 if (dskp->start == 0)
535 size = drvsize_ext(dskp);
537 return (size * DEV_BSIZE);
541 probe_drive(struct dsk *dsk)
546 unsigned part, entries_per_sec;
549 #if defined(GPT) || defined(LOADER_GELI_SUPPORT)
553 struct dos_partition *dp;
558 * If we find a vdev on the whole disk, stop here.
560 if (vdev_probe(vdev_read, dsk, NULL) == 0)
563 #ifdef LOADER_GELI_SUPPORT
565 * Taste the disk, if it is GELI encrypted, decrypt it and check to see if
566 * it is a usable vdev then. Otherwise dig
567 * out the partition table and probe each slice/partition
568 * in turn for a vdev or GELI encrypted vdev.
570 elba = drvsize_ext(dsk);
574 if (geli_taste(vdev_read, dsk, elba) == 0) {
575 if (geli_havekey(dsk) == 0 || geli_passphrase(&gelipw, dsk->unit,
577 if (vdev_probe(vdev_read, dsk, NULL) == 0) {
582 #endif /* LOADER_GELI_SUPPORT */
584 sec = dmadat->secbuf;
589 * First check for GPT.
591 if (drvread(dsk, sec, 1, 1)) {
594 memcpy(&hdr, sec, sizeof(hdr));
595 if (memcmp(hdr.hdr_sig, GPT_HDR_SIG, sizeof(hdr.hdr_sig)) != 0 ||
596 hdr.hdr_lba_self != 1 || hdr.hdr_revision < 0x00010000 ||
597 hdr.hdr_entsz < sizeof(*ent) || DEV_BSIZE % hdr.hdr_entsz != 0) {
602 * Probe all GPT partitions for the presence of ZFS pools. We
603 * return the spa_t for the first we find (if requested). This
604 * will have the effect of booting from the first pool on the
607 * If no vdev is found, GELI decrypting the device and try again
609 entries_per_sec = DEV_BSIZE / hdr.hdr_entsz;
610 slba = hdr.hdr_lba_table;
611 elba = slba + hdr.hdr_entries / entries_per_sec;
612 while (slba < elba) {
614 if (drvread(dsk, sec, slba, 1))
616 for (part = 0; part < entries_per_sec; part++) {
617 ent = (struct gpt_ent *)(sec + part * hdr.hdr_entsz);
618 if (memcmp(&ent->ent_type, &freebsd_zfs_uuid,
619 sizeof(uuid_t)) == 0) {
620 dsk->start = ent->ent_lba_start;
621 dsk->size = ent->ent_lba_end - ent->ent_lba_start + 1;
622 dsk->slice = part + 1;
624 if (vdev_probe(vdev_read, dsk, NULL) == 0) {
626 * This slice had a vdev. We need a new dsk
627 * structure now since the vdev now owns this one.
631 #ifdef LOADER_GELI_SUPPORT
632 else if (geli_taste(vdev_read, dsk, ent->ent_lba_end -
633 ent->ent_lba_start) == 0) {
634 if (geli_havekey(dsk) == 0 || geli_passphrase(&gelipw,
635 dsk->unit, 'p', dsk->slice, dsk) == 0) {
637 * This slice has GELI, check it for ZFS.
639 if (vdev_probe(vdev_read, dsk, NULL) == 0) {
641 * This slice had a vdev. We need a new dsk
642 * structure now since the vdev now owns this one.
649 #endif /* LOADER_GELI_SUPPORT */
658 if (drvread(dsk, sec, DOSBBSECTOR, 1))
660 dp = (void *)(sec + DOSPARTOFF);
662 for (i = 0; i < NDOSPART; i++) {
665 dsk->start = dp[i].dp_start;
666 dsk->size = dp[i].dp_size;
668 if (vdev_probe(vdev_read, dsk, NULL) == 0) {
671 #ifdef LOADER_GELI_SUPPORT
672 else if (geli_taste(vdev_read, dsk, dp[i].dp_size -
673 dp[i].dp_start) == 0) {
674 if (geli_havekey(dsk) == 0 || geli_passphrase(&gelipw, dsk->unit,
677 * This slice has GELI, check it for ZFS.
679 if (vdev_probe(vdev_read, dsk, NULL) == 0) {
681 * This slice had a vdev. We need a new dsk
682 * structure now since the vdev now owns this one.
689 #endif /* LOADER_GELI_SUPPORT */
703 dmadat = (void *)(roundup2(__base + (int32_t)&_end, 0x10000) - __base);
707 if (high_heap_size > 0) {
708 heap_end = PTOV(high_heap_base + high_heap_size);
709 heap_next = PTOV(high_heap_base);
711 heap_next = (char *)dmadat + sizeof(*dmadat);
712 heap_end = (char *)PTOV(bios_basemem);
715 dsk = malloc(sizeof(struct dsk));
716 dsk->drive = *(uint8_t *)PTOV(ARGS);
717 dsk->type = dsk->drive & DRV_HARD ? TYPE_AD : TYPE_FD;
718 dsk->unit = dsk->drive & DRV_MASK;
719 dsk->slice = *(uint8_t *)PTOV(ARGS + 1) + 1;
724 bootinfo.bi_version = BOOTINFO_VERSION;
725 bootinfo.bi_size = sizeof(bootinfo);
726 bootinfo.bi_basemem = bios_basemem / 1024;
727 bootinfo.bi_extmem = bios_extmem / 1024;
728 bootinfo.bi_memsizes_valid++;
729 bootinfo.bi_bios_dev = dsk->drive;
731 bootdev = MAKEBOOTDEV(dev_maj[dsk->type],
732 dsk->slice, dsk->unit, dsk->part);
734 /* Process configuration file */
738 #ifdef LOADER_GELI_SUPPORT
744 * Probe the boot drive first - we will try to boot from whatever
745 * pool we find on that drive.
750 * Probe the rest of the drives that the bios knows about. This
751 * will find any other available pools and it may fill in missing
752 * vdevs for the boot pool.
755 for (i = 0; i < *(unsigned char *)PTOV(BIOS_NUMDRIVES); i++)
757 for (i = 0; i < MAXBDDEV; i++)
760 if ((i | DRV_HARD) == *(uint8_t *)PTOV(ARGS))
763 if (!int13probe(i | DRV_HARD))
766 dsk = malloc(sizeof(struct dsk));
767 dsk->drive = i | DRV_HARD;
768 dsk->type = dsk->drive & TYPE_AD;
778 * The first discovered pool, if any, is the pool.
780 spa = spa_get_primary();
782 printf("%s: No ZFS pools located, can't boot\n", BOOTPROG);
788 primary_vdev = spa_get_primary_vdev(spa);
791 rc = vdev_read_pad2(primary_vdev, cmd, sizeof(cmd));
792 if (vdev_clear_pad2(primary_vdev))
793 printf("failed to clear pad2 area of primary vdev\n");
797 * We could find an old-style ZFS Boot Block header here.
800 if (*(uint64_t *)cmd != 0x2f5b007b10c) {
802 * Note that parse() is destructive to cmd[] and we also want
803 * to honor RBX_QUIET option that could be present in cmd[].
806 memcpy(cmddup, cmd, sizeof(cmd));
808 printf("failed to parse pad2 area of primary vdev\n");
811 if (!OPT_CHECK(RBX_QUIET))
812 printf("zfs nextboot: %s\n", cmddup);
814 /* Do not process this command twice */
818 printf("failed to read pad2 area of primary vdev\n");
820 /* Mount ZFS only if it's not already mounted via nextboot parsing. */
821 if (zfsmount.spa == NULL &&
822 (zfs_spa_init(spa) != 0 || zfs_mount(spa, 0, &zfsmount) != 0)) {
823 printf("%s: failed to mount default pool %s\n",
824 BOOTPROG, spa->spa_name);
826 } else if (zfs_lookup(&zfsmount, PATH_CONFIG, &dn) == 0 ||
827 zfs_lookup(&zfsmount, PATH_DOTCONFIG, &dn) == 0) {
829 zfs_read(spa, &dn, &off, cmd, sizeof(cmd));
834 * Note that parse_cmd() is destructive to cmd[] and we also want
835 * to honor RBX_QUIET option that could be present in cmd[].
837 memcpy(cmddup, cmd, sizeof(cmd));
840 if (!OPT_CHECK(RBX_QUIET))
841 printf("%s: %s\n", PATH_CONFIG, cmddup);
842 /* Do not process this command twice */
846 /* Do not risk waiting at the prompt forever. */
847 if (nextboot && !autoboot)
851 * Try to exec /boot/loader. If interrupted by a keypress,
852 * or in case of failure, try to load a kernel directly instead.
855 if (autoboot && !*kname) {
856 memcpy(kname, PATH_LOADER_ZFS, sizeof(PATH_LOADER_ZFS));
859 memcpy(kname, PATH_KERNEL, sizeof(PATH_KERNEL));
863 /* Present the user with the boot2 prompt. */
866 if (!autoboot || !OPT_CHECK(RBX_QUIET)) {
867 printf("\nFreeBSD/x86 boot\n");
868 if (zfs_rlookup(spa, zfsmount.rootobj, rootname) != 0)
869 printf("Default: %s/<0x%llx>:%s\n"
871 spa->spa_name, zfsmount.rootobj, kname);
872 else if (rootname[0] != '\0')
873 printf("Default: %s/%s:%s\n"
875 spa->spa_name, rootname, kname);
877 printf("Default: %s:%s\n"
879 spa->spa_name, kname);
881 if (ioctrl & IO_SERIAL)
883 if (!autoboot || keyhit(5))
884 getstr(cmd, sizeof(cmd));
885 else if (!autoboot || !OPT_CHECK(RBX_QUIET))
895 /* XXX - Needed for btxld to link the boot2 binary; do not remove. */
915 static Elf32_Phdr ep[2];
916 static Elf32_Shdr es[2];
923 if (zfs_lookup(&zfsmount, kname, &dn)) {
924 printf("\nCan't find %s\n", kname);
928 if (xfsread(&dn, &off, &hdr, sizeof(hdr)))
930 if (N_GETMAGIC(hdr.ex) == ZMAGIC)
932 else if (IS_ELF(hdr.eh))
935 printf("Invalid %s\n", "format");
939 addr = hdr.ex.a_entry & 0xffffff;
942 if (xfsread(&dn, &off, p, hdr.ex.a_text))
944 p += roundup2(hdr.ex.a_text, PAGE_SIZE);
945 if (xfsread(&dn, &off, p, hdr.ex.a_data))
947 p += hdr.ex.a_data + roundup2(hdr.ex.a_bss, PAGE_SIZE);
948 bootinfo.bi_symtab = VTOP(p);
949 memcpy(p, &hdr.ex.a_syms, sizeof(hdr.ex.a_syms));
950 p += sizeof(hdr.ex.a_syms);
952 if (xfsread(&dn, &off, p, hdr.ex.a_syms))
955 if (xfsread(&dn, &off, p, sizeof(int)))
960 if (xfsread(&dn, &off, p, x))
965 off = hdr.eh.e_phoff;
966 for (j = i = 0; i < hdr.eh.e_phnum && j < 2; i++) {
967 if (xfsread(&dn, &off, ep + j, sizeof(ep[0])))
969 if (ep[j].p_type == PT_LOAD)
972 for (i = 0; i < 2; i++) {
973 p = PTOV(ep[i].p_paddr & 0xffffff);
974 off = ep[i].p_offset;
975 if (xfsread(&dn, &off, p, ep[i].p_filesz))
978 p += roundup2(ep[1].p_memsz, PAGE_SIZE);
979 bootinfo.bi_symtab = VTOP(p);
980 if (hdr.eh.e_shnum == hdr.eh.e_shstrndx + 3) {
981 off = hdr.eh.e_shoff + sizeof(es[0]) *
982 (hdr.eh.e_shstrndx + 1);
983 if (xfsread(&dn, &off, &es, sizeof(es)))
985 for (i = 0; i < 2; i++) {
986 memcpy(p, &es[i].sh_size, sizeof(es[i].sh_size));
987 p += sizeof(es[i].sh_size);
988 off = es[i].sh_offset;
989 if (xfsread(&dn, &off, p, es[i].sh_size))
994 addr = hdr.eh.e_entry & 0xffffff;
996 bootinfo.bi_esymtab = VTOP(p);
997 bootinfo.bi_kernelname = VTOP(kname);
998 zfsargs.size = sizeof(zfsargs);
999 zfsargs.pool = zfsmount.spa->spa_guid;
1000 zfsargs.root = zfsmount.rootobj;
1001 zfsargs.primary_pool = primary_spa->spa_guid;
1002 #ifdef LOADER_GELI_SUPPORT
1003 explicit_bzero(gelipw, sizeof(gelipw));
1004 gelibuf = malloc(sizeof(struct keybuf) + (GELI_MAX_KEYS * sizeof(struct keybuf_ent)));
1005 geli_fill_keybuf(gelibuf);
1006 zfsargs.notapw = '\0';
1007 zfsargs.keybuf_sentinel = KEYBUF_SENTINEL;
1008 zfsargs.keybuf = gelibuf;
1010 zfsargs.gelipw[0] = '\0';
1012 if (primary_vdev != NULL)
1013 zfsargs.primary_vdev = primary_vdev->v_guid;
1015 printf("failed to detect primary vdev\n");
1016 __exec((caddr_t)addr, RB_BOOTINFO | (opts & RBX_MASK),
1018 KARGS_FLAGS_ZFS | KARGS_FLAGS_EXTARG,
1019 (uint32_t) spa->spa_guid,
1020 (uint32_t) (spa->spa_guid >> 32),
1026 zfs_mount_ds(char *dsname)
1032 q = strchr(dsname, '/');
1035 newspa = spa_find_by_name(dsname);
1036 if (newspa == NULL) {
1037 printf("\nCan't find ZFS pool %s\n", dsname);
1041 if (zfs_spa_init(newspa))
1046 if (zfs_lookup_dataset(newspa, q, &newroot)) {
1047 printf("\nCan't find dataset %s in ZFS pool %s\n",
1048 q, newspa->spa_name);
1052 if (zfs_mount(newspa, newroot, &zfsmount)) {
1053 printf("\nCan't mount ZFS dataset\n");
1068 while ((c = *arg++)) {
1069 if (c == ' ' || c == '\t' || c == '\n')
1071 for (p = arg; *p && *p != '\n' && *p != ' ' && *p != '\t'; p++);
1076 while ((c = *arg++)) {
1078 if (*(uint8_t *)PTOV(0x496) & 0x10) {
1081 opts |= OPT_SET(RBX_DUAL) | OPT_SET(RBX_SERIAL);
1084 printf("Keyboard: %s\n", cp);
1086 } else if (c == 'S') {
1088 while ((unsigned int)(i = *arg++ - '0') <= 9)
1090 if (j > 0 && i == -'0') {
1094 /* Fall through to error below ('S' not in optstr[]). */
1096 for (i = 0; c != optstr[i]; i++)
1099 opts ^= OPT_SET(flags[i]);
1101 ioctrl = OPT_CHECK(RBX_DUAL) ? (IO_SERIAL|IO_KEYBOARD) :
1102 OPT_CHECK(RBX_SERIAL) ? IO_SERIAL : IO_KEYBOARD;
1103 if (ioctrl & IO_SERIAL) {
1104 if (sio_init(115200 / comspeed) != 0)
1105 ioctrl &= ~IO_SERIAL;
1110 if (zfs_lookup(&zfsmount, arg, &dn) == 0) {
1118 * Report pool status if the comment is 'status'. Lets
1119 * hope no-one wants to load /status as a kernel.
1121 if (!strcmp(arg, "status")) {
1127 * If there is "zfs:" prefix simply ignore it.
1129 if (strncmp(arg, "zfs:", 4) == 0)
1133 * If there is a colon, switch pools.
1135 q = strchr(arg, ':');
1138 if (zfs_mount_ds(arg) != 0)
1142 if ((i = ep - arg)) {
1143 if ((size_t)i >= sizeof(kname))
1145 memcpy(kname, arg, i + 1);