Compare commits

...

1 Commits

Author SHA1 Message Date
CentOS Sources
cb97d19e10 import efivar-37-4.el8 2021-09-09 16:19:47 +00:00
107 changed files with 24742 additions and 6765 deletions

View File

@ -1 +1 @@
3c74c8a0d8bc7a39b74de52cad2a791c00cdfd67 SOURCES/efivar-36.tar.bz2 1ef24e0a06e1a42d7a93ba7a76b2970659c7c0c0 SOURCES/efivar-37.tar.bz2

2
.gitignore vendored
View File

@ -1 +1 @@
SOURCES/efivar-36.tar.bz2 SOURCES/efivar-37.tar.bz2

View File

@ -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/39] 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

View File

@ -0,0 +1,33 @@
From 9a35c81ba28788831a003c071a96acfab81ca354 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/63] 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.26.2

View File

@ -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/39] 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

View File

@ -0,0 +1,59 @@
From 945a87340240b70b3c579773c9481ca913d95a92 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/63] 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.26.2

View File

@ -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/39] 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

View File

@ -0,0 +1,27 @@
From 8c9cb884ebdc79bb69df13f2bfdf99543233588f 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/63] 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.26.2

View File

@ -0,0 +1,172 @@
From d1955bdfb19829221e2b6294bba256c5447677ac 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/63] 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.26.2

View File

@ -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/39] 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

View File

@ -0,0 +1,372 @@
From da19b396ed674a7c9fddca1e3b480a18e642e280 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/63] 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.26.2

View File

@ -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/39] 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

View File

@ -0,0 +1,38 @@
From be60850c79dcb62cf682ea496ec22d8ea45f9da2 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/63] 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.26.2

View File

@ -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/39] 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

View File

@ -0,0 +1,82 @@
From f5932cee024f080a005bbfc252a3596f093e7ecd 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/63] 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.26.2

View File

@ -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/39] 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

View File

@ -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/39] 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

View File

@ -0,0 +1,40 @@
From f9a64ce561b122368118149cb24c20bf3e0c9e1c 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/63] 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.26.2

View File

@ -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/39] 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

View File

@ -0,0 +1,54 @@
From d10381d23097d96afbb8d7c4199e58164da0d870 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/63] 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.26.2

View File

@ -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/39] 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

View File

@ -0,0 +1,34 @@
From 3ae06e10e5e25ca6aab04eba1cb0402bfe068997 Mon Sep 17 00:00:00 2001
From: Javier Martinez Canillas <javierm@redhat.com>
Date: Tue, 5 Mar 2019 17:23:24 +0100
Subject: [PATCH 10/63] ucs2.h: remove unused variable
The const uint16_t pointer is not used since now the two bytes of the
UCS-2 chars are checked to know if is the termination of the string.
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
---
src/ucs2.h | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/src/ucs2.h b/src/ucs2.h
index edd8367b4bc..e0390c34985 100644
--- a/src/ucs2.h
+++ b/src/ucs2.h
@@ -26,12 +26,11 @@ static inline size_t UNUSED
ucs2len(const void *vs, ssize_t limit)
{
ssize_t 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++)
+ i++, s8 += 2)
;
return i;
}
--
2.26.2

View File

@ -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/39] 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

View File

@ -0,0 +1,32 @@
From 4468e686c271cd208d741de4b304200bf28832f9 Mon Sep 17 00:00:00 2001
From: Javier Martinez Canillas <javierm@redhat.com>
Date: Tue, 5 Mar 2019 17:23:32 +0100
Subject: [PATCH 11/63] ucs2.h: fix logic that checks for UCS-2 string
termination
Currently the loop to count the lenght of the UCS-2 string ends if either
of the two bytes are 0, but 0 is a valid value for UCS-2 character codes.
So only break the loop when 0 is the value for both UCS-2 char bytes.
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
---
src/ucs2.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/ucs2.h b/src/ucs2.h
index e0390c34985..fd8b056ad25 100644
--- a/src/ucs2.h
+++ b/src/ucs2.h
@@ -29,7 +29,7 @@ ucs2len(const void *vs, ssize_t limit)
const uint8_t *s8 = vs;
for (i = 0;
- i < (limit >= 0 ? limit : i+1) && s8[0] != 0 && s8[1] != 0;
+ i < (limit >= 0 ? limit : i+1) && !(s8[0] == 0 && s8[1] == 0);
i++, s8 += 2)
;
return i;
--
2.26.2

View File

@ -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/39] 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

View File

@ -0,0 +1,44 @@
From 627860f1c60139b41580929a4c3a3328b579b278 Mon Sep 17 00:00:00 2001
From: Javier Martinez Canillas <javierm@redhat.com>
Date: Tue, 5 Mar 2019 17:23:36 +0100
Subject: [PATCH 12/63] dp-message: fix efidp_ipv4_addr fields assignment
The efidp_ipv4_addr structure has some 4-byte array fields to store IPv4
addresses and network mask. But the efidp_make_ipv4() function wrongly
casts these as a char * before dereferencing them to store a value.
Instead, cast it to a uint32_t * so the 32-bit value is correctly stored.
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
---
src/dp-message.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/dp-message.c b/src/dp-message.c
index 6b8e9072594..55fa7810439 100644
--- a/src/dp-message.c
+++ b/src/dp-message.c
@@ -678,16 +678,16 @@ efidp_make_ipv4(uint8_t *buf, ssize_t size, uint32_t local, uint32_t remote,
EFIDP_MSG_IPv4, sizeof (*ipv4));
ssize_t req = sizeof (*ipv4);
if (size && sz == req) {
- *((char *)ipv4->local_ipv4_addr) = htonl(local);
- *((char *)ipv4->remote_ipv4_addr) = htonl(remote);
+ *((uint32_t *)ipv4->local_ipv4_addr) = htonl(local);
+ *((uint32_t *)ipv4->remote_ipv4_addr) = htonl(remote);
ipv4->local_port = htons(local_port);
ipv4->remote_port = htons(remote_port);
ipv4->protocol = htons(protocol);
ipv4->static_ip_addr = 0;
if (is_static)
ipv4->static_ip_addr = 1;
- *((char *)ipv4->gateway) = htonl(gateway);
- *((char *)ipv4->netmask) = htonl(netmask);
+ *((uint32_t *)ipv4->gateway) = htonl(gateway);
+ *((uint32_t *)ipv4->netmask) = htonl(netmask);
}
if (sz < 0)
--
2.26.2

View File

@ -0,0 +1,129 @@
From 62d5bb056e8f9ed4517c460d4d7ea5d51bc8125c Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Wed, 13 Mar 2019 11:01:34 -0400
Subject: [PATCH 13/63] Always refer to MBR and GPT fixed values as 'magic' not
'signature'
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/disk.c | 5 +++--
src/gpt.c | 22 +++++++++++-----------
src/gpt.h | 8 ++++----
3 files changed, 18 insertions(+), 17 deletions(-)
diff --git a/src/disk.c b/src/disk.c
index 3efee03b804..519c2a19325 100644
--- a/src/disk.c
+++ b/src/disk.c
@@ -52,10 +52,11 @@ is_mbr_valid(legacy_mbr *mbr)
int ret;
if (!mbr)
return 0;
- ret = (mbr->signature == MSDOS_MBR_SIGNATURE);
+ ret = (mbr->magic == MSDOS_MBR_MAGIC);
if (!ret) {
errno = ENOTTY;
- efi_error("mbr signature is not MSDOS_MBR_SIGNATURE");
+ efi_error("mbr magic is 0x%04hx not MSDOS_MBR_MAGIC (0x%04hx)",
+ mbr->magic, MSDOS_MBR_MAGIC);
}
return ret;
}
diff --git a/src/gpt.c b/src/gpt.c
index ce8e638ab83..7bdb8ad1575 100644
--- a/src/gpt.c
+++ b/src/gpt.c
@@ -72,24 +72,24 @@ efi_crc32(const void *buf, unsigned long len)
*
* Description: Returns 1 if PMBR is valid, 0 otherwise.
* Validity depends on two things:
- * 1) MSDOS signature is in the last two bytes of the MBR
+ * 1) MSDOS magic is in the last two bytes of the MBR
* 2) One partition of type 0xEE is found
*/
static int
is_pmbr_valid(legacy_mbr *mbr)
{
- int i, found = 0, signature = 0;
+ int i, found = 0, magic = 0;
if (!mbr)
return 0;
- signature = (le16_to_cpu(mbr->signature) == MSDOS_MBR_SIGNATURE);
- for (i = 0; signature && i < 4; i++) {
+ magic = (le16_to_cpu(mbr->magic) == MSDOS_MBR_MAGIC);
+ for (i = 0; magic && i < 4; i++) {
if (mbr->partition[i].os_type ==
EFI_PMBR_OSTYPE_EFI_GPT) {
found = 1;
break;
}
}
- return (signature && found);
+ return (magic && found);
}
/**
@@ -389,11 +389,11 @@ is_gpt_valid(int fd, uint64_t lba,
if (!(*gpt = alloc_read_gpt_header(fd, lba)))
return 0;
- /* Check the GUID Partition Table signature */
- if (le64_to_cpu((*gpt)->signature) != GPT_HEADER_SIGNATURE) {
- efi_error("GUID Partition Table Header signature is wrong: %"PRIx64" != %"PRIx64,
- (uint64_t)le64_to_cpu((*gpt)->signature),
- GPT_HEADER_SIGNATURE);
+ /* Check the GUID Partition Table magic */
+ if (le64_to_cpu((*gpt)->magic) != GPT_HEADER_MAGIC) {
+ efi_error("GUID Partition Table Header magic is wrong: %"PRIx64" != %"PRIx64,
+ (uint64_t)le64_to_cpu((*gpt)->magic),
+ GPT_HEADER_MAGIC);
free(*gpt);
*gpt = NULL;
return rc;
@@ -673,7 +673,7 @@ find_valid_gpt(int fd, gpt_header ** gpt, gpt_entry ** ptes,
/* Would fail due to bad PMBR, but force GPT anyhow */
if ((good_pgpt || good_agpt) && !good_pmbr && ignore_pmbr_err) {
- efi_error(" Warning: Disk has a valid GPT signature but invalid PMBR.\n"
+ efi_error(" Warning: Disk has a valid GPT magic but invalid PMBR.\n"
" Use GNU Parted to correct disk.\n"
" gpt option taken, disk treated as GPT.");
}
diff --git a/src/gpt.h b/src/gpt.h
index 5eb5d1a732c..0d7d5e8a649 100644
--- a/src/gpt.h
+++ b/src/gpt.h
@@ -29,10 +29,10 @@
#define EFI_PMBR_OSTYPE_EFI 0xEF
#define EFI_PMBR_OSTYPE_EFI_GPT 0xEE
-#define MSDOS_MBR_SIGNATURE 0xaa55
+#define MSDOS_MBR_MAGIC 0xaa55
#define GPT_BLOCK_SIZE 512
-#define GPT_HEADER_SIGNATURE ((uint64_t)(0x5452415020494645ULL))
+#define GPT_HEADER_MAGIC ((uint64_t)(0x5452415020494645ULL))
#define GPT_HEADER_REVISION_V1_02 0x00010200
#define GPT_HEADER_REVISION_V1_00 0x00010000
#define GPT_HEADER_REVISION_V0_99 0x00009900
@@ -61,7 +61,7 @@
0x23, 0x8f, 0x2a, 0x3d, 0xf9, 0x28)
typedef struct _gpt_header {
- uint64_t signature;
+ uint64_t magic;
uint32_t revision;
uint32_t header_size;
uint32_t header_crc32;
@@ -133,7 +133,7 @@ typedef struct _legacy_mbr {
uint32_t unique_mbr_signature;
uint16_t unknown;
partition_record partition[4];
- uint16_t signature;
+ uint16_t magic;
} PACKED legacy_mbr;
#define EFI_GPT_PRIMARY_PARTITION_TABLE_LBA 1
--
2.26.2

View File

@ -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/39] 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

View File

@ -0,0 +1,87 @@
From 707276197e82e852e9d5c7acb97a9348efe467b7 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Wed, 13 Mar 2019 11:02:01 -0400
Subject: [PATCH 14/63] Add more hexdump logging functions.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/hexdump.h | 30 ++++++++++++++++++++++++++++--
src/util.h | 10 ++++++++++
2 files changed, 38 insertions(+), 2 deletions(-)
diff --git a/src/hexdump.h b/src/hexdump.h
index 4c45cb3732d..f8c32faa9e1 100644
--- a/src/hexdump.h
+++ b/src/hexdump.h
@@ -63,8 +63,12 @@ prepare_text(uint8_t *data, unsigned long size, char *buf)
buf[offset] = '\0';
}
+/*
+ * variadic fhexdump formatted
+ * think of it as: fprintf(f, %s%s\n", vformat(fmt, ap), hexdump(data,size));
+ */
static inline void UNUSED
-hexdump(uint8_t *data, unsigned long size)
+vfhexdumpf(FILE *f, const char * const fmt, uint8_t *data, unsigned long size, va_list ap)
{
unsigned long display_offset = (unsigned long)data & 0xffffffff;
unsigned long offset = 0;
@@ -80,11 +84,33 @@ hexdump(uint8_t *data, unsigned long size)
return;
prepare_text(data+offset, size-offset, txtbuf);
- printf("%016lx %s %s\n", display_offset, hexbuf, txtbuf);
+ vfprintf(f, fmt, ap);
+ fprintf(f, "%016lx %s %s\n", display_offset, hexbuf, txtbuf);
display_offset += sz;
offset += sz;
}
+ fflush(f);
+}
+
+/*
+ * fhexdump formatted
+ * think of it as: fprintf(f, %s%s\n", format(fmt, ...), hexdump(data,size));
+ */
+static inline void UNUSED
+fhexdumpf(FILE *f, const char * const fmt, uint8_t *data, unsigned long size, ...)
+{
+ va_list ap;
+
+ va_start(ap, size);
+ vfhexdumpf(f, fmt, data, size, ap);
+ va_end(ap);
+}
+
+static inline void UNUSED
+hexdump(uint8_t *data, unsigned long size)
+{
+ fhexdumpf(stdout, "", data, size);
}
#endif /* STATIC_HEXDUMP_H */
diff --git a/src/util.h b/src/util.h
index d98bfa1beed..a6a80e754ec 100644
--- a/src/util.h
+++ b/src/util.h
@@ -400,5 +400,15 @@ swizzle_guid_to_uuid(efi_guid_t *guid)
#endif
#define log(level, fmt, args...) log_(__FILE__, __LINE__, __func__, level, fmt, ## args)
#define debug(fmt, args...) log(LOG_DEBUG, fmt, ## args)
+#define log_hex_(file, line, func, level, buf, size) \
+ ({ \
+ if (efi_get_verbose() >= level) { \
+ fhexdumpf(efi_get_logfile(), "%s:%d %s(): ", \
+ (uint8_t *)buf, size, \
+ file, line, func); \
+ } \
+ })
+#define log_hex(level, buf, size) log_hex_(__FILE__, __LINE__, __func__, level, buf, size)
+#define debug_hex(buf, size) log_hex(LOG_DEBUG, buf, size)
#endif /* EFIVAR_UTIL_H */
--
2.26.2

View File

@ -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/39] 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

View File

@ -0,0 +1,147 @@
From c4e3c85e470705f2e8a3bdebf54ebcea90152963 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Tue, 28 May 2019 14:02:12 -0400
Subject: [PATCH 15/63] Add efi_error_pop() and pop some errors sometimes.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/error.c | 37 +++++++++++++++++++++++++++++--------
src/include/efivar/efivar.h | 9 +++++++++
src/libefivar.map.in | 7 +++++++
src/linux.c | 4 ++++
4 files changed, 49 insertions(+), 8 deletions(-)
diff --git a/src/error.c b/src/error.c
index d1008a3d676..df03d7f45e0 100644
--- a/src/error.c
+++ b/src/error.c
@@ -78,6 +78,22 @@ efi_error_get(unsigned int n,
return 1;
}
+static inline UNUSED void
+clear_error_entry(error_table_entry *et)
+{
+ if (!et)
+ return;
+
+ if (et->filename)
+ free(et->filename);
+ if (et->function)
+ free(et->function);
+ if (et->message)
+ free(et->message);
+
+ memset(et, '\0', sizeof(*et));
+}
+
int PUBLIC NONNULL(1, 2, 5) PRINTF(5, 6)
efi_error_set(const char *filename,
const char *function,
@@ -136,6 +152,16 @@ err:
return -1;
}
+void PUBLIC
+efi_error_pop(void)
+{
+ if (current <= 0)
+ return;
+
+ current -= 1;
+ clear_error_entry(&error_table[current]);
+}
+
void PUBLIC DESTRUCTOR
efi_error_clear(void)
{
@@ -143,14 +169,7 @@ efi_error_clear(void)
for (unsigned int i = 0; i < current; i++) {
error_table_entry *et = &error_table[i];
- if (et->filename)
- free(et->filename);
- if (et->function)
- free(et->function);
- if (et->message)
- free(et->message);
-
- memset(et, '\0', sizeof(*et));
+ clear_error_entry(et);
}
free(error_table);
}
@@ -182,3 +201,5 @@ efi_get_verbose(void)
{
return efi_verbose;
}
+
+// vim:fenc=utf-8:tw=75:noet
diff --git a/src/include/efivar/efivar.h b/src/include/efivar/efivar.h
index ad6449d9d93..dabf41789e5 100644
--- a/src/include/efivar/efivar.h
+++ b/src/include/efivar/efivar.h
@@ -187,6 +187,7 @@ extern int efi_error_set(const char *filename,
__attribute__((__nonnull__ (1, 2, 5)))
__attribute__((__format__ (printf, 5, 6)));
extern void efi_error_clear(void);
+extern void efi_error_pop(void);
#else
static inline int
__attribute__((__nonnull__ (2, 3, 4, 5, 6)))
@@ -218,6 +219,12 @@ efi_error_clear(void)
{
return;
}
+
+static inline void
+efi_error_pop(void)
+{
+ return;
+}
#endif
#define efi_error_real__(errval, file, function, line, fmt, args...) \
@@ -238,3 +245,5 @@ extern FILE * efi_get_logfile(void)
#include <efivar/efivar-dp.h>
#endif /* EFIVAR_H */
+
+// vim:fenc=utf-8:tw=75:noet
diff --git a/src/libefivar.map.in b/src/libefivar.map.in
index b5ee1ce334a..8e50d574f10 100644
--- a/src/libefivar.map.in
+++ b/src/libefivar.map.in
@@ -127,3 +127,10 @@ LIBEFIVAR_1.36 {
efi_get_verbose;
efi_get_logfile;
} LIBEFIVAR_1.35;
+
+LIBEFIVAR_1.37 {
+} LIBEFIVAR_1.36;
+
+LIBEFIVAR_1.38 {
+ global: efi_error_pop;
+} LIBEFIVAR_1.37;
diff --git a/src/linux.c b/src/linux.c
index 4bb453be834..4e102da5e24 100644
--- a/src/linux.c
+++ b/src/linux.c
@@ -405,6 +405,8 @@ struct device HIDDEN
rc = sysfs_readlink(&tmpbuf,
"block/%s/device/device/driver",
dev->disk_name);
+ if (rc >= 0 && tmpbuf)
+ efi_error_pop();
}
if (rc < 0 || !tmpbuf) {
efi_error("readlink of /sys/block/%s/device/driver failed",
@@ -626,3 +628,5 @@ get_sector_size(int filedes)
sector_size = 512;
return sector_size;
}
+
+// vim:fenc=utf-8:tw=75:et
--
2.26.2

View File

@ -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/39] 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

View File

@ -0,0 +1,215 @@
From 518bca17bd39d87a35b9f7c7f186f08dc9e4be15 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Tue, 28 May 2019 15:42:37 -0400
Subject: [PATCH 16/63] Always log to a memfd regardless of loglevel.
This writes all debug logs to a memfd, so that they'll always show up in
strace.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/error.c | 88 ++++++++++++++++++++++++++++++++++---
src/include/efivar/efivar.h | 7 +++
src/libefivar.map.in | 1 +
src/util.h | 26 +++++------
4 files changed, 102 insertions(+), 20 deletions(-)
diff --git a/src/error.c b/src/error.c
index df03d7f45e0..5dc43197c50 100644
--- a/src/error.c
+++ b/src/error.c
@@ -26,6 +26,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <sys/mman.h>
#include <unistd.h>
#include "efiboot.h"
@@ -162,7 +163,58 @@ efi_error_pop(void)
clear_error_entry(&error_table[current]);
}
-void PUBLIC DESTRUCTOR
+static int efi_verbose;
+static FILE *efi_errlog, *efi_dbglog;
+static int efi_dbglog_fd = -1;
+static int stashed_log_level;
+static char efi_dbglog_buf[4096];
+
+void PUBLIC
+efi_stash_loglevel_(int level)
+{
+ stashed_log_level = level;
+}
+
+static ssize_t
+dbglog_write(void *cookie UNUSED, const char *buf, size_t size)
+{
+ FILE *log = efi_errlog ? efi_errlog : stderr;
+ ssize_t ret = size;
+
+ if (efi_get_verbose() >= stashed_log_level) {
+ ret = fwrite(buf, 1, size, log);
+ } else if (efi_dbglog_fd >= 0) {
+ lseek(efi_dbglog_fd, 0, SEEK_SET);
+ write(efi_dbglog_fd, buf, size);
+ }
+ return ret;
+}
+
+static int
+dbglog_seek(void *cookie UNUSED, off64_t *offset, int whence)
+{
+ FILE *log = efi_errlog ? efi_errlog : stderr;
+ return fseek(log, *offset, whence);
+}
+
+static int
+dbglog_close(void *cookie UNUSED)
+{
+ if (efi_dbglog_fd >= 0) {
+ close(efi_dbglog_fd);
+ efi_dbglog_fd = -1;
+ }
+ if (efi_errlog) {
+ int ret = fclose(efi_errlog);
+ efi_errlog = NULL;
+ return ret;
+ }
+
+ errno = EBADF;
+ return -1;
+}
+
+void PUBLIC
efi_error_clear(void)
{
if (error_table) {
@@ -177,15 +229,39 @@ efi_error_clear(void)
current = 0;
}
-static int efi_verbose;
-static FILE *efi_errlog;
+void DESTRUCTOR
+efi_error_fini(void)
+{
+ efi_error_clear();
+ if (efi_dbglog) {
+ fclose(efi_dbglog);
+ efi_dbglog = NULL;
+ }
+}
+
+static void CONSTRUCTOR
+efi_error_init(void)
+{
+ cookie_io_functions_t io_funcs = {
+ .write = dbglog_write,
+ .seek = dbglog_seek,
+ .close = dbglog_close,
+ };
+
+ efi_dbglog_fd = memfd_create("efivar-debug.log", MFD_CLOEXEC);
+ if (efi_dbglog_fd == -1)
+ return;
+
+ efi_dbglog = fopencookie(NULL, "a", io_funcs);
+ if (efi_dbglog)
+ setvbuf(efi_dbglog, efi_dbglog_buf, _IOLBF,
+ sizeof(efi_dbglog_buf));
+}
FILE PUBLIC *
efi_get_logfile(void)
{
- if (efi_errlog)
- return efi_errlog;
- return stderr;
+ return efi_dbglog;
}
void PUBLIC
diff --git a/src/include/efivar/efivar.h b/src/include/efivar/efivar.h
index dabf41789e5..343d1c557da 100644
--- a/src/include/efivar/efivar.h
+++ b/src/include/efivar/efivar.h
@@ -188,6 +188,7 @@ extern int efi_error_set(const char *filename,
__attribute__((__format__ (printf, 5, 6)));
extern void efi_error_clear(void);
extern void efi_error_pop(void);
+extern void efi_stash_loglevel_(int level);
#else
static inline int
__attribute__((__nonnull__ (2, 3, 4, 5, 6)))
@@ -225,6 +226,12 @@ efi_error_pop(void)
{
return;
}
+
+static inline void
+efi_stash_loglevel_(int level __attribute__((__unused__)))
+{
+ return;
+}
#endif
#define efi_error_real__(errval, file, function, line, fmt, args...) \
diff --git a/src/libefivar.map.in b/src/libefivar.map.in
index 8e50d574f10..8965b729917 100644
--- a/src/libefivar.map.in
+++ b/src/libefivar.map.in
@@ -133,4 +133,5 @@ LIBEFIVAR_1.37 {
LIBEFIVAR_1.38 {
global: efi_error_pop;
+ efi_stash_loglevel_;
} LIBEFIVAR_1.37;
diff --git a/src/util.h b/src/util.h
index a6a80e754ec..337762c9902 100644
--- a/src/util.h
+++ b/src/util.h
@@ -382,15 +382,14 @@ swizzle_guid_to_uuid(efi_guid_t *guid)
#define log_(file, line, func, level, fmt, args...) \
({ \
- if (efi_get_verbose() >= level) { \
- FILE *logfile_ = efi_get_logfile(); \
- int len_ = strlen(fmt); \
- fprintf(logfile_, "%s:%d %s(): ", \
- file, line, func); \
- fprintf(logfile_, fmt, ## args); \
- if (!len_ || fmt[len_ - 1] != '\n') \
- fprintf(logfile_, "\n"); \
- } \
+ efi_stash_loglevel_(level); \
+ FILE *logfile_ = efi_get_logfile(); \
+ int len_ = strlen(fmt); \
+ fprintf(logfile_, "%s:%d %s(): ", \
+ file, line, func); \
+ fprintf(logfile_, fmt, ## args); \
+ if (!len_ || fmt[len_ - 1] != '\n') \
+ fprintf(logfile_, "\n"); \
})
#define LOG_VERBOSE 0
@@ -402,11 +401,10 @@ swizzle_guid_to_uuid(efi_guid_t *guid)
#define debug(fmt, args...) log(LOG_DEBUG, fmt, ## args)
#define log_hex_(file, line, func, level, buf, size) \
({ \
- if (efi_get_verbose() >= level) { \
- fhexdumpf(efi_get_logfile(), "%s:%d %s(): ", \
- (uint8_t *)buf, size, \
- file, line, func); \
- } \
+ efi_stash_loglevel_(level); \
+ fhexdumpf(efi_get_logfile(), "%s:%d %s(): ", \
+ (uint8_t *)buf, size, \
+ file, line, func); \
})
#define log_hex(level, buf, size) log_hex_(__FILE__, __LINE__, __func__, level, buf, size)
#define debug_hex(buf, size) log_hex(LOG_DEBUG, buf, size)
--
2.26.2

View File

@ -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/39] 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

View File

@ -0,0 +1,82 @@
From c723928663b03aed5fb74b3f821ac16a43d9118e Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Tue, 28 May 2019 16:27:31 -0400
Subject: [PATCH 17/63] Always initialize any variable we use with sscanf's %n
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/linux-acpi-root.c | 2 +-
src/linux-pci-root.c | 2 +-
src/linux-pci.c | 2 +-
src/linux-soc-root.c | 2 +-
src/linux-virtblk.c | 2 +-
5 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/linux-acpi-root.c b/src/linux-acpi-root.c
index 30728ded671..b237039685e 100644
--- a/src/linux-acpi-root.c
+++ b/src/linux-acpi-root.c
@@ -44,7 +44,7 @@ static ssize_t
parse_acpi_root(struct device *dev, const char *current, const char *root UNUSED)
{
int rc;
- int pos;
+ int pos = 0;
uint16_t pad0;
uint8_t pad1;
char *acpi_header = NULL;
diff --git a/src/linux-pci-root.c b/src/linux-pci-root.c
index 0605acfc7cb..0b5ad48d6db 100644
--- a/src/linux-pci-root.c
+++ b/src/linux-pci-root.c
@@ -44,7 +44,7 @@ static ssize_t
parse_pci_root(struct device *dev, const char *current, const char *root UNUSED)
{
int rc;
- int pos;
+ int pos = 0;
uint16_t root_domain;
uint8_t root_bus;
const char *devpart = current;
diff --git a/src/linux-pci.c b/src/linux-pci.c
index 64aaefb461c..c3b9fcf9092 100644
--- a/src/linux-pci.c
+++ b/src/linux-pci.c
@@ -46,7 +46,7 @@ static ssize_t
parse_pci(struct device *dev, const char *current, const char *root)
{
int rc;
- int pos;
+ int pos = 0;
const char *devpart = current;
debug("entry");
diff --git a/src/linux-soc-root.c b/src/linux-soc-root.c
index 373cd59521a..cbb4779b6fb 100644
--- a/src/linux-soc-root.c
+++ b/src/linux-soc-root.c
@@ -41,7 +41,7 @@ static ssize_t
parse_soc_root(struct device *dev UNUSED, const char *current, const char *root UNUSED)
{
int rc;
- int pos;
+ int pos = 0;
const char *devpart = current;
debug("entry");
diff --git a/src/linux-virtblk.c b/src/linux-virtblk.c
index 2e9889def2f..fe6eb873a37 100644
--- a/src/linux-virtblk.c
+++ b/src/linux-virtblk.c
@@ -48,7 +48,7 @@ static ssize_t
parse_virtblk(struct device *dev, const char *current, const char *root UNUSED)
{
uint32_t tosser;
- int pos;
+ int pos = 0;
int rc;
debug("entry");
--
2.26.2

View File

@ -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/39] 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

View File

@ -0,0 +1,126 @@
From fbda040f70143b207ef8d0daae509d6c15ffca95 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Tue, 28 May 2019 16:08:25 -0400
Subject: [PATCH 18/63] Add efi_get_libefivar_version() and
efi_get_libefiboot_version()
Signed-off-by: Peter Jones <pjones@redhat.com>
---
Make.defaults | 2 +-
src/Android.mk | 4 +++-
src/creator.c | 6 ++++++
src/include/efivar/efiboot.h | 3 +++
src/include/efivar/efivar.h | 3 +++
src/lib.c | 6 ++++++
src/libefiboot.map.in | 4 ++++
src/libefivar.map.in | 1 +
8 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/Make.defaults b/Make.defaults
index 57cee6e82b5..6c575846687 100644
--- a/Make.defaults
+++ b/Make.defaults
@@ -18,7 +18,7 @@ CCLD_FOR_BUILD ?= $(CC_FOR_BUILD)
CCLD := $(if $(filter undefined,$(origin CCLD)),$(CC),$(CCLD))
OPTIMIZE ?= -O2 -flto
CFLAGS ?= $(OPTIMIZE) -g3
-CFLAGS := $(CFLAGS)
+CFLAGS := $(CFLAGS) -DLIBEFIVAR_VERSION=$(VERSION)
LDFLAGS ?=
LDFLAGS := $(LDFLAGS)
AR := $(CROSS_COMPILE)$(COMPILER)-ar
diff --git a/src/Android.mk b/src/Android.mk
index b3410e1f3e7..bf6cfb2e91b 100644
--- a/src/Android.mk
+++ b/src/Android.mk
@@ -46,8 +46,10 @@ LIBEFIVAR_SOURCES := \
lib.c \
vars.c
+include $(LOCAL_PATH)/../Make.version
+
LOCAL_SRC_FILES := $(LIBEFIBOOT_SOURCES) $(LIBEFIVAR_SOURCES)
-LOCAL_CFLAGS := -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -std=gnu11
+LOCAL_CFLAGS := -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -std=gnu11 -DLIBEFIVAR_VERSION=$(VERSION)
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
diff --git a/src/creator.c b/src/creator.c
index 987fa033e5b..f4bb01bc4a6 100644
--- a/src/creator.c
+++ b/src/creator.c
@@ -511,3 +511,9 @@ efi_generate_ipv4_device_path(uint8_t *buf, ssize_t size,
return off;
}
+
+uint32_t PUBLIC
+efi_get_libefiboot_version(void)
+{
+ return LIBEFIVAR_VERSION;
+}
diff --git a/src/include/efivar/efiboot.h b/src/include/efivar/efiboot.h
index c2af55fbf45..2aee86d661e 100644
--- a/src/include/efivar/efiboot.h
+++ b/src/include/efivar/efiboot.h
@@ -35,4 +35,7 @@
#include <efivar/efiboot-creator.h>
#include <efivar/efiboot-loadopt.h>
+extern uint32_t efi_get_libefiboot_version(void)
+ __attribute__((__visibility__("default")));
+
#endif /* EFIBOOT_H */
diff --git a/src/include/efivar/efivar.h b/src/include/efivar/efivar.h
index 343d1c557da..ff95cb10791 100644
--- a/src/include/efivar/efivar.h
+++ b/src/include/efivar/efivar.h
@@ -249,6 +249,9 @@ extern int efi_get_verbose(void)
extern FILE * efi_get_logfile(void)
__attribute__((__visibility__("default")));
+extern uint32_t efi_get_libefivar_version(void)
+ __attribute__((__visibility__("default")));
+
#include <efivar/efivar-dp.h>
#endif /* EFIVAR_H */
diff --git a/src/lib.c b/src/lib.c
index dc06fdb3c15..457a8604d5d 100644
--- a/src/lib.c
+++ b/src/lib.c
@@ -265,3 +265,9 @@ libefivar_init(void)
}
}
}
+
+uint32_t PUBLIC
+efi_get_libefivar_version(void)
+{
+ return LIBEFIVAR_VERSION;
+}
diff --git a/src/libefiboot.map.in b/src/libefiboot.map.in
index cb19d65d0e4..0771eac5639 100644
--- a/src/libefiboot.map.in
+++ b/src/libefiboot.map.in
@@ -33,3 +33,7 @@ LIBEFIBOOT_1.29 {
LIBEFIBOOT_1.30 {
} LIBEFIBOOT_1.29;
+
+LIBEFIBOOT_1.31 {
+ global: efi_get_libefiboot_version;
+} LIBEFIBOOT_1.30;
diff --git a/src/libefivar.map.in b/src/libefivar.map.in
index 8965b729917..33196fefc64 100644
--- a/src/libefivar.map.in
+++ b/src/libefivar.map.in
@@ -134,4 +134,5 @@ LIBEFIVAR_1.37 {
LIBEFIVAR_1.38 {
global: efi_error_pop;
efi_stash_loglevel_;
+ efi_get_libefivar_version;
} LIBEFIVAR_1.37;
--
2.26.2

View File

@ -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/39] 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

View File

@ -0,0 +1,32 @@
From b90e0e1722ce442aec747e8d2b77dec4c05d6069 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Wed, 29 May 2019 09:28:50 -0400
Subject: [PATCH 19/63] Fix dbglog_seek() to update the offset.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/error.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/src/error.c b/src/error.c
index 5dc43197c50..5eaee84599a 100644
--- a/src/error.c
+++ b/src/error.c
@@ -194,7 +194,13 @@ static int
dbglog_seek(void *cookie UNUSED, off64_t *offset, int whence)
{
FILE *log = efi_errlog ? efi_errlog : stderr;
- return fseek(log, *offset, whence);
+ int rc;
+
+ rc = fseek(log, *offset, whence);
+ if (rc < 0)
+ return rc;
+ *offset = ftell(log);
+ return 0;
}
static int
--
2.26.2

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -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/39] 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

View File

@ -0,0 +1,70 @@
From 9985cbbf4073ce9d0beec66bf702db9123758852 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Wed, 29 May 2019 10:11:24 -0400
Subject: [PATCH 21/63] Fix up efi_guid_cmp()'s alignment problem a different
way
With the prior fix for efi_guid_cmp()'s alignment issue, abicheck shows:
1 function with some indirect sub-type change:
[C]'function int efi_guid_cmp(void* const, void* const)' at <built-in>:34:1 has some indirect sub-type changes:
parameter 1 of type 'void* const' changed:
entity changed from 'void* const' to 'const efi_guid_t*'
type size hasn't changed
parameter 2 of type 'void* const' changed:
entity changed from 'void* const' to 'const efi_guid_t*'
type size hasn't changed
While this isn't a meaningful ABI difference in terms of linking, it is
definitely worse than having the type actually specified.
This patch changes the type back to the previous type, but also changes
the typedef to require a 1-byte alignment. This will guarantee that all
new builds of efi_guid_cmp() and related code have code generated in a
way that's compatible with any alignment, thus alleviating the issue.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/guid.c | 2 +-
src/include/efivar/efivar.h | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/guid.c b/src/guid.c
index 3156b3b7c60..306c9ff8287 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 void * const a, const void * const b)
+efi_guid_cmp(const efi_guid_t *a, const efi_guid_t *b)
{
return memcmp(a, b, sizeof (efi_guid_t));
}
diff --git a/src/include/efivar/efivar.h b/src/include/efivar/efivar.h
index ff95cb10791..11d9a9d7b78 100644
--- a/src/include/efivar/efivar.h
+++ b/src/include/efivar/efivar.h
@@ -37,7 +37,7 @@ typedef struct {
uint16_t c;
uint16_t d;
uint8_t e[6];
-} efi_guid_t;
+} efi_guid_t __attribute__((__aligned__(1)));
typedef struct {
uint8_t addr[4];
@@ -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 void * const a, const void * const b);
+extern int efi_guid_cmp(const efi_guid_t *a, const efi_guid_t *b);
/* import / export functions */
typedef struct efi_variable efi_variable_t;
--
2.26.2

View File

@ -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/39] 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

View File

@ -0,0 +1,27 @@
From b132f9ef8b39ae31870be685566217191f8cde6a Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Wed, 29 May 2019 10:18:56 -0400
Subject: [PATCH 22/63] Fix dbglog_write() to always return the status of
write()
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/error.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/error.c b/src/error.c
index 5eaee84599a..a77b0df1feb 100644
--- a/src/error.c
+++ b/src/error.c
@@ -185,7 +185,7 @@ dbglog_write(void *cookie UNUSED, const char *buf, size_t size)
ret = fwrite(buf, 1, size, log);
} else if (efi_dbglog_fd >= 0) {
lseek(efi_dbglog_fd, 0, SEEK_SET);
- write(efi_dbglog_fd, buf, size);
+ ret = write(efi_dbglog_fd, buf, size);
}
return ret;
}
--
2.26.2

