efivar: new package
authorOskari Rauta <redacted>
Thu, 12 Jan 2023 08:49:49 +0000 (10:49 +0200)
committerDaniel Golle <redacted>
Wed, 18 Jan 2023 13:59:58 +0000 (13:59 +0000)
Co-authored-by: Tianling Shen <redacted>
Signed-off-by: Oskari Rauta <redacted>
libs/efivar/Makefile [new file with mode: 0644]
libs/efivar/patches/002-musl-compat.patch [new file with mode: 0644]
libs/efivar/patches/005-skip-docs.patch [new file with mode: 0644]

diff --git a/libs/efivar/Makefile b/libs/efivar/Makefile
new file mode 100644 (file)
index 0000000..63c2abe
--- /dev/null
@@ -0,0 +1,66 @@
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=efivar
+PKG_VERSION:=38
+PKG_RELEASE:=1
+
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
+PKG_SOURCE_URL:=https://github.com/rhboot/efivar/releases/download/$(PKG_VERSION)
+PKG_HASH:=f018ed6e49c5f1c16d336d9fd7687ce87023276591921db1e49a314ad6515349
+
+PKG_LICENSE:=LGPL-2.1-only
+PKG_LICENSE_FILES:=COPYING
+
+PKG_BUILD_PARALLEL:=1
+PKG_INSTALL:=1
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/efivar
+  SECTION:=libs
+  CATEGORY:=Libraries
+  TITLE:=Tools and libraries to work with EFI variables
+  DEPENDS:=@TARGET_x86_64
+  URL:=https://github.com/rhboot/efibootmgr
+endef
+
+define Package/efivar/description
+  Tools and libraries to work with EFI variables
+endef
+
+MAKE_VARS += \
+       ERRORS= \
+       HOSTCC="$(HOSTCC)" \
+       HOST_CFLAGS="$(HOST_CFLAGS)" \
+       HOST_LDFLAGS="$(HOST_LDFLAGS)" \
+       LIBDIR="/usr/lib"
+
+define Build/InstallDev
+       $(INSTALL_DIR) $(1)/usr/lib
+       $(CP) $(PKG_INSTALL_DIR)/usr/lib/libefiboot.so* $(1)/usr/lib/
+       $(CP) $(PKG_INSTALL_DIR)/usr/lib/libefisec.so* $(1)/usr/lib/
+       $(CP) $(PKG_INSTALL_DIR)/usr/lib/libefivar.so* $(1)/usr/lib/
+
+       $(INSTALL_DIR) $(1)/usr/include/efivar
+       $(CP) $(PKG_INSTALL_DIR)/usr/include/efivar/*.h $(1)/usr/include/efivar/
+       $(INSTALL_DIR) $(1)/usr/lib/pkgconfig/
+       $(CP) $(PKG_INSTALL_DIR)/usr/lib/pkgconfig/*.pc $(1)/usr/lib/pkgconfig/
+endef
+
+define Package/efivar/install
+       $(INSTALL_DIR) $(1)/usr/bin
+       $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/efisecdb $(1)/usr/bin/
+       $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/efivar $(1)/usr/bin/
+
+       $(INSTALL_DIR) $(1)/usr/lib
+       $(CP) $(PKG_INSTALL_DIR)/usr/lib/libefiboot.so* $(1)/usr/lib/
+       $(CP) $(PKG_INSTALL_DIR)/usr/lib/libefisec.so* $(1)/usr/lib/
+       $(CP) $(PKG_INSTALL_DIR)/usr/lib/libefivar.so* $(1)/usr/lib/
+endef
+
+$(eval $(call BuildPackage,efivar))
diff --git a/libs/efivar/patches/002-musl-compat.patch b/libs/efivar/patches/002-musl-compat.patch
new file mode 100644 (file)
index 0000000..be3cfec
--- /dev/null
@@ -0,0 +1,199 @@
+From cece3ffd5be2f8641eb694513f2b73e5eb97ffd3 Mon Sep 17 00:00:00 2001
+From: Natanael Copa <ncopa@alpinelinux.org>
+Date: Fri, 28 Jan 2022 12:13:30 +0100
+Subject: [PATCH 1/2] efisecdb: fix build with musl libc
+
+Refactor code to use POSIX atexit(3) instead of the GNU specific
+on_exit(3).
+
+Resolves: #197
+Resolves: #202
+Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
+
+--- a/src/compiler.h
++++ b/src/compiler.h
+@@ -7,8 +7,6 @@
+ #ifndef COMPILER_H_
+ #define COMPILER_H_
+-#include <sys/cdefs.h>
+-
+ /* GCC version checking borrowed from glibc. */
+ #if defined(__GNUC__) && defined(__GNUC_MINOR__)
+ #  define GNUC_PREREQ(maj,min) \
+--- a/src/efisecdb.c
++++ b/src/efisecdb.c
+@@ -25,6 +25,10 @@
+ extern char *optarg;
+ extern int optind, opterr, optopt;
++static efi_secdb_t *secdb = NULL;
++static list_t infiles;
++static list_t actions;
++
+ struct hash_param {
+       char *name;
+       efi_secdb_type_t algorithm;
+@@ -187,12 +191,11 @@ add_action(list_t *list, action_type_t a
+ }
+ static void
+-free_actions(int status UNUSED, void *actionsp)
++free_actions(void)
+ {
+-      list_t *actions = (list_t *)actionsp;
+       list_t *pos, *tmp;
+-      for_each_action_safe(pos, tmp, actions) {
++      for_each_action_safe(pos, tmp, &actions) {
+               action_t *action = list_entry(pos, action_t, list);
+               list_del(&action->list);
+@@ -202,12 +205,11 @@ free_actions(int status UNUSED, void *ac
+ }
+ static void
+-free_infiles(int status UNUSED, void *infilesp)
++free_infiles(void)
+ {
+-      list_t *infiles = (list_t *)infilesp;
+       list_t *pos, *tmp;
+-      for_each_ptr_safe(pos, tmp, infiles) {
++      for_each_ptr_safe(pos, tmp, &infiles) {
+               ptrlist_t *entry = list_entry(pos, ptrlist_t, list);
+               list_del(&entry->list);
+@@ -216,27 +218,12 @@ free_infiles(int status UNUSED, void *in
+ }
+ static void
+-maybe_free_secdb(int status UNUSED, void *voidp)
++maybe_free_secdb(void)
+ {
+-      efi_secdb_t **secdbp = (efi_secdb_t **)voidp;
+-
+-      if (secdbp == NULL || *secdbp == NULL)
++      if (secdb == NULL)
+               return;
+-      efi_secdb_free(*secdbp);
+-}
+-
+-static void
+-maybe_do_unlink(int status, void *filep)
+-{
+-      char **file = (char **)filep;
+-
+-      if (status == 0)
+-              return;
+-      if (file == NULL || *file == NULL)
+-              return;
+-
+-      unlink(*file);
++      efi_secdb_free(secdb);
+ }
+ static void
+@@ -268,8 +255,7 @@ list_guids(void)
+  * failure.
+  */
+ static int
+-parse_input_files(list_t *infiles, char **outfile, efi_secdb_t **secdb,
+-                bool dump)
++parse_input_files(list_t *infiles, efi_secdb_t **secdb, bool dump)
+ {
+       int status = 0;
+       list_t *pos, *tmp;
+@@ -310,8 +296,6 @@ parse_input_files(list_t *infiles, char
+                               if (!dump)
+                                       exit(1);
+                               status = 1;
+-                              xfree(*outfile);
+-                              *outfile = NULL;
+                               break;
+                       }
+               }
+@@ -323,15 +307,6 @@ parse_input_files(list_t *infiles, char
+       return status;
+ }
+-/*
+- * These need to be static globals so that they're not on main's stack when
+- * on_exit() fires.
+- */
+-static efi_secdb_t *secdb = NULL;
+-static list_t infiles;
+-static list_t actions;
+-static char *outfile = NULL;
+-
+ int
+ main(int argc, char *argv[])
+ {
+@@ -351,6 +326,7 @@ main(int argc, char *argv[])
+       bool do_sort_data = false;
+       bool sort_descending = false;
+       int status = 0;
++      char *outfile = NULL;
+       const char sopts[] = ":aAc:dfg:h:i:Lo:rs:t:v?";
+       const struct option lopts[] = {
+@@ -376,10 +352,9 @@ main(int argc, char *argv[])
+       INIT_LIST_HEAD(&infiles);
+       INIT_LIST_HEAD(&actions);
+-      on_exit(free_actions, &actions);
+-      on_exit(free_infiles, &infiles);
+-      on_exit(maybe_free_secdb, &secdb);
+-      on_exit(maybe_do_unlink, &outfile);
++      atexit(free_actions);
++      atexit(free_infiles);
++      atexit(maybe_free_secdb);
+       /*
+        * parse the command line.
+@@ -550,7 +525,7 @@ sort_err:
+       efi_secdb_set_bool(secdb, EFI_SECDB_SORT_DATA, do_sort_data);
+       efi_secdb_set_bool(secdb, EFI_SECDB_SORT_DESCENDING, sort_descending);
+-      status = parse_input_files(&infiles, &outfile, &secdb, dump);
++      status = parse_input_files(&infiles, &secdb, dump);
+       if (status == 0) {
+               for_each_action_safe(pos, tmp, &actions) {
+                       action_t *action = list_entry(pos, action_t, list);
+@@ -587,24 +562,30 @@ sort_err:
+       outfd = open(outfile, flags, 0600);
+       if (outfd < 0) {
+               char *tmpoutfile = outfile;
+-              if (errno == EEXIST)
+-                      outfile = NULL;
++              if (errno != EEXIST)
++                      unlink(outfile);
+               err(1, "could not open \"%s\"", tmpoutfile);
+       }
+       rc = ftruncate(outfd, 0);
+-      if (rc < 0)
++      if (rc < 0) {
++              unlink(outfile);
+               err(1, "could not truncate output file \"%s\"", outfile);
++      }
+       void *output;
+       size_t size = 0;
+       rc = efi_secdb_realize(secdb, &output, &size);
+-      if (rc < 0)
++      if (rc < 0) {
++              unlink(outfile);
+               secdb_err(1, "could not realize signature list");
++      }
+       rc = write(outfd, output, size);
+-      if (rc < 0)
++      if (rc < 0) {
++              unlink(outfile);
+               err(1, "could not write signature list");
++      }
+       close(outfd);
+       xfree(output);
diff --git a/libs/efivar/patches/005-skip-docs.patch b/libs/efivar/patches/005-skip-docs.patch
new file mode 100644 (file)
index 0000000..94e20d7
--- /dev/null
@@ -0,0 +1,11 @@
+--- a/Makefile
++++ b/Makefile
+@@ -7,7 +7,7 @@ include $(TOPDIR)/src/include/defaults.m
+ include $(TOPDIR)/src/include/coverity.mk
+ include $(TOPDIR)/src/include/scan-build.mk
+-SUBDIRS := src docs
++SUBDIRS := src
+ all : | efivar.spec src/include/version.mk prep
+ all clean install prep :
git clone https://git.99rst.org/PROJECT