FPGA----petalinux开机启动自定义脚本/程序的保姆级教程

1、petalinux的重启命令:reboot、关机命令:shutdown -h now、开机按键:在关机后,ZCU106的右上角指示灯会变为红色,此时按下左上角第一个按键可启动操作系统。

2、好久没写博客了,本次给大家带来的是petalinux开机启动自定义脚本/程序的保姆级教程。

3、在vivado sdk中编写c/c++程序,并右键打包

4、在debug文件夹下会出现xxxxx.elf文件,将此文件移动至sdk中。

5、在linux中写入命令创建自启动脚本

(1)创建APP

$ petalinux-create -t apps --template install -n myapp-init --enable

(2)编辑文件 /project-spec/meta-user/recipes-apps/myapp-init/myapp-init.bb

#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 写入下述代码

#!/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、启动截图,可以看到已经自动启动了

相关推荐

  1. ubuntu开机启动脚本

    2024-06-17 01:18:05       31 阅读
  2. 开机启动脚本配置

    2024-06-17 01:18:05       8 阅读
  3. Spring Boot Banner 教程定义启动画面艺术

    2024-06-17 01:18:05       42 阅读
  4. linux定义开机启动

    2024-06-17 01:18:05       8 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-06-17 01:18:05       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-06-17 01:18:05       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-06-17 01:18:05       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-06-17 01:18:05       18 阅读

热门阅读

  1. 简单剖析tRPC-Go中使用的第三方协程池ants

    2024-06-17 01:18:05       8 阅读
  2. Opencv无法自动补全

    2024-06-17 01:18:05       6 阅读
  3. 15分钟面试被5连CALL,你扛得住么?

    2024-06-17 01:18:05       7 阅读
  4. SSH error : no kex alg message

    2024-06-17 01:18:05       7 阅读
  5. Spring (60)Spring WebFlux

    2024-06-17 01:18:05       8 阅读
  6. 数据结构之B树的原理与业务场景

    2024-06-17 01:18:05       8 阅读
  7. Autosar实践——诊断配置(DaVinci Configuration)

    2024-06-17 01:18:05       6 阅读
  8. 2024.06.16 刷题日记

    2024-06-17 01:18:05       4 阅读
  9. linux发展历程

    2024-06-17 01:18:05       6 阅读
  10. atcoder ABC 358-B题详解

    2024-06-17 01:18:05       7 阅读
  11. Qt中的事件循环

    2024-06-17 01:18:05       6 阅读