summaryrefslogtreecommitdiff
path: root/cgpt
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 /cgpt
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>
Diffstat (limited to 'cgpt')
-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
5 files changed, 18 insertions, 9 deletions
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.