How to Cross-Compile your NetBSD Kernel under Linux

If your HP is as slow as mine is, you'll find it takes several hours to do a full kernel compilation on it, particularly if you're NFS mounting all the filesystems... However, cross-compiling the kernel isn't entirely straightforward.

This is how I set things up; I don't claim that this is the Right Way, but it seems to work. I didn't take notes as I went along, so errors and omissions may have crept in somewhere along the line. Also, I'm using NetBSD 1.2; things may be different (easier, harder) under -current.

First you need some cross-compilation tools. Get the GNU binutils and gcc source. Compile binutils with --target=m68k-hp-netbsd and install the resulting tools with make install. (I'm a little hazy on this stage, since I did it quite a while ago.) You should have a set of tools in /usr/local/m68k-hp-netbsd/bin.

Now copy across (recursively) /usr/include from your NetBSD box to /usr/local/m68k-hp-netbsd/include, and put NetBSD's /usr/lib/crt0.o, gcrt0.o, libc.a, libm.a, scrt0.o in /usr/local/m68k-hp-netbsd/lib. If your linux box is also your NFS server, don't try symlinking /usr/local/m68k-hp-netbsd/include to the NetBSD /usr/include -- it doesn't seem to work. (Actually, it might do, now I think about it, but I still wouldn't recommend it. Best to keep NetBSD and Linux stuff separate, it's easier.)

Configure gcc with --prefix=/usr/local . I'm sure this shouldn't be necessary, but without setting prefix it looks for the binutils tools in /usr/m68k-hp-netbsd. Anyway, compile and install it with make and make install. At this point you should have a lot of binaries in /usr/local/bin with names like m68k-hp-netbsd-foo.

The next stage is to get a version of BSD make. Linux uses GNU make, which won't do. Linux pmake is the right make, but I recommend building a separate version, because we're going to be hacking the config files about something chronic later :-) I suggest grabbing the source from the NetBSD-current directory of your nearest source archive, since the sources from NetBSD-1.2 are all wrapped up in a tarfile and hard to get at. Stick the sources in /usr/src/BSDmake or somewhere similar.
Copy Makefile.boot to Makefile, since we're going to make this with GNU make. Edit the MACHINE and MACHINE_ARCH variables to read MACHINE=hp300 and MACHINE_ARCH=m68k (ie set them for the target, not for Linux).
Now get util.c(9K), which I modified so it uses the GNU library versions of snprintf() and vsnprintf() rather than trying to define its own routines.
Edit pathnames.h to set the following variables:

#define _PATH_OBJDIRPREFIX      "/usr/local/m68k-hp-netbsd/obj"
#define _PATH_DEFSYSPATH        "/usr/local/m68k-hp-netbsd/mk"
Running make should now compile the BSD make cleanly as bmake. Copy it to /usr/local/bin/bsdmake and make sure it's executable.
Now extract mkstuff.tar.gz(12K) to /usr/local/m68k-hp-netbsd/mk. This is essentially NetBSD's mk config files, but with assorted changes to make sure that the cross-tools get used. Edit mk.conf to set PMM_PREFIX to the Linux path to the NetBSD filesystem root. Check that the BINGRP and BINOWN are right while you're at it.

There are still a couple of little tools that need to be provided: untar misctools.tar.gz(3K) in /usr/local/bin. This provides m68k-hp-netbsd-mkdep and m68k-hp-netbsd-lorder. These are basically the standard mkdep and lorder scripts, but fixed to call the cross-versions of gcc and nm. lorder also has a bugfix: neither the NetBSD or Linux versions (which are essentially the same) can cope with the output from GNU nm, which is slightly different to that of BSD nm.

Any other tools that the compilation process needs are the standard Linux versions -- you've probably got them already...

Now there are a couple of changes that need to be made to the Makefiles for the kernel. The following are all NetBSD pathnames.
/usr/src/sys/lib/libkern/Makefile : change all instances of "lorder" to "${LORDER}", and similarly with tsort and ${TSORT}.
/usr/src/sys/arch/hp300/conf/Makefile.hp300 : change size into ${SIZE}, and mkdep to ${MKDEPEXE}. (It's not ${MKDEP} because that seems to have been used already (in

I may have missed a Makefile or two that needs altering. If the compilation fails with 'unknown object file type' or anything similar, it's probably this. Locate the offending Makefile and fix it.

At this point, you're ready to compile the kernel! In the following, N indicates commands to execute on the NetBSD box, and L commands for the Linux box.

N: configure the kernel as normal.
Change to the sys/arch/hp300/compile/SYSTEMNAME directory on both machines.
L: bsdmake genassym
N: make assym.h
(note -- you need to make assym.h on the NetBSD box because it is made
by running the genassym executable just compiled, which is an m68k binary.)
L bsdmake depend
L bsdmake
The rest of the kernel will now compile and link. When the compilation is finished you can copy netbsd to the NetBSD root directory and reboot the machine as usual.
Back to the NetBSD on HP9000/340 page...
This page written by Peter Maydell (