efivar: Move dump functions into libefivar
To allow their use by efibootmgr. Signed-off-by: stephane.rochoy@stormshield.eu Reviewed by: imp Sponsored by: Stormshield Pull-Request: https://github.com/freebsd/freebsd-src/pull/2167
This commit is contained in:
committed by
Pouria Mousavizadeh Tehrani
parent
d9c0594191
commit
48363f39f1
@@ -35,6 +35,7 @@ LIB= efivar
|
||||
SRCS= efivar.c efichar.c efivar-dp-format.c \
|
||||
efivar-dp-parse.c \
|
||||
efivar-dp-xlate.c \
|
||||
efiutil.c \
|
||||
uefi-guid.c uefi-dputil.c
|
||||
INCS= efivar.h efivar-dp.h
|
||||
SHLIB_MAJOR= 1
|
||||
|
||||
@@ -35,16 +35,15 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "efiutil.h"
|
||||
#include "efichar.h"
|
||||
#include <efivar-dp.h>
|
||||
|
||||
/*
|
||||
* Dump the data as ASCII data, which is a pretty
|
||||
* printed form
|
||||
* printed form.
|
||||
*/
|
||||
void
|
||||
asciidump(uint8_t *data, size_t datalen)
|
||||
efi_asciidump(uint8_t *data, size_t datalen, int indent)
|
||||
{
|
||||
size_t i;
|
||||
int len;
|
||||
@@ -55,14 +54,14 @@ asciidump(uint8_t *data, size_t datalen)
|
||||
len++;
|
||||
if (len > 80) {
|
||||
len = 0;
|
||||
printf("\n");
|
||||
printf("\n%*s", indent, "");
|
||||
}
|
||||
printf("%c", data[i]);
|
||||
} else {
|
||||
len +=3;
|
||||
if (len > 80) {
|
||||
len = 0;
|
||||
printf("\n");
|
||||
printf("\n%*s", indent, "");
|
||||
}
|
||||
printf("%%%02x", data[i]);
|
||||
}
|
||||
@@ -71,7 +70,7 @@ asciidump(uint8_t *data, size_t datalen)
|
||||
}
|
||||
|
||||
void
|
||||
utf8dump(uint8_t *data, size_t datalen)
|
||||
efi_utf8dump(uint8_t *data, size_t datalen, int indent)
|
||||
{
|
||||
char *utf8 = NULL;
|
||||
efi_char *ucs2;
|
||||
@@ -84,21 +83,25 @@ utf8dump(uint8_t *data, size_t datalen)
|
||||
memcpy(ucs2, data, datalen);
|
||||
ucs2[datalen / sizeof(efi_char)] = 0;
|
||||
ucs2_to_utf8(ucs2, &utf8);
|
||||
printf("%s\n", utf8);
|
||||
printf("%*s%s\n", indent, "", utf8);
|
||||
free(utf8);
|
||||
free(ucs2);
|
||||
}
|
||||
|
||||
void
|
||||
hexdump(uint8_t *data, size_t datalen)
|
||||
efi_hexdump(uint8_t *data, size_t datalen, int indent)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < datalen; i++) {
|
||||
if (datalen == 0)
|
||||
return;
|
||||
|
||||
printf("0000: %02x ", data[0]);
|
||||
for (i = 1; i < datalen; i++) {
|
||||
if (i % 16 == 0) {
|
||||
if (i != 0)
|
||||
printf("\n");
|
||||
printf("%04x: ", (int)i);
|
||||
printf("%*s%04x: ", indent, "", (int)i);
|
||||
}
|
||||
printf("%02x ", data[i]);
|
||||
}
|
||||
@@ -106,7 +109,7 @@ hexdump(uint8_t *data, size_t datalen)
|
||||
}
|
||||
|
||||
void
|
||||
bindump(uint8_t *data, size_t datalen)
|
||||
efi_bindump(uint8_t *data, size_t datalen)
|
||||
{
|
||||
write(1, data, datalen);
|
||||
}
|
||||
@@ -180,11 +183,11 @@ efi_print_load_option(uint8_t *data, size_t datalen, int Aflag, int bflag, int u
|
||||
return;
|
||||
printf("Option:\n");
|
||||
if (Aflag)
|
||||
asciidump(opt, optlen);
|
||||
efi_asciidump(opt, optlen, 0);
|
||||
else if (bflag)
|
||||
bindump(opt, optlen);
|
||||
efi_bindump(opt, optlen);
|
||||
else if (uflag)
|
||||
utf8dump(opt, optlen);
|
||||
efi_utf8dump(opt, optlen, 0);
|
||||
else
|
||||
hexdump(opt, optlen);
|
||||
efi_hexdump(opt, optlen, 0);
|
||||
}
|
||||
@@ -79,6 +79,16 @@ int efi_set_variable(efi_guid_t guid, const char *name,
|
||||
int efi_str_to_guid(const char *s, efi_guid_t *guid);
|
||||
int efi_variables_supported(void);
|
||||
|
||||
/*
|
||||
* different routines to dump data.
|
||||
*/
|
||||
|
||||
void efi_asciidump(uint8_t *data, size_t datalen, int indent);
|
||||
void efi_bindump(uint8_t *data, size_t datalen);
|
||||
void efi_print_load_option(uint8_t *, size_t, int, int, int);
|
||||
void efi_hexdump(uint8_t *data, size_t datalen, int indent);
|
||||
void efi_utf8dump(uint8_t *data, size_t datalen, int indent);
|
||||
|
||||
/* FreeBSD extensions */
|
||||
struct guid_table
|
||||
{
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
EFIBOOT=${SRCTOP}/stand/efi
|
||||
EFIINCL=${SRCTOP}/stand/efi/include
|
||||
EFIVAR=${SRCTOP}/usr.sbin/efivar
|
||||
.PATH: ${EFIBOOT}/libefi ${EFIVAR}
|
||||
CFLAGS+= -I${EFIVAR} -I${EFIINCL}
|
||||
.PATH: ${EFIBOOT}/libefi
|
||||
CFLAGS+= -I${EFIINCL}
|
||||
|
||||
PACKAGE= efi-tools
|
||||
|
||||
PROG=efibootmgr
|
||||
MAN= efibootmgr.8
|
||||
SRCS= efichar.c efiutil.c efibootmgr.c
|
||||
SRCS= efichar.c efibootmgr.c
|
||||
|
||||
LIBADD= efivar geom
|
||||
|
||||
|
||||
@@ -50,7 +50,6 @@
|
||||
#include <geom/geom_int.h>
|
||||
|
||||
#include <efivar.h>
|
||||
#include <efiutil.h>
|
||||
#include <efichar.h>
|
||||
#include <efivar-dp.h>
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ MAN= efivar.8
|
||||
|
||||
LIBADD= efivar geom
|
||||
|
||||
SRCS= efivar.c efiutil.c
|
||||
SRCS= efivar.c
|
||||
|
||||
EFIBOOT=${SRCTOP}/stand/efi
|
||||
CFLAGS+= -I${EFIBOOT}/include
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 2017 Netflix, Inc.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* different routines to dump data.
|
||||
*/
|
||||
|
||||
void asciidump(uint8_t *data, size_t datalen);
|
||||
void bindump(uint8_t *data, size_t datalen);
|
||||
void efi_print_load_option(uint8_t *, size_t, int, int, int);
|
||||
void hexdump(uint8_t *data, size_t datalen);
|
||||
void utf8dump(uint8_t *data, size_t datalen);
|
||||
|
||||
@@ -38,7 +38,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "efiutil.h"
|
||||
#include "efichar.h"
|
||||
|
||||
/* options descriptor */
|
||||
@@ -254,15 +253,15 @@ print_var(efi_guid_t *guid, char *name)
|
||||
if (load_opt_flag)
|
||||
efi_print_load_option(data, datalen, Aflag, bflag, uflag);
|
||||
else if (Aflag)
|
||||
asciidump(data, datalen);
|
||||
efi_asciidump(data, datalen, 0);
|
||||
else if (uflag)
|
||||
utf8dump(data, datalen);
|
||||
efi_utf8dump(data, datalen, 0);
|
||||
else if (bflag)
|
||||
bindump(data, datalen);
|
||||
efi_bindump(data, datalen);
|
||||
else if (dflag)
|
||||
devpath_dump(data, datalen);
|
||||
else
|
||||
hexdump(data, datalen);
|
||||
efi_hexdump(data, datalen, 0);
|
||||
} else {
|
||||
printf("%s-%s", gname, name);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user