Petalinux 文档阅读笔记 UG1144

依赖环境配置

1
sudo apt-get install -y gcc git make net-tools libncurses5-dev tftpd zlib1g-dev libssl-dev flex bison libselinux1 gnupg wget diffstat chrpath socat xterm autoconf libtool tar unzip texinfo zlib1g-dev gcc-multilib build-essential libsdl1.2-dev libglib2.0-dev zlib1g:i386 screen pax gzip

安装过程

Once installed, you cannot move or copy the installed directory. In the above example,you cannot move or copy /opt/pkg/petalinux.

安装后记得source那个sh文件

Before running the PetaLinux command, you need to source PetaLinux settings first.

下表提供了一个示例设计工作流程,演示了应完成任务的顺序以及该任务的相应工具或工作流程。

Design Flow Step Tool / Workflow
创造硬件平台 vivado
创造petalinux工程 petalinux-create -t project
初始化PetaLinux项目(仅限自定义硬件) petalinux-config –get-hw-description
配置系统级选项 petalinux-config
创建用户组件 petalinux-create -t COMPONENT
配置Linux内核 petalinux-config -c内核
配置Root 文件系统 petalinux-config -c rootfs
构建系统 petalinux-build
用于部署系统 petalinux-package的软件包
启动系统以进行测试 petalinux-boot

Boot a PetaLinux Image on Hardware with SD Card

前提:

  1. 安装好的petalinux工具链

  2. 安装了petalinux BSP包

  3. minicom一类的串口通信软件安装,波特率115200bps

步骤:

  1. Mount the SD card on your host machine.

  2. Copy the following files from /pre-built/linux/images/
    into the root directory of the first partition which is in FAT32 format in the SD card:
    ° BOOT.BIN
    ° image.ub

  3. 打开串口工具

  4. 开发板设置为SD启动

  5. Plug the SD card into the board.

  6. Power on the board.

出了错误注意阅读Troubleshooting

固件版本设置

  1. Change into the root directory of your PetaLinux project.
    $ cd <plnx-proj-root>

  2. Launch the top level system configuration menu.
    $ petalinux-config

  3. Select Firmware Version Configuration –>.

  4. Select Host Name, Product Name, Firmware Version as per the requirement to edit them.

  5. Exit the menu and select when asked Do you wish to save your new
    configuration?:
    Do you wish to save your new configuration ?
    to continue.< Yes > < No >

  6. Once the target is booted up, verify the Host Name in cat /etc/hostname, Product
    Name in cat /etc/petalinux/product, and the Firmware Version in cat /etc/petalinux/version.

文件系统配置

  1. Change into the root directory of your PetaLinux project
    $ cd <plnx-proj-root>

  2. Launch the top level system configuration menu
    $ petalinux-config

  3. Select Image Packaging Configuration —> Root file System type —>

  4. Select INITRAMFS/INITRD/JFFS2/NFS/SD card as per the requirement

  5. Save Configuration settings.

Boot映像存储设置

我用的是SD卡,选SD卡的配置方式

  1. Change into the root directory of your PetaLinux project.
    $ cd <plnx-proj-root>

  2. Launch the top level system configuration menu.
    $ petalinux-config

  3. Select Subsystem AUTO Hardware Settings —> Advanced Bootable Images
    Storage Settings —> boot image settings —> Image Storage Media.

  4. Select boot device as per the requirement. To set flash as the boot device select primary flash. To make SD card as the boot device select primary sd.

  5. Under the Advanced Bootable Images Storage Settings submenu, select kernel
    image settings.

  6. Select Image Storage Media.

  7. Select storage device as per the requirement. To set flash as the boot device select primary flash. To make SD card as the boot device select primary sd.

  8. Save Configuration settings

还有一些管理映像的size的,暂时不管。
dsssssad
出了错误注意阅读Troubleshooting

Configuring INITRD BOOT

INITRD,缩写为初始RAMdisk。 INITRD提供了在PetaLinux启动过程中由引导加载程序加载RAM磁盘的功能。 Linux内核将其挂载为RootFS并启动初始化过程。 本节介绍配置INITRD引导的过程。

暂时不管,还有TFTP Boot、NFS Boot、 JFFS2 Boot

SD卡ext文件系统启动

  1. Change to root directory of your PetaLinux project.
    $ cd <plnx-proj-root>

  2. Launch top level system configuration menu.
    $ petalinux-config

  3. Select Image Packaging Configuration —> Root filesystem type.

  4. Select SD card as the RootFS type.

  5. Exit menuconfig and save configuration settings.

  6. Build PetaLinux images. For more information, see Build System Image.

  7. Generate boot image. For more information, see Generate Boot Image for Zynq
    UltraScale+ MPSoC.

  8. The generated rootfs.tar.gz file will be present in images/linux directory. To
    extract, use tar xvf rootfs.tar.gz.

