uboot之board.c源码分析
/lib_arm/board.c 主要完成了一些初始化的操作,最重要的是有start_armboot函数
_armboot_start地址为多少??
/*
 *
 * U-Boot code: 00F00000 -> 00F3C774  BSS: -> 00FC3274
 * IRQ Stack: 00ebff7c
 * FIQ Stack: 00ebef7c
 */
#include <common.h>
#include <command.h>
#include <malloc.h>
#include <devices.h>
#include <version.h>
#include <net.h>
#ifdef CONFIG_DRIVER_SMC91111
#include "../drivers/smc91111.h"
#endif
#ifdef CONFIG_DRIVER_LAN91C96  应该是关于网卡的定义
#include "../drivers/lan91c96.h"
#endif
DECLARE_GLOBAL_DATA_PTR //声明全局数据指针
#if (CONFIG_COMMANDS & CFG_CMD_NAND)
void nand_init (void); 声明这个方法
#endif
ulong monitor_flash_len;
#ifdef CONFIG_HAS_DATAFLASH
extern int  AT91F_DataflashInit(void);
extern void dataflash_print_info(void);
#endif
#ifndef CONFIG_IDENT_STRING 如果没有定义,CONFIG_IDENT_STRING就定义为空
#define CONFIG_IDENT_STRING ""
#endif
const char version_string[] =版本字符串
     U_BOOT_VERSION" (" __DATE__ " - " __TIME__ ")"CONFIG_IDENT_STRING;
#ifdef CONFIG_DRIVER_CS8900  如果是CS8900网卡,则声明下面的函数。好像是获取网址的意思
extern void cs8900_get_enetaddr (uchar * addr);
#endif
#ifdef CONFIG_DRIVER_RTL8019
extern void rtl8019_get_enetaddr (uchar * addr);
#endif
/*
 * Begin and End of memory area for malloc(), and current "brk" malloc用于用户程序进行分配内存
 */
;
;
;
static
void mem_malloc_init (ulong dest_addr) 内存分配初始函数。
{
     mem_malloc_start = dest_addr;
     mem_malloc_end = dest_addr + CFG_MALLOC_LEN;
     mem_malloc_brk = mem_malloc_start;
     memset ((,
              mem_malloc_end - mem_malloc_start);
真正实现内存分配的函数。分配了一个CFG_MALLOC_LEN大小的内存空间
}
void *sbrk (ptrdiff_t increment)     所分配内存区的brk指针调整。
{
     ulong old = mem_malloc_brk;
     ulong new = old + increment;
     if ((new < mem_malloc_start) || (new > mem_malloc_end)) {
         return (NULL);
     }
     mem_malloc_brk = new;
     return ((void *) old);
}
/************************************************************************
 * Init Utilities                             *
 ************************************************************************
 * Some of this code should be moved into the core functions,
 * or dropped completely,
 * but let's get it working (again) first...
 */
下面就是一系列的初始化操作。
static int init_baudrate (void)           初始化波特率
{
     ]; /* long enough for environment variables */
     int i = getenv_r ("baudrate", tmp, sizeof (tmp));
     gd->bd->bi_baudrate = gd->baudrate = (i > )
              ? ()
              : CONFIG_BAUDRATE;
     );
}
static int display_banner (void) 一些显示函数。显示IRQ_STACK_START等的地址
_armboot_start, _bss_start, _bss_end 这些值
{
     printf ("\n\n%s\n\n", version_string);
     debug ("U-Boot code: %08lX -> %08lX  BSS: -> %08lX\n",
            _armboot_start, _bss_start, _bss_end);
#ifdef CONFIG_MODEM_SUPPORT
     debug ("Modem Support enabled\n");
#endif
#ifdef CONFIG_USE_IRQ
     debug ("IRQ Stack: %08lx\n", IRQ_STACK_START);
     debug ("FIQ Stack: %08lx\n", FIQ_STACK_START);
#endif
     );
}
/*
 * 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)  显示内存的配置,打印出DRAM的大小
{
     int i;
#ifdef DEBUG
     puts ("RAM Configuration:\n");
     ; i<CONFIG_NR_DRAM_BANKS; i++) {
         printf ("Bank #%d: %08lx ", i, gd->bd->bi_dram[i].start);
         print_size (gd->bd->bi_dram[i].size, "\n");
     }
#else
     ;
     ; i<CONFIG_NR_DRAM_BANKS; i++) {
         size += gd->bd->bi_dram[i].size;
     }
     puts("DRAM:  ");
     print_size(size, "\n");
#endif
     );
}
#ifndef CFG_NO_FLASH
static void display_flash_config (ulong size)
{
     puts ("Flash: ");
     print_size (size, "\n");
}
#endif /* CFG_NO_FLASH */
/*初始化一个串行口作为控制台,同时进行一些硬件测试
 * 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.
 */
