Home > Articles > Mobile Application Development & Programming

How to Boot an Android Emulator Image Using U-Boot

Roger Ye, author of Embedded Programming with Android: Bringing Up an Android System from Scratch, explains how to set up and use the popular U-Boot bootloader to boot an Android emulator image.
Like this article? We recommend

Do you have difficulties with debugging U-Boot on an Android device in your project? Are you wondering how to start the Android system from scratch? These are common puzzles in the areas of Android system programming. To explore embedded system programming or Android system programming, you will need a hardware board, but the hardware might not always be available. How can you get started with something you already have on hand? The Android emulator is actually a good choice, even for system-level programming. In this article, I address how to use U-Boot to boot an Android emulator image.

U-Boot is a popular bootloader used in many embedded applications. Android system developers often use it to boot various Android-based embedded systems. As an Android application developer, you might use it to enter recovery mode or to restore the factory default settings for your testing devices. However, no bootloader is available in the Android emulator environment, which Android application developers use most of the time. Let's take a look at the details of how to use U-Boot in the Android emulator environment. Using U-Boot, Android system developers and application developers can gain the flexibility to manipulate the Android emulator system image. For example, testing and debugging issues related to recovery mode is almost impossible in the emulator environment. With a bootloader, you shouldn't have any problems testing recovery mode in the emulator environment.

This article will not discuss on how to port U-Boot to the Android emulator or how to build it for the Android emulator. Instead, we'll focus on how to use the U-Boot available in my book Embedded Programming with Android: Bringing Up an Android System from Scratch to design different usage scenarios for the Android emulator. The information in this article will help Android system developers and application developers to work with test cases that need a bootloader in the Android emulator environment.

How to Get the U-Boot for Android Emulator

The U-Boot for Android emulator can be downloaded from SourceForge, a web-based service that offers a source code repository, download mirrors, bug tracking, and other features. Two binary packages contain the U-Boot image for the Android emulator:

Both packages are built for KitKat (Android version 4.4.4 and API level 19). To test it, you need to download the Android software development kit (SDK) and install Android emulator images for API level 19. You can test these two packages using your Android SDK installation, which means you can test them in Windows, Linux, or OS X environments. This article demonstrates the setup in Ubuntu Linux 12.04.

After downloading these two packages, put them in a folder called images under your home folder:

$ ls images
aosp-bin.zip  cm-bin.zip

Next, you need to decompress the packages. After decompression, check the contents inside the packages:

$ ls -F images
aosp-bin/  aosp-bin.zip  cm-bin/  cm-bin.zip
$ ls images/aosp-bin
aosp-test.bat  ramdisk.img  system.img  userdata.img
aosp-test.sh   Readme.txt   u-boot.bin
$ ls images/cm-bin
cm-test.bat  ramdisk.img  system.img  userdata.img
cm-test.sh   Readme.txt   u-boot.bin

You can find the files listed in the following table in either aosp-bin.zip or cm-bin.zip.

File(s)

Description

Scripts for testing

You can use scripts aosp-test.bat/cm-test.bat to test AOSP or CyanogenMod in Windows, or aosp-bin.sh/cm-test.sh to test in Linux or OS X.

u-boot.bin

This is the U-Boot image for the Android emulator. Although this image can be used for any Android version, it has to build for a particular Android emulator version. It has no dependency to the upper layer (operating system and applications above it), but it has to build for the virtual hardware platform, called goldfish, which is the code name of the Android emulator virtual hardware platform. The virtual hardware interface of the Android emulator may differ in various Android SDK releases. The U-Boot image in this example is built for the Android SDK adt-bundle-linux-x86-20140702, but it should also work for the latest Android SDK.

system.img

This is a version of the Android emulator system image built using AOSP version android-4.4.4_r2 or CyanogenMod version cm-11.

userdata.img

This is a version of the Android emulator data image built using AOSP version android-4.4.4_r2 or CyanogenMod version cm-11.

ramdisk.img

This is a version of the Android emulator RAM disk image built using AOSP version android-4.4.4_r2 or CyanogenMod version cm-11.

Readme.txt

This file explains how to use the packages.

Setting Up the Android Virtual Device to Test AOSP and CyanogenMod Emulator Images

