Changeset View
Standalone View
stand/efi/loader/main.c
Show All 34 Lines | |||||
#include <stdint.h> | #include <stdint.h> | ||||
#include <stand.h> | #include <stand.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <setjmp.h> | #include <setjmp.h> | ||||
#include <disk.h> | #include <disk.h> | ||||
#include <efi.h> | #include <efi.h> | ||||
#include <efilib.h> | #include <efilib.h> | ||||
#include <efichar.h> | |||||
#include <uuid.h> | #include <uuid.h> | ||||
#include <bootstrap.h> | #include <bootstrap.h> | ||||
#include <smbios.h> | #include <smbios.h> | ||||
#ifdef EFI_ZFS_BOOT | #ifdef EFI_ZFS_BOOT | ||||
#include <libzfs.h> | #include <libzfs.h> | ||||
Show All 20 Lines | |||||
EFI_GUID lzmadecomp = LZMA_DECOMPRESSION_GUID; | EFI_GUID lzmadecomp = LZMA_DECOMPRESSION_GUID; | ||||
EFI_GUID mpcore = ARM_MP_CORE_INFO_TABLE_GUID; | EFI_GUID mpcore = ARM_MP_CORE_INFO_TABLE_GUID; | ||||
EFI_GUID esrt = ESRT_TABLE_GUID; | EFI_GUID esrt = ESRT_TABLE_GUID; | ||||
EFI_GUID memtype = MEMORY_TYPE_INFORMATION_TABLE_GUID; | EFI_GUID memtype = MEMORY_TYPE_INFORMATION_TABLE_GUID; | ||||
EFI_GUID debugimg = DEBUG_IMAGE_INFO_TABLE_GUID; | EFI_GUID debugimg = DEBUG_IMAGE_INFO_TABLE_GUID; | ||||
EFI_GUID fdtdtb = FDT_TABLE_GUID; | EFI_GUID fdtdtb = FDT_TABLE_GUID; | ||||
EFI_GUID inputid = SIMPLE_TEXT_INPUT_PROTOCOL; | EFI_GUID inputid = SIMPLE_TEXT_INPUT_PROTOCOL; | ||||
static EFI_GUID FreeBSDBootVarGUID = FREEBSD_BOOT_VAR_GUID; | |||||
tsoome: those 2 are not needed as we have them in efienv.c | |||||
static EFI_GUID GlobalBootVarGUID = UEFI_BOOT_VAR_GUID; | |||||
static EFI_LOADED_IMAGE *img; | static EFI_LOADED_IMAGE *img; | ||||
/* | |||||
* Number of seconds to wait for a keystroke before exiting with failure | |||||
* in the event no currdev is found. -2 means always break, -1 means | |||||
* never break, 0 means poll once and then reboot, > 0 means wait for | |||||
* that many seconds. "fail_timeout" can be set in the environment as | |||||
* well. | |||||
*/ | |||||
static int fail_timeout = 5; | |||||
#ifdef EFI_ZFS_BOOT | #ifdef EFI_ZFS_BOOT | ||||
bool | bool | ||||
efi_zfs_is_preferred(EFI_HANDLE *h) | efi_zfs_is_preferred(EFI_HANDLE *h) | ||||
{ | { | ||||
return (h == img->DeviceHandle); | return (h == img->DeviceHandle); | ||||
Not Done Inline ActionsNote, this statement is only true when you start loader manually with chain command. The problem is that by default, the img->DeviceHandle is handle for ESP of the booted disk, meaning that we should first find the boot disk itself, then we can check if the handle is for partition on that disk. tsoome: Note, this statement is only true when you start loader manually with chain command.
The… | |||||
Not Done Inline ActionsHow do we find that disk? imp: How do we find that disk? | |||||
Not Done Inline ActionsOr put another way, is this a problem? If we were chain loaded, it's the right answer. If we weren't, we have to go ahunting, and that's done elsewhere. imp: Or put another way, is this a problem? If we were chain loaded, it's the right answer. If we… | |||||
Not Done Inline ActionsWe can find this disk by fetching the devicepath, then chop off the last item (partition), then fetch handle for reminder. This is what we do in efipart. It may or may not be issue; it really depends on how the firmware will present and order the disks - if we will always get boot disk first or not. It can be quite annoying if booted from usb disk, on disk move etc - all the scenarios where the boot variable can not be set up yet. PS: it is not showstopper - I also did test this patch on illumos port and I was able to boot without boot1. I am in process of building such disk check (as in illumos I plan to use partition start LBA for time being). tsoome: We can find this disk by fetching the devicepath, then chop off the last item (partition), then… | |||||
} | } | ||||
#endif | #endif | ||||
static int | static int | ||||
has_keyboard(void) | has_keyboard(void) | ||||
{ | { | ||||
EFI_STATUS status; | EFI_STATUS status; | ||||
EFI_DEVICE_PATH *path; | EFI_DEVICE_PATH *path; | ||||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | for (walker = hin; walker < hin_end; walker++) { | ||||
} | } | ||||
} | } | ||||
out: | out: | ||||
free(hin); | free(hin); | ||||
return retval; | return retval; | ||||
} | } | ||||
static void | static void | ||||
set_devdesc_currdev(struct devsw *dev, int unit) | set_currdev_devdesc(struct devdesc *currdev) | ||||
{ | { | ||||
const char *devname; | |||||
devname = efi_fmtdev(currdev); | |||||
printf("Setting currdev to %s\n", devname); | |||||
env_setenv("currdev", EV_VOLATILE, devname, efi_setcurrdev, env_nounset); | |||||
env_setenv("loaddev", EV_VOLATILE, devname, env_noset, env_nounset); | |||||
} | |||||
static void | |||||
set_currdev_devsw(struct devsw *dev, int unit) | |||||
{ | |||||
struct devdesc currdev; | struct devdesc currdev; | ||||
char *devname; | |||||
currdev.d_dev = dev; | currdev.d_dev = dev; | ||||
currdev.d_type = currdev.d_dev->dv_type; | |||||
currdev.d_unit = unit; | currdev.d_unit = unit; | ||||
currdev.d_opendata = NULL; | currdev.d_opendata = NULL; | ||||
devname = efi_fmtdev(&currdev); | |||||
env_setenv("currdev", EV_VOLATILE, devname, efi_setcurrdev, | set_currdev_devdesc(&currdev); | ||||
env_nounset); | |||||
env_setenv("loaddev", EV_VOLATILE, devname, env_noset, env_nounset); | |||||
} | } | ||||
static int | static void | ||||
find_currdev(EFI_LOADED_IMAGE *img) | set_currdev_pdinfo(pdinfo_t *dp) | ||||
{ | { | ||||
pdinfo_list_t *pdi_list; | |||||
pdinfo_t *dp, *pp; | |||||
EFI_DEVICE_PATH *devpath, *copy; | |||||
EFI_HANDLE h; | |||||
char *devname; | |||||
struct devsw *dev; | |||||
int unit; | |||||
uint64_t extra; | |||||
/* | |||||
* Disks are special: they have partitions. if the parent | |||||
* pointer is non-null, we're a partition not a full disk | |||||
* and we need to adjust currdev appropriately. | |||||
*/ | |||||
if (dp->pd_devsw->dv_type == DEVT_DISK) { | |||||
struct disk_devdesc currdev; | |||||
currdev.d_dev = dp->pd_devsw; | |||||
currdev.d_opendata = NULL; | |||||
if (dp->pd_parent == NULL) { | |||||
currdev.d_unit = dp->pd_unit; | |||||
currdev.d_slice = -1; | |||||
currdev.d_partition = -1; | |||||
} else { | |||||
currdev.d_unit = dp->pd_parent->pd_unit; | |||||
currdev.d_slice = dp->pd_unit; | |||||
currdev.d_partition = 255; /* Assumes GPT */ | |||||
} | |||||
set_currdev_devdesc((struct devdesc *)&currdev); | |||||
} else { | |||||
set_currdev_devsw(dp->pd_devsw, dp->pd_unit); | |||||
} | |||||
} | |||||
static bool | |||||
sanity_check_currdev(void) | |||||
{ | |||||
struct stat st; | |||||
return (stat("/boot/defaults/loader.conf", &st) == 0); | |||||
} | |||||
#ifdef EFI_ZFS_BOOT | #ifdef EFI_ZFS_BOOT | ||||
/* Did efi_zfs_probe() detect the boot pool? */ | static bool | ||||
if (pool_guid != 0) { | probe_zfs_currdev(uint64_t guid) | ||||
{ | |||||
char *devname; | |||||
struct zfs_devdesc currdev; | struct zfs_devdesc currdev; | ||||
currdev.d_dev = &zfs_dev; | currdev.d_dev = &zfs_dev; | ||||
currdev.d_unit = 0; | currdev.d_unit = 0; | ||||
currdev.d_type = currdev.d_dev->dv_type; | |||||
currdev.d_opendata = NULL; | currdev.d_opendata = NULL; | ||||
currdev.pool_guid = pool_guid; | currdev.pool_guid = guid; | ||||
currdev.root_guid = 0; | currdev.root_guid = 0; | ||||
set_currdev_devdesc((struct devdesc *)&currdev); | |||||
devname = efi_fmtdev(&currdev); | devname = efi_fmtdev(&currdev); | ||||
env_setenv("currdev", EV_VOLATILE, devname, efi_setcurrdev, | |||||
env_nounset); | |||||
env_setenv("loaddev", EV_VOLATILE, devname, env_noset, | |||||
env_nounset); | |||||
init_zfs_bootenv(devname); | init_zfs_bootenv(devname); | ||||
return (0); | |||||
return (sanity_check_currdev()); | |||||
} | } | ||||
#endif /* EFI_ZFS_BOOT */ | #endif | ||||
/* We have device lists for hd, cd, fd, walk them all. */ | static bool | ||||
pdi_list = efiblk_get_pdinfo_list(&efipart_hddev); | try_as_currdev(pdinfo_t *hd, pdinfo_t *pp) | ||||
STAILQ_FOREACH(dp, pdi_list, pd_link) { | { | ||||
struct disk_devdesc currdev; | uint64_t guid; | ||||
currdev.d_dev = &efipart_hddev; | #ifdef EFI_ZFS_BOOT | ||||
currdev.d_type = currdev.d_dev->dv_type; | /* | ||||
currdev.d_unit = dp->pd_unit; | * If there's a zpool on this device, try it as a ZFS | ||||
currdev.d_opendata = NULL; | * filesystem, which has somewhat different setup than all | ||||
currdev.d_slice = -1; | * other types of fs due to imperfect loader integration. | ||||
currdev.d_partition = -1; | * This all stems from ZFS being both a device (zpool) and | ||||
* a filesystem, plus the boot env feature. | |||||
*/ | |||||
Done Inline ActionsZFS breaks because this no longer sets currdev.d_type. zfs_fmtdev @ stand/zfs/zfs.c:703 checks dev->d_type rather than dev->d_dev->dv_type. kevans: ZFS breaks because this no longer sets `currdev.d_type`. zfs_fmtdev @ stand/zfs/zfs.c:703… | |||||
Done Inline ActionsThen I'll have to fix ZFS to cope. imp: Then I'll have to fix ZFS to cope. | |||||
if (efizfs_get_guid_by_handle(pp->pd_handle, &guid)) | |||||
return (probe_zfs_currdev(guid)); | |||||
#endif | |||||
/* | |||||
* All other filesystems just need the pdinfo | |||||
* initialized in the standard way. | |||||
*/ | |||||
set_currdev_pdinfo(pp); | |||||
return (sanity_check_currdev()); | |||||
} | |||||
if (dp->pd_handle == img->DeviceHandle) { | static int | ||||
Done Inline Actionswhile there, I did change int to bool... as we only return 0 or ENOENT and this function is bool by nature... tsoome: while there, I did change int to bool... as we only return 0 or ENOENT and this function is… | |||||
Not Done Inline ActionsI don't want to break things that have been tested, so declining this for now. imp: I don't want to break things that have been tested, so declining this for now.
| |||||
devname = efi_fmtdev(&currdev); | find_currdev(EFI_LOADED_IMAGE *img) | ||||
{ | |||||
pdinfo_t *dp, *pp; | |||||
Done Inline Actionsleftover. tsoome: leftover. | |||||
EFI_DEVICE_PATH *devpath, *copy; | |||||
EFI_HANDLE h; | |||||
CHAR16 *text; | |||||
struct devsw *dev; | |||||
int unit; | |||||
Done Inline Actionslaoder.conf => loader.conf =) kevans: laoder.conf => loader.conf =) | |||||
Done Inline Actions/boot/loader.rc I think is better. imp: /boot/loader.rc I think is better.
| |||||
Done Inline ActionsOn further thought, I think it might be best to drop this sanity check until loader grows GELI support... I'll do some more testing tomorrow with it installed as loader.efi on my non-GELI ZFS laptop, but this test would actively break my primary laptop whether it's installed as loader.efi or to ESP. kevans: On further thought, I think it might be best to drop this sanity check until loader grows GELI… | |||||
Done Inline ActionsNot 100% true since I switch between encrypted and unencrypted /boot kevans: Not 100% true since I switch between encrypted and unencrypted /boot | |||||
Done Inline Actions/ needs to be readable. If it isn't readable, we can't use it. GELI will have to have keys loaded by the time this is called for it to work. imp: / needs to be readable. If it isn't readable, we can't use it. GELI will have to have keys… | |||||
uint64_t extra; | |||||
env_setenv("currdev", EV_VOLATILE, devname, | #ifdef EFI_ZFS_BOOT | ||||
efi_setcurrdev, env_nounset); | /* | ||||
env_setenv("loaddev", EV_VOLATILE, devname, | * Did efi_zfs_probe() detect the boot pool? If so, use the zpool | ||||
env_noset, env_nounset); | * it found, if it's sane. ZFS is the only thing that looks for | ||||
* disks and pools to boot. This may change in the future, however, | |||||
* if we allow specifying which pool to boot from via UEFI variables | |||||
* rather than the bootenv stuff that FreeBSD uses today. | |||||
*/ | |||||
if (pool_guid != 0) { | |||||
printf("Trying ZFS pool\n"); | |||||
if (probe_zfs_currdev(pool_guid)) | |||||
return (0); | return (0); | ||||
} | } | ||||
/* Assuming GPT partitioning. */ | #endif /* EFI_ZFS_BOOT */ | ||||
STAILQ_FOREACH(pp, &dp->pd_part, pd_link) { | |||||
if (pp->pd_handle == img->DeviceHandle) { | |||||
currdev.d_slice = pp->pd_unit; | |||||
currdev.d_partition = 255; | |||||
devname = efi_fmtdev(&currdev); | |||||
env_setenv("currdev", EV_VOLATILE, devname, | /* | ||||
efi_setcurrdev, env_nounset); | * Try to find the block device by its handle based on the | ||||
env_setenv("loaddev", EV_VOLATILE, devname, | * image we're booting. If we can't find a sane partition, | ||||
env_noset, env_nounset); | * search all the other partitions of the disk. We do not | ||||
return (0); | * search other disks because it's a violation of the UEFI | ||||
* boot protocol to do so. We fail and let UEFI go on to | |||||
* the next candidate. | |||||
*/ | |||||
dp = efiblk_get_pdinfo_by_handle(img->DeviceHandle); | |||||
if (dp != NULL) { | |||||
text = efi_devpath_name(dp->pd_devpath); | |||||
if (text != NULL) { | |||||
printf("Trying ESP: %S\n", text); | |||||
efi_free_devpath_name(text); | |||||
} | } | ||||
} | set_currdev_pdinfo(dp); | ||||
} | if (sanity_check_currdev()) | ||||
pdi_list = efiblk_get_pdinfo_list(&efipart_cddev); | |||||
STAILQ_FOREACH(dp, pdi_list, pd_link) { | |||||
if (dp->pd_handle == img->DeviceHandle || | |||||
dp->pd_alias == img->DeviceHandle) { | |||||
set_devdesc_currdev(&efipart_cddev, dp->pd_unit); | |||||
return (0); | return (0); | ||||
if (dp->pd_parent != NULL) { | |||||
dp = dp->pd_parent; | |||||
STAILQ_FOREACH(pp, &dp->pd_part, pd_link) { | |||||
text = efi_devpath_name(pp->pd_devpath); | |||||
if (text != NULL) { | |||||
printf("And now the part: %S\n", text); | |||||
efi_free_devpath_name(text); | |||||
} | } | ||||
} | /* | ||||
* Roll up the ZFS special case | |||||
pdi_list = efiblk_get_pdinfo_list(&efipart_fddev); | * for those partitions that have | ||||
STAILQ_FOREACH(dp, pdi_list, pd_link) { | * zpools on them | ||||
if (dp->pd_handle == img->DeviceHandle) { | */ | ||||
set_devdesc_currdev(&efipart_fddev, dp->pd_unit); | if (try_as_currdev(dp, pp)) | ||||
return (0); | return (0); | ||||
} | } | ||||
} | } | ||||
} else { | |||||
printf("Can't find device by handle\n"); | |||||
} | |||||
/* | /* | ||||
* Try the device handle from our loaded image first. If that | * Try the device handle from our loaded image first. If that | ||||
* fails, use the device path from the loaded image and see if | * fails, use the device path from the loaded image and see if | ||||
* any of the nodes in that path match one of the enumerated | * any of the nodes in that path match one of the enumerated | ||||
* handles. | * handles. Currently, this handle list is only for netboot. | ||||
*/ | */ | ||||
if (efi_handle_lookup(img->DeviceHandle, &dev, &unit, &extra) == 0) { | if (efi_handle_lookup(img->DeviceHandle, &dev, &unit, &extra) == 0) { | ||||
set_devdesc_currdev(dev, unit); | set_currdev_devsw(dev, unit); | ||||
if (sanity_check_currdev()) | |||||
return (0); | return (0); | ||||
} | } | ||||
copy = NULL; | copy = NULL; | ||||
devpath = efi_lookup_image_devpath(IH); | devpath = efi_lookup_image_devpath(IH); | ||||
while (devpath != NULL) { | while (devpath != NULL) { | ||||
h = efi_devpath_handle(devpath); | h = efi_devpath_handle(devpath); | ||||
if (h == NULL) | if (h == NULL) | ||||
break; | break; | ||||
free(copy); | free(copy); | ||||
copy = NULL; | copy = NULL; | ||||
if (efi_handle_lookup(h, &dev, &unit, &extra) == 0) { | if (efi_handle_lookup(h, &dev, &unit, &extra) == 0) { | ||||
set_devdesc_currdev(dev, unit); | set_currdev_devsw(dev, unit); | ||||
if (sanity_check_currdev()) | |||||
return (0); | return (0); | ||||
} | } | ||||
devpath = efi_lookup_devpath(h); | devpath = efi_lookup_devpath(h); | ||||
if (devpath != NULL) { | if (devpath != NULL) { | ||||
copy = efi_devpath_trim(devpath); | copy = efi_devpath_trim(devpath); | ||||
devpath = copy; | devpath = copy; | ||||
} | } | ||||
} | } | ||||
free(copy); | free(copy); | ||||
return (ENOENT); | return (ENOENT); | ||||
} | } | ||||
static EFI_STATUS | |||||
efi_getenv(EFI_GUID *g, const char *v, void *data, size_t *len) | |||||
tsoomeUnsubmitted Not Done Inline ActionsIsnt it better to have this and efi_setenv_freebsd_wcs in libefi/env.c? tsoome: Isnt it better to have this and efi_setenv_freebsd_wcs in libefi/env.c? | |||||
{ | |||||
size_t ul; | |||||
CHAR16 *uv; | |||||
UINT32 attr; | |||||
UINTN dl; | |||||
EFI_STATUS rv; | |||||
uv = NULL; | |||||
if (utf8_to_ucs2(v, &uv, &ul) != 0) | |||||
return (EFI_OUT_OF_RESOURCES); | |||||
dl = *len; | |||||
rv = RS->GetVariable(uv, g, &attr, &dl, data); | |||||
if (rv == EFI_SUCCESS) | |||||
*len = dl; | |||||
Done Inline Actionssmall nit. warning: format '%d' expects type 'int', but argument 2 has type 'time_t' [-Wformat] perhaps use: (int)(now - then) + fail_timeout tsoome: small nit.
warning: format '%d' expects type 'int', but argument 2 has type 'time_t'… | |||||
Done Inline ActionsNow that you mention it, that should probably be something more like: fail_timeout - (int)(now - then) -- this counter is probably going the wrong way, though I've not paid attention, since now - then is always increasing and fail_timeout remains constant. kevans: Now that you mention it, that should probably be something more like: `fail_timeout - (int)(now… | |||||
free(uv); | |||||
return (rv); | |||||
} | |||||
static EFI_STATUS | |||||
efi_setenv_freebsd_wcs(const char *varname, CHAR16 *valstr) | |||||
{ | |||||
CHAR16 *var = NULL; | |||||
size_t len; | |||||
EFI_STATUS rv; | |||||
if (utf8_to_ucs2(varname, &var, &len) != 0) | |||||
return (EFI_OUT_OF_RESOURCES); | |||||
rv = RS->SetVariable(var, &FreeBSDBootVarGUID, | |||||
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, | |||||
(ucs2len(valstr) + 1) * sizeof(efi_char), valstr); | |||||
free(var); | |||||
return (rv); | |||||
} | |||||
static bool | |||||
interactive_interrupt(const char *msg) | |||||
{ | |||||
time_t now, then, last; | |||||
last = 0; | |||||
now = then = getsecs(); | |||||
printf("%s\n", msg); | |||||
if (fail_timeout == -2) /* Always break to OK */ | |||||
return (true); | |||||
if (fail_timeout == -1) /* Never break to OK */ | |||||
return (false); | |||||
do { | |||||
if (last != now) { | |||||
printf("press any key to interrupt reboot in %d seconds\r", | |||||
fail_timeout - (int)(now - then)); | |||||
last = now; | |||||
} | |||||
/* XXX no pause or timeout wait for char */ | |||||
if (ischar()) | |||||
return (true); | |||||
now = getsecs(); | |||||
} while (now - then < fail_timeout); | |||||
return (false); | |||||
} | |||||
EFI_STATUS | EFI_STATUS | ||||
main(int argc, CHAR16 *argv[]) | main(int argc, CHAR16 *argv[]) | ||||
{ | { | ||||
char var[128]; | char var[128]; | ||||
EFI_GUID *guid; | EFI_GUID *guid; | ||||
int i, j, vargood, howto; | int i, j, vargood, howto; | ||||
UINTN k; | UINTN k; | ||||
int has_kbd; | int has_kbd; | ||||
char *s; | |||||
EFI_DEVICE_PATH *imgpath; | |||||
CHAR16 *text; | |||||
EFI_STATUS status; | |||||
UINT16 boot_current; | |||||
size_t sz; | |||||
UINT16 boot_order[100]; | |||||
#if !defined(__arm__) | #if !defined(__arm__) | ||||
char buf[40]; | char buf[40]; | ||||
#endif | #endif | ||||
archsw.arch_autoload = efi_autoload; | archsw.arch_autoload = efi_autoload; | ||||
archsw.arch_getdev = efi_getdev; | archsw.arch_getdev = efi_getdev; | ||||
archsw.arch_copyin = efi_copyin; | archsw.arch_copyin = efi_copyin; | ||||
archsw.arch_copyout = efi_copyout; | archsw.arch_copyout = efi_copyout; | ||||
Show All 22 Lines | #endif | ||||
/* | /* | ||||
* Initialise the block cache. Set the upper limit. | * Initialise the block cache. Set the upper limit. | ||||
*/ | */ | ||||
bcache_init(32768, 512); | bcache_init(32768, 512); | ||||
/* | /* | ||||
* Parse the args to set the console settings, etc | * Parse the args to set the console settings, etc | ||||
* boot1.efi passes these in, if it can read /boot.config or /boot/config | * boot1.efi passes these in, if it can read /boot.config or /boot/config | ||||
* or iPXE may be setup to pass these in. | * or iPXE may be setup to pass these in. Or the optional argument in the | ||||
* boot environment was used to pass these arguments in (in which case | |||||
* neither /boot.config nor /boot/config are consulted). | |||||
* | * | ||||
* Loop through the args, and for each one that contains an '=' that is | * Loop through the args, and for each one that contains an '=' that is | ||||
* not the first character, add it to the environment. This allows | * not the first character, add it to the environment. This allows | ||||
* loader and kernel env vars to be passed on the command line. Convert | * loader and kernel env vars to be passed on the command line. Convert | ||||
* args from UCS-2 to ASCII (16 to 8 bit) as they are copied. | * args from UCS-2 to ASCII (16 to 8 bit) as they are copied (though this | ||||
* method is flawed for non-ASCII characters). | |||||
*/ | */ | ||||
howto = 0; | howto = 0; | ||||
for (i = 1; i < argc; i++) { | for (i = 1; i < argc; i++) { | ||||
if (argv[i][0] == '-') { | if (argv[i][0] == '-') { | ||||
for (j = 1; argv[i][j] != 0; j++) { | for (j = 1; argv[i][j] != 0; j++) { | ||||
int ch; | int ch; | ||||
ch = argv[i][j]; | ch = argv[i][j]; | ||||
▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | if (argv[i][0] == '-') { | ||||
var[j] = 0; | var[j] = 0; | ||||
putenv(var); | putenv(var); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
for (i = 0; howto_names[i].ev != NULL; i++) | for (i = 0; howto_names[i].ev != NULL; i++) | ||||
if (howto & howto_names[i].mask) | if (howto & howto_names[i].mask) | ||||
setenv(howto_names[i].ev, "YES", 1); | setenv(howto_names[i].ev, "YES", 1); | ||||
/* | |||||
* XXX we need fallback to this stuff after looking at the ConIn, ConOut and ConErr variables | |||||
*/ | |||||
if (howto & RB_MULTIPLE) { | if (howto & RB_MULTIPLE) { | ||||
if (howto & RB_SERIAL) | if (howto & RB_SERIAL) | ||||
setenv("console", "comconsole efi" , 1); | setenv("console", "comconsole efi" , 1); | ||||
else | else | ||||
setenv("console", "efi comconsole" , 1); | setenv("console", "efi comconsole" , 1); | ||||
} else if (howto & RB_SERIAL) { | } else if (howto & RB_SERIAL) { | ||||
setenv("console", "comconsole" , 1); | setenv("console", "comconsole" , 1); | ||||
} | } else | ||||
setenv("console", "efi", 1); | |||||
if (efi_copy_init()) { | if (efi_copy_init()) { | ||||
printf("failed to allocate staging area\n"); | printf("failed to allocate staging area\n"); | ||||
return (EFI_BUFFER_TOO_SMALL); | return (EFI_BUFFER_TOO_SMALL); | ||||
} | } | ||||
if ((s = getenv("fail_timeout")) != NULL) | |||||
fail_timeout = strtol(s, NULL, 10); | |||||
Not Done Inline Actionswhat will happen if fail_timeout is set to garbage? tsoome: what will happen if fail_timeout is set to garbage? | |||||
Not Done Inline Actionsfail timeout will be 0. imp: fail timeout will be 0. | |||||
/* | /* | ||||
* Scan the BLOCK IO MEDIA handles then | * Scan the BLOCK IO MEDIA handles then | ||||
* march through the device switch probing for things. | * march through the device switch probing for things. | ||||
*/ | */ | ||||
if ((i = efipart_inithandles()) == 0) { | if ((i = efipart_inithandles()) == 0) { | ||||
for (i = 0; devsw[i] != NULL; i++) | for (i = 0; devsw[i] != NULL; i++) | ||||
if (devsw[i]->dv_init != NULL) | if (devsw[i]->dv_init != NULL) | ||||
(devsw[i]->dv_init)(); | (devsw[i]->dv_init)(); | ||||
} else | } else | ||||
printf("efipart_inithandles failed %d, expect failures", i); | printf("efipart_inithandles failed %d, expect failures", i); | ||||
printf("Command line arguments:"); | printf("Command line arguments:"); | ||||
for (i = 0; i < argc; i++) | for (i = 0; i < argc; i++) | ||||
printf(" %S", argv[i]); | printf(" %S", argv[i]); | ||||
printf("\n"); | printf("\n"); | ||||
printf("Image base: 0x%lx\n", (u_long)img->ImageBase); | printf("Image base: 0x%lx\n", (u_long)img->ImageBase); | ||||
printf("EFI version: %d.%02d\n", ST->Hdr.Revision >> 16, | printf("EFI version: %d.%02d\n", ST->Hdr.Revision >> 16, | ||||
ST->Hdr.Revision & 0xffff); | ST->Hdr.Revision & 0xffff); | ||||
printf("EFI Firmware: %S (rev %d.%02d)\n", ST->FirmwareVendor, | printf("EFI Firmware: %S (rev %d.%02d)\n", ST->FirmwareVendor, | ||||
ST->FirmwareRevision >> 16, ST->FirmwareRevision & 0xffff); | ST->FirmwareRevision >> 16, ST->FirmwareRevision & 0xffff); | ||||
printf("\n%s", bootprog_info); | printf("\n%s", bootprog_info); | ||||
/* Determine the devpath of our image so we can prefer it. */ | |||||
text = efi_devpath_name(img->FilePath); | |||||
if (text != NULL) { | |||||
printf(" Load Path: %S\n", text); | |||||
efi_setenv_freebsd_wcs("LoaderPath", text); | |||||
efi_free_devpath_name(text); | |||||
} | |||||
status = BS->HandleProtocol(img->DeviceHandle, &devid, (void **)&imgpath); | |||||
if (status == EFI_SUCCESS) { | |||||
text = efi_devpath_name(imgpath); | |||||
if (text != NULL) { | |||||
printf(" Load Device: %S\n", text); | |||||
efi_setenv_freebsd_wcs("LoaderDev", text); | |||||
efi_free_devpath_name(text); | |||||
} | |||||
} | |||||
boot_current = 0; | |||||
sz = sizeof(boot_current); | |||||
efi_getenv(&GlobalBootVarGUID, "BootCurrent", &boot_current, &sz); | |||||
printf(" BootCurrent: %04x\n", boot_current); | |||||
sz = sizeof(boot_order); | |||||
efi_getenv(&GlobalBootVarGUID, "BootOrder", &boot_order, &sz); | |||||
printf(" BootOrder:"); | |||||
for (i = 0; i < sz / sizeof(boot_order[0]); i++) | |||||
printf(" %04x%s", boot_order[i], | |||||
boot_order[i] == boot_current ? "[*]" : ""); | |||||
printf("\n"); | |||||
/* | /* | ||||
* Disable the watchdog timer. By default the boot manager sets | * Disable the watchdog timer. By default the boot manager sets | ||||
* the timer to 5 minutes before invoking a boot option. If we | * the timer to 5 minutes before invoking a boot option. If we | ||||
* want to return to the boot manager, we have to disable the | * want to return to the boot manager, we have to disable the | ||||
* watchdog timer and since we're an interactive program, we don't | * watchdog timer and since we're an interactive program, we don't | ||||
* want to wait until the user types "quit". The timer may have | * want to wait until the user types "quit". The timer may have | ||||
* fired by then. We don't care if this fails. It does not prevent | * fired by then. We don't care if this fails. It does not prevent | ||||
* normal functioning in any way... | * normal functioning in any way... | ||||
*/ | */ | ||||
BS->SetWatchdogTimer(0, 0, 0, NULL); | BS->SetWatchdogTimer(0, 0, 0, NULL); | ||||
/* | |||||
* Try and find a good currdev based on the image that was booted. | |||||
* It might be desirable here to have a short pause to allow falling | |||||
* through to the boot loader instead of returning instantly to follow | |||||
* the boot protocol and also allow an escape hatch for users wishing | |||||
* to try something different. | |||||
*/ | |||||
if (find_currdev(img) != 0) | if (find_currdev(img) != 0) | ||||
if (!interactive_interrupt("Failed to find bootable partition")) | |||||
return (EFI_NOT_FOUND); | return (EFI_NOT_FOUND); | ||||
efi_init_environment(); | efi_init_environment(); | ||||
setenv("LINES", "24", 1); /* optional */ | setenv("LINES", "48", 1); /* optional */ | ||||
tsoomeUnsubmitted Not Done Inline ActionsThis should not be arbitrary value, it should come from conout->QueryMode() - see command_mode() below. tsoome: This should not be arbitrary value, it should come from conout->QueryMode() - see command_mode… | |||||
for (k = 0; k < ST->NumberOfTableEntries; k++) { | for (k = 0; k < ST->NumberOfTableEntries; k++) { | ||||
guid = &ST->ConfigurationTable[k].VendorGuid; | guid = &ST->ConfigurationTable[k].VendorGuid; | ||||
#if !defined(__arm__) | #if !defined(__arm__) | ||||
if (!memcmp(guid, &smbios, sizeof(EFI_GUID))) { | if (!memcmp(guid, &smbios, sizeof(EFI_GUID))) { | ||||
snprintf(buf, sizeof(buf), "%p", | snprintf(buf, sizeof(buf), "%p", | ||||
ST->ConfigurationTable[k].VendorTable); | ST->ConfigurationTable[k].VendorTable); | ||||
setenv("hint.smbios.0.mem", buf, 1); | setenv("hint.smbios.0.mem", buf, 1); | ||||
▲ Show 20 Lines • Show All 337 Lines • ▼ Show 20 Lines | command_chain(int argc, char *argv[]) | ||||
if (efi_getdev((void **)&dev, name, (const char **)&path) == 0) { | if (efi_getdev((void **)&dev, name, (const char **)&path) == 0) { | ||||
#ifdef EFI_ZFS_BOOT | #ifdef EFI_ZFS_BOOT | ||||
struct zfs_devdesc *z_dev; | struct zfs_devdesc *z_dev; | ||||
#endif | #endif | ||||
struct disk_devdesc *d_dev; | struct disk_devdesc *d_dev; | ||||
pdinfo_t *hd, *pd; | pdinfo_t *hd, *pd; | ||||
switch (dev->d_type) { | switch (dev->d_dev->dv_type) { | ||||
#ifdef EFI_ZFS_BOOT | #ifdef EFI_ZFS_BOOT | ||||
case DEVT_ZFS: | case DEVT_ZFS: | ||||
z_dev = (struct zfs_devdesc *)dev; | z_dev = (struct zfs_devdesc *)dev; | ||||
loaded_image->DeviceHandle = | loaded_image->DeviceHandle = | ||||
efizfs_get_handle_by_guid(z_dev->pool_guid); | efizfs_get_handle_by_guid(z_dev->pool_guid); | ||||
break; | break; | ||||
#endif | #endif | ||||
case DEVT_NET: | case DEVT_NET: | ||||
Show All 38 Lines |
those 2 are not needed as we have them in efienv.c