To create a standard Debian 12 (Bookworm) system that runs on the PYNQ-Z2, replacing the minimal PetaLinux RootFS.
Why do this?
We need tools to bootstrap a foreign architecture (ARM) filesystem on your x86 PC.
sudo apt update
sudo apt install debootstrap qemu-user-static
We will create a folder and fill it with a minimal Debian system.
mkdir -p ~/debian_work
cd ~/debian_work
sudo debootstrap --arch=armhf --foreign bookworm ./debian-rootfs
# Copy the QEMU emulator into the new filesystem
sudo cp /usr/bin/qemu-arm-static ./debian-rootfs/usr/bin/
# Enter the ARM environment
sudo chroot ./debian-rootfs /bin/bash
# -– YOU ARE NOW “INSIDE” THE ARM FILESYSTEM -–
# Complete the installation
/debootstrap/debootstrap --second-stage
While still inside the chroot (your prompt might look different), run these commands to make the system usable.
passwd
# Enter a password (e.g., 'root')
echo "pynq-debian" > /etc/hostname
echo "127.0.0.1 localhost" > /etc/hosts
echo "127.0.1.1 pynq-debian" >> /etc/hosts
/dev/mmcblk0p2 / ext4 defaults,noatime,errors=remount-ro 0 1 proc /proc proc defaults 0 0 EOF
apt install -y net-tools iputils-ping nano
# Create interface config
cat <<EOF > /etc/network/interfaces
auto lo
iface lo inet loopback
# Legacy naming (just in case)
allow-hotplug eth0
iface eth0 inet dhcp
# Predictable naming (Debian 12 default)
allow-hotplug end0
iface end0 inet dhcp
EOF
ln -s /lib/systemd/system/getty@.service /etc/systemd/system/getty.target.wants/getty@ttyPS0.service
apt update
apt install -y build-essential python3 python3-pip git sudo
apt clean
exit
# --- YOU ARE NOW BACK ON YOUR HOST PC ---
We will build only the hardware-specific components (Bootloader, Kernel, Drivers) and skip building the PetaLinux RootFS entirely.
cd ~/projects/loopback_os/
# 1. Build the Bootloader (FSBL)
petalinux-build -c bootloader
# 2. Build U-Boot
petalinux-build -c u-boot
# 3. Build the Kernel (and Modules)
petalinux-build -c kernel
# 4. Build Device Tree
petalinux-build -c device-tree
ls images/linux/modules-*.tgz# Extract modules directly to the Debian /lib/modules folder
# Note: The tarball usually contains the path "lib/modules/..." inside it.
sudo tar -xzf images/linux/modules-*.tgz -C ~/debian_work/debian-rootfs/
~/debian_work/debian-rootfs/lib/modules/ now contains a folder named something like 6.1.x-xilinx....cd ~/projects/loopback_os/
# 1. Source the SDK environment (from Step 4)
# Adjust path if your SDK is located elsewhere
source images/linux/sdk/environment-setup-cortexa9t2hf-neon-amd-linux-gnueabi
# 2. Compile the binary
# Assuming loopback_test.c is in your home directory
$CC loopback_test.c -o loopback-test
# 3. Verify it is an ARM binary
file loopback-test
# Output should say: ELF 32-bit LSB executable, ARM...
# 4. Copy binary to /usr/local/bin (standard place for user apps)
sudo cp loopback-test ~/debian_work/debian-rootfs/usr/local/bin/
# 5. Set executable permissions
sudo chmod +x ~/debian_work/debian-rootfs/usr/local/bin/loopback-test
We will use PetaLinux’s package tool to bundle our new Debian filesystem into a .wic SD card image.
cd ~/debian_work/debian-rootfs
sudo tar -czpf ~/debian_work/debian-rootfs.tar.gz .
cd ~/projects/loopback_os/
petalinux-package --wic \
--bootfiles "BOOT.BIN image.ub boot.scr" \
--rootfs-file ~/debian_work/debian-rootfs.tar.gz \
--outdir ./images/linux/debian_output
cat /etc/debian_version
# Output: 12.x
loopback-test
# Output:
# --- FPGA Loopback Test ---
# Writing 42...
# Read 43 from Register 1.
# [SUCCESS] Hardware added 1 correctly!
The default .wic file is a byte-for-byte Raw Disk Image. If PetaLinux decides the Root partition should be 4GB, the file will be 4GB, even if 3.5GB is empty space.
Controlling Partition Sizes You can define exactly how the disk is sliced by creating a Kickstart (.wks) file.
# Boot partition (FAT32) - 100MB is plenty for Kernel + Bootloader
part /boot --source bootimg-partition --ondisk mmcblk0 --fstype=vfat --label boot --active --align 4 --fixed-size 100M
# Root Partition (EXT4) - Auto-expand to fit content + 500MB extra space
part / --source rootfs --ondisk mmcblk0 --fstype=ext4 --label root --align 4 --extra-space 500M
petalinux-package --wic \
--wks custom_sd_layout.wks \
--bootfiles "BOOT.BIN image.ub boot.scr" \
--rootfs-file ~/debian_work/debian-rootfs.tar.gz \
--outdir ./images/linux/optimized_output
Compressing the Image (The Sparse Trick) Since the “empty” space in the image is just zeros, it compresses extremely well.
gzip -9 ./images/linux/optimized_output/petalinux-sdimage.wic
You have achieved the “Holy Grail” of embedded development:
You can now use apt install to add libraries, compilers, and tools, while still retaining full low-level access to your custom FPGA hardware via /dev/mem.
We have a powerful Linux computer. Now let’s enable the High-Definition in HDMI.