ubuntu 在 R40e 上 還有 Debian 在 Sempron 2600 上

2014年12月26日 星期五

5.0.2 Nexus7 2012

ref:
  • http://forum.xda-developers.com/showthread.php?t=1907796
  • https://developers.google.com/android/nexus/images
這個是另一種方法:http://www.android-apk.com/2014/11/nexus-7-nexus-10-%E5%B9%B3%E6%9D%BF-android-5-0-lollipop-ota-link/


Download, 結果是tgz, 解開。
首先 adb 要能動。
用 adb reboot-bootloader
重開機,進入 bootloader
fastboot oem ublock
停住,畫面上問你Yes, No, touch "Yes"
...
(bootloader) erasing userdata...
(bootloader) erasing userdata done
(bootloader) erasing cache...
(bootloader) erasing cache done
(bootloader) unlocking...
(bootloader) Bootloader is unlocked now.
OKAY [ 11.693s]
finished. total time: 11.693s
接著就可以到剛剛解開的tgz的folder 去run script:
/nakasi-lrx22g$ ./flash-all.sh 
...
(bootloader) Bootloader is already unlocked
OKAY [  0.007s]
finished. total time: 0.007s
erasing 'boot'...
OKAY [  0.027s]
finished. total time: 0.027s
******** Did you mean to fastboot format this partition?
erasing 'cache'...
OKAY [  0.053s]
finished. total time: 0.053s
erasing 'recovery'...
OKAY [  0.028s]
finished. total time: 0.028s
******** Did you mean to fastboot format this partition?
erasing 'system'...
OKAY [  0.090s]
finished. total time: 0.090s
******** Did you mean to fastboot format this partition?
erasing 'userdata'...
OKAY [  1.087s]
finished. total time: 1.087s
sending 'bootloader' (2100 KB)...
OKAY [  0.268s]
writing 'bootloader'...
FAILED (remote: (InvalidState))
finished. total time: 0.408s
rebooting into bootloader...
OKAY [  0.002s]
finished. total time: 0.052s
archive does not contain 'boot.sig'
archive does not contain 'recovery.sig'
archive does not contain 'system.sig'
archive does not contain 'vendor.img'
Creating filesystem with parameters:
    Size: 14442037248
    Block size: 4096
    Blocks per group: 32768
    Inodes per group: 8176
    Inode size: 256
    Journal blocks: 32768
    Label: 
    Blocks: 3525888
    Block groups: 108
    Reserved block group size: 863
Created filesystem with 11/883008 inodes and 96825/3525888 blocks
Creating filesystem with parameters:
    Size: 464519168
    Block size: 4096
    Blocks per group: 32768
    Inodes per group: 7088
    Inode size: 256
    Journal blocks: 1772
    Label: 
    Blocks: 113408
    Block groups: 4
    Reserved block group size: 31
Created filesystem with 11/28352 inodes and 3654/113408 blocks
--------------------------------------------
Bootloader Version...: 4.23
Baseband Version.....: N/A
Serial Number........: 015d257xxxxxxxxx
--------------------------------------------
checking product...
OKAY [  0.040s]
checking version-bootloader...
OKAY [  0.023s]
sending 'boot' (5152 KB)...
OKAY [  0.636s]
writing 'boot'...
OKAY [  0.181s]
sending 'recovery' (5688 KB)...
OKAY [  0.691s]
writing 'recovery'...
OKAY [  0.200s]
erasing 'system'...
OKAY [  0.045s]
sending 'system' (648819 KB)...
OKAY [ 77.444s]
writing 'system'...
OKAY [ 31.717s]
erasing 'userdata'...
OKAY [  0.997s]
sending 'userdata' (137526 KB)...
OKAY [ 16.400s]
writing 'userdata'...
OKAY [  8.035s]
erasing 'cache'...
OKAY [  0.039s]
sending 'cache' (9052 KB)...
OKAY [  1.094s]
writing 'cache'...
OKAY [  0.492s]
rebooting...

finished. total time: 138.227s
然後就自己重開了...
進入圓球跑跑畫面.....持續 5 min

開進 android 畫面。

還好,沒有明顯變慢,當然也不會變快。
本來,asus 做的這台就是慢到不行。


第二天:一般還好,有些ap 開啟特別慢,像 chrome, twitter, fb
而且有月用月慢的感覺。
猜測這是 2012 n7 的nandflash 問題。
只有靠 f2fs 才能解決了。

2015/4/20
因為 linux journal login 有問題,一直說我exceeded the device limit,
然後 linux journal 的 mail 又說他 OK
所以我用一樣的方法把 nexus 7 重新燒 4.4.4

2014年12月24日 星期三

ref:
  • http://www.bennee.com/~alex/blog/2014/05/09/running-linux-in-qemus-aarch64-system-emulation-mode/
  • http://gogojesseco.blogspot.tw/2014/05/arm64.html

 ./configure --target-list=aarch64-softmmu
Disabling libtool due to broken toolchain support

ERROR: glib-2.12 gthread-2.0 is required to compile QEMU
ref: http://stackoverflow.com/questions/16931060/installing-qemu-on-lubuntu-13-04
說:
The error message from configure is misleading.

If you run it using bash -x you see:

:
:
+ cc -fPIE -DPIE -m64 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -Wendif-labels -Wmissing-include-dirs -Wempty-body -Wnested-externs -Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers -Wold-style-declaration -Wold-style-definition -Wtype-limits -fstack-protector-all -o /tmp/qemu-conf-14056-22808-16535.exe /tmp/qemu-conf-19869-22808-12418.c -Wl,-z,relro -Wl,-z,now -pie -m64 -g
+ return 1
+ test '' = yes
+ bluez=no
+ test no = yes
+ glib_req_ver=2.12
+ query_pkg_config --atleast-version=2.12 gthread-2.0
+ pkg-config --atleast-version=2.12 gthread-2.0
+ error_exit 'glib-2.12 required to compile QEMU'
+ echo

+ echo 'ERROR: glib-2.12 required to compile QEMU'
ERROR: glib-2.12 required to compile QEMU
+ test -n ''
+ echo

+ exit 1
+ rm -f /tmp/qemu-conf-19869-22808-12418.c /tmp/qemu-conf-12208-22808-897.o /tmp/qemu-conf-14056-22808-16535.exe
So you see that what is really missing is gthread-2.0. Now gthread-2.0 is part of the libglib2.0-dev "Development files for the GLib library" that is not installed by default. If you install it, you should be able to get past this stage, and them probably fail because pixman or something els isn't installed, but you wont need to install every glib dev library!

./sudo aptitude install libglib2.0-dev
then do config again:
./configure --target-list=aarch64-softmmu
Disabling libtool due to broken toolchain support
Install prefix    /usr/local
BIOS directory    /usr/local/share/qemu
binary directory  /usr/local/bin
library directory /usr/local/lib
module directory  /usr/local/lib/qemu
libexec directory /usr/local/libexec
include directory /usr/local/include
config directory  /usr/local/etc
local state directory   /usr/local/var
Manual directory  /usr/local/share/man
ELF interp prefix /usr/gnemul/qemu-%M
Source path       /home/charles-chang/teatime/qemu-2.2.0
C compiler        cc
Host C compiler   cc
C++ compiler      c++
Objective-C compiler cc
ARFLAGS           rv
CFLAGS            -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -pthread -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include  -g 
QEMU_CFLAGS       -I$(SRC_PATH)/pixman/pixman -I$(BUILD_DIR)/pixman/pixman -I$(SRC_PATH)/dtc/libfdt -fPIE -DPIE -m64 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common  -Wendif-labels -Wmissing-include-dirs -Wempty-body -Wnested-externs -Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers -Wold-style-declaration -Wold-style-definition -Wtype-limits -fstack-protector-all
LDFLAGS           -Wl,--warn-common -Wl,-z,relro -Wl,-z,now -pie -m64 -g 
make              make
install           install
python            python -B
smbd              /usr/sbin/smbd
module support    no
host CPU          x86_64
host big endian   no
target list       aarch64-softmmu
tcg debug enabled no
gprof enabled     no
sparse enabled    no
strip binaries    yes
profiler          no
static build      no
pixman            internal
SDL support       no
GTK support       no
VTE support       no
curses support    yes
curl support      no
mingw32 support   no
Audio drivers     oss
Block whitelist (rw) 
Block whitelist (ro) 
VirtFS support    no
VNC support       yes
VNC TLS support   no
VNC SASL support  no
VNC JPEG support  no
VNC PNG support   no
VNC WS support    no
xen support       no
brlapi support    no
bluez  support    no
Documentation     yes
GUEST_BASE        yes
PIE               yes
vde support       no
netmap support    no
Linux AIO support no
ATTR/XATTR support yes
Install blobs     yes
KVM support       yes
RDMA support      no
TCG interpreter   no
fdt support       yes
preadv support    yes
fdatasync         yes
madvise           yes
posix_madvise     yes
sigev_thread_id   yes
uuid support      no
libcap-ng support no
vhost-net support yes
vhost-scsi support yes
Trace backends    nop
spice support     no
rbd support       no
xfsctl support    no
nss used          no
libusb            no
usb net redir     no
GLX support       yes
libiscsi support  no
libnfs support    no
build guest agent yes
QGA VSS support   no
seccomp support   no
coroutine backend ucontext
coroutine pool    yes
GlusterFS support no
Archipelago support no
gcov              gcov
gcov enabled      no
TPM support       yes
libssh2 support   no
TPM passthrough   yes
QOM debugging     yes
vhdx              no
Quorum            no
lzo support       no
snappy support    no
NUMA host support no

2014年12月22日 星期一

因為 android studio 的 gradle complain 說 jdk 要到 7.
但是 build android source 時,我又要 6.

所以都裝。
然後系統 default 用 6 (update-alternatives)

然後在 android studio 的 Setting 中,選 jdk path 到 openjdk-7-amd64

2014年12月19日 星期五

crossmnt : nfs mount 包含 server mount 的內容

用途:

當 nfs mount server 的目錄下,有mount 其他的 partition 時。
client 端往往只能看到空目錄,不會看到 server mount partition 的內容。

如果要讓 client 也能看到 server mount 的內容。

就要:
  • server 把 mount partition 的 path 也 export (再一次)
  • 那個 partition 的 parent folder 在 exports 裡的宣告,要加上 crossmnt 這個 option


ref: http://unix.stackexchange.com/questions/42131/how-to-properly-export-and-import-nfs-shares-that-have-subdirectories-as-mount-p

2014年12月17日 星期三

inject the HOME key to system

L 先生看到 'Back Button(No root) 這個 ap, 可以作到像 iOS asistant button 的動作。
可以送出 HOME/BACK/MENU

裝還後,他會註冊一個 accessibility service, 要 user 開啟他 才能動作。

所以查了一下 android 的 accessibility service,

