From b384db34664466386016b03615fe1387aa2d53c7 Mon Sep 17 00:00:00 2001 From: Idwer Vollering Date: Mon, 10 May 2021 21:15:45 +0200 Subject: portability fixes: support building vboot on OpenBSD This was done on OpenBSD 6.8. Required packages are: e2fsprogs and gcc. Change-Id: I86ec080e1ddb90053d81f1edd17d3406e7e737c6 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/2903352 Reviewed-by: Patrick Georgi Tested-by: Patrick Georgi Commit-Queue: Patrick Georgi --- Makefile | 8 ++++++++ cgpt/cgpt.h | 2 +- cgpt/cgpt_common.c | 6 +++--- futility/cmd_vbutil_kernel.c | 4 ++-- futility/dump_kernel_config_lib.c | 4 ++-- futility/misc.c | 4 ++-- futility/updater_archive.c | 3 +++ futility/updater_utils.c | 2 +- host/arch/x86/lib/crossystem_arch.c | 6 +++--- 9 files changed, 25 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index acaad3e3..ab8f7912 100644 --- a/Makefile +++ b/Makefile @@ -373,6 +373,9 @@ INCLUDES += \ ifeq (${FIRMWARE_ARCH},) INCLUDES += -Ihost/include -Ihost/lib/include INCLUDES += -Ihost/lib21/include +ifeq ($(shell uname -s), OpenBSD) +INCLUDES += -I/usr/local/include +endif endif # Firmware library, used by the other firmware components (depthcharge, @@ -963,6 +966,8 @@ cgpt: ${CGPT} $(if ${GPT_SPI_NOR},cgpt_wrapper) # on FreeBSD: install misc/e2fsprogs-libuuid from ports, # or e2fsprogs-libuuid from its binary package system. +# on OpenBSD: install sysutils/e2fsprogs from ports, +# or e2fsprogs from its binary package system, to install uuid/uid.h ${CGPT}: LDLIBS += -luuid ${CGPT}: ${CGPT_OBJS} ${UTILLIB} @@ -1138,6 +1143,9 @@ CRYPTO_LIBS := $(shell ${PKG_CONFIG} --libs libcrypto) ifeq ($(shell uname -s), FreeBSD) CRYPTO_LIBS += -lcrypto endif +ifeq ($(shell uname -s), OpenBSD) +LDFLAGS += -Wl,-z,notext +endif ${BUILD}/utility/dumpRSAPublicKey: LDLIBS += ${CRYPTO_LIBS} ${BUILD}/utility/pad_digest_utility: LDLIBS += ${CRYPTO_LIBS} diff --git a/cgpt/cgpt.h b/cgpt/cgpt.h index 0747b5ce..89c357e8 100644 --- a/cgpt/cgpt.h +++ b/cgpt/cgpt.h @@ -7,7 +7,7 @@ #define VBOOT_REFERENCE_CGPT_H_ #include -#if !defined(HAVE_MACOS) && !defined(__FreeBSD__) +#if !defined(HAVE_MACOS) && !defined(__FreeBSD__) && !defined(__OpenBSD__) #include #endif #include diff --git a/cgpt/cgpt_common.c b/cgpt/cgpt_common.c index 426be3b8..c3edd0fc 100644 --- a/cgpt/cgpt_common.c +++ b/cgpt/cgpt_common.c @@ -9,7 +9,7 @@ #include #include #include -#if !defined(HAVE_MACOS) && !defined(__FreeBSD__) +#if !defined(HAVE_MACOS) && !defined(__FreeBSD__) && !defined(__OpenBSD__) #include #include #endif @@ -295,7 +295,7 @@ static int ObtainDriveSize(int fd, uint64_t* size, uint32_t* sector_bytes) { if (fstat(fd, &stat) == -1) { return -1; } -#if !defined(HAVE_MACOS) && !defined(__FreeBSD__) +#if !defined(HAVE_MACOS) && !defined(__FreeBSD__) && !defined(__OpenBSD__) if ((stat.st_mode & S_IFMT) != S_IFREG) { if (ioctl(fd, BLKGETSIZE64, size) < 0) { return -1; @@ -325,7 +325,7 @@ int DriveOpen(const char *drive_path, struct drive *drive, int mode, memset(drive, 0, sizeof(struct drive)); drive->fd = open(drive_path, mode | -#if !defined(HAVE_MACOS) && !defined(__FreeBSD__) +#if !defined(HAVE_MACOS) && !defined(__FreeBSD__) && !defined(__OpenBSD__) O_LARGEFILE | #endif O_NOFOLLOW); diff --git a/futility/cmd_vbutil_kernel.c b/futility/cmd_vbutil_kernel.c index 83a76f84..27cbb9bc 100644 --- a/futility/cmd_vbutil_kernel.c +++ b/futility/cmd_vbutil_kernel.c @@ -9,7 +9,7 @@ #include #include #include /* For PRIu64 */ -#if !defined(HAVE_MACOS) && !defined(__FreeBSD__) +#if !defined(HAVE_MACOS) && !defined(__FreeBSD__) && !defined(__OpenBSD__) #include /* For BLKGETSIZE64 */ #endif #include @@ -173,7 +173,7 @@ static uint8_t *ReadOldKPartFromFileOrDie(const char *filename, FATAL("Unable to stat %s: %s\n", filename, strerror(errno)); if (S_ISBLK(statbuf.st_mode)) { -#if !defined(HAVE_MACOS) && !defined(__FreeBSD__) +#if !defined(HAVE_MACOS) && !defined(__FreeBSD__) && !defined(__OpenBSD__) int fd = open(filename, O_RDONLY); if (fd >= 0) { ioctl(fd, BLKGETSIZE64, &file_size); diff --git a/futility/dump_kernel_config_lib.c b/futility/dump_kernel_config_lib.c index 4240e5ed..ff39c412 100644 --- a/futility/dump_kernel_config_lib.c +++ b/futility/dump_kernel_config_lib.c @@ -10,7 +10,7 @@ #include #include #include -#if !defined (__FreeBSD__) +#if !defined (__FreeBSD__) && !defined(__OpenBSD__) #include #endif #include @@ -125,7 +125,7 @@ char *FindKernelConfig(const char *infile, uint64_t kernel_body_load_address) char *newstr = NULL; int fd = open(infile, O_RDONLY | O_CLOEXEC -#if !defined(__FreeBSD__) +#if !defined(__FreeBSD__) && !defined(__OpenBSD__) | O_LARGEFILE #endif ); diff --git a/futility/misc.c b/futility/misc.c index 0c8a0e71..f3e7748e 100644 --- a/futility/misc.c +++ b/futility/misc.c @@ -5,7 +5,7 @@ #include #include -#if !defined(HAVE_MACOS) && !defined(__FreeBSD__) +#if !defined(HAVE_MACOS) && !defined(__FreeBSD__) && !defined(__OpenBSD__) #include /* For BLKGETSIZE64 */ #endif #include @@ -272,7 +272,7 @@ enum futil_file_err futil_map_file(int fd, int writeable, return FILE_ERR_STAT; } -#if !defined(HAVE_MACOS) && !defined(__FreeBSD__) +#if !defined(HAVE_MACOS) && !defined(__FreeBSD__) && !defined(__OpenBSD__) if (S_ISBLK(sb.st_mode)) ioctl(fd, BLKGETSIZE64, &sb.st_size); #endif diff --git a/futility/updater_archive.c b/futility/updater_archive.c index 218499e4..70d8bb33 100644 --- a/futility/updater_archive.c +++ b/futility/updater_archive.c @@ -8,6 +8,9 @@ #include #include #include +#if defined(__OpenBSD__) +#include +#endif #include #include #include diff --git a/futility/updater_utils.c b/futility/updater_utils.c index 1c626bcd..70ed3962 100644 --- a/futility/updater_utils.c +++ b/futility/updater_utils.c @@ -10,7 +10,7 @@ #include #include #include -#if defined (__FreeBSD__) +#if defined (__FreeBSD__) || defined(__OpenBSD__) #include #endif diff --git a/host/arch/x86/lib/crossystem_arch.c b/host/arch/x86/lib/crossystem_arch.c index 6a8f5a26..e805e2a9 100644 --- a/host/arch/x86/lib/crossystem_arch.c +++ b/host/arch/x86/lib/crossystem_arch.c @@ -7,7 +7,7 @@ #include #include #include -#if !defined(__FreeBSD__) +#if !defined(__FreeBSD__) && !defined(__OpenBSD__) #include #include #endif @@ -100,7 +100,7 @@ typedef struct { static void VbFixCmosChecksum(FILE* file) { -#if !defined(__FreeBSD__) +#if !defined(__FreeBSD__) && !defined(__OpenBSD__) int fd = fileno(file); ioctl(fd, NVRAM_SETCKS); #endif @@ -666,7 +666,7 @@ static int BraswellFindGpioChipOffset(unsigned *gpio_num, unsigned *offset, if (uname(&host) == 0) { if (sscanf(host.release, "%u.%u.", &maj, &min) == 2) { -#if !defined(__FreeBSD__) +#if !defined(__FreeBSD__) && !defined(__OpenBSD__) if (KERNEL_VERSION(maj, min, 0) >= KERNEL_VERSION(4, 16, 0) && *offset > 11) *offset += 3; -- cgit v1.2.1