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$");
21 #include <sys/param.h>
22 #include <sys/errno.h>
23 #include <sys/diskmbr.h>
27 #include <sys/reboot.h>
28 #include <sys/queue.h>
30 #include <machine/bootinfo.h>
31 #include <machine/elf.h>
32 #include <machine/pc/bios.h>
55 #define BIOS_NUMDRIVES 0x475
61 #define TYPE_MAXHARD TYPE_DA
64 #define DEV_GELIBOOT_BSIZE 4096
69 static const uuid_t freebsd_zfs_uuid = GPT_ENT_TYPE_FREEBSD_ZFS;
71 static const char optstr[NOPT] = "DhaCcdgmnpqrsv"; /* Also 'P', 'S' */
72 static const unsigned char flags[NOPT] = {
90 static const unsigned char dev_maj[NDEV] = {30, 4, 2};
93 static char cmddup[512];
94 static char kname[1024];
95 static char rootname[256];
96 static int comspeed = SIOSPD;
97 static struct bootinfo bootinfo;
98 static uint32_t bootdev;
99 static struct zfs_boot_args zfsargs;
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);
129 #ifdef LOADER_GELI_SUPPORT
130 #include "geliboot.c"
131 static char gelipw[GELI_PW_MAXLEN];
132 static struct keybuf *gelibuf;
138 * Read from a dnode (which must be from a ZPL filesystem).
141 zfs_read(spa_t *spa, const dnode_phys_t *dnode, off_t *offp, void *start, size_t size)
143 const znode_phys_t *zp = (const znode_phys_t *) dnode->dn_bonus;
148 if (*offp + n > zp->zp_size)
149 n = zp->zp_size - *offp;
151 rc = dnode_read(spa, dnode, *offp, start, n);
163 static spa_t *primary_spa;
164 static vdev_t *primary_vdev;
167 * A wrapper for dskread that doesn't have to worry about whether the
168 * buffer pointer crosses a 64k boundary.
171 vdev_read(void *xvdev, void *priv, off_t off, void *buf, size_t bytes)
174 daddr_t lba, alignlba;
176 unsigned int nb, alignnb;
177 struct dsk *dsk = (struct dsk *) priv;
179 if ((off & (DEV_BSIZE - 1)) || (bytes & (DEV_BSIZE - 1)))
183 lba = off / DEV_BSIZE;
186 * Align reads to 4k else 4k sector GELIs will not decrypt.
187 * Round LBA down to nearest multiple of DEV_GELIBOOT_BSIZE bytes.
189 alignlba = rounddown2(off, DEV_GELIBOOT_BSIZE) / DEV_BSIZE;
191 * The read must be aligned to DEV_GELIBOOT_BSIZE bytes relative to the
192 * start of the GELI partition, not the start of the actual disk.
194 alignlba += dsk->start;
195 diff = (lba - alignlba) * DEV_BSIZE;
198 nb = bytes / DEV_BSIZE;
200 * Ensure that the read size plus the leading offset does not
201 * exceed the size of the read buffer.
203 if (nb > (READ_BUF_SIZE - diff) / DEV_BSIZE)
204 nb = (READ_BUF_SIZE - diff) / DEV_BSIZE;
206 * Round the number of blocks to read up to the nearest multiple
207 * of DEV_GELIBOOT_BSIZE.
209 alignnb = roundup2(nb * DEV_BSIZE + diff, DEV_GELIBOOT_BSIZE)
212 if (drvread(dsk, dmadat->rdbuf, alignlba, alignnb))
214 #ifdef LOADER_GELI_SUPPORT
216 if (is_geli(dsk) == 0) {
217 if (geli_read(dsk, ((alignlba - dsk->start) *
218 DEV_BSIZE), dmadat->rdbuf, alignnb * DEV_BSIZE))
222 memcpy(p, dmadat->rdbuf + diff, nb * DEV_BSIZE);
226 bytes -= nb * DEV_BSIZE;
227 /* Don't need the leading offset after the first block. */
233 /* Match the signature exactly due to signature madness */
235 vdev_read2(vdev_t *vdev, void *priv, off_t off, void *buf, size_t bytes)
237 return vdev_read(vdev, priv, off, buf, bytes);
242 vdev_write(vdev_t *vdev, void *priv, off_t off, void *buf, size_t bytes)
247 struct dsk *dsk = (struct dsk *) priv;
249 if ((off & (DEV_BSIZE - 1)) || (bytes & (DEV_BSIZE - 1)))
253 lba = off / DEV_BSIZE;
256 nb = bytes / DEV_BSIZE;
257 if (nb > READ_BUF_SIZE / DEV_BSIZE)
258 nb = READ_BUF_SIZE / DEV_BSIZE;
259 memcpy(dmadat->rdbuf, p, nb * DEV_BSIZE);
260 if (drvwrite(dsk, dmadat->rdbuf, lba, nb))
264 bytes -= nb * DEV_BSIZE;
271 xfsread(const dnode_phys_t *dnode, off_t *offp, void *buf, size_t nbyte)
273 if ((size_t)zfs_read(spa, dnode, offp, buf, nbyte) != nbyte) {
274 printf("Invalid format\n");
281 * Read Pad2 (formerly "Boot Block Header") area of the first
282 * vdev label of the given vdev.
285 vdev_read_pad2(vdev_t *vdev, char *buf, size_t size)
288 char *tmp = zap_scratch;
289 off_t off = offsetof(vdev_label_t, vl_pad2);
291 if (size > VDEV_PAD_SIZE)
292 size = VDEV_PAD_SIZE;
295 BP_SET_LSIZE(&bp, VDEV_PAD_SIZE);
296 BP_SET_PSIZE(&bp, VDEV_PAD_SIZE);
297 BP_SET_CHECKSUM(&bp, ZIO_CHECKSUM_LABEL);
298 BP_SET_COMPRESS(&bp, ZIO_COMPRESS_OFF);
299 DVA_SET_OFFSET(BP_IDENTITY(&bp), off);
300 if (vdev_read_phys(vdev, &bp, tmp, off, 0))
302 memcpy(buf, tmp, size);
307 vdev_clear_pad2(vdev_t *vdev)
309 char *zeroes = zap_scratch;
311 off_t off = offsetof(vdev_label_t, vl_pad2);
313 memset(zeroes, 0, VDEV_PAD_SIZE);
314 end = (uint64_t *)(zeroes + VDEV_PAD_SIZE);
315 /* ZIO_CHECKSUM_LABEL magic and pre-calcualted checksum for all zeros */
316 end[-5] = 0x0210da7ab10c7a11;
317 end[-4] = 0x97f48f807f6e2a3f;
318 end[-3] = 0xaf909f1658aacefc;
319 end[-2] = 0xcbd1ea57ff6db48b;
320 end[-1] = 0x6ec692db0d465fab;
321 if (vdev_write(vdev, vdev->v_read_priv, off, zeroes, VDEV_PAD_SIZE))
331 /* Parse system memory map */
335 v86.addr = 0x15; /* int 0x15 function 0xe820*/
337 v86.ecx = sizeof(struct bios_smap);
339 v86.es = VTOPSEG(&smap);
340 v86.edi = VTOPOFF(&smap);
342 if (V86_CY(v86.efl) || (v86.eax != SMAP_SIG))
344 /* look for a low-memory segment that's large enough */
345 if ((smap.type == SMAP_TYPE_MEMORY) && (smap.base == 0) &&
346 (smap.length >= (512 * 1024)))
347 bios_basemem = smap.length;
348 /* look for the first segment in 'extended' memory */
349 if ((smap.type == SMAP_TYPE_MEMORY) && (smap.base == 0x100000)) {
350 bios_extmem = smap.length;
354 * Look for the largest segment in 'extended' memory beyond
357 if ((smap.type == SMAP_TYPE_MEMORY) && (smap.base > 0x100000) &&
358 (smap.base < 0x100000000ull)) {
362 * If this segment crosses the 4GB boundary, truncate it.
364 if (smap.base + size > 0x100000000ull)
365 size = 0x100000000ull - smap.base;
367 if (size > high_heap_size) {
368 high_heap_size = size;
369 high_heap_base = smap.base;
372 } while (v86.ebx != 0);
374 /* Fall back to the old compatibility function for base memory */
375 if (bios_basemem == 0) {
377 v86.addr = 0x12; /* int 0x12 */
380 bios_basemem = (v86.eax & 0xffff) * 1024;
383 /* Fall back through several compatibility functions for extended memory */
384 if (bios_extmem == 0) {
386 v86.addr = 0x15; /* int 0x15 function 0xe801*/
389 if (!V86_CY(v86.efl)) {
390 bios_extmem = ((v86.ecx & 0xffff) + ((v86.edx & 0xffff) * 64)) * 1024;
393 if (bios_extmem == 0) {
395 v86.addr = 0x15; /* int 0x15 function 0x88*/
398 bios_extmem = (v86.eax & 0xffff) * 1024;
402 * If we have extended memory and did not find a suitable heap
403 * region in the SMAP, use the last 3MB of 'extended' memory as a
404 * high heap candidate.
406 if (bios_extmem >= HEAP_MIN && high_heap_size < HEAP_MIN) {
407 high_heap_size = HEAP_MIN;
408 high_heap_base = bios_extmem + 0x100000 - HEAP_MIN;
413 * Try to detect a device supported by the legacy int13 BIOS
416 int13probe(int drive)
424 if (!V86_CY(v86.efl) && /* carry clear */
425 ((v86.edx & 0xff) != (drive & DRV_MASK))) { /* unit # OK */
426 if ((v86.ecx & 0x3f) == 0) { /* absurd sector size */
427 return(0); /* skip device */
435 * We call this when we find a ZFS vdev - ZFS consumes the dsk
436 * structure so we must make a new one.
439 copy_dsk(struct dsk *dsk)
443 newdsk = malloc(sizeof(struct dsk));
449 * Get disk size from eax=0x800 and 0x4800. We need to probe both
450 * because 0x4800 may not be available and we would like to get more
451 * or less correct disk size - if it is possible at all.
452 * Note we do not really want to touch drv.c because that code is shared
453 * with boot2 and we can not afford to grow that code.
456 drvsize_ext(struct dsk *dskp)
464 v86.edx = dskp->drive;
467 /* Don't error out if we get bad sector number, try EDD as well */
468 if (V86_CY(v86.efl) || /* carry set */
469 (v86.edx & 0xff) <= (unsigned)(dskp->drive & 0x7f)) /* unit # bad */
471 cyl = ((v86.ecx & 0xc0) << 2) + ((v86.ecx & 0xff00) >> 8) + 1;
472 /* Convert max head # -> # of heads */
473 hds = ((v86.edx & 0xff00) >> 8) + 1;
474 sec = v86.ecx & 0x3f;
476 size = (uint64_t)cyl * hds * sec;
478 /* Determine if we can use EDD with this device. */
482 v86.edx = dskp->drive;
485 if (V86_CY(v86.efl) || /* carry set */
486 (v86.ebx & 0xffff) != 0xaa55 || /* signature */
487 (v86.ecx & EDD_INTERFACE_FIXED_DISK) == 0)
498 * The "layered" ioctl to read disk/partition size. Unfortunately
499 * the zfsboot case is hardest, because we do not have full software
500 * stack available, so we need to do some manual work here.
503 ldi_get_size(void *priv)
505 struct dsk *dskp = priv;
506 uint64_t size = dskp->size;
508 if (dskp->start == 0)
509 size = drvsize_ext(dskp);
511 return (size * DEV_BSIZE);
515 probe_drive(struct dsk *dsk)
520 unsigned part, entries_per_sec;
523 #if defined(GPT) || defined(LOADER_GELI_SUPPORT)
527 struct dos_partition *dp;
532 * If we find a vdev on the whole disk, stop here.
534 if (vdev_probe(vdev_read2, dsk, NULL) == 0)
537 #ifdef LOADER_GELI_SUPPORT
539 * Taste the disk, if it is GELI encrypted, decrypt it and check to see if
540 * it is a usable vdev then. Otherwise dig
541 * out the partition table and probe each slice/partition
542 * in turn for a vdev or GELI encrypted vdev.
544 elba = drvsize_ext(dsk);
548 if (geli_taste(vdev_read, dsk, elba) == 0) {
549 if (geli_havekey(dsk) == 0 || geli_passphrase(gelipw, dsk->unit,
551 if (vdev_probe(vdev_read2, dsk, NULL) == 0) {
556 #endif /* LOADER_GELI_SUPPORT */
558 sec = dmadat->secbuf;
563 * First check for GPT.
565 if (drvread(dsk, sec, 1, 1)) {
568 memcpy(&hdr, sec, sizeof(hdr));
569 if (memcmp(hdr.hdr_sig, GPT_HDR_SIG, sizeof(hdr.hdr_sig)) != 0 ||
570 hdr.hdr_lba_self != 1 || hdr.hdr_revision < 0x00010000 ||
571 hdr.hdr_entsz < sizeof(*ent) || DEV_BSIZE % hdr.hdr_entsz != 0) {
576 * Probe all GPT partitions for the presence of ZFS pools. We
577 * return the spa_t for the first we find (if requested). This
578 * will have the effect of booting from the first pool on the
581 * If no vdev is found, GELI decrypting the device and try again
583 entries_per_sec = DEV_BSIZE / hdr.hdr_entsz;
584 slba = hdr.hdr_lba_table;
585 elba = slba + hdr.hdr_entries / entries_per_sec;
586 while (slba < elba) {
588 if (drvread(dsk, sec, slba, 1))
590 for (part = 0; part < entries_per_sec; part++) {
591 ent = (struct gpt_ent *)(sec + part * hdr.hdr_entsz);
592 if (memcmp(&ent->ent_type, &freebsd_zfs_uuid,
593 sizeof(uuid_t)) == 0) {
594 dsk->start = ent->ent_lba_start;
595 dsk->size = ent->ent_lba_end - ent->ent_lba_start + 1;
596 dsk->slice = part + 1;
598 if (vdev_probe(vdev_read2, dsk, NULL) == 0) {
600 * This slice had a vdev. We need a new dsk
601 * structure now since the vdev now owns this one.
605 #ifdef LOADER_GELI_SUPPORT
606 else if (geli_taste(vdev_read, dsk, ent->ent_lba_end -
607 ent->ent_lba_start) == 0) {
608 if (geli_havekey(dsk) == 0 || geli_passphrase(gelipw,
609 dsk->unit, 'p', dsk->slice, dsk) == 0) {
611 * This slice has GELI, check it for ZFS.
613 if (vdev_probe(vdev_read2, dsk, NULL) == 0) {
615 * This slice had a vdev. We need a new dsk
616 * structure now since the vdev now owns this one.
623 #endif /* LOADER_GELI_SUPPORT */
632 if (drvread(dsk, sec, DOSBBSECTOR, 1))
634 dp = (void *)(sec + DOSPARTOFF);
636 for (i = 0; i < NDOSPART; i++) {
639 dsk->start = dp[i].dp_start;
640 dsk->size = dp[i].dp_size;
642 if (vdev_probe(vdev_read2, dsk, NULL) == 0) {
645 #ifdef LOADER_GELI_SUPPORT
646 else if (geli_taste(vdev_read, dsk, dp[i].dp_size -
647 dp[i].dp_start) == 0) {
648 if (geli_havekey(dsk) == 0 || geli_passphrase(gelipw, dsk->unit,
651 * This slice has GELI, check it for ZFS.
653 if (vdev_probe(vdev_read2, dsk, NULL) == 0) {
655 * This slice had a vdev. We need a new dsk
656 * structure now since the vdev now owns this one.
663 #endif /* LOADER_GELI_SUPPORT */
677 dmadat = (void *)(roundup2(__base + (int32_t)&_end, 0x10000) - __base);
681 if (high_heap_size > 0) {
682 heap_end = PTOV(high_heap_base + high_heap_size);
683 heap_next = PTOV(high_heap_base);
685 heap_next = (char *)dmadat + sizeof(*dmadat);
686 heap_end = (char *)PTOV(bios_basemem);
688 setheap(heap_next, heap_end);
690 dsk = malloc(sizeof(struct dsk));
691 dsk->drive = *(uint8_t *)PTOV(ARGS);
692 dsk->type = dsk->drive & DRV_HARD ? TYPE_AD : TYPE_FD;
693 dsk->unit = dsk->drive & DRV_MASK;
694 dsk->slice = *(uint8_t *)PTOV(ARGS + 1) + 1;
699 bootinfo.bi_version = BOOTINFO_VERSION;
700 bootinfo.bi_size = sizeof(bootinfo);
701 bootinfo.bi_basemem = bios_basemem / 1024;
702 bootinfo.bi_extmem = bios_extmem / 1024;
703 bootinfo.bi_memsizes_valid++;
704 bootinfo.bi_bios_dev = dsk->drive;
706 bootdev = MAKEBOOTDEV(dev_maj[dsk->type],
707 dsk->slice, dsk->unit, dsk->part);
709 /* Process configuration file */
713 #ifdef LOADER_GELI_SUPPORT
719 * Probe the boot drive first - we will try to boot from whatever
720 * pool we find on that drive.
725 * Probe the rest of the drives that the bios knows about. This
726 * will find any other available pools and it may fill in missing
727 * vdevs for the boot pool.
730 for (i = 0; i < *(unsigned char *)PTOV(BIOS_NUMDRIVES); i++)
732 for (i = 0; i < MAXBDDEV; i++)
735 if ((i | DRV_HARD) == *(uint8_t *)PTOV(ARGS))
738 if (!int13probe(i | DRV_HARD))
741 dsk = malloc(sizeof(struct dsk));
742 dsk->drive = i | DRV_HARD;
743 dsk->type = dsk->drive & TYPE_AD;
753 * The first discovered pool, if any, is the pool.
755 spa = spa_get_primary();
757 printf("%s: No ZFS pools located, can't boot\n", BOOTPROG);
763 primary_vdev = spa_get_primary_vdev(spa);
766 rc = vdev_read_pad2(primary_vdev, cmd, sizeof(cmd));
767 if (vdev_clear_pad2(primary_vdev))
768 printf("failed to clear pad2 area of primary vdev\n");
772 * We could find an old-style ZFS Boot Block header here.
775 if (*(uint64_t *)cmd != 0x2f5b007b10c) {
777 * Note that parse() is destructive to cmd[] and we also want
778 * to honor RBX_QUIET option that could be present in cmd[].
781 memcpy(cmddup, cmd, sizeof(cmd));
783 printf("failed to parse pad2 area of primary vdev\n");
786 if (!OPT_CHECK(RBX_QUIET))
787 printf("zfs nextboot: %s\n", cmddup);
789 /* Do not process this command twice */
793 printf("failed to read pad2 area of primary vdev\n");
795 /* Mount ZFS only if it's not already mounted via nextboot parsing. */
796 if (zfsmount.spa == NULL &&
797 (zfs_spa_init(spa) != 0 || zfs_mount(spa, 0, &zfsmount) != 0)) {
798 printf("%s: failed to mount default pool %s\n",
799 BOOTPROG, spa->spa_name);
801 } else if (zfs_lookup(&zfsmount, PATH_CONFIG, &dn) == 0 ||
802 zfs_lookup(&zfsmount, PATH_DOTCONFIG, &dn) == 0) {
804 zfs_read(spa, &dn, &off, cmd, sizeof(cmd));
809 * Note that parse_cmd() is destructive to cmd[] and we also want
810 * to honor RBX_QUIET option that could be present in cmd[].
812 memcpy(cmddup, cmd, sizeof(cmd));
815 if (!OPT_CHECK(RBX_QUIET))
816 printf("%s: %s\n", PATH_CONFIG, cmddup);
817 /* Do not process this command twice */
821 /* Do not risk waiting at the prompt forever. */
822 if (nextboot && !autoboot)
826 * Try to exec /boot/loader. If interrupted by a keypress,
827 * or in case of failure, try to load a kernel directly instead.
830 if (autoboot && !*kname) {
831 memcpy(kname, PATH_LOADER_ZFS, sizeof(PATH_LOADER_ZFS));
834 memcpy(kname, PATH_KERNEL, sizeof(PATH_KERNEL));
838 /* Present the user with the boot2 prompt. */
841 if (!autoboot || !OPT_CHECK(RBX_QUIET)) {
842 printf("\nFreeBSD/x86 boot\n");
843 if (zfs_rlookup(spa, zfsmount.rootobj, rootname) != 0)
844 printf("Default: %s/<0x%llx>:%s\n"
846 spa->spa_name, zfsmount.rootobj, kname);
847 else if (rootname[0] != '\0')
848 printf("Default: %s/%s:%s\n"
850 spa->spa_name, rootname, kname);
852 printf("Default: %s:%s\n"
854 spa->spa_name, kname);
856 if (ioctrl & IO_SERIAL)
858 if (!autoboot || keyhit(5))
859 getstr(cmd, sizeof(cmd));
860 else if (!autoboot || !OPT_CHECK(RBX_QUIET))
870 /* XXX - Needed for btxld to link the boot2 binary; do not remove. */
890 static Elf32_Phdr ep[2];
891 static Elf32_Shdr es[2];
898 if (zfs_lookup(&zfsmount, kname, &dn)) {
899 printf("\nCan't find %s\n", kname);
903 if (xfsread(&dn, &off, &hdr, sizeof(hdr)))
905 if (N_GETMAGIC(hdr.ex) == ZMAGIC)
907 else if (IS_ELF(hdr.eh))
910 printf("Invalid %s\n", "format");
914 addr = hdr.ex.a_entry & 0xffffff;
917 if (xfsread(&dn, &off, p, hdr.ex.a_text))
919 p += roundup2(hdr.ex.a_text, PAGE_SIZE);
920 if (xfsread(&dn, &off, p, hdr.ex.a_data))
922 p += hdr.ex.a_data + roundup2(hdr.ex.a_bss, PAGE_SIZE);
923 bootinfo.bi_symtab = VTOP(p);
924 memcpy(p, &hdr.ex.a_syms, sizeof(hdr.ex.a_syms));
925 p += sizeof(hdr.ex.a_syms);
927 if (xfsread(&dn, &off, p, hdr.ex.a_syms))
930 if (xfsread(&dn, &off, p, sizeof(int)))
935 if (xfsread(&dn, &off, p, x))
940 off = hdr.eh.e_phoff;
941 for (j = i = 0; i < hdr.eh.e_phnum && j < 2; i++) {
942 if (xfsread(&dn, &off, ep + j, sizeof(ep[0])))
944 if (ep[j].p_type == PT_LOAD)
947 for (i = 0; i < 2; i++) {
948 p = PTOV(ep[i].p_paddr & 0xffffff);
949 off = ep[i].p_offset;
950 if (xfsread(&dn, &off, p, ep[i].p_filesz))
953 p += roundup2(ep[1].p_memsz, PAGE_SIZE);
954 bootinfo.bi_symtab = VTOP(p);
955 if (hdr.eh.e_shnum == hdr.eh.e_shstrndx + 3) {
956 off = hdr.eh.e_shoff + sizeof(es[0]) *
957 (hdr.eh.e_shstrndx + 1);
958 if (xfsread(&dn, &off, &es, sizeof(es)))
960 for (i = 0; i < 2; i++) {
961 memcpy(p, &es[i].sh_size, sizeof(es[i].sh_size));
962 p += sizeof(es[i].sh_size);
963 off = es[i].sh_offset;
964 if (xfsread(&dn, &off, p, es[i].sh_size))
969 addr = hdr.eh.e_entry & 0xffffff;
971 bootinfo.bi_esymtab = VTOP(p);
972 bootinfo.bi_kernelname = VTOP(kname);
973 zfsargs.size = sizeof(zfsargs);
974 zfsargs.pool = zfsmount.spa->spa_guid;
975 zfsargs.root = zfsmount.rootobj;
976 zfsargs.primary_pool = primary_spa->spa_guid;
977 #ifdef LOADER_GELI_SUPPORT
978 explicit_bzero(gelipw, sizeof(gelipw));
979 gelibuf = malloc(sizeof(struct keybuf) + (GELI_MAX_KEYS * sizeof(struct keybuf_ent)));
980 geli_fill_keybuf(gelibuf);
981 zfsargs.notapw = '\0';
982 zfsargs.keybuf_sentinel = KEYBUF_SENTINEL;
983 zfsargs.keybuf = gelibuf;
985 zfsargs.gelipw[0] = '\0';
987 if (primary_vdev != NULL)
988 zfsargs.primary_vdev = primary_vdev->v_guid;
990 printf("failed to detect primary vdev\n");
991 __exec((caddr_t)addr, RB_BOOTINFO | (opts & RBX_MASK),
993 KARGS_FLAGS_ZFS | KARGS_FLAGS_EXTARG,
994 (uint32_t) spa->spa_guid,
995 (uint32_t) (spa->spa_guid >> 32),
1001 zfs_mount_ds(char *dsname)
1007 q = strchr(dsname, '/');
1010 newspa = spa_find_by_name(dsname);
1011 if (newspa == NULL) {
1012 printf("\nCan't find ZFS pool %s\n", dsname);
1016 if (zfs_spa_init(newspa))
1021 if (zfs_lookup_dataset(newspa, q, &newroot)) {
1022 printf("\nCan't find dataset %s in ZFS pool %s\n",
1023 q, newspa->spa_name);
1027 if (zfs_mount(newspa, newroot, &zfsmount)) {
1028 printf("\nCan't mount ZFS dataset\n");
1043 while ((c = *arg++)) {
1044 if (c == ' ' || c == '\t' || c == '\n')
1046 for (p = arg; *p && *p != '\n' && *p != ' ' && *p != '\t'; p++);
1051 while ((c = *arg++)) {
1053 if (*(uint8_t *)PTOV(0x496) & 0x10) {
1056 opts |= OPT_SET(RBX_DUAL) | OPT_SET(RBX_SERIAL);
1059 printf("Keyboard: %s\n", cp);
1061 } else if (c == 'S') {
1063 while ((unsigned int)(i = *arg++ - '0') <= 9)
1065 if (j > 0 && i == -'0') {
1069 /* Fall through to error below ('S' not in optstr[]). */
1071 for (i = 0; c != optstr[i]; i++)
1074 opts ^= OPT_SET(flags[i]);
1076 ioctrl = OPT_CHECK(RBX_DUAL) ? (IO_SERIAL|IO_KEYBOARD) :
1077 OPT_CHECK(RBX_SERIAL) ? IO_SERIAL : IO_KEYBOARD;
1078 if (ioctrl & IO_SERIAL) {
1079 if (sio_init(115200 / comspeed) != 0)
1080 ioctrl &= ~IO_SERIAL;
1085 if (zfs_lookup(&zfsmount, arg, &dn) == 0) {
1093 * Report pool status if the comment is 'status'. Lets
1094 * hope no-one wants to load /status as a kernel.
1096 if (!strcmp(arg, "status")) {
1102 * If there is "zfs:" prefix simply ignore it.
1104 if (strncmp(arg, "zfs:", 4) == 0)
1108 * If there is a colon, switch pools.
1110 q = strchr(arg, ':');
1113 if (zfs_mount_ds(arg) != 0)
1117 if ((i = ep - arg)) {
1118 if ((size_t)i >= sizeof(kname))
1120 memcpy(kname, arg, i + 1);