不存在一个common 即通用的初始化序列来为所有的开发板及结构进行初始化。因为不同的体系结构差别还是比较大的。
/*
 * 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 #ifdef'ed 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 it's 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);
int print_cpuinfo (void); /* test-only */
init_fnc_t *init_sequence[] = {定义一个初始化的整型指针数组
     cpu_init,     /* basic cpu dependent setup *//cpu/arm920t/cpu.c
 这个函数在cpu.c函数中定义了
     board_init,        /* basic board dependent setup *//board/smdk2410/smdk2410.c
     interrupt_init,        /* set up exceptions */
     env_init,     /* initialize environment */tools/env/FW_env.c
     init_baudrate,         /* initialze baudrate settings */
     serial_init,       /* serial communications setup */
     console_init_f,        /* stage 1 init of console */
     display_banner,        /* say that we are here */
#if defined(CONFIG_DISPLAY_CPUINFO)       显示cpu的信息
     print_cpuinfo,         /* display cpu info (and speed) */
#endif
#if defined(CONFIG_DISPLAY_BOARDINFO)     显示板的信息
     checkboard,        /* display board info */
#endif
     dram_init,         /* configure available RAM banks */
     display_dram_config,
     NULL,
};
void start_armboot (void)
{
     init_fnc_t **init_fnc_ptr;定义一个双重整型指针。
     char *s;
#ifndef CFG_NO_FLASH
     ulong size;
#endif
#if defined(CONFIG_VFD) || defined(CONFIG_LCD)
     unsigned long addr;
#endif
     /* Pointer is writable since we allocated a register for it */
     gd = (gd_t*)(_armboot_start - CFG_MALLOC_LEN - sizeof(gd_t));
     _armboot_start为0x33f80000,CFG_MALLOC_LEN是堆大小加环境数据区大小,在smdk2410.h中有定义
#define CFG_MALLOC_LEN              (CFG_ENV_SIZE + 128*1024)  CFG_ENV_SIZE为64K,所以共192K
     /* compiler optimization barrier needed for GCC >= 3.4 */
     __asm__ __volatile__("": : :"memory");
     memset ((, sizeof (gd_t));获得一个gd指针,给全局数据变量gd分配内存
     gd->bd = (bd_t*)((char*)gd - sizeof(bd_t));
     memset (gd->bd, , sizeof (bd_t));给板子数据变量分配内存空间
     monitor_flash_len = _bss_start - _armboot_start;取整个代码区Uboot的长度
顺序执行init_sequence数组中的初始化函数
     for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
         ) {
              hang ();
         }
     }
#ifndef CFG_NO_FLASH
     /* configure available FLASH banks */从其实现上来看,好像只是配置nor flash
     size = flash_init ();
     display_flash_config (size);显示flash的信息
#endif /* CFG_NO_FLASH */
#ifdef CONFIG_VFD 定义显示类型
#    ifndef PAGE_SIZE
#      define PAGE_SIZE 
#    endif
     /*
      * reserve memory for VFD display (always full pages)
      */
     /* bss_end is defined in the board-specific linker script */
     addr = (_bss_end + (PAGE_SIZE - )) & ~(PAGE_SIZE - );按页对齐的方式保留显存
     size = vfd_setmem (addr);
     gd->fb_base = addr;
#endif /* CONFIG_VFD */
#ifdef CONFIG_LCD
#    ifndef PAGE_SIZE
#      define PAGE_SIZE 
#    endif
     /*
      * reserve memory for LCD display (always full pages)
      */
     /* bss_end is defined in the board-specific linker script */
     addr = (_bss_end + (PAGE_SIZE - )) & ~(PAGE_SIZE - );同上
     size = lcd_setmem (addr);
     gd->fb_base = addr;
#endif /* CONFIG_LCD */
     /* armboot_start is defined in the board-specific linker script */
     初始化CFG_MALLOC_LEN大小空间
     mem_malloc_init (_armboot_start - CFG_MALLOC_LEN);
#if (CONFIG_COMMANDS & CFG_CMD_NAND)
初始化nandflash,这是在nandflash启动的s3c2410移植Uboot的关键,根据flash时序编写函数即可。首先要在include/configs/smdk2410.h中打开CFG_CMD_NAND命令
     puts ("NAND:  ");
     nand_init();       /* go init the NAND */,这个函数在前面被声明过,现在就可以直接使用了/board/smdk2410/smdk2410.c中没有定义这个函数,需要添加
#endif
#ifdef CONFIG_HAS_DATAFLASH
     AT91F_DataflashInit();
     dataflash_print_info();
#endif
     /* initialize environment */
     env_relocate ();初始化环境参数
#ifdef CONFIG_VFD
     /* must do this after the framebuffer is allocated */
     drv_vfd_init();framebuffer初始化
#endif /* CONFIG_VFD */
     /* IP Address */
     gd->bd->bi_ip_addr = getenv_IPaddr ("ipaddr");
     /* MAC Address */
     {
         int i;
         ulong reg;
         char *s, *e;
         ];
         i = getenv_r ("ethaddr", tmp, sizeof (tmp));
         s = (i > ) ? tmp : NULL;
         ; reg < ; ++reg) {
              gd->bd->bi_enetaddr[reg] = s ? simple_strtoul (s, &e, ) : ;
              if (s)
                   s = (*e) ? e +  : e;
         }获取网卡地址
#ifdef CONFIG_HAS_ETH1
         i = getenv_r ("eth1addr", tmp, sizeof (tmp));
         s = (i > ) ? tmp : NULL;
         ; reg < ; ++reg) {
              gd->bd->bi_enet1addr[reg] = s ? simple_strtoul (s, &e, ) : ;
              if (s)
                   s = (*e) ? e +  : e;
         }
#endif
     }
     devices_init ();   /* get the devices list going. */调用相应驱动函数对硬件设备进行初始化
#ifdef CONFIG_CMC_PU2
     load_sernum_ethaddr ();
#endif /* CONFIG_CMC_PU2 */
     jumptable_init ();
     console_init_r (); /* fully init console as a device */
#if defined(CONFIG_MISC_INIT_R)
     /* miscellaneous platform dependent initialisations */
     misc_init_r ();
#endif
     /* enable exceptions */
     enable_interrupts ();开中断
     /* Perform network card initialisation if necessary */
#ifdef CONFIG_DRIVER_CS8900
     cs8900_get_enetaddr (gd->bd->bi_enetaddr);
#endif
#if defined(CONFIG_DRIVER_SMC91111) || defined (CONFIG_DRIVER_LAN91C96)
     if (getenv ("ethaddr")) {
         smc_set_mac_addr(gd->bd->bi_enetaddr);
     }
#endif /* CONFIG_DRIVER_SMC91111 || CONFIG_DRIVER_LAN91C96 */
     /* Initialize from environment */
     if ((s = getenv ("loadaddr")) != NULL) {
         load_addr = simple_strtoul (s, NULL, );
     }
#if (CONFIG_COMMANDS & CFG_CMD_NET)
     if ((s = getenv ("bootfile")) != NULL) {
         copy_filename (BootFile, s, sizeof (BootFile));
     }
#endif   /* CFG_CMD_NET */
#ifdef BOARD_LATE_INIT
     board_late_init ();
#endif
#if (CONFIG_COMMANDS & CFG_CMD_NET)
#if defined(CONFIG_NET_MULTI)
     puts ("Net:   ");
#endif
     eth_initialize(gd->bd);
#endif
     /* main_loop() can return to retry autoboot, if so just run it again. */
     for (;;) {
          main_loop ();
     }
     /* NOTREACHED - no way out of command loop except booting */
}
void hang (void)
{
     puts ("### ERROR ### Please RESET the board ###\n");
     for (;;);
}
 .......
后面是modem的配置 不用管
uboot之board.c源码分析的更多相关文章
- (九)uboot配置编译、源码分析
		一.X210官方uboot配置编译实践1.找到官方移植好的uboot(BSP概念)(1)源头的源代码是uboot官网下载的.这个下载的源代码可能没有你当前使用的开发板的移植,甚至找不到当前开发板使用的 ... 
- u-boot源码分析
		Uboot源码分析 源码以u-boot-1.3.4为基准,主芯片采用at91sam9260,主要介绍uboot执行流程. uboot官网:http://www.denx.de/wiki/U-Boot/ ... 
- U-BOOT概述及源码分析(一)
		嵌入式Linux系统从软件角度通常可以分为以下4个层次: 引导加载程序 | Linux内核 | 文件系统 | 用户应用程序 嵌入式Linux系统中典型分区结构: 正常启动过程中,Bootloader首 ... 
- u-boot 源码分析(1) 启动过程分析
		u-boot 源码分析(1) 启动过程分析 文章目录 u-boot 源码分析(1) 启动过程分析 前言 配置 源码结构 api arch board common cmd drivers fs Kbu ... 
