AT91Bootstrap is the 2nd level bootloader for Atmel AT91 SoC providing a set of algorithms to manage the hardware initialization such as clock speed configuration, PIO settings, DRAM initialization, to download your main application from specified boot media (NAND FLASH, serial FLASH (both AT25-compatible of DataFlash), serial EEPROM, SD Card, etc.) to main memory and to start it.

Boot strategies

AT91 chips embed a boot ROM code. It is enabled depending on BMS (Boot Mode Select) pin state on reset. The ROM code scans the contents of different media like serial FLASH, NAND FLASH, SD/MMC Card and serial EEPROM. If a valid application is available then it downloads this application into the chip internal SRAM and runs it. To determine if a valid application is present the ROM code checks the eight ARM exception vectors.

If no valid application is available then SAM-BA Monitor is executed. It waits for transactions either on the USB device, or on the DBGU serial port, then the SAM-BA tool can be used to program FLASH or EEPROM present on your board.

For more information on this topic, please check the corresponding SAM product datasheet section Boot Strategies.

ROM Code boot Sequence example

This is an example of boot sequence when BMS=1 taken from the sama5 product family:

sama5 boot sequence diagram

By programming BSC_CR register, we can bypass some steps in above sequence.

Pointing hand Note need a reset to make BSC_CR effective. And BSC_CR will be restored to factory value if power is removed.

Build AT91Bootstrap from sources

Setup ARM Cross Compiler

  • Ubuntu:
    In Ubuntu, you can install the ARM Cross Compiler by doing:
    sudo apt-get install gcc-arm-linux-gnueabi
    export CROSS_COMPILE=arm-linux-gnueabi-

  • Others:
    For others, you can download the Linaro cross compiler and setup the environment by doing:
    wget -c
    tar xf gcc-linaro-4.9-2014.11-x86_64_arm-linux-gnueabi.tar.xz
    export CROSS_COMPILE=`pwd`/gcc-linaro-4.9-2014.11-x86_64_arm-linux-gnueabi/bin/arm-linux-gnueabi-

Build AT91Bootstrap

This section describes how to get source code from the git repository, how to configure with the default configuration, how to customize AT91Bootstrap based on the default configuration and finally to build AT91Bootstrap to produce the binary. take the default configuration to download U-Boot from NandFlash for example.

Get AT91Boostrap Source Code

You can easily download AT91Bootstrap source code on the at91bootstrap git repository.

To get the source code, you should clone the repository by doing:

$ git clone git://
Cloning into 'at91bootstrap'...
remote: Reusing existing pack: 2476, done.
remote: Counting objects: 167, done.
remote: Compressing objects: 100% (167/167), done.
remote: Total 2643 (delta 135), reused 0 (delta 0)
Receiving objects: 100% (2643/2643), 2.06 MiB | 270 KiB/s, done.
Resolving deltas: 100% (1809/1809), done.
$ cd at91bootstrap/

Configure AT91Boostrap

Assuming you are at the AT91Bootstrap root directory, you will find a board/sama5d3xek folder which contains several default configuration files:


TIP Tips: nf means to read nandflash, df means to read serial flash, sd means to read mmc card.
TIP Tips: linux means to load linux kernel to RAM, android means to load android kernel to RAM, uboot means to load u-boot to RAM, dt means to load dtb to RAM.

You can configure AT91Bootstrap to load U-Boot binary from NAND flash by doing:

$ make mrproper
$ make sama5d3xeknf_uboot_defconfig
If the configuring process is successful, the .config file can be found at AT91Bootstrap root directory.

Customize AT91Bootstrap

If the default configuration doesn't meet your need, after configuring with the default configuration, you can customize it by doing:
$ make menuconfig
Now, in the menuconfig dialog, you can easily add or remove some features to/from AT91Bootstrap as the same way as kernel configuration.

Build AT91Bootstrap

Then you can build the AT91Bootstrap binary by doing:
$ make

If the building process is successful, the final .bin image is binaries/at91bootstrap.bin.

Program AT91Bootstrap binary into nandflash

Using SAM-BA to flash AT91Bootstrap to board

Launch SAM-BA tools

  • Start SAM-BA GUI application.
  • Select the board: "at91sama5d3x-ek" in the drop-down menu and choose the USB connection.

  • Click the "Connect" button, the SAM-BA main window show up:

Configure NAND ECC config

