AT91SAM9261 boot code for embOS + NOR Flash?

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • AT91SAM9261 boot code for embOS + NOR Flash?

    Hi Segger folks,

    I'm trying to boot a custom board based on the Atmel AT91SAM9261. I have a 16-bit NOR flash on CS0 which appears to work (I can boot into a GPIO toggler application running directly out of Flash) but I'm not sure how to get booted into the embOS environment. I'm using the IAR development environment.

    My attempts to boot from flash have yielded an unresponsive board. When I reattach to it with the J-Link, it appears to be stuck in a loop hitting the undefined instruction exception vector repeatedly.

    Is there any sample code that shows booting from NOR flash, copying the application into internal SRAM, and remapping?

    Thanks much.

    Michael
  • Atmel AT91SAM9261 NOR boot code

    Hi mtconnol,

    To do this, you need to do several steps:
    1. Modify the link file.
      Since we want to copy the application into internal SRAM, we must reserve some RAM for this.
      Therefore the DATA segments is after this area.

      C Source Code

      1. //*************************************************************************
      2. // XLINK command file for AT91SAM9261 using an external NOR flash
      3. //
      4. // Usage: xlink -f lnkarm <your_object_file(s)>
      5. // -s <program start label> <C/C++ runtime library>
      6. //
      7. //*************************************************************************
      8. //*************************************************************************
      9. -carm
      10. //
      11. // These settings are used for link the application.
      12. //
      13. -DROMSTART=00000000
      14. -DROMEND=00028000
      15. //
      16. // Define the internal SRAM.
      17. //
      18. -DIRAM_START=00300000
      19. -DIRAM_SIZE=28000
      20. -DIRAM_END=(IRAM_START+IRAM_SIZE-1)
      21. //
      22. // Define the external SDRAM.
      23. //
      24. -DSDRAMSTART=20000000
      25. -DSDRAM_SIZE=4000000
      26. -DSDRAMEND=(SDRAMSTART+SDRAM_SIZE-1)
      27. //
      28. // These defines are used for copying the code from ROM to RAM.
      29. // We reserve 1/2 of the SRAM for this. (80kByte)
      30. //
      31. -DRAMCODE_START=IRAM_START
      32. -DRAMCODE_SIZE=14000
      33. -DRAMCODE_END=(RAMCODE_START+RAMCODE_SIZE-1)
      34. //
      35. // Read/Write segments are after the reserved "RAMCode segement".
      36. // You can alternatively use the external SDRAM for this.
      37. // This will look like this:
      38. // -DRAMSTART=SDRAMSTART
      39. // -DRAMEND=SDRAMEND
      40. //
      41. -DRAMSTART=(RAMCODE_END+1)
      42. -DRAMEND=IRAM_END
      43. //*************************************************************************
      44. // Address range for reset and exception
      45. // vectors (INTVEC).
      46. // The vector area is 32 bytes,
      47. // an additional 32 bytes is allocated for the
      48. // constant table used by ldr PC in cstartup.s79.
      49. //*************************************************************************
      50. -Z(CODE)PROGRAM_START=ROMSTART-ROMEND
      51. -Z(CODE)INTVEC=ROMSTART-ROMEND
      52. //*************************************************************************
      53. // Startup code and exception routines (ICODE).
      54. //*************************************************************************
      55. -Z(CODE)ICODE,DIFUNCT=ROMSTART-ROMEND
      56. -Z(CODE)SWITAB=ROMSTART-ROMEND
      57. -Z(CODE)RAMCODE=RAMCODE_START-RAMCODE_END
      58. //*************************************************************************
      59. // Code segments may be placed anywhere.
      60. //*************************************************************************
      61. -Z(CODE)CODE=ROMSTART-ROMEND
      62. //*************************************************************************
      63. // Various constants and initializers.
      64. //*************************************************************************
      65. -Z(CONST)INITTAB,DATA_ID,DATA_C=ROMSTART-ROMEND
      66. -Z(CONST)CHECKSUM=ROMSTART-ROMEND
      67. -Z(CONST)PROGRAM_END
      68. //*************************************************************************
      69. // Data segments.
      70. //*************************************************************************
      71. -Z(DATA)DATA_I,DATA_Z,DATA_N=RAMSTART-RAMEND
      72. //*************************************************************************
      73. // __ramfunc code copied to and executed from RAM.
      74. //*************************************************************************
      75. -Z(DATA)CODE_I=RAMSTART-RAMEND
      76. -Z(CONST)CODE_ID=ROMSTART-ROMEND
      77. -QCODE_I=CODE_ID
      78. //*************************************************************************
      79. // ICCARM produces code for __ramfunc functions in
      80. // CODE_I segments. The -Q XLINK command line
      81. // option redirects XLINK to emit the code in the
      82. // debug information associated with the CODE_I
      83. // segment, where the code will execute.
      84. //*************************************************************************
      85. //*************************************************************************
      86. // Stack and heap segments.
      87. //*************************************************************************
      88. -D_CSTACK_SIZE=(100*4)
      89. -D_IRQ_STACK_SIZE=(8*8*4) // 8 nesting levels, 8 registers saved, 4 bytes each
      90. // System and IRQ stack should reside in internal RAM if possible
      91. -Z(DATA)CSTACK+_CSTACK_SIZE=RAMSTART-RAMEND
      92. -Z(DATA)IRQ_STACK+_IRQ_STACK_SIZE=RAMSTART-RAMEND
      93. //*************************************************************************
      94. // ELF/DWARF support.
      95. //
      96. // Uncomment the line "-Felf" below to generate ELF/DWARF output.
      97. // Available format specifiers are:
      98. //
      99. // "-yn": Suppress DWARF debug output
      100. // "-yp": Multiple ELF program sections
      101. // "-yas": Format suitable for debuggers from ARM Ltd (also sets -p flag)
      102. //
      103. // "-Felf" and the format specifiers can also be supplied directly as
      104. // command line options, or selected from the Xlink Output tab in the
      105. // IAR Embedded Workbench.
      106. //*************************************************************************
      107. // -Felf
      Display All

    2. Copy your embOS application into internal SRAM.
      We can do that in __low_level_init().
      Add following lines to your __low_level_init() after PLL initialization:

      C Source Code

      1. {
      2. #define MATRIX_MCFG (*(volatile unsigned long *)(0xFFFFEE00))
      3. #pragma segment="RAMCODE"
      4. #pragma segment="PROGRAM_START"
      5. #pragma segment="PROGRAM_END"
      6. void * pSrc = __sfb("RAMCODE");
      7. void * pDest = __sfb("PROGRAM_START");
      8. OS_U32 Size = (int)((OS_U8 *)__sfb("PROGRAM_START") - (OS_U8 *)__sfb("PROGRAM_END"));
      9. //
      10. // Copy ROM to internal SRAM
      11. //
      12. memcpy(pDest, pSrc, Size);
      13. //
      14. // Remap internal SRAM to 0
      15. //
      16. MATRIX_MCFG = 0x03;
      17. }
      Display All

    Let me know if this solves your problem.

    Souhail