YMMV

* your mileage may vary

Wednesday, 28 May 2014

Beaglebone Black (BBB) Cross Compile


The web site: http://eewiki.net/display/linuxonarm/BeagleBone+Black shows the instructions on how to compile from source for BBB.  The site is a bit flaky and not all the text is rendered and displayed (using Firefox!) so I've reproduced it here for convenience.  The only thing I've done it mde sure the all content is shown.  Full credit is attributed to Robert Nelson.
ARM Cross Compiler: GCC
This is a pre-built (32bit) version of Linaro GCC that runs on generic linux, so 64bit users need to make sure they have installed the 32bit libraries for their distribution.

Debian based (deb)
extra
pkgs: (sudo apt-get update ; sudo apt-get install xyz)
Ubuntu 12.04

ia32-libs
Debian 7 (Wheezy)
sudo dpkg --add-architecture i386
libc6:i386 libstdc++6:i386 libncurses5:i386 zlib1g:i386
Ubuntu 12.10 -> 14.04

libc6:i386 libstdc++6:i386 libncurses5:i386 zlib1g:i386
Red Hat based (rpm)
extra
pkgs: (yum install xyz)
Red Hat/Centos/Fedora

libstdc++.i686 ncurses-devel.i686 zlib.i686

Download/Extract:
~/
o   wget -c https://releases.linaro.org/14.03/components/toolchain/binaries/gcc-linaro-arm-linux-gnueabihf-4.8-2014.03_linux.tar.xz
o   tar xf gcc-linaro-arm-linux-gnueabihf-4.8-2014.03_linux.tar.xz
o   export CC=`pwd`/gcc-linaro-arm-linux-gnueabihf-4.8-2014.03_linux/bin/arm-linux-gnueabihf-

Test:
If this test fails, verify that you have the 32bit libraries installed on your development system.
~/
o   ${CC}gcc --version
arm-linux-gnueabihf-gcc (crosstool-NG linaro-1.13.1-4.8-2014.03 - Linaro GCC 2014.03) 4.8.3 20140303 (prerelease)
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Bootloader: U-Boot
Das U-Boot -- the Universal Boot Loader http://www.denx.de/wiki/U-Boot

Download:
~/
o   git clone git://git.denx.de/u-boot.git
o   cd u-boot/
o   git checkout v2014.04 -b tmp

Patches:
~/u-boot
o   wget -c https://raw.github.com/eewiki/u-boot-patches/master/v2014.04/0001-am335x_evm-uEnv.txt-bootz-n-fixes.patch
o   patch -p1 < 0001-am335x_evm-uEnv.txt-bootz-n-fixes.patch

Configure and Build:
~/u-boot
o   make ARCH=arm CROSS_COMPILE=${CC} distclean
o   make ARCH=arm CROSS_COMPILE=${CC} am335x_evm_config
o   make ARCH=arm CROSS_COMPILE=${CC}

Upgrade distro "device-tree-compiler" package

o   wget -c https://raw.github.com/RobertCNelson/tools/master/pkgs/dtc.sh
o   chmod +x dtc.sh
o   ./dtc.sh

Linux Kernel
This script will build the kernel and modules and copy them to the deploy directory.

Download:
~/
o   git clone https://github.com/RobertCNelson/bb-kernel.git
o   cd bb-kernel/

Checkout v3.8.x branch (full cape support):
~/linux-dev
o   git checkout origin/am33x-v3.8 -b tmp

Or the v3.14.x branch (better usb and ethernet):
~/linux-dev
o   git checkout origin/am33x-v3.14 -b tmp

Build:
~/linux-dev
o   ./build_kernel.sh

Root File System
Debian 7
User
Password
debian
temppwd
root
root

This image contains, systemd: https://wiki.debian.org/systemd to enable, add to uEnv.txt:
o   optargs=quiet init=/lib/systemd/systemd

Download:
~/
o   wget -c https://rcn-ee.net/deb/minfs/wheezy/debian-7.5-minimal-armhf-2014-05-07.tar.xz

Verify:
~/
o   md5sum debian-7.5-minimal-armhf-2014-05-07.tar.xz
o   215cdc3a5cfbdedb23f0fa2f2f3f256f debian-7.5-minimal-armhf-2014-05-07.tar.xz

Extract:
~/
o   tar xf debian-7.5-minimal-armhf-2014-05-07.tar.xz

Ubuntu 14.04
User
Password
ubuntu
temppwd

Download:
~/
o   wget -c https://rcn-ee.net/deb/minfs/trusty/ubuntu-14.04-minimal-armhf-2014-05-07.tar.xz

