A Handful Of Commands And Scripts To Get Started With BeagleBone Black

ZeekHuge Jun 16, 2016
Github Code Repository

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 .

joke

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
    1. Environment Variables
    2. Config-pin utility
    3. Force rebooting
    4. Sharing your Ubuntu system’s Internet with BBB
  • Kernel Development
    1. Linux Headers
    2. Install latest kernel
    3. BBB kernel source
    4. BBB clone kernel source
    5. Cross-compiler toolchain
    6. Particular kernel config file
    7. Cross compiling the kernel source
    8. Cross compile a driver
  • Working with PRUs
    1. Fact 1
    2. To shutdown PRU0
    3. To shutdown PRU1
    4. More


Starters :

  1. 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
    

  2. 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

    $ config-pin -l P8_46
    
    The output shows space separated list of available pin-modes and will look like :
    $ default gpio gpio_pu gpio_pd pruout pruin pwm
    
    Now to change pinmode, to, for example, pruout
    $ config-pin P8_46 pruout
    
    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 -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
    

  3. 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
    

  4. Sharing your Ubuntu system’s Internet with BBB - Use the command

    $ ifconfig 
    
    to determine the interface your system is using to connect to BBB (it will be mostly eth0) and to the Internet.

    • Let the Internet interface and BBB interface be <Internet-interface> and <BBB-interface> respectively. Now on your system, execute following commands as root:

      $ iptables -t nat -A POSTROUTING -o <Internet-interface> -j MASQUERADE
      $ iptables -A FORWARD -i <BBB-interface> -j ACCEPT
      $ sysctl net.ipv4.ip_forward=1
      
      Generally, these commands will look like :
      $ 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

  1. Linux Headers - To install Linux kernel header files for your current Linux version:

    $ apt-get install -y linux-headers-$(uname -r)
    

  2. 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 
    

  3. BBB kernel source - To browse the kernel source of a particular version, go onto :

    https://github.com/RobertCNelson/linux-stable-rcn-ee/tree/<kernel build number>
    
    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/4.4.11-ti-r29
    

  4. BBB clone kernel source - To clone a kernel source ( Thanks to Michael Welling and Stephanie for help on this ) :

    $ 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>
    
    for example if you want to clone the 4.4.11-ti-r29 kernel, the commands will be :
    $ 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
    

  5. 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-
    

  6. Particular kernel config file - To download .config file of a particular kernel build number:

    $ export NEW="<kernel build number>"
    $ wget -c http://rcn-ee.net/deb/jessie-armhf/v$NEW/defconfig -O config-$NEW
    
    for example
    $ export NEW="4.4.11-ti-r29"
    $ wget -c http://rcn-ee.net/deb/jessie-armhf/v$NEW/defconfig -O config-$NEW
    

  7. Cross compiling the kernel source - To cross compile the source code, cd into the kernel source’s root :

    $ export KERN_V="<kernel version>"
    $ export BUILD_V="<build version>"
    $ export CROSS_COMPILE=path/to/your/cross/compiler/tool/chain
    
    for example for kernel - 4.4.11-ti-r29,
    $ 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-
    
    then after that:
    $ 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
    
    now each time you want to build your kernel
    $ make ARCH=arm LOCALVERSION=$BUILD_V CROSS_COMPILE=path/to/the/cross/compile/toolchain 
    

  8. 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

    $ make modules SUB_DIRS=path/to/the/driver ARCH=arm LOCALVERSION=$BUILD_V 
    
    for example to compile rpmsg drivers :
    $ make modules SUB_DIRS=drivers/rpmsg/ ARCH=arm LOCALVERSION=$BUILD_V 
    

Working with PRUs

  1. 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)

  2. To shutdown PRU0

    echo "4a334000.pru0" > /sys/bus/platform/drivers/pru-rproc/unbind
    
    and to boot it up
    echo "4a334000.pru0" > /sys/bus/platform/drivers/pru-rproc/bind
    

  3. To shutdown PRU1

    echo "4a338000.pru1" > /sys/bus/platform/drivers/pru-rproc/unbind
    
    and to boot it up
    echo "4a338000.pru1" > /sys/bus/platform/drivers/pru-rproc/bind
    

  4. More - Some more of them have been described in the 2nd post of PTP series

comments powered by Disqus