Skip to content

Instantly share code, notes, and snippets.

@zOrg1331
Last active April 7, 2024 15:12
Show Gist options
  • Save zOrg1331/f1e90e4b31dc668fbe6837a18492a8ee to your computer and use it in GitHub Desktop.
Save zOrg1331/f1e90e4b31dc668fbe6837a18492a8ee to your computer and use it in GitHub Desktop.
PYNQ-Z2 board U-Boot and Linux kernel

PYNQ-Z2 board: https://www.tul.com.tw/ProductsPYNQ-z2.html

Based on instructions in https://github.com/SymbiFlow/symbiflow-xc7z-automatic-tester

Let's say we use ~/pynq-z2 as a working directory.

Prepare toolchain:

cd ~/pynq-z2
wget https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2019q4/RC2.1/gcc-arm-none-eabi-9-2019-q4-major-x86_64-linux.tar.bz2
tar -xf gcc-arm-none-eabi-9-2019-q4-major-x86_64-linux.tar.bz2

Prepare SD card. Create two partitions: 256+MiB for /boot (FAT32) and the rest for root filesystem (ext4). Assign labels to ease copying.

Prepare root filesystem content:

cd ~/pynq-z2
wget http://de5.mirror.archlinuxarm.org/os/ArchLinuxARM-armv7-latest.tar.gz
sudo tar -xf ArchLinuxARM-armv7-latest.tar.gz -C /media/root/

Take U-Boot from https://github.com/zOrg1331/u-boot-xlnx and switch to zynq_pynq_z2 branch.

Compile U-Boot.

cd ~/pynq-z2
export PATH=${PWD}/gcc-arm-none-eabi-9-2019-q4-major/bin:$PATH

export ARCH=arm
export CROSS_COMPILE=arm-none-eabi-

cd ~/pynq-z2/u-boot-xlnx
make zynq_pynqz2_defconfig
make -j`nproc`

Copy U-Boot to SD card:

cp spl/boot.bin /media/boot
cp u-boot.img /media/boot

Take Linux kernel from https://github.com/zOrg1331/linux-xlnx and switch to zynq_pynq_z2 branch.

Compile Linux kernel.

cd ~/pynq-z2/linux-xlnx
make xilinx_zynq_defconfig
make -j`nproc` zImage dtbs modules

Place the following file as ~/pynq-z2/pynq_z2_image.its:

/dts-v1/;

/ {
    description = "U-Boot fitImage for PYNQ arm kernel";
    #address-cells = <1>;

    images {
        kernel@0 {
            description = "Linux Kernel";
            data = /incbin/("./images/zImage");
            type = "kernel";
            arch = "arm";
            os = "linux";
            compression = "none";
            load = <0x80000>;
            entry = <0x80000>;
            hash@1 {
                algo = "sha1";
            };
        };
        fdt@0 {
            description = "Flattened Device Tree blob";
            data = /incbin/("./images/zynq-pynq-z2.dtb");
            type = "flat_dt";
            arch = "arm";
            compression = "none";
            hash@1 {
                algo = "sha1";
            };
        };
    };
    configurations {
        default = "conf@1";
        conf@1 {
            description = "Boot Linux kernel with FDT blob";
            kernel = "kernel@0";
            fdt = "fdt@0";
            hash@1 {
                algo = "sha1";
            };
        };
    };
};

Create ~/pynq-z2/images directory.

Prepare bootable image.

cd ~/pynq-z2/linux-xlnx
cp arch/arm/boot/zImage ~/pynq-z2/images
cp arch/arm/boot/dts/zynq-pynq-z2.dtb ~/pynq-z2/images

cd ~/pynq-z2
mkimage -f pynq_z2_image.its ./images/image.ub

Copy the resulting image to SD card.

cp ./images/image.ub /media/boot

Boot the board, interrupt boot process and configure U-Boot boot command.

setenv bootargs "root=/dev/mmcblk0p2 rw rootwait"
setenv bootcmd "fatload mmc 0 0x1000000 image.ub && bootm 0x1000000"
saveenv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment