ZYNQ petalinux设置自动获取永久IP
ZYNQ petalinux设置自动获取永久IP
情形:zynq petalinux在开机自启动以后ifconfig设置ip,然后运行应用程序,如果程序运行过程中挂掉,在系统自启动系统
/project-spec/meta-user/recipes-apps/startupip/files目录下的文件设置果的IP 或者自启动脚本中设置的IP 都会消失,然后再也ping不通了,为了解决这个问题只能重新上电运行,如果设备在很远的地方或者不容易进入的地方就会很不方便,解决办法如下
方法一:将IP编译到系统
1,cd 到项目工程目录下,运行命令:petalinux-config或者直接在petalinux-config --get-hw-description ../linux_base.sdk的时候,
依次选择 Subsystem AUTO Hardware Settings
2,依次选择-> Ethernet Settings
3,依次在-> Obtain IP address automatically -> Enter输入 "N",需要修改的固定MAC,IP地址,网关,子网掩码可以从这里设置,系统启动以后就会是这个固定IP。
4,然后保存配置并退出,编译生成启动文件petalinux-build。
方法二:设置两个脚本并并设置优先级
1,cd ,也就是ax_peta里面,创建两个shell脚本文件的app工程
petalinux-create -t apps --template install -n startupip --enable
petalinux-create -t apps --template install -n startupzk --enable
2,(1)将文件中文中startupip.bb中的startup全都改为startupip
(2)将文件中文中startupip.bb中的startup全都改为startupzk,同时将start 99 S改为start 98 S
96-99数字越低,优先级越高。linux有7个运行级别,用户可选择不同的运行级别。进入/etc/rc.d/目录,可查看到对应从rc0.d到rc6.d等7个目录,这些目录即对应7个级别。
3,在文件目录project-spec/meta-user/recipes-apps/startupip/files中的.bb文件,
shell脚本工程相关的内容如下,如果优先级都是99就不区分分别都要挂载。
此处zk .sh优先级高,原则上不用再挂载了,但是为了保险起见,还是重复挂载了一次。
#!/bin/sh
echo "~~~~~~~~~~startupip~~~~~~~~"
mount /dev/mmcblk1p1 /mnt/
cd /mnt
./ip.sh
#!/bin/sh
echo "~~~~~~~~~~startupzk~~~~~~~~"
mount /dev/mmcblk1p1 /mnt/
cd /mnt
./zk.sh
4,(1)ip.sh中,在末尾加上死循环,即使开机自启动退出了也可以继续保留IP
#!/bin/sh
ifconfig eth0 down
ifconfig eth0 hw ether 00:0A:35:00:1E:55
ifconfig eth0 down
ifconfig eth0 172.27.226.243 netmask 255.255.255.0
route add default gw 172.27.226.254
ifconfig eth0 up
while true
do
sleep 5
done
(2)在zk.sh中加入后台自动运行
#!/bin/sh
cp libtmControlClient.so /lib/
./maincontrol &
ZYNQ petalinux设置自动获取永久IP相关教程