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

开发环境

开发板: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 .  //设置成开机启动项

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

  • 5
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值