1. 建立新的 app 工程 - startup,最好都用小写字母,否则编译时会有warnning
cd <plnx-proj-proot>/
建立shell脚本文件的app工程:
petalinux-create -t apps --template install -n startup --enable
建立c语言的应用程序工程:
petalinux-create -t apps --template c -n startup --enable
2. 编辑文件 project-spec/meta-user/recipes-apps/startup/startup.bb
shell脚本工程相关的内容如下:
#
# This file is the startup recipe.
#
SUMMARY = "Simple startup application"
SECTION = "PETALINUX/apps"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
SRC_URI = "file://startup \
"
S = "${WORKDIR}"
FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
inherit update-rc.d
INITSCRIPT_NAME = "startup"
INITSCRIPT_PARAMS = "start 99 S ."
do_install() {
install -d ${D}/${sysconfdir}/init.d
install -m 0755 ${S}/startup ${D}/${sysconfdir}/init.d/startup
}
FILES_${PN} += "${sysconfdir}/*"
c语言工程相关的内容如下:
#
# This file is the startup recipe.
#
SUMMARY = "Simple startup application"
SECTION = "PETALINUX/apps"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
SRC_URI = "file://startup \
file://Makefile \
"
S = "${WORKDIR}"
FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
inherit update-rc.d
INITSCRIPT_NAME = "startup"
INITSCRIPT_PARAMS = "start 99 S ."
do_compile() {
oe_runmake
}
do_install() {
install -d ${D}/${sysconfdir}/init.d
install -m 0755 ${S}/startup ${D}/${sysconfdir}/init.d/startup
}
FILES_${PN} += "${sysconfdir}/*"
3. 编辑应用程序,在 project-spec/meta-user/recipes-apps/startup/files/ 文件夹里的 startup 或 startup.c 文件
#!/bin/sh
echo "Auto starting, Hello PetaLinux World"
#include <stdio.h>
int main(int argc, char **argv)
{
printf("Auto starting, Hello PetaLinux World!\n");
return 0;
}
4. rootfs文件系统设置
petalinux-config -c rootfs
在apps项选取startup
5. 执行编译
petalinux-build
6. 运行,在ZYNQ实验板启动PetaLinux,startup 自动运行
摘自ug1144