efivar renove

This commit is contained in:
Rmys
2023-03-12 21:20:16 +03:00
parent 7268447336
commit 45e7684639
52 changed files with 0 additions and 13086 deletions
-20
View File
@@ -1,20 +0,0 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Licensed under the GNU General Public License, version 3.
# See the file http://www.gnu.org/licenses/gpl.txt
from pisi.actionsapi import autotools
from pisi.actionsapi import shelltools
from pisi.actionsapi import pisitools
from pisi.actionsapi import get
def build():
shelltools.export("CFLAGS", "-Os -O2 -Wno-stringop-truncation")
# pisitools.dosed("Make.defaults","-O0","-Os")
# shelltools.system("sed -i -e 's/-Werror //' gcc.specs || die")
pisitools.dosed("src/test/Makefile","-rpath=$(TOPDIR)/src/","-rpath=$(libdir)|g")
autotools.make("libdir=/usr/lib bindir=/usr/bin includedir=/usr/include/ V=1 -j1")
def install():
autotools.rawInstall("DESTDIR=%s libdir=/usr/lib/" % get.installDIR())
@@ -1,29 +0,0 @@
From 3a0ae7189fe96355d64dc2daf91cf85282773c66 Mon Sep 17 00:00:00 2001
From: Mike Gilbert <floppym@gentoo.org>
Date: Thu, 14 Jan 2016 17:02:31 -0500
Subject: [PATCH] Workaround rename of linux/nvme.h
Bug: https://bugs.gentoo.org/571548
---
src/linux.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/src/linux.c b/src/linux.c
index b618cfd..9388cd3 100644
--- a/src/linux.c
+++ b/src/linux.c
@@ -22,7 +22,12 @@
#include <inttypes.h>
#include <limits.h>
#include <linux/ethtool.h>
+#include <linux/version.h>
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0)
+#include <linux/nvme_ioctl.h>
+#else
#include <linux/nvme.h>
+#endif
#include <linux/sockios.h>
#include <net/if.h>
#include <scsi/scsi.h>
--
2.7.2
@@ -1,36 +0,0 @@
From 5e2f64ebb96f45155d0301a81ccd141a17fd7d9b Mon Sep 17 00:00:00 2001
From: Andreas Schwab <schwab@suse.de>
Date: Tue, 12 Jul 2016 10:34:50 +0200
Subject: [PATCH] Remove use of deprecated readdir_r
Signed-off-by: Andreas Schwab <schwab@suse.de>
---
Index: efivar-0.23/src/vars.c
===================================================================
--- efivar-0.23.orig/src/vars.c
+++ efivar-0.23/src/vars.c
@@ -128,19 +128,15 @@ is_64bit(void)
if (dfd < 0)
goto err;
- struct dirent entry;
- struct dirent *result = NULL;
while (1) {
- int rc = readdir_r(dir, &entry, &result);
- if (rc != 0)
- break;
- if (result == NULL)
+ struct dirent *entry = readdir(dir);
+ if (entry == NULL)
break;
- if (!strcmp(entry.d_name, "..") || !strcmp(entry.d_name, "."))
+ if (!strcmp(entry->d_name, "..") || !strcmp(entry->d_name, "."))
continue;
- ssize_t size = get_file_data_size(dfd, entry.d_name);
+ ssize_t size = get_file_data_size(dfd, entry->d_name);
if (size < 0) {
continue;
} else if (size == 2084) {
@@ -1,25 +0,0 @@
From d084645fdc9bf805b39b0fb3ff7ec315661884be Mon Sep 17 00:00:00 2001
From: Gary Lin <glin@suse.com>
Date: Wed, 9 Mar 2016 12:19:26 +0800
Subject: [PATCH] Remove efivar-static since it requires static libs
Signed-off-by: Gary Lin <glin@suse.com>
---
src/Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Makefile b/src/Makefile
index 5fc7887..e1c1ccd 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -8,7 +8,7 @@ include $(TOPDIR)/Make.defaults
LIBTARGETS=libefivar.so libefiboot.so
STATICLIBTARGETS=libefivar.a libefiboot.a
-BINTARGETS=efivar efivar-static
+BINTARGETS=efivar
PCTARGETS=efivar.pc efiboot.pc
TARGETS=$(LIBTARGETS) $(STATICLIBTARGETS) $(BINTARGETS) $(PCTARGETS)
--
2.7.2
@@ -1,35 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Wei Fu <wefu@redhat.com>
Date: Sat, 2 Apr 2022 22:53:36 +0800
Subject: [PATCH] Fix the -march issue for riscv64
There is an issue on riscv64 system when compiling it natively:
gcc: error: '-march=native': ISA string must begin with rv32 or rv64
This patch set HOST_MARCH= like ia64 to resolve the issue.
Signed-off-by: Wei Fu <wefu@redhat.com>
(cherry picked from commit aab4e9b10ac9e98588a1b19771cf6f4c8c0a3096)
---
src/include/defaults.mk | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/include/defaults.mk b/src/include/defaults.mk
index 632b155..b8cc590 100644
--- a/src/include/defaults.mk
+++ b/src/include/defaults.mk
@@ -73,10 +73,14 @@ override SOFLAGS = $(_SOFLAGS) \
HOST_ARCH=$(shell uname -m)
ifneq ($(HOST_ARCH),ia64)
+ifneq ($(HOST_ARCH),riscv64)
HOST_MARCH=-march=native
else
HOST_MARCH=
endif
+else
+ HOST_MARCH=
+endif
HOST_CPPFLAGS ?= $(CPPFLAGS)
override _HOST_CPPFLAGS := $(HOST_CPPFLAGS)
override HOST_CPPFLAGS = $(_HOST_CPPFLAGS) \
@@ -1,56 +0,0 @@
From d5f88bb1d594451733261d62eac4b4f97d39e3f4 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Tue, 12 Jun 2018 14:36:20 -0400
Subject: [PATCH 01/34] Move the syntastic file I use out of the repo
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/.syntastic_c_config | 36 ------------------------------------
1 file changed, 36 deletions(-)
delete mode 100644 src/.syntastic_c_config
diff --git a/src/.syntastic_c_config b/src/.syntastic_c_config
deleted file mode 100644
index 3f3f0ca67c7..00000000000
--- a/src/.syntastic_c_config
+++ /dev/null
@@ -1,36 +0,0 @@
--g3
--Og
--Werror=format-security
--Wp,-D_FORTIFY_SOURCE=2
--fexceptions
--fstack-protector-strong
---param=ssp-buffer-size=4
--grecord-gcc-switches
--DFWUPDATE_HAVE_LIBSMBIOS__
--Wall
--Wextra
--Werror
--Wno-error=cpp
--Wno-unused-result
--Wno-unused-function
--Wsign-compare
--Werror=sign-compare
--fshort-wchar
---std=gnu11
--D_GNU_SOURCE
--Isrc/include
--Isrc/include/efivar
--Iinclude
--Iinclude/efivar
--fPIC
--fmath-errno
--fsigned-zeros
--ftrapping-math
--fno-trapv
--fno-openmp
--fno-openacc
--mtune=generic
--march=x86-64
--flto
--fno-merge-constants
--fvisibility=hidden
--
2.17.1
@@ -1,33 +0,0 @@
From cb0b1c30103abc17dbbed14210bbc59a73802206 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Mon, 7 Jan 2019 10:30:23 -0500
Subject: [PATCH 01/10] util.h: add unlikely() and likely() macros
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/util.h | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/src/util.h b/src/util.h
index f63a8907611..ba8fee35ae9 100644
--- a/src/util.h
+++ b/src/util.h
@@ -52,6 +52,15 @@
#define PACKED __attribute__((__packed__))
#define VERSION(sym, ver) __asm__(".symver " # sym "," # ver)
+#define __branch_check__(x, expect, is_constant) \
+ __builtin_expect(!!(x), expect)
+#ifndef likely
+#define likely(x) (__branch_check__(x, 1, __builtin_constant_p(x)))
+#endif
+#ifndef unlikely
+#define unlikely(x) (__branch_check__(x, 0, __builtin_constant_p(x)))
+#endif
+
/*
* I'm not actually sure when these appear, but they're present in the
* version in front of me.
--
2.23.0
@@ -1,56 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Robbie Harwood <rharwood@redhat.com>
Date: Thu, 28 Jul 2022 16:11:24 -0400
Subject: [PATCH] Fix glibc 2.36 build (mount.h conflicts)
glibc has decided that sys/mount.h and linux/mount.h are no longer
usable at the same time. This broke the build, since linux/fs.h itself
includes linux/mount.h. For now, fix the build by only including
sys/mount.h where we need it.
See-also: https://sourceware.org/glibc/wiki/Release/2.36#Usage_of_.3Clinux.2Fmount.h.3E_and_.3Csys.2Fmount.h.3E
Resolves: #227
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
(cherry picked from commit bc65d63ebf8fe6ac8a099ff15ca200986dba1565)
---
src/gpt.c | 1 +
src/linux.c | 1 +
src/util.h | 1 -
3 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/gpt.c b/src/gpt.c
index 1eda049..21413c3 100644
--- a/src/gpt.c
+++ b/src/gpt.c
@@ -17,6 +17,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/mount.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/utsname.h>
diff --git a/src/linux.c b/src/linux.c
index 47e45ae..1780816 100644
--- a/src/linux.c
+++ b/src/linux.c
@@ -20,6 +20,7 @@
#include <stdbool.h>
#include <stdio.h>
#include <sys/ioctl.h>
+#include <sys/mount.h>
#include <sys/socket.h>
#include <sys/sysmacros.h>
#include <sys/types.h>
diff --git a/src/util.h b/src/util.h
index 3300666..1e67e44 100644
--- a/src/util.h
+++ b/src/util.h
@@ -23,7 +23,6 @@
#include <stdio.h>
#include <string.h>
#include <sys/ioctl.h>
-#include <sys/mount.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <tgmath.h>
@@ -1,53 +0,0 @@
From daf3b6c6ae8a766f362c87dc80e40005428a1b2a Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Tue, 12 Jun 2018 14:36:20 -0400
Subject: [PATCH 02/34] Move verbosity headers to be public
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/include/efivar/efivar.h | 8 ++++++++
src/util.h | 4 ----
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/src/include/efivar/efivar.h b/src/include/efivar/efivar.h
index ddcc6771bdb..316891ccae9 100644
--- a/src/include/efivar/efivar.h
+++ b/src/include/efivar/efivar.h
@@ -25,6 +25,7 @@
#include <stdarg.h>
#include <stdint.h>
#include <string.h>
+#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
@@ -227,6 +228,13 @@ efi_error_clear(void)
#define efi_error_val(errval, msg, args...) \
efi_error_real__(errval, __FILE__, __func__, __LINE__, (fmt), ## args)
+extern void efi_set_verbose(int verbosity, FILE *errlog)
+ __attribute__((__visibility__("default")));
+extern int efi_get_verbose(void)
+ __attribute__((__visibility__("default")));
+extern FILE * efi_get_logfile(void)
+ __attribute__((__visibility__("default")));
+
#include <efivar/efivar-dp.h>
#endif /* EFIVAR_H */
diff --git a/src/util.h b/src/util.h
index 96ca66bd54d..cc5f669e6ec 100644
--- a/src/util.h
+++ b/src/util.h
@@ -369,8 +369,4 @@ swizzle_guid_to_uuid(efi_guid_t *guid)
#define DEBUG 1
-extern void PUBLIC efi_set_verbose(int verbosity, FILE *errlog);
-extern int PUBLIC efi_get_verbose(void);
-extern FILE PUBLIC *efi_get_logfile(void);
-
#endif /* EFIVAR_UTIL_H */
--
2.17.1
@@ -1,59 +0,0 @@
From b98ba8921010d03f46704a476c69861515deb1ca Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Mon, 7 Jan 2019 10:30:59 -0500
Subject: [PATCH 02/10] dp.h: make format_guid() handle misaligned guid
pointers safely.
GCC 9 adds -Werror=address-of-packed-member, which causes us to see the
build error reported at
https://bugzilla.opensuse.org/show_bug.cgi?id=1120862 .
That bug report shows us the following:
In file included from dp.c:26:
dp.h: In function 'format_vendor_helper':
dp.h:120:37: error: taking address of packed member of 'struct <anonymous>' may result in an unaligned pointer value [-Werror=address-of-packed-member]
120 | format_guid(buf, size, off, label, &dp->hw_vendor.vendor_guid);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
dp.h:74:25: note: in definition of macro 'format_guid'
74 | _rc = efi_guid_to_str(guid, &_guidstr); \
| ^~~~
cc1: all warnings being treated as errors
This patch makes format_guid() use a local variable as a bounce buffer
in the case that the guid we're passed is aligned as chaotic neutral.
Note that this only fixes this instance and there may be others that bz
didn't show because it exited too soon, and I don't have a gcc 9 build
in front of me right now.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/dp.h | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/src/dp.h b/src/dp.h
index aa4e3902992..20cb608d05f 100644
--- a/src/dp.h
+++ b/src/dp.h
@@ -70,8 +70,15 @@
#define format_guid(buf, size, off, dp_type, guid) ({ \
int _rc; \
char *_guidstr = NULL; \
- \
- _rc = efi_guid_to_str(guid, &_guidstr); \
+ efi_guid_t _guid; \
+ const efi_guid_t * const _guid_p = \
+ likely(__alignof__(guid) == sizeof(guid)) \
+ ? guid \
+ : &_guid; \
+ \
+ if (unlikely(__alignof__(guid) == sizeof(guid))) \
+ memmove(&_guid, guid, sizeof(_guid)); \
+ _rc = efi_guid_to_str(_guid_p, &_guidstr); \
if (_rc < 0) { \
efi_error("could not build %s GUID DP string", \
dp_type); \
--
2.23.0
@@ -1,45 +0,0 @@
From bd609a59369574c95f7f31b15caae8bb86b71f39 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Tue, 12 Jun 2018 14:36:20 -0400
Subject: [PATCH 03/34] Pacify some coverity nits.
Coverity has trouble tracking data flow sometimes, and believes that
sysfs_readlink() and read_sysfs_file() will sometimes return >= 0 when
the buffer has not been filled out. This changes the check to also test
for a NULL pointer, hopefully pacifying it.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/linux-pci.c | 2 +-
src/linux.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/linux-pci.c b/src/linux-pci.c
index 87878c39c94..0d2a90ab166 100644
--- a/src/linux-pci.c
+++ b/src/linux-pci.c
@@ -166,7 +166,7 @@ parse_pci(struct device *dev, const char *current)
tmp[devpart - current] = '\0';
rc = sysfs_readlink(&linkbuf, "class/block/%s/driver", tmp);
free(tmp);
- if (rc < 0) {
+ if (rc < 0 || !linkbuf) {
efi_error("Could not find driver for pci device");
return -1;
}
diff --git a/src/linux.c b/src/linux.c
index c8d1b3a9285..fe45c6004b9 100644
--- a/src/linux.c
+++ b/src/linux.c
@@ -356,7 +356,7 @@ struct device HIDDEN
if (dev->part == -1) {
rc = read_sysfs_file(&tmpbuf, "dev/block/%s/partition", dev->link);
- if (rc < 0) {
+ if (rc < 0 || !tmpbuf) {
efi_error("device has no /partition node; not a partition");
} else {
rc = sscanf((char *)tmpbuf, "%d\n", &dev->part);
--
2.17.1
@@ -1,27 +0,0 @@
From 8f803791a1c97a4d1bce049264218a94c46d7838 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Mon, 7 Jan 2019 11:32:41 -0500
Subject: [PATCH 03/10] linux-pci-root: remove an unused assignment
scan-build gripes about this, and it's pointless, so it can go.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/linux-pci-root.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/src/linux-pci-root.c b/src/linux-pci-root.c
index a2d9fb04a11..5d1df06119d 100644
--- a/src/linux-pci-root.c
+++ b/src/linux-pci-root.c
@@ -115,7 +115,6 @@ dp_create_pci_root(struct device *dev UNUSED,
return new;
}
}
- off += new;
sz += new;
debug("returning %zd", sz);
--
2.23.0
@@ -1,172 +0,0 @@
From c3c553db85ff10890209d0fe48fb4856ad68e4e0 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Thu, 21 Feb 2019 15:20:12 -0500
Subject: [PATCH 04/10] Fix all the places -Werror=address-of-packed-member
catches.
This gets rid of all the places GCC 9's -Werror=address-of-packed-member
flags as problematic.
Fixes github issue #123
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/dp-message.c | 6 ++++--
src/dp.h | 12 ++++--------
src/guid.c | 2 +-
src/include/efivar/efivar.h | 2 +-
src/ucs2.h | 27 +++++++++++++++++++--------
5 files changed, 29 insertions(+), 20 deletions(-)
diff --git a/src/dp-message.c b/src/dp-message.c
index 3724e5f57bd..9f964663de8 100644
--- a/src/dp-message.c
+++ b/src/dp-message.c
@@ -620,11 +620,13 @@ _format_message_dn(char *buf, size_t size, const_efidp dp)
) / sizeof(efi_ip_addr_t);
format(buf, size, off, "Dns", "Dns(");
for (int i=0; i < end; i++) {
- const efi_ip_addr_t *addr = &dp->dns.addrs[i];
+ efi_ip_addr_t addr;
+
+ memcpy(&addr, &dp->dns.addrs[i], sizeof(addr));
if (i != 0)
format(buf, size, off, "Dns", ",");
format_ip_addr(buf, size, off, "Dns",
- dp->dns.is_ipv6, addr);
+ dp->dns.is_ipv6, &addr);
}
format(buf, size, off, "Dns", ")");
break;
diff --git a/src/dp.h b/src/dp.h
index 20cb608d05f..1f921d524aa 100644
--- a/src/dp.h
+++ b/src/dp.h
@@ -71,13 +71,9 @@
int _rc; \
char *_guidstr = NULL; \
efi_guid_t _guid; \
- const efi_guid_t * const _guid_p = \
- likely(__alignof__(guid) == sizeof(guid)) \
- ? guid \
- : &_guid; \
- \
- if (unlikely(__alignof__(guid) == sizeof(guid))) \
- memmove(&_guid, guid, sizeof(_guid)); \
+ const efi_guid_t * const _guid_p = &_guid; \
+ \
+ memmove(&_guid, guid, sizeof(_guid)); \
_rc = efi_guid_to_str(_guid_p, &_guidstr); \
if (_rc < 0) { \
efi_error("could not build %s GUID DP string", \
@@ -86,7 +82,7 @@
_guidstr = onstack(_guidstr, \
strlen(_guidstr)+1); \
_rc = format(buf, size, off, dp_type, "%s", \
- _guidstr); \
+ _guidstr); \
} \
_rc; \
})
diff --git a/src/guid.c b/src/guid.c
index 306c9ff8287..3156b3b7c60 100644
--- a/src/guid.c
+++ b/src/guid.c
@@ -31,7 +31,7 @@
extern const efi_guid_t efi_guid_zero;
int NONNULL(1, 2) PUBLIC
-efi_guid_cmp(const efi_guid_t *a, const efi_guid_t *b)
+efi_guid_cmp(const void * const a, const void * const b)
{
return memcmp(a, b, sizeof (efi_guid_t));
}
diff --git a/src/include/efivar/efivar.h b/src/include/efivar/efivar.h
index 316891ccae9..ad6449d9d93 100644
--- a/src/include/efivar/efivar.h
+++ b/src/include/efivar/efivar.h
@@ -128,7 +128,7 @@ extern int efi_symbol_to_guid(const char *symbol, efi_guid_t *guid)
extern int efi_guid_is_zero(const efi_guid_t *guid);
extern int efi_guid_is_empty(const efi_guid_t *guid);
-extern int efi_guid_cmp(const efi_guid_t *a, const efi_guid_t *b);
+extern int efi_guid_cmp(const void * const a, const void * const b);
/* import / export functions */
typedef struct efi_variable efi_variable_t;
diff --git a/src/ucs2.h b/src/ucs2.h
index dbb59004b7c..edd8367b4bc 100644
--- a/src/ucs2.h
+++ b/src/ucs2.h
@@ -23,16 +23,21 @@
(((val) & ((mask) << (shift))) >> (shift))
static inline size_t UNUSED
-ucs2len(const uint16_t * const s, ssize_t limit)
+ucs2len(const void *vs, ssize_t limit)
{
ssize_t i;
- for (i = 0; i < (limit >= 0 ? limit : i+1) && s[i] != (uint16_t)0; i++)
+ const uint16_t *s = vs;
+ const uint8_t *s8 = vs;
+
+ for (i = 0;
+ i < (limit >= 0 ? limit : i+1) && s8[0] != 0 && s8[1] != 0;
+ i++, s8 += 2, s++)
;
return i;
}
static inline size_t UNUSED
-ucs2size(const uint16_t * const s, ssize_t limit)
+ucs2size(const void *s, ssize_t limit)
{
size_t rc = ucs2len(s, limit);
rc *= sizeof (uint16_t);
@@ -69,10 +74,11 @@ utf8size(uint8_t *s, ssize_t limit)
}
static inline unsigned char * UNUSED
-ucs2_to_utf8(const uint16_t * const chars, ssize_t limit)
+ucs2_to_utf8(const void * const voidchars, ssize_t limit)
{
ssize_t i, j;
unsigned char *ret;
+ const uint16_t * const chars = voidchars;
if (limit < 0)
limit = ucs2len(chars, -1);
@@ -124,10 +130,12 @@ ucs2_to_utf8(const uint16_t * const chars, ssize_t limit)
}
static inline ssize_t UNUSED NONNULL(4)
-utf8_to_ucs2(uint16_t *ucs2, ssize_t size, int terminate, uint8_t *utf8)
+utf8_to_ucs2(void *ucs2void, ssize_t size, int terminate, uint8_t *utf8)
{
ssize_t req;
ssize_t i, j;
+ uint16_t *ucs2 = ucs2void;
+ uint16_t val16;
if (!ucs2 && size > 0) {
errno = EINVAL;
@@ -162,10 +170,13 @@ utf8_to_ucs2(uint16_t *ucs2, ssize_t size, int terminate, uint8_t *utf8)
val = utf8[i] & 0x7f;
i += 1;
}
- ucs2[j] = val;
+ val16 = val;
+ ucs2[j] = val16;
+ }
+ if (terminate) {
+ val16 = 0;
+ ucs2[j++] = val16;
}
- if (terminate)
- ucs2[j++] = (uint16_t)0;
return j;
};
--
2.23.0
@@ -1,38 +0,0 @@
From 4becb1303fee8bd7b377292c74589d6ec69009ae Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Tue, 12 Jun 2018 14:36:20 -0400
Subject: [PATCH 04/34] efivar: Fix some types in -L behavior to pacify
coverity.
Coverity doesn't realize that efi_well_known_guids is /actually/ an
array, because we didn't tell it so. So fix the declaration so we've
told it so.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/efivar.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/efivar.c b/src/efivar.c
index 9ee3b397e29..228bdb745a7 100644
--- a/src/efivar.c
+++ b/src/efivar.c
@@ -485,13 +485,13 @@ int main(int argc, char *argv[])
case ACTION_LIST_GUIDS: {
efi_guid_t sentinal = {0xffffffff,0xffff,0xffff,0xffff,
{0xff,0xff,0xff,0xff,0xff,0xff}};
- extern struct guidname efi_well_known_guids;
+ extern struct guidname efi_well_known_guids[];
extern struct guidname efi_well_known_guids_end;
intptr_t start = (intptr_t)&efi_well_known_guids;
intptr_t end = (intptr_t)&efi_well_known_guids_end;
unsigned int i;
- struct guidname *guid = &efi_well_known_guids;
+ struct guidname *guid = &efi_well_known_guids[0];
for (i = 0; i < (end-start) / sizeof(*guid); i++) {
if (!efi_guid_cmp(&sentinal, &guid[i].guid))
break;
--
2.17.1
@@ -1,372 +0,0 @@
From e39fb5b9e590c6616459c15b5d95fbc09fb077d6 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Thu, 21 Feb 2019 15:26:23 -0500
Subject: [PATCH 05/10] Get rid of the arrows in our debug messages.
They're not *that* useful, and the code is clever and problematic.
Resolves github issue #124
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/linux-acpi-root.c | 7 -------
src/linux-emmc.c | 9 ---------
src/linux-md.c | 8 --------
src/linux-nvme.c | 9 ---------
src/linux-pci-root.c | 7 -------
src/linux-pci.c | 8 --------
src/linux-sata.c | 11 -----------
src/linux-scsi.c | 24 ------------------------
src/linux-soc-root.c | 7 -------
src/linux-virtblk.c | 8 --------
src/util.h | 1 -
11 files changed, 99 deletions(-)
diff --git a/src/linux-acpi-root.c b/src/linux-acpi-root.c
index 06e69eebe78..30728ded671 100644
--- a/src/linux-acpi-root.c
+++ b/src/linux-acpi-root.c
@@ -51,13 +51,6 @@ parse_acpi_root(struct device *dev, const char *current, const char *root UNUSED
char *colon;
const char *devpart = current;
- char *spaces;
-
- pos = strlen(current);
- spaces = alloca(pos+1);
- memset(spaces, ' ', pos+1);
- spaces[pos] = '\0';
- pos = 0;
debug("entry");
diff --git a/src/linux-emmc.c b/src/linux-emmc.c
index 87e92477554..b290ed0a2bd 100644
--- a/src/linux-emmc.c
+++ b/src/linux-emmc.c
@@ -50,13 +50,6 @@ parse_emmc(struct device *dev, const char *current, const char *root UNUSED)
int rc;
int32_t tosser0, tosser1, tosser2, tosser3, slot_id, partition;
int pos0 = 0, pos1 = 0;
- char *spaces;
-
- pos0 = strlen(current);
- spaces = alloca(pos0+1);
- memset(spaces, ' ', pos0+1);
- spaces[pos0] = '\0';
- pos0 = 0;
debug("entry");
@@ -65,8 +58,6 @@ parse_emmc(struct device *dev, const char *current, const char *root UNUSED)
&tosser0, &tosser1, &tosser2, &slot_id,
&pos0, &tosser3, &partition, &pos1);
debug("current:\"%s\" rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1);
- arrow(LOG_DEBUG, spaces, 9, pos0, rc, 4);
- arrow(LOG_DEBUG, spaces, 9, pos1, rc, 6);
/*
* If it isn't of that form, it's not one of our emmc devices.
*/
diff --git a/src/linux-md.c b/src/linux-md.c
index 0a5c1cdb435..cb584c96c4b 100644
--- a/src/linux-md.c
+++ b/src/linux-md.c
@@ -44,13 +44,6 @@ parse_md(struct device *dev, const char *current, const char *root UNUSED)
int rc;
int32_t md, tosser0, part;
int pos0 = 0, pos1 = 0;
- char *spaces;
-
- pos0 = strlen(current);
- spaces = alloca(pos0+1);
- memset(spaces, ' ', pos0+1);
- spaces[pos0] = '\0';
- pos0 = 0;
debug("entry");
@@ -58,7 +51,6 @@ parse_md(struct device *dev, const char *current, const char *root UNUSED)
rc = sscanf(current, "md%d/%nmd%dp%d%n",
&md, &pos0, &tosser0, &part, &pos1);
debug("current:\"%s\" rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1);
- arrow(LOG_DEBUG, spaces, 9, pos0, rc, 3);
/*
* If it isn't of that form, it's not one of our partitioned md devices.
*/
diff --git a/src/linux-nvme.c b/src/linux-nvme.c
index d68d11a3409..1d8fc654f76 100644
--- a/src/linux-nvme.c
+++ b/src/linux-nvme.c
@@ -54,13 +54,6 @@ parse_nvme(struct device *dev, const char *current, const char *root UNUSED)
int32_t tosser0, tosser1, tosser2, ctrl_id, ns_id, partition;
uint8_t *filebuf = NULL;
int pos0 = 0, pos1 = 0;
- char *spaces;
-
- pos0 = strlen(current);
- spaces = alloca(pos0+1);
- memset(spaces, ' ', pos0+1);
- spaces[pos0] = '\0';
- pos0 = 0;
debug("entry");
@@ -69,8 +62,6 @@ parse_nvme(struct device *dev, const char *current, const char *root UNUSED)
&tosser0, &ctrl_id, &ns_id, &pos0,
&tosser1, &tosser2, &partition, &pos1);
debug("current:\"%s\" rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1);
- arrow(LOG_DEBUG, spaces, 9, pos0, rc, 3);
- arrow(LOG_DEBUG, spaces, 9, pos1, rc, 6);
/*
* If it isn't of that form, it's not one of our nvme devices.
*/
diff --git a/src/linux-pci-root.c b/src/linux-pci-root.c
index 5d1df06119d..0605acfc7cb 100644
--- a/src/linux-pci-root.c
+++ b/src/linux-pci-root.c
@@ -48,13 +48,6 @@ parse_pci_root(struct device *dev, const char *current, const char *root UNUSED)
uint16_t root_domain;
uint8_t root_bus;
const char *devpart = current;
- char *spaces;
-
- pos = strlen(current);
- spaces = alloca(pos+1);
- memset(spaces, ' ', pos+1);
- spaces[pos] = '\0';
- pos = 0;
debug("entry");
diff --git a/src/linux-pci.c b/src/linux-pci.c
index f63f5914d9f..64aaefb461c 100644
--- a/src/linux-pci.c
+++ b/src/linux-pci.c
@@ -48,13 +48,6 @@ parse_pci(struct device *dev, const char *current, const char *root)
int rc;
int pos;
const char *devpart = current;
- char *spaces;
-
- pos = strlen(current);
- spaces = alloca(pos+1);
- memset(spaces, ' ', pos+1);
- spaces[pos] = '\0';
- pos = 0;
debug("entry");
@@ -75,7 +68,6 @@ parse_pci(struct device *dev, const char *current, const char *root)
rc = sscanf(devpart, "%hx:%hhx:%hhx.%hhx/%n",
&domain, &bus, &device, &function, &pos);
debug("current:\"%s\" rc:%d pos:%d", devpart, rc, pos);
- arrow(LOG_DEBUG, spaces, 9, pos, rc, 3);
if (rc != 4)
break;
devpart += pos;
diff --git a/src/linux-sata.c b/src/linux-sata.c
index 85265022f89..356411724bb 100644
--- a/src/linux-sata.c
+++ b/src/linux-sata.c
@@ -148,13 +148,6 @@ parse_sata(struct device *dev, const char *devlink, const char *root UNUSED)
uint64_t scsi_lun, tosser3;
int pos = 0;
int rc;
- char *spaces;
-
- pos = strlen(current);
- spaces = alloca(pos+1);
- memset(spaces, ' ', pos+1);
- spaces[pos] = '\0';
- pos = 0;
debug("entry");
if (is_pata(dev)) {
@@ -169,7 +162,6 @@ parse_sata(struct device *dev, const char *devlink, const char *root UNUSED)
debug("searching for ata1/");
rc = sscanf(current, "ata%"PRIu32"/%n", &print_id, &pos);
debug("current:\"%s\" rc:%d pos:%d\n", current, rc, pos);
- arrow(LOG_DEBUG, spaces, 9, pos, rc, 1);
/*
* If we don't find this one, it isn't an ata device, so return 0 not
* error. Later errors mean it is an ata device, but we can't parse
@@ -183,7 +175,6 @@ parse_sata(struct device *dev, const char *devlink, const char *root UNUSED)
debug("searching for host0/");
rc = sscanf(current, "host%"PRIu32"/%n", &scsi_bus, &pos);
debug("current:\"%s\" rc:%d pos:%d\n", current, rc, pos);
- arrow(LOG_DEBUG, spaces, 9, pos, rc, 1);
if (rc != 1)
return -1;
current += pos;
@@ -193,7 +184,6 @@ parse_sata(struct device *dev, const char *devlink, const char *root UNUSED)
rc = sscanf(current, "target%"PRIu32":%"PRIu32":%"PRIu64"/%n",
&scsi_device, &scsi_target, &scsi_lun, &pos);
debug("current:\"%s\" rc:%d pos:%d\n", current, rc, pos);
- arrow(LOG_DEBUG, spaces, 9, pos, rc, 3);
if (rc != 3)
return -1;
current += pos;
@@ -203,7 +193,6 @@ parse_sata(struct device *dev, const char *devlink, const char *root UNUSED)
rc = sscanf(current, "%"PRIu32":%"PRIu32":%"PRIu32":%"PRIu64"/%n",
&tosser0, &tosser1, &tosser2, &tosser3, &pos);
debug("current:\"%s\" rc:%d pos:%d\n", current, rc, pos);
- arrow(LOG_DEBUG, spaces, 9, pos, rc, 4);
if (rc != 4)
return -1;
current += pos;
diff --git a/src/linux-scsi.c b/src/linux-scsi.c
index a5e81cf9cb6..04892f02b4e 100644
--- a/src/linux-scsi.c
+++ b/src/linux-scsi.c
@@ -45,13 +45,6 @@ parse_scsi_link(const char *current, uint32_t *scsi_host,
int rc;
int sz = 0;
int pos0 = 0, pos1 = 0;
- char *spaces;
-
- sz = strlen(current);
- spaces = alloca(sz+1);
- memset(spaces, ' ', sz+1);
- spaces[sz] = '\0';
- sz = 0;
debug("entry");
/*
@@ -108,7 +101,6 @@ parse_scsi_link(const char *current, uint32_t *scsi_host,
debug("searching for host4/");
rc = sscanf(current, "host%d/%n", scsi_host, &pos0);
debug("current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0);
- arrow(LOG_DEBUG, spaces, 9, pos0, rc, 1);
if (rc != 1)
return -1;
sz += pos0;
@@ -126,8 +118,6 @@ parse_scsi_link(const char *current, uint32_t *scsi_host,
rc = sscanf(current+sz, "port-%d:%d%n:%d%n", &tosser0,
&tosser1, &pos0, &tosser2, &pos1);
debug("current:\"%s\" rc:%d pos0:%d pos1:%d\n", current+sz, rc, pos0, pos1);
- arrow(LOG_DEBUG, spaces, 9, pos0, rc, 2);
- arrow(LOG_DEBUG, spaces, 9, pos1, rc, 3);
if (rc == 2 || rc == 3) {
sz += pos0;
pos0 = 0;
@@ -153,7 +143,6 @@ parse_scsi_link(const char *current, uint32_t *scsi_host,
debug("searching for expander-4:0/");
rc = sscanf(current+sz, "expander-%d:%d/%n", &tosser0, &tosser1, &pos0);
debug("current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0);
- arrow(LOG_DEBUG, spaces, 9, pos0, rc, 2);
if (rc == 2) {
if (!remote_target_id) {
efi_error("Device is PHY is a remote target, but remote_target_id is NULL");
@@ -169,7 +158,6 @@ parse_scsi_link(const char *current, uint32_t *scsi_host,
debug("searching for port-2:0:2/");
rc = sscanf(current+sz, "port-%d:%d:%d/%n", &tosser0, &tosser1, &tosser2, &pos0);
debug("current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0);
- arrow(LOG_DEBUG, spaces, 9, pos0, rc, 3);
if (rc != 3) {
efi_error("Couldn't parse port expander port string");
return -1;
@@ -192,8 +180,6 @@ parse_scsi_link(const char *current, uint32_t *scsi_host,
pos1 = 0;
rc = sscanf(current + sz + pos0, ":%d%n", &tosser2, &pos1);
- arrow(LOG_DEBUG, spaces, 9, pos0, rc + 2, 2);
- arrow(LOG_DEBUG, spaces, 9, pos0 + pos1, rc + 2, 3);
if (rc != 0 && rc != 1)
return -1;
if (remote_port_id && rc == 1)
@@ -217,7 +203,6 @@ parse_scsi_link(const char *current, uint32_t *scsi_host,
rc = sscanf(current + sz, "target%d:%d:%"PRIu64"/%n", &tosser0, &tosser1,
&tosser3, &pos0);
debug("current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0);
- arrow(LOG_DEBUG, spaces, 9, pos0, rc, 3);
if (rc != 3)
return -1;
sz += pos0;
@@ -230,7 +215,6 @@ parse_scsi_link(const char *current, uint32_t *scsi_host,
rc = sscanf(current + sz, "%d:%d:%d:%"PRIu64"/%n",
scsi_bus, scsi_device, scsi_target, scsi_lun, &pos0);
debug("current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0);
- arrow(LOG_DEBUG, spaces, 9, pos0, rc, 4);
if (rc != 4)
return -1;
sz += pos0;
@@ -247,13 +231,6 @@ parse_scsi(struct device *dev, const char *current, const char *root UNUSED)
ssize_t sz;
int pos;
int rc;
- char *spaces;
-
- pos = strlen(current);
- spaces = alloca(pos+1);
- memset(spaces, ' ', pos+1);
- spaces[pos] = '\0';
- pos = 0;
debug("entry");
@@ -265,7 +242,6 @@ parse_scsi(struct device *dev, const char *current, const char *root UNUSED)
&dev->scsi_info.scsi_lun,
&pos);
debug("current:\"%s\" rc:%d pos:%d\n", dev->device, rc, pos);
- arrow(LOG_DEBUG, spaces, 9, pos, rc, 3);
if (rc != 4)
return 0;
diff --git a/src/linux-soc-root.c b/src/linux-soc-root.c
index 394f496a453..373cd59521a 100644
--- a/src/linux-soc-root.c
+++ b/src/linux-soc-root.c
@@ -43,13 +43,6 @@ parse_soc_root(struct device *dev UNUSED, const char *current, const char *root
int rc;
int pos;
const char *devpart = current;
- char *spaces;
-
- pos = strlen(current);
- spaces = alloca(pos+1);
- memset(spaces, ' ', pos+1);
- spaces[pos] = '\0';
- pos = 0;
debug("entry");
diff --git a/src/linux-virtblk.c b/src/linux-virtblk.c
index c54a813a947..2e9889def2f 100644
--- a/src/linux-virtblk.c
+++ b/src/linux-virtblk.c
@@ -50,20 +50,12 @@ parse_virtblk(struct device *dev, const char *current, const char *root UNUSED)
uint32_t tosser;
int pos;
int rc;
- char *spaces;
-
- pos = strlen(current);
- spaces = alloca(pos+1);
- memset(spaces, ' ', pos+1);
- spaces[pos] = '\0';
- pos = 0;
debug("entry");
debug("searching for virtio0/");
rc = sscanf(current, "virtio%x/%n", &tosser, &pos);
debug("current:\"%s\" rc:%d pos:%d\n", current, rc, pos);
- arrow(LOG_DEBUG, spaces, 9, pos, rc, 1);
/*
* If we couldn't find virtioX/ then it isn't a virtio device.
*/
diff --git a/src/util.h b/src/util.h
index ba8fee35ae9..6d3c10e946e 100644
--- a/src/util.h
+++ b/src/util.h
@@ -388,7 +388,6 @@ swizzle_guid_to_uuid(efi_guid_t *guid)
#undef log
#endif
#define log(level, fmt, args...) log_(__FILE__, __LINE__, __func__, level, fmt, ## args)
-#define arrow(l,b,o,p,n,m) ({if(n==m){char c_=b[p+1]; b[o]='^'; b[p+o]='^';b[p+o+1]='\0';log(l,"%s",b);b[o]=' ';b[p+o]=' ';b[p+o+1]=c_;}})
#define debug(fmt, args...) log(LOG_DEBUG, fmt, ## args)
#endif /* EFIVAR_UTIL_H */
--
2.23.0
@@ -1,88 +0,0 @@
From bd8fc0ebe86da82468b40a4998c3000819e73afe Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Tue, 12 Jun 2018 14:36:20 -0400
Subject: [PATCH 05/34] Promote _make_hd_dn() to make_hd_dn() and get rid of
the wrapper.
The wrapper is just hiding what the code's doing, and all the other code
around where we use it does the same thing anyway. This hopefully
convinces coverity we're not really dereferencing "buf" there unless
it's nonzero.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/creator.c | 3 ++-
src/disk.c | 4 ++--
src/dp-media.c | 2 ++
src/disk.h | 7 ++-----
4 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/src/creator.c b/src/creator.c
index 93f185fc0bc..76c1c1f7a99 100644
--- a/src/creator.c
+++ b/src/creator.c
@@ -281,7 +281,8 @@ efi_va_generate_file_device_path_from_esp(uint8_t *buf, ssize_t size,
goto err;
}
- sz = make_hd_dn(buf, size, off, disk_fd, dev->part, options);
+ sz = make_hd_dn(buf+off, size?size-off:0,
+ disk_fd, dev->part, options);
saved_errno = errno;
close(disk_fd);
errno = saved_errno;
diff --git a/src/disk.c b/src/disk.c
index deac512cf71..3efee03b804 100644
--- a/src/disk.c
+++ b/src/disk.c
@@ -257,8 +257,8 @@ is_partitioned(int fd)
}
ssize_t HIDDEN
-_make_hd_dn(uint8_t *buf, ssize_t size, int fd, int32_t partition,
- uint32_t options)
+make_hd_dn(uint8_t *buf, ssize_t size, int fd, int32_t partition,
+ uint32_t options)
{
uint64_t part_start=0, part_size = 0;
uint8_t signature[16]="", format=0, signature_type=0;
diff --git a/src/dp-media.c b/src/dp-media.c
index 0a0993ec3f4..cec6b8bb58d 100644
--- a/src/dp-media.c
+++ b/src/dp-media.c
@@ -161,6 +161,7 @@ efidp_make_file(uint8_t *buf, ssize_t size, char *filepath)
ssize_t sz;
ssize_t len = utf8len(lf, -1) + 1;
ssize_t req = sizeof (*file) + len * sizeof (uint16_t);
+
sz = efidp_make_generic(buf, size, EFIDP_MEDIA_TYPE, EFIDP_MEDIA_FILE,
req);
if (size && sz == req) {
@@ -182,6 +183,7 @@ efidp_make_hd(uint8_t *buf, ssize_t size, uint32_t num, uint64_t part_start,
efidp_hd *hd = (efidp_hd *)buf;
ssize_t sz;
ssize_t req = sizeof (*hd);
+
sz = efidp_make_generic(buf, size, EFIDP_MEDIA_TYPE, EFIDP_MEDIA_HD,
req);
if (size && sz == req) {
diff --git a/src/disk.h b/src/disk.h
index c040cc92a91..f0fa7f9f42d 100644
--- a/src/disk.h
+++ b/src/disk.h
@@ -23,10 +23,7 @@
extern bool HIDDEN is_partitioned(int fd);
-extern HIDDEN ssize_t _make_hd_dn(uint8_t *buf, ssize_t size, int fd,
- int32_t partition, uint32_t options);
-#define make_hd_dn(buf, size, off, fd, partition, option) \
- _make_hd_dn(((buf)+(off)), ((size)?((size)-(off)):0), (fd),\
- (partition), (options))
+extern HIDDEN ssize_t make_hd_dn(uint8_t *buf, ssize_t size, int fd,
+ int32_t partition, uint32_t options);
#endif /* _EFIBOOT_DISK_H */
--
2.17.1
@@ -1,38 +0,0 @@
From 25d73605b36933004b0266183de8051af30612ca Mon Sep 17 00:00:00 2001
From: Chih-Wei Huang <cwhuang@linux.org.tw>
Date: Thu, 10 Jan 2019 16:44:38 +0800
Subject: [PATCH 06/10] Define strdupa if it is not defined
Android does not include strdupa in <string.h>. Define strdupa if it has
not already been defined.
Signed-off-by: Chih-Wei Huang <cwhuang@linux.org.tw>
---
src/util.h | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/src/util.h b/src/util.h
index 6d3c10e946e..d98bfa1beed 100644
--- a/src/util.h
+++ b/src/util.h
@@ -252,6 +252,17 @@ lcm(uint64_t x, uint64_t y)
return (x / n) * y;
}
+#ifndef strdupa
+#define strdupa(s) \
+ (__extension__ ({ \
+ const char *__in = (s); \
+ size_t __len = strlen (__in); \
+ char *__out = (char *) alloca (__len + 1); \
+ strcpy(__out, __in); \
+ __out; \
+ }))
+#endif
+
#ifndef strndupa
#define strndupa(s, l) \
(__extension__ ({ \
--
2.23.0
@@ -1,138 +0,0 @@
From 5e2174acaf1a51ead0a079776229e0df89c7fd81 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Wed, 13 Jun 2018 09:15:17 -0400
Subject: [PATCH 06/34] Try to convince covscan that sysfs_read_file() doesn't
leak on error.
Basically, covscan gets confused about some of our return paths and
doesn't think the error condition correlates with not having allocated
(or having freed) the ram we're using to pass the file data back.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/linux.h | 5 +++++
src/util.h | 38 ++++++++++++++++++++------------------
2 files changed, 25 insertions(+), 18 deletions(-)
diff --git a/src/linux.h b/src/linux.h
index 2f9eb0fe66f..39826224a53 100644
--- a/src/linux.h
+++ b/src/linux.h
@@ -173,6 +173,11 @@ extern ssize_t HIDDEN make_mac_path(uint8_t *buf, ssize_t size,
free(buf_); \
*(buf) = (__typeof__(*(buf)))buf2_; \
errno = error_; \
+ } else if (buf_) { \
+ /* covscan is _sure_ we leak buf_ if bufsize_ */\
+ /* is <= 0, which is wrong, but appease it. */\
+ free(buf_); \
+ buf_ = NULL; \
} \
bufsize_; \
})
diff --git a/src/util.h b/src/util.h
index cc5f669e6ec..ef85a4c277e 100644
--- a/src/util.h
+++ b/src/util.h
@@ -149,22 +149,24 @@
#endif
static inline int UNUSED
-read_file(int fd, uint8_t **buf, size_t *bufsize)
+read_file(int fd, uint8_t **result, size_t *bufsize)
{
uint8_t *p;
size_t size = 4096;
size_t filesize = 0;
ssize_t s = 0;
+ uint8_t *buf, *newbuf;
- uint8_t *newbuf;
if (!(newbuf = calloc(size, sizeof (uint8_t)))) {
efi_error("could not allocate memory");
+ *result = buf = NULL;
+ *bufsize = 0;
return -1;
}
- *buf = newbuf;
+ buf = newbuf;
do {
- p = *buf + filesize;
+ p = buf + filesize;
/* size - filesize shouldn't exceed SSIZE_MAX because we're
* only allocating 4096 bytes at a time and we're checking that
* before doing so. */
@@ -179,8 +181,8 @@ read_file(int fd, uint8_t **buf, size_t *bufsize)
continue;
} else if (s < 0) {
int saved_errno = errno;
- free(*buf);
- *buf = NULL;
+ free(buf);
+ *result = buf = NULL;
*bufsize = 0;
errno = saved_errno;
efi_error("could not read from file");
@@ -194,38 +196,38 @@ read_file(int fd, uint8_t **buf, size_t *bufsize)
/* See if we're going to overrun and return an error
* instead. */
if (size > (size_t)-1 - 4096) {
- free(*buf);
- *buf = NULL;
+ free(buf);
+ *result = buf = NULL;
*bufsize = 0;
errno = ENOMEM;
efi_error("could not read from file");
return -1;
}
- newbuf = realloc(*buf, size + 4096);
+ newbuf = realloc(buf, size + 4096);
if (newbuf == NULL) {
int saved_errno = errno;
- free(*buf);
- *buf = NULL;
+ free(buf);
+ *result = buf = NULL;
*bufsize = 0;
errno = saved_errno;
efi_error("could not allocate memory");
return -1;
}
- *buf = newbuf;
- memset(*buf + size, '\0', 4096);
+ buf = newbuf;
+ memset(buf + size, '\0', 4096);
size += 4096;
}
} while (1);
- newbuf = realloc(*buf, filesize+1);
+ newbuf = realloc(buf, filesize+1);
if (!newbuf) {
- free(*buf);
- *buf = NULL;
+ free(buf);
+ *result = buf = NULL;
efi_error("could not allocate memory");
return -1;
}
newbuf[filesize] = '\0';
- *buf = newbuf;
+ *result = newbuf;
*bufsize = filesize+1;
return 0;
}
@@ -329,7 +331,7 @@ get_file(uint8_t **result, const char * const fmt, ...)
close(fd);
errno = error;
- if (rc < 0) {
+ if (rc < 0 || bufsize < 1) {
efi_error("could not read file \"%s\"", path);
return -1;
}
--
2.17.1
@@ -1,82 +0,0 @@
From 1a0ea5da82d8be7d05338bb42e8e71cdba7866f4 Mon Sep 17 00:00:00 2001
From: Chih-Wei Huang <cwhuang@linux.org.tw>
Date: Thu, 10 Jan 2019 16:48:30 +0800
Subject: [PATCH 07/10] Android: inital porting of libefivar
The static library is linked by efibootmgr.
Signed-off-by: Chih-Wei Huang <cwhuang@linux.org.tw>
---
src/Android.mk | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 60 insertions(+)
create mode 100644 src/Android.mk
diff --git a/src/Android.mk b/src/Android.mk
new file mode 100644
index 00000000000..b3410e1f3e7
--- /dev/null
+++ b/src/Android.mk
@@ -0,0 +1,60 @@
+#
+# Copyright (C) 2019 The Android-x86 Open Source Project
+#
+# Licensed under the GNU Lesser General Public License Version 2.1.
+# You may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.gnu.org/licenses/lgpl-2.1.html
+#
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := makeguids
+LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
+LOCAL_CFLAGS := -DEFIVAR_BUILD_ENVIRONMENT
+LOCAL_SRC_FILES := guid.c makeguids.c
+LOCAL_LDLIBS := -ldl
+include $(BUILD_HOST_EXECUTABLE)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := libefivar
+LOCAL_MODULE_CLASS := STATIC_LIBRARIES
+LIBEFIBOOT_SOURCES := \
+ crc32.c \
+ creator.c \
+ disk.c \
+ gpt.c \
+ loadopt.c \
+ path-helpers.c \
+ $(notdir $(wildcard $(LOCAL_PATH)/linux*.c))
+
+LIBEFIVAR_SOURCES := \
+ dp.c \
+ dp-acpi.c \
+ dp-hw.c \
+ dp-media.c \
+ dp-message.c \
+ efivarfs.c \
+ error.c \
+ export.c \
+ guid.c \
+ guids.S \
+ lib.c \
+ vars.c
+
+LOCAL_SRC_FILES := $(LIBEFIBOOT_SOURCES) $(LIBEFIVAR_SOURCES)
+LOCAL_CFLAGS := -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -std=gnu11
+LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
+LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_C_INCLUDES) $(LOCAL_C_INCLUDES)/efivar $(local-generated-sources-dir)
+LIBEFIVAR_GUIDS_H := $(local-generated-sources-dir)/efivar/efivar-guids.h
+LOCAL_GENERATED_SOURCES := $(LIBEFIVAR_GUIDS_H) $(local-generated-sources-dir)/guid-symbols.c
+$(LIBEFIVAR_GUIDS_H): PRIVATE_CUSTOM_TOOL = $^ $(addprefix $(dir $(@D)),guids.bin names.bin guid-symbols.c efivar/efivar-guids.h)
+$(LIBEFIVAR_GUIDS_H): $(BUILD_OUT_EXECUTABLES)/makeguids $(LOCAL_PATH)/guids.txt
+ $(transform-generated-source)
+$(lastword $(LOCAL_GENERATED_SOURCES)): $(LIBEFIVAR_GUIDS_H)
+
+include $(BUILD_STATIC_LIBRARY)
--
2.23.0
@@ -1,58 +0,0 @@
From 9bc1e24859630c933410bfb77658bd69ee400e16 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Wed, 13 Jun 2018 09:25:58 -0400
Subject: [PATCH 07/34] Make efidp_make_file() have even more, better input
constraints.
This is all in the effort to convince coverity that it doesn't
dereference buf when size==0, which it already doesn't.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/dp-media.c | 6 ++++++
src/dp.c | 10 +++++++++-
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/src/dp-media.c b/src/dp-media.c
index cec6b8bb58d..96a576fdc2a 100644
--- a/src/dp-media.c
+++ b/src/dp-media.c
@@ -162,6 +162,12 @@ efidp_make_file(uint8_t *buf, ssize_t size, char *filepath)
ssize_t len = utf8len(lf, -1) + 1;
ssize_t req = sizeof (*file) + len * sizeof (uint16_t);
+ if (len == 0) {
+ errno = EINVAL;
+ efi_error("%s() called with %s file path", __func__,
+ filepath == NULL ? "NULL" : "empty");
+ return -1;
+ }
sz = efidp_make_generic(buf, size, EFIDP_MEDIA_TYPE, EFIDP_MEDIA_FILE,
req);
if (size && sz == req) {
diff --git a/src/dp.c b/src/dp.c
index 4e76e25b1a1..82d60b4f9be 100644
--- a/src/dp.c
+++ b/src/dp.c
@@ -443,9 +443,17 @@ efidp_make_generic(uint8_t *buf, ssize_t size, uint8_t type, uint8_t subtype,
if (!size)
return total_size;
+
+ if (!buf) {
+ errno = EINVAL;
+ efi_error("%s was called with nonzero size and NULL buffer",
+ __func__);
+ return -1;
+ }
+
if (size < total_size) {
+ errno = ENOSPC;
efi_error("total size is bigger than size limit");
- errno = ENOSPC;
return -1;
}
--
2.17.1
@@ -1,25 +0,0 @@
From 025f791b57c988d33249c5c33250229fa0e7e8f1 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Thu, 14 Jun 2018 12:15:03 -0400
Subject: [PATCH 08/34] Make path-helpers.c also import fix_coverity.h
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/path-helpers.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/path-helpers.c b/src/path-helpers.c
index 1de00860d92..1b328071587 100644
--- a/src/path-helpers.c
+++ b/src/path-helpers.c
@@ -16,6 +16,7 @@
* License along with this library; if not, see
* <http://www.gnu.org/licenses/>.
*/
+#include "fix_coverity.h"
#include "efivar.h"
--
2.17.1
@@ -1,40 +0,0 @@
From 22da79a45a0c3a1437255c813b0b86a7b7925ae3 Mon Sep 17 00:00:00 2001
From: Chih-Wei Huang <cwhuang@linux.org.tw>
Date: Tue, 26 Feb 2019 14:57:00 +0800
Subject: [PATCH 08/10] Remove an unused function
This gets rid of an error from Android 9 clang:
external/efivar/src/linux.c:256:1: error: unused function 'supports_iface' [-Werror,-Wunused-function]
supports_iface(struct dev_probe *probe, enum interface_type iftype)
^
1 error generated.
Signed-off-by: Chih-Wei Huang <cwhuang@linux.org.tw>
---
src/linux.c | 9 ---------
1 file changed, 9 deletions(-)
diff --git a/src/linux.c b/src/linux.c
index 6d405af8a76..4bb453be834 100644
--- a/src/linux.c
+++ b/src/linux.c
@@ -252,15 +252,6 @@ static struct dev_probe *dev_probes[] = {
NULL
};
-static inline bool
-supports_iface(struct dev_probe *probe, enum interface_type iftype)
-{
- for (unsigned int i = 0; probe->iftypes[i] != unknown; i++)
- if (probe->iftypes[i] == iftype)
- return true;
- return false;
-}
-
void HIDDEN
device_free(struct device *dev)
{
--
2.23.0
@@ -1,34 +0,0 @@
From bf5225b0445cc1b7b69c2a80162d3c1b514a27cf Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Wed, 20 Jun 2018 14:12:42 -0400
Subject: [PATCH 09/34] Fix a makeguids building problem with generics.h.
Guard generics.h with EFIVAR_BUILD_ENVIRONMENT to keep it from
interfering with the makeguids build if libefivar.so isn't around
already.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/generics.h | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/generics.h b/src/generics.h
index e6af2fad79e..66be4bd76ab 100644
--- a/src/generics.h
+++ b/src/generics.h
@@ -17,6 +17,7 @@
*
*/
+#ifndef EFIVAR_BUILD_ENVIRONMENT
#ifndef LIBEFIVAR_GENERIC_NEXT_VARIABLE_NAME_H
#define LIBEFIVAR_GENERIC_NEXT_VARIABLE_NAME_H 1
@@ -182,3 +183,4 @@ generic_append_variable(efi_guid_t guid, const char *name,
}
#endif /* LIBEFIVAR_GENERIC_NEXT_VARIABLE_NAME_H */
+#endif /* EFIVAR_BUILD_ENVIRONMENT */
--
2.17.1
@@ -1,54 +0,0 @@
From 0dad6d78a7fb5f6c5fb4a1d646040539db6cf865 Mon Sep 17 00:00:00 2001
From: Chih-Wei Huang <cwhuang@linux.org.tw>
Date: Tue, 26 Feb 2019 18:42:20 +0800
Subject: [PATCH 09/10] Fix another error of -Werror=address-of-packed-member
Android 9 clang complains:
external/efivar/src/dp-message.c:367:24: error: taking address of packed member '' of class or structure 'efidp_infiniband' may result in an unaligned pointer value [-Werror,-Waddress-of-packed-member]
(efi_guid_t *)&dp->infiniband.ioc_guid);
^~~~~~~~~~~~~~~~~~~~~~~
external/efivar/src/dp.h:76:19: note: expanded from macro 'format_guid'
memmove(&_guid, guid, sizeof(_guid)); \
^~~~
1 error generated.
Since commit c3c553d the fifth parameter of format_guid() is treated as
a const void *. The casting is unnecessary.
Signed-off-by: Chih-Wei Huang <cwhuang@linux.org.tw>
---
src/dp-media.c | 3 +--
src/dp-message.c | 2 +-
2 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/src/dp-media.c b/src/dp-media.c
index 96a576fdc2a..be691c44326 100644
--- a/src/dp-media.c
+++ b/src/dp-media.c
@@ -46,8 +46,7 @@ _format_media_dn(char *buf, size_t size, const_efidp dp)
break;
case EFIDP_HD_SIGNATURE_GUID:
format(buf, size, off, "HD", "GPT,");
- format_guid(buf, size, off, "HD",
- (efi_guid_t *)dp->hd.signature);
+ format_guid(buf, size, off, "HD", dp->hd.signature);
format(buf, size, off, "HD",
",0x%"PRIx64",0x%"PRIx64")",
dp->hd.start, dp->hd.size);
diff --git a/src/dp-message.c b/src/dp-message.c
index 9f964663de8..6b8e9072594 100644
--- a/src/dp-message.c
+++ b/src/dp-message.c
@@ -364,7 +364,7 @@ _format_message_dn(char *buf, size_t size, const_efidp dp)
dp->infiniband.port_gid[1],
dp->infiniband.port_gid[0]);
format_guid(buf, size, off, "Infiniband",
- (efi_guid_t *)&dp->infiniband.ioc_guid);
+ &dp->infiniband.ioc_guid);
format(buf, size, off, "Infiniband",
",%"PRIu64",%"PRIu64")",
dp->infiniband.target_port_id,
--
2.23.0
@@ -1,402 +0,0 @@
From eb7db33c6cf4172551fe0f9f7cf4aa047dc16d88 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Wed, 20 Jun 2018 14:27:11 -0400
Subject: [PATCH 10/34] Improve ACPI device path formatting
This factors a bunch of the duplication out to another function, which
also does a better job of it.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/dp-acpi.c | 296 ++++++++++++++++++---------------
src/include/efivar/efivar-dp.h | 2 +-
2 files changed, 159 insertions(+), 139 deletions(-)
diff --git a/src/dp-acpi.c b/src/dp-acpi.c
index 70162f320dc..a49ef38488c 100644
--- a/src/dp-acpi.c
+++ b/src/dp-acpi.c
@@ -44,6 +44,59 @@ _format_acpi_adr(char *buf, size_t size,
#define format_acpi_adr(buf, size, off, dp) \
format_helper(_format_acpi_adr, buf, size, off, "AcpiAdr", dp)
+static ssize_t
+_format_acpi_hid_ex(char *buf, size_t size, const char *dp_type UNUSED,
+ const_efidp dp,
+ const char *hidstr, const char *cidstr, const char *uidstr)
+{
+ ssize_t off = 0;
+
+ debug(DEBUG, "hid:0x%08x hidstr:\"%s\"", dp->acpi_hid_ex.hid, hidstr);
+ debug(DEBUG, "cid:0x%08x cidstr:\"%s\"", dp->acpi_hid_ex.cid, cidstr);
+ debug(DEBUG, "uid:0x%08x uidstr:\"%s\"", dp->acpi_hid_ex.uid, uidstr);
+
+ if (!hidstr && !cidstr && (uidstr || dp->acpi_hid_ex.uid)) {
+ format(buf, size, off, "AcpiExp",
+ "AcpiExp(0x%"PRIx32",0x%"PRIx32",",
+ dp->acpi_hid_ex.hid, dp->acpi_hid_ex.cid);
+ if (uidstr) {
+ format(buf, size, off, "AcpiExp", "%s)", uidstr);
+ } else {
+ format(buf, size, off, "AcpiExp", "0x%"PRIx32")",
+ dp->acpi_hid_ex.uid);
+ }
+ return off;
+ }
+
+ format(buf, size, off, "AcpiEx", "AcpiEx(");
+ if (hidstr) {
+ format(buf, size, off, "AcpiEx", "%s,", hidstr);
+ } else {
+ format(buf, size, off, "AcpiEx", "0x%"PRIx32",",
+ dp->acpi_hid_ex.hid);
+ }
+
+ if (cidstr) {
+ format(buf, size, off, "AcpiEx", "%s,", cidstr);
+ } else {
+ format(buf, size, off, "AcpiEx", "0x%"PRIx32",",
+ dp->acpi_hid_ex.cid);
+ }
+
+ if (uidstr) {
+ format(buf, size, off, "AcpiEx", "%s)", uidstr);
+ } else {
+ format(buf, size, off, "AcpiEx", "0x%"PRIx32")",
+ dp->acpi_hid_ex.uid);
+ }
+
+ return off;
+}
+
+#define format_acpi_hid_ex(buf, size, off, dp, hidstr, cidstr, uidstr) \
+ format_helper(_format_acpi_hid_ex, buf, size, off, "AcpiEx", dp,\
+ hidstr, cidstr, uidstr)
+
ssize_t
_format_acpi_dn(char *buf, size_t size, const_efidp dp)
{
@@ -53,13 +106,15 @@ _format_acpi_dn(char *buf, size_t size, const_efidp dp)
const char *uidstr = NULL;
size_t uidlen = 0;
const char *cidstr = NULL;
- size_t cidlen = 0;
+ // size_t cidlen = 0;
if (dp->subtype == EFIDP_ACPI_ADR) {
+ debug(DEBUG, "formatting ACPI _ADR");
format_acpi_adr(buf, size, off, dp);
return off;
} else if (dp->subtype != EFIDP_ACPI_HID_EX &&
dp->subtype != EFIDP_ACPI_HID) {
+ debug(DEBUG, "DP subtype %d, formatting as ACPI Path", dp->subtype);
format(buf, size, off, "AcpiPath", "AcpiPath(%d,", dp->subtype);
format_hex(buf, size, off, "AcpiPath", (uint8_t *)dp+4,
(efidp_node_size(dp)-4) / 2);
@@ -69,6 +124,7 @@ _format_acpi_dn(char *buf, size_t size, const_efidp dp)
ssize_t limit = efidp_node_size(dp)
- offsetof(efidp_acpi_hid_ex, hidstr);
+ debug(DEBUG, "formatting ACPI HID EX");
hidstr = dp->acpi_hid_ex.hidstr;
hidlen = strnlen(hidstr, limit);
limit -= hidlen + 1;
@@ -81,7 +137,7 @@ _format_acpi_dn(char *buf, size_t size, const_efidp dp)
if (limit) {
cidstr = uidstr + uidlen + 1;
- cidlen = strnlen(cidstr, limit);
+ // cidlen = strnlen(cidstr, limit);
// limit -= cidlen + 1;
}
@@ -96,143 +152,102 @@ _format_acpi_dn(char *buf, size_t size, const_efidp dp)
"PcieRoot(%s)", uidstr);
return off;
default:
- format(buf, size, off, "AcpiEx", "AcpiEx(");
- if (hidlen)
- format(buf, size, off, "AcpiEx", "%s",
- hidstr);
- else
- format(buf, size, off, "AcpiEx", "0x%"PRIx32,
- dp->acpi_hid_ex.hid);
- if (cidlen)
- format(buf, size, off, "AcpiEx", ",%s",
- cidstr);
- else
- format(buf, size, off, "AcpiEx", ",0x%"PRIx32,
- dp->acpi_hid_ex.cid);
- if (uidlen)
- format(buf, size, off, "AcpiEx", ",%s",
- uidstr);
- else
- format(buf, size, off, "AcpiEx", ",0x%"PRIx32,
- dp->acpi_hid_ex.uid);
- format(buf, size, off, "AcpiEx", ")");
- break;
+ format_acpi_hid_ex(buf, size, off, dp,
+ hidstr, cidstr, uidstr);
+ return off;
}
}
- }
-
- switch (dp->acpi_hid.hid) {
- case EFIDP_ACPI_PCI_ROOT_HID:
- format(buf, size, off, "PciRoot", "PciRoot(0x%"PRIx32")",
- dp->acpi_hid.uid);
- break;
- case EFIDP_ACPI_PCIE_ROOT_HID:
- format(buf, size, off, "PcieRoot", "PcieRoot(0x%"PRIx32")",
- dp->acpi_hid.uid);
- break;
- case EFIDP_ACPI_FLOPPY_HID:
- format(buf, size, off, "Floppy", "Floppy(0x%"PRIx32")",
- dp->acpi_hid.uid);
- break;
- case EFIDP_ACPI_KEYBOARD_HID:
- format(buf, size, off, "Keyboard", "Keyboard(0x%"PRIx32")",
- dp->acpi_hid.uid);
- break;
- case EFIDP_ACPI_SERIAL_HID:
- format(buf, size, off, "Keyboard", "Serial(0x%"PRIx32")",
- dp->acpi_hid.uid);
- break;
- case EFIDP_ACPI_NVDIMM_HID: {
- int rc;
- const_efidp next = NULL;
- efidp_acpi_adr *adrdp;
- int end;
-
- format(buf, size, off, "NvRoot()", "NvRoot()");
-
- rc = efidp_next_node(dp, &next);
- if (rc < 0 || !next) {
- efi_error("could not format DP");
- return rc;
- }
+ } else if (dp->subtype == EFIDP_ACPI_HID_EX) {
+ switch (dp->acpi_hid.hid) {
+ case EFIDP_ACPI_PCI_ROOT_HID:
+ format(buf, size, off, "PciRoot",
+ "PciRoot(0x%"PRIx32")",
+ dp->acpi_hid.uid);
+ break;
+ case EFIDP_ACPI_PCIE_ROOT_HID:
+ format(buf, size, off, "PcieRoot",
+ "PcieRoot(0x%"PRIx32")",
+ dp->acpi_hid.uid);
+ break;
+ case EFIDP_ACPI_FLOPPY_HID:
+ format(buf, size, off, "Floppy",
+ "Floppy(0x%"PRIx32")",
+ dp->acpi_hid.uid);
+ break;
+ case EFIDP_ACPI_KEYBOARD_HID:
+ format(buf, size, off, "Keyboard",
+ "Keyboard(0x%"PRIx32")",
+ dp->acpi_hid.uid);
+ break;
+ case EFIDP_ACPI_SERIAL_HID:
+ format(buf, size, off, "Serial",
+ "Serial(0x%"PRIx32")",
+ dp->acpi_hid.uid);
+ break;
+ case EFIDP_ACPI_NVDIMM_HID: {
+ int rc;
+ const_efidp next = NULL;
+ efidp_acpi_adr *adrdp;
+ int end;
- if (efidp_type(next) != EFIDP_ACPI_TYPE ||
- efidp_subtype(next) != EFIDP_ACPI_ADR) {
- efi_error("Invalid child node type (0x%02x,0x%02x)",
- efidp_type(next), efidp_subtype(next));
- return -EINVAL;
- }
- adrdp = (efidp_acpi_adr *)next;
+ format(buf, size, off, "NvRoot()", "NvRoot()");
- end = efidp_size_after(adrdp, header)
- / sizeof(adrdp->adr[0]);
+ rc = efidp_next_node(dp, &next);
+ if (rc < 0 || !next) {
+ efi_error("could not format DP");
+ return rc;
+ }
- for (int i = 0; i < end; i++) {
- uint32_t node_controller, socket, memory_controller;
- uint32_t memory_channel, dimm;
- uint32_t adr = adrdp->adr[i];
+ if (efidp_type(next) != EFIDP_ACPI_TYPE ||
+ efidp_subtype(next) != EFIDP_ACPI_ADR) {
+ efi_error("Invalid child node type (0x%02x,0x%02x)",
+ efidp_type(next), efidp_subtype(next));
+ return -EINVAL;
+ }
+ adrdp = (efidp_acpi_adr *)next;
- efidp_decode_acpi_nvdimm_adr(adr, &node_controller,
- &socket,
- &memory_controller,
- &memory_channel, &dimm);
+ end = efidp_size_after(adrdp, header)
+ / sizeof(adrdp->adr[0]);
- if (i != 0)
- format(buf, size, off, "NvDimm", ",");
+ for (int i = 0; i < end; i++) {
+ uint32_t node_controller, socket, memory_controller;
+ uint32_t memory_channel, dimm;
+ uint32_t adr = adrdp->adr[i];
- format(buf, size, off, "NvDimm",
- "NvDimm(0x%03x,0x%01x,0x%01x,0x%01x,0x%01x)",
- node_controller, socket, memory_controller,
- memory_channel, dimm);
- }
- break;
- }
- default:
- switch (dp->subtype) {
- case EFIDP_ACPI_HID_EX:
- if (!hidstr && !cidstr &&
- (uidstr || dp->acpi_hid_ex.uid)){
- format(buf, size, off, "AcpiExp",
- "AcpiExp(0x%"PRIx32",0x%"PRIx32",",
- dp->acpi_hid_ex.hid,
- dp->acpi_hid_ex.cid);
- if (uidstr) {
- format(buf, size, off, "AcpiExp",
- "%s)", uidstr);
- } else {
- format(buf, size, off, "AcpiExp",
- "0x%"PRIx32")",
- dp->acpi_hid.uid);
- }
- break;
- }
- format(buf, size, off, "AcpiEx", "AcpiEx(");
- if (hidstr) {
- format(buf, size, off, "AcpiEx", "%s,", hidstr);
- } else {
- format(buf, size, off, "AcpiEx", "0x%"PRIx32",",
- dp->acpi_hid.hid);
- }
+ efidp_decode_acpi_nvdimm_adr(adr,
+ &node_controller, &socket,
+ &memory_controller, &memory_channel,
+ &dimm);
- if (cidstr) {
- format(buf, size, off, "AcpiEx", "%s,", cidstr);
- } else {
- format(buf, size, off, "AcpiEx", "0x%"PRIx32",",
- dp->acpi_hid_ex.cid);
- }
+ if (i != 0)
+ format(buf, size, off, "NvDimm", ",");
- if (uidstr) {
- format(buf, size, off, "AcpiEx", "%s)", uidstr);
- } else {
- format(buf, size, off, "AcpiEx", "0x%"PRIx32")",
- dp->acpi_hid.uid);
+ format(buf, size, off, "NvDimm",
+ "NvDimm(0x%03x,0x%01x,0x%01x,0x%01x,0x%01x)",
+ node_controller, socket, memory_controller,
+ memory_channel, dimm);
}
break;
- case EFIDP_ACPI_HID:
- format(buf, size, off, "Acpi",
- "Acpi(0x%"PRIx32",0x%"PRIx32")",
- dp->acpi_hid.hid, dp->acpi_hid.uid);
- break;
+ }
+ default:
+ debug(DEBUG, "Decoding non-well-known HID");
+ switch (dp->subtype) {
+ case EFIDP_ACPI_HID_EX:
+ format_acpi_hid_ex(buf, size, off, dp,
+ hidstr, cidstr, uidstr);
+ break;
+ case EFIDP_ACPI_HID:
+ debug(DEBUG, "Decoding ACPI HID");
+ format(buf, size, off, "Acpi",
+ "Acpi(0x%08x,0x%"PRIx32")",
+ dp->acpi_hid.hid, dp->acpi_hid.uid);
+ break;
+ default:
+ debug(DEBUG, "ACPI subtype %d???",
+ dp->subtype);
+ errno = EINVAL;
+ return -1;
+ }
}
}
@@ -259,7 +274,7 @@ efidp_make_acpi_hid(uint8_t *buf, ssize_t size, uint32_t hid, uint32_t uid)
return sz;
}
-ssize_t PUBLIC NONNULL(6, 7, 8)
+ssize_t PUBLIC
efidp_make_acpi_hid_ex(uint8_t *buf, ssize_t size,
uint32_t hid, uint32_t uid, uint32_t cid,
const char *hidstr, const char *uidstr,
@@ -268,21 +283,26 @@ efidp_make_acpi_hid_ex(uint8_t *buf, ssize_t size,
efidp_acpi_hid_ex *acpi_hid = (efidp_acpi_hid_ex *)buf;
ssize_t req;
ssize_t sz;
+ size_t hidlen = hidstr ? strlen(hidstr) : 0;
+ size_t uidlen = uidstr ? strlen(uidstr) : 0;
+ size_t cidlen = cidstr ? strlen(cidstr) : 0;
- req = sizeof (*acpi_hid) + 3 +
- strlen(hidstr) + strlen(uidstr) + strlen(cidstr);
+ req = sizeof (*acpi_hid) + 3 + hidlen + uidlen + cidlen;
sz = efidp_make_generic(buf, size, EFIDP_ACPI_TYPE, EFIDP_ACPI_HID_EX,
req);
if (size && sz == req) {
- acpi_hid->uid = uid;
- acpi_hid->hid = hid;
- acpi_hid->cid = cid;
+ acpi_hid->hid = hidlen ? 0 : hid;
+ acpi_hid->uid = uidlen ? 0 : uid;
+ acpi_hid->cid = cidlen ? 0 : cid;
char *next = (char *)buf+offsetof(efidp_acpi_hid_ex, hidstr);
- strcpy(next, hidstr);
- next += strlen(hidstr) + 1;
- strcpy(next, uidstr);
- next += strlen(uidstr) + 1;
- strcpy(next, cidstr);
+ if (hidlen)
+ strcpy(next, hidstr);
+ next += hidlen + 1;
+ if (uidlen)
+ strcpy(next, uidstr);
+ next += uidlen + 1;
+ if (cidlen)
+ strcpy(next, cidstr);
}
if (sz < 0)
diff --git a/src/include/efivar/efivar-dp.h b/src/include/efivar/efivar-dp.h
index 106d3645e21..1b05775ae7e 100644
--- a/src/include/efivar/efivar-dp.h
+++ b/src/include/efivar/efivar-dp.h
@@ -133,7 +133,7 @@ typedef struct {
/* three ascii string fields follow */
char hidstr[];
} EFIVAR_PACKED efidp_acpi_hid_ex;
-extern ssize_t __attribute__((__nonnull__ (6,7,8)))
+extern ssize_t
efidp_make_acpi_hid_ex(uint8_t *buf, ssize_t size,
uint32_t hid, uint32_t uid, uint32_t cid,
const char *hidstr, const char *uidstr,
--
2.17.1
File diff suppressed because it is too large Load Diff
@@ -1,177 +0,0 @@
From ba0655c62978ba64c227f1f87d9da3e1dea4f821 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Wed, 20 Jun 2018 14:37:14 -0400
Subject: [PATCH 11/34] Give linux-*'s ->parse() functions the unmodified
device link as well
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/linux-ata.c | 2 +-
src/linux-i2o.c | 2 +-
src/linux-nvme.c | 2 +-
src/linux-pci.c | 2 +-
src/linux-pmem.c | 2 +-
src/linux-sas.c | 2 +-
src/linux-sata.c | 2 +-
src/linux-scsi.c | 2 +-
src/linux-virtblk.c | 2 +-
src/linux.c | 4 ++--
src/linux.h | 3 ++-
11 files changed, 13 insertions(+), 12 deletions(-)
diff --git a/src/linux-ata.c b/src/linux-ata.c
index 6a47ff3f279..dab02f3d224 100644
--- a/src/linux-ata.c
+++ b/src/linux-ata.c
@@ -58,7 +58,7 @@ is_pata(struct device *dev)
* 11:0 -> ../../devices/pci0000:00/0000:00:11.5/ata3/host2/target2:0:0/2:0:0:0/block/sr0
*/
static ssize_t
-parse_ata(struct device *dev, const char *current)
+parse_ata(struct device *dev, const char *current, const char *root UNUSED)
{
uint32_t scsi_host, scsi_bus, scsi_device, scsi_target;
uint64_t scsi_lun;
diff --git a/src/linux-i2o.c b/src/linux-i2o.c
index e57c0cb344f..4fe79e5719f 100644
--- a/src/linux-i2o.c
+++ b/src/linux-i2o.c
@@ -33,7 +33,7 @@
* ... probably doesn't work.
*/
static ssize_t
-parse_i2o(struct device *dev, const char *current UNUSED)
+parse_i2o(struct device *dev, const char *current UNUSED, const char *root UNUSED)
{
debug(DEBUG, "entry");
/* I2O disks can have up to 16 partitions, or 4 bits worth. */
diff --git a/src/linux-nvme.c b/src/linux-nvme.c
index 6d5196fc082..00f53d5a9a7 100644
--- a/src/linux-nvme.c
+++ b/src/linux-nvme.c
@@ -48,7 +48,7 @@
*/
static ssize_t
-parse_nvme(struct device *dev, const char *current)
+parse_nvme(struct device *dev, const char *current, const char *root UNUSED)
{
int rc;
int32_t tosser0, tosser1, tosser2, ctrl_id, ns_id, partition;
diff --git a/src/linux-pci.c b/src/linux-pci.c
index 0d2a90ab166..4fbd108e3ed 100644
--- a/src/linux-pci.c
+++ b/src/linux-pci.c
@@ -41,7 +41,7 @@
*
*/
static ssize_t
-parse_pci(struct device *dev, const char *current)
+parse_pci(struct device *dev, const char *current, const char *root UNUSED)
{
int rc;
int pos;
diff --git a/src/linux-pmem.c b/src/linux-pmem.c
index 045650bc471..9a075716f7f 100644
--- a/src/linux-pmem.c
+++ b/src/linux-pmem.c
@@ -70,7 +70,7 @@
*/
static ssize_t
-parse_pmem(struct device *dev, const char *current)
+parse_pmem(struct device *dev, const char *current, const char *root UNUSED)
{
uint8_t *filebuf = NULL;
uint8_t system, sysbus, acpi_id;
diff --git a/src/linux-sas.c b/src/linux-sas.c
index 4a11147aef1..5f44f2c1f7b 100644
--- a/src/linux-sas.c
+++ b/src/linux-sas.c
@@ -45,7 +45,7 @@
* I'm not sure at the moment if they're the same or not.
*/
static ssize_t
-parse_sas(struct device *dev, const char *current)
+parse_sas(struct device *dev, const char *current, const char *root UNUSED)
{
struct stat statbuf = { 0, };
int rc;
diff --git a/src/linux-sata.c b/src/linux-sata.c
index a670ad9907e..d9a62efdbe6 100644
--- a/src/linux-sata.c
+++ b/src/linux-sata.c
@@ -138,7 +138,7 @@ sysfs_sata_get_port_info(uint32_t print_id, struct device *dev)
}
static ssize_t
-parse_sata(struct device *dev, const char *devlink)
+parse_sata(struct device *dev, const char *devlink, const char *root UNUSED)
{
const char *current = devlink;
uint32_t print_id;
diff --git a/src/linux-scsi.c b/src/linux-scsi.c
index 87f2f7f7c92..153a4ff87ad 100644
--- a/src/linux-scsi.c
+++ b/src/linux-scsi.c
@@ -160,7 +160,7 @@ parse_scsi_link(const char *current, uint32_t *scsi_host,
}
static ssize_t
-parse_scsi(struct device *dev, const char *current)
+parse_scsi(struct device *dev, const char *current, const char *root UNUSED)
{
uint32_t scsi_host, scsi_bus, scsi_device, scsi_target;
uint64_t scsi_lun;
diff --git a/src/linux-virtblk.c b/src/linux-virtblk.c
index 6dedf0f27ee..9ee7994aeb3 100644
--- a/src/linux-virtblk.c
+++ b/src/linux-virtblk.c
@@ -45,7 +45,7 @@
* But usually we just write the HD() entry, of course.
*/
static ssize_t
-parse_virtblk(struct device *dev, const char *current)
+parse_virtblk(struct device *dev, const char *current, const char *root UNUSED)
{
uint32_t tosser;
int pos;
diff --git a/src/linux.c b/src/linux.c
index fe45c6004b9..ef560753481 100644
--- a/src/linux.c
+++ b/src/linux.c
@@ -352,7 +352,7 @@ struct device HIDDEN
efi_error("strdup(\"%s\") failed", linkbuf);
goto err;
}
- debug(DEBUG, "dev->link: %s\n", dev->link);
+ debug(DEBUG, "dev->link: %s", dev->link);
if (dev->part == -1) {
rc = read_sysfs_file(&tmpbuf, "dev/block/%s/partition", dev->link);
@@ -431,7 +431,7 @@ struct device HIDDEN
}
debug(DEBUG, "trying %s", probe->name);
- pos = probe->parse(dev, current);
+ pos = probe->parse(dev, current, dev->link);
if (pos < 0) {
efi_error("parsing %s failed", probe->name);
goto err;
diff --git a/src/linux.h b/src/linux.h
index 39826224a53..35951bb4d16 100644
--- a/src/linux.h
+++ b/src/linux.h
@@ -244,7 +244,8 @@ struct dev_probe {
char *name;
enum interface_type *iftypes;
uint32_t flags;
- ssize_t (*parse)(struct device *dev, const char * const current);
+ ssize_t (*parse)(struct device *dev,
+ const char * const current, const char * const root);
ssize_t (*create)(struct device *dev,
uint8_t *buf, ssize_t size, ssize_t off);
char *(*make_part_name)(struct device *dev);
--
2.17.1
@@ -1,391 +0,0 @@
From e2f68c8f9f4fab48f1ef3a4585932f757593fa92 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Wed, 20 Jun 2018 14:43:32 -0400
Subject: [PATCH 12/34] Move ACPI ID parsing to a shared location.
This is getting out of PCI because we have some other platforms that do
ACPI root parsing, but don't use the PCI roots.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/linux-acpi.c | 119 +++++++++++++++++++++++++++++++++++++++++++++++
src/linux-pci.c | 112 +++++---------------------------------------
src/linux.c | 11 ++++-
src/linux.h | 19 +++++---
4 files changed, 152 insertions(+), 109 deletions(-)
create mode 100644 src/linux-acpi.c
diff --git a/src/linux-acpi.c b/src/linux-acpi.c
new file mode 100644
index 00000000000..cb93a113ee2
--- /dev/null
+++ b/src/linux-acpi.c
@@ -0,0 +1,119 @@
+/*
+ * libefiboot - library for the manipulation of EFI boot variables
+ * Copyright 2012-2018 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of the
+ * License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "fix_coverity.h"
+
+#include <errno.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <stdint.h>
+#include <unistd.h>
+
+#include "efiboot.h"
+
+int HIDDEN
+parse_acpi_hid_uid(struct device *dev, const char *fmt, ...)
+{
+ int rc;
+ char *path = NULL;
+ va_list ap;
+ char *fbuf = NULL;
+ uint16_t tmp16;
+ uint32_t acpi_hid = 0;
+ uint64_t acpi_uid_int = 0;
+
+ debug(DEBUG, "entry");
+
+ va_start(ap, fmt);
+ rc = vasprintfa(&path, fmt, ap);
+ va_end(ap);
+ debug(DEBUG, "path:%s rc:%d", path, rc);
+ if (rc < 0 || path == NULL)
+ return -1;
+
+ rc = read_sysfs_file(&fbuf, "%s/firmware_node/path", path);
+ if (rc > 0) {
+ size_t l = strlen(fbuf);
+ if (l > 1) {
+ fbuf[l-1] = 0;
+ dev->acpi_root.acpi_cid_str = strdup(fbuf);
+ debug(DEBUG, "Setting ACPI root path to \"%s\"", fbuf);
+ }
+ }
+
+ rc = read_sysfs_file(&fbuf, "%s/firmware_node/hid", path);
+ if (rc < 0 || fbuf == NULL) {
+ efi_error("could not read %s/firmware_node/hid", path);
+ return -1;
+ }
+
+ rc = strlen(fbuf);
+ if (rc < 4) {
+hid_err:
+ efi_error("could not parse %s/firmware_node/hid", path);
+ return -1;
+ }
+ rc -= 4;
+
+ rc = sscanf((char *)fbuf + rc, "%04hx", &tmp16);
+ debug(DEBUG, "rc:%d hid:0x%08x\n", rc, tmp16);
+ if (rc != 1)
+ goto hid_err;
+
+ acpi_hid = EFIDP_EFI_PNP_ID(tmp16);
+
+ /*
+ * Apparently basically nothing can look up a PcieRoot() node,
+ * because they just check _CID. So since _CID for the root pretty
+ * much always has to be PNP0A03 anyway, just use that no matter
+ * what.
+ */
+ if (acpi_hid == EFIDP_ACPI_PCIE_ROOT_HID)
+ acpi_hid = EFIDP_ACPI_PCI_ROOT_HID;
+ dev->acpi_root.acpi_hid = acpi_hid;
+ debug(DEBUG, "acpi root HID:0x%08x", acpi_hid);
+
+ errno = 0;
+ fbuf = NULL;
+ rc = read_sysfs_file(&fbuf, "%s/firmware_node/uid", path);
+ if ((rc <= 0 && errno != ENOENT) || fbuf == NULL) {
+ efi_error("could not read %s/firmware_node/uid", path);
+ return -1;
+ }
+ if (rc > 0) {
+ rc = sscanf((char *)fbuf, "%"PRIu64"\n", &acpi_uid_int);
+ if (rc == 1) {
+ dev->acpi_root.acpi_uid = acpi_uid_int;
+ } else {
+ /* kernel uses "%s\n" to print it, so there
+ * should always be some value and a newline... */
+ int l = strlen((char *)fbuf);
+ if (l >= 1) {
+ fbuf[l-1] = '\0';
+ dev->acpi_root.acpi_uid_str = strdup(fbuf);
+ }
+ }
+ }
+ debug(DEBUG, "acpi root UID:0x%"PRIx64" uidstr:\"%s\"",
+ dev->acpi_root.acpi_uid, dev->acpi_root.acpi_uid_str);
+
+ errno = 0;
+ return 0;
+}
diff --git a/src/linux-pci.c b/src/linux-pci.c
index 4fbd108e3ed..aa3e40c0f7c 100644
--- a/src/linux-pci.c
+++ b/src/linux-pci.c
@@ -37,21 +37,17 @@
* ^ root hub ^device ^device
*
* for network devices, we also get:
- * /sys/class/net/$IFACE -> ../../devices/$PCI_STUFF/net/$IFACE
+ * /sys/class/net/$IFACE -> ../../devices/$PCI_DEVICES/net/$IFACE
+ *
+ * In both cases our "current" pointer should be at $PCI_DEVICES.
*
*/
static ssize_t
-parse_pci(struct device *dev, const char *current, const char *root UNUSED)
+parse_pci(struct device *dev, const char *current, const char *root)
{
int rc;
int pos;
- uint16_t root_domain;
- uint8_t root_bus;
- uint32_t acpi_hid = 0;
- uint64_t acpi_uid_int = 0;
const char *devpart = current;
- char *fbuf = NULL;
- uint16_t tmp16 = 0;
char *spaces;
pos = strlen(current);
@@ -62,66 +58,6 @@ parse_pci(struct device *dev, const char *current, const char *root UNUSED)
debug(DEBUG, "entry");
- /*
- * find the pci root domain and port; they basically look like:
- * pci0000:00/
- * ^d ^p
- */
- rc = sscanf(devpart, "../../devices/pci%hx:%hhx/%n", &root_domain, &root_bus, &pos);
- /*
- * If we can't find that, it's not a PCI device.
- */
- if (rc != 2)
- return 0;
- devpart += pos;
-
- dev->pci_root.pci_root_domain = root_domain;
- dev->pci_root.pci_root_bus = root_bus;
-
- rc = read_sysfs_file(&fbuf,
- "devices/pci%04hx:%02hhx/firmware_node/hid",
- root_domain, root_bus);
- if (rc < 0 || fbuf == NULL)
- return -1;
-
- rc = sscanf((char *)fbuf, "PNP%hx", &tmp16);
- if (rc != 1)
- return -1;
- acpi_hid = EFIDP_EFI_PNP_ID(tmp16);
-
- /*
- * Apparently basically nothing can look up a PcieRoot() node,
- * because they just check _CID. So since _CID for the root pretty
- * much always has to be PNP0A03 anyway, just use that no matter
- * what.
- */
- if (acpi_hid == EFIDP_ACPI_PCIE_ROOT_HID)
- acpi_hid = EFIDP_ACPI_PCI_ROOT_HID;
- dev->pci_root.pci_root_acpi_hid = acpi_hid;
-
- errno = 0;
- fbuf = NULL;
- rc = read_sysfs_file(&fbuf,
- "devices/pci%04hx:%02hhx/firmware_node/uid",
- root_domain, root_bus);
- if ((rc <= 0 && errno != ENOENT) || fbuf == NULL)
- return -1;
- if (rc > 0) {
- rc = sscanf((char *)fbuf, "%"PRIu64"\n", &acpi_uid_int);
- if (rc == 1) {
- dev->pci_root.pci_root_acpi_uid = acpi_uid_int;
- } else {
- /* kernel uses "%s\n" to print it, so there
- * should always be some value and a newline... */
- int l = strlen((char *)fbuf);
- if (l >= 1) {
- fbuf[l-1] = '\0';
- dev->pci_root.pci_root_acpi_uid_str = fbuf;
- }
- }
- }
- errno = 0;
-
/* find the pci domain/bus/device/function:
* 0000:00:01.0/0000:01:00.0/
* ^d ^b ^d ^f (of the last one in the series)
@@ -136,7 +72,7 @@ parse_pci(struct device *dev, const char *current, const char *root UNUSED)
debug(DEBUG, "searching for 0000:00:00.0/");
rc = sscanf(devpart, "%hx:%hhx:%hhx.%hhx/%n",
&domain, &bus, &device, &function, &pos);
- debug(DEBUG, "current:\"%s\" rc:%d pos:%d\n", devpart, rc, pos);
+ debug(DEBUG, "current:\"%s\" rc:%d pos:%d", devpart, rc, pos);
arrow(DEBUG, spaces, 9, pos, rc, 3);
if (rc != 4)
break;
@@ -157,24 +93,26 @@ parse_pci(struct device *dev, const char *current, const char *root UNUSED)
dev->pci_dev[i].pci_bus = bus;
dev->pci_dev[i].pci_device = device;
dev->pci_dev[i].pci_function = function;
- char *tmp = strndup(current, devpart-current+1);
+ char *tmp = strndup(root, devpart-root+1);
char *linkbuf = NULL;
if (!tmp) {
efi_error("could not allocate memory");
return -1;
}
- tmp[devpart - current] = '\0';
+ tmp[devpart - root] = '\0';
rc = sysfs_readlink(&linkbuf, "class/block/%s/driver", tmp);
- free(tmp);
if (rc < 0 || !linkbuf) {
- efi_error("Could not find driver for pci device");
+ efi_error("Could not find driver for pci device %s", tmp);
+ free(tmp);
return -1;
}
+ free(tmp);
dev->pci_dev[i].driverlink = strdup(linkbuf);
debug(DEBUG, "driver:%s\n", linkbuf);
dev->n_pci_devs += 1;
}
+ debug(DEBUG, "next:\"%s\"", devpart);
return devpart - current;
}
@@ -186,34 +124,6 @@ dp_create_pci(struct device *dev,
debug(DEBUG, "entry buf:%p size:%zd off:%zd", buf, size, off);
- if (dev->pci_root.pci_root_acpi_uid_str) {
- debug(DEBUG, "creating acpi_hid_ex dp hid:0x%08x uid:\"%s\"",
- dev->pci_root.pci_root_acpi_hid,
- dev->pci_root.pci_root_acpi_uid_str);
- new = efidp_make_acpi_hid_ex(buf + off, size ? size - off : 0,
- dev->pci_root.pci_root_acpi_hid,
- 0, 0, "",
- dev->pci_root.pci_root_acpi_uid_str,
- "");
- if (new < 0) {
- efi_error("efidp_make_acpi_hid_ex() failed");
- return new;
- }
- } else {
- debug(DEBUG, "creating acpi_hid dp hid:0x%08x uid:0x%0"PRIx64,
- dev->pci_root.pci_root_acpi_hid,
- dev->pci_root.pci_root_acpi_uid);
- new = efidp_make_acpi_hid(buf + off, size ? size - off : 0,
- dev->pci_root.pci_root_acpi_hid,
- dev->pci_root.pci_root_acpi_uid);
- if (new < 0) {
- efi_error("efidp_make_acpi_hid() failed");
- return new;
- }
- }
- off += new;
- sz += new;
-
debug(DEBUG, "creating PCI device path nodes");
for (unsigned int i = 0; i < dev->n_pci_devs; i++) {
debug(DEBUG, "creating PCI device path node %u", i);
diff --git a/src/linux.c b/src/linux.c
index ef560753481..9f3a22f7025 100644
--- a/src/linux.c
+++ b/src/linux.c
@@ -272,6 +272,13 @@ device_free(struct device *dev)
if (dev->probes)
free(dev->probes);
+ if (dev->acpi_root.acpi_hid_str)
+ free(dev->acpi_root.acpi_hid_str);
+ if (dev->acpi_root.acpi_uid_str)
+ free(dev->acpi_root.acpi_uid_str);
+ if (dev->acpi_root.acpi_cid_str)
+ free(dev->acpi_root.acpi_cid_str);
+
if (dev->interface_type == network) {
if (dev->ifname)
free(dev->ifname);
@@ -325,8 +332,8 @@ struct device HIDDEN
goto err;
}
- dev->pci_root.pci_root_domain = 0xffff;
- dev->pci_root.pci_root_bus = 0xff;
+ dev->pci_root.pci_domain = 0xffff;
+ dev->pci_root.pci_bus = 0xff;
if (S_ISBLK(dev->stat.st_mode)) {
dev->major = major(dev->stat.st_rdev);
diff --git a/src/linux.h b/src/linux.h
index 35951bb4d16..aa9e3d14a83 100644
--- a/src/linux.h
+++ b/src/linux.h
@@ -21,12 +21,18 @@
#ifndef _EFIBOOT_LINUX_H
#define _EFIBOOT_LINUX_H
+struct acpi_root_info {
+ uint32_t acpi_hid;
+ uint64_t acpi_uid;
+ uint32_t acpi_cid;
+ char *acpi_hid_str;
+ char *acpi_uid_str;
+ char *acpi_cid_str;
+};
+
struct pci_root_info {
- uint16_t pci_root_domain;
- uint8_t pci_root_bus;
- uint32_t pci_root_acpi_hid;
- uint64_t pci_root_acpi_uid;
- char *pci_root_acpi_uid_str;
+ uint16_t pci_domain;
+ uint8_t pci_bus;
};
struct pci_dev_info {
@@ -121,6 +127,7 @@ struct device {
char *disk_name;
char *part_name;
+ struct acpi_root_info acpi_root;
struct pci_root_info pci_root;
unsigned int n_pci_devs;
struct pci_dev_info *pci_dev;
@@ -147,7 +154,7 @@ extern int HIDDEN set_disk_name(struct device *dev, const char * const fmt, ...)
extern bool HIDDEN is_pata(struct device *dev);
extern int HIDDEN make_blockdev_path(uint8_t *buf, ssize_t size,
struct device *dev);
-
+extern int HIDDEN parse_acpi_hid_uid(struct device *dev, const char *fmt, ...);
extern int HIDDEN eb_nvme_ns_id(int fd, uint32_t *ns_id);
int HIDDEN get_sector_size(int filedes);
--
2.17.1
@@ -1,425 +0,0 @@
From 6b62aa40cfa1feb924609a065098da98c99e925c Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Wed, 20 Jun 2018 14:45:14 -0400
Subject: [PATCH 13/34] Make a platform ACPI root parser separate from PCI
roots.
Because apparently PNP0A03 and PNP0A0C weren't good enough.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/linux-acpi-root.c | 199 ++++++++++++++++++++++++++++++++++++++++++
src/linux-pci-root.c | 136 +++++++++++++++++++++++++++++
src/linux-pci.c | 1 -
src/linux.c | 4 +-
src/linux.h | 4 +-
5 files changed, 341 insertions(+), 3 deletions(-)
create mode 100644 src/linux-acpi-root.c
create mode 100644 src/linux-pci-root.c
diff --git a/src/linux-acpi-root.c b/src/linux-acpi-root.c
new file mode 100644
index 00000000000..c7d8276a642
--- /dev/null
+++ b/src/linux-acpi-root.c
@@ -0,0 +1,199 @@
+/*
+ * libefiboot - library for the manipulation of EFI boot variables
+ * Copyright 2012-2018 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of the
+ * License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "fix_coverity.h"
+
+#include <errno.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <stdint.h>
+#include <unistd.h>
+
+#include "efiboot.h"
+
+/*
+ * support for ACPI-like platform root hub and devices
+ *
+ * various devices /sys/dev/block/$major:$minor start with:
+ * maj:min -> ../../devices/ACPI0000:00/$PCI_DEVICES/$BLOCKDEV_STUFF/block/$DISK/$PART
+ * i.e.: APMC0D0D:00/ata1/host0/target0:0:0/0:0:0:0/block/sda
+ * ^ root hub ^blockdev stuff
+ * or:
+ * maj:min -> ../../devices/ACPI0000:00/$PCI_DEVICES/$BLOCKDEV_STUFF/block/$DISK/$PART
+ * i.e.: APMC0D0D:00/0000:00:1d.0/0000:05:00.0/ata1/host0/target0:0:0/0:0:0:0/block/sda
+ * ^ root hub ^pci dev ^pci dev ^ blockdev stuff
+ */
+static ssize_t
+parse_acpi_root(struct device *dev, const char *current, const char *root UNUSED)
+{
+ int rc;
+ int pos;
+ uint16_t pad0;
+ uint8_t pad1;
+ char *acpi_header = NULL;
+ char *colon;
+
+ const char *devpart = current;
+ char *spaces;
+
+ pos = strlen(current);
+ spaces = alloca(pos+1);
+ memset(spaces, ' ', pos+1);
+ spaces[pos] = '\0';
+ pos = 0;
+
+ debug(DEBUG, "entry");
+
+ /*
+ * find the ACPI root dunno0 and dunno1; they basically look like:
+ * ABCD0000:00/
+ * ^d0 ^d1
+ * This is annoying because "/%04ms%h:%hhx/" won't bind from the right
+ * side in sscanf.
+ */
+ rc = sscanf(devpart, "../../devices/platform/%n", &pos);
+ debug(DEBUG, "devpart:\"%s\" rc:%d pos:%d", devpart, rc, pos);
+ if (rc != 0 || pos < 1)
+ return 0;
+ devpart += pos;
+
+ /*
+ * If it's too short to be A0000:00, it's not an ACPI string
+ */
+ if (strlen(devpart) < 8)
+ return 0;
+
+ colon = strchr(devpart, ':');
+ if (!colon)
+ return 0;
+ pos = colon - devpart;
+
+ /*
+ * If colon doesn't point at something between one of these:
+ * A0000:00 ACPI0000:00
+ * ^ 5 ^ 8
+ * Then it's not an ACPI string.
+ */
+ if (pos < 5 || pos > 8)
+ return 0;
+
+ dev->acpi_root.acpi_hid_str = strndup(devpart, pos + 1);
+ if (!dev->acpi_root.acpi_hid_str) {
+ efi_error("Could not allocate memory");
+ return -1;
+ }
+ dev->acpi_root.acpi_hid_str[pos] = 0;
+ debug(DEBUG, "acpi_hid_str:\"%s\"", dev->acpi_root.acpi_hid_str);
+
+ pos -= 4;
+ debug(DEBUG, "devpart:\"%s\" rc:%d pos:%d", devpart, rc, pos);
+ acpi_header = strndupa(devpart, pos);
+ if (!acpi_header)
+ return 0;
+ acpi_header[pos] = 0;
+ debug(DEBUG, "devpart:\"%s\" acpi_header:\"%s\"", devpart, acpi_header);
+ devpart += pos;
+
+ /*
+ * If we can't find these numbers, it's not an ACPI string
+ */
+ rc = sscanf(devpart, "%hx:%hhx/%n", &pad0, &pad1, &pos);
+ if (rc != 2) {
+ efi_error("Could not parse ACPI path \"%s\"", devpart);
+ return 0;
+ }
+ debug(DEBUG, "devpart:\"%s\" parsed:%04hx:%02hhx pos:%d rc:%d",
+ devpart, pad0, pad1, pos, rc);
+
+ devpart += pos;
+
+ rc = parse_acpi_hid_uid(dev, "devices/platform/%s%04hX:%02hhX",
+ acpi_header, pad0, pad1);
+ debug(DEBUG, "rc:%d acpi_header:%s pad0:%04hX pad1:%02hhX",
+ rc, acpi_header, pad0, pad1);
+ if (rc < 0 && errno == ENOENT) {
+ rc = parse_acpi_hid_uid(dev, "devices/platform/%s%04hx:%02hhx",
+ acpi_header, pad0, pad1);
+ debug(DEBUG, "rc:%d acpi_header:%s pad0:%04hx pad1:%02hhx",
+ rc, acpi_header, pad0, pad1);
+ }
+ if (rc < 0) {
+ efi_error("Could not parse hid/uid");
+ return rc;
+ }
+ debug(DEBUG, "Parsed HID:0x%08x UID:0x%"PRIx64" uidstr:\"%s\" path:\"%s\"",
+ dev->acpi_root.acpi_hid, dev->acpi_root.acpi_uid,
+ dev->acpi_root.acpi_uid_str,
+ dev->acpi_root.acpi_cid_str);
+
+ return devpart - current;
+}
+
+static ssize_t
+dp_create_acpi_root(struct device *dev,
+ uint8_t *buf, ssize_t size, ssize_t off)
+{
+ ssize_t sz = 0, new = 0;
+
+ debug(DEBUG, "entry buf:%p size:%zd off:%zd", buf, size, off);
+
+ if (dev->acpi_root.acpi_uid_str || dev->acpi_root.acpi_cid_str) {
+ debug(DEBUG, "creating acpi_hid_ex dp hid:0x%08x uid:0x%"PRIx64" uidstr:\"%s\" cidstr:\"%s\"",
+ dev->acpi_root.acpi_hid, dev->acpi_root.acpi_uid,
+ dev->acpi_root.acpi_uid_str, dev->acpi_root.acpi_cid_str);
+ new = efidp_make_acpi_hid_ex(buf + off, size ? size - off : 0,
+ dev->acpi_root.acpi_hid,
+ dev->acpi_root.acpi_uid,
+ dev->acpi_root.acpi_cid,
+ dev->acpi_root.acpi_hid_str,
+ dev->acpi_root.acpi_uid_str,
+ dev->acpi_root.acpi_cid_str);
+ if (new < 0) {
+ efi_error("efidp_make_acpi_hid_ex() failed");
+ return new;
+ }
+ } else {
+ debug(DEBUG, "creating acpi_hid dp hid:0x%08x uid:0x%0"PRIx64,
+ dev->acpi_root.acpi_hid,
+ dev->acpi_root.acpi_uid);
+ new = efidp_make_acpi_hid(buf + off, size ? size - off : 0,
+ dev->acpi_root.acpi_hid,
+ dev->acpi_root.acpi_uid);
+ if (new < 0) {
+ efi_error("efidp_make_acpi_hid() failed");
+ return new;
+ }
+ }
+ off += new;
+ sz += new;
+
+ debug(DEBUG, "returning %zd", sz);
+ return sz;
+}
+
+enum interface_type acpi_root_iftypes[] = { acpi_root, unknown };
+
+struct dev_probe HIDDEN acpi_root_parser = {
+ .name = "acpi_root",
+ .iftypes = acpi_root_iftypes,
+ .flags = DEV_PROVIDES_ROOT,
+ .parse = parse_acpi_root,
+ .create = dp_create_acpi_root,
+};
diff --git a/src/linux-pci-root.c b/src/linux-pci-root.c
new file mode 100644
index 00000000000..8f556a066f3
--- /dev/null
+++ b/src/linux-pci-root.c
@@ -0,0 +1,136 @@
+/*
+ * libefiboot - library for the manipulation of EFI boot variables
+ * Copyright 2012-2018 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of the
+ * License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "fix_coverity.h"
+
+#include <errno.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <stdint.h>
+#include <unistd.h>
+
+#include "efiboot.h"
+
+/*
+ * support for PCI root hub and devices
+ *
+ * various devices /sys/dev/block/$major:$minor start with:
+ * maj:min -> ../../devices/pci$PCIROOT/$PCI_DEVICES/$BLOCKDEV_STUFF/block/$DISK/$PART
+ * i.e.: pci0000:00/0000:00:1d.0/0000:05:00.0/
+ * ^ root hub ^device ^device
+ *
+ * for network devices, we also get:
+ * /sys/class/net/$IFACE -> ../../devices/$PCI_STUFF/net/$IFACE
+ *
+ */
+static ssize_t
+parse_pci_root(struct device *dev, const char *current, const char *root UNUSED)
+{
+ int rc;
+ int pos;
+ uint16_t root_domain;
+ uint8_t root_bus;
+ const char *devpart = current;
+ char *spaces;
+
+ pos = strlen(current);
+ spaces = alloca(pos+1);
+ memset(spaces, ' ', pos+1);
+ spaces[pos] = '\0';
+ pos = 0;
+
+ debug(DEBUG, "entry");
+
+ /*
+ * find the pci root domain and port; they basically look like:
+ * pci0000:00/
+ * ^d ^p
+ */
+ rc = sscanf(devpart, "../../devices/pci%hx:%hhx/%n", &root_domain, &root_bus, &pos);
+ /*
+ * If we can't find that, it's not a PCI device.
+ */
+ if (rc != 2)
+ return 0;
+ devpart += pos;
+
+ dev->pci_root.pci_domain = root_domain;
+ dev->pci_root.pci_bus = root_bus;
+
+ rc = parse_acpi_hid_uid(dev, "devices/pci%04hx:%02hhx",
+ root_domain, root_bus);
+ if (rc < 0)
+ return -1;
+
+ errno = 0;
+ return devpart - current;
+}
+
+static ssize_t
+dp_create_pci_root(struct device *dev UNUSED,
+ uint8_t *buf, ssize_t size, ssize_t off)
+{
+ debug(DEBUG, "entry buf:%p size:%zd off:%zd", buf, size, off);
+ debug(DEBUG, "returning 0");
+#if 0
+ if (dev->acpi_root.acpi_uid_str) {
+ debug(DEBUG, "creating acpi_hid_ex dp hid:0x%08x uid:\"%s\"",
+ dev->acpi_root.acpi_hid,
+ dev->acpi_root.acpi_uid_str);
+ new = efidp_make_acpi_hid_ex(buf + off, size ? size - off : 0,
+ dev->acpi_root.acpi_hid,
+ 0, 0, "",
+ dev->acpi_root.acpi_uid_str,
+ "");
+ if (new < 0) {
+ efi_error("efidp_make_acpi_hid_ex() failed");
+ return new;
+ }
+ } else {
+ debug(DEBUG, "creating acpi_hid dp hid:0x%08x uid:0x%0"PRIx64,
+ dev->acpi_root.acpi_hid,
+ dev->acpi_root.acpi_uid);
+ new = efidp_make_acpi_hid(buf + off, size ? size - off : 0,
+ dev->acpi_root.acpi_hid,
+ dev->acpi_root.acpi_uid);
+ if (new < 0) {
+ efi_error("efidp_make_acpi_hid() failed");
+ return new;
+ }
+ }
+ off += new;
+ sz += new;
+
+ debug(DEBUG, "returning %zd", sz);
+ return sz;
+#else
+ return 0;
+#endif
+}
+
+enum interface_type pci_root_iftypes[] = { pci_root, unknown };
+
+struct dev_probe HIDDEN pci_root_parser = {
+ .name = "pci_root",
+ .iftypes = pci_root_iftypes,
+ .flags = DEV_PROVIDES_ROOT,
+ .parse = parse_pci_root,
+ .create = dp_create_pci_root,
+};
diff --git a/src/linux-pci.c b/src/linux-pci.c
index aa3e40c0f7c..0f59d3e840d 100644
--- a/src/linux-pci.c
+++ b/src/linux-pci.c
@@ -147,7 +147,6 @@ enum interface_type pci_iftypes[] = { pci, unknown };
struct dev_probe HIDDEN pci_parser = {
.name = "pci",
.iftypes = pci_iftypes,
- .flags = DEV_PROVIDES_ROOT,
.parse = parse_pci,
.create = dp_create_pci,
};
diff --git a/src/linux.c b/src/linux.c
index 9f3a22f7025..436fb882a98 100644
--- a/src/linux.c
+++ b/src/linux.c
@@ -235,6 +235,8 @@ static struct dev_probe *dev_probes[] = {
* be found first.
*/
&pmem_parser,
+ &acpi_root_parser,
+ &pci_root_parser,
&pci_parser,
&virtblk_parser,
&sas_parser,
@@ -447,7 +449,7 @@ struct device HIDDEN
}
debug(DEBUG, "%s matched %s", probe->name, current);
- if (probe->flags & DEV_PROVIDES_HD)
+ if (probe->flags & DEV_PROVIDES_HD || probe->flags & DEV_PROVIDES_ROOT)
needs_root = false;
dev->probes[n++] = dev_probes[i];
current += pos;
diff --git a/src/linux.h b/src/linux.h
index aa9e3d14a83..7b18bda31c6 100644
--- a/src/linux.h
+++ b/src/linux.h
@@ -95,7 +95,7 @@ struct nvdimm_info {
enum interface_type {
unknown,
- isa, pci, network,
+ isa, acpi_root, pci_root, pci, network,
ata, atapi, scsi, sata, sas,
usb, i1394, fibre, i2o,
md, virtblk,
@@ -264,6 +264,8 @@ extern ssize_t parse_scsi_link(const char *current, uint32_t *host,
/* device support implementations */
extern struct dev_probe pmem_parser;
+extern struct dev_probe pci_root_parser;
+extern struct dev_probe acpi_root_parser;
extern struct dev_probe pci_parser;
extern struct dev_probe sas_parser;
extern struct dev_probe sata_parser;
--
2.17.1
@@ -1,71 +0,0 @@
From ca71ba77abee7cea805e71a7faded706d19e4c58 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Wed, 20 Jun 2018 16:16:00 -0400
Subject: [PATCH 14/34] Make a way to say "-e 3" isn't viable for a kind of
device.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/creator.c | 7 +++++++
src/linux.c | 5 ++++-
src/linux.h | 2 ++
3 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/src/creator.c b/src/creator.c
index 76c1c1f7a99..55b411ee3da 100644
--- a/src/creator.c
+++ b/src/creator.c
@@ -243,6 +243,13 @@ efi_va_generate_file_device_path_from_esp(uint8_t *buf, ssize_t size,
va_end(aq);
}
+ if (!(options & (EFIBOOT_ABBREV_FILE|EFIBOOT_ABBREV_HD)) &&
+ (dev->flags & DEV_ABBREV_ONLY)) {
+ errno = EINVAL;
+ efi_error("Device must use File() or HD() device path");
+ goto err;
+ }
+
if ((options & EFIBOOT_ABBREV_EDD10)
&& (!(options & EFIBOOT_ABBREV_FILE)
&& !(options & EFIBOOT_ABBREV_HD))) {
diff --git a/src/linux.c b/src/linux.c
index 436fb882a98..83adc510944 100644
--- a/src/linux.c
+++ b/src/linux.c
@@ -448,8 +448,11 @@ struct device HIDDEN
continue;
}
debug(DEBUG, "%s matched %s", probe->name, current);
+ dev->flags |= probe->flags;
- if (probe->flags & DEV_PROVIDES_HD || probe->flags & DEV_PROVIDES_ROOT)
+ if (probe->flags & DEV_PROVIDES_HD ||
+ probe->flags & DEV_PROVIDES_ROOT ||
+ probe->flags & DEV_ABBREV_ONLY)
needs_root = false;
dev->probes[n++] = dev_probes[i];
current += pos;
diff --git a/src/linux.h b/src/linux.h
index 7b18bda31c6..ef7dba769bd 100644
--- a/src/linux.h
+++ b/src/linux.h
@@ -106,6 +106,7 @@ struct dev_probe;
struct device {
enum interface_type interface_type;
+ uint32_t flags;
char *link;
char *device;
char *driver;
@@ -246,6 +247,7 @@ extern ssize_t HIDDEN make_mac_path(uint8_t *buf, ssize_t size,
#define DEV_PROVIDES_ROOT 1
#define DEV_PROVIDES_HD 2
+#define DEV_ABBREV_ONLY 4
struct dev_probe {
char *name;
--
2.17.1
@@ -1,131 +0,0 @@
From d8637ea2b540fc9d16f1d1c1312e49a24082eefe Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Wed, 20 Jun 2018 16:16:35 -0400
Subject: [PATCH 15/34] Make a linux device root for SOC devices that use FDT.
Add parsing for FDT devices in sysfs. These devices have to use HD() or
File() because we don't have a way to express FDT nodes in a Device
Path.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/linux-soc-root.c | 72 ++++++++++++++++++++++++++++++++++++++++++++
src/linux.c | 1 +
src/linux.h | 3 +-
3 files changed, 75 insertions(+), 1 deletion(-)
create mode 100644 src/linux-soc-root.c
diff --git a/src/linux-soc-root.c b/src/linux-soc-root.c
new file mode 100644
index 00000000000..57dd9b04f2c
--- /dev/null
+++ b/src/linux-soc-root.c
@@ -0,0 +1,72 @@
+/*
+ * libefiboot - library for the manipulation of EFI boot variables
+ * Copyright 2012-2018 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of the
+ * License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "fix_coverity.h"
+
+#include <errno.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <stdint.h>
+#include <unistd.h>
+
+#include "efiboot.h"
+
+/*
+ * support for soc platforms
+ *
+ * various devices /sys/dev/block/$major:$minor start with:
+ * maj:min -> ../../devices/platform/soc/$DEVICETREE_NODE/$BLOCKDEV_STUFF/block/$DISK/$PART
+ * i.e.: soc/1a400000.sata/ata1/host0/target0:0:0/0:0:0:0/block/sda/sda1
+ * ^ dt node ^ blockdev stuff ^ disk
+ * I don't *think* the devicetree nodes stack.
+ */
+static ssize_t
+parse_soc_root(struct device *dev UNUSED, const char *current, const char *root UNUSED)
+{
+ int rc;
+ int pos;
+ const char *devpart = current;
+ char *spaces;
+
+ pos = strlen(current);
+ spaces = alloca(pos+1);
+ memset(spaces, ' ', pos+1);
+ spaces[pos] = '\0';
+ pos = 0;
+
+ debug(DEBUG, "entry");
+
+ rc = sscanf(devpart, "../../devices/platform/soc/%*[^/]/%n", &pos);
+ if (rc != 0)
+ return 0;
+ devpart += pos;
+ debug(DEBUG, "new position is \"%s\"", devpart);
+
+ return devpart - current;
+}
+
+enum interface_type soc_root_iftypes[] = { soc_root, unknown };
+
+struct dev_probe HIDDEN soc_root_parser = {
+ .name = "soc_root",
+ .iftypes = soc_root_iftypes,
+ .flags = DEV_ABBREV_ONLY|DEV_PROVIDES_ROOT,
+ .parse = parse_soc_root,
+};
diff --git a/src/linux.c b/src/linux.c
index 83adc510944..1e7db4e3f61 100644
--- a/src/linux.c
+++ b/src/linux.c
@@ -237,6 +237,7 @@ static struct dev_probe *dev_probes[] = {
&pmem_parser,
&acpi_root_parser,
&pci_root_parser,
+ &soc_root_parser,
&pci_parser,
&virtblk_parser,
&sas_parser,
diff --git a/src/linux.h b/src/linux.h
index ef7dba769bd..99d61013e02 100644
--- a/src/linux.h
+++ b/src/linux.h
@@ -95,7 +95,7 @@ struct nvdimm_info {
enum interface_type {
unknown,
- isa, acpi_root, pci_root, pci, network,
+ isa, acpi_root, pci_root, soc_root, pci, network,
ata, atapi, scsi, sata, sas,
usb, i1394, fibre, i2o,
md, virtblk,
@@ -268,6 +268,7 @@ extern ssize_t parse_scsi_link(const char *current, uint32_t *host,
extern struct dev_probe pmem_parser;
extern struct dev_probe pci_root_parser;
extern struct dev_probe acpi_root_parser;
+extern struct dev_probe soc_root_parser;
extern struct dev_probe pci_parser;
extern struct dev_probe sas_parser;
extern struct dev_probe sata_parser;
--
2.17.1
@@ -1,110 +0,0 @@
From bc215d06720b346ba0d888a6149cf90f544a90ad Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Wed, 20 Jun 2018 17:00:24 -0400
Subject: [PATCH 16/34] If we can't parse part of the device link, skip it and
set DEV_ABBREV_ONLY
If we can't parse some part of the device symlink, we can't write a full
device path, but we can write an abbreviated HD() or File() path. So if
we've exausted all possibilities, skip to the next node, set
DEV_ABBREV_ONLY in the device's flags, and try parsing again. Then when
creator.c checks if that flag conflicts, it'll throw an error if it
does.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/linux.c | 62 ++++++++++++++++++++++++++++++++++++++++-------------
1 file changed, 47 insertions(+), 15 deletions(-)
diff --git a/src/linux.c b/src/linux.c
index 1e7db4e3f61..8fe21f19f78 100644
--- a/src/linux.c
+++ b/src/linux.c
@@ -429,14 +429,17 @@ struct device HIDDEN
const char *current = dev->link;
bool needs_root = true;
+ int last_successful_probe = -1;
debug(DEBUG, "searching for device nodes in %s", dev->link);
for (i = 0; dev_probes[i] && dev_probes[i]->parse; i++) {
struct dev_probe *probe = dev_probes[i];
ssize_t pos;
- if (!needs_root && (probe->flags & DEV_PROVIDES_ROOT)) {
- debug(DEBUG, "not testing %s because flags is 0x%x", probe->name, probe->flags);
+ if (!needs_root &&
+ (probe->flags & DEV_PROVIDES_ROOT)) {
+ debug(DEBUG, "not testing %s because flags is 0x%x",
+ probe->name, probe->flags);
continue;
}
@@ -445,22 +448,51 @@ struct device HIDDEN
if (pos < 0) {
efi_error("parsing %s failed", probe->name);
goto err;
- } else if (pos == 0) {
+ } else if (pos > 0) {
+ debug(DEBUG, "%s matched %s", probe->name, current);
+ dev->flags |= probe->flags;
+
+ if (probe->flags & DEV_PROVIDES_HD ||
+ probe->flags & DEV_PROVIDES_ROOT ||
+ probe->flags & DEV_ABBREV_ONLY)
+ needs_root = false;
+
+ dev->probes[n++] = dev_probes[i];
+ current += pos;
+ debug(DEBUG, "current:%s", current);
+ last_successful_probe = i;
+
+ if (!*current || !strncmp(current, "block/", 6))
+ break;
+
continue;
}
- debug(DEBUG, "%s matched %s", probe->name, current);
- dev->flags |= probe->flags;
- if (probe->flags & DEV_PROVIDES_HD ||
- probe->flags & DEV_PROVIDES_ROOT ||
- probe->flags & DEV_ABBREV_ONLY)
- needs_root = false;
- dev->probes[n++] = dev_probes[i];
- current += pos;
- debug(DEBUG, "current:%s", current);
-
- if (!*current || !strncmp(current, "block/", 6))
- break;
+ debug(DEBUG, "dev_probes[i+1]: %p dev->interface_type: %d\n",
+ dev_probes[i+1], dev->interface_type);
+ if (dev_probes[i+1] == NULL && dev->interface_type == unknown) {
+ int new_pos = 0;
+ rc = sscanf(current, "%*[^/]/%n", &new_pos);
+ if (rc < 0) {
+ efi_error(
+ "Cannot parse device link segment \"%s\"",
+ current);
+ goto err;
+ }
+ debug(DEBUG,
+ "Cannot parse device link segment \"%s\"",
+ current);
+ debug(DEBUG, "Skipping to \"%s\"", current + new_pos);
+ debug(DEBUG,
+ "This means we can only write abbreviated paths");
+ if (rc < 0)
+ goto err;
+ if (new_pos == 0)
+ goto err;
+ dev->flags |= DEV_ABBREV_ONLY;
+ i = last_successful_probe;
+ current += new_pos;
+ }
}
if (dev->interface_type == unknown) {
--
2.17.1
@@ -1,25 +0,0 @@
From 8f9c1406a2a50d0c67b1380ad6fddc2c266d39f6 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Thu, 21 Jun 2018 11:13:39 -0400
Subject: [PATCH 17/34] Pacify clang analyzer just a little.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/linux-acpi-root.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/src/linux-acpi-root.c b/src/linux-acpi-root.c
index c7d8276a642..e55af5fa385 100644
--- a/src/linux-acpi-root.c
+++ b/src/linux-acpi-root.c
@@ -181,7 +181,6 @@ dp_create_acpi_root(struct device *dev,
return new;
}
}
- off += new;
sz += new;
debug(DEBUG, "returning %zd", sz);
--
2.17.1
@@ -1,32 +0,0 @@
From 576b89de7d1a49d64efab9d494eeea5a296bdccd Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Thu, 21 Jun 2018 12:23:20 -0400
Subject: [PATCH 18/34] Try even harder to convince coverity that get_file
isn't leaking memory...
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/util.h | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/src/util.h b/src/util.h
index ef85a4c277e..441ced84fcf 100644
--- a/src/util.h
+++ b/src/util.h
@@ -332,6 +332,13 @@ get_file(uint8_t **result, const char * const fmt, ...)
errno = error;
if (rc < 0 || bufsize < 1) {
+ /*
+ * I don't think this can happen, but I can't convince
+ * cov-scan
+ */
+ if (buf)
+ free(buf);
+ *result = NULL;
efi_error("could not read file \"%s\"", path);
return -1;
}
--
2.17.1
File diff suppressed because it is too large Load Diff
@@ -1,79 +0,0 @@
From bc11451222cc77d8c1b4e752167adabd3c7f64c9 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Thu, 21 Jun 2018 13:33:26 -0400
Subject: [PATCH 20/34] efiboot: Make the device node skipping code pass
coverity.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/linux.c | 31 ++++++++++++++++++-------------
1 file changed, 18 insertions(+), 13 deletions(-)
diff --git a/src/linux.c b/src/linux.c
index f919dee5b67..6d20c2dbe25 100644
--- a/src/linux.c
+++ b/src/linux.c
@@ -308,7 +308,8 @@ struct device HIDDEN
{
struct device *dev;
char *linkbuf = NULL, *tmpbuf = NULL;
- unsigned int i, n = 0;
+ int i = 0;
+ unsigned int n = 0;
int rc;
size_t nmemb = (sizeof(dev_probes)
@@ -432,9 +433,11 @@ struct device HIDDEN
int last_successful_probe = -1;
debug("searching for device nodes in %s", dev->link);
- for (i = 0; dev_probes[i] && dev_probes[i]->parse; i++) {
+ for (i = 0;
+ dev_probes[i] && dev_probes[i]->parse && *current;
+ i++) {
struct dev_probe *probe = dev_probes[i];
- ssize_t pos;
+ int pos;
if (!needs_root &&
(probe->flags & DEV_PROVIDES_ROOT)) {
@@ -471,24 +474,26 @@ struct device HIDDEN
debug("dev_probes[i+1]: %p dev->interface_type: %d\n",
dev_probes[i+1], dev->interface_type);
if (dev_probes[i+1] == NULL && dev->interface_type == unknown) {
- int new_pos = 0;
- rc = sscanf(current, "%*[^/]/%n", &new_pos);
+ pos = 0;
+ rc = sscanf(current, "%*[^/]/%n", &pos);
if (rc < 0) {
- efi_error(
- "Cannot parse device link segment \"%s\"",
- current);
+slash_err:
+ efi_error("Cannot parse device link segment \"%s\"", current);
goto err;
}
+
+ while (current[pos] == '/')
+ pos += 1;
+
+ if (!current[pos])
+ goto slash_err;
+
debug("Cannot parse device link segment \"%s\"", current);
debug("Skipping to \"%s\"", current + pos);
debug("This means we can only create abbreviated paths");
- if (rc < 0)
- goto err;
- if (new_pos == 0)
- goto err;
dev->flags |= DEV_ABBREV_ONLY;
i = last_successful_probe;
- current += new_pos;
+ current += pos;
}
}
--
2.17.1
@@ -1,35 +0,0 @@
From 22b1a7477c5ef72821e6491c67ad85ca52c1ae85 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Thu, 21 Jun 2018 13:55:32 -0400
Subject: [PATCH 21/34] efiboot: don't error on unknown type with
DEV_ABBREV_ONLY
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/linux.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/src/linux.c b/src/linux.c
index 6d20c2dbe25..7fac339c50e 100644
--- a/src/linux.c
+++ b/src/linux.c
@@ -494,10 +494,15 @@ slash_err:
dev->flags |= DEV_ABBREV_ONLY;
i = last_successful_probe;
current += pos;
+
+ if (!*current || !strncmp(current, "block/", 6))
+ break;
}
}
- if (dev->interface_type == unknown) {
+ if (dev->interface_type == unknown &&
+ !(dev->flags & DEV_ABBREV_ONLY) &&
+ !strcmp(current, "block/")) {
efi_error("unknown storage interface");
errno = ENOSYS;
goto err;
--
2.17.1
@@ -1,26 +0,0 @@
From 6d87113fc3d9b2b0f520fc97eab9f5a60fda7d30 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Thu, 21 Jun 2018 13:55:45 -0400
Subject: [PATCH 22/34] efiboot: fix a bad error check
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/linux-acpi.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/linux-acpi.c b/src/linux-acpi.c
index 3eac526525f..88f0084a37e 100644
--- a/src/linux-acpi.c
+++ b/src/linux-acpi.c
@@ -93,7 +93,7 @@ hid_err:
errno = 0;
fbuf = NULL;
rc = read_sysfs_file(&fbuf, "%s/firmware_node/uid", path);
- if ((rc <= 0 && errno != ENOENT) || fbuf == NULL) {
+ if ((rc < 0 && errno != ENOENT) || (rc > 0 && fbuf == NULL)) {
efi_error("could not read %s/firmware_node/uid", path);
return -1;
}
--
2.17.1
@@ -1,27 +0,0 @@
From 50e8c66f92b2d93d20c2524936f6858fd2b07afe Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Thu, 21 Jun 2018 14:23:40 -0400
Subject: [PATCH 23/34] efiboot: parse_scsi_link(): fix the offset searching
for the port
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/linux-scsi.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/linux-scsi.c b/src/linux-scsi.c
index 80c2fb7d82e..2e4f710badf 100644
--- a/src/linux-scsi.c
+++ b/src/linux-scsi.c
@@ -92,7 +92,7 @@ parse_scsi_link(const char *current, uint32_t *scsi_host,
pos0 = 0;
debug("searching for port-4:0 or port-4:0:0");
- rc = sscanf(current, "port-%d:%d%n:%d%n", &tosser0,
+ rc = sscanf(current+sz, "port-%d:%d%n:%d%n", &tosser0,
&tosser1, &pos0, &tosser2, &pos1);
debug("current:\"%s\" rc:%d pos0:%d pos1:%d\n", current+sz, rc, pos0, pos1);
arrow(LOG_DEBUG, spaces, 9, pos0, rc, 2);
--
2.17.1
@@ -1,28 +0,0 @@
From c2223eb4638c6d8562626917651a11b8aa1e8f9e Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Thu, 21 Jun 2018 16:18:32 -0400
Subject: [PATCH 24/34] Coverity still doesn't believe in error codes...
So also test fbuf here.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/linux-acpi.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/linux-acpi.c b/src/linux-acpi.c
index 88f0084a37e..346eba09041 100644
--- a/src/linux-acpi.c
+++ b/src/linux-acpi.c
@@ -49,7 +49,7 @@ parse_acpi_hid_uid(struct device *dev, const char *fmt, ...)
return -1;
rc = read_sysfs_file(&fbuf, "%s/firmware_node/path", path);
- if (rc > 0) {
+ if (rc > 0 && fbuf) {
size_t l = strlen(fbuf);
if (l > 1) {
fbuf[l-1] = 0;
--
2.17.1
@@ -1,28 +0,0 @@
From d8d7e54fe01a7a255e649a7734820800edf82633 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Mon, 16 Jul 2018 15:40:22 -0400
Subject: [PATCH 25/34] Don't require NVME to have an EUI
Resolves: rhbz#1593784
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/linux-nvme.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/src/linux-nvme.c b/src/linux-nvme.c
index ce931b7e237..d68d11a3409 100644
--- a/src/linux-nvme.c
+++ b/src/linux-nvme.c
@@ -117,8 +117,6 @@ parse_nvme(struct device *dev, const char *current, const char *root UNUSED)
}
dev->nvme_info.has_eui = 1;
memcpy(dev->nvme_info.eui, eui, sizeof(eui));
- } else {
- return -1;
}
return pos0;
--
2.17.1
@@ -1,27 +0,0 @@
From 50d7b979d1aa1c4afbb60a702bd16f9ff3066c50 Mon Sep 17 00:00:00 2001
From: "Bernhard M. Wiedemann" <bwiedemann@suse.de>
Date: Tue, 24 Jul 2018 09:34:21 +0200
Subject: [PATCH 26/34] makeguids: initialize memory
so that we do not write uninitialized memory into guids.bin and names.bin
which made the resulting libefivar.so.1.36 unreproducible.
See https://reproducible-builds.org/ for why this matters.
---
src/makeguids.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/makeguids.c b/src/makeguids.c
index f84fbb81166..a15356b152e 100644
--- a/src/makeguids.c
+++ b/src/makeguids.c
@@ -147,6 +147,7 @@ main(int argc, char *argv[])
outbuf = realloc(outbuf, line * sizeof (struct guidname));
if (!outbuf)
err(1, "makeguids");
+ memset(outbuf + line - 1, 0, sizeof(struct guidname));
char *symbol = strchr(guidstr, '\t');
if (symbol == NULL)
--
2.17.1
@@ -1,255 +0,0 @@
From d6a526a0c819c439a894af625f45b657576f8744 Mon Sep 17 00:00:00 2001
From: Alek Du <alek.du@intel.com>
Date: Fri, 27 Jul 2018 21:31:01 +0800
Subject: [PATCH 27/34] emmc_parser: add emmc_parser
Signed-off-by: Alek Du <alek.du@intel.com>
---
src/dp-message.c | 18 +++++
src/linux-emmc.c | 129 +++++++++++++++++++++++++++++++++
src/linux.c | 1 +
src/include/efivar/efivar-dp.h | 2 +
src/linux.h | 7 ++
src/libefivar.map.in | 1 +
6 files changed, 158 insertions(+)
create mode 100644 src/linux-emmc.c
diff --git a/src/dp-message.c b/src/dp-message.c
index 5af66438bfc..3724e5f57bd 100644
--- a/src/dp-message.c
+++ b/src/dp-message.c
@@ -826,3 +826,21 @@ efidp_make_nvdimm(uint8_t *buf, ssize_t size, efi_guid_t *uuid)
return sz;
}
+
+ssize_t PUBLIC
+efidp_make_emmc(uint8_t *buf, ssize_t size, uint32_t slot_id)
+{
+ efidp_emmc *emmc = (efidp_emmc *)buf;
+ ssize_t req = sizeof (*emmc);
+ ssize_t sz;
+
+ sz = efidp_make_generic(buf, size, EFIDP_MESSAGE_TYPE,
+ EFIDP_MSG_NVME, sizeof (*emmc));
+ if (size && sz == req)
+ emmc->slot = slot_id;
+
+ if (sz < 0)
+ efi_error("efidp_make_generic failed");
+
+ return sz;
+}
diff --git a/src/linux-emmc.c b/src/linux-emmc.c
new file mode 100644
index 00000000000..f0c9e635cb6
--- /dev/null
+++ b/src/linux-emmc.c
@@ -0,0 +1,129 @@
+/*
+ * libefiboot - library for the manipulation of EFI boot variables
+ * Copyright 2012-2018 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of the
+ * License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "fix_coverity.h"
+
+#include <errno.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <stdint.h>
+#include <unistd.h>
+
+#include "efiboot.h"
+
+/*
+ * support for emmc devices
+ *
+ * /sys/dev/block/$major:$minor looks like:
+ * 179:0 -> ../../devices/pci0000:00/0000:00:1c.0/mmc_host/mmc0/mmc0:0001/block/mmcblk0
+ * 179:1 -> ../../devices/pci0000:00/0000:00:1c.0/mmc_host/mmc0/mmc0:0001/block/mmcblk0/mmcblk0p1
+ *
+ * /sys/dev/block/179:0/device looks like:
+ * device -> ../../../mmc0:0001
+ *
+ * /sys/dev/block/179:1/partition looks like:
+ * $ cat partition
+ * 1
+ *
+ */
+
+static ssize_t
+parse_emmc(struct device *dev, const char *current, const char *root UNUSED)
+{
+ int rc;
+ int32_t tosser0, tosser1, tosser2, tosser3, slot_id, partition;
+ int pos0 = 0, pos1 = 0;
+ char *spaces;
+
+ pos0 = strlen(current);
+ spaces = alloca(pos0+1);
+ memset(spaces, ' ', pos0+1);
+ spaces[pos0] = '\0';
+ pos0 = 0;
+
+ debug(DEBUG, "entry");
+
+ debug(DEBUG, "searching for mmc_host/mmc0/mmc0:0001/block/mmcblk0 or mmc_host/mmc0/mmc0:0001/block/mmcblk0/mmcblk0p1");
+ rc = sscanf(current, "mmc_host/mmc%d/mmc%d:%d/block/mmcblk%d%n/mmcblk%dp%d%n",
+ &tosser0, &tosser1, &tosser2, &slot_id,
+ &pos0, &tosser3, &partition, &pos1);
+ debug(DEBUG, "current:\"%s\" rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1);
+ arrow(DEBUG, spaces, 9, pos0, rc, 4);
+ arrow(DEBUG, spaces, 9, pos1, rc, 6);
+ /*
+ * If it isn't of that form, it's not one of our emmc devices.
+ */
+ if (rc != 4 && rc != 6)
+ return 0;
+
+ dev->emmc_info.slot_id = slot_id;
+ dev->interface_type = emmc;
+
+ if (rc == 6) {
+ if (dev->part == -1)
+ dev->part = partition;
+
+ pos0 = pos1;
+ }
+
+ return pos0;
+}
+
+static ssize_t
+dp_create_emmc(struct device *dev,
+ uint8_t *buf, ssize_t size, ssize_t off)
+{
+ ssize_t sz;
+
+ debug(DEBUG, "entry");
+
+ sz = efidp_make_emmc(buf + off, size ? size - off : 0,
+ dev->emmc_info.slot_id);
+ return sz;
+}
+
+static char *
+make_part_name(struct device *dev)
+{
+ char *ret = NULL;
+ ssize_t rc;
+
+ if (dev->part < 1)
+ return NULL;
+
+ rc = asprintf(&ret, "%sp%d", dev->disk_name, dev->part);
+ if (rc < 0) {
+ efi_error("could not allocate memory");
+ return NULL;
+ }
+
+ return ret;
+}
+
+static enum interface_type emmc_iftypes[] = { emmc, unknown };
+
+struct dev_probe HIDDEN emmc_parser = {
+ .name = "emmc",
+ .iftypes = emmc_iftypes,
+ .flags = DEV_PROVIDES_HD,
+ .parse = parse_emmc,
+ .create = dp_create_emmc,
+ .make_part_name = make_part_name,
+};
diff --git a/src/linux.c b/src/linux.c
index 7fac339c50e..ff8db812ad3 100644
--- a/src/linux.c
+++ b/src/linux.c
@@ -246,6 +246,7 @@ static struct dev_probe *dev_probes[] = {
&ata_parser,
&scsi_parser,
&i2o_parser,
+ &emmc_parser,
NULL
};
diff --git a/src/include/efivar/efivar-dp.h b/src/include/efivar/efivar-dp.h
index 1b05775ae7e..f9ebb059d06 100644
--- a/src/include/efivar/efivar-dp.h
+++ b/src/include/efivar/efivar-dp.h
@@ -689,6 +689,8 @@ typedef struct {
uint8_t slot;
} EFIVAR_PACKED efidp_emmc;
+extern ssize_t efidp_make_emmc(uint8_t *buf, ssize_t size, uint32_t slot_id);
+
#define EFIDP_MSG_BTLE 0x1e
typedef struct {
efidp_header header;
diff --git a/src/linux.h b/src/linux.h
index 99d61013e02..7c7ea91e771 100644
--- a/src/linux.h
+++ b/src/linux.h
@@ -93,6 +93,10 @@ struct nvdimm_info {
efi_guid_t nvdimm_label;
};
+struct emmc_info {
+ int32_t slot_id;
+};
+
enum interface_type {
unknown,
isa, acpi_root, pci_root, soc_root, pci, network,
@@ -100,6 +104,7 @@ enum interface_type {
usb, i1394, fibre, i2o,
md, virtblk,
nvme, nd_pmem,
+ emmc,
};
struct dev_probe;
@@ -139,6 +144,7 @@ struct device {
struct sata_info sata_info;
struct ata_info ata_info;
struct nvme_info nvme_info;
+ struct emmc_info emmc_info;
struct nvdimm_info nvdimm_info;
};
};
@@ -277,5 +283,6 @@ extern struct dev_probe virtblk_parser;
extern struct dev_probe i2o_parser;
extern struct dev_probe scsi_parser;
extern struct dev_probe ata_parser;
+extern struct dev_probe emmc_parser;
#endif /* _EFIBOOT_LINUX_H */
diff --git a/src/libefivar.map.in b/src/libefivar.map.in
index 31f696d3cb5..b5ee1ce334a 100644
--- a/src/libefivar.map.in
+++ b/src/libefivar.map.in
@@ -51,6 +51,7 @@ libefivar.so.0 {
efidp_make_sata;
efidp_make_scsi;
efidp_make_vendor;
+ efidp_make_emmc;
efidp_parse_device_node;
efidp_parse_device_path;
efidp_set_node_data;
--
2.17.1
@@ -1,55 +0,0 @@
From 1f385ff1bde1e783eba03df37af9421bac0df82b Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Fri, 3 Aug 2018 09:56:01 -0400
Subject: [PATCH 28/34] abignore: work around an abidw bug
Some versions of abignore mistakenly treat brackets as section headers,
thus ignoring the rest of the stanza after them. It's fixed upstream,
but I don't have the newer version yet. Moving the braces to be after
the change-kind and other things works around the issue.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/abignore | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/abignore b/src/abignore
index a4597b1029c..1badb2dab35 100644
--- a/src/abignore
+++ b/src/abignore
@@ -14,28 +14,28 @@
# 'efidp_wifi __anonymous_union__::wifi' at efivar-dp.h:868:1
#
[suppress_type]
- soname_regexp = libefi(var|boot)\\.so\\..*
name = efidp_data
type_kind = typedef
has_data_member_inserted_at = end
+ soname_regexp = libefi(var|boot)\\.so\\..*
# 1 Added variable:
#
# 'const __anonymous_struct__ efi_guid_ux_capsule' {efi_guid_ux_capsule@@LIBEFIVAR_1.33}
#
[suppress_variable]
+ change_kind = added-variable
soname_regexp = libefivar\\.so\\..*
symbol_name_regexp = ^efi_guid_[[:alnum:]_]+$
- change_kind = added-variable
# allow new functions that are prefixed correctly
[suppress_function]
+ change_kind = added-function
soname_regexp = ^libefi(var|boot)\\.so\\..*
name_regexp = ^(efidp_|efi_)[[:alnum:]_]+
- change_kind = added-function
# allow new variables that are prefixed correctly
[suppress_variable]
+ change_kind = added-variable
soname_regexp = libefi(var|boot)\\.so\\..*
symbol_name_regexp = ^(efidp_|efi_)[[:alnum:]_]+
- change_kind = added-variable
--
2.17.1
File diff suppressed because it is too large Load Diff
@@ -1,50 +0,0 @@
From 0c44e3d75a9c3a2a1d4cef3c1b836aa0d7fb004f Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Fri, 3 Aug 2018 10:02:02 -0400
Subject: [PATCH 30/34] linux-emmc: update for internal API breakage.
Alek wrote his code before I made debug() imply LOG_DEBUG, so we need to
change that here as well.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/linux-emmc.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/linux-emmc.c b/src/linux-emmc.c
index f0c9e635cb6..87e92477554 100644
--- a/src/linux-emmc.c
+++ b/src/linux-emmc.c
@@ -58,15 +58,15 @@ parse_emmc(struct device *dev, const char *current, const char *root UNUSED)
spaces[pos0] = '\0';
pos0 = 0;
- debug(DEBUG, "entry");
+ debug("entry");
- debug(DEBUG, "searching for mmc_host/mmc0/mmc0:0001/block/mmcblk0 or mmc_host/mmc0/mmc0:0001/block/mmcblk0/mmcblk0p1");
+ debug("searching for mmc_host/mmc0/mmc0:0001/block/mmcblk0 or mmc_host/mmc0/mmc0:0001/block/mmcblk0/mmcblk0p1");
rc = sscanf(current, "mmc_host/mmc%d/mmc%d:%d/block/mmcblk%d%n/mmcblk%dp%d%n",
&tosser0, &tosser1, &tosser2, &slot_id,
&pos0, &tosser3, &partition, &pos1);
- debug(DEBUG, "current:\"%s\" rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1);
- arrow(DEBUG, spaces, 9, pos0, rc, 4);
- arrow(DEBUG, spaces, 9, pos1, rc, 6);
+ debug("current:\"%s\" rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1);
+ arrow(LOG_DEBUG, spaces, 9, pos0, rc, 4);
+ arrow(LOG_DEBUG, spaces, 9, pos1, rc, 6);
/*
* If it isn't of that form, it's not one of our emmc devices.
*/
@@ -92,7 +92,7 @@ dp_create_emmc(struct device *dev,
{
ssize_t sz;
- debug(DEBUG, "entry");
+ debug("entry");
sz = efidp_make_emmc(buf + off, size ? size - off : 0,
dev->emmc_info.slot_id);
--
2.17.1
@@ -1,64 +0,0 @@
From da30e9f2eee235ce11d47bb2e32f976b8c187e5d Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Mon, 10 Sep 2018 15:00:03 -0400
Subject: [PATCH 31/34] Fix another buggy fake acpi pci root driver
In this case, the platform driver that creates the PCI(e) root device
doesn't fill in its driver link, so we can't look up what driver is in
use - but since it's the root, it *really* doesn't matter. And in
general, we only really care if it's the last node in our path, because
that'll be the controller for the boot device anyway.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/linux-pci.c | 24 +++++++++++++++++-------
1 file changed, 17 insertions(+), 7 deletions(-)
diff --git a/src/linux-pci.c b/src/linux-pci.c
index e7c864b2d33..f63f5914d9f 100644
--- a/src/linux-pci.c
+++ b/src/linux-pci.c
@@ -67,7 +67,9 @@ parse_pci(struct device *dev, const char *current, const char *root)
uint8_t bus, device, function;
struct pci_dev_info *pci_dev;
unsigned int i = dev->n_pci_devs;
+ struct stat statbuf;
+ debug("devpart is \"%s\"", devpart);
pos = 0;
debug("searching for 0000:00:00.0/");
rc = sscanf(devpart, "%hx:%hhx:%hhx.%hhx/%n",
@@ -100,15 +102,23 @@ parse_pci(struct device *dev, const char *current, const char *root)
return -1;
}
tmp[devpart - root] = '\0';
- rc = sysfs_readlink(&linkbuf, "class/block/%s/driver", tmp);
- if (rc < 0 || !linkbuf) {
- efi_error("Could not find driver for pci device %s", tmp);
- free(tmp);
- return -1;
+ rc = sysfs_stat(&statbuf, "class/block/%s/driver", tmp);
+ if (rc < 0 && errno == ENOENT) {
+ debug("No driver link for /sys/class/block/%s", tmp);
+ debug("Assuming this is just a buggy platform core driver");
+ dev->pci_dev[i].driverlink = NULL;
+ } else {
+ rc = sysfs_readlink(&linkbuf, "class/block/%s/driver", tmp);
+ if (rc < 0 || !linkbuf) {
+ efi_error("Could not find driver for pci device %s", tmp);
+ free(tmp);
+ return -1;
+ } else {
+ dev->pci_dev[i].driverlink = strdup(linkbuf);
+ debug("driver:%s\n", linkbuf);
+ }
}
free(tmp);
- dev->pci_dev[i].driverlink = strdup(linkbuf);
- debug("driver:%s\n", linkbuf);
dev->n_pci_devs += 1;
}
--
2.17.1
@@ -1,28 +0,0 @@
From e56cf8d480c27bf3ea81af63efb4704896282c6a Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Mon, 17 Sep 2018 16:12:25 -0400
Subject: [PATCH 32/34] Fix dev->probes intialization test
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/linux.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/linux.c b/src/linux.c
index ff8db812ad3..19eb488c992 100644
--- a/src/linux.c
+++ b/src/linux.c
@@ -117,7 +117,9 @@ reset_part_name(struct device *dev)
if (dev->part < 1)
return 0;
- if (dev->probes[dev->n_probes]->make_part_name) {
+ if (dev->n_probes > 0 &&
+ dev->probes[dev->n_probes-1] &&
+ dev->probes[dev->n_probes-1]->make_part_name) {
part = dev->probes[dev->n_probes]->make_part_name(dev);
dev->part_name = part;
rc = 0;
--
2.17.1
@@ -1,92 +0,0 @@
From e83002b08aa6db57b90d89968ab8d34f6c7f73cf Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Mon, 17 Sep 2018 16:13:24 -0400
Subject: [PATCH 33/34] Deal with devices that don't have a ->device link in
sysfs
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/linux.c | 53 ++++++++++++++++++++++++++++++-----------------------
1 file changed, 30 insertions(+), 23 deletions(-)
diff --git a/src/linux.c b/src/linux.c
index 19eb488c992..6d405af8a76 100644
--- a/src/linux.c
+++ b/src/linux.c
@@ -389,43 +389,50 @@ struct device HIDDEN
rc = sysfs_readlink(&tmpbuf, "block/%s/device", dev->disk_name);
if (rc < 0 || !tmpbuf) {
- efi_error("readlink of /sys/block/%s/device failed",
+ debug("readlink of /sys/block/%s/device failed",
dev->disk_name);
- goto err;
+
+ dev->device = strdup("");
+ } else {
+ dev->device = strdup(tmpbuf);
}
- dev->device = strdup(tmpbuf);
if (!dev->device) {
efi_error("strdup(\"%s\") failed", tmpbuf);
goto err;
}
- rc = sysfs_readlink(&tmpbuf, "block/%s/device/driver", dev->disk_name);
- if (rc < 0 || !tmpbuf) {
- if (errno == ENOENT) {
- /*
- * nvme, for example, will have nvme0n1/device point
- * at nvme0, and we need to look for device/driver
- * there.
- */
- rc = sysfs_readlink(&tmpbuf,
- "block/%s/device/device/driver",
- dev->disk_name);
- }
+ if (dev->device[0] != 0) {
+ rc = sysfs_readlink(&tmpbuf, "block/%s/device/driver", dev->disk_name);
if (rc < 0 || !tmpbuf) {
- efi_error("readlink of /sys/block/%s/device/driver failed",
- dev->disk_name);
+ if (errno == ENOENT) {
+ /*
+ * nvme, for example, will have nvme0n1/device point
+ * at nvme0, and we need to look for device/driver
+ * there.
+ */
+ rc = sysfs_readlink(&tmpbuf,
+ "block/%s/device/device/driver",
+ dev->disk_name);
+ }
+ if (rc < 0 || !tmpbuf) {
+ efi_error("readlink of /sys/block/%s/device/driver failed",
+ dev->disk_name);
+ goto err;
+ }
+ }
+
+ linkbuf = pathseg(tmpbuf, -1);
+ if (!linkbuf) {
+ efi_error("could not get segment -1 of \"%s\"", tmpbuf);
goto err;
}
- }
- linkbuf = pathseg(tmpbuf, -1);
- if (!linkbuf) {
- efi_error("could not get segment -1 of \"%s\"", tmpbuf);
- goto err;
+ dev->driver = strdup(linkbuf);
+ } else {
+ dev->driver = strdup("");
}
- dev->driver = strdup(linkbuf);
if (!dev->driver) {
efi_error("strdup(\"%s\") failed", linkbuf);
goto err;
--
2.17.1
@@ -1,124 +0,0 @@
From 576f55b02d9ec478bd5157352c884e3543bcca58 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Mon, 17 Sep 2018 16:52:57 -0400
Subject: [PATCH 34/34] Handle partition name parsing and formatting for
partitioned md.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/linux-md.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 103 insertions(+)
create mode 100644 src/linux-md.c
diff --git a/src/linux-md.c b/src/linux-md.c
new file mode 100644
index 00000000000..0a5c1cdb435
--- /dev/null
+++ b/src/linux-md.c
@@ -0,0 +1,103 @@
+/*
+ * libefiboot - library for the manipulation of EFI boot variables
+ * Copyright 2012-2018 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of the
+ * License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "fix_coverity.h"
+
+#include <errno.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <stdint.h>
+#include <unistd.h>
+
+#include "efiboot.h"
+
+/*
+ * "support" for partitioned md devices - basically we just need to format
+ * the partition name.
+ *
+ * /sys/dev/block/$major:$minor looks like:
+ * 259:0 -> ../../devices/virtual/block/md1/md1p1
+ * 9:1 -> ../../devices/virtual/block/md1
+ *
+ */
+
+static ssize_t
+parse_md(struct device *dev, const char *current, const char *root UNUSED)
+{
+ int rc;
+ int32_t md, tosser0, part;
+ int pos0 = 0, pos1 = 0;
+ char *spaces;
+
+ pos0 = strlen(current);
+ spaces = alloca(pos0+1);
+ memset(spaces, ' ', pos0+1);
+ spaces[pos0] = '\0';
+ pos0 = 0;
+
+ debug("entry");
+
+ debug("searching for mdM/mdMpN");
+ rc = sscanf(current, "md%d/%nmd%dp%d%n",
+ &md, &pos0, &tosser0, &part, &pos1);
+ debug("current:\"%s\" rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1);
+ arrow(LOG_DEBUG, spaces, 9, pos0, rc, 3);
+ /*
+ * If it isn't of that form, it's not one of our partitioned md devices.
+ */
+ if (rc != 3)
+ return 0;
+
+ dev->interface_type = md;
+
+ if (dev->part == -1)
+ dev->part = part;
+
+ return pos1;
+}
+
+
+static char *
+make_part_name(struct device *dev)
+{
+ char *ret = NULL;
+ ssize_t rc;
+
+ if (dev->part < 1)
+ return NULL;
+
+ rc = asprintf(&ret, "%sp%d", dev->disk_name, dev->part);
+ if (rc < 0) {
+ efi_error("could not allocate memory");
+ return NULL;
+ }
+
+ return ret;
+}
+
+static enum interface_type md_iftypes[] = { md, unknown };
+
+struct dev_probe HIDDEN md_parser = {
+ .name = "md",
+ .iftypes = md_iftypes,
+ .flags = DEV_PROVIDES_HD,
+ .parse = parse_md,
+ .make_part_name = make_part_name,
+};
--
2.17.1
-107
View File
@@ -1,107 +0,0 @@
<?xml version="1.0" ?>
<!DOCTYPE PISI SYSTEM "http://www.pisilinux.org/projeler/pisi/pisi-spec.dtd">
<PISI>
<Source>
<Name>efivar</Name>
<Homepage>https://github.com/vathpela/efivar</Homepage>
<Packager>
<Name>Aydın Demirel</Name>
<Email>aydin.demirel@pisilinux.org</Email>
</Packager>
<License>LGPL2.1</License>
<IsA>app:console</IsA>
<Summary>Tools and library to manipulate EFI variables</Summary>
<Description>Tools and library to manipulate EFI variables.</Description>
<Archive sha1sum="64dc75cf71b7a989b8b4ac5cd46d1010430e89dc" type="tarbz2">https://github.com/rhinstaller/efivar/releases/download/38/efivar-38.tar.bz2</Archive>
<BuildDependencies>
<Dependency>popt-devel</Dependency>
<Dependency>mandoc</Dependency>
</BuildDependencies>
<Patches>
<Patch level="1">fedora/0001-Fix-the-march-issue-for-riscv64.patch</Patch>
<Patch level="1">fedora/0002-Fix-glibc-2.36-build-mount.h-conflicts.patch</Patch>
</Patches>
</Source>
<Package>
<Name>efivar</Name>
<RuntimeDependencies>
<Dependency>popt</Dependency>
</RuntimeDependencies>
<Files>
<Path fileType="library">/usr/lib</Path>
<Path fileType="man">/usr/share/man</Path>
<Path fileType="executable">/usr/bin</Path>
</Files>
</Package>
<Package>
<Name>efivar-devel</Name>
<RuntimeDependencies>
<Dependency>popt-devel</Dependency>
<Dependency release="current">efivar</Dependency>
</RuntimeDependencies>
<Files>
<Path fileType="header">/usr/include</Path>
<Path fileType="data">/usr/lib/pkgconfig</Path>
</Files>
</Package>
<History>
<Update release="11">
<Date>2023-03-12</Date>
<Version>38</Version>
<Comment>Version bump.</Comment>
<Name>Mustafa Cinasal</Name>
<Email>muscnsl@gmail.com</Email>
</Update>
<Update release="10">
<Date>2021-07-16</Date>
<Version>37</Version>
<Comment>Rebuild.</Comment>
<Name>Mustafa Cinasal</Name>
<Email>muscnsl@gmail.com</Email>
</Update>
<Update release="9">
<Date>2020-01-25</Date>
<Version>37</Version>
<Comment>Version bump.</Comment>
<Name>Mustafa Cinasal</Name>
<Email>muscnsl@gmail.com</Email>
</Update>
<Update release="8">
<Date>2018-10-21</Date>
<Version>36</Version>
<Comment>Version bump.</Comment>
<Name>Ertuğrul Erata</Name>
<Email>ertugrulerata@gmail.com</Email>
</Update>
<Update release="7">
<Date>2018-08-13</Date>
<Version>31</Version>
<Comment>Rebuild New T.</Comment>
<Name>Mustafa Cinasal</Name>
<Email>muscnsl@gmail.com</Email>
</Update>
<Update release="6">
<Date>2017-12-09</Date>
<Version>31</Version>
<Comment>Version bump</Comment>
<Name>Ertuğrul Erata</Name>
<Email>ertugrulerata@gmail.com</Email>
</Update>
<Update release="5">
<Date>2017-01-24</Date>
<Version>26</Version>
<Comment>Version bump.</Comment>
<Name>Stefan Gronewold(groni)</Name>
<Email>groni@pisilinux.org</Email>
</Update>
<Update release="1">
<Date>2016-03-29</Date>
<Version>0.23</Version>
<Comment>First release</Comment>
<Name>Osman Erkan</Name>
<Email>osman.erkan@pisilinux.org</Email>
</Update>
</History>
</PISI>
-8
View File
@@ -1,8 +0,0 @@
<?xml version="1.0" ?>
<PISI>
<Source>
<Name>efivar</Name>
<Summary xml:lang="tr">EFI değişkenlerini işlemek için araçlar ve kütüphane</Summary>
<Description xml:lang="tr">EFI değişkenlerini işlemek için araçlar ve kütüphane</Description>
</Source>
</PISI>