Brillo: brillo-m10-dev @ RPi 3B – WiFi模块

我们知道Raspberry Pi 3B WiFi模块使用的是BCM43438芯片,并且网上关于这个芯片的介绍少之又少,实在是不符合Raspberry的选型规则啊。WiFi模支持STA模式那是必须的,但是能不能支持AP模式呢?

  • Raspbian系统

上网google之,果然有关于将其设置为AP模式的文章:https://frillip.com/using-your-raspberry-pi-3-as-a-wifi-access-point-with-hostapd/

1. WiFi工作在AP模式需要这两个安装包:

a. hostapd - 使WiFi工作在AP模式

b. dnsmasq-DNS server

执行如下命令进行安装:

$ sudo apt-get install hostapd dnsmasq

2. 配置网络接口wlan0

设置静态IP地址 - 修改/etc/dhcpcd.conf文件:

$ sudo cat >> /etc/dhcpcd.conf << EOF
interface wlan0  
    static ip_address=172.24.1.1/24
EOF

停用wpa_supplication - 修改/etc/ntwork/interfaces文件:

allow-hotplug wlan0  
iface wlan0 inet manual  
#    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

重启dhcpcd服务:

$ sudo service dhcpcd restart

NOTE: 如果不预先设置wlan0的IP地址,运行dhcpcd服务会失败。

3. 配置hostapd服务

创建配置文件-/etc/hostapd/hostapd.conf:

$ sudo cat >> /etc/hostapd/hostapd.conf << EOF
# This is the name of the WiFi interface we configured above
interface=wlan0

# Use the nl80211 driver with the brcmfmac driver
driver=nl80211

# This is the name of the network
ssid=Pi3-AP

# Use the 2.4GHz band
hw_mode=g

# Use channel 1
channel=1

# Accept all MAC addresses
macaddr_acl=0

# Use WPA authentication
auth_algs=1

# Require clients to know the network name
ignore_broadcast_ssid=0

# Use WPA2
wpa=2

# Use a pre-shared key
wpa_key_mgmt=WPA-PSK

# The network passphrase
wpa_passphrase=raspberry

# Use AES, instead of TKIP
rsn_pairwise=CCMP
EOF

NOTE: WiFi SSID名称为Pi3-AP,密码为raspbian。

修改/etc/default/hostapd文件:

$ sudo cat >> /etc/default/hostapd << EOF
DAEMON_CONF="/etc/hostapd/hostapd.conf"
EOF

4. 配置dnsmasq

修改/etc/dnsmasq.conf文件:

$ sudo cat >> /etc/dnsmasq.conf << EOF
interface=wlan0      # Use interface wlan0  
bind-interfaces      # Bind to the interface to make sure we aren't sending things elsewhere  
server=8.8.8.8       # Forward DNS requests to Google DNS  
domain-needed        # Don't forward short names  
bogus-priv           # Never forward addresses in the non-routed address spaces.  
dhcp-range=172.24.1.50,172.24.1.150,12h # Assign IP addresses between 172.24.1.50 and 172.24.1.150 with a 12 hour lease time  
EOF

5. 重启hostapd与dnsmasq服务

$ sudo service hostapd start 
$ sudo service dnsmasq start
  • Brillo系统

当前使用的分支为brillo-m10-dev, kernel的代码可以从这里下载:

https://github.com/raspberrypi/linux.git

使用的分支为rpi-4.1.y, commit ID为:

commit 20fe468af4bb40fec0f81753da4b20a8bfc259c9
Author: Phil Elwell <phil@raspberrypi.org>
Date:   Tue Mar 15 14:10:29 2016 +0000

    bcm2835-sdhost: Workaround for "slow" sectors
    
    Some cards have been seen to cause timeouts after certain sectors are
    read. This workaround enforces a minimum delay between the stop after
    reading one of those sectors and a subsequent data command.
    
    Using CMD23 (SET_BLOCK_COUNT) avoids this problem, so good cards will
    not be penalised by this workaround.
    
    Signed-off-by: Phil Elwell <phil@raspberrypi.org>

与NOOBS v1.9.0中所使用的kernel的版本一致,版本号可以从NOOBS_v1.9.0.zip/BUILD-DATA中取得:

$ cat /data/NOOBS_v1.9.0/BUILD-DATA 
Build-date: 2016-03-18
NOOBS Version: v1.9
NOOBS Git HEAD @ 776097e091d95b8ab23344c94d994b93f927b8a1
rpi-userland Git master @ c5341f09dc686c17966369485f7dd27f58dc081c
rpi-firmware Git master @ 951799bbcd795ddf27769d14acf4813fdcbe53dc
rpi-linux Git rpi-4.1.y @ 20fe468af4bb40fec0f81753da4b20a8bfc259c9

