载板主撑软件包(bootloader部分)
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.youkuaiyun.com/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.