EBC Exercises on BBB

Tips on Building Kenrel

Via following commands you could build the 3.8 kernel for BBB:

$ git clone git://github.com/RobertCNelson/linux-dev.git
$ cd linux-dev
$ git checkout origin/am33x-v3.8 -b am33x-v3.8
$ time git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git
$ cp system.sh.sample system.sh
$ diff system.sh*
15c15
< CC=arm-linux-gnueabi-
---
> #CC=arm-linux-gnueabi-
21c21
< LINUX_GIT=~/BeagleBoard/linux-stable/
---
> #LINUX_GIT=/home/user/linux-stable/
31c31
< ZRELADDR=0x80008000
---
> #ZRELADDR=0x80008000
$ ./build_kernel.sh

U-boot Cross-compile

Download the U-boot and cross-compile it.

# git clone git://git.denx.de/u-boot.git
# cd u-boot/
# git checkout v2013.07 -b tmp
# wget https://raw.github.com/eewiki/u-boot-patches/master/v2013.07/0001-am335x_evm-uEnv.txt-bootz-n-fixes.patch
# patch -p1 < 0001-am335x_evm-uEnv.txt-bootz-n-fixes.patch
# setpogo	# For setting my cross-compiler to arm-linux-gnueabi-
# export ARCH=arm
# export CROSS_COMPILE=arm-linux-gnueabi-
# make

After building you will get MLO and u-boot.img.

Test on NFS

Prepare the NFS File System.

mkdir dtbs
tar xzvf 3.8.13-bone53-dtbs.tar.gz -C ./dtbs
cp dtbs/am335x-boneblack.dtb /srv/tftp/
cp 3.8.13-bone53.zImage /srv/tftp/
mkimage -A arm -O linux -T kernel -C none -a 0x80008000 -e 0x80008000 -n "Linux" -d /srv/tftp/3.8.13-bone53.zImage  /srv/tftp/uImage
tar xJvf ubuntu-14.04-console-armhf-2014-08-13.tar.xz -C /srv/nfs4/
cd /srv/nfs4/ubuntu-14.04-console-armhf-2014-08-13
tar xvf armhf-rootfs-ubuntu-trusty.tar -C ../Ubuntu_fs/
chmod 777 -R Ubuntu_fs/

Then boot the system from U-boot Via:

setenv ipaddr 192.168.1.16
setenv serverip 192.168.1.221
tftpboot ${fdtaddr} am335x-boneblack.dtb
tftpboot ${kloadaddr} uImage
setenv bootargs console=ttyO0,115200n8 root=/dev/nfs rootfstype=nfs rw nfsroot=192.168.1.221:/srv/nfs4/Ubuntu_fs ip=192.168.1.1 
bootm ${kloadaddr} - ${fdtaddr}

Now boot the BBB and we got the ssh enabled, via ssh ubuntu@192.168.1.1, password is temppwd.

Sometimes you will meet sudo problem, just chown and chmod is OK

# chmod 4755 some_related_file
# chown root some_related_file

Since NFS gonna the write priviledge error, go back for SD card.

SD Card

FileSystem Preparation:

$ export DISK=/dev/mmcblk0
$ dd if=/dev/zero of=${DISK} bs=1M count=10
$ dd if=./u-boot/MLO of=${DISK} count=1 seek=1 conv=notrunc bs=128k
$ dd if=./u-boot/u-boot.img of=${DISK} count=2 seek=1 conv=notrunc bs=384k
 sfdisk --in-order --Linux --unit M ${DISK} <<-__EOF__
1,,0x83,*
__EOF__
$ mkfs.ext4 /dev/mmcblk0p1 -L rootfs

Copy the Operating system into the sd card partition 1, later we will use /mnt for mounting the partition 1:

# mount /dev/mmcblk0p1 /mnt
# cd ubuntu-14.04.1-console-armhf-2014-10-29
# tar xvf armhf-rootfs-ubuntu-trusty.tar -C /mnt/
# sync

Now install the kernel image into the ubuntu system. Imagine your SD is mount to /mnt/

cp /media/y/embedded/BBB/EBC/3.8Kernel/linux-dev/deploy/3.8.13-bone53.zImage /mnt/boot/vmlinuz-3.8.13-bone53
tar xzvf /media/y/embedded/BBB/EBC/3.8Kernel/linux-dev/deploy/3.8.13-bone53-dtbs.tar.gz -C /mnt/boot/dtbs/

Now create the following uEnv.txt located in /mnt/boot/ and /mnt/:

##This will work with: Angstrom's 2013.06.20 u-boot.
 
