九鼎创展论坛中文版English
登录 | 立即注册 设为首页收藏本站 切换到宽版
查看: 3847|回复: 3

裸机程序启动流程问题

[复制链接]
发表于 2014-9-19 18:55:17 | 显示全部楼层 |阅读模式
本帖最后由 laotang365 于 2014-9-19 18:57 编辑

以下是裸机程序中start.s的部分代码
  1. /* init system clock */
  2.         bl        system_clock_init

  3.         /* initialize memory controller */
  4.         bl        mem_ctrl_init

  5.         /* initialize nand flash controller */
  6.         bl        nand_init

  7.         /* setting trustzone protection controller */
  8.         bl        tzpc_init

  9.         /* wakeup or not */
  10.         ldr        r0, =(0xe0100000 + 0xa000)
  11.         ldr        r1, [r0]
  12.         bic        r1, r1, #0xfff6ffff
  13.         cmp        r1, #0x10000
  14.         beq        wakeup_reset
  15.         cmp        r1, #0x80000
  16.         beq        wakeup_reset

  17.         /* copyself to ram using irom */
  18.         adr        r0, _start
  19.         ldr r1, =_start
  20.         cmp        r0, r1
  21.         beq        have_copyed
  22.         bl        irom_copyself
复制代码
代码中的启动流程是先进行system_clock_init mem_ctrl_init nand_init tzpc_init,最后才开始进入判断程序决定是否自拷贝,但是start.s不是首先在iram中执行过一次了吗,自拷贝到0x34000000后,从0x34000010再重新运行一次,那么system_clock_init mem_ctrl_init nand_init tzpc_init重复再次运行????
此时代码已经在DDR中运行,mem_ctrl_init 再次初始化不会导致DDR复位吗?对程序运行没影响吗?
不过mem_ctrl_init 又必须在iram中先运行一次,初始化DDR,不然无法拷贝代码到DDR中,不太明白,DDR重新初始化不会影响代码运行?
另外,从nand_flash中启动时Uboot应该也必须进行DDR初始化然后自拷贝吧,这样我dnw将裸机程序下载到DDR中,用go命令为什么不能运行呢?
回复

使用道具 举报

发表于 2014-11-25 14:25:26 | 显示全部楼层
其实在启动时是不会运行两次的,这里有篇文件,你参考下http://blog.csdn.net/obobodog/article/details/38582285
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-11-25 17:47:08 | 显示全部楼层
本帖最后由 laotang365 于 2014-11-25 18:19 编辑

非常感谢,分析了一下源码,终于明白了,其实一开始程序的链接地址就指定在0x34000000了,只不过BL1部分的代码都是位置无关码,BL1最后运行的代码是 ldr    r1,=on_the_ram,这是绝对地址跳转,直接跳到DDR中的on_the_ram代码,on_the_ram中就执行bl    main了,所以在iram中完成自拷贝之后,start.s并没有重复运行:        ldr        r0, _bss_start
        ldr        r1, _bss_end
        mov r2, #0x00000000
        bl        mem_clear

        /* jump to ram */
        ldr        r1, =on_the_ram
        mov        pc, r1
on_the_ram:
        /* jump to main fuction */
        mov r0, #1;
        mov r1, #0;
        bl        main                        /* call main function */
        b        on_the_ram
回复 支持 反对

使用道具 举报

发表于 2014-11-25 19:52:44 | 显示全部楼层
laotang365 发表于 2014-11-25 17:47
非常感谢,分析了一下源码,终于明白了,其实一开始程序的链接地址就指定在0x34000000了,只不过BL1部分的 ...

正解,关键点跳转前的所有代码都是的位置无关的
回复 支持 反对

使用道具 举报

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

本版积分规则

QQ|手机版|小黑屋|深圳市九鼎创展科技官方论坛 ( 粤ICP备11028681号-2  

GMT+8, 2024-3-29 14:20 , Processed in 0.023203 second(s), 17 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表