In this topic, you will create a custom project in Buildroot so you can create binary image files ready to flash into mass storage for your target hardware. For this tutorial, our target hardware is the ATSAMA5D27-SOM1-EK1 Evaluation Kit which will use an SD Memory Card for its mass storage.
This topic will show you how to maintain your project-specific files and customizations outside of the main Buildroot file structure. This method has the advantage of keeping project-specific files separated from the main Buildroot tree while integrating them seamlessly into the build process. This method is called the br2_external mechanism.
As part of this process, you will download a pre-built, cross-compilation toolchain. This is known as "Buildroot’s external toolchain option". This has the advantage of using a well-known and tested cross-compilation toolchain as well as significantly reducing the overall build time.
You have downloaded Buildroot following the instructions in the topic: "Buildroot – Clone with Git".
Before you build a project in Buildroot, ensure you have the mandatory software packages required. Mandatory and optional packages required by Buildroot are listed in the "Buildroot User Manual": "System Requirements".
Buildroot uses the make utility and shell scripts to operate. There are helpful tips listed in the "Buildroot User Manual": "Make Tips".
Once you have downloaded Buildroot, the next step in the process is to create a project directory to maintain your project files outside of the Buildroot directory.
Buildroot recommends a directory structure outlined in the "Buildroot User Manual": "Recommended Directory Structure". You create this directory structure outside of the main Buildroot directory. Later, during the configuration process, you will tell Buildroot the location of this directory.
You will be creating the br2_external tree structure shown below in the following steps:
/my_br2_tree/ +-- board/ | +-- <company>/ | +-- <boardname>/ | +-- configs/ | +-- <boardname>_defconfig | +-- Config.in +-- external.mk +-- external.desc
Additional detail about the tree structure can be found in the "Buildroot User Manual": "Keeping Customizations Outside of Buildroot".
$ cd ~/project_1
$ mkdir my_br2_tree$ cd my_br2_tree
For this tutorial, we’ll name our br2_external directory my_br2_tree. For your custom project you would choose a unique name for the directory.
$ mkdir configs
The configs directory is used to store Buildroot default configuration (_defconfig) files in the br2_external tree.
$ touch Config.in$ touch external.mk
Both Config.in and external.mk will remain empty for this tutorial. They can be used to define package recipes or other custom configuration options or make logic.
name: my_br2_tree desc: Example br2_external tree
Buildroot uses the external.desc text file to identify and differentiate multiple br2_external directories. Therefore, the names must be unique.
name defines the name for the br2_external directory. It is mandatory. Buildroot uses name to set the variable BR2_EXTERNAL_$(NAME)_PATH to the absolute path of the my_br2_tree directory.
desc provides a short description for the br2_external directory and is used to display information about the directory. It is optional.
$ mkdir -p board/company_1/board_1
The board directory can be used to store board-specific configuration files such as the kernel configuration, the root filesystem overlay, or any other configuration file for which Buildroot allows you to set the location (by using the BR2_EXTERNAL_$(NAME)_PATH variable).
Once you have created your br2_external tree structure to maintain your project files outside of the Buildroot directory, your next step is to configure the project.
When you downloaded Buildroot, you also downloaded external files maintained by Microchip Technology called buildroot-external-microchip.
$ cd ~/project_1/buildroot
$ make BR2_EXTERNAL=~/project_1/buildroot-external-microchip:~/project_1/my_br2_tree menuconfig
This command to the make utility will set the BR2_EXTERNAL variable to the path of the external tree(s). If there are multiple external trees (as this tutorial does), separate the paths by a colon (“:”).
Target options select the MPU architecture of the embedded device and enables/disables features.
You may notice that the default architecture settings are for i386. You will be changing this to the SAMA5D2 Series ARM®-based MPU architecture.
| Target Architecture | (ARM (little endian)) | |
| Target Binary Format | (ELF) | |
| Target Architecture Variant | (cortex-A5) | |
| [*] | Enable NEON SIMD extension support | |
| [*] | Enable VFP extension support | |
| Target Application Binary Interface (ABI) | (EABIhf) | |
| Floating point strategy | (VFPv4-D16) | |
| ARM instruction set | (ARM) |
After completing the settings, the Target Options submenu will look like:

