基於S3C2410 的MDK 例程移植

移植所關注的要點如下所示:

1.分散加載文件

關於散加載文件的具體內容介紹,可參考附錄1“Realview MDK 中鏈接腳本詳細解析”,這裏只針對S3C2410 以及開發板的特點,給出具體的代碼參考。
之前提到的S3C2410 及其開發板的一些基本參數,這裏我們要關心的是SDRAM 和Nor Flash 的編址問題。通過閱讀S3C2410 用戶指南可知,地址分
布如下:
0x0000 0000 ~~ 0x0100 0000 :32M Nor Flash
0x8000 0000 ~~ 0x8100 0000 :32M Nor Flash
0x3000 0000 ~~ 0x0200 0000 :64M SDRAM
因此,針對不同的程序運行地址,就有不同的分散加載文件:

1) 程序運行在Nor Flash 中(RuninFlash.sct):
; *************************************************************
; *** Scatter-Loading Description File generated by uVision ***
; *************************************************************
;Run in Flash
LR_ROM1 0x00000000 { ; load region
ER_ROM1 0x00000000 0x0200000 { ; load address = execution address
*.o (RESET, +First)
*(InRoot$$Sections)
.ANY (+RO)
}
RW_RAM1 0x30000000 0x4000000 { ; RW data
.ANY (+RW +ZI)
}
RW_IRAM1 0x40000000 0x00001000 {
.ANY (+RW +ZI)
}
}
2) 程序運行在SDRAM 中(RuninRAM.sct):
; *************************************************************
; *** Scatter-Loading Description File generated by uVision ***
; *************************************************************
; Run in RAM
LR_ROM1 0x30000000 { ; load region
ER_ROM1 0x30000000 0x02000000 { ; load address = execution address

*.o (RESET, +First)
*(InRoot$$Sections)
.ANY (+RO)
}
RW_RAM1 0x30200000 0x3E00000 { ; RW data
.ANY (+RW +ZI)
}
RW_IRAM1 0x40000000 0x00001000 {
.ANY (+RW +ZI)
}
}


2.調試腳本

關於調試腳本的更多原理介紹,請參考附錄2 “Realview MDK 中調試腳本的詳細解析”。
在S3C2410 的MDK 移植過程中,調試腳本(SDRAM.INI)主要的內容是進行SDRAM 的配置和初始化運行指針。

/*******************************************************************/
/* Ext_RAM.INI: External RAM (SDRAM) Initialization File
*/
/*******************************************************************/
// <<< Use Configuration Wizard in Context Menu >>> //
/*******************************************************************/
/* This file is part of the uVision/ARM development tools. */
/* Copyright (c) 2005-2006 Keil Software. All rights reserved. */
/* This software may only be used under the terms of a valid, current, */
/* end user licence from KEIL for a compatible version of KEIL software */
/* development tools. Nothing else gives you the right to use this software.
*/
/********************************************************************/
FUNC void Setup (void) {
_WDWORD(0x53000000, 0x00000000);
_WDWORD(0x4A000008, 0xFFFFFFFF);
_WDWORD(0x4A00001C, 0x000007FF);
_WDWORD(0x4C000014, 0x00000003);
_WDWORD(0x4C000004, 0x0005c042);

_WDWORD(0x56000070, 0x00280000);

_WDWORD(0x56000078, 0x00000000);
_WDWORD(0x48000000, 0x22111110);
_WDWORD(0x48000004, 0x00000700);
_WDWORD(0x48000008, 0x00000700);
_WDWORD(0x4800000C, 0x00000700);
_WDWORD(0x48000010, 0x00000700);
_WDWORD(0x48000014, 0x00000700);
_WDWORD(0x48000018, 0x00000700);
_WDWORD(0x4800001c, 0x00018005);
_WDWORD(0x48000020, 0x00000700);
_WDWORD(0x48000024, 0x008e0459);
_WDWORD(0x48000028, 0x000000B2);
_WDWORD(0x4800002c, 0x00000030);
_WDWORD(0x48000030, 0x00000030);
_WDWORD(0x56000014, 0x00000001);
_WDWORD(0x56000020, 0xAAAA55AA);
_WDWORD(0x56000028, 0x0000FFFF);
_WDWORD(0x56000024, 0x00000000);

}
Setup(); // Setup for Init
LOAD SDRAM\Button_Test.axf INCREMENTAL // Download
PC = 0x30000000; // <o> Program Entry Point
g, main // Run to main function

