Chinaunix首页 | 论坛 | 博客
  • 博客访问: 111830
  • 博文数量: 15
  • 博客积分: 1423
  • 博客等级: 上尉
  • 技术积分: 140
  • 用 户 组: 普通用户
  • 注册时间: 2009-10-15 18:40
文章分类

全部博文(15)

文章存档

2011年(1)

2010年(9)

2009年(5)

分类: 嵌入式

2009-11-09 00:04:44

  在我迷迷糊学看了lowlevel_init.S中的代码之后,有一个感觉就是,要想读懂其中的代码首先得看一下你所用的芯片手册,因为里面有比较详细的存储器控制(MemoryController)描述。我用的是s3c2440手册里写得十分清楚,总共有8个块(Banks)(Bank0~Bank7),每个块对应着不同的控制与地址线,其实这些Bank很大一部分是对应着的控制寄存器的地址,这个要看实际的芯片与板子,看了下面的理解估计会有个大概。
   第二,就是要清楚你的板子上对的存储地址的分配,一般板子手册上都会有的。我的开发板是友善之臂的mini2440(不是很富裕只能买一些平民板子),在它的手册里写有SDRAM存储系统与FLASH系统的介绍包括芯片型号,存储大小,这些都是后面移植要注意,毕竟U-boot的移植就是对硬件支持的修改。mini2440的SDRAM使用两片32M bytes总共64M bytes型号为HY57V561620FTP芯片,地址空间为0x30000000~0x34000000
   进入正题:
 
/*
 * Memory Setup stuff - taken from blob memsetup.S
 *
 * Copyright (C) 1999 2000 2001 Erik Mouw () and
 *                     Jan-Derk Bakker ()
 *
 * Modified for the Samsung SMDK2410 by
 * (C) Copyright 2002
 * David Mueller, ELSOFT AG, <>
 *
 * 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
 */

#include
#include

/* some parameters for the board */
/*
 *
 * Taken from linux/arch/arm/boot/compressed/head-s3c2410.S
 *
 * Copyright (C) 2002 Samsung Electronics SW.LEE  <>
 *
 */
#define BWSCON 0x48000000  /*总线宽度&等待控制寄存器的宏定义(由s3c2440芯片手册5.4可知BW
                            SCON的地址正好为0x48000000可R/W复位值为0*/
 
 
/* BWSCON */
#define DW8    (0x0)
#define DW16    (0x1)
#define DW32    (0x2)    /*上面三个宏是数据总线宽度,分别是8位、16位、32位在s3c2440芯片手
                          册5.4中可以看到一个对BWSCON中每一位的详解其中DWn就是对每一个Bank
                          要使用的数宽度进行定义*/

#define WAIT    (0x1<<2) /*位WSn的宏定义,具体的作用在手册中有说明*/
#define UBLB    (0x1<<3) /*位STn的宏定义*/
 
#define B1_BWSCON    (DW32)
#define B2_BWSCON    (DW16)
#define B3_BWSCON    (DW16 + WAIT + UBLB)
#define B4_BWSCON    (DW16)
#define B5_BWSCON    (DW16)
#define B6_BWSCON    (DW32)
#define B7_BWSCON    (DW32) /*以上是对BANKn的数据总线宽度与功能的宏定义,对于BANK3因为要接
                             网卡,网卡有wait信号与没有wait信号两种,所以这里有些特别*/
 
 
//以下是对每一个Bank的BANKCON进行配置,这里要根据SRAM手册来配置来对应的值,否则不能正常进行使用,在0~5中大多是对一些时序与Page模式的配置,只对应SRAM的要求就可以了*/
/* BANK0CON */
#define B0_Tacs    0x0 /*  0clk */
#define B0_Tcos    0x0 /*  0clk */
#define B0_Tacc    0x7 /* 14clk */
#define B0_Tcoh    0x0 /*  0clk */
#define B0_Tah    0x0 /*  0clk */
#define B0_Tacp    0x0
#define B0_PMC    0x0 /* normal */
 
