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

Bootloader for LPC1766 - starting the program

I'm working on a bootloader that uses a hex file and I would like to know, how to start loaded program.

In Keil v. 4.24 startup.s file contained this:


Reset_Handler   PROC
                EXPORT  Reset_Handler             [WEAK]
                IMPORT  __main
                LDR     R0, =__main
                BX      R0
                ENDP

And __main function was an entry point for any program. Keil generated hex-file and __main-function address was here as "Linear start address". All was well.

But Keil's 4.5 (or higher) startup.s containes this:


Reset_Handler   PROC
                EXPORT  Reset_Handler             [WEAK]
                IMPORT  SystemInit
                IMPORT  __main
                LDR     R0, =SystemInit
                BLX     R0
                LDR     R0, =__main
                BX      R0
                ENDP

So what is an entry point now? And where does "linear start address" point to?
Is there some reliable way to start loaded program based on information in the hex file?

Moving SystemInit call from reset handler to the actual main is obvious, but a little bit inconvinient.

Parents
  • A hex file contains a record “Start Linear Address Record”. The meaning of this record is well defined for an Intel processor but open to interpretation for a Cortex-M3

    IMHO, the entry point is really “Reset_Handler” which branches to “__main” in your v4.24 example.

    However, a quick experiment seems to suggest that the “Start Linear Address Record” in the Keil generated HEX file will point to “__main” by default. (You may want to check in the Keil documentation in relation to what to expect here; I didn’t).

    This is of no consequence for the first start-up file you show as “Reset_Handler” branches immediately to main.

    However, if you were to use this value for the second example you would bypass the CMSIS initialisation function SystemInit. (BTW: SystemInit needs to be called before anything else to initialise the system so it should not be called from main).

    You might want to add this line

    --entry= Reset_Handler

    in your linker control string to get what I consider the correct entry point. It will control what is in the “Start Linear Address Record” of the hex file.

    It seems to default to the following in the absence of it being specified.
    --entry=__main

    However, this is a Cortex-M3 device so the exception vector table contains the true entry point.

    You will need to mimic the Cortex-M3 start-up by loading by the initial program counter AND the stack pointer.

    The exception vector table should be located at address 0x0 (by default) in the hex file.

    From your point of view, load the MSP with the value at offset 0x0 in the hex file, and vector to the entry point which is located at offset 0x4.

    In code…

            MOVS.N          R3      ,#0x0
            LDR.W           R13     ,[R3]
            LDR.W   PC      , [R3,#0x4]
    

Reply
  • A hex file contains a record “Start Linear Address Record”. The meaning of this record is well defined for an Intel processor but open to interpretation for a Cortex-M3

    IMHO, the entry point is really “Reset_Handler” which branches to “__main” in your v4.24 example.

    However, a quick experiment seems to suggest that the “Start Linear Address Record” in the Keil generated HEX file will point to “__main” by default. (You may want to check in the Keil documentation in relation to what to expect here; I didn’t).

    This is of no consequence for the first start-up file you show as “Reset_Handler” branches immediately to main.

    However, if you were to use this value for the second example you would bypass the CMSIS initialisation function SystemInit. (BTW: SystemInit needs to be called before anything else to initialise the system so it should not be called from main).

    You might want to add this line

    --entry= Reset_Handler

    in your linker control string to get what I consider the correct entry point. It will control what is in the “Start Linear Address Record” of the hex file.

    It seems to default to the following in the absence of it being specified.
    --entry=__main

    However, this is a Cortex-M3 device so the exception vector table contains the true entry point.

    You will need to mimic the Cortex-M3 start-up by loading by the initial program counter AND the stack pointer.

    The exception vector table should be located at address 0x0 (by default) in the hex file.

    From your point of view, load the MSP with the value at offset 0x0 in the hex file, and vector to the entry point which is located at offset 0x4.

    In code…

            MOVS.N          R3      ,#0x0
            LDR.W           R13     ,[R3]
            LDR.W   PC      , [R3,#0x4]
    

Children