Thursday, April 6, 2023

RISC-v on ZC706 EVB - Part III: build w/ Win11/WSL2/Vivado 2016.2

 Continue my journey with of RISC-v on ZC706 Evaluation Board - Part II. Finally get some spare time can back on this. Since it may need some effort to get PetaLinux setup and debug the executable issue, I changed my focus to setup Vivado 2016.2 on another Windows 11 + WSL2 PC. Luckily Xilinx_Vivado_SDK_2016.2_0605_1.tar.gz is just around 11.1GB, even much smaller than 2016.4 package. And I chose WSL2 as on Windows 11 it support GUI, and would be less hassle do the build under Linux. However, I do run into several problem with fresh installed WSL2:

  • Got 'libawt_xawt.so: libXrender.so.1: cannot open shared object file: No such file or directory' when running Vivado xsetup to install Vivado. Search from internet shows I need to do "sudo apt-get install libxrender1" , and that did work. Then hit next issue as below:
  • Got 'libawt_xawt.so: libXtst.so.6: cannot open shared object file: No such file or directory', turns out that I need do 'sudo apt install libxtst6'. Then next issue:
  • Got 'libawt_xawt.so: libXi.so.6: cannot open shared object file: No such file or directory', need to do "sudo apt install libxi6"

With that, xsetup is up and running. For installing option, I selected Vivado HL Design Edition as the WebPACK one might not have all features I need, and I don't need DSP support (for choices, may refer to Xilinx 2016.4 WebPACK Vivado and SDK Install on Windows 7 SP1 (css-techhelp.com) for more detail). Then the installation stuck with the flash screen for quite long time, which made me doubt whether it hanged or crashed. Luckily, it is not. After a while, the install option diag shows up, and I can select and continue the installation. At beginning I checked the option for creating Desktop shortcut, but not sure where it will go as I don't have Ubuntu Desktop installed. The installation not proceeding after a while, with log file name showed in console. By checking the log, likely there is issue with the shortcut. So re-run the installer, this time, not select the shortcut and create group box, however, installer still hangs, and log file shows it probably is running tcl script for generating the device list:

Executing script Generating installed device list: /home/Suser/Vivado/2016.2/bin/vivado [-nolog, -nojournal, -mode, batch, -source, /home/$user/.xinstall/Vivado_2016.2/scripts/xlpartinfo.tcl, -tclargs, /home/$user/Vivado/2016.2/data/parts/installed_devices.txt]
Tried 'sudo apt install tcl' but doesn't help. If manually run about  line, will get:
application-specific initialization failed: couldn't load file "librdi_commontasks.so": libncurses.so.5: cannot open shared object file: No such file or directory

Per this link, need to do: sudo apt install libncurses5

With that, I successfully installed Vivado 2016.2 under WSL. Then I start to pull fpga-zynq.git and build with it as described in fpga-zynq: 2) Pushing your rocket modifications to the FPGA, steps as:
  • Start WSL Ubuntu terminal
  • git clone https://github.com/ucb-bar/fpga-zynq.git to /mnt/c/workspace which can be easily accessed from Windows
  • Run sudo apt install openjdk-8-jdk-headless; sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/java-8-openjdk-amd64/bin/java" 1
  • There is a strange thing happened. To install JDK8 under WSL, sometime would need to do sudo apt update, but somehow WSL give me an error as: "Release file for http://archive.ubuntu.com/ubuntu/dists/jammy-updates/InRelease is not valid yet (invalid for another 1d 3h 20min 52s). Updates for this repository will not be applied.". https://itsfoss.com/fix-repository-not-valid-yet-error-ubuntu/ gives me a clue on this: my WSL clock is skewed for some reason and it is lagged more than 1 day. So have to issue 'wsl --shutdown' then restart WSL to fix the problem
  • For fresh WSL, would need do: sudo apt install make
  • cd to git repo zc706 subfolder, run:
    make init-submodules
  • Run below command, may get a lot of warn and error related to sbt, probably just ignore them:
    make rocket
  • If see Cannot run program "dtc", do: sudo apt install device-tree-compiler
  • Once 'make rocket' successfully completed, run Vivado setting script in the installation path such as: source ~/Vivado/2016.2/settings64.sh
  • run  make project, and soon will see something like 'Wrote  : </mnt/c/code/fpga-zynq/zc706/zc706_rocketchip_ZynqFPGAConfig/zc706_rocketchip_ZynqFPGAConfig.srcs/sources_1/bd/system/system.bd>' at the end. 'system.bd' is folder contains system folder.
  • Now run
    make fpga-images-zc706/boot.bin
    will see output like:

