安卓内核源码编译

http://stackoverflow.com/questions/1809774/android-kernel-compile-and-test-with-android-emulator

http://stackoverflow.com/questions/1809774/android-kernel-compile-and-test-with-android-emulator


http://blog.csdn.net/flydream0/article/details/7070392

http://blog.csdn.net/flydream0/article/details/7070392



Has anyone successfully compiled the android kernel and tested it in the Android emulator, and if so is there anything that special that needs to be done?

Documentation for the SDK is excellent, however documentation for compiling the kernel and setting up a custom machine in the emulator has been hard for me to find.

link | improve this question
 
3 
Wow, a development team account :) –  Nathan Campos Nov 27 '09 at 17:00
feedback

7 Answers

up vote 25 down vote accepted

Since August 2009 the kernel is no longer part of the standard repo manifest that you get when you follow the instructions to download the source code for the android open source project. The steps that are needed to successfully download, build and run a specific kernel on the emulator are as follows:

  • Get the Android kernel either by adding it to your repo manifest or manually by running:
    git clone https://android.googlesource.com/kernel/goldfish.git
  • Check out the correct branch for working with the emulator, i.e. goldfish:
    git checkout -t origin/android-goldfish-2.6.29 -b goldfish
  • Generate the emulator configuration (qemu emulator runs arm code, i.e. an arm config):
    make ARCH=arm goldfish_defconfig
  • Now build the kernel using the cross compilation tools distributed with the open source project:
    make ARCH=arm CROSS_COMPILE=mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi-
  • The kernel built this way should end up in the arch/arm/boot folder of your kernel tree (where you put the code from git clone)
  • To run the emulator with your kernel there are two alternatives, either copy it to the prebuilt kernel folder of the open source project to replace the standard kernel. The other option is to start the emulator with the kernel option set:
    emulator -kernel mydroid/kernel/common/arch/arm/boot/zImage

Note that I have used the default paths in the above description, you need to change them to what applies to your setup. It has been a some time since last time I tested this but I think it should work.

Some extra information:In the standard Android open source distribution the kernel is distributed as a pre-built binary in themydroid/prebuilt/android-arm/kernel folder and the source code is not included. The kernel source was removed from the default manifest for two reasons as I take it. One is that it takes a lot of bandwith and diskspace for a platform component that most people will not work with much. The other reason is that since the kernel is built with the kernel build system and not as part of the aosp build system it makes sense to keep it separated. The common branch for the kernel is the one used by the emulator. There are also branches for experimental, msm (Qualcomm platforms) and Omap (TI platform) and maybe some more. If you want to use the Android kernel with hardware these may be more interesting to you.

link | improve this answer
 
1 
Thanks for the additional info! Seeing as most of the Android documentation is in the form of google groups discussions, posts such as this are quite helpful. –  Mr. Shickadance Jun 15 '10 at 15:50
 
when i am trying to download kernel source , it giving me following erro : "android.git.kernel.org[0: 149.20.4.77]: errno=Connection refusedfatal: unable to connect a socket (Connection refused"can u suggest me alternative path to download source. –  Shubh Feb 4 at 9:55
 
The location of the emulator kernel changed with the move to android.googlesource.com after the kernel.org downtime. I have updated the post to be correct. –  BMB Feb 4 at 22:06
feedback

Just to correct a few things from BMB's post (which was very useful to me, it saved my project) :

  • git clone git://android.git.kernel.org/kernel/common.git (the kernel missed) ;
  • git checkout -t origin/android-goldfish-2.6.29 -b goldfish (the same) ;
  • make ARCH=arm goldfish_defconfig (idem) ;
  • make ARCH=arm CROSS_COMPILE=mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi- (idem)
  • emulator -avd my_avd -kernel mydroid/kernel/common/arch/arm/boot/zImage (here I added anavd in the command, it didn't work without for me).

Hope I'm right and this could be useful to someone :)
Good luck !
Arnaud LM

link | improve this answer
 
2 
Thanks for the extra info. I edited my post to include the correct kernel path, sry about that. –  BMB Jul 22 '10 at 22:07
feedback

This is an update for BMB and Arnaud LM's answers.
It seems the goldfish branchnames were changed as of 2011/03/03. When checking out the goldfish branch, use this:

git checkout -t origin/archive/android-gldfish-2.6.29 -b goldfish 

Note the missing 'o' in android-gldfish-2.6.29!

Hope this saves time for somebody.

link | improve this answer
 
+1 It certainly did! –  pehrs May 2 '11 at 15:00
feedback

That's easy. Follow the instructions at http://source.android.com/download for getting and compiling the source code for the whole android. That takes a while, but isn't that complicated.

By building that, you'll have you're output in the <android>/out directory. That includes, besides the ROM images, a bunch of tools too, including the emulator. My emulator is at<android>/out/host/linux-x86/bin/emulator. Just set an environment variable namedANDROID_PRODUCT_OUT to <android>/out/target/product/generic, and then running the emulator without any options will run your compiled ROM.

link | improve this answer
 
Were not looking to compile the emulator, were specifically looking to compile the android kernel and to take that compiled image and run it within the emulator. –  Zyris Development Team Nov 29 '09 at 11:52
 
That's the way to run the compiled image of the Android source code. I'm doing this everyday. You just compile the Android source code and you'll have an emulator to run it. –  Mostafa Nov 29 '09 at 12:12
2 
As we said above, were not looking to compile the source code for the emulator. Were looking to compile the ANDROID KERNEL (android.git.kernel.org) –  Zyris Development Team Nov 29 '09 at 14:39
 
This answer helped me anyway :) –  jeong Jan 3 '11 at 5:26
feedback

That is a very detailed tutorial about how to download the code, compile your kernel and run it in the emulator:

http://linuxclues.blogspot.com/2010/05/build-compile-linux-kernel-android.html

link | improve this answer
 
feedback

If you are interested, I did a howto on the topic since I personally ran into some problems.

http://blog.eeknay.net/2012/03/02/android-kernel/

link | improve this answer
 
feedback

The way I was able to boot the AOSP rom I compiled was to copy the system.img that got compiled to ~/.android/avd/Froyo.avd/But, when I extract the system.img and add the rooted version of su and busybox, then remake the system.img, the emulator does not boot. I'm still trying to figure that part out :S

link | improve this answer
 
feedback


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值