Configuration and Debugging of PCIe Endpoint (EP Mode) on OK3588-C Linux 5.10.66 Buildroot
by yir65681 in Circuits > Linux
48 Views, 0 Favorites, 0 Comments
Configuration and Debugging of PCIe Endpoint (EP Mode) on OK3588-C Linux 5.10.66 Buildroot

This article will provide a detailed introduction on how to complete the kernel configuration, U-Boot settings, and performance testing of the EP device on the RK3588 development board, helping developers quickly set up an efficient and stable PCIe Endpoint environment.
The document testing is based on the RK3588 development board.
- During the testing, both the RC (Root Complex, host device) and the EP (Endpoint, peripheral device) are Linux devices (RK3588 development boards).
- This article focuses on describing the configuration and testing process of the EP device. For detailed configuration information, please refer to the document: Rockchip_Developer_Guide_PCIe_EP_Stardard_Card_CN.pdf.
- Software:Linux 5.10.66 4G+32G
Kernel version: OK3588 linux 5.10.66 version kernel (Android12 Linux ForlinxDesktop20.04 R5 release)
Uboot version: OK3588 protection encryption uboot (Android12 Linux ForlinxDesktop20.04 R4 release)
Hardware Connection

For the hardware connection, only one PCIe 3x4 lane male-to-male extension cable is required.
Software Settings

Applying patches
To set the PCIe-EP mode on the 3588, Rockchip officially provides the configuration reference document and source code patches for the PCIe EP mode. The document is located in the docs directory.
Note:
1. The patch file is the basic configuration for the EP card. There is also an update package in the data package. The update package contains update patches based on the base patch, mainly for optimizing the base patch and fixing issues. First, apply the base patch, and then replace the corresponding files in the SDK with the files in the update package directory.
2. Both the patch directory and the source code directory contain necessary modifications. Users can choose to directly apply the patch file or replace the corresponding source code files, either method is acceptable.
Kernel

The kernel patch file is located at:
Rockchip_PCIe_EP_Stardard_Card_20231215\patch-kernel5.10\linux_base\Patch directory\kernel
Modify the kernel according to the patch file.
Uboot
The U-Boot patch file is located at:
\u-boot
After applying the patch, replace the files in the u-boot in the update package.
Rkbin
It is a bit cumbersome to use the patch method to modify the files under rkbin. Directly replace the source code files:
Rockchip_PCIe_EP_Stardard_Card_20231215\patch-kernel5.10\linux_base\Source code directory\rkbin
After replacing the files in the folder, replace the files in the update package to the corresponding positions.
The above configurations are required for both the EP card and the RC card.
General Kernel Configuration
The following configuration items need to be completed during the actual testing process to enable the functions of the EP card. It is recommended to make modifications according to the following configurations. If there are any objections, please refer to the Rockchip official document:
Rockchip_Developer_Guide_PCIe_EP_Stardard_Card_CN.pdf
1. SRNS
In the SRNS mode, the Refclock uses its own internal clock. Set this option so that the RC card and the EP card each use their own 100M clock generators.
uboot
kernel
There is a patch file for the SRNS mode in the kernel configuration:
Rockchip_PCIe_EP_Stardard_Card_20231215\patch-kernel5.10\SRNS
You can directly make corrections under the kernel.
2. Hugepage
Hugepage is a way to allocate memory through the linux HugePageSize. The official Rockchip document recommends using the HugePage method for memory allocation to meet the requirement of large-block memory for high-speed PCIe data transmission.
The kernel configuration file defconfig:
Device tree file:
3. BAR
The setup of BAR follows the official rk documentation
uboot
kernel
The above configurations are required for both the EP card and the RC card.
Uboot General Settings
Uboot is configured in defconfig
The above configurations are required for both the EP card and the RC card.
RC Kernel Configuration
The configuration on the RC side is simple.Only need to add the configuration in defconfig.
EP Kernel Configuration
The kernel of the EP (Endpoint) side needs to be configured. Note that if the `CONFIG_STRICT_DEVMEM` option is configured in the kernel, it should be removed.
Device tree configuration
Test
1. Verification
After the configuration in the above steps, the following phenomena should be observed on the development board:
RC Side
PCIe-related nodes can be seen under the /dev directory.
Successful registration and usage of the rkep driver can be queried.
EP Side
PCIe dependent nodes can be seen under dev.
2. Demo Test
There are many test demos in the data package provided by Rockchip. Here, the speed-testing demo is selected:
Rockchip_PCIe_EP_Stardard_Card_20231215\examples\PCIe_speed_test
This demo needs to be compiled under Linux. Copy the compiled executable file to the development board for testing.
According to the information in the README.txt file in the examples directory, the resources required by the demo need to be downloaded.
Considering that the dynamic libraries and resources on which the test application depends are relatively large, a resource directory is created to specifically store the test resources.
Download the resource directory to the examples/ directory via Baidu Netdisk.
Link: https://pan.baidu.com/s/1dyXEXMUfWREZii0kHbkOFw?pwd=u1h7
Extraction code: u1h7
Directory Structure
After downloading the resources, copy the entire resource package to any directory in the Linux source code. Configure the compilation toolchain in the compilation tool script according to the README.txt document in the speed-testing demo.
The main modifications are as follows:
!!! The path of the above toolchain should be modified according to the actual path in your development environment !!!
Execute the two .sh files respectively in the script directory, and you will get the speed-testing demo executable files for the RC (Root Complex) side and the EP (Endpoint) side.
Copy them to the corresponding boards for speed testing.
The README.txt in the speed-testing demo folder tells you how to use the executable files:
Rockchip_PCIe_EP_Stardard_Card_20231215\examples\PCIe_speed_test
EP side test script running
RC side test script running
Actual speed-testing results on the EP side
Actual speed-testing results on the RC side
Problems
1. The board fails to enter the system
It is found that the board gets stuck during startup. The phenomenon on the terminal interface is as follows:
After waiting for some time, the blue light on the core board flashes abnormally.
This is because the configuration in RK3588MINIALL.ini was modified during the configuration process.
It should be set to all 0s by default.
If the EP card still cannot enter the system after trying the above method, try to connect the RC card.
2. An error occurs when using the speed-testing demo on the RC side
The above error is summarized as a problem that the program encounters when allocating huge-page memory.
At this time, you can check the number of hugepages:
cat /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages
You can see that the number is 0. Set a number for it using echo:
echo 1000 > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages
This can solve the above error.
PS: This configuration also needs to be checked on the EP side.
The above information can also be found in /proc/meminfo:
cat /proc/meminfo | grep Huge
If it is 0, you need to set the number of hugepages.