View File

@ -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/39] 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

View File

@ -0,0 +1,36 @@
From a4212e47ff20b415e042682944a82623b3f75cee Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Wed, 29 May 2019 10:21:32 -0400
Subject: [PATCH 23/63] Do a better job of making sure -DLIBEFIVAR_VERSION
happens...
Signed-off-by: Peter Jones <pjones@redhat.com>
---
Make.defaults | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/Make.defaults b/Make.defaults
index 6c575846687..80fd99eba71 100644
--- a/Make.defaults
+++ b/Make.defaults
@@ -18,7 +18,7 @@ CCLD_FOR_BUILD ?= $(CC_FOR_BUILD)
CCLD := $(if $(filter undefined,$(origin CCLD)),$(CC),$(CCLD))
OPTIMIZE ?= -O2 -flto
CFLAGS ?= $(OPTIMIZE) -g3
-CFLAGS := $(CFLAGS) -DLIBEFIVAR_VERSION=$(VERSION)
+CFLAGS := $(CFLAGS)
LDFLAGS ?=
LDFLAGS := $(LDFLAGS)
AR := $(CROSS_COMPILE)$(COMPILER)-ar
@@ -29,6 +29,8 @@ ABIDIFF := abidiff
PKGS =
+CPPFLAGS += -DLIBEFIVAR_VERSION=$(VERSION)
+
clang_cflags = -D_GNU_SOURCE -std=gnu11 -Wno-address-of-packed-member
gcc_cflags = -specs=$(TOPDIR)/gcc.specs
cflags = $(CFLAGS) -I${TOPDIR}/src/include/ \
--
2.26.2

View File

@ -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/39] 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

View File

@ -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/39] 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

View File

@ -0,0 +1,102 @@
From 118d9afe4febf0ec6dea9327b044979588be2a60 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Wed, 29 May 2019 10:28:41 -0400
Subject: [PATCH 24/63] efi_stash_loglevel_() -> efi_set_loglevel()
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/error.c | 8 ++++----
src/include/efivar/efivar.h | 4 ++--
src/libefivar.map.in | 2 +-
src/util.h | 4 ++--
4 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/src/error.c b/src/error.c
index a77b0df1feb..083de15e984 100644
--- a/src/error.c
+++ b/src/error.c
@@ -166,13 +166,13 @@ efi_error_pop(void)
static int efi_verbose;
static FILE *efi_errlog, *efi_dbglog;
static int efi_dbglog_fd = -1;
-static int stashed_log_level;
+static int log_level;
static char efi_dbglog_buf[4096];
void PUBLIC
-efi_stash_loglevel_(int level)
+efi_set_loglevel(int level)
{
- stashed_log_level = level;
+ log_level = level;
}
static ssize_t
@@ -181,7 +181,7 @@ dbglog_write(void *cookie UNUSED, const char *buf, size_t size)
FILE *log = efi_errlog ? efi_errlog : stderr;
ssize_t ret = size;
- if (efi_get_verbose() >= stashed_log_level) {
+ if (efi_get_verbose() >= log_level) {
ret = fwrite(buf, 1, size, log);
} else if (efi_dbglog_fd >= 0) {
lseek(efi_dbglog_fd, 0, SEEK_SET);
diff --git a/src/include/efivar/efivar.h b/src/include/efivar/efivar.h
index 11d9a9d7b78..2fdf5b93b29 100644
--- a/src/include/efivar/efivar.h
+++ b/src/include/efivar/efivar.h
@@ -188,7 +188,7 @@ extern int efi_error_set(const char *filename,
__attribute__((__format__ (printf, 5, 6)));
extern void efi_error_clear(void);
extern void efi_error_pop(void);
-extern void efi_stash_loglevel_(int level);
+extern void efi_set_loglevel(int level);
#else
static inline int
__attribute__((__nonnull__ (2, 3, 4, 5, 6)))
@@ -228,7 +228,7 @@ efi_error_pop(void)
}
static inline void
-efi_stash_loglevel_(int level __attribute__((__unused__)))
+efi_set_loglevel(int level __attribute__((__unused__)))
{
return;
}
diff --git a/src/libefivar.map.in b/src/libefivar.map.in
index 33196fefc64..682e622c302 100644
--- a/src/libefivar.map.in
+++ b/src/libefivar.map.in
@@ -133,6 +133,6 @@ LIBEFIVAR_1.37 {
LIBEFIVAR_1.38 {
global: efi_error_pop;
- efi_stash_loglevel_;
+ efi_set_loglevel;
efi_get_libefivar_version;
} LIBEFIVAR_1.37;
diff --git a/src/util.h b/src/util.h
index 337762c9902..ec1c5f1a69a 100644
--- a/src/util.h
+++ b/src/util.h
@@ -382,7 +382,7 @@ swizzle_guid_to_uuid(efi_guid_t *guid)
#define log_(file, line, func, level, fmt, args...) \
({ \
- efi_stash_loglevel_(level); \
+ efi_set_loglevel(level); \
FILE *logfile_ = efi_get_logfile(); \
int len_ = strlen(fmt); \
fprintf(logfile_, "%s:%d %s(): ", \
@@ -401,7 +401,7 @@ swizzle_guid_to_uuid(efi_guid_t *guid)
#define debug(fmt, args...) log(LOG_DEBUG, fmt, ## args)
#define log_hex_(file, line, func, level, buf, size) \
({ \
- efi_stash_loglevel_(level); \
+ efi_set_loglevel(level); \
fhexdumpf(efi_get_logfile(), "%s:%d %s(): ", \
(uint8_t *)buf, size, \
file, line, func); \
--
2.26.2

View File

@ -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/39] 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

View File

@ -0,0 +1,38 @@
From 03041ba898eef2b73e2d9b336094869cd14e307e Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Mon, 17 Jun 2019 13:59:29 -0400
Subject: [PATCH 25/63] guids: add 'grub' guid for grubenv.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/guids.txt | 1 +
src/libefivar.map.in | 3 +++
2 files changed, 4 insertions(+)
diff --git a/src/guids.txt b/src/guids.txt
index 0d48ddbad30..2486255b26c 100644
--- a/src/guids.txt
+++ b/src/guids.txt
@@ -21,6 +21,7 @@
826ca512-cf10-4ac9-b187-be01496631bd sha1 SHA-1
82988420-7467-4490-9059-feb448dd1963 lenovo_me_config Lenovo ME Configuration Menu
8be4df61-93ca-11d2-aa0d-00e098032b8c global EFI Global Variable
+91376aff-cba6-42be-949d-06fde81128e8 grub GRUB
a5c059a1-94e4-4aa7-87b5-ab155c2bf072 x509_cert X.509 Certificate
a7717414-c616-4977-9420-844712a735bf rsa2048_sha256_cert RSA 2048 with SHA-256 Certificate
a7d8d9a6-6ab0-4aeb-ad9d-163e59a7a380 lenovo_diag_splash Lenovo Diagnostic Splash Screen
diff --git a/src/libefivar.map.in b/src/libefivar.map.in
index 682e622c302..54bfb765998 100644
--- a/src/libefivar.map.in
+++ b/src/libefivar.map.in
@@ -135,4 +135,7 @@ LIBEFIVAR_1.38 {
global: efi_error_pop;
efi_set_loglevel;
efi_get_libefivar_version;
+ efi_guid_grub;
+ efi_variable_alloc;
+ efi_variable_export_dmpstore;
} LIBEFIVAR_1.37;
--
2.26.2

View File

@ -0,0 +1,30 @@
From a2ea4f82a036756978e54f6f604f65aa81869051 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Mon, 17 Jun 2019 14:00:05 -0400
Subject: [PATCH 26/63] gcc.specs: add -grecord-gcc-switches
Signed-off-by: Peter Jones <pjones@redhat.com>
---
gcc.specs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/gcc.specs b/gcc.specs
index 45d43d11294..d06a8e096fc 100644
--- a/gcc.specs
+++ b/gcc.specs
@@ -8,10 +8,10 @@
+ %(efivar_cpp_options)
*cc1_options:
-+ %(efivar_cpp_options) -Wmaybe-uninitialized -fno-merge-constants -fvisibility=hidden %{!r:%{!fpie:%{!fPIE:%{!fpic:%{!fPIC:%{!fno-pic:-fPIE}}}}}}
++ %(efivar_cpp_options) -Wmaybe-uninitialized -fno-merge-constants -fvisibility=hidden %{!r:%{!fpie:%{!fPIE:%{!fpic:%{!fPIC:%{!fno-pic:-fPIE}}}}}} -grecord-gcc-switches
*self_spec:
-+ %{!shared:%{!static:%{!r:-pie}}} %{static:-Wl,-no-fatal-warnings -Wl,-static -static -Wl,-z,relro,-z,now}
++ %{!shared:%{!static:%{!r:-pie}}} %{static:-Wl,-no-fatal-warnings -Wl,-static -static -Wl,-z,relro,-z,now} -grecord-gcc-switches
*link:
+ %{!static:--fatal-warnings} --no-undefined-version --no-allow-shlib-undefined --add-needed -z now --build-id %{!static:%{!shared:-pie}} %{shared:-z relro} %{static:%<pie}
--
2.26.2

View File

@ -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/39] 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

View File

@ -0,0 +1,26 @@
From 24226715b44c2e53a211112092638962123e25d7 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Tue, 18 Jun 2019 10:05:11 -0400
Subject: [PATCH 27/63] Makefile: don't echo our deps submake invocation
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Makefile b/src/Makefile
index 76bc4748eb1..ecbbc02e1f7 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -84,7 +84,7 @@ libefiboot.so : LIBS=efivar
libefiboot.so : MAP=libefiboot.map
deps : $(ALL_SOURCES)
- $(MAKE) -f $(SRCDIR)/Make.deps deps SOURCES="$(ALL_SOURCES)"
+ @$(MAKE) -f $(SRCDIR)/Make.deps deps SOURCES="$(ALL_SOURCES)"
clean :
@rm -rfv *~ *.o *.a *.E *.so *.so.* *.pc *.bin .*.d *.map \
--
2.26.2

View File

@ -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/39] 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

View File

@ -0,0 +1,26 @@
From 7cfb9bd539ced0fd6fe35e7c08326bc3011d059b Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Tue, 18 Jun 2019 11:06:09 -0400
Subject: [PATCH 28/63] Make: Add some more stuff to the toplevel 'clean'
Signed-off-by: Peter Jones <pjones@redhat.com>
---
Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
index 8c67b9d2654..9c2620cb485 100644
--- a/Makefile
+++ b/Makefile
@@ -49,7 +49,7 @@ clean :
@set -e ; for x in $(SUBDIRS) ; do \
$(MAKE) -C $$x $@ ; \
done
- @rm -vf efivar.spec
+ @rm -vf efivar.spec vgcore.* core.*
test-archive: abicheck efivar.spec
@rm -rf /tmp/efivar-$(GITTAG) /tmp/efivar-$(GITTAG)-tmp
--
2.26.2

View File

@ -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/39] 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

View File

@ -0,0 +1,31 @@
From 20928bf97924328d41010aecdbf925c37f633739 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Wed, 19 Jun 2019 11:35:28 -0400
Subject: [PATCH 29/63] Make scan build rules slightly more intuitive.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
Make.scan-build | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/Make.scan-build b/Make.scan-build
index 7d684f7539f..f508e30be16 100644
--- a/Make.scan-build
+++ b/Make.scan-build
@@ -12,10 +12,9 @@ scan-build : | scan-test
scan-build : clean
scan-build -o scan-results make $(DASHJ) CC=clang all
-scan-build-all : | scan-test
-scan-build-all : clean
- scan-build -o scan-results make $(DASHJ) CC=clang all
+scan-build-all: | scan-build
+scan : | scan-build
-.PHONY : scan-build scan-clean
+.PHONY : scan-build scan-clean scan-build-all scan
# vim:ft=make
--
2.26.2

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -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/39] 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

View File

@ -0,0 +1,97 @@
From ce7434210d92f0eca1f8e90b82ff4078202c2da9 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Mon, 17 Jun 2019 14:27:08 -0400
Subject: [PATCH 31/63] Exported header whitespace cleanup.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/include/efivar/efiboot-creator.h | 2 ++
src/include/efivar/efiboot-loadopt.h | 2 ++
src/include/efivar/efiboot.h | 4 +++-
src/include/efivar/efivar-dp.h | 8 +++++---
src/include/efivar/efivar.h | 8 ++++----
5 files changed, 16 insertions(+), 8 deletions(-)
diff --git a/src/include/efivar/efiboot-creator.h b/src/include/efivar/efiboot-creator.h
index b56e836d2e5..b6e094c637c 100644
--- a/src/include/efivar/efiboot-creator.h
+++ b/src/include/efivar/efiboot-creator.h
@@ -58,3 +58,5 @@ extern ssize_t efi_generate_ipv4_device_path(uint8_t *buf, ssize_t size,
__attribute__((__visibility__ ("default")));
#endif /* _EFIBOOT_CREATOR_H */
+
+// vim:fenc=utf-8:tw=75:noet
diff --git a/src/include/efivar/efiboot-loadopt.h b/src/include/efivar/efiboot-loadopt.h
index efc29c69d47..97b7892f4b8 100644
--- a/src/include/efivar/efiboot-loadopt.h
+++ b/src/include/efivar/efiboot-loadopt.h
@@ -74,3 +74,5 @@ extern int efi_loadopt_is_valid(efi_load_option *opt, size_t size)
__attribute__((__visibility__ ("default")));
#endif /* _EFIBOOT_LOADOPT_H */
+
+// vim:fenc=utf-8:tw=75:noet
diff --git a/src/include/efivar/efiboot.h b/src/include/efivar/efiboot.h
index 2aee86d661e..8ae51ffa2a7 100644
--- a/src/include/efivar/efiboot.h
+++ b/src/include/efivar/efiboot.h
@@ -36,6 +36,8 @@
#include <efivar/efiboot-loadopt.h>
extern uint32_t efi_get_libefiboot_version(void)
- __attribute__((__visibility__("default")));
+ __attribute__((__visibility__("default")));
#endif /* EFIBOOT_H */
+
+// vim:fenc=utf-8:tw=75:noet
diff --git a/src/include/efivar/efivar-dp.h b/src/include/efivar/efivar-dp.h
index eab04f2dfac..57453548701 100644
--- a/src/include/efivar/efivar-dp.h
+++ b/src/include/efivar/efivar-dp.h
@@ -135,9 +135,9 @@ typedef struct {
} EFIVAR_PACKED efidp_acpi_hid_ex;
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,
- const char *cidstr);
+ uint32_t hid, uint32_t uid, uint32_t cid,
+ const char *hidstr, const char *uidstr,
+ const char *cidstr);
#define EFIDP_PNP_EISA_ID_CONST 0x41d0
#define EFIDP_PNP_ACPI_ID_CONST 0x8e09
@@ -1257,3 +1257,5 @@ extern ssize_t efidp_make_generic(uint8_t *buf, ssize_t size, uint8_t type,
EFIDP_END_INSTANCE, sizeof (efidp_header));
#endif /* _EFIVAR_DP_H */
+
+// vim:fenc=utf-8:tw=75:noet
diff --git a/src/include/efivar/efivar.h b/src/include/efivar/efivar.h
index 2fdf5b93b29..caa4adf056c 100644
--- a/src/include/efivar/efivar.h
+++ b/src/include/efivar/efivar.h
@@ -243,14 +243,14 @@ efi_set_loglevel(int level __attribute__((__unused__)))
efi_error_real__(errval, __FILE__, __func__, __LINE__, (fmt), ## args)
extern void efi_set_verbose(int verbosity, FILE *errlog)
- __attribute__((__visibility__("default")));
+ __attribute__((__visibility__("default")));
extern int efi_get_verbose(void)
- __attribute__((__visibility__("default")));
+ __attribute__((__visibility__("default")));
extern FILE * efi_get_logfile(void)
- __attribute__((__visibility__("default")));
+ __attribute__((__visibility__("default")));
extern uint32_t efi_get_libefivar_version(void)
- __attribute__((__visibility__("default")));
+ __attribute__((__visibility__("default")));
#include <efivar/efivar-dp.h>
--
2.26.2

View File

@ -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/39] 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

View File

@ -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/39] 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

File diff suppressed because it is too large Load Diff

View File

@ -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/39] 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

View File

@ -0,0 +1,142 @@
From 5f0b2b3460dfa826d75b95450bdc2903fa59e32e Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Mon, 17 Jun 2019 14:45:39 -0400
Subject: [PATCH 33/63] efivar: rework usage()
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/efivar.c | 74 ++++++++++++++++++++++++++++------------------------
1 file changed, 40 insertions(+), 34 deletions(-)
diff --git a/src/efivar.c b/src/efivar.c
index df075809db5..7f16ab15bab 100644
--- a/src/efivar.c
+++ b/src/efivar.c
@@ -39,10 +39,11 @@ extern int optind, opterr, optopt;
#include "efivar.h"
-#define ACTION_LIST 0x1
-#define ACTION_PRINT 0x2
-#define ACTION_APPEND 0x4
-#define ACTION_LIST_GUIDS 0x8
+#define ACTION_USAGE 0x00
+#define ACTION_LIST 0x01
+#define ACTION_PRINT 0x02
+#define ACTION_APPEND 0x04
+#define ACTION_LIST_GUIDS 0x08
#define ACTION_WRITE 0x10
#define ACTION_PRINT_DEC 0x20
@@ -326,7 +327,7 @@ validate_name(const char *name)
}
static void
-prepare_data(const char *filename, void **data, size_t *data_size)
+prepare_data(const char *filename, uint8_t **data, size_t *data_size)
{
int fd = -1;
void *buf;
@@ -365,25 +366,29 @@ err:
exit(1);
}
-static void
-usage(const char *progname)
+static void __attribute__((__noreturn__))
+usage(int ret)
{
- printf("Usage: %s [OPTION...]\n", basename(progname));
- printf(" -l, --list list current variables\n");
- printf(" -p, --print print variable specified by --name\n");
- printf(" -d, --print-decimal print variable in decimal values specified\n");
- printf(" by --name\n");
- printf(" -n, --name=<guid-name> variable to manipulate, in the form\n");
- printf(" 8be4df61-93ca-11d2-aa0d-00e098032b8c-Boot0000\n");
- printf(" -a, --append append to variable specified by --name\n");
- printf(" -f, --fromfile=<file> use data from <file>\n");
- printf(" -t, --attributes=<attributes> attributes to use on append\n");
- printf(" -L, --list-guids show internal guid list\n");
- printf(" -w, --write write to variable specified by --name\n\n");
- printf("Help options:\n");
- printf(" -?, --help Show this help message\n");
- printf(" --usage Display brief usage message\n");
- return;
+ FILE *out = ret == 0 ? stdout : stderr;
+ fprintf(out,
+ "Usage: %s [OPTION...]\n"
+ " -l, --list list current variables\n"
+ " -p, --print print variable specified by --name\n"
+ " -d, --print-decimal print variable in decimal values specified\n"
+ " by --name\n"
+ " -n, --name=<guid-name> variable to manipulate, in the form\n"
+ " 8be4df61-93ca-11d2-aa0d-00e098032b8c-Boot0000\n"
+ " -a, --append append to variable specified by --name\n"
+ " -e, --export=<file> export variable to <file>\n"
+ " -f, --fromfile=<file> use data from <file>\n"
+ " -t, --attributes=<attributes> attributes to use on append\n"
+ " -L, --list-guids show internal guid list\n"
+ " -w, --write write to variable specified by --name\n\n"
+ "Help options:\n"
+ " -?, --help Show this help message\n"
+ " --usage Display brief usage message\n",
+ program_invocation_short_name);
+ exit(ret);
}
int main(int argc, char *argv[])
@@ -391,7 +396,7 @@ int main(int argc, char *argv[])
int c = 0;
int i = 0;
int action = 0;
- void *data = NULL;
+ uint8_t *data = NULL;
size_t data_size = 0;
char *name = NULL;
char *file = NULL;
@@ -434,10 +439,10 @@ int main(int argc, char *argv[])
break;
case 't':
attributes = strtoul(optarg, NULL, 10);
- if (errno == ERANGE || errno == EINVAL) {
- fprintf(stderr, "invalid argument for -t: %s: %s\n", optarg, strerror(errno));
- return EXIT_FAILURE;
- }
+ if (errno == ERANGE || errno == EINVAL)
+ err(1,
+ "invalid argument for -t: %s: %m\n",
+ optarg);
break;
case 'L':
action |= ACTION_LIST_GUIDS;
@@ -446,13 +451,11 @@ int main(int argc, char *argv[])
action |= ACTION_WRITE;
break;
case '?':
- usage(argv[0]);
- return EXIT_SUCCESS;
+ usage(EXIT_SUCCESS);
+ break;
case 0:
- if (strcmp(lopts[i].name, "usage")) {
- usage(argv[0]);
- return EXIT_SUCCESS;
- }
+ if (strcmp(lopts[i].name, "usage"))
+ usage(EXIT_SUCCESS);
break;
}
}
@@ -506,6 +509,9 @@ int main(int argc, char *argv[])
guid[i].symbol + strlen("efi_guid_"),
guid[i].symbol, guid[i].name);
}
+ case ACTION_USAGE:
+ default:
+ usage(EXIT_FAILURE);
}
};
--
2.26.2

View File

@ -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/39] 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

View File

