




已阅读5页,还剩11页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
/* * (C) Copyright 2002-2006 * Wolfgang Denk, DENX Software Engineering, wddenx.de. * * (C) Copyright 2002 * Sysgo Real-Time Solutions, GmbH * Marius Groeger * * 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 */* * To match the U-Boot user interface on ARM platforms to the U-Boot * standard (as on PPC platforms), some messages with debug character * are removed from the default U-Boot build. * * Define DEBUG here if you want additional info as shown below * printed upon startup: * * U-Boot code: 00F00000 - 00F3C774 BSS: - 00FC3274 * IRQ Stack: 00ebff7c * FIQ Stack: 00ebef7c */#include #include #include #include #include #include #include #include #include #include #include #ifdef CONFIG_BITBANGMII#include #endif#ifdef CONFIG_DRIVER_SMC91111#include ./drivers/net/smc91111.h#endif#ifdef CONFIG_DRIVER_LAN91C96#include ./drivers/net/lan91c96.h#endifDECLARE_GLOBAL_DATA_PTR;ulong monitor_flash_len;#ifdef CONFIG_HAS_DATAFLASHextern int AT91F_DataflashInit(void);extern void dataflash_print_info(void);#endif#ifndef CONFIG_IDENT_STRING#define CONFIG_IDENT_STRING #endifconst char version_string =U_BOOT_VERSION ( U_BOOT_DATE - U_BOOT_TIME )CONFIG_IDENT_STRING;#ifdef CONFIG_DRIVER_RTL8019extern void rtl8019_get_enetaddr (uchar * addr);#endif#if defined(CONFIG_HARD_I2C) | defined(CONFIG_SOFT_I2C)#include #endif/* * Coloured LED functionality * * May be supplied by boards if desired */void inline _coloured_LED_init (void) void coloured_LED_init (void) _attribute_(weak, alias(_coloured_LED_init);void inline _red_LED_on (void) void red_LED_on (void) _attribute_(weak, alias(_red_LED_on);void inline _red_LED_off(void) void red_LED_off(void) _attribute_(weak, alias(_red_LED_off);void inline _green_LED_on(void) void green_LED_on(void) _attribute_(weak, alias(_green_LED_on);void inline _green_LED_off(void) void green_LED_off(void) _attribute_(weak, alias(_green_LED_off);void inline _yellow_LED_on(void) void yellow_LED_on(void) _attribute_(weak, alias(_yellow_LED_on);void inline _yellow_LED_off(void) void yellow_LED_off(void) _attribute_(weak, alias(_yellow_LED_off);void inline _blue_LED_on(void) void blue_LED_on(void) _attribute_(weak, alias(_blue_LED_on);void inline _blue_LED_off(void) void blue_LED_off(void) _attribute_(weak, alias(_blue_LED_off);/* * Init Utilities* * * Some of this code should be moved into the core functions, * or dropped completely, * but lets get it working (again) first. */#if defined(CONFIG_ARM_DCC) & !defined(CONFIG_BAUDRATE)#define CONFIG_BAUDRATE 115200#endifstatic int init_baudrate (void)char tmp64;/* long enough for environment variables */int i = getenv_r (baudrate, tmp, sizeof (tmp);gd-bd-bi_baudrate = gd-baudrate = (i 0)? (int) simple_strtoul (tmp, NULL, 10): CONFIG_BAUDRATE;return (0);static int display_banner (void)printf (nn%snn, version_string);debug (U-Boot code: %08lX - %08lX BSS: - %08lXn, _armboot_start, _bss_start, _bss_end);#ifdef CONFIG_MODEM_SUPPORTdebug (Modem Support enabledn);#endif#ifdef CONFIG_USE_IRQdebug (IRQ Stack: %08lxn, IRQ_STACK_START);debug (FIQ Stack: %08lxn, FIQ_STACK_START);#endifreturn (0);/* * WARNING: this code looks cleaner than the PowerPC version, but * has the disadvantage that you either get nothing, or everything. * On PowerPC, you might see DRAM: before the system hangs - which * gives a simple yet clear indication which part of the * initialization if failing. */static int display_dram_config (void)int i;#ifdef DEBUGputs (RAM Configuration:n);for(i=0; ibd-bi_drami.start);print_size (gd-bd-bi_drami.size, n);#elseulong size = 0;for (i=0; ibd-bi_drami.size;puts(DRAM: );print_size(size, n);#endifreturn (0);#ifndef CONFIG_SYS_NO_FLASHstatic void display_flash_config (ulong size)puts (Flash: );print_size (size, n);#endif /* CONFIG_SYS_NO_FLASH */#if defined(CONFIG_HARD_I2C) | defined(CONFIG_SOFT_I2C)static int init_func_i2c (void)puts (I2C: );i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);puts (readyn);return (0);#endif#if defined(CONFIG_CMD_PCI) | defined (CONFIG_PCI)#include static int arm_pci_init(void)pci_init();return 0;#endif /* CONFIG_CMD_PCI | CONFIG_PCI */* * Breathe some life into the board. * * Initialize a serial port as console, and carry out some hardware * tests. * * The first part of initialization is running from Flash memory; * its main purpose is to initialize the RAM so that we * can relocate the monitor code to RAM. */* * All attempts to come up with a common initialization sequence * that works for all boards and architectures failed: some of the * requirements are just _too_ different. To get rid of the resulting * mess of board dependent #ifdefed code we now make the whole * initialization sequence configurable to the user. * * The requirements for any new initalization function is simple: it * receives a pointer to the global data structure as its only * argument, and returns an integer return code, where 0 means * continue and != 0 means fatal error, hang the system. */typedef int (init_fnc_t) (void);/注意这种用法,linux内核中也经常使用 int print_cpuinfo (void);init_fnc_t *init_sequence = #if defined(CONFIG_ARCH_CPU_INIT)arch_cpu_init,/* basic arch cpu dependent setup */* basic arch cpu dependent setup /cpu/arm920t/cpu.c中定义,该函数为空,因为没有采用IRQ或FIQ模式*/ CPU的相关配置,如初始化IRQ/FIQ模式的栈cpu/arm920t/cpu.c*/#endifboard_init,/* basic board dependent setup */* basic board dependent ,初始化时钟频率,配置IO口,初始化全局数据bd(如平台号,传递内核参数的地址) ,setup /board/smdk2410/smdk2410.c */* basic board dependent setup开发板相关配置,是对板子的初始化,设置MPLL,改变系统时钟,以及一些GPIO寄存器的值,还设置了U-Boot机器码和内核启动参数地址,它是开发板相关的函数,比如2410是在:board/smdk2410/smdk2410.c中实现*/ #if defined(CONFIG_USE_IRQ)interrupt_init,/* set up exceptions 初始化中断,在cpu/arm920t/s3c24x0/interrupts.c实现*/#endiftimer_init,/* initialize timer */* initialize timer 使用定时器4 cpu/arm920t/s3c24x0/timer.c */#ifdef CONFIG_FSL_ESDHCget_clocks,#endifenv_init,/* initialize environment */* initialize environment common/Env_nand.c 校验环境变量,并获取环境变量的地址*/init_baudrate,/* initialze baudrate settings 始化波特率lib_arm/board.c */*/serial_init,/* serial communications setup */ driver/serial/serial_s3c24x0.c 初始化串口0,用于打印信息,该平台只支持配置串口1来打印信息 */console_init_f,/* stage 1 init of console */display_banner,/* say that we are here */打印uboot代码段和数据段地址信息#if defined(CONFIG_DISPLAY_CPUINFO)print_cpuinfo,/* display cpu info (and speed) */#endif#if defined(CONFIG_DISPLAY_BOARDINFO)checkboard,/* display board info */#endif#if defined(CONFIG_HARD_I2C) | defined(CONFIG_SOFT_I2C)init_func_i2c,#endifdram_init,/* configure available RAM banks */获取ram的地址和大小,banks board/sunsang/smdk2410/smdk2410.c*/#if defined(CONFIG_CMD_PCI) | defined (CONFIG_PCI)arm_pci_init,#endif/打印BANK的相关信息display_dram_config,/lib_arm/board.cNULL,;对于内核启动来说,这部分主要是完成全局数据gd的初始化,以便内核访问start_armboot是U-Boot执行的第一个C语言函数,完成系统初始化工作,进入主循环,处理用户输入的命令。这里只简要列出了主要执行的函数流程:可以看出这里定义了一个指针数组,它的每一个元素都是指针变量,这些指针变量指向的类型为init_fnc_t,在C语言中函数的入口地址就是函数名,所以这里使用一系列函数名来初始化这个数组void start_armboot (void)init_fnc_t *init_fnc_ptr;/*它是指向指针的指针变量,变量的类型为init_fnc_t,这是一个使用typedef定义的函数类型, 其中init_fnc_ptr将在后面指向一个数组指针*/char *s;#if defined(CONFIG_VFD) | defined(CONFIG_LCD)unsigned long addr;#endif gd_t: 定义在 /include/asm-arm/Global_data.h中,包含一些全局通用的变量. _armboot_start: 代码的起始地址,它定义在start.S中的前几行中,定义为 _start 当系统第一次加电时,指令是从0x0地址开始执行的,所以此时的 _start值 应为0x0;而当uboot经过代码重定位后,指令会从 _TEXT_BASE 处开始执行, 此时的 _start值就成了 _TEXT_BASE的值. CFG_MALLOC_LEN: 在/include/configs/smdk2440.h中有定义,该变量表示供 malloc函数使用的内存池空间,代码中定义值为:0x10000+128*1024 |-|- _armboot_start基址| 4 | |-|- malloc函数池基址| 3 | |-|- (gd_t)gd(全局变量表)基址| 2 | |-|= 3.4 */_asm_ _volatile_(: : :memory);memset (void*)gd, 0, sizeof (gd_t);/把gd变量的内容填充为0 ,填充 3 区的数据为0 ,即初始化gd表.注意:这里并没有/初始化bd表,在gd表中的bd成员只是一个指针,因为对初始化的是个指针地址 bd_t 结构体在/include/asm-arm/U-boot.h中定义, 定义板子的一些信息,包括: 波特率,IP地址, 以太网地址, 架构编码,启动参数 ,BANK的起始地址和大小等gd-bd = (bd_t*)(char*)gd - sizeof(bd_t);/分配区域 2 给bd, bd的基址 = gd的基址 - bd的尺寸/获取bd_info结构体指针memset (gd-bd, 0, sizeof (bd_t);/把区域 2 填充为 0 ,即初始化 bd 表gd-flags |= GD_FLG_RELOC;/标志位已经重定向monitor_flash_len = _bss_start - _armboot_start;/整个代码区的长度/_bss_start 在u-boot.lds中定位 在bin文件中 BSS 段和 TEXT 段和 DATA 段存放的顺序同前向后依次是: TEXT(代码段 RO) DATA(已初始化数据段 RW) BSS(未初始化数据段ZI) 所以 _bss_start 的基址等于 TEXT的长度加上DATA的长度.即: _bss_start(BSS段基址) = 代码段长度+数据段长度BSS(Block Started by Symbol)段是未被初始化的数据段,是存放程序中 未被初始化的全局变量的一块内存区域,初始化时应清零;该段只有 名称和大小却没有值;该段不包含任何数据,只是简单的维护开始和 结束的地址,以便内存区能在运行时被有效地清零,它在应用程序的 映像文件(ARM中也即bin文件)中并不存在. text :代码段,是包含程序代码的段dat :已经初始化的数据段,保存已经初始化的全局变量. 在嵌入式系统中,bin文件(又称Image文件)中只包含text和data段, 而bss段不在其中,它是由系统初始化为零. /_armboot_start 在start.S中定义为_start,而_start为代码的起始地址 /只包含 RO(TEXT) 和 RW(DATA) 段.重定位前的值为0x0,此时指向flash,/重定位后则指向RAM中的某一地址/由此可以知道: _bss_start - _armboot_start 的值即是在第一阶段从/flash中重定位到RAM中的那部分代码的长度,也即可TEXT和DATA数据段,/这个值与start.S中的重定位那部分代码所计算的值是相等的/所以,monitor_flash_len表示从flash中搬来的代码的长度for (init_fnc_ptr = init_sequence; *init_fnc_ptr; +init_fnc_ptr) if (*init_fnc_ptr)() != 0) hang ();/各设置的初始化.当返回值不为0时表示初始化失败 ,此时会调用 hang()函数/打印一错误提示信息,然后进入死循环/* armboot_start is defined in the board-specific linker script */mem_malloc_init (_armboot_start - CONFIG_SYS_MALLOC_LEN,CONFIG_SYS_MALLOC_LEN);#ifndef CONFIG_SYS_NO_FLASHCFG_NO_FLASH /没有flash,如果没定义该常量则表示板子上有flash,此时调用flash_init()对其进行初始化./* configure available FLASH banks */display_flash_config (flash_init ();/打印flash的信息,这里仅输出它的大小/board/smdk2410/flash.c配置flash/从其实现来看,好像只是配置nor flash/ze = flash_init (); /isplay_flash_config (size); /打印flash的信息,这里仅输出它的大小定义显示类型#endif /* CONFIG_SYS_NO_FLASH */#ifdef CONFIG_VFD#ifndef PAGE_SIZE# define PAGE_SIZE 4096#endif/* * reserve memory for VFD display (always full pages) */* bss_end is defined in the board-specific linker script */addr = (_bss_end + (PAGE_SIZE - 1) & (PAGE_SIZE - 1);/按页对其方式保留显存vfd_setmem (addr);gd-fb_base = addr;/帧缓冲基地址#endif /* CONFIG_VFD */#ifdef CONFIG_LCD*/为LCD分配RAM(内存)空间/* board init may have inited fb_base */if (!gd-fb_base) #ifndef PAGE_SIZE# define PAGE_SIZE 4096#endif/* * reserve memory for LCD display (always full pages) */* bss_end is defined in the board-specific linker script */addr = (_bss_end + (PAGE_SIZE - 1) & (PAGE_SIZE - 1);lcd_setmem (addr);gd-fb_base = addr;/为显存缓冲区地址变量赋值#endif /* CONFIG_LCD */初始化nand flash,这是在nand flash启动的s3c2410移植u-boot的关键,根据flash时序编写函数即可/在include/configs/smdk2410.h中的command definition中增加CONFIG_COMMANDS和CFG_CMD_NAND命令#if defined(CONFIG_CMD_NAND)/如果定义了命令和NAND命令,则初始化nand puts (NAND: );nand_init();/* go init the NAND */board/smdk2410/smdk2410.c,获取nand的基地址和 大小信息#endif#if defined(CONFIG_CMD_ONENAND)onenand_init();#endif#ifdef CONFIG_HAS_DATAFLASHAT91F_DataflashInit();dataflash_print_info();#endif/* initialize environment */env_relocate ();/* initialize environment 环境的初始化,代码在common/env_common.c中*/#ifdef CONFIG_VFD/* must do this after the framebuffer is allocated */drv_vfd_init();#endif /* CONFIG_VFD */#ifdef CONFIG_SERIAL_MULTIserial_initialize();#endif/* IP Address */* IP Address 为全局变量的成员赋值:IP地址*/gd-bd-bi_ip_addr = getenv_IPaddr (ipaddr);/通过命令行参数传递获取ip地址stdio_init ();/* get the devices list going. */标准输入输出和设备初始化.jumptable_init ();();/跳转表初始化,函数在commonexports.c文件中#if defined(CONFIG_API)/* Initialize API */api_init ();#endifconsole_init_r ();/* fully init console as a device */初始化串口#if defined(CONFIG_ARCH_MISC_INIT)/* miscellaneous arch dependent initialisations */arch_misc_init ();#endif#if defined(CONFIG_MISC_INIT_R)/* miscellaneous platform dependent initialisations */misc_init_r ();#endif/* enable exceptions */enable_interrupts ();/启用中断/* Perform network card initialisati
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 个人货车租赁合同
- 肾病内科学诊疗进展与临床实践
- 2025年事业单位工勤技能-湖南-湖南地图绘制员四级(中级工)历年参考题库典型考点含答案解析
- 2025年事业单位工勤技能-湖北-湖北热力运行工五级(初级工)历年参考题库典型考点含答案解析
- 2025年事业单位工勤技能-湖北-湖北无损探伤工二级(技师)历年参考题库典型考点含答案解析
- 2025年事业单位工勤技能-湖北-湖北仓库管理员五级(初级工)历年参考题库含答案解析
- 2025年事业单位工勤技能-海南-海南机械热加工一级(高级技师)历年参考题库含答案解析
- 2025年事业单位工勤技能-海南-海南保育员二级(技师)历年参考题库含答案解析
- 2025-2030中国箱包面料市场运作模式及营销发展趋势预测报告
- 2025年绿色消费理念传播与消费者行为引导的绿色消费市场竞争力分析
- 2024年中考物理压轴题专项训练:电磁继电器核心综合练(原卷版)
- 矿山事故应急报告制度
- 2024-2025学年山东省淄博市桓台县四年级上学期数学期中考试试题
- DB1402T36-2024农村居家养老服务规范
- 中国发电企业碳中和数字转型白皮书-埃森哲
- ISO27001信息安全管理体系培训资料
- 《绝对值》教学课件
- Unit 6 Work quietly!(教学设计)2023-2024学年人教PEP版英语五年级下册
- 高考英语考纲词汇3500词(珍藏版)
- 制造业智能化生产线改造方案提升生产效率
- 人教版五年级上册美术全册教学设计
评论
0/150
提交评论