Successfully read diagram <system> from BD file </mnt/c/code/fpga-zynq/zc706/zc706_rocketchip_ZynqFPGAConfig/zc706_rocketchip_ZynqFPGAConfig.srcs/sources_1/bd/system/system.bd>

Verilog Output written to : /mnt/c/code/fpga-zynq/zc706/zc706_rocketchip_ZynqFPGAConfig/zc706_rocketchip_ZynqFPGAConfig.srcs/sources_1/bd/system/hdl/system.v
Verilog Output written to : /mnt/c/code/fpga-zynq/zc706/zc706_rocketchip_ZynqFPGAConfig/zc706_rocketchip_ZynqFPGAConfig.srcs/sources_1/bd/system/hdl/system_wrapper.v
Wrote  : </mnt/c/code/fpga-zynq/zc706/zc706_rocketchip_ZynqFPGAConfig/zc706_rocketchip_ZynqFPGAConfig.srcs/sources_1/bd/system/system.bd>
INFO: [BD 41-1029] Generation completed for the IP Integrator block proc_sys_reset_0 .
WARNING: [xilinx.com:ip:processing_system7:5.5-1] system_processing_system7_0_0: The Zynq BFM requires an AXI BFM license to run. Please ensure that you have purchased and setup the AXI BFM license prior to running simulation with this block. Please contact your Xilinx sales office for more information on purchasing this license
INFO: [BD 41-1029] Generation completed for the IP Integrator block processing_system7_0
 

...

Attempting to get a license for feature 'Synthesis' and/or device 'xc7z045'
WARNING: [Common 17-348] Failed to get the license for feature 'Synthesis' and/or device 'xc7z045'
3 Infos, 1 Warnings, 0 Critical Warnings and 1 Errors encountered.
synth_design failed
ERROR: [Common 17-345] A valid license was not found for feature 'Synthesis' and/or device 'xc7z045'. Please run the Vivado License Manager for assistance in determining
which features and devices are licensed for your system.
Resolution: Check the status of your licenses in the Vivado License Manager. For debug help search Xilinx Support for "Licensing FAQ".
INFO: [Common 17-206] Exiting Vivado at Fri Apr  7 19:48:34 2023...
[Fri Apr  7 19:48:34 2023] synth_1 finished
wait_on_run: Time (s): cpu = 00:00:00.15 ; elapsed = 00:00:28 . Memory (MB): peak = 1186.469 ; gain = 0.000 ; free physical = 241 ; free virtual = 1777
# launch_runs impl_1 -to_step write_bitstream
ERROR: [Common 17-70] Application Exception: Failed to launch run 'impl_1' due to failures in the following run(s):
synth_1
These failed run(s) need to be reset prior to launching 'impl_1' again.

...

Likely would need a license to run synth and impl. As mentioned at https://dzone.com/articles/create-a-bootbin-program-an-sd-card-and-boot-a-zc7, The ZC706 has an XC7Z045-2FFG900 C SoC. This chip is not supported in WebPACK (see [link]) like the chip on the ZC702. You can get a 30-day license at [link].

Next, might see 'bootgen: command not found'. This could happen if user didn't run the Xilinx Vivado settings64.sh shell script, or XiLinx SDK wasn't installed. If the SDK is installed, bootgen should be available under Vivado/2016.2/bin folder. Without SDK, make boot.bin would fail. So need to select SDK during installation as below (I only select Zynq-7000 to save space and installing time. Also, not select Acquire or Manage a License Key as I will deal with that separately):

If already have Vivado installed, then it won't allow you to re-install at same location. Would need to launch Vivado, then goto help->Add Design Tools or Devices...->Check SDK and click install.

After all this, finally can successfully build the boot.bin. With this boot.bin copied to SD card, it can successfully boot the PetaLinux (connect the Uart USB, and use root/root to login). But running "./fesvr-zynq pk hello" still get "ERROR: No cores found".

Also tried following the prompted message for the problem 5 mentioned in Risc-v on zc706 evaluation board - Part I: ERROR: [BD_TCL-109] This script was generated using Vivado <2016.2> and is being run in <2022.1> of Vivado. Please run the script in Vivado <2016.2> then open the design in Vivado <2022.1>. Upgrade the design by running "Tools => Report => Report IP Status...", then run write_bd_tcl to create an updated script.

I opened the project file zc706_rocketchip_ZynqFPGAConfig.xpr created by 2016.2 Vivado with 2022.1 Vivado, and keep the project as Read-only while the new version Vivado prompt for choice. It would still treat the board type as error:

  • [Board 49-67] The board_part definition was not found for xilinx.com:zc706:part0:1.0. This can happen sometimes when you use custom board part. You can resolve this issue by setting 'board.repoPaths' parameter, pointing to the location of custom board files. Valid board_part values can be retrieved with the 'get_board_parts' Tcl command.

