怎么使用 pynq-z2 启动果壳

非常感谢 郑州大学和计算所联培 刘澳 编写的资料:https://www.cnblogs.com/GrootStudy/p/17059382.html

Compile chisel code
这里是英文版,之后会编写一个中文

before start, git checkout release-21228

Install mill. Refer to the Manual section in this guide.

Run make verilog BOARD=pynq to generate verilog code. The output file is build/TopMain.v.

Run programs by simulation
You can either use our ready-to-run image for simulation or build image yourself.

To use ready-to run image (recommended) :

Run make emu to launch simulation. Default image is linux kernel.
Run on FPGA
Sub-directories Overview
fpga
├── board # supported FPGA boards and files to build a Vivado project
├── boot # PS boot flow of zynq and zynqmp
├── lib # HDL sources shared by different boards
├── Makefile
├── Makefile.check
└── NutShell.tcl # wrapper of NutShell core in the Vivado project
Build a Vivado project
Install Vivado 2019.1, and source the setting of Vivado and SDK
Run the following command to build a Vivado project
cd fpga
make PRJ=myproject BOARD=pynq STANDALONE=true
(这里注意一下,vivado2019需要在board_files添加pynq-z2的板文件)Change pynq to the target board you want. Supported boards are listed under board/. The project will be created under board/pynq/build/myproject-pynq. Please note that STANDALONE mode is only used in pynq board.

Open the project with Vivado and generate bitstream.

To generate bitstream with vivado 2022.2, please add (* ram_style = “registers” *) before array tlbmd_0 tlbmd_2 tlbmd_3 in EmbeddedTLBMDmodule.See here for more details.

(* ram_style = “registers” *)
reg [120:0] tlbmd_0 [0:0];
prepare SD card
Stand-Alone Mode
In stand-alone mode, control is directly transferred to PL (Program Logic) through FSBL (First Stage BootLoader) after the board is powered on, so that PL has access to on-board peripherals such as SD card, Ethernet, etc., which is necessary to boot Debian and other OS.

We use PYNQ-Z2 board as example to demonstrate how to prepare SD card in stand-alone mode.

Build BOOT.BIN
BOOT.bin is the default filename of packaged hardware-related binary files. Here is a pre-built and currently-used BOOT.BIN.

You can also build it yourself. Please refer to the following process.

create a project in Vivado and generate bitstream

cd $(NUTSHELL_HOME)/fpga
make PRJ=myprj BOARD=pynq STANDALONE=true vivado
generate hardware description file in Vivado

Vivado -> File -> Export -> Export Hardware
do bootgen initially

cd $(NUTSHELL_HOME)/fpga
make bootgen PRJ=myprj BOARD=pynq STANDALONE=true

this will report some error messages

If you want to do bootgen with Vivado 22.2 please install Vitis first.

create project-related links

cd $(NUTSHELL_HOME)/fpga/boot/build/zynq
ln -sf $(NUTSHELL_HOME)/fpga/board/pynq/build/myprj-pynq/myprj-pynq.sdk/system_top_wrapper.hdf ps.hdf
ln -sf $(NUTSHELL_HOME)/fpga/board/pynq/build/myprj-pynq/myprj-pynq.runs/impl_1/system_top_wrapper.bit fpga.bit

modify FSBL_LOC in $(NUTSHELL_HOME)/fpga/resource/fsbl-loader/Makefile like this:

FSBL_LOC = …/…/boot/build/myprj-pynq/fsbl

generate BOOT.BIN

cd $(NUTSHELL_HOME)/fpga
make bootgen PRJ=myprj BOARD=pynq STANDALONE=true
Build RV_BOOT.bin
RV_BOOT.bin is the default filename of linux-kernel image. Here is a pre-built and currently-used image. You can also build it yourself by riscv-pk and riscv-linux (currently not avaliable to the public).

Build rootfs in SD card
Save the contents before the SD card in case of loss

mount -t vfat /dev/mmcblk0p1 /mnt
mkdir sd_card_save
cp /mnt/* sd_card_save
umount /mnt
Prepare
//umount the SD card
umount /dev/sdb*
Partition

creat two partitions in SD card

sudo fdisk /dev/sdb
Delete the partition before execute the steps

New partitions

Or use sudo cfdisk /dev/sdb to create partition
Format
mkfs.vfat /dev/sdb1
mkfs -t ext4 /dev/sdb2
if you see the following error report after executing mkfs -t ext4 /dev/sdb2 , you can change partition type by using sudo cfdisk /dev/sdb , see here for more details.

mkfs.ext4: inode_size (128) * inodes_count (0) too big for a
filesystem with 0 blocks, specify higher inode_ratio (-i)
or lower inode count (-N).
mount
mount -t ext4 /dev/sdb2 /mnt
mkdir /mnt/boot
mount -t vfat /dev/sdb1 /mnt/boot
copy
copy the files which has been generated before into /dev/sdb1

BOOT.BIN
RV_BOOT.BIN
download the debian base system to sdb2 with qemu-debootstrap , and enter the command below.
sudo su
qemu-debootstrap --arch riscv64 unstable /mnt http://deb.debian.org/debian-ports
chroot /mnt /bin/bash
passwd
apt-get update
apt-get install net-tools openssh-server vim build-essential minicom tmux libreadline-dev
exit
Add a line of ttyPS0 in /mnt/etc/securetty to allow login debian via ttyPS0. See here for more details.

Add a line of PermitRootLogin yes in /mnt/etc/ssh/sshd_config to enable root login via ssh. See here for more details.

Add the following lines to /mnt/etc/fstab

proc /proc proc defaults 0 0
/dev/mmcblk0p1 /boot vfat defaults 0 2
/dev/mmcblk0p2 / ext4 errors=remount-ro 0 1
Compile chisel code
Run programs by simulation
Run on FPGA
Sub-directories Overview
Build a Vivado project
prepare SD card
Stand-Alone Mode
Build BOOT.BIN
Build RV_BOOT.bin
Build rootfs in SD card

你可能感兴趣的:(fpga开发)