Before testing using U-Boot to boot the Android emulator image, you have to set up an Android Virtual Device (AVD). We'll use the Android Virtual Device Manager for this purpose.

You can launch the Android Virtual Device Manager from the Eclipse IDE, Android Studio, or the command line. In order to use the script in the downloaded package, we'll need to create two Android Virtual Devices, named armemu for AOSP and cm_armemu for CyanogenMod. Use the following command:

$ android avd

Once you've launched the Android Virtual Device Manager, create an Android Virtual Device as shown in Figure 1.

Figure 1 Setting up an Android Virtual Device.

In Figure 1, an Android Virtual Device named armemu for Android 4.4.2, API Level 19 was created. The target CPU/ABI is armeabi-v7a because the U-Boot image used here is for the ARM processor architecture. I choose 512MB RAM and 200MB internal storage space for the settings. The hardware spec for cm_armemu is the same as in Figure 1 except for the device name.

After setting up the Android Virtual Devices armemu and cm_armemu, we can boot up the Android emulator images using U-Boot. Let's test the AOSP build first, using these commands:

$ cd aosp-bin
$ ./aosp-test.sh

Enter the aosp-bin folder and launch the Android emulator image, using the script aosp-test.sh. This script executes the following command:

$ emulator -avd armemu -verbose -show-kernel -shell -system ./system.img
 -initdata ./userdata.img -ramdisk ./ramdisk.img -qemu -kernel ./u-boot.bin

This command starts the Android emulator with AVD name armemu and specifies the system.img, userdata.img and ramdisk.img files. It uses U-Boot image u-boot.bin as the kernel image to start the emulator.

Once the emulator enters the Android home screen, we can check the software version information from the About phone screen inside Settings, as shown in Figure 2.

Figure 2 Android version of the AOSP image.

We can do the same for the CyanogenMod image. Launch the Android emulator image for CyanogenMod by using the following commands:

$ cd ../cm-bin
$ ./cm-test.sh

Once the emulator enters the Android home screen, check the software version information in the same way as we did for the AOSP version. Notice the version information shown in Figure 3.

Figure 3 Android version of CyanogenMod image.

After using U-Boot to set up and test the Android emulator images for AOSP or CyanogenMod, we can refer to the boot log for more analysis. Using the boot log from the AOSP image, for example, shows the analysis below:

U-Boot 2013.01.-rc1-00004-g7d47698 (Apr 13 2015 - 09:49:09)

U-Boot code: 00010000 -> 00070F24  BSS: -> 000A9210
IRQ Stack: 0badc0de
FIQ Stack: 0badc0de
monitor len: 00099210
ramsize: 20000000
TLB table at: 1fff0000
Top of RAM usable for U-Boot at: 1fff0000
Reserving 612k for U-Boot at: 1ff56000
Reserving 4104k for malloc() at: 1fb54000
Reserving 32 Bytes for Board Info at: 1fb53fe0
Reserving 120 Bytes for Global Data at: 1fb53f68
Reserving 8192 Bytes for IRQ stack at: 1fb51f68
New Stack Pointer is: 1fb51f58
RAM Configuration:
Bank #0: 00000000 512 MiB
relocation Offset is: 1ff46000
goldfish_init(), gtty.base=ff012000
WARNING: Caches not enabled
monitor flash len: 00068C4C
Now running in RAM - U-Boot at: 1ff56000
NAND:  base=ff017000
goldfish_nand_init: id=0: name=nand0, nand_name=system
goldfish_nand_init: id=1: name=nand1, nand_name=userdata
goldfish_nand_init: id=2: name=nand2, nand_name=cache
517 MiB
MMC:   board_mmc_init called
goldfish_mmc: 0
Using default environment

Destroy Hash Table: 1ffb5be8 table = 00000000
Create Hash Table: N=104
INSERT: table 1ffb5be8, filled 1/107 rv 1fb542b0 ==> name="bootargs"
 value="qemu.gles=0 qemu=1 console=ttyS0 android.qemud=ttyS1
 androidboot.console=ttyS2 android.checkjni=1 ndns=1"
