Building Jelly Bean 4.3 AOSP for BeagleBone Black

This blog post describes how to use vanilla AOSP Jelly Bean 4.3 source to build and run Android on the BeagleBone Black development board. All components are built from source (well, nearly all: the GPU drivers contain some binary blobs).

Screenshot of BeagleBone running JB 4.3

*Edit:there is an alternative version of this tutorial which uses fastboot to install Android into the internal eMMC flash memory rather than on external micro SD cards: Building Jelly Bean 4.3 AOSP for BeagleBone Black v2.0 - with fastboot*

Some of the components are taken from the excellent Rowboat project (http://arowboat.org). In fact, I have just re-packaged Rowboat to be more compliant with the Android way of life. Amongst other things, that means

  1. Using the Android Makefile unchanged. Rowboat modifies it to build the kernel, U-Boot and GPU drivers as well
  2. Building the extras (kernel, U-Boot, etc.) separately by hand, as a consequence of (1)
  3. Using a “normal” set of Android images and file system partitions (ramdisk.img, system.img, userdata.img and cache.img). Rowboat combines the contents together into a single partition which is mounted through a “root=/dev/mmcblk0p2” kernel command line
  4. Switching to Jelly Bean 4.3

My main motivation was to make it more suitable to use in the Android internals training classes I run.
Overall, the steps are

  1. Get AOSP source from Google
  2. Get my device files for the BeagleBone Black
  3. Get the Rowboat kernel
  4. Get the Rowboat SGX 530 GPU drivers
  5. Get the Rowboat U-Boot
  6. Build everything and put it on a micro SD card

For those of you in a hurry, you can get the pre-built image and write it to a micro SD card of at least 2 GiB. Plug the SD card into your card reader: it will show up as something like /dev/mmcblk0 or /dev/sdc. Make absolutely sure that you know which it is before continuing because hard drives also show up as /dev/sd* and writing this image to your hard drive will make your computer unbootable!. Assuming that the card reader is mmcblk0, write the image using a command like this:

$ sudo sh -c "unzip -p BBB-aosp-4.3_r2-sd-img.zip | dd of=/dev/mmcblk0 bs=4M"

Then skip to the section Boot it!

For everyone else, make sure that you have a system capable to building AOSP in a reasonable amount of time as described here http://source.android.com/source/building.html. Then follow these steps to set it up http://source.android.com/source/initializing.html. For reference, I tested on two machines: one a laptop with dual core i7 and 4 GiB RAM running Ubuntu 12.04 64 bit (AOSP build takes more than 2 hours), and the other an octo core AMD FX-8150 with 16 GiB RAM running Ubuntu 10.04 64 bit (takes 35 minutes).

You will need in addition the U-Boot mkimage tool:
Ubuntu 10.04: sudo apt-get install uboot-mkimage
Ubuntu 12.04: sudo apt-get install u-boot-tools

Get AOSP version 4.3_r2.1

Note: in the following I am installing and building everything in the home directory (“~”). You may use whichever directory you wish but you will have to modify the paths used below accordingly.

Begin by getting the repo tool and using it to download the AOSP:

$ curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > ~/bin/repo 
$ chmod a+x ~/bin/repo
$ mkdir ~/aosp-4.3_r2.1
$ cd aosp-4.3_r2.1
$ repo init -u https://android.googlesource.com/platform/manifest -b android-4.3_r2.1
$ repo sync

This takes several hours because there is 17 GiB to download. When complete you will have all the Android source in ~/aosp-4.3_r2.1.

Get device files for BeagleBone Black

Get my device files for the BeagleBone Black into device/ti/beagleboneblack

$ cd ~/aosp-4.3_r2.1/device/ti
$ git clone https://github.com/csimmonds/bbb-android-device-files.git beagleboneblack
$ cd ~/aosp-4.3_r2.1
$ . build/envsetup.sh
$ lunch beagleboneblack-eng

Get and build the kernel

The kernel comes from the Rowboat project. It is version 3.2, without device tree support, but it works well enough for me.

$ cd ~/aosp-4.3_r2.1
$ git clone git://gitorious.org/rowboat/kernel.git
$ cd kernel
$ git checkout rowboat-am335x-kernel-3.2

You can use the Android ARM cross compiler, arm-eabi-gcc, to build. Assuming that you have already sourced build/envsetup.sh and run lunch then you can:

$ cd ~/aosp-4.3_r2.1/kernel
$ make ARCH=arm CROSS_COMPILE=arm-eabi- am335x_evm_android_defconfig
$ make ARCH=arm CROSS_COMPILE=arm-eabi- -j4 uImage
$ croot
$ cp kernel/arch/arm/boot/zImage device/ti/beagleboneblack/kernel

Build AOSP for BeagleBone

Now you are ready to run the first AOSP build. Note: the -j option to "make" determines the number of parallel jobs to run. My rule of thumb is to use the number of CPU cores plus 2

$ cd ~/aosp-4.3_r2.1
$ make -j10

This takes an hour or so. When complete you will find the compiled Android system in ~/aosp-4.3_r2.1/out/target/product/beagleboneblack/

Get and build U-Boot

U-Boot also comes from Rowboat:

$ cd ~/aosp-4.3_r2.1
$ git clone git://gitorious.org/rowboat/u-boot
$ cd u-boot
$ git checkout am335x-v2013.01.01

Building is similar to the kernel, using the Android ARM cross compiler:

$ make CROSS_COMPILE=arm-eabi- distclean
$ make CROSS_COMPILE=arm-eabi- am335x_evm_config
$ make CROSS_COMPILE=arm-eabi- 

This will create the first stage boot loader, MLO, and the second stage bootloader, u-boot.bin.

Get the SGX drivers

Once again I am getting these from Rowboat. This is messy because they are not very well integrated with the AOSP code. One issue is that the makefile has some paths hard coded which is why it has to be put into hardware/ti/sgx, and also why the kernel has to be in directory kernel/.

$ cd ~/aosp-4.3_r2.1/hardware/ti
$ git clone git://git.gitorious.org/rowboat/hardware-ti-sgx.git sgx
$ cd sgx
$ git checkout ti_sgx_sdk-ddk_1.10-jb-4.3

With Rowboat, the binaries are copied into out/target/product/beagleboneblack/system after the AOSP build is complete and then post-processed into the install tar ball. I want to have them built as part of the AOSP build, so I edit one of the makefiles to put the binaries into my device directory. Then they get sucked into the final images by the rules in my device.mk. So, edit Rules.make: line 23 and change

TARGETFS_INSTALL_DIR=$(ANDROID_ROOT_DIR)/out/target/product/$(TARGET_PRODUCT)/

to

TARGETFS_INSTALL_DIR=$(ANDROID_ROOT_DIR)/device/ti/beagleboneblack/sgx

Build SGX

This next bit has to be run in a completely new shell. I'm sorry, but for some reason it won't build in a shell that has been set up for an AOSP build (i.e. has ". build/emvsetup.sh").

Note: W=1 is needed to avoid turning warnings into errors...

$ cd ~/aosp-4.3_r2.1/hardware/ti/sgx
$ PATH=$HOME/aosp-4.3_r2.1/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin:$PATH
$ make TARGET_PRODUCT=beagleboneblack OMAPES=4.x ANDROID_ROOT_DIR=$HOME/aosp-4.3_r2.1 W=1
$ make TARGET_PRODUCT=beagleboneblack OMAPES=4.x ANDROID_ROOT_DIR=$HOME/aosp-4.3_r2.1 W=1 install 

That will result in populating device/ti/beagleboneblack/sgx

Optional – get Android VNC server

The droid VNC server is useful if you want to test Android on your BeagleBone but don't have a screen:

$ cd  ~/aosp-4.3_r2.1/external
$ git clone git://gitorious.org/rowboat/droid-vnc-server

Final build

Now you need to regenerate the Android image files to include the sgx binaries. This should only take a few minutes.

$ cd ~/aosp-4.3_r2.1
$ . build/envsetup.sh
$ lunch beagleboneblack-eng
$ make installclean
$ make -j10

If something goes wrong, go back through the steps and try to identify the problem. For reference here is a copy of the image files I created.

Format an SD card

You need a micro SD card of at least 2 GiB capacity. Insert your SD card into your SD card reader. It will appear as either /dev/sd? Or as /dev/mmcblk? Use fdisk or similar to create partitions like this:

Partition    type    bootable?   Size (MB)  ID and file system
1          primary      *               64   c  W95 FAT32 (LBA) 
2          primary                      32  83  Linux 
3          primary                      32  83  Linux
4          extended                1718955
5          logical                     270  83  Linux 
6          logical                     270  83  Linux 
7          logical                     270  83  Linux 

I am going to leave the details up to you: that way you can't blame me if it goes wrong, but as mentioned at the start, please do be aware that accidentally formatting the wrong device, for example your hard drive, is a distinct possibility. It has happened to me. So, please, double check everything.

Then format the first partition, the boot partition, giving the correct device node:

$ sudo mkfs -t vfat -n "boot" /dev/mmcblk0

Of course, you only need to do these steps once, to initialise the SD card

Copy files and images to the SD card

1. The boot partition

Create the ramdisk:

$ cd ~/aosp-4.3_r2.1
$ mkimage -A arm -O linux -T ramdisk -d out/target/product/beagleboneblack/ramdisk.img uRamdisk

Mount the first partition and copy these files to it

  1. u-boot/MLO
  2. u-boot/u-boot.img
  3. uRamdisk
  4. device/ti/beagleboneblack/uEnv.txt
  5. kernel/arch/arm/boot/uImage

2. System, userdata and cache

The remaining image files are already in ext4 format so they can be copied directly to partitions 5, 6 and 7. For example if the SD card is /dev/mmcblk0 then

$ cd ~/aosp-4.3_r2.1/out/target/product/beagleboneblack
$ sudo dd if=system.img of=/dev/mmcblk0p5 bs=4M
$ sudo dd if=userdata.img of=/dev/mmcblk0p6 bs=4M
$ sudo dd if=cache.img of=/dev/mmcblk0p7 bs=4M

Boot it!

Now put the SD card in your BeagleBone. Depending on what is in your on-board eMMC flash, you may need to hold down the boot button while powering on to get it to load U-Boot from the SD card. All being well, you should see the "Android" boot animation after about 30 seconds and the launcher screen after 90 to 120 seconds. The second time the boot should be faster, I find it to be about 30 seconds.

Display options

You have three options

HDMI

There is a 720p output (1280 x 720) on the HDMI port. Plug this into a suitable display, plug a mouse in to the USB and you have a usable system. This is your best bet.

LCD cape

I have tried it with the LCD7 cape (800 x 480). The display is fine but the resistive touch screen is a dead loss. OK for demos.

VNC

If all else fails...

Run "androidvncserver" on the Beagleboard. Now you can connect to it either over USB or Ethernet. For USB you need to use adb to forward the VNC port and run a VNC client such as vinagre like so:

$ adb forward tcp:5901 tcp:5901
$ vinagre localhost:5901

To use Ethernet, you need to know what the IP address of the Beagleboard:

# netcfg
lo       UP          127.0.0.1/8   0x00000049 00:00:00:00:00:00
sit0     DOWN          0.0.0.0/0   0x00000080 00:00:00:00:00:00
eth0     UP       192.168.1.19/24  0x00001043 90:59:af:5d:85:78

Then on the PC

$ vinagre 192.168.1.19:5901

There is an irritating quirk you should know about: any keys you press in vinagre will not be transmitted to the device until you click the left mouse button.

Conclusion

After this fairly lengthy set of instructions you should have JB 4.3 running on your BeagleBone, and more importantly you will have experienced the stages of putting together an AOSP build. There are a few things that would make it easier including better packaged SGX drivers and fully working fastboot support in U-Boot. One of these days I will look at both. But my next challenge is to get KitKat up and running...

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Hi! First of all, thanks for

Hi!

First of all, thanks for the tutorial you wrote.

I followed it completely, with a little help from the pages at android.com. Now I can't seem to get the actual image files to be created... These don't appear when I execute the final 'make' command. Naturally the mkimage command after fails as well.

The only problem I ran into, was here:

$ make TARGET_PRODUCT=beagleboneblack OMAPES=4.x ANDROID_ROOT_DIR=$HOME/aosp-4.3_r2.1 W=1

Yielding this error: "Must build against Android >= 2.0"

The next command did ran however:

$ make TARGET_PRODUCT=beagleboneblack OMAPES=4.x ANDROID_ROOT_DIR=$HOME/aosp-4.3_r2.1 W=1 install

So I figured it went well, as the SGX folder was populated.

The 'make' command finishes with this output:


Notice file: system/core/run-as/NOTICE -- out/target/product/beagleboneblack/obj/NOTICE_FILES/src//system/bin/run-as.txt
Notice file: frameworks/native/cmds/service/NOTICE -- out/target/product/beagleboneblack/obj/NOTICE_FILES/src//system/bin/service.txt
target thumb C++: sensorservice <= frameworks/native/cmds/sensorservice/main_sensorservice.cpp
make: *** No rule to make target `device/ti/beagleboneblack/sgx/system/bin/sgx/omaplfb.ko', needed by `out/target/product/beagleboneblack/system/bin/sgx/omaplfb.ko'. Stop.
make: *** Waiting for unfinished jobs....
Notice file: frameworks/av/cmds/stagefright/NOTICE -- out/target/product/beagleboneblack/obj/NOTICE_FILES/src//system/bin/sf2.txt
<\cite>

Further up I don't see any errors, only warnings. But the total output is so massive that I don't really know where to start.

Any ideas where the problem could be?

Please help me out, I really need this!
Thanks!

That indicates that the SGX

That indicates that the SGX build or the install failed. Try getting a fresh copy of sgx and build it over again. If you still have problems could you mail me off list at chris@2net.co.uk and I'll work out what is going wrong and post an update if necessary. Thanks, Chris.

In case someone is still

In case someone is still using the guide.
You need to be sure that your variable ANDROID_ROOT_DIR contains exactly the path to the android build directory. My example is :

make TARGET_PRODUCT=beagleboneblack OMAPES=4.x ANDROID_ROOT_DIR=/mnt/src/bbb/android/aosp-4.3_r2.1 W=1

In case you've set it up correctly sgx build scripts are able to find all needed files with Android version and set all needed internal makefile variables.

speed up the download

In chapter "Get AOSP version 4.3_r2.1"
you could use this to speed up the download
repo sync -c -j2

Re: speed up the download

Good tip, thanks

Error doing make

In section "Build AOSP for Beaglebone" the command make gets an error, what's missing?

make: *** No rule to make target `device/ti/beagleboneblack/kernel', needed by `out/target/product/beagleboneblack/kernel'.  Stop.

Re: Error doing make

Oops, that is a build sequence error: you have to build the kernel before running the first AOSP build. I have updated the post (24th Feburary 2014) so it works correctly now. Thanks for pointing it out.

SGX build fails

Hi Chris,

Thanks for your work - but i ran into the same problem building SGX

make TARGET_PRODUCT=beagleboneblack OMAPES=4.x ANDROID_ROOT_DIR=$HOME/aosp-4.3_r2.1 W=1

../common/android/platform_version.mk:141: *** Must build against Android >= 2.0
make: *** [buildkernel] error 2

if you have anny ideas ...

Thanks ind advance

Re: SGX build fails

Short answer: you missed a step or mistyped something.
Slightly longer answer: the SGX build is failing to discover the Android version and assuming that it is too old. It gets the version from file
out/target/product/beagleboneblack/system/build.prop

and reads the line
ro.build.version.release=4.3

If that string does not exist in that file you will see the error you describe. HTH.

Can you share your image

Thanks for the instructions, but can you share your image so that we can quickly try things and check?

Re: Can you share your image

Indeed I can, I have just uploaded the results of the AOSP build to http://2net.co.uk/downloads/bbb-android/BBB-aosp-4.3_r2-images.tar.bz2, and I have edited the post to reference them early on so that people don't have to read all the way down to here to find out about them.

problem with downloadable images

I installed the pre-built images. However, when booting it tried to mount the /system from partition 5 rather than 6.

I ended up downloading all the source and building the images myself, following the instructions here for the most part. This was eventually successful, and probably for the best as I had to enable some additional kernel options to get my Logitech unifying mouse/keyboard working

BTW... never did get `lunch beagleboardblack-eng` working... not sure what I'm missing as a result

Thanks for the tutorials!

RE: problem with downloadable images

Partition 5 is the correct one for system.img, userdata.img goes on partition 6.

"never did get `lunch beagleboardblack-eng` working": the command should be 'lunch beagleboneblack-eng', i.e. 'bone', not 'black'.

I should have probably

I should have probably mentioned that I tried these images with the fastboot method, and eMMC... which has MLO and u-boot on separate partitions, making 'system' partition 6.

I'm pretty sure I actually used `lunch beagleboneblack-eng`, and simply mistyped in my previous response. i can verify this later today.

Partitions

Hi, quick q - your partitions are confusing me. You specify partition 2 and 3 as 32MB Linux, then partition 4 as extended with partition 5/6/7 270MB each.

Your DD command examples however ask us to dd if=system.img of=/dev/sdc2 bs=4M, which in this case would go to partition 2. In my case, my system.img is nearly 270MB so it's far greater than the 32MB size of partition 2. I *could* instead apply it to /dev/sdc5. Would that be appropriate in this case?

Oops, my mistake. The

Oops, my mistake. The partition numbers were wrong. They are

partition 5: system.img
partition 6: userdata.img
partition 7: cache.img

I have edited the section "Copy files and images to the SD card" to use the correct commands.

when JDK7.0 is used, Android built error

Android SDK module "bad class file magic" Error occures

Re: when JDK7.0 is used, Android built error

That is correct. Android Gingerbread through KitKat will only build with Java 6, as described in http://source.android.com/source/initializing.html

Static wallpaper does not work

Hi,
Thanks for your work. I write the pre-build image to the SD card. It works fine. However, when I replaced the live wallpaper by static wallpaper (long press by mouse, and select wallpaper), the wallpaper went black after setting. Do you know how to solve it? I faced the same problem when I followed "TI-Android-JB-4.2.2-DevKit-4.1.1 DeveloperGuide".
Thanks,
Jimmy

Re: Static wallpaper does not work

Short answer: this problem is fixed in KK 4.4.4, see http://2net.co.uk/tutorial/android-4.4-beaglebone for information on how to install it.

Longer answer: it is a problem with screen sizes 1280 x 720 or larger, which covers anyone using HDMI or VNC server for the display. With those screen dimensions the width of the wallpaper is 2069 (don't as why, that really is a long storey and not very interesting). But, the OpenGL library for the SGX cannon handle a texture > 2048 so it fails and so you don't see any wallpaper. In KK 4.4 the bitmap is scaled correctly.

Android USB Host support?

Hello,

Thank you for the instructions and images. I am using your images on a BBB and it seems the Android USB Host support is not functioning.

Obviously the USB host itself is fine as the mouse I have plugged in works ok and I see messages in dmesg (and files in /sys/bus/usb/) when other devices are plugged in.

My applications fails to find any USB devices through UsbManager.getDeviceList(), same application works as expected on my Nexus 7 and other devices.

Is there perhaps a piece missing from the build?

- Juha

Hi. Did you have any success

Hi.
Did you have any success with that? Have the same issue...

Re: Android USB Host support?

I have updated the device configuration for 4.4.4 booting on microSD and internal flash. I should work for you now.
Chris.

Thanks a lot, very helpful

Thanks a lot, very helpful tutorial. After booting from SD card and going to settings, I can't access 'storage' settings

sgx build fail

make TARGET_PRODUCT=beagleboneblack OMAPES=4.x ANDROID_ROOT_DIR=$HOME/aosp-4.3_r2.1 W=1
By above command I cannot build it correct.
And the error message is as below:
make[1]: Entering directory `/home/tommylin/BBB_JB/hardware/ti/sgx/eurasiacon/build/linux2/omap4430_android'
../common/android/platform_version.mk:141: *** Must build against Android >= 2.0. Stop.
make[1]: Leaving directory `/home/tommylin/BBB_JB/hardware/ti/sgx/eurasiacon/build/linux2/omap4430_android'

trying to follow your indication, but I cannot find below file in be low path.

out/target/product/beagleboneblack/system/build.prop

Could you be kind to review the sequence about build sgx?

Thanks in advance!!

Tommy Lin

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Youtube and Vimeo video links are automatically converted into embedded videos.
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.