2012年11月22日 星期四

Internal SRAM Testing


呼 ,  最近剛剛修正一些 system 相關的 library so file , 和生產測試程式要用的 library .
最後發現 , 有一個項目是測試 CPU 內部的SRMA 讀寫動作 !!

哇咧 , AM335x ROM code booting 就會把 MLO 載入 SRAM 中執行 , 要是 SRAM 有問題, 那不就開不了機 ?? 後續哪需要測試這個 SRAM ?? 並且我們應用上也沒有使用這個 SRAM !! 真是三條線 .... 好吧依照需求寫 Driver 吧 !!

我想有兩種方式可以完成 ,
A. 使用 字元Driver  , 然後完成 mmap 的 function .讓 測試程式可以 mmap 出這段 SRAM , 然後進行 read/write testing.

B. 使用 Block Driver 將 SRAM 製作程一個 Block Driver . 說真的 Block Driver 我比較少碰到 , 所以不知道怎樣寫.... @@ . 不過我想應該有現成的... 找找看吧 !!

最後發現 MTD + MTD_PLATRAM 就可以將 某一段 ADDRESS map 到 mtbblock 上 來當作 Storage 存取用. 因為只是測試要用 , 所以我打算編譯程 ko module .

第一步驟 , 打開這兩個 driver , 修改後的 .config diff file.

-# CONFIG_MTD_RAM is not set
+CONFIG_MTD_RAM=m
 # CONFIG_MTD_ROM is not set
 # CONFIG_MTD_ABSENT is not set

@@ -671,7 +671,7 @@
 # CONFIG_MTD_COMPLEX_MAPPINGS is not set
 # CONFIG_MTD_PHYSMAP is not set
 # CONFIG_MTD_PHYSMAP_OF is not set
-# CONFIG_MTD_PLATRAM is not set
+CONFIG_MTD_PLATRAM=m


第二步驟 , 在 am335x_evm.c 中增加 SRAM platform device . 如下(diff list):

+//---- internel ram
+static struct platdata_mtd_ram am335x_sram_data =
+{
+    .bankwidth = 1,
+};
+
+static struct resource am335x_sram_resource =
+{
+    .start = AM33XX_SRAM_PA,
+    .end   = AM33XX_SRAM_PA + 64 * 1024 - 1,
+    .flags = IORESOURCE_MEM,
+};
+
+static struct platform_device am335x_sram_mtd_device =
+{
+    .name = "mtd-ram",
+    .id = 0,
+    .dev =
+    {
+        .platform_data = &am335x_sram_data,
+    },
+    .num_resources = 1,
+    .resource = &am335x_sram_resource,
+};
+
+static void internal_ram(void)
+{
+int status = 0;
+
+    status = platform_device_register(&am335x_sram_mtd_device);
+    if (status)
+        pr_err("failed to register matrix am335x_sram_mtd_device device\n");
+
+}
 

要使用前 , 在 code 中掛載 Driver ko
    system("modprobe plat-ram");

測試完畢後 , 卸載 Driver ko

    system("rmmod plat_ram");
    system("rmmod map_ram");


因為我有完整的 build kernel module . 所以用 modprobe  就可以自動掛在相依的 ko driver .

卸載時 , 我手動將沒有用到的 一起卸載 , 所以多一行 卸載 map_ram.

這樣就完成了 !!


另外要注意一件事情 , 就是  Suspend 過程中有一段 code 會放到 SRAM 中執行 , 小心不要因為 測試弄毀原來中的 CODE , 或是 suspend 過程中. 記得在將 suspend code 放入 SRAM 中.

沒有留言:

張貼留言