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.7k stars 1.83k forks source link

mgv3000(s905l3) 带蓝牙rtl8761btv 可正常驱动使用 #639

Closed imzlh closed 1 year ago

imzlh commented 1 year ago

最近刷了一台mgv3000机器,s905l3的cpu,带蓝牙rtl8761btv,这款芯片很容易驱动,就想着能否修改dtb增加蓝牙串口驱动蓝牙播放音乐什么的。 最开始clone了unifreq的kernel,照着dtsi一顿修改,然后用dtc编译,结果搞了半天还是没搞定问题,是include写法太无语了。。。自己还特地写了两个脚本把它都替换掉,但是还是没有成功 最后我还是选择了反编译,照着cm311-1a的dtb修改了一些,可是最后还是没有显示出/dev/ttyAML1。后来在网上冲浪也没有找到相关的资料,只能来这里碰碰运气了 您是怎么修改的呢?能否教教我?感激不尽! 最后附上我改的和原先的安卓dtb:https://imzlh.top/www.zip

ophub commented 1 year ago

你用的哪个dtb可以正常启动,有线网卡工作正常,只是缺蓝牙

https://github.com/unifreq/linux-5.15.y/blob/67ebe60c9eb5ce819a37f231b47707b6beb4d085/drivers/bluetooth/btrtl.c#L127-L146

/usr/lib/firmware/rtl_bt/rtl8761bu_fw.bin

xcray commented 1 year ago

看你改的dts文件逻辑上就没搞对。你用“meson-gxl-s905l2-x7-5g”可以正常启动是吗?

imzlh commented 1 year ago

是meson-gxl-s905l2-x7-5g.dtb,本来只是抱试一试的态度,结果还真的网卡正常,也不会重启需要插拔网线什么的,美中不足就是CPU频率不正确(没关系的)和指示灯得手动点亮(也还可以,gpio73),但是蓝牙我就想照抄大佬的作业试试看,但是反编译完我人傻了,大概g12a与gxl差别太大,我复制完一点用也没有。

xcray commented 1 year ago

我刚刚为你编译了一版,你试试吧: https://github.com/xcray/amlogic-s905l3a-armbian/releases/download/kernel_5.15.74/5.15.74.tar.gz

imzlh commented 1 year ago

我刚刚为你编译了一版,你试试吧: https://github.com/xcray/amlogic-s905l3a-armbian/releases/download/kernel_5.15.74/5.15.74.tar.gz

大佬,是帮我加好串口支持了吗?

imzlh commented 1 year ago

![Uploading 8545785D-1B45-4450-9C38-1BE51C62F387.jpeg…]() 谢谢,可以了。请教您是怎么改的

imzlh commented 1 year ago

可是好像报错了,没法成功驱动:( 4A50B9BC-AC6E-4FB4-AE71-5D594146FEB0

xcray commented 1 year ago

你成功地把我踩过的坑又重复踩了一遍。。。不过你运气比我好,当初根本就没有个明白人能帮我。。。

修改方法很简单原来说过:https://github.com/xcray/linux-5.15.y/blob/main/arch/arm64/boot/dts/amlogic/meson-gxl-s905l2-x7-5g.dts

报错的原因之前也说过,需要用gpioset重置一下蓝牙电路,或者关机断电再重开,一定要断电,reboot不行;另外一个可能是config文件有问题(里面指定的波特率是错的)。

ophub commented 1 year ago

meson-gxl-s905l3-mgv3000.dtb.zip

下载解压,上传到/boot/dtb/amlogic目录 修改/boot/uEnv.txt里的dtb名字

https://github.com/unifreq/linux-5.15.y/blob/main/drivers/bluetooth/btrtl.c#L134-L139

根据上面的描述,看看固件里有没这2个文件。 ls /usr/lib/firmware/rtl_bt/rtl8761b_*

imzlh commented 1 year ago

meson-gxl-s905l3-mgv3000.dtb.zip

下载解压,上传到/boot/dtb/amlogic目录 修改/boot/uEnv.txt里的dtb名字

https://github.com/unifreq/linux-5.15.y/blob/main/drivers/bluetooth/btrtl.c#L134-L139

根据上面的描述,看看固件里有没这2个文件。 ls /usr/lib/firmware/rtl_bt/rtl8761b_*

谢谢两位大佬,不过我都失败了 x大改的dtb的确名不虚传,出现了串口,但是当我尝试rtk_hciattach工具驱动时直接卡死掉线无响应,只能重新插拔电源 最后我试了试您的这个dtb,串口消失了。我反编译比较了下,看见dtb中好像加了bluetooth 的设置,不知为什么反而不行了 我再试试吧,谢谢大佬的努力

ophub commented 1 year ago

https://github.com/unifreq/linux-5.15.y/blob/main/Documentation/devicetree/bindings/net/rtl8723bs-bluetooth.txt

这有文档,你看看,r_pio每个机型不同,这是中断控制器的名字。你对一个安卓里的名字

imzlh commented 1 year ago

https://github.com/unifreq/linux-5.15.y/blob/main/Documentation/devicetree/bindings/net/rtl8723bs-bluetooth.txt

这有文档,你看看,r_pio每个机型不同,这是中断控制器的名字。你对一个安卓里的名字

我想不明白,为什么在uart_A里直接&gpio_a_pins就行了,是因为两个cpu接近的原因吗?不科学啊,理论上不通用吧,那请问应该如何修改?

imzlh commented 1 year ago

听说安卓dtb和armbian的很不一样,那类似这种gpio能直接照抄吗 我去看了看,好像你改的和安卓dtb有不一样的地方 CD024BB4-77B5-4F37-9AEA-C76E8843C084 76028EA3-2187-4C2E-9D40-A6189EAB5D70 还有一个问题,为什么要限制波特率为20000?

xcray commented 1 year ago

dtb里的蓝牙怎么起作用、起什么作用?这个问题我也没搞明白。不过就我的经验来说,只要串口对了,蓝牙就可以用起来。当然,蓝牙的固件(fw和config)也必须正确才行。

话说你试过别的config文件了吗?

imzlh commented 1 year ago

找到问题所在了,好像是clock不对,不是r_pio 72ECE3C3-D1F2-42F7-939C-867FE366363D

ophub commented 1 year ago

根据安卓dtb里的值修改,安卓的换到linux好象要减1,你试试原值不对就-1测试

lovelylain commented 1 year ago

dtb里的蓝牙怎么起作用、起什么作用?这个问题我也没搞明白。不过就我的经验来说,只要串口对了,蓝牙就可以用起来。当然,蓝牙的固件(fw和config)也必须正确才行。

话说你试过别的config文件了吗?

dtb里的bluetooth起自动加载蓝牙驱动的作用,如果dtb里的蓝牙正确驱动了,就不需要再在用户态运行rtk_hciattach了。dtb里如果配置了启用的bluetooth,就不会出现ttyAML,没配置就会出现且可以通过alias指定名称,这个时候是把底层的uart功能暴露给用户态,所以运行rtk_hciattach也能驱动。bluetooth的compatible并不是根据芯片确定的,虽然芯片是realtek 8761btv,并不是compatible配置为realtek,rtl8761b-bt就能自动识别并加载驱动,需要内核里有匹配的compatible名称才行。 https://github.com/unifreq/linux-5.15.y/blob/main/drivers/bluetooth/hci_h5.c#L1101 从这里可以看到,内核里只支持realtek,rtl8822cs-bt, realtek,rtl8723bs-bt, realtek,rtl8723ds-bt这3个名称,所以与其配置compatible为realtek,rtl8761b-bt,不如设置为realtek,rtl8723bs-bt试试,也许这样就能触发内核里的芯片检测功能,然后自动加载相应的驱动。

xcray commented 1 year ago

dtb里的bluetooth起自动加载蓝牙驱动的作用,如果dtb里的蓝牙正确驱动了,就不需要再在用户态运行rtk_hciattach了。dtb里如果配置了启用的bluetooth,就不会出现ttyAML,没配置就会出现且可以通过alias指定名称,这个时候是把底层的uart功能暴露给用户态,所以运行rtk_hciattach也能驱动。bluetooth的compatible并不是根据芯片确定的,虽然芯片是realtek 8761btv,并不是compatible配置为realtek,rtl8761b-bt就能自动识别并加载驱动,需要内核里有匹配的compatible名称才行。 https://github.com/unifreq/linux-5.15.y/blob/main/drivers/bluetooth/hci_h5.c#L1101 从这里可以看到,内核里只支持realtek,rtl8822cs-bt, realtek,rtl8723bs-bt, realtek,rtl8723ds-bt这3个名称,所以与其配置compatible为realtek,rtl8761b-bt,不如设置为realtek,rtl8723bs-bt试试,也许这样就能触发内核里的芯片检测功能,然后自动加载相应的驱动。

学习了! 根据realtek说明,初始化必须使用其提供的rtk_hciattach命令,系统/bluez自带的hciattach不好使。那么这个命令也可以被自动调用么?

ophub commented 1 year ago

meson-gxl-s905l3-mgv3000-1-2.zip

这个改为了realtek,rtl8723bs-bt,你试试 2个不同的都分别试下,修改/boot/uEnv.txt重启,看日志 dmesg | grep Bluetooth

ophub commented 1 year ago

https://github.com/ophub/amlogic-s9xxx-armbian/issues/645#issuecomment-1290880643

用户反馈rtl8723cs的芯片使用realtek,rtl8723bs-bt可以驱动蓝牙

meson-gxl-s905l3-mgv3000.dtb.zip

你再试试这个。添加了无线和蓝牙。

imzlh commented 1 year ago

呃,依旧没有效果:( 293AC552-95F0-4C36-9A34-89466D36A128 不过我这台机器没有wifi,这就尴尬了

ophub commented 1 year ago

dmesg | grep Bluetooth

大写B

imzlh commented 1 year ago

试了试,这是使用结果 91988BC1-3D4F-4B0F-BAC0-F00E8CA0E8F1 我开始怀疑问题出在串口的gpio不对,我打算再买一台在安卓里调试,也许能解决问题

ophub commented 1 year ago

这是ok了,这是驱动起来了。

dts代码如下:

// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
/*
 * Copyright (c) 2016 Endless Computers, Inc.
 * Author: Carlo Caione <carlo@endlessm.com>
 */

/dts-v1/;

#include "meson-gxl-s905w-p281.dts"

/ {
        compatible = "amlogic,mgv3000", "amlogic,s905l3", "amlogic,meson-gxl";
        model = "MGV3000 (s905l3)";

        aliases {
                serial1 = &uart_A;
        };
};

// the gpu in the S905L2 has one pp core less
// (i.e. only two in total) than the one in the other S905X/W
&mali {
        interrupts = <GIC_SPI 160 IRQ_TYPE_LEVEL_HIGH>,
                    <GIC_SPI 161 IRQ_TYPE_LEVEL_HIGH>,
                    <GIC_SPI 162 IRQ_TYPE_LEVEL_HIGH>,
                    <GIC_SPI 163 IRQ_TYPE_LEVEL_HIGH>,
                    <GIC_SPI 164 IRQ_TYPE_LEVEL_HIGH>,
                    <GIC_SPI 165 IRQ_TYPE_LEVEL_HIGH>,
                    <GIC_SPI 166 IRQ_TYPE_LEVEL_HIGH>,
                    <GIC_SPI 167 IRQ_TYPE_LEVEL_HIGH>;
        interrupt-names = "gp", "gpmmu", "pp", "pmu",
                    "pp0", "ppmmu0", "pp1", "ppmmu1";
};

/* Realtek Wireless SDIO Module */
&sd_emmc_a {
    /delete-node/ brcmf;

    rtl8723bs: wifi@1 {
        reg = <1>;
        compatible = "realtek,rtl8723bs";
    };
};

/* Connected to the Bluetooth module */
&uart_A {
    status = "okay";
    pinctrl-0 = <&uart_a_pins>, <&uart_a_cts_rts_pins>;
    pinctrl-names = "default";
    uart-has-rtscts;

    bluetooth {
        compatible = "realtek,rtl8723bs-bt";
        enable-gpios = <&gpio GPIOX_17 GPIO_ACTIVE_HIGH>;
        max-speed = <2000000>;
        clocks = <&wifi32k>;
        clock-names = "lpo";
    };
};

源码: meson-gxl-s905l3-mgv3000.dts.zip

文件: meson-gxl-s905l3-mgv3000.dtb.zip

ophub commented 1 year ago

把你的mgv3000的产品外观,盒子底部的型号描述信息,盒子主板正面、反面,都拍个照片发上来。 有这个设备的安卓系统镜像没?发个链接我备份到下载专区里。 你这设备有线和蓝牙都工作正常了,我给添加个安装序号。

imzlh commented 1 year ago

可是蓝牙还是不行啊,输了hciconfig啥都没有

ophub commented 1 year ago

armbian-config 安装蓝牙

imzlh commented 1 year ago

可是不行啊,蓝牙在armbian-config中安装过了

a393310872 commented 1 year ago

我有一台CM201-1的盒子...S905L3的....连启动都没法启动...好歹这台MGV3000是有反应的...而且这盒子刷任何安卓9都会死机.....难搞

xcray commented 1 year ago

我在cm311-1a上测试基本成功!

# dmesg |grep -i blue
[   11.233443] Bluetooth: Core ver 2.22
[   11.241688] Bluetooth: Starting self testing
[   11.264551] Bluetooth: ECDH test passed in 14707 usecs
[   11.273707] Bluetooth: SMP test passed in 2924 usecs
[   11.279273] Bluetooth: Finished self testing
[   11.284899] NET: Registered PF_BLUETOOTH protocol family
[   11.290705] Bluetooth: HCI device and connection manager initialized
[   11.297204] Bluetooth: HCI socket layer initialized
[   11.303243] Bluetooth: L2CAP socket layer initialized
[   11.308904] Bluetooth: SCO socket layer initialized
[   11.413112] Bluetooth: HCI UART driver ver 2.3
[   11.420043] Bluetooth: HCI UART protocol H4 registered
[   11.420056] Bluetooth: HCI UART protocol BCSP registered
[   11.420132] Bluetooth: HCI UART protocol LL registered
[   11.420135] Bluetooth: HCI UART protocol ATH3K registered
[   11.420178] Bluetooth: HCI UART protocol Three-wire (H5) registered
[   11.420590] Bluetooth: HCI UART protocol Intel registered
[   11.422487] Bluetooth: HCI UART protocol Broadcom registered
[   11.422540] Bluetooth: HCI UART protocol QCA registered
[   11.422543] Bluetooth: HCI UART protocol AG6XX registered
[   11.422585] Bluetooth: HCI UART protocol Marvell registered
[   12.056060] Bluetooth: hci0: RTL: examining hci_ver=0a hci_rev=000b lmp_ver=0a lmp_subver=8761
[   12.064154] Bluetooth: hci0: RTL: rom_version status=0 version=1
[   12.070054] Bluetooth: hci0: RTL: loading rtl_bt/rtl8761b_fw.bin
[   12.115401] Bluetooth: hci0: RTL: loading rtl_bt/rtl8761b_config.bin
[   12.144134] Bluetooth: hci0: RTL: cfg_sz 81, total sz 30005
[   12.669698] Bluetooth: hci0: RTL: fw version 0x0ca98a6b
[   17.866657] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
[   17.871322] Bluetooth: BNEP filters: protocol multicast
[   17.876140] Bluetooth: BNEP socket layer initialized

仔细看,有没有看到区别?多了几行!

关键点:系统自带的固件有问题!那个config文件的速率是1.5m的,好像这个芯片根本不支持。用之前用的2m速率的文件直接成功。hciconfig、bluetoothctl等都可以发现正确的蓝牙适配器信息,包括mac地址等。

重大缺陷:reboot后无法使用蓝牙、必须poweroff、断电,再重新开机才行! 由于gpio 0 82已被系统rfkill征用,所以无法用gpioset命令操作了,但是rfkill自己又不能操作这个gpio,导致reboot过程中蓝牙电路不会复位、重启后无法继续使用。

xcray commented 1 year ago

可能的优化方向: 1、正规的,修改dtb/驱动程序源码? 2、不正规的,dtb中删掉enable-gpios,继续使用gpioset操作

目标还是确保不断电reboot后蓝牙能够正常使用

ophub commented 1 year ago

上传一个你的2m的文件,看看他能不能使用

xcray commented 1 year ago

上传一个你的2m的文件,看看他能不能使用

当初就是他找到的~~~ rtl8761b_config_2m.zip

imzlh commented 1 year ago

我的config是2m的,在b863av3.1上测试过了可以使用

xcray commented 1 year ago

我的config是2m的,在b863av3.1上测试过了可以使用

你是不是没断电?这个玩法必须poweroff、断电1秒以上、然后再重新加电,直接reboot的话不行。 还有,config必须保存在/lib/firmware/rtl_bt目录下(有下划线、不是原来用的rtlbt)、文件名必须是rtl8761b_config.bin(和以前也不一样)。 另一个文件rtl8761b_fw.bin也必须在rtl_bt目录下(本来就有,可以用)。 dmesg |grep -i fail 可以查看固件加载是不是出错了。

ophub commented 1 year ago

我记得之前cm311的dtb的时候,也有这个config的选择问题,CM311-1A-YST使用rtl8761b驱动正常了?

我看到之前的帖子里写的: 厂商代码:CH=长虹,YST=易视腾,ZG=朝歌

Armbian已经支持的SOC CM311-1A YST,S905L3A,2+16GB,BT (RTL8761B) CM311-1SA CH,S905L3A,2+8GB,WIFI+BT (UWE5621DS) CM311-1SA ZG,S905L3A,2+8GB,WIFI+BT (UWE5621DS)

Armbian尚不支持的SOC CM311-1 YST,S905L3,2+16GB,WIFI+BT (型号不详) CM311-1S CH、S905L3B,2+8GB,WIFI+BT (UWE5621DS)

xcray commented 1 year ago

我记得之前cm311的dtb的时候,也有这个config的选择问题,CM311-1A-YST使用rtl8761b驱动正常了?

我看到之前的帖子里写的: 厂商代码:CH=长虹,YST=易视腾,ZG=朝歌

Armbian已经支持的SOC CM311-1A YST,S905L3A,2+16GB,BT (RTL8761B) CM311-1SA CH,S905L3A,2+8GB,WIFI+BT (UWE5621DS) CM311-1SA ZG,S905L3A,2+8GB,WIFI+BT (UWE5621DS)

Armbian尚不支持的SOC CM311-1 YST,S905L3,2+16GB,WIFI+BT (型号不详) CM311-1S CH、S905L3B,2+8GB,WIFI+BT (UWE5621DS)

是的,加电开机蓝牙直接就能用,就是不能reboot、必须poweroff断电才行。

ophub commented 1 year ago

https://github.com/unifreq/linux-5.15.y/blob/3f1f0123b98c9defe0f540b40065a8e88ccbed81/Documentation/devicetree/bindings/net/rtl8723bs-bluetooth.txt#L15-L19

用reset-gpios试试,看他下面的30-33行的代码示例。

xcray commented 1 year ago

https://github.com/unifreq/linux-5.15.y/blob/3f1f0123b98c9defe0f540b40065a8e88ccbed81/Documentation/devicetree/bindings/net/rtl8723bs-bluetooth.txt#L15-L19

用reset-gpios试试,看他下面的30-33行的代码示例。

增加reset-gpios= <&gpio GPIOX_17 GPIO_ACTIVE_HIGH>; 不行; 改成reset-gpios= <&gpio GPIOX_17 GPIO_ACTIVE_LOW>; 还是不行; 删掉enable-gpios只保留reset-gpios(ACTIVE_LOW不变);仍然不行; 改成reset-gpios= <&gpio GPIOX_17 GPIO_ACTIVE_HIGH>; 继续不行;

感觉rfkill就没有尝试做任何动作。 删掉enable只保留reset,倒是可以在命令行用gpioset操作了,重启后执行,先低后高,蓝牙自动恢复

修改/lib/systemd/system/bluetooth.server、在[Service]部分加一句? ExecStopPost=/usr/bin/env gpioset 0 82=0 反正这么弄很好用,重启了几次都没问题,我先这么用着了


简单学习了一下,这种方式比在用户空间运行rtk_hciattach要好——那种是陈旧的方法、这种是被称作serdev的“现代化”方式,虽然还没找到完美的方法,但值得采用。

ophub commented 1 year ago

示例里面的其他方法组合使用试试,示例里三个方法组合使用的

xcray commented 1 year ago

示例里面的其他方法组合使用试试

也就这两个语句有点关系,其它更没啥关系了,再说也不知道数字啊

imzlh commented 1 year ago

还是不行,fail也没有什么东西 [ 4.935314] genirq: Setting trigger mode 3 for irq 47 failed (meson_gpio_irq_set_type+0x0/0x140) [ 5.123768] meson-drm d0100000.vpu: failed to bind c883a000.hdmi-tx (ops 0xffffffc00a2e7ee8): -19 [ 5.138401] meson-drm d0100000.vpu: master bind failed: -19 [ 5.908182] hub 2-0:1.0: config failed, hub doesn't have any ports! (err -19) [ 14.123518] systemd[1]: Dependency failed for Swaps. [ 14.128210] systemd[1]: swap.target: Job swap.target/start failed with result 'dependency'.

imzlh commented 1 year ago

我想问一问,dtb里uart_A的gpio是靠kernel自己检测的还是已经写在dts里了?这么一搞,对于dtb概念越来越模糊:<

xcray commented 1 year ago

在m401a盒子5.15.75内核测试了各种组合,结果如下: bluetooth部分只需要一行:compatible = "realtek,rtl8723bs-bt"; 其它内容都没有任何作用,reboot问题只能靠gpioset来解决。

imzlh commented 1 year ago

我有一个成果,最大化利用EMMC空间: good 这个怎么样?(别问我为什么用Debian9,占用少) 这是我提前的分区表: android_partition_table_template.xlsx

ophub commented 1 year ago

p3p4是连续吧,中间有要跳过的空间?

imzlh commented 1 year ago

不需要,只是我把他分开来了

imzlh commented 1 year ago

个人觉得cache那块大蛋糕放着不用太浪费了,1G也好啊

ophub commented 1 year ago

很多盒子都被迫浪费了一块(在armbian-install安装脚本的分区备注里写了空间大小),可以计算好手动fdisk一个出来

ophub commented 1 year ago

在m401a盒子5.15.75内核测试了各种组合,结果如下: bluetooth部分只需要一行:compatible = "realtek,rtl8723bs-bt"; 其它内容都没有任何作用,reboot问题只能靠gpioset来解决。

max-speed = <2000000>; 把速率调低点试试,重启是否可以使用。

enable-gpios = <&gpio GPIOX_17 GPIO_ACTIVE_HIGH>; 这个值是盲猜的,不一定是对的,看看安卓里的值是多少。gpio是需要原理图确认的,或者是把cpu拆下来一台用万用表量。弄对了重启也可以。