一、在工程路径下新建app
petalinux-create -t apps --template install -n myapp-init --enable
petalinux会在metausr目录下新建一个目录,结构如下
project-spec/meta-user/recipes-apps/myapp-init/
├── files
│ └── myapp-init
├── myapp-init.bb
└── README1 directory, 4 files
二、修改myapp-init文件
#!/bin/shecho "Hello PetaLinux PD2201"#mount /dev/mmcblk0p1 /mnt/sd-mmcblk0p2echo "insmod my spi driver"
echo 'cd /lib/modules/5.4.0-xilinx-v2020.2/extra'>> /etc/profile
echo 'modprobe myspidriver.ko'>> /etc/profileecho 'FILE=/media/sd-mmcblk0p2/nanomsg_zc702.elf'>> /etc/profile
echo 'if [ -f "$FILE" ]; then'>> /etc/profile
echo ' echo "sd-mmcblk0p2 exist"'>> /etc/profile
echo ' cd /media/sd-mmcblk0p2'>> /etc/profileecho 'else'>> /etc/profile
echo ' echo "sd-mmcblk0p1 not exist,start mount"'>> /etc/profile
echo ' mkdir media/sd-mmcblk0p2'>> /etc/profile'mount /dev/mmcblk0p1 /media/sd-mmcblk0p2' >> /etc/profile
echo ' cd /media/sd-mmcblk0p2'>> /etc/profile
echo 'fi'>> /etc/profileecho 'cp ./nanomasg_lib/libnanomsg.so* /lib/'>> /etc/profileecho './nanomsg_zc702.elf' >> /etc/profile
因为/etc/profile文件会在登陆后自动执行,因此可以将挂载驱动、sd卡、启动APP的命令写在该文件后。
三、修改myapp-init.bb文件
#
# This file is the myapp-aoturun recipe.
#SUMMARY = "Simple myapp-aoturun application"
SECTION = "PETALINUX/apps"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"SRC_URI = "file://myapp-init \"S = "${WORKDIR}"inherit update-rc.d
INITSCRIPT_NAME = "myapp-init"
INITSCRIPT_PARAMS = "start 99 5 ."do_install() {
# install -d ${D}/${bindir}
# install -m 0755 ${S}/myapp-aoturun ${D}/${bindir}install -d ${D}${sysconfdir}/init.dinstall -m 0755 ${S}/myapp-init ${D}${sysconfdir}/init.d/myapp-init
}
FILES_${PN} += "${sysconfdir}/*"
四、rootfs中查看是否存在该APP
petalinux -config -c rootfs
五、build整个工程,并更新boot,rootfs
petalinux -build
petalinux-package --boot --fsbl --fpga --u-boot --force