樹莓派系統(BCM283x)的啓動過程

本文主要介紹了樹莓派主控芯片BCM28e3x的啓動過程,可瞭解樹莓派boot目錄下的哥哥文件的作用,以及被使用的時段。

文中的內容主要翻譯自:

 

https://www.raspberrypi.org/documentation/hardware/computemodule/cm-peri-sw-guide.md

 

BCM283x的啓動過程

 

BCM283x devices consist of a VideoCore GPU and ARM CPU cores. The GPU is in fact a system consisting of a DSP processor and hardware accelerators for imaging, video encode and decode, 3D graphics, and image compositing.

 

BCM283x芯片包含了一個處理視頻內核的GPU以及一個ARM CPU 內核。這個GPU包含了一個DSP處理器以及用於圖像,視頻編解碼3D圖形和圖像合成的加速器。

 

In BCM283x devices, it is the DSP core in the GPU that boots first. It is responsible for general setup and housekeeping before booting up the main ARM processor(s).

 

BCM283x設備中,GPUDSP覈實最先啓動的。DSP主要負責在啓動ARM處理器之前通用的設置和整理。

 

The BCM283x devices as used on Raspberry Pi and Compute Module boards have a three-stage boot process:

 

樹莓派和CM板在啓動階段分爲3個階段:

1. The GPU DSP comes out of reset and executes code from a small internal ROM (the boot ROM). The sole purpose of this code is to load a second stage boot loader via one of the external interfaces. On a Raspberry Pi or Compute Module, this code first looks for a second stage boot loader on the SD card (eMMC); it expects this to be called bootcode.bin and to be on the first partition (which must be FAT32). If no SD card is found or bootcode.bin is not found, the Boot ROM sits and waits in 'USB boot' mode, waiting for a host to give it a second stage boot loader via the USB interface.

1.GPUDSP復位並執行芯片內部ROM中一小段代碼。這段代碼的唯一目的就是通過一個外部的接口啓動加載第二階段的引導加載程序。在樹莓派和CM板上,這段代碼首先在SD卡或者emmc上尋找第二階段啓動加載程序,這個程序文件名是bootcode.bin,這個文件位於一個FAT32文件系統的第一分區。如果在SD卡或者emmc中沒有發現bootcode.bin文件,那麼啓動ROM代碼就會處於USB啓動模式,期望通過USB接口獲得第二階段的啓動加載程序。

 

2.The second stage boot loader (bootcode.bin on the sdcard or usbbootcode.bin for usb boot) is responsible for setting up the LPDDR2 SDRAM interface and various other critical system functions and then loading and executing the main GPU firmware (called start.elf, again on the primary SD card partition).

2.第二階段啓動加載程序(SD卡或emmc啓動是bootcode.binUSB啓動時usbbootcode.bin)主要負責設置LPDDR2 SDRAM 接口和多種其他關鍵的系統功能,然後加載和執行GPU固件(start.elf,在SD卡分的初始分區也就是boot分區中)

 

3.start.elf takes over and is responsible for further system setup and booting up the ARM processor subsystem, and contains the firmware that runs on the various parts of the GPU. It first reads dt-blob.bin to determine initial GPIO pin states and GPU-specific interfaces and clocks, then parses config.txt. It then loads an ARM device tree file (e.g. bcm2708-rpi-cm.dtb for a Compute Module) and any device tree overlays specified in config.txt before starting the ARM subsystem and passing the device tree data to the booting Linux kernel.

 

文件start.elf接管和負責進一步的系統設置以及啓動ARM處理器子系統,包含了運行GPU各個部分的固件。start.elf文件首先讀取dt-blob.bin文件以便初始化gpio引腳的狀態以及GPU特定的接口和時鐘,然後就解析文件config.txt。以上這些完成後,在開始arm子系統以及將設備樹的數據傳遞給Linux內核之前,這個文件加載一個ARM設備樹文件(如:cmbcm2708-rpi-cm.dtb )以及其他任何在config.txt文件中指定的設備樹覆蓋。

 

樹莓派設備樹

Device Tree is a special way of encoding all the information about the hardware attached to a system (and consequently required drivers).

設備樹是一種對附加到系統上硬件的所有信息編碼的特殊方式。

On a Pi or Compute Module there are several files in the first FAT partition of the SD/eMMC that are binary 'Device Tree' files. These binary files (usually with extension .dtb) are compiled from human readable text descriptions (usually files with extension .dts) by the Device Tree compiler.

在樹莓派或者是系統上有幾個文件在SD卡或者emmc上的第一個fat分區中,這些文件就是編譯好的二進制設備樹文件。這些二進制文件(dtb文件)是通過設備樹編譯器從dts文件編譯而來

On a standard Raspbian image in the first (FAT) partition you will find two different types of device tree files, one is used by the GPU only and the rest are standard ARM device tree files for each of the BCM283x based Pi products:

在一個標準的raspbian鏡像的第一個FAT分區可以看見兩種不同類型的設備樹文件,一種是隻被GPU使用,剩餘的就是標準的arm設備樹文件。

 

dt-blob.bin (used by the GPU)

