A Handful Of Commands And Scripts To Get Started With BeagleBone Black
Here I have compiled a list of commands and some info to get you started with BeagleBone Black. I will keep updating this list of commands as I find something new . I hope that it will save you some time .
picture credits: xkcd.com
All of these commands are to be executed on the BeagleBone black (BBB for short) itself after you login as root, and are expected to work on kernel version 4.4.11+
Content
- Starters
- Environment Variables
- Config-pin utility
- Force rebooting
- Sharing your Ubuntu system’s Internet with BBB
- Kernel Development
- Linux Headers
- Install latest kernel
- BBB kernel source
- BBB clone kernel source
- Cross-compiler toolchain
- Particular kernel config file
- Cross compiling the kernel source
- Cross compile a driver
- Working with PRUs
- Fact 1
- To shutdown PRU0
- To shutdown PRU1
- More
Starters :
- Environment Variables - ssh into your BBB and append your bashrc with following lines:
export PINS=/sys/kernel/debug/pinctrl/44e10800.pinmux export SLOTS=/sys/devices/platform/bone_capemgr/slots export FW=/lib/firmware
Config-pin utility - To change the pinmux settings for a pin does not need device tree overlays now (4.4+ kernel), you can simply use ‘config-pin’ utility. To configure the pin you just need to know its position on the board, so to change mux settings of pin at , for example , P8_46
The output shows space separated list of available pin-modes and will look like :$ config-pin -l P8_46
Now to change pinmode, to, for example, pruout$ default gpio gpio_pu gpio_pd pruout pruin pwm
This will configure pin at P8_46 to pru_output mode. Further status of the pin can be known using ‘config-pin -i’, which will give detailed output.$ config-pin P8_46 pruout
$ config-pin -i P8_46 Pin name: P8_46 Function if no cape loaded: hdmi Function if cape loaded: default gpio gpio_pu gpio_pd pruout pruin pwm Function information: lcd_data1 default gpio2_7 gpio2_7 gpio2_7 pr1_pru1_pru_r30_1 pr1_pru1_pru_r31_1 ehrpwm2B Cape: cape-universala cape-univ-hdmi Kernel GPIO id: 71 PRU GPIO id: 103
Force rebooting - One of my favorite commands, rebooting your BBB when something goes wrong and it won’t reboot the normal way ( Thanks to Stephanie for this).
echo b >/proc/sysrq-trigger
Sharing your Ubuntu system’s Internet with BBB - Use the command
to determine the interface your system is using to connect to BBB (it will be mostly eth0) and to the Internet.$ ifconfig
Let the Internet interface and BBB interface be <Internet-interface> and <BBB-interface> respectively. Now on your system, execute following commands as root:
Generally, these commands will look like :$ iptables -t nat -A POSTROUTING -o <Internet-interface> -j MASQUERADE $ iptables -A FORWARD -i <BBB-interface> -j ACCEPT $ sysctl net.ipv4.ip_forward=1
$ iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE $ iptables -A FORWARD -i eth0 -j ACCEPT $ sysctl net.ipv4.ip_forward=1
On your BBB, execute this command after you login as root :
$ route add default gw 192.168.7.1
To automate all this Internet connecting thing, just put all these commands in /etc/rc.local in their respective systems.
Now to test if all this works, use command “ping 8.8.8.8” and the output should look like :
root@beaglebone:~# ping 8.8.8.8 PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data. 64 bytes from 8.8.8.8: icmp_seq=1 ttl=54 time=49.2 ms 64 bytes from 8.8.8.8: icmp_seq=2 ttl=54 time=46.1 ms 64 bytes from 8.8.8.8: icmp_seq=3 ttl=54 time=40.0 ms 64 bytes from 8.8.8.8: icmp_seq=4 ttl=54 time=52.1 ms ^C --- 8.8.8.8 ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 3006ms rtt min/avg/max/mdev = 40.021/46.883/52.108/4.496 ms
It will be then useful to add “nameserver 8.8.8.8” in the first line of your /etc/resolv.conf
Kernel Development
- Linux Headers - To install Linux kernel header files for your current Linux version:
$ apt-get install -y linux-headers-$(uname -r)
Install latest kernel - To install a new version of kernel image for example: kernel image 4.4.11-ti-r29 ( Thanks to Steve Arnold for these ) :
$ sudo apt-get update $ export NEW="4.4.11-ti-r29" $ sudo apt-get install -y linux-firmware-image-$NEW linux-headers-$NEW linux-image-$NEW
BBB kernel source - To browse the kernel source of a particular version, go onto :
for example if you want to go to the 4.4.11-ti-r29 kernel, the link will be :https://github.com/RobertCNelson/linux-stable-rcn-ee/tree/<kernel build number>
https://github.com/RobertCNelson/linux-stable-rcn-ee/tree/4.4.11-ti-r29
BBB clone kernel source - To clone a kernel source ( Thanks to Michael Welling and Stephanie for help on this ) :
for example if you want to clone the 4.4.11-ti-r29 kernel, the commands will be :$ mkdir KERNEL-<build number> $ git clone --depth=100 -b <build number> https://github.com/RobertCNelson/linux-stable-rcn-ee.git KERNEL-<build number> $ touch KERNEL-<build number>/.ignore-<build number>
$ mkdir KERNEL-4.4.11-ti-r29 $ git clone --depth=100 -b 4.4.11-ti-r29 https://github.com/RobertCNelson/linux-stable-rcn-ee.git KERNEL-4.4.11-ti-r29 $ touch KERNEL-4.4.11-ti-r29/.ignore-4.4.11-ti-r29
Cross-compiler toolchain - To download the latest version of cross-compiler tool-chain ( command source : eewiki )
$ export DWL="gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf.tar.xz" $ wget -c https://releases.linaro.org/components/toolchain/binaries/5.3-2016.02/arm-linux-gnueabihf/$DWL $ tar xf gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf.tar.xz $ export CC=`pwd`/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-
Particular kernel config file - To download .config file of a particular kernel build number:
for example$ export NEW="<kernel build number>" $ wget -c http://rcn-ee.net/deb/jessie-armhf/v$NEW/defconfig -O config-$NEW
$ export NEW="4.4.11-ti-r29" $ wget -c http://rcn-ee.net/deb/jessie-armhf/v$NEW/defconfig -O config-$NEW
Cross compiling the kernel source - To cross compile the source code, cd into the kernel source’s root :
for example for kernel - 4.4.11-ti-r29,$ export KERN_V="<kernel version>" $ export BUILD_V="<build version>" $ export CROSS_COMPILE=path/to/your/cross/compiler/tool/chain
then after that:$ export KERN_V="4.4.11" $ export BUILD_V="-ti-r29" $ export CROSS_COMPILE=../../toolcahin/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-
now each time you want to build your kernel$ make mrproper ARCH=arm LOCALVERSION=$BUILD_V CROSS_COMPILE=path/to/the/cross/compile/toolchain $ wget -c http://rcn-ee.net/deb/jessie-armhf/v$KERN_V$BUILD_V/defconfig -O .config
$ make ARCH=arm LOCALVERSION=$BUILD_V CROSS_COMPILE=path/to/the/cross/compile/toolchain
Cross compile a driver - To cross compile particular drivers that is present in your kernel source, you will have to go through complete kernel build process at-least once so that it generates that symbol version file, and only then will you be able to load the module. Follow above steps to build the kernel, then to compile one driver
for example to compile rpmsg drivers :$ make modules SUB_DIRS=path/to/the/driver ARCH=arm LOCALVERSION=$BUILD_V
$ make modules SUB_DIRS=drivers/rpmsg/ ARCH=arm LOCALVERSION=$BUILD_V
Working with PRUs
- Fact 1 - Rebooting any PRU core (0 or 1) will result in reloading of the firmware that is at /lib/firmware/am335x-pruN-fw (pruN can be pru0 or pru1)
To shutdown PRU0
and to boot it upecho "4a334000.pru0" > /sys/bus/platform/drivers/pru-rproc/unbind
echo "4a334000.pru0" > /sys/bus/platform/drivers/pru-rproc/bind
To shutdown PRU1
and to boot it upecho "4a338000.pru1" > /sys/bus/platform/drivers/pru-rproc/unbind
echo "4a338000.pru1" > /sys/bus/platform/drivers/pru-rproc/bind
More - Some more of them have been described in the 2nd post of PTP series