mirror of
https://github.com/freebsd/freebsd-src
synced 2024-10-08 01:20:40 +00:00
Move the env convenience routines out of boot1.c.
These routines are more generally useful. Even though boot1 is on its way out, it's better to make these common during the transition than copy them.
This commit is contained in:
parent
f7b26b765b
commit
5722dd8394
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=330813
|
@ -54,8 +54,6 @@ static EFI_GUID BlockIoProtocolGUID = BLOCK_IO_PROTOCOL;
|
|||
static EFI_GUID DevicePathGUID = DEVICE_PATH_PROTOCOL;
|
||||
static EFI_GUID LoadedImageGUID = LOADED_IMAGE_PROTOCOL;
|
||||
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
|
||||
|
@ -80,42 +78,6 @@ Free(void *buf, const char *file __unused, int line __unused)
|
|||
(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,
|
||||
* FALSE otherwise.
|
||||
|
@ -505,11 +467,11 @@ efi_main(EFI_HANDLE Ximage, EFI_SYSTEM_TABLE *Xsystab)
|
|||
|
||||
boot_current = 0;
|
||||
sz = sizeof(boot_current);
|
||||
efi_getenv(&GlobalBootVarGUID, "BootCurrent", &boot_current, &sz);
|
||||
efi_global_getenv("BootCurrent", &boot_current, &sz);
|
||||
printf(" BootCurrent: %04x\n", boot_current);
|
||||
|
||||
sz = sizeof(boot_order);
|
||||
efi_getenv(&GlobalBootVarGUID, "BootOrder", &boot_order, &sz);
|
||||
efi_global_getenv("BootOrder", &boot_order, &sz);
|
||||
printf(" BootOrder:");
|
||||
for (i = 0; i < sz / sizeof(boot_order[0]); i++)
|
||||
printf(" %04x", boot_order[i]);
|
||||
|
|
|
@ -106,6 +106,17 @@ int wcscmp(CHAR16 *, CHAR16 *);
|
|||
void cpy8to16(const char *, CHAR16 *, size_t);
|
||||
void cpy16to8(const CHAR16 *, char *, size_t);
|
||||
|
||||
/*
|
||||
* Routines for interacting with EFI's env vars in a more unix-like
|
||||
* way than the standard APIs. In addition, convenience routines for
|
||||
* the loader setting / getting FreeBSD specific variables.
|
||||
*/
|
||||
|
||||
EFI_STATUS efi_freebsd_getenv(const char *v, void *data, __size_t *len);
|
||||
EFI_STATUS efi_getenv(EFI_GUID *g, const char *v, void *data, __size_t *len);
|
||||
EFI_STATUS efi_global_getenv(const char *v, void *data, __size_t *len);
|
||||
EFI_STATUS efi_setenv_freebsd_wcs(const char *varname, CHAR16 *valstr);
|
||||
|
||||
/* efipart.c */
|
||||
int efipart_inithandles(void);
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ SRCS= delay.c \
|
|||
efi_console.c \
|
||||
efi_driver_utils.c \
|
||||
efichar.c \
|
||||
efienv.c \
|
||||
efinet.c \
|
||||
efipart.c \
|
||||
efizfs.c \
|
||||
|
|
87
stand/efi/libefi/efienv.c
Normal file
87
stand/efi/libefi/efienv.c
Normal file
|
@ -0,0 +1,87 @@
|
|||
/*-
|
||||
* Copyright (c) 2018 Netflix, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <stand.h>
|
||||
#include <efi.h>
|
||||
#include <efichar.h>
|
||||
#include <efilib.h>
|
||||
|
||||
static EFI_GUID FreeBSDBootVarGUID = FREEBSD_BOOT_VAR_GUID;
|
||||
static EFI_GUID GlobalBootVarGUID = UEFI_BOOT_VAR_GUID;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
efi_global_getenv(const char *v, void *data, size_t *len)
|
||||
{
|
||||
|
||||
return (efi_getenv(&GlobalBootVarGUID, v, data, len));
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
efi_freebsd_getenv(const char *v, void *data, size_t *len)
|
||||
{
|
||||
|
||||
return (efi_getenv(&FreeBSDBootVarGUID, v, data, len));
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
Loading…
Reference in a new issue