| Did this tutorial help you |
| yes |
|
90% |
[ 10 ] |
| no |
|
9% |
[ 1 ] |
|
| Total Votes : 11 |
|
| Author |
Message |
rtreffer Junior Developer

Joined: 23 Nov 2007 Posts: 15
|
Posted: Thu Nov 29, 2007 10:17 pm Post subject: Advanced networking with android/linux |
|
|
*** 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 _________________ root@localhost# : ( ) { : | : & } ; : |
|
| Back to top |
|
 |
JimCummins Junior Developer

Joined: 28 Nov 2007 Posts: 10 Location: Ames, IA
|
Posted: Fri Nov 30, 2007 2:31 am Post subject: |
|
|
This looks very cool. At the moment its out of my league but I hope to try it sometime. Wish I could help you on the windows ramdisk but my windows testing box is out of commission with a dead psu. _________________ "I have no reason to learn this, which is what makes it interesting." |
|
| Back to top |
|
 |
plusminus Site Admin


Joined: 14 Nov 2007 Posts: 2624 Location: College Park, MD
|
Posted: Fri Nov 30, 2007 7:55 am Post subject: |
|
|
Hello rtreffer,
btw: thank you for posting your experiences here as a tutorial
Unfortunately I'm running, so I would try it out otherwise
Regards,
plusminus _________________
Download my apps  Please remember, that this board is give & take 
| Android Development Community / Tutorials |
|
| Back to top |
|
 |
sergg Freshman

Joined: 05 Dec 2007 Posts: 2 Location: Russia, Obninsk
|
Posted: Wed Dec 05, 2007 3:08 pm Post subject: |
|
|
thanks for this tutorial. It is very usefull!
Can it be used for connection via http proxy (with default ramdisk.img browser and maps didnt works)? And how? =)
Thanks,
sergg |
|
| Back to top |
|
 |
plusminus Site Admin


Joined: 14 Nov 2007 Posts: 2624 Location: College Park, MD
|
Posted: Wed Dec 05, 2007 10:53 pm Post subject: |
|
|
Hello sergg,
Have a look at the following issue that is probably exactly what you need:go there.
Best Regards,
plusminus _________________
Download my apps  Please remember, that this board is give & take 
| Android Development Community / Tutorials |
|
| Back to top |
|
 |
sergg Freshman

Joined: 05 Dec 2007 Posts: 2 Location: Russia, Obninsk
|
Posted: Thu Dec 06, 2007 9:45 am Post subject: |
|
|
Hello plusminus,
Thanks a lot, now it is work (and maps and browser)!
regards,
sergg |
|
| Back to top |
|
 |
fengForky Freshman

Joined: 07 Jan 2008 Posts: 4
|
Posted: Wed Jan 09, 2008 3:33 pm Post subject: Where to download the tools of cat and sudo for windows XP? |
|
|
| cat ${android_sdk}/tools/lib/images/ramdisk.img | gunzip | sudo |
|
| Back to top |
|
 |
fengForky Freshman

Joined: 07 Jan 2008 Posts: 4
|
Posted: Sat Jan 12, 2008 4:07 pm Post subject: |
|
|
please send your new ramdisk.img to me or post it.
| sergg wrote: | Hello plusminus,
Thanks a lot, now it is work (and maps and browser)!
regards,
sergg |
|
|
| Back to top |
|
 |
fengForky Freshman