WiFi模块所使用的固件可以从NOOBS_v1.9.0.zip/os/Raspbian/root.tar.xz/lib/firmware/brcm/中取得,需要这两个文件:

a. brcmfmac43430-sdio.txt

b. brcmfmac43430-sdio.bin

其他bsp相关的文件可以从这里下载:brillo-m10-dev-device-hzak-rpi3b.tar.gz

最后文件的目录结构看起来应该是这样的:

/local/brillo-m10-dev-rpi3b
|-- device
|   `-- hzak
|       `-- rpi3b
|           |-- base_product
|           `-- bsp
`-- hardware
    `-- bsp
        `-- kernel
            `-- hzak
                `-- rpi-4.1.y

更新kernel config文件:

hzak@B85RPI:/local/brillo-m10-dev-rpi3b$ cp device/hzak/rpi3b/bsp/kernel-config \
    hardware/bsp/kernel/hzak/rpi-4.1.y/arch/arm/configs/bcm2709_defconfig

由于kernel不支持BOOT_CLOCKALARM_TIME,所以还需要修改system/bt/osi/src/alarm.c文件:

hzak@B85RPI:/local/brillo-m10-dev-rpi3b/system/bt$ git diff
diff --git a/osi/src/alarm.c b/osi/src/alarm.c
index fa4f856..62d396c 100644
--- a/osi/src/alarm.c
+++ b/osi/src/alarm.c
@@ -96,11 +96,11 @@ struct alarm_t {
 int64_t TIMER_INTERVAL_FOR_WAKELOCK_IN_MS = 3000;
 static const clockid_t CLOCK_ID = CLOCK_BOOTTIME;
 
-#if defined(KERNEL_MISSING_CLOCK_BOOTTIME_ALARM) && (KERNEL_MISSING_CLOCK_BOOTTIME_ALARM == TRUE)
+//#if defined(KERNEL_MISSING_CLOCK_BOOTTIME_ALARM) && (KERNEL_MISSING_CLOCK_BOOTTIME_ALARM == TRUE)
 static const clockid_t CLOCK_ID_ALARM = CLOCK_BOOTTIME;
-#else
-static const clockid_t CLOCK_ID_ALARM = CLOCK_BOOTTIME_ALARM;
-#endif
+//#else
+//static const clockid_t CLOCK_ID_ALARM = CLOCK_BOOTTIME_ALARM;
+//#endif
 
 // This mutex ensures that the |alarm_set|, |alarm_cancel|, and alarm callback
 // functions execute serially and not concurrently. As a result, this mutex

NOTE: 从代码上看,如果kernel支持BOOT_CLOCKALARM_TIME需要RTC硬件支持,并且要求这个RTC硬件能够唤醒系统,而RPi 3B显然不支持。

如果不进行修改,系统开机的时候会出现如下fatal error:

04-01 16:58:57.341   237   238 E bt_btif_config: init unable to load backup; creating empty config.
04-01 16:58:57.342   237   238 E bt_osi_alarm: timer_create_internal unable to create timer with clock 9: Unknown error 524
04-01 16:58:57.342   237   238 E bt_osi_alarm: The kernel might not have support for timer_create(CLOCK_BOOTTIME_ALARM): https://lwn.net/Articles/429925/
04-01 16:58:57.342   237   238 E bt_osi_alarm: See following patches: https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/log/?qt=grep&q=CLOCK_BOOTTIME_ALARM
04-01 16:58:57.342   237   238 F libc    : system/bt/osi/./src/alarm.c:160: alarm_new_internal: assertion "false" failed
04-01 16:58:57.342   237   238 F libc    : Fatal signal 6 (SIGABRT), code -6 in tid 238 (stack_manager)
04-01 16:58:57.405   241   241 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
04-01 16:58:57.406   241   241 F DEBUG   : Build fingerprint: 'Brillo/rpi3b/rpi3b:6.0.1/MASTER/hzak04011258:eng/test-keys'
04-01 16:58:57.406   241   241 F DEBUG   : Revision: '0'
04-01 16:58:57.406   241   241 F DEBUG   : ABI: 'arm'
04-01 16:58:57.406   241   241 F DEBUG   : pid: 237, tid: 238, name: stack_manager  >>> /system/bin/bluetoothtbd <<<
04-01 16:58:57.406   241   241 F DEBUG   : signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
04-01 16:58:57.411   241   241 F DEBUG   : Abort message: 'system/bt/osi/./src/alarm.c:160: alarm_new_internal: assertion "false" failed'
04-01 16:58:57.411   241   241 F DEBUG   :     r0 00000000  r1 000000ee  r2 00000006  r3 00000008
04-01 16:58:57.411   241   241 F DEBUG   :     r4 75f6d978  r5 00000006  r6 75f6d920  r7 0000010c
04-01 16:58:57.411   241   241 F DEBUG   :     r8 00000001  r9 75f6d4b8  sl 7691b580  fp 75d83014
04-01 16:58:57.411   241   241 F DEBUG   :     ip 0000020c  sp 75f6d3d0  lr 76ac428f  pc 76ac6adc  cpsr 20000010
04-01 16:58:57.429   241   241 F DEBUG   : 
04-01 16:58:57.429   241   241 F DEBUG   : backtrace:
04-01 16:58:57.429   241   241 F DEBUG   :     #00 pc 00047adc  /system/lib/libc.so (tgkill+12)
04-01 16:58:57.429   241   241 F DEBUG   :     #01 pc 0004528b  /system/lib/libc.so (pthread_kill+34)
04-01 16:58:57.430   241   241 F DEBUG   :     #02 pc 0001bc99  /system/lib/libc.so (raise+10)
04-01 16:58:57.430   241   241 F DEBUG   :     #03 pc 00017877  /system/lib/libc.so (__libc_android_abort+34)
04-01 16:58:57.430   241   241 F DEBUG   :     #04 pc 00016f64  /system/lib/libc.so (abort+4)
04-01 16:58:57.430   241   241 F DEBUG   :     #05 pc 00019cbf  /system/lib/libc.so (__libc_fatal+22)
04-01 16:58:57.430   241   241 F DEBUG   :     #06 pc 00017a6f  /system/lib/libc.so (__assert2+18)
04-01 16:58:57.430   241   241 F DEBUG   :     #07 pc 000d9907  /system/lib/hw/bluetooth.default.so
04-01 16:58:57.430   241   241 F DEBUG   :     #08 pc 00041a6f  /system/lib/hw/bluetooth.default.so
04-01 16:58:57.430   241   241 F DEBUG   :     #09 pc 000d8be1  /system/lib/hw/bluetooth.default.so
04-01 16:58:57.430   241   241 F DEBUG   :     #10 pc 0007381d  /system/lib/hw/bluetooth.default.so
04-01 16:58:57.430   241   241 F DEBUG   :     #11 pc 000dde2f  /system/lib/hw/bluetooth.default.so
04-01 16:58:57.430   241   241 F DEBUG   :     #12 pc 000dcf39  /system/lib/hw/bluetooth.default.so
04-01 16:58:57.430   241   241 F DEBUG   :     #13 pc 000ddbc1  /system/lib/hw/bluetooth.default.so
04-01 16:58:57.430   241   241 F DEBUG   :     #14 pc 00044d5b  /system/lib/libc.so (__pthread_start(void*)+22)
04-01 16:58:57.430   241   241 F DEBUG   :     #15 pc 000182cd  /system/lib/libc.so (__start_thread+6)

配置编译环境与编译代码:

hzak@B85RPI:/local/brillo-m10-dev-rpi3b$ . build/envsetup.sh
$ lunch rpi3b-eng
$ m -j 4

烧机相关的步骤请参考这篇文档:http://www.brobwind.com/archives/219

默认情况下,如果在开机的时候连接有线网络,WiFi不会切换到AP模式,可以修改设备中的system/etc/init/weaved.rc,强制让WiFi工作在AP模式:

# cat /system/etc/init/weaved.rc                                               
on post-fs-data
    mkdir /data/misc/weaved 0700 system system

service weaved /system/bin/weaved --device_whitelist=wlan0
    class late_start
    user system
    group system dbus inet

由于在WiFi工作在AP模式时,所使用的网段为192.168.0.0/24,而wlan0使用静态IP地址192.168.0.254。如果再接入有线网络的时候,要保证这两个网口使用不同的网段。

另入一个问题是,firewalld服务无法使用iptables命令配置防火墙,可能需要手动配置tcp端口号:

iptables -I INPUT -p tcp --dport 80 -j ACCEPT -w
iptables -I INPUT -p tcp --dport 443 -j ACCEPT -w

RPi 3B WiFi工作在AP模式下,接入的设备还是无法自动获取IP地址,需要在连接的时候手动指定IP地址,当然指定的IP地址也需要在这个网段内:192.168.0.0/24。

  • 相关的参考文档:
  1. https://frillip.com/using-your-raspberry-pi-3-as-a-wifi-access-point-with-hostapd/

评论

1 Comment on "Brillo: brillo-m10-dev @ RPi 3B – WiFi模块"

提醒我
avatar

trackback

[…] 3B内置的WiFi模块BCM43438可以使WiFi工作在AP与STA模式->@<-。WiFi工作在AP模式时,需要dnsmasq服务作为dhcp […]

wpDiscuz