Installing Android on the BeagleBone Black
The Android OS is a complex piece of software that is constructed out of many components built from a very large codebase. It can be a difficult and time-consuming task to build Android from source, so you will be using a premade Android image from the BBBAndroid project (www.bbbandroid.org) throughout this book.
BBBAndroid is a port of Android Open Source Project (AOSP) KitKat Android to the BBB. There are a few different distributions of Android available for the BBB, but we selected BBBAndroid because it uses the 3.8 Linux kernel. This kernel includes the Cape Manager (capemgr) functionality as well as a few other tools that will assist you in interfacing hardware to Android apps. Other flavors of Android on the BBB use the 3.2 Linux kernel, which is much older and lacks capemgr support. Chapter 2, Interfacing with Android, discusses the capemgr functionality in more detail. The 3.8 kernel is a good balance between enabling the newer features for the BBB while avoiding any potentially unstable, cutting-edge features.
The BBB can boot its OS in a few different ways:
- Onboard eMMC: The OS resides within the onboard eMMC storage. The Angstrom or Debian OS that comes installed on your BBB boots from the eMMC out of the box.
- MicroSD card: The OS resides on a microSD card that is inserted into the BBB. If a bootloader is installed on the microSD card, the bootloader installed on the onboard eMMC notices the presence of the microSD and will boot from that instead. In addition, booting from the microSD card is forced when the user boot button is held down during BBB power up.
- Over the network: The bootloader is capable of downloading a kernel over the network via TFTP. The OS can actually be downloaded at boot time though this is usually only done during commercial product development. This is an advanced feature that is outside the scope of this book.
The BBBAndroid image is designed to be written to and booted from a microSD card. As the image creates a fully bootable system on the microSD card, you will not have to hold the BBB's user boot button during power on to boot into Android. Simply insert the microSD card into the BBB and you'll boot into Android automatically.
Using a microSD card-based OS is advantageous for us because you can easily mount the card on a Linux PC to modify the Android filesystem as you see fit. If the OS is installed in the eMMC, it can be hard to access the OS to change arbitrary files in the filesystem. The system must be running to access the eMMC contents, so making a change that corrupts the system or makes it unbootable makes accessing the eMMC to fix the problem difficult.
Downloading a premade Android image
The main page of the BBBAndroid website provides a download link for the most recent premade image. Like any open source project, details about the version number and size of each image are likely to change over time as bugs are found and changes are made. However, the latest and greatest will be available via the website.
BBBAndroid's images are compressed using the xz compressor utility to save time when downloading, so the image must be decompressed prior to writing it to a microSD card. The tools used to decompress and write the image will vary depending upon the OS that you are using. While the compressed image might only be a few hundred MB in size, the uncompressed image will be 8 GB.
Note
Prior to beginning the decompression of the image, make sure that you have enough hard drive space to hold the uncompressed image.
Creating your Android microSD card using Windows
Under Windows-based OSes, the compressed image can be uncompressed using tools such as 7-Zip or WinRAR and then written to the microSD card using the tool Win32 Disk Imager. All of these tools are freely available for download. To prepare an Android microSD card, follow these steps:
- For this example, you'll use the WinRAR application. Download WinRAR from www.rarlab.com and install it. WinRAR will integrate with the Windows Explorer shell of the Windows desktop.
- Download and install the Win32 Disk Imager application. It is available from the project's SourceForge page at http://sourceforge.net/projects/win32diskimager.
- Right-click on the BBBAndroid image that you downloaded and select the Extract here option on the Explorer shell context menu. An uncompressed version of the image (8 GB in size) will be written to the same location as the compressed image. The decompression process might take several minutes.
- Insert an 8+ GB microSD card into the system. The card will be detected by Windows as having a valid filesystem on it if it came preformatted (most cards are sold preformatted for your convenience). Irrespective of whether the card is formatted or not, a drive letter is assigned to it by Windows.
- Browse to This PC and examine the devices shown under Devices and drives. The card should be shown. Make a note of the drive letter assigned to the card.
- Launch Win32 Disk Imager. Enter the filename and path to the uncompressed image in the text field, or click on the folder icon to navigate to the file's location. Change the Device drop-down box to the drive letter of the microSD card that you identified in step 4.
- Writing the image will take several minutes. Once the write has completed, remove the microSD card from your computer and insert it into your BBB.
- Power on the BBB and Android will begin to boot. On the first boot, it will take several minutes for the top-level UI screen to appear. On subsequent boots, it will take only 30 to 60 seconds to reach the top-level UI screen.
Congratulations! Your BBB is now running the Android OS.
Creating your Android microSD card using Linux
Under Linux, the compressed Android image can be uncompressed using the xz
command and written to the microSD card using the dd
command. To prepare an Android microSD card, follow these steps:
- Make sure that you have
xz
installed. For systems usingapt-get
, try installing the xz-utils package:$ sudo apt-get install xz-utils
- Decompress the image using
xz
. Substitute the name of your image file (with the.xz
file extension), as shown in the following command:$ xz --decompress [IMAGE FILENAME]
- Once uncompressed, the image will lose its
.xz
file extension and have a size of 8 GB. Insert your microSD card into the computer. A device in the/dev
directory will be assigned to your card. To determine which device it is, usefdisk
:$ sudo fdisk –l
- The
fdisk
utility will display all storage devices currently connected to your computer. One of the devices will report as being the same size as the microSD card. For example, if you insert an 8 GB microSD card, you will see something similar to this:Disk /dev/sdb: 8018 MB, 8018460672 bytes
The exact storage capacity of the card varies slightly between manufacturers, but the size is approximately 8 GB. The device assigned to this card is
/dev/sdb
. Other devices listed byfdisk
will be secondary storage devices (such as your hard drive). Before proceeding any further, make certain that you have identified the proper device file that belongs to your microSD card. If you select the wrong device, you will destroy the filesystem on that device! - Write the image to the microSD card using
dd
. Assuming that the device you identified in step 5 is/dev/sdb
, use the following command to perform the write:$ sudo dd if=[NAME OF IMAGE] of=/dev/sdb bs=4M
- Writing the image will take several minutes. Once the write has completed, remove the microSD card from your computer and insert it into your BBB.
Power on the BBB and Android will begin to boot. On the first boot, it will take several minutes for the top-level UI screen to appear. On subsequent boots, it will take only 30 to 60 seconds to reach the top-level UI screen.
Congratulations! Your BBB is now running the Android OS.