how to compile and install a new driver

Chuck Robey chuckr at
Tue Nov 27 15:31:41 PST 2007

Warren Block wrote:
> On Tue, 27 Nov 2007, Steve Franks wrote:
>> I found this thread
>> to a driver I need for my system.
>> (1) The file extension
>> ( is .diff, not .c, so
>> what exactly do I do with it to compile it?
> It's a file produced by diff(1), which shows the differences between 
> files.  Normally, the difference is between the old files and what 
> someone has changed or added.  Also called a patch file, since you use 
> patch(1) to apply it.  patch(1) goes through the diff file and makes all 
> the changes shown.

Nice description, but you'd better include enough info so that they 
could make FreeBSD-stype diffs: diff has the unfortunate default of 
making an output that is compatible with ed(1).  This supplies extremely 
little information to use, in case the file you're trying to patch with 
that diff has changed, and is also damned hard for mere humans to 
understand.   There are two other options you can give to diff that 
change the format: -c gives "context" diffs, and -u gives "unified" 
diffs, and the -u is the option that is standard with FreeBSD.  How you 
do this is to copy the file you intend to change BEFORE you edit the 
chantes in to "somefile.orig", and then, when you perform the diff, you 
must give the .orig file first, else you will produce a file that tries 
to remove the patch instead of applying the patch, like this:

diff -u somefile.c.orig somefile.c >patchfile

diffs have a standard header on them, and (although it seems that this 
isn't a FreeBSD standard) you can easily enter in freeform comments 
before your patch's header, describing the reasons for this patch to be 
applied (whatever condition this patch fixes).

To tell you the truth, that idea of sticking comments at the top of 
patch files, I got from the crosscompiler site, and it's a great idea, 
it's how they set up their patches, and we should use  it.

> In this case, the diff file has changes to several files.
> Looks like it applies to /usr/src/sys.  After untarring the file, and as 
> root:
> # cd /usr/src/sys
> # patch < ucp-0.01.diff
> *If* the patch applies successfully, then you can compile.  Easiest 
> would probably be to just rebuild the kernel.  Slow, but you know it'll 
> get everything.
>> (2) Assuming I can get it to compile, which I've never done, what do I
>> do with the object/driver file?
> Probably like other ucom(4) devices:
> kldload ucp
> and then access the serial port through /dev/cuaU0.
>> This driver is long overdue, the part has been in usb devices for
>> several years, and support is in OpenBSD and Linux already (so I'm
>> told by google).  I'll happily document the process if someone holds
>> my hand.
> That is a good case for a PR.  Particularly when you've got a patch, at 
> least as a starting point.
> -Warren Block * Rapid City, South Dakota USA
> _______________________________________________
> freebsd-questions at mailing list
> To unsubscribe, send any mail to 
> "freebsd-questions-unsubscribe at"

More information about the freebsd-questions mailing list