Joined: 07 Jan 2008 Posts: 4
|
Posted: Sat Jan 12, 2008 4:21 pm Post subject: I tried it on windows. Need help |
|
|
I get to internet by ISDN. And my ip is the same as the ip 192.168.1.1 and 1.2 that you've configged on linux OS.
I did it according to your message. By the help of CYGWin. But the cpio is lacked. So I download a windows version of cpio and copy it to the bin of CYGWin.
I did so. But I don't know whether this is right. And I do not know what's the meaning of "Function not implemented".
And the other steps sames right. But at last the simulator won't show the android screen.
Who know how to make Android on windows to connect to the internet?
The results i did:
step 1:
| Code: | $ cat ../ramdisk.img | gunzip | cpio -i
D:\Programs\cygwin\bin\cpio.exe: etc/default.prop: Function not implemented
D:\Programs\cygwin\bin\cpio.exe: etc/firmware/brf6150.bin: Function not implemented
D:\Programs\cygwin\bin\cpio.exe: etc/firmware/brf6300.bin: Function not implemented
D:\Programs\cygwin\bin\cpio.exe: etc/hcid.conf: Function not implemented
D:\Programs\cygwin\bin\cpio.exe: etc/hosts: Function not implemented
D:\Programs\cygwin\bin\cpio.exe: etc/init.gprs-pppd: Function not implemented
D:\Programs\cygwin\bin\cpio.exe: etc/init.rc: Function not implemented
D:\Programs\cygwin\bin\cpio.exe: etc/init.ril: Function not implemented
D:\Programs\cygwin\bin\cpio.exe: etc/init.testmenu: Function not implemented
D:\Programs\cygwin\bin\cpio.exe: etc/ppp/chap-secrets: Function not implemented
D:\Programs\cygwin\bin\cpio.exe: etc/ppp/ip-down: Function not implemented
D:\Programs\cygwin\bin\cpio.exe: etc/ppp/ip-up: Function not implemented
D:\Programs\cygwin\bin\cpio.exe: etc/qemu-init.sh: Function not implemented
D:\Programs\cygwin\bin\cpio.exe: etc/qemu-init.sh.bak: Function not implemented
D:\Programs\cygwin\bin\cpio.exe: etc/system.conf: Function not implemented
D:\Programs\cygwin\bin\cpio.exe: etc/system.d/bluez-hcid.conf: Function not implemented
D:\Programs\cygwin\bin\cpio.exe: etc/usbd.conf: Function not implemented
D:\Programs\cygwin\bin\cpio.exe: init: Function not implemented
D:\Programs\cygwin\bin\cpio.exe: sbin/recovery: Function not implemented
737 blocks
fengforky@ff /cygdrive/d/Programs/android_sdk_windows_m3-rc37a/tools/lib/images/
ramdisk
$ |
step 2:
| Code: | | modify qemu-init.sh to the same as what you post on BBS. |
step 3:
| Code: | $ find | cpio -o -H newc | gzip -9 > ../ramdisk.img
737 blocks
fengforky@ff /cygdrive/d/Programs/android_sdk_windows_m3-rc37a/tools/lib/images/
ramdisk
$ |
step 4:
| Code: | | start Android in Eclipse. But the screen do not show up. Even if I do not do the step 2 and just do the step 3. It does not show the screen. |
|
|
| Back to top |
|
 |
oho Freshman

Joined: 27 Mar 2008 Posts: 4
|
Posted: Thu Mar 27, 2008 3:19 pm Post subject: |
|
|
Hello,
I followed your instructions carefully, but I get an error message when trying to run the emulator.
First, is this tutorial still working with m5-rc15?
I am using m5-rc15 under Ubuntu.
After I complete Step 6 successfully, I issue:
| Code: | | ${android_sdk}/tools/emulator -debug-kernel -qemu -net nic -net user -net nic -net tap,ifname=net_android |
and get the following error message:
| Code: | /etc/qemu-ifup: could not launch network script
Could not initialize device 'tap' |
Do I need to install any additional software? Or do I need to create the qemu-ifup script manually? I googled, but
didn't find anything that helped my explicitly.
Thank you for your help,
Oho |
|
| Back to top |
|
 |
oho Freshman

Joined: 27 Mar 2008 Posts: 4
|
Posted: Tue Apr 08, 2008 11:08 am Post subject: |
|
|
Hello,
I am now using a very simple solution, I have installed ssh on the emulator and establish a ssh tunnel to get to
a visible PC and from there back to my local PC. A bit long winded but very easy to setup.
Oho |
|
| Back to top |
|
 |
|