mirror of
https://git.proxmox.com/git/fwupd
synced 2025-08-04 01:20:25 +00:00
Make libelf support optional
This commit is contained in:
parent
39148003a7
commit
1deda31cae
23
configure.ac
23
configure.ac
@ -145,7 +145,6 @@ PKG_CHECK_MODULES(APPSTREAM_GLIB, appstream-glib >= 0.5.10)
|
||||
PKG_CHECK_MODULES(GUSB, gusb >= 0.2.9)
|
||||
PKG_CHECK_MODULES(SQLITE, sqlite3)
|
||||
PKG_CHECK_MODULES(ARCHIVE, libarchive)
|
||||
PKG_CHECK_MODULES(ELF, libelf)
|
||||
PKG_CHECK_MODULES(SOUP, libsoup-2.4 >= 2.51.92)
|
||||
AC_PATH_PROG(DOCBOOK2MAN, docbook2man)
|
||||
if test -z $DOCBOOK2MAN ; then
|
||||
@ -177,6 +176,27 @@ else
|
||||
fi
|
||||
AM_CONDITIONAL(HAVE_COLORHUG, test x$has_colorhug = xyes)
|
||||
|
||||
# libelf support
|
||||
AC_ARG_ENABLE(libelf,
|
||||
AS_HELP_STRING([--enable-libelf],
|
||||
[Enable libelf support [default=auto]]),,
|
||||
enable_libelf=maybe)
|
||||
if test x$enable_libelf != xno; then
|
||||
PKG_CHECK_MODULES(LIBELF, libelf >= 1.2.12,
|
||||
has_libelf=yes,
|
||||
has_libelf=no)
|
||||
fi
|
||||
if test x$has_libelf = xyes; then
|
||||
AC_DEFINE(HAVE_LIBELF,1,[Use libelf support])
|
||||
else
|
||||
has_libelf=no
|
||||
if test "x$enable_libelf" = "xyes"; then
|
||||
AC_MSG_ERROR([libelf support requested but 'libelf' was not found])
|
||||
fi
|
||||
fi
|
||||
AM_CONDITIONAL(HAVE_LIBELF, test x$has_libelf = xyes)
|
||||
|
||||
|
||||
# gpgme support
|
||||
AC_MSG_CHECKING([for gpgme])
|
||||
if ! test -x "/usr/bin/gpgme-config"; then
|
||||
@ -320,6 +340,7 @@ echo "
|
||||
optional providers
|
||||
------------------
|
||||
Colorhug: $has_colorhug
|
||||
libelf: $has_libelf
|
||||
UEFI: $has_fwup
|
||||
Dell: $has_dell
|
||||
"
|
||||
|
@ -24,8 +24,12 @@
|
||||
#include <fcntl.h>
|
||||
#include <gelf.h>
|
||||
#include <gio/gunixinputstream.h>
|
||||
|
||||
#ifdef HAVE_LIBELF
|
||||
#include <libelf.h>
|
||||
#include <linux/memfd.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <sys/syscall.h>
|
||||
|
||||
@ -60,6 +64,7 @@ dfu_firmware_detect_elf (GBytes *bytes)
|
||||
return DFU_FIRMWARE_FORMAT_ELF;
|
||||
}
|
||||
|
||||
#ifdef HAVE_LIBELF
|
||||
static DfuElement *
|
||||
_get_element_from_section_name (Elf *e, const gchar *desired_name)
|
||||
{
|
||||
@ -144,6 +149,7 @@ dfu_format_elf_symbols_from_symtab (DfuFirmware *firmware, Elf *e)
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* dfu_firmware_from_elf: (skip)
|
||||
@ -162,6 +168,7 @@ dfu_firmware_from_elf (DfuFirmware *firmware,
|
||||
DfuFirmwareParseFlags flags,
|
||||
GError **error)
|
||||
{
|
||||
#ifdef HAVE_LIBELF
|
||||
guint i;
|
||||
guint sections_cnt = 0;
|
||||
g_autoptr(Elf) e = NULL;
|
||||
@ -230,8 +237,16 @@ dfu_firmware_from_elf (DfuFirmware *firmware,
|
||||
|
||||
/* success */
|
||||
return TRUE;
|
||||
#else
|
||||
g_set_error_literal (error,
|
||||
DFU_ERROR,
|
||||
DFU_ERROR_INTERNAL,
|
||||
"compiled without libelf support");
|
||||
return FALSE;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef HAVE_LIBELF
|
||||
static int
|
||||
_memfd_create (const char *name, unsigned int flags)
|
||||
{
|
||||
@ -299,6 +314,7 @@ dfu_format_elf_pack_image (Elf *e, DfuImage *image, GError **error)
|
||||
}
|
||||
return dfu_format_elf_pack_element (e, element, error);
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* dfu_firmware_to_elf: (skip)
|
||||
@ -312,6 +328,7 @@ dfu_format_elf_pack_image (Elf *e, DfuImage *image, GError **error)
|
||||
GBytes *
|
||||
dfu_firmware_to_elf (DfuFirmware *firmware, GError **error)
|
||||
{
|
||||
#ifdef HAVE_LIBELF
|
||||
DfuImage *image;
|
||||
Elf32_Ehdr *ehdr;
|
||||
Elf32_Shdr *shdr;
|
||||
@ -446,4 +463,11 @@ dfu_firmware_to_elf (DfuFirmware *firmware, GError **error)
|
||||
return NULL;
|
||||
}
|
||||
return g_input_stream_read_bytes (stream, fsize, NULL, error);
|
||||
#else
|
||||
g_set_error_literal (error,
|
||||
DFU_ERROR,
|
||||
DFU_ERROR_INTERNAL,
|
||||
"compiled without libelf support");
|
||||
return FALSE;
|
||||
#endif
|
||||
}
|
||||
|
@ -362,6 +362,11 @@ dfu_firmware_elf_func (void)
|
||||
g_autoptr(GError) error = NULL;
|
||||
g_autoptr(GFile) file = NULL;
|
||||
|
||||
#ifndef HAVE_LIBELF
|
||||
g_test_skip ("compiled without libelf support");
|
||||
return;
|
||||
#endif
|
||||
|
||||
/* load a ELF firmware */
|
||||
filename = dfu_test_get_filename ("example.elf");
|
||||
g_assert (filename != NULL);
|
||||
|
Loading…
Reference in New Issue
Block a user