top of page
Writer's pictureAnup Halarnkar

How to Create an External Toolchain in Buildroot - Part 1

Updated: Nov 12


Buildroot External Toolchain - Part1

Background:


For some months, we at WhileOne Techsoft Pvt. Ltd. have been helping our customer setup a system to validate the performance of their SoC platform. In this context, we had to bring up an aarch64 Linux based target image to run on their proprietary hardware SoC platform.


Linux system using Buildroot


Part-1 of this series explains how to build an External Toolchain with BuildRoot.


Part -2 of this series explains how to build a Target Linux image and Rootfs in BuildRoot using the External Toolchain that we built in Part-1


Part -3 of this series explains how to integrate the generated External Toolchain binaries(built in Part -1)inside the Target Linux image using BuildRoot


Tools and Development station:


  1. Buildroot (www.buildroot.org)

  2. AWS aarch64 ubuntu based instance with 50GiB SSD and 8GiB RAM(Free Tier instances with drive space < 20GiB will fail during build process)

  3. SSH client(Putty or WSL2 Ubuntu VM for windows)


Why Buildroot?


Why use Buildroot

Buildroot is a tool that automates the process of building a complete Linux system for an embedded system, using cross compilation. It has a significantly lesser learning curve as compared to another popular tool Yocto. Yocto supports designing complex Linux systems using a plethora of recipes(customization scripts) whereas Buildroot supports quicker prototype designs targeted mainly for embedded systems.


Challenges?


Although Buildroot does not support toolchains generated by Yocto, OpenEmbedded or even GCC. So, any of these toolchain binaries cannot be used directly as the external toolchain. But, Buildroot provides an alternate way where we can create an external toolchain based on glibc, musl or uClibc-ng and cross-compile these with a choice of GCC v11.x or v12.x


Prepare the remote system for build:


First, we need to log in to the remote (aarch64) instance with IP address using either Putty or any other SSH tool of your choice. I have connected to the remote instance via SSH from WSL2 (Windows Subsystem Linux) Ubuntu on Windows 11. On successful login to ubuntu instance, we need to prepare it by installing needed dependencies for Buildroot to work properly.


1. From AWS website, using your account, launch an AWS Ubuntu aarch64 instance (c6g.2xlarge) [around 8GB RAM and 50GB SSD volume], generate keypair and store on local windows 11 system (Tutorial for launching your own instances can be found online or on aws website)


Setting up AWS Instance

2. Launch WSL2 Ubuntu OS (Installation of WSL2 is beyond the scope of this article)


Welcome to Ubuntu 20.04.4 LTS (GNU/Linux 5.10.16.3-microsoft-standard-WSL2 x86_64)* Documentation: https://help.ubuntu.com  Management: https://landscape.canonical.com  Support: https://ubuntu.com/advantage<windows-username>@<windows-machine-name>:~$



3. To copy the keypair on local system to Ubuntu WSL2, we need to open location “\\WSL$” in windows explorer. This will display folder structure with Ubuntu as primary and the only folder. Navigate to “Ubuntu/home/<windows username>” and copy the keypair to this location (other location can also be used as per convenience)



Ubuntu WSL2



4. Run the below command to connect to remote aws instance


ssh -i <path/to/keypair_file.pem> ubuntu@<IP addr of instance>
Connecting to Remote System

5. If connection is successful, an ubuntu prompt shall be displayed


Welcome to Ubuntu 20.04.4 LTS (GNU/Linux 5.13.0-1029-aws aarch64)* Documentation:  https://help.ubuntu.com
 * Support:        https://ubuntu.com/advantageSystem information as of Fri Jul  1 13:55:38 UTC 2022System load:  0.0                Processes:             186
  Usage of /:   41.2% of 28.91GB   Users logged in:       0
  Memory usage: 7%                 IPv4 address for ens5: 172.31.58.93
  Swap usage:   0%* Ubuntu Pro delivers the most comprehensive open source security and
   compliance features.https://ubuntu.com/aws/pro11 updates can be applied immediately.
To see these additional updates run: apt list --upgradableLast login: Thu Jun 30 20:05:55 2022 from 17x.4x.3x.5x
ubuntu@ip-17x-3x-5x-9x:~$

6. Run below command to verify system details of remote instance



Verify system details of remote instance

7. Run below required commands to install dependencies. The package libncurses-dev is needed for menuconfig to work properly


sudo apt updatesudo apt-get install build-essential libncurses-dev
Installing Dependencies

8. Clone buildroot repository



Cloning Buildroot Repository


9. Prepare the build for aarch64 platform. Get command from readme.txt


vi buildroot/board/aarch64-efi/readme.txt


10. Execute the command to configure for aarch64


make aarch64_efi_defconfig
Configuring for AARCH64

11. Execute command to display menuconfig GUI


make menuconfig

Navigating Menuconfig

12. Menuconfig is visible as shown below



Menuconfig

13. Modify Target Options (Select Architecture):



Modifying Target Options

14. Modify Toolchain Options: Select toolchain as Buildroot toolchain, C library as glibc, Kernel headers < version of kernel that is built, gcc version 11.x, Enable Fortran support


Modify toolchain options
Modifying Toolchain options


Modifying Toolchain option

15. Modify options for System configuration:


Modify options for System configuration

16. Modify options for Target packages (Disable option busybox):



Modify options for target packages

17. Modify options in Filesystem Images:



Modify options in Filesystem Images

18. Save and exit from "menuconfig" UI


19. Run command “make sdk” on terminal


Running SDK Build

20. SDK is built successfully. The log after generation of SDK is shown below.


>>>   Rendering the SDK relocatablePER_PACKAGE_DIR=/home/ubuntu/buildroot/output/per-package /home/ubuntu/buildroot/support/scripts/fix-rpath hostPER_PACKAGE_DIR=/home/ubuntu/buildroot/output/per-package /home/ubuntu/buildroot/support/scripts/fix-rpath staging/usr/bin/install -m 755 /home/ubuntu/buildroot/support/misc/relocate-sdk.sh /home/ubuntu/buildroot/output/host/relocate-sdk.shmkdir -p /home/ubuntu/buildroot/output/host/share/buildrootecho /home/ubuntu/buildroot/output/host > /home/ubuntu/buildroot/output/host/share/buildroot/sdk-location>>>   Generating SDK tarballtar czf "/home/ubuntu/buildroot/output/images/aarch64-buildroot-linux-gnu_sdk-buildroot.tar.gz" \--owner=0 --group=0 --numeric-owner \--transform='s#^home/ubuntu/buildroot/output/host#aarch64-buildroot-linux-gnu_sdk-buildroot#' \-C / home/ubuntu/buildroot/output/host


21. Verify if the tarball ‘aarch64-buildroot-linux-gnu_sdk-buildroot.tar.gz’ is available in the folder ‘buildroot/output/images’



Verify Tarball availability

22. Copy this tarball to some external location in ‘home/ubuntu’ outside the ‘buildroot’ directory.


SDK Tarball successful creation

mv output/images/aarch64-buildroot-linux-gnu_sdk-buildroot.tar.gz ~

In Part-2, we will use this tarball for generating a root file system and a kernel image by compiling the kernel with the newly generated External Toolchain



Conclusion:


Built external toolchain

A quote that has inspired me for a long time…


“Obstacles don’t have to stop you. If you run into a wall, don’t turn around and give up. Figure out how to climb it, go through it, or work around it.” — Michael Jordan



30 views0 comments

Recent Posts

See All

Comentarios


bottom of page