Code Monkey home page Code Monkey logo

zynqmp-arch's Introduction

zynqmp-arch

Arch Linux ARM for Xilinx Zynq UltraScale+ devices.

Installation

Required tools:

Step1: Prepare the Hardware Design

Use Vivado to create the hardware design. After synth, impl, and generating bitstream, export the .xsa file by following the TCL command.

Vivado% write_hw_platform -fixed -include_bit system.xsa

Step2: Build Boot Loaders and Firmwares

  1. Generate First Stage Boot Loader (fsbl) and PMU Firmware (pmufw) sources:
    $ mkdir xsct && cd $_
    $ cp /path/to/system.xsa .
    
    $ xsct -nodisp -interactive <<'EOS'
    hsi open_hw_design system.xsa
    
    hsi create_sw_design fsbl -proc psu_cortexa53_0 -app zynqmp_fsbl
    hsi set_property CONFIG.stdin  psu_uart_1 [hsi get_os]
    hsi set_property CONFIG.stdout psu_uart_1 [hsi get_os]
    hsi generate_app -app zynqmp_fsbl -dir fsbl
    hsi close_sw_design [hsi current_sw_design]
    
    hsi create_sw_design pmufw -proc psu_pmu_0 -app zynqmp_pmufw
    hsi set_property CONFIG.stdin  psu_uart_1 [hsi get_os]
    hsi set_property CONFIG.stdout psu_uart_1 [hsi get_os]
    hsi generate_app -app zynqmp_pmufw -dir pmufw
    hsi close_sw_design [hsi current_sw_design]
    EOS
    
    $ cd ..
    
  2. Patch the pmufw sources (Ultra96/Ultra96-V2):
    $ sed -i 's/^\(CFLAGS :=.*$\)/\1 -DENABLE_MOD_ULTRA96 -DULTRA96_VERSION=2/' xsct/pmufw/Makefile
    $ sed -i 's/^\(#define\s\+PMU_MIO_INPUT_PIN_VAL\).*/\1 (1U)/;
              s/^\(#define\s\+BOARD_SHUTDOWN_PIN_VAL\).*/\1 (1U)/;
              s/^\(#define\s\+BOARD_SHUTDOWN_PIN_STATE_VAL\).*/\1 (1U)/' xsct/pmufw/xpfw_config.h
    
  3. Build fsbl and pmufw:
    $ make -C xsct/fsbl
    $ make -C xsct/pmufw
    
  4. Build Xilinx/arm-trusted-firmware:
    $ mkdir arm-trusted-firmware && cd $_
    $ curl -L https://github.com/Xilinx/arm-trusted-firmware/archive/xilinx-v2022.2.tar.gz | \
        tar xz --strip-components=1 -C .
    $ sed -i 's!\s\(-Wl,\)\?--fatal-warnings\b!!g' Makefile
    
    $ CROSS_COMPILE=aarch64-linux-gnu- ARCH=aarch64 \
        make -j12 PLAT=zynqmp RESET_TO_BL31=1 ZYNQMP_CONSOLE=cadence1
    
    $ cd ..
    
  5. Build Xilinx/u-boot-xlnx:
    $ mkdir u-boot-xlnx && cd $_
    $ curl -L https://github.com/Xilinx/u-boot-xlnx/archive/xilinx-v2022.2.tar.gz | \
        tar xz --strip-components=1 -C .
    
    $ CROSS_COMPILE=aarch64-linux-gnu- ARCH=aarch64 make xilinx_zynqmp_virt_defconfig
    $ CROSS_COMPILE=aarch64-linux-gnu- ARCH=aarch64 \
        DEVICE_TREE="<your-target-device-tree-name>" \
        BL31=$PWD/../arm-trusted-firmware/build/zynqmp/release/bl31.bin \
        make -j12 u-boot.elf
    
    $ cd ..
    
  6. Create BOOT.BIN:
    $ mkdir boot && cd $_
    $ cp ../xsct/fsbl/executable.elf fsbl.elf
    $ cp ../xsct/pmufw/executable.elf pmufw.elf
    $ cp ../xsct/<bitstream_name>.bit bitstream.bit
    $ cp ../arm-trusted-firmware/build/zynqmp/release/bl31/bl31.elf .
    $ cp ../u-boot-xlnx/u-boot.elf .
    
    $ cat > boot.bif <<EOS
    all:
    {
      [destination_cpu=a53-0, bootloader]                       fsbl.elf
      [destination_cpu=pmu]                                     pmufw.elf
      [destination_device=pl]                                   bitstream.bit
      [destination_cpu=a53-0, exception_level=el-3, trustzone]  bl31.elf
      [destination_cpu=a53-0, exception_level=el-2]             u-boot.elf
    }
    EOS
    
    $ bootgen -arch zynqmp -image boot.bif -w -o BOOT.BIN
    
    $ cd ..
    

Step3: Create Bootable SD Card

  1. Partition the SD card:
    1. Start fdisk:
      $ sudo fdisk /dev/sdX
      
    2. Clear out all partitions:
      Command (m for help): o
      
    3. Create the first partition (32 MiB, FAT16, for BOOT.BIN):
      Command (m for help): n
      Partition type
      p   primary (0 primary, 0 extended, 4 free)
      e   extended (container for logical partitions)
      Select (default p): p
      Partition number (1-4, default 1): 1
      First sector (2048-15661055, default 2048):
      Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-15661055, default 15661055): +32M
      
      Created a new partition 1 of type 'Linux' and of size 32 MiB.
      
      Command (m for help): t
      Selected partition 1
      Hex code or alias (type L to list all): e
      Changed type of partition 'Linux' to 'W95 FAT16 (LBA)'.
      
    4. Create the second partition (remaining space, bootable, for Linux rootfs):
      Command (m for help): n
      Partition type
      p   primary (1 primary, 0 extended, 3 free)
      e   extended (container for logical partitions)
      Select (default p): p
      Partition number (2-4, default 2):
      First sector (67584-15661055, default 67584):
      Last sector, +/-sectors or +/-size{K,M,G,T,P} (67584-15661055, default 15661055):
      
      Created a new partition 2 of type 'Linux' and of size 7.4 GiB.
      
      Command (m for help): a
      Partition number (1,2, default 2):
      
      The bootable flag on partition 2 is enabled now.
      
    5. Write the partition table and exit:
      Command (m for help): w
      The partition table has been altered.
      Calling ioctl() to re-read partition table.
      Syncing disks.
      
  2. Format partitions:
    $ sudo mkfs.vfat -F 16 /dev/sdX1
    $ sudo mkfs.ext4 /dev/sdX2
    
  3. Download the latest Arch Linux ARM tarball and extract to the second partiton:
    $ curl -LO http://os.archlinuxarm.org/os/ArchLinuxARM-aarch64-latest.tar.gz
    $ curl -LO http://os.archlinuxarm.org/os/ArchLinuxARM-aarch64-latest.tar.gz.md5
    $ md5sum -c ArchLinuxARM-aarch64-latest.tar.gz.md5
    
    $ sudo mount /dev/sdX2 /mnt
    $ sudo bsdtar -xpf ArchLinuxARM-aarch64-latest.tar.gz -C /mnt
    $ sync
    
  4. Chroot into the target system:
    $ sudo arch-chroot /mnt /bin/bash
    
    (chroot)# uname -m
    aarch64
    
  5. Initialize the pacman keyring:
    (chroot)# pacman-key --init
    (chroot)# pacman-key --populate archlinuxarm
    
  6. Add zynqmp-arch package repository:
    (chroot)# cat >> /etc/pacman.conf <<EOS
    
    [zynqmp-arch]
    SigLevel = Never
    Server = https://zynqmp-arch.myon.info/\$arch
    EOS
    
  7. Add/Remove/Update packages:
    • Remove unneeded utilities:
      (chroot)# pacman -Rncs netctl dhcpcd net-tools
      
    • Remove pre-installed kernel:
      (chroot)# pacman -Rnd linux-aarch64
      
    • Update the system:
      (chroot)# pacman -Syu
      
    • Install the kernel (linux-zynqmp):
      (chroot)# pacman -S linux-zynqmp
      
    • Install Ultra96-V2 Wifi/BT driver (wilc3000-ultra96v2) and firmware (wilc-firmware):
      (chroot)# pacman -S wilc3000-ultra96v2 wilc-firmware
      
    • Install wpa_supplicant for connecting Wifi:
      (chroot)# pacman -S wireless_tools wpa_supplicant
      
    • Remove unrequired packages:
      (chroot)# pacman -Rncs $(pacman -Qdtq)
      
  8. Set passwords:
    (chroot)# passwd
    (chroot)# passwd alarm
    
  9. Configure /etc/fstab and exit the chroot environment:
    (chroot)# cat >> /etc/fstab <<EOS
    /dev/mmcblk0p2 /     ext4 defaults 0 1
    EOS
    
    (chroot)# exit
    
  10. Copy boot.scr to /boot:
    $ vim /path/to/zynqmp-arch/boot/boot.cmd    # modify if needed
    $ /path/to/u-boot-xlnx/tools/mkimage -c none -A arm64 -T script -d /path/to/zynqmp-arch/boot/boot.cmd boot.scr
    $ sudo mv boot.scr /mnt/boot/
    $ sudo umount /mnt
    
  11. Copy BOOT.BIN (created in step2) to the first partition:
    $ sudo mount /dev/sdX2 /mnt
    $ sudo cp BOOT.BIN /mnt
    $ sudo umount /mnt
    

Step4: Boot!

Insert the SD card and turn on the power. You will see the following messages via serial console.

Xilinx Zynq MP First Stage Boot Loader
Release 2022.1   Mar 18 2023  -  09:00:14
PMU Firmware 2022.1	Mar 18 2023   09:02:24
PMU_ROM Version: xpbr-v8.1.0-0
NOTICE:  BL31: v2.6(release):
NOTICE:  BL31: Built : 16:20:14, Mar 18 2023


U-Boot 2022.01 (Mar 18 2023 - 16:22:09 +0900)

CPU:   ZynqMP
Silicon: v3
Model: Avnet Ultra96 Rev1
Board: Xilinx ZynqMP
DRAM:  2 GiB
PMUFW:	v1.1
PMUFW no permission to change config object
EL Level:	EL2
Chip ID:	zu3eg
NAND:  0 MiB
MMC:   mmc@ff160000: 0, mmc@ff170000: 1
Loading Environment from FAT... Unable to use mmc 0:2... In:    serial
Out:   serial
Err:   serial
Bootmode: SD_MODE
Reset reason:	EXTERNAL
Net:   No ethernet found.
scanning bus for devices...
starting USB...
Bus usb@fe300000: probe failed, error -2
No working controllers found
Hit any key to stop autoboot:  0
switch to partitions #0, OK
mmc0 is current device
Scanning mmc 0:2...
Found U-Boot script /boot/boot.scr
540 bytes read in 18 ms (29.3 KiB/s)
## Executing script at 20000000
26909184 bytes read in 1931 ms (13.3 MiB/s)
41247 bytes read in 29 ms (1.4 MiB/s)
7612522 bytes read in 558 ms (13 MiB/s)
## Flattened Device Tree blob at 00100000
   Booting using the fdt blob at 0x100000
   Loading Ramdisk to 7b6bf000, end 7be0186a ... OK
   Loading Device Tree to 000000007b6b1000, end 000000007b6be11e ... OK

Starting kernel ...

[    0.000000] Booting Linux on physical CPU 0x0000000000 [0x410fd034]
[    0.000000] Linux version 5.15.36-1-zynqmp-ARCH (alarm@buildenv) (gcc (GCC) 12.1.0, GNU ld (GNU Binutils) 2.38) #1 SMP Sat Mar 18 04:38:57 UTC 2023
[    0.000000] Machine model: Avnet Ultra96-V2 Rev1
[    0.000000] earlycon: cdns0 at MMIO 0x00000000ff010000 (options '115200n8')
[    0.000000] printk: bootconsole [cdns0] enabled

(...)

Arch Linux 5.15.36-1-zynqmp-ARCH (ttyPS0)

alarm login:

zynqmp-arch's People

Contributors

tosainu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.