香橙派5Max系统移植
1. 需要准备的配件
(1) TF 卡,最小 16GB 容量(推荐 32GB 或以上)的 class10 级或以上的高速闪迪卡
(2) TF 卡读卡器,用于将镜像烧录到 TF 卡中
(3) HDMI 接口的显示器
(4) HDMI 转 HDMI 连接线,用于将开发板连接到 HDMI 显示器或者电视进行显示
(5) 电源适配器,Orange Pi 5 Max 建议使用 5V/5A 的 Type-C 电源供电
(6) USB接口的鼠标和键盘,只要是标准USB接口的鼠标和键盘都可以,鼠标和键盘可以用来控制Orange Pi开发板
2. 虚拟机
2.1 下载Ubuntu 22.04 amd64 版本的安装镜像
2.2 创建虚拟机
典型->安装程序光盘映像文件(选择刚刚下载的镜像)->输入信息->最大磁盘大小(根据个人选择,不要太小),将虚拟磁盘存储为单个文件->自定义硬件(我这里选择的是内存8G,处理器数量1,每个处理器内核数量6)
创建完毕后首先选择语言,推荐默认的英文,然后选择最小按照,其他选项不勾选,安装类型默认即可,有提示也继续,选择地区shanghai,然后填写用户信息,安装完毕后重启即可。
可以主机和虚拟机复制粘贴
sudo apt update
sudo apt install open-vm-tools open-vm-tools-desktop -y
2.3 获取 linux sdk 的源码(后可直接跳到2.7章)
2.3.1 从 github 下载 orangepi-build
test@test:~$ sudo apt-get update
test@test:~$ sudo apt-get install -y git
test@test:~$ git clone https://github.com/orangepi-xunlong/orangepi-build.git -b next
2.3.2 交叉编译工具链
第一次运行./build.sh会自动下载交叉编译工具链
test@test:~/orangepi-build$ ls toolchains/
gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu
gcc-arm-11.2-2022.02-x86_64-arm-none-linux-gnueabihf
gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu
gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf
gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabi
gcc-linaro-5.5.0-2017.10-x86_64_arm-linux-gnueabihf
gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu
gcc-linaro-7.4.1-2019.02-x86_64_arm-linux-gnueabi
gcc-linaro-aarch64-none-elf-4.8-2013.11_linux
gcc-linaro-arm-linux-gnueabihf-4.8-2014.04_linux
gcc-linaro-arm-none-eabi-4.8-2014.04_linux
其中编译 linux6.1 内核源码使用的交叉编译工具链为gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu
编译 u-boot v2017.09 源码使用的交叉编译工具链为gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu
2.3.3 Makefile写法
推荐在虚拟机进行交叉编译然后将生成的文件给开发板用
# 内核源码路径(你的香橙派6.1内核)
KERNELDIR := /home/pi/orangepi-build/kernel/orange-pi-6.1-rk35xx
# 当前目录
PWD := $(shell pwd)
# 交叉编译器
CROSS_COMPILE := /home/pi/orangepi-build/toolchains/gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-
# 架构:香橙派5Max是arm64
ARCH := arm64
# 要编译的驱动文件
obj-m += xxxx.o
# 目标文件
TARGET := hello
# 源文件
SRC := hello.c
all: modules app
modules:
$(MAKE) -C $(KERNELDIR) M=$(PWD) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
app:
$(CC) $(SRC) -o $(TARGET)
clean:
$(MAKE) -C $(KERNELDIR) M=$(PWD) clean
2.4 编译 u-boot
test@test:~/orangepi-build$ sudo ./build.sh
选择开发板的型号,选择 U-boot package,然后回车
查看编译生成的 u-boot deb 包
test@test:~/orangepi-build$ ls output/debs/u-boot/
linux-u-boot-legacy-orangepi5max_1.0.2_arm64.deb
test@test:~/orangepi-build$ cd output/debs/u-boot
test@test:~/orangepi_build/output/debs/u-boot$ dpkg -x linux-u-boot-legacy-orangepi5max_1.0.2_arm64.deb .
test@test:~/orangepi_build/output/debs/u-boot$ ls
linux-u-boot-legacy-orangepi5max_1.0.2_arm64.deb usr
test@test:~/orangepi-build/output/debs/u-boot$ tree usr
usr
└── lib
├── linux-u-boot-legacy-orangepi5max_1.0.2_arm64
│ ├── idbloader.img
│ ├── rkspi_loader.img
│ └── u-boot.itb
└── u-boot
├── LICENSE
├── orangepi_5_defconfig
└── platform_install.sh
3 directories, 6 files
2.5 编译 linux 内核
test@test:~/orangepi-build$ sudo ./build.sh
选择开发板的型号,选择 Kernel package,然后回车,然后会提示是否需要显示内核配置界面,如果不需要修改内核配置,则选择第一个即可,如果需要修改内核配置,则选择第二个
test@test:~/orangepi-build$ ls output/debs/linux-*
output/debs/linux-dtb-legacy-rockchip-rk3588_1.0.2_arm64.deb
output/debs/linux-image-legacy-rockchip-rk3588_1.0.2_arm64.deb
output/debs/linux-headers-legacy-rockchip-rk3588_1.0.2_arm64.deb
test@test:~/orangepi-build$ cd output/debs
test@test:~/orangepi_build/output/debs$ mkdir test
test@test:~/orangepi_build/output/debs$ cp \
linux-image-legacy-rockchip-rk3588_1.0.2_arm64.deb test/
test@test:~/orangepi_build/output/debs$ cd test
test@test:~/orangepi_build/output/debs/test$ dpkg -x \
linux-image-legacy-rockchip-rk3588_1.0.2_arm64.deb . test@test:~/orangepi_build/output/debs/test$ ls
boot etc lib linux-image-legacy-rockchip-rk3588_1.0.2_arm64.deb usr
test@test:~/orangepi-build/output/debs/test$ tree -L 2
.├── boot
│ ├── config-5.10.160-rockchip-rk3588
│ ├── System.map-5.10.160-rockchip-rk3588
│ └── vmlinuz-5.10.160-rockchip-rk3588
├── etc
│ └── kernel
├── lib
│ └── modules
├── linux-image-legacy-rockchip-rk3588_1.0.2_arm64.deb
└── usr
├── lib
└── share
2.6 编译 rootfs
test@test:~/orangepi-build$ sudo ./build.sh
选择开发板的型号,选择 Rootfs and all deb packages,然后回车,然后选择 rootfs 的类型,然后选择镜像的类型
a. Image with console interface (server)表示服务器版的镜像,体积比较小
b. Image with desktop environment 表示带桌面的镜像,体积比较大
如果是编译桌面版本的镜像还需要选择桌面环境的类型,目前 Ubuntu Jammy 主要维护 XFCE 和 Gnome 两种桌面,Ubuntu Focal 只维护 XFCE 桌面,Debian Bullseye主要维护 XFCE 和 KDE 桌面,Debian Bookwork 主要维护 XFCE 桌面
test@test:~/orangepi-build$ ls external/cache/rootfs/
jammy-xfce-arm64.f930ff6ebbac1a72108a2e100762b18f.tar.lz4
jammy-xfce-arm64.f930ff6ebbac1a72108a2e100762b18f.tar.lz4.current
jammy-xfce-arm64.f930ff6ebbac1a72108a2e100762b18f.tar.lz4.list
2.7 编译 linux 镜像
其实前面这三个编译都不用做,直接编译镜像就会把前面没做的顺带做出来。
test@test:~/orangepi-build$ sudo ./build.sh
后选择开发板的型号选择 Full OS image for flashing,然后回车,然后跟2.5的操作一样
编译的大致流程如下
a. 初始化 Ubuntu PC 的编译环境,安装编译过程需要的软件包
b. 下载 u-boot 和 linux 内核的源码(如果已经缓存,则只更新代码)
c. 编译 u-boot 源码,生成 u-boot 的 deb 包
d. 编译 linux 源码,生成 linux 相关的 deb 包
e. 制作 linux firmware 的 deb 包
f. 制作 orangepi-config 工具的 deb 包
g. 制作板级支持的 deb 包
h. 如果是编译 desktop 版镜像,还会制作 desktop 相关的 deb 包
i. 检查 rootfs 是否已经缓存,如果没有缓存,则重新制作 rootfs,如果已经缓
存,则直接解压使用
j. 安装前面生成的 deb 包到 rootfs 中
k. 对不同的开发板和不同类型镜像做一些特定的设置,如预装额外的软件包,
修改系统配置等
l. 然后制作镜像文件,并格式化分区,默认类型为 ext4
m. 再将配置好的 rootfs 拷贝到镜像的分区中
n. 然后更新 initramfs
o. 最后将 u-boot 的 bin 文件通过 dd 命令写入到镜像中
最后生成的镜像文件会放在/home/pi/orangepi-build/output/images/Orangepi5max_1.0.2_ubuntu_jammy_desktop_xfce_linux6.1.99目录下,名为Orangepi5max_1.0.2_ubuntu_jammy_desktop_xfce_linux6.1.99.img
3. 开发板
3.1 FileZilla
可以通过FileZilla把虚拟机的镜像文件传到电脑上
首先通过ip a获取虚拟机地址,然后输入用户名和密码 ,端口默认22,进行连接,如果虚拟机没有安装SSH可能会连接失败,安装命令sudo apt-get install openssh-server。
3.2 balenaEtcher

