This page describes how to set up Baserock running natively on the Acer CB5-311 Chromebook. Although Baserock can be installed onto the internal SSD, it is recommended to use an external HDD or SD card because the internal space is limited and dual boot with Chrome OS is convenient for developers.

Please be aware to check the devices e.g. with lsblk every time before running commands like dd and replace where appropriate.

Chrome OS Developer Mode

To activate the developer mode, hold down the ESC and Refresh (F3) keys and poke the Power button. During booting press one of the following:

Ctrl-D # Chrome OS dev mode
Ctrl-U # USB boot

Boot into Chrome OS dev mode, press Alt+Ctrl+T and type:

# Will jump into shell
shell

Enable legacy and USB/SD boot (crossystem man page can be found here)

sudo crossystem dev_boot_usb=1

Configuration of crossystem has to been repeated after an automatic Update of Chrome OS.

Partitioning

On your desktop machine, attach a USB HDD and do the following:

    # Install packages needed to partition and sign, e.g. on Ubuntu
    apt-get install cgpt vboot-kernel-utils

    # Partitioning the device, Kernel partition and two 100GB btrfs (size in 512 Byte blocks)
    parted --script /dev/sdX mklabel gpt
    cgpt create /dev/sdX
    cgpt add -t kernel -l uboot/kernel -b 34 -s 16384 /dev/sdX
    cgpt add -t data -l / -b 16418 -s 195300000 /dev/sdX
    cgpt add -t data -l / -b 195316418 -s 195300000 /dev/sdX
    blockdev --rereadpt /dev/sdX

    # Create the root filesystem
    mkfs.btrfs /dev/sdX2
    mkfs.btrfs /dev/sdX3

    # Mount partition
    mkdir /mnt/rootfs
    mount /dev/sdX2 /mnt/rootfs/

    # Create rootfs subvolume
    cd /mnt/rootfs
    mkdir -p system/factory
    btrfs subvolume create system/factory/run
    ln -sv system/factory system/default
    umount /mnt/rootfs

    # Mount the subvolume
    mount -o subvol=system/factory/run /dev/sdX2 /mnt/rootfs/

    # Get a plain ARM Baserock rootfs and extract
    mkdir ~/baserock_rootfs
    cd ~/baserock_rootfs
    wget http://download.baserock.org/baserock/build-system-armv7lhf-rootfs.tar.gz
    tar xvf build-system-armv7lhf-rootfs.tar.gz -C /mnt/rootfs

Build the Kernel

Build the Kernel from the repository (>=4.8 of arm-linux-gnueabi-gcc is needed)

    cd ~/
    git clone https://chromium.googlesource.com/chromiumos/third_party/kernel
    cd kernel
    git checkout chromeos-3.10
    ./chromeos/scripts/prepareconfig chromeos-tegra

    ./scripts/config -e CONFIG_FRAMEBUFFER_CONSOLE
    ./scripts/config -m CONFIG_USB_NET_CDC_MBIM
    ./scripts/config --set-val CONFIG_EXTRA_FIRMWARE \"nvidia/tegra124/xusb.bin\"
    ./scripts/config --set-val CONFIG_EXTRA_FIRMWARE_DIR \"/mnt/rootfs/lib/firmware\"
    ./scripts/config -m CONFIG_VLAN_8021Q
    ./scripts/config -e CONFIG_VT
    ./scripts/config -e CONFIG_VT_CONSOLE

    # Enable BTRFS support
    ./scripts/config -e BTRFS_FS

    # Download the USB firmware binary
    wget http://commondatastorage.googleapis.com/chromeos-localmirror/distfiles/xhci-firmware-2014.10.10.00.00.tbz2
    tar xvf xhci-firmware-2014.10.10.00.00.tbz2 -C /mnt/rootfs/

    # Build .config, Kernel, modules and install them
    make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- oldnoconfig  WIFIVERSION=-3.8
    make -j2 ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- -k zImage tegra124-nyan-big.dtb modules WIFIVERSION=-3.8

    # Install the Kernel modules
    make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- INSTALL_PATH=/mnt/rootfs/boot INSTALL_MOD_PATH=/mnt/rootfs firmware_install modules_install WIFIVERSION=-3.8

