现在的位置: 首页 > 综合 > 正文

android210 uboot 调试

2012年06月14日 ⁄ 综合 ⁄ 共 5488字 ⁄ 字号 评论关闭

目录

1.编译配置

2.u-boot.lds连接配置文件

3.Stage1之start.S

4.Stage2之入口start_armboot

1.编译配置

    编译前先进行配置:make smdkv210single_config

    其中,Makefile中make smdkv210single_config为:

  1. smdkv210single_config : unconfig  
  2.     @$(MKCONFIG) $(@:_config=) arm s5pc11x smdkc110 samsung s5pc110  
  3.     @echo "TEXT_BASE = 0xc3e00000" > $(obj)board/samsung/smdkc110/config.mk  

    这里使用了Makefile中的替换引用规则,类似常看到的例子 obj=$(srcfiles:%.c=%.o): 由.c得到对应的.o文件.
    这里是一样的道理: $(@:_config=) ,@代表的是target smdkv210single_config, 那么$(@:_config=)就是将smdkv210single_config中的_config替换为空,

    即得到smdkv210single。

    这里$(@:_config=) arm s5pc11x smdkc110 samsung s5pc110都是mkconfig(即@$(MKCONFIG))的参数,mkconfig即根目录下的脚本文件。

    执行这句命令后,在include/下生成config.mk和config.h。并且Makefile包含这个config.mk。

    config.mk文件:

  1. ARCH   = arm  
  2. CPU    = s5pc11x  
  3. BOARD  = smdkc110  
  4. VENDOR = samsung  
  5. SOC    = s5pc110  

    它指定里CPU架构,CPU型号,板子型号,CPU厂商,SOC??(母鸡啦)

    可以根据上面的这个信息找到对应的代码。比如说CPU代码在cpu/s5pc11x下,板子代码在board/samsung/smdkc110下。

2. u-boot.lds连接配置文件

      对于.lds文件,它定义了整个程序编译之后的连接过程,决定了一个可执行程序的各个段的存储位置。u-boot.lds如何指定连接过程?首先它被根目录下config.mk引用,定义如下:LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot.lds。根据这个路径,对于Android210而言,可以找到这个文件位于:board/samsung/smdkc110/u-boot.lds。其次,LDSCRIPT这个变量何时被用到?同样在config.mk中,可以找到:

       LDFLAGS += -Bstatic -T $(LDSCRIPT) $(PLATFORM_LDFLAGS)

       ifneq ($(TEXT_BASE),)
       LDFLAGS += -Ttext $(TEXT_BASE)
       endif

-T 参数指定生成可执行文件时ld连接器如何连接,TEXT_BASE是在make smdkv210single_config时写到board/samsung/smdkc110/config.mk中的,值为0xc3e00000。

[javascript] view
plain
copy

  1. /* 
  2.  * (C) Copyright 2002 
  3.  * Gary Jennejohn, DENX Software Engineering, <gj@denx.de> 
  4.  * 
  5.  * See file CREDITS for list of people who contributed to this 
  6.  * project. 
  7.  * 
  8.  * This program is free software; you can redistribute it and/or 
  9.  * modify it under the terms of the GNU General Public License as 
  10.  * published by the Free Software Foundation; either version 2 of 
  11.  * the License, or (at your option) any later version. 
  12.  * 
  13.  * This program is distributed in the hope that it will be useful, 
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of 
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
  16.  * GNU General Public License for more details. 
  17.  * 
  18.  * You should have received a copy of the GNU General Public License 
  19.  * along with this program; if not, write to the Free Software 
  20.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
  21.  * MA 02111-1307 USA 
  22.  */  
  23.   
  24. OUTPUT_FORMAT("elf32-littlearm""elf32-littlearm""elf32-littlearm");指定输出可执行文件是elf格式,32位ARM指令,小端  
  25. /*OUTPUT_FORMAT("elf32-arm", "elf32-arm", "elf32-arm")*/  
  26. OUTPUT_ARCH(arm);指定输出可执行文件的平台为ARM  
  27. ENTRY(_start);指定输出可执行文件的起始代码段为_start  
  28. SECTIONS  
  29. {  
  30.     . = 0x00000000; ;从0x0位置开始  
  31.   
  32.     . = ALIGN(4);  ;代码以4字节对齐  
  33.     .text      :     ;指定代码段  
  34.     {  
  35.       cpu/s5pc11x/start.o   (.text)  
  36.       cpu/s5pc11x/s5pc110/cpu_init.o    (.text)  
  37.       board/samsung/smdkc110/lowlevel_init.o    (.text)  
  38.           cpu/s5pc11x/onenand_cp.o      (.text)                   
  39.           cpu/s5pc11x/nand_cp.o (.text)                       
  40.           cpu/s5pc11x/movi.o (.text)   
  41.           board/samsung/smdkc110/flash.o (.text)   
  42.           common/secure.o (.text)   
  43.       common/ace_sha1.o (.text)  
  44.       cpu/s5pc11x/pmic.o (.text)  
  45.       *(.text)  
  46.     }  
  47.   
  48.     . = ALIGN(4);  
  49.     .rodata : { *(.rodata) }    ;指定只读数据段  
  50.   
  51.     . = ALIGN(4);  
  52.     .data : { *(.data) }    ;指定读/写数据段  
  53.   
  54.     . = ALIGN(4);  
  55.     .got : { *(.got) }   ;指定got段, got段式是uboot自定义的一个段, 非标准段  
  56.   
  57.     __u_boot_cmd_start = .;   ;把__u_boot_cmd_start赋值为当前位置, 即起始位置  
  58.     .u_boot_cmd : { *(.u_boot_cmd) }   ;指定u_boot_cmd段, uboot把所有的uboot命令放在该段  
  59.     __u_boot_cmd_end = .;  ;把__u_boot_cmd_end赋值为当前位置,即结束位置  
  60.   
  61.     . = ALIGN(4);  
  62.     .mmudata : { *(.mmudata) }   ;内存管理单元数据段  
  63.   
  64.     . = ALIGN(4);  
  65.     __bss_start = .;  ;把__bss_start赋值为当前位置,即bss段的开始位置  
  66.     .bss : { *(.bss) }   ;指定bss段  
  67.     _end = .;  ;把_end赋值为当前位置,即bss段的结束位置  
  68. }  

3.Stage1之start.S

     uboot是典型的bootloader之一,大多数bootloader都分为stage1和stage2两部分,u-boot也不例外。依赖于CPU体系结构的代码(如设备初始化代码等)通常都放在stage1且可以用汇编语言来实现,而stage2则通常用C语言来实现,这样可以实现复杂的功能,而且有更好的可读性和移植性。u-boot的Stage1代码通常放在start.S文件中,他用汇编语言写成,其主要代码部分如下:

 (1)定义入口。由于一个可执行的Image必须有一个入口点,并且只能有一个全局入口,通常这个入口放在ROM(Flash)的0x00000000地址,因此,必须通知编译器以使其知道这个入口,该工作可通过修改连接器脚本来完成。
 (2)设置异常向量(Exception Vector)。 
 (3)设置CPU的速度、时钟频率及终端控制寄存器。 
 (4)初始化内存控制器。 
 (5)将ROM中的程序复制到RAM中。 
 (6)初始化堆栈。 
 (7)转到RAM中执行,该工作可使用指令ldr pc来完成。

    根据config.mk中CPU的信息,找到对应的cpu目录为cpu/s5pc11x。首先看cpu/s5pc11x/start.S:

    其中代码解释引自:http://www.cnblogs.com/Efronc/archive/2012/02/28/2371662.html

[javascript] view
plain
copy

  1. /* 
  2.  *  armboot - Startup Code for S5PC110/ARM-Cortex CPU-core 
  3.  * 
  4.  *  Copyright (c) 2009  Samsung Electronics 
  5.  * 
  6.  * 
  7.  * See file CREDITS for list of people who contributed to this 
  8.  * project. 
  9.  * 
  10.  * This program is free software; you can redistribute it and/or 
  11.  * modify it under the terms of the GNU General Public License as 
  12.  * published by the Free Software Foundation; either version 2 of 
  13.  * the License, or (at your option) any later version. 
  14.  * 
  15.  * This program is distributed in the hope that it will be useful, 
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of 
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
  18.  * GNU General Public License for more details. 
  19.  * 
  20.  * You should have received a copy of the GNU General Public License 
  21.  * along with this program; if not, write to the Free Software 
  22.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
  23.  * MA 02111-1307 USA 
  24.  * 
  25.  * Base codes by scsuh (sc.suh) 
  26.  */  
  27.  
  28. #include <config.h>  
  29. #include <version.h>  
  30. #if defined(CONFIG_ENABLE_MMU)  

抱歉!评论已关闭.