2016/12/19

rtl8188eu ..

有人很好新 build 好了所有 kernel 版本的 ko..

...猜是從 這裡 build 的。

現在是 4.4.34+, build 930
所以 download path 是...https://dl.dropboxusercontent.com/u/80256631/8188eu-4.4.34-930.tar.gz
糟糕,dropbox public folder 功能要關了...


很麻煩。這個 wifi chip。

ap mode, trial1:
wifi dongle as access point, soft ap 8188eu on linux

這個是 source,要拉下來 make, make install
還好也有附 uninstall:
install:
        install -p -m 644 8188eu.ko  $(MODDESTDIR)
        @if [ -a /lib/modules/$(KVER)/kernel/drivers/staging/rtl8188eu/r8188eu.ko ] ; then modprobe -r r8188eu; fi;
        @echo "blacklist r8188eu" > /etc/modprobe.d/50-8188eu.conf
        cp rtl8188eufw.bin /lib/firmware/.
        /sbin/depmod -a ${KVER}
        mkdir -p /lib/firmware/rtlwifi
        cp rtl8188eufw.bin /lib/firmware/rtlwifi/.

uninstall:
        rm -f $(MODDESTDIR)/8188eu.ko
        /sbin/depmod -a ${KVER}
        @rm /etc/modprobe.d/50-8188eu.conf
build 好的安裝路徑是: /lib/modules/$(KVER)/kernel/drivers/net/wireless

2016/12/12

流水帳:wifi display...

WifiDisplaySetting.java: DEBUG=true
onCreate 後就啟動了...WifiP2pManager.initialize( )

framework/base/services/java/com/android/server/display/DisplayManagerService.java: DEBUG=true;
framework/base/services/java/com/android/server/display/WifiDisplayAdapter.java: DEBUG=true;
framework/base/services/java/com/android/server/display/WifiDisplayController.java: DEBUG=true

真正connect 的流程就在 WifiDisplayController.java: updateConnection()

大概就是..先 disconnect from the old one.
然後再call WifiP2pManager.connect( )
連線完成 call WifiP2pManager.setMiracastMode( )
然後叫 RemoteDispkay.listen( ) 這個 P2p connection...

有點跑掉...

framework/base/java/android/net/wifi/WifiNative.java: DBG=true;
doCommand : wifi_command
libhardware_legacy

wpa_ctrl_request( ) : TAG WifiHW
在 wpa_supplicant_8

是在 wpa_supplicant_8/wpa_supplicant/Android.mk
src/common/wpa_ctrl.c
有兩個 implement, depend on CTRL_IFACE_SOCKET 或是 CONFIG_CTRL_IFACE_NAMED_PIPE
因為 IFACE_UNIX, 所以是 IFACE_SOCKET
int wpa_ctrl_request(struct wpa_ctrl *ctrl, const char *cmd, size_t cmd_len,
                     char *reply, size_t *reply_len,
                     void (*msg_cb)(char *msg, size_t len))