/* BANK1CON */
#define B1_Tacs    0x0 /*  0clk */
#define B1_Tcos    0x0 /*  0clk */
#define B1_Tacc    0x7 /* 14clk */
#define B1_Tcoh    0x0 /*  0clk */
#define B1_Tah    0x0 /*  0clk */
#define B1_Tacp    0x0
#define B1_PMC    0x0
 
#define B2_Tacs    0x0
#define B2_Tcos    0x0
#define B2_Tacc    0x7
#define B2_Tcoh    0x0
#define B2_Tah    0x0
#define B2_Tacp    0x0
#define B2_PMC    0x0
 
#define B3_Tacs    0x0 /*  0clk */
#define B3_Tcos    0x3 /*  4clk */
#define B3_Tacc    0x7 /* 14clk */
#define B3_Tcoh    0x1 /*  1clk */
#define B3_Tah    0x0 /*  0clk */
#define B3_Tacp    0x3     /*  6clk */
#define B3_PMC    0x0 /* normal */
 
#define B4_Tacs    0x0 /*  0clk */
#define B4_Tcos    0x0 /*  0clk */
#define B4_Tacc    0x7 /* 14clk */
#define B4_Tcoh    0x0 /*  0clk */
#define B4_Tah    0x0 /*  0clk */
#define B4_Tacp    0x0
#define B4_PMC    0x0 /* normal */
 
#define B5_Tacs    0x0 /*  0clk */
#define B5_Tcos    0x0 /*  0clk */
#define B5_Tacc    0x7 /* 14clk */
#define B5_Tcoh    0x0 /*  0clk */
#define B5_Tah    0x0 /*  0clk */
#define B5_Tacp    0x0
#define B5_PMC    0x0 /* normal */
 
//在B6之后是SDBAM的配置,根据Datasheet里说的后两个Bank是可以作为ROM、SRAM、SDRAM等储存器
//因为这里配置为SDRAM所以其他只对于ROM、SRAM有效的位就不用配置了,其实这些位和上面的Bank是
//一样的。
//Bank的所就相应的选择配置位了MT
#define B6_MT    0x3 /* SDRAM */
#define B6_Trcd     0x1             //RAStoCAS的延时时钟周期
#define B6_SCAN    0x1 /* 9bit */   //列地址位数的宏定义,列扫描数,在SDRAM手册上定有
 
#define B7_MT    0x3 /* SDRAM */
#define B7_Trcd    0x1 /* 3clk */
#define B7_SCAN    0x1 /* 9bit */
 
 
//以下为刷新控制寄存器的配置,得根据SDRAM的具体参数来配置,移植时要特别的注意
/* REFRESH parameter */
#define REFEN    0x1 /* Refresh enable */ //使能刷新
#define TREFMD    0x0 /* CBR(CAS before RAS)/Auto refresh */ //刷新模式在此为自刷新
#define Trp    0x0 /* 2clk */  //RAS预充电时间
#define Trc    0x3 /* 7clk */  //SDRAM半行周期时间,行周期Trc=Tsrc+Trp
#define Tchr    0x2 /* 3clk */ //本人在s3c2440的Datasheet中没有找到这个位
#define REFCNT    1113 /* period=15.6us, HCLK=60Mhz, (2048+1-15.6*60) */
//SDRAM刷新计数值,即刷新频率
 
//以下是重点了,也即是重要的lowlevel_init函数了
/**************************************/
_TEXT_BASE:
 .word TEXT_BASE  //这里是获得代码段的起始地址,我的是0x33F80000(在board/xxx/config.mk中
                  //可到找到“TEXT_BASE=0x33F80000”
 
.globl lowlevel_init  //这里相当于定义一个全局的lowlevel_init以方便调用
lowlevel_init:
 /* memory control configuration */
 /* make r0 relative the current location so that it */
 /* reads SMRDATA out of FLASH rather than memory ! */
 ldr     r0, =SMRDATA  //SMDATA表示这13个寄存器的值存放的开始地址,值为0x33F8xxxx,处于内
                       //存中,这一句的作用是把其值加载到r0中
 
 ldr r1, _TEXT_BASE    //把代码的起始地址(0x33F80000)加载到r1中
 sub r0, r0, r1        //r0减去r1其结果存入r0,也即SMDATA中的起始地址0x33F8xxxx减去
                       //0x33F80000,其结果就是13个寄存器的值在NOR Flash存放的开始地址

 ldr r1, =BWSCON /* Bus Width Status Controller */ //存储控制器的基地址
 add     r2, r0, #13*4     //在计算出来的存放地址加上#13*4,然后其结果保存在r2中
                           //13个寄存器,每个寄存器占4个字节
