포럼 회원으로 등록하신분만 다운로드가 가능합니다. 최대 업로드 가능한 용량은 20MB 입니다.

*** Warnings ***

linux as host os is required, windows might be possible but is untested
You can easily destroy your emulator. Backup your emulator
Root access required


Preface

${android_sdk} refers to your android sdk root folder

Your emulator consists of three images:
  • ${android_sdk}/tools/lib/images/ramdisk.img (cpio[cnew] archive, gzip compressed)
  • ${android_sdk}/tools/lib/images/system.img (yaffs2 formated)
  • ${android_sdk}/tools/lib/images/userdata.img (yaffs2 formated)

By now noone has managed to mounting the yaffs2 formated partitions. Loopback mounting does not work. So for now the best way to hack the emulator is ${android_sdk}/tools/lib/images/ramdisk.img

Step 0 - backup
Code:
cp ${android_sdk}/tools/lib/images/ramdisk.img ${android_sdk}/tools/lib/images/ramdisk.img.old


Step 1 - extracting the ramdisk
Code:
mkdir ramdisk
cd ramdisk
cat ${android_sdk}/tools/lib/images/ramdisk.img | gunzip | sudo cpio -i

This will populate "ramdisk" with the ramdisks content.

Step 2 - looking at a simple boot skript
Android requires some special code to boot in the emulator, the code can be found in etc/qemu-init.sh
Code:
sudo vim etc/qemu-init.sh

Here is the original content:
Code:
#!/system/bin/sh

# Some special case stuff for running under emulation
qemu=`getprop ro.kernel.qemu`
case "$qemu" in
    "1" )
    ifconfig eth0 10.0.2.15 netmask 255.255.255.0 up
    route add default gw 10.0.2.2 dev eth0
    radio_ril=`getprop ro.kernel.android.ril`
    case "$radio_ril" in
        ttyS*) # a modem is emulated as a serial device
            ;;
        *) # no need for the radio interface daemon
            # telephony is entirely emulated in Java
            setprop ro.radio.noril yes
            stop ril-daemon
            ;;
    esac
    setprop net.eth0.dns1 10.0.2.3
    setprop net.gprs.local-ip 10.0.2.15
    setprop ro.radio.use-ppp no
    setprop ro.config.nocheckin yes
    setprop status.battery.state Slow
    setprop status.battery.level 5
    setprop status.battery.level_raw  50
    setprop status.battery.level_scale 9
    stop dund
    stop usbd
    ;;
esac


Step 3 - the target networking environment
Android is hardcoded to use 10.0.2.3 and 10.0.2.2 for comunication - especially with adb. You can not use anything except this userspace emulation for eth0.
Android
  • device: eth0, ip: 10.0.2.15, net: 10.0.2.0/255.255.255.0 - this will keep adb happy
  • device: eth1, ip: 192.168.1.2, net: 192.168.1.0/255.255.255.0 - this will be used for real communication
  • default gateway: 192.168.1.1 - or whatever suits your network
  • DNS: 10.0.2.3 - we simply keep this, no disadvantages except harder debugging

Host
  • net_android, virtual android network device
  • br0, network bridge linking eth0 and net_android

Depending on what you want to test you might want to turn your host system into a nat gateway, a dhcp server, transparent proxy, routing gateway or whatever you need.

Step 4 - altering the android network
Code:
#!/system/bin/sh

# Some special case stuff for running under emulation
qemu=`getprop ro.kernel.qemu`
case "$qemu" in
    "1" )

    if ifconfig eth1 up; then
        ifconfig eth1 down
        # Should we really check for eth1 that way?

        # DHCP - broken?
        # netcfg eth1 dhcp

        ifconfig eth1 192.168.1.2 netmask 255.255.255.0 up
        route add default gw 192.168.1.1 dev eth1

        ifconfig eth0 10.0.2.15 netmask 255.255.255.0 up

        setprop net.eth0.dns1 10.0.2.3
        setprop net.eth1.dns1 10.0.2.3
        setprop net.gprs.local-ip 192.168.1.2
    else
        ifconfig eth0 10.0.2.15 netmask 255.255.255.0 up
        route add default gw 10.0.2.2 dev eth0
        setprop net.eth0.dns1 10.0.2.3
        setprop net.gprs.local-ip 10.0.2.15
    fi

    # Proxy support - broken too?
    # setprop net.gprs.http-proxy http://proxy:8080/

    # No longer needed
    # ifconfig eth0 10.0.2.15 netmask 255.255.255.0 up
    # route add default gw 10.0.2.2 dev eth0
    radio_ril=`getprop ro.kernel.android.ril`
    case "$radio_ril" in
        ttyS*) # a modem is emulated as a serial device
            ;;
        *) # no need for the radio interface daemon
            # telephony is entirely emulated in Java
            setprop ro.radio.noril yes
            stop ril-daemon
            ;;
    esac
    # no longer needed
    # setprop net.eth0.dns1 10.0.2.3
    # setprop net.gprs.local-ip 10.0.2.15
    setprop ro.radio.use-ppp no
    setprop ro.config.nocheckin yes
    setprop status.battery.state Slow