..
wpa_ctrl structure 包含一個 socket.是 溝通的界面。
在 libhardware_legacy/wifi/wifi.c (wpa_supplicant 使用者) 中 是先呼叫:
wifi_connect_on_socket_path(const char *path)
{
   ctrl_conn = wpa_ctrl_open(path);
取得 connect socket
caller 是..
/* Establishes the control and monitor socket connections on the interface */
int wifi_connect_to_supplicant()
{
    static char path[PATH_MAX];

    if (access(IFACE_DIR, F_OK) == 0) {
        snprintf(path, sizeof(path), "%s/%s", IFACE_DIR, primary_iface);
    } else {
        snprintf(path, sizeof(path), "@android:wpa_%s", primary_iface);
    }
    return wifi_connect_on_socket_path(path);
}
其中..
static const char IFACE_DIR[]           = "/data/system/wpa_supplicant";
property_get("wifi.interface",primary_iface,..);
wifi.interface 定義在 system.prop : wlan0

完成後,用 android 的 system control:
    property_set("ctl.start", supplicant_name);
啟動 wpa_supplicant service.
根據 P2P 有沒有啟動, ctrl.start 的 service 不一樣:
static const char SUPPLICANT_NAME[]     = "wpa_supplicant";
static const char SUPP_PROP_NAME[]      = "init.svc.wpa_supplicant";
static const char P2P_SUPPLICANT_NAME[] = "p2p_supplicant";
static const char P2P_PROP_NAME[]       = "init.svc.p2p_supplicant";

找一下 libwpa_client..
其中只有:
  • src/common/wpa_ctrl.c
  • src/utils/os_unix.c

在 Android.mk:
include $(CLEAR_VARS)
LOCAL_MODULE = libwpa_client
LOCAL_CFLAGS = $(L_CFLAGS)
LOCAL_SRC_FILES = src/common/wpa_ctrl.c src/utils/os_$(CONFIG_OS).c
LOCAL_C_INCLUDES = $(INCLUDES)
LOCAL_SHARED_LIBRARIES := libcutils liblog
LOCAL_COPY_HEADERS_TO := libwpa_client
LOCAL_COPY_HEADERS := src/common/wpa_ctrl.h
include $(BUILD_SHARED_LIBRARY)
所以會把 wpa_ctrl.h copy 到 out folder 的 include/libwpa_client/ 下面。

所以有使用到的 project...
./frameworks/base/core/jni/Android.mk: libwpa_client \
./hardware/libhardware_legacy/wifi/Android.mk:LOCAL_SHARED_LIBRARIES += libnetutils libwpa_client
就 include "libwpa_client/wpa_ctrl.h"

framework/.../jni call 到 libhardware_legacy 的 wificommand.
沒有直接 call libwpa_client 的 api

所以所有call libwpa_client 的應該都是經過 libhardware_legacy

2016/11/29

bookmark: wifi display /Miracast sink


然後還有這篇,被 刪掉的 blog:
要改的部份:

1. #include <gui/SurfaceTextureClient.h> ==> #include <gui/Surface.h>
2. ISurfaceTexture ===> IGraphicBufferProducer

3. IMediaPlayerService    mPlayer = service->create(getpid(), mPlayerClient, 0); ==>
    mPlayer = service->create( mPlayerClient, 0);

4. sp<ISurfaceTexture> getSurfaceTexture(); ==>;    sp<IGraphicBufferProducer> getIGraphicBufferProducer() const;

比較仔細的是這一篇:https://github.com/kensuke/How-to-Miracast-on-AOSP/wiki/Android-4.4
但是 build 會出現:
frameworks/av/media/libstagefright/wifi-display/wfd.cpp:348: error: undefined reference to 
'android::WifiDisplaySink::WifiDisplaySink(unsigned int, 
                                           android::sp<android::ANetworkSession> const&, 
                                           android::sp<android::IGraphicBufferProducer> const&, 
                                           android::sp<android::AMessage> const&)'

2016/11/16

wifi worklog 隨便記

init.rc:
service p2p_supplicant /system/bin/logwrapper /system/bin/wpa_supplicant \
    -iwlan0 -Dnl80211 -c/data/misc/wifi/wpa_supplicant.conf \
    -I/system/etc/wifi/wpa_supplicant_overlay.conf -N \
    -ip2p0 -Dnl80211 -c/data/misc/wifi/p2p_supplicant.conf \
    -I/system/etc/wifi/p2p_supplicant_overlay.conf \
    -O/data/misc/wifi/sockets \
    -puse_p2p_group_interface=1 \
    -e/data/misc/wifi/entropy.bin -g@android:wpa_wlan0
    socket wpa_wlan0 dgram 660 wifi wifi
    class main
    disabled
    oneshot

然後在 device/.../ 下有 wifi_bt_common.mk

2016/11/14

eMMC 的 hardware rese pin - RST_n

