On 2010/06/29 10:29, Carl-Daniel Hailfinger wrote: > Fix pciutils non-32bit PCI write on OpenBSD. > OpenBSD supports only 32bit accesses to PCI config space. Emulate > smaller writes with a read/modify/write cycle. > > First try, untested. May break on bigendian architectures (actually, the > existing code looks like it is broken on big endian for either read or > write, so my patch may break it more, or actually fix it). > > This should get flashrom running.
It does; with securelevel=-1 I can flashrom -r and get a valid-looking file out of it. Here's a ports diff, updating pciutils to 3.1.7, and incorporating this fix. Index: Makefile =================================================================== RCS file: /cvs/ports/sysutils/pciutils/Makefile,v retrieving revision 1.11 diff -u -p -r1.11 Makefile --- Makefile 15 Apr 2010 14:29:16 -0000 1.11 +++ Makefile 29 Jun 2010 10:51:11 -0000 @@ -4,19 +4,19 @@ NOT_FOR_ARCHS = sparc m68k m88k vax COMMENT = PCI bus configuration register access tools -DISTNAME = pciutils-3.1.2 -PKGNAME = ${DISTNAME}p1 +DISTNAME = pciutils-3.1.7 CATEGORIES = sysutils HOMEPAGE = http://atrey.karlin.mff.cuni.cz/~mj/pciutils.shtml MAINTAINER = Matthieu Herrb <matth...@openbsd.org> -# GPL +# GPLv2 PERMIT_PACKAGE_CDROM = Yes PERMIT_PACKAGE_FTP = Yes PERMIT_DISTFILES_CDROM =Yes PERMIT_DISTFILES_FTP = Yes + WANTLIB = c z MASTER_SITES = ftp://atrey.karlin.mff.cuni.cz/pub/linux/pci/ Index: distinfo =================================================================== RCS file: /cvs/ports/sysutils/pciutils/distinfo,v retrieving revision 1.5 diff -u -p -r1.5 distinfo --- distinfo 22 Mar 2009 21:48:49 -0000 1.5 +++ distinfo 29 Jun 2010 10:51:11 -0000 @@ -1,5 +1,5 @@ -MD5 (pciutils-3.1.2.tar.gz) = tswTlVrXaaJcR1qH0u9Vlg== -RMD160 (pciutils-3.1.2.tar.gz) = BRkKLRPJLrBKiHFENORsICFYGZs= -SHA1 (pciutils-3.1.2.tar.gz) = qbdaWv3iHq5IO+5XfZBgZG4+uiU= -SHA256 (pciutils-3.1.2.tar.gz) = e2gjKUEKOebWEYPhaDQuHRJch1o1rNTHRv8b7Cq2eJ0= -SIZE (pciutils-3.1.2.tar.gz) = 291324 +MD5 (pciutils-3.1.7.tar.gz) = 8+NJ0io3FLQnKxcWSa1SNQ== +RMD160 (pciutils-3.1.7.tar.gz) = LYGmp/3waIn31ZVN/3FrsFFv/SA= +SHA1 (pciutils-3.1.7.tar.gz) = WDNu+MG76HDyzA7ZSBqM+KWOA5w= +SHA256 (pciutils-3.1.7.tar.gz) = DzmBjqvXk7tI1bmMpSFB2CRzBqhYdkgsAHXQyVrszqI= +SIZE (pciutils-3.1.7.tar.gz) = 320603 Index: patches/patch-Makefile =================================================================== RCS file: /cvs/ports/sysutils/pciutils/patches/patch-Makefile,v retrieving revision 1.3 diff -u -p -r1.3 patch-Makefile --- patches/patch-Makefile 30 Jan 2009 22:22:39 -0000 1.3 +++ patches/patch-Makefile 29 Jun 2010 10:51:11 -0000 @@ -1,16 +1,16 @@ ---- Makefile.orig Sun Nov 9 21:28:18 2008 -+++ Makefile Wed Jan 7 13:41:39 2009 +--- Makefile.orig Sun Jan 31 17:42:12 2010 ++++ Makefile Tue Jun 29 11:14:39 2010 @@ -1,8 +1,7 @@ # Makefile for The PCI Utilities - # (c) 1998--2008 Martin Mares <m...@ucw.cz> + # (c) 1998--2010 Martin Mares <m...@ucw.cz> -OPT=-O2 -CFLAGS=$(OPT) -Wall -W -Wno-parentheses -Wstrict-prototypes -Wmissing-prototypes +CFLAGS+= -Wall -W -Wno-parentheses -Wstrict-prototypes -Wmissing-prototypes - VERSION=3.0.3 - DATE=2008-11-09 -@@ -97,7 +96,6 @@ + VERSION=3.1.7 + DATE=2010-01-31 +@@ -105,7 +104,6 @@ install: all $(INSTALL) -c -m 755 update-pciids $(DESTDIR)$(SBINDIR) $(INSTALL) -c -m 644 $(PCI_IDS) $(DESTDIR)$(IDSDIR) $(INSTALL) -c -m 644 lspci.8 setpci.8 update-pciids.8 $(DESTDIR)$(MANDIR)/man8 Index: patches/patch-lib_names-net_c =================================================================== RCS file: /cvs/ports/sysutils/pciutils/patches/patch-lib_names-net_c,v retrieving revision 1.1 diff -u -p -r1.1 patch-lib_names-net_c --- patches/patch-lib_names-net_c 30 Jan 2009 22:22:39 -0000 1.1 +++ patches/patch-lib_names-net_c 29 Jun 2010 10:51:11 -0000 @@ -1,6 +1,7 @@ ---- lib/names-net.c.ori Wed Jan 7 12:50:25 2009 -+++ lib/names-net.c Wed Jan 7 12:52:26 2009 -@@ -194,7 +194,7 @@ +$OpenBSD$ +--- lib/names-net.c.orig Mon Nov 10 23:11:51 2008 ++++ lib/names-net.c Tue Jun 29 11:14:39 2010 +@@ -194,7 +194,7 @@ char resolver_inited = 1; res_init(); } @@ -9,7 +10,7 @@ if (res < 0) { a->debug("\tfailed, h_errno=%d\n", h_errno); -@@ -208,7 +208,7 @@ +@@ -208,7 +208,7 @@ char dns_init_section(&ds, DNS_SEC_ANSWER); while (dns_parse_rr(&ds) > 0) { Index: patches/patch-lib_obsd-device_c =================================================================== RCS file: /cvs/ports/sysutils/pciutils/patches/patch-lib_obsd-device_c,v retrieving revision 1.3 diff -u -p -r1.3 patch-lib_obsd-device_c --- patches/patch-lib_obsd-device_c 30 Dec 2006 14:55:25 -0000 1.3 +++ patches/patch-lib_obsd-device_c 29 Jun 2010 10:51:11 -0000 @@ -1,7 +1,7 @@ $OpenBSD: patch-lib_obsd-device_c,v 1.3 2006/12/30 14:55:25 matthieu Exp $ ---- lib/obsd-device.c.orig Sat Sep 9 12:53:01 2006 -+++ lib/obsd-device.c Sat Dec 16 16:13:26 2006 -@@ -58,11 +58,6 @@ static int +--- lib/obsd-device.c.orig Tue Jun 29 11:15:38 2010 ++++ lib/obsd-device.c Tue Jun 29 11:15:31 2010 +@@ -56,11 +56,6 @@ static int obsd_read(struct pci_dev *d, int pos, byte *buf, int len) { struct pci_io pi; @@ -12,10 +12,10 @@ $OpenBSD: patch-lib_obsd-device_c,v 1.3 - } u; if (!(len == 1 || len == 2 || len == 4)) - { -@@ -86,18 +81,16 @@ obsd_read(struct pci_dev *d, int pos, by + return pci_generic_block_read(d, pos, buf, len); +@@ -81,18 +76,16 @@ obsd_read(struct pci_dev *d, int pos, byte *buf, int l + else d->access->error("obsd_read: ioctl(PCIOCREAD) failed"); - } } - u.u32 = pi.pi_data; - @@ -35,3 +35,40 @@ $OpenBSD: patch-lib_obsd-device_c,v 1.3 break; } return 1; +@@ -113,19 +106,31 @@ obsd_write(struct pci_dev *d, int pos, byte *buf, int + pi.pi_sel.pc_dev = d->dev; + pi.pi_sel.pc_func = d->func; + +- pi.pi_reg = pos; +- pi.pi_width = len; ++ pi.pi_reg = pos - (pos % 4); ++ pi.pi_width = 4; ++ pi.pi_data = 0xffffffff; + ++ /* Questionable read-modify-write cycle for non-32-bit writes */ ++ if (len != 4) ++ if (ioctl(d->access->fd, PCIOCREAD, &pi) < 0) ++ { ++ /* Abort on any error because the write will contain garbage */ ++ d->access->error("obsd_read: ioctl(PCIOCREAD) failed"); ++ return 0; ++ } ++ + switch (len) + { + case 1: +- pi.pi_data = buf[0]; ++ pi.pi_data &= ~(0xff << ((pos % 4) * 8)); ++ pi.pi_data |= buf[0] << ((pos % 4) * 8); + break; + case 2: +- pi.pi_data = ((u16 *) buf)[0]; ++ pi.pi_data &= ~(0xffff << ((pos % 4) * 8)); ++ pi.pi_data |= htole16(((u16 *) buf)[0]) << ((pos % 4) * 8); + break; + case 4: +- pi.pi_data = ((u32 *) buf)[0]; ++ pi.pi_data = htole32(((u32 *) buf)[0]); + break; + } +