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 -#ifndef HAVE_MACOS +#if !defined(HAVE_MACOS) && !defined(__FreeBSD__) #include #endif #include 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 #include #include -#ifndef HAVE_MACOS +#if !defined(HAVE_MACOS) && !defined(__FreeBSD__) #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; } -#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 +#elif defined(__FreeBSD__) +#include #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 #include #include +#if !defined(__FreeBSD__) #include +#endif #include #include #include 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 #include #include +#if !defined(__FreeBSD__) #include +#endif #include #include #include #include #include #include +#if !defined(__FreeBSD__) #include +#endif #include #include @@ -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 #include #include /* For PRIu64 */ -#ifndef HAVE_MACOS +#if !defined(HAVE_MACOS) && !defined(__FreeBSD__) #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)) { -#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 #include #include +#if !defined (__FreeBSD__) #include +#endif #include #include @@ -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 #include -#ifndef HAVE_MACOS +#if !defined(HAVE_MACOS) && !defined(__FreeBSD__) #include /* For BLKGETSIZE64 */ #endif #include @@ -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 #include #include +#if defined (__FreeBSD__) +#include +#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 #include #include +#if !defined(__FreeBSD__) #include #include +#endif #include #include #include @@ -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