lowermachine/doc/develop_and_deploy.md
Miaow c98584d029 寒假前烟梗分选机上已经开始用的
测试能否打中暂时没啥问题,但溜的急,没充分测试
2022-07-03 19:47:53 +08:00

12 KiB
Raw Blame History

开发和部署

开发

本次开发基于zynq芯片因此FPGA设计软件为Vitis中包含的Vivado 2021.2Linux编译工具为petalinux 2022.1Linux应用程序编译工具为linaro的arm-linux-gnueabihf-gcc 12.0.1

生成硬件描述文件

doc/hardware_description.md

创建PETALINUX工程

  1. 创建名为ps-linux的工程,并创建两个模块

    $ cd ~
    $ petalinux-create -t project --template zynq -n ps-linux
    $ petalinux-create -t modules --name fifo --enable
    $ petalinux-create -t modules --name encoder --enable
    
  2. 上传驱动代码source/linux_driver/fifo.csource/linux_driver/encoder.c

    $ cd ~/ps-linux/project-spec/meta-user/recipes-modules/fifo
    $ rz  # 上传source/linux_driver/fifo.c
    $ cd ~/ps-linux/project-spec/meta-user/recipes-modules/encoder
    

$ rz # 上传source/linux_driver/encoder.c


3. 上传xsa文件并config

