blob: dbb52f30bc8ba3ffa0290573b502d050a56fc9f0 [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
Achuith Bhandarkar61f58962018-08-29 00:05:3148### VM versus Device
49
Steven Bennetts0d195912018-09-18 23:37:3950The easiest way to develop on Chrome OS is to use a [VM].
51
52If you need to test hardware-specific features such as graphics acceleration,
53bluetooth, mouse or input events, etc, you may also use a physical device
54(Googlers: Chromestop has the hardware). See [Set up the Chrome OS device] for
55details.
Achuith Bhandarkar61f58962018-08-29 00:05:3156
Steven Bennetts7f08b002018-06-29 23:28:4457---
James Cook3a2a0632018-01-18 06:21:5658
Steven Bennetts7f08b002018-06-29 23:28:4459## Enter the Simple Chrome environment
Satoru Takabayashieef6f592017-06-23 04:16:3660
Steven Bennetts7f08b002018-06-29 23:28:4461Building Chrome for Chrome OS requires a toolchain customized for each
Steven Bennetts0d195912018-09-18 23:37:3962Chromebook model (or "board"). For the Chrome OS [VM], and non-Googlers, use
Achuith Bhandarkar61f58962018-08-29 00:05:3163`amd64-generic`. For a physical device, look up the [Chrome OS board name] by
Steven Bennetts7f08b002018-06-29 23:28:4464navigating to the URL `about:version` on the device. For example:
65`Platform 10176.47.0 (Official Build) beta-channel samus` has board `samus`.
66
Achuith Bhandarkar61f58962018-08-29 00:05:3167To enter the Simple Chrome environment, run these from within your Chrome
68checkout:
Steven Bennetts5a79a1c2017-11-27 20:05:4769
Satoru Takabayashieef6f592017-06-23 04:16:3670```
Achuith Bhandarkar61f58962018-08-29 00:05:3171(shell) cd /path/to/chrome/src
72(shell) export BOARD=amd64-generic
73(shell) cros chrome-sdk --board=$BOARD --log-level=info [--download-vm]
Satoru Takabayashieef6f592017-06-23 04:16:3674```
Satoru Takabayashieef6f592017-06-23 04:16:3675
Steven Bennetts7f08b002018-06-29 23:28:4476The command prompt will change to look like `(sdk $BOARD $VERSION)`.
Satoru Takabayashieef6f592017-06-23 04:16:3677
Steven Bennetts7f08b002018-06-29 23:28:4478Entering the Simple Chrome environment does the following:
Satoru Takabayashieef6f592017-06-23 04:16:3679
Steven Bennetts7f08b002018-06-29 23:28:44801. Fetches the Chrome OS toolchain and sysroot (SDK) for building Chrome.
811. Creates out_$BOARD/Release and generates or updates args.gn.
Achuith Bhandarkar61f58962018-08-29 00:05:31821. Installs and starts [Goma].
83 (*Non-Googlers* may need to disable this with `--nogoma`).
841. `--download-vm` will download a Chrome OS VM and a QEMU binary.
85
Steven Bennetts8a0efd92018-11-27 17:32:5286### cros chrome-sdk options
Steven Bennetts7f08b002018-06-29 23:28:4487
Steven Bennetts7f08b002018-06-29 23:28:4488* `--internal` Sets up Simple Chrome to build and deploy the official *Chrome*
89 instead of *Chromium*.
Steven Bennetts8a0efd92018-11-27 17:32:5290* `--gn-extra-args='extra_arg=foo other_extra_arg=bar'` For setting
91 extra gn args, e.g. 'dcheck_always_on=true'.
Steven Bennetts7f08b002018-06-29 23:28:4492* `--log-level=info` Sets the log level to 'info' or 'debug' (default is
93 'warn').
Steven Bennetts8a0efd92018-11-27 17:32:5294* `--nogn-gen` Do not run 'gn gen' automatically.
95
96**Chrome OS developers**: Please set `dcheck_always_on=true` and file bugs if
97you encounter any DCHECK crashes.
98```
99(shell) cros chrome-sdk --internal --board=$BOARD --log-level=info --gn-extra-args='dcheck_always_on=true'
100```
101
102### cros chrome-sdk tips
Satoru Takabayashieef6f592017-06-23 04:16:36103
Achuith Bhandarkar61f58962018-08-29 00:05:31104> **Important:** When you sync/update your Chrome source, the Chrome OS SDK
Steven Bennetts7f08b002018-06-29 23:28:44105> version (src/chromeos/CHROMEOS_LKGM) may change. When the SDK version changes
106> you may need to exit and re-enter the Simple Chrome environment to
Achuith Bhandarkar61f58962018-08-29 00:05:31107> successfully build and deploy Chrome.
Satoru Takabayashieef6f592017-06-23 04:16:36108
Steven Bennetts8a0efd92018-11-27 17:32:52109> **Non-Googlers**: Only generic boards have publicly available SDK downloads,
110> so you will need to use a generic board (e.g. amd64-generic) or your own
111> Chrome OS build (see [Using a custom Chrome OS build]). For more info and
112> updates star [crbug.com/360342].
113
Achuith Bhandarkar61f58962018-08-29 00:05:31114> **Note**: See also [Using a custom Chrome OS build].
Satoru Takabayashieef6f592017-06-23 04:16:36115
Steven Bennetts7f08b002018-06-29 23:28:44116---
Steven Bennetts5a79a1c2017-11-27 20:05:47117
118## Build Chrome
119
Satoru Takabayashieef6f592017-06-23 04:16:36120To build Chrome, run:
121
122```
Achuith Bhandarkar61f58962018-08-29 00:05:31123(sdk) autoninja -C out_${SDK_BOARD}/Release chrome chrome_sandbox nacl_helper
Satoru Takabayashieef6f592017-06-23 04:16:36124```
125
Achuith Bhandarkar61f58962018-08-29 00:05:31126> **Note**: Targets other than **chrome, chrome_sandbox, nacl_helper** or
Steven Bennetts7f08b002018-06-29 23:28:44127> (optionally) **chromiumos_preflight** are not supported in Simple Chrome and
Achuith Bhandarkar61f58962018-08-29 00:05:31128> will likely fail. browser_tests should be run outside the Simple Chrome
129> environment. Some unit_tests may be built in the Simple Chrome environment and
130> run in the Chrome OS VM. For details, see
131> [Running a Chrome Google Test binary in the VM].
Satoru Takabayashieef6f592017-06-23 04:16:36132
Achuith Bhandarkar61f58962018-08-29 00:05:31133> **Note**: Simple Chrome uses [Goma]. To watch the build progress, find the
134> Goma port (`$ echo $SDK_GOMA_PORT`) and open http://localhost:<port_number>
135> in a browser.
Satoru Takabayashieef6f592017-06-23 04:16:36136
Steven Bennetts7f08b002018-06-29 23:28:44137> **Note:** The default extensions will be installed by the test image you use
138> below.
Satoru Takabayashieef6f592017-06-23 04:16:36139
Steven Bennetts7f08b002018-06-29 23:28:44140---
Satoru Takabayashieef6f592017-06-23 04:16:36141
Achuith Bhandarkar61f58962018-08-29 00:05:31142## Set up the Chrome OS device
Satoru Takabayashieef6f592017-06-23 04:16:36143
Achuith Bhandarkar61f58962018-08-29 00:05:31144### Getting started
145
146You need the following:
1471. USB flash drive 4 GB or larger (for example, a Sandisk Extreme USB 3.0)
1481. USB to Gigabit Ethernet adapter
149
150Before you can deploy your build of Chrome to the device, it needs to have a
Steven Bennetts7f08b002018-06-29 23:28:44151"test" OS image loaded on it. A test image has tools like rsync that are not
152part of the end-user image.
153
Achuith Bhandarkar61f58962018-08-29 00:05:31154Chrome should be deployed to a recent Chrome OS test image, ideally the
155version shown in your SDK prompt (or `(sdk) echo $SDK_VERSION`).
Satoru Takabayashieef6f592017-06-23 04:16:36156
157### Create a bootable USB stick
158
Achuith Bhandarkar61f58962018-08-29 00:05:31159**Googlers**: Images for all boards are available on [go/goldeneye]:
Satoru Takabayashieef6f592017-06-23 04:16:36160
Achuith Bhandarkar61f58962018-08-29 00:05:311611. Find the matching Chrome OS version and click on the column for 'Canary'
162 or 'Dev'.
Steven Bennetts7f08b002018-06-29 23:28:441631. Click on the dropdown icon in the 'Images' column and click on 'Unsigned
164 test image'.
165
166**Non-Googlers**: The build infrastructure is currently in flux. See
Achuith Bhandarkar61f58962018-08-29 00:05:31167[crbug.com/360342] for more details. You may need to build your own Chrome OS
168image.
James Cookb181cf72017-08-04 19:41:53169
Satoru Takabayashieef6f592017-06-23 04:16:36170After you download the compressed tarball containing the test image (it should
171have "test" somewhere in the file name), extract the image by running:
172
173```
Achuith Bhandarkar61f58962018-08-29 00:05:31174(sdk) tar xvf ~/Downloads/<image-you-downloaded>
Satoru Takabayashieef6f592017-06-23 04:16:36175```
176
Steven Bennetts7f08b002018-06-29 23:28:44177Copy the image to your USB stick using `cros flash`:
Satoru Takabayashieef6f592017-06-23 04:16:36178
179```
Achuith Bhandarkar61f58962018-08-29 00:05:31180(sdk) cros flash usb:// chromiumos_test_image.bin
Satoru Takabayashieef6f592017-06-23 04:16:36181```
182
Achuith Bhandarkar61f58962018-08-29 00:05:31183> **Tip:** If you have a Chrome OS checkout, the following can be used to
Steven Bennetts7f08b002018-06-29 23:28:44184update a device that already has a test image installed. Star
Achuith Bhandarkar61f58962018-08-29 00:05:31185[crbug.com/403086] for updates on a proposal to support this without a
186Chrome OS checkout.
Steven Bennetts7f08b002018-06-29 23:28:44187
188```
189.../chromeos/src $ cros flash $IP_ADDR chromiumos_test_image.bin
190```
191
Satoru Takabayashieef6f592017-06-23 04:16:36192### Put your Chrome OS device in dev mode
193
Steven Bennetts0d195912018-09-18 23:37:39194You can skip this section if you're using a [VM].
Achuith Bhandarkar61f58962018-08-29 00:05:31195
Steven Bennetts7f08b002018-06-29 23:28:44196> **Note:** Switching to dev mode wipes all data from the device (for security
197> reasons).
James Cook961c57d2018-01-23 21:34:05198
James Cook93506b02018-01-17 06:13:07199Most recent devices can use the [generic instructions]. To summarize:
Satoru Takabayashieef6f592017-06-23 04:16:36200
Steven Bennetts7f08b002018-06-29 23:28:442011. With the device on, hit Esc + Refresh (F2 or F3) + power button
2021. Wait for the white "recovery screen"
2031. Hit Ctrl-D to switch to developer mode (there's no prompt)
2041. Press enter to confirm
2051. Once it is done, hit Ctrl-D again to boot, then wait
Satoru Takabayashieef6f592017-06-23 04:16:36206
James Cook961c57d2018-01-23 21:34:05207From this point on you'll always see the white screen when you turn on
James Cook3a2a0632018-01-18 06:21:56208the device. Press Ctrl-D to boot.
James Cook93506b02018-01-17 06:13:07209
210Older devices may have [device-specific instructions].
211
Steven Bennetts7f08b002018-06-29 23:28:44212*Googlers*: If the device asks you to "enterprise enroll", click the X in the
213top-right of the dialog to skip it. Trying to use your google.com credentials
214will result in an error.
James Cook3a2a0632018-01-18 06:21:56215
James Cook93506b02018-01-17 06:13:07216### Enable booting from USB
217
James Cook3a2a0632018-01-18 06:21:56218By default Chromebooks will not boot off a USB stick for security reasons.
James Cook961c57d2018-01-23 21:34:05219You need to enable it.
James Cook3a2a0632018-01-18 06:21:56220
Steven Bennetts7f08b002018-06-29 23:28:442211. Start the device
2221. Press Ctrl-Alt-F2 to get a terminal. (You can use Ctrl-Alt-F1 to switch
223 back if you need to.)
2241. Login as `root` (no password yet, there will be one later)
2251. Run `enable_dev_usb_boot`
James Cook3d135382017-10-16 16:58:01226
Satoru Takabayashieef6f592017-06-23 04:16:36227### Install the test image onto your device
228
Steven Bennetts7f08b002018-06-29 23:28:44229> **Note:** Do not log into this test image with a username and password you
230> care about. The root password is public ("test0000"), so anyone with SSH
231> access could compromise the device. Create a test Gmail account and use that.
Satoru Takabayashieef6f592017-06-23 04:16:36232
Steven Bennetts7f08b002018-06-29 23:28:442331. Plug the USB stick into the machine and reboot.
2341. At the dev-mode warning screen, press Ctrl-U to boot from the USB stick.
2351. Switch to terminal by pressing Ctrl-Alt-F2
2361. Login as user `chronos`, password `test0000`.
2371. Run `/usr/sbin/chromeos-install`
2381. Wait for it to copy the image
2391. Run `poweroff`
James Cook3a2a0632018-01-18 06:21:56240
241You can now unplug the USB stick.
242
Steven Bennetts7f08b002018-06-29 23:28:44243### Connect device to Ethernet
244
245Use your USB-to-Ethernet adapter to connect the device to a network.
246
James Cook614fafc2019-01-22 23:21:02247*Googlers*: If your building has Ethernet jacks connected to the test VLAN
248(e.g. white ports), use one of those jacks. Otherwise get a second Ethernet
249adapter and see [go/shortleash] to reverse tether your Chromebook to your
250workstation.
Steven Bennetts7f08b002018-06-29 23:28:44251
Satoru Takabayashieef6f592017-06-23 04:16:36252### Checking the IP address
253
Steven Bennetts7f08b002018-06-29 23:28:442541. Click the status area in the lower-right corner
2551. Click the network icon
2561. Click the circled `i` symbol in the lower-right corner
2571. A small window pops up that shows the IP address
Satoru Takabayashieef6f592017-06-23 04:16:36258
Steven Bennetts7f08b002018-06-29 23:28:44259You can also run `ifconfig` from the terminal (Ctrl-Alt-F2).
James Cook3a2a0632018-01-18 06:21:56260
Achuith Bhandarkar61f58962018-08-29 00:05:31261---
262
263## Deploying Chrome to the device
264
265To deploy the build to a device/VM, you will need direct SSH access to it from
266your computer. The scripts below handle everything else.
267
Satoru Takabayashieef6f592017-06-23 04:16:36268### Using deploy_chrome
269
Achuith Bhandarkar61f58962018-08-29 00:05:31270The `deploy_chrome` script uses rsync to incrementally deploy Chrome to the
271device/VM.
Satoru Takabayashieef6f592017-06-23 04:16:36272
Achuith Bhandarkar61f58962018-08-29 00:05:31273Specify the build output directory to deploy from using `--build-dir`. For the
Steven Bennetts0d195912018-09-18 23:37:39274[VM]:
Satoru Takabayashieef6f592017-06-23 04:16:36275
276```
Steven Bennetts8a0efd92018-11-27 17:32:52277(sdk) deploy_chrome --build-dir=out_${SDK_BOARD}/Release --to=localhost --port=9222
Achuith Bhandarkar61f58962018-08-29 00:05:31278```
279
280For a physical device, which must be ssh-able as user 'root', you must specify
281the IP address using `--to`:
282
283```
284(sdk) deploy_chrome --build-dir=out_${SDK_BOARD}/Release --to=$IP_ADDR
Satoru Takabayashieef6f592017-06-23 04:16:36285```
286
Steven Bennetts7f08b002018-06-29 23:28:44287> **Note:** The first time you run this you will be prompted to remove rootfs
288> verification from the device. This is required to overwrite /opt/google/chrome
289> and will reboot the device. You can skip the prompt with `--force`.
Satoru Takabayashieef6f592017-06-23 04:16:36290
Steven Bennetts7f08b002018-06-29 23:28:44291### Deploying Chrome to the user partition
Satoru Takabayashieef6f592017-06-23 04:16:36292
Steven Bennetts7f08b002018-06-29 23:28:44293It is also possible to deploy Chrome to the user partition of the device and
Achuith Bhandarkard2570122018-08-03 00:56:43294set up a temporary mount from `/opt/google/chrome` using the option `--mount`.
295This is useful when deploying a binary that will not otherwise fit on the
296device, e.g.:
Satoru Takabayashieef6f592017-06-23 04:16:36297
Steven Bennetts7f08b002018-06-29 23:28:44298* When using `--nostrip` to provide symbols for backtraces.
299* When using other compile options that produce a significantly larger image.
James Cookba126f12017-08-21 19:59:07300
Steven Bennetts7f08b002018-06-29 23:28:44301```
Steven Bennetts8a0efd92018-11-27 17:32:52302(sdk) deploy_chrome --build-dir=out_$SDK_BOARD/Release --to=$IP_ADDR --mount [--nostrip]
Steven Bennetts7f08b002018-06-29 23:28:44303```
304
Achuith Bhandarkard2570122018-08-03 00:56:43305> **Note:** This also prompts to remove rootfs verification so that
Steven Bennetts7f08b002018-06-29 23:28:44306> /etc/chrome_dev.conf can be modified (see [Command-line flags and
307> environment variables]). You can skip that by adding
308> `--noremove-rootfs-verification`.
309
310#### Additional Notes:
311
Achuith Bhandarkard2570122018-08-03 00:56:43312* The mount is transient and does not survive a reboot. The easiest way to
313 reinstate the mount is to run the same deploy_chrome command after reboot.
314 It will only redeploy binaries if there is a change. To verify that the
315 mount is active, run `findmnt /opt/google/chrome`. The output should be:
316```
317TARGET SOURCE FSTYPE OPTIONS
318/opt/google/chrome /dev/sda1[/deploy_rootfs/opt/google/chrome] ext4 rw,nodev,noatime,resgid=20119,commit=600,data=ordered
319```
Steven Bennetts7f08b002018-06-29 23:28:44320* If startup needs to be tested (i.e. before deploy_chrome can be run), a
321 symbolic link will need to be created instead:
322 * ssh to device
323 * `mkdir /home/chrome`
324 * `rm -R /opt/google/chrome`
325 * `ln -s /home/chrome /opt/google/chrome`
326 * `deploy_chrome --build-dir=out_${SDK_BOARD}/Release --to=$IP_ADDR
327 --nostrip`
328 * The device can then be rebooted and the unstripped version of Chrome
329 will be run.
330* `deploy_chrome` lives under `$CHROME_DIR/src/third_party/chromite/bin`.
331 You can run `deploy_chrome` outside of a `chrome-sdk` shell.
332
333## Updating the Chrome OS image
334
335In order to keep Chrome and Chrome OS in sync, the Chrome OS test image
336should be updated weekly. See [Create a bootable USB stick] for a tip on
Achuith Bhandarkar61f58962018-08-29 00:05:31337updating an existing test device if you have a Chrome OS checkout.
Steven Bennetts7f08b002018-06-29 23:28:44338
339---
James Cookba126f12017-08-21 19:59:07340
Satoru Takabayashieef6f592017-06-23 04:16:36341## Debugging
342
Satoru Takabayashi7cc76c92017-06-26 04:46:05343### Log files
Satoru Takabayashieef6f592017-06-23 04:16:36344
Achuith Bhandarkar8bca7812019-02-06 20:51:10345[Chrome-related logs] are written to several locations on the device running a
346test image:
Satoru Takabayashieef6f592017-06-23 04:16:36347
Steven Bennetts7f08b002018-06-29 23:28:44348* `/var/log/ui/ui.LATEST` contains messages written to stderr by Chrome
349 before its log file has been initialized.
Achuith Bhandarkar8bca7812019-02-06 20:51:10350* `/var/log/chrome/chrome` contains messages logged by Chrome both before and
351 after login since Chrome runs with `--disable-logging-redirect` on test
352 images.
Steven Bennetts7f08b002018-06-29 23:28:44353* `/var/log/messages` contains messages logged by `session_manager`
354 (which is responsible for starting Chrome), in addition to kernel
355 messages when a Chrome process crashes.
Satoru Takabayashi7cc76c92017-06-26 04:46:05356
357### Command-line flags and environment variables
Satoru Takabayashieef6f592017-06-23 04:16:36358
359If you want to tweak the command line of Chrome or its environment, you have to
360do this on the device itself.
361
Satoru Takabayashieef6f592017-06-23 04:16:36362Edit the `/etc/chrome_dev.conf` (device) file. Instructions on using it are in
363the file itself.
364
James Cook961c57d2018-01-23 21:34:05365### Custom build directories
366
367This step is only necessary if you run `cros chrome-sdk` with `--nogn-gen`.
368
369To create a GN build directory, run the following inside the chrome-sdk shell:
370
371```
Achuith Bhandarkar61f58962018-08-29 00:05:31372(sdk) gn gen out_$SDK_BOARD/Release --args="$GN_ARGS"
James Cook961c57d2018-01-23 21:34:05373```
374
375This will generate `out_$SDK_BOARD/Release/args.gn`.
376
Steven Bennetts7f08b002018-06-29 23:28:44377* You must specify `--args`, otherwise your build will not work on the device.
378* You only need to run `gn gen` once within the same `cros chrome-sdk`
379 session.
380* However, if you exit the session or sync/update Chrome the `$GN_ARGS` might
381 change and you need to `gn gen` again.
James Cook961c57d2018-01-23 21:34:05382
383You can edit the args with:
384
385```
Achuith Bhandarkar61f58962018-08-29 00:05:31386(sdk) gn args out_$SDK_BOARD/Release
James Cook961c57d2018-01-23 21:34:05387```
388
389You can replace `Release` with `Debug` (or something else) for different
Steven Bennetts7f08b002018-06-29 23:28:44390configurations. See [Debug builds].
James Cook961c57d2018-01-23 21:34:05391
392[GN build configuration] discusses various GN build configurations. For more
393info on GN, run `gn help` on the command line or read the [quick start guide].
394
Steven Bennetts7f08b002018-06-29 23:28:44395### Debug builds
Satoru Takabayashieef6f592017-06-23 04:16:36396
397For cros chrome-sdk GN configurations, Release is the default. A debug build of
398Chrome will include useful tools like DCHECK and debug logs like DVLOG. For a
399Debug configuration, specify
Achuith Bhandarkar61f58962018-08-29 00:05:31400`--args="$GN_ARGS is_debug=true is_component_build=false"`.
Satoru Takabayashieef6f592017-06-23 04:16:36401
402Alternately, you can just turn on DCHECKs for a release build. You can do this
403with `--args="$GN_ARGS dcheck_always_on=true"`.
404
Steven Bennetts7f08b002018-06-29 23:28:44405To deploy a debug build you need to add `--nostrip` to `deploy_chrome` because
406otherwise it will strip symbols even from a debug build. This requires
407[Deploying Chrome to the user partition].
Satoru Takabayashieef6f592017-06-23 04:16:36408
Steven Bennetts7f08b002018-06-29 23:28:44409> **Note:** If you just want crash backtraces in the logs you can deploy a
410> release build with `--nostrip`. You don't need a debug build (but you still
411> need to deploy to a user partition).
412>
413> **Note:** You may hit `DCHECKs` during startup time, or when you login, which
414> eventually may reboot the device. You can check log files in `/var/log/chrome`
415> or `/home/chronos/user/log`.
416>
417> You can create `/run/disable_chrome_restart` to prevent a restart loop and
418> investigate.
419>
420> You can temporarily disable these `DCHECKs` to proceed, but please file a
421> bug for such `DCHECK` because it's most likely a bug.
Satoru Takabayashieef6f592017-06-23 04:16:36422
423### Remote GDB
424
Satoru Takabayashi7cc76c92017-06-26 04:46:05425Core dumps are disabled by default. See [additional debugging tips] for how to
Satoru Takabayashieef6f592017-06-23 04:16:36426enable core files.
427
428On the target machine, open up a port for the gdb server to listen on, and
Satoru Takabayashi7cc76c92017-06-26 04:46:05429attach the gdb server to the top-level Chrome process.
Satoru Takabayashieef6f592017-06-23 04:16:36430
431```
432(device) sudo /sbin/iptables -A INPUT -p tcp --dport 1234 -j ACCEPT
Steven Bennetts8a0efd92018-11-27 17:32:52433(device) sudo gdbserver --attach :1234 $(pgrep chrome -P $(pgrep session_manager))
Satoru Takabayashieef6f592017-06-23 04:16:36434```
435
436On your host machine (inside the chrome-sdk shell), run gdb and start the Python
437interpreter:
438
439```
Achuith Bhandarkar61f58962018-08-29 00:05:31440(sdk) cd %CHROME_DIR%/src
441(sdk) gdb out_${SDK_BOARD}/Release/chrome
442Reading symbols from /usr/local/google2/chromium2/src/out_amd64-generic/Release/chrome...
Satoru Takabayashieef6f592017-06-23 04:16:36443(gdb) pi
444>>>
445```
446
Steven Bennetts7f08b002018-06-29 23:28:44447> **Note:** These instructions are for targeting an x86_64 device. For now, to
448> target an ARM device, you need to run the cross-compiled gdb from within a
449> chroot.
Satoru Takabayashieef6f592017-06-23 04:16:36450
451Then from within the Python interpreter, run these commands:
452
Steven Bennetts7f08b002018-06-29 23:28:44453```python
Satoru Takabayashieef6f592017-06-23 04:16:36454import os
455sysroot = os.environ['SYSROOT']
Achuith Bhandarkar61f58962018-08-29 00:05:31456board = os.environ['SDK_BOARD']
Satoru Takabayashieef6f592017-06-23 04:16:36457gdb.execute('set sysroot %s' % sysroot)
458gdb.execute('set solib-absolute-prefix %s' % sysroot)
459gdb.execute('set debug-file-directory %s/usr/lib/debug' % sysroot)
Achuith Bhandarkar61f58962018-08-29 00:05:31460# "Debug" for a debug build
461gdb.execute('set solib-search-path out_%s/Release/lib' % board)
Steven Bennetts7f08b002018-06-29 23:28:44462gdb.execute('target remote $IP_ADDR:1234')
Satoru Takabayashieef6f592017-06-23 04:16:36463```
464
465If you wish, after you connect, you can Ctrl-D out of the Python shell.
466
Achuith Bhandarkar61f58962018-08-29 00:05:31467Extra debugging instructions are located at [debugging tips].
Steven Bennetts7f08b002018-06-29 23:28:44468
469---
Satoru Takabayashieef6f592017-06-23 04:16:36470
471## Additional instructions
472
473### Updating the version of the Chrome OS SDK
474
475When you invoke `cros chrome-sdk`, the script fetches the version of the SDK
Steven Bennetts7f08b002018-06-29 23:28:44476that corresponds to your Chrome checkout. To update the SDK, sync your Chrome
Satoru Takabayashieef6f592017-06-23 04:16:36477checkout and re-run `cros chrome-sdk`.
478
479**IMPORTANT NOTES:**
480
Achuith Bhandarkar61f58962018-08-29 00:05:31481* Every time that you update Chrome or the Chrome OS SDK, it is possible
482 that Chrome may start depending on new features from a new Chrome OS
483 image. This can cause unexpected problems, so it is important to update
484 your image regularly. Instructions for updating your Chrome OS image are
485 above in [Set up the Chrome OS device]. This is not a concern for a
486 downloaded VM.
Steven Bennetts7f08b002018-06-29 23:28:44487* Don't forget to re-configure your custom build directories if you have them
488 (see [Custom build directories]).
Satoru Takabayashieef6f592017-06-23 04:16:36489
490### Specifying the version of the Chrome OS SDK to use
491
492You can specify a version of Chrome OS to build against. This is handy for
493tracking down when a particular bug was introduced.
494
495```
Achuith Bhandarkar61f58962018-08-29 00:05:31496(shell) cros chrome-sdk --board=$BOARD --version=11005.0.0
Satoru Takabayashieef6f592017-06-23 04:16:36497```
498
Achuith Bhandarkar61f58962018-08-29 00:05:31499Once you are finished testing the old version of the chrome-sdk, you can
500always start a new shell with the latest version again. Here's an example:
Satoru Takabayashieef6f592017-06-23 04:16:36501
502```
Achuith Bhandarkar61f58962018-08-29 00:05:31503(shell) cros chrome-sdk --board=$BOARD --clear-sdk-cache
Satoru Takabayashieef6f592017-06-23 04:16:36504```
505
506### Updating Chrome
507
Steven Bennetts7f08b002018-06-29 23:28:44508```
Achuith Bhandarkar61f58962018-08-29 00:05:31509(sdk) exit
510(shell) git checkout master && git pull # (or if you prefer, git rebase-update)
511(shell) gclient sync
512(shell) cros chrome-sdk --board=$BOARD --log-level=info
Steven Bennetts7f08b002018-06-29 23:28:44513```
Satoru Takabayashieef6f592017-06-23 04:16:36514
Steven Bennetts7f08b002018-06-29 23:28:44515> **Tip:** If you update Chrome inside the chrome-sdk, you may then be using an
516> SDK that is out of date with the current Chrome.
517> See [Updating the version of the Chrome OS SDK] section above.
518
Satoru Takabayashieef6f592017-06-23 04:16:36519
520### Updating Deployed Files
521
Steven Bennetts7f08b002018-06-29 23:28:44522`deploy_chrome` determines which files to copy in `chrome_util.py` in the
523[chromite repo] which is pulled into `chrome/src/third_party/chromite` via DEPS.
Satoru Takabayashieef6f592017-06-23 04:16:36524
Steven Bennetts7f08b002018-06-29 23:28:44525When updating the list:
Satoru Takabayashieef6f592017-06-23 04:16:36526
Steven Bennetts7f08b002018-06-29 23:28:445271. Make changes to the appropriate list (e.g. `_COPY_PATHS_CHROME`).
5281. Be aware that deploy_chrome is used by the chromeos-chrome ebuild, so when
529 adding new files make sure to set optional=True initially.
5301. Changes to chromite will not affect Simple Chrome until a chromite roll
531 occurs.
Satoru Takabayashieef6f592017-06-23 04:16:36532
Achuith Bhandarkar61f58962018-08-29 00:05:31533### Using a custom Chrome OS build
James Cookba126f12017-08-21 19:59:07534
Achuith Bhandarkar61f58962018-08-29 00:05:31535If you are making changes to Chrome OS and have a Chrome OS build inside a
James Cookba126f12017-08-21 19:59:07536chroot that you want to build against, run `cros chrome-sdk` with the `--chroot`
Steven Bennetts7f08b002018-06-29 23:28:44537option:
James Cookba126f12017-08-21 19:59:07538
539```
Achuith Bhandarkar61f58962018-08-29 00:05:31540(shell) cros chrome-sdk --board=$BOARD --chroot=/path/to/chromiumos/chroot
James Cookba126f12017-08-21 19:59:07541```
542
Satoru Takabayashieef6f592017-06-23 04:16:36543### Using cros flash with xbuddy to download images
544
545`cros flash` with `xbuddy` will automatically download an image and write it to
546USB for you. It's very convenient, but for now it requires a full Chrome OS
547checkout and must be run inside the Chrome OS chroot. ([issue 437877])
548
549```
Satoru Takabayashie0af9cb2017-06-23 05:26:08550(chroot) cros flash usb:// xbuddy://remote/$BOARD/<version>/test
Satoru Takabayashieef6f592017-06-23 04:16:36551```
552
553Replace `$BOARD` and `<version>` with the right values. Both can be seen in your
554SDK prompt (e.g. `(sdk lumpy R27-3789.0.0)` is the lumpy board using version
555R27-3789.0.0).
556
557See the [Cros Flash page] for more details.
558
Steven Bennetts7f08b002018-06-29 23:28:44559### Setting a custom prompt
Satoru Takabayashieef6f592017-06-23 04:16:36560
561By default, cros chrome-sdk prepends something like '`(sdk link R52-8315.0.0)`'
Satoru Takabayashi7cc76c92017-06-26 04:46:05562to the prompt (with the version of the prebuilt system being used).
Satoru Takabayashieef6f592017-06-23 04:16:36563
564If you prefer to colorize the prompt, you can set `PS1` in
Achuith Bhandarkar61f58962018-08-29 00:05:31565`~/.chromite/chrome_sdk.bashrc`, e.g. to prepend a yellow
566'`(sdk link 8315.0.0)`' to the prompt:
Satoru Takabayashieef6f592017-06-23 04:16:36567
568```
569PS1='\[\033[01;33m\](sdk ${SDK_BOARD} ${SDK_VERSION})\[\033[00m\] \w \[\033[01;36m\]$(__git_ps1 "(%s)")\[\033[00m\] \$ '
570```
Steven Bennetts7f08b002018-06-29 23:28:44571NOTE: Currently the release version (e.g. 52) is not available as an
572environment variable.
Satoru Takabayashieef6f592017-06-23 04:16:36573
James Cookba126f12017-08-21 19:59:07574### GYP
575
James Cook961c57d2018-01-23 21:34:05576The legacy `GYP` build system is no longer supported.
James Cookba126f12017-08-21 19:59:07577
Achuith Bhandarkar61f58962018-08-29 00:05:31578[Custom build directories]: #custom-build-directories
579[Updating the version of the Chrome OS SDK]: #updating-the-version-of-the-chrome-os-sdk
580[Using a custom Chrome OS build]: #using-a-custom-chrome-os-build
581[Command-line flags and environment variables]: #command-line-flags-and-environment-variables
582[Deploying Chrome to the user partition]: #deploying-chrome-to-the-user-partition
583[Debug builds]: #debug-builds
584[Create a bootable USB stick]: #create-a-bootable-usb-stick
585[Set up the Chrome OS device]: #set-up-the-chrome-os-device
586[OS development guide]: https://chromium.googlesource.com/chromiumos/docs/+/master/developer_guide.md
587[Chrome source code and depot_tools]: https://chromium.googlesource.com/chromium/src/+/master/docs/linux_build_instructions.md
Steven Bennetts7f08b002018-06-29 23:28:44588[update .gclient]: https://chromium.googlesource.com/chromium/src/+/HEAD/docs/chromeos_build_instructions.md#updating-your-gclient-config
Achuith Bhandarkar61f58962018-08-29 00:05:31589[Chrome OS board name]: https://www.chromium.org/chromium-os/developer-information-for-chrome-os-devices
Steven Bennetts7f08b002018-06-29 23:28:44590[GN build configuration]: https://www.chromium.org/developers/gn-build-configuration
Achuith Bhandarkar61f58962018-08-29 00:05:31591[quick start guide]: https://gn.googlesource.com/gn/+/master/docs/quick_start.md
James Cook3d135382017-10-16 16:58:01592[device-specific instructions]: https://www.chromium.org/chromium-os/developer-information-for-chrome-os-devices
593[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:36594[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:44595[remounted as read-write]: https://www.chromium.org/chromium-os/how-tos-and-troubleshooting/debugging-tips#TOC-Setting-up-the-device
596[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:36597[chromite repo]: https://chromium.googlesource.com/chromiumos/chromite/
598[issue 437877]: https://bugs.chromium.org/p/chromium/issues/detail?id=403086
Steven Bennetts7f08b002018-06-29 23:28:44599[Cros Flash page]: https://www.chromium.org/chromium-os/build/cros-flash
Steven Bennetts0d195912018-09-18 23:37:39600[VM]: https://chromium.googlesource.com/chromiumos/docs/+/master/cros_vm.md
Achuith Bhandarkar61f58962018-08-29 00:05:31601[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
602[go/goldeneye]: https://cros-goldeneye.corp.google.com/chromeos/console/listBuild
James Cook614fafc2019-01-22 23:21:02603[go/shortleash]: https://goto.google.com/shortleash
Achuith Bhandarkar61f58962018-08-29 00:05:31604[debugging tips]: https://www.chromium.org/chromium-os/how-tos-and-troubleshooting/debugging-tips
605[go/chrome-build-instructions]: https://companydoc.corp.google.com/company/teams/chrome/chrome_build_instructions.md
606[api-keys]: https://www.chromium.org/developers/how-tos/api-keys
607[Goma]: https://sites.google.com/a/google.com/goma/
Achuith Bhandarkar8bca7812019-02-06 20:51:10608[Chrome-related logs]: https://chromium.googlesource.com/chromium/src/+/lkgr/docs/chrome_os_logging.md
Achuith Bhandarkar61f58962018-08-29 00:05:31609[crbug.com/360342]: https://bugs.chromium.org/p/chromium/issues/detail?id=360342
610[crbug.com/403086]: https://bugs.chromium.org/p/chromium/issues/detail?id=403086