大樹底下好乘涼 ︰ 《拜樹頭》 ? ※成而不居

百花齊放

百花齊放

百家爭鳴

百家爭鳴

鏡花緣‧第三回》徐英公傳檄起義兵 駱主簿修書寄良友

百花仙子笑道:「小仙今拜南極仙翁為師,若論高手,大約除了敝老師就要輪到小仙,豈可與從前一例看待。--就下十盤我也不懼!且命貴仙女暖酒安枰,我兩人好一飲一著,分個高下。」麻姑道:「仙姑休得誇強,到了終局,你才知利害,那才後悔不該同我對局哩!」百花仙子道:「仙姑今日如果得勝,小仙聞得下界高手甚多,我去凡間訪求明師,就便將弈秋請來,看你可怕?」麻姑道:「那弈秋老先生,連孟夫子都佩服的,我如何不怕!但仙姑『下凡訪師』這句話,未免動了紅塵之念,將來只怕下界有人聘你去做棋中高手哩。」

一面說笑,隨命仙女擺設酒肴,安排棋局,登時各逞心思,對著起來。百花仙子只顧在此著棋,那知下界帝王忽有御旨命他百花齊放

在一篇名為《 Device trees everywhere 》的文章裡,談及了二零零五年五月時,  IBM 的 Benjamin Herrenschmidt 建置了一套新的『設備樹』之 linux kernel 啟動機制,即使一個沒有『 OF 』 Open Firmware 的系統,也可以使用『設備樹』得到好處。此事記載於 Linux 《 booting-without-of.txt 》 文件之中,那時 ── May 18, 2005: Rev 0.1 – Initial draft, no chapter III yet. ── ,到了

November 21, 2005: Rev 0.5

– Additions/generalizations for 32-bit
– Changed to reflect the new arch/powerpc structure
– Added chapter VI

此刻的差異實在說並不大。『術語』與『架構』延襲至今,正是深入理解『 /proc/device-tree 』、『 The DT block format 』、『 Required content of the device tree 』以及一些『建議』的基礎『文本』。俗話講︰『十年磨一劍』,正此之謂耶??

雖說『設備樹』是種系統連接『硬體裝置』的簡易『描述語言』 ,但要三言兩語講清楚它與『第一啟動』 BIOS 韌體或是『 Boot Loader 』與『 kernel os 』之裝置『驅動程式』間的關係,其實很不容易。因此這裡也只能借花獻佛,請讀者自讀《 Device Tree for DUMMIES 》的了。

□︰ phandle 是什麼阿?
○︰ p + Handle 的吧!
□︰能說文解字嗎?
○︰ Handle 把柄, p (ointer) 乃指標是也!
□︰有些八卦呢??
○︰音譯成『ㄈㄟㄢ ㄉㄡ』才八卦哩!!

vray-bsp-tree-acceleration-structure

象棋‧仙人指路

既然『設備樹』 與『檔案樹』都是『樹狀結構』,系統開機後用『 /proc/device-tree 』來表現啟始 dtb 之結果,正是一一對應︰

設備根節點 Device Root  \Longleftrightarrow /proc/device-tree 目錄

設備節點 Device Node  \Longleftrightarrow 子目錄

設備屬性 Device Property  \Longleftrightarrow 檔案

# 設備樹鏈結至 /sys/firmware/devicetree/base
ls -la /proc/device-tree
lrwxrwxrwx 1 root root 29  3月  2 15:56 /proc/device-tree -> /sys/firmware/devicetree/base

# 與 fdt 同構
cd /proc/device-tree
ls -l

總計 0
-r--r--r--  1 root root  4  3月  2 15:55 #address-cells
drwxr-xr-x  2 root root  0  3月  2 15:55 aliases
drwxr-xr-x  7 root root  0  3月  2 15:55 axi
drwxr-xr-x  2 root root  0  3月  2 15:55 chosen
drwxr-xr-x  4 root root  0  3月  2 15:55 clocks
-r--r--r--  1 root root 13  3月  2 15:55 compatible
drwxr-xr-x  6 root root  0  3月  2 15:55 cpus
drwxr-xr-x  2 root root  0  3月  2 15:55 display
-r--r--r--  1 root root  4  3月  2 15:55 interrupt-parent
drwxr-xr-x  2 root root  0  3月  2 15:55 memory
-r--r--r--  1 root root  8  3月  2 15:55 memreserve
-r--r--r--  1 root root 23  3月  2 15:55 model
-r--r--r--  1 root root  1  3月  2 15:55 name
drwxr-xr-x  2 root root  0  3月  2 15:55 __overrides__
-r--r--r--  1 root root  4  3月  2 15:55 #size-cells
drwxr-xr-x 10 root root  0  3月  2 15:55 soc
drwxr-xr-x  2 root root  0  3月  2 15:55 sound
drwxr-xr-x  2 root root  0  3月  2 15:55 __symbols__
drwxr-xr-x  2 root root  0  3月  2 15:55 system
drwxr-xr-x  2 root root  0  3月  2 15:55 timer

這雖然說是了解 Linux FDT 建制很好的辦法, 然而

# 不是 ASCII 碼
cat \#address-cells 
□

# 不符數據內容
hexdump \#address-cells 
0000000 0000 0100                              
0000004

# 字串 OK
cat compatible 
brcm,bcm2709

,所以也不是容易的事。要是

# 產生當下 /proc/device-tree
dtc -I fs -O dtb -o runtime.dtb /proc/device-tree
Warning (avoid_default_addr_size): Relying on default #address-cells value for /axi/vc_mem
Warning (avoid_default_addr_size): Relying on default #size-cells value for /axi/vc_mem

# 總覽
fdtdump runtime.dtb
/dts-v1/;
// magic:		0xd00dfeed
// totalsize:		0x1ce3 (7395)
// off_dt_struct:	0x38
// off_dt_strings:	0x1948
// off_mem_rsvmap:	0x28
// version:		17
// last_comp_version:	16
// boot_cpuid_phys:	0xf00
// size_dt_strings:	0x39b
// size_dt_struct:	0x1910

/ {
    model = "Raspberry Pi 2 Model B";
    compatible = "brcm,bcm2709";
    memreserve = <0x3b000000 0x0000001c>;
    #address-cells = <0x00000001>;
    #size-cells = <0x00000001>;
    interrupt-parent = <0x00000001>;
    axi {
...

# 閱讀
fdtget runtime.dtb -l /
axi
soc
cpus
display
sound
timer
chosen
clocks
memory
system
__symbols__
aliases
__overrides__

fdtget runtime.dtb -p /
model
compatible
memreserve
#address-cells
#size-cells
interrupt-parent

fdtget runtime.dtb / \#address-cells
1

 

 

─── 也許在這逐鹿中原之時,快就是好!! ───