Chinaunix首页 | 论坛 | 博客

OS

  • 博客访问: 2229269
  • 博文数量: 691
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 2660
  • 用 户 组: 普通用户
  • 注册时间: 2014-04-05 12:49
个人简介

不浮躁

文章分类

全部博文(691)

文章存档

2019年(1)

2017年(12)

2016年(99)

2015年(207)

2014年(372)

分类: 嵌入式

2015-12-08 21:39:59

cpu/arm_cortexa9/u-boot.lds
u-boot程序的入口地址问题
    要理解程序的入口地址,自然想到的是连接文件,首先看看开发板相对于某个开发板的连接文件"/cpu/arm_cortexa9/u-boot.lds",看一个例子:
/*
 * January 2004 - Changed to support H4 device
 * Copyright (c) 2004-2008 Texas Instruments
 *
 * (C) Copyright 2002
 * Gary Jennejohn, DENX Software Engineering,
 *
 * See file CREDITS for list of people who contributed to this
 * project.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA 02111-1307 USA
 */

OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm") //指定输出可执行文件是elf 格式,32 位ARM 指令,小端
OUTPUT_ARCH(arm)  //指定输出可执行文件的平台为ARM
ENTRY(_start)           //指定输出可执行文件的起始代码段为_start.
SECTIONS
{
 . = 0x00000000;    //从0x0 位置开始

 . = ALIGN(4);       //代码以4 字节对齐
 .text :
 {
  cpu/arm_cortexa9/start.o  (.text)                        //代码的第一个代码部分
  cpu/arm_cortexa9/s5pc210/cpu_init.o (.text)       //cpu 初始化
  board/samsung/smdkc210/lowlevel_init.o (.text)  //flash 初始化
  common/ace_sha1.o (.text)                               //serial 初始化
  *(.text)                                                            //其它代码部分
 }

 . = ALIGN(4);                                               
 .rodata : { *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.rodata*))) }  //指定只读数据段

 . = ALIGN(4);
 .data : { *(.data) }                                        //指定读/写数据段

 . = ALIGN(4);
 .got : { *(.got) }                                          //指定got 段, got 段式是uboot 自定义的一个段, 非标准段

 __u_boot_cmd_start = .;                             //把__u_boot_cmd_start 赋值为当前位置, 即起始位置

 .u_boot_cmd : { *(.u_boot_cmd) }              //指定u_boot_cmd 段, uboot 把所有的uboot 命令放在该段.
 __u_boot_cmd_end = .;                             //把__u_boot_cmd_end 赋值为当前位置,即结束位置

 . = ALIGN(4);
 __bss_start = .;                                       //把__bss_start 赋值为当前位置,即bss 段的开始位置
 .bss : { *(.bss) }                                      //指定bss 段
 _end = .;                                                //把_end 赋值为当前位置,即bss 段的结束位置
}
(1) 从ENTRY(_start)可以看出u-boot的入口函数是_start,这个没错
(2) 从. = 0x00000000也许可以看出_start的地址是0x00000000,事实并不是这样的,这里的0x00000000没效,在连接的时候最终会被TETX_BASE所代替的,具体请参考u-boot根目录下的config.mk.
(3) 网上很多说法是 _start=TEXT_BASE,我想这种说法也是正确的,但没有说具体原因。
本人的理解是这样的,TEXT_BASE表示text段的起始地址,而从
.text      :
{
  cpu/arm920t/start.o (.text)
  *(.text)
}
看,放在text段的第一个文件就是start.c编译后的内容,而start.c中的第一个函数就是
_start,所以 _start应该是放在text段的起始位置,因此说_start=TEXT_BASE也不为过。

 4412的TEXT_BASE地址存放在 board/samgsung/smdk210/config.mk 的第一行,而不是定义在cpu/arm_cortexa9/start.S。
    注 _TEXT_BASE 在老版的uboot里藏在.mk文件里,新版放在配置头文件中,其实就是一个宏
       _TEXT_BASE 表示的uboot镜像在目标系统上被烧写的起始物理地址

一直不明白的
U-BOOT是怎样从4Ksteppingstone跳到RAM中执行的,现在终于明白了。关键在于:
              ldr   pc, _start_armboot
_start_armboot:    .word start_armboot
这两条语句,ldr       pc, _start_armboot指令把_start_armboot这个标签的地方存放的内容(也即是start_armboot)移到PC寄存器里面,start_armboot是一个函数地址,在编译的时候给分配了一个绝对地址,所以上面语句实际上是完成了一个绝对地址的跳转。而我一直不明白的为什么在start.S里面有很多BL,B跳转语句都没有跳出4Ksteppingstone,原因是他们都是相对于PC的便宜的跳转,而不是绝对地址的跳转。还有要补充一下LDR,MOV,LDR伪指令的区别。
LDR      R0,0x12345678   //把地址0x12345678存放的内容放到R0里面
MOV    R0,#x                   //把立即数x放到R0里面,x必须是一个8 bits的数移到偶数次得到的数。
LDR      R0,=0x12345678        //把立即数0x12345678放到R0里面
阅读(1508) | 评论(0) | 转发(0) |
0

上一篇:Uboot start.S

下一篇:u-boot 中的命令实现

给主人留下些什么吧!~~