bcm2708-rpi-b.dtb (Used for Pi model A and B)

bcm2708-rpi-b-plus.dtb (Used for Pi model B+ and A+)

bcm2709-rpi-2-b.dtb (Used for Pi 2 model B)

bcm2710-rpi-3-b.dtb (Used for Pi 3 model B)

bcm2708-rpi-cm.dtb (Used for Pi Compute Module)

bcm2710-rpi-cm3.dtb (Used for Pi Compute Module 3)

 

NOTE dt-blob.bin by default does not exist as there is a 'default' version compiled into start.elf, but for Compute Module projects it will often be necessary to provide a dt-blob.bin (which overrides the default built-in file).

注意:由於有一個默認的是將dt-blob.bin文件編譯到start.elf文件中,所以dt-blob.bin文件默認是不存在fat分區中的。但是對於CM工程來說常常需要提供一個dt-blob.bin文件(這個文件覆蓋默認的內置文件)

 

Note that dt-blob.bin is in compiled device tree format, but is only read by the GPU firmware to set up functions exclusive to the GPU - see below.

值得注意的是dt-blob.bin文件被編譯成設備樹文件格式,但是它只能被GPU固件讀取用作設置GPU的一些功能。

 

During boot, the user can specify a specific ARM device tree to use via the device_tree parameter in config.txt, for example adding the line device_tree=mydt.dtb to config.txt where mydt.dtb is the dtb file to load instead of one of the standard ARM dtb files. While a user can create a full device tree for their Compute Module product, the recommended way to add hardware is to use overlays (see next section).

 

在啓動期間,通過在config.txt文件中的device_tree參數,用戶能夠制定一個特殊的ARM設備樹文件。例如,增加一行device_tree=mydt.dtb到config.txt中(這個mydt.dtb是一個dtb文件,這個文件用於加載代替標準的arm dtb文件)。雖然用戶可以通過創建一個完整的設備樹文件爲CM產品,但是仍然推薦在overlays目錄下增加硬件的方式。

 

In addition to loading an ARM dtb, start.elf supports loading additional Device Tree 'overlays' via the dtoverlay parameter in config.txt, for example adding as many dtoverlay=myoverlay lines as required as overlays to config.txt, noting that overlays live in /overlays and are suffixed -overlay.dtb e.g. /overlays/myoverlay-overlay.dtb. Overlays are merged with the base dtb file before the data is passed to the Linux kernel when it starts.

除了添加arm dtb文件之外,start.elf文件支持加載附加的設備樹'overlays'通過config.txt中的參數dtoverlay。例如,根據需要在文件中添加了儘可能多的dtoverlay=myoverlay命令行,這裏的overlays位於/boot/overlays/中並且是dtb的後綴,如: /overlays/myoverlay-overlay.dtb.譯者注:我這裏在這個路勁下看到的都是dtbo的文件,具體區別還不是很清楚)。overlays的文件將會和這個基本的dtb文件合併,在這個基本的dtb啓動時將數據傳遞給Linux內核之前

 

Overlays are used to add data to the base dtb that (nominally) describes non board-specific hardware. This includes GPIO pins used and their function, as well as the device(s) attached, so that the correct drivers can be loaded. The convention is that on a Raspberry Pi, all hardware attached to the Bank0 GPIOs (the GPIO header) should be described using an overlay. On a Compute Module all hardware attached to the Bank0 and Bank1 GPIOs should be described in an overlay file. You don't have to follow these conventions: you can roll all the information into one single dtb file, as previously described, replacing bcm2708-rpi-cm.dtb. However, following the conventions means that you can use a 'standard' Raspbian release, with its standard base dtb and all the product-specific information contained in a separate overlay. Occasionally the base dtb might change - usually in a way that will not break overlays - which is why using an overlay is suggested.

Overlays是增加數據到基本的dtb文件中用於描述非板級硬件。這些包括使用到的gpio引腳和他們的功能,以及附加在上面的設備,因此合適的驅動將被加載。在樹莓派上約定,所有依附在Bank0 GPIO的硬件應該使用一個overlay描述。在CM板子上所有依附在Bank0Bank1 GPIOs硬件應該在overlay文件中被描述。你不必必須遵循如下約定:將所有的信息加入一個單獨的dtb文件,就像前面描述的那樣,替換bcm2708-rpi-cm.dtb然而,遵循下面的約定意味着你能用一個標準的raspbian發行版,標準的發行版帶有標準的dtb文件和所有特定產品信息,這些都被包含在一個分離的overlay中。偶爾這個基本的dtb文件可能會被通常以一種不會打破覆蓋的方式修改,這就是爲什麼建議使用overlay

 

dt-blob.bin

When start.elf runs, it first reads something called dt-blob.bin. This is a special form of Device Tree blob which tells the GPU how to (initially) set up the GPIO pin states, and also any information about GPIOs/peripherals that are controlled (owned) by the GPU, rather than being used via Linux on the ARM. For example, the Raspberry Pi Camera peripheral is managed by the GPU, and the GPU needs exclusive access to an I2C interface to talk to it, as well as a couple of control pins. I2C0 on most Pi Boards and Compute Modules is nominally reserved for exclusive GPU use. The information on which GPIO pins the GPU should use for I2C0, and to control the camera functions, comes from dt-blob.bin.

 

start.elf文件啓動的時候,首先會讀取dt-blob.bin的文件。這是一種特殊的設備數二進制文件格式,用於告訴GPU如何初始化gpio的引腳狀態,以及關於被GPU控制的gpio和外設的任何信息,而不是通過arm上的Linux。例如,樹莓派的攝像頭外設是被GPU管理的,GPU需要單獨的訪問一個i2c的一對控制引腳和攝像頭通訊。i2c0在名義上在大多數樹莓派板子和CM板是GPU獨佔的。這些來自文件dt-blob.bin的信息確定了哪些gpio引腳是被GPU用來控制攝像頭i2c0

 

NOTE: the start.elf firmware has a 'built-in' default dt-blob.bin which is used if no dt-blob.bin is found on the root of the first FAT partition. Most Compute Module projects will want to provide their own custom dt-blob.bin. Note that dt-blob.bin specifies which pin is for HDMI hot plug detect, although this should never change on Compute Module. It can also be used to set up a GPIO as a GPCLK output, and specify an ACT LED that the GPU can use while booting. Other functions may be added in future. For information on dt-blob.bin see here.

 

如果start.elf文件在第一分區FAT中沒有找到dt-blob.bin文件,那麼就會使用內置默認的dt-blob.bin文件。大多數的CM工程中將會提供他們自己的dt-blob.bin。值得注意的是這個dt-blob.bin說明哪個引腳是HDMI熱插拔探測引腳,雖然這些不會再CM板子上被改變。這個文件也能夠被用來設置一個GPIO用作GPCLK輸出的GPIO。指定一個GPU能夠在啓動的時候使用的ACT LED。其他的功能將在今後添加。

 

dt-blob.bin文件的編譯:

dtc -I dts -O dtb -o dt-blob.bin minimal-cm-dt-blob.dts

其中minimal-cm-dt-blob.dts來自於:

https://www.raspberrypi.org/documentation/hardware/computemodule/cm-peri-sw-guide.md

 

After start.elf has read dt-blob.bin and set up the initial pin states and clocks, it reads config.txt

start.elf讀完dt-blob.bin文件和設置初始化引腳的狀態和時鐘之後,他將讀取config.txt文件的內容。

After reading config.txt another device tree file specific to the board the hardware is running on is read: this is bcm2708-rpi-cm.dtb for a Compute Module, or bcm2710-rpi-cm.dtb for CM3. This file is a standard ARM Linux device tree file, which details how hardware is attached to the processor: what peripheral devices exist in the SoC and where, which GPIOs are used, what functions those GPIOs have, and what physical devices are connected. This file will set up the GPIOs appropriately, overwriting the pin state set up in dt-blob.bin if it is different. It will also try to load driver(s) for the specific device(s).

 

讀取config.txt文件之後,讀取另外一個針對於本次運行的硬件板子的設備樹文件。如果是CM板,這個文件就是 bcm2708-rpi-cm.dtb,如果是CM3,這個文件就是bcm2710-rpi-cm.dtb。這個文件是標準的armLinux設備樹文件,並詳細描述了硬件是如何依附在處理器上的:有哪些外設設備存在,用到了哪些GPIO,以及這些gpio具有哪些功能,鏈接的物理設備。這個文件將恰當合適的設置gpio,如果這些引腳狀態和dt-blob.bin設置的不一樣,那麼就覆蓋之前dt-blob.bingpio設置。這個文件也會嘗試從指定的設備加載驅動。

 

Although the bcm2708-rpi-cm.dtb file can be used to load all attached devices, the recommendation for Compute Module users is to leave this file alone. Instead, use the one supplied in the standard Raspbian software image, and add devices using a custom 'overlay' file as previously described. The bcm2708-rpi-cm.dtbfile contains (disabled) entries for the various peripherals (I2C, SPI, I2S etc.) and no GPIO pin definitions, apart from the eMMC/SD Card peripheral which has GPIO defs and is enabled, because it is always on the same pins. The idea is that the separate overlay file will enable the required interfaces, describe the pins used, and also describe the required drivers. The start.elf firmware will read and merge the bcm2708-rpi-cm.dtb with the overlay data before giving the merged device tree to the Linux kernel as it boots up.

儘管 bcm2708-rpi-cm.dtb文件能夠用於加載所有的附加設備,仍然建議CM用戶不要使用這個文件。相反,使用標準raspbian鏡像中提供的那個文件,如前面描述,使用自定義的overlay文件添加設備。文件bcm2708-rpi-cm.dtb包含各種外設條目(I2C, SPI, I2S等)沒有gpio的引腳的定義和沒有使能,除了emmc或者SD卡外設,這兩個外設由於使用的是同樣的引腳,所以gpio都有被定義及使能。單獨的overlay文件將會使能所需要的接口,描述引腳和所需要的驅動。固件start.elf文件將讀取合入bcm2708-rpi-cm.dtb的overlay數據,然後再Linux內核啓動時將合併後的設備樹文件交給Linux內核。

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章