Skip to content

RISC-V Demo Windows Support 2024 #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 73 additions & 11 deletions risc-v-demo/Readme-compile.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ compile the application software and update the example webpage on the board.

## Requirements To Recompile the Example:

- Use Libero/SmartHLS release 2023.2
- Use Linux as development environment to recompile the example using the provided
scripts and commands in this file.
- Use Libero/SmartHLS release 2024.1
- Use the PolarFireSoC Video Kit with Production Silicon. For boards with
Engineering Sample silicon you would need to change the project parameters in
the `sev-kit-reference-design/MPFS_SEV_KIT_REFERENCE_DESIGN.tcl` file.
- Using Linux as development environment is highly recommended, as to use the provided
scripts and commands in this file. Provisions have been made for Windows users,
although there is a [known issue](#known-issues) with the `run_libero.bat` script.

## Example Setup

Expand All @@ -23,10 +24,17 @@ the board. See [Readme.md](./Readme.md).
**NOTE:** After the example is up and running, make sure to export the ``BOARD_IP``
variable with the assigned IPv4 value and connect to the right Ethernet port on
the board. This will be required to copy files over to the board from your Host PC.

If you are using Linux, open a terminal and run:
```
export BOARD_IP=192.168.2.1
```

If you are using Windows, open the command prompt (cmd) and run:
```
set BOARD_IP=192.168.2.1
```

## Source Code Directory Structure

Overall this is the directory tree of the Libero project:
Expand Down Expand Up @@ -80,7 +88,7 @@ There are a few things that can be changed in this example:
## Compiling the SmartHLS Modules and Libero Project

To compile the example from the command line make sure Libero and SmartHLS are
in the PATH in your terminal. You can confirm this by typing the following commands:
in the PATH in your terminal. On Linux, you can confirm this by typing the following commands:

```
which shls
Expand All @@ -90,16 +98,34 @@ which shls
which libero
```

On Windows, you can confirm this by typing the following commands:
```
where shls.bat
```

```
where libero
```


and compile by typing the following commands:
and compile by typing the following commands.

On Linux, use:
```
cd sev-kit-reference-design
./script_support/additional_configurations/smarthls/run_libero.sh
```

On Windows, use:
```
cd sev-kit-reference-design
./script_support/additional_configurations/smarthls/run_libero.bat
```

Notice the relative path from which the script has to be executed. The compilation
process may take about 40 min. depending on how fast the machine is.

The `run_libero.sh` script calls Libero and passes the `MPFS_SEV_KIT_REFERENCE_DESIGN.tcl`
The `run_libero` script calls Libero and passes the `MPFS_SEV_KIT_REFERENCE_DESIGN.tcl`
script along with some arguments. It is this TCL file that drives the compilation flow.
One of the steps in the flow is to call SmartHLS to compile the C++ code into
Verilog and integrate the HLS cores into the overall Libero design.
Expand Down Expand Up @@ -128,28 +154,55 @@ flow through the FPGA fabric. In the CPU data path case, only the get_frame() an
put_frame() HLS functions are used to move frames to/from DDR. In the FPGA data
path all the HLS functions are used.

There is a script that compiles the executables for both paths, just type the
following:
To compile the example from the command line, make sure the RISC-V GNU Cross-Compiler
is in the PATH. On Linux, you can confirm this by typing the following command:
```
which riscv64-unknown-linux-gnu-g++
```

On Windows, you must also add `<SHLS_INSTALLATION_DIR>\dependencies\lib\cygwin` to your path.
Then, also confirm the RISC-V GNU Cross-Compiler is in the PATH:
```
where riscv64-unknown-linux-gnu-g++
```

Now you can run script that compiles the executables for both paths by typing the
following.

On Linux, type:
```
cd sev-kit-reference-design/script_support/additional_configurations/smarthls/hls_pipeline
./compile_all.sh
```

On Windows, type:
```
cd sev-kit-reference-design/script_support/additional_configurations/smarthls/hls_pipeline
compile_all.bat
```


This will compile the code and copy the .elf files over to the board using `scp`.
Make sure the `BOARD_IP` environment variable has been setup as described in the
[Example Setup](#example_setup) section

If all goes well, then you should see the text `"ALL_DONE"` at the end. At this
point you can click on the `Start` button and the updated .elf files will be used.

The `compile_all.sh` script calls twice another script (`compile_and_copy.sh`)
that actually has all the steps to compile the application. You can use it to
The `compile_all` script calls twice another script, `compile_and_copy`,
that has all the steps to compile the application. You can use it to
only compile one path. For example, to compile only the FPGA data path type
this from the command line:
```
datapath=fpga arch=riscv_64 ./compile_and_copy.sh
```

or
```
CALL compile_and_copy.bat fpga riscv_64
```
if you're on Windows.

## Updating the On-board Website

The website files are located under the
Expand Down Expand Up @@ -199,11 +252,16 @@ applications that control the video pipeline modules described in C++.

You can change any of these files on the host machine and then copy the updated
files to the board. This can be easily done by typing the following command
(make sure the `BOARD_IP` variable is defined):
(make sure the `BOARD_IP` variable is defined). If you're using Linux, type:
```
cd sev-kit-reference-design/script_support/additional_configurations/smarthls/www
./update_website.sh
```
If you're using Windows, type:
```
cd sev-kit-reference-design/script_support/additional_configurations/smarthls/www
update_website.bat
```

## SmartHLS Directory Structure

Expand Down Expand Up @@ -292,3 +350,7 @@ Finally, the `common` directory has some common bitmaps and helper code.
[SmartHLS User Guide](https://microchiptech.github.io/fpga-hls-docs/)

[PolarFire_SoC_FPGA_H264_Video_Streaming_Over_Ethernet_Application_Note_AN4529.pdf](https://ww1.microchip.com/downloads/aemDocuments/documents/FPGA/ApplicationNotes/ApplicationNotes/PolarFire_SoC_FPGA_H264_Video_Streaming_Over_Ethernet_Application_Note_AN4529.pdf)


## Known Issues:
`run_libero.bat` does not print anything to `stdout`. This is a known issue with Libero.
44 changes: 18 additions & 26 deletions risc-v-demo/Readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# End-to-end SmartHLS + RISC-V + H264 over Ethernet Example
# End-to-end SmartHLS + RISC-V + H264 over Ethernet Example

This SmartHLS example is meant to show how to perform simple, real-time and live
video processing within an end-to-end system including the interaction and
Expand Down Expand Up @@ -143,12 +143,7 @@ update the parameters and recompile the bitstream.**

## Downloading Software Dependencies

The precompiled libraries are downloaded from this [link](https://www.microchip.com/en-us/software-library/smarthls-compiled-open-source-libraries). For convenience, there is a script that can download them. From a Linux terminal (or cygwin terminal in Windows) run the following:

```
cd precompiiled/shls_sw_dependencies
./download_precopiled_libraries.sh
```
The precompiled libraries are included with your installation of SHLS, under `<SmartHLS INSTALLATION DIR>\smarthls-library\external\vision\precompiled_sw_libraries`.

## Board Setup

Expand Down Expand Up @@ -243,8 +238,7 @@ now updated.
### Flashing the Board on Windows

On Windows, you can either use a program like [Balena's Etcher](https://etcher.balena.io)
or use the `zcat` command inside the Cygwin terminal to program the flash memory.
Cygwin is included in the SmartHLS installation.
or use a shell that can run the the `zcat`, such as Cygwin, to program the flash memory.

<ins>Using Balena Etcher<ins>

Expand All @@ -271,25 +265,23 @@ After the flashing command completes, you should disconnect the mounted drive,
by typing `Ctrl+C` in the HSS Serial Terminal. The Linux image on the board is
now updated.

<ins>Using Cygwin<ins>
<ins>Using `zcat`<ins>

To open the Host PC Terminal users should open `Cygwin` that is shipped with SmartHLS.
Open Windows File Explorer, then navigate to the SmartHLS installation directory:
`<SMARTHLS_INSTALLATION_DIR>/cygwin64/`. Then right-click on `Cygwin.bat` and
To open the Host PC Terminal users should open their shell and
choose “Run as administrator”. Administrator rights are required to flash the
Linux image to the board.

In Cygwin, enter the command `ls /dev/sd*`, and take note of what appears.
Enter the command `ls /dev/sd*`, and take note of what appears.
This will be used in a later step to help determine the device name of the eMMC flash memory.
To flash the Linux image we first need to expose the eMMC flash memory as a USB
storage device to the host PC. Make sure you have connected the `j19` USB port on
the board to your PC.

In the Cygwin terminal, type the `ls /dev/sd*` command again, and compare with
Type the `ls /dev/sd*` command again, and compare with
what you saw in the earlier step. Note which device has showed up, as it will be
the eMMC flash memory on the board.

To use `zcat` command inside the Cygwin terminal, navigate to the example folder and
To use `zcat` command, navigate to the example folder and
use the following command (replace `sdx` with the new sd device name you have for the
flash memory):

Expand Down Expand Up @@ -359,19 +351,19 @@ has been setup correctly, let's setup the software for the example.

In Section [Setup static IP address](#setup-static-ip-address) the board IPv4
address was set to `192.168.2.1`. If you changed that, then open the `setup.sh`
file and adjust the `BOARD_IP` variable accordingly. After that run the setup
script from a command-line terminal under the `precompiled` directory.

**NOTE:** If you
are using Windows, you can open a Cygwin terminal by executing the `Cygwin.bat`
file included in the SmartHLS installation, for example,
`C:\Microchip\Libero_SoC_v20XX.Y\SmartHLS-20XX.Y\cygwin64\Cygwin.bat`.


or `setup.bat` file, depending on if you're using Linux or Windows, and adjust the `BOARD_IP`
variable accordingly. After that run the setup
script from a command-line terminal under the `precompiled` directory. If you are
using Linux, run:
```
bash> cd precompiled
bash> setup.sh
```
If you are using Windows, run:
```
cd precompiled
setup.bat
```

This script will copy the OpenCV and FFMPEG libraries, the files for the control
web page, the SmartHLS application executables and some configuration files to
Expand All @@ -392,7 +384,7 @@ You should see the SmartHLS example GUI show up. Then you can click on the `Star
button and at the top-left corner you should see the Frames-Per-Second counter
changing. Otherwise, something went wrong during the setup process.

To watch the streaming video, click on the `SDP File`` button at the bottom-right
To watch the streaming video, click on the `SDP File` button at the bottom-right
corner and open it with the VLC software or any other Video player that supports
that format.

Expand Down
55 changes: 55 additions & 0 deletions risc-v-demo/precompiled/setup.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
@echo off

if not defined BOARD_IP set "BOARD_IP=192.168.2.1"

set "SSH_OPT= -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=ERROR "
FOR /F "tokens=*" %%g IN ('where shls.bat') do (SET SHLS_PATH=%%g)
for %%F in (%SHLS_PATH%) do set SHLS_ROOT_DIR=%%~dpF..\

REM Remote command execute over ssh

REM Create the necessary directories
ssh %SSH_OPT% root@%BOARD_IP% rm -rf /usr/local/shls_sw_dependencies
ssh %SSH_OPT% root@%BOARD_IP% rm -rf /srv/www/test
ssh %SSH_OPT% root@%BOARD_IP% mkdir -p /usr/local/shls_sw_dependencies
ssh %SSH_OPT% root@%BOARD_IP% mkdir -p /srv/www/test;"

REM Now copy the necessary files to the board
set "cmd=scp -r %SSH_OPT% "
set "cmd=%cmd% %SHLS_ROOT_DIR%\smarthls-library\external\vision\precompiled_sw_libraries\ffmpeg4.4-riscv_64"
set "cmd=%cmd% %SHLS_ROOT_DIR%\smarthls-library\external\vision\precompiled_sw_libraries\opencv4.5.4-riscv_64"
set "cmd=%cmd% root@%BOARD_IP%:/usr/local/shls_sw_dependencies"
echo %cmd%
%cmd%

REM Copy sudoers file
set "cmd=scp %SSH_OPT% "
set "cmd=%cmd% ../sev-kit-reference-design/script_support/additional_configurations/smarthls/www/h264/0001_daemon"
set "cmd=%cmd% root@%BOARD_IP%:/etc/sudoers.d/"
echo %cmd%
%cmd%

REM Copy website files
set "cmd=scp -r %SSH_OPT% "
set "cmd=%cmd% ../sev-kit-reference-design/script_support/additional_configurations/smarthls/www/h264 "
set "cmd=%cmd% root@%BOARD_IP%:/srv/www/test"
echo %cmd%
%cmd%

REM Copy HLS binaries
set "cmd=scp %SSH_OPT% "
set "cmd=%cmd% ./*.elf "
set "cmd=%cmd% root@%BOARD_IP%:/srv/www/test/h264/"
echo %cmd%
%cmd%

REM Update ownership
ssh %SSH_OPT% root@%BOARD_IP% chown -R daemon /srv/www/test
ssh %SSH_OPT% root@%BOARD_IP% chgrp -R daemon /srv/www/test

echo "-------"
echo "Reboot the CPU by issuing the RESET command on the HSS command prompt via UART"
echo "- or-"
echo "Just power cycle the board"


Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
proc getHlsPaths { } {
set install_loc [defvar_get -name ACTEL_SW_DIR]
set OS [lindex $::tcl_platform(os) 0]

set liberoRelease [string trim [string range [get_libero_release] 0 end] "*v" ]

# set base_path ""
if {![info exists shls_path]} {catch {set shls_path [exec which shls]}}

if {[info exists shls_path]} {
set base_path [string trimright $shls_path SmartHLS/bin/shls]
} else {
global shls_path
if { $OS == "Linux" } {
set base_path [string cat [string trimright $install_loc Libero]/SmartHLS-$liberoRelease {/}]
set ::env(PATH) [string cat $::env(PATH) ":" $base_path {SmartHLS/bin}]
Expand All @@ -27,7 +28,8 @@ proc getHlsPaths { } {
set base_path [string cat [string trimright $install_loc Designer]SmartHLS-$liberoRelease {/}]
set base_path [file normalize $base_path]
set drive [string range $install_loc 0 0]
set shls_path "$base_path/SmartHLS/bin/shls"
set shls_path "$base_path/SmartHLS/bin/shls.bat"
set shls_path [file normalize $shls_path]
set ::env(PATH) [string cat $::env(PATH) ";" $base_path {SmartHLS/bin}]
}
}
Expand All @@ -41,17 +43,10 @@ proc getHlsPaths { } {
exit 1
}

# By default on Linux bash_path is just "bash", but on Windows bash_path points to
# the cygwin version
catch {set bash_path [exec which bash]}
if { $OS != "Linux" } { set bash_path [string cat $base_path {/Cygwin64/bin/bash.exe} ]}
puts "bash_path: $bash_path"
if { ![file exists "$bash_path"] } {
puts "bash NOT found!"
exit 1
}
#return the list of paths
set pathList [list $bash_path $shls_path]
puts "SHLS PATH $shls_path"
puts "BASE PATH $base_path"
set pathList [list $base_path $shls_path]
}

proc create_config {current_config updated_config} {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ cd $hlsModuleDir
# Detect where SmartHLS and bash interpreter are located
#
set pathList [getHlsPaths]
set bash_path [lindex $pathList 0]
set shls_path [lindex $pathList 1]

puts "base_path: $base_path"
puts "shls_path: $shls_path"

set ::env(SHLS_ROOT_DIR) [file dirname $shls_path]/..
Expand All @@ -26,8 +23,14 @@ set ::env(SHLS_ROOT_DIR) [file dirname $shls_path]/..
# Call SmartHLS.
#
# - The file open is just to pipe stdout as SmartHLS compilation advances
set fid [open "| $bash_path --login -c \"cd $hlsModuleDir ; $shls_path -a hw\"" r]
while {[gets $fid line] != -1} { puts $line }
set command "$shls_path -a hw"
set fid [open "| $command" "r"]
# Print the result while execution
while {[gets $fid line] != -1} {
# Process each line of output
puts $line
}
# Close the fid
close $fid

#
Expand Down
Loading