# Interresting - is this the way to check battery status?
    setprop status.battery.level 5
    setprop status.battery.level_raw  50
    setprop status.battery.level_scale 9
    stop dund
    stop usbd
    ;;
esac

This will keep your classic config if eth1 doesn't exist and if it exists adb will still work.

Step 5 - packing your new ramdisk
Code:
 sudo find | sudo cpio -o -H newc | gzip -9 > ${android_sdk}/tools/lib/images/ramdisk.img


Step 6 - Host configuration
Code:
sudo brctl addbr br0
sudo tunctl -u $USER -t net_android
sudo ifconfig eth0 0.0.0.0 promisc up
sudo ifconfig net_android 0.0.0.0 promisc up
sudo brctl addif br0 eth0
sudo brctl addif br0 net_android
sudo dhclient3 br0

Depending on you sodu configuration you might need to substitute $USER with your username. Depending on your local network you might need to substitute sudo dhclient3 br0 with your normal network initialization.

Step 7 - boot and test
Code:
${android_sdk}/tools/emulator -debug-kernel -qemu -net nic -net user -net nic -net tap,ifname=net_android

Now on your host system do
Code:
ping 192.168.2.2
adb shell

If everything went well both commands will work.

Enjoy!

TODO1: Tutorial how to use the new network link from within dalvik.
TODO2: Find a windows user who will try the ramdisk with windows and openvpn/tun/tap driver


http://www.anddev.org/advanced_networking_with_android-linux-t155.html
profile

인생은 연극이고 세상은 무대이다!

이솝 임베디드 포럼 운영 및 비즈니스와 관련된 것 이외에 E-Mail이나 메신저 및 휴대폰 등을 통한 개인적인 질문 및 답변은 받지 않습니다. 문의 사항은 이솝 임베디드 포럼 게시판을 이용해 주시면 감사하겠습니다.

엮인글 :
http://www.aesop.or.kr/index.php?mid=Board_Documents_Android_Frameworks&document_srl=34648&act=trackback&key=128

고현철

2009.04.21 23:04:59
*.32.117.22

안드로이드 부티되고 나서는 netcfg 명령이 ifconfig랑 비슷하더군요....
List of Articles
번호 제목 글쓴이 날짜 조회 수sort
84 Android 2.3 GingerBread Multimedia Framework 분석 - 1 [26] 고도리 2011-05-23 56037
83 [안드로이드 책] Input관련 간단자료 및 PhoneWindowManager 연동 file [2] 고도리 2011-08-02 52411
82 [Android 분석 및 포팅] Binder의 동작원리 - #2 IPC/RPC file 고도리 2011-06-30 40886
81 Android Initialization Process 최종환 2009-04-09 24638
80 OpenGL ES와 Android [3] 이제현 2009-04-18 22839
79 [참고] Android wifi howto - 아직 테스트는 다 못했습니다. file [10] 고도리 2009-09-22 21723
78 Android용 root filesystem으로 cramfs 구성 할 때의 주의사항 [7] 김영문 2009-04-09 21375
» Android에서의 Linux Network 환경 설정 방법 [1] 김재훈 2009-04-21 20515
76 S3C6410 target으로의 Android porting에 대하여(1) [3] 고현철 2009-04-23 20133
75 [번역] Android Camera Framework 번역 file [7] 고도리 2009-09-10 19665
74 Android make옵션 [3] 2009-07-16 19464
73 Android 2.x AudioFlinger와 HAL의 연결 구조 분석 [2] JhoonKim 2010-04-08 19343
72 Android Debug Bridge(ADB) 사용 가이드 김재훈 2009-04-09 18864
71 Android audioflinger 분석자료 입니다. file [11] 고현철 2009-07-30 18819
70 android를 6410에 포팅하면서... [7] 전병환 2009-04-10 18227
69 PV와 Android [5] 이제현 2009-04-19 18163
68 [번역] Android Opencore Multimedia Framework 번역본 file [7] 고도리 2009-08-25 17636
67 Android 윈도우에서 git로 소스 받기.. [3] 2009-07-14 17021
66 Android 부팅 및 초기화 절차 김재훈 2009-04-09 17000
65 Android OpenCore 모임추진 ? [8] 장석원 2009-08-07 16001

사용자 로그인