分享到plurk 分享到twitter 分享到facebook

版本 169bec3b32e0bbf844dc4395184faa7f2ba1caa6

RT-Thread

協作者

  • 2015 年春季
    • 周曠宇<https://github.com/luckyjoou>, 吳子晨<https://github.com/Eddy0402>, Adrian Huang<https://github.com/AdrianHuang>, 吳念祖<https://github.com/nienzu>, 吳義路<https://github.com/jackraken>, 江冠霆<https://github.com/CKT-tw>

共筆

  • 2015 年春季
    • Hackpad<https://rt-thread.hackpad.com/RT-Thread-on-Beaglebone-Black-i93C7gRxZuW>_

目錄

  • AM335x ARM Cortex-A8 Boot Sequence<#AM335x ARM Cortex-A8 Boot Sequence>_

AM335x ARM Cortex-A8 Boot Sequence

圖1 為AM335x開機流程,其包含ROM Code、MLO、U-Boot與OS Image,底下將說明ROM Code、MLO與U-Boot。

.. image:: https://lh3.googleusercontent.com/-6t7H14Lj3Bc/VT3n0BPjOaI/AAAAAAAAH9M/woI49MW-TC4/w1099-h752-no/am335x-boot-sequence.png 圖1 High-level Overview to AM335x Boot Sequence

ROM Code主要有幾項任務: - Stack Setup - Watchdog timer 1 configuration (set to three minutes) - System clock configuration - Search bootable devices (must be the FAT 12/16/32 partition) for a valid booting image (the image name must be MLO) - Load the content of the file “MLO” from a bootable device to internal RAM (the 128KB on-chip memory) - Execute the file “MLO” stored in internal RAM

圖2為ROM Code架構,由“Public ROM Code drivers”可知ROM code支援如下裝置: - MMCSD (MultiMediaCard SD) - NAND - XIP (eXecute In Place) - SPI - USB UART - EMAC (Ethernet Media Access Control)

也就是說,系統一上電,ROM Code會掃描上述裝置,以便找到Bootable device。由於ROM Code只支援FAT檔案系統格式,所以Bootable device一定要是FAT檔案系統 (FAT12/16/32檔案系統都可以)。 注意: 該架構的On-chip boot ROM大小為176 KB。

.. image:: https://lh5.googleusercontent.com/-ClS3EZ2u0Hk/VT33Y8THfxI/AAAAAAAAH9w/t9gFp9N6ajM/w1011-h631-no/ROM-code-architecture.png 圖2 ROM Code Architecuture (page 4096 in AM335x TRM)

圖3為ROM Memory Map: - ROM Exception Vectors (0x20000-0x2001F): 該區段定義Exception Handler的位址。譬如: 0x20000存放Reset Handler的位址,也就是板子一上電,第一個執行的地方,課程第七周有詳盡的說明,可參考此文件。詳盡的ROM Exception Vectors如表1所示。

.. image:: https://lh5.googleusercontent.com/-ClS3EZ2u0Hk/VT33Y8THfxI/AAAAAAAAH9w/t9gFp9N6ajM/w1011-h631-no/ROM-code-architecture.png 表1 ROM Exception Vectors (page 4099 in AM335x TRM)

  • Public ROM Code CRC (0x20020): 由0x20000-0x2BFFF計算得出的四個位元組CRC值。
  • Dead loops (0x20080-0x200FF): 該區段定義預設的exception handlers,其預設handlers都是執行while(1)迴圈,程式設計者可以定義相同名字的exception handler,如此便能覆蓋 (override)對應之預設exception handlers。可參考mini-arm-os<https://github.com/jserv/mini-arm-os/blob/master/05-TimerInterrupt/startup.c#L63>_與freertos<https://github.com/embedded2015/freertos-basic/blob/master/freertos/libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/startup/gcc_ride7/startup_stm32f10x_md.s#L124>_程式碼,以便了解其設計概念。
  • Code (started from 0x20100): ROM程式碼
  • ROM Version (0x2BFFC-0x2BFFF): ROM Code Version

.. image:: https://lh3.googleusercontent.com/-xhXu1yv0eik/VT33Y0MPSDI/AAAAAAAAH9k/S7dXDW7UrGI/w306-h329-no/ROM-memory-map.png 圖3 ROM Memory Map (page 4098 in AM335x TRM)

MMU Configuration in RT-Thread

MRC/MCR Instruction MMU設定跟Coprocessor 15有關,下圖為Coprocessor 15暫存器配置圖 。

.. image:: https://lh5.googleusercontent.com/-XhcpJ1M19PI/VVC07E249nI/AAAAAAAAIEM/o41r7sl8cwQ/w1083-h564-no/cp15-overview.png 圖四 VMSA: Virtual Memory System Architecture

MRC: Move to ARM register from coprocessor
- MRC coproc, opcode1, Rd, CRn, CRm{, opcode2}, where Rd is ARM source register
MCR: Move to coprocessor from ARM registers
- MCR coproc, opcode1, Rd, CRn, CRm{, opcode2}, where Rd is ARM source register

