Hello!
Here goes my third tutorial on Minized and PYNQ using EMMC memory
This project will prepare your Minized to work with PYNQ and give you some insight how to modify existing projects to suit your needs.
Edit: added how to use Vitis HLS with PYNQ for acceleration.
Story
This tutorial shows how to create PYNQ for Minized, that uses EMMC memory with extra storage option as PMOD sdcard.
Preparing environment
First we will need to clone repositories from Avnet GitHub with these scripts we will build our project and BSP.
mkdir Avnet;
cd Avnet;
git clone https://github.com/Avnet/bdf.git --branch master;
git clone https://github.com/Avnet/hdl.git --branch 2019.1;
git clone https://github.com/Avnet/petalinux.git --branch 2019.1;
git clone https://github.com/Xilinx/PYNQ.git --branch image_v2.5.4;
wget http://downloads.element14.com/downloads/zedboard/minized/minized_ttc_2019_1.bsp.zip?ICID=minized-datasheet-widget;
unzip minized_ttc_2019_1.bsp.zip?ICID=minized-datasheet-widget;
Go to petalinux → scripts and edit "make_minized_qspi_minimal_bsp.sh"
cd petalinux/scripts;
gedit make_minized_qspi_minimal_bsp.sh;
Change Vivado and Petalinux installation paths
Run script and wait until it is finished.
./make_minized_qspi_minimal_bsp.sh
In meantime, we will create project based on "minized_ttc_2019.1.bsp"
Open new terminal and source petalinux settings.sh
source /home/bartek/petalinux20191/settings.sh
and create project
petalinux-create -t project -s minized_ttc_2019_1.bsp
Open newly created project.
cd minized_ttc_2019_1
Inside you can see "hardware" folder that contain hardware design used to build that BSP.
We will need to modify device tree used for this project, or else Petalinux won't build with FPGA manager turned on.
Go to project-spec → meta-user → recipes-bsp → device-tree → files and edit "system-user.dtsi"
cd project-spec/meta-user/recipes-bsp/device-tree;
gedit system-user.dtsi
We can safely remove nodes that reference to Wi-Fi module and accelerometer.
I have tried before and reprogramming FPGA will cause Wi-Fi driver to crash, that why I'm removing it, also if you leave accelerometer nodes petalinux build will fail.
/include/ "system-conf.dtsi"
/ {
aliases {
serial0 = &uart1;
serial1 = &uart0;
};
};
&flash0 {
compatible = "micron,n25q128", "jedec,spi-nor";
};
/{
usb_phy0: usb_phy@0 {
compatible = "ulpi-phy";
#phy-cells = <0>;
reg = <0xe0002000 0x1000>;
view-port = <0x0170>;
drv-vbus;
};
};
&usb0 {
dr_mode = "otg";
usb-phy = <&usb_phy0>;
} ;
/* QSPI addresses are defined with petalinux-config, but here they are overwritten so that one can program the flash internally */
&qspi {
#address-cells = <1>;
#size-cells = <0>;
flash0: flash@0 {
compatible = "micron,m25p80";
reg = <0x0>;
#address-cells = <1>;
#size-cells = <1>;
spi-max-frequency = <50000000>;
partition@0x00000000 {
label = "boot";
reg = <0x00000000 0x00ff0000>;
};
};
};
/* PMOD SD Interface */
&sdhci0 {
status = "okay";
bus-width= <4>;
xlnx,has-cd = <0x0>;
xlnx,has-power = <0x0>;
xlnx,has-wp = <0x0>;
/* cd-inverted; */
wp-inverted;
mmccardpmod: mmccardpmod@1 {
/* reg = <0>; */
compatible = "mmc-card";
};
};
/* SD Interface for eMMC */
&sdhci1 {
status = "okay";
non-removeable;
bus-width= <4>;
xlnx,has-cd = <0x0>;
xlnx,has-power = <0x0>;
xlnx,has-wp = <0x0>;
mmccard: mmccard@0 {
reg = <0>;
compatible = "mmc-card";
broken-hpi;
};
};
/* Console UART. UART1 is tied to the USB serial port on the Zedboard */
&uart1 {
status = "okay";
current-speed = <115200>;
port-number = <0>;
};
/ {
};
PYNQ setup
Open PYNQ → sdbuild → scripts and run "setup_host.sh" script (if you didn't before).
cd PYNQ/sdbuild/scripts;
bash setup_host.sh
Now we will need to modify boot settings for PYNQ.
Open PYNQ → sdbuild → boot → meta-pynq → recipes-bsp → device-tree and edit "pynq_bootargs.dtsi"
cd PYNQ/sdbuild/boot/meta-pynq/recipes-bsp/device-tree;
gedit pynq_bootargs.dtsi
Change "/dev/mmcblk0p2" to "/dev/mmcblk1p2"
Also, you will need prebuilt rootfs image for arm architecture. See PYNQ quick porting guide.
Download it.
Go to PYNQ → sdbuild and type:
make BOARDS=Pynq-Z1
To see if PYNQ is set up properly.
Modifying Minized minimal
The script we ran at start for Minized QSPI should be finished by now.
Open petalinux → project → minized_qspi_minimal_2019_1 and add utility packages to format memory (optional).
cd petalinux/projects/minized_qspi_minimal_2019_1;
petalinux-config -c rootfs
Enable "e2fsprogs", "e2fsprogs-resize2fs", "e2fsprogs-e2fsck" packages.
You can search for packages using "/" in petalinux window.
Exit and rebuild project
petalinux-build
Now we will boot our system via JTAG.
petalinux-boot --jtag --fpga --kernel --verbose;
Login to Minized for example using cutecom or putty.
Format EMMC
Now we will format EMMC. (optional, later we can use "dd" to write image to EMMC)
Use "df -h" command to list all mounted drives and their location
df -h
or "fdisk -l"
fdisk -l
EMMC is "/dev/mmcblk1"
We need to create two partitions. One for "image.ub" and second for "rootfs"
First partition needs to be FAT32 and second partition ext4.
Open mmcblk1.
fdisk /dev/mmcblk1
Delete partitions using fdisk and write changes.
d
1
d
2
w
Now we need to create new partitions (you can use "format_emmc.sh" script as reference it is located in local/bin).
fdisk /dev/mmcblk1
o
n
p
1
enter (default command)
+255M
w
Now we have first partition with for example 255Mb.
fdisk /dev/mmcblk1
n
p
2
enter (default command)
enter (default command)
w
Make first partition w95 fat32
fdisk /dev/mmcblk1
t
1
b
w
or use mkfs to format mmblk1p1 to fat32
mkfs.vfat -F 32 -n boot /dev/mmcblk1p1
Format mmblk1p2 to ext4
mkfs.ext4 -L root /dev/mmcblk1p2
Now you EMMC is ready as storage medium.
Creating base project
Open hdl → Projects → minized_petalinux →MINIZED_2019_1
Open block design and remove unused IP's (You could connect SD card mgr to SDIO_0 port for extra storage).
Generate new bistream and export HDF from project.
Creating PYNQ image
Go to minized_ttc_2019_1 project and change referenced HDF and image packaging configuration.
cd minized_ttc_2019_1;
petalinux-config --get-hw-description=/home/bartek/Desktop/Minized_EMMC/Avnet;
Build project and package new BSP.
petalinux-build;
petalinux-package --bsp --p ${PWD} --hwsource /home/bartek/Desktop/Minized_EMMC/Avnet/hdl/Projects/minized_petalinux/MINIZED_2019_1 -o MinizedEMMCPynq;
Copy created BSP to PYNQ → sdbuild with previously downloaded "bionic.arm.2.5.img"
And create PYNQ image
cd PYNQ/sdbuild;
bash scripts/image_from_prebuilt.sh MinizedEMMCPynq MinizedEMMCPynq.bsp arm bionic.arm.2.5.img;
It is better to create custom image for Minized. We will need to apply some modifications to PYNQ board project. (Ready package is in attachments MinizedPynq.7z) extract it somewhere for example in "PYNQ/zz" <- this is our board repository.
I have modified petalinux_bsp → meta-user → ... → user_2018-06-26-17-14-00.cfg
and enabled kernel drivers for some USB Wi-Fi modules.
You can do this via "petalinux-config -c kernel" before packaging BSP.
cd PYNQ/sdbuild;
make PREBUILT=/home/bartek/PYNQ/sdbuild/bionic.arm.2.5.img BOARDDIR=/home/bartek/PYNQ/zz BOARD=Minizedzik
If it doesn't work try adding PYNQ_SDIST:
make PYNQ_SDIST=/home/bartek/Downloads/pynq-2.5.tar.gz PREBUILT=/home/bartek/PYNQ/sdbuild/bionic.arm.2.5.img BOARDDIR=/home/bartek/PYNQ/zz BOARD=Minizedzik
Minized image should be in output folder.
Restore disk image on USB drive.
And resize partition2 to less than size of EMMC minus partition1 size for example 7Gb and check for errors.
Connect USB drive to Minized.
Write image to EMMC using "dd" command (this will take a while).
dd if=/dev/sda of=/dev/mmcblk1
And if you wish check for errors.
e2fsck /dev/mmcblk1p1
e2fsck /dev/mmcblk1p2
Program Minized with "minized_ttc_2019_1" BOOT.bin
petalinux-build;
petalinux-package --boot --fpga --u-boot -o BOOT.bin --force;
program_flash -f ./BOOT.bin -offset 0 -flash_type qspi_single -fsbl ./images/linux/zynq_fsbl.elf;
Minized will use QSPI memory to load BOOT.bin.
ZYNQ will use that BOOT.bin to load FSBL that programs FPGA for Minized, then it will load u-boot that will search for image.ub on "/dev/mmcblk1p1" partition. Image.ub will wait until "/dev/mmcblk1p2" is mounted and load rootfs.
Now Minized should boot with PYNQ system.
Now let's mount pmod sdcard and write something to test functionality.
mkdir mnt;
ls -l /dev | grep mmc;
sudo mount /dev/mmcblk0p2 mnt;
Open mnt folder and create.txt file.
cd mnt;
sudo nano TestWrite.txt;
Exit and save, umount sdcard.
cd ..;
sudo umount mnt;
Let's check what is on sdcard.
Creating overlays
I have upgraded this project for 2020.1 version of Vivado.
Open Vitis HLS and create new empty project for xc7z007 chip.
Click sources → new file
Create addition IP-core
Go to project settings → Synthesis and in "Top Function" type "add"
Click ok and run synthesis.
Export our IP to local IP-repository.
Extract "add.zip"
Open Vivado and add new IP to the project and connect it to AXI interconnect.
Save project and export bitstream.
Open Vivado project and search for bistream and .hwh file.
Copy and rename these files.
Upload them to Minized, but first we will need Wi-Fi.
Start Minized and connect to it for example with putty.
As you can see Minized detected our wireless adapter
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
sudo wpa_supplicant -c /etc/wpa_supplicant/wpa_supplicant.conf -i wlan0 -B
sudo dhclient wlan0
Open internet browser and connect to Minized (password is xilinx)
http://192.168.0.105:9090/tree?
Upload files via jupyter notebook.
The End
Now you are ready to develop your own IOT applications based on these three projects.
Top Comments