3.MMU

S3C2410 支持MMU,具體的內容可見附錄3 “RealView MDK 中如何對MMU 進行操作”。當程序運行在SDRAM 中時,需要運行MMU,以便能夠找到正確的異常入

口。具體的函數實現過程如下:
/****************************************************************
* name: EnableMMU
* func: Enable the MMU
* para: none
* ret: none
* modify:
* comment:
****************************************************************/
void EnableMMU()
{
unsigned int ctl;
ctl = ARM_ReadControl();
ctl |= (1 << 0);
ARM_WriteControl(ctl);
}
/***********************************************************
* name: InitMMU
* func: Initialization the MMU
* para: pTranslationTable-TranslationTable Address
* ret: none
* modify:
* comment:
*****************************************************************/
void InitMMU(unsigned int *pTranslationTable)
{
int i;
// Program the TTB
ARM_WriteTTB((unsigned int) pTranslationTable);
// Program the domain access register
ARM_WriteDomain(0xC0000000); // domain 15: access are not checked
// Reset table entries
for (i = 0; i < 0x200; ++i)
pTranslationTable[i] = 0;
// Program level 1 page table entry
pTranslationTable[0x0] =
(0x300 << 20) | // Physical Address
(1 << 10) | // Access in supervisor mode
(15 << 5) | // Domain
1 << 4 |
0x2; // Set as 1 Mbyte section
pTranslationTable[0x1] =

(0x301 << 20) | // Physical Address
(1 << 10) | // Access in supervisor mode
(15 << 5) | // Domain
1 << 4 |
0x2; // Set as 1 Mbyte section
pTranslationTable[0x2] =
(0x302 << 20) | // Physical Address
(1 << 10) | // Access in supervisor mode
(15 << 5) | // Domain
1 << 4 |
0x2; // Set as 1 Mbyte section
pTranslationTable[0x3] =
(0x303 << 20) | // Physical Address
(1 << 10) | // Access in supervisor mode
(15 << 5) | // Domain
1 << 4 |
0x2; // Set as 1 Mbyte section
for(i = 0x200; i < 0xFFF; ++i)
pTranslationTable[i] =
(i << 20) | // Physical Address
(1 << 10) | // Access in supervisor mode
(15 << 5) | // Domain
1 << 4 |
0x2; // Set as 1 Mbyte section
EnableMMU(); // Enable the MMU
}
/****************************************************************
* name: ARM_WriteTTB
* func: Write Translation table base register
* para: TTB Address
* ret: none
* modify:
* comment:
*************************************************************/
__inline void ARM_WriteTTB(unsigned int ttb)
{
__asm("MCR p15, 0, (ttb & 0xFFFFC000), c2, c0, 0");
}
/*************************************************************
* name: ARM_WriteDomain
* func: Write domain access control
* para: Domain NO.
* ret: none

* modify:
* comment:
*******************************************************************/
__inline void ARM_WriteDomain(unsigned int domain)
{
__asm("MCR p15, 0, domain, c3, c0, 0");
}
因爲對於MMU 的控制必須在管理態下進行,故應該對啓動代碼進行相應的
修改。其中粗體部分爲添加的內容。
; Enter Supervisor Mode and set its Stack Pointer
MSR CPSR_c, #Mode_SVC:OR:I_Bit:OR:F_Bit
MOV SP, R0
SUB R0, R0, #SVC_Stack_Size
; Enable MMU Map Address 0x00 to 0x300000000,So if have no norflash the
interrupt can also work!
IF :DEF:ENABLEMMU
IMPORT InitMMU
STMFD SP!,{R0}
LDR R0, =TTB_ADDR
BL InitMMU
LDMFD SP!,{R0}
ENDIF

; Enter User Mode and set its Stack Pointer
MSR CPSR_c, #Mode_USR
MOV SP, R0
SUB SL, SP, #USR_Stack_Size

注意設置:Option or target ==>選擇Asm 標籤頁進行彙編器屬性配置。因爲程序運行在SDRAM 中時,需要MMU,故需要在Define 中預定義:ENABLEMMU。該標號用來作爲啓動代碼中的“IF:DEF:ENABLEMMU”的判斷條件。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章