發現:
constant: GLOBAL_ACTION_HOME
找一下 framewowk:
在 framework/base/services/java/com/android/server/accessibility/AccessibilityManagerService.java
        public boolean performGlobalAction(int action) {
               ...
               ...
                switch (action) {
                    case AccessibilityService.GLOBAL_ACTION_BACK: {
                        sendDownAndUpKeyEvents(KeyEvent.KEYCODE_BACK);
                    } return true;
                    case AccessibilityService.GLOBAL_ACTION_HOME: {
                        sendDownAndUpKeyEvents(KeyEvent.KEYCODE_HOME);
                    } return true;
                    ...
所以,service 送出 GLOBAL_ACTION_HOME 後,framework 的 action handle 就會模擬出一個 HOME 按鍵動作。

2014年12月16日 星期二

Kconfig, show/hide options and select

Kconfig 的 item,如果沒有 prompt 屬性,就不會在 make menuconfig 顯示出來。

prompt 屬性有兩種表示方法:
  • 直接寫在 type 後面。像: tristate "Soc Sound Card for I2S support"
  • 用 prompt 直接寫一行。像:prompt "Soc Sound Card for I2S support"

沒有在 make menuconfig 列出來的像木,通常是被其他 item select 的項目。
也就是說,如果選了某個 option,則這個option 也要 select

2014年12月12日 星期五

rfkill

rfkill 好像是用來開關所有Wireless 裝置的架構 (Bt, wifi, ..etc)

l$ sudo rfkill list
0: phy0: Wireless LAN
 Soft blocked: yes
 Hard blocked: no
1: tpacpi_bluetooth_sw: Bluetooth
 Soft blocked: no
 Hard blocked: no
2: hci0: Bluetooth
 Soft blocked: no
 Hard blocked: no
列出所有的裝置,和開關狀態。
其中 Hardware 好像是說有些 nb 有實際的switch, button 控制 wifi, bluetooth.
Software 就是軟體的設定狀態。

rfkill 的開/關是用 unblock, block

rfkill block 0 -- 關掉第一個裝置 (phy0 : Wireless LAN)

rfkill 在 kernel 有一個專門的 driver:
net/rfkill/

之後,所有support rfkill 的 driver ,都要寫一個 rfkill 的註冊城市。

        rfkill->rfkill_dev = rfkill_alloc("csrbt-8311", &pdev->dev,
                                          RFKILL_TYPE_BLUETOOTH,
                                          &rfkill_gpio_ops, rfkill);
        if (!rfkill->rfkill_dev) {
                ret = -ENOMEM;
                goto fail_reset;
        }

        ret = rfkill_register(rfkill->rfkill_dev);
        if (ret < 0)
                goto fail_rfkill;

        platform_set_drvdata(pdev, rfkill);

2014年12月11日 星期四

jiffies, msecs_to_jiffies( )

jiffies 是 kernel 內部 tick 的記數。
要是要知道頻率,可以用: msecs_to_jiffies(100) 來看,100ms 是要幾個 jiffies.

2014年12月10日 星期三

遭遇到
Failed to start samba.service: Unit samba.service is masked.
ref: http://aptosid.com/index.php?name=PNphpBB2&file=viewtopic&p=17662

所以看一下,果然,smbd 有起來。
所以應該是:
 sudo service smbd start
芳鄰可以用了。

遭遇到..
W: Failed to fetch http://dl.google.com/linux/chrome/deb/dists/stable/main/binary-amd64/Packages: Hash Sum mismatch
W: Failed to fetch http://dl.google.com/linux/chrome/deb/dists/stable/main/binary-i386/Packages: Hash Sum mismatch
E: Some index files failed to download. They have been ignored, or old ones used instead.
不知道是因為 google site, down 還是 ?

因為 follow : http://askubuntu.com/questions/502263/hash-sum-mismatch-when-installing-spotify-on-14-04

把 /var/lib/apt/lists/*都刪除,一樣沒效。

2014年12月5日 星期五

raspberry pi, airplay mirror -- xbmc-gamebox

上次測試 raspbmc 已經可以 support airplay 了 (不含 mirror)
現在令一個公司 xbmc-gamebox 補足了 mirro 的功能: ref: http://www.xindawn.com/bbs/viewtopic.php?f=5&t=8&sid=c0e5ff300675e69e30139605d2632cee

就 download sd card image, run 企來,
其他就 follow 上次 raspbmc 就可以。

實測是真的有 mirror 功能。
但是 lag (delay) 大了一些,
所以像一些跑庫,racing 的 game 都不能玩,控制會 delay

還有上次 raspbmc 的 youtube 問題一樣存在。

2014年12月4日 星期四

java.lang.IllegalArgumentException
 at sun.nio.ch.Net.checkAddress(Net.java:24)
 at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:512)
 at java.nio.channels.SocketChannel.open(SocketChannel.java:146)
 at com.android.ddmlib.DeviceMonitor.openAdbConnection(DeviceMonitor.java:261)
 at com.android.ddmlib.DeviceMonitor.deviceMonitorLoop(DeviceMonitor.java:163)
 at com.android.ddmlib.DeviceMonitor.access$000(DeviceMonitor.java:44)
 at com.android.ddmlib.DeviceMonitor$1.run(DeviceMonitor.java:84)
然後是..
java.lang.RuntimeException: Timeout getting device list!
 at net.srcz.android.screencast.Main.waitDeviceList(Unknown Source)
 at net.srcz.android.screencast.Main.initialize(Unknown Source)
 at net.srcz.android.screencast.Main.(Unknown Source)
 at net.srcz.android.screencast.Main.main(Unknown Source)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
 at com.sun.javaws.Launcher.executeApplication(Launcher.java:1822)
 at com.sun.javaws.Launcher.executeMainClass(Launcher.java:1763)
 at com.sun.javaws.Launcher.doLaunchApp(Launcher.java:1525)
 at com.sun.javaws.Launcher.run(Launcher.java:131)
 at java.lang.Thread.run(Thread.java:662)

2014年12月3日 星期三

ant 就是 Make ..

用來build java project 的 tool : apache ant
角色上就跟用來 build c project 的 Make 一樣。

那為什麼要特別做一個 tool 呢?
有什麼是 Make 做不到的 ?

這一篇有說明:

大概是因為啟動 javac 的時間很長,所以compile java 傾向於一次 compile 很多 java file.
和 c 一次compile 一個差異很大。

加上 target-depends rules 的更動,不太容易處理階層性的 source code.
所以才重寫了 make 的 tool

所以,就把 ant 當 make 就好了


make 是吃 Makefile
ant 是吃 build.xml (default)

是 xml 格式。
大約也跟 makefile 一樣,定義變數,定義 target, 然後有 action

同意也有 include 的功能。
還有一些定義另外分別開來,叫 property file, 或 config 檔,。

啟動ant 的 command 大概就是:
ant -v -f build.xml
加上 -v 是output message,好方便 verify 動作。


android software developement kit 也使用 ant 作為 build system (雖然後來又改用 grandle)
所以sdk 中有一個 folder: sdk/tools/ant, 裡面有一些寫好的 xml,
讓 developer 直接使用,不用自己再寫 build.xml



ant 雖然是為java 而做,但是他在包裝 jar 時,不會自動 copy resource file (png, wav,..etc)。
所以 jar 中用 getResource("icon.png"), 常常會出現 nullpointerexception.
因為 ant 在包 jar 時,沒有把 icon.png 也包進去。

一般來說,resource 所在位置,就是要跟使用 getResource( ) 的那個 class 在相同的目錄。
ref: http://stackoverflow.com/questions/804150/ant-compile-doesnt-copy-the-resources

就是在 jar 的 action 加上.. https://github.com/checko/androidscreencast_org/commit/fe9083623469a2e8e533179226766b84bfcd09a9

2014年12月2日 星期二

install run-java6 on Debian Jessie

去 http://ghaffarian.net/downloads/Java/JDK/ 下載 jdk-6u45-linux-x64.bin (因為到 oracle 下載要註冊).

ref: http://unix.aspcode.net/view/635395087004115229152482/install-java-sdk-6-wheezy

debiand 沒辦法直接提供 oracle java package (因為 license),但是提供了把 Orcale java 包裝成 deb 的 tool:
apt-get install java-package
包裝 jdk-6u45-linux-x64.bin:
make-jpkg jdk-6u45-linux-x64.bin
安裝剛剛包好的 deb:
dpkg -i oracle-java6-jdk_6u45_amd64.deb

Selecting previously unselected package oracle-java6-jdk.
(Reading database ... 169950 files and directories currently installed.)
Preparing to unpack oracle-java6-jdk_6u45_amd64.deb ...
Unpacking oracle-java6-jdk (6u45) ...
Setting up oracle-java6-jdk (6u45) ...
update-alternatives: using /usr/lib/jvm/jdk-6-oracle-x64/jre/bin/ControlPanel to provide /usr/bin/ControlPanel (ControlPanel) in auto mode
update-alternatives: using /usr/lib/jvm/jdk-6-oracle-x64/jre/lib/amd64/libnpjp2.so to provide /usr/lib/mozilla/plugins/libjavaplugin.so (mozilla-javaplugin.so) in auto mode

會裝在 /usr/lib/jvm/jdk-6-oracle-x64

然後就是設定 default :
sudo update-java-alternatives -s jdk-6-oracle-x64
然後會 complain 一下 這個 folder 有一些 tool 沒提供。

2014年11月28日 星期五

build and install minidlna from source

因為一些舊的 distribution 沒有,所以只好自己 build

ref:
先download source..
現在 sourceforge 也有提供 git 囉: http://sourceforge.net/p/minidlna/git/ci/master/tree/

裝好需要的 libxxx-dev

然後依照說明 (INSTALL),應該是要先 run ./autogen.sh
但是 他 complain 說 gettext 版本太舊。

所以只好直接做:
./configure
make
sudo make install
然後是手動的部份:
sudo cp minidlna.conf /etc/
sudo cp linux/minidlna.init.d.script /etc/init.d/minidlna
sudo chmod 755 /etc/init.d/minidlna
sudo update-rc.d minidlna defaults
這樣做完之後,就可以和一般一樣,編輯 /etc/minidlna.conf
然後用 service minidlna start|stop|status 來控制了。



為了測試(亂動),所以 fork 一份到 github 了: https://github.com/checko/minidlna

client (player) 的話,用 VLC 就可以了。vlc 2.0 以上都有內建 UPNP player 功能。
ref: http://askubuntu.com/questions/88754/upnp-dlna-client-player-recommendations

開啟的位置是: View -- Playlist -- Local Network -- Universal Plug'N'Play

2014年11月27日 星期四

controldlna and iperf

from : https://github.com/Nutomic/controldlna

附的 build tool 是 gradle.

build 的過程大概就是...

找不到 android sdk ..
ref: http://xinyustudio.wordpress.com/2014/07/02/gradle-sdk-location-not-found-the-problem-and-solution/

new 一個 local.properties:
sdk.dir=/home/charles-chang/adt-bundle-linux-x86_64-20140702/sdk
這樣就可以。

剩下就是 需要對應的 sdk version, build tool version, support repository 等等。
就有 error 就開啟 android sdk manager 來 install 就可以。


github: https://github.com/checko/iperf-project

這個 project 很有趣,是分成兩部份: iperf, Android UI

iperf 就是一般的 iperf 執行城市,所以是用 ndk-build,
build 出來執行檔 iperf 會被放在 Android package 的 assets 中。

UI 啟動後,把 assets/iperf copy 到 /data/data/iperf.project/ 來執行。
 InputStream  in  = getResources().getAssets().open("iperf");
 OutputStream out = new FileOutputStream("/data/data/iperf-project/iperf", false);
 byte[] buf = new byte[1024];
 int len;
 while ((len=in.read(buf)) > 0) {
    out.write(buf,0,len);
 }
 in.close();
 out.close();

然後 chmod +x :
 Process processchmod = runtime.GetRuntime().exec("/system/bin/chmod 744 /data/data/iperf.project/iperf");
 processchmod.waitFor();

執行 iperf 和取得結果的動作在令一個 , AsyncTask 做:
先把 command process 做出來,執行。
 List<String> commandList = new ArrayList<String>(Arrays.asList(commands));
 commandsList.add(0,"/data/data/iperf.project/iperf");
 Process process = new ProcessBuilder().command(commandList).redirectErrorStream(true).start();

然後拿到這個 process 的 output, 接到一個 InputStream 來讀:
 BufferReader reader = new BufferReader(new InputStreamReader(process.getInputStream()));

 int read;
 char[] buffer = new char[4096];
 StringBuffer output = new StringBuffer();
 while((read = reader.read(buffer)) > 0) {
   output.append(buffer,0,read);
   publishProgress(output.toString());
   output.delete(0,output.length());
 }
 reader.close();
 process.destroy();

2014年11月26日 星期三

mount partition and the owner

mount partition 的時候,mount folder 的 ower 依據 partition 的 filesystem 而有不同的決定方法。
像沒有 owner attr 的 filesystem, 像 fat。
就可以在 mount 的時候指定 uid, gid

如果是本來就有 ower attr 的 filesystem, 像 ext4
就是由 partition 的 root attrib 決定的。

像 mount ext4 進來後,到 mount folder 的 root 去看 (ls -al)

那個 . 的 owner 是誰,就決定 mount folder 的 owner 是誰。

2014年11月20日 星期四

enable adb for redmi 1s

ref: http://en.miui.com/thread-52488-1-1.html

大概就是..
  • 把redmi1s 的 各種 vid, pid 寫到 /etc/udev/rules.d/50-android.rules, 讓 user 有 access 的權限
  • 新增 .android/adb_usb.int 把 redmin1s 的 vid 寫進去,這樣 adb server 才會認得

redmi1s 的pid 根據mode 會不一樣:
# Xiaomi Redmi1S WCDMA - PTP Mode
SUBSYSTEM=="usb", ATTR{idVendor}=="2717", ATTR{idProduct}=="1210", MODE="0666",GROUP="plugdev"
# Xiaomi Redmi1S WCDMA - PTP Mode with USB Debug
SUBSYSTEM=="usb", ATTR{idVendor}=="2717", ATTR{idProduct}=="1218", MODE="0666",GROUP="plugdev"
# Xiaomi Redmi1S WCDMA - USB Mode == Built-in CD-ROM Mode!
SUBSYSTEM=="usb", ATTR{idVendor}=="2717", ATTR{idProduct}=="1220", MODE="0666",GROUP="plugdev"
# Xiaomi Redmi1S WCDMA - USB Mode with USB Debug
SUBSYSTEM=="usb", ATTR{idVendor}=="2717", ATTR{idProduct}=="1228", MODE="0666",GROUP="plugdev"
# Xiaomi Redmi1S WCDMA - MTP Mode
SUBSYSTEM=="usb", ATTR{idVendor}=="2717", ATTR{idProduct}=="1260", MODE="0666",GROUP="plugdev"
# Xiaomi Redmi1S WCDMA - MTP Mode with USB Debug
SUBSYSTEM=="usb", ATTR{idVendor}=="2717", ATTR{idProduct}=="1268", MODE="0666",GROUP="plugdev"

而 .android/adb_usb.in 內,就是把 vid 寫進去:
0x2717

2014年11月13日 星期四

sfdisk . script fdisk.

create_partition(p, 1, +5M)...
create_partition(p, 2, +30M)...
create_partition(p, 3, +160M)...
create_partition(e, 4, +all)...
create_partition(l, 5, +100M)...
create_partition(l, 6, +512M)...
create_partition(l, 7, +1024M)...
create_partition(l, 8, +all)
寫成 sfdisk 的 script 的話是....

start, size, id, bootable

FT2323R vid 0403 pid 0000 driver

[14771.500536] usb 3-1.4: new full-speed USB device number 8 using xhci_hcd
[14771.959368] usb 3-1.4: New USB device found, idVendor=0403, idProduct=0000
[14771.959374] usb 3-1.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[14771.959378] usb 3-1.4: Product: FT232R USB UART
[14771.959381] usb 3-1.4: Manufacturer: FTDI
[14771.959384] usb 3-1.4: SerialNumber: A92X933R
這個 usb-serial driver 已經內建在 kernel 理了 /lib/module/`uname -r`/kernel/drivers/usb/serial/ftdi_sio

但是大概因為這個 chip 是新的,所以不會自己 load

ref: https://bbs.archlinux.org/viewtopic.php?id=175499

先 load ftdi_sio ,之後再把 0403 0000 寫入 new_id:
# modprobe ftdi_sio
# echo 0403 0000 > /sys/bus/usb-serial/drivers/ftdi_sio/new_id 

這樣之後...
[16240.939782] usbcore: registered new interface driver usbserial
[16240.939807] usbcore: registered new interface driver usbserial_generic
[16240.939827] usbserial: USB Serial support registered for generic
[16240.950945] usbcore: registered new interface driver ftdi_sio
[16240.950969] usbserial: USB Serial support registered for FTDI USB Serial Device
[16281.458752] usbserial: USB Serial deregistering driver FTDI USB Serial Device
[16281.458807] usbcore: deregistering interface driver ftdi_sio
[16580.239129] usbcore: registered new interface driver ftdi_sio
[16580.239174] usbserial: USB Serial support registered for FTDI USB Serial Device
[16660.940658] ftdi_sio 3-1.4:1.0: FTDI USB Serial Device converter detected
[16660.940749] usb 3-1.4: Detected FT232RL
[16660.940754] usb 3-1.4: Number of endpoints 2
[16660.940758] usb 3-1.4: Endpoint 1 MaxPacketSize 64
[16660.940762] usb 3-1.4: Endpoint 2 MaxPacketSize 64
[16660.940766] usb 3-1.4: Setting MaxPacketSize 64
[16660.941420] usb 3-1.4: FTDI USB Serial Device converter now attached to ttyUSB0
就出現 ttyUSB0 了。

又因為 ftdi_sio 已經load在 kernel,所以拔掉 後再插一樣會動作。

2014年11月12日 星期三

Test Install Jessie ..

因為 nb 夠新,所以把 iso copy 到 /dev/sdX (usb) 就可以開機。
開機按 F12, 選 usb

直接裝 jessie 沒辦法開機。
所以裝 wheezy,記得 grub 要裝到 usb 上,不要裝在 mbr 上。
一開始選安裝target 時要寄一下是 /sdX,因為後來裝 grub 時,要寫,,,,

system time 是 UTC 沒錯 (有問?)
裝完 OK

然後改 sources.lst ,把 wheezy 改 jessie, update, dist-upgrade (超久,約 2hrs)。
開機 OK

裝 mate -- 一堆,結果開機一樣進 gnome3。
follow instruction 把 gnome* remove.
然後裝 lightdm

重開,出現不一樣的login 畫面。
進入是最基本的 WM. 所有 windows 都沒有邊框。
猜是因為 remove gname* 的關係。

network 也沒啟動,只好手動 加 /etc/network/interface 的 eth0

裝 network-manager-gnome.

這樣大概用了 4.7 G


not sure if it's OK, just a command log:

sudo apt-get install git gnupg flex bison gperf build-essential   zip curl libc6-dev libncurses5-dev x11proto-core-dev   libx11-dev libreadline6-dev libgl1-mesa-glx   libgl1-mesa-dev g++-multilib mingw32 tofrodos   python-markdown libxml2-utils xsltproc zlib1g-dev

libz.so.1:   lib32z1 lib32ncurses5

add squeeze main non-free, install sun-java6-jdk -- not work, break a lot packages dependency.
add wheezy main, install openjdk-6-jdk, downgrade jre to 6
sudo update-alternatives --config java


正式安裝

裝在 HD 上,用 jessie Oct.5 的 image 直接安裝就可以。
將 iso dd 到 usb 上,開機近bios 選 startup..當插兩隻 usb 時,如果開機順續錯,就交換。
usb 3.0 port 的 boot pri 好像比較高。
proxy 時,要用 http://192.168.100.132:3128
不可以家字串符號,也不可以不加 http
裝完也可以開機。

所以可以直接選 MATE, 不要gnome.

先是時間,這次沒看到問 UTC還是 local,就直接用 UTC 了。
但是因為 bios 是 local,所以時間是錯的。

有說從 wheezy 開始,不要用 rcS 設定 UTC=yes/no 了。
要改用 /etc/adjtime

但是這個 adjtime 要用 hwclock 產生。
不可以自己 edit。

查一下,系統沒有這個檔。

hwclock 產生 /etc/adjtime 的方法就是用 hwclock 設定一次時間。
sudo hwclock --set --localtime --date "07 Nov 2014 14:39:55"
這樣 /etc/adjtime 就產生了。
因為有指定 localtime,所以是把 RTC 當 localtime 用。

很奇怪,改完 bios 時間竟然變了,只好重新設定 bios, 之後就 OK 了。

中文輸入

MATE 很陽春,沒有 input config.
所以就裝了 scim 和 scim-chewing

裝完就出現 scim 和 config-input,
用 config-input 選 scim,default 也選 scim。
然後 follow : http://blog.roodo.com/rocksaying/archives/31556973.html
dpkg-reconfigure locales, 選 zh_TW,UTF-8

重開機,status bar 出現 keyboard,已經可以用 ctrl-space 切換輸入法了。


自動登入/autologin

MATE 是用 lightdm,所以 config 是 /etc/lightdm
follow https://wiki.debian.org/LightDM
修改 /etc/lightdm/lightdm.conf
-#autologin-user=
-#autologin-user-timeout=0
+autologin-user=checko-chang
+autologin-user-timeout=3


fix: lightdm 不會 run .profile

ref: http://bazaar.launchpad.net/~ubuntu-branches/ubuntu/oneiric/lightdm/oneiric/revision/10
方法就是..叫 lightdm 啟動後去 run 一個 script,然後那個 script 去 run .profile..
一樣修改 /etc/lightdm/lightdm.conf:
diff --git a/lightdm.conf b/lightdm.conf
index 49f7d9f..fc5163c 100644
--- a/lightdm.conf
+++ b/lightdm.conf
@@ -105,7 +105,7 @@
 #allow-user-switching=true
 #allow-guest=true
 #guest-session=
-#session-wrapper=lightdm-session
+session-wrapper=/etc/lightdm/Xsession
 #greeter-wrapper=
 #guest-wrapper=

然後加上這個 Xsession:

wifi/BCM43228

就 follow wheezy 的安裝方法..https://wiki.debian.org/wl#Debian_7_.22Wheezy.22
但是做完,modprobe 時竟然說找不到 wl 這個 module.

回頭看一下 安裝的 log, 好像說,因為 kernel header 與 kernel 版本不符,所以skip build module 的動作。
找一下 install 的 kernel 版本 (uname -a) 是 3.16-2
但是安裝的 kernel header 版本是 3.16-3

做 apt-get update, apt-get upgrade 看到,.. hold back 項目有 kernel-image
改用 aptitude upgrade 竟然就安裝了...
重開機後,果然變成 3.16-3

purge 後再 install broadcom-sta-dkms, 果然就開始 build module

完成後 modprobe wl 也 OK

然後再 top banner 的網路 panel. 就出現 wifi, 一些 AP 出現,可以連線了。

裝 gconf-editor
沒用。


裝 chrome, 要 libappindicator1

proxy 認錯,所以要用command line 啟動。看一下 man google-chromd

git difftool readonly

ref: http://stackoverflow.com/questions/18544238/how-to-prevent-git-vimdiff-from-opening-files-as-read-only
就是 create 一個 .vimrc,裡面是:
:set noro

就可以了。
另外,要 set vimdiff 為 git diff 的 tool ,可以用 command:
git config --global diff.tool vimdiff  
git config --global difftool.prompt No


Build Android

缺 libmpc.so.2 -- 裝 libmpc2
缺libgmp.so.3 -- 沒辦法解,只好到其他的系統 (ubuntu 12.10 amd64), copy libgmp.so.3 到 /usr/lib

然後是 "mixed implicit and normal rules: deprecated syntax"
這個 ref: http://stackoverflow.com/questions/9356735/makefile-rule-error-mixed-implicit-and-normal-rules

我的 case 是:
all %:
        $(SILENT)for dir in $(KBUILD_SUBDIRS); \
        do \
        ,,,
根據 ref 的說法,是 target 包含 explicit(all) 和 implicit (%)。是不行的,
所以猜開兩個,。就是方開寫 (copy):
all:
     $(SILENT) for dir in ...

%:
     $(SILENT)for dir in ,..


make 4.x 的沒辦法 make gingerbread, 只好copy 其他機器的舊版 make 回來,放到 bin/ 下。
-- jessie 的 lighdm 有問題,部會 run .profile,所以要自己 run..

然後一樣,build fail, 要裝 xutils-dev, lib32z1-dev (不然 ld 會說找不到 -lz), lib32ncurses (ld 5找不到 lncurses), lib32readline6-dev

jessie 的 gcc 版本是 4.9 和 4.8。

一樣,要裝 4.4 (for 2.3).
裝完後 一樣。 (ref: http://r40eubuntu.blogspot.tw/2013/11/wheezy-dell-n1418.html)
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.4 50 --slave /usr/bin/g++ g++ /usr/bin/g++-4.4 --slave /usr/bin/gcov gcov /usr/bin/gcov-4.4

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 40 --slave /usr/bin/g++ g++ /usr/bin/g++-4.9 --slave /usr/bin/gcov gcov /usr/bin/gcov-4.9
手動建 link /usr/include/x86_64/zconf.h 到 /usr/include


然後是那個 weak point assgined to ... public 問題,google 起來是 openjdk 與 sunjdk 不相容的地方。
如果不想改 sun jdk 的話,只好把發生這個 error 的 cts/Android.mk MARK 調..

改 sun jdk 比較麻煩,因為還要改用舊版 jdk6. ref: http://r40eubuntu.blogspot.tw/2014/12/install-run-java6-on-debian-jessie.html


某版 build uboot 說..
/home/charles-chang/17.2.14/boot/uboot/lib/rsa/rsa-sign.c:12:25: error: openssl/rsa.h: No such file or directory
/home/charles-chang/17.2.14/boot/uboot/lib/rsa/rsa-sign.c:13:25: error: openssl/pem.h: No such file or directory
...
本來以為是沒有指到正確的 android/external/openssl
結果竟然是 host 的問題。
$sudo aptitude install libssl-dev
就 OK 了


接著是 make android 後面:
linux-x86/sign/mkimage: error while loading shared libraries: libssl.so.0.9.8: cannot open shared object file: No such file or directory
make: *** [android-recovery] Error 127

查一下,系統的是 .../x86_64-linux-gnu/libssl.so.1.0.0

所以到舊 server 去...copy libssl.so.0.9.8

之後是缺 libcrypto.so.0.9.8


然後是 flash.sh, 新的 fdisk 不吃 tab, 不會自動律調。
所以用
echo "n
p
1

+32M
wq " | fdisk -c -u /dev/sdc
這樣的 command,左邊要對齊。

還是不行耶,jessie shell script 好像會有點重疊。
所以只好改用 ..
echo -e 'n\np\n1\n\n+32M\nwq" | fdisk
這樣的寫法,並且為了減少重疊,把所有 command 都準備好之後再一次使用 fdisk

format 出問題:
常常 format 到 partition 6 的時候出現 resource busy, 所以 part size 是 0 的狀況。
加 delay 也沒用。

結果,把所有 &t;null 都拿掉,吐出所有 message 後,就 OK 了。


adb permission denied

就 follow google 那一篇: http://developer.android.com/tools/device.html
在 /etc/udev/rules.d/ 下新增一個 file : 50-android.rules:
SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", MODE="0666", GROUP="plugdev" 

然後記得自己要在 plugdev 這個 group 李。
改完重開機就可以。

後來令一個 2.3 板的 竟然 idVendor 不一樣,所以再加一行就可以:
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", MODE="0666", GROUP="plugdev"


sudo no password

ref: http://askubuntu.com/questions/192050/how-to-run-sudo-command-with-no-password/443071#443071

就是改:
# Allow members of group sudo to execute any command
#%sudo  ALL=(ALL:ALL) ALL
%sudo ALL=(ALL) NOPASSWD:ALL

2014年11月10日 星期一

debian jessie MATE disable Automount

要先安裝 dconf-editor,
然後 run dconf-editor

在 mate/desktop/media-handling/automount uncheck

2014年11月5日 星期三

unicode, UTF...

ref: http://www.cnblogs.com/skyaspnet/archive/2011/02/18/1957770.html

原來 unicode 是只 code 與 字的對應。
UTF 是 Unicode Tranform Format
是為了節省(?) 空間,對 unicode 進行編碼。
--就像壓縮的方式。
所以有 UTF-8.16.32 三種編碼方式。

2014年11月4日 星期二

AirPlay AirTune Keys

http://theiphonewiki.com/wiki/AirPlay

所以 public , private key 都被找出來了,,,,
這樣不等於沒有 key ,,,,

--- 為什麼不換?

另外 這是 airtune 的 protocol 說明:http://git.zx2c4.com/Airtunes2/about/

link - 手動啟動 ppp

from http://mafipulation.org/blagoblig/

belows are the copies:

Wed, 03 Jul 2013

Japanese data SIM adventures
I've just arrived in Osaka, and so has my b-mobile Visitor SIM, which promises a prepaid data connection. Unfortunately, my phone doesn't even attempt a data connection, because the SIM won't let the phone register on the network at large - and it just gives up.

I was pretty grumpy at having a non-returnable $30 SIM I can't use. So I booted my phone into baseband mode (where the baseband IC presents itself directly on the phone's USB port, allowing me to send it AT commands). Checking the network registration with AT+CREG yields 3 - registration denied. But the GPRS registration, AT+CGREG, is valid! Evidently not a situation the phone's designers considered. But how do we use it?

The answer is to use the +CGDATA command, which opens a connection we can use for PPP. Now you just need to set up PPP... update: there is a super neat solution by Josua Dietze, check the bottom of this post for the link! Setting up PPP on Android
To make this work, you need a rooted phone with direct access to your baseband's AT-style port. On my Droid 4 this is /dev/ttyUSB4. If you don't know what this means, stop reading here.

I had to build chat and ended up building my own pppd because the Android one logs to the Android logs (duh), so here they are as binaries for you: chat, and pppd. I put them in /system/xbin.

You then need to write the following files: /etc/ppp/options.mobile, changing ttyUSB4 for your tty:
ttyUSB4
modem
passive
novj
defaultroute
noipdefault
usepeerdns
persist
holdoff 10
maxfail 0
noauth
nodetach
debug
You will probably want to remove nodetach and/or debug once you have it working, depending on how you run it.

/etc/ppp/peers/mobile, changing (or removing) the user/password lines:
file /etc/ppp/options.mobile
user "bmobile@fr"
password "bmobile"
connect "/system/xbin/chat -v -t15 -f /etc/ppp/chat.mobile"
Now for /etc/ppp/chat.mobile, where you must replace bmobile.ne.jp with your APN:
TIMEOUT 10
ABORT 'ERROR'
ABORT 'BUSY'
ABORT 'NO CARRIER'
'' ATZ OK
'AT+CGDCONT=1,"IP","bmobile.ne.jp"' OK
AT+CGDATA="PPP",1 CONNECT
Finally, /etc/ppp/ip-up, which you must then chmod 755:
#!/system/bin/sh

ip route add default via $4
setprop net.dns1 $DNS1
setprop net.dns2 $DNS2
You should now be able to run the whole shebang with:
/system/xbin/pppd call mobile
If it runs all the way to printing you some IP addresses and running the ip-up script, you are a winner. Note that it may not replace the default route if you already have one (if you're on wifi, for example).

Of course, apps which use the Android network manager to decide if they're connected will still refuse to work - Google Maps won't let you search, for example. Any suggestions for tricking the manager?
The right and obvious answer
The amazing Josua Dietze has already done all this, wrapped it into an app, and sorted out all the network manager issues. Amazing! Get it from the Play Store.

2014年11月3日 星期一

try raspbmc

因為download 了 install.img 也不知道怎麼作,
所以還是 follow http://www.raspbmc.com/wiki/user/os-x-linux-installation/

這個 python script 是會從網路下載 image,並且dd 到 SDCard,
所以:
  1. 要有 root 權限
  2. 要有 網路連線
因為要經過 proxy,所以該頁面下有一個 comment 是修改 script,加上 proxy support:
diff --git a/install.py b/install.py
index 71f5926..b8a2557 100755
--- a/install.py
+++ b/install.py
@@ -73,7 +73,10 @@ def chunk_read(response, file, chunk_size, report_hook):
 
 def download(url):
     print "Downloading, please be patient..."
-    dl = urllib2.urlopen(url)
+    proxy_support = urllib2.ProxyHandler({'http':'192.168.11.1:8080'})
+    opener = urllib2.build_opener(proxy_support)
+    urllib2.install_opener(opener)
+    dl = opener.open(url)
     dlFile = open('installer.img.gz', 'w')
     chunk_read(dl, dlFile, 8192, chunk_report)
     #dlFile.write(dl.read())
這樣就可以,
run 完,插入 board 開機....到:
Starting dropnbear sshd: generating rsa key... generating dsa key... NET: Registered protocol family 10
OK
然後就...
所以只好改 download full image : image.gz, 解開後直接 dd...

開機進入 OK, 是接有線
但是因為找不到 proxy 設定,所以無法連上 internet 作 update.
只好設法改用 iPhone 的 Wifi AP..

從 install.py 做起,,, Advance 選 Yes,
到 Wifi 選 Wireless, SSID ,password 設好。
開機,一樣卡住,看起來連 Wifi Dongle (TP-LINK TL-WN725N) 的 driver (8818eu) 都沒找到。
只好再從 full image 開始做起,,,

開機,到 program -- Raspbmc 設定,Wifi. SSID, password 都要設好,用 Search AP 沒用。
apply 後,可以正確連上了。

連上後,到 System Info 去看,就開始自動 update....
kernel, module, 重開機,..然後是 security patch... XBMC build (這個很久..)

開機後已經是 3.12, 10/29 build, 應該是很新了...

在 System Service 開啟 AirPlay ,之後,
開啟 iphone 的 Wifi Ap.
讓 raspbmc 連上
在 iphone 的上拉menu 出現 Airplay 選擇。
選這個 RASPBMC, 不能選 mirroring.

之後在一些影片播放的 ap 都會有這個選項出現,

選後,影片會自動在 raspbmc 上播放。

2014年10月31日 星期五

2012 nexus 7 無法開機

後來依照這一篇: https://support.google.com/nexus/troubleshooter/3337561?hl=zh-Hant
現象是:

按 power 沒反應。
插入 usb 沒出現 白電池。
長按 power 也沒反應。

所以依照上面的影片:
  1. 插上usb 充電 一小時 (我充 5min)
  2. 拔掉usb 再馬上插上
  3. 按 power button 15 sec
結果終於出現 白電池。


充電真的是 asus 的死穴啊,記得TF101 也是這樣,放電太多就沒辦法充。

2014年10月24日 星期五

usb . some codes, about force full speed connect

driver 的 data : struct ehci_hcd, 內嵌在 struct usb_hcd 裡。
usb_hcd 是在 init_host_mode( ) 時 create 出來的。
hcd = usb_create_hcd(...)
compion_ports 是一個 bit variable, 每一個 bit 代表一個 port.
這個變數代表哪一個 port 歸 companion controller 管。


SET_CMF(PORTC1, reg_val, PFSC, 0x01);
這個 function 定義是:
#define SET_CMF(r, rv, c, v) rv = ((rv & ~r##_##c##_MASK) | (v << r##_##c##_OFFSET)) 
所以上面就變成..
PORTC1_PFSC_MASK 和 PORTC1_PFSC_OFFSET 的操作。


ehci_hcd.c -- include 一堆。
其中有 :
module_init(ehci_hcd_init);
所以這個大概是 driver 的本體(?)

include
  • ehci-hub.c
  • sucksoc_usb_hcd.c
另一個 driver 本體應該就是 socksoc_usb_driver.c ..

其中的 control register table 初始話就 是在 driver probe:
 rsc = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 
 usbcd_db->vaddr = (u8 *)ioremap(rsc->start, (rsc->end - rsc->start + 1));

datasheet , Port Status Control Register 中,有一個 Port Force Full Speed Connect.
可以限制 在 full speed 工作。

理論上只要 set 這個 bit,並且 keep 住,就可以讓 usb controller 工作在 full-speed.

但是這個 bit 在 controller reset 後就會被 clear。
所以要注意,reset 前要 先 save bit, 完後 restore

這樣找完所有的 code, 修改掉後,就可以讓 usb controller 工作在 full speed 了。

usb has_tt

usb driver 裡有一個 flag : has_tt.
tt 是 Transation Translater.
Wifi 說這個東西是 hub 用的。

hub 接到 High Speed 的 device 時,直接接到 up.
hub 接到 full speed 的 device 時,先經過 TT,再到 up

這是為了比免低速的 packet 站住大部分 up 的頻寬。
TT 會先用低速 buffer 住 full speed 的packet,再用 High Speed 送到 UP

2014年10月17日 星期五

Usb thumb driver


pchome..699 跟 450

kernel message 是:
usb 3-1.3.4: new high speed USB device using ehci_hcd and address 5
usb 3-1.3.4: New USB device found, idVendor=8564, idProduct=1000
usb 3-1.3.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
usb 3-1.3.4: Product: Mass Storage Device
usb 3-1.3.4: Manufacturer: JetFlash
usb 3-1.3.4: SerialNumber: 
usb 3-1.3.4: configuration #1 chosen from 1 choice
scsi7 : SCSI emulation for USB Mass Storage devices
usb-storage: device found at 5
usb-storage: waiting for device to settle before scanning
usb-storage: device scan complete
scsi 7:0:0:0: Direct-Access     JetFlash Transcend 32GB   1100 PQ: 0 ANSI: 6
sd 7:0:0:0: Attached scsi generic sg5 type 0
61702144 512-byte logical blocks: (31.5 GB/29.4 GiB)
Write Protect is off
Mode Sense: 43 00 00 00
speed:
charles-chang@squeeze:~$ sudo hdparm -tT /dev/sde

/dev/sde:
 Timing cached reads:   14904 MB in  2.00 seconds = 7457.59 MB/sec
 Timing buffered disk reads: 102 MB in  3.03 seconds =  33.69 MB/sec
charles-chang@squeeze:~$ sudo hdparm -tT /dev/sde

/dev/sde:
 Timing cached reads:   9202 MB in  2.00 seconds = 4603.31 MB/sec
 Timing buffered disk reads: 102 MB in  3.04 seconds =  33.53 MB/sec
charles-chang@squeeze:~$ sudo hdparm -tT /dev/sde

/dev/sde:
 Timing cached reads:   14386 MB in  2.00 seconds = 7198.39 MB/sec
 Timing buffered disk reads: 102 MB in  3.04 seconds =  33.54 MB/sec
write:
charles-chang@squeeze:~/sd$ sudo dd if=/dev/zero of=tempfile bs=1M count=1024 conv=fdatasync,notrunc
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB) copied, 65.8158 s, 16.3 MB/s

第2 支

kernel msg:
usb 3-1.3.4: USB disconnect, address 5
usb 3-1.3.4: new high speed USB device using ehci_hcd and address 6
usb 3-1.3.4: New USB device found, idVendor=125f, idProduct=312b
usb 3-1.3.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
usb 3-1.3.4: Product: ADATA USB Flash Drive
usb 3-1.3.4: Manufacturer: ADATA
usb 3-1.3.4: SerialNumber: 000000000000
usb 3-1.3.4: configuration #1 chosen from 1 choice
scsi8 : SCSI emulation for USB Mass Storage devices
usb-storage: device found at 6
usb-storage: waiting for device to settle before scanning
usb-storage: device scan complete
scsi 8:0:0:0: Direct-Access     ADATA    USB Flash Drive  1.00 PQ: 0 ANSI: 6
sd 8:0:0:0: Attached scsi generic sg5 type 0
61739008 512-byte logical blocks: (31.6 GB/29.4 GiB)
Write Protect is off
Mode Sense: 23 00 00 00
speed:
charles-chang@squeeze:~$ sudo hdparm -tT /dev/sde

/dev/sde:
 Timing cached reads:   9560 MB in  2.00 seconds = 4782.52 MB/sec
 Timing buffered disk reads: 104 MB in  3.02 seconds =  34.49 MB/sec

write:

2014年10月14日 星期二

usb

原來 wusb 是 wireless usb 的意思。
-- 看來應該是掛了。

2014年10月8日 星期三

CFUN=0 trace:

static void requestRadioPower(void *data, size_t datalen, RIL_Token t) 
static void processRequest (int request, void *data, size_t datalen, RIL_Token t) { ... case RIL_REQUEST_RADIO_POWER: requestRadioPower(data, datalen, t); break;
RIL_REQUEST_RADIO_POWER : ril_commands.h
    {RIL_REQUEST_RADIO_POWER, dispatchInts, responseVoid},
ril_commands.h : requestdatahandler.c
typedef struct CommandInfo {
    int requestId;
    void *(*dispatchFunction) (void *data, size_t datalen);
    void (*responseFunction) (void);
} CommandInfo;

/* RILD made me do it! */
static CommandInfo s_commandInfo[] = {
#include "ril_commands.h"
};

先查一下這些 ril 的 constant 定義在...
hardware/ril/include/telephony/ril.h

framework, java 的部份,是在:
framework/base/telephony/java/com/android/internal/telephony/RILConstants.java
為了怕兩邊定義不一致,這邊有 comment:
/*
cat include/telephony/ril.h | \
   egrep '^#define' | \
   sed -re 's/^#define +([^ ]+)* +([^ ]+)/    int \1 = \2;/' \
   >>java/android/com.android.internal.telephony/gsm/RILConstants.java
*/

回到 framework.. reference REQUEST_RADIO_POWER 的..
opt/telephony/src/java/com/android/internal/telephony/RIL.java

  setRadioPower(boolean on, Message result) {
 

2014年10月3日 星期五

3Gdongle 工作狀態 AT+CFUN
AT+CFUN AT command  sets the level of functionality in the MT. Level 
"full functionality" is where the highest level of power is drawn. 
"Minimum functionality" is where minimum power is drawn.

Possible values are,

0 - minimum functionality
1 - full functionality
2 - disable phone transmit RF circuits only
3 - disable phone receive RF circuits only
4 - disable phone both transmit and receive RF circuits
所以 ATCommand 在..
AT+CFUN?
+CFUN: 1
OK
就代表可以開始撥號了。

2014年9月26日 星期五

HUAWEI HiLink - E3131 3G Dongle

[99274.544647] usb-storage: device scan complete
[99274.545218] scsi 36:0:0:0: CD-ROM            HUAWEI   Mass Storage     2.31 PQ: 0 ANSI: 2
[99274.547006] sr1: scsi-1 drive
[99274.547156] sr 36:0:0:0: Attached scsi CD-ROM sr1
[99274.547246] sr 36:0:0:0: Attached scsi generic sg6 type 5
[99475.187782] usb 3-1.1.4: USB disconnect, address 35
[100478.559739] usb 3-1.1.3: new high speed USB device using ehci_hcd and address 36
[100478.664682] usb 3-1.1.3: New USB device found, idVendor=12d1, idProduct=1f01
[100478.664688] usb 3-1.1.3: New USB device strings: Mfr=2, Product=1, SerialNumber=0
[100478.664692] usb 3-1.1.3: Product: HUAWEI HiLink
[100478.664695] usb 3-1.1.3: Manufacturer: HUAWEI
[100478.664820] usb 3-1.1.3: configuration #1 chosen from 1 choice
[100478.666119] scsi37 : SCSI emulation for USB Mass Storage devices
[100478.666249] usb-storage: device found at 36
[100478.666253] usb-storage: waiting for device to settle before scanning
ref: http://www.pcduino.com/3g-cellular-usb-dongle-for-pcduino-huawei-e303s/

檢查一下 usb_modeswitch:

/lib/udev/rules.d/40-usb_modeswitch.rules:
# Huawei E3131
ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="1f01", RUN+="usb_modeswitch '%b/%k'"
如果沒有,就加上去。

然後是 /etc/usb_modeswitch.d/
有沒有 12d1:1f01 這個 file.

雖然有 google 到一些不同得,最後是..
#Huawei E3131
DefaultVendor= 0x12d1
DefaultProduct= 0x1f01
TargetVendor= 0x12d1
RargetProduct= 0x1f01
MessageEndPoint = "0x01"
MessageContent="55534243000000000000000000000011060000000000000000000000000000"
NoDriverLoading=1

這樣,插入 3G dongle,, dmesg:
[97530.910739] usb 3-1.3.4: new high speed USB device using ehci_hcd and address 66
[97531.015681] usb 3-1.3.4: New USB device found, idVendor=12d1, idProduct=1f01
[97531.015688] usb 3-1.3.4: New USB device strings: Mfr=2, Product=1, SerialNumber=0
[97531.015691] usb 3-1.3.4: Product: HUAWEI HiLink
[97531.015694] usb 3-1.3.4: Manufacturer: HUAWEI
[97531.015825] usb 3-1.3.4: configuration #1 chosen from 1 choice
[97531.017289] scsi49 : SCSI emulation for USB Mass Storage devices
[97531.017547] usb-storage: device found at 66
[97531.017551] usb-storage: waiting for device to settle before scanning
[97531.723149] usb 3-1.3.4: USB disconnect, address 66
[97536.787599] usb 3-1.3.4: new high speed USB device using ehci_hcd and address 67
[97536.891893] usb 3-1.3.4: New USB device found, idVendor=12d1, idProduct=1001
[97536.891896] usb 3-1.3.4: New USB device strings: Mfr=2, Product=1, SerialNumber=0
[97536.891898] usb 3-1.3.4: Product: HUAWEI HiLink
[97536.891900] usb 3-1.3.4: Manufacturer: HUAWEI
[97536.891984] usb 3-1.3.4: configuration #1 chosen from 1 choice
[97536.892444] option 3-1.3.4:1.0: GSM modem (1-port) converter detected
[97536.892521] usb 3-1.3.4: GSM modem (1-port) converter now attached to ttyUSB0
[97536.892587] option 3-1.3.4:1.1: GSM modem (1-port) converter detected
[97536.892637] usb 3-1.3.4: GSM modem (1-port) converter now attached to ttyUSB1
[97536.892688] option 3-1.3.4:1.2: GSM modem (1-port) converter detected
[97536.892736] usb 3-1.3.4: GSM modem (1-port) converter now attached to ttyUSB2
pid 變成 1001, 並且出現了 ttyUSB0.1.2

有關 usb_modeswitch, 可以修改 /etc/usb_modeswitch.conf. 把 log 打開:
# Enable logging (results in a extensive report file in /var/log, named
# "usb_modeswitch_"

EnableLogging=1

這隻 dongle 好像有好多種 configuration.
ref: http://mybroadband.co.za/vb/showthread.php/507680-Huawei-HiLink-modems-%28E303-E3131-etc-%29/page2

在 modeswitch 後,minicom 開啟 ttyUSB0. 下:
AT^U2DIAG=0
AT+CFUN=4
AT+CFUN=6
之後 dongle reboot, 然後變成 網路裝置,pid 也變了...

--- 這是安裝過 CDROM mode driver 才會出現。

一但變成這個模式後,dongle 會紀錄這個模式。
以後每次插入都是這個 vid, pid, 插入 linux 也一樣。

要切回原來的模式,要 follow 上面的 link ,重新對 comport 下:
AT^U2DIAG=119
AT+CFUN=4
AT+CFUN=6
但是在 windows 下沒有出現 COM Port,插入 linux 也一樣。
認不得這個 vid, pid

[ 6369.326587] usb 2-1.3.4: new high speed USB device using ehci_hcd and address 10
[ 6369.431758] usb 2-1.3.4: New USB device found, idVendor=12d1, idProduct=1c05
[ 6369.431764] usb 2-1.3.4: New USB device strings: Mfr=2, Product=1, SerialNumber=0
[ 6369.431768] usb 2-1.3.4: Product: HUAWEI HiLink
[ 6369.431770] usb 2-1.3.4: Manufacturer: HUAWEI
[ 6369.431901] usb 2-1.3.4: configuration #1 chosen from 1 choice
[ 6369.793255] usbcore: registered new interface driver cdc_ether
[ 6369.795967] usb 2-1.3.4: bad CDC descriptors
[ 6369.795991] usb 2-1.3.4: bad CDC descriptors
[ 6369.796014] usb 2-1.3.4: bad CDC descriptors
[ 6369.796046] usbcore: registered new interface driver rndis_host
[ 6369.833178] cfg80211: Using static regulatory domain info
[ 6369.833183] cfg80211: Regulatory domain: US
[ 6369.833186]  (start_freq - end_freq @ bandwidth), (max_antenna_gain, max_eirp)
[ 6369.833192]  (2402000 KHz - 2472000 KHz @ 40000 KHz), (600 mBi, 2700 mBm)
[ 6369.833223]  (5170000 KHz - 5190000 KHz @ 40000 KHz), (600 mBi, 2300 mBm)
[ 6369.833227]  (5190000 KHz - 5210000 KHz @ 40000 KHz), (600 mBi, 2300 mBm)
[ 6369.833232]  (5210000 KHz - 5230000 KHz @ 40000 KHz), (600 mBi, 2300 mBm)
[ 6369.833237]  (5230000 KHz - 5330000 KHz @ 40000 KHz), (600 mBi, 2300 mBm)
[ 6369.833242]  (5735000 KHz - 5835000 KHz @ 40000 KHz), (600 mBi, 3000 mBm)
[ 6369.833556] cfg80211: Calling CRDA for country: US
[ 6369.838314] usb 2-1.3.4: bad CDC descriptors
[ 6369.839245] usb 2-1.3.4: bad CDC descriptors
[ 6369.839326] usb 2-1.3.4: bad CDC descriptors
[ 6369.839378] usbcore: registered new interface driver rndis_wlan
ref: http://www.draisberghof.de/usb_modeswitch/bb/viewtopic.php?t=571

就是:
# echo "12d1 1c05" >/sys/bus/usb-serial/drivers/option1/new_id 
很奇怪,一定要是 root 才行。
用 sudo 的話,會是 permission deny

然後 kernel msg:
[ 6846.542169] option 2-1.3.4:1.0: GSM modem (1-port) converter detected
[ 6846.542302] usb 2-1.3.4: GSM modem (1-port) converter now attached to ttyUSB0
[ 6846.542346] option 2-1.3.4:1.1: GSM modem (1-port) converter detected
[ 6846.542420] usb 2-1.3.4: GSM modem (1-port) converter now attached to ttyUSB1
[ 6846.542461] option 2-1.3.4:1.2: GSM modem (1-port) converter detected
[ 6846.542538] usb 2-1.3.4: GSM modem (1-port) converter now attached to ttyUSB2
這樣就出現 COM port 了。
之後用 minicom 打開 ttyUSB0.
輸入:
AT^U2DIAG=119
AT+CFUN=4
AT+CFUN=6
dongle 會重開,然後 dmesg 出來是..
[ 7832.680140] usb 2-1.3.4: new high speed USB device using ehci_hcd and address 13
[ 7832.785372] usb 2-1.3.4: New USB device found, idVendor=12d1, idProduct=1f01
[ 7832.785378] usb 2-1.3.4: New USB device strings: Mfr=2, Product=1, SerialNumber=0
[ 7832.785382] usb 2-1.3.4: Product: HUAWEI HiLink
[ 7832.785384] usb 2-1.3.4: Manufacturer: HUAWEI
[ 7832.785511] usb 2-1.3.4: configuration #1 chosen from 1 choice
[ 7832.786962] scsi11 : SCSI emulation for USB Mass Storage devices
[ 7832.787105] usb-storage: device found at 13
[ 7832.787109] usb-storage: waiting for device to settle before scanning
[ 7833.490017] usb 2-1.3.4: USB disconnect, address 13
[ 7838.553987] usb 2-1.3.4: new high speed USB device using ehci_hcd and address 14
[ 7838.659009] usb 2-1.3.4: New USB device found, idVendor=12d1, idProduct=1001
[ 7838.659015] usb 2-1.3.4: New USB device strings: Mfr=2, Product=1, SerialNumber=0
[ 7838.659019] usb 2-1.3.4: Product: HUAWEI HiLink
[ 7838.659021] usb 2-1.3.4: Manufacturer: HUAWEI
[ 7838.659149] usb 2-1.3.4: configuration #1 chosen from 1 choice
[ 7838.659589] option 2-1.3.4:1.0: GSM modem (1-port) converter detected
[ 7838.659732] usb 2-1.3.4: GSM modem (1-port) converter now attached to ttyUSB0
[ 7838.659874] option 2-1.3.4:1.1: GSM modem (1-port) converter detected
[ 7838.659977] usb 2-1.3.4: GSM modem (1-port) converter now attached to ttyUSB1
[ 7838.660088] option 2-1.3.4:1.2: GSM modem (1-port) converter detected
[ 7838.660186] usb 2-1.3.4: GSM modem (1-port) converter now attached to ttyUSB2
回到以前的 1f01, 然後 modeswitch 到 1001


撥號連線...用 wvdial 撥號,接 ppp..
寫 /etc/wvdial.conf

[Dialer e3131]
Modem = /dev/ttyUSB0
Init1 = ATZ
Init2 = AT^CURC=0
Init3 = AT+CGDCONT=1,"IP","internet"
Phone = *99#
Stupid mode = yes
Dial Attempts = 0
Auto Reconect = yes
Password=''
Username=''
然後下命令:sudo wvdial e3131..
--> WvDial: Internet dialer version 1.60
--> Cannot get information for serial port.
--> Initializing modem.
--> Sending: ATZ
ATZ
OK
--> Sending: AT^CURC=0
AT^CURC=0
OK
--> Sending: AT+CGDCONT=1,"IP","internet"
AT+CGDCONT=1,"IP","internet"
OK
--> Modem initialized.
--> Sending: ATDT*99#
--> Waiting for carrier.
ATDT*99#
CONNECT
--> Carrier detected.  Starting PPP immediately.
--> Starting pppd at Fri Sep 26 11:09:15 2014
--> Pid of pppd: 4065
--> Using interface ppp0
--> local  IP address 42.68.94.228
--> remote IP address 10.64.64.64
--> primary   DNS address 168.95.1.1
--> secondary DNS address 168.95.192.1

之後用 ifconfig 看,OK

wvdial.conf 如果沒有寫
Password=''
Username=''
wvdial 會 complain 沒有給 username, password

2014年9月19日 星期五

test piracast ..

上一篇文章其實是為了試這個: https://github.com/codemonkeyricky/piracast

mircast 真的就是Wifi Direct 連線,然後 streaming H264.

有關 Wifi Direct 連線,跟 Wifi Module 有關。
ref: http://rtl8192cu.googlecode.com/hg-history/bdd3a2265bdd6a92f24cef3d52fa594b2844c9c1/document/RTK_Wi-Fi_Direct_Programming_guide.pdf

換位子了...RTK_WiFi_Direct_Programming_guide.pdf

2014年9月18日 星期四

wifi dongle on Raspberry Pi

ref: http://www.fars-robotics.net/ dongle 就是piracast 唯一支援的 TP-LINK TL-WN725N

安裝 driver..
lsusb:
Bus 001 Device 011: ID 0bda:8179 Realtek Semiconductor Corp. 
uname -a:
Linux raspberrypi 3.12.20+ #687 PREEMPT Fri May 30 16:39:11 BST 2014 armv6l GNU/Linux
所以屬於:
rtl8188eu drivers for 3.12.18+ to 3.12.25+

3.12.20+ #687       - 8188eu-20140509.tar.gz

所以我要 download 的是...
https://dl.dropboxusercontent.com/u/80256631/8188eu-20140509.tar.gz

ko 裝完後,用 wpa_supplicant 的方式。
修改 /etc/wpa_supplicant/wpa_supplicant.conf
加上 ssid 和 psk 後,重新開機。

OK.


為防止page 不見,copy 一下:
Installing rtl8188cus and rtl8188eu based wifi adaptors for raspbian using wpa_supplicant.

Default /etc/network/interfaces file as supplied in the raspbian image - do not edit

auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp

Edit the file /etc/wpa_supplicant/wpa_supplicant.conf and add the network={.....} section. Use the command sudo nano 
/etc/wpa_supplicant/wpa_supplicant.conf to open and edit the file. Exit the editor and save the file using keys cntl-X, 
Y, Enter.

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
    ssid="Your-Network-Name"
    psk="Your-Network-Password"
}

You may add additional network={.....} sections defining different networks if your Pi is mobile and you carry it 
around with you. This will allow you to connect to these other networks at various different locations without needing 
to change your set up.


變成 4.1 版了。所以根據https://www.raspberrypi.org/forums/viewtopic.php?p=462982#p462982, uname -a 是 4.1.19+ #858
要 download 的就是..https://dl.dropboxusercontent.com/u/80256631/8188eu-4.1.19-858.tar.gz

2014年9月15日 星期一

1.5 T, 2700,  USB3. 0

socket, android 4.2 init.rc 啟動和手動啟動的 socket fd , access mode 不同

一個 service create 一個 socket 作 service 入口。
在 init.rc 中 service 啟動這個 service.

結果
在 2.3 版, create 出來的 permission 是 0777
在 4.2 版, create 出來的 permission 是 0700

但是若是不用 init.rc 的 service 啟動,
在 console 手動launch 的話,
無論 2.3 還是 4.2, create 出來的 socket 都是 0777


... 雖然是這樣,
但是在程式中,當socket create 完,bind OK 後,
用 chmod( ) 改成 0777, 是 OK 的。

USB_EHCI_TT_NEWSCHED 最後好像還是沒有接受

是在 ehci 處理 1.1 連線的時候,出問題,所設計的 新 ehci scheduler.

但是最後好像還是沒被納入成 default:

http://permalink.gmane.org/gmane.linux.usb.general/96451
最後:
It's not a matter of sloppy coding but of design.  The main issues are:

 We don't handle siTD back link pointers.  Therefore we can't
 allow full-speed isochronous IN transfers to be scheduled in
 B-uframe 4 or later.

 We don't handle FSTN nodes in the schedule.  Therefore we can't
 allow full- or low-speed interrupt transfers to be scheduled
 in B-uframe 4 or later.  (In principle, that is -- in practice
 we do allow uframes 4 and 5, at the cost of having too few
 CSPLIT packets.)

 We don't compute the full-speed budget according to the USB 
 spec.  The spec says that budgets are to be computed in terms
 of best-case full-speed bytes, not worst-case microseconds.

 If an URB's bandwidth can't be accomodated in the current
 schedule, we don't try to rebalance the schedule to make the
 bandwidth fit.

 We don't obey various restrictions on allowable schedules.
 For example, the EHCI spec says that any full-speed isochronous
 transfer of length >= 588 bytes must be the first one in its
 frame, but we don't enforce this.

 We reserve an endpoint's bandwidth when the first URB is 
 submitted rather than when the alternate setting is installed.

There's a bunch of smaller issues under each of those categories, but 
those are the biggies.

Alan Stern

2014年9月9日 星期二

Usbee DX 使用心得

跟一般的示波器比起來..

1 chan sampling rate 有到 24M, (有效到 2M 已經算 OK)
PC 端雖然一定要 windows 和 .net 有點鳥,, UI 也有點...
但是算堪用

最大的問題,也就是看出專業示波器和玩具的差別就是:
信號放大器。

USBee 缺這個,
所以他一直用最大檔 +-10V 來量,
加上 AD 解析度不夠,

所以小信號是悲劇。
size wave 最少要有 +- 1.5V 才會看得出來。
否則會變成階梯狀。

數位部份就還好,因為只有 0 ~ 5.5V,
加上數位也不 care 暫態.

2014年9月5日 星期五

hardware/libhardware_legacy/audio/AudioPolicyManagerBase.cpp
    ALOGV("setOutputDevice() changing device");
    // do the routing
    param.addInt(String8(AudioParameter::keyRouting), (int)device);
    mpClientInterface->setParameters(output, param.toString(), delayMs);


mixer route 的設置變成 hard-code:
AudioHardware.cpp:
   mMixer = mHardware->openMixer_l();
    if (mMixer) {
        ALOGV("open playback normal");
        
        headphone_l_ctl = mixer_get_ctl_by_name(mMixer, "Left dac to hp left amp Switch");
        headphone_r_ctl = mixer_get_ctl_by_name(mMixer, "Right dac to hp right amp Switch");
        speaker_l_ctl = mixer_get_ctl_by_name(mMixer, "Left dac to speaker lineout Switch");
        speaker_r_ctl = mixer_get_ctl_by_name(mMixer, "Right dac to speaker lineout Switch");
        
    }
    
    if (headphone_l_ctl && headphone_r_ctl && speaker_l_ctl && speaker_r_ctl) {
        unsigned int num_values;
        unsigned int hp_num_values;
        unsigned int i;
        num_values = mixer_ctl_get_num_values(speaker_l_ctl);
        hp_num_values = mixer_ctl_get_num_values(headphone_l_ctl);
        
     for (i = 0; i < num_values; i++) {
     if (mDevices & (AudioSystem::DEVICE_OUT_SPEAKER | AudioSystem::DEVICE_OUT_EARPIECE)) {
                mixer_ctl_set_value(speaker_l_ctl, i, 1);
                mixer_ctl_set_value(speaker_r_ctl, i, 1);
     } else {
                mixer_ctl_set_value(speaker_l_ctl, i, 0);
                mixer_ctl_set_value(speaker_r_ctl, i, 0);
     }
 }
 for (i = 0; i < hp_num_values; i++) {
     if (mDevices & AudioSystem::DEVICE_OUT_WIRED_HEADSET) {
                mixer_ctl_set_value(headphone_l_ctl, i, 1);
                mixer_ctl_set_value(headphone_r_ctl, i, 1);
            } else {
                mixer_ctl_set_value(headphone_l_ctl, i, 0);
                mixer_ctl_set_value(headphone_r_ctl, i, 0);
            }
 }
以前這一段是寫在 asound.conf。
改為 tinyalsa 後就變成 hard-coded

這只是 4.2 的作法, 4.4 以後會是一個專職的 libaudioroute library..

2014年9月2日 星期二

dtb, dtc, dts

上次說的,kernel config 改成 dts,然後用 dtc compile 成 dtb

dtc 在 kernel/script/dtc

dts 到 dtb 的 Makfile rule 在.. (以 arm 為例):
%.dtb: scripts
        $(Q)$(MAKE) $(build)=$(boot)/dts MACHINE=$(MACHINE) $(boot)/dts/$@

dtbs: scripts
        $(Q)$(MAKE) $(build)=$(boot)/dts MACHINE=$(MACHINE) dtbs

所以 make dtbs 就會 make platform 的 dtb
make abc.dtb 就會把 abc.dts compile 成 abc.dtb

2014年8月28日 星期四

asound.conf , route path,

/etc/asound.conf 有 alsa 裝置的配置開關.

有關 codec routing 部份.,,,

先看 driver 的 snd_soc_dapm_route 矩陣
.先把array copy 出來。
https://gist.github.com/checko/eb5fd55bfd7baa25ddd4

每個 element 有三個欄位. (OUT, SW, IN).

看 電路,決定一下 route 的 in, out.
以 play 來說,:
out 是 HPOL, HPOR.
input 是 I2S 第一組

找 array 中,OUT 欄位是 HPOL. HPOR 的..
 { "HPOL", NULL, "HP Amp" },
 { "HPOL", NULL, "HP L Amp" },
 { "HPOL", NULL, "Improve HP Amp Drv" },

 { "HPOR", NULL, "HP Amp" },
 { "HPOR", NULL, "HP R Amp" },
 { "HPOR", NULL, "Improve HP Amp Drv" },
所以可以知道HPO 可以有三個 input path 可以選 : HP AMP. HP L/R Amp, Improved HP Amp Drv

其中 HP L/R Amp 和 Improve HP Amp Drv 都沒有 input path, 只有 HP Amp 有:
 { "HP Amp", NULL, "HPO MIX" },
 { "HP Amp", NULL, "JD Power" },
 { "HP Amp", NULL, "Mic Det Power" },
一樣,其中只有 HPO MIX有 input source:
 { "HPO MIX", "DAC1 Switch", "DAC 1" },
 { "HPO MIX", "HPVOL Switch", "HPOVOL" },

HPOVOL 的話,要經過..
 { "HPOVOL", NULL, "HPOVOL MIXL" },
 { "HPOVOL", NULL, "HPOVOL MIXR" },
只看 HPOVOL MIXL (因為沒有要 swap L/R, or mono):
 { "HPOVOL MIXL", "DAC1 Switch", "DAC L1" },
 { "HPOVOL MIXL", "INL Switch", "INL VOL" },
有兩個選項,一個 DAC L1 (跟剛剛 HPO MIX 一樣), 另一個是 INL VOL

IN VOL 接到 Analog Input,所以不是我們要用的。
看 DAC L1:
 { "DAC L1", NULL, "Stereo DAC MIXL" },
 { "DAC L1", NULL, "PLL1", check_sysclk1_source },
其中 PLL1 會 trigger check_sysclk_source, 同時也沒有 input,所以只看 Stereo DAC MIXL:
 { "Stereo DAC MIXL", "DAC L1 Switch", "DAC1 MIXL" },
 { "Stereo DAC MIXL", "DAC R1 Switch", "DAC1 MIXR" },
 { "Stereo DAC MIXL", "DAC L2 Switch", "DAC L2 Volume" },
 { "Stereo DAC MIXL", NULL, "dac stereo1 filter" },
 { "Stereo DAC MIXL", NULL, "DAC L1 Power" },
DAC L1 Power 和 dac stereo1 filter 沒有 input,
IF1_DAC (也就是 I2S 第一組),有 0-7 共 8組 DAC...(!!)
DAC L1 接到 SounzReal, DAC L2 接到 Voice, 所以先看簡單的. DAC1 MIXL..
 { "DAC1 MIXL", "Stereo ADC Switch", "Stereo1 ADC MIXL" },
 { "DAC1 MIXL", "DAC1 Switch", "DAC1 L Mux" },
 { "DAC1 MIXL", NULL, "dac stereo1 filter" },
 { "DAC1 MIXL", NULL, "DAC L1 Power" },
dac stereo1 filter, DAC L1 Power 一樣,沒有 input.
Stereo1 ADC MIXL 接到 Analog Input ADC 哪一路,
所以應該是要看 DAC1 L Mux:
 { "DAC1 L Mux", "IF1 DAC", "IF1 DAC1 L" },
 { "DAC1 L Mux", "IF2 DAC", "IF2 DAC L" },
要 route 到 I2S 第一路,所以選 IF1 DAC1 L:
 { "IF1 DAC1 L", NULL, "IF1 DAC1" },
IF1 DAC1 的 source 有兩個:
 { "IF1 DAC1", NULL, "AIF1RX" },
 { "IF1 DAC1", NULL, "I2S1" },
好像就是最後了....
最後是..
#ifdef USE_ASRC
 {"I2S1", NULL, "ASRC enable"},
 {"I2S2", NULL, "ASRC enable"},
#endif

OK, 把上面的 path 列出來: (L)
 { "HPOL"           , NULL           , "HP Amp"          },
 { "HP Amp"         , NULL           , "HPO MIX"         },
 { "HPO MIX"        , "DAC1 Switch"  , "DAC 1"           },
 { "DAC 1"          , NULL           , "DAC L1"          },
 { "DAC L1"         , NULL           , "Stereo DAC MIXL" },
 { "Stereo DAC MIXL", "DAC L1 Switch", "DAC1 MIXL"       },
 { "DAC1 MIXL"      , "DAC1 Switch"  , "DAC1 L Mux"      },
 { "DAC1 L Mux"     , "IF1 DAC"      , "IF1 DAC1 L"      },
 { "IF1 DAC1 L"     , NULL           , "IF1 DAC1"        },
 { "IF1 DAC1"       , NULL           , "I2S1"            },
 { "I2S1"           , NULL           , "ASRC enable"     },
其中,中間一項不是 NULL 的,就要寫在 asound.conf 中..

寫的東西要用 tinymixer 來看...
tinymixer 會列出所有的 control gadge..

要設的有...
36 BOOL 1 HPO MIX DAC1 Switch                      On
62 BOOL 1 Stereo DAC MIXR DAC R1 Switch            On
65 BOOL 1 Stereo DAC MIXL DAC L1 Switch            On
73 BOOL 1 DAC1 MIXR DAC1 Switch                    On
75 BOOL 1 DAC1 MIXL DAC1 Switch                    On
68 ENUM 1 DAC1 R Mux                               IF1 DAC
69 ENUM 1 DAC1 L Mux                               IF1 DAC

所以 /etc/asound.conf 就是....

2014年8月26日 星期二

亂亂寫

dtsi 就是給 dts include 的 ?

2014年8月25日 星期一

加語系 -- android

支援的語系可以從: android/build/target/product/language_full.mk:
PRODUCT_LOCALES := en_US fr_FR it_IT es_ES de_DE nl_NL cs_CZ pl_PL ja_JP zh_TW zh_CN ru_RU ko_KR nb_NO es_US da_DK el_GR
tr_TR pt_PT pt_BR rm_CH sv_SE bg_BG ca_ES en_GB fi_FI hi_IN hr_HR hu_HU in_ID iw_IL lt_LT lv_LV ro_RO sk_SK sl_SI sr_RS 
uk_UA vi_VN tl_PH ar_EG fa_IR th_TH sw_TZ ms_MY af_ZA zu_ZA am_ET hi_IN
ref:

a whole set of __dev... macros are no longer used or defined

copy:
a whole set of __dev... macros are no longer used or defined

  • Here is the list: __devinit, __devinitdata, __devinitconst, __devexit, __devexitdata, __devexitconst
  • background: These attributes were used on certain driver functions and data declarations, putting them in a separate section that could be discarded under certain circumstances. This functionality is no longer relevant, and the macros were removed in version 3.8 of the kernel. The macros should no longer be used.
  • Just remove the attributes any place they are used.

ref:
  • http://elinux.org/Kernel_3.4_to_3.10_porting_guide
  • https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=54b956b903607
  • https://groups.google.com/forum/#!msg/linux.kernel/rHxmuN4tiE8/_LhGvxCjS18J

2014年8月19日 星期二

default.prop

就是在 android/build/core/Makefile:
# -----------------------------------------------------------------
# default.prop
INSTALLED_DEFAULT_PROP_TARGET := $(TARGET_ROOT_OUT)/default.prop
ALL_DEFAULT_INSTALLED_MODULES += $(INSTALLED_DEFAULT_PROP_TARGET)
ADDITIONAL_DEFAULT_PROPERTIES := \
    $(call collapse-pairs, $(ADDITIONAL_DEFAULT_PROPERTIES))
ADDITIONAL_DEFAULT_PROPERTIES += \
    $(call collapse-pairs, $(PRODUCT_DEFAULT_PROPERTY_OVERRIDES))
ADDITIONAL_DEFAULT_PROPERTIES := $(call uniq-pairs-by-first-component, \
    $(ADDITIONAL_DEFAULT_PROPERTIES),=)

$(INSTALLED_DEFAULT_PROP_TARGET):
        @echo Target buildinfo: $@
        @mkdir -p $(dir $@)
        $(hide) echo "#" > $@; \
                echo "# ADDITIONAL_DEFAULT_PROPERTIES" >> $@; \
                echo "#" >> $@;
        $(hide) $(foreach line,$(ADDITIONAL_DEFAULT_PROPERTIES), \
                echo "$(line)" >> $@;)
        build/tools/post_process_props.py $@

所以在所有 *.mk 中,有宣告 ADDITIONAL_DEFAULT_PROPERTY_OVERRIDES 的,都會被加入 default.prop 中。
例如:
android/devices/common/common.mk:
# Set default USB interface
PRODUCT_DEFAULT_PROPERTY_OVERRIDES += \
        persist.sys.usb.config=mass_storage \
        persist.sys.strictmode.disable=1

另外,script 又多加處理某些部份,寫在 build/tools/post_process_props.py:
# Put the modifications that you need to make into the /system/build.prop into this
# function. The prop object has get(name) and put(name,value) methods.
def mangle_default_prop(prop):
  # If ro.debuggable is 1, then enable adb on USB by default
  # (this is for userdebug builds)
  if prop.get("ro.debuggable") == "1":
    val = prop.get("persist.sys.usb.config")
    if val == "":
      val = "adb"
    else:
      val = val + ",adb"
    prop.put("persist.sys.usb.config", val)
  # UsbDeviceManager expects a value here.  If it doesn't get it, it will
  # default to "adb". That might not the right policy there, but it's better
  # to be explicit.
  if not prop.get("persist.sys.usb.config"):
    prop.put("persist.sys.usb.config", "none");

他加上 persist.sys.usb.config adb

所以最後 rootfs/default.prop 就有:
persist.sys.usb.config=mass_storage,adb

2014年8月18日 星期一

/* SoC machine DAI configuration, glues a codec and cpu DAI together */
struct snd_soc_pcm_runtime {
 struct device *dev;
 struct snd_soc_card *card;
 struct snd_soc_dai_link *dai_link;
 struct mutex pcm_mutex;
 enum snd_soc_pcm_subclass pcm_subclass;
 struct snd_pcm_ops ops;

 unsigned int dev_registered:1;

 /* Dynamic PCM BE runtime data */
 struct snd_soc_dpcm_runtime dpcm[2];

 long pmdown_time;
 unsigned char pop_wait:1;

 /* runtime devices */
 struct snd_pcm *pcm;
 struct snd_compr *compr;
 struct snd_soc_codec *codec;
 struct snd_soc_platform *platform;
 struct snd_soc_dai *codec_dai;
 struct snd_soc_dai *cpu_dai;

 struct delayed_work delayed_work;
#ifdef CONFIG_DEBUG_FS
 struct dentry *debugfs_dpcm_root;
 struct dentry *debugfs_dpcm_state;
#endif
};
還有 soc_soc_dai_link:
struct snd_soc_dai_link {
 /* config - must be set by machine driver */
 const char *name;   /* Codec name */
 const char *stream_name;  /* Stream name */
 /*
  * You MAY specify the link's CPU-side device, either by device name,
  * or by DT/OF node, but not both. If this information is omitted,
  * the CPU-side DAI is matched using .cpu_dai_name only, which hence
  * must be globally unique. These fields are currently typically used
  * only for codec to codec links, or systems using device tree.
  */
 const char *cpu_name;
 const struct device_node *cpu_of_node;
 /*
  * You MAY specify the DAI name of the CPU DAI. If this information is
  * omitted, the CPU-side DAI is matched using .cpu_name/.cpu_of_node
  * only, which only works well when that device exposes a single DAI.
  */
 const char *cpu_dai_name;
 /*
  * You MUST specify the link's codec, either by device name, or by
  * DT/OF node, but not both.
  */
 const char *codec_name;
 const struct device_node *codec_of_node;
 /* You MUST specify the DAI name within the codec */
 const char *codec_dai_name;
 /*
  * You MAY specify the link's platform/PCM/DMA driver, either by
  * device name, or by DT/OF node, but not both. Some forms of link
  * do not need a platform.
  */
 const char *platform_name;
 const struct device_node *platform_of_node;
 int be_id; /* optional ID for machine driver BE identification */

 const struct snd_soc_pcm_stream *params;

 unsigned int dai_fmt;           /* format to set on init */

 enum snd_soc_dpcm_trigger trigger[2]; /* trigger type for DPCM */

 /* Keep DAI active over suspend */
 unsigned int ignore_suspend:1;

 /* Symmetry requirements */
 unsigned int symmetric_rates:1;

 /* Do not create a PCM for this DAI link (Backend link) */
 unsigned int no_pcm:1;

 /* This DAI link can route to other DAI links at runtime (Frontend)*/
 unsigned int dynamic:1;

 /* pmdown_time is ignored at stop */
 unsigned int ignore_pmdown_time:1;

 /* codec/machine specific init - e.g. add machine controls */
 int (*init)(struct snd_soc_pcm_runtime *rtd);

 /* optional hw_params re-writing for BE and FE sync */
 int (*be_hw_params_fixup)(struct snd_soc_pcm_runtime *rtd,
   struct snd_pcm_hw_params *params);

 /* machine stream operations */
 const struct snd_soc_ops *ops;
 const struct snd_soc_compr_ops *compr_ops;
};

2014年8月14日 星期四

convert mp3 to wav file , stereo 48000

因為 sound codec 只吃 48k, stereo 的 wav 檔。
所以就要自己轉檔。

感覺還是 command line 的比較好用。
 mpg123 -o output --stereo -r 48000 1kHz.mp3
這樣就能強制把 mp3 轉成 48k, 2 channel (stereo) 的 wav 檔。
-- 用 man 可以看所有 option.
ref:
  • http://www.cyberciti.biz/faq/convert-mp3-files-to-wav-files-in-linux/

2014年8月13日 星期三

libtinyalsa.so 同時給 tinyplay 和 audioflinger link
debug 的時候, fprintf(srtderr,"..

但是在 Dalvik 中,會把 stdout, stderr 重導到 /dev/null
所以看不到。

http://developer.android.com/tools/debugging/debugging-log.html#viewingStd

說,可以用 setprop log.redirect-stdio true 來叫 dalvik 把 stdout, stderr 重導到 logcat

看一下 code...

2014年8月12日 星期二

worklog - tinyalsa, tinyplay

變成 tinyalsa.
tinyplay -- pcm_open()

struct pcm *pcm_open(unsigned int card,  unsigned int device,
                     unsigned int flags, struct pcm_config *config)
{
   ...
   ...
   snprintf(fn , sizeof(fn), "/dev/snd?pcmC%dD%u%c", card, device, flags & PCM_IN ? 'c' : 'p');
   ...
   pcm->fb = open(fn, O_RDWR);

在 android/external/tinyalsa 下

build 出:
  • libtinyalsa.so
  • tinyplay
  • tinycap
  • tinymix

kernel:

include/uapi/sound/asound.h:
struct snd_interval {
 unsigned int min, max;
 unsigned int openmin:1,
              openmax:1,
              integer:1,
              empty:1;
};

是在:
struct snd_pcm_hw_params {
 unsigned int flags;
 struct snd_mask masks[SNDRV_PCM_HW_PARAM_LAST_MASK -  SNDRV_PCM_HW_PARAM_FIRST_MASK + 1];
 struct snd_mask mres[5]; /* reserved masks */
 struct snd_interval intervals[SNDRV_PCM_HW_PARAM_LAST_INTERVAL - SNDRV_PCM_HW_PARAM_FIRST_INTERVAL + 1];
 struct snd_interval ires[9]; /* reserved intervals */
 unsigned int rmask;          /* W: requested masks */
 unsigned int cmask;          /* R: changed masks */
 unsigned int info;           /* R: Info flags for returned setup */
 unsigned int msbits;         /* R: used most significant bits */
 unsigned int rate_num;       /* R: rate numerator */
 unsigned int rate_den;       /* R: rate denominator */
 snd_pcm_uframes_t fifo_size; /* R: chip FIFO size in frames */
 unsigned char reserved[64];  /* reserved for future */
};

Android AudioHardware 可以正常 pcm_open( )
tinyplay 就 fail

/AudioHardware open 時的 config:
         struct pcm_config config = {
            channels : 2,
            rate : 48000,
            period_size : 1024,
            period_count : 2,
            format : PCM_FORMAT_S16_LE,
            start_threshold : 0,
            stop_threshold : 0,
            silence_threshold : 0,
        };


在 target board 上,tinyplay pcm_open failed 的原因都是 config 內容不符合 codec support 的範圍。
pcm_open( ) 是 tinyalsa library function (pcm.c).

其中依次是:
  • fd = open("pcmC0D0p",O_RDWR)
  • ioctl(fd, SNDRV_PCM_IOCTL_INFO, &info)
  • ioctl(fd, SNDRV_PCM_IOCTL_HW_PARAMS, ¶ms)
  • ioctl(fd, SNDRV_PCM_IOCTL_SW_PARAMS, &sparams)
config 內容不支援,是在 IOCTL_HW_PARAMS 時出錯。

打開 kernel/sound/pcm_native.c 的 RULES_DEBUG 還有掉 printk 的 KERN_DEBUG 後,

kernel msg 會有:
 SAMPLE_BITS = [16 16] -> [16 16]
 FRAME_BITS = [32 32] -> [32 32]
 CHANNELS = [1 1] -> empty
這樣就知道是 channels 沒有 match (codec 只 support 2 channels)
改用 2 channels (stereo) 的 sample wav file 後...
 ..
 ..
 PERIODS = [4 4] -> empty
這就是 period number 參數不對。
還好 tinyplay 有 optio "-n" 可以指定。
加上 -n 2 後,就沒有問題了。

2014年8月6日 星期三

Kingmax uhs i 32g

Pc 家 399 ?

Broway usb 3.0 4port hub

結果沒有附 adaptor,
附的是 usb power cable.....


因為是加價購買的,$249

2014年7月28日 星期一

AudioPolicyManagerBae : loadAudioPolicyConfig() loaded /system/etc/audio_polocy.conf

2014年7月11日 星期五

基本上就是 MIXER.
然後每個 可以/需要 控制的地方,都是一個 widget

然後用 route {out, sw, in} 把 widget 間的 routing 關係描述出來。

這一篇 說明得很好。
怎麼從一堆 route elem 中,把你要的 path (routing) 找出來。

就是依照 in - out 把你要的 path 繞出來。
最後把 path 中, sw 不是 NULL的寫下來。
這就是 asound.conf 要的 hook_args[ ]

playback 已經 OK.

以下就用 Capture 作測試:

Capture 就是:
  • IN : MIC
  • OUT : I2S
首先要開啟 alsa-lib 的 debug message : SND_ERR

在 project 的 include/config.h ..
#ifndef NDEBUG
#define NDEBUG
#endif
把這三行 comment 掉。

之後 logcat 就可以看到..
ALSALib( ): external/lib-alsa/src/control/setup.c:565:(add_elem) Cannot obtain infor for CTL elem (MIXER,'Speaker Switch'
,0,0,0): No such file or directory
開啟了 之後,asound.conf 內容如果有錯,會有 error 顯示出來。

2014年7月10日 星期四

snd_kcontrol_new     : snd_soc_add_controls( )
snd_soc_dapm_widget  : snd_soc_dapm_new_controls( )
snd_soc_dapm_route   : snd_soc_dapm_add_routes( )
widget 裡有:
  • SUPPLY
  • VMID
  • MICBIAS
  • INPUT
  • OUTPUT
  • PGA
  • PGA_E
  • MIXER
  • ADC
  • DAC
  • MUX
  • MUX_E
  • AIF_IN
  • AIF_OUT
  • SWITCH
struct snd_kcontrol_new {
  snd_ctl_elem_iface_t iface; /* interface identifier */
  unsigned int device;  /* device/client number */
  unsigned int subdevice;  /* subdevice (substream) number */
  unsigned char *name;  /* ASCII name of item */
  unsigned int index;  /* index of item */
  unsigned int access;  /* access rights */
  unsigned int count;  /* count of same elements */
  snd_kcontrol_info_t *info;
  snd_kcontrol_get_t *get;
  snd_kcontrol_put_t *put;
  union {
  snd_kcontrol_tlv_rw_t *c;
  const unsigned int *p;
  } tlv;
  unsigned long private_value;
};

struct soc_mixer_control {
 int min, max, platform_max;
 unsigned int reg, rreg, shift, rshift, invert;
}

static const struct snd_kcontrol_new rt5625_snd_controls[] = {
        ...
 SOC_DOUBLE("Headphone Playback Switch", RT5625_HP_OUT_VOL,
   RT5625_L_MUTE_SFT, RT5625_R_MUTE_SFT, 1, 1),
        ...
};

#define SOC_DOUBLE(xname, xreg, shift_left, shift_right, xmax, xinvert) \
{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
 .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
 .put = snd_soc_put_volsw, \
 .private_value = (unsigned long)&(struct soc_mixer_control) \
                 {
                   .reg = xreg, .shift = shift_left, .rshift = shift_right, \
                   .max = xmax, .platform_max = xmax, .invert = xinvert    \
                 }                                                         \
}

/*
 * DAPM audio route definition.
 *
 * Defines an audio route originating at source via control and finishing
 * at sink.
 */
struct snd_soc_dapm_route {
 const char *sink;
 const char *control;
 const char *source;

 /* Note: currently only supported for links where source is a supply */
 int (*connected)(struct snd_soc_dapm_widget *source,
    struct snd_soc_dapm_widget *sink);
};

2014年7月9日 星期三

notes : android and alsa conf

alsa 和 android 的介面好像是靠 一個 conf 決定的。
有些說是 alsa.conf ,有些說是 asound.conf
在 android 4.2,是 /usr/share/alsa/alsa.conf 裡指定了 /etc/asound.conf

這個系統是在 /etc/asound.conf

這個檔案是在 /rootfs/rootdir/etc/ 下。
這是一個 prebuild folder, 該 file 也是預先寫定。
在 build system 時,rootdir 的內容會被整個 copy 到最後 image 的 root/ 中。

也就是說,實際系統的 /etc/asound.conf 就是這裡來的。


android 设置Audio Path 根据 getStrategy(stream_type) 和 getDeviceForStrategy() 取出對應的输出、输入,
然後 call setOutputDevice(mHardwareOutput, newDevice)
他會 call alsa_default.cpp
然後 會用到 s_route, s_open 控制到底層。

s_open 利用 deviceName(handle, devices, mode)
依照 Devices 動態組合出path字串,
用 snd_pcm_open( ) 依照 asound.conf 設定檔的 pcm 裡的 controls

所以 logcat 時可以看到:
D/AudioHardwareALSA(  674): openOutputStream called for devices: 0x00000002
I/ALSAModule(  674): s_close AndroidPlayback
D/ALSAModule(  674): open called for devices 00000002 in mode 0, channel 2...
E/ALSAModule(  674): s_open: AndroidPlayback_Speaker_normal
E/ALSALib (  674): external/alsa-lib/src/control/setup.c:565:(add_elem) Cannot obtain info for CTL elem (MIXER,'Speaker Switch',0,0,0): No such file or directory
E/ALSAModule(  674): s_open: AndroidPlayback_Speaker
E/ALSALib (  674): external/alsa-lib/src/control/setup.c:565:(add_elem) Cannot obtain info for CTL elem (MIXER,'Speaker Switch',0,0,0): No such file or directory
E/ALSAModule(  674): s_open: AndroidPlayback
D/ALSAModule(  674): force handle channels to 2
D/ALSAModule(  674): Set 48000 , handl channel 2
D/ALSAModule(  674): Set PCM format to S16_LE (Signed 16 bit Little Endian)
D/ALSAModule(  674): Using 2 channels for stream.
D/ALSAModule(  674): Set stream sample rate to 48000 HZ
D/ALSAModule(  674): Buffer size: 4096
D/ALSAModule(  674): Latency: 85333
I/ALSAModule(  674): Initialized ALSA PLAYBACK device AndroidPlayback_Speaker_normal
Error 是因為我改了 codec kcontrol name...

2014年7月1日 星期二

usbmon -- usb sniffer for linux

usbmon 是一個 kernel module.
要啟動 debugfs 的 support 才能使用。

kernel 起來後,mount /sys/kernel/debugfs
usb mon 就會在 裡面。

然後 cat XXX 就會把 usb 內容都log 出來。

詳細可以google 一下 usbmon 就可以。
也可以直接看 kernel document

...偷看其他人的 protocol 時很好用...

2014年6月23日 星期一

build.prop 中的 property 在哪一個階段可以開始使用..

很多人很喜歡在 build.prop 中加東西。

build.prop 在 bionic/libc/include/sys/_system_properties.h :  #define PROP_PATH_SYSTEM_BUILD "/system/build.prop"

然後在 system/core/init/ 中ref...
void start_property_service(void)
{
    int fd;

    load_properties_from_file(PROP_PATH_SYSTEM_BUILD);
    load_properties_from_file(PROP_PATH_SYSTEM_DEFAULT);
    load_override_properties();
    /* Read persistent properties after all default values have been loaded. */
    load_persistent_properties();

#ifdef HAVE_SELINUX
    fd = create_socket(PROP_SERVICE_NAME, SOCK_STREAM, 0666, 0, 0, NULL);
#else
    fd = create_socket(PROP_SERVICE_NAME, SOCK_STREAM, 0666, 0, 0);
#endif
    if(fd < 0) return;
    fcntl(fd, F_SETFD, FD_CLOEXEC);
    fcntl(fd, F_SETFL, O_NONBLOCK);

    listen(fd, 8);
    property_set_fd = fd;
}

然後是在init.c :
static int property_service_init_action(int nargs, char **args)
{
    /* read any property files on system or data and
     * fire up the property service.  This must happen
     * after the ro.foo properties are set above so
     * that /data/local.prop cannot interfere with them.
     */
    start_property_service();
    return 0;
}
在 init 的 main process 中,可以看到啟動的順序:
    INFO("reading config file\n");
    init_parse_config_file("/init.rc");

    action_for_each_trigger("early-init", action_add_queue_tail);

    queue_builtin_action(wait_for_coldboot_done_action, "wait_for_coldboot_done");
    queue_builtin_action(keychord_init_action, "keychord_init");
    queue_builtin_action(console_init_action, "console_init");

    /* execute all the boot actions to get us started */
    action_for_each_trigger("init", action_add_queue_tail);

    /* skip mounting filesystems in charger mode */
    if (!is_charger) {
        action_for_each_trigger("early-fs", action_add_queue_tail);
        action_for_each_trigger("fs", action_add_queue_tail);
        action_for_each_trigger("post-fs", action_add_queue_tail);
        action_for_each_trigger("post-fs-data", action_add_queue_tail);
    }

    queue_builtin_action(property_service_init_action, "property_service_init");
    queue_builtin_action(signal_init_action, "signal_init");
    queue_builtin_action(check_startup_action, "check_startup");

    if (is_charger) {
        action_for_each_trigger("charger", action_add_queue_tail);
    } else {
        action_for_each_trigger("early-boot", action_add_queue_tail);
        action_for_each_trigger("boot", action_add_queue_tail);
    }

        /* run all property triggers based on current state of the properties */
    queue_builtin_action(queue_property_triggers_action, "queue_property_triggers");
所以在 build.prop 中的設定值,在 signal_init 階段後,就可以使用了。


其實從 code 來看,各個 prop 的順序是..
  • /default.prop
  • /system/build.prop
  • /system/default.prop
  • /data/local.prop
看 /system/default.prop 的產生經過...
在 android/build/ 中...依照 product_name, 會有一堆...

2014年6月20日 星期五

of_property_read_string

Linux 3.0 後新增的 DTB, 其中,string 的 property 用 of_property_read_string

在 /driver/of/base.c:
/**
 * of_property_read_string - Find and read a string from a property
 * @np:  device node from which the property value is to be read.
 * @propname: name of the property to be searched.
 * @out_string: pointer to null terminated return string, modified only if
 *  return value is 0.
 *
 * Search for a property in a device tree node and retrieve a null
 * terminated string value (pointer to data, not a copy). Returns 0 on
 * success, -EINVAL if the property does not exist, -ENODATA if property
 * does not have a value, and -EILSEQ if the string is not null-terminated
 * within the length of the property data.
 *
 * The out_string pointer is modified only if a valid string can be decoded.
 */
int of_property_read_string(struct device_node *np, const char *propname,
    const char **out_string)
{
   struct property *prop = of_find_property(np, propname, NULL);
   if (!prop)
      return -EINVAL;
   if (!prop->value)
      return -ENODATA;
   if (strnlen(prop->value, prop->length) >= prop->length)
      return -EILSEQ;
   *out_string = prop->value;
   return 0;
}
這個 function 只是把 DTB 中該 string 的位置 return 出來。
所以傳入的 pointer 不必預先 allocate 空間,
同樣的,return 回來後,也不能修改內容。

2014年6月17日 星期二

raspberry pi, 更改 keyboard layout

裝完官方 wheezy image 後,keyboard 的 layout 是英國的,所以打 '|' 會出現 '~'

修改的方式,就是手動 edit /etc/default/keyboard
其中有一行:
 XKBLAYOUT="gb"
改成
 XKBLAYOUT="us"
然後重開機就可以了。

2014年6月12日 星期四

device tree , arm and linux

linux 3.0 以後。ARM 也開始使用 Device Tree.

各platform , chip 的 device tree 寫在 arch/arm/boot/dts

build kernel 時,kernel 與 dts file 會分開 build.
dts 會用 device tree compile compile 成 DTB 檔。

bootloader 啟動 kernel 時,會同時把 DTB 讀入記憶體,交給 kernel.
kernel 啟動後,在 arch/arm/kernel/setup.c : setup_arch( ) 中
unflatten_device_tree();
負責把 DTB 解成 device tree 結構。

driver/of/fdt.c:
/**
 * unflatten_device_tree - create tree of device_nodes from flat blob
 *
 * unflattens the device-tree passed by the firmware, creating the
 * tree of struct device_node. It also fills the "name" and "type"
 * pointers of the nodes so the normal device-tree walking functions
 * can be used.
 */
void __init unflatten_device_tree(void)
{
 __unflatten_device_tree(initial_boot_params, &of_allnodes,
    early_init_dt_alloc_memory_arch);

 /* Get pointer to "/chosen" and "/aliasas" nodes for use everywhere */
 of_alias_scan(early_init_dt_alloc_memory_arch);
}


ref:
  • http://events.linuxfoundation.org/sites/events/files/slides/petazzoni-device-tree-dummies.pdf
  • http://blog.csdn.net/21cnbao/article/details/8457546
  • https://sites.google.com/site/yucheng1102/linux-kernel/device-tree
  • http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=dfcd04b19d16c0016c705ed96a8b3cfa5315a2e9

2014年5月28日 星期三

3g dongle - SIM5320

插到 debian 上,直接出現 都採用 default setting 後,就撥接 OK
tail -f /var/log/messages
看到是對 /dev/ttyUSB2 工作。

remove 掉 modemmanager
重新插入 debian, demsg 看,是有 ttyUSB0~4

分別:
cat /dev/ttyUSB?
另一個
echo -e 'at/n' > /dev/ttyUSB?
另一個 cat 的就會出現 OK

ttyUSB 的 default baudrate 都是 9600

結果,只有對 ttyUSB2 下 AT command 有反應。

所以,依照另一份資料:
  • ttyUSB2 : AT Command
  • ttyUSB3 : Modem

2014年5月23日 星期五

MediaScanner 實際scan, extract 的是 StagFrightMetadataRetriever

FileSource.cpp 負責 open, read, seek file , close file 的動作。

總共有:
java/android/media/ThumbnailUtils.java:        MediaMetadataRetriever retriever = new MediaMetadataRetriever();
jni/android_media_MediaMetadataRetriever.cpp:    MediaMetadataRetriever* retriever = new MediaMetadataRetriever();
libstagefright/StagefrightMediaScanner.cpp:    : mRetriever(new MediaMetadataRetriever) {
生成 MediaMetadataRetriever()

2014年5月20日 星期二

Dalvik : CheckJni

Dalvik VM 有一個控制參數: checkjni

因為 jni code 比較難 debug,還有一旦出問題,就會造成整個 vm crash.
所以 android 提供一個 switch, 讓 user 決定是不是要啟動 dalvik 對 jni 的安全檢查。

ro.kernel.android.checkjni

這個 option 在 build eng type 的 image 時,會被加進 build.prop

framework 中參考這個 option 是在:framework/base/core/jni/AndroidRuntime.cpp:
 
   property_get("dalvik.vm.checkjni", propBuf, "");
    if (strcmp(propBuf, "true") == 0) {
        checkJni = true;
    } else if (strcmp(propBuf, "false") != 0) {
        /* property is neither true nor false; fall back on kernel parameter */
        property_get("ro.kernel.android.checkjni", propBuf, "");
        if (propBuf[0] == '1') {
            checkJni = true;
        }
    }
所以在 init.rc 中加上
 setprop dalvik.vm.checkjni false

也可以。

在 dalvik 的 source code 中。
vm/Jni.c:


        } else if (strcmp(optStr, "-Xcheck:jni") == 0) {
            checkJni = true;
        } else if (strncmp(optStr, "-Xjniopts:", 10) == 0) {
        ...
        
    if (checkJni) {
        dvmUseCheckedJniVm(pVM);
        pVM->useChecked = true;
    }


...

    if (vm->useChecked)
        dvmUseCheckedJniEnv(newEnv);


也就是說,一旦 enable check:jni..
vm 就會..
vm/CheckJni.c

void dvmUseCheckedJniEnv(JNIEnvExt* pEnv)
{
    assert(pEnv->funcTable != &gCheckNativeInterface);
    pEnv->baseFuncTable = pEnv->funcTable;
    pEnv->funcTable = &gCheckNativeInterface;
}


其中,gCheckNativeInterface 就是一些 check function..
static const struct JNINativeInterface gCheckNativeInterface = {
    NULL,
    NULL,
    NULL,
    NULL,

    Check_GetVersion,

    Check_DefineClass,
    Check_FindClass,

    Check_FromReflectedMethod,
    Check_FromReflectedField,
    Check_ToReflectedMethod,

    Check_GetSuperclass,
    Check_IsAssignableFrom,

    Check_ToReflectedField,

    ...
    ...

其中的一個,checkUtfString, 就是檢查 passing throught 的 string 是不是符合 modified utf 的格式。
/*
 * Verify that "bytes" points to valid "modified UTF-8" data.
 */
static void checkUtfString(JNIEnv* env, const char* bytes, bool nullOk,
    const char* func)
{
    const char* origBytes = bytes;
    ...
    ...
    while (*bytes != '\0') {
        u1 utf8 = *(bytes++);
        // Switch on the high four bits.
        switch (utf8 >> 4) {
            case 0x00:
            case 0x01:
            case 0x02:
            case 0x03:
            case 0x04:
            case 0x05:
            case 0x06:
            case 0x07: {
                // Bit pattern 0xxx. No need for any extra bytes.
                break;
            }
    .,,,

這個 function check fail 的話,在logcat 就會出現:
W/dalvikvm( 1044): JNI WARNING: illegal start byte 0xa6
W/dalvikvm( 1044):              string: '米??007亞洲初登場超級紀念盤 Disc 2'
W/dalvikvm( 1044):              in Landroid/media/MediaScanner;.processFile (Ljava/lang/String;Ljava
 /lang/String;Landroid/media/MediaScannerClient;)V (NewStringUTF)
..


ref:

標籤

網誌存檔