run the code in ram under asm.

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

run the code in ram under asm.

1,844 次查看
100asong
Contributor I

I want to copy the boot code into ram and then run it in ram.

Boot code address is 0xf000,memory address is 0x3980.

So I implement the prm as follow:

My prm file:

SEGMENTS /* here all RAM/ROM areas of the device are listed. Used in PLACEMENT below. All addresses are 'logical' */

          ......

          BOOT_MEM      = READ_ONLY   0xF000 TO 0xF9FF RELOCATE_TO 0x3980;

          ......

END

 

PLACEMENT /* here all predefined and user segments are placed into the SEGMENTS defined above. */
          ......

         BootStart          INTO BOOT_MEM;

          ......

END

 

VECTOR 0 BootStart  /* reset vector: this is the default entry point for an Assembly application. */

 

My bootloader code is asm code.

        org $f000
BootStart:

......

 

 

 

But it looks the code can not been copied into ram 0x3980 when we run this project.

In C,it should be okay,I think.But in asm,how to complete it.

 

Thanks ,please help me.

Best Regards.
      

标签 (1)
0 项奖励
回复
4 回复数

1,123 次查看
CompilerGuru
NXP Employee
NXP Employee

There are a couple of misunderstandings in this code.

First, the copy from ROM to RAM is done by the C startup code mainly for initialized variables, not for code. While it is possible to use this for code too (it is used for XGATE code for example), C code is not handled this way. Also for variables copied by the startup code the relocation offset is computed by the linker, not explicitly given in the prm. 

Second the RELOCATE_TO directive is used to place relocatable code at the different address in flash than references to it resolve too. When writing PIC (position independent code) it is not necessary as PIC means there are no absolute references, hence nothing to adapt. Also the relocated too address range, to which the code gets copied at runtime, must have at least the size of the relocated buffer. Here the BOOT_MEM area is 0xA00 bytes, but there are not 0xA00 RAM bytes after 0x3980 (just 0x680 up to 0x4000). So this BOOT_MEM segment seems problematic.

Also the PLACEMENT maps (relocatable) sections to segments, but BootStart in the assembly code is a label, not a relocatable section. Sections and assembly labels have their own namespace and do not interfere with each other, so in the shown code the two uses of BootStart do not refer to the same entity.

Sections in assembly are defined with the section directive (BootStart: SECTION), this is different from the used ORG directive which defines the allocation of the code here. Also that the address used  in the ORG directive matches to the one used in the BOOT_MEM segment is only considered for error checking (memory overlaps...) it does not affect the outcome of how the ORG sections content gets treated.

 

About the booloader setup, typically a bootloader is used to flash an application, not to flash itself. As flash needs to be first erased and then programmed there is always a time window when the flash does not contain a valid image and therefore any spike could render the device non bootable (without bdm). Therefore the safe setup is to separate the bootloader from the main application and to only update the application in the filed, while keeping the bootloader itself in a protected area, say never erasing it. Reprogram the bootloader itself should generally not be necessary if the bootloader is used for booting only, and not part of the user application.

 

0 项奖励
回复

1,123 次查看
100asong
Contributor I

HI, CompilerGuru,

  

        Thanks for your help.

 Through your help,I know my thinking has some error:1.Section and label.2.Relocate size...

       

       About the booloader setup, typically a bootloader is used to flash an application, not to flash itself.

       I want to flash bootloader since that bootloader have issue and we need to modify it. I think ,in this case ,we should flash it.

      

       How to flash bootloader in asm environent?How to get it?

      Thanks sir.

Best regards.

 

0 项奖励
回复

1,123 次查看
bigmac
Specialist III

Hello asong,

 

If I correctly understand your problem, the reset vector must point to a non-volatile location, i.e. flash memory, which should not be at BOOTMEM, since this is reserved for the flash copy of the RAM based code.

 

The Bootstart routine should then initialise the stack pointer, and then explicitly transfer each byte of the RAM based code into RAM.  The routine woud then jump to the start of the RAM based code.

 

Is your ASM project relocatable or not?  If an absolute assembly project, it is possible that the linker, and therefore the PRM file, would not be used.  I am not sure whether this applies to 16-bit devices.

 

Regards,

Mac

 

0 项奖励
回复

1,123 次查看
100asong
Contributor I

Hi,

      Thanks for your reply.

       Sorry,My cpu is xep100.

 

       Is your ASM project relocatable or not?  If an absolute assembly project,

       My asm project can not relocate now,the address is 0xF000.I think my project is absulute assembly project.

 

 

       I think whether we have 2 ways for my question(run the bootloader code in ram,since I want to reflash the bootloader code):

1.At the beginning of  my bootloader code, copy the code from flash to ram,and then jump to the ram address to run it.

Based on this way,I think we should calculate the right ram address since bootloader code contain copy the code and jump instruction. This right ram address should pass the copy and jump code,or not ,it will been dead loop.For this reason,I think perhaps it is not good way.

2.Whether we can modify prm file or other settings,and then compiler helps us to arrive the aim.

 

 

0 项奖励
回复