User Tools

Site Tools


hw:zynq:linux:petalinux:rootfs

Root filesystem

  1. Install required packages:
    qemu-user-static debootstrap binfmt-support 
  2. Setup enviroment:
    export targetdir=rootfs

    For Debian 9:

    export distro=stretch 

    Or for Debian 10:

    export distro=buster 

    Or for Debian 11:

    export distro=bullseye
    sudo mkdir $targetdir

    Ensure that $targetdir is owned by root:root.

  3. Build the root file system: download the needed .deb packages and unpack it into $targetdir:
    sudo debootstrap --arch=armhf --foreign $distro $targetdir
    sudo cp /usr/bin/qemu-arm-static $targetdir/usr/bin
    sudo cp /etc/resolv.conf $targetdir/etc
    sudo chroot $targetdir
  4. Configure and install the root filesystem by running the .deb configuration scripts inside the emulated armhf architecture (this is why qemu-arm-static is needed). For Debian 9:
    export distro=stretch 

    Or for Debian 10:

    export distro=buster 

    Or for Debian 11:

    export distro=bullseye
    export LANG=C
    /debootstrap/debootstrap --second-stage
  5. Setup APT: For Debian 11:
    cat << EOT > /etc/apt/sources.list
    deb http://ftp.ch.debian.org/debian/ $distro main contrib non-free
    deb-src http://ftp.ch.debian.org/debian/ $distro main contrib non-free
    deb http://security.debian.org/debian-security $distro-security main contrib non-free
    deb-src http://security.debian.org/debian-security $distro-security main contrib non-free
    deb http://ftp.ch.debian.org/debian/ $distro-updates main contrib non-free
    deb-src http://ftp.ch.debian.org/debian/ $distro-updates main contrib non-free
    EOT

    For older Debian:

    cat << EOT > /etc/apt/sources.list
    deb http://ftp.ch.debian.org/debian/ $distro main contrib non-free
    deb-src http://ftp.ch.debian.org/debian/ $distro main contrib non-free
    deb http://security.debian.org/debian-security $distro/updates main contrib non-free
    deb-src http://security.debian.org/debian-security $distro/updates main contrib non-free
    deb http://ftp.ch.debian.org/debian/ $distro-updates main contrib non-free
    deb-src http://ftp.ch.debian.org/debian/ $distro-updates main contrib non-free
    EOT

    Disable the recommended and suggested packages automatic installation to reduce the root file system size:

    cat << EOT > /etc/apt/apt.conf.d/71-no-recommends
    APT::Install-Recommends "0";
    APT::Install-Suggests "0";
    EOT
  6. Install required packages:
    apt update
    apt install locales dialog
    dpkg-reconfigure locales
    apt install openssh-server ntpdate resolvconf sudo less hwinfo ntp tcsh zsh vim 
  7. Set root password:
    passwd
  8. Install really required packages (if you want to use non-static address):
    apt install net-tools isc-dhcp-client
  9. Install anything you need and customize your system. Some useful set:
    apt install build-essential bash-completion time python python-pip python3 python3-pip i2c-tools gcc g++ 
  10. In order to auto-close ssh session on powerdown, install:
    apt install libpam-systemd dbus

    and check if UsePAM yes is set in /etc/ssh/sshd_config

  11. Configure interfaces:
    – assign fixed address:
    cat << EOT > /etc/network/interfaces.d/interface
    auto eth0
    iface eth0 inet static
    address 192.168.0.100
    netmask 255.255.255.0
    gateway 192.168.0.1
    dns-nameservers 192.168.0.1
    EOT
    cat << EOT >> /etc/resolv.conf
    nameserver 192.168.0.1
    EOT

    – or use dhcp:

    cat << EOT > /etc/network/interfaces.d/interface
    auto eth0
    iface eth0 inet dhcp
    EOT
    cat << EOT > /etc/resolv.conf
    EOT
  12. Turn on password authentication – uncomment PasswordAuthentication yes in
    vim /etc/ssh/sshd_config
  13. Add user
    adduser username

    and add it to sudo group:

    usermod -a -G sudo <username>
  14. Auto-mount SD card: add entry to /etc/fstab:
    /dev/mmcblk0p1 /sdcard auto defaults 0 0

    and make mount point

    mkdir /sdcard
  15. Set hostname:
    echo <linux_name> > /etc/hostname
    echo 127.0.0.1 <linux_name> >> /etc/hosts
  16. Set debug UART console:
    echo T0:2345:respawn:/sbin/getty -L ttyS0 115200 vt1000 >> /etc/inittab
  17. Install kernel modules build by PetaLinux:
    From different console:
    cd <boot_project_path>/<boot_project_name>
    sudo tar xvfp build/tmp/deploy/images/plnx-zynq7/modules-plnx-zynq7.tgz -C <rootfs_project_path>

    or

    sudo tar xvfp build/tmp/deploy/images/zynq-generic/modules-zynq-generic.tgz -C <rootfs_project_path>

    The <rootfs_project_path> should point at the root of the rootfs, i.e. at $targetdir.
    Please notice that the modules file may have different name depending on the architecture.

    In the chroot enviroment – petalinux 2018.3:

    chown -R root:root /lib
    mv /lib/modules/4.14.0-xilinx-v2018.3/ /lib/modules/`uname -r`/
    depmod
    mv /lib/modules/`uname -r`/ /lib/modules/4.14.0-xilinx-v2018.3/


    In the chroot enviroment – petalinux 2020.2:

    chown -R root:root /lib
    mv /lib/modules/5.4.0-xilinx-v2020.2/ /lib/modules/`uname -r`/
    depmod
    mv /lib/modules/`uname -r`/ /lib/modules/5.4.0-xilinx-v2020.2/
  18. Load module for generic UIO with altered compatible property:
    cat << EOT > /etc/modules-load.d/uio_pdrv_genirq.conf
    uio_pdrv_genirq
    EOT
    cat << EOT > /etc/modprobe.d/uio_pdrv_genirq.conf
    options uio_pdrv_genirq of_id=generic-uio
    EOT
  19. Create group uio_user (or any other name you want) and add user to it:
    groupadd uio_user
    usermod -a -G uio_user <username>
  20. Make /dev/uio* devices accessible for group uio_user:
    cat << EOT > /etc/udev/rules.d/90-uio.rules
    SUBSYSTEM=="uio", KERNEL=="uio[0-9]*", GROUP="uio_user", MODE="0660"
    EOT
  21. Make i2c-tools command available for the user
    usermod -a -G i2c <username>

    and add path to /usr/sbin to user .bashrc

  22. Exit and cleanup:
    exit
    sudo rm -f $targetdir/usr/bin/qemu-arm-static
  • In any case you need to modify the system
    export targetdir=rootfs
    sudo cp /usr/bin/qemu-arm-static $targetdir/usr/bin
    sudo chroot $targetdir

    Debian 10 - qemu-arm-static comes from qemu-user-static package.
    In case of network problems:

    echo "nameserver 8.8.8.8" > /etc/resolv.conf

    Do what you need and

    exit
    sudo rm -f $targetdir/usr/bin/qemu-arm-static
/services/www/http/wiki/data/pages/hw/zynq/linux/petalinux/rootfs.txt · Last modified: 2022/03/09 10:30 by jakub.moron