s3c lowleve_init.S分析

來源:互聯網
上載者:User

/*
 * Memory Setup stuff - taken from blob memsetup.S
 *
 * Copyright (C) 1999 2000 2001 Erik Mouw (J.A.K.Mouw@its.tudelft.nl) and
 *                     Jan-Derk Bakker (J.D.Bakker@its.tudelft.nl)
 *
 * Modified for the Samsung SMDK2410 by
 * (C) Copyright 2002
 * David Mueller, ELSOFT AG, <d.mueller@elsoft.ch>
 *
 * 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 <config.h>
#include <version.h>

 


/* some parameters for the board */

 

/*
 *
 * Taken from linux/arch/arm/boot/compressed/head-s3c2410.S
 *
 * Copyright (C) 2002 Samsung Electronics SW.LEE  <hitchcar@sec.samsung.com>
 *
 */
@我的開發板上的SDRAM為:HY57V561620FTP-H,4Mx16bitx4Banks,兩片接成32bit,64MB,接在BANK6上,位址範圍為:[0x30000000-0x33ffffff]
@(還沒搞清楚SDRAM的結構,為什麼要分成Banks,改天看下相關的文檔研究一下)
@對於SDRAM的初始化是要配置13個寄存器,好像多採用迴圈方式。

 

#define BWSCON 0x48000000
@BWSCON寄存器地址,控制每個匯流排

 

/* BWSCON */
#define DW8   (0x0)
#define DW16   (0x1)
#define DW32   (0x2)
@將用來設定位寬的三個宏
#define WAIT   (0x1<<2)
#define UBLB   (0x1<<3)
@將用來設定wait和ublb的宏

 

#define B1_BWSCON  (DW32)
#define B2_BWSCON  (DW16)
#define B3_BWSCON  (DW16 + WAIT + UBLB)
#define B4_BWSCON  (DW16)
#define B5_BWSCON  (DW16)
@BANK2、BANK3、BANK4、BANK5為什麼配成16bit匯流排寬度,而且BANK3還要加上WAIT和UBLB屬性沒有搞明白,感覺如果沒用到的話可以配成預設值的吧?
#define B6_BWSCON  (DW32)
#define B7_BWSCON  (DW32)
@我板子的SDRAM接在BANK6,所以配成32bit位寬,BANK7按datasheet的要求配置的和BANK6相同

 

@分別配置每個BANK的BANKCON寄存器,這裡應該根據SRAM的手冊來配置相應的BANK,BANK0~5主要是配置一些時序參數
/* 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

 

@這裡BANK3CON不為預設值,是因為在SMDK2410上BANK3上應該接了ROM
@根據我自己的板子,我把這裡換成了預設值(根據vivi上的預設值修改的),不過要不是預設值的話應該也沒有影響的吧?我的板子這裡接了DM9000A

#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 */

 

@配置SDRAM的參數,BANK6和BANK7要配置成同樣的值,需要查看SDRAM的datasheet
@當記憶體為ROM或SRAM時需要配置所有位,當為SDRAM時只要配置[0~3]
#define B6_MT   0x3 /* SDRAM */
@記憶體類型,預設為SDRAM
#define B6_Trcd   0x1
@RAS到CAS的延時
#define B6_SCAN   0x1 /* 9bit */
@列掃描數,在SDRAM手冊上,有一句:C0~C8即為9列

 

#define B7_MT   0x3 /* SDRAM */
#define B7_Trcd   0x1 /* 3clk */
#define B7_SCAN   0x1 /* 9bit */

 

/* REFRESH parameter */
@SDRAM重新整理參數,這個很重要,移植時要更改
#define REFEN   0x1 /* Refresh enable */
@預設為允許重新整理
#define TREFMD   0x0 /* CBR(CAS before RAS)/Auto refresh */
@據說下面三個時間參數多是根據經驗來設定
#define Trp   0x0 /* 2clk */
@RAS precharge Time
#define Trc   0x3 /* 7clk */
@根據S3C2440的datasheet為:Trc=Tsrc+Trp,但寄存器中要填入的是Tsrc,這裡彷彿應該設為10個時鐘才對?
#define Tchr   0x2 /* 3clk */
@SDRAM手冊上沒有找到這個時鐘的定義
#define REFCNT   1113 /* period="15".6us, HCLK="60Mhz", (2048+1-15.6*60) */
@SDRAM重新整理計數值,這個值比較重要,根據SDRAM的datasheet,(我使用的這款晶片在datasheet寫著8192Refresh cycle/64ms,所以一個重新整理周期為64ms/8192=7.8125us,取7.9的話REFCNT的值就為1259)
/**************************************/

 

_TEXT_BASE:
 .word TEXT_BASE

 

@這裡開始lowlevel_init函數了,通過迴圈連續初始化13個寄存器
.globl 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  
// SMRDATA=0x33F8 06C8
 ldr r1, _TEXT_BASE   
//TEXT_BASE為0x33F8 0000
@r1放程式碼片段的開始位置
 sub r0, r0, r1
    //計算SMRDATA的相對位址儲存到R0中
    //SMRDATA為虛擬位址,而TEXT_BASE為虛擬位址的起始地址
    //而現在Uboot的起始地址並不為虛擬位址
    //TEXT_BASE為0x33F8 0000,SMRDATA為0x33F8 06C8
    //而現在程式運行在起始地址為0x0000 0000的地方
    //所以需要計算以0x0000 0000為標準的相對位址
(參考uboot-1.3.0-rc3引導啟動學習筆記,這一段確實要好好理解)
 ldr r1, =BWSCON /* Bus Width Status Controller */
 add     r2, r0, #13*4   // r0=SMRDATA-TEXT_BASE
@13個寄存器,每個寄存器佔4個位元組
@讀取一個值存入寄存器中,然後迴圈,直到讀完13個寄存器

0:
 ldr     r3, [r0], #4
 str     r3, [r1], #4  
// ldr r1, =BWSCON
 cmp     r2, r0
 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))
@設定每個BWSCON,注意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)
@設定REFRESH,在S3C2440中11~17位是保留的,也即(Tchr<<16)無意義
    .word 0x32
@設定BANKSIZE,對於容量可以設定大寫,多出來的空記憶體會被自動檢測出來。沒有搞明白高載模式操作是什麼意思!
    .word 0x30
@設定MRSRB6
    .word 0x30
@設定MRSRB7

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.