MycroftAI / mark-ii-sandbox

Image for the Mark II based on Raspberry Pi OS
5 stars 9 forks source link

Mark II Sandbox

Builds a working base image for the Mark II based on Raspberry Pi OS.

Prerequisites

Steps to Build

  1. Download/extract a Raspberry Pi 64-bit Lite image to the raspberry-pi-os directory
  2. In raspberry-pi-os, run img2tar.py -i <img-file> to create p1.tar and p2.tar
  3. Fetch submodules for build:
    git submodule init
    git submodule update
  4. In the root directory, run make
  5. Run sudo ./update-image.sh
  6. Burn custom.img

Once you've completed steps 1 and 2, you can run steps 3-5 after any changes to the Dockerfile.

How it Works

This splits a Raspberry Pi OS image into boot/user partitions (p1.tar and p2.tar respectively). It then runs the Docker build with the user partition (p2.tar) as the base file system, allowing for software to be installed, etc.

Finally, update-image.sh recombines the original boot parition (p1.tar) with the result of the Docker build. This uses the files in the boot to overwrite /boot in the image (e.g., with config.txt).

Partition Size

NOTE: depending on how much stuff you install during the Docker build, you may need to adjust the raspberry-pi-os/partition_table.txt file. The size of the second partition (type=83) may need to be increased before you run update-image.sh. Remember that this size is in sectors of 512 bytes. Lastly, ensure that the custom_image_bytes in update-image.sh is large enough to accomodate your new parition size.

Installed Software

The following software is installed on top of the base Raspberry Pi OS:

Additionally, I2C and SPI are enabled by default (required for the Mark II hardware).

Docker Build

Building requires Docker BuildKit. This is used to build for the arm64 platform as well as cache apt/python packages so they can be reused across multiple builds.

To bootstrap your machine for the first build, ensure that you have qemu "binformat" support:

sudo apt-get install binfmt-support

Then, create a Docker "builder" that supports multi-platform builds:

docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
docker buildx create --use --name mybuilder
docker buildx use mybuilder
docker buildx inspect --bootstrap

After that, you should be able to run make <TARGET> to build one of the images (e.g., make dinkum).