at91bootstrap: A Second Stage Bootloader for Microchip MPUs
Introduction
This training topic describes at91bootstrap, a second-stage bootloader for Microchip Technology Arm®-based microprocessors (MPU), where to get the source code, how to configure and compile it, and how to write it to mass storage (external Non-Volatile Memory (NVM)) for booting.
The at91bootstrap bootloader is stored in an external NVM (SD Memory Card, MultiMedia Card (MMC), Embedded MultiMedia Card (e.MMC), NAND Flash, Serial Flash, NOR Flash). The first-stage bootloader (contained in the ROM Boot Code of the MPU) will load at91bootstrap from external NVM depending on its configuration. Refer to the device datasheet for specific details on their boot strategies. Additional information is available at:
If configured to do so, at91bootstrap will initialize the following peripherals and memory controllers:
- Advanced Interrupt Controller (AIC)
- Peripheral I/O Controller (PIO)
- Power Management Controller (PMC)
- Clock Generator (CKGR)
- Static Memory Controller (HSMC)
- NAND Flash Controller (NFC)
- Multiport DDR-SDRAM Controller (MPDDRC)
- Secure Digital MultiMedia Card Controller (SDMMC)
at91bootstrap can be configured to:
- Download and jump to the third-stage bootloader (for example, Das U-Boot or BusyBox)
- Download and jump to the Linux® kernel directly, thus it does not require a third-stage bootloader
- Download and jump to a Real Time Operating System (RTOS)
- Download and jump to the debugger (JTAG)
- Configure peripherals and wait for a debugger to take over the JTAG
- Configure peripherals and jump to your main program
at91bootstrap is written and maintained by Microchip Technology and hosted on GitHub.
Prerequisites
Cross Toolchain
A working cross-toolchain for Arm-based MPU targets is required to complete this topic.
Boot Process
Knowledge of the Boot Process is required as this topic discusses the second-stage bootloader.
Also, see:
- SAMA5D2 Series Datasheet (Section 16 – Boot Strategies)
- SAM9X60 Datasheet (Section 12 – Boot Strategies)
- SAMA7G5 Series Datasheet (Section 19 - Boot Strategies)
Git
If you are new to git there are many online resources. One such resource is the online book Pro Git by Scott Chacon and Ben Straub. It is available in several languages and you can also download the book in eBook formats (EPUB and MOBI) and PDF.
Another excellent resource is the Learn Git tutorial by Atlassian.
Git documentation is also available.
Download - Getting at91bootstrap Source Code
Create a Project Directory
It is a good practice to create a project directory to place the source code for a given project. In this way, you can archive the contents so that you may give them to other developers and/or for archival purposes.
For the purposes of this tutorial topic, we’ll name our project directory project_1:
Get at91bootstrap
You will get at91bootstrap by copying (git clone) the source code from a remote repository to your project directory:
Change the directory to the project directory:
Copy (git clone) the at91bootstrap source code to your project directory:
The result of this command will be a copy of at91bootstrap on your host computer with the following directory structure:
|-- at91bootstrap/
|-- board/
|-- config/
|-- contrib/
|-- driver/
|-- fs/
|-- host-utilities/
|-- include/
|-- lib/
|-- scripts/
|-- README.txt##
Checkout Branch
Once you have cloned at91bootstrap to your project directory, it will contain several branches (versions). You can view all the available branches by issuing a git tag command.
5series_1.0
5series_1.1
5series_1.2
5series_1.3
.
.
v3.9.1
v3.9.1
v3.9.2
v3.9.2-mplabx
v3.9.2-rc1
v3.9.2-rc2
v3.9.3
Since you just cloned the remote repository, the HEAD pointer is pointing to the “master” branch. Think of “master” as the “default” branch after cloning and informs you that it has not diverged from the same branch that is on the GitHub repository. You can see this by issuing a git status command:
On branch master
Your branch is up-to-date with "origin/master".
nothing to commit, working tree clean
The results of this command is to check out the latest branch (version) that was observed when you issued the git tag command above. The -b switch causes a new branch of the name <temp_branch> to be created. Now, when you issue a git status command:
On branch <temp_branch>
Nothing to commit, working tree clean
Updating at91bootstrap Source Code
If during development you require an updated copy of at91bootstrap, you can issue the git pull command:
The results of this command will be to copy updated files from the at91bootstrap GitHub repository and merge them into your project directory.
Dependencies
Starting with version 3.9.3, at91bootstrap requires Python 3.x.y (python3). This is required for the scripts generating the PMECC headers for NAND Flash memories.
Configure Using a Default Configuration
Once you have cloned at91bootstrap to your project directory, the next step is to configure the files for building. In this section, you will use a default configuration file supplied by Microchip Technology.
Default configuration (defconfig) files are provided for the many evaluation kits sold by Microchip. They are located in the /project_1/at91bootstrap/board/ directory. At this level you will see directories arranged by processor model/type:
|-- at91bootstrap/
|-- board/
|-- at91sam9260ek/
|-- at91sam9261ek/
|-- at91sam9263ek/
|-- at91sam9g10ek/
|-- at91sam9g20ek/
|-- at91sam9m10g45ek/
|-- at91sam9n12ek/
|-- at91sam9rlek/
|-- at91sam9x5ek/
|-- at91sam9xeek/
|-- sam9x60_ddr2_sip_eb/
|-- sam9x60ek/
|-- sam9x60_sdr_sip_eb/
|-- sama5d27_som1_ek/
|-- sama5d27_wlsom1_ek/
|-- sama5d2_icp/
|-- sama5d2_lpddr2sip_vb/
|-- sama5d2_ptc_ek/
|-- sama5d2_xplained/
|-- sama5d3x_cmp/
|-- sama5d3xek/
|-- sama5d3_xplained/
|-- sama5d4ek/
|-- sama5d4_xplained/
|-- config/
|-- contrib/
|-- driver/
|-- fs/
|-- host-utilities/
|-- include/
|-- lib/
|-- scripts/
|-- README.txt
As you enter the processor model/type directory, you will see default configuration files for each of the evaluation kits. The following is an example showing the ATSAMA5D27-SOM1-EK1 evaluation kit:
|-- at91bootstrap/
|-- board/
|-- sama5d27_som1_ek/
|-- sama5d27_som1_ekqspi_linux_image_dt_defconfig
|-- sama5d27_som1_ekqspi_uboot_defconfig
|-- sama5d27_som1_eksd1_uboot_defconfig
|-- sama5d27_som1_eksd_linux_image_dt_defconfig
|-- sama5d27_som1_eksd_uboot_defconfig
The files are annotated with the choice of location of external boot memory. In the case of the ATSAMA5D27-SOM1-EK1 evaluation kit, you can boot at91bootstrap from either NOR Flash memory (qspi) or SD Memory Card (sd).
Legend:
- qspi– NOR Flash Memory
- sd– SD Memory Card
- If no number is given, boot from port 0
- If number is given, boot from indicated port (for example, 1 = port 1)
- nf– NAND Flash Memory
- df – Serial/DataFlash™ Memory
The default configure files are also annotated with the choice of what at91bootstrap will load next: either a third-stage bootloader (uboot) and/or application (linux_image_dt).
Legend:
- uboot– Third-Stage Bootloader
- linux_image_dt– Linux kernel and Device Tree
Default Configure at91bootstrap
The following are the steps to configuring at91bootstrap using a default configuration file.
Change the directory into the at91bootstrap directory:
Configure at91bootstrap for the desired evaluation board and boot/application settings.
For this example, we will boot at91bootstrap from the SD Memory Card on port 0 and load the third-stage bootloader, U-Boot:
$ make sama5d27_som1_eksd_uboot_defconfig
You may customize the default configuration setting using menuconfig:
Menuconfig allows you to view the settings of the default configuration and it also allows you to make any customization. We go into more detail in the next section.
You may exit menuconfig by repeatedly typing ESC-ESC.
Build at91bootstrap:
The results of the build will be a binary (*.bin) image that can be written to the external memory device selected during configuration. The *.elf image is used by a debugger.
$ ls -l
at91bootstrap.bin -> sama5d27_som1_ek-sdcardboot-uboot-3.9.3.bin
boot.bin -> sama5d27_som1_ek-sdcardboot-uboot-3.9.3.bin
sama5d27_som1_ek-sdcardboot-uboot-3.9.3.bin
sama5d27_som1_ek-sdcardboot-uboot-3.9.3.elf
sama5d27_som1_ek-sdcardboot-uboot-3.9.3.map
Note the resulting binary image is named sama5d27_som1_ek-sdcardboot-uboot-3.9.3.bin. There are two symbolic links at91bootstrap.bin and boot.bin pointing to it.
In the next section, you will be shown the steps required to write boot.bin to an external NVM memory.
Writing boot.bin to External NVM Memory
Once boot.bin has been configured and built, it can be written to Mass Storage memory (external NVM memory). Below are links for how to write to various external NVM memories on evaluation kits and using the SAM-BA® In-System Programmer utility program.
SAM-BA In-System Programmer
- Program External NAND Flash Memory (nandflash)
- Program External QSPI NOR Flash Memory (qspiflash)
- Program High Speed Multimedia Card Interface (HSMCIx) or Secure Digital Multi-Media Card (SDMMCx) (sdmcc)
ATSAMA5D27-SOM1-EK1 Evaluation Kit
- ATSAMA5D27-SOM1-EK1 - Booting a Linux Image
- ATSAMA5D27-SOM1-EK1 - Booting from NOR Flash (QSPI) Memory
SAM9X60-EK Evaluation Kit
- SAM9X60-EK - Booting Demo Linux Image
- SAM9X60-EK - Booting from NAND Flash Memory
- SAM9X60-EK - Booting from NOR Flash (QSPI) Memory
- SAM9X60-EK - Booting from SD Memory Card
- SAM9X60-EK - Configure and Build at91bootstrap for a MPLAB® Harmony 3 Project with MPLAB X IDE
- SAM9X60-EK - Configure and Build at91bootstrap to Load an MPLAB® Harmony 3 Application from NAND Flash Memory
- SAM9X60-EK - Writing MPLAB® Harmony 3 Application and at91bootstrap to NAND Flash Memory Using SAM-BA ISP
- SAM9X60-EK - Configure and Build at91bootstrap to Load an MPLAB® Harmony 3 Application from NOR Flash (QSPI) Memory
- SAM9X60-EK - Writing MPLAB® Harmony 3 Application and at91bootstrap to NOR Flash (QSPI) Memory using SAM-BA ISP
- SAM9X60-EK - Configure and Build at91bootstrap to Load an MPLAB® Harmony 3 Application from SD Memory Card
- SAM9X60-EK - Copy MPLAB® Harmony 3 Application and at91bootstrap to SD Memory Card
SAM9X60-Curiosity Development Board
- SAM9X60-Curiosity - Booting Demo Linux Image
- SAM9X60 Curiosity - Configuring and Building at91Bootstrap with MPLAB® X IDE for an MPLAB® Harmony 3 Project
Additional Resources
Summary
In this training topic, you learned about the at91bootstrap program, what it is, where to get it, and how to configure, build, and write it to external NVM.