INSERT: table 1ffb5be8, filled 2/107 rv 1fb54394 ==> name="bootcmd"
 value="ydevconfig sys 0 0x0 0x7f0 ; ymount sys ;
 yrdm sys/ramdisk.uimg 0x610000 ; yrdm sys/zImage.uimg 0x210000 ;
 yumount sys ; bootm 0x210000 0x610000"
INSERT: table 1ffb5be8, filled 3/107 rv 1fb5440c ==> name="bootdelay" value="2"
INSERT: table 1ffb5be8, filled 4/107 rv 1fb54478 ==> name="baudrate" value="38400"
INSERT: table 1ffb5be8, filled 5/107 rv 1fb54604 ==> name="bootfile" value="/tftpboot/uImage"
INSERT: free(data = 1fb54008)
INSERT: done
In:    serial
Out:   serial
Err:   serial
Net:   SMC91111-0
Warning: SMC91111-0 using MAC address from net device

### main_loop entered: bootdelay=2

### main_loop: bootcmd="ydevconfig sys 0 0x0 0x7f0 ; ymount sys ; yrdm sys/ramdisk.uimg 0x610000 ;
 yrdm sys/zImage.uimg 0x210000 ; yumount sys ; bootm 0x210000 0x610000"
Hit any key to stop autoboot:  0
Configures yaffs mount sys: dev 0 start block 0, end block 2032
Mounting yaffs2 mount point sys
Copy sys/ramdisk.uimg to 0x00610000...       [DONE]
Copy sys/zImage.uimg to 0x00210000...        [DONE]
Unmounting yaffs2 mount point sys
## Current stack ends at 0x1fb51b00 *  kernel: cmdline image address = 0x00210000
## Booting kernel from Legacy Image at 00210000 ...
   Image Name:
   Created:      2015-04-13   1:49:27 UTC
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    2423552 Bytes = 2.3 MiB
   Load Address: 00010000
   Entry Point:  00010000
   kernel data at 0x00210040, len = 0x0024fb00 (2423552)
*  ramdisk: cmdline image address = 0x00610000
## Loading init Ramdisk from Legacy Image at 00610000 ...
   Image Name:
   Created:      2015-04-13   1:49:27 UTC
   Image Type:   ARM Linux RAMDisk Image (uncompressed)
   Data Size:    323724 Bytes = 316.1 KiB
   Load Address: 00800000
   Entry Point:  00800000
   ramdisk start = 0x00800000, ramdisk end = 0x0084f08c
   Loading Kernel Image ... OK
OK
   kernel loaded at 0x00010000, end = 0x0025fb00
images.os.start = 0x210000, images.os.end = 0x45fb40
images.os.load = 0x10000, load_end = 0x25fb00
using: ATAGS
## Transferring control to Linux (at address 00010000)...

Starting kernel ...

Uncompressing Linux... done, booting the kernel.

From this boot log, we can see that after U-Boot starts, it prints the following version information:

U-Boot 2013.01.-rc1-00004-g7d47698 (Apr 13 2015 - 09:49:09)

This U-Boot image was built on April 13, 2015 and is based on version 2013.01.-rc1-00004-g7d47698 build from the Linaro release.

During startup, this image initializes the following NAND devices:

goldfish_nand_init: id=0: name=nand0, nand_name=system
goldfish_nand_init: id=1: name=nand1, nand_name=userdata
goldfish_nand_init: id=2: name=nand2, nand_name=cache

After U-Boot initializes the hardware interfaces, the following boot commands are used to boot the Android system:

bootcmd="ydevconfig sys 0 0x0 0x7f0 ; ymount sys ; yrdm sys/ramdisk.uimg 0x610000 ;
 yrdm sys/zImage.uimg 0x210000 ; yumount sys ; bootm 0x210000 0x610000"

Command Details

Let's look into the details and see how to use these commands to boot the Android system. First, we use U-Boot command ydevconfig to configure the NAND device:

ydevconfig sys 0 0x0 0x7f0

The first parameter (sys) is the name that we choose for device nand0. The second parameter is the number of the NAND device. (Device ID 0 is the NAND device storing the Android file system.) The third parameter is the starting block, and the fourth parameter is the end block.

Once the NAND device is configured, we use the ymount command to mount the NAND device:

ymount sys

Thereafter, we can use the yrdm command to load the RAM disk image and kernel image to memory:

yrdm sys/ramdisk.uimg 0x610000
yrdm sys/zImage.uimg 0x210000

Once the kernel image and RAM disk image are loaded into memory, we can see from the above boot log that the kernel image is loaded at memory address 0x210000 and the RAM disk image is at memory address 0x610000.

Now we can unmount the NAND device, using U-Boot command yumount, and boot to the operating system using the bootm command:

yumount sys
bootm 0x210000 0x610000

How to Get the U-Boot Console

In the files aosp-bin.zip or cm-bin.zip, the U-Boot image is built with proper boot commands so that U-Boot can boot operating system automatically. It is difficult to get the U-Boot command console using U-Boot in these two packages. With U-Boot command console, we can debug the boot process and do something extra. An U-Boot image which can boot to U-Boot command console is posted at u-boot_goldfish.zip. You can download and do your own testing with it. After you download u-boot_goldfish.zip and decompress it, you'll see two files:

$ cd u-boot_goldfish
$ ls
Readme.txt  u-boot.bin

You can get the U-Boot console by using the following commands:

$ emulator -avd armemu -show-kernel -shell -qemu -kernel ./u-boot.bin
...
### main_loop entered: bootdelay=2

### main_loop: bootcmd="ver"
Hit any key to stop autoboot:  0

U-Boot 2013.01.-rc1-00004-g7d47698-dirty (Jul 19 2015 - 19:53:01)
arm-none-eabi-gcc (Sourcery CodeBench Lite 2012.03-56) 4.6.3
GNU ld (Sourcery CodeBench Lite 2012.03-56) 2.21.53.20110905
armemu #

Once you enter the U-Boot command console, you can test various U-Boot commands available in the U-Boot manual. For example, you can get version information and check environment variables as shown below:

armemu # ver

U-Boot 2013.01.-rc1-00004-g7d47698-dirty (Jul 19 2015 - 19:53:01)
arm-none-eabi-gcc (Sourcery CodeBench Lite 2012.03-56) 4.6.3
GNU ld (Sourcery CodeBench Lite 2012.03-56) 2.21.53.20110905
armemu # printenv
EXPORT  table = 1ffb601c, htab.size = 89, htab.filled = 11, size = 0
Unsorted: n=11
          0: 1fb54144 ==> bootfile   => /tftpboot/uImage
          1: 1fb54150 ==> bootcmd    => ver
          2: 1fb5415c ==> stderr     => serial
          3: 1fb54168 ==> baudrate   => 38400
          4: 1fb54294 ==> bootargs   => qemu.gles=0 qemu=1 console=ttyS0 android.qemud=ttyS1
                                        androidboot.console=ttyS2 android.checkjni=1 ndns=1
          5: 1fb542b8 ==> stdin      => serial
          6: 1fb542e8 ==> bootdelay  => 2
          7: 1fb543c0 ==> ethaddr    => 52:54:00:12:34:56
          8: 1fb54414 ==> verify     => n
          9: 1fb544bc ==> stdout     => serial
         10: 1fb544ec ==> ethact     => SMC91111-0
baudrate=38400
bootargs=qemu.gles=0 qemu=1 console=ttyS0 android.qemud=ttyS1
 androidboot.console=ttyS2 android.checkjni=1 ndns=1
bootcmd=ver
bootdelay=2
bootfile=/tftpboot/uImage
ethact=SMC91111-0
ethaddr=52:54:00:12:34:56
stderr=serial
stdin=serial
stdout=serial
verify=n

Environment size: 296/8188 bytes
armemu #

As you can see from the environment variables above, for this build of U-Boot, the variable bootcmd was set as ver. After U-Boot is loaded, it will just print version information and enter the command console.

What Else Can You Do with U-Boot?

With U-Boot support, you can explore various methods to boot the Android system emulator. For example, you can test the boot process from either NOR or NAND flash.

Without a bootloader, you can't test cases related to recovery mode. With U-Boot, you can build your own recovery images and test them using U-Boot. Furthermore, you can test multi-boot systems, just like you can on a PC. You can put more than one Android system into one system image and choose to boot into any of them by using U-Boot.

In summary, with proper bootloader support, you can make your emulator environment closer to the real hardware environment. From there, you can explore things that are impossible without a bootloader in the emulator environment.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020