最近在帮忙调试Android设备marsboard,需求就是开机设置静态IP地址。

调试过程与查找了很多资料,经过两天的测试终于成功了。

首先,init.rc文件最后添加开机自启动:

on property:sys.boot_completed=1    //系统启动完成后会执行以下命令设置静态IP
 /sbin/busybox ifconfig eth0 up
    /sbin/busybox ifconfig eth0 192.168.1.48 netmask 255.255.255.0 up
    /sbin/busybox route add default gw 192.168.1.1 dev eth0
    setprop net.eth0.dns1 218.30.19.40 
    setprop net.eth0.dns2 59.75.42.2

这样启动后,系统本来应该可以设置静态IP的了。可惜init.rc里有这样一个服务:

service dhcpcd_eth0 /system/bin/dhcpcd -ABKL  
    class main
    disabled
    oneshot

这个服务在插拔网线时都会运行一次 /system/bin/dhcpcd,设置动态IP,就这样导致eth0一直没有IP地址。

后面想了个折中的办法,就是修改这个服务:

service dhcpcd_eth0 /system/bin/setStaticIP.sh //把原先的“ /system/bin/dhcpcd -ABKL”改为我们自己的静态IP地址脚本/system/bin/setStaticIP.sh
    class main
    disabled
    oneshot

#on property:sys.boot_completed=1    //系统启动完成后会执行以下命令设置静态IP
#  /sbin/busybox ifconfig eth0 up
#    /sbin/busybox ifconfig eth0 192.168.1.48 netmask 255.255.255.0 up
#    /sbin/busybox route add default gw 192.168.1.1 dev eth0
#    setprop net.eth0.dns1 218.30.19.40 
#    setprop net.eth0.dns2 59.75.42.2

这样自己每次插拔网线就会执行一次我们自己的脚本/system/bin/setStaticIP.sh

记得把脚本setStaticIP.sh放到/system/bin/目录,并且设置好执行权限:chmod 777 /system/bin/setStaticIP.sh

/system/bin/setStaticIP.sh内容如下:

#!/system/bin/sh

# eth0 network setting static ip address
    /sbin/busybox ifconfig eth0 up
    /sbin/busybox ifconfig eth0 192.168.1.48 netmask 255.255.255.0 up
    /sbin/busybox route add default gw 192.168.1.1 dev eth0
    setprop net.eth0.dns1 218.30.19.40 
    setprop net.eth0.dns2 59.75.42.2
    echo "set static ip done"

注意:千万别用windows上编辑器编写setStaticIP.sh,不然会出现no such file。原因就是window编辑后每行都有一个^M结尾的(推荐使用VIM编写,VIM可以看到^M字符)。

我就是因为这样,出现no such file。解决办法:fromdos setStaticIP.sh


调试过程使用过的一些编译命令:

Android比较重要的三个img文件:
make systemimage - system.img
make userdataimage - userdata.img
make ramdisk - ramdisk.img
make snod - 快速打包system.img (with this command, it will build a new system.img very quickly. well, you cannot use “make snod” for all the situations. it would not check the dependences. if you change some code in the framework which will effect other applications)
因為
system.img 是 從 out/target/product/xxxx/system 做出來的。
如果改了 這個 folder 的內容,想要重新產生 system.img。不要管 system folde 裡面的 file 的 dependency,可以用 snod 這個 target:
make snod


调试命令:

start dhcpcd_eth0 //手动运行一次这个服务

stop dhcpcd_eth0 //手工停止这个服务


挂载分区命令:

# mount //查看挂载分区情况和权限

# mount -o remount,rw rootfs /

# mount -o remount,ro /dev/block/mtdblock0 /system 

能否挂载成功,涉及权限问题。init.rc有相关的设置,可以参考以下:

marsboard Android 4.4 添加开机自动设置静态IP地址_第1张图片

marsboard Android 4.4 添加开机自动设置静态IP地址_第2张图片

参考网页:

http://blog.chinaunix.net/uid-24856020-id-3389654.html

http://www.360doc.com/content/11/1213/19/3700464_172018977.shtml

http://www.tuicool.com/articles/Nbu6Bv


更多相关文章

  1. 网上有价值资源地址整理
  2. android 入门学习笔记 判断网页地址 邮箱 电话号码 符合要求的加
  3. android NDK编译.a静态库
  4. 得到email的地址
  5. Android静态安全检测 -> 证书弱校验
  6. android 自动化压力测试-monkey 3 命令参数
  7. so文件静态分析&&Android录屏技术
  8. android cts 命令的说明

随机推荐

  1. android_atomic_dec android_atomic_inc
  2. android中的对话框之二:各种系统对话框的
  3. Android(安卓)px转dip px转sp法则
  4. android 控制软键盘显示和隐藏
  5. Android(安卓)onTouchEvent, onClick及on
  6. Failed to resolve: com.android.support
  7. 关于 android 远程控制(pc 控制手机)
  8. Intent学习
  9. 浅谈Android的BaseAdapter适配器模式
  10. Android开发环境配置之ADT怪异问题