[flashrom] Porting flashrom to OpenBSD

Carl-Daniel Hailfinger c-d.hailfinger.devel.2006 at gmx.net
Tue Jun 22 04:02:51 CEST 2010


Hi Stuart, hi Ian,

thanks for the enthusiastic response.
I added a few fixups to the flashrom tree in the meantime to get the
OpenBSD patch size down a bit. After all, if it gets easier for you to
test, we all win.

Stuart, if this works for you, I'll commit the patches into flashrom
subversion ASAP. My stated goal is to support every OS without the need
for any local patches.

A good first step to check if flashrom could run on your system is to
run lspci. You may have to set
machdep.allowaperture=2
and possibly other settings to get it working.
flashrom uses raw memory access (/dev/mem), raw x86 port access (via
inb/outb functions) and PCI access (via libpci).

On 19.06.2010 03:38, Ian McWilliam wrote:
> On 19/06/2010 10:42 AM, Stuart Henderson wrote:
>> On 2010/06/19 02:33, Carl-Daniel Hailfinger wrote:  
>>> I'm one of the lead developers of flashrom, a GPLv2 application to
>>> read/write/erase flash chips on mainboards, network/storage/graphics
>>> cards and external programmers.[...]
>>>
>>> I have two patches which get flashrom to compile on OpenBSD on i386,
>>> and
>>> they should work on amd64 as well. Those patches will be merged into
>>> the
>>> official flashrom source tree once I know that they work. The big
>>> obstacle for me is that I don't own any OpenBSD machine, and all I have
>>> is shell access to a public OpenBSD i386 shell server. flashrom is
>>> pretty small, you can compile it in ~5 seconds on a reasonably fast
>>> machine, so compile testing shouldn't need too much time.
>>>  
>> If you send me the patches I'll write a port Makefile for it.
>> Then it's easier for people to test. Compile testing is no problem
>> but I don't have any machines that I can spare to test actual bios
>> updates on though.
>>
>> It would be great to have flashrom working on OpenBSD.    
>
> I have 2 ASUS M2N-SLI deluxe motherboards that have a later bios
> update that I can test under AMD64 && i386.
> Create the port and throw my way for some testing.

First patch (libpci fixups) is available at
http://patchwork.coreboot.org/patch/1506/ (click the "patch" link there
to download it). It is needed for gcc 3.x.
The second patch (which has the actual OpenBSD support code) is below
and will be available for download near the top of
http://patchwork.coreboot.org/project/flashrom/list/ in case the patch
gets mangled in transit.

To compile flashrom, please check out
svn://svn.coreboot.org/flashrom/trunk
then apply the libpci fixup patch, then apply the patch below:

Add OpenBSD support (i386 and amd64) to flashrom.
Compile tested on i386.
To compile flashrom, you need libpci from pciutils. flashrom expects
/usr/local/include/pci/pci.h (see OpenBSD-specific CPPFLAGS in the
Makefile patch) and /usr/local/lib/libpci.so or libpci.a or something
which can be found by the linker. flashrom needs gmake. Depending on the
cleanliness of your headers, you may have to set WARNERROR=no. Run
gmake
or
gmake WARNERROR=no

If /usr/local is not the place where ports end up, please tell me so I
can fix the patch.

Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006 at gmx.net>

Index: flashrom-openbsd/hwaccess.h
===================================================================
--- flashrom-openbsd/hwaccess.h	(revision 1057)
+++ flashrom-openbsd/hwaccess.h	(working copy)
@@ -221,17 +221,25 @@
 #endif
 #endif
 
-#if defined(__NetBSD__)
+#if defined(__NetBSD__) || defined (__OpenBSD__)
   #define off64_t off_t
   #define lseek64 lseek
   #if defined(__i386__) || defined(__x86_64__)
     #include <sys/types.h>
     #include <machine/sysarch.h>
+#if defined(__NetBSD__)
     #if defined(__i386__)
       #define iopl i386_iopl
     #elif defined(__x86_64__)
       #define iopl x86_64_iopl
     #endif
+#elif defined (__OpenBSD__)
+    #if defined(__i386__)
+      #define iopl i386_iopl
+    #elif defined(__amd64__)
+      #define iopl amd64_iopl
+    #endif
+#endif
   #include <stdint.h>
 
 static inline void outb(uint8_t value, uint16_t port)
Index: flashrom-openbsd/Makefile
===================================================================
--- flashrom-openbsd/Makefile	(revision 1057)
+++ flashrom-openbsd/Makefile	(working copy)
@@ -48,6 +48,10 @@
 CPPFLAGS += -I/usr/local/include
 LDFLAGS += -L/usr/local/lib
 endif
+ifeq ($(OS_ARCH), OpenBSD)
+CPPFLAGS += -I/usr/local/include
+LDFLAGS += -L/usr/local/lib
+endif
 ifeq ($(OS_ARCH), DOS)
 EXEC_SUFFIX := .exe
 CPPFLAGS += -I../libgetopt -I../libpci/include
@@ -259,9 +263,13 @@
 LIBS += ../libpci/lib/libpci.a
 else
 LIBS += -lpci
+ifeq ($(OS_ARCH), OpenBSD)
+# For (i386|amd64)_iopl(2).
+LIBS += -l$(shell uname -m)
 endif
 endif
 endif
+endif
 
 ifeq ($(CONFIG_PRINT_WIKI), yes)
 FEATURE_CFLAGS += -D'CONFIG_PRINT_WIKI=1'
Index: flashrom-openbsd/README
===================================================================
--- flashrom-openbsd/README	(revision 1057)
+++ flashrom-openbsd/README	(working copy)
@@ -55,6 +55,11 @@
  * devel/gmake
  * devel/libpci
 
+On OpenBSD, you need the following ports:
+
+ * devel/gmake
+ * sysutils/pciutils
+
 To compile on Linux, use:
 
  make
@@ -76,6 +81,10 @@
  ln -s /usr/pkg/include/pciutils pci
  gmake CPPFLAGS=-I. LDFLAGS="-L/usr/pkg/lib -Wl,-rpath-link,/usr/pkg/lib"
 
+To compile on OpenBSD, use:
+
+ gmake
+
 To compile and run on Darwin/Mac OS X:
 
  Install DirectIO from coresystems GmbH.


-- 
http://www.hailfinger.org/





More information about the flashrom mailing list