Install Ubuntu+OpenCL on Rock Pi 4C/4B with M.2 NVME SSD & eMMC & μSD


推荐使用MobaXterm作为SSH客户端,连接Rock Pi和电脑。

0. 参考资料

[1] https://wiki.radxa.com/Rockpi4/dev/install-opencl
[2] https://wiki.radxa.com/Rockpi4/radxa-apt
[3] https://wiki.radxa.com/Rockpi4/FAQs
[4] https://iblog.isowa.io/2020/04/29/darknet-in-opencl-on-beagleboard-ai/
[ROCK Pi boards images download URL] https://github.com/radxa/rock-pi-images-released/releases

1. Install Ubuntu 20.04 on Rock Pi 4B

1.1 Use the tool Etcher to install on μSD/eMMC

  • Download OS images from https://github.com/radxa/rock-pi-images-released/releases
  • Download and install Etcher - A user friendly Image Writer from https://www.balena.io/etcher/
  • Write OS into Rock Pi
    username: rock passwd: rock

The best command to use is lsblk -f. It will list all the devices and partitions, how they are mounted (if at all) and the tree structure of the devices in the case of using LVM, crypto_LUKS, or multiple volume groups on the same drive.

1.2 Install OS on eMMC module

Ref: https://wiki.radxa.com/Rockpi4/install/eMMC

  • Download a OS image (rockpi4b_ubuntu_focal_server_arm64_20210823_2154-gpt.img) from https://github.com/radxa/rock-pi-images-released/releases
  • Insert both your μSD and the (empty) eMMC module into the Rock PI 4. Reboot it. It will boot from μSD.
  • Verify that the system has booted from μSD, which should be /dev/mmcblk0p5 and that the eMMC module is found as /dev/mmcblk1:
$ ls -l /dev/mmcblk1 
brw-rw---- 1 root disk 179, 0 Jan  6 13:25 /dev/mmcblk1

Then, write your downloaded OS image to eMMC:

$ dd if=rockpi4b_ubuntu_focal_server_arm64_20210823_2154-gpt.img of=/dev/mmcblk1

1.3 Install OS on M.2 SSD module

  • Insert both your μSD and the (empty) M.2 SSD module into the Rock PI 4. Reboot it. It will boot from μSD.
  • the M.2 SSD module is found as /dev/mmcblk1:
$ ls -l /dev/nvme0n1
brw-rw---- 1 root disk 259, 0 Mar 18  2021 /dev/nvme0n1

Then, write your downloaded OS image to SSD:

$ dd if=rockpi4b_ubuntu_focal_server_arm64_20210823_2154-gpt.img of=/dev/nvme0n1

1.4 WIFI Connection [Must operate through local host rather than SSH client]

https://wiki.radxa.com/Rockpi4/Ubuntu

$ nmcli r wifi on   #Open the WIFI
$ nmcli dev wifi    #Scan WIFI
$ nmcli dev wifi connect "wifi_name" password "wifi_password"  #Connect to WIFI network
# Error: Failed to add/activate new connection: Not authorized to control networking. 提示该错误是因为采用SSH Client进行WIFI设置,更换为开发板连接显示器进行设置即可。
$ ifconfig

2. Install OpenCL on Ubuntu 20.04(Rock Pi 4B)

2.1 Install OpenCL Runtime for Rock Pi 4 GPU on OS with kernel 5.10

参考:https://wiki.radxa.com/Rockpi4/dev/install-opencl
[2021-10-24] The newly updated Ubuntu 20.04 OS (rockpi4b_ubuntu_focal_server_arm64_20210823_2154-gpt.img) has included the Mali GPU OpenCL repos. Then, the OpenCL runtime for Mali GPUs can be installed with the following commands directly, and does not needs to add the OpenCL repos from Ubutnu 18.04.

  1. Download and Install libmali for Kernel 5.10
    See Install OpenCL for Rock Pi 4B+5b with Kernel 5.10
1 Download the Mali GPU drivers (libmali-midgard-t86x-r18p0-wayland-gbm.so) from https://github.com/JeffyCN/mirrors/tree/libmali/lib/aarch64-linux-gnu and copy it to /usr/lib
2 Registered the mali drivers as an OpenCL implementation. 
sudo mkdir -p /etc/OpenCL/vendors
sudo touch /etc/OpenCL/vendors/mali.icd
sudo vi /etc/OpenCL/vendors/mali.icd
# add /usr/lib/libmali-midgard-t86x-r18p0-wayland-gbm.so into the newly created mali.icd
sudo apt install clinfo
clinfo
3 If it outputs Number of platform 0, you should check the required libs are installed by the new kernel.
  1. Checkout with clinfo
sudo apt install ocl-icd-opencl-dev opencl-headers
sudo apt install clinfo
clinfo  #显示OpenCL设备信息
  1. Install clBLAS+OpenCV with apt
sudo apt install libclblas-dev
sudo apt install libopencv-dev
  1. Install pthreads
sudo apt install libpthread-stubs0-dev  manpages-posix-dev libblas-dev

2.2 Install OpenCL Runtime for Rock Pi 4 CPU

#安装必要的库
sudo apt-get update
export LLVM_VERSION=12
sudo apt install -y build-essential ocl-icd-libopencl1 cmake git pkg-config libclang-${LLVM_VERSION}-dev clang llvm-${LLVM_VERSION} make ninja-build ocl-icd-libopencl1 ocl-icd-dev ocl-icd-opencl-dev libhwloc-dev zlib1g zlib1g-dev clinfo dialog apt-utils libxml2-dev libclang-cpp${LLVM_VERSION}-dev libclang-cpp${LLVM_VERSION} llvm-${LLVM_VERSION}-dev 
sudo apt install libpthread-stubs0-dev  manpages-posix-dev libblas-dev

#编译安装
cd pocl-1.7     #进入pocl项目文件夹
mkdir build && cd build
#如果有多个同类型的CPU设备使用\;隔开,为这多个device(如A53和A72 CPUs)安装pocl驱动
cmake -DKERNELLIB_HOST_CPU_VARIANTS=cortex-a72\;cortex-a53 .. 
make    #编译
sudo make install #安装
sudo ldconfig   #使之生效
clinfo    #查看是否安装成功

#如果clinfo未找到ARM CPU平台,则需执行下列步骤
sudo mkdir -pv /etc/OpenCL/vendors/
sudo cp /usr/local/etc/OpenCL/vendors/pocl.icd /etc/OpenCL/vendors/

2.3 Install CLBlast from the Ubuntu Repository

CLBlast can be installed as follows on Ubuntu 20.04:

sudo apt install software-properties-common
sudo add-apt-repository ppa:cnugteren/clblast
sudo apt-get update
sudo apt install libclblast-dev

3 [Optional] Enable M.2 NVME SSD for Rock Pi 4B/4C

  • 重要提示
  1. 4C开发板可使用SD卡+Ubuntu 18.04完成,且可以单独执行sudo /usr/local/sbin/rockpi4b_upgrade_bootloader.sh命令多次进入u-boot镜像;
  2. 4B开发板使用方法1失败, 需使用Debian 9(stretch)来完成,且每刷一次u-boot镜像,就需要重新烧一次SD上的Debian OS,因为通过执行sudo /usr/local/sbin/rockpi4b_upgrade_bootloader.sh命令向新4B板上刷u-boot镜像无效。
  3. For Chinese users, you can use https://apt.setq.me instead of http://apt.radxa.com to improve download speed. https://apt.setq.me is a mirror of Radxa APT. 特别要注意的是国内镜像是https,而国外镜像是http。
  4. 参考网址:https://wiki.radxa.com/Rockpi4/install/NVME
  • Install ROCK Pi 4 u-boot image to SPI Flash
    Firstly, add Radxa APT source.
    For Debian stretch
export DISTRO=stretch-testing    #Debian 9

or Ubuntu server

export DISTRO=bionic-stable    #Ubuntu 18.04
echo "deb https://apt.setq.me/$DISTRO/ ${DISTRO%-*} main" | sudo tee -a /etc/apt/sources.list.d/apt-radxa-com.list
#注释掉国外源(否则会出错)
sudo vi /etc/apt/sources.list.d/apt-radxa-com.list
wget -O - apt.setq.me/$DISTRO/public.key | sudo apt-key add -
sudo apt-get update
sudo apt upgrade   #建议不执行
sudo apt --fix-broken install   #仅出错时执行修复命令
sudo apt install -y rockchip-fstab rockchip-overlay rockpi4-dtbo  linux-4.4-latest  
sudo apt install u-boot-rockchip
#Install necessary packages

Second,Update u-boot in uSD card or eMMC:

sudo apt install -y rockpi4b-rk-u-boot-latest    #for ROCK Pi 4B
sudo apt install -y rockpi4c-rk-u-boot-latest    #for ROCK Pi 4C

若出现下列提示,则表示安装成功,否则表示安装失败

 Overwrite bootloader to SPI Flash device.
 Writing /dev/mtd0 with content of /usr/lib/u-boot-rockpi4b/spi/uboot-trust-spi.img
 Erasing 4 Kibyte @ 3ff000 -- 100 % complete 
 Writing data to block 0 at offset 0x0
 Writing data to block 1 at offset 0x1000
 ...
 Writing data to block 1022 at offset 0x3fe000
 Writing data to block 1023 at offset 0x3ff000

Third, Edit file /boot/hw_intfc.conf. Make sure the following configuration are there:

 intfc:uart4=off
 intfc:spi1=on
 intfc:dtoverlay=spi1-flash

Reboot the machine. After login, there is a device /dev/mtd0.

 $ ls /dev/mtd*
 /dev/mtd0  /dev/mtd0ro  /dev/mtdblock0
  • Install ROCK Pi 4 system image to M.2 NVME SSD
    Power on ROCK Pi 4 and the system runs on M.2 NVME SSD. Now we need to check out some important information. Also, you need to update necessary u-boot and kernel packages.
sudo apt install -y rockchip-overlay
sudo apt install -y linux-4.4-latest rockpi4-dtbo rockpi4b-rk-u-boot-latest

Modify file, /boot/hw_intfc.conf. Uncomment these lines. Thus we can use SPI Flash device (/dev/mtd0)

intfc:uart4=off
intfc:spi1=on
intfc:dtoverlay=spi1-flash

Reboot the Pi.

  • Enable PCIe Gen2 mode to get max speed
    To enable PCIe gen2 mode, make sure you are booting on NVMe as rootfs and /boot is mounted:
├─nvme0n1p4 259:4    0   112M  0 part /boot

edit /boot/hw_intfc.conf, uncomment the line:

intfc:dtoverlay=pcie-gen2

save and reboot. You should have a higher speed on NVMe.

4 Rock Pi常用配置

Install Ubuntu Desktop

sudo apt install ubuntu-gnome-desktop  
sudo apt install xubuntu-desktop
sudo service lightdm start

Install GitHub Desktop on Linux
Website: https://github.com/shiftkey/desktop
https://meshworld.in/install-github-desktop-on-ubuntu-20-04-or-ubuntu-based-distributions/

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值