树莓派系统(BCM283x)的启动过程

28 篇文章 2 订阅
21 篇文章 0 订阅

本文主要介绍了树莓派主控芯片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内核。

 

 

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值