Building Chromium for Chromium OS (simple chrome)

This workflow allows you to quickly build/deploy Chromium for any Chromium OS device, without a Chromium OS checkout, and without a Chromium OS chroot.

At its core is the chrome-sdk shell which sets up the shell environment, and fetches the necessary SDK components (CrOS toolchain, sysroot, etc.).

Typography conventions

Color Paths, files, and commands:
green text on your build machine, outside the chroot
purple text inside the chrome-sdk shell on your build machine
Note: This is not the same thing as the cros-sdk chroot.
crimson text on your Chromium OS device

Get a Chromium checkout

First off make sure all preconditions are met:

  1. You have a local copy of the Chromium source code.
  2. You have a local copy of depot_tools.

Secondly, think about whether you need access to Google APIs from the executable you are building.  If the answer is yes, you will need to have your keys (see http://www.chromium.org/developers/how-tos/api-keys) either in your include.gypi, or in a file in your home directory called ".googleapikeys".

Run 'cros chrome-sdk'

Run this from within your Chromium checkout (outside the chroot):

NOTE: When prompted for a project ID, enter 134157665460 as your project ID (this is the Chrome OS project ID).

Replace <board> with a Chromium OS board name 

gclient sync -n -R  # Or 'git crup' for the submodule workflow.
cros chrome-sdk --board=<board>  # See 'go/cros-names' for a list of board overlay names.

cros chrome-sdk may ask you to set up gsutil access by providing you with a link. Follow the link, and grab the authentication token. Then paste the token into the prompt. (If you are a Googler, use your @google.com account)

cros chrome-sdk will fetch the latest Chrome OS SDK for building Chrome, and put you in a shell (with a yellow command prompt).  chrome-sdk will also automatically install and start the Goma server, with the active server port stored in the $SDK_GOMA_PORT environment variable.

The necessary environment variables needed to build Chrome (i.e., GYP_DEFINES, GYP_GENERATORS, etc.) are set up for you, and the contents of ~/.chromite/chrome_sdk.bashrc (which you can use to set a custom environment) will be sourced.

Tip: cros chrome-sdk will set up the environment to build external Chromium by default. To build the official Chrome, run with the --internal flag.

Using a custom Chromium OS build from your Chromium OS chroot (optional)

If you are making changes to Chromium OS and have a Chromium OS build inside a chroot that you want to build against, run cros chrome-sdk with the --chroot option.

cros chrome-sdk --board=<board> --chroot=/path/to/chroot

Build Chromium

cros chrome-sdk defaults to setting Ninja as the GYP_GENERATOR. From inside the chrome-sdk shell, run the following commands, where %CHROME_DIR% is the path to your Chromium checkout:

unset PKG_CONFIG_PATH
cd %CHROME_DIR%/src
./build/install-build-deps.sh # Append --arm for arm targets (e.g., ${SDK_BOARD}=daisy)
gclient runhooks   # Or 'git crup' for the submodule workflow.
ninja -C out_${SDK_BOARD}/Release -j500 chrome chrome_sandbox nacl_helper

Congratulations, you've now built Chromium for Chromium OS!

Once you've built Chromium the first time, you can build incrementally just using ninja. Here's an example:

ninja -C out_${SDK_BOARD}/Release -j500 chrome

Tip: The default extensions will be installed by the test image you use below.

Setting up your Chromium OS device

Before you can deploy your build of Chromium to the device, it needs to have a test image loaded on it.

Download a test image

Easiest way to get test image is "Image Search" link on http://chromeos-images/ 
https://www.google.com/chromeos/partner/fe/#release

Alternative way:

You can get a Chromium OS test image by going to https://storage.cloud.google.com/chromeos-image-archive/<board>-release/<version>/chromiumos_test_image.tar.xz, where <board> is the board you're working on and <version> is the version of the Chromium SDK that is shown on the SDK prompt (i.e., '(sdk lumpy R27-3789.0.0)').  After you download the compressed .tar.xz file, extract the image by running:

tar -xf <path_to_file>

Get the Chromium OS build scripts

If you don't have a Chromium OS checkout yet, follow these instructions (where %CHROMEOS_DIR% is the directory you want the build scripts to live):

mkdir -p %CHROMEOS_DIR% && cd %CHROMEOS_DIR%
repo init -u https://chromium.googlesource.com/chromiumos/manifest.git \
  -g minilayout --repo-url https://chromium.googlesource.com/external/repo.git
repo sync

Put the test image onto a USB stick

You will need a 4GB USB stick (you can get one at the ChromeStop where you picked up your Chromebook).  Once you download and unpack the image, run the image_to_usb.sh script located in the Chromium OS checkout.

%CHROMEOS_DIR%/src/scripts/image_to_usb.sh --board=<board> --from=<path_to_image>

Put your Chrome OS device in dev mode

Follow the device-specific instructions to put your device into dev mode and enable booting from USB.

Install the test image onto your device

Now that you are in dev mode and have enabled booting from USB, plug the USB stick into the machine and reboot.  At the dev-mode warning screen, press Ctrl-U to boot from the usb.  Once you've booted from the USB, login as a guest user and press Ctrl-Alt-T to get a terminal and run

shell
sudo /usr/sbin/chromeos-install

IMPORTANT NOTE: Installing Chromium OS onto your hard disk will WIPE YOUR HARD DISK CLEAN.

Connect device to corp network

To do this you will need a USB-to-ethernet dongle (you can find these at the techstop).

Deploying Chrome to the device

To deploy the build to a device, you can either rsync (install) the artifacts onto the target device's rootfs, or directly mount your host build directory from the target device using sshfs. Using sshfs provides for slightly faster incremental cycle time, as no files need to be transferred, but requires the device to be able to connect to the host (not required for rsync), and a consistent network connection.

Using deploy_chrome

Just type deploy_chrome from with your chrome-sdk shell. It will use rsync to incrementally deploy to the device.

Specify the build output directory to deploy from using --build-dir, and the IP address of the target device (which must be ssh-able as user 'root') using --to, where %CHROME_DIR% is the path to your Chrome checkout:

cd %CHROME_DIR%/src
deploy_chrome --build-dir=out_${SDK_BOARD}/Release --to=172.11.11.11

Tip: deploy_chrome lives under $CHROMEOS_DIR/third_party/chromite/bin. You can run deploy_chrome outside of a chrome-sdk shell as well.

Tip: Specify the --target-dir flag to deploy to a custom location on the target device.

Using sshfs (Experimental)

For now, you will need to use cwolfe's experimental cros_chrome_mount (search for 'cros_chrome_mount' on the page) script to deploy to the device through an sshfs mount. Note you will need a chroot to use cros_chrome_mount.

Remote Debugging

On the target machine, open up a port for the gdb server to listen on, and attach the gdb server to the running chrome process.  

sudo /sbin/iptables -A INPUT -p tcp --dport 1234 -j ACCEPT
sudo gdbserver --attach :1234 $(pgrep chrome -P $(pgrep session_manager))

On your host machine (inside the chrome-sdk shell), run gdb and start the Python interpreter:

cd %CHROME_DIR%/src
gdb out_${SDK_BOARD}/Release/chrome
Reading symbols from /usr/local/google2/chromium2/src/out_link/Release/chrome...
(gdb) pi 
>>>

Note: These instructions are for targeting an x86_64 device.  For now, to target an ARM device, you need to run the cross-compiled gdb from within a chroot.

Then from within the Python interpreter, run these commands:

import os
sysroot = os.environ['SYSROOT']
gdb.execute('set sysroot %s' % sysroot)
gdb.execute('set solib-absolute-prefix %s' % sysroot)
gdb.execute('set debug-file-directory %s/usr/lib/debug' % sysroot)
gdb.execute('target remote 12.34.56.78:1234')

If you wish, after you connect, you can Ctrl-D out of the Python shell.

Extra debugging instructions are located at http://www.chromium.org/chromium-os/how-tos-and-troubleshooting/debugging-tips.

Additional instructions

Updating the version of the Chrome OS SDK

When you invoke cros chrome-sdk, the script fetches the version of the SDK that corresponds to your Chrome checkout.  To update the SDK, sync your Chrome checkout and re-run cros chrome-sdk.

IMPORTANT NOTE: Every time that you update Chrome or the Chrome OS SDK, it is possible that Chrome may start depending on new features from a new Chrome OS image. This can cause unexpected problems, so it is important to update your image regularlyThe instructions for updating your Chrome OS image are in Step 4.

Specifying the version of the Chrome OS SDK to use

You can specify a version of Chrome OS to build against. This is handy for tracking down when a particular bug was introduced.

cros chrome-sdk --board=<board> --version=3680.0.0

Once you are finished testing the old version of the chrome-sdk, you can always start a new shell with the latest version again. Here's an example:

cros chrome-sdk --board=<board>

Updating Chrome

Tip: If you update Chrome inside the chrome-sdk, it will automatically run ./build/gyp-chromium for you inside the chrome-sdk shell.  Note that you may then be using an SDK that is out of date with the current Chrome.  See the section on 'Updating the version of the Chrome OS SDK' above.

gclient sync # for gclient
git crup     # for the git submodule workflow

Using clang

Run cros chrome-sdk with the --clang flag.  Clang doesn't work with Ninja right now, so you'll also need to pass in --make.

cros chrome-sdk --board=<board> --clang --make

Then run these commands to build with make, where %CHROME_DIR% is the path to your Chrome checkout:

cd %CHROME_DIR%/src
./build/gyp_chromium
make -j1000 chrome chrome_sandbox nacl_helper

Note that  Make files are spread through the source tree, and not concentrated in the out_<board> directory, so you can only have one Make config running at a time.

Updating Deployed Files

Since the gyp files don't define which targets get installed, that information is maintained in the chromite repo as part of Chromium OS. That repo is also integrated into the Chromium source tree via the DEPS file.

In order to add/remove a file from the installed list:

  1. Go into the chromite directory and modify lib/chrome_util.py
    1. Look for the _COPY_PATHS list
    2. Add your new file with optional=True
  2. Commit your change locally using git
  3. Upload your change to gerrit
    1. git push origin master:refs/for/master
  4. Get it reviewed by someone on the Chromium OS build team (e-mail chromium-os-dev@ if you can't find anyone)
  5. Merge the change into Chromium OS via gerrit
  6. Update the DEPS file in Chromium to use the new chromite sha1
  7. Check in the Chromium change like normal
  8. Once everything has settled, then go back and remove the optional=True from the file list
    1. Unless the file is actually optional, then keep it
Comments