--- tags: David, OpenSSD, Cosmos+, Configs --- # Cosmos+ Projects ## Prerequisites 之後 Build 專案時會使用到 Make 之類的開發工具,因此需要先安裝: ```shell $ sudo apt install build-essential ``` 而編譯專案時則需要部份 32 位元的工具: ```shell $ sudo apt-get install lib32z1 lib32ncurses5 lib32bz2-1.0 lib32stdc++6 ``` 否則可能會出現以下錯誤訊息: > arm-xilinx-eabi-gcc: not found :::warning Ubuntu 22.04 STL 則需要特別指定: ```shell $ sudo apt install lib32z1 libncurses5:i386 libstdc++6:i386 libbz2-1.0:i386 ``` 參考: - https://askubuntu.com/questions/637113/unable-to-locate-package-lib32bz2-1-0 - https://developer.android.com/studio/install.html#64bit-libs ::: 安裝完以上工具後重開機(或重新登入),然後應該就能夠正常啟動 SDK 等工具了。 :::warning 以上的 Ubuntu 22.04 STL 測試環境皆為 KDE(Qt),所以第一次開啟 SDK 時有**印出**以下錯誤: ```shell libgtk-x11-2.0.so.0: cannot open shared object file: No such file or directory ``` 可以看到是缺少 GTK 相關的檔案,因此需要額外安裝: ```shell $ sudo apt install libgtk2.0-0 $ sudo apt install gnome-themes-standard # optional, just a gtk theme ``` Ubuntu 14.04 STL 則不須特別安裝這些 library。(其他版本未測) ::: --- 順利安裝完成後來測試[官方提供的 Projects](https://github.com/Cosmos-OpenSSD/Cosmos-plus-OpenSSD/tree/master/project),分成 Predefined 與 Prebuild 兩種專案,最大的差別在是否需要自行生成 [FPGA bitstream](https://www.xilinx.com/htmldocs/xilinx2018_1/SDK_Doc/SDK_concepts/concept_fpgabitstream.html),完整的操作流程可以參考 [GitHub 上的 Cosmos+ OpenSSD Tutorial 2017](https://github.com/Cosmos-OpenSSD/Cosmos-plus-OpenSSD/blob/master/doc/Cosmos+%20OpenSSD%202017%20Tutorial.pdf) 或是 [Youtube 上的教學影片](https://www.youtube.com/watch?v=idwbhjPasnI)。 --- ![](https://i.imgur.com/XnCD3Jp.png) ![](https://i.imgur.com/jMinBDN.png) --- ## Predefined Project --- ## Prebuild Project Prebuild 專案的目錄結構如下: ``` prebuild └── 8Ch8Way-3.0.0 ├── GreedyFTL-2.7.0.d │   └── nvme ├── GreedyFTL-3.0.0 │ └── nvme ├── Prebuild-3.0.0-Tutorial.pdf └── OpenSSD2-8C8W-Prebuild-3.0.0.hdf ``` 只有 `8Ch8Way-3.0.0` 一個專案,而專案目錄下包含一個 Hardware Description File (.hdf),包含 FPGA bitstream 以及硬體相關的資訊,在建立專案時會使用到;GreedyFTL 開頭的兩個目錄則是 Firmware 的程式碼,在建立專案時需要將其中一個版本程式碼複製到專案的 `src` 目錄下。 :::info TODO: 兩個版本的差異 ::: 而 [Prebuild-3.0.0-Tutorial.pdf](https://github.com/Cosmos-OpenSSD/Cosmos-plus-OpenSSD/blob/master/project/Prebuild/8Ch8Way-3.0.0/Prebuild-3.0.0-Tutorial.pdf) 則是 Prebuild 專案的說明文件,以下操作基本上參考於以這個文件,細部說明則參考前面提到的 [Cosmos+ OpenSSD Tutorial 2017](https://github.com/Cosmos-OpenSSD/Cosmos-plus-OpenSSD/blob/master/doc/Cosmos+%20OpenSSD%202017%20Tutorial.pdf): ### Create Project 首先需要開啟 SDK 並選擇 workspace 路徑,若是首次在 workspace 中開啟 SDK 的話,會出現 Welcome 的畫面,直接關掉即可。 然後就可以看到 Prebuild 文件中相似的 SDK 畫面: ![](https://i.imgur.com/i0NJazf.png) 點選左上角的 File 新建 Application Project,並照 Prebuild 文件中的流程選擇 hdf 檔,並按 Next 建立 Empty Application。 :::warning 注意這邊設定的 Project Name,以下若沒特別強調的話,皆指該名稱的專案,而非 Hardware Platform 的 Project Name 或是 `_bsp` 後綴的專案,如下圖中的 `Greedy`。 ![](https://i.imgur.com/yZh1F4X.png) ::: ### Build Project 接著需要依照前面講的,把需要的 Firmware 程式碼都複製到專案的 `src` 目錄,直接複製檔案後對 src 目錄點右鍵貼上所有檔案,然後再對專案點右鍵、選擇 Properties > C/C++ Build > Settings 中新增專案需要 Include 的目錄: ![](https://i.imgur.com/kjqSEXM.png) ![](https://i.imgur.com/HddsLIh.png) 把 `src` 與 `src/nvme` 加到 Settings 並按下確定後,再對專案點右鍵 > Build Project,然後應該會在 Console 中看到 Build 完成的訊息: ![](https://i.imgur.com/hHDLPqz.png) :::warning 接著若在 build project 時出現錯誤訊息的話: > /opt/Xilinx/SDK/2014.4/gnu/arm/lin/bin/../lib/gcc/arm-xilinx-eabi/4.8.3/../../../../arm-xilinx-eabi/bin/ld: cannot find -lxil 就先對 `${ProjectName}_bsp` 按右鍵 > make target > build > OK 即可。 參考:https://support.xilinx.com/s/question/0D52E00006hpTgmSAE/libxil-not-found?language=en_US ::: 最後再對專案點右鍵 > Build Configurations > Build All,同樣也該在 Build 完成後看到類似的訊息。 ### Connect Cosmos+ Board 接著需要接上 Cosmos+ 開發板,先按照 Cosmos+ OpenSSD Tutorial 2017 文件中的 P.59 ~ P.69 的說明檢查 Jumper Pins 、記憶體、線路的設置。 接著開啟電源、插入 JTAG 與 UART 的兩個 USB 到開發裝置上,並在 Terminal 中透過 `$ ls -l /dev/ttyUSB*` 檢查對應的 Serial Port 編號: ```shell $ ls -l /dev/ttyUSB* crw-rw---- 1 root dialout 188, 0 Jul 12 15:50 /dev/ttyUSB0 crw-rw---- 1 root dialout 188, 1 Jul 12 15:51 /dev/ttyUSB1 ``` 但由於當前 User 不是 root user,也不屬於 dialout 這個 group,而後面的操作需要透過這兩個 Port 進行,但 other 的權限為 0,所以這邊需要透過 chmod 讓 other 有讀寫權限: ```shell $ sudo chmod 666 /dev/ttyUSB* && ll /dev/ttyUSB* crw-rw-rw- 1 root dialout 188, 0 Jul 12 15:50 /dev/ttyUSB0 crw-rw-rw- 1 root dialout 188, 1 Jul 12 15:51 /dev/ttyUSB1 ``` 接著在 Terminal 新增一個 Serial Connection,並設定 UART 對應的 Port 以及 Baud Rate,如下圖(Port 可能會不同): ![](https://i.imgur.com/XhcQb7Y.png) 接著再按 Program FPGA 將 prebuild 專案附帶的 bitstream 設定到 FPGA 上: ![](https://i.imgur.com/o2LDrqX.png) 跑完後應該能夠在 SDK Log 中看到 `FPGA configured successfully with bitstream` 的訊息。 ### Run project 接著再對專案按右鍵 > Run as > Launch on Hardware (GDB) 啟動程式,若 GDB 正常啟動的話,應該能夠在 Terminal 中看到以下訊息: ![](https://i.imgur.com/4YeqxEZ.png) :::danger 在 Ubuntu 22.04 STL 上透過 Run as 執行 GDB 時會 crash 並跳出錯誤訊息: ``` # # A fatal error has been detected by the Java Runtime Environment: # # SIGSEGV (0xb) at pc=0x00007f6cf760724d, pid=29687, tid=140106337875520 # # JRE version: Java(TM) SE Runtime Environment (8.0_05-b13) (build 1.8.0_05-b13) # Java VM: Java HotSpot(TM) 64-Bit Server VM (25.5-b02 mixed mode linux-amd64 compressed oops) # Problematic frame: # C [librxtxSerial.so+0x724d] read_byte_array+0x3d # # Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again # # If you would like to submit a bug report, please visit: # http://bugreport.sun.com/bugreport/crash.jsp # The crash happened outside the Java Virtual Machine in native code. # See problematic frame for where to report the bug. # ``` 從錯誤訊息可以看到是 `librxtxSerial.so` 這個 Shared Library 有問題,可以先安裝 `librxtx-java`,然後再用 `/usr/lib/jni/librxtxSerial.so` 取代 SDK 中的 `librxtxSerial.so`: ```shell $ pwd /home/hsi/Softwares/Xilinx/SDK/2014.4 $ cd eclipse/lnx64.o/plugins/gnu.io.rxtx.linux.x86_64_2.1.7.3_v20071015/os/linux/x86_64/ $ mv librxtxSerial.so librxtxSerial.so.old $ ln -s /usr/lib/jni/librxtxSerial.so . ``` 安裝完後再重新登入應該就不會再 crash 了,但會出現版本不相符的警告訊息: ``` WARNING: RXTX Version mismatch Jar version = RXTX-2.1-7 native lib Version = RXTX-2.2pre2 ``` 參考: - https://support.xilinx.com/s/question/0D52E00006hpSjBSAU/sdk-segfault-on-uart-output?language=en_US - https://support.xilinx.com/s/question/0D52E00006iHw1YSAS/xilinx-sdk-20183-crash-on-ubuntu-1804?language=en_US ::: :::info TODO: launch with PCIe :::