Changeset View
Changeset View
Standalone View
Standalone View
stand/efi/boot1/boot1.c
Show First 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | |||||
#define NUM_BOOT_MODULES nitems(boot_modules) | #define NUM_BOOT_MODULES nitems(boot_modules) | ||||
/* The initial number of handles used to query EFI for partitions. */ | /* The initial number of handles used to query EFI for partitions. */ | ||||
#define NUM_HANDLES_INIT 24 | #define NUM_HANDLES_INIT 24 | ||||
static EFI_GUID BlockIoProtocolGUID = BLOCK_IO_PROTOCOL; | static EFI_GUID BlockIoProtocolGUID = BLOCK_IO_PROTOCOL; | ||||
static EFI_GUID DevicePathGUID = DEVICE_PATH_PROTOCOL; | static EFI_GUID DevicePathGUID = DEVICE_PATH_PROTOCOL; | ||||
static EFI_GUID LoadedImageGUID = LOADED_IMAGE_PROTOCOL; | static EFI_GUID LoadedImageGUID = LOADED_IMAGE_PROTOCOL; | ||||
static EFI_GUID ConsoleControlGUID = EFI_CONSOLE_CONTROL_PROTOCOL_GUID; | static EFI_GUID ConsoleControlGUID = EFI_CONSOLE_CONTROL_PROTOCOL_GUID; | ||||
static EFI_GUID FreeBSDBootVarGUID = FREEBSD_BOOT_VAR_GUID; | |||||
static EFI_GUID GlobalBootVarGUID = UEFI_BOOT_VAR_GUID; | |||||
/* | /* | ||||
* Provide Malloc / Free backed by EFIs AllocatePool / FreePool which ensures | * Provide Malloc / Free backed by EFIs AllocatePool / FreePool which ensures | ||||
* memory is correctly aligned avoiding EFI_INVALID_PARAMETER returns from | * memory is correctly aligned avoiding EFI_INVALID_PARAMETER returns from | ||||
* EFI methods. | * EFI methods. | ||||
*/ | */ | ||||
void * | void * | ||||
Malloc(size_t len, const char *file __unused, int line __unused) | Malloc(size_t len, const char *file __unused, int line __unused) | ||||
{ | { | ||||
void *out; | void *out; | ||||
if (BS->AllocatePool(EfiLoaderData, len, &out) == EFI_SUCCESS) | if (BS->AllocatePool(EfiLoaderData, len, &out) == EFI_SUCCESS) | ||||
return (out); | return (out); | ||||
return (NULL); | return (NULL); | ||||
} | } | ||||
void | void | ||||
Free(void *buf, const char *file __unused, int line __unused) | Free(void *buf, const char *file __unused, int line __unused) | ||||
{ | { | ||||
if (buf != NULL) | if (buf != NULL) | ||||
(void)BS->FreePool(buf); | (void)BS->FreePool(buf); | ||||
} | } | ||||
static EFI_STATUS | |||||
efi_getenv(EFI_GUID *g, const char *v, void *data, size_t *len) | |||||
{ | |||||
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; | |||||
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); | |||||
} | |||||
/* | /* | ||||
* nodes_match returns TRUE if the imgpath isn't NULL and the nodes match, | * nodes_match returns TRUE if the imgpath isn't NULL and the nodes match, | ||||
* FALSE otherwise. | * FALSE otherwise. | ||||
*/ | */ | ||||
static BOOLEAN | static BOOLEAN | ||||
nodes_match(EFI_DEVICE_PATH *imgpath, EFI_DEVICE_PATH *devpath) | nodes_match(EFI_DEVICE_PATH *imgpath, EFI_DEVICE_PATH *devpath) | ||||
{ | { | ||||
size_t len; | size_t len; | ||||
▲ Show 20 Lines • Show All 373 Lines • ▼ Show 20 Lines | if (status != EFI_SUCCESS) { | ||||
efi_setenv_freebsd_wcs("Boot1Dev", text); | efi_setenv_freebsd_wcs("Boot1Dev", text); | ||||
efi_free_devpath_name(text); | efi_free_devpath_name(text); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
boot_current = 0; | boot_current = 0; | ||||
sz = sizeof(boot_current); | sz = sizeof(boot_current); | ||||
efi_getenv(&GlobalBootVarGUID, "BootCurrent", &boot_current, &sz); | efi_global_getenv("BootCurrent", &boot_current, &sz); | ||||
printf(" BootCurrent: %04x\n", boot_current); | printf(" BootCurrent: %04x\n", boot_current); | ||||
sz = sizeof(boot_order); | sz = sizeof(boot_order); | ||||
efi_getenv(&GlobalBootVarGUID, "BootOrder", &boot_order, &sz); | efi_global_getenv("BootOrder", &boot_order, &sz); | ||||
printf(" BootOrder:"); | printf(" BootOrder:"); | ||||
for (i = 0; i < sz / sizeof(boot_order[0]); i++) | for (i = 0; i < sz / sizeof(boot_order[0]); i++) | ||||
printf(" %04x", boot_order[i]); | printf(" %04x%s", boot_order[i], | ||||
boot_order[i] == boot_current ? "[*]" : ""); | |||||
printf("\n"); | printf("\n"); | ||||
#ifdef TEST_FAILURE | #ifdef TEST_FAILURE | ||||
/* | /* | ||||
* For testing failover scenarios, it's nice to be able to fail fast. | * For testing failover scenarios, it's nice to be able to fail fast. | ||||
* Define TEST_FAILURE to create a boot1.efi that always fails after | * Define TEST_FAILURE to create a boot1.efi that always fails after | ||||
* reporting the boot manager protocol details. | * reporting the boot manager protocol details. | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 102 Lines • Show Last 20 Lines |