Atmel SAM4E Bootloader/VTOR executing new application

I've written a boot loader for the Atmel SAM4E device which is working to a point, it can receive new application code via SPI, erase flash and write to flash, but I don't understand how to execute the new application. I've learned the VTOR can be relocated, but I'm not sure how. (my application sits at address 0x00420000).
I'm very new to writing code for ARM, so I'd appreciate any help.

Many thanks

Paul

Parents
  • Hello everyone!

    I am also trying to write my own bootloader, so I am facing similar problems dealt in this post.

    One good question would be, when am I able to modify the VTOR? I say this because I init the bootloader as a normal application with its Interrupt Vector Table, and being the reset vector in 0x0000_0000, I pretend to do all the bootloader stuff and after finishing, modify VTOR register and jump to 0x0000_2000 (the bootloader has been configured with BOOTPROT 2, so 8K memory has been "protected" for this purpose). Is this possible? It is not working right now. I tried to modify VTOR before and after initializing the board (ATMEL R21 with a ARM CORTEX M0+).

    In order to modify the VTOR I do it like this:

    SCB->VTOR = ((uint32_t)0x00002000);

    But being the VTOR just from 32:7 won't it be better to do it like this?

    SCB->VTOR = ((uint32_t)0x00002000 << (SCB_VTOR_TBLOFF_Pos - 1)); // shift 7 to the left ARM Information Center

    After doing this (that is nor working), I pretend to jump to the application so... which considerations should I bear in mind? Would be enough just with a jump to the 0x0000_2000 address?

    void start_application( uint32_t app_link_location )

    {

       asm(" blx r0");

    }

    Because I have seen in other posts code like this inside the function:

    asm(" ldr r1, [r0,#0]"); // get the stack pointer value from the program's reset vector

    asm(" mov sp, r1");      // copy the value to the stack pointer asm(" ldr r0, [r0,#4]"); // get the program counter value from the program's reset vector

    asm(" mov r0, #0");

    asm(" blx r0");          // jump to the start address

    or even something like this avoiding the assembly:

    void jump_to_application( void )

    {

      typedef int(*fn_prt_t)(void);

      fn_prt_t main_prog;

      main_prog= (fn_prt_t)0x00002000;

      main_prog();

    }

    I would really appreciate any advice.

    Best regards,

    Iván

Reply
  • Hello everyone!

    I am also trying to write my own bootloader, so I am facing similar problems dealt in this post.

    One good question would be, when am I able to modify the VTOR? I say this because I init the bootloader as a normal application with its Interrupt Vector Table, and being the reset vector in 0x0000_0000, I pretend to do all the bootloader stuff and after finishing, modify VTOR register and jump to 0x0000_2000 (the bootloader has been configured with BOOTPROT 2, so 8K memory has been "protected" for this purpose). Is this possible? It is not working right now. I tried to modify VTOR before and after initializing the board (ATMEL R21 with a ARM CORTEX M0+).

    In order to modify the VTOR I do it like this:

    SCB->VTOR = ((uint32_t)0x00002000);

    But being the VTOR just from 32:7 won't it be better to do it like this?

    SCB->VTOR = ((uint32_t)0x00002000 << (SCB_VTOR_TBLOFF_Pos - 1)); // shift 7 to the left ARM Information Center

    After doing this (that is nor working), I pretend to jump to the application so... which considerations should I bear in mind? Would be enough just with a jump to the 0x0000_2000 address?

    void start_application( uint32_t app_link_location )

    {

       asm(" blx r0");

    }

    Because I have seen in other posts code like this inside the function:

    asm(" ldr r1, [r0,#0]"); // get the stack pointer value from the program's reset vector

    asm(" mov sp, r1");      // copy the value to the stack pointer asm(" ldr r0, [r0,#4]"); // get the program counter value from the program's reset vector

    asm(" mov r0, #0");

    asm(" blx r0");          // jump to the start address

    or even something like this avoiding the assembly:

    void jump_to_application( void )

    {

      typedef int(*fn_prt_t)(void);

      fn_prt_t main_prog;

      main_prog= (fn_prt_t)0x00002000;

      main_prog();

    }

    I would really appreciate any advice.

    Best regards,

    Iván

Children
No data