【OK210试用体验】u-boot篇 -- SPL移植 - 在线问答 - 电子技术论坛 - 最好最受欢迎电子论坛!

【OK210试用体验】u-boot篇 -- SPL移植

本帖最后由 q15920078530 于 2015-8-28 20:25 编辑

【OK210试用体验】u-boot篇 -- SPL移植

    在S5PV210的启动流程中可以知道,iROM运行后会先后拷贝BL1和BL2到内存中运行。BL1阶段除了完成基本的硬件初始化,还完成了BL2拷贝到内存中运行的重要任务。在u-boot中,其提供了SPL架构,来更好地完成BL2的加载。
    SPL,secondary program loader,中文翻译为 第二阶段编程加载器。在u-boot**/doc目录下,有README.SPL专门说明SPL。
    重点文件及函数:start.S、lowlevel_init、board_init_f、board_init_r、_main

移植准备

    要移植SPL,首先要先分析一下u-boot的走向。在逻辑程序编写部分上,我们总是习惯用start.S来作为起始部分代码,u-boot其实也不例外。S5PV210的可以在**/arch/arm/cpu/armv7 找到 start.S。代码的内存安排可以看链接脚本:**/arch/arm/cpu/u-boot.lds 和 **/arch/arm/cpu/u-boot-spl.lds 。不管是u-boot-spl.lds还是u-boot.lds ,起始入口都是ENTRY(_start)。所以要分析详细思路,还是从 start.S开始。
   
    根据提示可以更方便地看懂汇编代码,没有仔细学过ARM汇编的可以参考《GNU assembly》和ARM汇编指令详解等资料。有了提示就很方便,不看代码看注释也可快速浏览知道代码做了哪些事。
      在cpu_init_crit中调用了 lowlevel_init,lowlevel_init位于 **/board/samsung/smdkv210/lowlevel_init.S,其进行了系统时钟、串口、内存等的底层初始化。
      判断完CONFIG_SKIP_LOWLEVEL_INIT是否定义,执行相关命令后跳转到 _main,_main位于**/arch/arm/lib/crt0.S。crt0是 C Run-time。
      在crt0.S中有列出_main函数的工作流程:
  1. * 1. Set up initial environment for calling board_init_f().
  2. *    This environment only provides a stack and a place to store
  3. *    the GD ('global data') structure, both located in some readily
  4. *    available RAM (SRAM, locked cache...). In this context, VARIABLE
  5. *    global data, initialized or not (BSS), are UNAVAILABLE; only
  6. *    CONSTANT initialized data are available.
  7. *
  8. * 2. Call board_init_f(). This function prepares the hardware for
  9. *    execution from system RAM (DRAM, DDR...) As system RAM may not
  10. *    be available yet, , board_init_f() must use the current GD to
  11. *    store any data which must be passed on to later stages. These
  12. *    data include the relocation destination, the future stack, and
  13. *    the future GD location.
  14. *
  15. * (the following applies only to non-SPL builds)
  16. *
  17. * 3. Set up intermediate environment where the stack and GD are the
  18. *    ones allocated by board_init_f() in system RAM, but BSS and
  19. *    initialized non-const data are still not available.
  20. *
  21. * 4. Call relocate_code(). This function relocates U-Boot from its
  22. *    current location into the relocation destination computed by
  23. *    board_init_f().
  24. *
  25. * 5. Set up final environment for calling board_init_r(). This
  26. *    environment has BSS (initialized to 0), initialized non-const
  27. *    data (initialized to their intended value), and stack in system
  28. *    RAM. GD has retained values set by board_init_f(). Some CPUs
  29. *    have some work left to do at this point regarding memory, so
  30. *    call c_runtime_cpu_setup.
  31. *
  32. * 6. Branch to board_init_r().
复制代码

    其中board_init_f()位于arch/arm/lib/board.c,此函数进行了硬件初始化,并为进入DRAM运行代码做准备。
    其中代码还会调用main_loop函数,位于**/common/main.c。
    代码都有详细说明,就不用多说了哈。

0个回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则


关闭

站长推荐上一条 /6 下一条

小黑屋|手机版|Archiver|电子发烧友 ( 湘ICP备2023018690号 )

GMT+8, 2024-4-24 15:23 , Processed in 0.758997 second(s), Total 68, Slave 48 queries .

Powered by 电子发烧友网

© 2015 bbs.elecfans.com

微信扫描
快速回复 返回顶部 返回列表