Skip to content
Matt Bennett edited this page Jan 15, 2016 · 36 revisions

How to build a kernel and SD card image

1. Get the LiteBSD sources

Get the LiteBSD sources:

$ cd $HOME
$ git clone https://github.com/sergev/LiteBSD.git

2. Install GCC toolchain

Download and install GCC toolkit for MIPS. You can use Mentor Sourcery CodeBench Lite toolchain (Linux, Win32).

$ wget https://sourcery.mentor.com/GNUToolchain/package12725/public/mips-sde-elf/mips-2014.05-24-mips-sde-elf-i686-pc-linux-gnu.tar.bz2
$ sudo tar xvjf mips-2014.05-24-mips-sde-elf-i686-pc-linux-gnu.tar.bz2 -C /usr/local

For Mac OS, use a precompiled package gcc-4.8.1-mips-macosx.tgz.

$ wget https://github.com/sergev/LiteBSD/releases/download/tools/gcc-4.8.1-mips-macosx.tgz
$ sudo tar xvjf gcc-4.8.1-mips-macosx.tgz -C /usr/local

As an alternative, you can build GCC from sources, following these instructions: Installation of GCC toolchain for MIPS architecture.

3. Setup shell environment

Setup shell environment:

$ export BSDSRC=$HOME/LiteBSD
$ export MIPS_GCC_ROOT=/usr/local/mips-2014.05
$ export MAKESYSPATH=$BSDSRC/share/mk-pic32

BSDSRC is a path to LiteBSD source directory. MIPS_GCC_ROOT contains the installation root of the installed GCC toolkit. MAKESYSPATH selects a PIC32-specific set of mk files for BSD make utility. It makes sense to out these three lines to your ~/.bashrc file.

4. Install BSD make and other utilities

Install a BSD make, and some other required utilities. For Ubuntu or Debian Linux, use:

$ sudo apt-get install bmake git gcc-multilib byacc flex exuberant-ctags libfuse-dev

For Mac OS X:

$ sudo port install bmake

BSD make can have a different name on your system. Use bmake alias for compatibility.

5. Compile the kernel

Compile the kernel:

$ cd $BSDSRC
$ bmake kernel

A binary file vmunix will be created:

$ /usr/local/mips-2014.05/bin/mips-sde-elf-size sys/compile/WIFIRE.pic32/vmunix
   text	   data	    bss	    dec	    hex	filename
 496208	  13816	  18472	 528496	  81070	sys/compile/WIFIRE.pic32/vmunix

HEX file for programming into the board is located as sys/compile/WIFIRE.pic32/vmunix.hex .

6. Compile the filesystem

Build the contents of the root filesystem:

$ cd $BSDSRC
$ bmake build

The target filesystem tree will be placed in a DESTDIR subdirectory of $BSDSRC:

$ ls -l $BSDSRC/DESTDIR
total 8
-r--r--r--   1 vak  staff  3425 21 фев 01:14 COPYRIGHT
drwxr-xr-x  31 vak  staff  1054 21 фев 01:14 bin/
drwxr-xr-x   4 vak  staff   136 21 фев 01:14 dev/
drwxr-xr-x  49 vak  staff  1666 21 фев 01:14 etc/
drwxr-xr-x   7 vak  staff   238 21 фев 01:14 root/
drwxr-xr-x  50 vak  staff  1700 21 фев 01:14 sbin/
lrwxr-xr-x   1 vak  staff    11 21 фев 01:14 sys@ -> usr/src/sys
drwxr-xr-x   2 vak  staff    68 10 дек 21:51 tmp/
drwxr-xr-x   9 vak  staff   306 10 дек 21:54 usr/
drwxr-xr-x   6 vak  staff   204 10 дек 21:52 var/

7. Build the SD card image

Build the SD card image.

$ cd $BSDSRC
$ bmake fs

The resulting file is sdcard.img. It contains three partitions: root filesystem (200Mb), swap space (32Mb) and user /home area (100).

$ fdisk -l sdcard.img 

Disk sdcard.img: 348 MB, 348128256 bytes
1 heads, 63 sectors/track, 10792 cylinders, total 679938 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

     Device Boot      Start         End      Blocks   Id  System
sdcard.img1   *           2      409601      204800   b7  BSDI fs
sdcard.img2          409602      475137       32768   b8  BSDI swap
sdcard.img3          475138      679937      102400   b7  BSDI fs

You need to put a filesystem image on a SD card. On Windows, use Win32DiskImager utility. On Linux or Mac OS, run:

$ sudo bmake installfs SDCARD=/dev/XYZ

Here XYZ is a device name of SD card, as recognized by Linux (sdb in my case). Use lsblk utility to find out the device name.