Verify:
~/
o   md5sum ubuntu-14.04-minimal-armhf-2014-05-07.tar.xz
o   2ca8170aca04ca88ca4b946844a76844 ubuntu-14.04-minimal-armhf-2014-05-07.tar.xz

Extract:
~/
o   tar xf ubuntu-14.04-minimal-armhf-2014-05-07.tar.xz

Root File System (small flash)
A Root File System around 64Mb in size, for flash applications.

Debian 7 (small flash)
User
Password
debian
temppwd
root
root

Download:
~/
o   wget -c https://rcn-ee.net/deb/barefs/wheezy/debian-7.5-bare-armhf-2014-05-07.tar.xz

Verify: 
~/
o   md5sum debian-7.5-bare-armhf-2014-05-07.tar.xz
o   6dfe01c32929546146f75c7791dc8317  debian-7.5-bare-armhf-2014-05-07.tar.xz

Extract: 
~/
o   tar xf debian-7.5-bare-armhf-2014-05-07.tar.xz

Setup microSD/SD card

For these instruction, we are assuming: DISK=/dev/mmcblk0, "lsblk" is very useful for determining the device id.

o   export DISK=/dev/mmcblk0

Erase microSD/SD card:
o   sudo dd if=/dev/zero of=${DISK} bs=1M count=16

Create Partition Layout:
sudo sfdisk --in-order --Linux --unit M ${DISK} <<-__EOF__
1,48,0xE,*
,,,-
__EOF__

Format Partitions:
for: DISK=/dev/mmcblk0
o   sudo mkfs.vfat -F 16 ${DISK}p1 -n boot
o   sudo mkfs.ext4 ${DISK}p2 -L rootfs

for: DISK=/dev/sdX
o   sudo mkfs.vfat -F 16 ${DISK}1 -n boot
o   sudo mkfs.ext4 ${DISK}2 -L rootfs

Mount Partitions:
On some systems, these partitions may be auto-mounted...
o   sudo mkdir -p /media/boot/
o   sudo mkdir -p /media/rootfs/

for: DISK=/dev/mmcblk0
o   sudo mount ${DISK}p1 /media/boot/
o   sudo mount ${DISK}p2 /media/rootfs/

for: DISK=/dev/sdX
o   sudo mount ${DISK}1 /media/boot/
o   sudo mount ${DISK}2 /media/rootfs/

Install Bootloader
Copy MLO/u-boot.img to the boot partition
~/
o   sudo cp -v ./u-boot/MLO /media/boot/
o   sudo cp -v ./u-boot/u-boot.img /media/boot/

uEnv.txt based bootscript

In the case of the production BeagleBone Black we also have to deal with the default bootloader...

Create "uEnv.txt" boot script: (nano uEnv.txt)
~/uEnv.txt
#u-boot eMMC specific overrides; Angstrom Distribution (BeagleBone Black) 2013-06-20
kernel_file=zImage
initrd_file=initrd.img

loadaddr=0x82000000
initrd_addr=0x88080000
fdtaddr=0x88000000

initrd_high=0xffffffff
fdt_high=0xffffffff

loadimage=load mmc ${mmcdev}:${mmcpart} ${loadaddr} ${kernel_file}
loadinitrd=load mmc ${mmcdev}:${mmcpart} ${initrd_addr} ${initrd_file}; setenv initrd_size ${filesize}
loadfdt=load mmc ${mmcdev}:${mmcpart} ${fdtaddr} /dtbs/${fdtfile}
#

##Un-comment to enable systemd in Debian Wheezy
#optargs=quiet init=/lib/systemd/systemd

console=ttyO0,115200n8
mmcroot=/dev/mmcblk0p2 ro
mmcrootfstype=ext4 rootwait fixrtc

##To disable HDMI/eMMC...
#optargs=capemgr.disable_partno=BB-BONELT-HDMI,BB-BONELT-HDMIN,BB-BONE-EMMC-2G

##3.1MP Camera Cape
#optargs=capemgr.disable_partno=BB-BONE-EMMC-2G

mmcargs=setenv bootargs console=${console} root=${mmcroot} rootfstype=${mmcrootfstype} ${optargs}

#zImage:
uenvcmd=run loadimage; run loadfdt; run mmcargs; bootz ${loadaddr} - ${fdtaddr}

#zImage + uInitrd: where uInitrd has to be generated on the running system.
#boot_fdt=run loadimage; run loadinitrd; run loadfdt
#uenvcmd=run boot_fdt; run mmcargs; bootz ${loadaddr} ${initrd_addr}:${initrd_size} ${fdtaddr}

Copy uEnv.txt to the boot partition:
~/
o   sudo cp -v ./uEnv.txt /media/boot/

Install Kernel and Root File System
To help new users, since the kernel version can change on a daily basis. The kernel building scripts listed on this page will now give you a hint of what kernel version was built.
-----------------------------
Script Complete
eewiki.net: [user@localhost:~$ export kernel_version=3.X.Y-Z]
-----------------------------

Copy and paste that "export kernel_version=3.X.Y-Z" exactly as shown in your own build/desktop environment and hit enter to create an environment variable to be used later.
o   export kernel_version=3.X.Y-Z

Copy Root File System
~/
o   sudo tar xfvp ./*-*-*-armhf-*/armhf-rootfs-*.tar -C /media/rootfs/

Copy Kernel Files
Kernel Image:
~/
o   sudo cp -v ./bb-kernel/deploy/${kernel_version}.zImage /media/boot/zImage

Kernel Device Tree Binaries:
~/
o   sudo mkdir -p /media/boot/dtbs/
o   sudo tar xfov ./bb-kernel/deploy/${kernel_version}-dtbs.tar.gz -C /media/boot/dtbs/
o   sudo tar xfv ./bb-kernel/deploy/${kernel_version}-firmware.tar.gz -C /media/rootfs/lib/firmware/

Kernel Modules:
~/
o   sudo tar xfv ./bb-kernel/deploy/${kernel_version}-modules.tar.gz -C /media/rootfs/

File Systems Table (/etc/fstab)
Edit: /etc/fstab
o   sudo nano /media/rootfs/etc/fstab
/etc/fstab
/dev/mmcblk0p2   /           auto   errors=remount-ro   0   1
/dev/mmcblk0p1   /boot/uboot auto   defaults            0   2

Networking
Edit: /etc/network/interfaces
o   sudo nano /media/rootfs/etc/network/interfaces

Add:
/etc/network/interfaces
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

Networking: Using a shared SD card with Multiple BeagleBone 
To always enable the Ethernet interface as eth0.
Edit: /etc/udev/rules.d/70-persistent-net.rules
o   sudo nano /media/rootfs/etc/udev/rules.d/70-persistent-net.rules

Add:
/etc/udev/rules.d/70-persistent-net.rules
# BeagleBone: net device ()
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

Serial Login
Debian
Edit: /etc/inittab
o   sudo nano /media/rootfs/etc/inittab

Add this at the end of: /etc/inittab
/etc/inittab
T0:23:respawn:/sbin/getty -L ttyO0 115200 vt102

Ubuntu
Create new file: /etc/init/serial.conf
o   sudo nano /media/rootfs/etc/init/serial.conf

With this content:
/etc/init/serial.conf
start on stopped rc RUNLEVEL=[2345]
stop on runlevel [!2345]

respawn
exec /sbin/getty 115200 ttyO0

Remove microSD/SD card:
o   sync
o   sudo umount /media/boot
o   sudo umount /media/rootfs

usb gadget (http access to beaglebone black over usb)
This is just a temp hack till we get some udev rules setup in the default minimal file system:

Install udhcpd
o   sudo apt-get install udhcpd

Edit: /etc/network/interfaces and add:
/etc/network/interfaces
# Ethernet/RNDIS gadget (g_ether)
# ... or on host side, usbnet and random hwaddr
iface usb0 inet static
    address 192.168.7.2
    netmask 255.255.255.0
    network 192.168.7.0
    gateway 192.168.7.1

Temp Script:
o   wget -c https://raw.github.com/RobertCNelson/tools/master/scripts/beaglebone-black-g-ether-load.sh
o   chmod +x beaglebone-black-g-ether-load.sh
o   sudo ./beaglebone-black-g-ether-load.sh

HDMI
This sections assumes you have already installed your favorite xorg based window manager, such as lxde, xfce, kde, gnome, etc... These are packages that need to be installed on top of your selected windows manager and an xorg.conf needed to correctly setup the video interface.

Note: If the cursor doesn't show up right away, first hit: ctlr-alt-f1 then: ctrl-alt-f7 after which it 'should' show up...

Make sure to install, modesetting driver and xrandr utilities:
o   sudo apt-get update
o   sudo apt-get install read-edid xserver-xorg-video-modesetting x11-xserver-utils

/etc/X11/xorg.conf
Section "Monitor"
        Identifier      "Builtin Default Monitor"
EndSection
Section "Device"
        Identifier      "Builtin Default fbdev Device 0"
        Driver          "modesetting"