For this, no need to update update zc706/src/tcl/zc706_rocketchip_ZynqFPGAConfig.tcl, but update the project xpr file directly as it is XML format, just update <Option Name="BoardPart" Val="xilinx.com:zc706:part0:1.0"/> to xilinx.com:zc706:part0:1.4. For above update instruction, I cannot find 'write_bd_tcl' script, but did find there is a man doc as Vivado/2022.1/doc/eng/man/write_bd_tcl. And 'Report IP' now is under menu/Report but not Tools. Open the Tcl Console (menu/Window->Tcl Console), issue command write_bd_tcl with output filename. It may prompt:  ERROR: [BD 5-229] Please open or create a block design first. So need to select from left Flow Navigator->IP INTEGRATOR-> Open Block Design before running the write_bd_tcl command.



Saturday, March 4, 2023

CodeFormer: AI Face Enhancement, 图片人脸智能增强

最近看到这个由周尚长博士领队的几位南洋理工大学S-Lab成员开发的开源程序,用来恢复和增强照片中的人脸,效果惊人。可以点进以下3分半的you-tube看一下就知我所言不虚(包括1927 Fifth Solvay International Conference群英会的照片)。

 

Face Restoration

Face Color Enhancement and Restoration

Face Inpainting

 

https://shangchenzhou.com/projects/CodeFormer/ 是项目主页,有些简单介绍。code的github网址是:https://github.com/sczhou/CodeFormer,附有简单的安装使用说明,除了要git clone代码,和下载样本数据外,主要是要设置conda。关于conda, 可参见:学习TensorFlow - 设置Python环境。Miniconda就足够了(参见https://stackoverflow.com/questions/45421163/anaconda-vs-miniconda)

注意,CUDA不是必须的,像我的电脑是AMD APU,不支持nVida的CUDA,也可以完美的运行CodeFormer。

当你用CodeFormer转化自己的照片时,最初可能并不会注意到转化后的照片有什么不一样,记住,一定要zoom in,放大再放大,看细节,一定有惊喜。

除了增强照片,Codeformer还支持video的人脸增强(需要引入FFMpeg)。有空要研究研究怎样加入AMD ROMc的支持,加快在我的AMD计算机上的处理速度。

 

 

Wednesday, January 4, 2023

Setup ssh tunnel/port forward on Windows

 Reference link:

https://docs.oracle.com/cd/E24628_01/install.121/e22624/preinstall_req_cygwin_ssh.htm

https://linuxize.com/post/how-to-setup-ssh-tunneling/

Make sure for Cygwin, has openssh installed. Then run
ssh-host-config

*** Query: Enter the value of CYGWIN for the daemon: [] binmode ntsec

Then run this to start the service: cygrunsrv -S sshd

May need to change Windows firewall setting to open the port 22.

 

SSH tunneling or SSH port forwarding is a method of creating an encrypted SSH connection between a client and a server machine through which services ports can be relayed.

There are three types of SSH port forwarding:

  • Local Port Forwarding. - Forwards a connection from the client host to the SSH server host and then to the destination host port.
  • Remote Port Forwarding. - Forwards a port from the server host to the client host and then to the destination host port.
  • Dynamic Port Forwarding. - Creates a SOCKS proxy server that allows communication across a range of ports.

Friday, December 30, 2022

RISC-v on ZC706 Evaluation Board - Part II

With RISC-v on ZC706 Evaluation Board - Part I, I was successfully building the boot.bin. I thought I got the work done, but realized it was not when I tried the binary I made: after replaced the 'boot.bin' on the SD card with the one I built, the Init LED turns to green for about 1 second, then turns to red, no output from UART port, so something is wrong. Actually there is a warning while making the boot.bin:

[WARNING]: Partition FSBL.elf.0 range is overlapped with partition rocketchip_wrapper.bit.0 memory range
[INFO]   : Bootimage generated successfully

Would need to check the partition layout.

Beside this problem, I'm seeing another issue when playing more, with the fetched SD binaries: running "./fesvr-zynq pk hello" got "ERROR: No cores found", same error for any command with fesvr-zynq. Search the symptom returned same issue:

https://github.com/chipsalliance/rocket-chip/issues/1390

https://github.com/ucb-bar/fpga-zynq/issues/87

