[BPI-R2] internal Wifi/BT (MT6625L) - Kernel

Ssid and password in wifi.sh?

These values are in /etc/hostapd/hostapd_ap0.conf

You have to configure also dnsmasq and ip in wifi.sh

For second hostapd create a secont hostapd.conf and only run hostapd with this config

I start a second bash-script at the end of wifi.sh

[13:59] frank@bpi-r2-e:~$ cat /usr/local/sbin/hostapd_2.sh
pid=$(ps auxf | grep hostapd | grep wlan1 | awk '{print $2}')
if [[ -n "$pid" ]];then
  kill -9 $pid
sleep 5s
hostapd -dd /etc/hostapd/hostapd_wlan1.conf &>/var/log/hostapd_wlan1.log &

you’re right, a made changes in hostapd_ap0.conf and created new hostapd_ap1.conf for external

Before adding second script to wifi.sh test it…

Based on your configuration you have to use different subnet for new wifi…ip and dhcp

is ap0 working now (connection and dhcp/access from client to server)?

Anyone having an idea how we can drop wmt_loader and stp_uart_launcher?

Maybe it’s a good idea to make wifi also to an module so that kernel itself is completely loaded when wifi-driver is initialized

hi, i’m trying to port wifi-driver to 5.3

compile/bootup works well, but i cannot write to /dev/wmtWifi

root@bpi-r2-ubuntu:~# echo A >/dev/wmtWifi                                      
-bash: echo: write error: Input/output error 
root@bpi-r2-ubuntu:~# ls -l /dev/wmtWifi                                        
crw------- 1 root root 155, 0 Jul 24 11:11 /dev/wmtWifi

any idea how to fix this? commands before (wmtloader,stp_uart_launcher) were without errors.

looked in dmesg and found this:

[  459.795195] [WMT-DETECT][I]wmt_detect_open:open major 154 minor 0 (pid 1677)                                                                                        
[  459.795234] [WMT-DETECT][I]wmt_detect_unlocked_ioctl:cmd (-2147191037),arg(0)                                                                                       
[  459.795328] [WMT-DETECT][I]wmt_detect_unlocked_ioctl:cmd (1074034433),arg(30243)                                                                                    
[  459.795336] set current consys chipid (0x7623)                                                                                                                      
[  459.795349] [WMT-DETECT][I]wmt_detect_unlocked_ioctl:cmd (-2147191036),arg(30243)                                                                                   
[  459.795359] [WMT-MOD-INIT][I]do_common_drv_init:start to do common driver init, chipid:0x00007623                                                                   
[  459.808166] [WMT-CONF][E]wmt_conf_parse_pair(323):unknown field 'mt6620.defAnt'.                                                                                    
[  459.808181] [WMT-CONF][E]wmt_conf_parse_pair(323):unknown field 'mt6628.defAnt'.                                                                                    
[  459.808189] [WMT-CONF][E]wmt_conf_parse_pair(323):unknown field 'mt6630.defAnt'.                                                                                    
[  459.811229] [WMT-CONSYS-HW][E]mtk_wmt_probe(123):Wmt Cannot find pinctrl default!                                                                                   
[  459.812574] [WMT-MOD-INIT][I]do_common_drv_init:finish common driver init                                                                                           
[  459.812592] [WCN-MOD-INIT][E]do_connectivity_driver_init(57):do common driver init failed, ret:-1                                                                   
[  459.812597] [GPS-MOD-INIT][I]do_gps_drv_init:CONFIG_MTK_COMBO_GPS is not defined                                                                                    
[  459.812602] [WCN-MOD-INIT][E]do_connectivity_driver_init(62):do common driver init failed, ret:-1                                                                   
[  459.812607] [FM-MOD-INIT][I]do_fm_drv_init:start to do fm module init                                                                                               
[  459.812611] [FM-MOD-INIT][I]do_fm_drv_init:finish fm module init                                                                                                    
[  459.812616] [WLAN-MOD-INIT][I]do_wlan_drv_init:start to do wlan module init 0x7623                                                                                  
[  459.813011] [MTK-WIFI] WIFI_init: mtk_wmt_WIFI_chrdev driver(major 155) installed.                                                                                  
[  459.813020] [WLAN-MOD-INIT][I]do_wlan_drv_init:WMT-WIFI char dev init, ret:0                                                                                        
[  459.813093] ------------[ cut here ]------------                                                                                                                    
[  459.813117] WARNING: CPU: 1 PID: 1677 at net/wireless/core.c:868 wiphy_register+0x900/0xc0c                                                                         
[  459.813122] Modules linked in:                                                                                                                                      
[  459.813135] CPU: 1 PID: 1677 Comm: wmt_loader Not tainted 5.3.0-rc1-bpi-r2-wifi #291                                                                                
[  459.813139] Hardware name: Mediatek Cortex-A7 (Device Tree)                                                                                                         
[  459.813143] Backtrace:                                                                                                                                              
[  459.813161] [<c010e4ec>] (dump_backtrace) from [<c010e800>] (show_stack+0x20/0x24)                                                                                  
[  459.813180]  r7:00000009 r6:60000013 r5:00000000 r4:c12bfb90                                                                                                        
[  459.813193] [<c010e7e0>] (show_stack) from [<c0c38624>] (dump_stack+0xbc/0xd0)                                                                                      
[  459.813204] [<c0c38568>] (dump_stack) from [<c01276e4>] (__warn+0xf0/0x108)                                                                                         
[  459.813212]  r7:00000009 r6:c106ab60 r5:00000000 r4:00000000                                                                                                        
[  459.813221] [<c01275f4>] (__warn) from [<c0127834>] (warn_slowpath_null+0x50/0x58)                                                                                  
[  459.813231]  r9:0000001e r8:0000003a r7:c1397444 r6:c0b6df4c r5:00000364 r4:c106ab60                                                                                
[  459.813243] [<c01277e4>] (warn_slowpath_null) from [<c0b6df4c>] (wiphy_register+0x900/0xc0c)                                                                        
[  459.813250]  r6:ffffffea r5:c1204c48 r4:e735e1a0                                                                                                                    
[  459.813263] [<c0b6d64c>] (wiphy_register) from [<c06d2adc>] (mtk_wcn_wlan_gen2_init+0x140/0x2ec)                                                                    
[  459.813273]  r10:ea7f63b8 r9:00007623 r8:c1204c48 r7:c0d7b2e0 r6:e672b600 r5:c138837c                                                                               
[  459.813278]  r4:e735e1a0                                                                                                                                            
[  459.813288] [<c06d299c>] (mtk_wcn_wlan_gen2_init) from [<c0691358>] (do_wlan_drv_init+0x5c/0x114)                                                                   
[  459.813296]  r7:80047704 r6:00007623 r5:00000000 r4:c12891f4                                                                                                        
[  459.813307] [<c06912fc>] (do_wlan_drv_init) from [<c0690f8c>] (do_connectivity_driver_init+0x64/0x14c)                                                              
[  459.813315]  r7:80047704 r6:00007623 r5:00007623 r4:fffffffe                                                                                                        
[  459.813324] [<c0690f28>] (do_connectivity_driver_init) from [<c0690420>] (wmt_detect_unlocked_ioctl+0x158/0x1c8)                                                    
[  459.813330]  r5:80047704 r4:c12891f0                                                                                                                                
[  459.813341] [<c06902c8>] (wmt_detect_unlocked_ioctl) from [<c02ff50c>] (do_vfs_ioctl+0xc0/0x91c)                                                                    
[  459.813349]  r7:80047704 r6:00000003 r5:e5266840 r4:e5266840                                                                                                        
[  459.813358] [<c02ff44c>] (do_vfs_ioctl) from [<c02ffdac>] (ksys_ioctl+0x44/0x68)                                                                                    
[  459.813368]  r10:00000036 r9:e778c000 r8:00007623 r7:80047704 r6:00000003 r5:e5266840                                                                               
[  459.813372]  r4:e5266840                                                                                                                                            
[  459.813381] [<c02ffd68>] (ksys_ioctl) from [<c02ffde8>] (sys_ioctl+0x18/0x1c)                                                                                       
[  459.813391]  r9:e778c000 r8:c0101204 r7:00000036 r6:00000000 r5:00000000 r4:be86abb8                                                                                
[  459.813402] [<c02ffdd0>] (sys_ioctl) from [<c0101000>] (ret_fast_syscall+0x0/0x54)                                                                                  
[  459.813407] Exception stack(0xe778dfa8 to 0xe778dff0)                                                                                                               
[  459.813416] dfa0:                   be86abb8 00000000 00000003 80047704 00007623 00000000                                                                           
[  459.813425] dfc0: be86abb8 00000000 00000000 00000036 00000000 00000000 b6f89000 00000000                                                                           
[  459.813432] dfe0: 00011010 be86ab84 000085b3 b6efb0a8                                                                                                               
[  459.813437] ---[ end trace 59c29bd1592a6faa ]---                                                                                                                    
[  459.814031] [WLAN-MOD-INIT][I]do_wlan_drv_init:WLAN-GEN2 driver init, ret:0                                                                                         
[  459.814041] [WLAN-MOD-INIT][I]do_wlan_drv_init:finish wlan module init                                                                                              
[  459.814676] [WMT-DETECT][I]wmt_detect_close:close major 154 minor 0 (pid 1677)                                                                                      
[  462.848809] [WMT-CORE][E]opfunc_hif_conf(874):WMT-CORE: WMT HIF info added                                                                                          
[  462.849086] DEBUG: Passed mtk_wcn_consys_hw_reg_ctrl 235                                                                                                            
[  462.849103] vcn18: mode operation not allowed                                                                                                                       
[  462.849109] DEBUG: Passed mtk_wcn_consys_hw_reg_ctrl 239                                                                                                            
[  462.849113] DEBUG: Passed mtk_wcn_consys_hw_reg_ctrl 242                                                                                                            
[  462.849123] DEBUG: Passed mtk_wcn_consys_hw_reg_ctrl 244                                                                                                            
[  462.849642] DEBUG: Passed mtk_wcn_consys_hw_reg_ctrl 251                                                                                                            
[  462.849965] DEBUG: Passed mtk_wcn_consys_hw_reg_ctrl 278                                                                                                            
[  462.850573] DEBUG: Passed mtk_wcn_consys_hw_reg_ctrl 280                                                                                                            
[  462.850580] DEBUG: Passed mtk_wcn_consys_power_on 194                                                                                                               
[  462.850622] DEBUG: Passed mtk_wcn_consys_power_on 196                                                                                                               
[  462.850685] DEBUG: Passed mtk_wcn_consys_power_on 203                                                                                                               
[  462.850691] DEBUG: Passed mtk_wcn_consys_hw_reg_ctrl 282                                                                                                            
[  462.850715] DEBUG: Passed mtk_wcn_consys_hw_reg_ctrl 287                                                                                                            
[  462.850723] [WMT-CONSYS-HW][E]mtk_wcn_consys_hw_reg_ctrl(302):Read CONSYS chipId(0xfffff093)                                                                        
[  462.950712] [WMT-CONF][E]wmt_conf_parse_pair(323):unknown field 'mt6620.defAnt'.                                                                                    
[  462.950741] [WMT-CONF][E]wmt_conf_parse_pair(323):unknown field 'mt6628.defAnt'.                                                                                    
[  462.950760] [WMT-CONF][E]wmt_conf_parse_pair(323):unknown field 'mt6630.defAnt'.                                                                                    
[  463.551515] [STP] mtk_wcn_stp_psm_enable:[W] STP Not Ready, Dont do Sleep/Wakeup                                                                                    
[  467.905980] [MTK-WIFI] WIFI_open: WIFI_open: major 155 minor 0 (pid 1675)                                                                                           
[  467.906040] [MTK-WIFI] WIFI_write: WIFI_write A                                                                                                                     
[  467.940714] [WMT-FUNC][E]wmt_func_wifi_on(651):WMT-FUNC: wmt call wlan probe fail(-1)                                                                               
[  467.940802] [WMT-CORE][E]opfunc_func_on(1053):WMT-CORE:type(0x3) function on failed, ret(-1)                                                                        
[  467.940857] drivers/misc/mediatek/connectivity/common/conn_soc/core/wmt_core.c, 1054, (0)                                                                           
[  467.941216] [MTK-WIFI] WIFI_write: WMT turn on WIFI fail!                                                                                                           
[  467.949589] [MTK-WIFI] WIFI_close: WIFI_close: major 155 minor 0 (pid 1675)

so something near mtk_wcn_wlan_gen2_init seems to go wrong


do_wlan_drv_init:WMT-WIFI char dev init, ret:0

mtk_wcn_wlan_gen2_init only calls initWlan which calls createWirelessDevice which calls wiphy_register,where crash occours

warning itself points to

wiphy-register is called here:

i found no position where vendor_commands[i].policy is set…maybe this is the problem

which points me to this commit: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=901bb9891855164fdcfcfdd9c3d25bcc800d3f5b

seems i need to change this struct same way it’s done in the commit for other drivers:

Currently patches out the warn-on and wifi works…have contacted author of this change to help me fixing this the right way…

1 Like

i think i have fixed the problem…can now start wifi with WARN_ON activated :slight_smile:


Hi all,

wow quite some content in this thread.

So what’s the current best way of doing wifi drivers for BPI-R2 with @frank-w 4.14-main branch? Do we still need the blobs with wmt_loader etc.?

Also: dId anyone find a way yet to make those go nicely with OpenWRT?


We still need wmt-tools cause i did not find a way to drop these and did not get any help on this yet.

@abbradar have tried pushing it to openwrt but it is too big and dirty to get it upstream (same for linux mainline)

ok thanks i will try the old blobs I used in the past and recombine them with your 4.14 branch then and see how that flies these days the openwrt userspace i currently use …

My repo and packages (tar.gz and deb) also containing the wmt-tools

I’ve updated my openwrt fork in https://github.com/abbradar/openwrt/tree/bpi-wifi , this required changes to wifi drivers code, see https://github.com/abbradar/mt6625l-wlan-gen2/commit/5a8fafb8b3d99da21d356219ed599556efbd990b . I’m also trying to upstream some patches again, see https://github.com/openwrt/openwrt/pull/2365

Nice to see you again…can you hrlp me getting the wifi-driver in better shape?

  • sort out necessary changes in mtk_wdt.c because they seems to break other devices like r64
  • drop wmt-tools

Nice to see you too :slight_smile: I’m currently working on upstreaming openwrt again (without wifi for now), would love to help with wifi after that.

  • What specifically do you try to change in mtk_wdt?
  • How are you going to get rid of ugly userspace helpers?

we have seen on porting that wifi does not work without use code in mtk_wdt.c

these are the changes in mtk_wdt.c (have simply copied the file from 4.14 to each kernel-version and did only compile fixes):


Here i tried to drop wmt-tools (first wmt_loader by initialize on bootup):

Have you ever send a Patch to mainline? What needs to be changed in pcie? Is it a dts or driver-patch? Afair i have no pcie-patch in 4.19+

I currently try to push poweroff-driver to mainline (and pcie/ahci to uboot)

@abbradar have you looked into it?

curently i try to port driver to 5.4, but again much have changed…one thing i don’t know to fix is build-errors (implicit-fallthrough). e.g. this one:

drivers/misc/mediatek/connectivity/wlan/gen2/common/wlan_lib.c: In function 'wlanCfgFindNextToken':
drivers/misc/mediatek/connectivity/wlan/gen2/common/wlan_lib.c:5834:8: error: this statement may fall through [-Werror=implicit-fallthrough=]
     if (x[1] != '\n') {
drivers/misc/mediatek/connectivity/wlan/gen2/common/wlan_lib.c:5838:4: note: here
    case '\n':
cc1: all warnings being treated as errors
make[6]: *** [drivers/misc/mediatek/connectivity/wlan/gen2/common/wlan_lib.o] Error 1
make[6]: *** Waiting for unfinished jobs....
In file included from ./include/linux/printk.h:332,
                 from ./include/linux/kernel.h:15,
                 from drivers/misc/mediatek/connectivity/wlan/gen2/os/linux/include/gl_os.h:534,
                 from drivers/misc/mediatek/connectivity/wlan/gen2/include/precomp.h:171,
                 from drivers/misc/mediatek/connectivity/wlan/gen2/common/wlan_oid.c:1061:
drivers/misc/mediatek/connectivity/wlan/gen2/common/wlan_oid.c: In function 'wlanoidSetAcpiDevicePowerState':
./include/linux/dynamic_debug.h:122:52: error: this statement may fall through [-Werror=implicit-fallthrough=]
 #define __dynamic_func_call(id, fmt, func, ...) do { \
./include/linux/dynamic_debug.h:143:2: note: in expansion of macro '__dynamic_func_call'
  __dynamic_func_call(__UNIQUE_ID(ddebug), fmt, func, ##__VA_ARGS__)
./include/linux/dynamic_debug.h:153:2: note: in expansion of macro '_dynamic_func_call'
  _dynamic_func_call(fmt, __dynamic_pr_debug,  \
./include/linux/printk.h:336:2: note: in expansion of macro 'dynamic_pr_debug'
  dynamic_pr_debug(fmt, ##__VA_ARGS__)
drivers/misc/mediatek/connectivity/wlan/gen2/os/linux/include/gl_kal.h:947:53: note: in expansion of macro 'pr_debug'
 #define kalPrint                                    pr_debug
drivers/misc/mediatek/connectivity/wlan/gen2/include/debug.h:258:33: note: in expansion of macro 'kalPrint'
 #define LOG_FUNC                kalPrint
drivers/misc/mediatek/connectivity/wlan/gen2/include/debug.h:265:3: note: in expansion of macro 'LOG_FUNC'
   LOG_FUNC("%s:(" #_Module " " #_Class ")"_Fmt, __func__, ##__VA_ARGS__); \
drivers/misc/mediatek/connectivity/wlan/gen2/common/wlan_oid.c:6556:3: note: in expansion of macro 'DBGLOG'
   DBGLOG(OID, INFO, "Set Power State: D1\n");
drivers/misc/mediatek/connectivity/wlan/gen2/common/wlan_oid.c:6558:2: note: here
  case ParamDeviceStateD2:

anyone can help here?

imho it’s a false positive, because implicit-fallthrough is printed if break is missing in a switch’s case and here it is written as comment that break is not wanted (to print D1-D3 together if Powerstate=D1 and always set powerstate to D3)

 6549         switch (*prPowerState) {
 6550         case ParamDeviceStateD0:
 6551                 DBGLOG(OID, INFO, "Set Power State: D0\n");
 6552                 kalDevSetPowerState(prAdapter->prGlueInfo, (UINT_32) ParamDeviceStateD0);
 6553                 fgRetValue = nicpmSetAcpiPowerD0(prAdapter);
 6554                 break;
 6555         case ParamDeviceStateD1:
 6556                 DBGLOG(OID, INFO, "Set Power State: D1\n");
 6557                 /* no break here */
 6558         case ParamDeviceStateD2:
 6559                 DBGLOG(OID, INFO, "Set Power State: D2\n");
 6560                 /* no break here */
 6561         case ParamDeviceStateD3:
 6562                 DBGLOG(OID, INFO, "Set Power State: D3\n");
 6563                 fgRetValue = nicpmSetAcpiPowerD3(prAdapter);
 6564                 kalDevSetPowerState(prAdapter->prGlueInfo, (UINT_32) ParamDeviceStateD3);
 6565                 break;
 6566         default:
 6567                 break;
 6568         }

please take also a look at the last commit (try to fix wakeup_source_prepare build-error), it compiles fine, but maybe it’s wrong (imho double memory-allocation)

@frank-w not yet, I won’t be near my R2 till mid-November :smiley: I think it’s false positive too but this is from 5-minute code reading.

thank you for first check…have marked the lines as wanted fallthroughs to get it compiled…any idea about the wakeup_source_prepare?

i tried to modify code to use wakeup_source_create directly, but can’t get it working till now

wake_lock_init called wakeup_source_init which is replaced by wakeup_source_create

 static inline void wake_lock_init(struct wake_lock *lock, int type,
                                  const char *name)
        wakeup_source_init(&lock->ws, name);

something like this (not working):

+++ b/drivers/misc/mediatek/connectivity/common/conn_soc/linux/pub/osal.c
@@ -984,12 +984,16 @@ INT32 osal_wake_lock_init(P_OSAL_WAKE_LOCK pLock)
        if (!pLock)
                return -1;
+       struct wakeup_source *ws;//=pLock->wake_lock;
        #ifdef CONFIG_PM_WAKELOCKS
        wakeup_source_init(&pLock->wake_lock, pLock->name);
        wake_lock_init(&pLock->wake_lock, WAKE_LOCK_SUSPEND, pLock->name);
+       ws=wakeup_source_create(pLock->name);
+       pLock->wake_lock->ws=ws;
        return 0;

the wakeup-functions were dropped with this Patch: https://patchwork.kernel.org/patch/11080905/

maybe my current implementation is ok…because before prepare-function has allocated memory which is now done by create-function

--- a/include/linux/pm_wakeup.h
+++ b/include/linux/pm_wakeup.h
@@ -186,7 +186,7 @@ static inline void pm_wakeup_dev_event(struct device *dev, unsigned int msec,
 static inline void wakeup_source_init(struct wakeup_source *ws,
                                      const char *name)
-       wakeup_source_prepare(ws, name);
+       ws=wakeup_source_create(name);

seems it’s not right yet…

[  340.888358] Backtrace: 
[  340.890813] [<c01afa48>] (mod_timer) from [<c0660c24>] (pm_wakeup_ws_event.part.8+0x94/0xc4)
[  340.899260]  r10:c13c9020 r9:c1301e08 r8:00000000 r7:a00f0193 r6:e68d51f8 r5:00000fd4
[  340.907092]  r4:e68d51e8
[  340.909630] [<c0660b90>] (pm_wakeup_ws_event.part.8) from [<c0660c74>] (pm_wakeup_ws_event+0x20/0x24)
[  340.918857]  r9:c1301e08 r8:ea021000 r7:000000d7 r6:e68d54e0 r5:00000000 r4:e68d44e0
[  340.926611] [<c0660c54>] (pm_wakeup_ws_event) from [<c06e9754>] (kalHifAhbKalWakeLockTimeout+0x34/0x38)
[  340.936012] [<c06e9720>] (kalHifAhbKalWakeLockTimeout) from [<c0713d4c>] (HifAhbISR+0x78/0x1b4)
[  340.944714]  r5:00000000 r4:e68d44e0
[  340.948294] [<c0713cd4>] (HifAhbISR) from [<c018ddd0>] (__handle_irq_event_percpu+0xa8/0x27c)
[  340.956824]  r6:00000000 r5:ea2f2268 r4:e68dc940

i guess it’s because pointer to ws changes inside function and does not pushed back to caller (no reference-parameter)…and the crash is the first access to the wrong pointer…how can i fix this?

in testing code above i need to assign pointer to new created struct (ws) to pLock->wake_lock->ws


0001-Drop-usage-of-wakelocks-Android-API-use-wake-sources.patch (12.6 KB)

Please try applying attached patch over 3061ab72e23bf4b077be3bf63faec28d13426d01 (it was the tip of 5.4-wifi at the moment of posting this message) and test if it works. Disclaimer: I hadn’t had a chance to boot-check this one, only did a compile-test. Changes in patch are to remove usage of Android specific wakelock API and switch into using wake sources API instead. Half of the driver had already been aware that wakesources exists but this support was disabled due to CONFIG_PM_WAKELOCKS being non-relevant for detecting if wake sources are available (and wake sources API is always safe to use no matter if wake sources are enabled/supported in current kernel). Instead all parts of the driver relied on the wakelock.h wrapper that was borrowed from the Android kernel sources and the only thing it did was to provide a fallback to wake sources API for wakelocks API calls.

IMO as you try to maintain driver specifically for linux kernel there’s no need to drag in Android compatibility bits - they only do increase maintenance burden for you. Thus I cleaned it up from parts that were relying on CONFIG_ANDROID and Android-only APIs.

1 Like

unfortunately same crash as before in pm_wakeup_ws_event, but in wifi-driver there is no call to this function…i guess it is called by kernel after a timeout reaches 0 and this is only initialized by wifi-driver with the wakeup_source_create (or similar) above

Well, looks like it’s time to sharpen my gdb skills :-). I will have to set up test image with this kernel though beforehand. I’d try to squeeze this into my evening schedule for today but no warranties :-).