layout: doc title: “Set up your environment - Raspberry Pi”

These instructions explain how to set up Cobalt for your workstation and your Raspberry Pi device. They have been tested with Ubuntu:20.04 and a Raspberry Pi 3 Model B.

Set up your device

Download the latest Cobalt customized Raspbian image from GCS bucket (this is built via this customization tool)

On MacOS, use an image flashing tool like balenaEtcher to write the image to a 32GB SD-card.

On Linux, follow the steps below.

Check the location of your SD card (/dev/sdX or /dev/mmcblkX)

$ sudo fdisk -l

Make sure the card isn't mounted ( umount /dev/sdX ).

Copy the downloaded image to your SD card (the disk, not the partition. E.g. /dev/sdX or /dev/mmcblkX):

$ sudo dd bs=4M if=2020-02-13-raspbian-buster-lite_shrunk_20210427.img of=/dev/sdX

After flashing your device, you‘ll still need to setup your wifi. Login with the default pi login, and run sudo raspi-config. You’ll find wifi settings under 1. System Options, then S1 Wireless LAN.

Set up your workstation

The following steps install the cross-compiling toolchain on your workstation. The toolchain runs on an x86 workstation and compiles binaries for your ARM Raspberry Pi.

  1. Run the following command to install packages needed to build and run Cobalt for Raspberry Pi:

    $ sudo apt install -qqy --no-install-recommends g++-multilib \
        wget xz-utils libxml2  binutils-aarch64-linux-gnu \
        binutils-arm-linux-gnueabi  libglib2.0-dev
    
  2. Choose a location for the installed toolchain – e.g. raspi-tools – and set $RASPI_HOME to that location.

  3. Add $RASPI_HOME to your .bashrc (or equivalent).

  4. Create the directory for the installed toolchain and go to it:

    $ mkdir -p $RASPI_HOME
    $ cd $RASPI_HOME
    
  5. Download the pre-packaged toolchain and extract it in $RASPI_HOME.

    $ curl -O https://storage.googleapis.com/cobalt-static-storage/cobalt_raspi_tools.tar.bz2
    $ tar xvpf cobalt_raspi_tools.tar.bz2
    

    (This is a combination of old raspi tools and a newer one from linaro to support older Raspbian Jessie and newer Raspbian Buster)

Build, install, and run Cobalt for Raspberry Pi

  1. Build the code by navigating to the cobalt directory and run the following command:

    $ cobalt/build/gn.py -p raspi-2
    
  2. Compile the code from the cobalt/ directory:

    $ ninja -C out/raspi-2_debug cobalt
    
  3. Run the following command to install your Cobalt binary (and content) on the device:

    $ rsync -avzLPh --exclude="obj*" --exclude="gen/" \
          $COBALT_SRC/out/raspi-2_debug pi@$RASPI_ADDR:~/
    

    The rsyncs get somewhat faster after the first time, as rsync is good at doing the minimum necessary effort.

  4. Even if you have a keyboard hooked up to the RasPi, you should SSH into the device to run Cobalt. Using SSH will make it easy for you to quit or restart Cobalt.

    $ ssh pi@$RASPI_ADDR
    $ cd raspi-2_debug
    $ ./cobalt
    

    With this approach, you can just hit [CTRL-C] to close Cobalt. If you were to run it from the console, you would have no way to quit without SSHing into the device and killing the Cobalt process by its PID.

    Note that you can also exit YouTube on Cobalt by hitting the [Esc] key enough times to bring up the “Do you want to quit YouTube?” dialog and selecting “yes”.