• uboot-重定位中断向量表 relocate_vectors 函数


     一.  uboot启动流程

    _main 函数中,调用完 relocate_code 函数,即执行了uboot重定位后,开始执行relocate_vectors 函数。

    本文学习 relocate_vectors 函数,uboot的重定位中断向量表。

    二.  重定位中断向量表

    _main 函数在 uboot的  /arch/arm/lib/crt0.S 文件中。如下:

    1. b relocate_code
    2. here:
    3. /*
    4. * now relocate vectors
    5. */
    6. bl relocate_vectors

    函数 relocate_vectors 用于重定位向量表,此函数定义在文件 relocate.S 中。

    代码如下:

    1. 27 ENTRY(relocate_vectors)
    2. 28
    3. 29 #ifdef CONFIG_CPU_V7M
    4. 30 /*
    5. 31 * On ARMv7-M we only have to write the new vector address
    6. 32 * to VTOR register.
    7. 33 */
    8. 34 ldr r0, [r9, #GD_RELOCADDR] /* r0 = gd->relocaddr */
    9. 35 ldr r1, =V7M_SCB_BASE
    10. 36 str r0, [r1, V7M_SCB_VTOR]
    11. 37 #else
    12. 38 #ifdef CONFIG_HAS_VBAR
    13. 39 /*
    14. 40 * If the ARM processor has the security extensions,
    15. 41 * use VBAR to relocate the exception vectors.
    16. 42 */
    17. 43 ldr r0, [r9, #GD_RELOCADDR] /* r0 = gd->relocaddr */
    18. 44 mcr p15, 0, r0, c12, c0, 0 /* Set VBAR */
    19. 45 #else
    20. 46 /*
    21. 47 * Copy the relocated exception vectors to the
    22. 48 * correct address
    23. 49 * CP15 c1 V bit gives us the location of the vectors:
    24. 50 * 0x00000000 or 0xFFFF0000.
    25. 51 */
    26. 52 ldr r0, [r9, #GD_RELOCADDR] /* r0 = gd->relocaddr */
    27. 53 mrc p15, 0, r2, c1, c0, 0 /* V bit (bit[13]) in CP15 c1 */
    28. 54 ands r2, r2, #(1 << 13)
    29. 55 ldreq r1, =0x00000000 /* If V=0 */
    30. 56 ldrne r1, =0xFFFF0000 /* If V=1 */
    31. 57 ldmia r0!, {r2-r8,r10}
    32. 58 stmia r1!, {r2-r8,r10}
    33. 59 ldmia r0!, {r2-r8,r10}
    34. 60 stmia r1!, {r2-r8,r10}
    35. 61 #endif
    36. 62 #endif
    37. 63 bx lr
    38. 64
    39. 65 ENDPROC(relocate_vectors)

    29 行,如果定义了 CONFIG_CPU_V7M 的话就执行第 30~36 行的代码,这是 Cortex-M内核单片机执行的语句,因此对于 I.MX6ULL 来说是无效的。
    38 行,如果定义了 CONFIG_HAS_VBAR 的话就执行此语句,这个是向量表偏移, Cortex- A7 是支持向量表偏移的。而且,在 .config 里面定义了 CONFIG_HAS_VBAR ,因此会执行这个
    分支。
    43 行, r0=gd->relocaddr ,也就是重定位后 uboot 的首地址,向量表肯定是从这个地址开 始存放的。
    44 行,将 r0 的值写入到 CP15 VBAR 寄存器中,也就是将新的向量表首地址写入到 寄存器 VBAR 中,设置向量表偏移。

    总结:

    relocate_vectors 函数可以看出,对于 IMX6ULL芯片而言,因为属于 Cortex-A7架构,所以,这个函数中只执行了两行:

    1. #ifdef CONFIG_HAS_VBAR
    2. 39 /*
    3. 40 * If the ARM processor has the security extensions,
    4. 41 * use VBAR to relocate the exception vectors.
    5. 42 */
    6. 43 ldr r0, [r9, #GD_RELOCADDR] /* r0 = gd->relocaddr */
    7. 44 mcr p15, 0, r0, c12, c0, 0 /* Set VBAR */

    relocate_vectors 函数主要做的事:设置 VBAR寄存器为重定位后的中断向量表起始地址。

  • 相关阅读:
    动态规划01 背包问题(算法)
    Jan 2023-Prioritizing Samples in Reinforcement Learning with Reducible Loss
    Creaform形创HandySCAN MAX三维扫描仪大型零部件尺寸测量设备
    python pandas query用法
    手机提词器有哪些?简单介绍这一款
    基于open CV实现YOLOv3复现_预测阶段和后处理阶段
    八家知名大厂联合手写的Java面试手册刚上线,竟就到达巅峰?
    力扣(LeetCode)177. 第N高的薪水(2022.06.26)
    一键开启云原生网络安全新视界
    mysql之MHA的高可用
  • 原文地址:https://blog.csdn.net/wojiaxiaohuang2014/article/details/133692303