MMU Initialization in RT-Thread Disable Data Cache mrc p15, 0, r0, c1, c0, 0 /* Read System Control Register */ .. image:: https://lh3.googleusercontent.com/-Rz5eQdg4EcM/VVC5t2eTCjI/AAAAAAAAIEY/9YMC3tQf6yw/w1160-h566-no/cp15-c1.png

VMM (Virtual Machine Module) and vbus

  • VMM (Virtual Machine Module) VMM模組可同時運行Linux與RT-Thread,如圖五所示。VMM以半虛擬化方式 (para-virtualization)運行另一個OS。

.. image:: https://lh4.googleusercontent.com/-49-7jFwVpZM/VUgwLRtPPqI/AAAAAAAAIBs/w0K4npFRaJg/w939-h634-no/rt-thread-vmm.png 圖五、VMM/vbus Framework

三個元件需要用來實現同時運行RT-Thread與Linux,如下所述: 1. Linux VMM Kernel Patches: RT-Thread開發者發佈兩個Kernel Patches <https://github.com/AdrianHuang/rt-thread-for-vmm/tree/master/components/vmm/linux_patch-v3.8>_支援多個作業系統同時運行。 2. Linux VMM Kernel Module (rtvmm.ko): 此模組用來載入RT-Thread Binary File。 3. RT-Thread Binary File (rtthread.bin): RT-Thread作業系統二進制檔。

[編譯與執行]

rt-thread-vmm-builder <https://github.com/AdrianHuang/rt-thread-vmm-builder>_自動地將Linux VMM Kernel Patches、Linux VMM Kernel Module與RT-Thread Binary File編譯,並產生kernel image (zImage)與root file system。參考底下步驟 (同時可參考rt-thread-vmm-builder README檔 <https://github.com/AdrianHuang/rt-thread-vmm-builder>_建構環境及相關Toolchain):

.. code-block:: prettyprint

git clone https://github.com/AdrianHuang/rt-thread-vmm-builder.git
cd rt-thread-vmm-builder/
make
make qemu

執行’make qemu’後, 會啟動qemu模擬器,Linux console與RT-Thread console切換鍵如下: 1. Linux Console -> Ctrl+Alt+F3 2. RT-Thread Console -> Ctrl+Alt+F4

[執行畫面]

.. image:: https://lh6.googleusercontent.com/-rhNG5HsX5bk/VX_IJMNczbI/AAAAAAAAIKU/hM1CFIP0cKM/w790-h569-no/linux-1.png 圖六、執行’make qemu’並按Ctrl+Alt+F3進入Linux Console

.. image:: https://lh5.googleusercontent.com/-zM0eIcnkK-U/VX_IJD9ZevI/AAAAAAAAIKM/b_CZuAyN_1o/w1011-h307-no/linux-insmod-rtvmm-driver.png 圖七、載入rtvmm.ko模組

.. image:: https://lh3.googleusercontent.com/-NZlzQBrzD1g/VX_IJOegylI/AAAAAAAAIKQ/cE8BBcgPrPY/w1013-h314-no/rt-thread.png 圖八、Ctrl+Alt+F4進入RT-Thread Console

  • vbus

參考資料

  • Beaglebone
    • Rev. changes<http://elinux.org/Beagleboard:BeagleBoneBlack#Revision_C_.28Production_Version.29>_
    • Schematic<http://beagleboard.org/static/beaglebone/latest/Docs/Hardware/BONE_SCH.pdf>_
    • System Reference Manual<http://docs-asia.electrocomponents.com/webdocs/12d7/0900766b812d788b.pdf>_
  • AM335x (3358) TRM, Datasheet
    • TRM<https://drive.google.com/open?id=0B90H2V1uw2FnVmNndG5jV3V5N2M&authuser=0>_
    • Datasheet<https://drive.google.com/open?id=0B90H2V1uw2FnbzFDZTNpRC1jOGc&authuser=0>_
    • Boot process<http://processors.wiki.ti.com/index.php/AM335x_U-Boot_User%27s_Guide#U-Boot>_
  • ARM Cortex-A8
    • TRM<https://drive.google.com/open?id=0B90H2V1uw2FnRnJOSlpzTm4yWFU&authuser=0>_
    • ISA: ①<https://drive.google.com/open?id=0B90H2V1uw2FnUEZzWFpmR3JKa1U&authuser=0>_ ②<http://people.cs.nctu.edu.tw/~chenwj/dokuwiki/doku.php?id=arm>_
    • Bus:
      • AMBA<https://drive.google.com/open?id=0B90H2V1uw2FnRHpIWGJLaUUwZzA&authuser=0>_
      • APB<https://drive.google.com/open?id=0B90H2V1uw2FnUEZzWFpmR3JKa1U&authuser=0>_
      • AXI<https://drive.google.com/open?id=0B90H2V1uw2FnSVBERUdFUFlsZkE&authuser=0>_
  • POSIX
    • The Open Group Base Specifications Issue 7<http://pubs.opengroup.org/onlinepubs/9699919799//>_
    • Open POSIX Test Suite<http://posixtest.sourceforge.net/>_
  • EMMC
    • Kingston KE4CN2H5A<http://uk.rs-online.com/web/p/flash-memory-chips/7852322P/>_