The Build Options submenu selects options that Buildroot will use to download and build the packages and files needed by the host and the target.
The first line below the Commands —> entry is the save location of the Buildroot default configuration files. Enter:
$(BR2_EXTERNAL_my_br2_tree_PATH)/configs/project_1_defconfig
The second line below the Commands —> entry is the save location of the target packages and files that Buildroot will download for the build. This directory will contain all of the upstream projects as a compressed archive (*.tar.gz) files.
We see the default location $(TOPDIR)/dl is entered. Recall that you can type the make printvars command:
$ make -s printvars VARS=’TOPDIR’
TOPDIR=/home/steve/project_1/buildroot
to see the expanded directory.
The third line below the Commands —> entry is the save location of the packages and files Buildroot will download, build, and run on the host. This includes the cross-compilation toolchain when building the internal Buildroot toolchain.
We see the default location $(BASE_DIR)/host is entered. Recall that you can type the make printvars command:
$ make -s printvars VARS=’BASE_DIR’
BASE_DIR=/home/steve/project_1/buildroot/output
to see the expanded directory.
After completing the settings, the "Build Options" submenu will look like:

Buildroot provides two solutions for the cross-compilation toolchain:
To learn more you can read about Cross-compilation toolchain in the Buildroot manual.
The Toolchain submenu opens as shown in the figure below.

Once selected, the menu will expand.
Step a: Select Toolchain ( ) and select Linaro ARM 2018.05.
Step b: Select Toolchain Origin ( ) and select Toolchain to be downloaded and installed.
After completing the settings, the Toolchain submenu will look like this:

The System configuration submenu selects options for the system such as which INIT to run, root login, root password, and login prompt. It also supports scripts that may be run during the build.
You can enter the name of the target’s hostname and system banner:
| (buildroot) | System hostname | . |
| (Welcome to Buildroot) | System banner | . |
You can choose the INIT system:
| . | Init system | (BusyBox) |
You can enable/disable root login, set the root password, and enable a login prompt.
| [*] | Enable root login with password | . |
| ( ) | Root password | . |
| [*] | Run a getty (login prompt) after boot —> | . |
Note that the default selection the root login has been enabled with no password required.
Select the last line of the system configuration: Custom scripts to run after creating filesystem images and enter the text string:
support/scripts/genimage.sh
This shell script is located in the main Buildroot directory.
Once entered, a new configuration option is displayed: Extra arguments passed to custom scripts and enter the text string:
-c $(BR2_EXTERNAL_MCHP_PATH)/board/microchip/sama5d27_som1_ek/genimage.cfg
This configuration file is located in the buildroot-external-microchip files.
After completing the settings, the System Configuration submenu will look like:

The Kernel submenu selects the Linux kernel, the location to download the kernel source and options in the build process.
By default, the Linux kernel is not selected.

Once selected, the menu will expand.
Step a: Select Kernel Version and check Custom Git Repository.
Step b: Select URL of custom repository and enter:
https://github.com/linux4sam/linux-at91.git
Step c: Select Custom Repository Version and enter linux4sam_6.0.
Step a: Select Kernel configuration and select Using an in-tree defconfig file.
Step b: Select Defconfig name and enter sama5.
Step a: Select Build a Device Tree Blob (BTD).
Step b: Select In-tree Device Tree Source file names and enter:
at91-sama5d27_som1_ek
After completing the settings, the Kernel submenu will look like:

The Target Packages submenu opens as shown in the figure below. The Target Packages submenu selects from over 2000+ software packages. The submenu lists them by category. For example, Audio and Video, Games, Networking Applications, etc.
At this step, you would select the software packages you require for your custom project.
The Filesystem Images submenu selects the filesystem type and options.
By default, no filesystem is selected. This is by design as your choice of file system depends on your project hardware memory architecture and type.
Once selected, the menu will expand.
After completing the settings, the Filesystem Images submenu will look like:

The Bootloaders submenu opens as shown in the figure below. The Bootloaders submenu selects and configures the choice of bootloaders Buildroot will build.
The Bootloaders submenu opens as shown in the figure below.

Once selected, the menu will expand.
Step a: Select AT91 Bootstrap 3 version.
Select Custom Git Repository.
Step b: Select URL of custom repository.
Enter:
https://github.com/linux4sam/at91bootstrap.git
Step c: Select Custom repository version.
Enter:
v3.8.12
Step d: Select AT91 Bootstrap 3 configuration.
Select Using a defconfig.
Step e: Select Defconfig name.
Enter:
sama5d27_som1_eksd_uboot
This completes the selections for the AT91Bootstrap bootloader.
Once selected, the menu will expand.
Step a: Select Build system.
Select Kconfig.
Step b: Select U-Boot Version.\
Select Custom Git repository.
Step c: Select URL of Custom Repository.
Enter:
https://github.com/linux4sam/u-boot-at91.git
Step d: Select Custom Repository Version.
Enter:
linux4sam_6.0
Step e: Select U-Boot configuration.
Select Using an in-tree board defconfig file.
Step f: Select Board defconfig.
Enter:
sama5d27_som1_ek_mmc
Step g: Select U-Boot needs dtc.
Step h: Select Environment Image - - - -.
Once the entry has been selected, the - - - - changes to a - - - > indicating that more information can be entered.
Select ( ) Source files for environment and enter:
$(BR2_EXTERNAL_MCHP_PATH)/board/microchip/sama5d27_som1_ek/uboot-env.txt
Select ( ) Size of environment and enter:
0x4000
This completes the selections for the U-Boot bootloader.
After completing the settings, the Filesystem Images submenu will look like:


The Host Utilities submenu opens as shown in the figure below. The Host Utilities submenu selects utility programs that the host will need to build the target’s binary images.
The host dosfstools utility for creating and checking DOS FAT filesystem. It is needed by the genimage to assist in generating flash images.
The host genimage utility to generate flash images from a given root filesystem tree.
The host mtools utility to access DOS disks from Unix without mounting them. It is needed by the genimage to assist in generating flash images.
Once selected, the menu will expand.
Select [ ] Flattend Image Tree (FIT) support.
The host u-boot tools are companion tools for the U-Boot bootloader.
After completing the settings, the Host Utilities submenu will look like:



The Legacy config options submenu allows the developer to select software that has been removed in the present version of Buildroot. This submenu makes it convenient for the developer to maintain backward compatibility.
The Legacy config options submenu opens.
Feel free to browse. However, as mentioned, it is for backward compatibility. Generally, you will have no selections unless absolutely necessary.
The External Options submenu displays options available in the br2_external tree(s) that Buildroot knows about.
The External Options submenu opens as shown in the figure below.

You are now viewing the available packages in the buildroot-external-microchip directory.
Once selected, the menu will expand.
Select ( ) platform name and enter:
sama5d27_som1_ek
After completing the settings, the External Options submenu will look like:

At this point, your project-specific configuration is stored as .config in the ~/project_1/buildroot directory.
To save your project-specific configuration as a default configuration (_defconfig) file:
$ make savedefconfig
Recall that you told Buildroot, under the Build options submenu, the location to save the _defconfig file:
$(BR2_EXTERNAL_my_br2_tree_PATH)/configs/project_1_defconfig
In this topic, we explained how to create a project-specific Buildroot environment. You began by downloading Buildroot and any external files (buildroot-external-microchip) into a project directory (project_1). Then you created a project-specific directory (my_br2_tree) with the necessary files required by Buildroot. Next, you configured the project using the graphical menu command, menuconfig. Finally, once you completed and saved your configuration, you created a project-specific _defconfig file.
Once Buildroot has been configured, the next step is to build the binary image(s) for the system, in this case, the ATSAMA5D27-SOM1-EK1 Evaluation Kit. Instructions are available at Buildroot – Build.