Skip to content

Commit

Permalink
add Buildroot chapter, cfg change
Browse files Browse the repository at this point in the history
  • Loading branch information
kaplan2539 committed Feb 18, 2024
1 parent dab4abf commit 0d42320
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 10 deletions.
6 changes: 4 additions & 2 deletions book/book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ authors = ["Alexander Kaplan"]
language = "en"
multilingual = false
src = "src"

[output.html]
cname = "d.eadc0.de"
default-theme = "dark"
preferred-dark-theme = "Ayu"
git-repository-url = "https://github.com/kaplan2539/cindy"
edit-url-template = "https://github.com/kaplan2539/cindy/edit/<branch>/{path}"
side-url = "https://d.eadc0.de/cindy"
cname = "d.eadc0.de"
site-url = "https://d.eadc0.de/cindy"

[build]
build-dir = "output"
1 change: 1 addition & 0 deletions book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@


- [Warm Up](./warmup.md)
- [Buildroot](./buildroot.md)
117 changes: 117 additions & 0 deletions book/src/buildroot.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# Buildroot

In the Warm Up Excercise chapter we've manually installed a cross-compiler,
downloaded the U-Boot, Linux and Busybox sources, compiled them and created
a rootfs image.
In this chapter we are going to use Buildroot to do that for us.

Buildroot is a great tool to generate embedded Linux images.
It integrates all of the steps mentioned above and makes it really easy to
add various software packages to the root file system.