0:
 ldr     r3, [r0], #4      //内存中r0的值加载到r3中,然后r0加4,即下一个寄存器的
 str     r3, [r1], #4      //读出寄存器的值保存到r1中,然后r1也偏移4
 cmp     r2, r0            //比较r0与r2的值,如果不等继续返回0:执行,也即13个寄存器的值
                           //是否读完
 bne     0b
 /* everything is fine now */
 mov pc, lr               //程序跳转,返回到cpu_init_crit中
 .ltorg
/* the literal pools origin */
SMRDATA:
    .word (0+(B1_BWSCON<<4)+(B2_BWSCON<<8)+(B3_BWSCON<<12)+(B4_BWSCON<<16)+(B5_BWSCON<<20)+(B6_BWSCON<<24)+(B7_BWSCON<<28))
                                               //设置每个BWCSCON,BANK0由硬件连线定
    .word ((B0_Tacs<<13)+(B0_Tcos<<11)+(B0_Tacc<<8)+(B0_Tcoh<<6)+(B0_Tah<<4)+(B0_Tacp<<2)+(B0_PMC))
    .word ((B1_Tacs<<13)+(B1_Tcos<<11)+(B1_Tacc<<8)+(B1_Tcoh<<6)+(B1_Tah<<4)+(B1_Tacp<<2)+(B1_PMC))
    .word ((B2_Tacs<<13)+(B2_Tcos<<11)+(B2_Tacc<<8)+(B2_Tcoh<<6)+(B2_Tah<<4)+(B2_Tacp<<2)+(B2_PMC))
    .word ((B3_Tacs<<13)+(B3_Tcos<<11)+(B3_Tacc<<8)+(B3_Tcoh<<6)+(B3_Tah<<4)+(B3_Tacp<<2)+(B3_PMC))
    .word ((B4_Tacs<<13)+(B4_Tcos<<11)+(B4_Tacc<<8)+(B4_Tcoh<<6)+(B4_Tah<<4)+(B4_Tacp<<2)+(B4_PMC))
    .word ((B5_Tacs<<13)+(B5_Tcos<<11)+(B5_Tacc<<8)+(B5_Tcoh<<6)+(B5_Tah<<4)+(B5_Tacp<<2)+(B5_PMC))
                                  //以上是对BANKCON0~BANKCON5的设置
    .word ((B6_MT<<15)+(B6_Trcd<<2)+(B6_SCAN))
    .word ((B7_MT<<15)+(B7_Trcd<<2)+(B7_SCAN))  //对BANKCON6、BANKCON7的设置

    .word ((REFEN<<23)+(TREFMD<<22)+(Trp<<20)+(Trc<<18)+(Tchr<<16)+REFCNT)
    .word 0x32     //BANKSIZE寄存器的设置
    .word 0x30     //对MRSRB6设置
    .word 0x30     //对MRSRB7设置

通过以上对代码的分析可以知道,这里主要是对储存寄存器的设置,特别是SMRDATA后面的。这里代码的作用是为加载Bootloader的第二阶段代码准备RAM空间。所谓准备,即是初始化内存芯片,使其可用。这个函数被cpu/xxx/start.S调用。
阅读(2892) | 评论(1) | 转发(1) |
给主人留下些什么吧!~~

chinaunix网友2010-10-14 16:43:31

你好,我是个菜鸟,刚开始学习这方面,看了你的文章受益良多。我有个很白痴的问题。我想问下 #define WAIT (0x1<<2) /*位WSn的宏定义,具体的作用在手册中有说明*/ #define UBLB (0x1<<3) /*位STn的宏定义*/ 这里面为什么要0x1<<2?不是只要定义0或者1就行了吗?