Running a Source-built android image/kernel in the emulator

2,330 views
Skip to first unread message

wsvoorhees

unread,
Nov 21, 2011, 7:32:12 PM11/21/11
to Android Building
My Colleague Adam Bates and I are trying to build Android Operating
System and Kernel from source to explore some Linux Security Modules
(specifically TOMOYO Linux)

-------------Loading Android OS----------------
We have followed the instructions on the http://source.android.com/source/
website with steps:
initializing.html (We used gingerbread)
downloading.html
building.html

After seemingly successful building the android system from source
we've had some difficulty loading it in the emulator, it seems that
the 'emulator' command has not been placed in our path, as a debuging
step I tried:

`source build/envsetup.sh`

which output

including device/htc/passion/vendorsetup.sh
including device/samsung/crespo4g/vendorsetup.sh
including device/samsung/crespo/vendorsetup.sh

but `which emulator` still returned nothing.

We then decided to try and build the sdk, and then use the sdk tools
that it creates (including emulator) which should presumably be able
to run the android operating system image we just built. We issued
`make sdk`.
After which we could find the SDK in:
WORKING_DIRECTORY/out/host/linux-x86/sdk/android-
sdk_eng.voorhees_linux-x86/

running ./tools/android from this directory brings up the android tool
- however if we try and create an AVD from this tool, no target is
available despite the fact that there appears to be a valid target
under the platforms sub-directory.

ls platforms/
android-2.3.7

In fact copying the android-2.3.7 folder into the platforms directory
of the android-sdk downloaded from http://developer.android.com/sdk/index.html
(ensuring that no other platforms exist in this directory)
does work! and we where able to use this image to create an AVD which
we could run in the emulator. If any help could be provided in how to
do this from the SDK we've built, or some clarity as to how else we
should be loading in the android system image that would be
appreciated.

---------Building Android Kernel---------------
As I'm sure you know the android source build environment does not
actually build a kernel from source, instead it includes a pre-built
kernel. Since we're attempting to perform modifications to the kernel
it is necessary for us to build it from source, and boot it with the
image created above in an android emulator.

In order to accomplish this goal we download the android kernel source
from:
https://android.googlesource.com/kernel/common.git

using the 3.0 branch and the 2.6.39 branch.

This ended up not working for the same reasons specified bellow, but
we thought that it might be because those kernel versions seem to be
newer than the kernel that shipped with gingerbread, So we also
tracked down a git repo containing the older branches (no longer
visible in the git repo above)
https://github.com/android/kernel_common.git

In particular we checked out the branch android-gldfish-2.6.29

We needed an appropriate .config for the kernel, we acquired one from
the android system built above by issuing the command
'adb pull /proc/config.gz'

After unziping and renaming the file to .config, we updated the config
to include any new kernel options with the command
export CROSS_COMPILER=WORKING_DIRECTORY/prebuilt/linux-x86/toolchain/
arm-eabi-4.3.1/bin/arm-eabi-
make ARCH=arm CROSS_COMPILER=$CCOMPILER oldconfig

and then built the kernel with
make ARCH=arm CROSS_COMPILER=$CCOMPILER -j8

It appears to have built correctly.

-----------Loading The newly compiled kernel into the Android
Emulator----
It appears that there may be a couple of ways to load in a custom
compiled kernel into the android emulator.
First we tried running the emulator command with the avd created above
with -kernel pointing to the just built kernel. The emulator crashes
on boot.

Then we tried replacing the WORKING_DIRECTORY/prebuilt/android-arm/
kernel/kernel-qemu-armv7 with the kernel we just built, rerunning make/
make sdk and then using the files listed under platforms as described
under the
'Loading Android OS' heading. Unfortunately this also did not work.

---------Questions--------

How should we be loading the Android Image above into the emulator?
Does the method we derived work properly?

How can we get a custom compiled kernel to run in one of these images?

Jean-Baptiste Queru

unread,
Nov 21, 2011, 7:43:46 PM11/21/11
to android-...@googlegroups.com
You probably don't want to bother building the SDK and trying to load
AVDs in there. It's much easier to follow the regular platform
development steps:

source build/envsetup/sh
lunch full-eng
make
emulator&

As for building custom emulator kernels, you'll need to work from
https://android.googlesource.com/kernel/goldfish as the common android
kernel code doesn't include emulator support. Check
external/qemu/docs/ANDROID-KERNEL.txt for more info.

JBQ

> --
> You received this message because you are subscribed to the "Android Building" mailing list.
> To post to this group, send email to android-...@googlegroups.com
> To unsubscribe from this group, send email to
> android-buildi...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-building?hl=en
>

--
Jean-Baptiste M. "JBQ" Queru
Software Engineer, Android Open-Source Project, Google.

Questions sent directly to me that have no reason for being private
will likely get ignored or forwarded to a public forum with no further
warning.

William Voorhees

unread,
Nov 22, 2011, 3:16:04 AM11/22/11
to android-...@googlegroups.com
Thank you very much for your reply! We started fresh on 64bit system because we didn't want that to be an issue, and furthermore a fresh start sounded like a good idea.

-----Building Android Source as recommended -----------

Running 'emulator' in this setup resulting in a black screen, we attributed this result to the problem you describe in this post:

That seems consistent with our need to use the sdk downloaded from google to run the emulator specified in the last post.

We tried following the instructions, but I was a little unclear about how to update qemu we ended up doing: 
cd external/qemu
git checkout tools_r12

and then rebuilding the android source tree with Make.

Afterwards running the emulator with:
emulator -kernel prebuilt/android-arm/kernel/kernel-qemu-armv7 

Worked!

-----Running a kernel compiled from source -----------
As you suggested we downloaded the android kernel from

Please note that we where unable to find 
external/qemu/docs/ANDROID-KERNEL.txt 
we did however find:
external/qemu/docs/KERNEL.txt 
which seemed to discuss the things we are trying to do, we attempted to follow the manual procedure noted in the second half of the document since the rebuild-kernel.sh script doesn't seem to exist, though we suspect
/android-source/external/qemu/distrib/build-kernel.sh is the file being referenced.

We checked out the origin/android-goldfish-2.6.29 branch.

We built it using:
export CCOMPILER=android-source/prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi-
make arch=ARM CROSS_COMPILE=$CCOMPILER goldfish_defconfig
make arch=ARM CROSS_COMPILE=$CCOMPILER -j8

We then try and run the kernel we just built in the emulator:
emulator -kernel  ../goldfish/arch/arm/boot/zImage 
Which launches the emulator with just a black screen
emulator -kernel ../goldfish/vmlinux
Doesn't work either.

-William Voorhees & Adam Bates

Jean-Baptiste Queru

unread,
Nov 22, 2011, 10:20:57 AM11/22/11
to android-...@googlegroups.com
Ah, I missed the point where you said you were using gingerbread.
Emulator support in gingerbread is funky, and while I know how to make
it work with a prebuilt kernel, I don't know how to generate a new
kernel for it.

It's very possible however that you'll need to go back in the history
of the kernel source tree to the point that was used to build the
gingerbread kernel, as it's possible that the ICS kernel (which is the
one you're building) might not be compatible with gingerbread.

JBQ

Reply all
Reply to author
Forward
0 new messages