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>
This commit is contained in:
parent
176e01ded3
commit
ade6151a67
7
Makefile
7
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}
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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");
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue