> For the complete documentation index, see [llms.txt](https://amobile-solutions.gitbook.io/yocto-developer-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://amobile-solutions.gitbook.io/yocto-developer-guide/getting-started/iot-800n-g420/build-from-source-code.md).

# Build from Source Code

## Unpack the SDK

The SDK ships as git bundles, one per layer, so the full history and the exact revisions used for the release come with it.

```
tar xzf release-iot-800n-g420-v26.0-alpha1.tar.gz
cd release-iot-800n-g420-v26.0-alpha1

./unpack.sh ~/g420/src
```

`unpack.sh` verifies every checksum before restoring, then unpacks 17 repositories. It refuses to write into a directory that already exists, so a second run needs a different target.

To see exactly what you have:

```
cat manifest.txt
```

Each line gives a repository, its branch and the commit it was built from.

## Set up the environment

```
cd ~/g420
export PROJ_ROOT=$(pwd)

TEMPLATECONF=$PROJ_ROOT/src/meta-amobile-iot800n-g420/conf/templates/default \
  source src/poky/oe-init-build-env g420_build
```

{% hint style="warning" %}
`TEMPLATECONF` is only applied when `conf/` does not yet exist. Reusing an existing build directory keeps its old configuration, so template changes are silently ignored. To pick them up, move the directory aside and let the template regenerate it:

```
mv conf conf.old
cd .. && TEMPLATECONF=... source src/poky/oe-init-build-env g420_build
diff conf.old/local.conf conf/local.conf
```

`sstate-cache` is unaffected, so the rebuild is quick.
{% endhint %}

## Check the configuration

```
bitbake -e | grep -E "^MACHINE=|^KERNEL_DEVICETREE="
```

Expect:

```
MACHINE=iot800n-g420
KERNEL_DEVICETREE=mt8391-iot800n-g420.dtb
```

## Build

```
bitbake rity-demo-image
```

A first build from scratch takes several hours. Output lands in:

```
g420_build/tmp/deploy/images/iot800n-g420/
```

## Building individual components

```
bitbake linux-mtk                     the kernel
bitbake linux-mtk -c menuconfig       kernel configuration
bitbake linux-mtk -c compile -f       force a rebuild
bitbake <recipe> -c cleansstate       discard a recipe's cached output
```

## Working on the kernel

The kernel is built directly from `src/linux-mtk` using `externalsrc` rather than being fetched, so edits there take effect on the next build with no patch management involved.

```
src/linux-mtk/arch/arm64/boot/dts/mediatek/mt8391-iot800n-g420.dts
```

{% hint style="info" %}
Because `externalsrc` is in use, bitbake does not run `do_patch`. The MediaTek patches are already applied in the tree as shipped.
{% endhint %}

## Layer layout

```
src/
  poky/                            OpenEmbedded core
  meta-openembedded/               additional layers
  meta-mediatek-bsp/               MediaTek SoC support
  meta-rity/                       MediaTek IoT Yocto distro
  meta-amobile-iot800n-g420/       this board
  linux-mtk/                       kernel
  ...
```

Board documentation lives under `src/meta-amobile-iot800n-g420/docs/` and covers the hardware mapping, the out-of-tree drivers and the GPIO interfaces.
