blob: d688afe41ef9a2c4c68d557e0154c18dd160d66a [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
Achuith Bhandarkar61f58962018-08-29 00:05:313This workflow allows you to quickly build/deploy Chrome to a Chrome OS
Steven Bennetts0d195912018-09-18 23:37:394[VM] or device without needing a Chrome OS source checkout or chroot. It's useful
Achuith Bhandarkar61f58962018-08-29 00:05:315for trying out your changes on Chrome OS while you're doing Chrome
6development. If you have an OS checkout and want your local Chrome changes to
James Cook961c57d2018-01-23 21:34:057be included when building a full OS image, see the [OS development guide].
Satoru Takabayashieef6f592017-06-23 04:16:368
James Cook961c57d2018-01-23 21:34:059At its core is the `chrome-sdk` shell which sets up the shell environment and
Achuith Bhandarkar61f58962018-08-29 00:05:3110fetches the necessary SDK components (Chrome OS toolchain, sysroot, VM, etc.).
Satoru Takabayashieef6f592017-06-23 04:16:3611
12[TOC]
13
14## Typography conventions
15
Achuith Bhandarkar61f58962018-08-29 00:05:3116| Label | Paths, files, and commands |
17|---------------|-------------------------------------------------------|
18| (shell) | outside the chroot and SDK shell on your workstation |
19| (sdk) | inside the `chrome-sdk` SDK shell on your workstation |
20| (chroot) | inside the `cros_sdk` chroot on your workstation |
Steven Bennetts0d195912018-09-18 23:37:3921| (device) | in your [VM] or Chrome OS device |
Satoru Takabayashieef6f592017-06-23 04:16:3622
Satoru Takabayashieef6f592017-06-23 04:16:3623
James Cookba126f12017-08-21 19:59:0724## Getting started
Satoru Takabayashieef6f592017-06-23 04:16:3625
Achuith Bhandarkar61f58962018-08-29 00:05:3126Check out a copy of the [Chrome source code and depot_tools].
27Be certain to [update .gclient] to include `target_os = ["chromeos"]`.
Satoru Takabayashieef6f592017-06-23 04:16:3628
Steven Bennetts7f08b002018-06-29 23:28:4429### Get the Google API keys
Satoru Takabayashieef6f592017-06-23 04:16:3630
Achuith Bhandarkar61f58962018-08-29 00:05:3131In order to sign in to Chrome OS you must have Google API keys:
Satoru Takabayashieef6f592017-06-23 04:16:3632
Achuith Bhandarkar61f58962018-08-29 00:05:3133* External contributors: See [api-keys]. You'll need to put them in your
34 `out_$BOARD/Release/args.gn file`, see below.
35* *Googlers*: See [go/chrome-build-instructions] to get the internal source.
36 If you have `src-internal` in your `.gclient` file the official API keys
37 will be set up automatically.
Satoru Takabayashieef6f592017-06-23 04:16:3638
Steven Bennetts7f08b002018-06-29 23:28:4439### Set up gsutil
Satoru Takabayashieef6f592017-06-23 04:16:3640
James Cook961c57d2018-01-23 21:34:0541Use depot_tools/gsutil.py and run `gsutil.py config` to set the authentication
Steven Bennetts7f08b002018-06-29 23:28:4442token. (*Googlers*: Use your @google.com account.) Otherwise steps below may run
James Cook961c57d2018-01-23 21:34:0543slowly and fail with "Login Required" from gsutil.
James Cook3a2a0632018-01-18 06:21:5644
James Cook961c57d2018-01-23 21:34:0545When prompted for a project ID, enter `134157665460` (this is the Chrome OS
46project ID).
James Cook3a2a0632018-01-18 06:21:5647
Ben Pastene957ea272019-03-18 16:06:0148### Install build deps
49
50You'll also need to pull in Android native toolchain dependencies to build
51ARC++ support libraries. This is done by running the
52[install-build-deps-android.sh] script in Chrome's source code, located at
53`$CHROME_DIR/src/build/install-build-deps-android.sh`.
54
Achuith Bhandarkar61f58962018-08-29 00:05:3155### VM versus Device
56
Steven Bennetts0d195912018-09-18 23:37:3957The easiest way to develop on Chrome OS is to use a [VM].
58
59If you need to test hardware-specific features such as graphics acceleration,
60bluetooth, mouse or input events, etc, you may also use a physical device
61(Googlers: Chromestop has the hardware). See [Set up the Chrome OS device] for
62details.
Achuith Bhandarkar61f58962018-08-29 00:05:3163
Steven Bennetts7f08b002018-06-29 23:28:4464---
James Cook3a2a0632018-01-18 06:21:5665
Steven Bennetts7f08b002018-06-29 23:28:4466## Enter the Simple Chrome environment
Satoru Takabayashieef6f592017-06-23 04:16:3667
Steven Bennetts7f08b002018-06-29 23:28:4468Building Chrome for Chrome OS requires a toolchain customized for each
Steven Bennetts0d195912018-09-18 23:37:3969Chromebook model (or "board"). For the Chrome OS [VM], and non-Googlers, use
Achuith Bhandarkar61f58962018-08-29 00:05:3170`amd64-generic`. For a physical device, look up the [Chrome OS board name] by
Steven Bennetts7f08b002018-06-29 23:28:4471navigating to the URL `about:version` on the device. For example:
72`Platform 10176.47.0 (Official Build) beta-channel samus` has board `samus`.
73
Achuith Bhandarkar61f58962018-08-29 00:05:3174To enter the Simple Chrome environment, run these from within your Chrome
75checkout:
Steven Bennetts5a79a1c2017-11-27 20:05:4776
Satoru Takabayashieef6f592017-06-23 04:16:3677```
Achuith Bhandarkar61f58962018-08-29 00:05:3178(shell) cd /path/to/chrome/src
79(shell) export BOARD=amd64-generic
Junichi Uekawa4db84bb2019-07-02 09:33:5580(shell) cros chrome-sdk --board=$BOARD --log-level=info [--download-vm] [--gomadir=~/goma]
Satoru Takabayashieef6f592017-06-23 04:16:3681```
Satoru Takabayashieef6f592017-06-23 04:16:3682
Steven Bennetts7f08b002018-06-29 23:28:4483The command prompt will change to look like `(sdk $BOARD $VERSION)`.
Satoru Takabayashieef6f592017-06-23 04:16:3684
Steven Bennetts7f08b002018-06-29 23:28:4485Entering the Simple Chrome environment does the following:
Satoru Takabayashieef6f592017-06-23 04:16:3686
Steven Bennetts7f08b002018-06-29 23:28:44871. Fetches the Chrome OS toolchain and sysroot (SDK) for building Chrome.
881. Creates out_$BOARD/Release and generates or updates args.gn.
Junichi Uekawa4db84bb2019-07-02 09:33:55891. Installs and starts [Goma]. (*Non-Googlers* may need to disable this with
90 `--nogoma`, Googlers would want to reuse existing installation with
91 `--gomadir`.)
Achuith Bhandarkar61f58962018-08-29 00:05:31921. `--download-vm` will download a Chrome OS VM and a QEMU binary.
93
Steven Bennetts8a0efd92018-11-27 17:32:5294### cros chrome-sdk options
Steven Bennetts7f08b002018-06-29 23:28:4495
Steven Bennetts7f08b002018-06-29 23:28:4496* `--internal` Sets up Simple Chrome to build and deploy the official *Chrome*
97 instead of *Chromium*.
Steven Bennetts8a0efd92018-11-27 17:32:5298* `--gn-extra-args='extra_arg=foo other_extra_arg=bar'` For setting
99 extra gn args, e.g. 'dcheck_always_on=true'.
Steven Bennetts7f08b002018-06-29 23:28:44100* `--log-level=info` Sets the log level to 'info' or 'debug' (default is
101 'warn').
Steven Bennetts8a0efd92018-11-27 17:32:52102* `--nogn-gen` Do not run 'gn gen' automatically.
103
104**Chrome OS developers**: Please set `dcheck_always_on=true` and file bugs if
105you encounter any DCHECK crashes.
106```
107(shell) cros chrome-sdk --internal --board=$BOARD --log-level=info --gn-extra-args='dcheck_always_on=true'
108```
109
110### cros chrome-sdk tips
Satoru Takabayashieef6f592017-06-23 04:16:36111
Achuith Bhandarkar61f58962018-08-29 00:05:31112> **Important:** When you sync/update your Chrome source, the Chrome OS SDK
Steven Bennetts7f08b002018-06-29 23:28:44113> version (src/chromeos/CHROMEOS_LKGM) may change. When the SDK version changes
114> you may need to exit and re-enter the Simple Chrome environment to
Achuith Bhandarkar61f58962018-08-29 00:05:31115> successfully build and deploy Chrome.
Satoru Takabayashieef6f592017-06-23 04:16:36116
Steven Bennetts8a0efd92018-11-27 17:32:52117> **Non-Googlers**: Only generic boards have publicly available SDK downloads,
118> so you will need to use a generic board (e.g. amd64-generic) or your own
119> Chrome OS build (see [Using a custom Chrome OS build]). For more info and
120> updates star [crbug.com/360342].
121
Achuith Bhandarkar61f58962018-08-29 00:05:31122> **Note**: See also [Using a custom Chrome OS build].
Satoru Takabayashieef6f592017-06-23 04:16:36123
Steven Bennetts7f08b002018-06-29 23:28:44124---
Steven Bennetts5a79a1c2017-11-27 20:05:47125
126## Build Chrome
127
Satoru Takabayashieef6f592017-06-23 04:16:36128To build Chrome, run:
129
130```
Jorge Lucangeli Obes12c0b7a2019-02-26 16:36:45131(sdk) autoninja -C out_${SDK_BOARD}/Release chrome nacl_helper
Satoru Takabayashieef6f592017-06-23 04:16:36132```
133
Jorge Lucangeli Obes12c0b7a2019-02-26 16:36:45134> **Note**: Targets other than **chrome**, **nacl_helper** or
Steven Bennetts7f08b002018-06-29 23:28:44135> (optionally) **chromiumos_preflight** are not supported in Simple Chrome and
Achuith Bhandarkar61f58962018-08-29 00:05:31136> will likely fail. browser_tests should be run outside the Simple Chrome
137> environment. Some unit_tests may be built in the Simple Chrome environment and
138> run in the Chrome OS VM. For details, see
139> [Running a Chrome Google Test binary in the VM].
Satoru Takabayashieef6f592017-06-23 04:16:36140
Achuith Bhandarkar61f58962018-08-29 00:05:31141> **Note**: Simple Chrome uses [Goma]. To watch the build progress, find the
142> Goma port (`$ echo $SDK_GOMA_PORT`) and open http://localhost:<port_number>
143> in a browser.
Satoru Takabayashieef6f592017-06-23 04:16:36144
Steven Bennetts7f08b002018-06-29 23:28:44145> **Note:** The default extensions will be installed by the test image you use
146> below.
Satoru Takabayashieef6f592017-06-23 04:16:36147
Steven Bennetts7f08b002018-06-29 23:28:44148---
Satoru Takabayashieef6f592017-06-23 04:16:36149
Achuith Bhandarkar61f58962018-08-29 00:05:31150## Set up the Chrome OS device
Satoru Takabayashieef6f592017-06-23 04:16:36151
Achuith Bhandarkar61f58962018-08-29 00:05:31152### Getting started
153
154You need the following:
1551. USB flash drive 4 GB or larger (for example, a Sandisk Extreme USB 3.0)
1561. USB to Gigabit Ethernet adapter
157
158Before you can deploy your build of Chrome to the device, it needs to have a
Steven Bennetts7f08b002018-06-29 23:28:44159"test" OS image loaded on it. A test image has tools like rsync that are not
160part of the end-user image.
161
Achuith Bhandarkar61f58962018-08-29 00:05:31162Chrome should be deployed to a recent Chrome OS test image, ideally the
163version shown in your SDK prompt (or `(sdk) echo $SDK_VERSION`).
Satoru Takabayashieef6f592017-06-23 04:16:36164
165### Create a bootable USB stick
166
Achuith Bhandarkar61f58962018-08-29 00:05:31167**Googlers**: Images for all boards are available on [go/goldeneye]:
Satoru Takabayashieef6f592017-06-23 04:16:36168
Achuith Bhandarkar61f58962018-08-29 00:05:311691. Find the matching Chrome OS version and click on the column for 'Canary'
170 or 'Dev'.
Steven Bennetts7f08b002018-06-29 23:28:441711. Click on the dropdown icon in the 'Images' column and click on 'Unsigned
172 test image'.
173
174**Non-Googlers**: The build infrastructure is currently in flux. See
Achuith Bhandarkar61f58962018-08-29 00:05:31175[crbug.com/360342] for more details. You may need to build your own Chrome OS
176image.
James Cookb181cf72017-08-04 19:41:53177
Satoru Takabayashieef6f592017-06-23 04:16:36178After you download the compressed tarball containing the test image (it should
179have "test" somewhere in the file name), extract the image by running:
180
181```
Achuith Bhandarkar61f58962018-08-29 00:05:31182(sdk) tar xvf ~/Downloads/<image-you-downloaded>
Satoru Takabayashieef6f592017-06-23 04:16:36183```
184
Steven Bennetts7f08b002018-06-29 23:28:44185Copy the image to your USB stick using `cros flash`:
Satoru Takabayashieef6f592017-06-23 04:16:36186
187```
Achuith Bhandarkar61f58962018-08-29 00:05:31188(sdk) cros flash usb:// chromiumos_test_image.bin
Satoru Takabayashieef6f592017-06-23 04:16:36189```
190
Achuith Bhandarkar61f58962018-08-29 00:05:31191> **Tip:** If you have a Chrome OS checkout, the following can be used to
Steven Bennetts7f08b002018-06-29 23:28:44192update a device that already has a test image installed. Star
Achuith Bhandarkar61f58962018-08-29 00:05:31193[crbug.com/403086] for updates on a proposal to support this without a
194Chrome OS checkout.
Steven Bennetts7f08b002018-06-29 23:28:44195
196```
197.../chromeos/src $ cros flash $IP_ADDR chromiumos_test_image.bin
198```
199
Satoru Takabayashieef6f592017-06-23 04:16:36200### Put your Chrome OS device in dev mode
201
Steven Bennetts0d195912018-09-18 23:37:39202You can skip this section if you're using a [VM].
Achuith Bhandarkar61f58962018-08-29 00:05:31203
Steven Bennetts7f08b002018-06-29 23:28:44204> **Note:** Switching to dev mode wipes all data from the device (for security
205> reasons).
James Cook961c57d2018-01-23 21:34:05206
James Cook93506b02018-01-17 06:13:07207Most recent devices can use the [generic instructions]. To summarize:
Satoru Takabayashieef6f592017-06-23 04:16:36208
Steven Bennetts7f08b002018-06-29 23:28:442091. With the device on, hit Esc + Refresh (F2 or F3) + power button
2101. Wait for the white "recovery screen"
2111. Hit Ctrl-D to switch to developer mode (there's no prompt)
2121. Press enter to confirm
2131. Once it is done, hit Ctrl-D again to boot, then wait
Satoru Takabayashieef6f592017-06-23 04:16:36214
James Cook961c57d2018-01-23 21:34:05215From this point on you'll always see the white screen when you turn on
James Cook3a2a0632018-01-18 06:21:56216the device. Press Ctrl-D to boot.
James Cook93506b02018-01-17 06:13:07217
218Older devices may have [device-specific instructions].
219
Steven Bennetts7f08b002018-06-29 23:28:44220*Googlers*: If the device asks you to "enterprise enroll", click the X in the
221top-right of the dialog to skip it. Trying to use your google.com credentials
222will result in an error.
James Cook3a2a0632018-01-18 06:21:56223
James Cook93506b02018-01-17 06:13:07224### Enable booting from USB
225
James Cook3a2a0632018-01-18 06:21:56226By default Chromebooks will not boot off a USB stick for security reasons.
James Cook961c57d2018-01-23 21:34:05227You need to enable it.
James Cook3a2a0632018-01-18 06:21:56228
Steven Bennetts7f08b002018-06-29 23:28:442291. Start the device
2301. Press Ctrl-Alt-F2 to get a terminal. (You can use Ctrl-Alt-F1 to switch
231 back if you need to.)
2321. Login as `root` (no password yet, there will be one later)
2331. Run `enable_dev_usb_boot`
James Cook3d135382017-10-16 16:58:01234
Satoru Takabayashieef6f592017-06-23 04:16:36235### Install the test image onto your device
236
Steven Bennetts7f08b002018-06-29 23:28:44237> **Note:** Do not log into this test image with a username and password you
238> care about. The root password is public ("test0000"), so anyone with SSH
239> access could compromise the device. Create a test Gmail account and use that.
Satoru Takabayashieef6f592017-06-23 04:16:36240
Steven Bennetts7f08b002018-06-29 23:28:442411. Plug the USB stick into the machine and reboot.
2421. At the dev-mode warning screen, press Ctrl-U to boot from the USB stick.
2431. Switch to terminal by pressing Ctrl-Alt-F2
2441. Login as user `chronos`, password `test0000`.
2451. Run `/usr/sbin/chromeos-install`
2461. Wait for it to copy the image
2471. Run `poweroff`
James Cook3a2a0632018-01-18 06:21:56248
249You can now unplug the USB stick.
250
Steven Bennetts7f08b002018-06-29 23:28:44251### Connect device to Ethernet
252
253Use your USB-to-Ethernet adapter to connect the device to a network.
254
James Cook614fafc2019-01-22 23:21:02255*Googlers*: If your building has Ethernet jacks connected to the test VLAN
256(e.g. white ports), use one of those jacks. Otherwise get a second Ethernet
257adapter and see [go/shortleash] to reverse tether your Chromebook to your
258workstation.
Steven Bennetts7f08b002018-06-29 23:28:44259
Satoru Takabayashieef6f592017-06-23 04:16:36260### Checking the IP address
261
Steven Bennetts7f08b002018-06-29 23:28:442621. Click the status area in the lower-right corner
2631. Click the network icon
2641. Click the circled `i` symbol in the lower-right corner
2651. A small window pops up that shows the IP address
Satoru Takabayashieef6f592017-06-23 04:16:36266
Steven Bennetts7f08b002018-06-29 23:28:44267You can also run `ifconfig` from the terminal (Ctrl-Alt-F2).
James Cook3a2a0632018-01-18 06:21:56268
Achuith Bhandarkar61f58962018-08-29 00:05:31269---
270
271## Deploying Chrome to the device
272
273To deploy the build to a device/VM, you will need direct SSH access to it from
274your computer. The scripts below handle everything else.
275
Satoru Takabayashieef6f592017-06-23 04:16:36276### Using deploy_chrome
277
Achuith Bhandarkar61f58962018-08-29 00:05:31278The `deploy_chrome` script uses rsync to incrementally deploy Chrome to the
279device/VM.
Satoru Takabayashieef6f592017-06-23 04:16:36280
Achuith Bhandarkar61f58962018-08-29 00:05:31281Specify the build output directory to deploy from using `--build-dir`. For the
Steven Bennetts0d195912018-09-18 23:37:39282[VM]:
Satoru Takabayashieef6f592017-06-23 04:16:36283
284```
Steven Bennetts8a0efd92018-11-27 17:32:52285(sdk) deploy_chrome --build-dir=out_${SDK_BOARD}/Release --to=localhost --port=9222
Achuith Bhandarkar61f58962018-08-29 00:05:31286```
287
288For a physical device, which must be ssh-able as user 'root', you must specify
289the IP address using `--to`:
290
291```
292(sdk) deploy_chrome --build-dir=out_${SDK_BOARD}/Release --to=$IP_ADDR
Satoru Takabayashieef6f592017-06-23 04:16:36293```
294
Steven Bennetts7f08b002018-06-29 23:28:44295> **Note:** The first time you run this you will be prompted to remove rootfs
296> verification from the device. This is required to overwrite /opt/google/chrome
297> and will reboot the device. You can skip the prompt with `--force`.
Satoru Takabayashieef6f592017-06-23 04:16:36298
Steven Bennetts7f08b002018-06-29 23:28:44299### Deploying Chrome to the user partition
Satoru Takabayashieef6f592017-06-23 04:16:36300
Steven Bennetts7f08b002018-06-29 23:28:44301It is also possible to deploy Chrome to the user partition of the device and
Achuith Bhandarkard2570122018-08-03 00:56:43302set up a temporary mount from `/opt/google/chrome` using the option `--mount`.
303This is useful when deploying a binary that will not otherwise fit on the
304device, e.g.:
Satoru Takabayashieef6f592017-06-23 04:16:36305
Steven Bennetts7f08b002018-06-29 23:28:44306* When using `--nostrip` to provide symbols for backtraces.
307* When using other compile options that produce a significantly larger image.
James Cookba126f12017-08-21 19:59:07308
Steven Bennetts7f08b002018-06-29 23:28:44309```
Steven Bennetts8a0efd92018-11-27 17:32:52310(sdk) deploy_chrome --build-dir=out_$SDK_BOARD/Release --to=$IP_ADDR --mount [--nostrip]
Steven Bennetts7f08b002018-06-29 23:28:44311```
312
Achuith Bhandarkard2570122018-08-03 00:56:43313> **Note:** This also prompts to remove rootfs verification so that
Steven Bennetts7f08b002018-06-29 23:28:44314> /etc/chrome_dev.conf can be modified (see [Command-line flags and
315> environment variables]). You can skip that by adding
316> `--noremove-rootfs-verification`.
317
318#### Additional Notes:
319
Achuith Bhandarkard2570122018-08-03 00:56:43320* The mount is transient and does not survive a reboot. The easiest way to
321 reinstate the mount is to run the same deploy_chrome command after reboot.
322 It will only redeploy binaries if there is a change. To verify that the
323 mount is active, run `findmnt /opt/google/chrome`. The output should be:
324```
325TARGET SOURCE FSTYPE OPTIONS
326/opt/google/chrome /dev/sda1[/deploy_rootfs/opt/google/chrome] ext4 rw,nodev,noatime,resgid=20119,commit=600,data=ordered
327```
Steven Bennetts7f08b002018-06-29 23:28:44328* If startup needs to be tested (i.e. before deploy_chrome can be run), a
329 symbolic link will need to be created instead:
330 * ssh to device
Roman Sorokin1c9c7682019-09-17 02:26:26331 * `mkdir /usr/local/chrome`
Steven Bennetts7f08b002018-06-29 23:28:44332 * `rm -R /opt/google/chrome`
Roman Sorokin1c9c7682019-09-17 02:26:26333 * `ln -s /usr/local/chrome /opt/google/chrome`
Steven Bennetts7f08b002018-06-29 23:28:44334 * `deploy_chrome --build-dir=out_${SDK_BOARD}/Release --to=$IP_ADDR
335 --nostrip`
336 * The device can then be rebooted and the unstripped version of Chrome
337 will be run.
338* `deploy_chrome` lives under `$CHROME_DIR/src/third_party/chromite/bin`.
339 You can run `deploy_chrome` outside of a `chrome-sdk` shell.
340
341## Updating the Chrome OS image
342
343In order to keep Chrome and Chrome OS in sync, the Chrome OS test image
344should be updated weekly. See [Create a bootable USB stick] for a tip on
Achuith Bhandarkar61f58962018-08-29 00:05:31345updating an existing test device if you have a Chrome OS checkout.
Steven Bennetts7f08b002018-06-29 23:28:44346
347---
James Cookba126f12017-08-21 19:59:07348
Satoru Takabayashieef6f592017-06-23 04:16:36349## Debugging
350
Satoru Takabayashi7cc76c92017-06-26 04:46:05351### Log files
Satoru Takabayashieef6f592017-06-23 04:16:36352
Achuith Bhandarkar8bca7812019-02-06 20:51:10353[Chrome-related logs] are written to several locations on the device running a
354test image:
Satoru Takabayashieef6f592017-06-23 04:16:36355
Steven Bennetts7f08b002018-06-29 23:28:44356* `/var/log/ui/ui.LATEST` contains messages written to stderr by Chrome
357 before its log file has been initialized.
Achuith Bhandarkar8bca7812019-02-06 20:51:10358* `/var/log/chrome/chrome` contains messages logged by Chrome both before and
359 after login since Chrome runs with `--disable-logging-redirect` on test
360 images.
Steven Bennetts7f08b002018-06-29 23:28:44361* `/var/log/messages` contains messages logged by `session_manager`
362 (which is responsible for starting Chrome), in addition to kernel
363 messages when a Chrome process crashes.
Satoru Takabayashi7cc76c92017-06-26 04:46:05364
365### Command-line flags and environment variables
Satoru Takabayashieef6f592017-06-23 04:16:36366
367If you want to tweak the command line of Chrome or its environment, you have to
368do this on the device itself.
369
Satoru Takabayashieef6f592017-06-23 04:16:36370Edit the `/etc/chrome_dev.conf` (device) file. Instructions on using it are in
371the file itself.
372
James Cook961c57d2018-01-23 21:34:05373### Custom build directories
374
375This step is only necessary if you run `cros chrome-sdk` with `--nogn-gen`.
376
377To create a GN build directory, run the following inside the chrome-sdk shell:
378
379```
Achuith Bhandarkar61f58962018-08-29 00:05:31380(sdk) gn gen out_$SDK_BOARD/Release --args="$GN_ARGS"
James Cook961c57d2018-01-23 21:34:05381```
382
383This will generate `out_$SDK_BOARD/Release/args.gn`.
384
Steven Bennetts7f08b002018-06-29 23:28:44385* You must specify `--args`, otherwise your build will not work on the device.
386* You only need to run `gn gen` once within the same `cros chrome-sdk`
387 session.
388* However, if you exit the session or sync/update Chrome the `$GN_ARGS` might
389 change and you need to `gn gen` again.
James Cook961c57d2018-01-23 21:34:05390
391You can edit the args with:
392
393```
Achuith Bhandarkar61f58962018-08-29 00:05:31394(sdk) gn args out_$SDK_BOARD/Release
James Cook961c57d2018-01-23 21:34:05395```
396
397You can replace `Release` with `Debug` (or something else) for different
Steven Bennetts7f08b002018-06-29 23:28:44398configurations. See [Debug builds].
James Cook961c57d2018-01-23 21:34:05399
400[GN build configuration] discusses various GN build configurations. For more
401info on GN, run `gn help` on the command line or read the [quick start guide].
402
Steven Bennetts7f08b002018-06-29 23:28:44403### Debug builds
Satoru Takabayashieef6f592017-06-23 04:16:36404
405For cros chrome-sdk GN configurations, Release is the default. A debug build of
406Chrome will include useful tools like DCHECK and debug logs like DVLOG. For a
407Debug configuration, specify
Achuith Bhandarkar61f58962018-08-29 00:05:31408`--args="$GN_ARGS is_debug=true is_component_build=false"`.
Satoru Takabayashieef6f592017-06-23 04:16:36409
410Alternately, you can just turn on DCHECKs for a release build. You can do this
411with `--args="$GN_ARGS dcheck_always_on=true"`.
412
Steven Bennetts7f08b002018-06-29 23:28:44413To deploy a debug build you need to add `--nostrip` to `deploy_chrome` because
414otherwise it will strip symbols even from a debug build. This requires
415[Deploying Chrome to the user partition].
Satoru Takabayashieef6f592017-06-23 04:16:36416
Steven Bennetts7f08b002018-06-29 23:28:44417> **Note:** If you just want crash backtraces in the logs you can deploy a
418> release build with `--nostrip`. You don't need a debug build (but you still
419> need to deploy to a user partition).
420>
421> **Note:** You may hit `DCHECKs` during startup time, or when you login, which
422> eventually may reboot the device. You can check log files in `/var/log/chrome`
423> or `/home/chronos/user/log`.
424>
425> You can create `/run/disable_chrome_restart` to prevent a restart loop and
426> investigate.
427>
428> You can temporarily disable these `DCHECKs` to proceed, but please file a
429> bug for such `DCHECK` because it's most likely a bug.
Satoru Takabayashieef6f592017-06-23 04:16:36430
431### Remote GDB
432
Satoru Takabayashi7cc76c92017-06-26 04:46:05433Core dumps are disabled by default. See [additional debugging tips] for how to
Satoru Takabayashieef6f592017-06-23 04:16:36434enable core files.
435
436On the target machine, open up a port for the gdb server to listen on, and
Satoru Takabayashi7cc76c92017-06-26 04:46:05437attach the gdb server to the top-level Chrome process.
Satoru Takabayashieef6f592017-06-23 04:16:36438
439```
440(device) sudo /sbin/iptables -A INPUT -p tcp --dport 1234 -j ACCEPT
Steven Bennetts8a0efd92018-11-27 17:32:52441(device) sudo gdbserver --attach :1234 $(pgrep chrome -P $(pgrep session_manager))
Satoru Takabayashieef6f592017-06-23 04:16:36442```
443
444On your host machine (inside the chrome-sdk shell), run gdb and start the Python
445interpreter:
446
447```
Achuith Bhandarkar61f58962018-08-29 00:05:31448(sdk) cd %CHROME_DIR%/src
449(sdk) gdb out_${SDK_BOARD}/Release/chrome
450Reading symbols from /usr/local/google2/chromium2/src/out_amd64-generic/Release/chrome...
Satoru Takabayashieef6f592017-06-23 04:16:36451(gdb) pi
452>>>
453```
454
Steven Bennetts7f08b002018-06-29 23:28:44455> **Note:** These instructions are for targeting an x86_64 device. For now, to
456> target an ARM device, you need to run the cross-compiled gdb from within a
457> chroot.
Satoru Takabayashieef6f592017-06-23 04:16:36458
459Then from within the Python interpreter, run these commands:
460
Steven Bennetts7f08b002018-06-29 23:28:44461```python
Satoru Takabayashieef6f592017-06-23 04:16:36462import os
463sysroot = os.environ['SYSROOT']
Achuith Bhandarkar61f58962018-08-29 00:05:31464board = os.environ['SDK_BOARD']
Satoru Takabayashieef6f592017-06-23 04:16:36465gdb.execute('set sysroot %s' % sysroot)
466gdb.execute('set solib-absolute-prefix %s' % sysroot)
467gdb.execute('set debug-file-directory %s/usr/lib/debug' % sysroot)
Achuith Bhandarkar61f58962018-08-29 00:05:31468# "Debug" for a debug build
469gdb.execute('set solib-search-path out_%s/Release/lib' % board)
Steven Bennetts7f08b002018-06-29 23:28:44470gdb.execute('target remote $IP_ADDR:1234')
Satoru Takabayashieef6f592017-06-23 04:16:36471```
472
473If you wish, after you connect, you can Ctrl-D out of the Python shell.
474
Achuith Bhandarkar61f58962018-08-29 00:05:31475Extra debugging instructions are located at [debugging tips].
Steven Bennetts7f08b002018-06-29 23:28:44476
477---
Satoru Takabayashieef6f592017-06-23 04:16:36478
479## Additional instructions
480
481### Updating the version of the Chrome OS SDK
482
483When you invoke `cros chrome-sdk`, the script fetches the version of the SDK
Steven Bennetts7f08b002018-06-29 23:28:44484that corresponds to your Chrome checkout. To update the SDK, sync your Chrome
Satoru Takabayashieef6f592017-06-23 04:16:36485checkout and re-run `cros chrome-sdk`.
486
487**IMPORTANT NOTES:**
488
Achuith Bhandarkar61f58962018-08-29 00:05:31489* Every time that you update Chrome or the Chrome OS SDK, it is possible
490 that Chrome may start depending on new features from a new Chrome OS
491 image. This can cause unexpected problems, so it is important to update
492 your image regularly. Instructions for updating your Chrome OS image are
493 above in [Set up the Chrome OS device]. This is not a concern for a
494 downloaded VM.
Steven Bennetts7f08b002018-06-29 23:28:44495* Don't forget to re-configure your custom build directories if you have them
496 (see [Custom build directories]).
Satoru Takabayashieef6f592017-06-23 04:16:36497
498### Specifying the version of the Chrome OS SDK to use
499
500You can specify a version of Chrome OS to build against. This is handy for
501tracking down when a particular bug was introduced.
502
503```
Achuith Bhandarkar61f58962018-08-29 00:05:31504(shell) cros chrome-sdk --board=$BOARD --version=11005.0.0
Satoru Takabayashieef6f592017-06-23 04:16:36505```
506
Achuith Bhandarkar61f58962018-08-29 00:05:31507Once you are finished testing the old version of the chrome-sdk, you can
508always start a new shell with the latest version again. Here's an example:
Satoru Takabayashieef6f592017-06-23 04:16:36509
510```
Achuith Bhandarkar61f58962018-08-29 00:05:31511(shell) cros chrome-sdk --board=$BOARD --clear-sdk-cache
Satoru Takabayashieef6f592017-06-23 04:16:36512```
513
514### Updating Chrome
515
Steven Bennetts7f08b002018-06-29 23:28:44516```
Achuith Bhandarkar61f58962018-08-29 00:05:31517(sdk) exit
518(shell) git checkout master && git pull # (or if you prefer, git rebase-update)
519(shell) gclient sync
520(shell) cros chrome-sdk --board=$BOARD --log-level=info
Steven Bennetts7f08b002018-06-29 23:28:44521```
Satoru Takabayashieef6f592017-06-23 04:16:36522
Steven Bennetts7f08b002018-06-29 23:28:44523> **Tip:** If you update Chrome inside the chrome-sdk, you may then be using an
524> SDK that is out of date with the current Chrome.
525> See [Updating the version of the Chrome OS SDK] section above.
526
Satoru Takabayashieef6f592017-06-23 04:16:36527
528### Updating Deployed Files
529
Steven Bennetts7f08b002018-06-29 23:28:44530`deploy_chrome` determines which files to copy in `chrome_util.py` in the
531[chromite repo] which is pulled into `chrome/src/third_party/chromite` via DEPS.
Satoru Takabayashieef6f592017-06-23 04:16:36532
Steven Bennetts7f08b002018-06-29 23:28:44533When updating the list:
Satoru Takabayashieef6f592017-06-23 04:16:36534
Steven Bennetts7f08b002018-06-29 23:28:445351. Make changes to the appropriate list (e.g. `_COPY_PATHS_CHROME`).
5361. Be aware that deploy_chrome is used by the chromeos-chrome ebuild, so when
537 adding new files make sure to set optional=True initially.
5381. Changes to chromite will not affect Simple Chrome until a chromite roll
539 occurs.
Satoru Takabayashieef6f592017-06-23 04:16:36540
Achuith Bhandarkar61f58962018-08-29 00:05:31541### Using a custom Chrome OS build
James Cookba126f12017-08-21 19:59:07542
Achuith Bhandarkar61f58962018-08-29 00:05:31543If you are making changes to Chrome OS and have a Chrome OS build inside a
James Cookba126f12017-08-21 19:59:07544chroot that you want to build against, run `cros chrome-sdk` with the `--chroot`
Steven Bennetts7f08b002018-06-29 23:28:44545option:
James Cookba126f12017-08-21 19:59:07546
547```
Achuith Bhandarkar61f58962018-08-29 00:05:31548(shell) cros chrome-sdk --board=$BOARD --chroot=/path/to/chromiumos/chroot
James Cookba126f12017-08-21 19:59:07549```
550
Satoru Takabayashieef6f592017-06-23 04:16:36551### Using cros flash with xbuddy to download images
552
553`cros flash` with `xbuddy` will automatically download an image and write it to
554USB for you. It's very convenient, but for now it requires a full Chrome OS
555checkout and must be run inside the Chrome OS chroot. ([issue 437877])
556
557```
Satoru Takabayashie0af9cb2017-06-23 05:26:08558(chroot) cros flash usb:// xbuddy://remote/$BOARD/<version>/test
Satoru Takabayashieef6f592017-06-23 04:16:36559```
560
561Replace `$BOARD` and `<version>` with the right values. Both can be seen in your
562SDK prompt (e.g. `(sdk lumpy R27-3789.0.0)` is the lumpy board using version
563R27-3789.0.0).
564
565See the [Cros Flash page] for more details.
566
Harry Cutts2cfd02d2019-03-23 00:33:11567### Running tests
568
Xiyuan Xia6c8ef612019-04-26 22:30:22569Chrome's unit and browser tests are compiled into test binaries. At the moment,
570not all of them run on a Chrome OS device. Most of the unit tests and part of
571interactive_ui_tests that measure Chrome OS performance should work.
572
573To build and run a chrome test on device (or VM),
574```bash
575(sdk) .../chrome/src $ cros_run_test --build --device=$IP --chrome-test -- \
David Pursehouseb3b7da12019-06-17 12:23:39576out_$SDK_BOARD/Release/interactive_ui_tests \
Xiyuan Xia6c8ef612019-04-26 22:30:22577 --dbus-stub \
578 --enable-pixel-output-in-tests \
579 --gtest_filter=SplitViewTest.SplitViewResize
580```
581
582Alternatively, manually build and use the generated `run_$TEST` scripts to run
583like build bots:
584```bash
585(sdk) .../chrome/src $ autoninja -C out_$SDK_BOARD/Release interactive_ui_tests
586(sdk) .../chrome/src $ out_$SDK_BOARD/Release/bin/run_interactive_ui_tests \
587 --device=$IP \
588 --dbus-stub \
589 --enable-pixel-output-in-tests \
590 --gtest_filter=SplitViewTest.SplitViewResize
591```
592
593To run tests locally on dev box, follow the [instructions for running tests on
594Linux] using a separate GN build directory with `target_os = "chromeos"` in its
595arguments. (You can create one using the `gn args` command.)
Harry Cutts2cfd02d2019-03-23 00:33:11596
597If you're running tests which create windows on-screen, you might find the
598instructions for using an embedded X server in [web_tests_linux.md] useful.
599
Steven Bennetts7f08b002018-06-29 23:28:44600### Setting a custom prompt
Satoru Takabayashieef6f592017-06-23 04:16:36601
602By default, cros chrome-sdk prepends something like '`(sdk link R52-8315.0.0)`'
Satoru Takabayashi7cc76c92017-06-26 04:46:05603to the prompt (with the version of the prebuilt system being used).
Satoru Takabayashieef6f592017-06-23 04:16:36604
605If you prefer to colorize the prompt, you can set `PS1` in
Achuith Bhandarkar61f58962018-08-29 00:05:31606`~/.chromite/chrome_sdk.bashrc`, e.g. to prepend a yellow
607'`(sdk link 8315.0.0)`' to the prompt:
Satoru Takabayashieef6f592017-06-23 04:16:36608
609```
610PS1='\[\033[01;33m\](sdk ${SDK_BOARD} ${SDK_VERSION})\[\033[00m\] \w \[\033[01;36m\]$(__git_ps1 "(%s)")\[\033[00m\] \$ '
611```
Steven Bennetts7f08b002018-06-29 23:28:44612NOTE: Currently the release version (e.g. 52) is not available as an
613environment variable.
Satoru Takabayashieef6f592017-06-23 04:16:36614
James Cookba126f12017-08-21 19:59:07615### GYP
616
James Cook961c57d2018-01-23 21:34:05617The legacy `GYP` build system is no longer supported.
James Cookba126f12017-08-21 19:59:07618
Achuith Bhandarkar61f58962018-08-29 00:05:31619[Custom build directories]: #custom-build-directories
620[Updating the version of the Chrome OS SDK]: #updating-the-version-of-the-chrome-os-sdk
621[Using a custom Chrome OS build]: #using-a-custom-chrome-os-build
622[Command-line flags and environment variables]: #command-line-flags-and-environment-variables
623[Deploying Chrome to the user partition]: #deploying-chrome-to-the-user-partition
624[Debug builds]: #debug-builds
625[Create a bootable USB stick]: #create-a-bootable-usb-stick
626[Set up the Chrome OS device]: #set-up-the-chrome-os-device
627[OS development guide]: https://chromium.googlesource.com/chromiumos/docs/+/master/developer_guide.md
628[Chrome source code and depot_tools]: https://chromium.googlesource.com/chromium/src/+/master/docs/linux_build_instructions.md
Harry Cutts2cfd02d2019-03-23 00:33:11629[instructions for running tests on Linux]: https://chromium.googlesource.com/chromium/src/+/master/docs/linux_build_instructions.md#Running-test-targets
Steven Bennetts7f08b002018-06-29 23:28:44630[update .gclient]: https://chromium.googlesource.com/chromium/src/+/HEAD/docs/chromeos_build_instructions.md#updating-your-gclient-config
Achuith Bhandarkar61f58962018-08-29 00:05:31631[Chrome OS board name]: https://www.chromium.org/chromium-os/developer-information-for-chrome-os-devices
Steven Bennetts7f08b002018-06-29 23:28:44632[GN build configuration]: https://www.chromium.org/developers/gn-build-configuration
Achuith Bhandarkar61f58962018-08-29 00:05:31633[quick start guide]: https://gn.googlesource.com/gn/+/master/docs/quick_start.md
James Cook3d135382017-10-16 16:58:01634[device-specific instructions]: https://www.chromium.org/chromium-os/developer-information-for-chrome-os-devices
635[generic instructions]: https://www.chromium.org/a/chromium.org/dev/chromium-os/developer-information-for-chrome-os-devices/generic
Satoru Takabayashieef6f592017-06-23 04:16:36636[rootfs has been removed]: https://www.chromium.org/chromium-os/poking-around-your-chrome-os-device#TOC-Making-changes-to-the-filesystem
Steven Bennetts7f08b002018-06-29 23:28:44637[remounted as read-write]: https://www.chromium.org/chromium-os/how-tos-and-troubleshooting/debugging-tips#TOC-Setting-up-the-device
638[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:36639[chromite repo]: https://chromium.googlesource.com/chromiumos/chromite/
640[issue 437877]: https://bugs.chromium.org/p/chromium/issues/detail?id=403086
Will Bradleyca8befd2019-02-22 21:31:51641[Cros Flash page]: https://chromium.googlesource.com/chromiumos/docs/+/master/cros_flash.md
Steven Bennetts0d195912018-09-18 23:37:39642[VM]: https://chromium.googlesource.com/chromiumos/docs/+/master/cros_vm.md
Achuith Bhandarkar61f58962018-08-29 00:05:31643[Running a Chrome Google Test binary in the VM]: https://chromium.googlesource.com/chromiumos/docs/+/master/cros_vm.md#Run-a-Chrome-GTest-binary-in-the-VM
644[go/goldeneye]: https://cros-goldeneye.corp.google.com/chromeos/console/listBuild
James Cook614fafc2019-01-22 23:21:02645[go/shortleash]: https://goto.google.com/shortleash
Achuith Bhandarkar61f58962018-08-29 00:05:31646[debugging tips]: https://www.chromium.org/chromium-os/how-tos-and-troubleshooting/debugging-tips
647[go/chrome-build-instructions]: https://companydoc.corp.google.com/company/teams/chrome/chrome_build_instructions.md
648[api-keys]: https://www.chromium.org/developers/how-tos/api-keys
Ben Pastene957ea272019-03-18 16:06:01649[install-build-deps-android.sh]: https://chromium.googlesource.com/chromium/src/+/master/build/install-build-deps-android.sh
Achuith Bhandarkar61f58962018-08-29 00:05:31650[Goma]: https://sites.google.com/a/google.com/goma/
Achuith Bhandarkar8bca7812019-02-06 20:51:10651[Chrome-related logs]: https://chromium.googlesource.com/chromium/src/+/lkgr/docs/chrome_os_logging.md
Achuith Bhandarkar61f58962018-08-29 00:05:31652[crbug.com/360342]: https://bugs.chromium.org/p/chromium/issues/detail?id=360342
653[crbug.com/403086]: https://bugs.chromium.org/p/chromium/issues/detail?id=403086
Harry Cutts2cfd02d2019-03-23 00:33:11654[web_tests_linux.md]: https://chromium.googlesource.com/chromium/src/+show/master/docs/web_tests_linux.md