PAC1934 Energy Metering Using Linux Step 3
Create a BR2_EXTERNAL Tree Structure
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
/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
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
The external.desc contents should contain the following information:
name: <external_tree_name> desc: <Your project description>
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
The main menu screen of menuconfig should appear.
We will configure our project from scratch (without using any defconfigs). This will allow us to create a project without any unnecessary packages installed.
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
Your screen should now look like the accompanying screenshot shown:
Save the configuration by selecting Save from the bottom screen options and pressing Enter. Do not change the default options, then press Enter again.
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:
Save the configuration and navigate back to the main menu screen.
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 this screenshot:
Save the configuration and navigate back to the main menu screen.
Enter the System configuration menu and configure the option as shown:
- 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:
Save the configuration and navigate back to the main menu screen.
Enter the kernel menu and configure the Linux kernel options:
- 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:
Save the configuration and navigate back to the main menu screen.
Enter the Filesystem images menu and configure the options:
- ext2/3/4 root filesystem
- ext2/3/4 variant: ext4
Your screen should look like:
Save the configuration and navigate back to the main menu screen.
Enter the Bootloaders menu and configure the options:
- 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
Your screen should look like this screenshot:
Save the configuration and navigate back to the main menu screen.
Enter the host utilities menu and configure the options:
- 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 accompanying screenshot:
Save the configuration and navigate back to the main menu screen.
Enter the external options menu and then the MCHP menu and configure the options:
- dt-overlay-at91
- platform name: sama5d27_som1_ek
- output: FIT image
Your screen should look like:
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.
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 this screenshots:
nano – for editing files within the target device.
Target packages —-> Text editors and viewers
- [*] nano
- [*] optimize for size
libgpiod – includes tools like gpiodetect, gpioinfo etc. which can be helpful in checking GPIO.
Target packages —> Libraries —> Hardware handling
- [*] libgpiod
- [*] install tools
openssh – for connecting to the target device via ssh and transferring files via scp
Target packages —-> Networking applications
- [*] openssh
- [*] client
- [*] server
- [*] key utilities
Target Packages for 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
Run Make
Build the image by running make command.
$ 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 this screen 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 this: