zoukankan      html  css  js  c++  java
  • U-boot中SPL功能和源码流程分析

      在U-boot目录下,有个比较重要的目录就是SPL的,SPL到底是什么呢?为什么要用它呢?

      SPL(Secondary programloader)是uboot第一阶段执行的代码。主要负责搬移uboot第二阶段的代码到

    系统内存(System Ram,也叫片外内存)中运行。SPL是由固化在芯片内部的ROM引导的。我们知道很多芯

    片厂商固化的ROM支持从nandflash、SDCARD等外部介质启动。所谓启动,就是从这些外部介质中搬移一段

    固定大小(4K/8K/16K等)的代码到内部RAM中运行。这里搬移的就是SPL。在最新版本的uboot中,可以看到

    SPL也支持nandflash,SDCARD等多种启动方式。当SPL本身被搬移到内部RAM中运行时,它会从nandflash、

    SDCARD等外部介质中搬移uboot第二阶段的代码到系统内存中。

      SPL复用的是uboot里面的代码.

      SPL的主要功能就是衔接系统的硬件SRAM和u-boot之间的纽带。

    1.BasicArm Initialization
    2.UART console initialization
    3.Clocks and DPLL Locking(minimal)
    4.SDRAM initialization
    5.Mux(minimal)
    6.Boot Device Initialization, based on where we are booting from MMC1, or MMC2,or Nand, or Onenand
    7.Bootloading real u-boot from the Boot Device and passing control to it.

      怎么编译SPL呢?

      上文中说道“SPL复用的是uboot里面的代码”,那要生成我们所需要的SPL目标文件,我们又该如何下手呢?

    很容易想到,通过编译选项便可以将SPL和uboot代码分离、复用。这里所说的编译选项便是CONFIG_SPL_BUILD,

    在make Kconfig的时候使能。最终编译生成的SPL二进制文件有u-boot-spl,u-boot-spl.bin以及u-boot-spl.map。

      源码流程

      从ARM的启动流程上来看,可以看出SPL在哪一层的:

    RomBoot --> SPL --> u-boot --> Linux kernel --> file system --> start application

    (RomBoot是固化在SoC内部的。)

    容易想到,通过编译选项便可以将SPL和uboot代码分离、复用。这里所说的编译选项便是CONFIG_SPL_BUILD,

    在make Kconfig的时候使能。最终编译生成的SPL二进制文件有u-boot-spl,u-boot-spl.bin以及u-boot-spl.map。

      SPL的启动一般要从链接文件看,链接文件决定一个可执行程序的各个段的存储(加载)地址,以及运行(链接)地址。

    下面来看看SPL的链接文件U-boot-spl.lds:

      4 OUTPUT_ARCH(arm)
      5 ENTRY(_start)
      6 SECTIONS
      7 {
      8  .text :
      9  {
     10   __start = .;
     11   *(.vectors)
     12   arch/arm/cpu/armv7/start.o (.text*)
     13   *(.text*)
     14  } >.sram

      从lds的起始地址来看,这里面主要撒地方做了两件事情,一个是

    *(.vectors)是调用中断向量表:arch/arm/lib/vectors.S 另外

    一个就是运行启动代码:

    arch/arm/cpu/armv7/start.o (.text*)

      在启动代码start.S中,代码的流程是什么样的呢?

      (reset) <arch/arm/cpu/armv7/start.S > (b lowlevel_init: arch/arm/cpu/armv7/lowlevel_init.S)
     (b _main) --> <arch/arm/lib/crt0.S> (bl board_init_f) --> <arch/arm/lib/spl.c> (board_init_r)
    --> <common/spl/spl.c> (jump_to_image_no_args去启动u-boot)
    到此SPL的生命周期结束。
     到此SPL的分析流程结束了,这里只做个粗略的分析,后面再针对每个部分做详细的介绍。

    参考文档:
    1 http://blog.csdn.net/voice_shen/article/details/17373671
    2 http://bbs.chinaunix.net/thread-4248378-1-1.html

  • 相关阅读:
    Java对象初始化
    some tool collections
    链接、单选按钮虚线框与focus:this.blur()与outline
    火狐拓展开发 基础知识
    Multidimensional Array And an Array of Arrays
    Byte Array to Hexadecimal String
    Comparer<T> IComparer<T> IComparable<T>
    Little Puzzlers–List All Anagrams in a Word
    JavaScript-Curry
    OOP in JS Public/Private Variables and Methods
  • 原文地址:https://www.cnblogs.com/dylancao/p/8621789.html
Copyright © 2011-2022 走看看