Likely there is an update for zedboard but not for zc706. So likely will have to build this fesvr-zynq by myself. Run 'make fesvr-zynq' lead me realized that all sub-modules of rocket-chip/riscv-tools didn't get cloned, especially 'riscv-fesvr' which is needed for making fesvr-zynq. With that repo cloned, the build did make some progress, but eventually would complain cannot find 'arm-xilinx-linux-gnueabi-g++'. Though I did find the executable under Xilinx Vitis, running environment setup script, or even adding the path of the executable won't help, as it needs the PetaLinux build environment, which seems hasn't been fully integrated to Xilinx Vitis. Have to download PetaLinux Tools from Xilinx site.

Will update this once get some progress on this.

Below is quoted from https://github.com/ucb-bar/fpga-zynq

Overview of System Stack

Our system will allow you to run a RISC-V binary on a rocket core instantiated on a supported Zynq FPGA. This section will outline the stack of all of the parts involved and by proxy, outline the rest of the documentation. Going top-down from the RISC-V binary to the development system:

Target Application (RISC-V binary) will run on top of whatever kernel the rocket chip is running. Compiled by riscv-gcc or riscv-llvm.

RISC-V Kernel (proxy kernel or RISC-V Linux) runs on top of the rocket chip. The proxy kernel is extremely lightweight and designed to be used with a single binary linked against Newlib while RISC-V Linux is appropriate for everything else.

Rocket Chip (rocket core with L1 instruction and data caches) is instantiated on the FPGA. Many of its structures will typically map to various hard blocks including BRAMs and DSP slices. It communicates to the host ARM core on the Zynq via AXI.

Front-end Server (riscv-fesvr) runs on the host ARM core and provides an interface to the rocket chip running on the FPGA (connected via AXI).

Zynq ARM Core (actually dual Cortex A9) runs Linux and simplifies interfacing with the FPGA.

FPGA Board (Zybo, Zedboard, or ZC706) contains the Zynq FPGA and several I/O devices. At power on, the contents of the SD card are used to configure the FPGA and boot Linux on the ARM core.

External Communication (TTY over serial on USB or telnet/ssh over ethernet) allows the development system to communicate with the FPGA board.

Development System (PC with SD card reader) generates the images to configure the FPGA.

Tuesday, December 27, 2022

RISC-v on ZC706 Evaluation Board - Part I

Continue my journey with RISC-v on FPGA. This time, I got a Xilinx Zynq-7000 SoC ZC706 Evaluation kit. The board is at least 7 years old. The FPGA has two Cortex-a9 cores. And there is https://github.com/ucb-bar/fpga-zynq which has everything needed to get RISC-v running on several Zynq FPGA boards, including ZC706. Again, this project has no update for more than four years now, so can foresee something might be out-of-date. Making this blog just for reference.

The fpga-zynq github repo has pretty good documentation. It's very easy to follow the Quick Instruction, just fetch images and load them to SD card. Setup the boot mode of the board, and all done. The only issue I had run into is related to the SD card. There are several links for FPGA boot from SD issue, like https://support.xilinx.com/s/question/0D52E00006hpPfLSAU/sd-card-boot-problems-zc706-board and https://support.xilinx.com/s/article/59476. In general, need to make sure all needed files are properly copied to SD card. For my case, the SD card reader I used first has some weird issue. After I used a newer SD card reader, everything goes very smoothly.

For the 2nd step, pushing Rocket modification to FPGA, I got several problems.

  • Problem 1: the instruction mentioned user can pick own rocket-chip directory by override ROCKET_DIR. Since the freedom repo for Arty A7 contains rocket-chip repo, I was thinking to re-use that to reduce the time and disk usage. However, the 'make rocket' command will run into this error: 
        module not found: edu.berkeley.cs#chisel3_2.12;3.2-SNAPSHOT

The error is like https://github.com/ucb-bar/chiseltest/issues/72 and edu.berkeley.cs#chisel_2.11;3.1-SNAPSHOT: not found · Issue #518 · chipsalliance/chisel3 · GitHub. One post mentioned need to update the dependency from chisel2 to chisel3. I cannot figure out a quick way to get around this, so gave up on this. Instead, remove the setting of ROCKET_DIR. 'make init-submodules' will download rocket_chip repo, and the not found of edu.berkeley.cs:chisel3_2.12:3.3-SNAPSHOT is gone.

  • Problem 2: 'make rocket' successfully created rocket_chip.stamp file, but reported no rule to make testchipip.stamp. This is a weird one, as the Makefile and common/Makefrag file does not have testchipip.stamp as target. Turns out due to the line-ending of generate-pkg-mk.sh file, the shell script failed to finish some work which leads to issue for EXTRA_PACKAGES=testchipip. One problem is the make command line doesn't generate meaningful message pointing to the shell script problem. I figured out that by turning on -d option for make, and run the script manually. For fixing this, do: "git config --global core.autocrlf false" then do git checkout to apply the setting.
  • Problem 3: Seeing error
    Missing dependency 'object java.lang.Object in compiler mirror', 
    required by /.m2/repository/org/scala-lang/scala-library/2.10.4/scala-library-2.10.4.jar(scala/package.class)
    
    JDK version not compatible with scala. As replied for https://stackoverflow.com/questions/53942248/maven-error-missing-dependency-java-lang-object-required-by-scala, each version of scala only works with certain version of JDK (refer to docs.scala-lang.org/overviews/jdk-compatibility/overview.html). For this case, have to stick with JDK8:
sudo apt install openjdk-8-jdk-headless
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/java-8-openjdk-amd64/bin/java" 1
sudo update-alternatives --config java
  • Problem 4: "make project" will need to invoke Vivado. On Windows, this can be achieved by running under Cygwin with Vivado executable added to PATH. However, on both Windows and Linux, I'm seeing same error as:
    ERROR: [Board 49-71] The board_part definition was not found for xilinx.com:zc706:part0:1.0. The project's board_part property was not set, but the project's part property was set to xc7z045ffg900-2. Valid board_part values can be retrieved with the 'get_board_parts' Tcl command. Check if board.repoPaths parameter is set and the board_part is installed from the tcl app store.
    Per this, this and this, as the instruction/repo is for Vivado 2016 but I'm using 2022 version, would need to update the tcl script for creating Vivado project, modify the line like this: 
    1. set_property board_part xilinx.com:zcu102:part0:3.0 [current_project]
    to: xilinx.com:zcu102:part0:3.1
    For my case, would need to update zc706/src/tcl/zc706_rocketchip_ZynqFPGAConfig.tcl, which has line as: set_property "board_part" "xilinx.com:zc706:part0:1.0" $obj
    Run get_board_parts within the tcl console shows xilinx.com:zc706:part0:1.4. So update the tcl script, run "rm -rf zc706_rocketchip_ZynqFPGAConfig" first, then run "make project" again.
    Then run into problem 5:
    ERROR: [BD_TCL-109] This script was generated using Vivado <2016.2> and is being run in <2022.1> of Vivado. Please run the script in Vivado <2016.2> then open the design in Vivado <2022.1>. Upgrade the design by running "Tools => Report => Report IP Status...", then run write_bd_tcl to create an updated script.
    This error is from zc706/src/tcl/zc706_bd.tcl. With 2022.1, "Report" is a separate menu item beside tools, and it only shows up after a project is opened. Really don't want to spend hours to install the 2016.2 version. So I just modified the zc706_bd.tcl to set the version as 2022.1 which matches the version I'm using. With that, there is some critical warning, like this: "CRITICAL WARNING: [BD 41-737] Cannot set the parameter PCW_M_AXI_GP0_FREQMHZ on /processing_system7_0. It is read-only.", but the project (.xpr) file did get created successfully. 
     
    Run "make fpga-images-zc706/boot.bin" will do synthesis and implementation with the project. This somehow not working for me, because of the bit file is missing. Likely this is due to my Vivado installation does not have valid license for creating bit for zynq. Opened the project from Vivado which has valid license, and generate bit file there. It got successfully generated on both Linux and Windows Vivado. However, when run "make fpga-images-zc706/boot.bin" again, the boot.bin would be successfully generated on Linux but not on Windows. Error for Windows/Cygwin run is like this:

    ln -sf ../../zc706_rocketchip_ZynqFPGAConfig/zc706_rocketchip_ZynqFPGAConfig.runs/impl_1/rocketchip_wrapper.bit fpga-images-zc706/boot_image/rocketchip_wrapper.bit
    cd fpga-images-zc706; bootgen -image boot.bif -w -o boot.bin
    ...
    [ERROR]  : Cannot read BIT file - boot_image/rocketchip_wrapper.bit

    The bit file under impl_1 did exist, however, 'ln -sf' may create a junction point on NTFS, which might not work for Xilinx Windows bootgen. To get around this, delete the symbolic link, copy the bit file directly to fpga-images-zc706/boot_image folder, then CD to fpga-images-zc706 folder, and run "bootgen -image boot.bif -w -o boot.bin" directly (don't try the make command, as it will create the soft symbolic link again), and this works under Cygwin.
     
    So finally I got the binary built on both Linux and Windows/Cygwin.  Lesson learned is: for FPGA development, better do everything on Linux but not Windows: too many hassle.

    At this point, I thought I had it completed, but in fact, it is not. So  <to be continue>