summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIdwer Vollering <vidwer@gmail.com>2020-08-28 23:16:28 +0200
committerCommit Bot <commit-bot@chromium.org>2020-09-11 01:29:19 +0000
commitade6151a678c59e270c89bcca37f61cfdd41700d (patch)
tree446f2f41581df2f1939abaa544b4ead71a36417a
parent176e01ded3bcefb6cb8baa984a158d42562bb1e9 (diff)
downloadvboot-ade6151a678c59e270c89bcca37f61cfdd41700d.tar.gz
portability fixes: support building vboot on FreeBSD
Built on FreeBSD 12.1-RELEASE, 13-CURRENT, using gcc9 installed from packages. Change-Id: Ifa8bb343c7e916c1b545cf6c1e4bd0a18ea391cd Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/2382790 Reviewed-by: Julius Werner <jwerner@chromium.org> Tested-by: Julius Werner <jwerner@chromium.org> Commit-Queue: Julius Werner <jwerner@chromium.org>
-rw-r--r--Makefile7
-rw-r--r--cgpt/cgpt.h2
-rw-r--r--cgpt/cgpt_common.c6
-rw-r--r--cgpt/cgpt_endian.h4
-rw-r--r--cgpt/cgpt_nor.c2
-rw-r--r--cgpt/cgpt_wrapper.c13
-rw-r--r--futility/cmd_vbutil_kernel.c4
-rw-r--r--futility/dump_kernel_config_lib.c8
-rw-r--r--futility/misc.c4
-rw-r--r--futility/updater_utils.c3
-rw-r--r--host/arch/x86/lib/crossystem_arch.c6
-rw-r--r--host/lib/flashrom.c4
-rwxr-xr-xscripts/getversion.sh2
13 files changed, 49 insertions, 16 deletions
diff --git a/Makefile b/Makefile
index f77e79e9..637ca873 100644
--- a/Makefile
+++ b/Makefile
@@ -325,7 +325,7 @@ export BUILD_RUN
.PHONY: all
all: fwlib futil utillib hostlib cgpt tlcl \
$(if ${SDK_BUILD},utils_sdk,utils_board) \
- $(if $(filter x86_64,${ARCH}),fuzzers) \
+ $(if $(filter x86_64,${ARCH}),$(if $(filter clang,${CC}),fuzzers)) \
$(if ${COV},coverage)
##############################################################################
@@ -944,6 +944,8 @@ ${CGPT_WRAPPER}: ${CGPT_WRAPPER_OBJS} ${UTILLIB}
.PHONY: cgpt
cgpt: ${CGPT} ${CGPT_WRAPPER}
+# on FreeBSD: install misc/e2fsprogs-libuuid from ports,
+# or e2fsprogs-libuuid from its binary package system.
${CGPT}: LDLIBS += -luuid
${CGPT}: ${CGPT_OBJS} ${UTILLIB}
@@ -1116,6 +1118,9 @@ ${UTIL_DEFAULTS}:
# Some utilities need external crypto functions
CRYPTO_LIBS := $(shell ${PKG_CONFIG} --libs libcrypto)
+ifeq ($(shell uname -s), FreeBSD)
+CRYPTO_LIBS += -lcrypto
+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 23f2f90c..0747b5ce 100644
--- a/cgpt/cgpt.h
+++ b/cgpt/cgpt.h
@@ -7,7 +7,7 @@
#define VBOOT_REFERENCE_CGPT_H_
#include <fcntl.h>
-#ifndef HAVE_MACOS
+#if !defined(HAVE_MACOS) && !defined(__FreeBSD__)
#include <features.h>
#endif
#include <stdint.h>
diff --git a/cgpt/cgpt_common.c b/cgpt/cgpt_common.c
index 2ace9002..426be3b8 100644
--- a/cgpt/cgpt_common.c
+++ b/cgpt/cgpt_common.c
@@ -9,7 +9,7 @@
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
-#ifndef HAVE_MACOS
+#if !defined(HAVE_MACOS) && !defined(__FreeBSD__)
#include <linux/major.h>
#include <mtd/mtd-user.h>
#endif
@@ -295,7 +295,7 @@ static int ObtainDriveSize(int fd, uint64_t* size, uint32_t* sector_bytes) {
if (fstat(fd, &stat) == -1) {
return -1;
}
-#ifndef HAVE_MACOS
+#if !defined(HAVE_MACOS) && !defined(__FreeBSD__)
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 |
-#ifndef HAVE_MACOS
+#if !defined(HAVE_MACOS) && !defined(__FreeBSD__)
O_LARGEFILE |
#endif
O_NOFOLLOW);
diff --git a/cgpt/cgpt_endian.h b/cgpt/cgpt_endian.h
index a40b2c18..f59ab1b2 100644
--- a/cgpt/cgpt_endian.h
+++ b/cgpt/cgpt_endian.h
@@ -7,8 +7,10 @@
#define VBOOT_REFERENCE_CGPT_ENDIAN_H_
// Newer distros already have this. For those that don't, we add it here.
-#ifndef HAVE_MACOS
+#if !defined(HAVE_MACOS) && !defined(__FreeBSD__)
#include <endian.h>
+#elif defined(__FreeBSD__)
+#include <sys/endian.h>
#endif
#ifndef le16toh
diff --git a/cgpt/cgpt_nor.c b/cgpt/cgpt_nor.c
index f8b361f8..fd184463 100644
--- a/cgpt/cgpt_nor.c
+++ b/cgpt/cgpt_nor.c
@@ -8,7 +8,9 @@
#include <fcntl.h>
#include <ftw.h>
#include <inttypes.h>
+#if !defined(__FreeBSD__)
#include <linux/major.h>
+#endif
#include <stdbool.h>
#include <stdarg.h>
#include <stdlib.h>
diff --git a/cgpt/cgpt_wrapper.c b/cgpt/cgpt_wrapper.c
index 2b473835..d26682dd 100644
--- a/cgpt/cgpt_wrapper.c
+++ b/cgpt/cgpt_wrapper.c
@@ -11,14 +11,18 @@
#include <fcntl.h>
#include <inttypes.h>
#include <limits.h>
+#if !defined(__FreeBSD__)
#include <linux/major.h>
+#endif
#include <stdbool.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
+#if !defined(__FreeBSD__)
#include <sys/sysmacros.h>
+#endif
#include <sys/types.h>
#include <unistd.h>
@@ -49,11 +53,12 @@ static bool is_mtd(const char *device_path) {
return false;
}
- if (major(stat.st_rdev) != MTD_CHAR_MAJOR) {
- return false;
+#if !defined(__FreeBSD__)
+ if (major(stat.st_rdev) == MTD_CHAR_MAJOR) {
+ return true;
}
-
- return true;
+#endif
+ return false;
}
// Return the element in |argv| that is an MTD device.
diff --git a/futility/cmd_vbutil_kernel.c b/futility/cmd_vbutil_kernel.c
index 1684c185..83a76f84 100644
--- a/futility/cmd_vbutil_kernel.c
+++ b/futility/cmd_vbutil_kernel.c
@@ -9,7 +9,7 @@
#include <fcntl.h>
#include <getopt.h>
#include <inttypes.h> /* For PRIu64 */
-#ifndef HAVE_MACOS
+#if !defined(HAVE_MACOS) && !defined(__FreeBSD__)
#include <linux/fs.h> /* For BLKGETSIZE64 */
#endif
#include <stdarg.h>
@@ -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)) {
-#ifndef HAVE_MACOS
+#if !defined(HAVE_MACOS) && !defined(__FreeBSD__)
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 5f7aa20e..4240e5ed 100644
--- a/futility/dump_kernel_config_lib.c
+++ b/futility/dump_kernel_config_lib.c
@@ -10,7 +10,9 @@
#include <string.h>
#include <sys/mman.h>
#include <sys/stat.h>
+#if !defined (__FreeBSD__)
#include <sys/sysmacros.h>
+#endif
#include <sys/types.h>
#include <unistd.h>
@@ -122,7 +124,11 @@ char *FindKernelConfig(const char *infile, uint64_t kernel_body_load_address)
{
char *newstr = NULL;
- int fd = open(infile, O_RDONLY | O_CLOEXEC | O_LARGEFILE);
+ int fd = open(infile, O_RDONLY | O_CLOEXEC
+#if !defined(__FreeBSD__)
+ | O_LARGEFILE
+#endif
+ );
if (fd < 0) {
FATAL("Cannot open %s\n", infile);
return NULL;
diff --git a/futility/misc.c b/futility/misc.c
index de7db515..0c8a0e71 100644
--- a/futility/misc.c
+++ b/futility/misc.c
@@ -5,7 +5,7 @@
#include <assert.h>
#include <errno.h>
-#ifndef HAVE_MACOS
+#if !defined(HAVE_MACOS) && !defined(__FreeBSD__)
#include <linux/fs.h> /* For BLKGETSIZE64 */
#endif
#include <stdarg.h>
@@ -272,7 +272,7 @@ enum futil_file_err futil_map_file(int fd, int writeable,
return FILE_ERR_STAT;
}
-#ifndef HAVE_MACOS
+#if !defined(HAVE_MACOS) && !defined(__FreeBSD__)
if (S_ISBLK(sb.st_mode))
ioctl(fd, BLKGETSIZE64, &sb.st_size);
#endif
diff --git a/futility/updater_utils.c b/futility/updater_utils.c
index e87094b4..5a2a5e6d 100644
--- a/futility/updater_utils.c
+++ b/futility/updater_utils.c
@@ -10,6 +10,9 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
+#if defined (__FreeBSD__)
+#include <sys/wait.h>
+#endif
#include "2common.h"
#include "crossystem.h"
diff --git a/host/arch/x86/lib/crossystem_arch.c b/host/arch/x86/lib/crossystem_arch.c
index 3d1c8181..6a8f5a26 100644
--- a/host/arch/x86/lib/crossystem_arch.c
+++ b/host/arch/x86/lib/crossystem_arch.c
@@ -7,8 +7,10 @@
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
+#if !defined(__FreeBSD__)
#include <linux/nvram.h>
#include <linux/version.h>
+#endif
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
@@ -98,8 +100,10 @@ typedef struct {
static void VbFixCmosChecksum(FILE* file)
{
+#if !defined(__FreeBSD__)
int fd = fileno(file);
ioctl(fd, NVRAM_SETCKS);
+#endif
}
@@ -662,9 +666,11 @@ 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 (KERNEL_VERSION(maj, min, 0) >= KERNEL_VERSION(4, 16, 0) &&
*offset > 11)
*offset += 3;
+#endif
} else {
printf("Couldn't retrieve kernel version!\n");
ret = 0;
diff --git a/host/lib/flashrom.c b/host/lib/flashrom.c
index b1647ae0..62ab1bc8 100644
--- a/host/lib/flashrom.c
+++ b/host/lib/flashrom.c
@@ -47,6 +47,10 @@ static vb2_error_t write_temp_file(const uint8_t *data, uint32_t data_size,
char *path;
mode_t umask_save;
+#if defined(__FreeBSD__)
+#define P_tmpdir "/tmp"
+#endif
+
*path_out = NULL;
path = strdup(P_tmpdir "/vb2_flashrom.XXXXXX");
diff --git a/scripts/getversion.sh b/scripts/getversion.sh
index d505579f..a5630072 100755
--- a/scripts/getversion.sh
+++ b/scripts/getversion.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/env bash
#
# Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be