載板主撐軟體包(bootloader部分)

來源:互聯網
上載者:User
載板主撐軟體包(bootloader部分)
譯自:《Embedded Linux System Design and Development

》by P. Raghavan等

劉建文略譯(http://blog.csdn.net/keminlau

KEY:BSP HAL 嵌入式 Linux

載板主撐軟體包(Board Support Package)

A BSP or “Board Support Package” is the set of software used to initialize the hardware devices on the board and implement the board-specific routines that can be used by the kernel and device drivers alike.

BSP is thus a hardware abstraction layer gluing hardware to the OS by hiding the details of the processor and the board. The BSP hides the board- and CPU-specific details from the rest of the OS, so portability of drivers across multiple boards and CPUs becomes extremely easy. Another term that is often used instead of BSP is the Hardware Abstraction Layer or the HAL.

載板主撐軟體包(Board Support
Package)是指一集負責初始化硬體載板上的裝置和封裝硬體相關細節為作業系統提供高層介面的程式。有了BSP,作業系統(包括硬體驅動)有一定的獨
立性,從而在不同的硬體平台間移植變得更容易。BSP與常見HAL有類似的功能和角色,但不是完全一樣。

 

KEMIN:應該把BSP嚴格分為兩部分,一部分只涉及硬體的初始化,另一部分是硬體底層功能的封裝。為什麼要這樣,因為,前者只與移植任務相關,與作業系統開發(驅動開發)無關,而後者除了有與移植有關的任務,更多是在構建一個[系統級應用開發架構

],這個架構其實是一組抽象介面,作業系統開發人員瞭解組抽象介面的抽象語義即可作來,但對這些介面
的實現原理有更深入的理解,則更有開發效率。(original:http://blog.csdn.net/keminlau/archive/2009/12/20/5045121.aspx)

BSP兩個主要部分

1. The microprocessor support: Linux has wide support for all the leading processors in the embedded market such as MIPS, ARM, and soon the PowerPC.

2. The board-specific routines: A typical HAL for the board hardware will include:

  • a. Bootloader support
  • b. Memory map support
  • c. System timers
  • d. Interrupt controller support
  • e. Real-Time Clock (RTC)
  • f. Serial support (debug and console)
  • g. Bus support (PCI/ISA)
  • h. DMA support
  • i. Power management
HAL與BSP

For making the terminology clean, we refer to the HAL as the layer that combines the board- and the processor-specific software and the BSP as the layer that has only the board-specific code. So when we talk about the MIPS HAL it means the support for the MIPS processors and the boards built with MIPS processors. When we talk about a BSP we refer to the software that does not have the processor support software but just the additional software for supporting the board. The HAL can be understood as a superset of all supported BSPs and it additionally includes the processor-specific software.

HAL與BSP的一些定義的差別,前者涵蓋了載板(Board )與處理器(processors)的抽象,後者特指載板的主撐軟體部分。

BSP(抽象介面)沒有標準

As mentioned in Chapter 2, neither the Linux HAL nor the BSP has any standard. Hence it is very difficult to explain the HAL for multiple architectures.

載板的組件(以EUREKA 為例)

This chapter delves into the Linux BSP and porting issues for a MIPS-based architecture; For making things easier, we use a fictitious board EUREKA that is MIPS-based having the following set of hardware components.

  • A 32-bit MIPS processor
  • 8 MB of SDRAM
  • 4 MB of flash
  • A 8259-based programmable interrupt controller
  • A PCI bus with some devices such as Ethernet and a sound card connected to it
  • A timer chip for generating the system heartbeat
  • A serial port that can be used for console and remote debugging
為核心構建流程加入BSP部分

3.1 Inserting BSP in Kernel Build Procedure

BSP在源碼樹的位置及相應的功能

The Linux HAL source code resides under arch/ and include/<asm-XXX>(XXX = processor name such as PowerPC, MIPS) directories. Thus arch/ppc will contain the source files for the PPC-based board and include/asm-ppc will contain the header files.

Under each processor directory, all boards based on that CPU are categorized again into subdirectories. The important directories under each subdirectory are:

  • * kernel: This directory contains the CPU-specific routines for initializing, IRQ set-up, interrupts, and traps routines.
  • * mm: Contains the hardware-specific TLB set-up and exception-handling code.

For example, MIPS HAL has the two subdirectories arch/mips/kernel and arch/mips/mm that hold the above code. Along with these two directories there is a host of other subdirectories; these are the BSP directories that hold the board-specific code only. The user needs to create a subdirectory tree under the appropriate processor directory that contains the files necessary for the BSP.

整合BSP到[核心構建系統]是為了方便進行組件選擇(kernel component selection),也就是核心配置。

3.2 The Boot Loader Interface

Most of the reset initialization is board-specific and normally manufacturers of boards give an onboard PROM that does the above. It is better to make use of the PROM to load either a kernel image or an intermittent boot loader and thus save the developers from the job of programming the board. Even if a PROM is not available, it is better to separate the boot process to a boot loader than let the kernel bootstrap itself. The following are the advantages with this approach.

系統引導是一個複雜的過程,並且引導程式(Boot Loader)是一支與硬體高度相關的程式。Boot Loader的表現形式多樣,根據硬體設定還可選(去掉或由核心內建引導代碼)。硬體廠商一般會隨載板內建一支PROM程式實現系統引(或部分實現),這樣開發人員可免除開發引導程式的需要,直接利用PROM提供的功能介面。

為什麼需要Boot Loader?

A computer's central processor can only execute program code found in Read-Only Memory (ROM) and Random Access Memory (RAM). Modern operating systems and application program code and data are stored on nonvolatile data storage devices, such as hard disk drives, When a computer is first powered on, it does not have an operating system in ROM or RAM. The computer must initially execute a small program stored in ROM along with the bare minimum of data needed to access the nonvolatile devices from which the operating system programs and data are loaded into RAM.

 

不管引導程式的表現形式如何,將系統引導過程獨立於作業系統有以下一些優點:

Other than ROM downloads, multiple methods of downloading the kernel such as serial (Kermit) or network (TFTP) can be implemented.

It provides protection against unsafe overwrites of the kernel image in case the kernel image is stored in flash. Assume that there was a power outage when a kernel image is upgraded; then the board is in limbo. The safer way is to burn a boot loader into some protected sectors of flash (normally called boot sectors) and leave them untouched so that there is a recovery route always available.

第一,多種核心下載(載入到RAM)策略;核心可以通過串口或網路下載;

第二,如果核心與引導程式連體,核心的更新不慎容易報廢硬體載板,而核心開發,比如驅動開發,更新是相當頻繁的。再者,引導程式與是核心是不性質的程式,分隔很合理自然。

As a thumb rule Linux always assumes that it is executing from memory (some allow Linux to execute from ROM directly; ). Boot loaders are independent pieces of software that need to be built independently of the Linux kernel. Unless your board supports a PROM, the boot loader does the initialization of the processor and the board. Hence the boot loader is highly board- and processor-specific.

Linux 是現代的作業系統,它假定自己是運行在主存RAM的,使用虛擬位址等(一般不能直接在ROM運行)。而Boot loaders一般是很小,並且與硬體高度相關,所以可直接在ROM中運行。Boot loaders的功能可分為必選和可選兩部分,可選部分滿足客戶需求的定製,必選功能有兩個:

第一,硬體的初始化,包括處理器、一些重要的控制器(比如主存控制器)和一些必需的外設(比如存放核心的快閃記憶體flash);

第二,載入核心;

The boot loader functionalities can be divided into two: the mandatory ones and the optional ones. The optional boot loader functionalities are varied and depend on the customer usage. The mandatory boot loader functionalities are:

1. Initializing the hardware: This includes the processor, the essential controllers such as the memory controller, and the hardware devices necessary for loading the kernel such as flash.

2. Loading the kernel: The necessary software to download the kernel and copy it to the appropriate memory location.

以下是引導過程的一般性步驟(generic steps),非X86平台的:

these are generic steps and there can be exceptions depending on the usage.

Note that the X86 processors normally are shipped with an onboard BIOS that helps with the basic power-on and loading a secondary boot loader for loading the operating system; hence the following set of steps is meant for the non-X86 processors such as MIPS and ARM.

1. Booting: Most boot loaders start from the flash. They do the initial processor initialization such as configuring the cache, setting up some basic registers, and verifying the onboard RAM. Also they run the POST routines to do validation of the hardware required for the boot procedure such as validating memory, flash, buses, and so on.

2. Relocation: The boot loaders relocate themselves to the RAM. This is because RAM is faster than flash. Also the relocation step may include decompression as the boot loaders can be kept in a compressed format to save costly storage space.

3. Device initialization: Next the boot loader initializes the basic devices necessary for user interaction. This usually means setting up a console so that a UI is thrown for the user. It also initializes the devices necessary for picking up the kernel (and maybe the root file system). This may include the flash, network card, USB, and so on.

4. UI: Next the UI is thrown for the user to select the kernel image she wishes to download onto the target. There can be a deadline set for the user to enter her choice; in case of a timeout a default image can be downloaded.

5. Image download: The kernel image is downloaded. In case the user has been given the choice to download a root file system using the initrd mechanism, the initrd image too gets downloaded to memory.

為嵌入式系統選擇boot loaders及選擇標準(criteria)

There are many freely available boot loaders for Linux; the system architect can evaluate the existing ones before deciding to write a new boot loader from scratch. What are the criteria in choosing a boot loader for a given embedded platform?

  • * Support for the embedded hardware
  • * Licensing issues: These are discussed in detail in Appendix B.
  • * Storage footprint
  • * Support for network booting
  • * Support for flash booting
  • * Console UI availability
  • * Upgrade solutions availability
boot loader到核心的介面

One other important area of discussion surrounding the boot loaders is the boot loader-to-kernel interface, which comprises the following components.

Argument passing from the boot loader to Linux kernel:

The list of Linux kernel boot time arguments can be verified after the system is fully up by reading the proc file /proc/cmdline.

  • * – Passing boot command arguments:
  • * – Parsing of boot command arguments:

Some important boot parameters are:

  • * – root:
  • * – nfsroot:
  • * – mem:
  • * – debug:

Memory Map:

On many platforms, especially the Intel and PowerPC, boot loaders set up a memory map that can be picked up by the OS. This makes it easy to port the OS across multiple platforms.

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.