loadaddr=0x82000000
fdtaddr=0x88000000
rdaddr=0x88080000
 
initrd_high=0xffffffff
fdt_high=0xffffffff

console=ttyO0,115200n8
mmcroot=/dev/mmcblk0p1 ro
 
loadximage=load mmc 0:1 ${loadaddr} /boot/vmlinuz-3.8.13-bone53
loadxfdt=load mmc 0:1 ${fdtaddr} /boot/dtbs/3.8.13-bone53/am335x-boneblack.dtb
loadxrd=load mmc 0:1 ${rdaddr} /boot/initrd.img-${uname_r}; setenv rdsize ${filesize}
loaduEnvtxt=load mmc 0:1 ${loadaddr} /boot/uEnv.txt ; env import -t ${loadaddr} ${filesize};
loadall=run loaduEnvtxt; run loadximage; run loadxfdt;
 
mmcargs=setenv bootargs console=tty0 console=${console} ${optargs} ${cape_disable} ${cape_enable} root=${mmcroot} rootfstype=${mmcrootfstype} ${cmdline}
 
uenvcmd=run loadall; run mmcargs; bootz ${loadaddr} - ${fdtaddr};
optargs="debug"

Enable the dhcp, /mnt/etc/network/interfaces:

auto lo
iface lo inet loopback
 
auto eth0
iface eth0 inet dhcp

Enable the serial port:

$ sudo vim /mnt/etc/init/serial.conf
start on stopped rc RUNLEVEL=[2345]
stop on runlevel [!2345]
 
respawn
exec /sbin/getty 115200 ttyO0

Now restart and you got the 3.8 kernel enabled, so next time if you want to change the kernel, simply change the uEnv.txt file is OK.

ubuntu@arm:/boot$ uname -a
Linux arm 3.8.13-bone53 #1 SMP Tue Nov 11 18:40:19 CST 2014 armv7l armv7l armv7l GNU/Linux

EBC Exercises on BBB - Control LED

Using Sysfs

The easiest way to do general purpose I/O(gpio) on BBB is through the terminal and shell command. sysfs is the virtual file system which exposes the drivers for the hardware so you can directly use them.

# cd /sys/class/leds
# ls
# beaglebone:green:usr0  beaglebone:green:usr1  beaglebone:green:usr2  beaglebone:green:usr3
# cd beaglebone\:green\:usr0
# cat trigger 
none nand-disk mmc0 mmc1 timer oneshot [heartbeat] backlight gpio cpu0 default-on transient 

If you want to disable the heartbeat:

# echo none > trigger
# cat trigger 
[none] nand-disk mmc0 mmc1 timer oneshot heartbeat backlight gpio cpu0 default-on transient 

Turn on/off the led via:

# echo 1 > brightness
# echo 0 > brightness

More trigger options via:

# echo timer>trigger 
# cat trigger 
none nand-disk mmc0 mmc1 [timer] oneshot heartbeat backlight gpio cpu0 default-on transient 

Set the deplay frequency:

echo 100>delay_on
echo 900>delay_off

Adding Own LED

Add the connection of LED.
P9 Pin1 –> 220 ohm –> LED Negative Pin P9 Pin 12 -> Led Positive Pin

Pin 12 in the table is shown in table as GPIO1_28. Bank of 32 each, so find the gpio number via:
1*32+28=60.

We have to turn this pin on.

Turn it ON

export/unexport, turn on/off of the LED via following command:

$ cd /sys/class/gpio/
$ echo 60 > export
$ cd gpio60/
$ echo out > direction
$ echo 1 > value
$ echo 0 > value
$ cd ..
$ ls
export  gpio60  gpiochip0  gpiochip32  gpiochip64  gpiochip96  unexport
$ echo 60 > unexport
$ ls -F
export  gpiochip0@  gpiochip32@  gpiochip64@  gpiochip96@  unexport

Add Own Key

Connection for the key:
P9 Pin 3(3.3V) –>220 ohm –> Key 1
P9 Pin 42 –> Key 2
Pin 42 is GPIO0_7, then the actual gpio number is Just 7.

Read Value

export/unexport, read value via following command:

# cd /sys/class/gpio/
# echo 7 > export
# cd gpio7/
# echo in > direction
# cat value
# cat value 
0
Hold down the button and see the result: 
# cat value 
1

The script for reading the gpio value:

