This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

IVT Memory mapping problem for Bootloader and Application Code

Hi,

I am working on LPC2368 microcontroller. I need to develop two codes. One for bootloader and other is the actual application code.

The bootloader resides at 0x0000 and the application code is at 0x2000
The bootloader RAM is from 0x40000000 to 0x40000BFF
and the application code RAM is from 0x40000C00 onwards.

I am using a flag in the bootloader to identify if there is a firmware upgrade.
If this flag is set then the new firmware stored at a location other than actual application will be loaded into the application location i.e., 0x2000 and hence the firmware had been upgraded.

Now my problem is when my actual application code is running the interrupts are being called from the IVT of the Bootloader. Since i am using the VIC Vector Table for interrupts so both the IVT from Bootloader and application code are pointing to the same location. So i am not having any trouble with the IRQs.

Now i need to add a Data Abort handler which calls a function in the application code for handling data abort instructions.

This handling i have added in the IVT of the application code. But since the interrupts are being called from the IVT of the bootloader i couldnt write handling for Data Abort from application code.

I had seen many threads and all suggest to remap the interrupt vectors to RAM Mode.
But if i did so the IVT of the application code will be mapped to 0x40000000.

But my bootloader is using the RAM from 0x40000000 so should i leave the first 64 bytes of RAM for application IVT and then allocate my Bootloader RAM and after that allocate my Application RAM??

Please do suggest me how i need to achieve this.

Thanks in advance

Parents
  • The application code will have a full startup file.
    And as per the RAM i got your point.

    I will leave 64 Bytes of RAM for IVT of Application Code i.e., 0x40000000 to 0x40000040.
    I will then assaign the RAM location for Bootloader from 0x40000040 to 0x40000400 i.e., 1024 bytes for the bootloader. And the remaining RAM will be assigned to the actual application code.

    So to remap to the IVT of the application code to the RAM i had done the following settings in the IDE

    Right click on the startup file.
    Go to 'Options for File"LPC2300.s"'
    Asm -> Conditional Assembly control symbols
    RAM_INTVEC REMAP RAM_MODE

    Now the following gets executed in the startup code of the Application.
    ; Copy Exception Vectors to Internal RAM ---------------------------------------

    IF :DEF:RAM_INTVEC ADR R8, Vectors ; Source LDR R9, =RAM_BASE ; Destination LDMIA R8!, {R0-R7} ; Load Vectors STMIA R9!, {R0-R7} ; Store Vectors LDMIA R8!, {R0-R7} ; Load Handler Addresses STMIA R9!, {R0-R7} ; Store Handler Addresses ENDIF

    ; Memory Mapping (when Interrupt Vectors are in RAM) ---------------------------

    MEMMAP EQU 0xE01FC040 ; Memory Mapping Control IF :DEF:REMAP LDR R0, =MEMMAP IF :DEF:EXTMEM_MODE MOV R1, #3 ELIF :DEF:RAM_MODE MOV R1, #2 ELSE MOV R1, #1 ENDIF STR R1, [R0] ENDIF

    Now i have another doubt regarding the mapping of IVT to RAM.

    Vectors LDR PC, Reset_Addr LDR PC, Undef_Addr LDR PC, SWI_Addr LDR PC, PAbt_Addr LDR PC, DAbt_Addr NOP ; Reserved Vector
    ; LDR PC, IRQ_Addr LDR PC, [PC, #-0x0120] ; Vector from VicVectAddr LDR PC, FIQ_Addr

    For IRQ's it is as LDR PC, [PC, #-0x0120] ; Vector from VicVectAddr

    Previously when IRQ interrupt arises PC is loaded from PC - 0x120 to get the VIC Vector Address.
    But now the PC will contain an address near to RAM location (0x40000000 + IRQ handler location)

    Now if minus 0x120 from PC how can IRQ handling takes place?

Reply
  • The application code will have a full startup file.
    And as per the RAM i got your point.

    I will leave 64 Bytes of RAM for IVT of Application Code i.e., 0x40000000 to 0x40000040.
    I will then assaign the RAM location for Bootloader from 0x40000040 to 0x40000400 i.e., 1024 bytes for the bootloader. And the remaining RAM will be assigned to the actual application code.

    So to remap to the IVT of the application code to the RAM i had done the following settings in the IDE

    Right click on the startup file.
    Go to 'Options for File"LPC2300.s"'
    Asm -> Conditional Assembly control symbols
    RAM_INTVEC REMAP RAM_MODE

    Now the following gets executed in the startup code of the Application.
    ; Copy Exception Vectors to Internal RAM ---------------------------------------

    IF :DEF:RAM_INTVEC ADR R8, Vectors ; Source LDR R9, =RAM_BASE ; Destination LDMIA R8!, {R0-R7} ; Load Vectors STMIA R9!, {R0-R7} ; Store Vectors LDMIA R8!, {R0-R7} ; Load Handler Addresses STMIA R9!, {R0-R7} ; Store Handler Addresses ENDIF

    ; Memory Mapping (when Interrupt Vectors are in RAM) ---------------------------

    MEMMAP EQU 0xE01FC040 ; Memory Mapping Control IF :DEF:REMAP LDR R0, =MEMMAP IF :DEF:EXTMEM_MODE MOV R1, #3 ELIF :DEF:RAM_MODE MOV R1, #2 ELSE MOV R1, #1 ENDIF STR R1, [R0] ENDIF

    Now i have another doubt regarding the mapping of IVT to RAM.

    Vectors LDR PC, Reset_Addr LDR PC, Undef_Addr LDR PC, SWI_Addr LDR PC, PAbt_Addr LDR PC, DAbt_Addr NOP ; Reserved Vector
    ; LDR PC, IRQ_Addr LDR PC, [PC, #-0x0120] ; Vector from VicVectAddr LDR PC, FIQ_Addr

    For IRQ's it is as LDR PC, [PC, #-0x0120] ; Vector from VicVectAddr

    Previously when IRQ interrupt arises PC is loaded from PC - 0x120 to get the VIC Vector Address.
    But now the PC will contain an address near to RAM location (0x40000000 + IRQ handler location)

    Now if minus 0x120 from PC how can IRQ handling takes place?

Children
  • The interrupt vector code is identical.

    The processor remaps the interrupt vector table, so it will take a block of RAM and map on top of the lowest addresses of the flash. So the processor will still think that the interrupt vector table starts from address 0 - just as it did before.

    The only difference is that your application (which starts at address 0x2000) will be linked with an interrupt vector table at address 0x2000. And the startup code will copy these bytes from address 0x2000 into RAM. And then map that RAM block on top of address 0x0000.

    But back to the bootloader use of RAM again.

    You write:
    "I will then assaign the RAM location for Bootloader from 0x40000040 to 0x40000400 i.e., 1024 bytes for the bootloader. And the remaining RAM will be assigned to the actual application code."

    Why not map 0x40000040 .. whatever you feel you need (only matters how much memory to zero-init on boot).

    And map 0x40000040 .. max to the application, where max represents all RAM supported by the chip.

    There is zero reason for the application to leave the RAM that the boot loader used. The boot loader doesn't need it anymore at the same moment the processor enters the startup file of the application. So the startup code for the application is free to initialize all ram but the bytes reserved for the interrupt vector table. No reason to waste 1kB RAM for the boot loader, if the interrupt vector table remapping only requires 64 bytes. The other 1024-64 bytes will just be wasted by your configuration.