blob: bbf2678d0d062a17b4cb19263eb249184e4586ef [file] [log] [blame] [view]
Satoru Takabayashi7cc76c92017-06-26 04:46:051# Building Chrome for Chrome OS (Simple Chrome)
Satoru Takabayashieef6f592017-06-23 04:16:362
Mike Frysinger05bebd52021-01-27 18:48:113*** note
4**Warning: This document is old & has moved. Please update any links:**<br>
5https://chromium.googlesource.com/chromiumos/docs/+/HEAD/simple_chrome_workflow.md
6***
7
Achuith Bhandarkar61f58962018-08-29 00:05:318This workflow allows you to quickly build/deploy Chrome to a Chrome OS
Steven Bennetts0d195912018-09-18 23:37:399[VM] or device without needing a Chrome OS source checkout or chroot. It's useful
Achuith Bhandarkar61f58962018-08-29 00:05:3110for trying out your changes on Chrome OS while you're doing Chrome
11development. If you have an OS checkout and want your local Chrome changes to
James Cook961c57d2018-01-23 21:34:0512be included when building a full OS image, see the [OS development guide].
Satoru Takabayashieef6f592017-06-23 04:16:3613
James Cook961c57d2018-01-23 21:34:0514At its core is the `chrome-sdk` shell which sets up the shell environment and
Achuith Bhandarkar61f58962018-08-29 00:05:3115fetches the necessary SDK components (Chrome OS toolchain, sysroot, VM, etc.).
Satoru Takabayashieef6f592017-06-23 04:16:3616
17[TOC]
18
19## Typography conventions
20
Achuith Bhandarkar61f58962018-08-29 00:05:3121| Label | Paths, files, and commands |
22|---------------|-------------------------------------------------------|
23| (shell) | outside the chroot and SDK shell on your workstation |
24| (sdk) | inside the `chrome-sdk` SDK shell on your workstation |
25| (chroot) | inside the `cros_sdk` chroot on your workstation |
Steven Bennetts0d195912018-09-18 23:37:3926| (device) | in your [VM] or Chrome OS device |
Satoru Takabayashieef6f592017-06-23 04:16:3627
Satoru Takabayashieef6f592017-06-23 04:16:3628
James Cookba126f12017-08-21 19:59:0729## Getting started
Satoru Takabayashieef6f592017-06-23 04:16:3630
Achuith Bhandarkar61f58962018-08-29 00:05:3131Check out a copy of the [Chrome source code and depot_tools].
32Be certain to [update .gclient] to include `target_os = ["chromeos"]`.
Satoru Takabayashieef6f592017-06-23 04:16:3633
Steven Bennetts7f08b002018-06-29 23:28:4434### Get the Google API keys
Satoru Takabayashieef6f592017-06-23 04:16:3635
Achuith Bhandarkar61f58962018-08-29 00:05:3136In order to sign in to Chrome OS you must have Google API keys:
Satoru Takabayashieef6f592017-06-23 04:16:3637
Achuith Bhandarkar61f58962018-08-29 00:05:3138* External contributors: See [api-keys]. You'll need to put them in your
39 `out_$BOARD/Release/args.gn file`, see below.
Achuith Bhandarkar83630262020-05-24 10:20:5940* *Googlers*: See [chrome build instructions] to get the internal source.
Achuith Bhandarkar61f58962018-08-29 00:05:3141 If you have `src-internal` in your `.gclient` file the official API keys
42 will be set up automatically.
Satoru Takabayashieef6f592017-06-23 04:16:3643
Steven Bennetts7f08b002018-06-29 23:28:4444### Set up gsutil
Satoru Takabayashieef6f592017-06-23 04:16:3645
James Cook961c57d2018-01-23 21:34:0546Use depot_tools/gsutil.py and run `gsutil.py config` to set the authentication
Steven Bennetts7f08b002018-06-29 23:28:4447token. (*Googlers*: Use your @google.com account.) Otherwise steps below may run
James Cook961c57d2018-01-23 21:34:0548slowly and fail with "Login Required" from gsutil.
James Cook3a2a0632018-01-18 06:21:5649
James Cook961c57d2018-01-23 21:34:0550When prompted for a project ID, enter `134157665460` (this is the Chrome OS
51project ID).
James Cook3a2a0632018-01-18 06:21:5652
Ben Pastene957ea272019-03-18 16:06:0153### Install build deps
54
55You'll also need to pull in Android native toolchain dependencies to build
56ARC++ support libraries. This is done by running the
57[install-build-deps-android.sh] script in Chrome's source code, located at
58`$CHROME_DIR/src/build/install-build-deps-android.sh`.
59
Achuith Bhandarkar61f58962018-08-29 00:05:3160### VM versus Device
61
Steven Bennetts0d195912018-09-18 23:37:3962The easiest way to develop on Chrome OS is to use a [VM].
63
64If you need to test hardware-specific features such as graphics acceleration,
65bluetooth, mouse or input events, etc, you may also use a physical device
66(Googlers: Chromestop has the hardware). See [Set up the Chrome OS device] for
67details.
Achuith Bhandarkar61f58962018-08-29 00:05:3168
Steven Bennetts7f08b002018-06-29 23:28:4469---
James Cook3a2a0632018-01-18 06:21:5670
Steven Bennetts7f08b002018-06-29 23:28:4471## Enter the Simple Chrome environment
Satoru Takabayashieef6f592017-06-23 04:16:3672
Steven Bennetts7f08b002018-06-29 23:28:4473Building Chrome for Chrome OS requires a toolchain customized for each
Steven Bennetts0d195912018-09-18 23:37:3974Chromebook model (or "board"). For the Chrome OS [VM], and non-Googlers, use
Achuith Bhandarkar61f58962018-08-29 00:05:3175`amd64-generic`. For a physical device, look up the [Chrome OS board name] by
Steven Bennetts7f08b002018-06-29 23:28:4476navigating to the URL `about:version` on the device. For example:
77`Platform 10176.47.0 (Official Build) beta-channel samus` has board `samus`.
78
Achuith Bhandarkar61f58962018-08-29 00:05:3179To enter the Simple Chrome environment, run these from within your Chrome
80checkout:
Steven Bennetts5a79a1c2017-11-27 20:05:4781
Satoru Takabayashieef6f592017-06-23 04:16:3682```
Achuith Bhandarkar61f58962018-08-29 00:05:3183(shell) cd /path/to/chrome/src
84(shell) export BOARD=amd64-generic
=71679e62020-05-08 18:06:2585(shell) cros chrome-sdk --board=$BOARD --log-level=info [--download-vm]
Satoru Takabayashieef6f592017-06-23 04:16:3686```
Satoru Takabayashieef6f592017-06-23 04:16:3687
Steven Bennetts7f08b002018-06-29 23:28:4488The command prompt will change to look like `(sdk $BOARD $VERSION)`.
Satoru Takabayashieef6f592017-06-23 04:16:3689
Steven Bennetts7f08b002018-06-29 23:28:4490Entering the Simple Chrome environment does the following:
Satoru Takabayashieef6f592017-06-23 04:16:3691
Steven Bennetts7f08b002018-06-29 23:28:44921. Fetches the Chrome OS toolchain and sysroot (SDK) for building Chrome.
931. Creates out_$BOARD/Release and generates or updates args.gn.
=71679e62020-05-08 18:06:25941. Starts [Goma]. (*Non-Googlers* may need to disable this with `--nogoma`.)
Achuith Bhandarkar61f58962018-08-29 00:05:31951. `--download-vm` will download a Chrome OS VM and a QEMU binary.
96
Steven Bennetts8a0efd92018-11-27 17:32:5297### cros chrome-sdk options
Steven Bennetts7f08b002018-06-29 23:28:4498
Ryo Hashimotoaccfa882020-06-19 15:01:4199* `--chrome-branding` Sets up Simple Chrome to build and deploy the internal *Chrome* instead of *Chromium*.
100* `--official` Enables the official build level of optimization.
Steven Bennetts8a0efd92018-11-27 17:32:52101* `--gn-extra-args='extra_arg=foo other_extra_arg=bar'` For setting
102 extra gn args, e.g. 'dcheck_always_on=true'.
Steven Bennetts7f08b002018-06-29 23:28:44103* `--log-level=info` Sets the log level to 'info' or 'debug' (default is
104 'warn').
Erik Chen256c2d22020-01-10 23:41:04105* `--nogn-gen` Do not run 'gn gen' automatically. Use this option to persist
106 changes made to a previous session's gn args.
Steven Bennetts8a0efd92018-11-27 17:32:52107
Ryo Hashimotoaccfa882020-06-19 15:01:41108> **Googlers**: Use `--chrome-branding` if you need a branded *Chrome* build including resources and components from src-internal to work on internal features like ARC and assistant. `--official` doesn't involve branding, instead it enables an additional level of optimization and removes development conveniences like runtime stack traces. Use it for performance testing, not for debugging.
109
Claudio Mb5f7d762020-05-04 05:13:59110**Chrome OS developers**
111
112Use the following command:
113```
Ryo Hashimotoaccfa882020-06-19 15:01:41114(shell) cros chrome-sdk --chrome-branding --board=$BOARD --log-level=info
Claudio Mb5f7d762020-05-04 05:13:59115```
116
117*Optional*: Please help development by setting `dcheck_always_on=true` and filing
118bugs if you encounter any DCHECK crashes:
Steven Bennetts8a0efd92018-11-27 17:32:52119```
Ryo Hashimotoaccfa882020-06-19 15:01:41120(shell) cros chrome-sdk --chrome-branding --board=$BOARD --log-level=info --gn-extra-args='dcheck_always_on=true'
Steven Bennetts8a0efd92018-11-27 17:32:52121```
Pranav Batrabe53d222020-10-07 19:42:22122Alternatively, you can set `dcheck_is_configurable=true` to log DCHECK errors without crashing.
Steven Bennetts8a0efd92018-11-27 17:32:52123
124### cros chrome-sdk tips
Satoru Takabayashieef6f592017-06-23 04:16:36125
Achuith Bhandarkar61f58962018-08-29 00:05:31126> **Important:** When you sync/update your Chrome source, the Chrome OS SDK
Steven Bennetts7f08b002018-06-29 23:28:44127> version (src/chromeos/CHROMEOS_LKGM) may change. When the SDK version changes
128> you may need to exit and re-enter the Simple Chrome environment to
Achuith Bhandarkar61f58962018-08-29 00:05:31129> successfully build and deploy Chrome.
Satoru Takabayashieef6f592017-06-23 04:16:36130
Steven Bennetts8a0efd92018-11-27 17:32:52131> **Non-Googlers**: Only generic boards have publicly available SDK downloads,
132> so you will need to use a generic board (e.g. amd64-generic) or your own
133> Chrome OS build (see [Using a custom Chrome OS build]). For more info and
134> updates star [crbug.com/360342].
135
Achuith Bhandarkar61f58962018-08-29 00:05:31136> **Note**: See also [Using a custom Chrome OS build].
Satoru Takabayashieef6f592017-06-23 04:16:36137
Ben Pastene2c4e46b2020-08-04 20:38:36138### Shell-less flow
139
140It's also possible to follow all these instructions _outside_ the Simple Chrome
141SDK shell, which conforms more closely to how the browser is built for its
142other supported platforms. In this alternative workflow, the `cros chrome-sdk`
143is never called directly by hand, but instead called once during `gclient sync`.
144
145To do this, simply add the board you're interested in to the `cros_boards`
146[custom gclient var] of your .gclient file. The board's SDK will then be
147downloaded (and cached) everytime you run `gclient sync`, which should be run
148after every update to your chromium checkout. Similar to the shell, this will
149also create a convenient build dir at `out_$BOARD/Release`. However, GN won't
150automatically run in that dir. So to proceed with compilation, run:
151
152```
153(shell) gn gen out_$BOARD/Release
154```
155
156Then to compile Chrome:
157
158```
159(shell) autoninja -C out_$BOARD/Release chrome
160```
161
162And any tool or script you would run inside the shell needs to be tweaked to
163include the full path inside chromite, and may need the board explicitly passed.
164For example, a `deploy_chrome` invocation outside the shell looks like:
165
166```
167(shell) ./third_party/chromite/bin/deploy_chrome --build-dir=out_${BOARD}/Release --device=$IP_ADDR --board=${BOARD}
168```
169
170This shell-less flow is currently in use by all of [Chrome's builders], so
171there's some guarantee that it will function correctly. Conversely, the
172traditional flow that uses the shell has no such continuous build coverage and
173is mostly community-supported. In practice, however, the two flows are mostly
174identical under the hood. So if one works, the other is likely to as well.
175
Steven Bennetts7f08b002018-06-29 23:28:44176---
Steven Bennetts5a79a1c2017-11-27 20:05:47177
178## Build Chrome
179
Satoru Takabayashieef6f592017-06-23 04:16:36180To build Chrome, run:
181
182```
Jorge Lucangeli Obes12c0b7a2019-02-26 16:36:45183(sdk) autoninja -C out_${SDK_BOARD}/Release chrome nacl_helper
Satoru Takabayashieef6f592017-06-23 04:16:36184```
185
Jorge Lucangeli Obes12c0b7a2019-02-26 16:36:45186> **Note**: Targets other than **chrome**, **nacl_helper** or
Steven Bennetts7f08b002018-06-29 23:28:44187> (optionally) **chromiumos_preflight** are not supported in Simple Chrome and
Achuith Bhandarkar61f58962018-08-29 00:05:31188> will likely fail. browser_tests should be run outside the Simple Chrome
189> environment. Some unit_tests may be built in the Simple Chrome environment and
190> run in the Chrome OS VM. For details, see
191> [Running a Chrome Google Test binary in the VM].
Satoru Takabayashieef6f592017-06-23 04:16:36192
Achuith Bhandarkar61f58962018-08-29 00:05:31193> **Note**: Simple Chrome uses [Goma]. To watch the build progress, find the
194> Goma port (`$ echo $SDK_GOMA_PORT`) and open http://localhost:<port_number>
195> in a browser.
Satoru Takabayashieef6f592017-06-23 04:16:36196
Steven Bennetts7f08b002018-06-29 23:28:44197> **Note:** The default extensions will be installed by the test image you use
198> below.
Satoru Takabayashieef6f592017-06-23 04:16:36199
Steven Bennetts7f08b002018-06-29 23:28:44200---
Satoru Takabayashieef6f592017-06-23 04:16:36201
Achuith Bhandarkar61f58962018-08-29 00:05:31202## Set up the Chrome OS device
Satoru Takabayashieef6f592017-06-23 04:16:36203
Achuith Bhandarkar61f58962018-08-29 00:05:31204### Getting started
205
206You need the following:
2071. USB flash drive 4 GB or larger (for example, a Sandisk Extreme USB 3.0)
2081. USB to Gigabit Ethernet adapter
209
210Before you can deploy your build of Chrome to the device, it needs to have a
Steven Bennetts7f08b002018-06-29 23:28:44211"test" OS image loaded on it. A test image has tools like rsync that are not
Achuith Bhandarkar928352e2020-01-16 20:20:59212part of the base image.
Steven Bennetts7f08b002018-06-29 23:28:44213
Achuith Bhandarkar61f58962018-08-29 00:05:31214Chrome should be deployed to a recent Chrome OS test image, ideally the
215version shown in your SDK prompt (or `(sdk) echo $SDK_VERSION`).
Satoru Takabayashieef6f592017-06-23 04:16:36216
217### Create a bootable USB stick
218
Steven Bennetts7f08b002018-06-29 23:28:44219**Non-Googlers**: The build infrastructure is currently in flux. See
Achuith Bhandarkar61f58962018-08-29 00:05:31220[crbug.com/360342] for more details. You may need to build your own Chrome OS
221image.
James Cookb181cf72017-08-04 19:41:53222
Achuith Bhandarkar928352e2020-01-16 20:20:59223Flash the latest canary test image to your USB stick using `cros flash`:
Satoru Takabayashieef6f592017-06-23 04:16:36224
225```
Achuith Bhandarkar928352e2020-01-16 20:20:59226(sdk) cros flash usb:// xbuddy://remote/${SDK_BOARD}/latest-canary
Satoru Takabayashieef6f592017-06-23 04:16:36227```
228
Achuith Bhandarkar928352e2020-01-16 20:20:59229You can also flash an image with the sdk version (the SDK prompt has the
230full version, for instance, R81-12750.0.0):
Satoru Takabayashieef6f592017-06-23 04:16:36231
232```
Achuith Bhandarkar928352e2020-01-16 20:20:59233(sdk) cros flash usb:// xbuddy://remote/${SDK_BOARD}/R81-12750.0.0
Satoru Takabayashieef6f592017-06-23 04:16:36234```
235
Achuith Bhandarkar928352e2020-01-16 20:20:59236> **Tip:** If the device already has a test image installed, the following
237can be used to update the device directly.
Steven Bennetts7f08b002018-06-29 23:28:44238
239```
Achuith Bhandarkar928352e2020-01-16 20:20:59240(sdk) $ cros flash $IP_ADDR xbuddy://remote/${SDK_BOARD}/latest-canary
Steven Bennetts7f08b002018-06-29 23:28:44241```
242
Achuith Bhandarkar928352e2020-01-16 20:20:59243See the [CrOS Flash page] for more details.
244
Satoru Takabayashieef6f592017-06-23 04:16:36245### Put your Chrome OS device in dev mode
246
Steven Bennetts0d195912018-09-18 23:37:39247You can skip this section if you're using a [VM].
Achuith Bhandarkar61f58962018-08-29 00:05:31248
Steven Bennetts7f08b002018-06-29 23:28:44249> **Note:** Switching to dev mode wipes all data from the device (for security
250> reasons).
James Cook961c57d2018-01-23 21:34:05251
James Cook93506b02018-01-17 06:13:07252Most recent devices can use the [generic instructions]. To summarize:
Satoru Takabayashieef6f592017-06-23 04:16:36253
Steven Bennetts7f08b002018-06-29 23:28:442541. With the device on, hit Esc + Refresh (F2 or F3) + power button
2551. Wait for the white "recovery screen"
2561. Hit Ctrl-D to switch to developer mode (there's no prompt)
2571. Press enter to confirm
2581. Once it is done, hit Ctrl-D again to boot, then wait
Satoru Takabayashieef6f592017-06-23 04:16:36259
James Cook961c57d2018-01-23 21:34:05260From this point on you'll always see the white screen when you turn on
James Cook3a2a0632018-01-18 06:21:56261the device. Press Ctrl-D to boot.
James Cook93506b02018-01-17 06:13:07262
263Older devices may have [device-specific instructions].
264
Steven Bennetts7f08b002018-06-29 23:28:44265*Googlers*: If the device asks you to "enterprise enroll", click the X in the
266top-right of the dialog to skip it. Trying to use your google.com credentials
267will result in an error.
James Cook3a2a0632018-01-18 06:21:56268
James Cook93506b02018-01-17 06:13:07269### Enable booting from USB
270
James Cook3a2a0632018-01-18 06:21:56271By default Chromebooks will not boot off a USB stick for security reasons.
James Cook961c57d2018-01-23 21:34:05272You need to enable it.
James Cook3a2a0632018-01-18 06:21:56273
Steven Bennetts7f08b002018-06-29 23:28:442741. Start the device
2751. Press Ctrl-Alt-F2 to get a terminal. (You can use Ctrl-Alt-F1 to switch
276 back if you need to.)
2771. Login as `root` (no password yet, there will be one later)
2781. Run `enable_dev_usb_boot`
James Cook3d135382017-10-16 16:58:01279
Satoru Takabayashieef6f592017-06-23 04:16:36280### Install the test image onto your device
281
Steven Bennetts7f08b002018-06-29 23:28:44282> **Note:** Do not log into this test image with a username and password you
283> care about. The root password is public ("test0000"), so anyone with SSH
284> access could compromise the device. Create a test Gmail account and use that.
Satoru Takabayashieef6f592017-06-23 04:16:36285
Steven Bennetts7f08b002018-06-29 23:28:442861. Plug the USB stick into the machine and reboot.
2871. At the dev-mode warning screen, press Ctrl-U to boot from the USB stick.
2881. Switch to terminal by pressing Ctrl-Alt-F2
2891. Login as user `chronos`, password `test0000`.
2901. Run `/usr/sbin/chromeos-install`
2911. Wait for it to copy the image
2921. Run `poweroff`
James Cook3a2a0632018-01-18 06:21:56293
294You can now unplug the USB stick.
295
Steven Bennetts7f08b002018-06-29 23:28:44296### Connect device to Ethernet
297
298Use your USB-to-Ethernet adapter to connect the device to a network.
299
James Cook614fafc2019-01-22 23:21:02300*Googlers*: If your building has Ethernet jacks connected to the test VLAN
301(e.g. white ports), use one of those jacks. Otherwise get a second Ethernet
302adapter and see [go/shortleash] to reverse tether your Chromebook to your
303workstation.
Steven Bennetts7f08b002018-06-29 23:28:44304
Satoru Takabayashieef6f592017-06-23 04:16:36305### Checking the IP address
306
Steven Bennetts7f08b002018-06-29 23:28:443071. Click the status area in the lower-right corner
3081. Click the network icon
3091. Click the circled `i` symbol in the lower-right corner
3101. A small window pops up that shows the IP address
Satoru Takabayashieef6f592017-06-23 04:16:36311
Steven Bennetts7f08b002018-06-29 23:28:44312You can also run `ifconfig` from the terminal (Ctrl-Alt-F2).
James Cook3a2a0632018-01-18 06:21:56313
Achuith Bhandarkar61f58962018-08-29 00:05:31314---
315
316## Deploying Chrome to the device
317
318To deploy the build to a device/VM, you will need direct SSH access to it from
319your computer. The scripts below handle everything else.
320
Satoru Takabayashieef6f592017-06-23 04:16:36321### Using deploy_chrome
322
Achuith Bhandarkar61f58962018-08-29 00:05:31323The `deploy_chrome` script uses rsync to incrementally deploy Chrome to the
324device/VM.
Satoru Takabayashieef6f592017-06-23 04:16:36325
Achuith Bhandarkar61f58962018-08-29 00:05:31326Specify the build output directory to deploy from using `--build-dir`. For the
Steven Bennetts0d195912018-09-18 23:37:39327[VM]:
Satoru Takabayashieef6f592017-06-23 04:16:36328
329```
Ben Pastene2c4e46b2020-08-04 20:38:36330(sdk) deploy_chrome --build-dir=out_${SDK_BOARD}/Release --device=localhost:9222
Achuith Bhandarkar61f58962018-08-29 00:05:31331```
332
333For a physical device, which must be ssh-able as user 'root', you must specify
Ben Pastene2c4e46b2020-08-04 20:38:36334the IP address using `--device`:
Achuith Bhandarkar61f58962018-08-29 00:05:31335
336```
Ben Pastene2c4e46b2020-08-04 20:38:36337(sdk) deploy_chrome --build-dir=out_${SDK_BOARD}/Release --device=$IP_ADDR
Satoru Takabayashieef6f592017-06-23 04:16:36338```
339
Steven Bennetts7f08b002018-06-29 23:28:44340> **Note:** The first time you run this you will be prompted to remove rootfs
341> verification from the device. This is required to overwrite /opt/google/chrome
342> and will reboot the device. You can skip the prompt with `--force`.
Satoru Takabayashieef6f592017-06-23 04:16:36343
Steven Bennetts7f08b002018-06-29 23:28:44344### Deploying Chrome to the user partition
Satoru Takabayashieef6f592017-06-23 04:16:36345
Steven Bennetts7f08b002018-06-29 23:28:44346It is also possible to deploy Chrome to the user partition of the device and
Achuith Bhandarkard2570122018-08-03 00:56:43347set up a temporary mount from `/opt/google/chrome` using the option `--mount`.
348This is useful when deploying a binary that will not otherwise fit on the
349device, e.g.:
Satoru Takabayashieef6f592017-06-23 04:16:36350
Steven Bennetts7f08b002018-06-29 23:28:44351* When using `--nostrip` to provide symbols for backtraces.
352* When using other compile options that produce a significantly larger image.
James Cookba126f12017-08-21 19:59:07353
Steven Bennetts7f08b002018-06-29 23:28:44354```
Ben Pastene2c4e46b2020-08-04 20:38:36355(sdk) deploy_chrome --build-dir=out_$SDK_BOARD/Release --device=$IP_ADDR --mount [--nostrip]
Steven Bennetts7f08b002018-06-29 23:28:44356```
357
Achuith Bhandarkard2570122018-08-03 00:56:43358> **Note:** This also prompts to remove rootfs verification so that
Steven Bennetts7f08b002018-06-29 23:28:44359> /etc/chrome_dev.conf can be modified (see [Command-line flags and
360> environment variables]). You can skip that by adding
361> `--noremove-rootfs-verification`.
362
363#### Additional Notes:
364
Achuith Bhandarkard2570122018-08-03 00:56:43365* The mount is transient and does not survive a reboot. The easiest way to
366 reinstate the mount is to run the same deploy_chrome command after reboot.
367 It will only redeploy binaries if there is a change. To verify that the
368 mount is active, run `findmnt /opt/google/chrome`. The output should be:
369```
370TARGET SOURCE FSTYPE OPTIONS
371/opt/google/chrome /dev/sda1[/deploy_rootfs/opt/google/chrome] ext4 rw,nodev,noatime,resgid=20119,commit=600,data=ordered
372```
Steven Bennetts7f08b002018-06-29 23:28:44373* If startup needs to be tested (i.e. before deploy_chrome can be run), a
374 symbolic link will need to be created instead:
375 * ssh to device
Roman Sorokin1c9c7682019-09-17 02:26:26376 * `mkdir /usr/local/chrome`
Steven Bennetts7f08b002018-06-29 23:28:44377 * `rm -R /opt/google/chrome`
Roman Sorokin1c9c7682019-09-17 02:26:26378 * `ln -s /usr/local/chrome /opt/google/chrome`
Ben Pastene2c4e46b2020-08-04 20:38:36379 * `deploy_chrome --build-dir=out_${SDK_BOARD}/Release --device=$IP_ADDR
Steven Bennetts7f08b002018-06-29 23:28:44380 --nostrip`
381 * The device can then be rebooted and the unstripped version of Chrome
382 will be run.
383* `deploy_chrome` lives under `$CHROME_DIR/src/third_party/chromite/bin`.
384 You can run `deploy_chrome` outside of a `chrome-sdk` shell.
385
386## Updating the Chrome OS image
387
388In order to keep Chrome and Chrome OS in sync, the Chrome OS test image
389should be updated weekly. See [Create a bootable USB stick] for a tip on
Achuith Bhandarkar61f58962018-08-29 00:05:31390updating an existing test device if you have a Chrome OS checkout.
Steven Bennetts7f08b002018-06-29 23:28:44391
392---
James Cookba126f12017-08-21 19:59:07393
Satoru Takabayashieef6f592017-06-23 04:16:36394## Debugging
395
Satoru Takabayashi7cc76c92017-06-26 04:46:05396### Log files
Satoru Takabayashieef6f592017-06-23 04:16:36397
Achuith Bhandarkar8bca7812019-02-06 20:51:10398[Chrome-related logs] are written to several locations on the device running a
399test image:
Satoru Takabayashieef6f592017-06-23 04:16:36400
Steven Bennetts7f08b002018-06-29 23:28:44401* `/var/log/ui/ui.LATEST` contains messages written to stderr by Chrome
402 before its log file has been initialized.
Achuith Bhandarkar8bca7812019-02-06 20:51:10403* `/var/log/chrome/chrome` contains messages logged by Chrome both before and
404 after login since Chrome runs with `--disable-logging-redirect` on test
405 images.
Steven Bennetts7f08b002018-06-29 23:28:44406* `/var/log/messages` contains messages logged by `session_manager`
407 (which is responsible for starting Chrome), in addition to kernel
408 messages when a Chrome process crashes.
Satoru Takabayashi7cc76c92017-06-26 04:46:05409
410### Command-line flags and environment variables
Satoru Takabayashieef6f592017-06-23 04:16:36411
412If you want to tweak the command line of Chrome or its environment, you have to
413do this on the device itself.
414
Satoru Takabayashieef6f592017-06-23 04:16:36415Edit the `/etc/chrome_dev.conf` (device) file. Instructions on using it are in
416the file itself.
417
James Cook961c57d2018-01-23 21:34:05418### Custom build directories
419
420This step is only necessary if you run `cros chrome-sdk` with `--nogn-gen`.
421
422To create a GN build directory, run the following inside the chrome-sdk shell:
423
424```
Achuith Bhandarkar61f58962018-08-29 00:05:31425(sdk) gn gen out_$SDK_BOARD/Release --args="$GN_ARGS"
James Cook961c57d2018-01-23 21:34:05426```
427
428This will generate `out_$SDK_BOARD/Release/args.gn`.
429
Steven Bennetts7f08b002018-06-29 23:28:44430* You must specify `--args`, otherwise your build will not work on the device.
431* You only need to run `gn gen` once within the same `cros chrome-sdk`
432 session.
433* However, if you exit the session or sync/update Chrome the `$GN_ARGS` might
434 change and you need to `gn gen` again.
James Cook961c57d2018-01-23 21:34:05435
436You can edit the args with:
437
438```
Achuith Bhandarkar61f58962018-08-29 00:05:31439(sdk) gn args out_$SDK_BOARD/Release
James Cook961c57d2018-01-23 21:34:05440```
441
442You can replace `Release` with `Debug` (or something else) for different
Steven Bennetts7f08b002018-06-29 23:28:44443configurations. See [Debug builds].
James Cook961c57d2018-01-23 21:34:05444
445[GN build configuration] discusses various GN build configurations. For more
446info on GN, run `gn help` on the command line or read the [quick start guide].
447
Steven Bennetts7f08b002018-06-29 23:28:44448### Debug builds
Satoru Takabayashieef6f592017-06-23 04:16:36449
450For cros chrome-sdk GN configurations, Release is the default. A debug build of
451Chrome will include useful tools like DCHECK and debug logs like DVLOG. For a
452Debug configuration, specify
Achuith Bhandarkar61f58962018-08-29 00:05:31453`--args="$GN_ARGS is_debug=true is_component_build=false"`.
Satoru Takabayashieef6f592017-06-23 04:16:36454
455Alternately, you can just turn on DCHECKs for a release build. You can do this
456with `--args="$GN_ARGS dcheck_always_on=true"`.
457
Steven Bennetts7f08b002018-06-29 23:28:44458To deploy a debug build you need to add `--nostrip` to `deploy_chrome` because
459otherwise it will strip symbols even from a debug build. This requires
460[Deploying Chrome to the user partition].
Satoru Takabayashieef6f592017-06-23 04:16:36461
Eliot Courtneyaf7edf32020-06-16 05:49:50462See [./stack_traces.md] for some tips on getting stack traces at runtime
463(not during a crash).
464
Steven Bennetts7f08b002018-06-29 23:28:44465> **Note:** If you just want crash backtraces in the logs you can deploy a
466> release build with `--nostrip`. You don't need a debug build (but you still
467> need to deploy to a user partition).
468>
469> **Note:** You may hit `DCHECKs` during startup time, or when you login, which
470> eventually may reboot the device. You can check log files in `/var/log/chrome`
471> or `/home/chronos/user/log`.
472>
473> You can create `/run/disable_chrome_restart` to prevent a restart loop and
474> investigate.
475>
476> You can temporarily disable these `DCHECKs` to proceed, but please file a
477> bug for such `DCHECK` because it's most likely a bug.
Satoru Takabayashieef6f592017-06-23 04:16:36478
479### Remote GDB
480
Satoru Takabayashi7cc76c92017-06-26 04:46:05481Core dumps are disabled by default. See [additional debugging tips] for how to
Satoru Takabayashieef6f592017-06-23 04:16:36482enable core files.
483
484On the target machine, open up a port for the gdb server to listen on, and
Satoru Takabayashi7cc76c92017-06-26 04:46:05485attach the gdb server to the top-level Chrome process.
Satoru Takabayashieef6f592017-06-23 04:16:36486
487```
488(device) sudo /sbin/iptables -A INPUT -p tcp --dport 1234 -j ACCEPT
Steven Bennetts8a0efd92018-11-27 17:32:52489(device) sudo gdbserver --attach :1234 $(pgrep chrome -P $(pgrep session_manager))
Satoru Takabayashieef6f592017-06-23 04:16:36490```
491
492On your host machine (inside the chrome-sdk shell), run gdb and start the Python
493interpreter:
494
495```
Achuith Bhandarkar61f58962018-08-29 00:05:31496(sdk) cd %CHROME_DIR%/src
497(sdk) gdb out_${SDK_BOARD}/Release/chrome
498Reading symbols from /usr/local/google2/chromium2/src/out_amd64-generic/Release/chrome...
Satoru Takabayashieef6f592017-06-23 04:16:36499(gdb) pi
500>>>
501```
502
Steven Bennetts7f08b002018-06-29 23:28:44503> **Note:** These instructions are for targeting an x86_64 device. For now, to
504> target an ARM device, you need to run the cross-compiled gdb from within a
505> chroot.
Satoru Takabayashieef6f592017-06-23 04:16:36506
507Then from within the Python interpreter, run these commands:
508
Steven Bennetts7f08b002018-06-29 23:28:44509```python
Satoru Takabayashieef6f592017-06-23 04:16:36510import os
511sysroot = os.environ['SYSROOT']
Achuith Bhandarkar61f58962018-08-29 00:05:31512board = os.environ['SDK_BOARD']
Satoru Takabayashieef6f592017-06-23 04:16:36513gdb.execute('set sysroot %s' % sysroot)
514gdb.execute('set solib-absolute-prefix %s' % sysroot)
515gdb.execute('set debug-file-directory %s/usr/lib/debug' % sysroot)
Achuith Bhandarkar61f58962018-08-29 00:05:31516# "Debug" for a debug build
517gdb.execute('set solib-search-path out_%s/Release/lib' % board)
Steven Bennetts7f08b002018-06-29 23:28:44518gdb.execute('target remote $IP_ADDR:1234')
Satoru Takabayashieef6f592017-06-23 04:16:36519```
520
521If you wish, after you connect, you can Ctrl-D out of the Python shell.
522
Achuith Bhandarkar61f58962018-08-29 00:05:31523Extra debugging instructions are located at [debugging tips].
Steven Bennetts7f08b002018-06-29 23:28:44524
525---
Satoru Takabayashieef6f592017-06-23 04:16:36526
527## Additional instructions
528
529### Updating the version of the Chrome OS SDK
530
531When you invoke `cros chrome-sdk`, the script fetches the version of the SDK
Steven Bennetts7f08b002018-06-29 23:28:44532that corresponds to your Chrome checkout. To update the SDK, sync your Chrome
Satoru Takabayashieef6f592017-06-23 04:16:36533checkout and re-run `cros chrome-sdk`.
534
535**IMPORTANT NOTES:**
536
Achuith Bhandarkar61f58962018-08-29 00:05:31537* Every time that you update Chrome or the Chrome OS SDK, it is possible
538 that Chrome may start depending on new features from a new Chrome OS
539 image. This can cause unexpected problems, so it is important to update
540 your image regularly. Instructions for updating your Chrome OS image are
541 above in [Set up the Chrome OS device]. This is not a concern for a
542 downloaded VM.
Steven Bennetts7f08b002018-06-29 23:28:44543* Don't forget to re-configure your custom build directories if you have them
544 (see [Custom build directories]).
Satoru Takabayashieef6f592017-06-23 04:16:36545
546### Specifying the version of the Chrome OS SDK to use
547
548You can specify a version of Chrome OS to build against. This is handy for
549tracking down when a particular bug was introduced.
550
551```
Achuith Bhandarkar61f58962018-08-29 00:05:31552(shell) cros chrome-sdk --board=$BOARD --version=11005.0.0
Satoru Takabayashieef6f592017-06-23 04:16:36553```
554
Achuith Bhandarkar61f58962018-08-29 00:05:31555Once you are finished testing the old version of the chrome-sdk, you can
556always start a new shell with the latest version again. Here's an example:
Satoru Takabayashieef6f592017-06-23 04:16:36557
558```
Achuith Bhandarkar61f58962018-08-29 00:05:31559(shell) cros chrome-sdk --board=$BOARD --clear-sdk-cache
Satoru Takabayashieef6f592017-06-23 04:16:36560```
561
562### Updating Chrome
563
Steven Bennetts7f08b002018-06-29 23:28:44564```
Achuith Bhandarkar61f58962018-08-29 00:05:31565(sdk) exit
566(shell) git checkout master && git pull # (or if you prefer, git rebase-update)
567(shell) gclient sync
568(shell) cros chrome-sdk --board=$BOARD --log-level=info
Steven Bennetts7f08b002018-06-29 23:28:44569```
Satoru Takabayashieef6f592017-06-23 04:16:36570
Steven Bennetts7f08b002018-06-29 23:28:44571> **Tip:** If you update Chrome inside the chrome-sdk, you may then be using an
572> SDK that is out of date with the current Chrome.
573> See [Updating the version of the Chrome OS SDK] section above.
574
Satoru Takabayashieef6f592017-06-23 04:16:36575
576### Updating Deployed Files
577
Steven Bennetts7f08b002018-06-29 23:28:44578`deploy_chrome` determines which files to copy in `chrome_util.py` in the
579[chromite repo] which is pulled into `chrome/src/third_party/chromite` via DEPS.
Satoru Takabayashieef6f592017-06-23 04:16:36580
Steven Bennetts7f08b002018-06-29 23:28:44581When updating the list:
Satoru Takabayashieef6f592017-06-23 04:16:36582
Steven Bennetts7f08b002018-06-29 23:28:445831. Make changes to the appropriate list (e.g. `_COPY_PATHS_CHROME`).
5841. Be aware that deploy_chrome is used by the chromeos-chrome ebuild, so when
585 adding new files make sure to set optional=True initially.
5861. Changes to chromite will not affect Simple Chrome until a chromite roll
587 occurs.
Satoru Takabayashieef6f592017-06-23 04:16:36588
Achuith Bhandarkar61f58962018-08-29 00:05:31589### Using a custom Chrome OS build
James Cookba126f12017-08-21 19:59:07590
Achuith Bhandarkar61f58962018-08-29 00:05:31591If you are making changes to Chrome OS and have a Chrome OS build inside a
James Cookba126f12017-08-21 19:59:07592chroot that you want to build against, run `cros chrome-sdk` with the `--chroot`
Steven Bennetts7f08b002018-06-29 23:28:44593option:
James Cookba126f12017-08-21 19:59:07594
595```
Achuith Bhandarkar61f58962018-08-29 00:05:31596(shell) cros chrome-sdk --board=$BOARD --chroot=/path/to/chromiumos/chroot
James Cookba126f12017-08-21 19:59:07597```
598
Harry Cutts2cfd02d2019-03-23 00:33:11599### Running tests
600
Xiyuan Xia6c8ef612019-04-26 22:30:22601Chrome's unit and browser tests are compiled into test binaries. At the moment,
602not all of them run on a Chrome OS device. Most of the unit tests and part of
603interactive_ui_tests that measure Chrome OS performance should work.
604
605To build and run a chrome test on device (or VM),
606```bash
607(sdk) .../chrome/src $ cros_run_test --build --device=$IP --chrome-test -- \
David Pursehouseb3b7da12019-06-17 12:23:39608out_$SDK_BOARD/Release/interactive_ui_tests \
Xiyuan Xia6c8ef612019-04-26 22:30:22609 --dbus-stub \
610 --enable-pixel-output-in-tests \
611 --gtest_filter=SplitViewTest.SplitViewResize
612```
613
614Alternatively, manually build and use the generated `run_$TEST` scripts to run
615like build bots:
616```bash
617(sdk) .../chrome/src $ autoninja -C out_$SDK_BOARD/Release interactive_ui_tests
618(sdk) .../chrome/src $ out_$SDK_BOARD/Release/bin/run_interactive_ui_tests \
619 --device=$IP \
620 --dbus-stub \
621 --enable-pixel-output-in-tests \
622 --gtest_filter=SplitViewTest.SplitViewResize
623```
624
625To run tests locally on dev box, follow the [instructions for running tests on
626Linux] using a separate GN build directory with `target_os = "chromeos"` in its
627arguments. (You can create one using the `gn args` command.)
Harry Cutts2cfd02d2019-03-23 00:33:11628
629If you're running tests which create windows on-screen, you might find the
630instructions for using an embedded X server in [web_tests_linux.md] useful.
631
Steven Bennetts7f08b002018-06-29 23:28:44632### Setting a custom prompt
Satoru Takabayashieef6f592017-06-23 04:16:36633
634By default, cros chrome-sdk prepends something like '`(sdk link R52-8315.0.0)`'
Satoru Takabayashi7cc76c92017-06-26 04:46:05635to the prompt (with the version of the prebuilt system being used).
Satoru Takabayashieef6f592017-06-23 04:16:36636
637If you prefer to colorize the prompt, you can set `PS1` in
Achuith Bhandarkar61f58962018-08-29 00:05:31638`~/.chromite/chrome_sdk.bashrc`, e.g. to prepend a yellow
639'`(sdk link 8315.0.0)`' to the prompt:
Satoru Takabayashieef6f592017-06-23 04:16:36640
641```
642PS1='\[\033[01;33m\](sdk ${SDK_BOARD} ${SDK_VERSION})\[\033[00m\] \w \[\033[01;36m\]$(__git_ps1 "(%s)")\[\033[00m\] \$ '
643```
Steven Bennetts7f08b002018-06-29 23:28:44644NOTE: Currently the release version (e.g. 52) is not available as an
645environment variable.
Satoru Takabayashieef6f592017-06-23 04:16:36646
Achuith Bhandarkar61f58962018-08-29 00:05:31647[Custom build directories]: #custom-build-directories
648[Updating the version of the Chrome OS SDK]: #updating-the-version-of-the-chrome-os-sdk
649[Using a custom Chrome OS build]: #using-a-custom-chrome-os-build
Ben Pastene2c4e46b2020-08-04 20:38:36650[custom gclient var]: https://chromium.googlesource.com/chromium/src/+/HEAD/docs/chromeos_build_instructions.md#additional-gclient-setup
651[Chrome's builders]: chrome_commit_pipeline.md#the-chromium-waterfall
Achuith Bhandarkar61f58962018-08-29 00:05:31652[Command-line flags and environment variables]: #command-line-flags-and-environment-variables
653[Deploying Chrome to the user partition]: #deploying-chrome-to-the-user-partition
654[Debug builds]: #debug-builds
655[Create a bootable USB stick]: #create-a-bootable-usb-stick
656[Set up the Chrome OS device]: #set-up-the-chrome-os-device
Mike Frysinger9fc0fc02020-09-05 05:18:57657[OS development guide]: developer_guide.md
658[Chrome source code and depot_tools]: https://chromium.googlesource.com/chromium/src/+/HEAD/docs/linux/build_instructions.md
659[instructions for running tests on Linux]: https://chromium.googlesource.com/chromium/src/+/HEAD/docs/linux/build_instructions.md#Running-test-targets
Steven Bennetts7f08b002018-06-29 23:28:44660[update .gclient]: https://chromium.googlesource.com/chromium/src/+/HEAD/docs/chromeos_build_instructions.md#updating-your-gclient-config
Achuith Bhandarkar61f58962018-08-29 00:05:31661[Chrome OS board name]: https://www.chromium.org/chromium-os/developer-information-for-chrome-os-devices
Steven Bennetts7f08b002018-06-29 23:28:44662[GN build configuration]: https://www.chromium.org/developers/gn-build-configuration
Mike Frysinger9fc0fc02020-09-05 05:18:57663[quick start guide]: https://gn.googlesource.com/gn/+/HEAD/docs/quick_start.md
James Cook3d135382017-10-16 16:58:01664[device-specific instructions]: https://www.chromium.org/chromium-os/developer-information-for-chrome-os-devices
665[generic instructions]: https://www.chromium.org/a/chromium.org/dev/chromium-os/developer-information-for-chrome-os-devices/generic
Evan Benn6a6383b2019-10-31 23:01:07666[rootfs has been removed]: developer_mode.md#TOC-Making-changes-to-the-filesystem
Steven Bennetts7f08b002018-06-29 23:28:44667[remounted as read-write]: https://www.chromium.org/chromium-os/how-tos-and-troubleshooting/debugging-tips#TOC-Setting-up-the-device
668[additional debugging tips]: https://www.chromium.org/chromium-os/how-tos-and-troubleshooting/debugging-tips#TOC-Enabling-core-dumps
Satoru Takabayashieef6f592017-06-23 04:16:36669[chromite repo]: https://chromium.googlesource.com/chromiumos/chromite/
Mike Frysinger9fc0fc02020-09-05 05:18:57670[issue 437877]: https://crbug.com/403086
671[CrOS Flash page]: cros_flash.md
672[VM]: cros_vm.md
673[Running a Chrome Google Test binary in the VM]: cros_vm.md#Run-a-Chrome-GTest-binary-in-the-VM
James Cook614fafc2019-01-22 23:21:02674[go/shortleash]: https://goto.google.com/shortleash
Achuith Bhandarkar61f58962018-08-29 00:05:31675[debugging tips]: https://www.chromium.org/chromium-os/how-tos-and-troubleshooting/debugging-tips
Achuith Bhandarkar83630262020-05-24 10:20:59676[chrome build instructions]: https://g3doc.corp.google.com/company/teams/chrome/linux_build_instructions.md
Achuith Bhandarkar61f58962018-08-29 00:05:31677[api-keys]: https://www.chromium.org/developers/how-tos/api-keys
Mike Frysinger9fc0fc02020-09-05 05:18:57678[install-build-deps-android.sh]: https://chromium.googlesource.com/chromium/src/+/HEAD/build/install-build-deps-android.sh
Evan Benn6a6383b2019-10-31 23:01:07679[Goma]: https://chromium.googlesource.com/infra/goma/client/
Achuith Bhandarkar8bca7812019-02-06 20:51:10680[Chrome-related logs]: https://chromium.googlesource.com/chromium/src/+/lkgr/docs/chrome_os_logging.md
Mike Frysinger9fc0fc02020-09-05 05:18:57681[crbug.com/360342]: https://crbug.com/360342
682[crbug.com/403086]: https://crbug.com/403086
683[web_tests_linux.md]: https://chromium.googlesource.com/chromium/src/+show/HEAD/docs/web_tests_linux.md
684[./stack_traces.md]: stack_traces.md