Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3170799
  • 博文数量: 685
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 5303
  • 用 户 组: 普通用户
  • 注册时间: 2014-04-19 14:17
个人简介

文章分类

全部博文(685)

文章存档

2015年(116)

2014年(569)

分类: 嵌入式

2014-09-29 09:35:50

原文地址:http://blog.csdn.net/white_eyes/article/details/8191047

Android模拟器默认内核不支持netfilter,所以试图使用iptalbes时,会出现错误。


  1. # iptables -L
  2. iptables -L
  3. iptables v1.3.7: can't initialize iptables table `filter': iptables who? (do you need to insmod?)
  4. Perhaps iptables or your kernel needs to be upgraded.
  5. #
# iptables -L
iptables -L
iptables v1.3.7: can't initialize iptables table `filter': iptables who? (do you need to insmod?)
Perhaps iptables or your kernel needs to be upgraded.
#

解决方法是重新编译一个android内核,编译的时候打开netfilter相关模块,用新内核替换原有内核即可。



实验环境:ubuntu10.04 64bit




下载适用模拟器的android内核代码


  1. root@ubuntu:~/android/kernel# git clone
  2. Initialized empty Git repository in /home/shanks/android/kernel/goldfish/.git/
  3. remote: Counting objects: 28280, done
  4. remote: Finding sources: 100% (6/6)
  5. remote: Getting sizes: 100% (5/5)
  6. remote: Compressing objects: 100% (5/5)
  7. Receiving objects: 100% (2442118/2442118), 499.20 MiB | 772 KiB/s, done.
  8. remote: Total 2442118 (delta 2048586), reused 2442116 (delta 2048586)
  9. Resolving deltas: 100% (2048602/2048602), done.
root@ubuntu:~/android/kernel# git clone 
Initialized empty Git repository in /home/shanks/android/kernel/goldfish/.git/
remote: Counting objects: 28280, done
remote: Finding sources: 100% (6/6)
remote: Getting sizes: 100% (5/5)
remote: Compressing objects: 100% (5/5)
Receiving objects: 100% (2442118/2442118), 499.20 MiB | 772 KiB/s, done.
remote: Total 2442118 (delta 2048586), reused 2442116 (delta 2048586)
Resolving deltas: 100% (2048602/2048602), done.

查看可用版本



  1. root@ubuntu:~/android/kernel/goldfish# git branch -a
  2. * master
  3. remotes/origin/HEAD -> origin/master
  4. remotes/origin/android-goldfish-2.6.29
  5. remotes/origin/android-goldfish-3.4
  6. remotes/origin/linux-goldfish-3.0-wip
  7. remotes/origin/master
root@ubuntu:~/android/kernel/goldfish# git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/android-goldfish-2.6.29
  remotes/origin/android-goldfish-3.4
  remotes/origin/linux-goldfish-3.0-wip
  remotes/origin/master

下载2.6.29版本。



  1. root@ubuntu:~/android/kernel/goldfish# git checkout remotes/origin/android-goldfish-2.6.29
  2. Checking out files: 100% (26821/26821), done.
  3. Note: checking out 'remotes/origin/android-goldfish-2.6.29'.
root@ubuntu:~/android/kernel/goldfish# git checkout remotes/origin/android-goldfish-2.6.29
Checking out files: 100% (26821/26821), done.
Note: checking out 'remotes/origin/android-goldfish-2.6.29'.

下载完成后,设置编译所需环境变量。



  1. root@ubuntu:~/android/kernel/goldfish# export ARCH=arm
  2. root@ubuntu:~/android/kernel/goldfish# export SUBARCH=arm
  3. root@ubuntu:~/android/kernel/goldfish# export CROSS_COMPILE=arm-eabi-
  4. root@ubuntu:~/android/kernel/goldfish# export PATH=/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin:$PATH
root@ubuntu:~/android/kernel/goldfish# export ARCH=arm
root@ubuntu:~/android/kernel/goldfish# export SUBARCH=arm
root@ubuntu:~/android/kernel/goldfish# export CROSS_COMPILE=arm-eabi-
root@ubuntu:~/android/kernel/goldfish# export PATH=/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin:$PATH

运行make


  1. make goldfish_defconfig
make goldfish_defconfig

接下来配置编译的模块,这个过程可能会报缺少一些必要的包,可以提前安装相关的包,也可以根据错误逐步添加。


  1. root@ubuntu:~/android/kernel/goldfish# apt-get install ia32-libs
root@ubuntu:~/android/kernel/goldfish# apt-get install ia32-libs

下面是实验过程记录。



  1. root@ubuntu:~/android/kernel/goldfish# make menuconfig
  2. *** Unable to find the ncurses libraries or the
  3. *** required header files.
  4. *** 'make menuconfig' requires the ncurses libraries.
  5. ***
  6. *** Install ncurses (ncurses-devel) and try again.
  7. ***
  8. make[1]: *** [scripts/kconfig/dochecklxdialog] Error 1
  9. make: *** [menuconfig] Error 2
  10. root@ubuntu:~/android/kernel/goldfish# apt-get install libncurses-dev
  11. Reading package lists... Done
  12. Building dependency tree
  13. Reading state information... Done
root@ubuntu:~/android/kernel/goldfish# make menuconfig
 *** Unable to find the ncurses libraries or the
 *** required header files.
 *** 'make menuconfig' requires the ncurses libraries.
 *** 
 *** Install ncurses (ncurses-devel) and try again.
 *** 
make[1]: *** [scripts/kconfig/dochecklxdialog] Error 1
make: *** [menuconfig] Error 2


root@ubuntu:~/android/kernel/goldfish# apt-get install libncurses-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done

再运行make menuconfig,选择相关模块。


配置完成后,进行编译


  1. root@ubuntu:~/android/kernel/goldfish# make -j4
  2. make: arm-eabi-gcc: Command not found
  3. CHK include/linux/version.h
  4. make[1]: `include/asm-arm/mach-types.h' is up to date.
  5. CHK include/linux/utsrelease.h
  6. SYMLINK include/asm -> include/asm-arm
  7. CC scripts/mod/empty.o
  8. /bin/sh: arm-eabi-gcc: not found
  9. make[2]: *** [scripts/mod/empty.o] Error 127
  10. make[1]: *** [scripts/mod] Error 2
  11. make: *** [scripts] Error 2
  12. root@ubuntu:~/android/kernel/goldfish# apt-get install lib32ncurses5-dev
  13. root@ubuntu:~/android/kernel/goldfish# make -j4
  14. CHK include/linux/version.h
  15. SYMLINK include/asm -> include/asm-arm
  16. make[1]: `include/asm-arm/mach-types.h' is up to date.
  17. CHK include/linux/utsrelease.h
  18. CC scripts/mod/empty.o
  19. .../prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/arm-eabi/4.4.3/../../../../arm-eabi/bin/as: error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory
  20. make[2]: *** [scripts/mod/empty.o] Error 1
  21. make[1]: *** [scripts/mod] Error 2
  22. make: *** [scripts] Error 2
  23. root@ubuntu:~/android/kernel/goldfish# apt-get install ia32-libs
  24. OBJCOPY arch/arm/boot/zImage
  25. Kernel: arch/arm/boot/zImage is ready
root@ubuntu:~/android/kernel/goldfish# make -j4
make: arm-eabi-gcc: Command not found
  CHK     include/linux/version.h
make[1]: `include/asm-arm/mach-types.h' is up to date.
  CHK     include/linux/utsrelease.h
  SYMLINK include/asm -> include/asm-arm
  CC      scripts/mod/empty.o
/bin/sh: arm-eabi-gcc: not found
make[2]: *** [scripts/mod/empty.o] Error 127
make[1]: *** [scripts/mod] Error 2
make: *** [scripts] Error 2

root@ubuntu:~/android/kernel/goldfish# apt-get install lib32ncurses5-dev

root@ubuntu:~/android/kernel/goldfish# make -j4
  CHK     include/linux/version.h
  SYMLINK include/asm -> include/asm-arm
make[1]: `include/asm-arm/mach-types.h' is up to date.
  CHK     include/linux/utsrelease.h
  CC      scripts/mod/empty.o
.../prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/arm-eabi/4.4.3/../../../../arm-eabi/bin/as: error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory
make[2]: *** [scripts/mod/empty.o] Error 1
make[1]: *** [scripts/mod] Error 2
make: *** [scripts] Error 2
root@ubuntu:~/android/kernel/goldfish# apt-get install ia32-libs


  OBJCOPY arch/arm/boot/zImage
  Kernel: arch/arm/boot/zImage is ready

编译完成后,使用新内核运行模拟器。



  1. ...\tools>emulator.exe -avd CM2.3 -kernel ....\zImage -show-kernel -no-snapshot
  2. serial0 console
  3. Uncompressing Linux......................................................... done, booting the kernel.
  4. Initializing cgroup subsys cpu
  5. Linux version 2.6.29-gcb06bef (root@ubuntu) (gcc version 4.4.3 (GCC) ) #1 Thu Nov 8 01:35:29 PST 2012
  6. CPU: ARM926EJ-S [41069265] revision 5 (ARMv5TEJ), cr=00093177
  7. CPU: VIVT data cache, VIVT instruction cache
...\tools>emulator.exe -avd CM2.3 -kernel ....\zImage -show-kernel -no-snapshot
serial0 console
Uncompressing Linux......................................................... done, booting the kernel.
Initializing cgroup subsys cpu
Linux version 2.6.29-gcb06bef (root@ubuntu) (gcc version 4.4.3 (GCC) ) #1 Thu Nov 8 01:35:29 PST 2012
CPU: ARM926EJ-S [41069265] revision 5 (ARMv5TEJ), cr=00093177
CPU: VIVT data cache, VIVT instruction cache  
问题得以解决




参考:

http://blog.csdn.net/fdl19881/article/details/7467129



阅读(3329) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~