From a2aceb5023780728901349a182ccd378070c60b0 Mon Sep 17 00:00:00 2001 From: stefanct Date: Sat, 13 Jul 2013 20:55:33 +0000 Subject: Fix hwaccess (again). I completely forgot about NetBSD in r1638 which was broken since then. Also, on OpenBSD use iopl again and refine the warning in case we have insufficient privileges. Thanks to Jonathan A. Kollasch for his help in getting the details right. Signed-off-by: Stefan Tauner Acked-by: Carl-Daniel Hailfinger git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@1695 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1 --- hwaccess.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'hwaccess.c') diff --git a/hwaccess.c b/hwaccess.c index 598aa67..8a4a50a 100644 --- a/hwaccess.c +++ b/hwaccess.c @@ -26,10 +26,9 @@ #error Unknown architecture #endif -#define IS_BSD (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__OpenBSD__)) #define IS_LINUX (defined(__gnu_linux__) || defined(__linux__)) #define IS_MACOSX (defined(__APPLE__) && defined(__MACH__)) -#if !(IS_BSD || IS_LINUX || IS_MACOSX || defined(__DJGPP__) || defined(__LIBPAYLOAD__) || defined(__sun)) +#if !(IS_LINUX || IS_MACOSX || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__DJGPP__) || defined(__LIBPAYLOAD__) || defined(__sun)) #error "Unknown operating system" #endif @@ -47,7 +46,10 @@ #include "flash.h" #include "hwaccess.h" -#if IS_X86 && IS_BSD +#define USE_IOPL (IS_LINUX || IS_MACOSX || defined(__NetBSD__) || defined(__OpenBSD__)) +#define USE_DEV_IO (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)) + +#if IS_X86 && USE_DEV_IO int io_fd; #endif @@ -71,9 +73,9 @@ static int release_io_perms(void *p) { #if defined (__sun) sysi86(SI86V86, V86SC_IOPL, 0); -#elif IS_BSD +#elif USE_DEV_IO close(io_fd); -#elif IS_LINUX || IS_MACOSX +#elif USE_IOPL iopl(0); #endif return 0; @@ -86,16 +88,19 @@ int rget_io_perms(void) #if IS_X86 && !(defined(__DJGPP__) || defined(__LIBPAYLOAD__)) #if defined (__sun) if (sysi86(SI86V86, V86SC_IOPL, PS_IOPL) != 0) { -#elif IS_BSD +#elif USE_DEV_IO if ((io_fd = open("/dev/io", O_RDWR)) < 0) { -#elif IS_LINUX || IS_MACOSX +#elif USE_IOPL if (iopl(3) != 0) { #endif - msg_perr("ERROR: Could not get I/O privileges (%s).\n" - "You need to be root.\n", strerror(errno)); + msg_perr("ERROR: Could not get I/O privileges (%s).\n", strerror(errno)); + msg_perr("You need to be root.\n"); #if defined (__OpenBSD__) - msg_perr("Please set securelevel=-1 in /etc/rc.securelevel and reboot, or reboot into \n"); - msg_perr("single user mode.\n"); + msg_perr("If you are root already please set securelevel=-1 in /etc/rc.securelevel and\n" + "reboot, or reboot into single user mode.\n"); +#elif defined(__NetBSD__) + msg_perr("If you are root already please reboot into single user mode or make sure\n" + "that your kernel configuration has the option INSECURE enabled.\n"); #endif return 1; } else { -- cgit v1.2.1