嵌入式爱好者

查看: 11578|回复: 0

[裸机程序] 请教程序分段(section)的问题

[复制链接]

2

主题

6

帖子

11

积分

扫一扫,手机访问本帖
发表于 2014-11-18 16:35:41 | 显示全部楼层 |阅读模式
在ok6410上,程序在lds文件里面指定了分段,如下:
mmu.lds:

SECTIONS {
  first    0 : { head.o init.o }
  second    3072 : AT(2048) { leds.o }
}
---------------------------
head.S:
     
.text
.global _start
_start:

ldr r0, =0x70000013       
mcr p15, 0, r0, c15, c2, 4

ldr sp, =8192                       
bl  disable_watch_dog                                       
////////        bl  copy_2048_to_3072              
////////        ldr pc, =2048
////////        ldr pc, =3072

bl main

halt_loop:
    b   halt_loop
---------------------------
init.c:

void copy_2048_to_3072(void)
{
unsigned int *pdwSrc  = (unsigned int *)2048;
unsigned int *pdwDest = (unsigned int *)3072;       
   
while(pdwSrc < (unsigned int *)(2048+512))       
{
*pdwDest = *pdwSrc;
        pdwDest++;
        pdwSrc++;
}
}
---------------------------
leds.c:

int main()
{
volatile unsigned int k;
volatile unsigned int i,j;      
    GPMCON = 0x11111;  
    GPMDAT = 0x00000000;  

    while(1)
    {
            for(k=0;k<4;k++)
            {
                GPMDAT=~(1<<k);
for(i=0;i<20000;i++)
                    for(j=0;j<3;j++)
                    ;
            }
    }
return 0;
}
---------------------------

main函数在leds.c里面,用来点亮led   

程序烧到板子led不亮,是从nand flash-steppingstone启动的

然后我把head.S的bl main 改成 ldr pc, =2048试试,因为第二段代码存储在镜像2048的位置,但还是不亮

接着把head.S的bl main 改成 ldr pc, =3072试试,因为第二段代码在3072位置运行,但还是不亮

最后加上 bl  copy_2048_to_3072,把2048处的代码拷贝到运行地址3072,bl main 改成 ldr pc, =3072,还是不亮

相同的程序,我不用分段,在makefile里面用
arm-linux-ld -Ttext 0x50000000 -o mmu_elf $^
连接后编译的程序,led可以点亮,说明main点亮函数是没有问题的。

现在能试的都试了,不知道为什么程序分段后,就不好用了,麻烦各位大神帮看看,十分感谢!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋| 飞凌嵌入式 ( 冀ICP备12004394号-1 )

GMT+8, 2025-3-14 21:10

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表