```shell
$ cd ~/ps-linux; rz  # 上传source/petalinux_hwdescription/system_wrapper.xsa
$ petalinux-config --get-hw-description system_wrapper.xsa

petalinux-config时候,按下面提示配置

# Subsystem AUTO Hardware Settings
# ├─Serial Settings
# | ├─FSBL Serial stdin/stdout (设为ps7_uart_0)
# | ├─DTG Serial stdin/stdout (设为ps7_uart_0)
# | └─System stdin/stdout baudrate for ps7_uart_0 (设为115200)
# ├─Ethernet Settings
# | ├─Randomise MAC address (不选)
# | ├─Primary Ethernet (设为ps7_ethernet_0)
# | ├─Ethernet MAC address (设为00:0a:35:00:1e:53) 
# | ├─Obtain IP address automatically (不选)
# | ├─Static IP address (设为192.168.10.10)
# | ├─Static IP netmask (设为255.255.255.0)
# | └─Static IP gateway (设为192.168.10.1)
# ├─Flash Settings
# | └─Primary Flash (设为ps7_qspi_0)
# ├─Flash Settings
# | └─Primary Flash (设为ps7_qspi_0)
# ├─SD/SDIO Settings
# | └─Primary SD/SDIO (设为ps7_sd_0)
# Image Packaging Configuration
# └─Image Packaging Configuration
#   ├─Root filesystem type (设为EXT4 (SD/eMMC/SATA/USB))
#   ├─name for bootable kernel image (设为image.ub)
#   ├─Root filesystem formats (设为ext4 tar.gz)
#   └─Copy final images to tftpboot (不选)
  1. 修改设备树,需要修改的文件为project-spec/meta-user/recipes-bsp/device-tree/files/system-user.dtsi,先删除该文件,然后上传新的自定义设备树文件source/petalinux_devicetree/system-user.dtsi

    $ cd ~/ps-linux/project-spec/meta-user/recipes-bsp/device-tree/files
    $ rm system-user.dtsi
    $ rz  # 上传source/petalinux_devicetree/system-user.dtsi
    
  2. 配置kernel使用命令petalinux-config -c kernel,按下面提示或source/petalinux_config/kernel.cfg配置

    # File systems
    # ├─FUSE (Filesystem in Userspace) support (勾选为星号)
    # └─DOS/FAT/EXFAT/NT Filesystems
    #   ├─Enable FAT UTF-8 option by default (勾选为星号)
    #   ├─exFAT filesystem support (勾选为星号)
    #   ├─NTFS file system support (勾选为星号)
    #   └─NTFS write support (勾选为星号)
    # Device Drivers
    # └─USB support
    #   └─OTG support (勾选为星号)
    
  3. 配置rootfs使用命令petalinux-config -c rootfs,按下面提示或source/petalinux_config/rootfs_config配置

    # Filesystem Packages
    # ├─base
    # | ├─shell
    # | | └─bash
    # | |   └─bash (勾选为星号)
    # | ├─tar
    # | | └─tar (勾选为星号)
    # | ├─util-linux
    # | | ├─util-linux-blkid (勾选为星号)
    # | | ├─util-linux-lscpu (勾选为星号)
    # | | ├─util-linux-umount (勾选为星号)
    # | | └─util-linux-mount (勾选为星号)
    # | └─xz
    # |   ├─xz (勾选为星号)
    # |   └─liblzma (勾选为星号)
    # ├─console
    # | ├─network
    # | | ├─curl
    # | | | ├─curl (勾选为星号)
    # | | | └─libcurl (勾选为星号)
    # | | ├─dropbear
    # | | | └─dropbear (不选)
    # | | ├─ethtool
    # | | | └─ethtool (勾选为星号)
    # | | ├─lrzsz
    # | | | └─lrzsz (勾选为星号)
    # | | ├─minicom
    # | | | └─minicom (勾选为星号)
    # | | ├─openssh
    # | | | ├─openssh (勾选为星号)
    # | | | ├─openssh-misc (勾选为星号)
    # | | | ├─openssh-sshd (勾选为星号)
    # | | | ├─openssh-keygen (勾选为星号)
    # | | | ├─openssh-ssh (勾选为星号)
    # | | | ├─openssh-sftp (勾选为星号)
    # | | | ├─openssh-sftp-server (勾选为星号)
    # | | | └─openssh-scp (勾选为星号)
    # | | └─wget
    # | |   └─wget (勾选为星号)
    # | ├─utils
    # | | ├─bash-completion
    # | | | ├─bash-completion (勾选为星号)
    # | | | └─bash-completion-extra (勾选为星号)
    # | ├─bzip2
    # | | ├─bzip2 (勾选为星号)
    # | | └─libbz2 (勾选为星号)
    # | ├─file
    # | | └─file (勾选为星号)
    # | ├─findutils
    # | | └─findutils (勾选为星号)
    # | ├─gawk
    # | | └─gawk (勾选为星号)
    # | ├─grep
    # | | └─grep (勾选为星号)
    # | ├─gzip
    # | | └─gzip (勾选为星号)
    # | ├─less
    # | | └─less (勾选为星号)
    # | ├─man
    # | | └─man (勾选为星号)
    # | ├─man-pages
    # | | └─man-pages (勾选为星号)
    # | ├─screen
    # | | └─screen (勾选为星号)
    # | ├─sed
    # | | └─sed (勾选为星号)
    # | ├─unzip
    # | | └─unzip (勾选为星号)
    # | ├─vim
    # | | ├─vim (勾选为星号)
    # | | ├─vim-syntax (勾选为星号)
    # | | └─vim-common (勾选为星号)
    # | └─zip
    # |   └─zip (勾选为星号)
    # ├─devel
    # | └─lsof
    # |   └─lsof (勾选为星号)
    # ├─misc
    # | └─perf
    # |   └─perf (勾选为星号)
    # Image Features
    # ├─imagefeature-ssh-server-dropbear (不选)
    # ├─imagefeature-ssh-server-openssh (勾选为星号)
    # ├─imagefeature-hwcodecs (勾选为星号)
    # └─imagefeature-package-management (勾选为星号)
    # modules
    # ├─encoder (勾选为星号)
    # └─fifo (勾选为星号)
    # PetaLinux RootFS Settings
    # ├─ADD_EXTRA_USERS (root:3703;petalinux:3703;)
    # ├─ADD_USERS_TO_GROUPS (petalinux:audio,video;)
    # └─ADD_USERS_TO_SUDOERS (petalinux)
    

编译PETALINUX工程

  1. 编译工程,使用命令petalinux-build。编译完成在当前工程目录下生成images文件夹该命令将生成设备树文件、FSBL文件、U-Boot文件Linux Kernel文件和rootfs文件镜像

  2. 制作BOOT.BIN启动文件具体命令如下

    $ cd ~/petalinux-projects/ps-linux/images/linux/  # 生成的BOOT.BIN也在该路径下
    $ petalinux-package --boot --fsbl ./zynq_fsbl.elf --fpga ./system.bit --u-boot ./u-boot.elf --force
    

部署

注意这部分所需的文件按上一章节编译得到或者从github的release中下载

SSH连接

  1. 电脑网卡设置到开发板同一网段

  2. SSH连接信息如下

    $ sshpass -p "3703" ssh root@192.168.10.10 -p 22
    

修改文件系统

注意github的release中包含了修改完成的rootfs.tar.gz因此无需重复本节的步骤本节仅用作记录修改步骤

  1. 给SD卡创建DOS分区表然后分2个区并创建文件系统细节如下表

    扇区 大小 分区类型 文件系统 卷标
    2048~x扇区 100M C W95 FAT32 (LBA) FAT32 boot
    x扇区~最后扇区 ≈SD卡大小-100M 83 Linux ext4 rootfs
  2. 将打包和编译得到的BOOT.BIN、boot.scr和image.ub复制到boot分区将rootfs.tar.gz解压到rootfs分区。

  3. 拨码开关拨到SD卡启动插入SD卡到XME0724底板上上电启动。

  4. 终端软件连接底板上的串口波特率1152008位1停止位无校验

  5. 修改/etc/shadow文件将root用户的密码删除切换到root用户并设定密码为3703具体命令如下:

    $ sudo sed "1c root::15069:0:99999:7:::" /etc/shadow
    # 如果没有sed命令用任何其他方式都可以比如vim
    $ su root
    $ passwd
    
  6. 配置网络和ssh服务用root登录

    $ vi /etc/network/interfaces
      添加或确认内容如下:
      auto eth0
      iface eth0 inet static
        address 192.168.10.10
        netmask 255.255.255.0
        gateway 192.168.10.1
    $ vi /etc/ssh/sshd_config
      确认修改如下选项:
      PermitRootLogin yes
      PermitEmptyPasswords yes
      PasswordAuthentication yes
    $ reboot
    
  7. 安装编译得到的驱动文件fifo.ko和encode.ko并设置自动加载对应脚本见script/loadfifo.shscript/loadencoder.sh

    ssh方式root登录:

    $ cd ~; rz  #上传fifo.ko
    $ rz  # 上传encoder.ko
    $ mv fifo.ko encoder.ko /lib/modules/[内核版本]/kernel/drivers/
    $ cd /lib/modules/[内核版本]; depmod
    $ echo "#!/bin/sh\nmodprobe fifo" > /etc/init.d/loadfifo.sh
    $ echo "#!/bin/sh\nmodprobe encoder" > /etc/init.d/loadencoder.sh
    $ chmod 755 /etc/init.d/loadfifo.sh
    $ chmod 755 /etc/init.d/loadencoder.sh
    $ cd /etc/rc5.d 
    $ ln -s ../init.d/loadfifo.sh S20loadfifo.sh
    $ ln -s ../init.d/loadencoder.sh S20loadencoder.sh
    
  8. 安装编译得到的应用程序target并设置自启动对应脚本见script/target.sh

    ssh方式root登录:

    $ cd ~; rz  # 上传target
    $ chmod 755 target
    $ echo "#!/bin/sh\nif [ -x /home/root/target ]; then\n /home/root/target\nfi" > /etc/init.d/target.sh
    $ chmod 755 /etc/init.d/target.sh
    $ cd /etc/rc5.d
    $ ln -s ../init.d/target.sh S99target.sh
    
  9. 可选
    $ cd ~; rz  # 上传.bashrc
    $ rz  # 上传.profile
    $ if [ ! -a /home/petalinux/.profile ]; then cp /home/root/.profile /home/petalinux/ fi
    $ if [ ! -a /home/petalinux/.bashrc ]; then cp /home/root/.bashrc /home/petalinux/ & chown petalinux:petalinux -R /home/petalinux fi
    $ source ~/.profile
    
  10. 可选
$ cd ~; rz  # 上传ncurses-6.3.tar.gz
$ tar xzf /home/root/ncurses-6.3.tar.gz -C /usr/
$ rz  # 上传htop.tar.gz
$ tar xzf /home/root/htop.tar.gz -C /usr/

SD卡启动

  1. 给SD卡创建DOS分区表然后分2个区并创建文件系统细节如下表

    扇区 大小 分区类型 文件系统 卷标
    2048~x扇区 100M C W95 FAT32 (LBA) FAT32 boot
    x扇区~最后扇区 ≈SD卡大小-100M 83 Linux ext4 rootfs
  2. 将Github Release中的BOOT.BIN、boot.scr和image.ub复制到boot分区将rootfs.tar.gz解压到rootfs分区。

  3. 拨码开关拨到SD卡启动插入SD卡到XME0724底板上上电启动。