ophub / amlogic-s9xxx-armbian

Support for Armbian in Amlogic, Rockchip and Allwinner boxes. Support a311d, s922x, s905x3, s905x2, s912, s905d, s905x, s905w, s905, s905l, rk3588, rk3568, rk3399, rk3328, h6, etc.
GNU General Public License v2.0
5.8k stars 1.86k forks source link

Compile a driver #2431

Open ChandraOrbit opened 1 month ago

ChandraOrbit commented 1 month ago

Some kernels do not have drivers for certain machines, but in older kernels there are.

How do I compile a driver, for example the RTL8189FS wireless driver? Please guide?

ophub commented 1 month ago

You can include the complete driver code in the kernel source code, add it to the configuration options, enable it, and then compile the kernel. Alternatively, you can compile and install a specific driver separately in the current Armbian system.

ChandraOrbit commented 1 month ago

Sorry, I'm still confused about where to start. currently I am using an STB HG680P with the latest OS release namely Armbian_24.8.0_amlogic_s905x_bookworm_6.6.36_server_2024.07.05.img.gz

but the Wifi doesn't work and I checked and it turns out the RTL81889fs driver doesn't exist, it seems the 6.x.x kernel doesn't include that driver.

So I want to compile my own driver based on https://github.com/jwrdegoede/rtl8189ES_linux

But I don't know what the stages are. I looked for it on Wiki and it wasn't there.

PJ-568 commented 1 month ago

Try this, it might work.

sudo apt update

sudo apt install -y build-essential dkms unzip

cd

wget https://github.com/jwrdegoede/rtl8189ES_linux/archive/master.zip

unzip master.zip

cd rtl8189ES_linux
make
make install

modprobe rtl8189es
ChandraOrbit commented 1 month ago

Try this, it might work.

sudo apt update

sudo apt install -y build-essential dkms unzip

cd

wget https://github.com/jwrdegoede/rtl8189ES_linux/archive/master.zip

unzip master.zip

cd rtl8189ES_linux
make
make install

modprobe rtl8189es

GET ERROR :

root@armbian:/home/hg680p/rtl8189ES_linux# make make ARCH= CROSS_COMPILE= -C M=/home/hg680p/rtl8189ES_linux modules make[1]: M=/home/hg680p/rtl8189ES_linux: No such file or directory. Stop. make: [Makefile:2299: modules] Error 2

chris4git commented 1 month ago

Hi, I also try to compile a rtl8189es driver (cf ChalesYu/rtl8822bs-aml), without success so far ! Look at /lib/modules/6.6.36* and replace the "build" entry by a link to your headers (/usr/src/linux-headers-6.6.36...). There is a chance you go further...

Chris

ophub commented 1 month ago

Thanks for the heads-up! I found an issue with the invalid symbolic link address for "build" in armbian-update. It's now fixed, and you can update to the latest script using the armbian-sync command.

ChandraOrbit commented 1 month ago

STILL ERROR

root@armbian:/home/hg680p/rtl8189ES_linux# make ARCH=arm64 -C /lib/modules/$(uname -r)/build M=/home/hg680p/rtl8189ES_linux modules -j4 make: Entering directory '/usr/src/linux-headers-6.6.39-ophub' awk: cannot open include/generated/asm-offsets.h (No such file or directory) warning: the compiler differs from the one used to build the kernel The kernel was built by: aarch64-none-elf-gcc (Arm GNU Toolchain 13.3.Rel1 (Build arm-13.24)) 13.3.1 20240614 You are using: gcc (Debian 12.2.0-14) 12.2.0 make[2]: No rule to make target 'scripts/mod/modpost', needed by '/home/hg680p/rtl8189ES_linux/Module.symvers'. Stop. make[1]: [/usr/src/linux-headers-6.6.39-ophub/Makefile:1873: modpost] Error 2 make: *** [Makefile:234: __sub-make] Error 2 make: Leaving directory '/usr/src/linux-headers-6.6.39-ophub'

ophub commented 1 month ago

https://github.com/ophub/amlogic-s9xxx-armbian/issues/1043#issuecomment-1432720738

chris4git commented 1 month ago

STILL ERROR

root@armbian:/home/hg680p/rtl8189ES_linux# make ARCH=arm64 -C /lib/modules/$(uname -r)/build M=/home/hg680p/rtl8189ES_linux modules -j4 make: Entering directory '/usr/src/linux-headers-6.6.39-ophub' awk: cannot open include/generated/asm-offsets.h (No such file or directory) warning: the compiler differs from the one used to build the kernel The kernel was built by: aarch64-none-elf-gcc (Arm GNU Toolchain 13.3.Rel1 (Build arm-13.24)) 13.3.1 20240614 You are using: gcc (Debian 12.2.0-14) 12.2.0 make[2]: No rule to make target 'scripts/mod/modpost', needed by '/home/hg680p/rtl8189ES_linux/Module.symvers'. Stop. make[1]: [/usr/src/linux-headers-6.6.39-ophub/Makefile:1873: modpost] Error 2 make: *** [Makefile:234: __sub-make] Error 2 make: Leaving directory '/usr/src/linux-headers-6.6.39-ophub'

Hi @ChandraOrbit, I'm here too (I use kernel 5.15.162-ophub). I've tried to do "make modules_prepare" in the headers dir (/usr/src/linux-headers-6.6.39-ophub for you) but it fails before making modpost :-(

ChandraOrbit commented 1 month ago

#1043 (comment)

STILL ERROR

[ INFO ] Start adjusting compilation toolchain [ /usr/local/toolchain/arm-gnu-toolchain-13.3.rel1-aarch64-aarch64-none-elf ]... '/usr/bin/gcc' -> '/usr/local/toolchain/arm-gnu-toolchain-13.3.rel1-aarch64-aarch64-none-elf/bin/aarch64-none-elf-gcc' '/usr/bin/g++' -> '/usr/local/toolchain/arm-gnu-toolchain-13.3.rel1-aarch64-aarch64-none-elf/bin/aarch64-none-elf-g++' '/usr/bin/gcc-ar' -> '/usr/local/toolchain/arm-gnu-toolchain-13.3.rel1-aarch64-aarch64-none-elf/bin/aarch64-none-elf-gcc-ar' '/usr/bin/gcc-nm' -> '/usr/local/toolchain/arm-gnu-toolchain-13.3.rel1-aarch64-aarch64-none-elf/bin/aarch64-none-elf-gcc-nm' '/usr/bin/gcc-ranlib' -> '/usr/local/toolchain/arm-gnu-toolchain-13.3.rel1-aarch64-aarch64-none-elf/bin/aarch64-none-elf-gcc-ranlib' '/usr/include/asm' -> '/usr/include/aarch64-none-elf/asm' [ STEPS ] Start compiling driver...

make -C M=/home/orbit/rtl8822bs-aml clean

cd hal ; rm -fr ///.mod.c ///.mod ///.o ///..cmd ///.ko cd hal ; rm -fr //.mod.c //.mod //.o //..cmd //.ko cd hal ; rm -fr /.mod.c /.mod /.o /..cmd /.ko cd hal ; rm -fr .mod.c .mod .o ..cmd .ko cd core/efuse ; rm -fr .mod.c .mod .o ..cmd .ko cd core ; rm -fr .mod.c .mod .o ..cmd .ko cd os_dep/linux ; rm -fr .mod.c .mod .o ..cmd .ko cd os_dep ; rm -fr .mod.c .mod .o ..cmd .ko cd platform ; rm -fr .mod.c .mod .o ..cmd .ko rm -fr Module.symvers ; rm -fr Module.markers ; rm -fr modules.order rm -fr .mod.c .mod .o ..cmd .ko *~ rm -fr .tmp_versions make ARCH=arm64 CROSS_COMPILE=/usr/local/toolchain/arm-gnu-toolchain-13.3.rel1-aarch64-aarch64-none-elf/bin/aarch64-none-elf- -C M=/home/orbit/rtl8822bs-aml modules make[1]: M=/home/orbit/rtl8822bs-aml: No such file or directory. Stop. make: [Makefile:2014: modules] Error 2 [ ERROR ] There is an error in the driver, please handle it according to the log prompt.

ChandraOrbit commented 1 month ago

STILL ERROR root@armbian:/home/hg680p/rtl8189ES_linux# make ARCH=arm64 -C /lib/modules/$(uname -r)/build M=/home/hg680p/rtl8189ES_linux modules -j4 make: Entering directory '/usr/src/linux-headers-6.6.39-ophub' awk: cannot open include/generated/asm-offsets.h (No such file or directory) warning: the compiler differs from the one used to build the kernel The kernel was built by: aarch64-none-elf-gcc (Arm GNU Toolchain 13.3.Rel1 (Build arm-13.24)) 13.3.1 20240614 You are using: gcc (Debian 12.2.0-14) 12.2.0 make[2]: No rule to make target 'scripts/mod/modpost', needed by '/home/hg680p/rtl8189ES_linux/Module.symvers'. Stop. make[1]: [/usr/src/linux-headers-6.6.39-ophub/Makefile:1873: modpost] Error 2 make: *** [Makefile:234: __sub-make] Error 2 make: Leaving directory '/usr/src/linux-headers-6.6.39-ophub'

Hi @ChandraOrbit, I'm here too (I use kernel 5.15.162-ophub). I've tried to do "make modules_prepare" in the headers dir (/usr/src/linux-headers-6.6.39-ophub for you) but it fails before making modpost :-(

I tried flashing my STB using the image https://www.armbian.com/download/ and successfully compile the 81889fs wifi driver, but the Image from here (kernel 6.x.x-ophub) always fails to compile the driver.

chris4git commented 1 month ago

I tried flashing my STB using the image https://www.armbian.com/download/ and successfully compile the 81889fs wifi driver, but the Image from here (kernel 6.x.x-ophub) always fails to compile the driver.

I also tried to compile the driver on a Station M1 under Armbian 24.2.1 Jammy with kernel 6.1.77 from www.armbian.com/download and it was as simple as git clone https://github.com/ChalesYu/rtl8822bs-aml.git cd rtl8822bs-aml/ make

It didn't go to the end, probably because I didn't find a proper CONFIG_PLATFORM in the Makefile, but there were no problem related to the headers. We have a debian/Jammy in the two cases :-/

bombjinne commented 1 month ago

一样的尝试在盒子里编译github上找到8188gu网卡驱动,结果报错: QQ截图20240724140826 本来想升级内核试试的,armbian-update后看着原来的内核备份了,结果重启就进不去系统了,直接进ramfs了,在ramfs系统里发现原来的内核就没有备份,想求教下目前怎么才能从U盘启动重新安装armbian,是不是只能再刷一次安卓才行。 然后8188gu的驱动再慢慢研究吧…… @ophub

ophub commented 1 month ago

https://github.com/ophub/amlogic-s9xxx-armbian/commit/bb99eef48c24637ca3b62f47af26948f5660ddad

刚刚修复了这个问题,header里遗失了一些文件,f大修复了编译内核的脚步,我同步更新了,但是我还没跑完测试: https://github.com/ophub/kernel/actions/runs/10073384652

等测试好了,重新编译内核,安装新内核即可。

目前还有一种做法,是更新到dev系列里的内核,这个的包含了这些缺少的文件,是我在armbian里编译的。 armbian-update -u dev -k 6.6

ophub commented 1 month ago

如果安装内核失败,可以使用u盘启动armbian,对emmc里的内核进行救援恢复 armbian-update -s

详细介绍在仓库的首页有说明

bombjinne commented 1 month ago

如果安装内核失败,可以使用u盘启动armbian,对emmc里的内核进行救援恢复 armbian-update -s

详细介绍在仓库的首页有说明

冒昧的问一下,首页没找到ramfs里怎么设置从U盘启动,只看到从U盘启动后备份/恢复,目前从ramfs里也看没有找到备份的文件夹/ddbr

ophub commented 1 month ago

https://github.com/ophub/amlogic-s9xxx-armbian/blob/main/documents/README.cn.md

看第10节

bombjinne commented 1 month ago

https://github.com/ophub/amlogic-s9xxx-armbian/blob/main/documents/README.cn.md

看第10节

感谢回复,教程内修复及更新内容写得非常详细,我只是在目前环境如果不重刷安卓系统还不知道怎么设置从U盘启动,第一次在机顶盒刷这个系统不是很了解,打扰了

ophub commented 1 month ago

只要从U盘启动过一次,就不需要再刷安卓了,安卓系统只有刷机救砖的时候用,平时直接从U盘启动新armbian系统就可以救援内核,或者重新安装等。

bombjinne commented 1 month ago

只要从U盘启动过一次,就不需要再刷安卓了,安卓系统只有刷机救砖的时候用,平时直接从U盘启动新armbian系统就可以救援内核,或者重新安装等。

奇怪了,重新安装了一次,又试了下下载的稳定版最新内核到本地更新,一样的失败Screenshot_2024-07-24-22-48-35-302_org.connectbot.jpg

ophub commented 1 month ago

安装gcc编译工具链

Snip20240725_1

更新到最新内核(2024.07.25日以后编译的内核,必须操作)

Snip20240725_12

linux-6.1.y 内核下测试:

Snip20240725_6

Snip20240725_8

linux-6.6.y 内核下测试

Snip20240725_10

Snip20240725_11

文字版说明

第一步,更新到今天的最新内核

armbian-sync armbian-update -k 6.1

第二步,安装编译工具

mkdir -p /usr/local/toolchain cd /usr/local/toolchain

下载编译工具

wget https://github.com/ophub/kernel/releases/download/dev/arm-gnu-toolchain-13.3.rel1-aarch64-aarch64-none-elf.tar.xz

解压

tar -Jxf arm-gnu-toolchain-13.3.rel1-aarch64-aarch64-none-elf.tar.xz

安装其他编译依赖包(可选项,可根据错误提示手动安装缺少项)

armbian-kernel -u

第三步,下载驱动,编译

下载驱动源码

cd ~/ git clone https://github.com/jwrdegoede/rtl8189ES_linux cd rtl8189ES_linux

设置编译环境

gun_file="arm-gnu-toolchain-13.3.rel1-aarch64-aarch64-none-elf.tar.xz" toolchain_path="/usr/local/toolchain" toolchain_name="gcc" export CROSS_COMPILE="${toolchain_path}/${gun_file//.tar.xz/}/bin/aarch64-none-elf-" export CC="${CROSS_COMPILE}gcc" export LD="${CROSS_COMPILE}ld.bfd" export ARCH="arm64" export M="/root/rtl8189ES_linux" export KSRC=/usr/lib/modules/$(uname -r)/build

编译驱动

make

第四步,安装驱动

sudo cp -f 8189es.ko /lib/modules/$(uname -r)/kernel/drivers/net/wireless/

更新模块依赖关系

sudo depmod -a

加载驱动模块

sudo modprobe 8189es

检查驱动是否加载成功

lsmod | grep 8189es

可以看到成功加载驱动

8189es 1843200 0 cfg80211 917504 2 8189es,brcmfmac



这个帖子里的方法,我已经放在帮助文档里了,具体详见9.3
https://github.com/ophub/amlogic-s9xxx-armbian/tree/main/documents
bombjinne commented 1 month ago

感谢提供示例操作,我是在更新内核的时候就直接进不去系统了,不知道是不是因为首次安装时重编译过dtb文件,修改了频率的原因,今天重新下载dev最新版内核后把我机器(UNT402A S905L)修改后的dtb改到内核文件的包里重新计算了sha256值,目前内核更新成功了. image

测试编译rtl8188gu无线驱动https://github.com/lwfinger/rtl8xxxu,编译还是失败了,不知道什么原因 Screenshot_2024-07-25-18-23-51-844_org.connectbot-edit.jpg

ophub commented 1 month ago

我给你费劲巴拉写了4步,你就1步概括了?编译工具呢?环境设置呢?我给你图文并茂地写了半天,你又自己敲了?错误日志上写的很清楚,gcc不同。你不想看我的说明,就自己认真看错误日志,根据提示进行操作。

bombjinne commented 1 month ago

我给你费劲巴拉写了4步,你就1步概括了?

老大,莫生气,每一步都按你写的做了,只是截图没有截出来,只截了报错的部分,第一步内核更新了dev的最新版,第二步安装编译工具也完成了(armbian-kernel -u没有更新,盒子总共才8G,存储不够)环境也是按你写的全部配置了的,第三步失败了,根据你的教程make的时候会报错,所以根据AI提示加了headers源码路径还是报错,看了下貌似是GLIBC版本不一致,在根据AI提示编译高版本的glibc

ChandraOrbit commented 1 month ago

安装gcc编译工具链

Potongan20240725_1

更新到最新内核(25/07/2024, 必须操作)

Potongan20240725_12

linux-6.1.y 内核下测试:

Potongan20240725_6

Potongan20240725_8

linux-6.6.y untuk diunduh

Potongan20240725_10

Potongan20240725_11

文字版说明

  • header yang stabil dan stabil无法自定义编译驱动(但dev系列里面的内核一直可以,这个系列是在armbian系统里编译的,里包含的文件是完整的)
  • 5.4.y dan 6.6.y, 5.4.y, 5.4.280, 5.10.222, 5.15.163, 6.1.100, 6.6.41
  • seperti kernel_stable , kernel_stable , kernel_dev , dan rk35xx serta rk3588. header缺少文件的bug已经修复了。

# 第一步,更新到今天的最新内核
armbian-sync
armbian-update -k 6.1

# 第二步,安装编译工具
mkdir -p /usr/local/toolchain
cd /usr/local/toolchain
# 下载编译工具
wget https://github.com/ophub/kernel/releases/download/dev/arm-gnu-toolchain-13.3.rel1-aarch64-aarch64-none-elf.tar.xz
# 解压
tar -Jxf arm-gnu-toolchain-13.3.rel1-aarch64-aarch64-none-elf.tar.xz
# 安装其他编译依赖包(可选项,可根据错误提示手动安装缺少项)
armbian-kernel -u

# 第三步,下载驱动,编译
# 下载驱动源码
cd ~/
git clone https://github.com/jwrdegoede/rtl8189ES_linux
cd rtl8189ES_linux
# 设置编译环境
gun_file="arm-gnu-toolchain-13.3.rel1-aarch64-aarch64-none-elf.tar.xz"
toolchain_path="/usr/local/toolchain"
toolchain_name="gcc"
export CROSS_COMPILE="${toolchain_path}/${gun_file//.tar.xz/}/bin/aarch64-none-elf-"
export CC="${CROSS_COMPILE}gcc"
export LD="${CROSS_COMPILE}ld.bfd"
export ARCH="arm64"
export M="/root/rtl8189ES_linux"
export KSRC=/usr/lib/modules/$(uname -r)/build
# 编译驱动
make

# 第四步,安装驱动
sudo cp -f 8189es.ko /lib/modules/$(uname -r)/kernel/drivers/net/wireless/
# 更新模块依赖关系
sudo depmod -a
# 加载驱动模块
sudo modprobe 8189es
# 检查驱动是否加载成功
lsmod | grep 8189es
# 可以看到成功加载驱动
8189es               1843200  0
cfg80211              917504  2 8189es,brcmfmac

Panduan Pengguna

Thank you, you are the best, it's been successful, I finally compiled the Wifi rtl8189fs driver

BTF [M] /root/rtl8189ES_linux/8189fs.ko Skipping BTF generation for /root/rtl8189ES_linux/8189fs.ko due to unavailability of vmlinux make[1]: Leaving directory '/usr/src/linux-headers-6.6.41-ophub' root@armbian:~/rtl8189ES_linux# ls 8189fs.ko 8189fs.mod.c 8189fs.o core ifcfg-wlan0 Kconfig modules.order os_dep runwpa 8189fs.mod 8189fs.mod.o clean hal include Makefile Module.symvers platform wlan0dhcp root@armbian:~/rtl8189ES_linux# sudo cp -f 8189fs.ko /lib/modules/$(uname -r)/kernel/drivers/net/wireless root@armbian:~/rtl8189ES_linux# sudo depmod -a root@armbian:~/rtl8189ES_linux# sudo modprobe 8189fs root@armbian:~/rtl8189ES_linux# nmcli radio WIFI-HW WIFI WWAN-HW WWAN enabled enabled missing enabled root@armbian:~/rtl8189ES_linux# lsmod | grep 8189fs 8189fs 1634304 0 cfg80211 937984 1 8189fs