`
yidongkaifa
  • 浏览: 4052445 次
文章分类
社区版块
存档分类
最新评论

基于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”的判断条件。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics