Bf533 Ldr文件到DXE文件的转换-答jack

 
   
Blackfin系列DSP内置了BOOTROM,当设置好相应的BOOT MODE后,BOOTROM即可发挥作用,将用户程序读取到片内Cache或者SDRAM的指定位置,然后程序从预设好的地址开始执行。在这种方式下,要求用户的程序按照一定的格式存放,这就是ldr的文件格式。
在Visual DSP中提供了elfloader.exe工具,用以将DXE文件转换为ldr文件。不过遗憾的是它没有提供将ldr反向转换为dxe的工具,仅仅提供了一个网上的共享工具的链接,这就是ldrViewer,用以查看ldr文件的内容。
究其原因,无非是认为ldr到dxe的转换意义不大,因为在转换后,DXE文件中的所有调试信息将全部丢失,反向转换后也很难进行修改。
日前花了点时间研究了一下ldr到dxe的转换问题,在原来 elfeditor的基础上添加了ldr的查看和转换功能,生成了一个新的工具 uCTools。现将其中的几个关键问题说明如下,也供有需要的朋友参考。
1   Ldr的文件格式
关于ldr的文件格式,VDSP的文档已经解释得比较清楚了,无非就是将一些Block按顺序排列,每个Block含有10个字节的块头和不超过65535个字节的数据(需要使用多个DXE的略有不同,多几个控制字节)。在块头中指明了块大小,此块将引导到哪块存储区域及2个字节的标志位,如下所示(来源:VisualDSP++ 4.5 Loader and Utilities Manual Revision 1.0, April 2006):
Table 2-4. ADSP-BF531/BF532/BF533 Block Header Structure 
Bit Field
Description
Address
4-byte address at which the block resides in memory.
Count
4-byte number of bytes to boot.
Flag
2-byte flag containing information about the block; the following text describes the flag structure.
Flag的意义如下所示:
Table 2-5. Flag Structure 
Bit Field
Description
Zero-fill block
Indicates that the block is for a buffer filled with zeros. The body of a zero block is not included within the loader file. When the loader utility parses through the .dxe file and encounters a large buffer with zeros, it creates a zero-fill block to reduce .ldr file size and boot time. If this bit is set, there is no block body in the block.
Ignore block
Indicates that the block is not to be booted into memory; skips the block and moves on to the next one. Currently is not implemented for application code.
Initialization block
Indicates that the block is to be executed before booting. The initialization block indicator allows the on-chip boot ROM to execute a number of instructions before booting the actual application code. When the on-chip boot ROM detects an init block, it boots the block into internal memory and makes a CALL to it (initialization code must have an RTS at the end).
This option allows the user to run initialization code (such as SDRAM initialization) before the full boot sequence proceeds. Initialization code can be included within the .ldr file by using the -init switch.
Processor type
Indicates the processor, either ADSP-BF531/BF532/BF538 or ADSP-BF533/BF534/BF536/BF537/BF539. After booting is complete, the on-chip boot ROM jumps to 0xFFA0 0000 for the ADSP-BF533/BF536/BF537/BF539 processor and to 0xFFA0 8000 for the ADSP-BF531/BF532/BF538 processor.
Last block
Indicates that the block is the last block to be booted into memory. After the last block, the processor jumps to the start of L1 memory for application code execution. When it jumps to L1 memory for code execution, the processor is still in supervisor mode and in the lowest priority interrupt (IVG15).
Compressed block
Indicates that the block contains compressed data. The compressed block can include a number of blocks compressed together to form a single compressed block.
一般地说,ldr文件的第一个块的Ignore标志位应该为1,即不使用它,但在这个块中可以设置好其它的一些信息。
2   DXE文件格式
DXE文件是在elf文件格式的基础上添加了一些VDSP特有的配置,如elf文件头中的e_type设置,还有一些特殊的调试段.annotations,.attributs等等。但是在这其中只有几个段是必须的:
空段:这是elf文件中的第一个段,其中不包含任何信息,其段头配置全为0。
至少一个保存字符串的段:这个段通常为第二个段,用以存放段名称等字符串。
程序段:就是程序代码,每个段不超过65535个字节。
.processor:这个段不是必须的,Visual DSP通过这个段来识别程序所针对的DSP类型。它的内容是一个字符串,如“ADSP-BF531 ”、“ADSP-BF561”等等。如果没有这个段,Visual DSP将认为DXE程序就是针对设置好的session开发的。
至于program header,我原来一直认为是必须的,但经过测试,发现DXE文件中没有这部分信息也可以,VDSP照样工作!
3   Ldr到dxe的转换
从两个文件的比较很容易可以看出转换的方法,就是为ldr文件中每一个不能Ignore的Block生成一个对应的程序段,设置好相应的section head,至于内容,当然就是原样copy。然后添加上一个空段和一个字符段,设置好.processor,就基本上可以了。
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

嵌云阁主

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值