×
单片机 > 单片机程序设计 > 详情

arm-linux之为开发板写上电自启动程序之方法

发布时间:2024-04-20 发布时间:
|

开发环境


开发板:AM335

虚拟机:ubuntu 14.04

编译器:gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf

开发板内核:linux 4.4.12


首先开发板的文件使用的是systemd 并没有/etc/rc.local文件 所以要想修改rc.local这一简单的操作已经不存在 但是也是可以用systemd和initd两种方式解决这个问题

1.systemd

我这里是修改自带的service


root@am335x-evm:/etc/rc5.d# ls /lib/systemd/system/rc-local.service

/lib/systemd/system/rc-local.service


在开发板这个目录我找到了rc-local.service文件 查看其内容


root@am335x-evm:/etc/rc5.d# cat /lib/systemd/system/rc-local.service

# This file is part of systemd.

#

# systemd is free software; you can redistribute it and/or modify it

# under the terms of the GNU Lesser General Public License as published by

# the Free Software Foundation; either version 2.1 of the License, or

# (at your option) any later version.


# This unit gets pulled automatically into multi-user.target by

# systemd-rc-local-generator if /etc/rc.local is executable.

[Unit]

Description=/etc/rc.local Compatibility

ConditionFileIsExecutable=/etc/rc.local

After=network.target


[Service]

Type=forking

ExecStart=/etc/rc.local start

TimeoutSec=0

RemainAfterExit=yes


可见开发板是支持/etc/rc.local文件的使用的 但是开发板下又没有/etc/rc.local文件 所以我们只能自己去建立了

在/lib/systemd/system/rc-local.service下加多一段文字


[Install]

WantedBy=multi-user.target


multi-user.target指明的是非图形界面的多用户方式


然后就去创建rc.local文件


vi /etc/rc.cal


然后加入以下代码


#!/bin/sh

case "$1" in

start)

/file_creat Tronlong

;;

stop)

exit 0;;

esac


然后就输入以下命令


# chmod +x /etc/rc.local

# systemctl enable rc-local.service

# systemctl --system daemon-reload

# systemctl start rc-local.service


然后重启后就可以看到Tronlong这个文件了


2.initd

首先创建/etc/init.d/helloworld文件

vi /etc/init.d/helloworld

内容为


#!/bin/sh

xxxxxxxx //你要启动的程序命令


# chmod +x /etc/init.d/helloworld //加可执行权限

# ln -sf /etc/init.d/helloworld /etc/rc5.d/S99helloworld //建立链接

# update-rc.d helloworld start 99 2 . //设置成开机启动项


然后重启就能看到程序运行了


『本文转载自网络,版权归原作者所有,如有侵权请联系删除』

热门文章 更多
浅谈msp430f5529入门(2)----时钟配置.例程分析