Create an its_script.its for mkimage (more information in the Chrome OS SDK Kernel ebuild):

    /dts-v1/;

    / {
        description = "Chrome OS kernel image with one or more FDT blobs";
          #address-cells = <1>;

          images {
              kernel@1 {
                  data = /incbin/("./arch/arm/boot/zImage");
                  type = "kernel_noload";
                  arch = "arm";
                  os = "linux";
                  compression = "none";
                  load = <0>;
                  entry = <0>;
              };
          fdt@1 {
              description = "tegra124-nyan-big.dtb";
              data = /incbin/("./arch/arm/boot/dts/tegra124-nyan-big.dtb");
              type = "flat_dt";
              arch = "arm";
              compression = "none";
              hash@1 {
                  algo = "sha1";
              };
          };
      };
      configurations {
          default = "conf@1";
          conf@1 {
              kernel = "kernel@1";
              fdt = "fdt@1";
          };
      };
    };

Use mkimage to create the Kernel image:

    # Create the Kernel imagine in the uboot format
    mkimage -D "-I dts -O dtb -p 1024" -f its_script.its /mnt/rootfs/boot/vmlinuz

Sign the Kernel

    # Write Kernel flags
    cat > /mnt/rootfs/boot/kernel.flags <<EOF
    console=tty1 console=ttyS0,115200n8 console=ttyS1,115200n8 verbose debug printk.time=1 root=/dev/sdaX rootwait rw rootfstype=btrfs rootflags=subvol=system/factory/run lsm.module_locking=0
    EOF

    # Sign Kernel
    vbutil_kernel --pack /mnt/rootfs/boot/vmlinuz.signed \
    --keyblock /usr/share/vboot/devkeys/kernel.keyblock \
    --version 1 \
    --signprivate /usr/share/vboot/devkeys/kernel_data_key.vbprivk \
    --config /mnt/rootfs/boot/kernel.flags \
    --vmlinuz /mnt/rootfs/boot/vmlinuz \
    --arch arm

    # Write the ChromiumOS Kernel to the first partition
    dd if=/mnt/rootfs/boot/vmlinuz.signed of=/dev/sdX1 bs=4M

    # Mark Kernel partition as good and set priority
    cgpt add -i 1 -S 1 -T 5 -P 1 /dev/sdX

    # Unmount the partition
    umount /mnt/rootfs

Baserock Setup

Attach the USB HDD or insert the SD to the Chromebook and press Ctrl-U to boot into the Kernel partition.

Once booted attach a USB Ethernet adapter and do:

    # Set up systemd-network daemon
    cat > /usr/lib/systemd/network/mynetwork.network <<EOF
    [Network]
    DHCP=v4
    DNS=8.8.8.8
    EOF

    # Start network daemon
    systemctl start systemd-networkd

    # Set password
    passwd root

    # Find out the IP
    ifconfig -a

    # Increase /tmp size
    mount -o remount,size=10G tmpfs /tmp/

    # Create /src
    mkdir /src/

From your main machine you can connect via SSH and mount /src:

    # Copy SSH key
    ssh-copy-id root@IPADDR

    # Login from main machine
    ssh root@IPADDR

    # Create directory
    mkdir ~/ssh-src

    # Mount /src on your main machine
    sshfs -o idmap=user -d root@IPADDR:/src ~/ssh-src

Init and build a Baserock system:

    # Create /src/morph.conf
    # ln -sv /src/morph.conf /etc/morph.conf

    # Set Git identity
    git config --global user.name "John Doe"
    git config --global user.email johndoe@example.com

    # Clone definitions
    git clone git://git.baserock.org/baserock/baserock/definitions
    cd definitions

    # Build your first system
    morph build systems/weston-system-armv7lhf-jetson.morph