# ./readgpio.sh 7
sh: echo: I/O error
trap: SIGINT: bad trap
__________________________|^^^^^^^^^^^^^^^^^^^^^^^|__________|^^^^^^^^^^|___
___|^^^^^^^|______|^^^^^^^|______|^^^^^^^|______|^^^^^^^|______|^^^^^^^|______|^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^|____|^^^^^^^^|____|^^|__|^^|_|^^^^^^|___|^^
|__|^|__|^|__|^|__|^^|___|^|_|^|___|^|_|^|_|^|_|^^|_|^|_|^|_|^^|_|^^^^^^^^^^^^^|______|^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^|____|^^^^^^^^^^^|_____|^^^^^^^^^^^^^^|____|^^^^^^^^^^
^^^|___|^^^^^^^^^^^^|____|^^^^^^^^^^^^|__|^^^^^^^^^^|__|^^^^^^^^|__|^^^^^^^|___|^^^^
^|_____|^^^^^|____|^^^^^^^^^^^^^^^^^^^^^^^|___|^^^^^^^^^^^^^^^^^|___|^^^^^^^^^^^
|_^C

This seems like a little game.

EBC Exercises on BBB - Device Tree

Install js wrapped bonescript

For using the javascript wrapped library, first we have to install following packages:

$ sudo apt-get install nodejs npm nodejs-legacy
$ npm config set proxy http://1xx.xx.xx.xxx:2xxx
$ npm config set https-proxy http://1xx.xx.xx.xx:2xxx
$ npm install bonescript

Because my network environment is under the firewall, so I need to set the proxy, if you directly connect to internet, you could ignore the npm config set commands.

EBC Exercises on BBB - Read Analog

Connection

The wired connection is listed as following:
Pin 34(analog ground) —> Negative Pin
Pin 32(1.8 V) —> Positive Pin
Pin 36(AIN5) —> Wiper
Pin 32: VADC, Pin 34: AGND, Pin36, AIN5.

Operation

root@arm:/sys/kernel/debug/pinctrl/44e10800.pinmux# cat /sys/devices/bone_capemgr.*/slots
 0: 54:PF--- 
 1: 55:PF--- 
 2: 56:PF--- 
 3: 57:PF--- 
 4: ff:P-O-L Bone-LT-eMMC-2G,00A0,Texas Instrument,BB-BONE-EMMC-2G
 5: ff:P-O-L Bone-Black-HDMI,00A0,Texas Instrument,BB-BONELT-HDMI
root@arm:/sys/kernel/debug/pinctrl/44e10800.pinmux# SLOTS=/sys/devices/bone_capemgr.*/slots
root@arm:/sys/kernel/debug/pinctrl/44e10800.pinmux# PINS=/sys/kernel/debug/pinctrl/44e10800.pinmux/pins
root@arm:/sys/kernel/debug/pinctrl/44e10800.pinmux# echo cape-bone-iio > $SLOTS
root@arm:/sys/kernel/debug/pinctrl/44e10800.pinmux# cat $SLOTS
 0: 54:PF--- 
 1: 55:PF--- 
 2: 56:PF--- 
 3: 57:PF--- 
 4: ff:P-O-L Bone-LT-eMMC-2G,00A0,Texas Instrument,BB-BONE-EMMC-2G
 5: ff:P-O-L Bone-Black-HDMI,00A0,Texas Instrument,BB-BONELT-HDMI
 7: ff:P-O-L Override Board Name,00A0,Override Manuf,cape-bone-iio
root@arm:/sys/kernel/debug/pinctrl/44e10800.pinmux# find /sys -name "*AIN*"
/sys/devices/ocp.3/helper.15/AIN0
/sys/devices/ocp.3/helper.15/AIN1
/sys/devices/ocp.3/helper.15/AIN2
/sys/devices/ocp.3/helper.15/AIN3
/sys/devices/ocp.3/helper.15/AIN4
/sys/devices/ocp.3/helper.15/AIN5
/sys/devices/ocp.3/helper.15/AIN6
/sys/devices/ocp.3/helper.15/AIN7

Now try to read the value out:

# cd /sys/devices/ocp.3/helper.15
# ls
AIN0  AIN1  AIN2  AIN3  AIN4  AIN5  AIN6  AIN7  driver  modalias  power  subsystem  uevent
# cat AIN5
537

In the origin material it said should plus 1, to read AIN5 you have to look at AIN6, but it seems wrong, because the table and the interface all starts from 0.

AIN pins are sampled at 12bits and 100k samples per time. while the input voltage is between 0 and 1.8V.

It’s very easy to use anlog read value for controlling some variables, like volumn, brightness, etc.

Server Performance

Get the UnixBench and run

wget http://byte-unixbench.googlecode.com/files/UnixBench5.1.3.tgz
tar xvf UnixBench5.1.3.tgz 
cd UnixBench
./Run


Result: