免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
1234下一页
最近访问板块 发新帖
查看: 8223 | 回复: 35
打印 上一主题 下一主题

[BootLoader] 请教程序分段(section)的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2014-11-19 10:34 |只看该作者 |倒序浏览
在ok6410上,程序在lds文件里面指定了分段,如下:
mmu.lds:

SECTIONS {
  first    0 : { head.o init.o }
  second    3072 : AT(204 { 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点亮函数是没有问题的。

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

论坛徽章:
1
2015年迎新春徽章
日期:2015-03-04 09:58:11
2 [报告]
发表于 2014-11-19 11:39 |只看该作者
本帖最后由 arm-linux-gcc 于 2014-11-19 11:40 编辑

你这代码和链接脚本看来问题很多哦

1,mcr p15, 0, r0, c15, c2, 4这个是做什么的?

2,arm-linux-ld -Ttext 0x50000000 -o mmu_elf $^,请将生成的mmu_elf反汇编,通过附件传上来看一下

3,你自己的连接脚本地址貌似有问题,6410的0地址是ddr吗?

先将这3个问题理清楚才好回答你

论坛徽章:
0
3 [报告]
发表于 2014-11-19 12:21 |只看该作者
谢谢arm-linux-gcc的回复,
1. 在arm11的手册中的描述:
c15, Peripheral Port Memory Remap Register
The purpose of the Peripheral Port Memory Remap Register is to remap the memory attributes
to Non-Shared Device. This forces access to the peripheral port and overrides what is
programmed in the page tables. The remapping happens both with the MMU enabled and with
the MMU disabled, therefore you can remap the peripheral port even when you do not use the
MMU. The Peripheral Port Memory Remap Registerhas the highest priority, higher than that
of the Primary and Normal memory remap registers.
这个必须得有的,否则led不亮,找这个我调了好长时间

2. 已经上传,请查看

3.因为板子设置从nand flash启动的,所以启动时6410会把nand flash的前8KB数据拷贝到steppingstone,即sram里面,所以我这段程序是在片内sram跑的

谢谢^^

mmu.rar

2.43 KB, 下载次数: 6

论坛徽章:
1
2015年迎新春徽章
日期:2015-03-04 09:58:11
4 [报告]
发表于 2014-11-19 12:40 |只看该作者
相同的程序,我不用分段,在makefile里面用
arm-linux-ld -Ttext 0x50000000 -o mmu_elf $^
连接后编译的程序,led可以点亮,说明main点亮函数是没有问题的。


你附件里是这个的反汇编吗?你地址设置的是0x50000000啊,但是我看到你传上来的文件里地址是0



另外反汇编最好加上头,objdump -hD -C elf > xxx

论坛徽章:
0
5 [报告]
发表于 2014-11-19 13:28 |只看该作者
反汇编的头已经加上了,请看附件

arm-linux-ld -Ttext 0x50000000 -o mmu_elf $^ 对应不分段的好用的程序,无论我设置-Ttext 0x50000000还是-Ttext 0x00000000运行地址都能点亮

分段的程序我只想让它在sram里面跑,只设置了0为运行地址

mmu.rar

2.55 KB, 下载次数: 2

论坛徽章:
1
2015年迎新春徽章
日期:2015-03-04 09:58:11
6 [报告]
发表于 2014-11-19 13:57 |只看该作者
你传上来的第二个反汇编,是能点亮的还是不能点亮的?

论坛徽章:
0
7 [报告]
发表于 2014-11-19 13:57 |只看该作者
是不能点亮的

论坛徽章:
1
2015年迎新春徽章
日期:2015-03-04 09:58:11
8 [报告]
发表于 2014-11-19 14:08 |只看该作者
本帖最后由 arm-linux-gcc 于 2014-11-19 14:08 编辑

无论我设置-Ttext 0x50000000还是-Ttext 0x00000000运行地址都能点亮

把能点亮的反汇编发一手,-Ttext 0x0000000的或0x5000000的都可以

论坛徽章:
1
2015年迎新春徽章
日期:2015-03-04 09:58:11
9 [报告]
发表于 2014-11-19 14:19 |只看该作者
sram地址是0对吧?
sram容量有多大?

论坛徽章:
0
10 [报告]
发表于 2014-11-19 14:25 |只看该作者
无论设置0x50000000还是0x00000000都能在sram里面正常跑,点亮led

反汇编文件请看附件

mmu-能亮-Ttext 0x00000000.rar

2.65 KB, 下载次数: 6

mmu-能亮-Ttext 0x50000000.rar

2.68 KB, 下载次数: 6

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

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP