Step 3.1: Create a BR2_EXTERNAL Tree Structure
The “Recommended directory structure” section of the Buildroot user manual contains the recommended directory structure which will be created outside the main Buildroot directory.
For this project, we will name our BR2_EXTERNAL directory as my_external_tree.
- Create a directory for the BR2_EXTERNAL outside the main Buildroot directory using the following commands:
$ cd ~/project
$ mkdir my_external_tree
We will be creating the BR2_EXTERNAL tree structure shown below in the following steps:
/my_external_tree/
| +-- board/
| +-- my_company/
| +-- my_board/
|
| +-- configs/
| +-- package/
| +-- patches/
|
| +-- Config.in
| +--external.mk
| +-- external.desc
- Change directory to my_external_tree
$ cd my_external_tree
- Create the necessary files for the BR2_EXTERNAL using the following command:
$ touch Config.in external.mk external.desc
- Create the other subfolders within my_external_tree using the following command:
$ mkdir configs package patches -p board/my_company/my_board
my_company and my_board may be replaced with your desired directory names. For this project, we will simply name them as such.
Step 3.2: Configure BR2_EXTERNAL
- Add a basic description of the project within external.desc using your preferred text editor. For this tutorial, we will use nano as shown:
$ nano external.desc
You can use a different text editor such as Gedit. In that case, replace nano with gedit in the command above. The steps below assume the use of nano unless otherwise stated.
- The external.desc contents should contain the following information:
name: <external_tree_name>
desc: <Your project description>
- <external_tree_name> may be replaced with the desired name for your BR2_EXTERNAL. For this project, my_external_tree can be used. The <external_tree_name> is case-sensitive and will be used by packages from the external tree
- The name property must be unique if multiple external trees are referenced by the BR2_EXTERNAL variable
- Use Ctrl+X to quit nano editor then press “Y” to save file and then Enter to save changes to external.desc file
- The BR2_EXTERNAL will be referenced by Buildroot as shown based on the name value given above:
“$(BR2_EXTERNAL_external_tree_name_PATH)/…”
Step 3.3: Add Packages Through menuconfig
Once we are done configuring my_external_tree, our next step is to configure the project.
- Make sure my_external_tree is the current working directory
$ cd ~/project/my_external_tree
- Run menuconfig using the following command:
$ make O=$PWD BR2_EXTERNAL=$PWD:../buildroot-external-microchip -C ../buildroot-at91 menuconfig
O=$PWD specifies the output directory for Buildroot. The $PWD indicates the shell should use the current working directory which happens to be my_external_tree. You could also use the absolute path of “~/project/my_external_tree”.
The main menu screen of menuconfig should appear.
After running the command above, we can simply use make menuconfig the next time we want to configure our Linux® image.
We will configure our project from scratch (without using any defconfigs). This will allow us to create a project without any unnecessary packages installed.
1
Enter the Target options menu and configure the following options:
- Target Architecture: ARM (little endian)
- Target Binary Format: ELF
- Target Architecture Variant: cortex-A5
- Enable NEON SIMD extension support
- Enable VFP extension support
- ARM instruction set: ARM
Use space to tick selections.
Your screen should now look like the screenshot shown below:
- Save the configuration by selecting Save from the bottom screen options and pressing Enter. Do not change the default options, then press Enter again.
Navigate back to the main menu screen by selecting Exit from the bottom screen options or by pressing Esc twice. The latter is mentioned at the top part of the menuconfig screen which also includes various tips on how to navigate each menu.
2
Enter the Build options menu and configure the following option:
- Location to save buildroot config:
$(BR2_EXTERNAL_my_external_tree_PATH)/configs/my_defconfig
Your screen should now look like the screenshot below:
To view more details about each option, press <?> for help. An example of the help description for the location to save Buildroot config is shown in the screenshot below:
Save the configuration and navigate back to the main menu screen.
3
Enter the Toolchain menu and configure the following options:
- Enable WCHAR Support
- Enable toolchain locale/i18n support:
- Enable C++ support
Your screen should look like the screenshot below:
Buildroot can build its own toolchain or download an existing one. We can also select a pre-installed toolchain if available. For this project, we will have Buildroot build the toolchain for us.
Save the configuration and navigate back to the main menu screen.
4
Enter the System configuration menu and configure the option below:
- Root password:
- root
- Network interface to configure through DHCP:
- eth0
- Custom scripts to run after creating filesystem images:
- support/scripts/genimage.sh
- Extra arguments passed to custom scripts
-c $(BR2_EXTERNAL_MCHP_PATH)/board/microchip/sama5d27_som1_ek/genimage.cfg
Your screen should look like the screenshot below:
Make sure that support/scripts/genimage.sh is added to Custom scripts to run after creating file system images.
You can also change the system hostname and system banner settings as shown above. For this project, we will leave these settings default.
We include a root password because ssh and scp require a password (both of which will be used in Step 5); it does not accept blank passwords.
Save the configuration and navigate back to the main menu screen.
5
Enter the kernel menu and configure the Linux kernel options below:
- Linux Kernel
Additional options will appear after selecting Linux kernel. Configure the following options:
- Kernel version: Custom Git repository
- URL of custom repository: https://github.com/linux4sam/linux-at91.git
- Custom repository version: linux4sam-2021.04
- Deconfig name: sama5
- Build a Device Tree Blob (DTB):
- In-tree device tree source file names: at91-sama5d27_som1_ek
- Needs host OpenSSL
Your screen should look like the screenshot below:
Save the configuration and navigate back to the main menu screen.
7
Enter the Bootloaders menu and configure the options below:
- T91 Bootstrap 3+
- AT91 Bootstrap 3+ version: Custom Git repository
- URL of custom repository: https://github.com/linux4sam/at91bootstrap.git
- Custom repository version: v4.0.0
- Deconfig name: sama5d27_som1_eksd_uboot
- U-Boot
- Build system: Kconfig
- U-Boot Version: Custom Git repository
- URL of custom repository: https://github.com/linux4sam/u-boot-at91.git
- Custom repository version: linux4sam-2021.04
- Board deconfig: sama5d27_som1_ek_mmc
- U-Boot needs dtc
The build system option will revert to legacy when changing the U-Boot version to a custom Git repository. You will have to go back and change it to Kconfig again.
Your screen should look like the screenshot below:
Save the configuration and navigate back to the main menu screen.
8
Enter the host utilities menu and configure the options below:
- host genimage
- host u-boot-tools
- Flattened Image Tree (FIT) support
- Environment image
- Source files for environment: $(BR2_EXTERNAL_MCHP_PATH)/board/microchip/sama5d27_som1_ek/uboot-env.txt
- Size of environment: 0x4000
Your screen should look like the screenshot below:
Save the configuration and navigate back to the main menu screen.
Step 3.4: Add Target Packages
We will now add required target packages for the demo, along with recommended target packages needed for troubleshooting and transferring files from the Linux host to the target device.
1
Recommended Target Packages
Enter the Target packages menu from the main menu screen. Install the following packages by navigating to the specified submenus.
- i2c-tools – for checking devices in I2C bus
- spi-tools – includes “spi-config” and “spi-pipe” for configuring and testing Serial Peripheral Interface (SPI).
- lshw – for checking drivers loaded to a specific device.
- evtest – for testing General Purpose Input/Output (GPIO) events on the SOM1-EK.
Target packages
- [*] Show packages that are also provided by busybox
Target packages —-> Hardware handling
- <*> evtest
- <*> i2c-tools
- <*> lshw
- <*> spi-tools
Your screen should look like the screenshots below:
5. nano – for editing files within the target device.
Target packages —-> Text editors and viewers
- [*] nano
- [*] optimize for size
6. libgpiod – includes tools like gpiodetect, gpioinfo etc. which can be helpful in checking GPIO.
Target packages —> Libraries —> Hardware handling
- [*] libgpiod
- [*] install tools
7. openssh – for connecting to the target device via ssh and transferring files via scp
Target packages —-> Networking applications
- [*] openssh
- [*] client
- [*] server
- [*] key utilities
The image will need to be rebuilt by executing make clean then make if these target packages are skipped, so we’d suggest including these tools right now. Refer to the Appendix on how to use these tools.
2
Target Packages for the Python Demo
Feel free to skip this optional step if you prefer to run the C Demo. Otherwise, the target packages below will be required to run the Python demo.
Install the following packages by navigating to the specified submenus relative to the main menu screen:
- 1. python3
- Target packages —-> Interpreter languages and scripting
- [*] python3
- python3 module format to install (.pyc compiled sources only)
- 2. python-spidev
- Target packages —> Interpreter languages and scripting —> External python modules
- [*] python-spidev
- 3. python-mpio
- External options —-> MCHP
- [*] python-mpio
Clicking save configuration in menuconfig saves the current configuration to ~/.config file. To save the configuration in the default configuration file, in this case, $(BR2_EXTERNAL_my_external_tree_PATH)/configs/my_defconfig, run make savedefconfig.
Step 3.5: Run Make
Build the image by running make command.
$ cd ~/project/my_external_tree
$ make
It normally takes a while to build the image. The build time depends on how many packages were included in the configuration and the performance of the virtual machine and its operating system (e.g., number of cores and processors, allocated memory, etc.). Also, internet bandwidth affects build time since Buildroot needs to download the packages from the internet.
Your screen should look like the screen below after the image has been built. Generally, there should be no error after make.
The files inside my_external_tree directory after running make command may look like the screenshot below: