199767f8919635c4928607450d9e0abb932109ceToomas Soome/*-
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (c) 2008-2010 Rui Paulo
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (c) 2006 Marcel Moolenaar
199767f8919635c4928607450d9e0abb932109ceToomas Soome * All rights reserved.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Redistribution and use in source and binary forms, with or without
199767f8919635c4928607450d9e0abb932109ceToomas Soome * modification, are permitted provided that the following conditions
199767f8919635c4928607450d9e0abb932109ceToomas Soome * are met:
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 1. Redistributions of source code must retain the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 2. Redistributions in binary form must reproduce the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer in the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * documentation and/or other materials provided with the distribution.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
199767f8919635c4928607450d9e0abb932109ceToomas Soome * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
199767f8919635c4928607450d9e0abb932109ceToomas Soome * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
199767f8919635c4928607450d9e0abb932109ceToomas Soome * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
199767f8919635c4928607450d9e0abb932109ceToomas Soome * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
199767f8919635c4928607450d9e0abb932109ceToomas Soome * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <sys/cdefs.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome__FBSDID("$FreeBSD$");
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <sys/param.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <sys/reboot.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <sys/boot.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <stand.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <string.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <setjmp.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <efi.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <efilib.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <efigpt.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <bootstrap.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <smbios.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef EFI_ZFS_BOOT
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <libzfs.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include "loader_efi.h"
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern char bootprog_name[];
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern char bootprog_rev[];
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern char bootprog_date[];
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern char bootprog_maker[];
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct arch_switch archsw; /* MI/MD interface boundary */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas SoomeEFI_GUID acpi = ACPI_TABLE_GUID;
199767f8919635c4928607450d9e0abb932109ceToomas SoomeEFI_GUID acpi20 = ACPI_20_TABLE_GUID;
199767f8919635c4928607450d9e0abb932109ceToomas SoomeEFI_GUID devid = DEVICE_PATH_PROTOCOL;
199767f8919635c4928607450d9e0abb932109ceToomas SoomeEFI_GUID imgid = LOADED_IMAGE_PROTOCOL;
199767f8919635c4928607450d9e0abb932109ceToomas SoomeEFI_GUID mps = MPS_TABLE_GUID;
199767f8919635c4928607450d9e0abb932109ceToomas SoomeEFI_GUID netid = EFI_SIMPLE_NETWORK_PROTOCOL;
199767f8919635c4928607450d9e0abb932109ceToomas SoomeEFI_GUID smbios = SMBIOS_TABLE_GUID;
199767f8919635c4928607450d9e0abb932109ceToomas SoomeEFI_GUID smbios3 = SMBIOS3_TABLE_GUID;
199767f8919635c4928607450d9e0abb932109ceToomas SoomeEFI_GUID dxe = DXE_SERVICES_TABLE_GUID;
199767f8919635c4928607450d9e0abb932109ceToomas SoomeEFI_GUID hoblist = HOB_LIST_TABLE_GUID;
199767f8919635c4928607450d9e0abb932109ceToomas SoomeEFI_GUID memtype = MEMORY_TYPE_INFORMATION_TABLE_GUID;
199767f8919635c4928607450d9e0abb932109ceToomas SoomeEFI_GUID debugimg = DEBUG_IMAGE_INFO_TABLE_GUID;
199767f8919635c4928607450d9e0abb932109ceToomas SoomeEFI_GUID fdtdtb = FDT_TABLE_GUID;
199767f8919635c4928607450d9e0abb932109ceToomas SoomeEFI_GUID inputid = SIMPLE_TEXT_INPUT_PROTOCOL;
199767f8919635c4928607450d9e0abb932109ceToomas SoomeEFI_GUID serial_io = SERIAL_IO_PROTOCOL;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern void acpi_detect(const caddr_t);
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid efi_serial_init(void);
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef EFI_ZFS_BOOT
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic void efi_zfs_probe(void);
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Need this because EFI uses UTF-16 unicode string constants, but we
199767f8919635c4928607450d9e0abb932109ceToomas Soome * use UTF-8. We can't use printf due to the possiblity of \0 and we
199767f8919635c4928607450d9e0abb932109ceToomas Soome * don't support support wide characters either.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic void
199767f8919635c4928607450d9e0abb932109ceToomas Soomeprint_str16(const CHAR16 *str)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome int i;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; str[i]; i++)
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("%c", (char)str[i]);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic void
199767f8919635c4928607450d9e0abb932109ceToomas Soomecp16to8(const CHAR16 *src, char *dst, size_t len)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome size_t i;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; i < len && src[i]; i++)
199767f8919635c4928607450d9e0abb932109ceToomas Soome dst[i] = (char)src[i];
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int
199767f8919635c4928607450d9e0abb932109ceToomas Soomehas_keyboard(void)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome EFI_STATUS status;
199767f8919635c4928607450d9e0abb932109ceToomas Soome EFI_DEVICE_PATH *path;
199767f8919635c4928607450d9e0abb932109ceToomas Soome EFI_HANDLE *hin, *hin_end, *walker;
199767f8919635c4928607450d9e0abb932109ceToomas Soome UINTN sz;
199767f8919635c4928607450d9e0abb932109ceToomas Soome int retval = 0;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Find all the handles that support the SIMPLE_TEXT_INPUT_PROTOCOL and
199767f8919635c4928607450d9e0abb932109ceToomas Soome * do the typical dance to get the right sized buffer.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome sz = 0;
199767f8919635c4928607450d9e0abb932109ceToomas Soome hin = NULL;
199767f8919635c4928607450d9e0abb932109ceToomas Soome status = BS->LocateHandle(ByProtocol, &inputid, 0, &sz, 0);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (status == EFI_BUFFER_TOO_SMALL) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome hin = (EFI_HANDLE *)malloc(sz);
199767f8919635c4928607450d9e0abb932109ceToomas Soome status = BS->LocateHandle(ByProtocol, &inputid, 0, &sz,
199767f8919635c4928607450d9e0abb932109ceToomas Soome hin);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (EFI_ERROR(status))
199767f8919635c4928607450d9e0abb932109ceToomas Soome free(hin);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (EFI_ERROR(status))
199767f8919635c4928607450d9e0abb932109ceToomas Soome return retval;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Look at each of the handles. If it supports the device path protocol,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * use it to get the device path for this handle. Then see if that
199767f8919635c4928607450d9e0abb932109ceToomas Soome * device path matches either the USB device path for keyboards or the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * legacy device path for keyboards.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome hin_end = &hin[sz / sizeof(*hin)];
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (walker = hin; walker < hin_end; walker++) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome status = BS->HandleProtocol(*walker, &devid, (VOID **)&path);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (EFI_ERROR(status))
199767f8919635c4928607450d9e0abb932109ceToomas Soome continue;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome while (!IsDevicePathEnd(path)) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Check for the ACPI keyboard node. All PNP3xx nodes
199767f8919635c4928607450d9e0abb932109ceToomas Soome * are keyboards of different flavors. Note: It is
199767f8919635c4928607450d9e0abb932109ceToomas Soome * unclear of there's always a keyboard node when
199767f8919635c4928607450d9e0abb932109ceToomas Soome * there's a keyboard controller, or if there's only one
199767f8919635c4928607450d9e0abb932109ceToomas Soome * when a keyboard is detected at boot.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (DevicePathType(path) == ACPI_DEVICE_PATH &&
199767f8919635c4928607450d9e0abb932109ceToomas Soome (DevicePathSubType(path) == ACPI_DP ||
199767f8919635c4928607450d9e0abb932109ceToomas Soome DevicePathSubType(path) == ACPI_EXTENDED_DP)) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome ACPI_HID_DEVICE_PATH *acpi;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome acpi = (ACPI_HID_DEVICE_PATH *)(void *)path;
199767f8919635c4928607450d9e0abb932109ceToomas Soome if ((EISA_ID_TO_NUM(acpi->HID) & 0xff00) == 0x300 &&
199767f8919635c4928607450d9e0abb932109ceToomas Soome (acpi->HID & 0xffff) == PNP_EISA_ID_CONST) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome retval = 1;
199767f8919635c4928607450d9e0abb932109ceToomas Soome goto out;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Check for USB keyboard node, if present. Unlike a
199767f8919635c4928607450d9e0abb932109ceToomas Soome * PS/2 keyboard, these definitely only appear when
199767f8919635c4928607450d9e0abb932109ceToomas Soome * connected to the system.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome } else if (DevicePathType(path) == MESSAGING_DEVICE_PATH &&
199767f8919635c4928607450d9e0abb932109ceToomas Soome DevicePathSubType(path) == MSG_USB_CLASS_DP) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome USB_CLASS_DEVICE_PATH *usb;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome usb = (USB_CLASS_DEVICE_PATH *)(void *)path;
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (usb->DeviceClass == 3 && /* HID */
199767f8919635c4928607450d9e0abb932109ceToomas Soome usb->DeviceSubClass == 1 && /* Boot devices */
199767f8919635c4928607450d9e0abb932109ceToomas Soome usb->DeviceProtocol == 1) { /* Boot keyboards */
199767f8919635c4928607450d9e0abb932109ceToomas Soome retval = 1;
199767f8919635c4928607450d9e0abb932109ceToomas Soome goto out;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome path = NextDevicePathNode(path);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soomeout:
199767f8919635c4928607450d9e0abb932109ceToomas Soome free(hin);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return retval;
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas SoomeEFI_STATUS
199767f8919635c4928607450d9e0abb932109ceToomas Soomemain(int argc, CHAR16 *argv[])
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome char var[128];
199767f8919635c4928607450d9e0abb932109ceToomas Soome EFI_LOADED_IMAGE *img;
199767f8919635c4928607450d9e0abb932109ceToomas Soome EFI_GUID *guid;
199767f8919635c4928607450d9e0abb932109ceToomas Soome int i, j, vargood, unit, howto;
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct devsw *dev;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t pool_guid;
199767f8919635c4928607450d9e0abb932109ceToomas Soome UINTN k;
199767f8919635c4928607450d9e0abb932109ceToomas Soome int has_kbd;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome archsw.arch_autoload = efi_autoload;
199767f8919635c4928607450d9e0abb932109ceToomas Soome archsw.arch_getdev = efi_getdev;
199767f8919635c4928607450d9e0abb932109ceToomas Soome archsw.arch_copyin = efi_copyin;
199767f8919635c4928607450d9e0abb932109ceToomas Soome archsw.arch_copyout = efi_copyout;
199767f8919635c4928607450d9e0abb932109ceToomas Soome archsw.arch_readin = efi_readin;
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef EFI_ZFS_BOOT
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* Note this needs to be set before ZFS init. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome archsw.arch_zfs_probe = efi_zfs_probe;
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome has_kbd = has_keyboard();
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * XXX Chicken-and-egg problem; we want to have console output
199767f8919635c4928607450d9e0abb932109ceToomas Soome * early, but some console attributes may depend on reading from
199767f8919635c4928607450d9e0abb932109ceToomas Soome * eg. the boot device, which we can't do yet. We can use
199767f8919635c4928607450d9e0abb932109ceToomas Soome * printf() etc. once this is done.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome cons_probe();
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Initialise the block cache. Set the upper limit.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome bcache_init(32768, 512);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Parse the args to set the console settings, etc
199767f8919635c4928607450d9e0abb932109ceToomas Soome * boot1.efi passes these in, if it can read /boot.config or /boot/config
199767f8919635c4928607450d9e0abb932109ceToomas Soome * or iPXE may be setup to pass these in.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Loop through the args, and for each one that contains an '=' that is
199767f8919635c4928607450d9e0abb932109ceToomas Soome * not the first character, add it to the environment. This allows
199767f8919635c4928607450d9e0abb932109ceToomas Soome * loader and kernel env vars to be passed on the command line. Convert
199767f8919635c4928607450d9e0abb932109ceToomas Soome * args from UCS-2 to ASCII (16 to 8 bit) as they are copied.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome howto = 0;
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 1; i < argc; i++) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (argv[i][0] == '-') {
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (j = 1; argv[i][j] != 0; j++) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome int ch;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome ch = argv[i][j];
199767f8919635c4928607450d9e0abb932109ceToomas Soome switch (ch) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome case 'a':
199767f8919635c4928607450d9e0abb932109ceToomas Soome howto |= RB_ASKNAME;
199767f8919635c4928607450d9e0abb932109ceToomas Soome break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome case 'd':
199767f8919635c4928607450d9e0abb932109ceToomas Soome howto |= RB_KDB;
199767f8919635c4928607450d9e0abb932109ceToomas Soome break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome case 'D':
199767f8919635c4928607450d9e0abb932109ceToomas Soome howto |= RB_MULTIPLE;
199767f8919635c4928607450d9e0abb932109ceToomas Soome break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome case 'h':
199767f8919635c4928607450d9e0abb932109ceToomas Soome howto |= RB_SERIAL;
199767f8919635c4928607450d9e0abb932109ceToomas Soome break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome case 'm':
199767f8919635c4928607450d9e0abb932109ceToomas Soome howto |= RB_MUTE;
199767f8919635c4928607450d9e0abb932109ceToomas Soome break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome case 'p':
199767f8919635c4928607450d9e0abb932109ceToomas Soome howto |= RB_PAUSE;
199767f8919635c4928607450d9e0abb932109ceToomas Soome break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome case 'P':
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (!has_kbd)
199767f8919635c4928607450d9e0abb932109ceToomas Soome howto |= RB_SERIAL | RB_MULTIPLE;
199767f8919635c4928607450d9e0abb932109ceToomas Soome break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome case 'r':
199767f8919635c4928607450d9e0abb932109ceToomas Soome howto |= RB_DFLTROOT;
199767f8919635c4928607450d9e0abb932109ceToomas Soome break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome case 's':
199767f8919635c4928607450d9e0abb932109ceToomas Soome howto |= RB_SINGLE;
199767f8919635c4928607450d9e0abb932109ceToomas Soome break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome case 'S':
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (argv[i][j + 1] == 0) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (i + 1 == argc) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome setenv("comconsole_speed", "115200", 1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome } else {
199767f8919635c4928607450d9e0abb932109ceToomas Soome cp16to8(&argv[i + 1][0], var,
199767f8919635c4928607450d9e0abb932109ceToomas Soome sizeof(var));
199767f8919635c4928607450d9e0abb932109ceToomas Soome setenv("comconsole_speedspeed", var, 1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome i++;
199767f8919635c4928607450d9e0abb932109ceToomas Soome break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome } else {
199767f8919635c4928607450d9e0abb932109ceToomas Soome cp16to8(&argv[i][j + 1], var,
199767f8919635c4928607450d9e0abb932109ceToomas Soome sizeof(var));
199767f8919635c4928607450d9e0abb932109ceToomas Soome setenv("comconsole_speed", var, 1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome case 'v':
199767f8919635c4928607450d9e0abb932109ceToomas Soome howto |= RB_VERBOSE;
199767f8919635c4928607450d9e0abb932109ceToomas Soome break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome } else {
199767f8919635c4928607450d9e0abb932109ceToomas Soome vargood = 0;
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (j = 0; argv[i][j] != 0; j++) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (j == sizeof(var)) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome vargood = 0;
199767f8919635c4928607450d9e0abb932109ceToomas Soome break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (j > 0 && argv[i][j] == '=')
199767f8919635c4928607450d9e0abb932109ceToomas Soome vargood = 1;
199767f8919635c4928607450d9e0abb932109ceToomas Soome var[j] = (char)argv[i][j];
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (vargood) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome var[j] = 0;
199767f8919635c4928607450d9e0abb932109ceToomas Soome putenv(var);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; howto_names[i].ev != NULL; i++)
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (howto & howto_names[i].mask)
199767f8919635c4928607450d9e0abb932109ceToomas Soome setenv(howto_names[i].ev, "YES", 1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (howto & RB_MULTIPLE) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (howto & RB_SERIAL)
199767f8919635c4928607450d9e0abb932109ceToomas Soome setenv("console", "ttya text" , 1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome else
199767f8919635c4928607450d9e0abb932109ceToomas Soome setenv("console", "text ttya" , 1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome } else if (howto & RB_SERIAL) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome setenv("console", "ttya" , 1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (efi_copy_init()) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("failed to allocate staging area\n");
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (EFI_BUFFER_TOO_SMALL);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * March through the device switch probing for things.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; devsw[i] != NULL; i++)
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (devsw[i]->dv_init != NULL)
199767f8919635c4928607450d9e0abb932109ceToomas Soome (devsw[i]->dv_init)();
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* Get our loaded image protocol interface structure. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome BS->HandleProtocol(IH, &imgid, (VOID**)&img);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("Command line arguments:");
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; i < argc; i++) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf(" ");
199767f8919635c4928607450d9e0abb932109ceToomas Soome print_str16(argv[i]);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("\n");
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("Image base: 0x%lx\n", (u_long)img->ImageBase);
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("EFI version: %d.%02d\n", ST->Hdr.Revision >> 16,
199767f8919635c4928607450d9e0abb932109ceToomas Soome ST->Hdr.Revision & 0xffff);
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("EFI Firmware: ");
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* printf doesn't understand EFI Unicode */
199767f8919635c4928607450d9e0abb932109ceToomas Soome ST->ConOut->OutputString(ST->ConOut, ST->FirmwareVendor);
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf(" (rev %d.%02d)\n", ST->FirmwareRevision >> 16,
199767f8919635c4928607450d9e0abb932109ceToomas Soome ST->FirmwareRevision & 0xffff);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("\n");
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("%s, Revision %s\n", bootprog_name, bootprog_rev);
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("(%s, %s)\n", bootprog_maker, bootprog_date);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Disable the watchdog timer. By default the boot manager sets
199767f8919635c4928607450d9e0abb932109ceToomas Soome * the timer to 5 minutes before invoking a boot option. If we
199767f8919635c4928607450d9e0abb932109ceToomas Soome * want to return to the boot manager, we have to disable the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * watchdog timer and since we're an interactive program, we don't
199767f8919635c4928607450d9e0abb932109ceToomas Soome * want to wait until the user types "quit". The timer may have
199767f8919635c4928607450d9e0abb932109ceToomas Soome * fired by then. We don't care if this fails. It does not prevent
199767f8919635c4928607450d9e0abb932109ceToomas Soome * normal functioning in any way...
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome BS->SetWatchdogTimer(0, 0, 0, NULL);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (efi_handle_lookup(img->DeviceHandle, &dev, &unit, &pool_guid) != 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (EFI_NOT_FOUND);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome switch (dev->dv_type) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef EFI_ZFS_BOOT
199767f8919635c4928607450d9e0abb932109ceToomas Soome case DEVT_ZFS: {
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct zfs_devdesc currdev;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome currdev.d_dev = dev;
199767f8919635c4928607450d9e0abb932109ceToomas Soome currdev.d_unit = unit;
199767f8919635c4928607450d9e0abb932109ceToomas Soome currdev.d_type = currdev.d_dev->dv_type;
199767f8919635c4928607450d9e0abb932109ceToomas Soome currdev.d_opendata = NULL;
199767f8919635c4928607450d9e0abb932109ceToomas Soome currdev.pool_guid = pool_guid;
199767f8919635c4928607450d9e0abb932109ceToomas Soome currdev.root_guid = 0;
199767f8919635c4928607450d9e0abb932109ceToomas Soome env_setenv("currdev", EV_VOLATILE, efi_fmtdev(&currdev),
199767f8919635c4928607450d9e0abb932109ceToomas Soome efi_setcurrdev, env_nounset);
199767f8919635c4928607450d9e0abb932109ceToomas Soome env_setenv("loaddev", EV_VOLATILE, efi_fmtdev(&currdev), env_noset,
199767f8919635c4928607450d9e0abb932109ceToomas Soome env_nounset);
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef __FreeBSD__
199767f8919635c4928607450d9e0abb932109ceToomas Soome init_zfs_bootenv(zfs_fmtdev(&currdev));
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome default: {
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct devdesc currdev;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome currdev.d_dev = dev;
199767f8919635c4928607450d9e0abb932109ceToomas Soome currdev.d_unit = unit;
199767f8919635c4928607450d9e0abb932109ceToomas Soome currdev.d_opendata = NULL;
199767f8919635c4928607450d9e0abb932109ceToomas Soome currdev.d_type = currdev.d_dev->dv_type;
199767f8919635c4928607450d9e0abb932109ceToomas Soome env_setenv("currdev", EV_VOLATILE, efi_fmtdev(&currdev),
199767f8919635c4928607450d9e0abb932109ceToomas Soome efi_setcurrdev, env_nounset);
199767f8919635c4928607450d9e0abb932109ceToomas Soome env_setenv("loaddev", EV_VOLATILE, efi_fmtdev(&currdev), env_noset,
199767f8919635c4928607450d9e0abb932109ceToomas Soome env_nounset);
199767f8919635c4928607450d9e0abb932109ceToomas Soome break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome setenv("LINES", "24", 1); /* optional */
199767f8919635c4928607450d9e0abb932109ceToomas Soome setenv("COLUMNS", "80", 1); /* optional */
199767f8919635c4928607450d9e0abb932109ceToomas Soome setenv("ISADIR", "amd64", 1); /* we only build 64bit */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (k = 0; k < ST->NumberOfTableEntries; k++) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome guid = &ST->ConfigurationTable[k].VendorGuid;
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (!memcmp(guid, &smbios, sizeof(EFI_GUID)) ||
199767f8919635c4928607450d9e0abb932109ceToomas Soome !memcmp(guid, &smbios3, sizeof(EFI_GUID))) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome smbios_detect(ST->ConfigurationTable[k].VendorTable);
199767f8919635c4928607450d9e0abb932109ceToomas Soome continue;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (!memcmp(guid, &acpi20, sizeof(EFI_GUID))) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome acpi_detect(ST->ConfigurationTable[k].VendorTable);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome efi_serial_init(); /* detect and set up serial ports */
199767f8919635c4928607450d9e0abb932109ceToomas Soome interact(NULL); /* doesn't return */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (EFI_SUCCESS); /* keep compiler happy */
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas SoomeCOMMAND_SET(reboot, "reboot", "reboot the system", command_reboot);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int
199767f8919635c4928607450d9e0abb932109ceToomas Soomecommand_reboot(int argc __attribute((unused)),
199767f8919635c4928607450d9e0abb932109ceToomas Soome char *argv[] __attribute((unused)))
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome int i;
199767f8919635c4928607450d9e0abb932109ceToomas Soome const CHAR16 *msg = L"Reboot from the loader";
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; devsw[i] != NULL; ++i)
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (devsw[i]->dv_cleanup != NULL)
199767f8919635c4928607450d9e0abb932109ceToomas Soome (devsw[i]->dv_cleanup)();
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome RS->ResetSystem(EfiResetCold, EFI_SUCCESS, 23, (CHAR16 *)msg);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* NOTREACHED */
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (CMD_ERROR);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas SoomeCOMMAND_SET(memmap, "memmap", "print memory map", command_memmap);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int
199767f8919635c4928607450d9e0abb932109ceToomas Soomecommand_memmap(int argc __attribute((unused)),
199767f8919635c4928607450d9e0abb932109ceToomas Soome char *argv[] __attribute((unused)))
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome UINTN sz;
199767f8919635c4928607450d9e0abb932109ceToomas Soome EFI_MEMORY_DESCRIPTOR *map, *p;
199767f8919635c4928607450d9e0abb932109ceToomas Soome UINTN key, dsz;
199767f8919635c4928607450d9e0abb932109ceToomas Soome UINT32 dver;
199767f8919635c4928607450d9e0abb932109ceToomas Soome EFI_STATUS status;
199767f8919635c4928607450d9e0abb932109ceToomas Soome int i, ndesc;
199767f8919635c4928607450d9e0abb932109ceToomas Soome int rv = 0;
199767f8919635c4928607450d9e0abb932109ceToomas Soome char line[80];
199767f8919635c4928607450d9e0abb932109ceToomas Soome static const char *types[] = {
199767f8919635c4928607450d9e0abb932109ceToomas Soome "Reserved",
199767f8919635c4928607450d9e0abb932109ceToomas Soome "LoaderCode",
199767f8919635c4928607450d9e0abb932109ceToomas Soome "LoaderData",
199767f8919635c4928607450d9e0abb932109ceToomas Soome "BootServicesCode",
199767f8919635c4928607450d9e0abb932109ceToomas Soome "BootServicesData",
199767f8919635c4928607450d9e0abb932109ceToomas Soome "RuntimeServicesCode",
199767f8919635c4928607450d9e0abb932109ceToomas Soome "RuntimeServicesData",
199767f8919635c4928607450d9e0abb932109ceToomas Soome "ConventionalMemory",
199767f8919635c4928607450d9e0abb932109ceToomas Soome "UnusableMemory",
199767f8919635c4928607450d9e0abb932109ceToomas Soome "ACPIReclaimMemory",
199767f8919635c4928607450d9e0abb932109ceToomas Soome "ACPIMemoryNVS",
199767f8919635c4928607450d9e0abb932109ceToomas Soome "MemoryMappedIO",
199767f8919635c4928607450d9e0abb932109ceToomas Soome "MemoryMappedIOPortSpace",
199767f8919635c4928607450d9e0abb932109ceToomas Soome "PalCode"
199767f8919635c4928607450d9e0abb932109ceToomas Soome };
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome sz = 0;
199767f8919635c4928607450d9e0abb932109ceToomas Soome status = BS->GetMemoryMap(&sz, 0, &key, &dsz, &dver);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (status != EFI_BUFFER_TOO_SMALL) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("Can't determine memory map size\n");
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (CMD_ERROR);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome map = malloc(sz);
199767f8919635c4928607450d9e0abb932109ceToomas Soome status = BS->GetMemoryMap(&sz, map, &key, &dsz, &dver);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (EFI_ERROR(status)) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("Can't read memory map\n");
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (CMD_ERROR);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome ndesc = sz / dsz;
199767f8919635c4928607450d9e0abb932109ceToomas Soome snprintf(line, 80, "%23s %12s %12s %8s %4s\n",
199767f8919635c4928607450d9e0abb932109ceToomas Soome "Type", "Physical", "Virtual", "#Pages", "Attr");
199767f8919635c4928607450d9e0abb932109ceToomas Soome pager_open();
199767f8919635c4928607450d9e0abb932109ceToomas Soome rv = pager_output(line);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (rv) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome pager_close();
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (CMD_OK);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0, p = map; i < ndesc;
199767f8919635c4928607450d9e0abb932109ceToomas Soome i++, p = NextMemoryDescriptor(p, dsz)) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome snprintf(line, 80, "%23s %012lx %012lx %08lx ",
199767f8919635c4928607450d9e0abb932109ceToomas Soome types[p->Type],
199767f8919635c4928607450d9e0abb932109ceToomas Soome p->PhysicalStart,
199767f8919635c4928607450d9e0abb932109ceToomas Soome p->VirtualStart,
199767f8919635c4928607450d9e0abb932109ceToomas Soome p->NumberOfPages);
199767f8919635c4928607450d9e0abb932109ceToomas Soome rv = pager_output(line);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (rv)
199767f8919635c4928607450d9e0abb932109ceToomas Soome break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (p->Attribute & EFI_MEMORY_UC)
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("UC ");
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (p->Attribute & EFI_MEMORY_WC)
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("WC ");
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (p->Attribute & EFI_MEMORY_WT)
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("WT ");
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (p->Attribute & EFI_MEMORY_WB)
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("WB ");
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (p->Attribute & EFI_MEMORY_UCE)
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("UCE ");
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (p->Attribute & EFI_MEMORY_WP)
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("WP ");
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (p->Attribute & EFI_MEMORY_RP)
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("RP ");
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (p->Attribute & EFI_MEMORY_XP)
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("XP ");
199767f8919635c4928607450d9e0abb932109ceToomas Soome rv = pager_output("\n");
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (rv)
199767f8919635c4928607450d9e0abb932109ceToomas Soome break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome pager_close();
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (CMD_OK);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas SoomeCOMMAND_SET(configuration, "configuration", "print configuration tables",
199767f8919635c4928607450d9e0abb932109ceToomas Soome command_configuration);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic const char *
199767f8919635c4928607450d9e0abb932109ceToomas Soomeguid_to_string(EFI_GUID *guid)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome static char buf[40];
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome sprintf(buf, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
199767f8919635c4928607450d9e0abb932109ceToomas Soome guid->Data1, guid->Data2, guid->Data3, guid->Data4[0],
199767f8919635c4928607450d9e0abb932109ceToomas Soome guid->Data4[1], guid->Data4[2], guid->Data4[3], guid->Data4[4],
199767f8919635c4928607450d9e0abb932109ceToomas Soome guid->Data4[5], guid->Data4[6], guid->Data4[7]);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (buf);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int
199767f8919635c4928607450d9e0abb932109ceToomas Soomecommand_configuration(int argc __attribute((unused)),
199767f8919635c4928607450d9e0abb932109ceToomas Soome char *argv[] __attribute((unused)))
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome UINTN i;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("NumberOfTableEntries=%lu\n",
199767f8919635c4928607450d9e0abb932109ceToomas Soome (unsigned long)ST->NumberOfTableEntries);
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; i < ST->NumberOfTableEntries; i++) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome EFI_GUID *guid;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf(" ");
199767f8919635c4928607450d9e0abb932109ceToomas Soome guid = &ST->ConfigurationTable[i].VendorGuid;
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (!memcmp(guid, &mps, sizeof(EFI_GUID)))
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("MPS Table");
199767f8919635c4928607450d9e0abb932109ceToomas Soome else if (!memcmp(guid, &acpi, sizeof(EFI_GUID)))
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("ACPI Table");
199767f8919635c4928607450d9e0abb932109ceToomas Soome else if (!memcmp(guid, &acpi20, sizeof(EFI_GUID)))
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("ACPI 2.0 Table");
199767f8919635c4928607450d9e0abb932109ceToomas Soome else if (!memcmp(guid, &smbios, sizeof(EFI_GUID)))
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("SMBIOS Table");
199767f8919635c4928607450d9e0abb932109ceToomas Soome else if (!memcmp(guid, &smbios3, sizeof(EFI_GUID)))
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("SMBIOS3 Table");
199767f8919635c4928607450d9e0abb932109ceToomas Soome else if (!memcmp(guid, &dxe, sizeof(EFI_GUID)))
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("DXE Table");
199767f8919635c4928607450d9e0abb932109ceToomas Soome else if (!memcmp(guid, &hoblist, sizeof(EFI_GUID)))
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("HOB List Table");
199767f8919635c4928607450d9e0abb932109ceToomas Soome else if (!memcmp(guid, &memtype, sizeof(EFI_GUID)))
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("Memory Type Information Table");
199767f8919635c4928607450d9e0abb932109ceToomas Soome else if (!memcmp(guid, &debugimg, sizeof(EFI_GUID)))
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("Debug Image Info Table");
199767f8919635c4928607450d9e0abb932109ceToomas Soome else if (!memcmp(guid, &fdtdtb, sizeof(EFI_GUID)))
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("FDT Table");
199767f8919635c4928607450d9e0abb932109ceToomas Soome else
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("Unknown Table (%s)", guid_to_string(guid));
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf(" at %p\n", ST->ConfigurationTable[i].VendorTable);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (CMD_OK);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas SoomeCOMMAND_SET(mode, "mode", "change or display EFI text modes", command_mode);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int
199767f8919635c4928607450d9e0abb932109ceToomas Soomecommand_mode(int argc, char *argv[])
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome UINTN cols, rows;
199767f8919635c4928607450d9e0abb932109ceToomas Soome unsigned int mode;
199767f8919635c4928607450d9e0abb932109ceToomas Soome int i;
199767f8919635c4928607450d9e0abb932109ceToomas Soome char *cp;
199767f8919635c4928607450d9e0abb932109ceToomas Soome char rowenv[8];
199767f8919635c4928607450d9e0abb932109ceToomas Soome EFI_STATUS status;
199767f8919635c4928607450d9e0abb932109ceToomas Soome SIMPLE_TEXT_OUTPUT_INTERFACE *conout;
199767f8919635c4928607450d9e0abb932109ceToomas Soome extern void HO(void);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome conout = ST->ConOut;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (argc > 1) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome mode = strtol(argv[1], &cp, 0);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (cp[0] != '\0') {
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("Invalid mode\n");
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (CMD_ERROR);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome status = conout->QueryMode(conout, mode, &cols, &rows);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (EFI_ERROR(status)) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("invalid mode %d\n", mode);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (CMD_ERROR);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome status = conout->SetMode(conout, mode);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (EFI_ERROR(status)) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("couldn't set mode %d\n", mode);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (CMD_ERROR);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome sprintf(rowenv, "%u", (unsigned)rows);
199767f8919635c4928607450d9e0abb932109ceToomas Soome setenv("LINES", rowenv, 1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome sprintf(rowenv, "%u", (unsigned)cols);
199767f8919635c4928607450d9e0abb932109ceToomas Soome setenv("COLUMNS", rowenv, 1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome HO(); /* set cursor */
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (CMD_OK);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("Current mode: %d\n", conout->Mode->Mode);
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; i <= conout->Mode->MaxMode; i++) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome status = conout->QueryMode(conout, i, &cols, &rows);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (EFI_ERROR(status))
199767f8919635c4928607450d9e0abb932109ceToomas Soome continue;
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("Mode %d: %u columns, %u rows\n", i, (unsigned)cols,
199767f8919635c4928607450d9e0abb932109ceToomas Soome (unsigned)rows);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (i != 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("Select a mode with the command \"mode <number>\"\n");
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (CMD_OK);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas SoomeCOMMAND_SET(nvram, "nvram", "get NVRAM variables", command_nvram);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int
199767f8919635c4928607450d9e0abb932109ceToomas Soomecommand_nvram(int argc __attribute((unused)),
199767f8919635c4928607450d9e0abb932109ceToomas Soome char *argv[] __attribute((unused)))
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome CHAR16 var[128];
199767f8919635c4928607450d9e0abb932109ceToomas Soome UINT8 *data; /* value is in bytes */
199767f8919635c4928607450d9e0abb932109ceToomas Soome EFI_STATUS status;
199767f8919635c4928607450d9e0abb932109ceToomas Soome EFI_GUID varguid = { 0,0,0,{0,0,0,0,0,0,0,0} };
199767f8919635c4928607450d9e0abb932109ceToomas Soome UINTN varsz, datasz, i;
199767f8919635c4928607450d9e0abb932109ceToomas Soome UINT32 attr;
199767f8919635c4928607450d9e0abb932109ceToomas Soome SIMPLE_TEXT_OUTPUT_INTERFACE *conout;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome conout = ST->ConOut;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome pager_open();
199767f8919635c4928607450d9e0abb932109ceToomas Soome var[0] = 0; /* Initiate the enumeration */
199767f8919635c4928607450d9e0abb932109ceToomas Soome varsz = 128;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (status = RS->GetNextVariableName(&varsz, var, &varguid);
199767f8919635c4928607450d9e0abb932109ceToomas Soome status != EFI_NOT_FOUND;
199767f8919635c4928607450d9e0abb932109ceToomas Soome status = RS->GetNextVariableName(&varsz, var, &varguid)) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * as term emu is keeping track on cursor, use putchar().
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; var[i] != 0; i++)
199767f8919635c4928607450d9e0abb932109ceToomas Soome putchar(var[i]);
199767f8919635c4928607450d9e0abb932109ceToomas Soome varsz = 128; /* GetNextVariableName() did change it. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf(": Attributes:");
199767f8919635c4928607450d9e0abb932109ceToomas Soome datasz = 0;
199767f8919635c4928607450d9e0abb932109ceToomas Soome status = RS->GetVariable(var, &varguid, &attr, &datasz, NULL);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if ((data = malloc(datasz)) == NULL)
199767f8919635c4928607450d9e0abb932109ceToomas Soome break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome status = RS->GetVariable(var, &varguid, &attr, &datasz, data);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (EFI_ERROR(status))
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("<error retrieving variable>");
199767f8919635c4928607450d9e0abb932109ceToomas Soome else {
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (attr & EFI_VARIABLE_NON_VOLATILE)
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf(" NV");
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (attr & EFI_VARIABLE_BOOTSERVICE_ACCESS)
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf(" BS");
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (attr & EFI_VARIABLE_RUNTIME_ACCESS)
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf(" RS");
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (attr & EFI_VARIABLE_HARDWARE_ERROR_RECORD)
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf(" HR");
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (attr & EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS)
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf(" AW");
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (attr &
199767f8919635c4928607450d9e0abb932109ceToomas Soome EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS)
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf(" TW");
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf(": DataLength: %lld", (long long)datasz);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome free(data);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (pager_output("\n"))
199767f8919635c4928607450d9e0abb932109ceToomas Soome break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome pager_close();
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (CMD_OK);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct protocol_name {
199767f8919635c4928607450d9e0abb932109ceToomas Soome EFI_GUID guid;
199767f8919635c4928607450d9e0abb932109ceToomas Soome const char *name;
199767f8919635c4928607450d9e0abb932109ceToomas Soome} proto_names[] = {
199767f8919635c4928607450d9e0abb932109ceToomas Soome { DEVICE_PATH_PROTOCOL, "device path" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { BLOCK_IO_PROTOCOL, "block io" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { DISK_IO_PROTOCOL, "disk io" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_DISK_INFO_PROTOCOL_GUID, "disk info" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { SIMPLE_FILE_SYSTEM_PROTOCOL, "simple fs" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { LOAD_FILE_PROTOCOL, "load file" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { DEVICE_IO_PROTOCOL, "device io" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { UNICODE_COLLATION_PROTOCOL, "unicode collation" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_UNICODE_COLLATION2_PROTOCOL_GUID, "unicode collation2" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_SIMPLE_NETWORK_PROTOCOL, "simple network" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { SIMPLE_TEXT_OUTPUT_PROTOCOL, "simple text output" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { SIMPLE_TEXT_INPUT_PROTOCOL, "simple text input" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL_GUID, "simple text ex input" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_CONSOLE_CONTROL_PROTOCOL_GUID, "console control" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_CONSOLE_IN_DEVICE_GUID, "stdin" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_CONSOLE_OUT_DEVICE_GUID, "stdout" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_STANDARD_ERROR_DEVICE_GUID, "stderr" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID, "GOP" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_UGA_DRAW_PROTOCOL_GUID, "UGA draw" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_PXE_BASE_CODE_PROTOCOL, "PXE base code" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL, "PXE base code callback" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { SERIAL_IO_PROTOCOL, "serial io" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { LOADED_IMAGE_PROTOCOL, "loaded image" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_LOADED_IMAGE_DEVICE_PATH_PROTOCOL_GUID,
199767f8919635c4928607450d9e0abb932109ceToomas Soome "loaded image device path" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_ISA_IO_PROTOCOL_GUID, "ISA io" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_IDE_CONTROLLER_INIT_PROTOCOL_GUID, "IDE controller init" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_ISA_ACPI_PROTOCOL_GUID, "ISA ACPI" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_PCI_IO_PROTOCOL_GUID, "PCI" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_PCI_ROOT_IO_GUID, "PCI root" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_PCI_ENUMERATION_COMPLETE_GUID, "PCI enumeration" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_DRIVER_DIAGNOSTICS_PROTOCOL_GUID, "Driver diagnostics" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_DRIVER_DIAGNOSTICS2_PROTOCOL_GUID, "Driver diagnostics2" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_SIMPLE_POINTER_PROTOCOL_GUID, "simple pointer" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_ABSOLUTE_POINTER_PROTOCOL_GUID, "absolute pointer" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_VLAN_CONFIG_PROTOCOL_GUID, "VLAN config" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_ARP_SERVICE_BINDING_PROTOCOL_GUID, "ARP service binding" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_ARP_PROTOCOL_GUID, "ARP" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_IP4_SERVICE_BINDING_PROTOCOL, "IPv4 service binding" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_IP4_PROTOCOL, "IPv4" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_IP4_CONFIG_PROTOCOL_GUID, "IPv4 config" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_IP6_SERVICE_BINDING_PROTOCOL, "IPv6 service binding" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_IP6_PROTOCOL, "IPv6" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_IP6_CONFIG_PROTOCOL_GUID, "IPv6 config" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_UDP4_PROTOCOL, "UDPv4" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_UDP4_SERVICE_BINDING_PROTOCOL, "UDPv4 service binding" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_UDP6_PROTOCOL, "UDPv6" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_UDP6_SERVICE_BINDING_PROTOCOL, "UDPv6 service binding" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_TCP4_PROTOCOL, "TCPv4" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_TCP4_SERVICE_BINDING_PROTOCOL, "TCPv4 service binding" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_TCP6_PROTOCOL, "TCPv6" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_TCP6_SERVICE_BINDING_PROTOCOL, "TCPv6 service binding" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_PART_TYPE_EFI_SYSTEM_PART_GUID, "EFI System partition" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_PART_TYPE_LEGACY_MBR_GUID, "MBR legacy" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_DEVICE_TREE_GUID, "device tree" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_USB_IO_PROTOCOL_GUID, "USB io" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_USB2_HC_PROTOCOL_GUID, "USB2 HC" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_COMPONENT_NAME_PROTOCOL_GUID, "component name" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_COMPONENT_NAME2_PROTOCOL_GUID, "component name2" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_DRIVER_BINDING_PROTOCOL_GUID, "driver binding" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_DRIVER_CONFIGURATION_PROTOCOL_GUID, "driver configuration" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_DRIVER_CONFIGURATION2_PROTOCOL_GUID, "driver configuration2" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_DECOMPRESS_PROTOCOL_GUID, "decompress" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_EBC_INTERPRETER_PROTOCOL_GUID, "ebc interpreter" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL,
199767f8919635c4928607450d9e0abb932109ceToomas Soome "network interface identifier" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL_31,
199767f8919635c4928607450d9e0abb932109ceToomas Soome "network interface identifier_31" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_MANAGED_NETWORK_SERVICE_BINDING_PROTOCOL_GUID,
199767f8919635c4928607450d9e0abb932109ceToomas Soome "managed network service binding" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_MANAGED_NETWORK_PROTOCOL_GUID, "managed network" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_FORM_BROWSER2_PROTOCOL_GUID, "form browser" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_HII_CONFIG_ROUTING_PROTOCOL_GUID, "HII config routing" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_HII_DATABASE_PROTOCOL_GUID, "HII database" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_HII_STRING_PROTOCOL_GUID, "HII string" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_HII_IMAGE_PROTOCOL_GUID, "HII image" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_HII_FONT_PROTOCOL_GUID, "HII font" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_HII_CONFIGURATION_ACCESS_PROTOCOL_GUID, "HII config" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_MTFTP4_SERVICE_BINDING_PROTOCOL_GUID, "MTFTP4 service binding" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_MTFTP4_PROTOCOL_GUID, "MTFTP4" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_MTFTP6_SERVICE_BINDING_PROTOCOL_GUID, "MTFTP6 service binding" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_MTFTP6_PROTOCOL_GUID, "MTFTP6" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_DHCP4_SERVICE_BINDING_PROTOCOL_GUID, "DHCP4 service binding" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_DHCP4_PROTOCOL_GUID, "DHCP4" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_DHCP6_SERVICE_BINDING_PROTOCOL_GUID, "DHCP6 service binding" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_DHCP6_PROTOCOL_GUID, "DHCP6" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_SCSI_IO_PROTOCOL_GUID, "SCSI io" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_SCSI_PASS_THRU_PROTOCOL_GUID, "SCSI pass thru" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_EXT_SCSI_PASS_THRU_PROTOCOL_GUID, "SCSI pass thru ext" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_CAPSULE_ARCH_PROTOCOL_GUID, "Capsule arch" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_MONOTONIC_COUNTER_ARCH_PROTOCOL_GUID, "monotonic counter arch" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_REALTIME_CLOCK_ARCH_PROTOCOL_GUID, "realtime clock arch" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_VARIABLE_ARCH_PROTOCOL_GUID, "variable arch" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_VARIABLE_WRITE_ARCH_PROTOCOL_GUID, "variable write arch" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_WATCHDOG_TIMER_ARCH_PROTOCOL_GUID, "watchdog timer arch" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_MP_SERVICES_PROTOCOL_GUID, "MP services" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_ACPI_SUPPORT_PROTOCOL_GUID, "ACPI support" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_BDS_ARCH_PROTOCOL_GUID, "BDS arch" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_METRONOME_ARCH_PROTOCOL_GUID, "metronome arch" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_TIMER_ARCH_PROTOCOL_GUID, "timer arch" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_DPC_PROTOCOL_GUID, "DPC" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_PRINT2_PROTOCOL_GUID, "print2" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID, "device path to text" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_RESET_ARCH_PROTOCOL_GUID, "reset arch" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_CPU_ARCH_PROTOCOL_GUID, "CPU arch" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_CPU_IO2_PROTOCOL_GUID, "CPU IO2" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_LEGACY_8259_PROTOCOL_GUID, "Legacy 8259" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_SECURITY_ARCH_PROTOCOL_GUID, "Security arch" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_SECURITY2_ARCH_PROTOCOL_GUID, "Security2 arch" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_RUNTIME_ARCH_PROTOCOL_GUID, "Runtime arch" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_STATUS_CODE_RUNTIME_PROTOCOL_GUID, "status code runtime" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_DATA_HUB_PROTOCOL_GUID, "data hub" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { PCD_PROTOCOL_GUID, "PCD" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_PCD_PROTOCOL_GUID, "EFI PCD" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL_GUID, "firmware volume block" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_FIRMWARE_VOLUME2_PROTOCOL_GUID, "firmware volume2" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { EFI_FIRMWARE_VOLUME_DISPATCH_PROTOCOL_GUID,
199767f8919635c4928607450d9e0abb932109ceToomas Soome "firmware volume dispatch" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { LZMA_COMPRESS_GUID, "lzma compress" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { { 0,0,0,{0,0,0,0,0,0,0,0} }, NULL } /* must be last entry */
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas SoomeCOMMAND_SET(lsefi, "lsefi", "list EFI handles", command_lsefi);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int
199767f8919635c4928607450d9e0abb932109ceToomas Soomecommand_lsefi(int argc __attribute((unused)),
199767f8919635c4928607450d9e0abb932109ceToomas Soome char *argv[] __attribute((unused)))
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome EFI_HANDLE *buffer = NULL;
199767f8919635c4928607450d9e0abb932109ceToomas Soome EFI_HANDLE handle;
199767f8919635c4928607450d9e0abb932109ceToomas Soome UINTN bufsz = 0, i, j;
199767f8919635c4928607450d9e0abb932109ceToomas Soome EFI_STATUS status;
199767f8919635c4928607450d9e0abb932109ceToomas Soome int k, ret;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome status = BS->LocateHandle(AllHandles, NULL, NULL, &bufsz, buffer);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (status != EFI_BUFFER_TOO_SMALL) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome snprintf(command_errbuf, sizeof (command_errbuf),
199767f8919635c4928607450d9e0abb932109ceToomas Soome "unexpected error: %lld", (long long)status);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (CMD_ERROR);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome if ((buffer = malloc(bufsz)) == NULL) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome sprintf(command_errbuf, "out of memory");
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (CMD_ERROR);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome status = BS->LocateHandle(AllHandles, NULL, NULL, &bufsz, buffer);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (EFI_ERROR(status)) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome free(buffer);
199767f8919635c4928607450d9e0abb932109ceToomas Soome snprintf(command_errbuf, sizeof (command_errbuf),
199767f8919635c4928607450d9e0abb932109ceToomas Soome "LocateHandle() error: %lld", (long long)status);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (CMD_ERROR);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome pager_open();
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; i < (bufsz / sizeof (EFI_HANDLE)); i++) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome UINTN nproto = 0;
199767f8919635c4928607450d9e0abb932109ceToomas Soome EFI_GUID **protocols = NULL;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome handle = buffer[i];
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("Handle %p", handle);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (pager_output("\n"))
199767f8919635c4928607450d9e0abb932109ceToomas Soome break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* device path */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome status = BS->ProtocolsPerHandle(handle, &protocols, &nproto);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (EFI_ERROR(status)) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome snprintf(command_errbuf, sizeof (command_errbuf),
199767f8919635c4928607450d9e0abb932109ceToomas Soome "ProtocolsPerHandle() error: %lld",
199767f8919635c4928607450d9e0abb932109ceToomas Soome (long long)status);
199767f8919635c4928607450d9e0abb932109ceToomas Soome continue;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (j = 0; j < nproto; j++) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (k = 0; proto_names[k].name != NULL; k++)
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (memcmp(protocols[j], &proto_names[k].guid,
199767f8919635c4928607450d9e0abb932109ceToomas Soome sizeof (proto_names[k].guid)) == 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (proto_names[k].name != NULL)
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf(" %s", proto_names[k].name);
199767f8919635c4928607450d9e0abb932109ceToomas Soome else
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf(" %s", guid_to_string(protocols[j]));
199767f8919635c4928607450d9e0abb932109ceToomas Soome ret = pager_output("\n");
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (ret)
199767f8919635c4928607450d9e0abb932109ceToomas Soome break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome BS->FreePool(protocols);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (ret)
199767f8919635c4928607450d9e0abb932109ceToomas Soome break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome pager_close();
199767f8919635c4928607450d9e0abb932109ceToomas Soome free(buffer);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (CMD_OK);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef EFI_ZFS_BOOT
199767f8919635c4928607450d9e0abb932109ceToomas SoomeCOMMAND_SET(lszfs, "lszfs", "list child datasets of a zfs dataset",
199767f8919635c4928607450d9e0abb932109ceToomas Soome command_lszfs);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int
199767f8919635c4928607450d9e0abb932109ceToomas Soomecommand_lszfs(int argc, char *argv[])
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome int err;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (argc != 2) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome command_errmsg = "wrong number of arguments";
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (CMD_ERROR);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome err = zfs_list(argv[1]);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (err != 0) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome command_errmsg = strerror(err);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (CMD_ERROR);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (CMD_OK);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef __FreeBSD__
199767f8919635c4928607450d9e0abb932109ceToomas SoomeCOMMAND_SET(reloadbe, "reloadbe", "refresh the list of ZFS Boot Environments",
199767f8919635c4928607450d9e0abb932109ceToomas Soome command_reloadbe);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int
199767f8919635c4928607450d9e0abb932109ceToomas Soomecommand_reloadbe(int argc, char *argv[])
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome int err;
199767f8919635c4928607450d9e0abb932109ceToomas Soome char *root;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (argc > 2) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome command_errmsg = "wrong number of arguments";
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (CMD_ERROR);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (argc == 2) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome err = zfs_bootenv(argv[1]);
199767f8919635c4928607450d9e0abb932109ceToomas Soome } else {
199767f8919635c4928607450d9e0abb932109ceToomas Soome root = getenv("zfs_be_root");
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (root == NULL) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (CMD_OK);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome err = zfs_bootenv(root);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (err != 0) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome command_errmsg = strerror(err);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (CMD_ERROR);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (CMD_OK);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* __FreeBSD__ */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid
199767f8919635c4928607450d9e0abb932109ceToomas Soomeefi_serial_init(void)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome EFI_HANDLE *buffer = NULL;
199767f8919635c4928607450d9e0abb932109ceToomas Soome UINTN bufsz = 0, i;
199767f8919635c4928607450d9e0abb932109ceToomas Soome EFI_STATUS status;
199767f8919635c4928607450d9e0abb932109ceToomas Soome int serial = 0;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * get buffer size
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome status = BS->LocateHandle(ByProtocol, &serial_io, NULL, &bufsz, buffer);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (status != EFI_BUFFER_TOO_SMALL) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome snprintf(command_errbuf, sizeof (command_errbuf),
199767f8919635c4928607450d9e0abb932109ceToomas Soome "unexpected error: %lld", (long long)status);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome if ((buffer = malloc(bufsz)) == NULL) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome sprintf(command_errbuf, "out of memory");
199767f8919635c4928607450d9e0abb932109ceToomas Soome return;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * get handle array
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome status = BS->LocateHandle(ByProtocol, &serial_io, NULL, &bufsz, buffer);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (EFI_ERROR(status)) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome free(buffer);
199767f8919635c4928607450d9e0abb932109ceToomas Soome snprintf(command_errbuf, sizeof (command_errbuf),
199767f8919635c4928607450d9e0abb932109ceToomas Soome "LocateHandle() error: %lld", (long long)status);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; i < (bufsz / sizeof (EFI_HANDLE)); i++) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome SERIAL_IO_INTERFACE *sio;
199767f8919635c4928607450d9e0abb932109ceToomas Soome status = BS->OpenProtocol(buffer[i], &serial_io, (void**)&sio,
199767f8919635c4928607450d9e0abb932109ceToomas Soome IH, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (EFI_ERROR(status)) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome snprintf(command_errbuf, sizeof (command_errbuf),
199767f8919635c4928607450d9e0abb932109ceToomas Soome "OpenProtocol() error: %lld", (long long)status);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("serial# %d\n", serial++);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome free(buffer);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef LOADER_FDT_SUPPORT
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern int command_fdt_internal(int argc, char *argv[]);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Since proper fdt command handling function is defined in fdt_loader_cmd.c,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * and declaring it as extern is in contradiction with COMMAND_SET() macro
199767f8919635c4928607450d9e0abb932109ceToomas Soome * (which uses static pointer), we're defining wrapper function, which
199767f8919635c4928607450d9e0abb932109ceToomas Soome * calls the proper fdt handling routine.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int
199767f8919635c4928607450d9e0abb932109ceToomas Soomecommand_fdt(int argc, char *argv[])
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (command_fdt_internal(argc, argv));
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas SoomeCOMMAND_SET(fdt, "fdt", "flattened device tree handling", command_fdt);
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef EFI_ZFS_BOOT
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic void
199767f8919635c4928607450d9e0abb932109ceToomas Soomeefi_zfs_probe(void)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome EFI_HANDLE h;
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_int unit;
199767f8919635c4928607450d9e0abb932109ceToomas Soome int i;
199767f8919635c4928607450d9e0abb932109ceToomas Soome char dname[SPECNAMELEN + 1];
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t guid;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome unit = 0;
199767f8919635c4928607450d9e0abb932109ceToomas Soome h = efi_find_handle(&efipart_dev, 0);
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; h != NULL; h = efi_find_handle(&efipart_dev, ++i)) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome snprintf(dname, sizeof(dname), "%s%d:", efipart_dev.dv_name, i);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (zfs_probe_dev(dname, &guid) == 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome (void)efi_handle_update_dev(h, &zfs_dev, unit++, guid);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif