利用mmc test c研究mmc模組

2021-06-25 17:30:56 字數 4808 閱讀 4228

近日開始研究mmc模組。老是看**不免睏意來襲,為了克服睏意,可以通過一些小的試驗來加深對該模組的理解。

第一步:

首先,自己建立了乙個小的測試模組,通過獲取mmc模組初始化時sdhci_host結構體的指標(初始化時就將這些sdhci_host結構的指標儲存在乙個陣列,並提供介面匯出該陣列首位址供其它模組使用)為神秘的mmc子系統開啟一扇視窗。

註冊sdhci_host的檔案中需要做如下改動:

static unsigned int host_addr[5] = ; 

static unsigned int host_count = 0;

static int ***_sdhci_host_probe(struct platform_device *pdev)

unsigned int *export_host_addr()

export_symbol(export_host_addr);

測試檔案獲取到sdhci_host結構體的方法:

extern unsigned int *export_host_addr();

int test_init()

通過上述**可以看出,我們獲取到sdhci_host結構體之後,可以進一步獲取到對應的mmc_host 結構體,進而獲取到和該控制器對應的mmc_card結構體。我當前的mmc子系統用到3個mmc_host(mmc/sdio/sd),對應兩個mmc_card:mmc——emmc,sd——外接sd卡。

第二步:

獲取到這些重要的結構體後,我們就可以參考mmc_init的流程,向mmc傳送一些指令,如go_idle/send_op_cond/send_cid/send_csd/send_ext_csd(遵循mmc_init流程,其他指令都能順利執行,唯獨send_ext_csd指令會超時,至今原因不明,哪位朋友知道請告知,不勝感激)等,掌握mmc控制器和card互動的最基本指令。

第三步: 

接下來,想研究一下i/o介面的呼叫方法,畢竟emmc/sd卡最重要的作用是用來儲存資料。恰好,在mmc/card/目錄下發現了檔案mmc_test.c,開啟一看,好像有用來測試讀寫介面的方法,真是天助我也!果斷將該檔案編譯為動態模組,但載入後發現並未執行任何實際操作,僅僅新增了乙個測試驅動。繼續看**,發現只有觸發probe函式才會做一些具體的事情:在debugfs中建立兩個檔案節點test和testlist,供使用者通過"echo/cat"指令進行操作——事實上所有實際工作都是使用者通過操縱在debug檔案系統中建立的兩個節點來進行。我們知道,想要觸發probe函式,還需要註冊乙個和驅動名一致的裝置。難道我們為了建立這兩個檔案節點,一定要註冊乙個名為"mmc_test"的裝置才行嗎?

答案是不需要如此麻煩!我們完全可以將這兩個建立檔案節點的介面移到init函式中嘛,或者直接在init函式中就去呼叫probe函式,問題不久迎刃而解了嗎?

再來看probe函式,只需要給它傳入乙個合法的mmc_card指標就足夠了,而我們在第一步已經介紹過如何獲取到合法的mmc_card指標,這裡直接拿來用就可以了(mmc = sdhci_host->mmc, card = mmc->card)。

萬事俱備,開始試驗!

root@scx35_sp7731gea:/sys/kernel/debug/mmc1/mmc1:1234 # ls

lsstate

status

test

testlist

載入該測試模組後可以看到,在該目錄下建立了2個測試節點:test和testlist。執行第25項測試的指令如下:

root@scx35_sp7731gea:/sys/kernel/debug/mmc1/mmc1:1234 # echo 25 > test

測試結果如下:

<6>[ 2479.634882] c1 mmc_test: mmc1: starting tests of card mmc1:1234...

<6>[ 2479.634912] c1 mmc_test: mmc1: test case 25. best-case read performance into scattered pages...

<6>[ 2479.748526] c2 mmc_test: mmc1: transfer of 1 x 8 sectors (1 x 4 kib) took 0.000564193 seconds (7259 kb/s, 7089 kib/s, 1772.44 iops, sg_len 1)

<6>[ 2479.748570] c2 mmc_test: mmc1: result: ok

<6>[ 2479.748633] c2 mmc_test: mmc1: tests completed.

下述指令,可以看出test模組支援的測試項:

root@scx35_sp7731gea:/sys/kernel/debug/mmc1/mmc1:1234 # cat testlist

cat testlist

1:      basic write (no data verification)

2:      basic read (no data verification)

3:      basic write (with data verification)

4:      basic read (with data verification)

5:      multi-block write

6:      multi-block read

7:      power of two block writes

8:      power of two block reads

9:      weird sized block writes

10:     weird sized block reads

11:     badly aligned write

12:     badly aligned read

13:     badly aligned multi-block write

14:     badly aligned multi-block read

15:     correct xfer_size at write (start failure)

16:     correct xfer_size at read (start failure)

17:     correct xfer_size at write (midway failure)

18:     correct xfer_size at read (midway failure)

19:     highmem write

20:     highmem read

21:     multi-block highmem write

22:     multi-block highmem read

23:     best-case read performance

24:     best-case write performance

25:     best-case read performance into scattered pages

26:     best-case write performance from scattered pages

27:     single read performance by transfer size

28:     single write performance by transfer size

29:     single trim performance by transfer size

30:     consecutive read performance by transfer size

31:     consecutive write performance by transfer size

32:     consecutive trim performance by transfer size

33:     random read performance by transfer size

34:     random write performance by transfer size

35:     large sequential read into scattered pages

36:     large sequential write from scattered pages

37:     write performance with blocking req 4k to 4mb

38:     write performance with non-blocking req 4k to 4mb

39:     read performance with blocking req 4k to 4mb

40:     read performance with non-blocking req 4k to 4mb

41:     write performance blocking req 1 to 512 sg elems

42:     write performance non-blocking req 1 to 512 sg elems

43:     read performance blocking req 1 to 512 sg elems

44:     read performance non-blocking req 1 to 512 sg elems

45:     emmc hardware reset

由此,可以開啟乙個操作mmc/sd卡的入口,再結合**,很輕鬆就可以弄清楚各個指令是如何呼叫。

研究和利用printf 和scanf

他們稱為輸入 輸出函式,簡稱i o函式。使用printf printf control string,item1,item2,item1和item2都是要列印的專案。可以是變數也可以是常量,在列印前進行計算的表示式。control string是乙個描述專案的如何列印的字串。乙個轉換符號對應乙個變數...

利用clang和gcc進行巨集的研究

寫乙個巨集 define maxx x,y x y x y int main int argc,char argv 為了看到這個巨集轉換後的效果,即替換後的效果,可以使用gcc或clang命令。命令是以前編譯器使用的,現在普遍不再使用 使用terminal對這個.m檔案進行轉換 gcc e main...

WPF 利用子線程彈出子窗體的研究

原文 wpf 利用子線程彈出子窗體的研究 一般來說子執行緒都是用來處理資料的,主窗體用來實現展現,但是有些時候我們希望子窗體實現等待效果,遮擋主窗體並使主窗體邏輯正常進行,這個業務需求雖然不多,但是正好我們用到了,於是我打算把研究成果寫在這了。稍後我會上傳我的 包含測試程式以及之前兩邊博文談到的控制...