- u-boot源码分析之C语言段
		题外话: 最近一直在学习u-boot的源代码,从代码量到代码风格,都让我认识到什么才是真正的程序.以往我所学到的C语言知识和u-boot的源代码相比,实在不值一提.说到底,机器都是0和1控制的.感觉这 ... 
- 鸿蒙内核源码分析(GN应用篇) | GN语法及在鸿蒙的使用 | 百篇博客分析OpenHarmony源码 | v60.01
		百篇博客系列篇.本篇为: v60.xx 鸿蒙内核源码分析(gn应用篇) | gn语法及在鸿蒙的使用 | 51.c.h.o 编译构建相关篇为: v50.xx 鸿蒙内核源码分析(编译环境篇) | 编译鸿蒙 ... 
- 鸿蒙内核源码分析(构建工具篇) | 顺瓜摸藤调试鸿蒙构建过程 | 百篇博客分析OpenHarmony源码 | v59.01
		百篇博客系列篇.本篇为: v59.xx 鸿蒙内核源码分析(构建工具篇) | 顺瓜摸藤调试鸿蒙构建过程 | 51.c.h.o 编译构建相关篇为: v50.xx 鸿蒙内核源码分析(编译环境篇) | 编译鸿 ... 
- 鸿蒙内核源码分析(编译脚本篇) | 如何防编译环境中的牛皮癣 | 百篇博客分析OpenHarmony源码 | v58.01
		百篇博客系列篇.本篇为: v58.xx 鸿蒙内核源码分析(环境脚本篇) | 编译鸿蒙原来如此简单 | 51.c.h.o 本篇用两个脚本完成鸿蒙(L1)的编译环境安装/源码下载/编译过程,让编译,调试鸿 ... 
- 鸿蒙内核源码分析(编译环境篇) | 编译鸿蒙看这篇或许真的够了 | 百篇博客分析OpenHarmony源码 | v50.06
		百篇博客系列篇.本篇为: v50.xx 鸿蒙内核源码分析(编译环境篇) | 编译鸿蒙防掉坑指南 | 51.c.h.o 编译构建相关篇为: v50.xx 鸿蒙内核源码分析(编译环境篇) | 编译鸿蒙防掉 ... 
随机推荐
- sql server 判断相同值的数据
			举个栗子, 求出相同作者的书 select * from [books] where author in (select author from [books] group by author ha ... 
- android窗体动画:activity启动从底部向上滑动出现,关闭的时候从顶部向下滑动消失的动画实现
			在IOS系统里,我们打开app都是有启动动画的,这样子在打开一个新窗体,用户感觉有个过渡动画,体验效果很好,不会觉得很突然就冒出一个窗体,下面就实现一个android 的activity启动和关闭动画 ... 
- 详述iOS国际化
			在真正将国际化实践前,只知道通过NSLocalizedString方法将相应语言的字符串加载进来即可.但最近公司项目的新需求增加英文版本,并支持应用内无死角切换~,这才跳过各种坑实现了应用内切换语言, ... 
- mybatis 自动生成xml文件配置
			http://blog.csdn.net/techbirds_bao/article/details/9233599/ 
- W3C小组宣布:HTML5标准制定完成
			近日,W3C小组宣布已经完成对HTML5标准以及Canvas 2D性能草案的制定,这就意味着开发人员将会有一个稳定的“计划和实施”目标. Web性能工作组已经推出W3C的两个版本建议草案. Navig ... 
- java 对list中对象按属性排序
			实体对象类 --略 排序类----实现Comparator接口,重写compare方法 package com.tang.list; import java.util.Comparator; publ ... 
- [转]《深度探索C++对象模型》读书笔记[一]
			前 言 Stanley B.Lippman1. 任何对象模型都需要的三种转换风味: ü 与编译器息息相关的转换 ü 语言语义转换 ü 程序代码和对象模型的 ... 
- IntelliJ IDEA 12 创建Web项目 教程 超详细版
			IntelliJ IDEA 12 新版本发布 第一时间去官网看了下 黑色的主题 很给力 大体使用了下 对于一开始就是用eclipse的童鞋们 估计很难从eclipse中走出来 当然 我也很艰难的走 ... 
- thinkphp3.23整合phpexcel
			HINKPHP3.2.3整合PHPexcel实现数据的导入导出.可以上传excel文件后批量导入到数据库,兼容.xls和.xlsx格式:数据库里的数据可以按照搜索条件和分页导出为excel文件.最近接 ... 
- NGINX关于配置PATHINFO
			最近在群里发现有很多小白不会配置pathinfo现贴出来配置代码照着配置就可以了 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 2 ... 
