Port-arm archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

NetBSD on BeagleBone Black HOW-TO


I feel like I've spent ten hours figuring out ten minutes' worth of stuff. The documentation is horribly written - most is written with whatever assumptions are made for a given GNU/Linux distro and very little else.

First, starting with the serial port, the six pin header's pinout is not listed in the BeagleBone SRM. Since an FTDI adapter will work, I had to Google that to get the pinout, and unlike the FTDI pinout, there's no VCC, so those of us who still prefer a real RS232 port have to get power from elsewhere or solder a wire from VCC to pin 3 of the serial header. Pin 1 is ground, 3 is VCC, 4 is RxD (output from BeagleBone Black, meaning this is DTE) and 5 is TxD (input).

U-boot is a multistage bootloader. I'll take the opportunity to explain it for people who don't want to read pages and pages of irrelevant information to infer how it works. First, the boot firmware loads a file called MLO from the FAT partition in the case of the BeagleBone Black - it could be any other kind of partition on other hardware. MLO is the first stage bootloader. I don't know if this hardware can get it from anything other than FAT without installing new firmware.

Next, MLO loads whatever it is compiled to load. In the case of the default GNU/Linux Angstrom distro which comes with the BeagleBone Black, the second stage is named u-boot.img. I mention this because other boards and other compiles of MLO load uImage, uBoot and other names and it isn't immediately obvious where these names originate.

The u-boot.img file is compiled with ext2 or ext4 filesystem support so it can load the Linux kernel directly from the filesystem. It also has a bunch of boot commands hardcoded which confusingly appear to be environment variables when you're in the u-boot command prompt. I was going nuts trying to figure out why I couldn't run saveenv which is supposed to store environment variables for later boots.

So once MLO loads u-boot.img, those hard-coded commands are run. They have their own rules regarding how booting proceeds. In summary, if a card is in the SD card slot, it boots from that card. If a file called uEnv.txt exists on the FAT partition which is to be booted, it is loaded and parsed and can be used to override environment variables (but only those that matter after that point in the booting process, of course) and, most importantly, offer a new boot command.

There have been other MLO / uboot image combinations which do other things such as allow direct booting off of a FreeBSD ufs partition, so it's important to remember that many of these things are specific to the MLO / uboot which came with the BeagleBone Black. Older MLO / uboot sets may no longer be compatible with the current firmware in which case you'll get an error message.

From what I've been told, the uboot image is supposed to initialize hardware so the kernel knows where everything is and can start using it. In practice, this may be true of GNU/Linux, but things which worked with NetBSD using older uboot versions don't work now, so at least some is done by uboot and some by the kernel. This is why my examples below have the "mmc init" commands.

I've read anecdotally that certain FAT partitions are fine but others can't be booted which supposedly has to do whether the filesystem is FAT-12 or FAT-16. I would guess that a FAT-16 filesystem which is anywhere from 100 megs to 250 megs would work fine, but until I've tried it a few times, I can't say. It's in here just in case you run into problems.

So, in summary, in order to install and boot NetBSD automatically, one has to use fdisk (ugh!) to partition an SD card, create a small FAT partition with sysid 006 (primary big MS-DOS FAT, larger than 32 megs) at the beginning and assign the rest using sysid 169 (NetBSD, of course). I still don't personally understand how the fdisk partition becomes a disklabel because I've been hoping fdisk and friends would die before I needed to know. Oh, well.

In these examples the SD card shows up as /dev/sd0 because it's plugged in to a USB SD card reader.

fdisk -u
n (don't change idea of what BIOS thinks)

0 (partition to change)
6 (sysid)
(return) (use default for start)
262081 (number of sectors - 63 sectors less than 128 megs)
(return) (no bootmenu)

1 (partition to change)
169 (sysid)
(return) (use default for start)
(return) (number of sectors - let it default to rest of disk)
(return) (no bootmenu)

(return) (no partition to change)
(return) (don't install bootcode)
y (write new partition table)

fdisk -a sd0
y (change the active partition)
0 (make partition 0 active)
y (happy with choice)
y (write partition table)

I'm not sure that the MS-DOS partition needs to be active, but it can't hurt.

Next, unplug and replug the SD card. Not sure how to reread the disklabel from disk since disklabel -r doesn't work. After replugging, disklabel sd0 should show something like:

6 partitions:
#        size    offset     fstype [fsize bsize cpg/sgs]
 c:  61143040    262144     unused      0     0        # (Cyl. 32*- 7614*)
 d:  61405184         0     unused      0     0        # (Cyl.  0 - 7614*)
 e:    262081        63      MSDOS                     # (Cyl.  0*-   32*)
 f:  61143040    262144     4.2BSD      0     0     0  # (Cyl. 32*- 7614*)

So we run:

newfs_msdos -F 16 /dev/rsd0e

Then we mount the partition:

mount_msdos /dev/sd0e /mnt

Then we populate the filesystem. Copy a kernel, either one you've made yourself, or untargzip the kern-BEAGLEBONE.tgz from ftp://nyftp.netbsd.org/pub/NetBSD-daily/HEAD/whatever's recent/evbarm/binary/sets/kern-BEAGLEBONE.tgz

You may also want to get an install kernel, but since BEAGLEBONE_INSTALL isn't automatically built, I put one here:


You may want to rename it after gunzipping and before copying to the FAT partition to install.ub or something like that since I haven't a clue how other FAT software sees long filenames.

Then you need MLO and u-boot.img from the latest Angstrom image. They're here:


Finally, create a file called uEnv.txt on the FAT partition with the following as one continuous line:

uenvcmd=mmc dev 0; mmc rescan; mmc dev 1; mmc rescan; fatload mmc 1:1 82000000 
netbsd.ub; bootm 82000000

This is for booting off of the built-in 2 gig flash. If you're going to boot off the SD card, then change the "fatload mmc 1:1" bit to "fatload mmc 0:1".

Your file listing should look something like this:

-rwxr-xr-x  1 root  wheel    99976 Jul 23 06:04 MLO
-rwxr-xr-x  1 root  wheel  6799168 Jul 23 05:57 install.ub
-rwxr-xr-x  1 root  wheel  2670656 Jul 23 05:56 netbsd.ub
-rwxr-xr-x  1 root  wheel   379428 Jul 23 06:05 u-boot.img
-rwxr-xr-x  1 root  wheel      105 Jul 23 06:07 uEnv.txt

Next, unmount the SD card, put it in your BeagleBone Black, then boot!

This worked for me, but until someone fixes the mmc scanning, we'll only ever see ld0 (the built-in 2 gig flash in NetBSD), so the only way to make a usable, self-booting system is to use the install kernel to change the Linux partition type on the built-in flash to NetBSD (169), then install NetBSD into the 2 gig flash. After doing this, if you don't want to leave the SD card in to boot, you'll have to copy the files listed above to the FAT partition in the built-in 2 gig flash. Also, if you want NetBSD to go multiuser without prompting, compile a custom kernel changing this:

config          netbsd          root on ? type ?
config          netbsd          root on ld0f type ffs


Home | Main Index | Thread Index | Old Index