选择要烧写的镜像,选择要烧入的TF卡然后等待烧写完毕后将TF卡放到香橙派后面的卡槽中,然后连接屏幕鼠标键盘,以及电源,就可以看到香橙派的启动了。
4. 其他配置
4.1 mobaxterm

然后会提示输入密码,默认 root 和 orangepi 用户的密码都为 orangepi
成功登录系统后的显示如下图所示

4.2 adb
4.2.1 网络 adb 的使用方法
系统启动后请先确认下 adbd 已经启动了
orangepi@orangepi:~$ ps -ax | grep "adbd"
808 ? Sl 0:00 /usr/bin/adbd
3707 ttyFIQ0 S+ 0:00 grep --color=auto adbd
然后在 Ubuntu PC 上安装 adb 工具
test@test:~$ sudo apt-get update
test@test:~$ sudo apt-get install -y adb
然后使用下面的命令连接网络 adb
test@test:~$ adb connect 192.168.1.xx:5555 #IP 地址请替换为开发板的 IP 地址
* daemon not running; starting now at tcp:5037
* daemon started successfully
connected to 192.168.1.xx:5555
test@test:~$ adb devices
List of devices attached
192.168.1.xx:5555 device
4.2 使用 USB2.0 公对公数据线连接 adb
(1)用 USB2.0 公对公数据线连接开发板和电脑
(2)然后运行下面的命令将 USB2.0 接口设置为 device 模式
orangepi@orangepi:~$ sudo set_device.sh
如果 linux 系统中不存在 set_device.sh 脚本,请直接使用下面的命令:
orangepi@orangepi:~$ sudo bash -c "echo device > /sys/kernel/debug/usb/fc000000.usb/mode"
orangepi@orangepi:~$ sudo systemctl restart usbdevice
(3)然后请确认下 adbd 已经启动了
orangepi@orangepi:~$ ps -ax | grep "adbd"
808 ? Sl 0:00 /usr/bin/adbd
3707 ttyFIQ0 S+ 0:00 grep --color=auto adbd
(4)使用下面的命令查看下有没有识别到 adb 设备
test@test:~$ adb devices
List of devices attached
e0f9f71bc343c305 device
5. 修改设备树
5.1 编译设备树
进入内核目录
cd /home/pi/orangepi-build/kernel/orange-pi-6.1-rk35xx
设置工具链
export PATH=$PATH:/home/pi/orangepi-build/toolchains/gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu/bin
只编译目标 dtb
make ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- rockchip/rk3588-orangepi-5-max.dtb
如果没有权限先
sudo chown -R pi:pi /home/pi/orangepi-build/kernel/orange-pi-6.1-rk35xx
5.2 替换设备树
虚拟机
adb push arch/arm64/boot/dts/rockchip/rk3588-orangepi-5-max.dtb /home/orangepi/my_custom.dtb
开发板
sudo cp /home/orangepi/my_custom.dtb /boot/dtb/rockchip/rk3588-orangepi-5-max.dtb
sudo reboot
6. vscode通过remote-ssh远程连接虚拟机
(1)在vscode中安装Remote - SSH插件
虚拟机安装SSH
sudo apt update
sudo apt install openssh-server