把映像文件复制到SD卡分区

1.切换到PetaLinux项目的根目录。
$ cd <plnx-proj-root>

2.将BOOT.BIN和image.ub复制到SD卡的BOOT分区。 image.ub文件将包含设备树和内核映像文件。
$ cp images/linux/BOOT.BIN /media/BOOT/

$ cp images/linux/image.ub /media/BOOT/

3.将rootfs.cpio文件复制到SD卡的rootfs分区并解压缩文件系统。
$ sudo tar xvf rootfs.tar.gz -C /media/rootfs
要启动此SD卡ext映像,请参阅使用SD卡在硬件上启动PetaLinux映像。

出了错误注意阅读Troubleshooting

自定义配置文件系统

加入预编译模块

如果您有预编译的内核模块,您可能只想将模块添加到PetaLinux根文件系统中。 本节介绍如何将预编译的模块包含到PetaLinux根文件系统中。

包含预建模块的步骤:

如果您的预建模块名称是mymodule,则将其包含在PetaLinux根文件系统中,将在以下步骤中说明:

  1. Ensure that the pre-compiled kernel module has been compiled for your PetaLinux target architecture (For example, MicroBlaze, Arm etc.).

  2. To create a module project, use the following command.

$ petalinux-create -t modules --template install --name mymodule --enable

  1. Change to the newly created module directory.

$ cd <plnx-proj-root>/project-spec/meta-user/recipes-modules/mymodule/files

  1. Place the pre-built module mymodule.ko into meta-user/mymodule/files/
    directory

$ cp <path-to-prebuilt-module>/mymodule.ko ./

  1. Edit mymodule.bb file, the file should look like the following:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    #
    # This file is the mymodule recipe.
    #
    SUMMARY = "Simple shivamod mymodule"
    SECTION = "PETALINUX/apps"
    LICENSE = "MIT"
    LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
    SRC_URI = "file://mymodule.ko \
    "
    inherit module-base
    S = "${WORKDIR}"
    do_install() {
    install -d ${D}${base_libdir}/modules/${KERNEL_VERSION}/extra
    install -m 0755 ${S}/mymodule.ko ${D}/${base_libdir}/modules/${KERNEL_VERSION}/extra/
    }
    FILES_${PN} = "${base_libdir}/modules/"
  2. Run
    petalinux-build

Out-of-tree编译配置

在网上看到介绍,有两种linux kernel模块编译方式,一种是out of tree,另一种是in tree。

I have not come across “in-tree” and “out-of-tree” outside of the Linux kernel source development and then only for working with modules. All modules start out as “out-of-tree” developments, that can be compiled using the context of a source-tree. Once a module gets accepted to be included, it becomes an in-tree module. A I have not come across an official definition for both terms though, maybe that was never necessary as it was clear to those working with modules what was meant.
E.g. while Reiserfs module was still an out-of-tree module I did the RPM package generation for SuSE, once it became in-tree there was no longer need for that.

简而言之,linux下设备驱动程序可以按照两种方式进行编译,一种是直接静态编译成内核的一部分,另一种是编译成可以动态加载的模块。

具体步骤

  1. Change into the root directory of your PetaLinux project.
    $ cd <plnx-proj-root>

  2. Launch the top level system configuration menu.
    $ petalinux-config

  3. Select linux Components Selection —> sub-menu
    ° For kernel, select linux-kernel () —> and then select remote
    ° For U-Boot, select u-boot () —> and then select remote

  4. For kernel, select Remote linux-kernel settings —> Remote linux-kernel git URL and
    enter git URL for linux-kernel.
    For example: To use https://github.com/Xilinx/linux-xlnx, enter
    git://github.com/Xilinx/linux-xlnx.git;protocol=https
    For U-Boot, select Remote U-Boot settings —> Remote u-boot git URL and enter git
    URL for u-boot. For example:
    git://github.com/Xilinx/u-boot-xlnx.git;protocol=https

  5. Exit the menu, and save your settings.

注意,你也可以选择外部内核和Uboot

出了错误注意阅读Troubleshooting

配置项目组件

  1. 配置Linux kernel

$ petalinux-config -c kernel

  1. 配置文件系统

$ petalinux-config -c rootfs

还有配置设备树和uboot的,之前貌似是SDK配置的。

附录

Petalinux工程结构

  1. Device tree
  2. First stage bootloader (optional)
  3. U-Boot
  4. Linux kernel
  5. rootfs is composed of the following components:
    ° Prebuilt packages
    ° Linux user applications (optional)
    ° User modules (optional)

文档内还有各个文件夹的功能的介绍表格

参考文档

  1. ug1144-petalinux-tools-reference-guide

2019-04-27-16-44-50