From b737a24c903ff75475fc7ac8a2f80901fb0acfcb Mon Sep 17 00:00:00 2001 From: Nicholas Chin Date: Sun, 28 Apr 2024 14:55:47 -0600 Subject: dell-flash-unlock: Remove memory clobber from inline assembly The x86 port IO instructions do not access memory so it is not needed in the clobber list. Signed-off-by: Nicholas Chin --- util/dell-flash-unlock/accessors.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/util/dell-flash-unlock/accessors.c b/util/dell-flash-unlock/accessors.c index a35f8139..a5f936c8 100644 --- a/util/dell-flash-unlock/accessors.c +++ b/util/dell-flash-unlock/accessors.c @@ -43,7 +43,7 @@ sys_outb(unsigned int port, uint8_t data) outb(port, data); #endif #if defined(__NetBSD__) - __asm__ volatile ( "outb %b0, %w1" : : "a"(data), "d"(port) : "memory"); + __asm__ volatile ("outb %b0, %w1" : : "a"(data), "d"(port)); #endif } @@ -57,7 +57,7 @@ sys_outl(unsigned int port, uint32_t data) outl(port, data); #endif #if defined(__NetBSD__) - __asm__ volatile ( "outl %0, %w1" : : "a"(data), "d"(port) : "memory"); + __asm__ volatile ("outl %0, %w1" : : "a"(data), "d"(port)); #endif } @@ -70,7 +70,7 @@ sys_inb(unsigned int port) #if defined(__NetBSD__) uint8_t retval; - __asm__ volatile("inb %w1, %b0" : "=a" (retval) : "d" (port) : "memory"); + __asm__ volatile ("inb %w1, %b0" : "=a" (retval) : "d" (port)); return retval; #endif return 0; @@ -84,7 +84,7 @@ sys_inl(unsigned int port) #endif #if defined(__NetBSD__) int retval; - __asm__ volatile("inl %w1, %0" : "=a" (retval) : "d" (port) : "memory"); + __asm__ volatile ("inl %w1, %0" : "=a" (retval) : "d" (port)); return retval; #endif return 0; -- cgit v1.2.1 From 6fe2482fdf035abf4bfb076801aef314fe70776c Mon Sep 17 00:00:00 2001 From: Nicholas Chin Date: Sun, 28 Apr 2024 15:16:19 -0600 Subject: dell-flash-unlock: Remove unnecessary includes for NetBSD The pio.h header, although present on NetBSD, is not necessary, as it only declares x86 port IO inx()/outx() functions which are not actually implemented. Signed-off-by: Nicholas Chin --- util/dell-flash-unlock/accessors.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/util/dell-flash-unlock/accessors.c b/util/dell-flash-unlock/accessors.c index a5f936c8..a8541e28 100644 --- a/util/dell-flash-unlock/accessors.c +++ b/util/dell-flash-unlock/accessors.c @@ -8,12 +8,15 @@ #if defined(__OpenBSD__) || defined(__NetBSD__) #include #include +#endif /* __OpenBSD__ || __NetBSD__ */ + +#if defined(__OpenBSD__) #if defined(__amd64__) #include #elif defined(__i386__) #include #endif /* __i386__ */ -#endif /* __OpenBSD__ || __NetBSD__ */ +#endif /* __OpenBSD__ */ #include -- cgit v1.2.1 From 355dffb7089707efd8ebe75b1652cec44a06f317 Mon Sep 17 00:00:00 2001 From: Nicholas Chin Date: Wed, 1 May 2024 20:09:50 -0600 Subject: dell_flash_unlock: Fix ec_set_fdo() signature Set argument list as void. Signed-off-by: Nicholas Chin --- util/dell-flash-unlock/dell_flash_unlock.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/dell-flash-unlock/dell_flash_unlock.c b/util/dell-flash-unlock/dell_flash_unlock.c index 174a1c92..6118b0d4 100644 --- a/util/dell-flash-unlock/dell_flash_unlock.c +++ b/util/dell-flash-unlock/dell_flash_unlock.c @@ -15,7 +15,7 @@ int get_fdo_status(void); int check_lpc_decode(void); -void ec_set_fdo(); +void ec_set_fdo(void); void write_ec_reg(uint8_t index, uint8_t data); void send_ec_cmd(uint8_t cmd); int wait_ec(void); @@ -141,7 +141,7 @@ check_lpc_decode(void) } void -ec_set_fdo() +ec_set_fdo(void) { /* EC FDO command arguments for reference: * 0 = Query EC FDO status -- cgit v1.2.1 From 61dbaf9463034fb893ca8f5131681bdd54ec5472 Mon Sep 17 00:00:00 2001 From: Nicholas Chin Date: Wed, 1 May 2024 20:10:43 -0600 Subject: dell_flash_unlock: Set iopl level back to 0 when done Signed-off-by: Nicholas Chin --- util/dell-flash-unlock/dell_flash_unlock.c | 1 + 1 file changed, 1 insertion(+) diff --git a/util/dell-flash-unlock/dell_flash_unlock.c b/util/dell-flash-unlock/dell_flash_unlock.c index 6118b0d4..d59f5d5b 100644 --- a/util/dell-flash-unlock/dell_flash_unlock.c +++ b/util/dell-flash-unlock/dell_flash_unlock.c @@ -96,6 +96,7 @@ main(int argc, char *argv[]) "You can now shutdown the system.\n"); } } + sys_iopl(0); return errno; } -- cgit v1.2.1 From 5e2e761142085f60c85f19895d985a58a6f5ee0f Mon Sep 17 00:00:00 2001 From: Nicholas Chin Date: Wed, 1 May 2024 20:11:14 -0600 Subject: dell_flash_unlock: Add support for FreeBSD Signed-off-by: Nicholas Chin --- util/dell-flash-unlock/accessors.c | 39 ++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/util/dell-flash-unlock/accessors.c b/util/dell-flash-unlock/accessors.c index a8541e28..0a5df760 100644 --- a/util/dell-flash-unlock/accessors.c +++ b/util/dell-flash-unlock/accessors.c @@ -18,6 +18,13 @@ #endif /* __i386__ */ #endif /* __OpenBSD__ */ +#if defined(__FreeBSD__) +#include +#include +#include +#include +#endif /* __FreeBSD__ */ + #include #include "accessors.h" @@ -42,7 +49,7 @@ sys_outb(unsigned int port, uint8_t data) #if defined(__linux__) outb(data, port); #endif - #if defined(__OpenBSD__) + #if defined(__OpenBSD__) || defined(__FreeBSD__) outb(port, data); #endif #if defined(__NetBSD__) @@ -56,7 +63,7 @@ sys_outl(unsigned int port, uint32_t data) #if defined(__linux__) outl(data, port); #endif - #if defined(__OpenBSD__) + #if defined(__OpenBSD__) || defined(__FreeBSD__) outl(port, data); #endif #if defined(__NetBSD__) @@ -67,7 +74,8 @@ sys_outl(unsigned int port, uint32_t data) uint8_t sys_inb(unsigned int port) { - #if defined(__linux__) || defined (__OpenBSD__) + #if defined(__linux__) || defined (__OpenBSD__) \ + || defined(__FreeBSD__) return inb(port); #endif @@ -82,7 +90,8 @@ sys_inb(unsigned int port) uint32_t sys_inl(unsigned int port) { - #if defined(__linux__) || defined (__OpenBSD__) + #if defined(__linux__) || defined (__OpenBSD__) \ + || defined(__FreeBSD__) return inl(port); #endif #if defined(__NetBSD__) @@ -115,6 +124,28 @@ sys_iopl(int level) #endif /* __amd64__ */ #endif /* __NetBSD__ */ +#if defined(__FreeBSD__) + /* Refer to io(4) manual page. This assumes the legacy behavior + * where opening /dev/io raises the IOPL of the process */ + static int io_fd = -1; + + /* Requesting privileged access */ + if (level > 0) { + if (io_fd == -1) { + io_fd = open("/dev/io", O_RDONLY); + return (io_fd == -1) ? -1 : 0; + } + /* Lowering access to lowest level */ + } else if (level == 0 && io_fd != -1) { + if (close(io_fd) == -1) { + return -1; + } else { + io_fd = -1; + } + } + return 0; +#endif /* __FreeBSD__ */ + errno = ENOSYS; return -1; } -- cgit v1.2.1 From 61f66a46eab2480d45b14a14889e082678daaa80 Mon Sep 17 00:00:00 2001 From: Nicholas Chin Date: Wed, 1 May 2024 20:20:24 -0600 Subject: dell-flash-unlock: Update README for BSD Add FreeBSD to the README as it is now supported. Make a note about using gmake instead of make as the makefile currently uses GNU extensions to determine build flags based on the OS. Signed-off-by: Nicholas Chin --- util/dell-flash-unlock/README.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/util/dell-flash-unlock/README.md b/util/dell-flash-unlock/README.md index aca01743..e179e77c 100644 --- a/util/dell-flash-unlock/README.md +++ b/util/dell-flash-unlock/README.md @@ -20,14 +20,17 @@ around 2008 (E6400 era). If it says it is not set, then you will need to install or compile a kernel with that option set. -### OpenBSD/NetBSD -- On OpenBSD/NetBSD, ensure you are booting with securelevel set to -1. +### OpenBSD/NetBSD/FreeBSD +- The makefile is not currently compatible with POSIX make; install and use GNU + Make (gmake) to build dell-flash-unlock instead of make +- On OpenBSD/NetBSD/FreeBSD, ensure you are booting with securelevel set to -1. ### General Make sure an AC adapter is plugged into your system -Run `make` to compile the utility, and then run `./dell_flash_unlock` with -root/superuser permissions and follow the directions it outputs. +Run `make` (or `gmake` on BSD) to compile the utility, and then run +`./dell_flash_unlock` with root/superuser permissions and follow the directions +it outputs. ## Confirmed supported devices - Latitude E6400, E6500 -- cgit v1.2.1