第33节:串口编程之开机启动运行
1、使用已经编译好的helloworld.c的程序进行实现开机启动运行。
代码如下:
#include<stdio.h>
main()
{
printf("Hello World!\n");
}
2、挂载U盘并查看文件是否存在并执行hello是否能执行 。
[root@iTOP-4412]# mount /dev/mmcblk1p1 /mnt
[root@iTOP-4412]# cd /mnt
[root@iTOP-4412]# ls
System Volume Information hello hello.c
[root@iTOP-4412]# ./hello Hello World!
3、将hello文件拷贝到/bin下,并查看是否拷贝成功
[root@iTOP-4412]# cp -rp hello /bin
[root@iTOP-4412]# ls -l /bin/hello
-rwxr-xr-x 1 root 0 648462 Feb 17 2018 /bin/hello
4、让hello文件在开机状态下启动。
[root@iTOP-4412]# vi /etc/init.d/rcS
#echo "*************************************" > /dev/ttySAC2
#echo " http://www.topeet.com.cn " > /dev/ttySAC2
#echo "*************************************" > /dev/ttySAC2
#echo "*************************************"
#echo " http://www.topeet.com.cn "
#echo "*************************************"
/sbin/ifconfig lo 127.0.0.1
/etc/init.d/ifconfig-eth0
/bin/hello &
注意:在最尾巴加入/bin/hello &
5、重新启动看开机信息
Please press Enter to activate this console. Hello World!
6、另一种方法是在编译最小系统时写入hello程序也是可以的。
1、使用已经编译好的helloworld.c的程序进行实现开机启动运行。
代码如下:
#include<stdio.h>
main()
{
printf("Hello World!\n");
}
2、挂载U盘并查看文件是否存在并执行hello是否能执行 。
[root@iTOP-4412]# mount /dev/mmcblk1p1 /mnt
[root@iTOP-4412]# cd /mnt
[root@iTOP-4412]# ls
System Volume Information hello hello.c
[root@iTOP-4412]# ./hello Hello World!
3、将hello文件拷贝到/bin下,并查看是否拷贝成功
[root@iTOP-4412]# cp -rp hello /bin
[root@iTOP-4412]# ls -l /bin/hello
-rwxr-xr-x 1 root 0 648462 Feb 17 2018 /bin/hello
4、让hello文件在开机状态下启动。
[root@iTOP-4412]# vi /etc/init.d/rcS
#echo "*************************************" > /dev/ttySAC2
#echo " http://www.topeet.com.cn " > /dev/ttySAC2
#echo "*************************************" > /dev/ttySAC2
#echo "*************************************"
#echo " http://www.topeet.com.cn "
#echo "*************************************"
mkdir /mnt/disk
sleep 1/sbin/ifconfig lo 127.0.0.1
/etc/init.d/ifconfig-eth0
/bin/hello &
注意:在最尾巴加入/bin/hello &
5、重新启动看开机信息
Please press Enter to activate this console. Hello World!
6、另一种方法是在编译最小系统时写入hello程序也是可以的。