Programming AT91Bootstrap

  • Choose Send Boot File action, then press Execute button to select the at91bootstrap binary file and to program the binary to the NandFlash.

Using U-Boot to flash AT91Bootstrap

Setup PMECC header for different type of board

When ROM code load AT91Bootstrap in nandflash, at first ROM code will check the header to know what kind of ecc that binary is stored in nand.

So the header is made of 52 times the same 32-bit word, total in 0xd0 bytes, each 32-bit word in made in following format:

pmecc header

For different EK boards, the pmecc header is listed in following:

# at91sam9x5ek & at91sam9n12ek
# 2 bit pmecc in 512 byte sector, one page has 4 sectors, spare size: 64, ecc offset: 48
setenv pmecc_header 0xc0c00405

# sama5d3xek & sama5d3_xplained
# 4 bit pmecc in 512 byte sector, one page has 4 sectors, spare size: 64, ecc offset: 36
setenv pmecc_header 0xc0902405

# sama5d4ek & sama5d4 xplained
# 8 bit pmecc in 512 byte sector, one page has 8 sectors, spare size: 224, ecc offset: 120
setenv pmecc_header 0xc1e04e07

Load AT91Bootstrap binary and setup the 6th vector (offset is 0x14) as the file size

  • Following is U-Boot commands that can flash at91bootstrap to nand flash
    setenv load_addr 22000000                            # load_addr started by pmecc header
    setenv load_addr_bootstrap 220000d0                  # load_addr + 0xd0
    setenv load_addr_bootstrap_vector 220000e4           # load_addr + 0xd0 + 0x14
    setenv erase_bootstrap 'nand erase 0 10000'          # erase first 64k nand.
    setenv mmc_bootstrap_file 'boot.bin'                 # at91bootstrap file name in mmc card
    setenv load_mmc_bootstrap 'mw.b ${load_addr} 0xff 0x10000; mw.l ${load_addr} ${pmecc_header} 0x34; fatload mmc 0 ${load_addr_bootstrap} ${mmc_bootstrap_file};'
    setenv flash_bootstrap_from_mmc 'run erase_bootstrap; run load_mmc_bootstrap; mw.l ${load_addr_bootstrap_vector} ${filesize}; nand write ${load_addr} 0 0x10000;'
    setenv tftp_bootstrap_file 'u-boot/boot.bin'         # at91bootstrap file name in tftp server folder
    setenv load_tftp_bootstrap 'mw.b ${load_addr} 0xff 0x10000; mw.l ${load_addr} ${pmecc_header} 0x34;tftp ${load_addr_bootstrap} ${tftp_bootstrap_file};'
    setenv flash_bootstrap_from_tftp 'run erase_bootstrap; run load_tftp_bootstrap; mw.l ${load_addr_bootstrap_vector} ${filesize}; nand write ${load_addr} 0 0x10000;'

  • Now we can run following commands to programming at91bootstrap to nandflash in U-Boot:
    run flash_bootstrap_from_tftp or run flash_bootstrap_from_mmc

Known Issues

About the latest version, some issues are found not fixed, please see the document KNOWN ISSUES with the project.

Recent FAQ


SDCard Boot Notice: How to boot up the board from SD card. (Sama5d2Xplained, Sama5d4Xplained, Sama5d4ek, Sama5d3Xplained, Sama5d3xek, AT91sam9x5-ek)
AT91 Bootstrap Debug Eclipse: Debug AT91Bootstrap. (Sama5d4Xplained, Sama5d4ek, Sama5d3Xplained, Sama5d3xek)
Topic attachments
I Attachment Action Size Date Who Comment
PNGpng nvm_boot_sequence.png manage 39.8 K 2015-05-19 - 03:31 JoshWu  
PNGpng pmecc_header_format.png manage 15.4 K 2015-05-19 - 03:32 JoshWu  
r73 - 15 Sep 2015 - 14:36:39 - NicolasFerre
Linux & Open Source related information for AT91 Smart ARM Microcontrollers

Copyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.

Linux® is the registered trademark of Linus Torvalds in the U.S. and other countries.

Atmel® and others, are registered trademarks or trademarks of Atmel Corporation or its subsidiaries. This site is powered by the TWiki collaboration platform

ARM® and others are registered trademarks or trademarks of ARM Ltd. Other terms and product names may be trademarks of others.

Ideas, requests, contributions ? Connect to LinksToCommunities page.

Syndicate this siteRSS ATOM