Dev/BeagleBone/BBB/From Scratch

From Embeded Linux (and more) Wiki by Nathael
< Dev‎ | BeagleBone‎ | BBB
Revision as of 20:11, 16 October 2019 by Drizzt (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

u-boot

Full AM335x U-Boot User's Guide on ti wiki.

Grab the sources

git clone git://git.denx.de/u-boot.git
cd u-boot/
git checkout v2017.03

Optional :

git checkout -b new_branch
(Replace "new_branch" with the name of your choice !)

Patches:

wget https://raw.github.com/eewiki/u-boot-patches/master/v2013.10/0001-am335x_evm-uEnv.txt-bootz-n-fixes.patch
patch -p1 < 0001-am335x_evm-uEnv.txt-bootz-n-fixes.patch

Patched sources can be recovered on my server : uboot_***.tar.bz2.

Compile

Configure and Build:

mkdir -p ../Build/uboot/ ../Build/results/
rm -rf ../Build/uboot/*
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- O=../Build/uboot/ distclean
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- O=../Build/uboot/ am335x_boneblack_defconfig
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- O=../Build/uboot/ -j 8
cp ../Build/uboot/MLO ../Build/uboot/u-boot.img ../Build/results/

You need both binaries as the BeagleBone Black processor (Texas Instrument AM335x), in SD card boot mode, will look for a file named "MLO", which must fit on the only available memory at this point : the instruction cache (128k minus 19k reserved for boot rom).

MLO stand for "Memory Locator" and is a "Secondary Program Loader (SPL)". It is in fact a reduced "1st stage" u-boot image, which in turns looks for a file named "u-boot.img" which the "2nd stage" uboot.

When always booting in the same known configuration it is possible to avoid the second stage u-boot and change the MLO configuration to look for a fixed name Linux kernel image and device tree and immediately load and run these instead.

Configuration

Create the file ../Build/results/uEnv.txt
An example file can be found in the results.tar.bz2 archive on my server.

Use

The resulting binaries are part of the results.tar.bz2 archive on my server.

The "MLO" file must be on the first partition of the µSD card, which must be formated as FAT32 and flaged as bootable.

You will need to place "u-boot.img" and "uEnv.txt" on the same partition.

Linux Kernel

Grab the sources

FIXME : Must be updated to a newer kernel !! (At least the 4.4.1 I'm currently using)

using information from Robert C Nelson or Mainline Linux on the Beaglebone Black

Sources :

git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

Extract specific version ***FIXME***

git checkout ***

Optional (creates a new local branch) :

git checkout -b new_branch

Patched sources can be recovered on my server : linux_***.tar.bz2.

Compilation

Create build dir and copy default config

cd linux
mkdir -p ../Build/kernel
cp config_nath_**** ../Build/kernel/.config
make ARCH=arm O=../Build/kernel/ oldconfig

Optional : make menuconfig (for example to change the cross-compiler prefix : arm-linux-gnueabihf-)

make ARCH=arm O=../Build/kernel/ menuconfig

Build kernel

make -j 8 ARCH=arm O=../Build/kernel/ zImage

Build device tree blobs

make -j 8 ARCH=arm O=../Build/kernel/ dtbs

Get the results :

cp ../Build/kernel/arch/arm/boot/zImage ../Build/kernel/arch/arm/boot/dts/am335x-boneblack.dtb ../Build/results/

Build and install modules

make -j 8 ARCH=arm O=../Build/kernel/ modules
make -j 8 ARCH=arm O=../Build/kernel/ modules_install INSTALL_MOD_PATH=../results/

Device Tree

Refer to "Build device tree blob" in the previous section.

Note: I'm using "am335x-boneblack-bbbmini.dtb" from my sources for 4.4.1 kernel.

Firmwares

make -j 8 ARCH=arm O=../Build/kernel/ firmware
make -j 8 ARCH=arm O=../Build/kernel/ firmware_install INSTALL_FW_PATH=../results/lib/firmware

Still required ??

wget http://arago-project.org/git/projects/?p=am33x-cm3.git\;a=blob_plain\;f=bin/am335x-pm-firmware.bin\;hb=HEAD -O ../results/lib/firmware/am335x-pm-firmware.bin

Use

The resulting binaries are part of the results.tar.bz2 archive on my server.

You will need to place "zImage" and "am335x-boneblack.dtb" with u-boot images on the first partition of the SD card.

You'll also need to copy the modules and firmware directories ("../results/lib/modules/***" and "../results/lib/firmware") to the corresponding directories in the root filesystem. Make sure you do not change the name for the module directory, as it MUST match the kernel name.

Warning : somewhere between kernel 3.12 and 4.4.1 a stupid guy decided to change a part of the kernel interface (which is strictly forbidden by the kernel development rules !!!) : the tty for (all ?) omap processors got renamed from ttyO* to ttyS*, breaking the userspace !
Thus, if you've got no messages from your kernel while you had some from u-boot (which means your serial cable is plugged in a running just fine), then check your kernel command line (in the uEnv.txt file or in your kernel config) for boot messages and your "/etc/inittab" file for your login console.

SD Card creation

SD card architecture

Start by partitioning your µSD card. My preferred tool for this is cfdisk, but any other partitioning tool should do the job :)
The partition type must be "DOS".

start size usage
0MB 50MB First partition - W95 FAT32 (0x0b) with bootable flag
50MB - Second partition - Linux (0x83)

You can of course add more partitions if you need or want to separate your root filesystem and your data.

Then format both partitions :

dev=sdc   # Select the right device according to your system (sdb, mmcblk0p, ...)
mkfs.vfat /dev/${dev}1 -F 32 -n BBB_Boot
mkfs.ext4 /dev/${dev}2 -L BBB_System

Note : you may use lsblk or check the content of /proc/partitions to find the right device (or run tail -f on /var/log/syslog before plugging the µSD card reader) :

lsblk /dev/sd* -o NAME,PATH,FSTYPE,LABEL,PARTTYPE,MODEL,SIZE,VENDOR
tail -f /var/log/syslog

First partition

The first partition must be formated as vfat (FAT32) and flagged as bootable. A few MB (20MB to 50MB) are OK unless you want to store dozens of kernel versions :)
It holds u-boot images, u-boot environnement script and the Linux kernel image and the device tree. It's also a good idea to add the kernel configuration (.config, renamed with the kernel name).

These files are part of the results.tar.bz2 archive on my server.

Second partition

The second partition is formated using ext4 and holds the root filesystem (rootfs).

Rootfs

This board uses an ARM processor with hardfloat support, thus the root filesystem should be built using "arm-linux-gnueabihf-" cross-toolchain or use the armhf architecture for Devuan or other Debian based distribution.

Refer to the rootfs creation page for more information. You should find a base Devuan rootfs here : rootfs_devuan_ceres_armhf_***.tar.bz2.