We can only give very brief overview of how to use Buildroot for our purposes.
Luckily, Buildroot comes with
[detailed documentation](https://buildroot.org/downloads/manual/manual.html)
that should cover everything important to know.

Download and unpack the latest "stable" release:

```shell
wget -c -P download https://buildroot.org/downloads/buildroot-2023.11.tar.gz
tar xf download/buildroot-2023.11.tar.gz
```

## Customizing Buildroot for CHIP

We are going to use the 'br2-external' mechanism (c.f. Buildroot documentation
[Chapter 9.2](https://buildroot.org/downloads/manual/manual.html#outside-br-custom)
) in order to keep our
costumizations outside of the official buildroot tree:

```
mkdir buildroot-external
export BR2_EXTERNAL="$(realpath buildroot-external)"
```

Create `buildroot-external/external.desc`:

```
cat <<EOF >buildroot-external/external.desc
name: CHIP
desc: Buildroot configuration for CHIP
EOF
```

Create `buildroot-external/external.mk`:

```
cat <<EOF >buildroot-external/external.mk
include \$(sort \$(wildcard \$(BR2_EXTERNAL_CHIP_PATH)/package/*/*.mk))
EOF
```

Create empty `buildroot-external/Config.in`:

```
touch buildroot-external/Config.in
```

Create
[recommended directory structure](https://buildroot.org/downloads/manual/manual.html#customize-dir-structure):

```shell
mkdir -p "${BR2_EXTERNAL}"/board/nextthingco/CHIP/{dts,linux,uboot}
mkdir -p "${BR2_EXTERNAL}"/configs
```

Create Buildroot configuration for CHIP, for now using the default U-Boot
`CHIP_defconfig` and Linux `sunxi_defconfig`:

```shell
cat <<EOF >"${BR2_EXTERNAL}"/configs/nextthingco_chip_defconfig
BR2_arm=y
BR2_cortex_a8=y
BR2_TOOLCHAIN_EXTERNAL=y
BR2_LINUX_KERNEL=y
BR2_LINUX_KERNEL_CUSTOM_VERSION=y
BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="6.1.68"
BR2_LINUX_KERNEL_PATCH="${BR2_EXTERNAL_CHIP_PATH}/board/nextthingco/CHIP/linux"
BR2_LINUX_KERNEL_DEFCONFIG="sunxi"
BR2_LINUX_KERNEL_DTS_SUPPORT=y
BR2_LINUX_KERNEL_INTREE_DTS_NAME="sun5i-r8-chip"
BR2_LINUX_KERNEL_DTB_OVERLAY_SUPPORT=y
BR2_LINUX_KERNEL_INSTALL_TARGET=y
BR2_TARGET_ROOTFS_CPIO=y
BR2_TARGET_ROOTFS_CPIO_GZIP=y
BR2_TARGET_ROOTFS_CPIO_UIMAGE=y
BR2_TARGET_UBOOT=y
BR2_TARGET_UBOOT_BUILD_SYSTEM_KCONFIG=y
BR2_TARGET_UBOOT_CUSTOM_VERSION=y
BR2_TARGET_UBOOT_CUSTOM_VERSION_VALUE="2023.10"
BR2_TARGET_UBOOT_PATCH="${BR2_EXTERNAL_CHIP_PATH}/board/nextthingco/CHIP/uboot"
BR2_TARGET_UBOOT_BOARD_DEFCONFIG="CHIP"
BR2_TARGET_UBOOT_NEEDS_DTC=y
BR2_TARGET_UBOOT_NEEDS_PYLIBFDT=y
BR2_TARGET_UBOOT_SPL=y
BR2_TARGET_UBOOT_SPL_NAME="u-boot-sunxi-with-spl.bin spl/u-boot-spl.bin"
EOF
```

Now compile Linux, U-Boot and build a rootfs image using Buildroot:

```shell
cd buildroot-2023.11
make nextthingco_chip_defconfig
make
```

Buildroot put everything into the `output/images` sub-directory.
To boot type:

```shell
cd output/images
sunxi-fel -v -p uboot u-boot-sunxi-with-spl.bin \
write 0x42000000 zImage \
write 0x43000000 sun5i-r8-chip.dtb \
write 0x43400000 rootfs.cpio.uboot
```
16 changes: 8 additions & 8 deletions book/src/warmup.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ The following has been tested on a `x86_64` computer running Ubuntu 22.04.
These commands are going to install a cross-compiler toolchain, the
`sunxi-fel` tool, the `cu` terminal program, and couple of dependencies:

```
```shell
sudo bash -c '{{#include ../../setup/install_packages.sh:3:}}'
```

Let us add the current user to the `dialout` group in order to run the `cu`
without being a super-user:
```
```shell
sudo adduser $USER dialout
```
For the change to take effect we need to logout and login again.
Expand Down Expand Up @@ -72,7 +72,7 @@ There's even a default config for CHIP in `u-boot-v2023.10/configs/CHIP_defconfi

Now, let's build U-Boot for CHIP:

```
```shell
ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make CHIP_defconfig
ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make -j$(nproc)
```
Expand Down Expand Up @@ -162,15 +162,15 @@ U-Boot release which is already great.
At the time of writing, the latest Linux LTS kernel is 6.1.62, which we
donwnload and extract by typing:

```
```shell
wget -c https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.1.62.tar.xz
tar xf linux-6.1.62.tar.xz
```

Let's try building with the `sunxi_defconfig` which can be found in
`linux-6.1.62/arch/arm/configs`:

```
```shell
cd linux-6.1.62
ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make sunxi_defconfig
ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make -j$(nproc) zImage
Expand Down Expand Up @@ -233,13 +233,13 @@ The above attempt to boot into Linux failed because we did not have a root
filesystem (rootfs). Let's build one using Busybox!

Download Busybox
```
```shell
wget -c -P downlad https://busybox.net/downloads/busybox-1.36.1.tar.bz2
tar x -C build -f download/busybox-1.36.1.tar.bz2
```

Configure & Compile:
```
```shell
cd build/busybox-1.36.1
ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make defconfig
sed -e 's/# CONFIG_STATIC is not set/CONFIG_STATIC=y/' -i .config
Expand All @@ -249,7 +249,7 @@ ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make CONFIG_PREFIX=./../rootfs insta
```

Finalize initramfs:
```
```shell
cat > rootfs/init << EOF
#!/bin/sh
mount -t proc none /proc
Expand Down

0 comments on commit 0d42320

Please sign in to comment.