JESD84-C44.pdf
Embedded MultiMediaCard
(e•MMC) Mechanical Standard,
with Optional Reset Signal

p.7:
Reset :RST_n 
Reset signal is used for host resetting device, moving the device to pre-idle state.
By default, the RST_n signal is temporary disabled in device. Host need to set bit[0:1] in
the extended CSD register [162] to 0x1 to enable this functionality before the host uses.

About Extended CSD Register:
The 512 bytes long Extended CSD register defines the Device properties and selected modes.
The Higher 320 bytes are the Properties segment, which defines the Device capabilities and cannot be
modified by the host. 
The lower 192 bytes are the Modes segment, which defines the configuration the
Device is working in. These modes can be changed by the host by means of the SWITCH command.

更新版:EMMC_JESD84-A441
p.164:
RST_n_FUNCTION [162]

For backward compatibility reason, RST_n signal is temporary disabled in device by default. Host may
need to set the signal as either permanently enable or permanently disable before it uses the card.
Bit[7:2]: Reserved
Bit[1:0]: RST_n_ENABLE (Reable and Writable once)
0x0: RST_n signal is temporarily disabled (default)
0x1: RST_n signal is permanently enabled
0x2: RST_n signal is permanently disabled
0x3: Reserved

By default, RST_n_ENABLE is set to 0x0, which is RST_n is temporarily disabled. Host can change the
value to either 0x1 (permanently enabled) or 0x2 (permanently disabled). Once host sets the value to either
one, the value can not be changed again.

Once host sets RST_n_ENABLE bits to 0x2 (permanently disabled), the card will not accept the input of
RST_n signal permanently.
During the disable period, the card has to take care that any state of RST_n (high, low and floating) will
not cause any issue (i.e. mal function and high leakage current in the input buffer) in the device.
When RST_n_ENABLE is set to 0x1 (permanently enabled), the card accepts the input of RST_n permanently.
Host can not change the bits back to the disabled values. Also, when host set RST_n_ENABLE to
0x1, the card must not start resetting internal circuits by triggering the register bit change. Internal reset
sequence must be triggered by RST_n rising edge but not by the register change.
Since card does not have any internal pull up or pull down resistor on RST_n terminal, host has to pull up
or down RST_n to prevent the input circuits from flowing unnecessary leakage current when RST_n is
enabled

http://www.mt-system.ru/sites/default/files/klmxgxge4a-x001mmc4_41_2ynm_based_emmc1_1.pdf
p.22
Extend CSD register 162 的 properties 是:R/W: One time programmable and readable

一樣,在 micross eMMC datasheet 也有。
說得更仔細, ECSD 的幾種 cell :
R  Read-only
R/W  One-time programmable and readable
R/W/E  Multiple writable with the value kept after a power cycle, assertion of the RST_n signal, and any
  CMD0 reset, and readable
R/W/C_P  Writable after the value is cleared by a power cycle and assertion of the RST_n signal (the
  value not cleared by CMD0 reset) and readable
R/W/E_P  Multiple writable with the value reset after a power cycle, assertion of the RST_n signal, and
  any CMD0 reset, and readable
W/E_P  Multiple writable with the value reset after power cycle, assertion of the RST_n signal, and any
  CMD0 reset, and not readable

所以 chip 的 ECSD 162 一但 enable 後,就沒辦法 disable 了。
--- 和 A441 說的不一樣?


Software 的 reset 是... CMD0
ref: SD Physical Layer Spec
p.24:
4.2.1 Card Reset
The command GO_IDLE_STATE (CMD0) is the software reset command and sets each card into Idle
State regardless of the current card state. Cards in Inactive State are not affected by this command.
After power-on by the host, all cards are in Idle State, including the cards that have been in Inactive
State before.
After power-on or CMD0, all cards’ CMD lines are in input mode, waiting for start bit of the next command.
The cards are initialized with a default relative card address (RCA=0x0000) and with a default
driver stage register setting (lowest speed, highest driving current capability). 

2016/10/26

banana pi -- jessie

很可惜的板子。
以前的 banana pi 只要 800,那時候一堆人用得很愉快。
後來,不知怎麼,所有的賣家都改成賣 1200 以上。
可惜,雖然只差 400
但是,1200 等級得的板子,大多效能,功能都比 banana pi 好很多。
-- raspberry pi 3. orange pi, ... etc

所以,他就失去了優勢,漸漸的沒落下去。
現在好像沒人用了。


用的是 banaian, 下載最新版就是 jessie 了。
燒錄一樣,解開 zip 後直接 dd

uart console TX.RX.GND 在版上gpio 旁邊有印
開機,在 ipv6 那版會卡一下,就跳出 login prompt
username: root
password: pi
開機完會有提示要你 run banaian-config
回答問題,把 root partition 加大。
timezone 選 Taipei
重開機,OK

看一下 sources.list, 竟然是標準的 debian.org
加入 proxy:
/etc/apt/apt.conf:

Acquire::http::Proxy "http://192.168.100.132:3128"
然後就可以 apt-get update 了..
出現 kernel 需要更新: linux-image-3.4-banaian


設定 ntp ... ref: ntpdate

run banania-update
這會用到 curl ,用 script run 不會 reference 環境變數,
所以只好修改 banania-update 這個 script, 在 curl 的命令中加入 -x option
ref: http://www.cyberciti.biz/faq/linux-unix-curl-command-with-proxy-username-password-http-options/
之後就可以 run 了...


repository 要放在 usb disk 上,所以要 mount usb disk 到 /home/git/ 下。
owner 要是 git
所以 format 完 usb disk 後,要先 mount 近來,然後去,,
 sudo chown git:git .
這樣 mount point 就會是 git:git 了。
ref:http://r40eubuntu.blogspot.tw/2014/11/mount-partition-and-owner.html


wifi

ref: http://r40eubuntu.blogspot.tw/2015/05/wifi-on-banana-pi-tp-link-tl-wn725n.html
插上,改一下 /etc/network/interfaces 就可以了。

routing table 會依照 network interface 啟動的順序決定 default gw 和 dns (resolv.conf)
要用 wlan 做 default gw 和 dns
所以..
先插著 wlan 開機,OK後,再插上 eth0
很奇怪,有時候 eth0 dhcp 部會正常動作,所以要手動 ifdown, ifup 一次。
之後, resolve.conf 會被改掉 (eth0)
所以要改回來...
nameserver 172.20.10.1

ap mode:

使用 hostapd 跟 dnsmasq 了。
/etc/hostapd/hostapd.conf
設定 SSID, password, wlan interface

/etc/dnsmasq.conf
設定 dnsmasq 的 ip range

然後就是 iptable
和 interfaces 要把 wlan1 設 static ip.

2016/10/7

FIQ_DEBUGGER console

arm kernel 有一個 option 是 CONFIG_FIQ_DEBUGGER_CONSOLE
如果開啟的話,就會讓 kernel 內部的 debug console 功能起動。
再開啟一個 CONFIG_FIQ_DEBUGGER_CONSOLE_DEFAULT_ENABLE 的話,就會用 debug UART 作為 kernel fiq debugger 的界面。

所以 kernel console 一邊作為 shell console 用,另一方面,也被作為 kernel debugger console用。

要讓 kernel debugger console 啟動,送出 Break 鍵。
用 Putty 的話,就是設定為 VT100+ 模式。
然後輸入 Ctrl-Break 就可以。,
console 會顯示:
#fiq debugger mode
debug >
這樣就進入 kernel debugger mode 了,

輸入 help 可以看 支援的 command
要回到 console mode 就輸入 console 就可以。

在 kernel debug mode 時,系統一樣正常運作。

minicom 要輸入 brk 的話,是 'Ctrl-A F'
tera term 的話,在 control 有一個 send break