@ -0,0 +1,431 @@
From 70e86dc3e48345f1a961aef6173d5126edebf90a Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Mon, 17 Jun 2019 14:47:24 -0400
Subject: [PATCH 34/63] Try to deal with some signof(char) != signof(uint8_t)
madness.
The 3-sign "char" type in C is so so painful sometimes. This attempts
to use -funsigned-char to avoid type-casting between (uint8_t *) and
(char *) quite so much. I'm not sure it'll pay off. The fact that
"char" is something that's not ever actually the same type as "unsigned
char" or "signed char" is still the absolute worst thing.
Why do we need signed char at all again?
Signed-off-by: Peter Jones <pjones@redhat.com>
---
Make.defaults | 4 +++-
gcc.specs | 4 ++--
src/dp-acpi.c | 11 ++++++-----
src/dp-hw.c | 5 +++--
src/dp-media.c | 2 +-
src/dp-message.c | 22 +++++++++++-----------
src/dp.c | 8 +++++---
src/dp.h | 18 ++++++++++--------
src/export.c | 12 ++++++------
src/include/efivar/efivar-dp.h | 10 ++++++----
src/include/efivar/efivar.h | 4 ++--
src/ucs2.h | 6 +++---
12 files changed, 58 insertions(+), 48 deletions(-)
diff --git a/Make.defaults b/Make.defaults
index 80fd99eba71..36e922f5ba7 100644
--- a/Make.defaults
+++ b/Make.defaults
@@ -31,7 +31,9 @@ PKGS =
CPPFLAGS += -DLIBEFIVAR_VERSION=$(VERSION)
-clang_cflags = -D_GNU_SOURCE -std=gnu11 -Wno-address-of-packed-member
+clang_cflags = -D_GNU_SOURCE -std=gnu11 -Wno-address-of-packed-member \
+ -funsigned-char -Wall -Wno-nonnull-compare \
+ -Werror -Wno-error=cpp
gcc_cflags = -specs=$(TOPDIR)/gcc.specs
cflags = $(CFLAGS) -I${TOPDIR}/src/include/ \
$(if $(findstring clang,$(CC)),$(clang_cflags),) \
diff --git a/gcc.specs b/gcc.specs
index d06a8e096fc..9d2b145ee6e 100644
--- a/gcc.specs
+++ b/gcc.specs
@@ -2,13 +2,13 @@
+ -D_GNU_SOURCE
*efivar_cpp_options:
- -Werror -Wall -std=gnu11 -Wextra
+ -Wall -Wno-nonnull-compare -Werror -Wno-error=cpp -std=gnu11 -Wextra -funsigned-char
*cpp_options:
+ %(efivar_cpp_options)
*cc1_options:
-+ %(efivar_cpp_options) -Wmaybe-uninitialized -fno-merge-constants -fvisibility=hidden %{!r:%{!fpie:%{!fPIE:%{!fpic:%{!fPIC:%{!fno-pic:-fPIE}}}}}} -grecord-gcc-switches
++ %(efivar_cpp_options) -Wmaybe-uninitialized -fno-merge-constants -funsigned-char -fvisibility=hidden %{!r:%{!fpie:%{!fPIE:%{!fpic:%{!fPIC:%{!fno-pic:-fPIE}}}}}} -grecord-gcc-switches
*self_spec:
+ %{!shared:%{!static:%{!r:-pie}}} %{static:-Wl,-no-fatal-warnings -Wl,-static -static -Wl,-z,relro,-z,now} -grecord-gcc-switches
diff --git a/src/dp-acpi.c b/src/dp-acpi.c
index 2525fdfd073..02ec70eec7a 100644
--- a/src/dp-acpi.c
+++ b/src/dp-acpi.c
@@ -28,7 +28,7 @@
#include "efivar.h"
static ssize_t
-_format_acpi_adr(char *buf, size_t size,
+_format_acpi_adr(unsigned char *buf, size_t size,
const char *dp_type UNUSED,
const_efidp dp)
{
@@ -45,9 +45,10 @@ _format_acpi_adr(char *buf, size_t size,
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)
+_format_acpi_hid_ex(unsigned 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;
@@ -98,7 +99,7 @@ _format_acpi_hid_ex(char *buf, size_t size, const char *dp_type UNUSED,
hidstr, cidstr, uidstr)
ssize_t
-_format_acpi_dn(char *buf, size_t size, const_efidp dp)
+_format_acpi_dn(unsigned char *buf, size_t size, const_efidp dp)
{
ssize_t off = 0;
const char *hidstr = NULL;
diff --git a/src/dp-hw.c b/src/dp-hw.c
index 1fe0f66e871..28998316d9d 100644
--- a/src/dp-hw.c
+++ b/src/dp-hw.c
@@ -26,7 +26,8 @@
#include "efivar.h"
ssize_t
-format_edd10_guid(char *buf, size_t size, const char *dp_type, const_efidp dp)
+format_edd10_guid(unsigned char *buf, size_t size,
+ const char *dp_type, const_efidp dp)
{
ssize_t off = 0;
efidp_edd10 const *edd_dp = (efidp_edd10 *)dp;
@@ -36,7 +37,7 @@ format_edd10_guid(char *buf, size_t size, const char *dp_type, const_efidp dp)
}
ssize_t
-_format_hw_dn(char *buf, size_t size, const_efidp dp)
+_format_hw_dn(unsigned char *buf, size_t size, const_efidp dp)
{
efi_guid_t edd10_guid = EDD10_HARDWARE_VENDOR_PATH_GUID;
ssize_t off = 0;
diff --git a/src/dp-media.c b/src/dp-media.c
index 4728c326100..7f5d1c678ce 100644
--- a/src/dp-media.c
+++ b/src/dp-media.c
@@ -28,7 +28,7 @@
#include "efivar.h"
ssize_t
-_format_media_dn(char *buf, size_t size, const_efidp dp)
+_format_media_dn(unsigned char *buf, size_t size, const_efidp dp)
{
ssize_t off = 0;
switch (dp->subtype) {
diff --git a/src/dp-message.c b/src/dp-message.c
index b88f17fb712..d00b2ad5d67 100644
--- a/src/dp-message.c
+++ b/src/dp-message.c
@@ -28,7 +28,7 @@
#include "efivar.h"
static ssize_t
-format_ipv4_addr_helper(char *buf, size_t size, const char *dp_type,
+format_ipv4_addr_helper(unsigned char *buf, size_t size, const char *dp_type,
const uint8_t *ipaddr, int32_t port)
{
ssize_t off = 0;
@@ -40,7 +40,7 @@ format_ipv4_addr_helper(char *buf, size_t size, const char *dp_type,
}
static ssize_t
-format_ipv6_addr_helper(char *buf, size_t size, const char *dp_type,
+format_ipv6_addr_helper(unsigned char *buf, size_t size, const char *dp_type,
const uint8_t *ipaddr, int32_t port)
{
uint16_t *ip = (uint16_t *)ipaddr;
@@ -123,7 +123,7 @@ format_ipv6_addr_helper(char *buf, size_t size, const char *dp_type,
"IPv6", addr, port)
static ssize_t
-format_ip_addr_helper(char *buf, size_t size,
+format_ip_addr_helper(unsigned char *buf, size_t size,
const char *dp_type UNUSED,
int is_ipv6, const efi_ip_addr_t *addr)
{
@@ -142,7 +142,7 @@ format_ip_addr_helper(char *buf, size_t size,
dp_type, is_ipv6, addr)
static ssize_t
-format_uart(char *buf, size_t size,
+format_uart(unsigned char *buf, size_t size,
const char *dp_type UNUSED,
const_efidp dp)
{
@@ -162,7 +162,7 @@ format_uart(char *buf, size_t size,
}
static ssize_t
-format_sas(char *buf, size_t size,
+format_sas(unsigned char *buf, size_t size,
const char *dp_type UNUSED,
const_efidp dp)
{
@@ -232,7 +232,7 @@ format_sas(char *buf, size_t size,
dp->usb_class.device_protocol)
static ssize_t
-format_usb_class(char *buf, size_t size,
+format_usb_class(unsigned char *buf, size_t size,
const char *dp_type UNUSED,
const_efidp dp)
{
@@ -312,7 +312,7 @@ format_usb_class(char *buf, size_t size,
}
ssize_t
-_format_message_dn(char *buf, size_t size, const_efidp dp)
+_format_message_dn(unsigned char *buf, size_t size, const_efidp dp)
{
ssize_t off = 0;
switch (dp->subtype) {
@@ -393,7 +393,7 @@ _format_message_dn(char *buf, size_t size, const_efidp dp)
struct {
efi_guid_t guid;
char label[40];
- ssize_t (*formatter)(char *buf, size_t size,
+ ssize_t (*formatter)(unsigned char *buf, size_t size,
const char *dp_type UNUSED,
const_efidp dp);
} subtypes[] = {
@@ -417,7 +417,7 @@ _format_message_dn(char *buf, size_t size, const_efidp dp)
.label = "" }
};
char *label = NULL;
- ssize_t (*formatter)(char *buf, size_t size,
+ ssize_t (*formatter)(unsigned char *buf, size_t size,
const char *dp_type UNUSED,
const_efidp dp) = NULL;
@@ -455,8 +455,8 @@ _format_message_dn(char *buf, size_t size, const_efidp dp)
}
case EFIDP_MSG_IPv6: {
efidp_ipv6_addr const *a = &dp->ipv6_addr;
- char *addr0 = NULL;
- char *addr1 = NULL;
+ unsigned char *addr0 = NULL;
+ unsigned char *addr1 = NULL;
ssize_t tmpoff = 0;
ssize_t sz;
diff --git a/src/dp.c b/src/dp.c
index b6eea74878c..f6a4b2ddafa 100644
--- a/src/dp.c
+++ b/src/dp.c
@@ -298,7 +298,8 @@ efidp_append_instance(const_efidp dp, const_efidp dpi, efidp *out)
}
ssize_t PUBLIC
-efidp_format_device_path(char *buf, size_t size, const_efidp dp, ssize_t limit)
+efidp_format_device_path(unsigned char *buf, size_t size, const_efidp dp,
+ ssize_t limit)
{
ssize_t off = 0;
int first = 1;
@@ -402,7 +403,8 @@ efidp_format_device_path(char *buf, size_t size, const_efidp dp, ssize_t limit)
}
ssize_t PUBLIC
-efidp_parse_device_node(char *path UNUSED, efidp out UNUSED, size_t size UNUSED)
+efidp_parse_device_node(unsigned char *path UNUSED,
+ efidp out UNUSED, size_t size UNUSED)
{
efi_error("not implented");
errno = -ENOSYS;
@@ -410,7 +412,7 @@ efidp_parse_device_node(char *path UNUSED, efidp out UNUSED, size_t size UNUSED)
}
ssize_t PUBLIC
-efidp_parse_device_path(char *path UNUSED, efidp out UNUSED,
+efidp_parse_device_path(unsigned char *path UNUSED, efidp out UNUSED,
size_t size UNUSED)
{
efi_error("not implented");
diff --git a/src/dp.h b/src/dp.h
index 33a29db0d5d..6609b0d827e 100644
--- a/src/dp.h
+++ b/src/dp.h
@@ -88,8 +88,9 @@
})
static inline ssize_t UNUSED
-format_hex_helper(char *buf, size_t size, const char *dp_type, char *separator,
- int stride, const void * const addr, const size_t len)
+format_hex_helper(unsigned char *buf, size_t size, const char *dp_type,
+ char *separator, int stride, const void * const addr,
+ const size_t len)
{
ssize_t off = 0;
for (size_t i = 0; i < len; i++) {
@@ -110,7 +111,8 @@ format_hex_helper(char *buf, size_t size, const char *dp_type, char *separator,
addr, len)
static inline ssize_t UNUSED
-format_vendor_helper(char *buf, size_t size, char *label, const_efidp dp)
+format_vendor_helper(unsigned char *buf, size_t size, char *label,
+ const_efidp dp)
{
ssize_t off = 0;
ssize_t bytes = efidp_node_size(dp)
@@ -157,11 +159,11 @@ format_vendor_helper(char *buf, size_t size, char *label, const_efidp dp)
off; \
})
-extern ssize_t _format_hw_dn(char *buf, size_t size, const_efidp dp);
-extern ssize_t _format_acpi_dn(char *buf, size_t size, const_efidp dp);
-extern ssize_t _format_message_dn(char *buf, size_t size, const_efidp dp);
-extern ssize_t _format_media_dn(char *buf, size_t size, const_efidp dp);
-extern ssize_t _format_bios_boot_dn(char *buf, size_t size, const_efidp dp);
+extern ssize_t _format_hw_dn(unsigned char *buf, size_t size, const_efidp dp);
+extern ssize_t _format_acpi_dn(unsigned char *buf, size_t size, const_efidp dp);
+extern ssize_t _format_message_dn(unsigned char *buf, size_t size, const_efidp dp);
+extern ssize_t _format_media_dn(unsigned char *buf, size_t size, const_efidp dp);
+extern ssize_t _format_bios_boot_dn(unsigned char *buf, size_t size, const_efidp dp);
#define format_helper_2(name, buf, size, off, dp) ({ \
ssize_t _sz; \
diff --git a/src/export.c b/src/export.c
index 5b11ae883cf..6b78412cce1 100644
--- a/src/export.c
+++ b/src/export.c
@@ -35,7 +35,7 @@
struct efi_variable {
uint64_t attrs;
efi_guid_t *guid;
- char *name;
+ unsigned char *name;
uint8_t *data;
size_t data_size;
};
@@ -149,7 +149,7 @@ efi_variable_import(uint8_t *data, size_t size, efi_variable_t **var_out)
ssize_t NONNULL(1) PUBLIC
efi_variable_export(efi_variable_t *var, uint8_t *data, size_t size)
{
- size_t name_len = strlen(var->name);
+ size_t name_len = strlen((char *)var->name);
size_t needed = sizeof (uint32_t) /* magic */
+ sizeof (uint32_t) /* version */
@@ -233,13 +233,13 @@ efi_variable_free(efi_variable_t *var, int free_data)
}
int NONNULL(1, 2) PUBLIC
-efi_variable_set_name(efi_variable_t *var, char *name)
+efi_variable_set_name(efi_variable_t *var, unsigned char *name)
{
var->name = name;
return 0;
}
-char PUBLIC NONNULL(1) *
+unsigned char PUBLIC NONNULL(1) *
efi_variable_get_name(efi_variable_t *var)
{
if (!var->name) {
@@ -329,10 +329,10 @@ efi_variable_realize(efi_variable_t *var)
}
uint32_t attrs = var->attrs & ATTRS_MASK;
if (attrs & EFI_VARIABLE_APPEND_WRITE) {
- return efi_append_variable(*var->guid, var->name,
+ return efi_append_variable(*var->guid, (char *)var->name,
var->data, var->data_size, attrs);
}
- return efi_set_variable(*var->guid, var->name, var->data,
+ return efi_set_variable(*var->guid, (char *)var->name, var->data,
var->data_size, attrs, 0600);
}
diff --git a/src/include/efivar/efivar-dp.h b/src/include/efivar/efivar-dp.h
index 57453548701..706d25bdebd 100644
--- a/src/include/efivar/efivar-dp.h
+++ b/src/include/efivar/efivar-dp.h
@@ -1240,10 +1240,12 @@ efidp_is_valid(const_efidp dp, ssize_t limit)
#endif
/* and now, printing and parsing */
-extern ssize_t efidp_parse_device_node(char *path, efidp out, size_t size);
-extern ssize_t efidp_parse_device_path(char *path, efidp out, size_t size);
-extern ssize_t efidp_format_device_path(char *buf, size_t size, const_efidp dp,
- ssize_t limit);
+extern ssize_t efidp_parse_device_node(unsigned char *path,
+ efidp out, size_t size);
+extern ssize_t efidp_parse_device_path(unsigned char *path,
+ efidp out, size_t size);
+extern ssize_t efidp_format_device_path(unsigned char *buf, size_t size,
+ const_efidp dp, ssize_t limit);
extern ssize_t efidp_make_vendor(uint8_t *buf, ssize_t size, uint8_t type,
uint8_t subtype, efi_guid_t vendor_guid,
void *data, size_t data_size);
diff --git a/src/include/efivar/efivar.h b/src/include/efivar/efivar.h
index caa4adf056c..729b6fe80f7 100644
--- a/src/include/efivar/efivar.h
+++ b/src/include/efivar/efivar.h
@@ -144,9 +144,9 @@ extern efi_variable_t *efi_variable_alloc(void)
__attribute__((__visibility__ ("default")));
extern void efi_variable_free(efi_variable_t *var, int free_data);
-extern int efi_variable_set_name(efi_variable_t *var, char *name)
+extern int efi_variable_set_name(efi_variable_t *var, unsigned char *name)
__attribute__((__nonnull__ (1, 2)));
-extern char *efi_variable_get_name(efi_variable_t *var)
+extern unsigned char *efi_variable_get_name(efi_variable_t *var)
__attribute__((__visibility__ ("default")))
__attribute__((__nonnull__ (1)));
diff --git a/src/ucs2.h b/src/ucs2.h
index 176f9ccac57..478de23b23f 100644
--- a/src/ucs2.h
+++ b/src/ucs2.h
@@ -47,7 +47,7 @@ ucs2size(const void *s, ssize_t limit)
}
static inline size_t UNUSED NONNULL(1)
-utf8len(uint8_t *s, ssize_t limit)
+utf8len(const unsigned char *s, ssize_t limit)
{
ssize_t i, j;
for (i = 0, j = 0; i < (limit >= 0 ? limit : i+1) && s[i] != '\0';
@@ -64,7 +64,7 @@ utf8len(uint8_t *s, ssize_t limit)
}
static inline size_t UNUSED NONNULL(1)
-utf8size(uint8_t *s, ssize_t limit)
+utf8size(const unsigned char *s, ssize_t limit)
{
size_t ret = utf8len(s,limit);
if (ret < (limit >= 0 ? (size_t)limit : ret+1))
@@ -129,7 +129,7 @@ ucs2_to_utf8(const void * const voidchars, ssize_t limit)
}
static inline ssize_t UNUSED NONNULL(4)
-utf8_to_ucs2(void *ucs2void, ssize_t size, int terminate, uint8_t *utf8)
+utf8_to_ucs2(void *ucs2void, ssize_t size, int terminate, const unsigned char *utf8)
{
ssize_t req;
ssize_t i, j;
--
2.26.2

View File

@ -1,79 +0,0 @@
From cff35642eac6699e30549db2db3341e7657bf4a6 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Tue, 18 Sep 2018 14:57:13 -0400
Subject: [PATCH 35/39] Fix partition number detection when it's not provided.
We need to actually get the partition number from the child device when
we're called without it.
Resolves: rhbz#1616305
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/creator.c | 43 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+)
diff --git a/src/creator.c b/src/creator.c
index ef782e2b647..987fa033e5b 100644
--- a/src/creator.c
+++ b/src/creator.c
@@ -350,6 +350,36 @@ efi_generate_file_device_path_from_esp(uint8_t *buf, ssize_t size,
return ret;
}
+static int
+get_part(char *devpath)
+{
+ int fd;
+ int partition = -1;
+ struct device *dev = NULL;
+
+ fd = open(devpath, O_RDONLY);
+ if (fd < 0) {
+ efi_error("could not open device for ESP");
+ goto err;
+ }
+
+ dev = device_get(fd, -1);
+ if (dev == NULL) {
+ efi_error("could not get ESP disk info");
+ goto err;
+ }
+
+ partition = dev->part;
+ if (partition < 0)
+ partition = 0;
+err:
+ if (dev)
+ device_free(dev);
+ if (fd >= 0)
+ close(fd);
+ return partition;
+}
+
ssize_t NONNULL(3) PUBLIC
efi_generate_file_device_path(uint8_t *buf, ssize_t size,
const char * const filepath,
@@ -374,6 +404,19 @@ efi_generate_file_device_path(uint8_t *buf, ssize_t size,
efi_error("could not find parent device for file");
goto err;
}
+ debug("child_devpath:%s", child_devpath);
+
+ debug("parent_devpath:%s", parent_devpath);
+ debug("child_devpath:%s", child_devpath);
+ debug("rc:%d", rc);
+
+ rc = get_part(child_devpath);
+ if (rc < 0) {
+ efi_error("Couldn't get partition number for %s",
+ child_devpath);
+ goto err;
+ }
+ debug("detected partition:%d", rc);
va_start(ap, options);
--
2.17.1

View File

@ -0,0 +1,219 @@
From ee7ba570f7c555f93f41badefb63397737ef7810 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Tue, 18 Jun 2019 13:12:39 -0400
Subject: [PATCH 35/63] ucs2: document things a little better
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/ucs2.h | 135 +++++++++++++++++++++++++++++++++++++++--------------
1 file changed, 100 insertions(+), 35 deletions(-)
diff --git a/src/ucs2.h b/src/ucs2.h
index 478de23b23f..3f8a41d8ccc 100644
--- a/src/ucs2.h
+++ b/src/ucs2.h
@@ -22,11 +22,20 @@
#define ev_bits(val, mask, shift) \
(((val) & ((mask) << (shift))) >> (shift))
+/*
+ * ucs2len(): Count the number of characters in a UCS-2 string.
+ * s: a UCS-2 string
+ * limit: the maximum number of uint16_t bytepairs to examine
+ *
+ * returns the number of characters before NUL is found (i.e., excluding
+ * the NUL character). If limit is non-negative, no character index above
+ * limit will be accessed, and the maximum return value is limit.
+ */
static inline size_t UNUSED
-ucs2len(const void *vs, ssize_t limit)
+ucs2len(const void *s, ssize_t limit)
{
ssize_t i;
- const uint8_t *s8 = vs;
+ const uint8_t *s8 = s;
for (i = 0;
i < (limit >= 0 ? limit : i+1) && !(s8[0] == 0 && s8[1] == 0);
@@ -35,6 +44,15 @@ ucs2len(const void *vs, ssize_t limit)
return i;
}
+/*
+ * ucs2size(): count the number of bytes in use by a UCS-2 string.
+ * s: a UCS-2 string
+ * limit: the maximum number of uint16_t bytepairs to examine
+ *
+ * returns the number of bytes, including NUL, in the UCS-2 string s. If
+ * limit is non-negative, no character index above limit will be accessed,
+ * and the maximum return value is limit.
+ */
static inline size_t UNUSED
ucs2size(const void *s, ssize_t limit)
{
@@ -46,6 +64,18 @@ ucs2size(const void *s, ssize_t limit)
return rc;
}
+/*
+ * utf8len(): Count the number of characters in a UTF-8 string.
+ * s: a UTF-8 string
+ * limit: the maximum number of bytes to examine
+ *
+ * returns the number of UTF-8 charters before NUL is found (i.e.,
+ * excluding the NUL character). If limit is non-negative, no character
+ * index above limit will be accessed, and the maximum return value is
+ * limit.
+ *
+ * Caveat: only good up to 3-byte sequences.
+ */
static inline size_t UNUSED NONNULL(1)
utf8len(const unsigned char *s, ssize_t limit)
{
@@ -63,6 +93,15 @@ utf8len(const unsigned char *s, ssize_t limit)
return j;
}
+/*
+ * utf8size(): count the number of bytes in use by a UTF-8 string.
+ * s: a UTF-8 string
+ * limit: the maximum number of bytes to examine
+ *
+ * returns the number of bytes, including NUL, in the UTF-8 string s.
+ * If limit is non-negative, no character index above limit will be
+ * accessed, and the maximum return value is limit.
+ */
static inline size_t UNUSED NONNULL(1)
utf8size(const unsigned char *s, ssize_t limit)
{
@@ -72,68 +111,94 @@ utf8size(const unsigned char *s, ssize_t limit)
return ret;
}
+/*
+ * ucs2_to_utf8(): convert UCS-2 to UTF-8
+ * s: the UCS-2 string
+ * limit: the maximum number of characters to copy from s, including the
+ * NUL terminator, or -1 for no limit.
+ *
+ * returns an allocated string, into which at most limit - 1 characters of
+ * UTF-8 are translated from UCS-2. The return value is *always*
+ * NUL-terminated.
+ */
static inline unsigned char * UNUSED
-ucs2_to_utf8(const void * const voidchars, ssize_t limit)
+ucs2_to_utf8(const void * const s, ssize_t limit)
{
ssize_t i, j;
- unsigned char *ret;
- const uint16_t * const chars = voidchars;
+ unsigned char *out, *ret;
+ const uint16_t * const chars = s;
if (limit < 0)
limit = ucs2len(chars, -1);
- ret = malloc(limit * 6 + 1);
- if (!ret)
+ out = malloc(limit * 6 + 1);
+ if (!out)
return NULL;
- memset(ret, 0, limit * 6 +1);
+ memset(out, 0, limit * 6 +1);
for (i=0, j=0; chars[i] && i < (limit >= 0 ? limit : i+1); i++,j++) {
if (chars[i] <= 0x7f) {
- ret[j] = chars[i];
+ out[j] = chars[i];
} else if (chars[i] > 0x7f && chars[i] <= 0x7ff) {
- ret[j++] = 0xc0 | ev_bits(chars[i], 0x1f, 6);
- ret[j] = 0x80 | ev_bits(chars[i], 0x3f, 0);
+ out[j++] = 0xc0 | ev_bits(chars[i], 0x1f, 6);
+ out[j] = 0x80 | ev_bits(chars[i], 0x3f, 0);
#if 1
} else if (chars[i] > 0x7ff) {
- ret[j++] = 0xe0 | ev_bits(chars[i], 0xf, 12);
- ret[j++] = 0x80 | ev_bits(chars[i], 0x3f, 6);
- ret[j] = 0x80| ev_bits(chars[i], 0x3f, 0);
+ out[j++] = 0xe0 | ev_bits(chars[i], 0xf, 12);
+ out[j++] = 0x80 | ev_bits(chars[i], 0x3f, 6);
+ out[j] = 0x80| ev_bits(chars[i], 0x3f, 0);
}
#else
} else if (chars[i] > 0x7ff && chars[i] < 0x10000) {
- ret[j++] = 0xe0 | ev_bits(chars[i], 0xf, 12);
- ret[j++] = 0x80 | ev_bits(chars[i], 0x3f, 6);
- ret[j] = 0x80| ev_bits(chars[i], 0x3f, 0);
+ out[j++] = 0xe0 | ev_bits(chars[i], 0xf, 12);
+ out[j++] = 0x80 | ev_bits(chars[i], 0x3f, 6);
+ out[j] = 0x80| ev_bits(chars[i], 0x3f, 0);
} else if (chars[i] > 0xffff && chars[i] < 0x200000) {
- ret[j++] = 0xf0 | ev_bits(chars[i], 0x7, 18);
- ret[j++] = 0x80 | ev_bits(chars[i], 0x3f, 12);
- ret[j++] = 0x80 | ev_bits(chars[i], 0x3f, 6);
- ret[j] = 0x80| ev_bits(chars[i], 0x3f, 0);
+ out[j++] = 0xf0 | ev_bits(chars[i], 0x7, 18);
+ out[j++] = 0x80 | ev_bits(chars[i], 0x3f, 12);
+ out[j++] = 0x80 | ev_bits(chars[i], 0x3f, 6);
+ out[j] = 0x80| ev_bits(chars[i], 0x3f, 0);
} else if (chars[i] > 0x1fffff && chars[i] < 0x4000000) {
- ret[j++] = 0xf8 | ev_bits(chars[i], 0x3, 24);
- ret[j++] = 0x80 | ev_bits(chars[i], 0x3f, 18);
- ret[j++] = 0x80 | ev_bits(chars[i], 0x3f, 12);
- ret[j++] = 0x80 | ev_bits(chars[i], 0x3f, 6);
- ret[j] = 0x80 | ev_bits(chars[i], 0x3f, 0);
+ out[j++] = 0xf8 | ev_bits(chars[i], 0x3, 24);
+ out[j++] = 0x80 | ev_bits(chars[i], 0x3f, 18);
+ out[j++] = 0x80 | ev_bits(chars[i], 0x3f, 12);
+ out[j++] = 0x80 | ev_bits(chars[i], 0x3f, 6);
+ out[j] = 0x80 | ev_bits(chars[i], 0x3f, 0);
} else if (chars[i] > 0x3ffffff) {
- ret[j++] = 0xfc | ev_bits(chars[i], 0x1, 30);
- ret[j++] = 0x80 | ev_bits(chars[i], 0x3f, 24);
- ret[j++] = 0x80 | ev_bits(chars[i], 0x3f, 18);
- ret[j++] = 0x80 | ev_bits(chars[i], 0x3f, 12);
- ret[j++] = 0x80 | ev_bits(chars[i], 0x3f, 6);
- ret[j] = 0x80 | ev_bits(chars[i], 0x3f, 0);
+ out[j++] = 0xfc | ev_bits(chars[i], 0x1, 30);
+ out[j++] = 0x80 | ev_bits(chars[i], 0x3f, 24);
+ out[j++] = 0x80 | ev_bits(chars[i], 0x3f, 18);
+ out[j++] = 0x80 | ev_bits(chars[i], 0x3f, 12);
+ out[j++] = 0x80 | ev_bits(chars[i], 0x3f, 6);
+ out[j] = 0x80 | ev_bits(chars[i], 0x3f, 0);
}
#endif
}
- ret[j] = '\0';
+ out[j++] = '\0';
+ ret = realloc(out, j);
+ if (!ret) {
+ free(out);
+ return NULL;
+ }
return ret;
}
+/*
+ * utf8_to_ucs2(): convert UTF-8 to UCS-2
+ * s: the destination buffer to write to.
+ * size: the size of the allocation to write to
+ * terminate: whether or not to add a terminator to the string
+ * utf8: the utf8 source
+ *
+ * returns the number of characters written to s, including the NUL
+ * terminator if "terminate" is true, or -1 on error. In the case of an
+ * error, the buffer will not be modified.
+ */
static inline ssize_t UNUSED NONNULL(4)
-utf8_to_ucs2(void *ucs2void, ssize_t size, int terminate, const unsigned char *utf8)
+utf8_to_ucs2(void *s, ssize_t size, bool terminate, const unsigned char *utf8)
{
ssize_t req;
ssize_t i, j;
- uint16_t *ucs2 = ucs2void;
+ uint16_t *ucs2 = s;
uint16_t val16;
if (!ucs2 && size > 0) {
--
2.26.2

View File

@ -1,38 +0,0 @@
From ebc0b14923faa8da19dbdc2501a6fef0728906a1 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Mon, 1 Oct 2018 14:27:04 -0400
Subject: [PATCH 36/39] dp-acpi: fix HID vs HID_EX formatting bug.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/dp-acpi.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/src/dp-acpi.c b/src/dp-acpi.c
index 6f3e94443e5..019f910c164 100644
--- a/src/dp-acpi.c
+++ b/src/dp-acpi.c
@@ -157,7 +157,9 @@ _format_acpi_dn(char *buf, size_t size, const_efidp dp)
return off;
}
}
- } else if (dp->subtype == EFIDP_ACPI_HID_EX) {
+ } else if (dp->subtype == EFIDP_ACPI_HID) {
+ debug("formatting ACPI HID 0x%08x", dp->acpi_hid.hid);
+
switch (dp->acpi_hid.hid) {
case EFIDP_ACPI_PCI_ROOT_HID:
format(buf, size, off, "PciRoot",
@@ -249,6 +251,9 @@ _format_acpi_dn(char *buf, size_t size, const_efidp dp)
return -1;
}
}
+ } else {
+ debug("Unknown ACPI device path type {0x%04hhx,0x%04hhx}",
+ dp->type, dp->subtype);
}
return off;
--
2.17.1

View File

@ -0,0 +1,370 @@
From 73635c7e096eb36b52c1e874f9b76856c6a41228 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Mon, 17 Jun 2019 16:37:29 -0400
Subject: [PATCH 36/63] util.h: implement add()/mul()/sub() for more integer
types.
This adds the following:
uint_add()
uint_mul()
uint_sub()
long_sub()
ulong_sub()
Additionally it renames ulong_mult() to ulong_mul() and long_mult() to
long_mul().
As before, all of these are available without caring about the types,
as if declared:
bool add(TYPE addend, TYPE addend, TYPE *sum);
bool mul(TYPE factor, TYPE factor, TYPE *product);
bool sub(TYPE minuend, TYPE subtractahend, TYPE *difference);
If overflow would occur, the pointer target for the result is not
changed and the function returns true, otherwise it returns false.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/efivar.h | 1 +
src/safemath.h | 208 +++++++++++++++++++++++++++++++++++++++++++++++++
src/util.h | 96 -----------------------
3 files changed, 209 insertions(+), 96 deletions(-)
create mode 100644 src/safemath.h
diff --git a/src/efivar.h b/src/efivar.h
index 3d4b429631e..646863d14c5 100644
--- a/src/efivar.h
+++ b/src/efivar.h
@@ -23,6 +23,7 @@
#include <efivar/efivar.h>
#include "util.h"
+#include "safemath.h"
#include "efivar_endian.h"
#include "lib.h"
#include "guid.h"
diff --git a/src/safemath.h b/src/safemath.h
new file mode 100644
index 00000000000..08dfef7ec0b
--- /dev/null
+++ b/src/safemath.h
@@ -0,0 +1,208 @@
+/*
+ * safemath.h
+ * Copyright 2016-2019 Peter Jones <pjones@redhat.com>
+ *
+ * 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/>.
+ *
+ */
+
+#ifndef SAFEMATH_H_
+#define SAFEMATH_H_
+
+/*
+ * I'm not actually sure when these appear, but they're present in the
+ * version in front of me.
+ */
+#if defined(__GNUC__) && defined(__GNUC_MINOR__)
+#if __GNUC__ >= 5 && __GNUC_MINOR__ >= 1
+#define int_add(a, b, c) __builtin_add_overflow(a, b, c)
+#define uint_add(a, b, c) __builtin_add_overflow(a, b, c)
+#define long_add(a, b, c) __builtin_add_overflow(a, b, c)
+#define ulong_add(a, b, c) __builtin_add_overflow(a, b, c)
+
+#define int_mul(a, b, c) __builtin_mul_overflow(a, b, c)
+#define uint_mul(a, b, c) __builtin_mul_overflow(a, b, c)
+#define long_mul(a, b, c) __builtin_mul_overflow(a, b, c)
+#define ulong_mul(a, b, c) __builtin_mul_overflow(a, b, c)
+
+#define int_sub(a, b, c) __builtin_sub_overflow(a, b, c)
+#define uint_sub(a, b, c) __builtin_sub_overflow(a, b, c)
+#define long_sub(a, b, c) __builtin_sub_overflow(a, b, c)
+#define ulong_sub(a, b, c) __builtin_sub_overflow(a, b, c)
+#endif
+#endif
+
+#ifndef int_add
+#define int_add(a, b, c) ({ \
+ const int _limit = INT_MAX; \
+ long int _ret = _limit - (a); \
+ _ret = _ret > (b); \
+ if (!_ret) \
+ *(c) = ((a) + (b)); \
+ (bool)_ret; \
+ })
+#endif
+
+#ifndef uint_add
+#define uint_add(a, b, c) ({ \
+ const unsigned int _limit = UINT_MAX; \
+ unsigned int _ret = _limit - (a); \
+ _ret = _ret > (b); \
+ if (!_ret) \
+ *(c) = ((a) + (b)); \
+ (bool)_ret; \
+ })
+#endif
+
+#ifndef long_add
+#define long_add(a, b, c) ({ \
+ const long _limit = LONG_MAX; \
+ long _ret = _limit - (a); \
+ _ret = _ret > (b); \
+ if (!_ret) \
+ *(c) = ((a) + (b)); \
+ (bool)_ret; \
+ })
+#endif
+
+#ifndef ulong_add
+#define ulong_add(a, b, c) ({ \
+ const unsigned long _limit = ULONG_MAX; \
+ unsigned long _ret = _limit - (a); \
+ _ret = _ret > (b); \
+ if (!_ret) \
+ *(c) = ((a) + (b)); \
+ (bool)_ret; \
+ })
+#endif
+
+#ifndef int_mul
+#define int_mul(a, b, c) ({ \
+ int _ret; \
+ _ret = __builtin_popcount(a) + __builtin_popcount(b); \
+ _ret = _ret < ((sizeof(a) + sizeof(b)) << 4); \
+ if (!_ret) \
+ *(c) = ((a) * (b)); \
+ (bool)_ret; \
+ })
+#endif
+
+#ifndef uint_mul
+#define uint_mul(a, b, c) int_mul(a, b, c)
+#endif
+
+#ifndef long_mul
+#define long_mul(a, b, c) int_mul(a, b, c)
+#endif
+
+#ifndef ulong_mul
+#define ulong_mul(a, b, c) int_mul(a, b, c)
+#endif
+
+#ifndef int_sub
+#define int_sub(a, b, c) ({ \
+ const long _min_limit = INT_MIN; \
+ const long _max_limit = INT_MAX; \
+ int _ret; \
+ _ret = _min_limit + (b); \
+ _ret = !(_ret < (a)); \
+ if (!_ret) { \
+ _ret = _max_limit - (a); \
+ _ret = _ret > (b); \
+ } \
+ if (!_ret) \
+ *(c) = ((a) - (b)); \
+ (bool)_ret; \
+ })
+#endif
+
+#ifndef uint_sub
+#define uint_sub(a, b, c) ({ \
+ const unsigned int _limit = UINT_MAX; \
+ unsigned int _ret = _limit - (a); \
+ _ret = _ret > (b); \
+ if (!_ret) \
+ *(c) = ((a) - (b)); \
+ (bool)_ret; \
+ })
+#endif
+
+#ifndef long_sub
+#define long_sub(a, b, c) ({ \
+ const long _min_limit = LONG_MIN; \
+ const long _max_limit = LONG_MAX; \
+ int _ret; \
+ _ret = _min_limit + (b); \
+ _ret = !(_ret < (a)); \
+ if (!_ret) { \
+ _ret = _max_limit - (a); \
+ _ret = _ret > (b); \
+ } \
+ if (!_ret) \
+ *(c) = ((a) - (b)); \
+ (bool)_ret; \
+ })
+#endif
+
+#ifndef ulong_sub
+#define ulong_sub(a, b, c) ({ \
+ const unsigned long _limit = ULONG_MAX; \
+ unsigned long _ret = _limit - (a); \
+ _ret = _ret > (b); \
+ if (!_ret) \
+ *(c) = ((a) - (b)); \
+ _ret; \
+ })
+#endif
+
+#if defined(__GNUC__) && defined(__GNUC_MINOR__)
+#if __GNUC__ >= 5 && __GNUC_MINOR__ >= 1
+#define add(a, b, c) _Generic((c), \
+ int *: int_add(a, b, c), \
+ unsigned int *: uint_add(a, b, c), \
+ long *: long_add(a, b, c), \
+ unsigned long *: ulong_add(a, b, c))
+#define sub(a, b, c) _Generic((c), \
+ int *: int_sub(a, b, c), \
+ unsigned int *: uint_sub(a, b, c), \
+ long *: long_sub(a, b, c), \
+ unsigned long *: ulong_sub(a, b, c))
+#define mul(a, b, c) _Generic((c), \
+ int *: int_sub(a, b, c), \
+ unsigned int *: uint_mul(a, b, c), \
+ long *: long_mul(a, b, c), \
+ unsigned long *: ulong_mul(a, b, c))
+#endif
+#endif
+
+#ifndef add
+#define add(a, b, c) ({ \
+ (*(c)) = ((a) + (b)); \
+ })
+#endif
+#ifndef mul
+#define mul(a, b, c) ({ \
+ (*(c)) = ((a) * (b)); \
+ })
+#endif
+#ifndef sub
+#define sub(a, b, c) ({ \
+ (*(c)) = ((a) - (b)); \
+ })
+#endif
+
+
+#endif /* !SAFEMATH_H_ */
+// vim:fenc=utf-8:tw=75:noet
diff --git a/src/util.h b/src/util.h
index 712abea2d42..3f68d812700 100644
--- a/src/util.h
+++ b/src/util.h
@@ -61,102 +61,6 @@
#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.
- */
-#if defined(__GNUC__) && defined(__GNUC_MINOR__)
-#if __GNUC__ >= 5 && __GNUC_MINOR__ >= 1
-#define int_add(a, b, c) __builtin_add_overflow(a, b, c)
-#define long_add(a, b, c) __builtin_add_overflow(a, b, c)
-#define long_mult(a, b, c) __builtin_mul_overflow(a, b, c)
-#define ulong_add(a, b, c) __builtin_add_overflow(a, b, c)
-#define ulong_mult(a, b, c) __builtin_mul_overflow(a, b, c)
-#endif
-#endif
-#ifndef int_add
-#define int_add(a, b, c) ({ \
- const int _limit = INT_MAX; \
- int _ret; \
- _ret = _limit - ((unsigned long long)a) > \
- ((unsigned long long)b); \
- if (!_ret) \
- *(c) = ((a) + (b)); \
- _ret; \
- })
-#endif
-#ifndef long_add
-#define long_add(a, b, c) ({ \
- const long _limit = LONG_MAX; \
- int _ret; \
- _ret = _limit - ((unsigned long long)a) > \
- ((unsigned long long)b); \
- if (!_ret) \
- *(c) = ((a) + (b)); \
- _ret; \
- })
-#endif
-#ifndef long_mult
-#define long_mult(a, b, c) ({ \
- const long _limit = LONG_MAX; \
- int _ret = 1; \
- if ((a) == 0 || (b) == 0) \
- _ret = 0; \
- else \
- _ret = _limit / (a) < (b); \
- if (!_ret) \
- *(c) = ((a) * (b)); \
- _ret; \
- })
-#endif
-#ifndef ulong_add
-#define ulong_add(a, b, c) ({ \
- const unsigned long _limit = ULONG_MAX; \
- int _ret; \
- _ret = _limit - ((unsigned long long)a) > \
- ((unsigned long long)b); \
- if (!_ret) \
- *(c) = ((a) + (b)); \
- _ret; \
- })
-#endif
-#ifndef ulong_mult
-#define ulong_mult(a, b, c) ({ \
- const unsigned long _limit = ULONG_MAX; \
- int _ret = 1; \
- if ((a) == 0 || (b) == 0) \
- _ret = 0; \
- else \
- _ret = _limit / (a) < (b); \
- if (!_ret) \
- *(c) = ((a) * (b)); \
- _ret; \
- })
-#endif
-
-#if defined(__GNUC__) && defined(__GNUC_MINOR__)
-#if __GNUC__ >= 5 && __GNUC_MINOR__ >= 1
-#define add(a, b, c) _Generic((c), \
- int *: int_add(a,b,c), \
- long *: long_add(a,b,c), \
- unsigned long *: ulong_add(a,b,c))
-#define mult(a, b, c) _Generic((c), \
- long *: long_mult(a,b,c), \
- unsigned long *: ulong_mult(a,b,c))
-#endif
-#endif
-
-#ifndef add
-#define add(a, b, c) ({ \
- (*(c)) = ((a) + (b)); \
- })
-#endif
-#ifndef mult
-#define mult(a, b, c) ({ \
- (*(c)) = ((a) * (b)); \
- })
-#endif
-
static inline int UNUSED
read_file(int fd, uint8_t **result, size_t *bufsize)
{
--
2.26.2

File diff suppressed because it is too large Load Diff

View File

@ -1,75 +0,0 @@
From 7775b2fdd12151f78f575026bb5e416575dad455 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Mon, 1 Oct 2018 14:31:06 -0400
Subject: [PATCH 37/39] Support decoding ACPI Generic Container and Embedded
Controller dp nodes
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/dp-acpi.c | 18 ++++++++++++++++++
src/include/efivar/efivar-dp.h | 3 +++
2 files changed, 21 insertions(+)
diff --git a/src/dp-acpi.c b/src/dp-acpi.c
index 019f910c164..3a80ba9e006 100644
--- a/src/dp-acpi.c
+++ b/src/dp-acpi.c
@@ -147,10 +147,19 @@ _format_acpi_dn(char *buf, size_t size, const_efidp dp)
format(buf, size, off, "PciRoot",
"PciRoot(%s)", uidstr);
return off;
+ case EFIDP_ACPI_CONTAINER_0A05_HID:
+ case EFIDP_ACPI_CONTAINER_0A06_HID:
+ format(buf, size, off, "AcpiContainer",
+ "AcpiContainer(%s)", uidstr);
+ break;
case EFIDP_ACPI_PCIE_ROOT_HID:
format(buf, size, off, "PcieRoot",
"PcieRoot(%s)", uidstr);
return off;
+ case EFIDP_ACPI_EC_HID:
+ format(buf, size, off, "EmbeddedController",
+ "EmbeddedController()");
+ return off;
default:
format_acpi_hid_ex(buf, size, off, dp,
hidstr, cidstr, uidstr);
@@ -166,11 +175,20 @@ _format_acpi_dn(char *buf, size_t size, const_efidp dp)
"PciRoot(0x%"PRIx32")",
dp->acpi_hid.uid);
break;
+ case EFIDP_ACPI_CONTAINER_0A05_HID:
+ case EFIDP_ACPI_CONTAINER_0A06_HID:
+ format(buf, size, off, "AcpiContainer",
+ "AcpiContainer()");
+ break;
case EFIDP_ACPI_PCIE_ROOT_HID:
format(buf, size, off, "PcieRoot",
"PcieRoot(0x%"PRIx32")",
dp->acpi_hid.uid);
break;
+ case EFIDP_ACPI_EC_HID:
+ format(buf, size, off, "EmbeddedController",
+ "EmbeddedController()");
+ break;
case EFIDP_ACPI_FLOPPY_HID:
format(buf, size, off, "Floppy",
"Floppy(0x%"PRIx32")",
diff --git a/src/include/efivar/efivar-dp.h b/src/include/efivar/efivar-dp.h
index f9ebb059d06..eab04f2dfac 100644
--- a/src/include/efivar/efivar-dp.h
+++ b/src/include/efivar/efivar-dp.h
@@ -155,7 +155,10 @@ efidp_make_acpi_hid_ex(uint8_t *buf, ssize_t size,
#define EFIDP_ACPI_ID_TO_NUM(_HID) ((_HID) >> 16)
#define EFIDP_ACPI_PCI_ROOT_HID EFIDP_EFI_PNP_ID(0x0a03)
+#define EFIDP_ACPI_CONTAINER_0A05_HID EFIDP_EFI_PNP_ID(0x0a05)
+#define EFIDP_ACPI_CONTAINER_0A06_HID EFIDP_EFI_PNP_ID(0x0a06)
#define EFIDP_ACPI_PCIE_ROOT_HID EFIDP_EFI_PNP_ID(0x0a08)
+#define EFIDP_ACPI_EC_HID EFIDP_EFI_PNP_ID(0x0a09)
#define EFIDP_ACPI_FLOPPY_HID EFIDP_EFI_PNP_ID(0x0604)
#define EFIDP_ACPI_KEYBOARD_HID EFIDP_EFI_PNP_ID(0x0301)
#define EFIDP_ACPI_SERIAL_HID EFIDP_EFI_PNP_ID(0x0501)
--
2.17.1

View File

@ -0,0 +1,187 @@
From 693dbef8d7d6287b438ad7e385b383f60df74a8c Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Tue, 18 Jun 2019 13:21:45 -0400
Subject: [PATCH 38/63] Add some test cases for efivar export/import
Signed-off-by: Peter Jones <pjones@redhat.com>
---
Makefile | 3 ++
tests/.gitignore | 2 +
tests/Makefile | 86 ++++++++++++++++++++++++++++++++++++++++++
tests/test.0.goal.var | Bin 0 -> 562 bytes
tests/test.1.goal.var | Bin 0 -> 574 bytes
tests/test.3.goal.var | Bin 0 -> 66 bytes
tests/test.4.goal.var | Bin 0 -> 365 bytes
7 files changed, 91 insertions(+)
create mode 100644 tests/.gitignore
create mode 100644 tests/Makefile
create mode 100644 tests/test.0.goal.var
create mode 100644 tests/test.1.goal.var
create mode 100644 tests/test.3.goal.var
create mode 100644 tests/test.4.goal.var
diff --git a/Makefile b/Makefile
index 9c2620cb485..2d134ea9d6f 100644
--- a/Makefile
+++ b/Makefile
@@ -51,6 +51,9 @@ clean :
done
@rm -vf efivar.spec vgcore.* core.*
+test : all
+ @$(MAKE) -C tests
+
test-archive: abicheck efivar.spec
@rm -rf /tmp/efivar-$(GITTAG) /tmp/efivar-$(GITTAG)-tmp
@mkdir -p /tmp/efivar-$(GITTAG)-tmp
diff --git a/tests/.gitignore b/tests/.gitignore
new file mode 100644
index 00000000000..a0149cf75de
--- /dev/null
+++ b/tests/.gitignore
@@ -0,0 +1,2 @@
+!*.var
+*.result.*
diff --git a/tests/Makefile b/tests/Makefile
new file mode 100644
index 00000000000..5e0c604e355
--- /dev/null
+++ b/tests/Makefile
@@ -0,0 +1,86 @@
+#
+# Makefile
+# Peter Jones, 2019-06-18 11:10
+#
+
+all: clean test0 test1 test2 test3 test4
+
+GRUB_PREFIX ?= grub2
+TOPDIR ?= ..
+EFIVAR ?= ../src/efivar
+
+clean:
+ @rm -f *.result.env *.result.var
+
+test0:
+ @echo testing export to DMPSTORE format
+ @$(GRUB_PREFIX)-editenv test.0.result.env create
+ @$(GRUB_PREFIX)-editenv test.0.result.env set debug=all,-scripting,-lexer
+ @truncate -s 512 test.0.result.env
+ @LD_LIBRARY_PATH=$(TOPDIR)/src $(EFIVAR) -n {grub}-GRUB_ENV -f test.0.result.env -D -e test.0.result.var
+ @cmp test.0.result.var test.0.goal.var
+ @rm test.0.result.*
+ @echo passed
+
+test1:
+ @echo testing export to libefivar format
+ @$(GRUB_PREFIX)-editenv test.1.result.env create
+ @$(GRUB_PREFIX)-editenv test.1.result.env set debug=all,-scripting,-lexer
+ @truncate -s 512 test.1.result.env
+ @LD_LIBRARY_PATH=$(TOPDIR)/src $(EFIVAR) -n {grub}-GRUB_ENV -f test.1.result.env -e test.1.result.var
+ @cmp test.1.result.var test.1.goal.var
+ @rm test.1.result.*
+ @echo passed
+
+test2:
+ @$(GRUB_PREFIX)-editenv test.2.result.env create
+ @$(GRUB_PREFIX)-editenv test.2.result.env set debug=all,-scripting,-lexer
+ @truncate -s 512 test.2.result.env
+ @echo test importing from DMPSTORE and exporting to DMPSTORE and symbolic guid-name validation
+ @LD_LIBRARY_PATH=$(TOPDIR)/src $(EFIVAR) -n {grub}-GRUB_ENV -f test.2.result.env -D -e test.2.0.goal.var
+ @LD_LIBRARY_PATH=$(TOPDIR)/src $(EFIVAR) -i test.2.0.goal.var -e test.2.0.result.var -D
+ @cmp test.2.0.result.var test.2.0.result.var
+ @rm test.2.0.*
+ @echo passed
+ @echo test importing from DMPSTORE and exporting to libefivar
+ @LD_LIBRARY_PATH=$(TOPDIR)/src $(EFIVAR) -n {grub}-GRUB_ENV -f test.2.result.env -D -e test.2.1.goal.var
+ @LD_LIBRARY_PATH=$(TOPDIR)/src $(EFIVAR) -i test.2.1.goal.var -e test.2.1.result.var
+ @cmp test.2.1.result.var test.2.1.result.var
+ @rm test.2.1.*
+ @echo passed
+ @echo test importing from libefivar and exporting to DMPSTORE and mixed-case guid-name validation
+ @LD_LIBRARY_PATH=$(TOPDIR)/src $(EFIVAR) -n 91376aff-cBa6-42bE-949d-06fde81128e8-GRUB_ENV -f test.2.result.env -e test.2.2.goal.var
+ @LD_LIBRARY_PATH=$(TOPDIR)/src $(EFIVAR) -i test.2.2.goal.var -e test.2.2.result.var -D
+ @cmp test.2.2.result.var test.2.2.result.var
+ @rm test.2.2.*
+ @echo passed
+ @echo test importing from libefivar and exporting to libefivar and guid-name validation
+ @LD_LIBRARY_PATH=$(TOPDIR)/src $(EFIVAR) -n 91376aff-cba6-42be-949d-06fde81128e8-GRUB_ENV -f test.2.result.env -e test.2.3.goal.var
+ @LD_LIBRARY_PATH=$(TOPDIR)/src $(EFIVAR) -i test.2.3.goal.var -e test.2.3.result.var
+ @cmp test.2.3.result.var test.2.3.result.var
+ @rm test.2.3.* test.2.result.env
+ @echo passed
+ @echo testing efivar -L
+ @LD_LIBRARY_PATH=$(TOPDIR)/src $(EFIVAR) -L | \
+ grep -q '^{91376aff-cba6-42be-949d-06fde81128e8} {grub} efi_guid_grub GRUB$$'
+ @echo passed
+
+test3:
+ @echo testing with BootOrder variable dmpstore generated
+ @LD_LIBRARY_PATH=$(TOPDIR)/src $(EFIVAR) -i test.3.goal.var -e test.3.0.result.var
+ @LD_LIBRARY_PATH=$(TOPDIR)/src $(EFIVAR) -i test.3.0.result.var -e test.3.1.result.var -D
+ @cmp test.3.goal.var test.3.1.result.var
+ @rm test.3.0.result.var test.3.1.result.var
+ @echo passed
+
+test4:
+ @echo testing with ConIn variable dmpstore generated
+ @LD_LIBRARY_PATH=$(TOPDIR)/src $(EFIVAR) -i test.4.goal.var -e test.4.0.result.var
+ @LD_LIBRARY_PATH=$(TOPDIR)/src $(EFIVAR) -i test.4.0.result.var -e test.4.1.result.var -D
+ @cmp test.4.goal.var test.4.1.result.var
+ @rm test.4.0.result.var test.4.1.result.var
+ @echo passed
+
+.PHONY: all clean test0
+# vim:ft=make
+#
diff --git a/tests/test.0.goal.var b/tests/test.0.goal.var
new file mode 100644
index 0000000000000000000000000000000000000000..a3bfb4db5ea49c8b26b0b9a0e118da4109969efb
GIT binary patch
literal 562
zcmWe)00Jfk26u)ahEN74hIj^720w-{py2;3^NGt&?{k_mm+kKhL5&yeKrv+n_n=TG
z1=qZ?%%c3f+|;}h1*e?+<ZP~#)TGjM+r*q49o^#OqRfJl%)E3R-JH~l)FLkBQ7~LW
Jz?Da0CID%RU7r8|
literal 0
HcmV?d00001
diff --git a/tests/test.1.goal.var b/tests/test.1.goal.var
new file mode 100644
index 0000000000000000000000000000000000000000..7f70c93317d996c429430ec434098c0417370970
GIT binary patch
literal 574
zcmbO(djB&c0|Ns)5QD(~Ec1!WPVaM?GMDY|3qg$+LLfmV1_pPAAcjx|Cx&<iR|Y?Z
zFrc8af_qS?lY(nrS!PjwUT$h$iGov3esVTfN@`MRx@}@kj*f0|a#3bMNoHQUj&4qB
SMQRb3@+cTCAs{>T<#Pa%YGIxL
literal 0
HcmV?d00001
diff --git a/tests/test.3.goal.var b/tests/test.3.goal.var
new file mode 100644
index 0000000000000000000000000000000000000000..972dd553e2043e782b096c9a8ad509c07b73782d
GIT binary patch
literal 66
zcmWe(U|`?_Vkd@tAS_|<XDDJwVMqm%3=E0)pLCy^d`WN>FT;Zw%-TKdKru!JW+2JL
Pz{0@Fz{b#`@+=nsxhf5!
literal 0
HcmV?d00001
diff --git a/tests/test.4.goal.var b/tests/test.4.goal.var
new file mode 100644
index 0000000000000000000000000000000000000000..549ed5b717dd23843883d3d45f65f4dafeede870
GIT binary patch
literal 365
zcmWe)U|_IjWMFV+$Y;o7@C0HPhE#?!plIU#C*7weUlLr!%kW?Zvvv;~P>hj9gu%OZ
z#$~DL@y<Q#J=0$&6*)5V2?J$-U>bztU}R+G5@85-KlotZ&r5={co-(A+aL6;XJjEo
zduqb6`;uEO3(nFdOFQ@Rb=42T%Y6FU_2+4DG&_@MdqeKT+KtgYu1oqK#orBlKZQi?
e*A|Gbebas3YeDe^+2?h-9rgcN7(R2c?F0Zk6=943
literal 0
HcmV?d00001
--
2.26.2

View File

@ -1,38 +0,0 @@
From 0d63973b32767e1c4d44c0c172ae6222d9acefff Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Mon, 1 Oct 2018 14:33:20 -0400
Subject: [PATCH 38/39] pci-root: actually create the device path node.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/linux-pci-root.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/src/linux-pci-root.c b/src/linux-pci-root.c
index 269e30e2c31..a2d9fb04a11 100644
--- a/src/linux-pci-root.c
+++ b/src/linux-pci-root.c
@@ -87,9 +87,9 @@ static ssize_t
dp_create_pci_root(struct device *dev UNUSED,
uint8_t *buf, ssize_t size, ssize_t off)
{
+ ssize_t new = 0, sz = 0;
debug("entry buf:%p size:%zd off:%zd", buf, size, off);
debug("returning 0");
-#if 0
if (dev->acpi_root.acpi_uid_str) {
debug("creating acpi_hid_ex dp hid:0x%08x uid:\"%s\"",
dev->acpi_root.acpi_hid,
@@ -120,9 +120,6 @@ dp_create_pci_root(struct device *dev UNUSED,
debug("returning %zd", sz);
return sz;
-#else
- return 0;
-#endif
}
enum interface_type pci_root_iftypes[] = { pci_root, unknown };
--
2.17.1

View File

@ -0,0 +1,119 @@
From 9819ec7325089d325ff13af3c3d615209f3fb2c9 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Tue, 18 Jun 2019 15:54:58 -0400
Subject: [PATCH 39/63] Fix a case clang-analyzer found where we may try to
parse a NULL
I don't think this is something that can *actually* happen - it didn't
trigger before save_variable() was added, and the save_variable() path
that calls this calls validate_name() immediately prior to this call.
validate_name() calls exit() if it's NULL. But that's weird as well,
because that's the same pattern all the other users of parse_name() use.
Anyway, this patch expands validate_name() and moves it into
parse_name() so we don't need to call it from everywhere when we're just
calling the two in a row anyway.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/efivar.c | 45 ++++++++++++++++++++++++++++++---------------
1 file changed, 30 insertions(+), 15 deletions(-)
diff --git a/src/efivar.c b/src/efivar.c
index 885a9af864b..8b1da8888f6 100644
--- a/src/efivar.c
+++ b/src/efivar.c
@@ -95,6 +95,34 @@ show_errors(void)
}
}
+static inline void
+validate_name(const char *name)
+{
+ if (name == NULL) {
+err:
+ warnx("Invalid variable name \"%s\"",
+ (name == NULL) ? "(null)" : name);
+ show_errors();
+ exit(1);
+ }
+ if (name[0] == '{') {
+ const char *next = strchr(name+1, '}');
+ if (!next)
+ goto err;
+ if (next[1] != '-')
+ goto err;
+ if (next[2] == '\000')
+ goto err;
+ } else {
+ if (strlen(name) < 38)
+ goto err;
+ if (name[8] != '-' || name[13] != '-' ||
+ name[18] != '-' || name[23] != '-' ||
+ name[36] != '-')
+ goto err;
+ }
+}
+
static void
list_all_variables(void)
{
@@ -124,6 +152,8 @@ parse_name(const char *guid_name, char **name, efi_guid_t *guid)
const char *left, *right;
+ validate_name(guid_name);
+
left = strchr(guid_name, '{');
right = strchr(guid_name, '}');
if (left && right) {
@@ -408,16 +438,6 @@ edit_variable(const char *guid_name, void *data, size_t data_size,
}
}
-static void
-validate_name(const char *name)
-{
- if (name == NULL) {
- fprintf(stderr, "Invalid variable name\n");
- show_errors();
- exit(1);
- }
-}
-
static void
prepare_data(const char *filename, uint8_t **data, size_t *data_size)
{
@@ -588,21 +608,17 @@ int main(int argc, char *argv[])
list_all_variables();
break;
case ACTION_PRINT:
- validate_name(guid_name);
show_variable(guid_name, SHOW_VERBOSE);
break;
case ACTION_PRINT_DEC | ACTION_PRINT:
- validate_name(guid_name);
show_variable(guid_name, SHOW_DECIMAL);
break;
case ACTION_APPEND | ACTION_PRINT:
- validate_name(guid_name);
prepare_data(infile, &data, &data_size);
edit_variable(guid_name, data, data_size, attributes,
EDIT_APPEND);
break;
case ACTION_WRITE | ACTION_PRINT:
- validate_name(guid_name);
prepare_data(infile, &data, &data_size);
edit_variable(guid_name, data, data_size, attributes,
EDIT_WRITE);
@@ -653,7 +669,6 @@ int main(int argc, char *argv[])
efi_variable_free(var, false);
} else {
- validate_name(guid_name);
save_variable(guid_name, outfile, dmpstore);
}
break;
--
2.26.2

View File

@ -1,431 +0,0 @@
From 3e687d8072f3ed53ae727ec2cb99ae56dbcdf02b Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Mon, 1 Oct 2018 14:35:01 -0400
Subject: [PATCH 39/39] sas: handle port expanders at all.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/linux-ata.c | 3 +-
src/linux-sas.c | 168 ++++++++++++++++++++++++++++++++++++++++++-----
src/linux-scsi.c | 105 +++++++++++++++++++++++++----
src/linux.h | 6 +-
4 files changed, 250 insertions(+), 32 deletions(-)
diff --git a/src/linux-ata.c b/src/linux-ata.c
index 32cb99361e5..43e5f4c5d23 100644
--- a/src/linux-ata.c
+++ b/src/linux-ata.c
@@ -114,7 +114,8 @@ parse_ata(struct device *dev, const char *current, const char *root UNUSED)
pos = parse_scsi_link(host + 1, &scsi_host,
&scsi_bus, &scsi_device,
- &scsi_target, &scsi_lun);
+ &scsi_target, &scsi_lun,
+ NULL, NULL, NULL);
if (pos < 0)
return -1;
diff --git a/src/linux-sas.c b/src/linux-sas.c
index 4d77d39a24d..bb04fe83064 100644
--- a/src/linux-sas.c
+++ b/src/linux-sas.c
@@ -28,6 +28,91 @@
#include "efiboot.h"
+static int
+get_port_expander_sas_address(uint64_t *sas_address, uint32_t scsi_host,
+ uint32_t local_port_id,
+ uint32_t remote_port_id, uint32_t remote_scsi_target)
+{
+ uint8_t *filebuf = NULL;
+ int rc;
+
+ /*
+ * We find sas_address via this insanity:
+ * /sys/class/scsi_host/host2 -> ../../devices/pci0000:74/0000:74:02.0/host2/scsi_host/host2
+ * /sys/devices/pci0000:74/0000:74:02.0/host2/scsi_host/host2/device -> ../../../host2
+ * /sys/devices/pci0000:74/0000:74:02.0/host2/device -> ../../../host2
+ * /sys/devices/host2/port-2:0/expander-2:0/sas_device/expander-2:0/sas_address
+ *
+ * But since host2 is always host2, we can skip most of that and just
+ * go for:
+ * /sys/devices/pci0000:74/0000:74:02.0/host2/port-2:0/expander-2:0/port-2:0:2/end_device-2:0:2/sas_device/end_device-2:0:2/sas_address
+ */
+
+#if 0 /* previously thought this was right, but it's the expander's address, not the target's address */
+ /*
+ * /sys/class/scsi_host/host2/device/port-2:0/expander-2:0/sas_device/expander-2:0/sas_address
+ * ... I think. I would have expected that to be port-2:0:0 and I
+ * don't understand why it isn't. (I do now; this is the expander not
+ * the port.)
+ */
+
+ debug("looking for /sys/class/scsi_host/host%d/device/port-%d:%d/expander-%d:%d/sas_device/expander-%d:%d/sas_address",
+ scsi_host, scsi_host, port_id, scsi_host, remote_scsi_target, scsi_host, remote_scsi_target);
+ rc = read_sysfs_file(&filebuf,
+ "class/scsi_host/host%d/device/port-%d:%d/expander-%d:%d/sas_device/expander-%d:%d/sas_address",
+ scsi_host, scsi_host, port_id, scsi_host, remote_scsi_target, scsi_host, remote_scsi_target);
+ if (rc < 0 || filebuf == NULL) {
+ debug("didn't find it.");
+ return -1;
+ }
+#else
+ debug("looking for /sys/class/scsi_host/host%d/device/port-%d:%d/expander-%d:%d/port-%d:%d:%d/end_device-%d:%d:%d/sas_device/end_device-%d:%d:%d/sas_address",
+ scsi_host,
+ scsi_host, local_port_id,
+ scsi_host, remote_scsi_target,
+ scsi_host, remote_scsi_target, remote_port_id,
+ scsi_host, remote_scsi_target, remote_port_id,
+ scsi_host, remote_scsi_target, remote_port_id);
+ rc = read_sysfs_file(&filebuf,
+ "class/scsi_host/host%d/device/port-%d:%d/expander-%d:%d/port-%d:%d:%d/end_device-%d:%d:%d/sas_device/end_device-%d:%d:%d/sas_address",
+ scsi_host,
+ scsi_host, local_port_id,
+ scsi_host, remote_scsi_target,
+ scsi_host, remote_scsi_target, remote_port_id,
+ scsi_host, remote_scsi_target, remote_port_id,
+ scsi_host, remote_scsi_target, remote_port_id);
+ if (rc < 0 || filebuf == NULL) {
+ debug("didn't find it.");
+ return -1;
+ }
+#endif
+
+ rc = sscanf((char *)filebuf, "%"PRIx64, sas_address);
+ if (rc != 1)
+ return -1;
+
+ return 0;
+}
+
+static int
+get_local_sas_address(uint64_t *sas_address, struct device *dev)
+{
+ int rc;
+ char *filebuf = NULL;
+
+ rc = read_sysfs_file(&filebuf,
+ "class/block/%s/device/sas_address",
+ dev->disk_name);
+ if (rc < 0 || filebuf == NULL)
+ return -1;
+
+ rc = sscanf((char *)filebuf, "%"PRIx64, sas_address);
+ if (rc != 1)
+ return -1;
+
+ return 0;
+}
+
/*
* support for SAS devices
*
@@ -43,6 +128,24 @@
* /sys/class/block/sdc/device/sas_address
*
* I'm not sure at the moment if they're the same or not.
+ *
+ * There are also other devices that look like:
+ *
+ * 8:0 -> ../../devices/pci0000:74/0000:74:02.0/host2/port-2:0/expander-2:0/port-2:0:2/end_device-2:0:2/target2:0:0/2:0:0:0/block/sda
+ * 8:1 -> ../../devices/pci0000:74/0000:74:02.0/host2/port-2:0/expander-2:0/port-2:0:2/end_device-2:0:2/target2:0:0/2:0:0:0/block/sda/sda1
+ *
+ * /sys/dev/block/8:0/device -> ../../../2:0:0:0
+ *
+ * This exists:
+ *
+ * /sys/class/scsi_host/host2 -> ../../devices/pci0000:74/0000:74:02.0/host2/scsi_host/host2
+ * /sys/devices/pci0000:74/0000:74:02.0/host2/scsi_host/host2/device -> ../../../host2
+ * /sys/devices/pci0000:74/0000:74:02.0/host2/device -> ../../../host2
+ * /sys/devices/pci0000:74/0000:74:02.0/host2/port-2:0/expander-2:0/sas_device/expander-2:0/sas_address
+ *
+ * but the device doesn't actually have a sas_host_address, because it's on a
+ * port expander, and sas_address doesn't directly exist under /sys/class/
+ * anywhere.
*/
static ssize_t
parse_sas(struct device *dev, const char *current, const char *root UNUSED)
@@ -50,16 +153,19 @@ parse_sas(struct device *dev, const char *current, const char *root UNUSED)
struct stat statbuf = { 0, };
int rc;
uint32_t scsi_host, scsi_bus, scsi_device, scsi_target;
+ uint32_t local_port_id = 0, remote_port_id = 0;
+ uint32_t remote_scsi_target = 0;
uint64_t scsi_lun;
ssize_t pos;
- uint8_t *filebuf = NULL;
- uint64_t sas_address;
+ uint64_t sas_address = 0;
debug("entry");
pos = parse_scsi_link(current, &scsi_host,
&scsi_bus, &scsi_device,
- &scsi_target, &scsi_lun);
+ &scsi_target, &scsi_lun,
+ &local_port_id, &remote_port_id,
+ &remote_scsi_target);
/*
* If we can't parse the scsi data, it isn't a sas device, so return 0
* not error.
@@ -71,6 +177,7 @@ parse_sas(struct device *dev, const char *current, const char *root UNUSED)
* Make sure it has the actual /SAS/ bits before we continue
* validating all this junk.
*/
+ debug("looking for /sys/class/scsi_host/host%d/host_sas_address", scsi_host);
rc = sysfs_stat(&statbuf,
"class/scsi_host/host%d/host_sas_address",
scsi_host);
@@ -79,21 +186,48 @@ parse_sas(struct device *dev, const char *current, const char *root UNUSED)
* 0 not error. Later errors mean it is an ata device, but we can't
* parse it right, so they return -1.
*/
- if (rc < 0)
- return 0;
+ if (rc < 0) {
+ debug("didn't find it.");
+ /*
+ * If it's on a port expander, it won't have the
+ * host_sas_address, so we need to check if it's a sas_host
+ * instead.
+ * It may work to just check this to begin with, but I don't
+ * have such a device in front of me right now.
+ */
+ debug("looking for /sys/class/sas_host/host%d", scsi_host);
+ rc = sysfs_stat(&statbuf,
+ "class/sas_host/host%d", scsi_host);
+ if (rc < 0) {
+ debug("didn't find it.");
+ return 0;
+ }
+ debug("found it.");
- /*
- * we also need to get the actual sas_address from someplace...
- */
- rc = read_sysfs_file(&filebuf,
- "class/block/%s/device/sas_address",
- dev->disk_name);
- if (rc < 0 || filebuf == NULL)
- return -1;
-
- rc = sscanf((char *)filebuf, "%"PRIx64, &sas_address);
- if (rc != 1)
- return -1;
+ /*
+ * So it *is* a sas_host, and we have to fish the sas_address
+ * from the remote port
+ */
+ rc = get_port_expander_sas_address(&sas_address, scsi_host,
+ local_port_id,
+ remote_port_id,
+ remote_scsi_target);
+ if (rc < 0) {
+ debug("Couldn't find port expander sas address");
+ return 0;
+ }
+ } else {
+ /*
+ * we also need to get the actual sas_address from someplace...
+ */
+ debug("found it.");
+ rc = get_local_sas_address(&sas_address, dev);
+ if (rc < 0) {
+ debug("Couldn't find sas address");
+ return 0;
+ }
+ }
+ debug("sas address is 0x%"PRIx64, sas_address);
dev->sas_info.sas_address = sas_address;
diff --git a/src/linux-scsi.c b/src/linux-scsi.c
index 2e4f710badf..a5e81cf9cb6 100644
--- a/src/linux-scsi.c
+++ b/src/linux-scsi.c
@@ -38,7 +38,9 @@
ssize_t HIDDEN
parse_scsi_link(const char *current, uint32_t *scsi_host,
uint32_t *scsi_bus, uint32_t *scsi_device,
- uint32_t *scsi_target, uint64_t *scsi_lun)
+ uint32_t *scsi_target, uint64_t *scsi_lun,
+ uint32_t *local_port_id, uint32_t *remote_port_id,
+ uint32_t *remote_target_id)
{
int rc;
int sz = 0;
@@ -70,11 +72,32 @@ parse_scsi_link(const char *current, uint32_t *scsi_host,
* /sys/block/sdc/device looks like:
* device-> ../../../4:2:0:0
*
+ * OR
+ *
+ * 8:0 -> ../../devices/pci0000:74/0000:74:02.0/host2/port-2:0/expander-2:0/port-2:0:2/end_device-2:0:2/target2:0:0/2:0:0:0/block/sda
+ * 8:1 -> ../../devices/pci0000:74/0000:74:02.0/host2/port-2:0/expander-2:0/port-2:0:2/end_device-2:0:2/target2:0:0/2:0:0:0/block/sda/sda1
+ *
+ * /sys/block/sda/device looks like:
+ * device -> ../../../2:0:0:0 *
+ *
+ * sas_address exists, but it's hard to find:
+ * /sys/devices/pci0000:74/0000:74:02.0/host2/port-2:0/expander-2:0/sas_device/expander-2:0/sas_address
+ * but sas_host_address is nowhere to be found, and sas_address
+ * doesn't directly exist under /sys/class/ anywhere. So you actually
+ * have to go to
+ * /sys/devices/pci0000:74/0000:74:02.0/host2/port-2:0/expander-2:0/sas_device/expander-2:0/sas_address
+ * and chop that off to
+ * /sys/devices/pci0000:74/0000:74:02.0/host2/port-2:0/expander-2:0/
+ * and then add a bunch of port and end device crap to it to get:
+ * /sys/devices/pci0000:74/0000:74:02.0/host2/port-2:0/expander-2:0/port-2:0:2/end_device-2:0:2/sas_device/end_device-2:0:2/sas_address
+
*/
/*
* So we start when current is:
* host4/port-4:0/end_device-4:0/target4:0:0/4:0:0:0/block/sdc/sdc1
+ * or
+ * host2/port-2:0/expander-2:0/port-2:0:2/end_device-2:0:2/target2:0:0/2:0:0:0/block/sda/sda1
*/
uint32_t tosser0, tosser1, tosser2;
@@ -91,6 +114,14 @@ parse_scsi_link(const char *current, uint32_t *scsi_host,
sz += pos0;
pos0 = 0;
+ /*
+ * We might have this next:
+ * port-2:0/expander-2:0/port-2:0:2/end_device-2:0:2/target2:0:0/2:0:0:0/block/sda/sda1
+ * or:
+ * port-2:0/end_device-2:0:2/target2:0:0/2:0:0:0/block/sda/sda1
+ * or maybe (not sure):
+ * port-2:0:2/end_device-2:0:2/target2:0:0/2:0:0:0/block/sda/sda1
+ */
debug("searching for port-4:0 or port-4:0:0");
rc = sscanf(current+sz, "port-%d:%d%n:%d%n", &tosser0,
&tosser1, &pos0, &tosser2, &pos1);
@@ -100,6 +131,52 @@ parse_scsi_link(const char *current, uint32_t *scsi_host,
if (rc == 2 || rc == 3) {
sz += pos0;
pos0 = 0;
+ if (local_port_id && rc == 2)
+ *local_port_id = tosser1;
+ if (remote_port_id && rc == 3)
+ *remote_port_id = tosser2;
+
+ if (current[sz] == '/')
+ sz += 1;
+
+ /*
+ * We might have this next:
+ * expander-2:0/port-2:0:2/end_device-2:0:2/target2:0:0/2:0:0:0/block/sda/sda1
+ * ^ port id
+ * ^ scsi target id
+ * ^ host number
+ * ^ host number
+ * We don't actually care about either number in expander-.../,
+ * because they're replicated in all the other places. We just need
+ * to get past it.
+ */
+ 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");
+ return -1;
+ }
+ *remote_target_id = tosser1;
+ sz += pos0;
+ pos0 = 0;
+
+ /*
+ * if we have that, we should have a 3-part port next
+ */
+ 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;
+ }
+ sz += pos0;
+ }
+ pos0 = 0;
/* next:
* /end_device-4:0
@@ -107,22 +184,24 @@ parse_scsi_link(const char *current, uint32_t *scsi_host,
* awesomely these are the exact same fields that go into port-blah,
* but we don't care for now about any of them anyway.
*/
- debug("searching for /end_device-4:0/ or /end_device-4:0:0/");
- rc = sscanf(current + sz, "/end_device-%d:%d%n", &tosser0, &tosser1, &pos0);
+ debug("searching for end_device-4:0/ or end_device-4:0:0/");
+ rc = sscanf(current + sz, "end_device-%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)
return -1;
- sz += pos0;
- pos0 = 0;
- rc = sscanf(current + sz, ":%d%n", &tosser0, &pos0);
- debug("current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0);
- arrow(LOG_DEBUG, spaces, 9, pos0, rc, 2);
+ 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;
- sz += pos0;
- pos0 = 0;
+ if (remote_port_id && rc == 1)
+ *remote_port_id = tosser2;
+ if (local_port_id && rc == 0)
+ *local_port_id = tosser1;
+ sz += pos0 + pos1;
+ pos0 = pos1 = 0;
if (current[sz] == '/')
sz += 1;
@@ -156,6 +235,7 @@ parse_scsi_link(const char *current, uint32_t *scsi_host,
return -1;
sz += pos0;
+ debug("returning %d", sz);
return sz;
}
@@ -191,7 +271,8 @@ parse_scsi(struct device *dev, const char *current, const char *root UNUSED)
sz = parse_scsi_link(current, &scsi_host,
&scsi_bus, &scsi_device,
- &scsi_target, &scsi_lun);
+ &scsi_target, &scsi_lun,
+ NULL, NULL, NULL);
if (sz < 0)
return 0;
diff --git a/src/linux.h b/src/linux.h
index 7c7ea91e771..43a9b7899f5 100644
--- a/src/linux.h
+++ b/src/linux.h
@@ -267,8 +267,10 @@ struct dev_probe {
};
extern ssize_t parse_scsi_link(const char *current, uint32_t *host,
- uint32_t *bus, uint32_t *device,
- uint32_t *target, uint64_t *lun);
+ uint32_t *bus, uint32_t *device,
+ uint32_t *target, uint64_t *lun,
+ uint32_t *local_port_id, uint32_t *remote_port_id,
+ uint32_t *remote_target_id);
/* device support implementations */
extern struct dev_probe pmem_parser;
--
2.17.1

View File

@ -0,0 +1,37 @@
From 4baa930ea79314e778a5ca84e3f85e94b2f9968f Mon Sep 17 00:00:00 2001
From: Dmitry Torokhov <dtor@chromium.org>
Date: Tue, 6 Aug 2019 09:22:25 -0700
Subject: [PATCH 40/63] Make sure makeguids helper is compiled for the host's
arch
Currently makeguids is compiled with the same flags/settings as the rest
of the package, which does not work in case of cross-compiles when arch
of the build host and the target host are different. Let's force
compiling for the native host arch to avoid this issue.
Note that this is not a full cross-compile solution as this does not
account for potential differences in host/target compilers (versions,
clang vs gcc, etc), but it removes one of the issue with package build
aborting due to invalid instruction on the host.
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
---
src/Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Makefile b/src/Makefile
index addfaa03c85..3729d2b8f35 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -52,7 +52,7 @@ include/efivar/efivar-guids.h : makeguids guids.txt
./makeguids guids.txt guids.bin names.bin \
guid-symbols.c include/efivar/efivar-guids.h
-makeguids : CPPFLAGS+=-DEFIVAR_BUILD_ENVIRONMENT
+makeguids : CPPFLAGS+=-DEFIVAR_BUILD_ENVIRONMENT -march=native
makeguids : LIBS=dl
makeguids : $(MAKEGUIDS_SOURCES)
makeguids : CCLD=$(CCLD_FOR_BUILD)
--
2.26.2

View File

@ -0,0 +1,49 @@
From 709afd3e2c946a765550992fa93adca8a88f2952 Mon Sep 17 00:00:00 2001
From: Pierre Bourdon <delroth@gmail.com>
Date: Tue, 13 Aug 2019 05:08:20 +0200
Subject: [PATCH 41/63] Makefile: sort $(wildcard) output for reproducibility
https://reproducible-builds.org/docs/stable-inputs/
This should fix reproducibility issues noticed on Debian[1] and NixOS[2]
[1] https://tests.reproducible-builds.org/debian/rb-pkg/buster/i386/diffoscope-results/efivar.html
[2] https://r13y.com/diff/b32a9d1c4159dab6aa15e873c0e5fc315ea2bdf545416d21d5b4a29f3c138727-3473019ee52f59732b13253b828bf2eb545384510f30db34413eb6c91dd3d047.html
---
src/Makefile | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/Makefile b/src/Makefile
index 3729d2b8f35..253d1f1d56c 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -15,7 +15,7 @@ TARGETS=$(LIBTARGETS) $(BINTARGETS) $(PCTARGETS)
STATICTARGETS=$(STATICLIBTARGETS) $(STATICBINTARGETS)
LIBEFIBOOT_SOURCES = crc32.c creator.c disk.c gpt.c loadopt.c path-helpers.c \
- linux.c $(wildcard linux-*.c)
+ linux.c $(sort $(wildcard linux-*.c))
LIBEFIBOOT_OBJECTS = $(patsubst %.c,%.o,$(LIBEFIBOOT_SOURCES))
LIBEFIVAR_SOURCES = crc32.c dp.c dp-acpi.c dp-hw.c dp-media.c dp-message.c \
efivarfs.c error.c export.c guid.c guids.S guid-symbols.c \
@@ -25,7 +25,7 @@ EFIVAR_SOURCES = efivar.c
GENERATED_SOURCES = include/efivar/efivar-guids.h guid-symbols.c
MAKEGUIDS_SOURCES = makeguids.c guid.c
ALL_SOURCES=$(LIBEFIBOOT_SOURCES) $(LIBEFIVAR_SOURCES) $(MAKEGUIDS_SOURCES) \
- $(wildcard include/efivar/*.h) $(GENERATED_SOURCES) $(EFIVAR_SOURCES)
+ $(sort $(wildcard include/efivar/*.h)) $(GENERATED_SOURCES) $(EFIVAR_SOURCES)
$(call deps-of,$(ALL_SOURCES)) : | deps
-include $(call deps-of,$(ALL_SOURCES))
@@ -103,7 +103,7 @@ install : all
$(INSTALL) -d -m 755 $(DESTDIR)$(PCDIR)
$(foreach x, $(PCTARGETS), $(INSTALL) -m 644 $(x) $(DESTDIR)$(PCDIR) ;)
$(INSTALL) -d -m 755 $(DESTDIR)$(INCLUDEDIR)/efivar
- $(foreach x, $(wildcard $(TOPDIR)/src/include/efivar/*.h), $(INSTALL) -m 644 $(x) $(DESTDIR)$(INCLUDEDIR)/efivar/$(notdir $(x));)
+ $(foreach x, $(sort $(wildcard $(TOPDIR)/src/include/efivar/*.h)), $(INSTALL) -m 644 $(x) $(DESTDIR)$(INCLUDEDIR)/efivar/$(notdir $(x));)
$(INSTALL) -d -m 755 $(DESTDIR)$(BINDIR)
$(foreach x, $(BINTARGETS), $(INSTALL) -m 755 $(x) $(DESTDIR)$(BINDIR);)
--
2.26.2

View File

@ -0,0 +1,22 @@
From 636aefebf32527dc8c7a592687a9bca3bdf028d2 Mon Sep 17 00:00:00 2001
From: Will Thompson <will@willthompson.co.uk>
Date: Thu, 29 Aug 2019 10:39:39 +0100
Subject: [PATCH 42/63] guids.txt: correct "sentinal" typo
---
src/guids.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/guids.txt b/src/guids.txt
index 2486255b26c..f2f0282b3be 100644
--- a/src/guids.txt
+++ b/src/guids.txt
@@ -1,4 +1,4 @@
-00000000-0000-0000-0000-000000000000 zero zeroed sentinal guid
+00000000-0000-0000-0000-000000000000 zero zeroed sentinel guid
093e0fae-a6c4-4f50-9f1b-d41e2b89c19a sha512 SHA-512
0abba7dc-e516-4167-bbf5-4d9d1c739416 fwupdate Linux Firmware Update Tool
0b6e5233-a65c-44c9-9407-d9ab83bfc8bd sha224 SHA-224
--
2.26.2

View File

@ -0,0 +1,73 @@
From f46b0d46545419e9db9853fc73919064f367ca34 Mon Sep 17 00:00:00 2001
From: Robert Bisewski <contact@ibiscybernetics.com>
Date: Wed, 25 Sep 2019 15:38:02 -0500
Subject: [PATCH 43/63] update manpage for efivar such that it reflects the
current options of the efivar util
---
docs/efivar.1 | 30 ++++++++++++++++++++++--------
1 file changed, 22 insertions(+), 8 deletions(-)
diff --git a/docs/efivar.1 b/docs/efivar.1
index e4c84bb1fe8..6a3036f5dcd 100644
--- a/docs/efivar.1
+++ b/docs/efivar.1
@@ -1,5 +1,4 @@
-.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.45.1.
-.TH EFIVAR "1" "June 2014" "efivar 0.10" "User Commands"
+.TH EFIVAR "1" "September 2019" "efivar 37" "User Commands"
.SH NAME
efivar \- Tool to manipulate UEFI variables
.SH SYNOPSIS
@@ -7,8 +6,8 @@ efivar \- Tool to manipulate UEFI variables
[\fI\,OPTION\/\fR...]
.SH DESCRIPTION
.TP
-\fB\-L\fR, \fB\-\-list\-guids\fR
-list guids efivar knows about
+\fB\-t\fR, \fB\-\-attributes=\fR<attributes>
+attributes to use on append
.TP
\fB\-l\fR, \fB\-\-list\fR
list current variables
@@ -16,6 +15,12 @@ list current variables
\fB\-p\fR, \fB\-\-print\fR
print variable specified by \fB\-\-name\fR
.TP
+\fB\-D\fR, \fB\-\-dmpstore\fR
+use DMPSTORE format when exporting
+.TP
+\fB\-d\fR, \fB\-\-print\-decimal\fR
+print variable in decimal format values specified by \fB\-\-name\fR
+.TP
\fB\-n\fR, \fB\-\-name=\fR<guid\-name>
variable to manipulate, in the form
8be4df61\-93ca\-11d2\-aa0d\-00e098032b8c\-Boot0000
@@ -23,11 +28,20 @@ variable to manipulate, in the form
\fB\-a\fR, \fB\-\-append\fR
append to variable specified by \fB\-\-name\fR
.TP
-\fB\-f\fR, \fB\-\-fromfile=\fR<file>
-use data from <file>
+\fB\-f\fR, \fB\-\-datafile=\fR<file>
+load or save variable contents from <file>
.TP
-\fB\-t\fR, \fB\-\-attributes=\fR<attributes>
-attributes to use on append
+\fB\-e\fR, \fB\-\-export=\fR<file>
+export variable to <file>
+.TP
+\fB\-i\fR, \fB\-\-import=\fR<file>
+import variable from <file>
+.TP
+\fB\-L\fR, \fB\-\-list\-guids\fR
+show internal guid list
+.TP
+\fB\-w\fR, \fB\-\-write\fR
+write to variable specified by \fB\-\-name\fR
.SS "Help options:"
.TP
\-?, \fB\-\-help\fR
--
2.26.2

View File

@ -0,0 +1,53 @@
From 150873b00fdb2d5aca2e7c66d0545ad55801409a Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Fri, 11 Oct 2019 10:44:53 -0400
Subject: [PATCH 44/63] Fix some 32-bit size_t format specifier errors
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/export.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/export.c b/src/export.c
index cfb021525ff..732b4bf30ad 100644
--- a/src/export.c
+++ b/src/export.c
@@ -149,7 +149,7 @@ overflow:
}
crc = efi_crc32(data, size - sizeof(uint32_t));
- debug("efi_crc32(%p, %lu) -> 0x%"PRIx32", expected 0x%"PRIx32,
+ debug("efi_crc32(%p, %zu) -> 0x%"PRIx32", expected 0x%"PRIx32,
data, size - sizeof(uint32_t), crc,
*(uint32_t*)(data + size - sizeof(uint32_t)));
@@ -282,7 +282,7 @@ efi_variable_import_efivar(uint8_t *data, size_t datasz, efi_variable_t **var_ou
}
crc = efi_crc32(data, datasz - sizeof(uint32_t));
- debug("efi_crc32(%p, %lu) -> 0x%"PRIx32", expected 0x%"PRIx32,
+ debug("efi_crc32(%p, %zu) -> 0x%"PRIx32", expected 0x%"PRIx32,
data, datasz - sizeof(uint32_t), crc,
*(uint32_t*)(data + datasz - sizeof(uint32_t)));
@@ -473,7 +473,7 @@ overflow:
ptr += var->data_size;
crc = efi_crc32(data, needed - sizeof(uint32_t));
- debug("efi_crc32(%p, %lu) -> 0x%"PRIx32,
+ debug("efi_crc32(%p, %zu) -> 0x%"PRIx32,
data, needed - sizeof(uint32_t), crc);
*(uint32_t *)ptr = crc;
@@ -611,7 +611,7 @@ overflow:
ptr += var->data_size;
crc = efi_crc32(data, needed - sizeof(uint32_t));
- debug("efi_crc32(%p, %lu) -> 0x%"PRIx32,
+ debug("efi_crc32(%p, %zu) -> 0x%"PRIx32,
data, needed - sizeof(uint32_t), crc);
*(uint32_t *)ptr = crc;
--
2.26.2

View File

@ -0,0 +1,34 @@
From aae6a63e34320299a3707a9a468ab78333230283 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Fri, 11 Oct 2019 10:52:12 -0400
Subject: [PATCH 45/63] Make the top level makefile not parallelize.
Right now if you run:
make
make -j9 clean all
"clean" and "all" will run in parallel, and "all" will often finish
before "clean" will. This is obviously wrong.
This patch adds .NOTPARALLEL: at the top level, so none of the top-level
targets will parallelize, because we really never want that.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
index 2d134ea9d6f..61b79a60369 100644
--- a/Makefile
+++ b/Makefile
@@ -83,4 +83,4 @@ archive: abicheck bumpver abidw tag efivar.spec
@rm -rf /tmp/efivar-$(GITTAG)
@echo "The archive is in efivar-$(GITTAG).tar.bz2"
-
+.NOTPARALLEL:
--
2.26.2

View File

@ -0,0 +1,25 @@
From 8922c5692eebfe05e59bd5c4de464f3db10a69f3 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Fri, 11 Oct 2019 14:30:42 -0400
Subject: [PATCH 46/63] guids: add auto_created_boot_option
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/guids.txt | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/guids.txt b/src/guids.txt
index f2f0282b3be..95d93c0df74 100644
--- a/src/guids.txt
+++ b/src/guids.txt
@@ -18,6 +18,7 @@
721c8b66-426c-4e86-8e99-3457c46ab0b9 lenovo_setup Lenovo Firmware Setup
77fa9abd-0359-4d32-bd60-28f4e78f784b microsoft Microsoft
7FACC7B6-127F-4E9C-9C5D-080F98994345 lenovo_2 Lenovo
+8108ac4e-9f11-4d59-850e-e21a522c59b2 auto_created_boot_option Automatically Created Boot Option
826ca512-cf10-4ac9-b187-be01496631bd sha1 SHA-1
82988420-7467-4490-9059-feb448dd1963 lenovo_me_config Lenovo ME Configuration Menu
8be4df61-93ca-11d2-aa0d-00e098032b8c global EFI Global Variable
--
2.26.2

View File

@ -0,0 +1,260 @@
From 1249545850373e9c1717eab077a74b87069e90ba Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Thu, 10 Oct 2019 13:52:22 -0400
Subject: [PATCH 47/63] Move our infrastructure makefiles out of the topdir.
No sense in leaving all this cluttering up what's usually my working
directory...
Signed-off-by: Peter Jones <pjones@redhat.com>
---
Makefile | 22 ++++++++++----------
docs/Makefile | 11 +++++-----
src/Android.mk | 2 +-
src/Makefile | 11 +++++-----
Make.coverity => src/include/coverity.mk | 0
Make.defaults => src/include/defaults.mk | 2 +-
Make.deprecated => src/include/deprecated.mk | 0
src/{Make.deps => include/deps.mk} | 7 +++----
gcc.specs => src/include/gcc.specs | 0
Make.rules => src/include/rules.mk | 2 +-
Make.scan-build => src/include/scan-build.mk | 0
Make.version => src/include/version.mk | 0
src/test/Makefile | 7 +++----
tests/Makefile | 3 +--
14 files changed, 31 insertions(+), 36 deletions(-)
rename Make.coverity => src/include/coverity.mk (100%)
rename Make.defaults => src/include/defaults.mk (97%)
rename Make.deprecated => src/include/deprecated.mk (100%)
rename src/{Make.deps => include/deps.mk} (65%)
rename gcc.specs => src/include/gcc.specs (100%)
rename Make.rules => src/include/rules.mk (98%)
rename Make.scan-build => src/include/scan-build.mk (100%)
rename Make.version => src/include/version.mk (100%)
diff --git a/Makefile b/Makefile
index 61b79a60369..7a4ac8c62e4 100644
--- a/Makefile
+++ b/Makefile
@@ -1,15 +1,15 @@
-TOPDIR = $(shell echo $$PWD)
+export TOPDIR = $(realpath $(dir $(firstword $(MAKEFILE_LIST))))
-include $(TOPDIR)/Make.deprecated
-include $(TOPDIR)/Make.version
-include $(TOPDIR)/Make.rules
-include $(TOPDIR)/Make.defaults
-include $(TOPDIR)/Make.coverity
-include $(TOPDIR)/Make.scan-build
+include $(TOPDIR)/src/include/deprecated.mk
+include $(TOPDIR)/src/include/version.mk
+include $(TOPDIR)/src/include/rules.mk
+include $(TOPDIR)/src/include/defaults.mk
+include $(TOPDIR)/src/include/coverity.mk
+include $(TOPDIR)/src/include/scan-build.mk
SUBDIRS := src docs
-all : | efivar.spec Make.version
+all : | efivar.spec src/include/version.mk
all :
@set -e ; for x in $(SUBDIRS) ; do \
$(MAKE) -C $$x $@ ; \
@@ -43,7 +43,7 @@ a :
GITTAG = $(shell bash -c "echo $$(($(VERSION) + 1))")
-efivar.spec : | Makefile Make.version
+efivar.spec : | Makefile src/include/version.mk
clean :
@set -e ; for x in $(SUBDIRS) ; do \
@@ -66,8 +66,8 @@ test-archive: abicheck efivar.spec
@echo "The archive is in efivar-$(GITTAG).tar.bz2"
bumpver :
- @echo VERSION=$(GITTAG) > Make.version
- @git add Make.version
+ @echo VERSION=$(GITTAG) > src/include/version.mk
+ @git add src/include/version.mk
git commit -m "Bump version to $(GITTAG)" -s
tag:
diff --git a/docs/Makefile b/docs/Makefile
index 0f610d9d9a9..2f6fc89b694 100644
--- a/docs/Makefile
+++ b/docs/Makefile
@@ -1,10 +1,9 @@
SRCDIR = $(realpath .)
-TOPDIR = $(realpath ..)
-include $(TOPDIR)/Make.deprecated
-include $(TOPDIR)/Make.version
-include $(TOPDIR)/Make.rules
-include $(TOPDIR)/Make.defaults
+include $(TOPDIR)/src/include/deprecated.mk
+include $(TOPDIR)/src/include/version.mk
+include $(TOPDIR)/src/include/rules.mk
+include $(TOPDIR)/src/include/defaults.mk
MAN1TARGETS = efivar.1
MAN3TARGETS = efi_append_variable.3 \
@@ -51,4 +50,4 @@ install :
.PHONY: all clean install
-include $(TOPDIR)/Make.rules
+include $(TOPDIR)/src/include/rules.mk
diff --git a/src/Android.mk b/src/Android.mk
index bf6cfb2e91b..ea6ee3f9432 100644
--- a/src/Android.mk
+++ b/src/Android.mk
@@ -46,7 +46,7 @@ LIBEFIVAR_SOURCES := \
lib.c \
vars.c
-include $(LOCAL_PATH)/../Make.version
+include $(LOCAL_PATH)/../version.mk
LOCAL_SRC_FILES := $(LIBEFIBOOT_SOURCES) $(LIBEFIVAR_SOURCES)
LOCAL_CFLAGS := -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -std=gnu11 -DLIBEFIVAR_VERSION=$(VERSION)
diff --git a/src/Makefile b/src/Makefile
index 253d1f1d56c..e5f10d4c7bf 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,10 +1,9 @@
SRCDIR = $(realpath .)
-TOPDIR = $(realpath ..)
-include $(TOPDIR)/Make.deprecated
-include $(TOPDIR)/Make.version
-include $(TOPDIR)/Make.rules
-include $(TOPDIR)/Make.defaults
+include $(TOPDIR)/src/include/deprecated.mk
+include $(TOPDIR)/src/include/version.mk
+include $(TOPDIR)/src/include/rules.mk
+include $(TOPDIR)/src/include/defaults.mk
LIBTARGETS=libefivar.so libefiboot.so
STATICLIBTARGETS=libefivar.a libefiboot.a
@@ -84,7 +83,7 @@ libefiboot.so : LIBS=efivar
libefiboot.so : MAP=libefiboot.map
deps : $(ALL_SOURCES)
- @$(MAKE) -f $(SRCDIR)/Make.deps deps SOURCES="$(ALL_SOURCES)"
+ @$(MAKE) -f $(SRCDIR)/include/deps.mk deps SOURCES="$(ALL_SOURCES)"
clean :
@rm -rfv *~ *.o *.a *.E *.so *.so.* *.pc *.bin .*.d *.map \
diff --git a/Make.coverity b/src/include/coverity.mk
similarity index 100%
rename from Make.coverity
rename to src/include/coverity.mk
diff --git a/Make.defaults b/src/include/defaults.mk
similarity index 97%
rename from Make.defaults
rename to src/include/defaults.mk
index 36e922f5ba7..7290187ceba 100644
--- a/Make.defaults
+++ b/src/include/defaults.mk
@@ -34,7 +34,7 @@ CPPFLAGS += -DLIBEFIVAR_VERSION=$(VERSION)
clang_cflags = -D_GNU_SOURCE -std=gnu11 -Wno-address-of-packed-member \
-funsigned-char -Wall -Wno-nonnull-compare \
-Werror -Wno-error=cpp
-gcc_cflags = -specs=$(TOPDIR)/gcc.specs
+gcc_cflags = -specs=$(TOPDIR)/src/include/gcc.specs
cflags = $(CFLAGS) -I${TOPDIR}/src/include/ \
$(if $(findstring clang,$(CC)),$(clang_cflags),) \
$(if $(findstring ccc-analyzer,$(CC)),$(clang_cflags),) \
diff --git a/Make.deprecated b/src/include/deprecated.mk
similarity index 100%
rename from Make.deprecated
rename to src/include/deprecated.mk
diff --git a/src/Make.deps b/src/include/deps.mk
similarity index 65%
rename from src/Make.deps
rename to src/include/deps.mk
index c3df9e46559..a797d1bdbf5 100644
--- a/src/Make.deps
+++ b/src/include/deps.mk
@@ -1,11 +1,10 @@
SRCDIR = $(realpath .)
-TOPDIR = $(realpath ..)
all : deps
-include $(TOPDIR)/Make.version
-include $(TOPDIR)/Make.rules
-include $(TOPDIR)/Make.defaults
+include $(TOPDIR)/src/include/version.mk
+include $(TOPDIR)/src/include/rules.mk
+include $(TOPDIR)/src/include/defaults.mk
.%.d : %.c
$(CC) $(cflags) $(CPPFLAGS) -MM -MG -MF $@ $^
diff --git a/gcc.specs b/src/include/gcc.specs
similarity index 100%
rename from gcc.specs
rename to src/include/gcc.specs
diff --git a/Make.rules b/src/include/rules.mk
similarity index 98%
rename from Make.rules
rename to src/include/rules.mk
index 042585b533c..1783dda573b 100644
--- a/Make.rules
+++ b/src/include/rules.mk
@@ -2,7 +2,7 @@ default : all
.PHONY: default all clean install test
-include $(TOPDIR)/Make.version
+include $(TOPDIR)/src/include/version.mk
%.a :
$(AR) -cvqs $@ $^
diff --git a/Make.scan-build b/src/include/scan-build.mk
similarity index 100%
rename from Make.scan-build
rename to src/include/scan-build.mk
diff --git a/Make.version b/src/include/version.mk
similarity index 100%
rename from Make.version
rename to src/include/version.mk
diff --git a/src/test/Makefile b/src/test/Makefile
index 4c2a18f8426..df16c7a5f3b 100644
--- a/src/test/Makefile
+++ b/src/test/Makefile
@@ -1,8 +1,7 @@
SRCDIR = $(realpath .)
-TOPDIR = $(realpath $(SRCDIR)/../..)
-include $(TOPDIR)/Make.defaults
-include $(TOPDIR)/Make.version
+include $(TOPDIR)/src/include/defaults.mk
+include $(TOPDIR)/src/include/version.mk
ccldflags += -L$(TOPDIR)/src/ -Wl,-rpath=$(TOPDIR)/src/
LIBS=efivar
@@ -22,4 +21,4 @@ tester :: tester.o
.PHONY: all clean install test
-include $(TOPDIR)/Make.rules
+include $(TOPDIR)/src/include/rules.mk
diff --git a/tests/Makefile b/tests/Makefile
index 5e0c604e355..6f233d53fd1 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -6,8 +6,7 @@
all: clean test0 test1 test2 test3 test4
GRUB_PREFIX ?= grub2
-TOPDIR ?= ..
-EFIVAR ?= ../src/efivar
+EFIVAR ?= $(TOPDIR)/src/efivar
clean:
@rm -f *.result.env *.result.var
--
2.26.2

View File

@ -0,0 +1,33 @@
From 9fa2e902ad0581b57e6e387ec629a70b16a26095 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Thu, 10 Oct 2019 13:52:46 -0400
Subject: [PATCH 48/63] Make CC_FOR_BUILD and CCLD_FOR_BUILD override
HOSTCC/HOSTCCLD
---
src/include/deprecated.mk | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/src/include/deprecated.mk b/src/include/deprecated.mk
index a31b080dbf6..00abc8c8226 100644
--- a/src/include/deprecated.mk
+++ b/src/include/deprecated.mk
@@ -38,5 +38,15 @@ ifneq ($(origin bindir),undefined)
override BINDIR = $(bindir)
endif
endif
+ifneq ($(origin CC_FOR_BUILD),undefined)
+ ifeq ($(origin HOSTCC),file)
+ override HOSTCC = $(CC_FOR_BUILD)
+ endif
+endif
+ifneq ($(origin CCLD_FOR_BUILD),undefined)
+ ifeq ($(origin HOSTCCLD),file)
+ override HOSTCCLD = $(CCLD_FOR_BUILD)
+ endif
+endif
# vim:ft=make
--
2.26.2

View File

@ -0,0 +1,299 @@
From 88663428b13a281d0b759718d7c8faa454b3409a Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Thu, 10 Oct 2019 15:45:10 -0400
Subject: [PATCH 49/63] Rework some makefile bits to make overriding some
options simpler.
This reworks a lot of defaults.mk to make some variables more regularly
partially overridden on the command line, making e.g. suppression of
-Werror easier when warranted. It also makes having per-compiler
versions of each thing simpler.
The following variables can be overridden, though in some cases only
partially:
name kind of things in it
COMPILER gcc
CROSS_COMPILE arm-linux-gnu-
CC $(CROSS_COMPILE)$(COMPILER)
DEBUGINFO -g
OPTIMIZE -O2 -flto
WARNINGS -Wfoo -Wno-bar
ERRORS -Werror -Wno-error=cpp
CPPFLAGS -D and -I
CFLAGS $(OPTIMIZE) $(DEBUGINFO) $(WARNINGS) $(ERRORS)
LDFLAGS linker options (add-only)
CCLDFLAGS -Wl, prefixed linker options (add-only and it's
normally machine generated from LDFLAGS
HOSTCC $(COMPILER)
HOST_CPPFLAGS $(CPPFLAGS) (add-only)
HOST_CFLAGS $(CFLAGS) (add-only)
HOST_CCLDFLAGS $(CCLDFLAGS) (add-only)
This resolves issue #31
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/Makefile | 5 ++-
src/include/defaults.mk | 83 +++++++++++++++++++++++++++--------------
src/include/gcc.specs | 11 +-----
src/include/rules.mk | 51 +++++++++++++------------
src/test/Makefile | 2 +-
5 files changed, 87 insertions(+), 65 deletions(-)
diff --git a/src/Makefile b/src/Makefile
index e5f10d4c7bf..1d0e217c89b 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -51,10 +51,11 @@ include/efivar/efivar-guids.h : makeguids guids.txt
./makeguids guids.txt guids.bin names.bin \
guid-symbols.c include/efivar/efivar-guids.h
-makeguids : CPPFLAGS+=-DEFIVAR_BUILD_ENVIRONMENT -march=native
+makeguids : CPPFLAGS=$(HOST_CPPFLAGS)
makeguids : LIBS=dl
+makeguids : CCLD=$(HOSTCCLD)
+makeguids : CFLAGS=$(HOST_CFLAGS)
makeguids : $(MAKEGUIDS_SOURCES)
-makeguids : CCLD=$(CCLD_FOR_BUILD)
guids.o : guids.S | guids.bin names.bin
diff --git a/src/include/defaults.mk b/src/include/defaults.mk
index 7290187ceba..df738feddea 100644
--- a/src/include/defaults.mk
+++ b/src/include/defaults.mk
@@ -8,19 +8,63 @@ BINDIR ?= $(EXEC_PREFIX)/bin
PCDIR ?= $(LIBDIR)/pkgconfig
DESTDIR ?=
-INSTALL ?= install
CROSS_COMPILE ?=
COMPILER ?= gcc
-PKG_CONFIG = $(shell if [ -e "$$(env $(CROSS_COMPILE)pkg-config 2>&1)" ]; then echo $(CROSS_COMPILE)pkg-config ; else echo pkg-config ; fi)
-CC_FOR_BUILD ?= cc
-CC := $(if $(filter default,$(origin CC)),$(CROSS_COMPILE)$(COMPILER),$(CC))
-CCLD_FOR_BUILD ?= $(CC_FOR_BUILD)
-CCLD := $(if $(filter undefined,$(origin CCLD)),$(CC),$(CCLD))
+$(call set-if-undefined,CC,$(CROSS_COMPILE)$(COMPILER))
+$(call set-if-undefined,CCLD,$(CC))
+$(call set-if-undefined,HOSTCC,$(COMPILER))
+$(call set-if-undefined,HOSTCCLD,$(HOSTCC))
+
OPTIMIZE ?= -O2 -flto
-CFLAGS ?= $(OPTIMIZE) -g3
-CFLAGS := $(CFLAGS)
+DEBUGINFO ?= -g3
+WARNINGS_GCC ?= -Wmaybe-uninitialized \
+ -Wno-nonnull-compare
+WARNINGS_CCC_ANALYZER ?= $(WARNINGS_GCC)
+WARNINGS ?= -Wall -Wextra \
+ -Wno-address-of-packed-member \
+ $(call family,WARNINGS)
+ERRORS ?= -Werror -Wno-error=cpp $(call family,ERRORS)
+CPPFLAGS ?=
+override _CPPFLAGS := $(CPPFLAGS)
+override CPPFLAGS = $(_CPPFLAGS) -DLIBEFIVAR_VERSION=$(VERSION) \
+ -D_GNU_SOURCE \
+ -I$(TOPDIR)/src/include/
+CFLAGS ?= $(OPTIMIZE) $(DEBUGINFO) $(WARNINGS) $(ERRORS)
+CFLAGS_GCC ?= -specs=$(TOPDIR)/src/include/gcc.specs \
+ -fno-merge-constants
+override _CFLAGS := $(CFLAGS)
+override CFLAGS = $(_CFLAGS) \
+ -std=gnu11 \
+ -funsigned-char \
+ -fvisibility=hidden \
+ $(call family,CFLAGS) \
+ $(call pkg-config-cflags)
+LDFLAGS_CLANG ?= --fatal-warnings -pie -z relro
LDFLAGS ?=
-LDFLAGS := $(LDFLAGS)
+override _LDFLAGS := $(LDFLAGS)
+override LDFLAGS = $(_LDFLAGS) \
+ --add-needed \
+ --build-id \
+ --no-allow-shlib-undefined \
+ --no-undefined-version \
+ -z now \
+ -z muldefs \
+ $(call family,LDFLAGS)
+CCLDFLAGS ?=
+override _CCLDFLAGS := $(CCLDFLAGS)
+override CCLDFLAGS = $(CFLAGS) -L. $(_CCLDFLAGS) \
+ $(call add-prefix,-Wl,$(LDFLAGS)) \
+ $(call pkg-config-ccldflags)
+HOST_CPPFLAGS ?= $(CPPFLAGS)
+override _HOST_CPPFLAGS := $(HOST_CPPFLAGS)
+override HOST_CPPFLAGS = $(_HOST_CPPFLAGS) \
+ -DEFIVAR_BUILD_ENVIRONMENT -march=native
+HOST_CFLAGS ?= $(CFLAGS)
+override _HOST_CFLAGS := $(HOST_CFLAGS)
+override HOST_CFLAGS = $(_HOST_CFLAGS)
+
+PKG_CONFIG = $(shell if [ -e "$$(env $(CROSS_COMPILE)pkg-config 2>&1)" ]; then echo $(CROSS_COMPILE)pkg-config ; else echo pkg-config ; fi)
+INSTALL ?= install
AR := $(CROSS_COMPILE)$(COMPILER)-ar
NM := $(CROSS_COMPILE)$(COMPILER)-nm
RANLIB := $(CROSS_COMPILE)$(COMPILER)-ranlib
@@ -29,26 +73,7 @@ ABIDIFF := abidiff
PKGS =
-CPPFLAGS += -DLIBEFIVAR_VERSION=$(VERSION)
-
-clang_cflags = -D_GNU_SOURCE -std=gnu11 -Wno-address-of-packed-member \
- -funsigned-char -Wall -Wno-nonnull-compare \
- -Werror -Wno-error=cpp
-gcc_cflags = -specs=$(TOPDIR)/src/include/gcc.specs
-cflags = $(CFLAGS) -I${TOPDIR}/src/include/ \
- $(if $(findstring clang,$(CC)),$(clang_cflags),) \
- $(if $(findstring ccc-analyzer,$(CC)),$(clang_cflags),) \
- $(if $(findstring gcc,$(CC)),$(gcc_cflags),) \
- $(call pkg-config-cflags)
-clang_ccldflags =
-gcc_ccldflags =
-ccldflags = $(cflags) -L. $(CCLDFLAGS) $(LDFLAGS) \
- -Wl,-z,muldefs \
- $(if $(findstring clang,$(CCLD)),$(clang_ccldflags),) \
- $(if $(findstring ccc-analyzer,$(CCLD)),$(clang_ccldflags),) \
- $(if $(findstring gcc,$(CCLD)),$(gcc_ccldflags),) \
- $(call pkg-config-ldflags)
-SOFLAGS=-shared
+SOFLAGS=-shared $(call family,SOFLAGS)
LDLIBS=$(foreach lib,$(LIBS),-l$(lib)) $(call pkg-config-ldlibs)
COMMIT_ID=$(shell git log -1 --pretty=%H 2>/dev/null || echo master)
diff --git a/src/include/gcc.specs b/src/include/gcc.specs
index 9d2b145ee6e..ef28e2bb51a 100644
--- a/src/include/gcc.specs
+++ b/src/include/gcc.specs
@@ -1,14 +1,5 @@
-*cpp:
-+ -D_GNU_SOURCE
-
-*efivar_cpp_options:
- -Wall -Wno-nonnull-compare -Werror -Wno-error=cpp -std=gnu11 -Wextra -funsigned-char
-
-*cpp_options:
-+ %(efivar_cpp_options)
-
*cc1_options:
-+ %(efivar_cpp_options) -Wmaybe-uninitialized -fno-merge-constants -funsigned-char -fvisibility=hidden %{!r:%{!fpie:%{!fPIE:%{!fpic:%{!fPIC:%{!fno-pic:-fPIE}}}}}} -grecord-gcc-switches
++ %{!r:%{!fpie:%{!fPIE:%{!fpic:%{!fPIC:%{!fno-pic:-fPIE}}}}}} -grecord-gcc-switches
*self_spec:
+ %{!shared:%{!static:%{!r:-pie}}} %{static:-Wl,-no-fatal-warnings -Wl,-static -static -Wl,-z,relro,-z,now} -grecord-gcc-switches
diff --git a/src/include/rules.mk b/src/include/rules.mk
index 1783dda573b..ff0ff4ef61b 100644
--- a/src/include/rules.mk
+++ b/src/include/rules.mk
@@ -4,20 +4,32 @@ default : all
include $(TOPDIR)/src/include/version.mk
+comma:= ,
+empty:=
+space:= $(empty) $(empty)
+
+set-if-undefined = $(call eval,$(1) := $(if $(filter default undefined,$(origin $(1))),$(2),$($(1))))
+add-prefix = $(subst $(space),$(empty),$(1)$(foreach x,$(2),$(comma)$(x)))
+
+FAMILY_SUFFIXES = $(if $(findstring clang,$(CC)),CLANG,) \
+ $(if $(findstring ccc-analyzer,$(CC)),CCC_ANALYZER,) \
+ $(if $(findstring gcc,$(CC)),GCC,)
+family = $(foreach FAMILY_SUFFIX,$(FAMILY_SUFFIXES),$($(1)_$(FAMILY_SUFFIX)))
+
%.a :
$(AR) -cvqs $@ $^
% : %.c
% : %.c
- $(CCLD) $(ccldflags) $(CPPFLAGS) -o $@ $^ $(LDLIBS)
+ $(CCLD) $(CCLDFLAGS) $(CPPFLAGS) -o $@ $^ $(LDLIBS)
-%-static : ccldflags+=-static
+%-static : CCLDFLAGS+=-static
%-static : %.c
- $(CCLD) $(ccldflags) $(CPPFLAGS) -o $@ $^ $(LDLIBS)
+ $(CCLD) $(CCLDFLAGS) $(CPPFLAGS) -o $@ $^ $(LDLIBS)
%.so :
- $(CCLD) $(ccldflags) $(CPPFLAGS) $(SOFLAGS) \
+ $(CCLD) $(CCLDFLAGS) $(CPPFLAGS) $(SOFLAGS) \
-Wl,-soname,$@.1 \
-Wl,--version-script=$(MAP) \
-o $@ $^ $(LDLIBS)
@@ -35,22 +47,22 @@ include $(TOPDIR)/src/include/version.mk
$<
%.o : %.c
- $(CC) $(cflags) -fPIC $(CPPFLAGS) -c -o $@ $(filter %.c %.o %.S,$^)
+ $(CC) $(CFLAGS) -fPIC $(CPPFLAGS) -c -o $@ $(filter %.c %.o %.S,$^)
%.static.o : %.c
- $(CC) $(cflags) -fPIE $(CPPFLAGS) -c -o $@ $(filter %.c %.o %.S,$^)
+ $(CC) $(CFLAGS) -fPIE $(CPPFLAGS) -c -o $@ $(filter %.c %.o %.S,$^)
%.o : %.S
- $(CC) $(cflags) -fPIC $(CPPFLAGS) -c -o $@ $(filter %.c %.o %.S,$^)
+ $(CC) $(CFLAGS) -fPIC $(CPPFLAGS) -c -o $@ $(filter %.c %.o %.S,$^)
%.static.o : %.S
- $(CC) $(cflags) -fPIE $(CPPFLAGS) -c -o $@ $(filter %.c %.o %.S,$^)
+ $(CC) $(CFLAGS) -fPIE $(CPPFLAGS) -c -o $@ $(filter %.c %.o %.S,$^)
%.S: %.c
- $(CC) $(cflags) $(CPPFLAGS) -S $< -o $@
+ $(CC) $(CFLAGS) $(CPPFLAGS) -S $< -o $@
%.E: %.c
- $(CC) $(cflags) $(CPPFLAGS) -E $< -o $@
+ $(CC) $(CFLAGS) $(CPPFLAGS) -E $< -o $@
%.c : %.h
@@ -71,20 +83,13 @@ endef
%.map : %.map.in
@$(call substitute-version,$<,$@)
-pkg-config-cflags = \
- $(shell if [ -n "$(PKGS)" ]; then $(PKG_CONFIG) --cflags $(PKGS); fi)
-pkg-config-ldflags = \
- $(shell if [ -n "$(PKGS)" ]; then $(PKG_CONFIG) --libs-only-L --libs-only-other $(PKGS) ; fi)
-pkg-config-ldlibs = \
- $(shell if [ -n "$(PKGS)" ]; then $(PKG_CONFIG) --libs-only-l $(PKGS) ; fi)
+pkg-config-cflags = $(if $(PKGS),$(shell $(PKG_CONFIG) --cflags $(PKGS)))
+pkg-config-ccldflags = $(if $(PKGS),$(shell $(PKG_CONFIG) --libs-only-L --libs-only-other $(PKGS)))
+pkg-config-ldlibs = $(if $(PKGS),$(shell $(PKG_CONFIG) --libs-only-l $(PKGS)))
-define deps-of
- $(foreach src,$(filter %.c,$(1)),$(patsubst %.c,.%.d,$(src))) \
- $(foreach src,$(filter %.S,$(1)),$(patsubst %.S,.%.d,$(src)))
-endef
+deps-of = $(foreach src,$(filter %.c,$(1)),$(patsubst %.c,.%.d,$(src))) \
+ $(foreach src,$(filter %.S,$(1)),$(patsubst %.S,.%.d,$(src)))
-define get-config
-$(shell git config --local --get "efivar.$(1)")
-endef
+get-config = $(shell git config --local --get "efivar.$(1)")
# vim:ft=make
diff --git a/src/test/Makefile b/src/test/Makefile
index df16c7a5f3b..7a2aa496b48 100644
--- a/src/test/Makefile
+++ b/src/test/Makefile
@@ -3,7 +3,7 @@ SRCDIR = $(realpath .)
include $(TOPDIR)/src/include/defaults.mk
include $(TOPDIR)/src/include/version.mk
-ccldflags += -L$(TOPDIR)/src/ -Wl,-rpath=$(TOPDIR)/src/
+CCLDFLAGS += -L$(TOPDIR)/src/ -Wl,-rpath=$(TOPDIR)/src/
LIBS=efivar
all : tester
--
2.26.2

View File

@ -0,0 +1,55 @@
From 1b5da030b19e6f7f086ef2f1719159951c574fa7 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Tue, 15 Oct 2019 16:49:54 -0400
Subject: [PATCH 50/63] Make: add -Wno-missing-field-initializers
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Ritchie wrote in '84:
If there are fewer initializers in the list than there are members of
the aggregate, then the aggregate is padded with 0's.
c99 §6.7.8 and c11 §6.7.9 each say:
10 If an object that has automatic storage duration is not initialized
explicitly, its value is indeterminate. If an object that has static
storage duration is not initialized explicitly, then:
— if it has pointer type, it is initialized to a null pointer;
— if it has arithmetic type, it is initialized to (positive or
unsigned) zero;
— if it is an aggregate, every member is initialized (recursively)
according to these rules;
— if it is a union, the first named member is initialized
(recursively) according to these rules.
...
21 If there are fewer initializers in a brace-enclosed list than there
are elements or members of an aggregate, or fewer characters in a
string literal used to initialize an array of known size than there
are elements in the array, the remainder of the aggregate shall be
initialized implicitly the same as objects that have static storage
duration.
This warning is thoroughly pointless.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/include/defaults.mk | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/include/defaults.mk b/src/include/defaults.mk
index df738feddea..af6a41a9824 100644
--- a/src/include/defaults.mk
+++ b/src/include/defaults.mk
@@ -22,6 +22,7 @@ WARNINGS_GCC ?= -Wmaybe-uninitialized \
WARNINGS_CCC_ANALYZER ?= $(WARNINGS_GCC)
WARNINGS ?= -Wall -Wextra \
-Wno-address-of-packed-member \
+ -Wno-missing-field-initializers \
$(call family,WARNINGS)
ERRORS ?= -Werror -Wno-error=cpp $(call family,ERRORS)
CPPFLAGS ?=
--
2.26.2

View File

@ -0,0 +1,78 @@
From f9797c91e190fc53ce997beb1e7c2a140abfd665 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Tue, 15 Oct 2019 16:27:39 -0400
Subject: [PATCH 51/63] debug(): don't write newlines to memfd
If we know our log will only be seen by strace, the newlines don't add
anything to the strings but clutter.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/error.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/src/error.c b/src/error.c
index 083de15e984..8ceba31dd55 100644
--- a/src/error.c
+++ b/src/error.c
@@ -27,6 +27,7 @@
#include <stdio.h>
#include <string.h>
#include <sys/mman.h>
+#include <sys/random.h>
#include <unistd.h>
#include "efiboot.h"
@@ -166,6 +167,7 @@ efi_error_pop(void)
static int efi_verbose;
static FILE *efi_errlog, *efi_dbglog;
static int efi_dbglog_fd = -1;
+static intptr_t efi_dbglog_cookie;
static int log_level;
static char efi_dbglog_buf[4096];
@@ -176,7 +178,7 @@ efi_set_loglevel(int level)
}
static ssize_t
-dbglog_write(void *cookie UNUSED, const char *buf, size_t size)
+dbglog_write(void *cookie, const char *buf, size_t size)
{
FILE *log = efi_errlog ? efi_errlog : stderr;
ssize_t ret = size;
@@ -185,6 +187,11 @@ dbglog_write(void *cookie UNUSED, const char *buf, size_t size)
ret = fwrite(buf, 1, size, log);
} else if (efi_dbglog_fd >= 0) {
lseek(efi_dbglog_fd, 0, SEEK_SET);
+ if ((intptr_t)cookie != 0 &&
+ (intptr_t)cookie == efi_dbglog_cookie &&
+ size > 0 &&
+ buf[size-1] == '\n')
+ size -= 1;
ret = write(efi_dbglog_fd, buf, size);
}
return ret;
@@ -248,6 +255,7 @@ efi_error_fini(void)
static void CONSTRUCTOR
efi_error_init(void)
{
+ ssize_t bytes;
cookie_io_functions_t io_funcs = {
.write = dbglog_write,
.seek = dbglog_seek,
@@ -258,7 +266,11 @@ efi_error_init(void)
if (efi_dbglog_fd == -1)
return;
- efi_dbglog = fopencookie(NULL, "a", io_funcs);
+ bytes = getrandom(&efi_dbglog_cookie, sizeof(efi_dbglog_cookie), 0);
+ if (bytes < (ssize_t)sizeof(efi_dbglog_cookie))
+ efi_dbglog_cookie = 0;
+
+ efi_dbglog = fopencookie((void *)efi_dbglog_cookie, "a", io_funcs);
if (efi_dbglog)
setvbuf(efi_dbglog, efi_dbglog_buf, _IOLBF,
sizeof(efi_dbglog_buf));
--
2.26.2

View File

@ -0,0 +1,314 @@
From f1d09655cbc47a738410b601ac1f7ddde2d72b26 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Wed, 2 Oct 2019 16:59:14 -0400
Subject: [PATCH 52/63] sysfs parsing: add some more debugging output
This adds highlights under the things we've found when searching, like:
linux-pci.c:66 parse_pci(): searching for 0000:00:00.0/
linux-pci.c:69 parse_pci(): current:'0000:00:1d.4/0000:6e:00.0/nvme/nvme0/nvme0n1' rc:4 pos0:0 pos1:13
linux-pci.c:70 parse_pci(): ^^^^^^^^^^^^^
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/linux-acpi-root.c | 3 +++
src/linux-emmc.c | 1 +
src/linux-md.c | 1 +
src/linux-nvme.c | 1 +
src/linux-pci-root.c | 2 ++
src/linux-pci.c | 1 +
src/linux-pmem.c | 2 ++
src/linux-sata.c | 4 ++++
src/linux-scsi.c | 8 ++++++++
src/linux-soc-root.c | 2 ++
src/linux-virtblk.c | 1 +
src/util.h | 35 +++++++++++++++++++++++++++++++++++
12 files changed, 61 insertions(+)
diff --git a/src/linux-acpi-root.c b/src/linux-acpi-root.c
index f48d4be9ac6..5ed4d7f5b86 100644
--- a/src/linux-acpi-root.c
+++ b/src/linux-acpi-root.c
@@ -63,6 +63,7 @@ parse_acpi_root(struct device *dev, const char *current, const char *root UNUSED
*/
rc = sscanf(devpart, "../../devices/platform/%n", &pos);
debug("devpart:\"%s\" rc:%d pos:%d", devpart, rc, pos);
+ dbgmk(" ", pos);
if (rc != 0 || pos < 1)
return 0;
devpart += pos;
@@ -97,6 +98,7 @@ parse_acpi_root(struct device *dev, const char *current, const char *root UNUSED
pos -= 4;
debug("devpart:\"%s\" rc:%d pos:%d", devpart, rc, pos);
+ dbgmk(" ", pos);
acpi_header = strndupa(devpart, pos);
if (!acpi_header)
return 0;
@@ -114,6 +116,7 @@ parse_acpi_root(struct device *dev, const char *current, const char *root UNUSED
}
debug("devpart:\"%s\" parsed:%04hx:%02hhx pos:%d rc:%d",
devpart, pad0, pad1, pos, rc);
+ dbgmk(" ", pos);
devpart += pos;
diff --git a/src/linux-emmc.c b/src/linux-emmc.c
index 8af316a1723..59ef8e7524d 100644
--- a/src/linux-emmc.c
+++ b/src/linux-emmc.c
@@ -58,6 +58,7 @@ 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);
+ dbgmk(" ", pos0, pos1);
/*
* 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 3d5975d8195..1d7bd3195c0 100644
--- a/src/linux-md.c
+++ b/src/linux-md.c
@@ -51,6 +51,7 @@ 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);
+ dbgmk(" ", pos0, pos1);
/*
* 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 e6e42c7a3fc..0b4eae74f79 100644
--- a/src/linux-nvme.c
+++ b/src/linux-nvme.c
@@ -62,6 +62,7 @@ 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);
+ dbgmk(" ", pos0, pos1);
/*
* 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 ede9321395c..c84b639cbfe 100644
--- a/src/linux-pci-root.c
+++ b/src/linux-pci-root.c
@@ -57,6 +57,8 @@ parse_pci_root(struct device *dev, const char *current, const char *root UNUSED)
* ^d ^p
*/
rc = sscanf(devpart, "../../devices/pci%hx:%hhx/%n", &root_domain, &root_bus, &pos);
+ debug("current:\"%s\" rc:%d pos:%d", devpart, rc, pos);
+ dbgmk(" ", pos);
/*
* If we can't find that, it's not a PCI device.
*/
diff --git a/src/linux-pci.c b/src/linux-pci.c
index 4c715df3d6e..0de330db628 100644
--- a/src/linux-pci.c
+++ b/src/linux-pci.c
@@ -68,6 +68,7 @@ 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);
+ dbgmk(" ", pos);
if (rc != 4)
break;
devpart += pos;
diff --git a/src/linux-pmem.c b/src/linux-pmem.c
index 099ac8aef8c..18eb7dce5e3 100644
--- a/src/linux-pmem.c
+++ b/src/linux-pmem.c
@@ -105,6 +105,8 @@ parse_pmem(struct device *dev, const char *current, const char *root UNUSED)
"../../devices/LNXSYSTM:%hhx/LNXSYBUS:%hhx/ACPI%hx:%hhx/ndbus%d/region%d/btt%d.%d/%n",
&system, &sysbus, &pnp_id, &acpi_id, &ndbus, &region,
&btt_region_id, &btt_id, &pos);
+ debug("current:\"%s\" rc:%d pos:%d", current, rc, pos);
+ dbgmk(" ", pos);
if (rc < 8)
return 0;
diff --git a/src/linux-sata.c b/src/linux-sata.c
index ee285d84a76..b0caa3fa401 100644
--- a/src/linux-sata.c
+++ b/src/linux-sata.c
@@ -162,6 +162,7 @@ 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);
+ dbgmk(" ", pos);
/*
* 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
@@ -175,6 +176,7 @@ 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);
+ dbgmk(" ", pos);
if (rc != 1)
return -1;
current += pos;
@@ -184,6 +186,7 @@ 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);
+ dbgmk(" ", pos);
if (rc != 3)
return -1;
current += pos;
@@ -193,6 +196,7 @@ 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);
+ dbgmk(" ", pos);
if (rc != 4)
return -1;
current += pos;
diff --git a/src/linux-scsi.c b/src/linux-scsi.c
index 90a85836b1c..96fde7e15fa 100644
--- a/src/linux-scsi.c
+++ b/src/linux-scsi.c
@@ -101,6 +101,7 @@ 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);
+ dbgmk(" ", pos0);
if (rc != 1)
return -1;
sz += pos0;
@@ -118,6 +119,7 @@ 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);
+ dbgmk(" ", pos0, pos1);
if (rc == 2 || rc == 3) {
sz += pos0;
pos0 = 0;
@@ -143,6 +145,7 @@ 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);
+ dbgmk(" ", pos0);
if (rc == 2) {
if (!remote_target_id) {
efi_error("Device is PHY is a remote target, but remote_target_id is NULL");
@@ -158,6 +161,7 @@ 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);
+ dbgmk(" ", pos0);
if (rc != 3) {
efi_error("Couldn't parse port expander port string");
return -1;
@@ -182,6 +186,7 @@ parse_scsi_link(const char *current, uint32_t *scsi_host,
rc = sscanf(current + sz + pos0, ":%d%n", &tosser2, &pos1);
if (rc != 0 && rc != 1)
return -1;
+ dbgmk(" ", pos0, pos0+pos1);
if (remote_port_id && rc == 1)
*remote_port_id = tosser2;
if (local_port_id && rc == 0)
@@ -203,6 +208,7 @@ 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);
+ dbgmk(" ", pos0);
if (rc != 3)
return -1;
sz += pos0;
@@ -215,6 +221,7 @@ 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);
+ dbgmk(" ", pos0);
if (rc != 4)
return -1;
sz += pos0;
@@ -242,6 +249,7 @@ 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);
+ dbgmk(" ", pos);
if (rc != 4)
return 0;
diff --git a/src/linux-soc-root.c b/src/linux-soc-root.c
index 27633d69c97..c932670ef15 100644
--- a/src/linux-soc-root.c
+++ b/src/linux-soc-root.c
@@ -49,6 +49,8 @@ parse_soc_root(struct device *dev UNUSED, const char *current, const char *root
rc = sscanf(devpart, "../../devices/platform/soc/%*[^/]/%n", &pos);
if (rc != 0)
return 0;
+ debug("current:\"%s\" rc:%d pos:%d", current, rc, pos);
+ dbgmk(" ", pos);
devpart += pos;
debug("new position is \"%s\"", devpart);
diff --git a/src/linux-virtblk.c b/src/linux-virtblk.c
index 891c262fe05..7517db55555 100644
--- a/src/linux-virtblk.c
+++ b/src/linux-virtblk.c
@@ -56,6 +56,7 @@ parse_virtblk(struct device *dev, const char *current, const char *root UNUSED)
debug("searching for virtio0/");
rc = sscanf(current, "virtio%x/%n", &tosser, &pos);
debug("current:\"%s\" rc:%d pos:%d\n", current, rc, pos);
+ dbgmk(" ", pos);
/*
* If we couldn't find virtioX/ then it isn't a virtio device.
*/
diff --git a/src/util.h b/src/util.h
index 3f68d812700..845989bbfe9 100644
--- a/src/util.h
+++ b/src/util.h
@@ -284,6 +284,40 @@ swizzle_guid_to_uuid(efi_guid_t *guid)
u16[1] = __builtin_bswap16(u16[1]);
}
+static inline void UNUSED
+debug_markers_(const char * const file, int line,
+ const char * const func, int level,
+ const char * const prefix, ...)
+{
+ FILE *logfile;
+ va_list ap;
+ int pos;
+ int n = 0;
+ bool on = false;
+
+ va_start(ap, prefix);
+ for (n = 0, pos = va_arg(ap, int); pos >= 0; pos = va_arg(ap, int), n++)
+ ;
+ va_end(ap);
+ if (n < 2)
+ return;
+ n = 0;
+
+ efi_set_loglevel(level);
+ logfile = efi_get_logfile();
+ fprintf(logfile, "%s:%d %s(): %s", file, line, func, prefix ? prefix : "");
+ va_start(ap, prefix);
+ while ((pos = va_arg(ap, int)) >= 0) {
+ for (; n <= pos; n++) {
+ if (n == pos)
+ on = !on;
+ fprintf(logfile, "%c", on ? '^' : ' ');
+ }
+ }
+ fprintf(logfile, "\n");
+ va_end(ap);
+}
+
#define log_(file, line, func, level, fmt, args...) \
({ \
efi_set_loglevel(level); \
@@ -312,6 +346,7 @@ swizzle_guid_to_uuid(efi_guid_t *guid)
})
#define log_hex(level, buf, size) log_hex_(__FILE__, __LINE__, __func__, level, buf, size)
#define debug_hex(buf, size) log_hex(LOG_DEBUG, buf, size)
+#define dbgmk(prefix, args...) debug_markers_(__FILE__, __LINE__, __func__, LOG_DEBUG, prefix, ## args, -1)
#endif /* EFIVAR_UTIL_H */
--
2.26.2

View File

@ -0,0 +1,25 @@
From 45d1aa955a38541ba8e1554026847e582ae28bfd Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Wed, 16 Oct 2019 10:01:00 -0400
Subject: [PATCH 53/63] gitignore: ignore *.strace
Signed-off-by: Peter Jones <pjones@redhat.com>
---
.gitignore | 1 +
1 file changed, 1 insertion(+)
diff --git a/.gitignore b/.gitignore
index 947d88eec42..f61b0bcb340 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,6 +14,7 @@
*.so
*.so.*
*.spec
+*.strace
*.tar.*
*.var
core.*
--
2.26.2

View File

@ -0,0 +1,809 @@
From cb81253cc60d9641ee766fa2be691d82821710ca Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Tue, 15 Oct 2019 16:26:30 -0400
Subject: [PATCH 54/63] Improve consistency of debug prints
This changes debug prints in a couple of ways:
- always calls the path we're parsing "current" in the output
- always use ' not " for quoting in the debug output, so tools that
escape strings won't change the lenghts
- everything that parses "current" has a debug print after each parse
attempt and before returning.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/dp-acpi.c | 6 ++---
src/linux-acpi-root.c | 20 +++++++++--------
src/linux-acpi.c | 4 ++--
src/linux-ata.c | 6 ++---
src/linux-emmc.c | 5 +++--
src/linux-i2o.c | 8 +++----
src/linux-md.c | 4 ++--
src/linux-nvme.c | 8 +++++--
src/linux-pci-root.c | 16 ++++++++------
src/linux-pci.c | 17 +++++++--------
src/linux-pmem.c | 19 +++++++++-------
src/linux-sas.c | 3 +++
src/linux-sata.c | 9 ++++----
src/linux-scsi.c | 51 +++++++++++++++++++++++++++----------------
src/linux-soc-root.c | 6 ++---
src/linux-virtblk.c | 5 +++--
src/linux.c | 27 ++++++++++++++---------
17 files changed, 125 insertions(+), 89 deletions(-)
diff --git a/src/dp-acpi.c b/src/dp-acpi.c
index 02ec70eec7a..4845410c2cf 100644
--- a/src/dp-acpi.c
+++ b/src/dp-acpi.c
@@ -52,9 +52,9 @@ _format_acpi_hid_ex(unsigned char *buf, size_t size,
{
ssize_t off = 0;
- debug("hid:0x%08x hidstr:\"%s\"", dp->acpi_hid_ex.hid, hidstr);
- debug("cid:0x%08x cidstr:\"%s\"", dp->acpi_hid_ex.cid, cidstr);
- debug("uid:0x%08x uidstr:\"%s\"", dp->acpi_hid_ex.uid, uidstr);
+ debug("hid:0x%08x hidstr:'%s'", dp->acpi_hid_ex.hid, hidstr);
+ debug("cid:0x%08x cidstr:'%s'", dp->acpi_hid_ex.cid, cidstr);
+ 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",
diff --git a/src/linux-acpi-root.c b/src/linux-acpi-root.c
index 5ed4d7f5b86..57a648981b3 100644
--- a/src/linux-acpi-root.c
+++ b/src/linux-acpi-root.c
@@ -44,7 +44,7 @@ static ssize_t
parse_acpi_root(struct device *dev, const char *current, const char *root UNUSED)
{
int rc;
- int pos = 0;
+ int pos = -1;
uint16_t pad0;
uint8_t pad1;
char *acpi_header = NULL;
@@ -62,7 +62,7 @@ parse_acpi_root(struct device *dev, const char *current, const char *root UNUSED
* side in sscanf.
*/
rc = sscanf(devpart, "../../devices/platform/%n", &pos);
- debug("devpart:\"%s\" rc:%d pos:%d", devpart, rc, pos);
+ debug("current:'%s' rc:%d pos:%d", devpart, rc, pos);
dbgmk(" ", pos);
if (rc != 0 || pos < 1)
return 0;
@@ -94,16 +94,16 @@ parse_acpi_root(struct device *dev, const char *current, const char *root UNUSED
return -1;
}
dev->acpi_root.acpi_hid_str[pos] = 0;
- debug("acpi_hid_str:\"%s\"", dev->acpi_root.acpi_hid_str);
+ debug("acpi_hid_str:'%s'", dev->acpi_root.acpi_hid_str);
pos -= 4;
- debug("devpart:\"%s\" rc:%d pos:%d", devpart, rc, pos);
+ debug("current:'%s' rc:%d pos:%d", devpart, rc, pos);
dbgmk(" ", pos);
acpi_header = strndupa(devpart, pos);
if (!acpi_header)
return 0;
acpi_header[pos] = 0;
- debug("devpart:\"%s\" acpi_header:\"%s\"", devpart, acpi_header);
+ debug("current:'%s' acpi_header:'%s'", devpart, acpi_header);
devpart += pos;
/*
@@ -114,7 +114,7 @@ parse_acpi_root(struct device *dev, const char *current, const char *root UNUSED
efi_error("Could not parse ACPI path \"%s\"", devpart);
return 0;
}
- debug("devpart:\"%s\" parsed:%04hx:%02hhx pos:%d rc:%d",
+ debug("current:'%s' parsed:%04hx:%02hhx pos:%d rc:%d",
devpart, pad0, pad1, pos, rc);
dbgmk(" ", pos);
@@ -134,12 +134,14 @@ parse_acpi_root(struct device *dev, const char *current, const char *root UNUSED
efi_error("Could not parse hid/uid");
return rc;
}
- debug("Parsed HID:0x%08x UID:0x%"PRIx64" uidstr:\"%s\" path:\"%s\"",
+ 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;
+ size_t sz = devpart - current;
+ debug("current:'%s' sz:%zd", devpart, sz);
+ return sz;
}
static ssize_t
@@ -151,7 +153,7 @@ dp_create_acpi_root(struct device *dev,
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("creating acpi_hid_ex dp hid:0x%08x uid:0x%"PRIx64" uidstr:\"%s\" cidstr:\"%s\"",
+ 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,
diff --git a/src/linux-acpi.c b/src/linux-acpi.c
index 919f4654ae3..70161ca7b9e 100644
--- a/src/linux-acpi.c
+++ b/src/linux-acpi.c
@@ -54,7 +54,7 @@ parse_acpi_hid_uid(struct device *dev, const char *fmt, ...)
if (l > 1) {
fbuf[l-1] = 0;
dev->acpi_root.acpi_cid_str = strdup(fbuf);
- debug("Setting ACPI root path to \"%s\"", fbuf);
+ debug("Setting ACPI root path to '%s'", fbuf);
}
}
@@ -111,7 +111,7 @@ hid_err:
}
}
}
- debug("acpi root UID:0x%"PRIx64" uidstr:\"%s\"",
+ debug("acpi root UID:0x%"PRIx64" uidstr:'%s'",
dev->acpi_root.acpi_uid, dev->acpi_root.acpi_uid_str);
errno = 0;
diff --git a/src/linux-ata.c b/src/linux-ata.c
index b6a7c2dcf8a..7bb23da60f5 100644
--- a/src/linux-ata.c
+++ b/src/linux-ata.c
@@ -126,9 +126,9 @@ parse_ata(struct device *dev, const char *current, const char *root UNUSED)
dev->ata_info.scsi_lun = scsi_lun;
char *block = strstr(current, "/block/");
- if (!block)
- return -1;
- return block + 1 - current;
+ ssize_t sz = block ? block + 1 - current : -1;
+ debug("current:'%s' sz:%zd", current, sz);
+ return sz;
}
static ssize_t
diff --git a/src/linux-emmc.c b/src/linux-emmc.c
index 59ef8e7524d..74cf54aa336 100644
--- a/src/linux-emmc.c
+++ b/src/linux-emmc.c
@@ -49,7 +49,7 @@ 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;
+ int pos0 = -1, pos1 = -1;
debug("entry");
@@ -57,7 +57,7 @@ parse_emmc(struct device *dev, const char *current, const char *root UNUSED)
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("current:\"%s\" rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1);
+ debug("current:'%s' rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1);
dbgmk(" ", pos0, pos1);
/*
* If it isn't of that form, it's not one of our emmc devices.
@@ -75,6 +75,7 @@ parse_emmc(struct device *dev, const char *current, const char *root UNUSED)
pos0 = pos1;
}
+ debug("current:'%s' sz:%d\n", current, pos0);
return pos0;
}
diff --git a/src/linux-i2o.c b/src/linux-i2o.c
index ebd92aeeb53..76b3d4d5d39 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, const char *root UNUSED)
+parse_i2o(struct device *dev, const char *current, const char *root UNUSED)
{
debug("entry");
/* I2O disks can have up to 16 partitions, or 4 bits worth. */
@@ -47,9 +47,9 @@ parse_i2o(struct device *dev, const char *current UNUSED, const char *root UNUSE
}
char *block = strstr(current, "/block/");
- if (!block)
- return -1;
- return block + 1 - current;
+ ssize_t sz = block ? block + 1 - current : -1;
+ debug("current:'%s' sz:%zd", current, sz);
+ return sz;
}
enum interface_type i2o_iftypes[] = { i2o, unknown };
diff --git a/src/linux-md.c b/src/linux-md.c
index 1d7bd3195c0..ded7cbd169c 100644
--- a/src/linux-md.c
+++ b/src/linux-md.c
@@ -50,7 +50,7 @@ parse_md(struct device *dev, const char *current, const char *root UNUSED)
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);
+ debug("current:'%s' rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1);
dbgmk(" ", pos0, pos1);
/*
* If it isn't of that form, it's not one of our partitioned md devices.
@@ -63,10 +63,10 @@ parse_md(struct device *dev, const char *current, const char *root UNUSED)
if (dev->part == -1)
dev->part = part;
+ debug("current:'%s' sz:%d\n", current, pos1);
return pos1;
}
-
static char *
make_part_name(struct device *dev)
{
diff --git a/src/linux-nvme.c b/src/linux-nvme.c
index 0b4eae74f79..7b18d7990ac 100644
--- a/src/linux-nvme.c
+++ b/src/linux-nvme.c
@@ -53,6 +53,7 @@ parse_nvme(struct device *dev, const char *current, const char *root UNUSED)
int rc;
int32_t tosser0, tosser1, tosser2, ctrl_id, ns_id, partition;
uint8_t *filebuf = NULL;
+ ssize_t sz = 0;
int pos0 = 0, pos1 = 0;
debug("entry");
@@ -61,7 +62,7 @@ parse_nvme(struct device *dev, const char *current, const char *root UNUSED)
rc = sscanf(current, "nvme/nvme%d/nvme%dn%d%n/nvme%dn%dp%d%n",
&tosser0, &ctrl_id, &ns_id, &pos0,
&tosser1, &tosser2, &partition, &pos1);
- debug("current:\"%s\" rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1);
+ debug("current:'%s' rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1);
dbgmk(" ", pos0, pos1);
/*
* If it isn't of that form, it's not one of our nvme devices.
@@ -81,6 +82,8 @@ parse_nvme(struct device *dev, const char *current, const char *root UNUSED)
pos0 = pos1;
}
+ sz += pos0;
+
/*
* now fish the eui out of sysfs is there is one...
*/
@@ -111,7 +114,8 @@ parse_nvme(struct device *dev, const char *current, const char *root UNUSED)
memcpy(dev->nvme_info.eui, eui, sizeof(eui));
}
- return pos0;
+ debug("current:'%s' sz:%zd\n", current, sz);
+ return sz;
}
static ssize_t
diff --git a/src/linux-pci-root.c b/src/linux-pci-root.c
index c84b639cbfe..c7e279118f5 100644
--- a/src/linux-pci-root.c
+++ b/src/linux-pci-root.c
@@ -44,7 +44,7 @@ static ssize_t
parse_pci_root(struct device *dev, const char *current, const char *root UNUSED)
{
int rc;
- int pos = 0;
+ int pos0 = -1, pos1 = -1;
uint16_t root_domain;
uint8_t root_bus;
const char *devpart = current;
@@ -56,15 +56,16 @@ parse_pci_root(struct device *dev, const char *current, const char *root UNUSED)
* pci0000:00/
* ^d ^p
*/
- rc = sscanf(devpart, "../../devices/pci%hx:%hhx/%n", &root_domain, &root_bus, &pos);
- debug("current:\"%s\" rc:%d pos:%d", devpart, rc, pos);
- dbgmk(" ", pos);
+ rc = sscanf(devpart, "%n../../devices/pci%hx:%hhx/%n", &pos0, &root_domain, &root_bus, &pos1);
+ debug("current:'%s' rc:%d pos0:%d pos1:%d", devpart, rc, pos0, pos1);
+ dbgmk(" ", pos0, pos1);
+
/*
* If we can't find that, it's not a PCI device.
*/
if (rc != 2)
return 0;
- devpart += pos;
+ devpart += pos1;
dev->pci_root.pci_domain = root_domain;
dev->pci_root.pci_bus = root_bus;
@@ -75,7 +76,8 @@ parse_pci_root(struct device *dev, const char *current, const char *root UNUSED)
return -1;
errno = 0;
- return devpart - current;
+ debug("current:'%s' sz:%d\n", devpart, pos1);
+ return pos1;
}
static ssize_t
@@ -86,7 +88,7 @@ dp_create_pci_root(struct device *dev UNUSED,
debug("entry buf:%p size:%zd off:%zd", buf, size, off);
debug("returning 0");
if (dev->acpi_root.acpi_uid_str) {
- debug("creating acpi_hid_ex dp hid:0x%08x uid:\"%s\"",
+ 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,
diff --git a/src/linux-pci.c b/src/linux-pci.c
index 0de330db628..a3a0dc28afd 100644
--- a/src/linux-pci.c
+++ b/src/linux-pci.c
@@ -46,7 +46,7 @@ static ssize_t
parse_pci(struct device *dev, const char *current, const char *root)
{
int rc;
- int pos = 0;
+ int pos0 = -1, pos1 = -1;
const char *devpart = current;
debug("entry");
@@ -62,16 +62,15 @@ parse_pci(struct device *dev, const char *current, const char *root)
unsigned int i = dev->n_pci_devs;
struct stat statbuf;
- debug("devpart is \"%s\"", devpart);
- pos = 0;
+ pos0 = pos1 = -1;
debug("searching for 0000:00:00.0/");
- rc = sscanf(devpart, "%hx:%hhx:%hhx.%hhx/%n",
- &domain, &bus, &device, &function, &pos);
- debug("current:\"%s\" rc:%d pos:%d", devpart, rc, pos);
- dbgmk(" ", pos);
+ rc = sscanf(devpart, "%n%hx:%hhx:%hhx.%hhx/%n",
+ &pos0, &domain, &bus, &device, &function, &pos1);
+ debug("current:'%s' rc:%d pos0:%d pos1:%d", devpart, rc, pos0, pos1);
+ dbgmk(" ", pos0, pos1);
if (rc != 4)
break;
- devpart += pos;
+ devpart += pos1;
debug("found pci domain %04hx:%02hhx:%02hhx.%02hhx",
domain, bus, device, function);
@@ -115,7 +114,7 @@ parse_pci(struct device *dev, const char *current, const char *root)
dev->n_pci_devs += 1;
}
- debug("next:\"%s\"", devpart);
+ debug("current:'%s' sz:%zd\n", devpart, devpart - current);
return devpart - current;
}
diff --git a/src/linux-pmem.c b/src/linux-pmem.c
index 18eb7dce5e3..49db24560fa 100644
--- a/src/linux-pmem.c
+++ b/src/linux-pmem.c
@@ -75,7 +75,7 @@ parse_pmem(struct device *dev, const char *current, const char *root UNUSED)
uint8_t *filebuf = NULL;
uint8_t system, sysbus, acpi_id;
uint16_t pnp_id;
- int ndbus, region, btt_region_id, btt_id, rc, pos;
+ int ndbus, region, btt_region_id, btt_id, rc, pos0, pos1;
char *namespace = NULL;
debug("entry");
@@ -101,14 +101,16 @@ parse_pmem(struct device *dev, const char *current, const char *root UNUSED)
*
* 259:0 -> ../../devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0012:00/ndbus0/region12/btt12.1/block/pmem12s
*/
+ pos0 = pos1 = -1;
rc = sscanf(current,
- "../../devices/LNXSYSTM:%hhx/LNXSYBUS:%hhx/ACPI%hx:%hhx/ndbus%d/region%d/btt%d.%d/%n",
- &system, &sysbus, &pnp_id, &acpi_id, &ndbus, &region,
- &btt_region_id, &btt_id, &pos);
- debug("current:\"%s\" rc:%d pos:%d", current, rc, pos);
- dbgmk(" ", pos);
+ "../../devices/%nLNXSYSTM:%hhx/LNXSYBUS:%hhx/ACPI%hx:%hhx/ndbus%d/region%d/btt%d.%d/%n",
+ &pos0, &system, &sysbus, &pnp_id, &acpi_id, &ndbus,
+ &region, &btt_region_id, &btt_id, &pos1);
+ debug("current:'%s' rc:%d pos0:%d pos1:%d", current, rc, pos0, pos1);
+ dbgmk(" ", pos0, pos1);
if (rc < 8)
return 0;
+ current += pos1;
/*
* but the UUID we really do need to have.
@@ -123,7 +125,7 @@ parse_pmem(struct device *dev, const char *current, const char *root UNUSED)
return -1;
filebuf = NULL;
- debug("nvdimm namespace is \"%s\"", namespace);
+ debug("nvdimm namespace is '%s'", namespace);
rc = read_sysfs_file(&filebuf, "bus/nd/devices/%s/uuid", namespace);
free(namespace);
if (rc < 0 || filebuf == NULL)
@@ -158,7 +160,8 @@ parse_pmem(struct device *dev, const char *current, const char *root UNUSED)
dev->interface_type = nd_pmem;
- return pos;
+ debug("current:'%s' sz:%d\n", current, pos1);
+ return pos1;
}
static ssize_t
diff --git a/src/linux-sas.c b/src/linux-sas.c
index f985deeaa3f..d14fcfb231a 100644
--- a/src/linux-sas.c
+++ b/src/linux-sas.c
@@ -172,6 +172,7 @@ parse_sas(struct device *dev, const char *current, const char *root UNUSED)
*/
if (pos < 0)
return 0;
+ current += pos;
/*
* Make sure it has the actual /SAS/ bits before we continue
@@ -236,6 +237,8 @@ parse_sas(struct device *dev, const char *current, const char *root UNUSED)
dev->scsi_info.scsi_target = scsi_target;
dev->scsi_info.scsi_lun = scsi_lun;
dev->interface_type = sas;
+
+ debug("current:'%s' sz:%zd\n", current, pos);
return pos;
}
diff --git a/src/linux-sata.c b/src/linux-sata.c
index b0caa3fa401..4f4e983568e 100644
--- a/src/linux-sata.c
+++ b/src/linux-sata.c
@@ -161,7 +161,7 @@ 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);
+ debug("current:'%s' rc:%d pos:%d\n", current, rc, pos);
dbgmk(" ", pos);
/*
* If we don't find this one, it isn't an ata device, so return 0 not
@@ -175,7 +175,7 @@ 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);
+ debug("current:'%s' rc:%d pos:%d\n", current, rc, pos);
dbgmk(" ", pos);
if (rc != 1)
return -1;
@@ -185,7 +185,7 @@ parse_sata(struct device *dev, const char *devlink, const char *root UNUSED)
debug("searching for target0:0:0:0/");
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);
+ debug("current:'%s' rc:%d pos:%d\n", current, rc, pos);
dbgmk(" ", pos);
if (rc != 3)
return -1;
@@ -195,7 +195,7 @@ parse_sata(struct device *dev, const char *devlink, const char *root UNUSED)
debug("searching for 0:0:0:0/");
rc = sscanf(current, "%"PRIu32":%"PRIu32":%"PRIu32":%"PRIu64"/%n",
&tosser0, &tosser1, &tosser2, &tosser3, &pos);
- debug("current:\"%s\" rc:%d pos:%d\n", current, rc, pos);
+ debug("current:'%s' rc:%d pos:%d\n", current, rc, pos);
dbgmk(" ", pos);
if (rc != 4)
return -1;
@@ -213,6 +213,7 @@ parse_sata(struct device *dev, const char *devlink, const char *root UNUSED)
if (dev->interface_type == unknown)
dev->interface_type = sata;
+ debug("current:'%s' sz:%zd\n", current, current - devlink);
return current - devlink;
}
diff --git a/src/linux-scsi.c b/src/linux-scsi.c
index 96fde7e15fa..6b92908d6bc 100644
--- a/src/linux-scsi.c
+++ b/src/linux-scsi.c
@@ -43,7 +43,7 @@ parse_scsi_link(const char *current, uint32_t *scsi_host,
uint32_t *remote_target_id)
{
int rc;
- int sz = 0;
+ ssize_t sz = 0;
int pos0 = 0, pos1 = 0;
debug("entry");
@@ -100,10 +100,11 @@ 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);
+ debug("current:'%s' rc:%d pos0:%d\n", current, rc, pos0);
dbgmk(" ", pos0);
if (rc != 1)
return -1;
+ current += pos0;
sz += pos0;
pos0 = 0;
@@ -116,11 +117,12 @@ parse_scsi_link(const char *current, uint32_t *scsi_host,
* port-2:0:2/end_device-2:0:2/target2:0:0/2:0:0:0/block/sda/sda1
*/
debug("searching for port-4:0 or port-4:0:0");
- rc = sscanf(current+sz, "port-%d:%d%n:%d%n", &tosser0,
+ rc = sscanf(current, "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);
+ debug("current:'%s' rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1);
dbgmk(" ", pos0, pos1);
if (rc == 2 || rc == 3) {
+ current += pos0;
sz += pos0;
pos0 = 0;
if (local_port_id && rc == 2)
@@ -128,8 +130,10 @@ parse_scsi_link(const char *current, uint32_t *scsi_host,
if (remote_port_id && rc == 3)
*remote_port_id = tosser2;
- if (current[sz] == '/')
+ if (current[0] == '/') {
+ current += 1;
sz += 1;
+ }
/*
* We might have this next:
@@ -143,8 +147,8 @@ parse_scsi_link(const char *current, uint32_t *scsi_host,
* to get past it.
*/
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);
+ rc = sscanf(current, "expander-%d:%d/%n", &tosser0, &tosser1, &pos0);
+ debug("current:'%s' rc:%d pos0:%d\n", current, rc, pos0);
dbgmk(" ", pos0);
if (rc == 2) {
if (!remote_target_id) {
@@ -152,6 +156,7 @@ parse_scsi_link(const char *current, uint32_t *scsi_host,
return -1;
}
*remote_target_id = tosser1;
+ current += pos0;
sz += pos0;
pos0 = 0;
@@ -159,13 +164,14 @@ parse_scsi_link(const char *current, uint32_t *scsi_host,
* if we have that, we should have a 3-part port next
*/
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);
+ rc = sscanf(current, "port-%d:%d:%d/%n", &tosser0, &tosser1, &tosser2, &pos0);
+ debug("current:'%s' rc:%d pos0:%d\n", current, rc, pos0);
dbgmk(" ", pos0);
if (rc != 3) {
efi_error("Couldn't parse port expander port string");
return -1;
}
+ current += pos0;
sz += pos0;
}
pos0 = 0;
@@ -177,13 +183,13 @@ parse_scsi_link(const char *current, uint32_t *scsi_host,
* but we don't care for now about any of them anyway.
*/
debug("searching for end_device-4:0/ or end_device-4:0:0/");
- rc = sscanf(current + sz, "end_device-%d:%d%n", &tosser0, &tosser1, &pos0);
- debug("current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0);
+ rc = sscanf(current, "end_device-%d:%d%n", &tosser0, &tosser1, &pos0);
+ debug("current:'%s' rc:%d pos0:%d\n", current, rc, pos0);
if (rc != 2)
return -1;
pos1 = 0;
- rc = sscanf(current + sz + pos0, ":%d%n", &tosser2, &pos1);
+ rc = sscanf(current + pos0, ":%d%n", &tosser2, &pos1);
if (rc != 0 && rc != 1)
return -1;
dbgmk(" ", pos0, pos0+pos1);
@@ -191,11 +197,14 @@ parse_scsi_link(const char *current, uint32_t *scsi_host,
*remote_port_id = tosser2;
if (local_port_id && rc == 0)
*local_port_id = tosser1;
+ current += pos0 + pos1;
sz += pos0 + pos1;
pos0 = pos1 = 0;
- if (current[sz] == '/')
+ if (current[0] == '/') {
+ current += sz;
sz += 1;
+ }
} else if (rc != 0) {
return -1;
}
@@ -205,12 +214,13 @@ parse_scsi_link(const char *current, uint32_t *scsi_host,
*/
uint64_t tosser3;
debug("searching for target4:0:0/");
- rc = sscanf(current + sz, "target%d:%d:%"PRIu64"/%n", &tosser0, &tosser1,
+ rc = sscanf(current, "target%d:%d:%"PRIu64"/%n", &tosser0, &tosser1,
&tosser3, &pos0);
- debug("current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0);
+ debug("current:'%s' rc:%d pos0:%d\n", current, rc, pos0);
dbgmk(" ", pos0);
if (rc != 3)
return -1;
+ current += pos0;
sz += pos0;
pos0 = 0;
@@ -218,15 +228,16 @@ parse_scsi_link(const char *current, uint32_t *scsi_host,
* %d:%d:%d:%llu/
*/
debug("searching for 4:0:0:0/");
- rc = sscanf(current + sz, "%d:%d:%d:%"PRIu64"/%n",
+ rc = sscanf(current, "%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);
+ debug("current:'%s' rc:%d pos0:%d\n", current, rc, pos0);
dbgmk(" ", pos0);
if (rc != 4)
return -1;
+ current += pos0;
sz += pos0;
- debug("returning %d", sz);
+ debug("current:'%s' sz:%zd\n", current, sz);
return sz;
}
@@ -248,7 +259,7 @@ parse_scsi(struct device *dev, const char *current, const char *root UNUSED)
&dev->scsi_info.scsi_target,
&dev->scsi_info.scsi_lun,
&pos);
- debug("current:\"%s\" rc:%d pos:%d\n", dev->device, rc, pos);
+ debug("current:'%s' rc:%d pos:%d\n", dev->device, rc, pos);
dbgmk(" ", pos);
if (rc != 4)
return 0;
@@ -259,6 +270,7 @@ parse_scsi(struct device *dev, const char *current, const char *root UNUSED)
NULL, NULL, NULL);
if (sz < 0)
return 0;
+ current += sz;
/*
* SCSI disks can have up to 16 partitions, or 4 bits worth
@@ -281,6 +293,7 @@ parse_scsi(struct device *dev, const char *current, const char *root UNUSED)
return -1;
}
+ debug("current:'%s' sz:%zd\n", current, sz);
return sz;
}
diff --git a/src/linux-soc-root.c b/src/linux-soc-root.c
index c932670ef15..9c9e9573dcd 100644
--- a/src/linux-soc-root.c
+++ b/src/linux-soc-root.c
@@ -49,12 +49,12 @@ parse_soc_root(struct device *dev UNUSED, const char *current, const char *root
rc = sscanf(devpart, "../../devices/platform/soc/%*[^/]/%n", &pos);
if (rc != 0)
return 0;
- debug("current:\"%s\" rc:%d pos:%d", current, rc, pos);
+ debug("current:'%s' rc:%d pos:%d", current, rc, pos);
dbgmk(" ", pos);
devpart += pos;
- debug("new position is \"%s\"", devpart);
- return devpart - current;
+ debug("current:'%s' sz:%d\n", devpart, pos);
+ return pos;
}
enum interface_type soc_root_iftypes[] = { soc_root, unknown };
diff --git a/src/linux-virtblk.c b/src/linux-virtblk.c
index 7517db55555..df14673dac8 100644
--- a/src/linux-virtblk.c
+++ b/src/linux-virtblk.c
@@ -48,14 +48,14 @@ static ssize_t
parse_virtblk(struct device *dev, const char *current, const char *root UNUSED)
{
uint32_t tosser;
- int pos = 0;
+ int pos = -1;
int rc;
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);
+ debug("current:'%s' rc:%d pos:%d\n", current, rc, pos);
dbgmk(" ", pos);
/*
* If we couldn't find virtioX/ then it isn't a virtio device.
@@ -65,6 +65,7 @@ parse_virtblk(struct device *dev, const char *current, const char *root UNUSED)
dev->interface_type = virtblk;
+ debug("current:'%s' sz:%d\n", current, pos);
return pos;
}
diff --git a/src/linux.c b/src/linux.c
index 45b1ee2d96f..45f07d3913c 100644
--- a/src/linux.c
+++ b/src/linux.c
@@ -182,10 +182,10 @@ set_disk_and_part_name(struct device *dev)
errno = 0;
debug("dev->disk_name:%p dev->part_name:%p", dev->disk_name, dev->part_name);
debug("dev->part:%d", dev->part);
- debug("ultimate:\"%s\"", ultimate ? : "");
- debug("penultimate:\"%s\"", penultimate ? : "");
- debug("approximate:\"%s\"", approximate ? : "");
- debug("proximate:\"%s\"", proximate ? : "");
+ debug("ultimate:'%s'", ultimate ? : "");
+ debug("penultimate:'%s'", penultimate ? : "");
+ debug("approximate:'%s'", approximate ? : "");
+ debug("proximate:'%s'", proximate ? : "");
if (ultimate && penultimate &&
((proximate && !strcmp(proximate, "nvme")) ||
@@ -455,7 +455,11 @@ struct device HIDDEN
efi_error("parsing %s failed", probe->name);
goto err;
} else if (pos > 0) {
- debug("%s matched %s", probe->name, current);
+ char match[pos+1];
+
+ strncpy(match, current, pos);
+ match[pos] = '\0';
+ debug("%s matched '%s'", probe->name, match);
dev->flags |= probe->flags;
if (probe->flags & DEV_PROVIDES_HD ||
@@ -465,7 +469,10 @@ struct device HIDDEN
dev->probes[n++] = dev_probes[i];
current += pos;
- debug("current:%s", current);
+ if (current[0] == '\0')
+ debug("finished");
+ else
+ debug("current:'%s'", current);
last_successful_probe = i;
if (!*current || !strncmp(current, "block/", 6))
@@ -474,8 +481,8 @@ struct device HIDDEN
continue;
}
- debug("dev_probes[i+1]: %p dev->interface_type: %d\n",
- dev_probes[i+1], dev->interface_type);
+ debug("dev_probes[%d]: %p dev->interface_type: %d\n",
+ i+1, dev_probes[i+1], dev->interface_type);
if (dev_probes[i+1] == NULL && dev->interface_type == unknown) {
pos = 0;
rc = sscanf(current, "%*[^/]/%n", &pos);
@@ -491,8 +498,8 @@ slash_err:
if (!current[pos])
goto slash_err;
- debug("Cannot parse device link segment \"%s\"", current);
- debug("Skipping to \"%s\"", current + pos);
+ debug("Cannot parse device link segment '%s'", current);
+ debug("Skipping to '%s'", current + pos);
debug("This means we can only create abbreviated paths");
dev->flags |= DEV_ABBREV_ONLY;
i = last_successful_probe;
--
2.26.2

View File

@ -0,0 +1,63 @@
From 74aa359f7474040aef2bd18b66201412f853b5c4 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Wed, 2 Oct 2019 17:01:00 -0400
Subject: [PATCH 55/63] Fix the error path in set_disk_and_part_name()
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/linux.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/src/linux.c b/src/linux.c
index 45f07d3913c..73c67cbafd3 100644
--- a/src/linux.c
+++ b/src/linux.c
@@ -169,6 +169,8 @@ set_disk_name(struct device *dev, const char * const fmt, ...)
int HIDDEN
set_disk_and_part_name(struct device *dev)
{
+ int rc = -1;
+
/*
* results are like such:
* maj:min -> ../../devices/pci$PCI_STUFF/$BLOCKDEV_STUFF/block/$DISK/$PART
@@ -200,6 +202,7 @@ set_disk_and_part_name(struct device *dev)
set_disk_name(dev, "%s", penultimate);
set_part_name(dev, "%s", ultimate);
debug("disk:%s part:%s", penultimate, ultimate);
+ rc = 0;
} else if (ultimate && approximate && !strcmp(approximate, "nvme")) {
/*
* 259:0 -> ../../devices/pci0000:00/0000:00:1d.0/0000:05:00.0/nvme/nvme0/nvme0n1
@@ -207,6 +210,7 @@ set_disk_and_part_name(struct device *dev)
set_disk_name(dev, "%s", ultimate);
set_part_name(dev, "%sp%d", ultimate, dev->part);
debug("disk:%s part:%sp%d", ultimate, ultimate, dev->part);
+ rc = 0;
} else if (ultimate && penultimate && !strcmp(penultimate, "block")) {
/*
* 253:0 -> ../../devices/virtual/block/dm-0 (... I guess)
@@ -220,15 +224,19 @@ set_disk_and_part_name(struct device *dev)
set_disk_name(dev, "%s", ultimate);
set_part_name(dev, "%s%d", ultimate, dev->part);
debug("disk:%s part:%s%d", ultimate, ultimate, dev->part);
+ rc = 0;
} else if (ultimate && approximate && !strcmp(approximate, "mtd")) {
/*
* 31:0 -> ../../devices/platform/1e000000.palmbus/1e000b00.spi/spi_master/spi32766/spi32766.0/mtd/mtd0/mtdblock0
*/
set_disk_name(dev, "%s", ultimate);
debug("disk:%s", ultimate);
+ rc = 0;
}
- return 0;
+ if (rc < 0)
+ efi_error("Could not parse disk name:\"%s\"", dev->link);
+ return rc;
}
static struct dev_probe *dev_probes[] = {
--
2.26.2

View File

@ -0,0 +1,204 @@
From 156d7a1e123f85863db854aae5c10acd3864f9d8 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Fri, 11 Oct 2019 14:20:54 -0400
Subject: [PATCH 56/63] Try even harder to find disk device symlinks in sysfs.
Today's realization is that the thing encoded into the structure of
sysfs is, in the best case, the dependency graph of the makefile targets
to build a device driver.
In the case of nvme-fabric, or really wherever the kernel has
class_create() and device_create() in the same function, there's an
extra level of indirection.
Anyway, in this patch we stop pretending sysfs isn't completely absurd,
and just try adding "/device" in the middle of the driver symlink path,
until we actually either get ENOENT on the device symlink or find a
device symlink that actually has a driver symlink under it.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/linux-nvme.c | 13 +++++----
src/linux.c | 46 ++++++++++++++++++--------------
src/linux.h | 69 ++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 101 insertions(+), 27 deletions(-)
diff --git a/src/linux-nvme.c b/src/linux-nvme.c
index 7b18d7990ac..455c4c7ba9b 100644
--- a/src/linux-nvme.c
+++ b/src/linux-nvme.c
@@ -87,13 +87,12 @@ parse_nvme(struct device *dev, const char *current, const char *root UNUSED)
/*
* now fish the eui out of sysfs is there is one...
*/
- rc = read_sysfs_file(&filebuf,
- "class/block/nvme%dn%d/eui",
- ctrl_id, ns_id);
- if ((rc < 0 && errno == ENOENT) || filebuf == NULL) {
- rc = read_sysfs_file(&filebuf,
- "class/block/nvme%dn%d/device/eui",
- ctrl_id, ns_id);
+ char *euipath = NULL;
+ rc = read_sysfs_file(&filebuf, "class/block/nvme%dn%d/eui", ctrl_id, ns_id);
+ if (rc < 0 && (errno == ENOENT || errno == ENOTDIR)) {
+ rc = find_device_file(&euipath, "eui", "class/block/nvme%dn%d", ctrl_id, ns_id);
+ if (rc >= 0 && euipath != NULL)
+ rc = read_sysfs_file(&filebuf, "%s", euipath);
}
if (rc >= 0 && filebuf != NULL) {
uint8_t eui[8];
diff --git a/src/linux.c b/src/linux.c
index 73c67cbafd3..30db22d95dd 100644
--- a/src/linux.c
+++ b/src/linux.c
@@ -401,26 +401,32 @@ struct device HIDDEN
goto err;
}
- if (dev->device[0] != 0) {
- rc = sysfs_readlink(&tmpbuf, "block/%s/device/driver", dev->disk_name);
+ /*
+ * So, on a normal disk, you get something like:
+ * /sys/block/sda/device -> ../../0:0:0:0
+ * /sys/block/sda/device/driver -> ../../../../../../../bus/scsi/drivers/sd
+ *
+ * On a directly attached nvme device you get:
+ * /sys/block/nvme0n1/device -> ../../nvme0
+ * /sys/block/nvme0n1/device/device -> ../../../0000:6e:00.0
+ * /sys/block/nvme0n1/device/device/driver -> ../../../../bus/pci/drivers/nvme
+ *
+ * On a fabric-attached nvme device, you get something like:
+ * /sys/block/nvme0n1/device -> ../../nvme0
+ * /sys/block/nvme0n1/device/device -> ../../ctl
+ * /sys/block/nvme0n1/device/device/device -> ../../../../../0000:6e:00.0
+ * /sys/block/nvme0n1/device/device/device/driver -> ../../../../../../bus/pci/drivers/nvme-fabrics
+ *
+ * ... I think? I don't have one in front of me.
+ */
+
+ char *filepath = NULL;
+ rc = find_device_file(&filepath, "driver", "block/%s", dev->disk_name);
+ if (rc >= 0) {
+ rc = sysfs_readlink(&tmpbuf, "%s", filepath);
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 (rc >= 0 && tmpbuf)
- efi_error_pop();
- }
- if (rc < 0 || !tmpbuf) {
- efi_error("readlink of /sys/block/%s/device/driver failed",
- dev->disk_name);
- goto err;
- }
+ efi_error("readlink of /sys/%s failed", filepath);
+ goto err;
}
linkbuf = pathseg(tmpbuf, -1);
@@ -431,7 +437,7 @@ struct device HIDDEN
dev->driver = strdup(linkbuf);
} else {
- dev->driver = strdup("");
+ dev->driver = strdup("");
}
if (!dev->driver) {
diff --git a/src/linux.h b/src/linux.h
index 5ae64ffaacf..ae9835ef7ce 100644
--- a/src/linux.h
+++ b/src/linux.h
@@ -218,6 +218,22 @@ extern ssize_t HIDDEN make_mac_path(uint8_t *buf, ssize_t size,
_rc; \
})
+#define sysfs_access(mode, fmt, args...) \
+ ({ \
+ int rc_; \
+ char *pn_; \
+ \
+ rc_ = asprintfa(&pn_, "/sys/" fmt, ## args); \
+ if (rc_ >= 0) { \
+ rc_ = access(pn_, mode); \
+ if (rc_ < 0) \
+ efi_error("could not access %s", pn_); \
+ } else { \
+ efi_error("could not allocate memory"); \
+ } \
+ rc_; \
+ })
+
#define sysfs_stat(statbuf, fmt, args...) \
({ \
int rc_; \
@@ -251,6 +267,59 @@ extern ssize_t HIDDEN make_mac_path(uint8_t *buf, ssize_t size,
dir_; \
})
+/*
+ * Iterate a /sys/block directory looking for device/foo, device/device/foo,
+ * etc. I'm not proud of this method.
+ */
+#define find_device_file(result, name, fmt, args...) \
+ ({ \
+ int rc_ = 0; \
+ debug("searching for %s from in %s", name, dev->disk_name); \
+ for (unsigned int try_ = 0; true; try_++) { \
+ char slashdev_[sizeof("device") \
+ + try_ * strlen("/device")]; \
+ \
+ char *nul_ = stpcpy(slashdev_, "device"); \
+ for (unsigned int i_ = 0; i_ < try_; i_++) \
+ nul_ = stpcpy(nul_, "/device"); \
+ \
+ debug("trying /sys/" fmt "/%s/%s", \
+ ## args, slashdev_, name); \
+ \
+ rc_ = sysfs_access(F_OK, fmt "/%s", ## args, slashdev_);\
+ if (rc_ < 0) { \
+ if (errno == ENOENT) { \
+ efi_error_pop(); \
+ break; \
+ } \
+ efi_error("cannot access /sys/"fmt"/%s: %m", \
+ ## args, slashdev_); \
+ goto find_device_link_err_; \
+ } \
+ \
+ rc_ = sysfs_access(F_OK, fmt "/%s/%s", \
+ ## args, slashdev_, name); \
+ if (rc_ < 0) { \
+ if (errno == ENOENT) { \
+ efi_error_pop(); \
+ break; \
+ } \
+ efi_error("cannot access /sys/"fmt"/%s/%s: %m", \
+ ## args, slashdev_, name); \
+ goto find_device_link_err_; \
+ } \
+ \
+ rc_ = asprintfa(result, fmt "/%s/%s", \
+ ## args, slashdev_, name); \
+ if (rc_ < 0) { \
+ efi_error("cannot allocate memory: %m"); \
+ goto find_device_link_err_; \
+ } \
+ } \
+find_device_link_err_: \
+ rc_; \
+ })
+
#define DEV_PROVIDES_ROOT 1
#define DEV_PROVIDES_HD 2
#define DEV_ABBREV_ONLY 4
--
2.26.2

View File

@ -0,0 +1,334 @@
From ad1d30fc5e20b933b6ad59d35c13e0193cd68a2d Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Wed, 2 Oct 2019 17:04:12 -0400
Subject: [PATCH 57/63] Handle
/sys/devices/virtual/{nvme-fabrics,nvme-subsystem} devices
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/linux-nvme.c | 59 ++++++++++++++++++++++-----
src/linux-virtual-root.c | 88 ++++++++++++++++++++++++++++++++++++++++
src/linux.c | 43 +++++++++++++++++---
src/linux.h | 4 +-
4 files changed, 176 insertions(+), 18 deletions(-)
create mode 100644 src/linux-virtual-root.c
diff --git a/src/linux-nvme.c b/src/linux-nvme.c
index 455c4c7ba9b..7ca2fa3c283 100644
--- a/src/linux-nvme.c
+++ b/src/linux-nvme.c
@@ -1,6 +1,6 @@
/*
* libefiboot - library for the manipulation of EFI boot variables
- * Copyright 2012-2018 Red Hat, Inc.
+ * Copyright 2012-2019 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
@@ -15,7 +15,6 @@
* 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"
@@ -24,6 +23,7 @@
#include <fcntl.h>
#include <inttypes.h>
#include <stdint.h>
+#include <sys/param.h>
#include <unistd.h>
#include "efiboot.h"
@@ -34,6 +34,12 @@
* /sys/dev/block/$major:$minor looks like:
* 259:0 -> ../../devices/pci0000:00/0000:00:1d.0/0000:05:00.0/nvme/nvme0/nvme0n1
* 259:1 -> ../../devices/pci0000:00/0000:00:1d.0/0000:05:00.0/nvme/nvme0/nvme0n1/nvme0n1p1
+ * or:
+ * 259:0 ->../../devices/virtual/nvme-fabrics/ctl/nvme0/nvme0n1
+ * 259:1 ->../../devices/virtual/nvme-fabrics/ctl/nvme0/nvme0n1/nvme0n1p1
+ * or:
+ * 259:5 -> ../../devices/virtual/nvme-subsystem/nvme-subsys0/nvme0n1
+ * 259:6 -> ../../devices/virtual/nvme-subsystem/nvme-subsys0/nvme0n1/nvme0n1p1
*
* /sys/dev/block/259:0/device looks like:
* device -> ../../nvme0
@@ -53,17 +59,44 @@ parse_nvme(struct device *dev, const char *current, const char *root UNUSED)
int rc;
int32_t tosser0, tosser1, tosser2, ctrl_id, ns_id, partition;
uint8_t *filebuf = NULL;
+ int pos0 = -1, pos1 = -1, pos2 = -1;
ssize_t sz = 0;
- int pos0 = 0, pos1 = 0;
+ struct subdir {
+ const char * const name;
+ const char * const fmt;
+ int *pos0, *pos1;
+ } subdirs[] = {
+ {"nvme-subsysN/", "%nnvme-subsys%d/%n", &pos0, &pos2},
+ {"ctl/", "%nctl/%n%n", &pos0, &pos1},
+ {"nvme/", "%nnvme/%n%n", &pos0, &pos1},
+ {NULL, }
+ };
debug("entry");
- debug("searching for nvme/nvme0/nvme0n1 or nvme/nvme0/nvme0n1/nvme0n1p1");
- rc = sscanf(current, "nvme/nvme%d/nvme%dn%d%n/nvme%dn%dp%d%n",
- &tosser0, &ctrl_id, &ns_id, &pos0,
- &tosser1, &tosser2, &partition, &pos1);
- debug("current:'%s' rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1);
- dbgmk(" ", pos0, pos1);
+ /*
+ * in this case, *any* of these is okay.
+ */
+ for (int i = 0; subdirs[i].name; i++) {
+ debug("searching for %s", subdirs[i].name);
+ pos0 = tosser0 = pos1 = -1;
+ rc = sscanf(current, subdirs[i].fmt, &pos0, &pos1, &pos2);
+ debug("current:'%s' rc:%d pos0:%d pos1:%d\n", current, rc,
+ *subdirs[i].pos0, *subdirs[i].pos1);
+ dbgmk(" ", *subdirs[i].pos0, *subdirs[i].pos1);
+ if (*subdirs[i].pos0 >= 0 && *subdirs[i].pos1 >= *subdirs[i].pos0) {
+ sz += *subdirs[i].pos1;
+ current += *subdirs[i].pos1;
+ break;
+ }
+ }
+
+ debug("searching for nvme0/nvme0n1 or nvme0/nvme0n1/nvme0n1p1");
+ rc = sscanf(current, "%nnvme%d/nvme%dn%d%n/nvme%dn%dp%d%n",
+ &pos0, &tosser0, &ctrl_id, &ns_id, &pos1,
+ &tosser1, &tosser2, &partition, &pos2);
+ debug("current:'%s' rc:%d pos0:%d pos1:%d pos2:%d\n", current, rc, pos0, pos1, pos2);
+ dbgmk(" ", pos0, MAX(pos1,pos2));
/*
* If it isn't of that form, it's not one of our nvme devices.
*/
@@ -79,14 +112,15 @@ parse_nvme(struct device *dev, const char *current, const char *root UNUSED)
if (dev->part == -1)
dev->part = partition;
- pos0 = pos1;
+ pos1 = pos2;
}
- sz += pos0;
+ sz += pos1;
/*
* now fish the eui out of sysfs is there is one...
*/
+ debug("looking for the eui");
char *euipath = NULL;
rc = read_sysfs_file(&filebuf, "class/block/nvme%dn%d/eui", ctrl_id, ns_id);
if (rc < 0 && (errno == ENOENT || errno == ENOTDIR)) {
@@ -109,6 +143,9 @@ parse_nvme(struct device *dev, const char *current, const char *root UNUSED)
errno = EINVAL;
return -1;
}
+ debug("eui is %02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
+ eui[0], eui[1], eui[2], eui[3],
+ eui[4], eui[5], eui[6], eui[7]);
dev->nvme_info.has_eui = 1;
memcpy(dev->nvme_info.eui, eui, sizeof(eui));
}
diff --git a/src/linux-virtual-root.c b/src/linux-virtual-root.c
new file mode 100644
index 00000000000..b2d36b4095f
--- /dev/null
+++ b/src/linux-virtual-root.c
@@ -0,0 +1,88 @@
+/*
+ * libefiboot - library for the manipulation of EFI boot variables
+ * Copyright 2012-2019 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 virtually rooted devices (fibre+nvme, etc.)
+ *
+ * /sys/dev/block/$major:$minor looks like:
+ * 259:0 ->../../devices/virtual/nvme-fabrics/ctl/nvme0/nvme0n1
+ * 259:1 ->../../devices/virtual/nvme-fabrics/ctl/nvme0/nvme0n1/nvme0n1p1
+ * or:
+ * 259:5 -> ../../devices/virtual/nvme-subsystem/nvme-subsys0/nvme0n1
+ * 259:6 -> ../../devices/virtual/nvme-subsystem/nvme-subsys0/nvme0n1/nvme0n1p1
+ */
+
+static ssize_t
+parse_virtual_root(struct device *dev UNUSED, const char *current, const char *root UNUSED)
+{
+ int rc;
+ ssize_t sz;
+ int pos0 = 0, pos1 = 0;
+ struct subdir {
+ const char * const name;
+ const char * const fmt;
+ } subdirs[] = {
+ {"../../devices/virtual", "%n../../devices/virtual/%n"},
+ {"nvme-subsystem/", "%nnvme-subsystem/%n"},
+ {"nvme-fabrics/ctl/", "%nnvme-fabrics/ctl/%n"},
+ {NULL, NULL}
+ };
+
+ debug("entry");
+
+ for (int i = 0; subdirs[i].name; i++) {
+ debug("searching for %s", subdirs[i].name);
+ pos0 = pos1 = -1;
+ rc = sscanf(current, subdirs[i].fmt, &pos0, &pos1);
+ debug("current:'%s' rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1);
+ dbgmk(" ", pos0, pos1);
+ if (rc == 1) {
+ sz += pos1;
+ current += pos1;
+ if (i > 0)
+ goto found;
+ }
+ }
+
+ sz = 0;
+found:
+ debug("current:'%s' sz:%zd\n", current, sz);
+ return sz;
+}
+
+static enum interface_type virtual_root_iftypes[] = { virtual_root, unknown };
+
+struct dev_probe HIDDEN virtual_root_parser = {
+ .name = "virtual_root",
+ .iftypes = virtual_root_iftypes,
+ .flags = DEV_ABBREV_ONLY|DEV_PROVIDES_ROOT,
+ .parse = parse_virtual_root,
+};
+
+// vim:fenc=utf-8:tw=75:noet
diff --git a/src/linux.c b/src/linux.c
index 30db22d95dd..7dd8d4cd858 100644
--- a/src/linux.c
+++ b/src/linux.c
@@ -170,16 +170,17 @@ int HIDDEN
set_disk_and_part_name(struct device *dev)
{
int rc = -1;
-
- /*
- * results are like such:
- * maj:min -> ../../devices/pci$PCI_STUFF/$BLOCKDEV_STUFF/block/$DISK/$PART
- */
-
char *ultimate = pathseg(dev->link, -1);
char *penultimate = pathseg(dev->link, -2);
char *approximate = pathseg(dev->link, -3);
char *proximate = pathseg(dev->link, -4);
+ char *psl5 = pathseg(dev->link, -5);
+
+
+ /*
+ * devlinks look something like:
+ * maj:min -> ../../devices/pci$PCI_STUFF/$BLOCKDEV_STUFF/block/$DISK/$PART
+ */
errno = 0;
debug("dev->disk_name:%p dev->part_name:%p", dev->disk_name, dev->part_name);
@@ -188,6 +189,7 @@ set_disk_and_part_name(struct device *dev)
debug("penultimate:'%s'", penultimate ? : "");
debug("approximate:'%s'", approximate ? : "");
debug("proximate:'%s'", proximate ? : "");
+ debug("psl5:'%s'", psl5 ? : "");
if (ultimate && penultimate &&
((proximate && !strcmp(proximate, "nvme")) ||
@@ -232,6 +234,34 @@ set_disk_and_part_name(struct device *dev)
set_disk_name(dev, "%s", ultimate);
debug("disk:%s", ultimate);
rc = 0;
+ } else if ((proximate && ultimate && !strcmp(proximate, "nvme-fabrics")) ||
+ (approximate && ultimate && !strcmp(approximate, "nvme-subsystem"))) {
+ /*
+ * 259:0 ->../../devices/virtual/nvme-fabrics/ctl/nvme0/nvme0n1
+ * ^ proximate ^ ultimate
+ * or
+ * 259:5 -> ../../devices/virtual/nvme-subsystem/nvme-subsys0/nvme0n1
+ * ^ approximate ^ penultimate
+ * ultimate ^
+ */
+ set_disk_name(dev, "%s", ultimate);
+ debug("disk:%s", ultimate);
+ rc = 0;
+ } else if ((psl5 && penultimate && ultimate && !strcmp(psl5, "nvme-fabrics")) ||
+ (proximate && penultimate && ultimate && !strcmp(proximate, "nvme-subsystem"))) {
+ /*
+ * 259:1 -> ../../devices/virtual/nvme-fabrics/ctl/nvme0/nvme0n1/nvme0n1p1
+ * ^psl5 ^ penultimate
+ * ultimate ^
+ * or
+ * 259:6 -> ../../devices/virtual/nvme-subsystem/nvme-subsys0/nvme0n1/nvme0n1p1
+ * ^ proximate ^ penultimate
+ * ultimate ^
+ */
+ set_disk_name(dev, "%s", penultimate);
+ set_part_name(dev, "%s", ultimate);
+ debug("disk:%s part:%s", penultimate, ultimate);
+ rc = 0;
}
if (rc < 0)
@@ -248,6 +278,7 @@ static struct dev_probe *dev_probes[] = {
&acpi_root_parser,
&pci_root_parser,
&soc_root_parser,
+ &virtual_root_parser,
&pci_parser,
&virtblk_parser,
&sas_parser,
diff --git a/src/linux.h b/src/linux.h
index ae9835ef7ce..6bfc5869254 100644
--- a/src/linux.h
+++ b/src/linux.h
@@ -99,7 +99,8 @@ struct emmc_info {
enum interface_type {
unknown,
- isa, acpi_root, pci_root, soc_root, pci, network,
+ isa, acpi_root, pci_root, soc_root, virtual_root,
+ pci, network,
ata, atapi, scsi, sata, sas,
usb, i1394, fibre, i2o,
md, virtblk,
@@ -346,6 +347,7 @@ 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 virtual_root_parser;
extern struct dev_probe pci_parser;
extern struct dev_probe sas_parser;
extern struct dev_probe sata_parser;
--
2.26.2

View File

@ -0,0 +1,778 @@
From fa9336914ef43d1a1dbc3384c8051362eea12cd7 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Tue, 15 Oct 2019 16:53:27 -0400
Subject: [PATCH 58/63] sysfs parsers: make all the /sys/block link parsers
work the same way
Apparently I wrote some of these one way and some the other, and the one
special case where everything was "current+sz" instead of some form of
"current += pos; sz += pos; ...; return sz;".
Make them all the same, where possible.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/linux-acpi-root.c | 65 +++++-----
src/linux-pci-root.c | 9 +-
src/linux-pci.c | 21 ++--
src/linux-sata.c | 56 +++++----
src/linux-scsi.c | 248 ++++++++++++++++++++-------------------
src/linux-soc-root.c | 19 +--
src/linux-virtblk.c | 15 ++-
src/linux-virtual-root.c | 2 +-
8 files changed, 227 insertions(+), 208 deletions(-)
diff --git a/src/linux-acpi-root.c b/src/linux-acpi-root.c
index 57a648981b3..6bfc1ad9a2b 100644
--- a/src/linux-acpi-root.c
+++ b/src/linux-acpi-root.c
@@ -44,14 +44,13 @@ static ssize_t
parse_acpi_root(struct device *dev, const char *current, const char *root UNUSED)
{
int rc;
- int pos = -1;
+ int pos0 = -1, pos1 = -1, pos2 = -1;
+ ssize_t sz = 0;
uint16_t pad0;
uint8_t pad1;
char *acpi_header = NULL;
char *colon;
- const char *devpart = current;
-
debug("entry");
/*
@@ -61,23 +60,26 @@ parse_acpi_root(struct device *dev, const char *current, const char *root UNUSED
* This is annoying because "/%04ms%h:%hhx/" won't bind from the right
* side in sscanf.
*/
- rc = sscanf(devpart, "../../devices/platform/%n", &pos);
- debug("current:'%s' rc:%d pos:%d", devpart, rc, pos);
- dbgmk(" ", pos);
- if (rc != 0 || pos < 1)
+ rc = sscanf(current, "../../devices/%nplatform/%n", &pos0, &pos1);
+ debug("current:'%s' rc:%d pos0:%d pos1:%d", current, rc, pos0, pos1);
+ dbgmk(" ", pos0, pos1);
+ if (rc != 0 || pos0 == -1 || pos1 == -1)
return 0;
- devpart += pos;
+ current += pos1;
+ sz += pos1;
+ debug("searching for an ACPI string like A0000:00 or ACPI0000:00");
+ pos0 = 0;
/*
* If it's too short to be A0000:00, it's not an ACPI string
*/
- if (strlen(devpart) < 8)
+ if (strlen(current) < 8)
return 0;
- colon = strchr(devpart, ':');
+ colon = strchr(current, ':');
if (!colon)
return 0;
- pos = colon - devpart;
+ pos1 = colon - current;
/*
* If colon doesn't point at something between one of these:
@@ -85,40 +87,44 @@ parse_acpi_root(struct device *dev, const char *current, const char *root UNUSED
* ^ 5 ^ 8
* Then it's not an ACPI string.
*/
- if (pos < 5 || pos > 8)
+ if (pos1 < 5 || pos1 > 8)
return 0;
- dev->acpi_root.acpi_hid_str = strndup(devpart, pos + 1);
+ debug("current:'%s' rc:%d pos0:%d pos1:%d", current, rc, pos0, pos1);
+ dbgmk(" ", pos0, pos1);
+
+ dev->acpi_root.acpi_hid_str = strndup(current, pos1 + 1);
if (!dev->acpi_root.acpi_hid_str) {
efi_error("Could not allocate memory");
return -1;
}
- dev->acpi_root.acpi_hid_str[pos] = 0;
+ dev->acpi_root.acpi_hid_str[pos1] = 0;
debug("acpi_hid_str:'%s'", dev->acpi_root.acpi_hid_str);
- pos -= 4;
- debug("current:'%s' rc:%d pos:%d", devpart, rc, pos);
- dbgmk(" ", pos);
- acpi_header = strndupa(devpart, pos);
+ pos2 = pos1 - 4;
+ debug("current:'%s' rc:%d pos0:%d pos1:%d", current, rc, pos0, pos2);
+ dbgmk(" ", pos0, pos2);
+ acpi_header = strndupa(current, pos2);
if (!acpi_header)
return 0;
- acpi_header[pos] = 0;
- debug("current:'%s' acpi_header:'%s'", devpart, acpi_header);
- devpart += pos;
+ acpi_header[pos2] = 0;
+ debug("current:'%s' acpi_header:'%s'", current, acpi_header);
+ current += pos1;
+ sz += pos1;
/*
* If we can't find these numbers, it's not an ACPI string
*/
- rc = sscanf(devpart, "%hx:%hhx/%n", &pad0, &pad1, &pos);
+ rc = sscanf(current, "%n%hx:%hhx/%n", &pos0, &pad0, &pad1, &pos1);
if (rc != 2) {
- efi_error("Could not parse ACPI path \"%s\"", devpart);
+ efi_error("Could not parse ACPI path \"%s\"", current);
return 0;
}
- debug("current:'%s' parsed:%04hx:%02hhx pos:%d rc:%d",
- devpart, pad0, pad1, pos, rc);
- dbgmk(" ", pos);
-
- devpart += pos;
+ debug("current:'%s' parsed:%04hx:%02hhx rc:%d pos0:%d pos1:%d",
+ current, pad0, pad1, rc, pos0, pos1);
+ dbgmk(" ", pos0, pos1);
+ current += pos1;
+ sz += pos1;
rc = parse_acpi_hid_uid(dev, "devices/platform/%s%04hX:%02hhX",
acpi_header, pad0, pad1);
@@ -139,8 +145,7 @@ parse_acpi_root(struct device *dev, const char *current, const char *root UNUSED
dev->acpi_root.acpi_uid_str,
dev->acpi_root.acpi_cid_str);
- size_t sz = devpart - current;
- debug("current:'%s' sz:%zd", devpart, sz);
+ debug("current:'%s' sz:%zd", current, sz);
return sz;
}
diff --git a/src/linux-pci-root.c b/src/linux-pci-root.c
index c7e279118f5..8f7cfe293bf 100644
--- a/src/linux-pci-root.c
+++ b/src/linux-pci-root.c
@@ -47,7 +47,6 @@ parse_pci_root(struct device *dev, const char *current, const char *root UNUSED)
int pos0 = -1, pos1 = -1;
uint16_t root_domain;
uint8_t root_bus;
- const char *devpart = current;
debug("entry");
@@ -56,8 +55,8 @@ parse_pci_root(struct device *dev, const char *current, const char *root UNUSED)
* pci0000:00/
* ^d ^p
*/
- rc = sscanf(devpart, "%n../../devices/pci%hx:%hhx/%n", &pos0, &root_domain, &root_bus, &pos1);
- debug("current:'%s' rc:%d pos0:%d pos1:%d", devpart, rc, pos0, pos1);
+ rc = sscanf(current, "%n../../devices/pci%hx:%hhx/%n", &pos0, &root_domain, &root_bus, &pos1);
+ debug("current:'%s' rc:%d pos0:%d pos1:%d", current, rc, pos0, pos1);
dbgmk(" ", pos0, pos1);
/*
@@ -65,7 +64,7 @@ parse_pci_root(struct device *dev, const char *current, const char *root UNUSED)
*/
if (rc != 2)
return 0;
- devpart += pos1;
+ current += pos1;
dev->pci_root.pci_domain = root_domain;
dev->pci_root.pci_bus = root_bus;
@@ -76,7 +75,7 @@ parse_pci_root(struct device *dev, const char *current, const char *root UNUSED)
return -1;
errno = 0;
- debug("current:'%s' sz:%d\n", devpart, pos1);
+ debug("current:'%s' sz:%d\n", current, pos1);
return pos1;
}
diff --git a/src/linux-pci.c b/src/linux-pci.c
index a3a0dc28afd..ca6f693cd8a 100644
--- a/src/linux-pci.c
+++ b/src/linux-pci.c
@@ -46,8 +46,7 @@ static ssize_t
parse_pci(struct device *dev, const char *current, const char *root)
{
int rc;
- int pos0 = -1, pos1 = -1;
- const char *devpart = current;
+ ssize_t sz = 0;
debug("entry");
@@ -55,22 +54,24 @@ parse_pci(struct device *dev, const char *current, const char *root)
* 0000:00:01.0/0000:01:00.0/
* ^d ^b ^d ^f (of the last one in the series)
*/
- while (*devpart) {
+ while (*current) {
uint16_t domain;
uint8_t bus, device, function;
struct pci_dev_info *pci_dev;
unsigned int i = dev->n_pci_devs;
struct stat statbuf;
+ int pos0 = -1, pos1 = -1;
pos0 = pos1 = -1;
debug("searching for 0000:00:00.0/");
- rc = sscanf(devpart, "%n%hx:%hhx:%hhx.%hhx/%n",
+ rc = sscanf(current, "%n%hx:%hhx:%hhx.%hhx/%n",
&pos0, &domain, &bus, &device, &function, &pos1);
- debug("current:'%s' rc:%d pos0:%d pos1:%d", devpart, rc, pos0, pos1);
+ debug("current:'%s' rc:%d pos0:%d pos1:%d", current, rc, pos0, pos1);
dbgmk(" ", pos0, pos1);
if (rc != 4)
break;
- devpart += pos1;
+ current += pos1;
+ sz += pos1;
debug("found pci domain %04hx:%02hhx:%02hhx.%02hhx",
domain, bus, device, function);
@@ -87,13 +88,13 @@ parse_pci(struct device *dev, const char *current, const char *root)
dev->pci_dev[i].pci_bus = bus;
dev->pci_dev[i].pci_device = device;
dev->pci_dev[i].pci_function = function;
- char *tmp = strndup(root, devpart-root+1);
+ char *tmp = strndup(root, current-root+1);
char *linkbuf = NULL;
if (!tmp) {
efi_error("could not allocate memory");
return -1;
}
- tmp[devpart - root] = '\0';
+ tmp[current - root] = '\0';
rc = sysfs_stat(&statbuf, "class/block/%s/driver", tmp);
if (rc < 0 && errno == ENOENT) {
debug("No driver link for /sys/class/block/%s", tmp);
@@ -114,8 +115,8 @@ parse_pci(struct device *dev, const char *current, const char *root)
dev->n_pci_devs += 1;
}
- debug("current:'%s' sz:%zd\n", devpart, devpart - current);
- return devpart - current;
+ debug("current:'%s' sz:%zd\n", current, sz);
+ return sz;
}
static ssize_t
diff --git a/src/linux-sata.c b/src/linux-sata.c
index 4f4e983568e..b49cf99dcb7 100644
--- a/src/linux-sata.c
+++ b/src/linux-sata.c
@@ -138,15 +138,15 @@ sysfs_sata_get_port_info(uint32_t print_id, struct device *dev)
}
static ssize_t
-parse_sata(struct device *dev, const char *devlink, const char *root UNUSED)
+parse_sata(struct device *dev, const char *current, const char *root UNUSED)
{
- const char *current = devlink;
uint32_t print_id;
uint32_t scsi_bus, tosser0;
uint32_t scsi_device, tosser1;
uint32_t scsi_target, tosser2;
uint64_t scsi_lun, tosser3;
- int pos = 0;
+ int pos0 = -1, pos1 = -1;
+ size_t sz = 0;
int rc;
debug("entry");
@@ -160,9 +160,9 @@ parse_sata(struct device *dev, const char *devlink, const char *root UNUSED)
* ^dev ^host x y z
*/
debug("searching for ata1/");
- rc = sscanf(current, "ata%"PRIu32"/%n", &print_id, &pos);
- debug("current:'%s' rc:%d pos:%d\n", current, rc, pos);
- dbgmk(" ", pos);
+ rc = sscanf(current, "%nata%"PRIu32"/%n", &pos0, &print_id, &pos1);
+ debug("current:'%s' rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1);
+ dbgmk(" ", pos0, pos1);
/*
* 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
@@ -170,36 +170,40 @@ parse_sata(struct device *dev, const char *devlink, const char *root UNUSED)
*/
if (rc != 1)
return 0;
- current += pos;
- pos = 0;
+ current += pos1;
+ sz += pos1;
+ pos0 = pos1 = -1;
debug("searching for host0/");
- rc = sscanf(current, "host%"PRIu32"/%n", &scsi_bus, &pos);
- debug("current:'%s' rc:%d pos:%d\n", current, rc, pos);
- dbgmk(" ", pos);
+ rc = sscanf(current, "%nhost%"PRIu32"/%n", &pos0, &scsi_bus, &pos1);
+ debug("current:'%s' rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1);
+ dbgmk(" ", pos0, pos1);
if (rc != 1)
return -1;
- current += pos;
- pos = 0;
+ current += pos1;
+ sz += pos1;
+ pos0 = pos1 = -1;
debug("searching for target0:0:0:0/");
- 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);
- dbgmk(" ", pos);
+ rc = sscanf(current, "%ntarget%"PRIu32":%"PRIu32":%"PRIu64"/%n",
+ &pos0, &scsi_device, &scsi_target, &scsi_lun, &pos1);
+ debug("current:'%s' rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1);
+ dbgmk(" ", pos0, pos1);
if (rc != 3)
return -1;
- current += pos;
- pos = 0;
+ current += pos1;
+ sz += pos1;
+ pos0 = pos1 = -1;
debug("searching for 0:0:0:0/");
- rc = sscanf(current, "%"PRIu32":%"PRIu32":%"PRIu32":%"PRIu64"/%n",
- &tosser0, &tosser1, &tosser2, &tosser3, &pos);
- debug("current:'%s' rc:%d pos:%d\n", current, rc, pos);
- dbgmk(" ", pos);
+ rc = sscanf(current, "%n%"PRIu32":%"PRIu32":%"PRIu32":%"PRIu64"/%n",
+ &pos0, &tosser0, &tosser1, &tosser2, &tosser3, &pos1);
+ debug("current:'%s' rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1);
+ dbgmk(" ", pos0, pos1);
if (rc != 4)
return -1;
- current += pos;
+ current += pos1;
+ sz += pos1;
rc = sysfs_sata_get_port_info(print_id, dev);
if (rc < 0)
@@ -213,8 +217,8 @@ parse_sata(struct device *dev, const char *devlink, const char *root UNUSED)
if (dev->interface_type == unknown)
dev->interface_type = sata;
- debug("current:'%s' sz:%zd\n", current, current - devlink);
- return current - devlink;
+ debug("current:'%s' sz:%zd\n", current, sz);
+ return sz;
}
static ssize_t
diff --git a/src/linux-scsi.c b/src/linux-scsi.c
index 6b92908d6bc..73db53b3ed6 100644
--- a/src/linux-scsi.c
+++ b/src/linux-scsi.c
@@ -24,6 +24,7 @@
#include <fcntl.h>
#include <inttypes.h>
#include <stdint.h>
+#include <sys/param.h>
#include <unistd.h>
#include "efiboot.h"
@@ -44,7 +45,7 @@ parse_scsi_link(const char *current, uint32_t *scsi_host,
{
int rc;
ssize_t sz = 0;
- int pos0 = 0, pos1 = 0;
+ int pos0 = -1, pos1 = -1, pos2 = -1;
debug("entry");
/*
@@ -99,14 +100,14 @@ parse_scsi_link(const char *current, uint32_t *scsi_host,
* or host4/port-4:0:0
*/
debug("searching for host4/");
- rc = sscanf(current, "host%d/%n", scsi_host, &pos0);
- debug("current:'%s' rc:%d pos0:%d\n", current, rc, pos0);
- dbgmk(" ", pos0);
+ rc = sscanf(current, "%nhost%d/%n", scsi_host, &pos0, &pos1);
+ debug("current:'%s' rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1);
+ dbgmk(" ", pos0, pos1);
if (rc != 1)
return -1;
- current += pos0;
- sz += pos0;
- pos0 = 0;
+ current += pos1;
+ sz += pos1;
+ pos0 = pos1 = -1;
/*
* We might have this next:
@@ -117,96 +118,100 @@ parse_scsi_link(const char *current, uint32_t *scsi_host,
* port-2:0:2/end_device-2:0:2/target2:0:0/2:0:0:0/block/sda/sda1
*/
debug("searching for port-4:0 or port-4:0:0");
- rc = sscanf(current, "port-%d:%d%n:%d%n", &tosser0,
- &tosser1, &pos0, &tosser2, &pos1);
- debug("current:'%s' rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1);
- dbgmk(" ", pos0, pos1);
- if (rc == 2 || rc == 3) {
- current += pos0;
- sz += pos0;
- pos0 = 0;
- if (local_port_id && rc == 2)
- *local_port_id = tosser1;
- if (remote_port_id && rc == 3)
- *remote_port_id = tosser2;
-
- if (current[0] == '/') {
- current += 1;
- sz += 1;
- }
-
- /*
- * We might have this next:
- * expander-2:0/port-2:0:2/end_device-2:0:2/target2:0:0/2:0:0:0/block/sda/sda1
- * ^ port id
- * ^ scsi target id
- * ^ host number
- * ^ host number
- * We don't actually care about either number in expander-.../,
- * because they're replicated in all the other places. We just need
- * to get past it.
- */
- debug("searching for expander-4:0/");
- rc = sscanf(current, "expander-%d:%d/%n", &tosser0, &tosser1, &pos0);
- debug("current:'%s' rc:%d pos0:%d\n", current, rc, pos0);
- dbgmk(" ", pos0);
- if (rc == 2) {
- if (!remote_target_id) {
- efi_error("Device is PHY is a remote target, but remote_target_id is NULL");
- return -1;
- }
- *remote_target_id = tosser1;
- current += pos0;
- sz += pos0;
- pos0 = 0;
-
- /*
- * if we have that, we should have a 3-part port next
- */
- debug("searching for port-2:0:2/");
- rc = sscanf(current, "port-%d:%d:%d/%n", &tosser0, &tosser1, &tosser2, &pos0);
- debug("current:'%s' rc:%d pos0:%d\n", current, rc, pos0);
- dbgmk(" ", pos0);
- if (rc != 3) {
- efi_error("Couldn't parse port expander port string");
- return -1;
- }
- current += pos0;
- sz += pos0;
- }
- pos0 = 0;
-
- /* next:
- * /end_device-4:0
- * or /end_device-4:0:0
- * awesomely these are the exact same fields that go into port-blah,
- * but we don't care for now about any of them anyway.
- */
- debug("searching for end_device-4:0/ or end_device-4:0:0/");
- rc = sscanf(current, "end_device-%d:%d%n", &tosser0, &tosser1, &pos0);
- debug("current:'%s' rc:%d pos0:%d\n", current, rc, pos0);
- if (rc != 2)
- return -1;
+ rc = sscanf(current, "%nport-%d:%d%n:%d%n",
+ &pos0, &tosser0, &tosser1, &pos1, &tosser2, &pos2);
+ debug("current:'%s' rc:%d pos0:%d pos1:%d pos2:%d\n", current, rc, pos0, pos1, pos2);
+ dbgmk(" ", pos0, MAX(pos1, pos2));
+ if (rc == 3) {
+ if (remote_port_id)
+ *remote_port_id = tosser2;
+ pos1 = pos2;
+ } else if (rc == 2) {
+ if (local_port_id)
+ *local_port_id = tosser1;
+ } else if (rc != 0) {
+ return -1;
+ } else {
+ pos1 = 0;
+ }
+ current += pos1;
+ sz += pos1;
- pos1 = 0;
- rc = sscanf(current + pos0, ":%d%n", &tosser2, &pos1);
- if (rc != 0 && rc != 1)
- return -1;
- dbgmk(" ", pos0, pos0+pos1);
- if (remote_port_id && rc == 1)
- *remote_port_id = tosser2;
- if (local_port_id && rc == 0)
- *local_port_id = tosser1;
- current += pos0 + pos1;
- sz += pos0 + pos1;
- pos0 = pos1 = 0;
+ if (current[0] == '/') {
+ current += 1;
+ sz += 1;
+ }
+ pos0 = pos1 = pos2 = -1;
+
+ /*
+ * We might have this next:
+ * expander-2:0/port-2:0:2/end_device-2:0:2/target2:0:0/2:0:0:0/block/sda/sda1
+ * ^ port id
+ * ^ scsi target id
+ * ^ host number
+ * ^ host number
+ * We don't actually care about either number in expander-.../,
+ * because they're replicated in all the other places. We just need
+ * to get past it.
+ */
+ debug("searching for expander-4:0/");
+ rc = sscanf(current, "%nexpander-%d:%d/%n", &pos0, &tosser0, &tosser1, &pos1);
+ debug("current:'%s' rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1);
+ dbgmk(" ", pos0, pos1);
+ if (rc == 2) {
+ if (!remote_target_id) {
+ efi_error("Device is PHY is a remote target, but remote_target_id is NULL");
+ return -1;
+ }
+ *remote_target_id = tosser1;
+ current += pos1;
+ sz += pos1;
+ pos0 = pos1 = -1;
+
+ /*
+ * if we have that, we should have a 3-part port next
+ */
+ debug("searching for port-2:0:2/");
+ rc = sscanf(current, "%nport-%d:%d:%d/%n", &pos0, &tosser0, &tosser1, &tosser2, &pos1);
+ debug("current:'%s' rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1);
+ dbgmk(" ", pos0, pos1);
+ if (rc != 3) {
+ efi_error("Couldn't parse port expander port string");
+ return -1;
+ }
+ current += pos1;
+ sz += pos1;
+ }
+ pos0 = pos1 = -1;
+
+ /* next:
+ * /end_device-4:0
+ * or /end_device-4:0:0
+ * awesomely these are the exact same fields that go into port-blah,
+ * but we don't care for now about any of them anyway.
+ */
+ debug("searching for end_device-4:0/ or end_device-4:0:0/");
+ rc = sscanf(current, "%nend_device-%d:%d%n:%d%n",
+ &pos0, &tosser0, &tosser1, &pos1, &tosser2, &pos2);
+ debug("current:'%s' rc:%d pos0:%d\n", current, rc, pos0);
+ dbgmk(" ", pos0, MAX(pos1, pos2));
+ if (rc == 3) {
+ if (remote_port_id)
+ *remote_port_id = tosser2;
+ pos1 = pos2;
+ } else if (rc == 2) {
+ if (local_port_id)
+ *local_port_id = tosser1;
+ } else {
+ pos1 = 0;
+ }
+ current += pos1;
+ sz += pos1;
+ pos0 = pos1 = pos2 = -1;
- if (current[0] == '/') {
- current += sz;
- sz += 1;
- }
- } else if (rc != 0) {
- return -1;
+ if (current[0] == '/') {
+ current += sz;
+ sz += 1;
}
/* now:
@@ -214,28 +219,28 @@ parse_scsi_link(const char *current, uint32_t *scsi_host,
*/
uint64_t tosser3;
debug("searching for target4:0:0/");
- rc = sscanf(current, "target%d:%d:%"PRIu64"/%n", &tosser0, &tosser1,
- &tosser3, &pos0);
- debug("current:'%s' rc:%d pos0:%d\n", current, rc, pos0);
- dbgmk(" ", pos0);
+ rc = sscanf(current, "%ntarget%d:%d:%"PRIu64"/%n",
+ &pos0, &tosser0, &tosser1, &tosser3, &pos1);
+ debug("current:'%s' rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1);
+ dbgmk(" ", pos0, pos1);
if (rc != 3)
return -1;
- current += pos0;
- sz += pos0;
- pos0 = 0;
+ current += pos1;
+ sz += pos1;
+ pos0 = pos1 = -1;
/* now:
* %d:%d:%d:%llu/
*/
debug("searching for 4:0:0:0/");
- rc = sscanf(current, "%d:%d:%d:%"PRIu64"/%n",
- scsi_bus, scsi_device, scsi_target, scsi_lun, &pos0);
- debug("current:'%s' rc:%d pos0:%d\n", current, rc, pos0);
- dbgmk(" ", pos0);
+ rc = sscanf(current, "%n%d:%d:%d:%"PRIu64"/%n",
+ &pos0, scsi_bus, scsi_device, scsi_target, scsi_lun, &pos1);
+ debug("current:'%s' rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1);
+ dbgmk(" ", pos0, pos1);
if (rc != 4)
return -1;
- current += pos0;
- sz += pos0;
+ current += pos1;
+ sz += pos1;
debug("current:'%s' sz:%zd\n", current, sz);
return sz;
@@ -246,31 +251,32 @@ 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;
- ssize_t sz;
- int pos;
+ ssize_t sz = 0;
+ int pos0, pos1;
int rc;
debug("entry");
- debug("searching for ../../../0:0:0:0");
- rc = sscanf(dev->device, "../../../%d:%d:%d:%"PRIu64"%n",
+ debug("searching device for ../../../0:0:0:0");
+ pos0 = pos1 = -1;
+ rc = sscanf(dev->device, "../../../%n%d:%d:%d:%"PRIu64"%n",
+ &pos0,
&dev->scsi_info.scsi_bus,
&dev->scsi_info.scsi_device,
&dev->scsi_info.scsi_target,
&dev->scsi_info.scsi_lun,
- &pos);
- debug("current:'%s' rc:%d pos:%d\n", dev->device, rc, pos);
- dbgmk(" ", pos);
+ &pos1);
+ debug("device:'%s' rc:%d pos0:%d pos1:%d\n", dev->device, rc, pos0, pos1);
+ dbgmk(" ", pos0, pos1);
if (rc != 4)
return 0;
- sz = parse_scsi_link(current, &scsi_host,
- &scsi_bus, &scsi_device,
- &scsi_target, &scsi_lun,
- NULL, NULL, NULL);
- if (sz < 0)
+ pos0 = parse_scsi_link(current, &scsi_host, &scsi_bus, &scsi_device,
+ &scsi_target, &scsi_lun, NULL, NULL, NULL);
+ if (pos0 < 0)
return 0;
- current += sz;
+ current += pos0;
+ sz += pos0;
/*
* SCSI disks can have up to 16 partitions, or 4 bits worth
diff --git a/src/linux-soc-root.c b/src/linux-soc-root.c
index 9c9e9573dcd..bad37c9f874 100644
--- a/src/linux-soc-root.c
+++ b/src/linux-soc-root.c
@@ -41,20 +41,21 @@ static ssize_t
parse_soc_root(struct device *dev UNUSED, const char *current, const char *root UNUSED)
{
int rc;
- int pos = 0;
- const char *devpart = current;
+ int pos0 = -1, pos1 = -1;
+ ssize_t sz = 0;
debug("entry");
- rc = sscanf(devpart, "../../devices/platform/soc/%*[^/]/%n", &pos);
- if (rc != 0)
+ rc = sscanf(current, "../../devices/%nplatform/soc/%*[^/]/%n", &pos0, &pos1);
+ if (rc != 0 || pos0 == -1 || pos1 == -1)
return 0;
- debug("current:'%s' rc:%d pos:%d", current, rc, pos);
- dbgmk(" ", pos);
- devpart += pos;
+ debug("current:'%s' rc:%d pos0:%d pos1:%d", current, rc, pos0, pos1);
+ dbgmk(" ", pos0, pos1);
+ current += pos1;
+ sz += pos1;
- debug("current:'%s' sz:%d\n", devpart, pos);
- return pos;
+ debug("current:'%s' sz:%zd\n", current, sz);
+ return sz;
}
enum interface_type soc_root_iftypes[] = { soc_root, unknown };
diff --git a/src/linux-virtblk.c b/src/linux-virtblk.c
index df14673dac8..a3366c9c677 100644
--- a/src/linux-virtblk.c
+++ b/src/linux-virtblk.c
@@ -48,15 +48,16 @@ static ssize_t
parse_virtblk(struct device *dev, const char *current, const char *root UNUSED)
{
uint32_t tosser;
- int pos = -1;
+ int pos0 = -1, pos1 = -1;
+ ssize_t sz = 0;
int rc;
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);
- dbgmk(" ", pos);
+ rc = sscanf(current, "%nvirtio%x/%n", &pos0, &tosser, &pos1);
+ debug("current:'%s' rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1);
+ dbgmk(" ", pos0, pos1);
/*
* If we couldn't find virtioX/ then it isn't a virtio device.
*/
@@ -64,9 +65,11 @@ parse_virtblk(struct device *dev, const char *current, const char *root UNUSED)
return 0;
dev->interface_type = virtblk;
+ current += pos1;
+ sz += pos1;
- debug("current:'%s' sz:%d\n", current, pos);
- return pos;
+ debug("current:'%s' sz:%zd\n", current, sz);
+ return sz;
}
enum interface_type virtblk_iftypes[] = { virtblk, unknown };
diff --git a/src/linux-virtual-root.c b/src/linux-virtual-root.c
index b2d36b4095f..75fbbfc1de6 100644
--- a/src/linux-virtual-root.c
+++ b/src/linux-virtual-root.c
@@ -61,7 +61,7 @@ parse_virtual_root(struct device *dev UNUSED, const char *current, const char *r
pos0 = pos1 = -1;
rc = sscanf(current, subdirs[i].fmt, &pos0, &pos1);
debug("current:'%s' rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1);
- dbgmk(" ", pos0, pos1);
+ dbgmk(" ", pos0, pos1);
if (rc == 1) {
sz += pos1;
current += pos1;
--
2.26.2

View File

@ -0,0 +1,72 @@
From effecb5ce0baf2fae011dd61e45852cd2fb1ec19 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Tue, 15 Oct 2019 16:58:19 -0400
Subject: [PATCH 59/63] Put some EFI device paths into the debug log
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/linux.c | 41 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
diff --git a/src/linux.c b/src/linux.c
index 7dd8d4cd858..9d8480a94a9 100644
--- a/src/linux.c
+++ b/src/linux.c
@@ -336,6 +336,44 @@ device_free(struct device *dev)
free(dev);
}
+static void
+print_dev_dp_node(struct device *dev, struct dev_probe *probe)
+{
+ ssize_t dpsz;
+ uint8_t *dp;
+ ssize_t bufsz;
+ uint8_t *buf;
+
+ dpsz = probe->create(dev, NULL, 0, 0);
+ if (dpsz <= 0)
+ return;
+
+ dp = alloca(dpsz + 4);
+ if (!dp)
+ return;
+
+ dpsz = probe->create(dev, dp, dpsz, 0);
+ if (dpsz <= 0)
+ return;
+
+ efidp_make_end_entire(dp + dpsz, 4);
+ bufsz = efidp_format_device_path(NULL, 0,
+ (const_efidp)dp, dpsz + 4);
+ if (bufsz <= 0)
+ return;
+
+ buf = alloca(bufsz);
+ if (!buf)
+ return;
+
+ bufsz = efidp_format_device_path(buf, bufsz,
+ (const_efidp)dp, dpsz + 4);
+ if (bufsz <= 0)
+ return;
+
+ debug("Device path node is %s", buf);
+}
+
struct device HIDDEN
*device_get(int fd, int partition)
{
@@ -512,6 +550,9 @@ struct device HIDDEN
probe->flags & DEV_ABBREV_ONLY)
needs_root = false;
+ if (probe->create)
+ print_dev_dp_node(dev, probe);
+
dev->probes[n++] = dev_probes[i];
current += pos;
if (current[0] == '\0')
--
2.26.2

Some files were not shown because too many files have changed in this diff Show More