1、petalinux的重启命令:reboot、关机命令:shutdown -h now、开机按键:在关机后,ZCU106的右上角指示灯会变为红色,此时按下左上角第一个按键可启动操作系统。
2、好久没写博客了,本次给大家带来的是petalinux开机启动自定义脚本/程序的保姆级教程。
3、在vivado sdk中编写c/c++程序,并右键打包
4、在debug文件夹下会出现xxxxx.elf文件,将此文件移动至sdk中。
5、在linux中写入命令创建自启动脚本
(1)创建APP
bash
$ petalinux-create -t apps --template install -n myapp-init --enable
(2)编辑文件 /project-spec/meta-user/recipes-apps/myapp-init/myapp-init.bb
bash
#this file is the myapp-init recipe.
#
SUMMARY = "Simple myapp-init application"
SECTION = "PETALINUX/apps"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
SRC_URI = "file://myapp-init \
"
S = "${WORKDIR}"
FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
inherit update-rc.d
INITSCRIPT_NAME = "myapp-init"
INITSCRIPT_PARAMS = "start 99 5 ."
# 1为单用户模式
# 2-4是文本模式,一般不用图形界面的话用3就行了,3是多用户字符界面模式
# 5是多用户图形模式
# 0关机
# 6重启
# S就是全都有
# 写 "99 5" 的原因是,在第五程序启动层级的第99个程序启动
# 因为我们的网络是第5层启动的
# 写S的话,网络应用无法正常启动
do_install() {
install -d ${D}${sysconfdir}/init.d
install -m 0755 ${S}/myapp-init ${D}${sysconfdir}/init.d/myapp-init
}
FILES_${PN} += "${sysconfdir}/*"
这个文件的意思就是把myapp-init 放在/etc/init.d文件下,在linux系统中,放在init.d目录文件下可执行文件都会执行。
(3)在文件 /project-spec/meta-user/recipes-apps/myapp-init/files/myapp-init 写入下述代码
bash
#!/bin/sh
echo "Starting myapp-init"
# 挂载SD卡
if mountpoint -q /mnt/; then
echo "/mnt/ is already mounted."
else
mount /dev/mmcblk0p1 /mnt/
if [ $? -ne 0 ]; then
echo "Failed to mount /dev/mmcblk0p1 on /mnt/"
exit 1
fi
fi
# 提升权限 app_iec104_36_3.elf就是你Vivado SDK生成的elf文件,记得将其拖入到SD卡中
chmod +x /mnt/app_iec104_36_3.elf
if [ $? -ne 0 ]; then
echo "Failed to make /mnt/app_iec104_36_3.elf executable"
exit 1
fi
# 切换到文件所在目录并执行文件
cd /mnt/
if [ $? -ne 0 ]; then
echo "Failed to change directory to /mnt/"
exit 1
fi
# 执行app_iec104_36_3.elf
./app_iec104_36_3.elf
if [ $? -ne 0 ]; then
echo "Failed to execute ./app_iec104_36_3.elf"
exit 1
fi
echo "myapp-init completed"
(4)petalinux-build
(5)将生成的启动文件拖入SD卡中
6、启动截图,可以看到已经自动启动了