# Compiling Buildroot from scratch 

<abstract>
Buildroot is a simple, efficient and easy-to-use tool to generate embedded Linux systems through cross-compilation. 
This article illustrates how to generate a ready-to-use microSD image 
from scratch using the Buildroot scripts and utilities to download 
the sources of any code, compile them and generate a fully working microSD.
</abstract>

This article was written using a Linux Ubuntu 22.04.2 LTS. It is advisable to use an [USB to 3V TTL serial cable](/USB-3V-SER) 
or a [DPI](/DPI) interface to have access to the debug port. 

Install on your Linux PC the requested packages listed here:

* <http://buildroot.uclibc.org/downloads/manual/manual.html#requirement-mandatory>

Open a command line and download Buildroot from the official web site:

	$ wget https://buildroot.org/downloads/buildroot-2024.02.1.tar.gz
	$ tar -xvf buildroot-2024.02.1.tar.gz
	$ cd buildroot-2024.02.1

Create a git repository:

	$ git init ; git add . ; git commit -m "vanilla" ; git branch acme ; git checkout acme
	
Download the patch for the Acme board you have (just one): 

	$ wget https://www.acmesystems.it/www/buildroot/acme.patch
	
Apply the patch:	
	
	$ patch -p1 < acme.patch


And set the configuration you need:

	$ make foxd27_defconfig

The available configurations are:

* arietta_defconfig
* foxd27_defconfig
* foxd27-h10cu_defconfig
* foxd27-bot_defconfig

Launch the compilation:

	$ make

This operation will take about 1 hour to download and compile any sources. 

If all went well you will obtain this file in <code>output/images</code> directory:

	sdcard.img

### Install new packages

To install new packages from the menuconfig menu type:

	$ make menuconfig
	
Then repeat the procedure to generate the new microSD image from <code>Make</code> command.

### Regenerate the target directory

	$ rm -rf output/target
	$ find output/ -name ".stamp_target_installed" -delete
	$ rm -f output/build/host-gcc-final-*/.stamp_host_installed

### Change the Linux Kernel configuration

	$ make linux-menuconfig
	$ make linux-rebuild
	$ make

Save the kernel config

	$ make linux-savedefconfig
	
## Links

* <a href="https://buildroot.org/" target="_new">Buildroot home page</a>

## File used:

* [acme.patch](./foxd27.patch)


<a name="arietta">

<blockquote markdown="1">
## Download ready-to-use microSD images for your boards

* [Arietta](/download/buildroot/arietta/sdcard.img)<br/>
Buildroot 2024.02.1, Kernel 6.1, At91Boostrap 3.10.4, lighttpd, Python3, RNDIS drivers
* [Fox Board D27](/download/buildroot/foxd27/sdcard.img)<br/>
Buildroot 2024.02.1, Kernel 6.1, At91Boostrap 3.10.4, lighttpd, Python3

</blockquote>

## Make the microSD

Download and install the free tool [Balena Etcher](https://www.balena.io/etcher/) available for any platform to write the microSD using the <code>filename.img</code> generated by scratch od downloaded:

* <https://www.balena.io/etcher/>

Insert the microSD generated in your board and use the debug port to check the boot messages and get the 
access to the Linux prompt.

<div class="alert alert-danger" role="alert" markdown="1">
!! SECURITY WARNING !!
<br><br>
By default, only the <code>root</code> user is defined, and no password is requested at login, both on the debug port and on SSH access. This is because this image is intended for educational and experimental use only. Don't release your products with this image as is.
</div>

## Partition resizing

Type this command to check how is partitioned the microSD

	$ parted /dev/mmcblk0 --script print

	Model: SD SS08G (sd/mmc)
	Disk /dev/mmcblk0: 7948MB
	Sector size (logical/physical): 512B/512B
	Partition Table: msdos
	Disk Flags: 
	
	Number  Start   End     Size    Type     File system  Flags
	 1      512B    16.8MB  16.8MB  primary  fat16        boot, lba
	 2      16.8MB  101MB   83.9MB  primary  ext4
 
To resize the root partition to fill the entire microSD type:

	$ parted /dev/mmcblk0 --script resizepart 2 100%
	$ resize2fs /dev/mmcblk0p2

Check it again:
	
	$ parted /dev/mmcblk0 --script print

	Model: SD SS08G (sd/mmc)
	Disk /dev/mmcblk0: 7948MB
	Sector size (logical/physical): 512B/512B
	Partition Table: msdos
	Disk Flags: 


<h2>Products related</h2>

<div class="row equal">
	<div class="col-md-3 col-sm-6">
		@include='card_arietta'
	</div>
	<div class="col-md-3 col-sm-6">
		@include='card_foxd27'
	</div>
</div>
