# mkdir /usr/cvs # cd /usr/cvs # env CVS_RSH=ssh cvs -d anoncvs@anoncvs.netbsd.org:/cvsroot co src # mv src src-currentThe process of crosscompiling a kernel consists of three steps, which we will describe in more detail below:
The command to create the toolchain is quite simple, using NetBSD's new src/build.sh script:
# cd /usr/cvs/src-current # ./build.sh -m shark -u -tThis will build all the tools for the named target platform. Arguments used here are:
The toolchain itself is part of this, but as it's hosted and compiled for a i386 system, it will get placed in it's own directory indicating where to cross-build from. Here's where our crosscompiler tools are located:
miyu# pwd /usr/cvs/src-current miyu# ls tools/obj.shark/ tools.NetBSD-1.6-i386So the general rule of thumb is for a given "host" and "target" system combination, the crosscompiler will be placed in the "src/tools/obj.target/tools.host" directory by default. A full list of all tools created for crosscompiling the whole NetBSD operating system includes:
miyu# ls tools/obj.shark/tools.NetBSD-1.6-i386/bin/ arm--netbsdelf-addr2line arm--netbsdelf-strings nbmakefs arm--netbsdelf-ar arm--netbsdelf-strip nbmakeinfo arm--netbsdelf-as nbasn1_compile nbmakewhatis arm--netbsdelf-c++ nbcap_mkdb nbmenuc arm--netbsdelf-c++filt nbcompile_et nbmkdep arm--netbsdelf-cpp nbconfig nbmklocale arm--netbsdelf-dbsym nbcrunchgen nbmsgc arm--netbsdelf-g++ nbctags nbmtree arm--netbsdelf-g77 nbeqn nbpax arm--netbsdelf-gasp nbgencat nbpic arm--netbsdelf-gcc nbgroff nbpwd_mkdb arm--netbsdelf-gcov nbhost-mkdep nbrefer arm--netbsdelf-ld nbindxbib nbrpcgen arm--netbsdelf-lint nbinfo nbsoelim arm--netbsdelf-mdsetimage nbinstall nbtbl arm--netbsdelf-nm nbinstall-info nbtexi2dvi arm--netbsdelf-objcopy nblex nbtexindex arm--netbsdelf-objdump nblorder nbtsort arm--netbsdelf-ranlib nbm4 nbuudecode arm--netbsdelf-readelf nbmake nbyacc arm--netbsdelf-size nbmake-shark nbzicAs you can see, most of the tools that are available natively on NetBSD are also available, with some program prefix to identify the target platform. (The naming here is a bit redundant due to the directory structure containing all the information, but the program names are created by the GNU based toolchain and were chosen not to be changed).
One important tool that should be pointed out here is "nbmake-shark". This is a shell wrapper for a BSD compatible make(1) command that's setup to use all the right commands from the crosscompiler toolchain. Using this wrapper instead of /usr/bin/make allows crosscompiling programs that were written using the NetBSD Makefile infrastructure (see src/share/mk). We will use this make(1) wrapper in a second!
# cd /usr/cvs/src-current/sys/arch/shark/conf/ # /usr/cvs/src-current/tools/obj.shark/tools.NetBSD-1.6-i386/bin/nbconfig GENERICThat's all. This command has created a directory "../compile/GENERIC" with a number of header files defining information about devices to compile into the kernel, a Makefile that is setup to build all the needed files for the kernel, and link them together. As the Shark port uses ELF as execution format but the Shark's OpenFirmware can only load a.out kernels, that Makefile will also convert the kernel from ELF to a.out once it's built.
More information about building NetBSD kernels can be found at http://www.netbsd.org/Documentation/kernel/.
# cd ../compile/GENERIC/ # /usr/cvs/src-current/tools/obj.shark/tools.NetBSD-1.6-i386/bin/nbmake-sharkThis will churn away a bit, then spit out a kernel:
... text data bss dec hex filename 1687520 69632 184576 1941728 1da0e0 netbsd.aout miyu# ls -la netbsd.aout -rwxr-xr-x 1 root wheel 1757216 Mar 27 02:55 netbsd.aout miyu# file netbsd.aout netbsd.aout: NetBSD/arm32 demand paged executableNow the a.out(!) kernel can either be transferred to a shark (via NFS, FTP, scp, etc.) and booted from a possible harddisk, or directly from our cross-development machine using NFS. Be sure to actually use the a.out kernel, as the Shark's firmware cannot use the one in ELF format.
$ ./build.sh -m shark -d \ -D /usr/tmp/shark-root \ -R /usr/tmp/shark-releaseThis command will first build a crosscompiler, as described above. After that it will crosscompile the whole operating system including all libraries, binaries, etc. To make things complete, kernels for installing and running the systems will be built, and everything will be packed into distribution sets & install media, so a full NetBSD release is available i /usr/tmp/shark-release after that command!
Too easy? Sorry, but that's NetBSD! :-)