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

2016/9/23

repo sync fail: unable to read sha1 file of ...

error: unable to read sha1 file of gradle-1.4-all.zip (25ee925013e572af4735884757af1e2228c103b0)
Traceback (most recent call last):
  File "/home/charles-chang/px3sdk_raw/.repo/repo/main.py", line 500, in 
    _Main(sys.argv[1:])
  File "/home/charles-chang/px3sdk_raw/.repo/repo/main.py", line 476, in _Main
    result = repo._Run(argv) or 0
  File "/home/charles-chang/px3sdk_raw/.repo/repo/main.py", line 155, in _Run
    result = cmd.Execute(copts, cargs)
  File "/home/charles-chang/px3sdk_raw/.repo/repo/subcmds/sync.py", line 675, in Execute
    project.Sync_LocalHalf(syncbuf)
  File "/home/charles-chang/px3sdk_raw/.repo/repo/project.py", line 1170, in Sync_LocalHalf
    self._InitWorkTree()
  File "/home/charles-chang/px3sdk_raw/.repo/repo/project.py", line 2230, in _InitWorkTree
    raise GitError("cannot initialize work tree")
error.GitError: cannot initialize work tree
可能是因為常常Ctrl-C 來中斷/resume repo sync , 所以最後 repo sync checkout 的時候, git 內容有錯了。

無稐怎樣 gc, fsck, 都沒辦法修復。
單獨,參考 manifest.xml 的 gradle project 去 clone 出來,checkout 也 OK

所以,只好...到 .repo/ 下 search 所以 gradl*:
有關的是:
./projects/tools/external/gradle.git
./project-objects/platform/tools/external/gradle.git

把這兩個刪掉。
整個 bsp 也刪掉,留下 .repo 這個 folder

然後再做 repo sync..就 OK了

2016/9/22

ssh config : 不同 server 給不同的 key, ignore key change

ssh 就是自己產生一對 key, 把public 的送給別人,讓別人可以用 你給的key 來認證你。

所以,也可以產生很多對key, 然後一個 server 給一個,每個 server 都給不同的 pub key
當然,這樣就要小心,在連線的時候,要拿對key
ssh -i id_rsa_therightone servername

這樣很麻煩,所以 ssh 就給一個 config, 讓你可以寫 key- sever 的對應。
這樣 ssh 就會自動照這格 config 拿正確的key 來連。

.ssh/config 的內容:
Host my3rd
    HostName the3.my.com
    user  charles
    IdentityFile ~/.ssh/id_rsa_key1

Host my4th
    HostName the4.my.com
    user checko
    IdentityFile ~/.ssh/id_rsa_key4

另外,如果 ssh 連線的 server 不在 .ssh/config 中,
ssh 也沒有加上 -i (指定 key file) 的選項。
ssh 就會用 .ssh/id_rsa 來連。



這個 config 很有趣,好像只會認得 Host,
以上面的例子來說..
ssh my3rd
會正確的使用 id_rsa_key1

但是用server 真正的名子:
ssh the3.my.com
就不會用 id_rsa_key4 了。

我猜這是為了一個 server 用不同user name login..
這樣才可以用 Host 來區分,

如果是 embedded system, 一直更換 key 的情況,ssh 連線出現:
Hostkey verification failed
M
可以在 config 加入:
$ cat .ssh/config
StrictHostKeyChecking no
UserKnownHostsFile /dev/null
這樣都不會檢查了...

ssh-agent .真的就是一個agent

為了安全,用 ssh private, public key...
然後key還加上密碼。

這樣登入雖然安全了,但是又恢復到每次登入都要輸入密碼。
所以就出現 ssh-agent, 會聽你的通訊,在要輸入密碼的時候,自動幫你輸入密碼。
--- 這樣幫 key 加上密碼不就沒意義了?

所以,啟動 ssh-agent 邦你工作的時候,ssh-agent 會需要你輸入密碼,這樣他才能幫你。
所以:
ssh-add : 加入 key, 要 ssh-agent 幫你傳key
ssh-add 會對每一個 key, 如果有須要密碼的,請妳輸入密碼,他會記下來,以後好幫你輸入。

這樣就改成...只要啟動 ssh-agent 時輸入一次密碼就好,避免掉每次都需要輸入的問題。


2016/9/6

reboot ..

最後 reset 是...arm/arm/mach-kk40/reset.c
static void kk40_arch_reset(char mode, const char *cmd)
{
        u32 boot_flag = 0;
        u32 boot_mode = BOOT_MODE_REBOOT;

        if (cmd) {
                if (!strcmp(cmd, "loader") || !strcmp(cmd, "bootloader"))
                        boot_flag = SYS_LOADER_REBOOT_FLAG + BOOT_LOADER;
                else if(!strcmp(cmd, "recovery"))
                        boot_flag = SYS_LOADER_REBOOT_FLAG + BOOT_RECOVER;
                else if (!strcmp(cmd, "charge"))
                        boot_mode = BOOT_MODE_CHARGE;
        } else {
                if (is_panic)
                        boot_mode = BOOT_MODE_PANIC;
        }
#ifndef RK30_PMU_BASE
        writel_relaxed(boot_flag, RK30_GRF_BASE + GRF_OS_REG4); // for loader
        writel_relaxed(boot_mode, RK30_GRF_BASE + GRF_OS_REG5); // for linux
#else
        writel_relaxed(boot_flag, RK30_PMU_BASE + PMU_SYS_REG0);        // for loader
        writel_relaxed(boot_mode, RK30_PMU_BASE + PMU_SYS_REG1);        // for linux
#endif
 ....

所以會reboot flag 和 mode 會被寫入 cpu register...