EndSection
Section "Screen"
        Identifier      "Builtin Default fbdev Screen 0"
        Device          "Builtin Default fbdev Device 0"
        Monitor         "Builtin Default Monitor"
        DefaultDepth    16
EndSection
Section "ServerLayout"
        Identifier      "Builtin Default Layout"
        Screen          "Builtin Default fbdev Screen 0"
EndSection

xrandr:
o   xrandr
o   xrandr --output HDMI-0 --mode 1024x768 --rate 60

xrandr (over serial/ssh)
o   xrandr -display :0.0 -q
o   xrandr -display :0.0 --output HDMI-0 --mode 1024x768 --rate 60

eMMC
These scripts require booting with an init filesystem (uInitrd in uEnv.txt) as we use UUID's.. Otherwise this will happen:
[ 2.601453] ALSA device list:
[    2.604593]   #0: TI BeagleBone Black
[    2.609156] Waiting for root device UUID=148737f6-66ae-49e4-8271-8e69c014a349...
<hardlock>

Update uEnv.txt for zImage + uInitrd boot... First, Comment out zImage only boot:
 #zImage:
uenvcmd=run loadimage; run loadfdt; run mmcargs; bootz ${loadaddr} - ${fdtaddr}

to:
#zImage:
#uenvcmd=run loadimage; run loadfdt; run mmcargs; bootz ${loadaddr} - ${fdtaddr}

Second, uncomment zImage + uInitrd boot:
#zImage + uInitrd: where uInitrd has to be generated on the running system.
#boot_ftd=run loadimage; run loadinitrd; run loadfdt
#uenvcmd=run boot_ftd; run mmcargs; bootz ${loadaddr} 0x81000000:${initrd_size} ${fdtaddr}

to:
#zImage + uInitrd: where uInitrd has to be generated on the running system.
boot_ftd=run loadimage; run loadinitrd; run loadfdt
uenvcmd=run boot_ftd; run mmcargs; bootz ${loadaddr} 0x81000000:${initrd_size} ${fdtaddr}
The "uInitrd" file will be generated by default with these scripts:

Script to copy your microSD card to eMMC:
o   wget -c https://raw.github.com/RobertCNelson/tools/master/scripts/beaglebone-black-copy-microSD-to-eMMC.sh
o   chmod +x beaglebone-black-copy-microSD-to-eMMC.sh
o   sudo ./beaglebone-black-copy-microSD-to-eMMC.sh
Script to just update the boot partition of the eMMC:
o   wget -c https://raw.github.com/RobertCNelson/tools/master/scripts/beaglebone-black-just-copy-boot-to-eMMC.sh
o   chmod +x beaglebone-black-just-copy-boot-to-eMMC.sh
o   sudo ./beaglebone-black-just-copy-boot-to-eMMC.sh

FAQ
BeagleBone Black Angstrom usb networking fails to load
dmesg will show an error like:
[    5.179269] g_multi: `' invalid for parameter `C7'

Background:
hexdump has a feature to replace repeated characters with a *, thus the mac-address can become corrupted when read:
hexdump -e '1/1 "%02X" ":"' /proc/device-tree/ocp/ethernet@4a100000/slave@4a100300/mac-address
90:59:AF:5C:*
C7:root@beaglebone:~#


hexdump -v -e '1/1 "%02X" ":"' /proc/device-tree/ocp/ethernet@4a100000/slave@4a100300/mac-address
90:59:AF:5C:5C:C7:root@beaglebone:~#

/usr/bin/g-ether-load.sh
mac_address="/proc/device-tree/ocp/ethernet@4a100000/slave@4a100300/mac-address"
if [ -f ${mac_address} ] ; then
    DEV_ADDR=$(hexdump -e '1/1 "%02X" ":"' ${mac_address} | sed 's/.$//')
else

Add "-v" to hexdump call.
/usr/bin/g-ether-load.sh
mac_address="/proc/device-tree/ocp/ethernet@4a100000/slave@4a100300/mac-address"
if [ -f ${mac_address} ] ; then
    DEV_ADDR=$(hexdump -v -e '1/1 "%02X" ":"' ${mac_address} | sed 's/.$//')
else

Patch posted:


https://github.com/beagleboard/meta-beagleboard/pull/12


1 comment:

  1. Dear sir,

    i am using this blog,i able to boot from sdcard as well as emmc.but with the help in i want to boot from emmc but play video from sdcard.

    in my sdcard,only 2 video is there.

    and give the power to beaglebone then board is not boot.

    thanks
    rahul

    ReplyDelete