Wiki2
BuildOpenBSD

Build and Patch OpenBSD

Pre download source

# ftp ftp://ftp.stacken.kth.se/pub/OpenBSD/5.4/*.gz
# cd /usr/src
# tar xzf ../sys.tar.gz
# tar xzf ../src.tar.gz
# cd /usr
# tar xzf xenocara.tar.gz
# tar xzf ports.tar.gz

Update source from AnonCVS.

# cd /usr
# export CVSROOT=anoncvs@anoncvs.eu.openbsd.org:/cvs
# cvs -d$CVSROOT checkout -P src
# cvs -d$CVSROOT checkout -P ports

When you want the latest update you can update the tree

# cd /usr/src
# cvs -d$CVSROOT up -rHEAD -Pd

You can also update individual files if neccesary.

cd /usr/src/sys/dev/usb
cvs -d$CVSROOT up -Pd -rHEAD ehci.c

Build kernel

# cd /usr/src/sys/arch/i386/conf
# config GENERIC
# cd /usr/src/sys/arch/i386/compile/GENERIC
# make clean && make
    [...lots of output...]
# make install

Patch kernel with security update

# cd /usr/src
# patch -p0 < 001_st.patch

Patch kernel with diff in mail. Make sure mail is stored as raw text. And don’t open the patch file in any “smart” text editor which removes trailing spaces.

Specific problem with ehci.c patch

Note that modern text editors may remove trailing spaces which destroys the patch file. Use e.g. vi or nano to avoid this.

I also had problems with trailing CR.

cat ehci.patch | tr -d '\r' > ehci2.patch

This made the patch work for more hunks but not all. I ended up using patch on OSX to solve the problem.

# cd /usr/src/sys/dev/usb
# patch -ul < ehci.diff                                                                                                                   

Hmm...  Looks like a unified diff to me...
The text leading up to this was:

|Index: ehci.c
|===================================================================
|RCS file: ehci.c,v
|retrieving revision 1.138
|diff -u -p -r1.138 ehci.c
|--- ehci.c     9 Nov 2013 08:46:05 -0000       1.138
|+++ ehci.c     22 Nov 2013 10:21:10 -0000

Patching file ehci.c using Plan A...
Hunk #1 succeeded at 181.
Hunk #2 succeeded at 501.
Hunk #3 succeeded at 681.
Hunk #4 succeeded at 737.
Hunk #5 succeeded at 1439.
Hunk #6 succeeded at 1538.
Hunk #7 succeeded at 1569.
Hunk #8 succeeded at 1578.
Hunk #9 succeeded at 1659.
Hunk #10 succeeded at 2716.
Hunk #11 succeeded at 2739.
Hunk #12 succeeded at 2775.
Hunk #13 succeeded at 2943.
Hunk #14 succeeded at 3191.
Hunk #15 succeeded at 3277.
Hunk #16 succeeded at 3359.
Hunk #17 succeeded at 3470.
done

Enable debugging on kernel build

See chapter 19 of Absolute OpenBSD and config(8) and options(4). Debugging the OpenBSD kernel via QEMU was also quite informative.

cd /usr/src/sys/arch/i386/conf/
cp GENERIC.MP UMASSDEBUG

Edit UMASSDEBUG file

#
#       Just enable UMASS_DEBUG in umass.c and other ...
#

include "arch/i386/conf/GENERIC"

option  USB_DEBUG
option  UMASS_DEBUG
option  EHCI_DEBUG

Enter build folder.

config UMASSDEBUG
cd ../compile/UMASSDEBUG/
make clean; make
make install

References