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 / execute programm in nor flash

Hello,

I'm working with the AT91SAM9361 controller.
Moreover I installed a nor flash (where the real program is stored) and a small data flash (where a small bootloader is stored. Among other things, the bootloader should check if the arm vectors (at the beginning of each code) are valid). If this code is valid the program stored in the nor flash should be executed.

I want to use two seperate memories, so that everyone is able to load a new update of the real program via the bootloader in the dataflash in the nor flash.

How is it possible to start the application from the bootloader in the nor flash? Do I have to set the PC to the beginning of the nor flash? Which are the steps to execute this programm?

I'm not working with an operating system.

best regards
Hans

Parents
  • thanks for your help.

    copy the complete vector table (first 64 bytes) from NOR Flash to SRAM
    the only thing I don't understand is how could I copy the first 64Byte from the nor flash to the internal sram, if the bootloader from the data flash is already at 0x00?

    
    //copy from 0x10000000 to 0x00000000 (range 0x20)
    
    //jump to 0x10000000 or 0x10000020?
    
    

    And what about the first 64 Bytes? I thought I've only to copy the first 32Byte (arm vectors) to the internal RAM?

    best regards
    Hans

Reply
  • thanks for your help.

    copy the complete vector table (first 64 bytes) from NOR Flash to SRAM
    the only thing I don't understand is how could I copy the first 64Byte from the nor flash to the internal sram, if the bootloader from the data flash is already at 0x00?

    
    //copy from 0x10000000 to 0x00000000 (range 0x20)
    
    //jump to 0x10000000 or 0x10000020?
    
    

    And what about the first 64 Bytes? I thought I've only to copy the first 32Byte (arm vectors) to the internal RAM?

    best regards
    Hans

Children
  • ok the bootloader in the data flash works.

    But could you tell me the way I have to write the jump instruction?

    I copy the first 32Bytes (arm vectors) to 0x00000000 with memcpy()

    
    int main(void)
    {
       void (*functionptr)( void ) = 0x0;
       //...
    
       //copy the arm vectors
       memcpy((char *)0x00000000, (char *)(0x10000000), 32);
    
       //generate jump instruction to 0x10000000????
    
    
    
       //jump to 0x00000000
       functionptr();
       return 0;
    }
    

    The problem is that I have to place the jump instruction behind the last arm vector and I don't know how to do that...

    
    __asm {
    
      //JMP 0x10000000
    }
    
    

    best regards
    Hans

  • how could I copy the first 64Byte from the nor flash to the internal sram, if the bootloader from the data flash is already at 0x00?

    Bootloader already executed remap and now SRAM is at address 0. So copying should be performed like:

    //copy from 0x10000000 to 0x00000000 (range 0x40)
    

    And then the user code can be executed:

    //jump to 0x10000000 or 0
    

    And what about the first 64 Bytes? I thought I've only to copy the first 32Byte (arm vectors) to the internal RAM?

    8 vectors (32 bytes) are actually LDR instructions which use addresses located after the vectors (another 32 bytes). Therefore you need to copy the first 64 bytes.

  • thank you for your explanations. At the moment the programm code in the nor flash won't work.

    That's my programm which runs in the internal RAM (executed from the data-flash)and should start the nor-flash application. Could you see some errors?

    
    int main(void)
    {
            void (*functionptr)( void ) = (void (*)(void))0x10000000;
    
            //led
            led();
    
    
            //copy first 64Bytes to 0x0 (START_ADDR)
            memcpy((char *)START_ADDR, (char *)(AT91_NORFLASH_BASE), 64);
             //Norflash-Base: 0x10000000
    
            functionptr();
    
            return 0;
    }
    

    best regards
    Hans

  • I made a test and it seems that it should work. I load a small programm in the internal RAM so that I could see what the processor is doing.

    The internal RAM is at 0x00200000

    1. copy the 64Bytes at the beginning of the internal RAM

    memcpy((char *)0x00200000, (char *)(0x10000000), 64);
    

    2. functionsptr() //to 0x10000000

    The PC jump to 0x10000000 and then to 0x10000058 (after the last vectors EAFFFFFE B...)

    When I run the programm I get a lof of "JTAG Communication Failure" error messages.

    best regards
    Hans

  • Hi,

    now I'm able to run the programm! The error was within the startup script. You have to disable the pll, because if the pll is already started, plls will be turned off!

    I find this message in the atmel startup file. Maybe it would be a great thing if Keil could add some comments to their files, too!

    best regards
    Hans