https://linux-sunxi.org/Allwinner_Nezha
opensbi
sudo apt install gcc-riscv64-linux-gnu
git clone https://github.com/riscv-software-src/opensbi.git
cd opensbi
make CROSS_COMPILE=riscv64-linux-gnu- PLATFORM=generic FW_PIC=y -j$(nproc)
cd ..
uboot
sudo apt install bison swig flex libpython3.11-dev python3-setuptools # libpython3.11-dev 要对应电脑 python 的版本,不然会报找不到 Python.h
git clone https://github.com/smaeul/u-boot.git -b d1-wip
cd u-boot
make lichee_rv_dock_defconfig
# make menuconfig
make CROSS_COMPILE=riscv64-linux-gnu- OPENSBI=../opensbi/build/platform/generic/firmware/fw_dynamic.bin -j$(nproc)
cd ..
kernel 的设备树使用的是 uboot 传递的,如果要改这个设备树就要重新编译 uboot 并烧录。如果 sd 卡已经分区,烧录之前要执行sudo sgdisk /dev/sdc -o
清除分区(不会破坏数据),再烧录 uboot。再重新执行一次分区命令分区就回来了,数据也可以访问
kernel linux
git clone https://github.com/smaeul/linux.git -b d1/all
# 手动添加 licheerv_defconfig:https://github.com/jamesgraves/licheerv-debian-linux/blob/main/licheerv_linux_defconfig
cd linux/
make ARCH=riscv licheerv_defconfig
# make ARCH=riscv menuconfig
make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- KCFLAGS='-fno-asynchronous-unwind-tables -fno-unwind-tables' -j$(nproc)
cd ..
extlinux.conf
默认使用 uboot 的设备树
label default
linux /Image
append root=/dev/mmcblk0p2 rootwait console=ttyS0,115200 earlycon=sbi ignore_loglevel init=/lib/systemd/systemd
rootfs
sudo apt install mmdebstrap qemu-user-static
sudo mmdebstrap --architectures=riscv64 unstable rootfs "deb http://mirrors.tuna.tsinghua.edu.cn/debian unstable main"
sudo chroot ./rootfs
passwd
apt update
apt install network-manager # nmcli 连 wifi
exit
rootfs镜像
dd if=/dev/zero of=rootfs.img bs=1G count=1
sudo mkfs.ext4 rootfs.img
mkdir rootfs_mount
sudo mount rootfs.img rootfs_mount
sudo cp -rfp rootfs/* rootfs_mount
sudo umount rootfs_mount
rm -r rootfs_mount
sudo e2fsck -f rootfs.img
sudo resize2fs -M rootfs.img
烧录到sd卡
# 分区
sudo sgdisk /dev/sdc -o \
--new=1:4096:69631 --change-name=1:boot \
--new=2:69632: --change-name=2:rootfs \
-p
# 32MiB、剩余全部
# 格式化
sudo mkfs.vfat /dev/sdc1
# uboot
sudo dd if=./u-boot/u-boot-sunxi-with-spl.bin of=/dev/sdc seek=256
sync
# linux
sudo mount /dev/sdc1 /mnt
sudo mkdir /mnt/extlinux
sudo cp ./linux/arch/riscv/boot/Image /mnt/
sudo cp ./extlinux.conf /mnt/extlinux/
sync
sudo umount /mnt
# rootfs
sudo dd if=./rootfs.img of=/dev/sdc2 bs=4096
sync
恢复分区大小
# 如果 rootfs 分区被电脑自动挂载了需要先用 umount 卸载
sudo e2fsck -f /dev/sdc2
sudo resize2fs /dev/sdc2
安装模块
sudo mount /dev/sdc2 /mnt
cd linux
sudo make modules_install ARCH=riscv INSTALL_MOD_PATH=/mnt KERNELRELEASE=6.1.0-rc3+
# 6.1.0-rc3+ 来自于 uname -r,以实际为准
sudo rm /mnt/lib/modules/6.1.0-rc3+/build
sudo rm /mnt/lib/modules/6.1.0-rc3+/source
sudo umount /mnt
cd ..
wifi
git clone https://github.com/lwfinger/rtl8723ds.git
# 在 Makefile 里添加这行
KBUILD_CFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables
cd rtl8723ds
make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- KSRC=../linux modules -j$(nproc)
cd ..
sudo mount /dev/sdc2 /mnt
sudo cp ./rtl8723ds/8723ds.ko /mnt/lib/modules/6.1.0-rc3+/kernel/drivers/net/wireless/
sudo depmod -a -b /mnt 6.1.0-rc3+
sudo umount /mnt
其他
nmcli r wifi on # 打开 wifi
nmcli dev wifi # 扫描 wifi,按 q 退出页面
nmcli dev wifi connect "ChinaNet-45F7" password "12345678"
date -s '2024-04-26 19:07:00' # 设置为实际时间,如果系统时间和实际时间误差过大就访问不了 apt update
apt update
- 设置时区:ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
- apt https 支持:ca-certificates
- ntp 自动同步支持:chrony
问题
- kernel_comp_addr_r or kernel_comp_size is not provided!
extlinux.conf 的 Image 不要 .gz - mmc_load_image_raw_sector: mmc block read error
使用sudo sgdisk /dev/sdc -o
清除 sd 卡的分区信息,再重新烧录 uboot,再重新分区
设备树
在 uboot 里新加了个设备树,使用了 rgb800x480 7 寸屏,电阻触摸 ic 是 ns2009,tsc2007 驱动是兼容的,ti,x-plate-ohms 是 x 方向的电阻,一个通用值就行,用于判断按下抬起,其 gpios 是笔中断
linux 里要开启 lcd pwm,input event interface,tsc2007,i2c,图形方面可能要开启 drm?不太确定,摸索过程中开启了不少相关功能
uboot 里的 d1 设备树和 d1s 有交叉,有点乱,我直接把 linux 里的复制过来统一加了个new-
的前缀,看起来方便,内容是一致的
u-boot/configs/lichee_rv_dock_defconfig 里的 CONFIG_DEFAULT_DEVICE_TREE 的值改成"new-sun20i-d1-lichee-rv-dock-ext"
,u-boot/arch/riscv/dts/Makefile 里加dtb-$(CONFIG_TARGET_SUN20I_D1) += new-sun20i-d1-lichee-rv-dock-ext.dtb
new-sun20i-d1-lichee-rv-dock-ext.dts:
// SPDX-License-Identifier: (GPL-2.0+ or MIT)
// Copyright (C) 2022 Jisheng Zhang <jszhang@kernel.org>
// Copyright (C) 2022 Samuel Holland <samuel@sholland.org>
#include <dt-bindings/interrupt-controller/irq.h>
#include <dt-bindings/gpio/gpio.h>
#include "new-sun20i-d1-lichee-rv-dock.dts"
/ {
model = "Sipeed Lichee RV Dock Ext";
compatible = "sipeed,lichee-rv-dock-ext", "sipeed,lichee-rv-dock", "sipeed,lichee-rv",
"allwinner,sun20i-d1";
backlight: backlight {
compatible = "pwm-backlight";
pwms = <&pwm 7 50000 0>;
power-supply = <®_vcc>;
};
panel: panel {
status = "okay";
compatible = "panel-dpi";
backlight = <&backlight>;
panel-timing {
clock-frequency = <29200000>;
hsync-len = <48>;
hactive = <800>;
hback-porch = <40>;
hfront-porch = <40>;
vsync-len = <3>;
vactive = <480>;
vback-porch = <29>;
vfront-porch = <13>;
};
port {
panel_in_tcon_lcd0: endpoint {
remote-endpoint = <&tcon_lcd0_out_panel>;
};
};
};
};
&de {
status = "okay";
};
&hdmi {
status = "disabled";
};
&hdmi_phy {
status = "disabled";
};
&pwm {
status = "okay";
pinctrl-0 = <&pwm7_pd22_pin>;
pinctrl-names = "default";
};
&tcon_lcd0 {
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&lcd_rgb666_pins>;
};
&tcon_lcd0_out {
tcon_lcd0_out_panel: endpoint {
remote-endpoint = <&panel_in_tcon_lcd0>;
};
};
&i2c2 {
status = "okay";
pinctrl-0 = <&i2c2_pb0_pins>;
pinctrl-names = "default";
touchscreen@48 {
reg = <0x48>;
compatible = "ti,tsc2007";
interrupt-parent = <&pio>;
interrupts = <6 14 IRQ_TYPE_EDGE_FALLING>;
gpios = <&pio 6 14 GPIO_ACTIVE_LOW>; /* PG14 */
ti,x-plate-ohms = <660>;
wakeup-source;
};
};
&i2c2_pb0_pins {
bias-pull-up;
};
&usb_otg {
status = "disabled";
};
&usbphy {
/delete-property/ usb0_id_det-gpios;
/delete-property/ usb0_vbus_det-gpios;
};
桌面
已测试 xcfe4、lxde,使用 xfce4 时系统占用约 350MB 的内存,使用 lxde 时系统占用约 150MB 的内存。桌面比较卡,但是 sipeed 提供的 lichee rv d1 的 debian + lxde 很流畅,那个用的是 tina 的内核,/dev 下有 disp 和 g2d,这里用的内核是没有的。disp 在设备树里有注释,就是合并起来的 tcon_top、de、tcon_lcd0,这里的内核的设备树里是分开的