ssh 虚拟机名字@虚拟机ip


(2)配置vscode
(2.1)工作区单独配置
首先通过vscode给虚拟机下这个插件

然后ctrl+shift+p输入C/C++: Edit Configurations (UI)打开可视化的配置界面




最后按 Ctrl+Shift+P,输入并执行:C/C++: Reset IntelliSense Database让 VSCode 重新解析文件。
(2.2)全局配置
打开 全局设置Ctrl + Shift + P输入:C/C++: Edit Settings (JSON)

把 settings.json 内容改成下面这段
setting.json
{
"editor.fontSize": 20,
"remote.SSH.remotePlatform": {
"192.168.xx.xxx": "linux"
},
"C_Cpp.default.includePath": [
"/home/pi/orangepi-build/kernel/orange-pi-6.1-rk35xx/include",
"/home/pi/orangepi-build/kernel/orange-pi-6.1-rk35xx/arch/arm64/include",
"/home/pi/orangepi-build/kernel/orange-pi-6.1-rk35xx/include/uapi",
"${workspaceFolder}/**"
],
"C_Cpp.default.compilerPath": "/home/pi/orangepi-build/toolchains/gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-gcc",
"C_Cpp.default.cStandard": "gnu17",
"C_Cpp.default.intelliSenseMode": "linux-gcc-arm64",
"C_Cpp.default.defines": [
"__KERNEL__",
"MODULE",
"KERNEL"
]
}
7. 将Linux内核源码传给开发板
镜像文件是不带内核源码的,如果需要,可以通过虚拟机将内核源码传给开发板
scp -r orange-pi-6.1-rk35xx orangepi@开发板IP:/home/orangepi/

浙公网安备 33010602011771号