Satoru Takabayashi | 7cc76c9 | 2017-06-26 04:46:05 | [diff] [blame] | 1 | # Building Chrome for Chrome OS (Simple Chrome) |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 2 | |
| 3 | This workflow allows you to quickly build/deploy Chromium to any Chromium OS |
| 4 | device without needing a Chromium OS checkout or chroot. It's useful for trying |
| 5 | out your changes on a real device while you're doing Chromium development. If |
| 6 | you want your Chromium changes to be included when building a full Chromium OS |
| 7 | image, see the [instructions in the development guide]. |
| 8 | |
| 9 | At its core is the `chrome-sdk` shell which sets up the shell environment, and |
| 10 | fetches the necessary SDK components (CrOS toolchain, sysroot, etc.). |
| 11 | |
| 12 | [TOC] |
| 13 | |
| 14 | ## Typography conventions |
| 15 | |
| 16 | | Label | Paths, files, and commands | |
| 17 | |---------------|--------------------------------------------------------| |
Satoru Takabayashi | 7cc76c9 | 2017-06-26 04:46:05 | [diff] [blame] | 18 | | (outside) | on your build machine, outside the chroot | |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 19 | | (inside) | inside the `chrome-sdk` shell on your build machine (1)| |
| 20 | | (device) | on your Chromium OS device | |
James Cook | ba126f1 | 2017-08-21 19:59:07 | [diff] [blame] | 21 | | (chroot) | inside the `cros_sdk` crhoot | |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 22 | |
James Cook | ba126f1 | 2017-08-21 19:59:07 | [diff] [blame] | 23 | (1) Note: This is not the same thing as the `cros_sdk` chroot. |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 24 | |
James Cook | ba126f1 | 2017-08-21 19:59:07 | [diff] [blame] | 25 | ## Getting started |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 26 | |
James Cook | ba126f1 | 2017-08-21 19:59:07 | [diff] [blame] | 27 | First make sure you have a: |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 28 | |
James Cook | ba126f1 | 2017-08-21 19:59:07 | [diff] [blame] | 29 | 1. [Local copy of the Chromium source code and depot_tools] |
| 30 | 2. USB flash drive 4 GB or larger (for example, a Sandisk Extreme USB 3.0) |
| 31 | 3. USB to Ethernet adapter |
| 32 | |
| 33 | Googlers: Chromestop has the hardware. |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 34 | |
| 35 | ### Get Google API keys |
| 36 | |
| 37 | In order to sign in to your Chromebook you must have Google API keys: |
| 38 | |
| 39 | * External contributors, see http://www.chromium.org/developers/how-tos/api-keys |
| 40 | You'll need to put them in your `out_board/Release/args.gn file`, see below. |
Satoru Takabayashi | 7cc76c9 | 2017-06-26 04:46:05 | [diff] [blame] | 41 | * Googlers, see http://go/building-chrome to get internal source. If you have |
| 42 | `src-internal` in your `.gclient` file the official API keys will be set up |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 43 | automatically. |
| 44 | |
James Cook | 3a2a063 | 2018-01-18 06:21:56 | [diff] [blame^] | 45 | ## Set up gsutil |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 46 | |
James Cook | 3a2a063 | 2018-01-18 06:21:56 | [diff] [blame^] | 47 | Steps below may run slowly and fail with "Login Required" from gsutil. Use |
| 48 | depot_tools/gsutil.py and run `gsutil config` (outside) to set the |
| 49 | authentication token. (Googlers: Use your @google.com account.) |
| 50 | |
| 51 | **NOTE: When prompted for a project ID, enter 134157665460 as your project ID (this is the Chrome OS project ID).** |
| 52 | |
| 53 | ## Fetch the Chrome OS toolchain and SDK for building Chrome |
| 54 | |
| 55 | Toolchains are customized for each Chromebook model (or "board"). Look up your |
| 56 | [Chromium OS board name] by navigating to the URL `about:version` on the device. |
| 57 | For example: `Platform 10176.47.0 (Official Build) beta-channel samus` |
| 58 | has board `samus`. |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 59 | |
Steven Bennetts | 5a79a1c | 2017-11-27 20:05:47 | [diff] [blame] | 60 | Run this from within your Chromium checkout (not the Chromium OS chroot): |
| 61 | |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 62 | ``` |
James Cook | 3a2a063 | 2018-01-18 06:21:56 | [diff] [blame^] | 63 | (outside) cd /path/to/chrome/src |
| 64 | (outside) export BOARD=samus # or your board name |
| 65 | (outside) cros chrome-sdk --board=$BOARD --gn-gen --log-level=info |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 66 | ``` |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 67 | |
| 68 | `cros chrome-sdk` will fetch the latest Chrome OS SDK for building Chrome, and |
Steven Bennetts | 5a79a1c | 2017-11-27 20:05:47 | [diff] [blame] | 69 | put you in a shell with a command prompt starting with `(sdk $BOARD $VERSION)`. |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 70 | |
| 71 | `cros chrome-sdk` will also automatically install and start the Goma server, |
| 72 | with the active server port stored in the `$SDK_GOMA_PORT` (inside) environment |
| 73 | variable. |
| 74 | |
Steven Bennetts | 5a79a1c | 2017-11-27 20:05:47 | [diff] [blame] | 75 | **Note:** There are no public builders yet for non-generic boards, so you will |
| 76 | need to use a generic board (e.g. amd64-generic) or create your own local |
| 77 | build. Star http://crbug.com/360342 for updates. |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 78 | |
Steven Bennetts | 5a79a1c | 2017-11-27 20:05:47 | [diff] [blame] | 79 | ### cros chrome-sdk options: |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 80 | |
Steven Bennetts | 5a79a1c | 2017-11-27 20:05:47 | [diff] [blame] | 81 | * `--gn-gen` causes Simple Chrome to run 'gn gen' automatically (see below). |
| 82 | * `--nogn-gen` Do not run 'gn gen' automatically (nogn-gen is currently the |
| 83 | default but that may change). |
| 84 | * `--gn-extra-args = 'extra_arg = foo other_extra_arg = bar'` For setting |
| 85 | extra gn args, e.g. 'dcheck_always_on = true'. |
| 86 | * `--internal` Sets up Simple Chrome to build and deploy the official *Chrome* |
| 87 | instead of *Chromium*. |
| 88 | * `--log-level=info` Set the log level to 'info' or 'debug' (default is 'warn'). |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 89 | |
Steven Bennetts | 5a79a1c | 2017-11-27 20:05:47 | [diff] [blame] | 90 | **Note:** See below if you want to use a custom Chrome OS build. |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 91 | |
Steven Bennetts | 5a79a1c | 2017-11-27 20:05:47 | [diff] [blame] | 92 | > **Important:** If the Chromium checkout is updated, the Chrome OS build |
| 93 | > number may have changed (src/chromeos/CHROMEOS_LKGM) in which case it may |
| 94 | > be necessary to exit and re-enter the Simple Chrome environment to |
| 95 | > successfully build and deploy Chromium. |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 96 | |
Steven Bennetts | 5a79a1c | 2017-11-27 20:05:47 | [diff] [blame] | 97 | |
| 98 | ## Build Chrome |
| 99 | |
| 100 | ### Configure a build directory (optional) |
| 101 | |
| 102 | If you run `cros chrome-sdk` with `--gn-gen`, this step is not necessary. |
| 103 | |
| 104 | To create a GN build directory, run the following inside the chrome-sdk shell: |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 105 | |
| 106 | ``` |
| 107 | (inside) gn gen out_$SDK_BOARD/Release --args="$GN_ARGS" |
| 108 | ``` |
| 109 | |
| 110 | This will generate `out_$SDK_BOARD/Release/args.gn`. |
| 111 | |
| 112 | * You must specify `--args`, otherwise your build will not work on the device. |
Satoru Takabayashi | 7cc76c9 | 2017-06-26 04:46:05 | [diff] [blame] | 113 | * You only need to run `gn gen` once within the same `cros chrome-sdk` session. |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 114 | * However, if you exit the session or sync/update chrome the `$GN_ARGS` might |
| 115 | change and you need to `gn gen` again. |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 116 | |
| 117 | You can edit the args with: |
| 118 | |
| 119 | ``` |
| 120 | (inside) gn args out_$SDK_BOARD/Release |
| 121 | ``` |
| 122 | |
| 123 | You can replace Release with Debug (or something else) for different |
Satoru Takabayashi | 7cc76c9 | 2017-06-26 04:46:05 | [diff] [blame] | 124 | configurations. See **Debug build** section below. |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 125 | |
| 126 | [GN build configuration] discusses various GN build configurations. For more |
Satoru Takabayashi | 7cc76c9 | 2017-06-26 04:46:05 | [diff] [blame] | 127 | info on GN, run `gn help` on the command line or read the [quick start guide]. |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 128 | |
Steven Bennetts | 5a79a1c | 2017-11-27 20:05:47 | [diff] [blame] | 129 | ### Build Chrome |
| 130 | |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 131 | To build Chrome, run: |
| 132 | |
| 133 | ``` |
James Cook | 3a2a063 | 2018-01-18 06:21:56 | [diff] [blame^] | 134 | (inside) autoninja -C out_${SDK_BOARD}/Release chrome chrome_sandbox nacl_helper |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 135 | ``` |
| 136 | |
James Cook | 3a2a063 | 2018-01-18 06:21:56 | [diff] [blame^] | 137 | This runs Goma with a large number of concurrent jobs. To watch the build |
| 138 | progress, find the Goma port (`$ echo $SDK_GOMA_PORT`) and open |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 139 | http://localhost:<port_number> in a browser. |
| 140 | |
| 141 | **IMPORTANT**: Do not attempt to build targets other than **chrome, chrome_sandbox, |
| 142 | nacl_helper**, or (optionally) **chromiumos_preflight** in Simple Chrome, they will |
| 143 | likely fail. |
| 144 | |
| 145 | Congratulations, you've now built Chromium for Chromium OS! |
| 146 | |
| 147 | Once you've built Chromium the first time, you can build incrementally just |
| 148 | using ninja, e.g.: |
| 149 | |
| 150 | ``` |
James Cook | 3a2a063 | 2018-01-18 06:21:56 | [diff] [blame^] | 151 | (inside) autoninja -C out_${SDK_BOARD}/Release chrome |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 152 | ``` |
| 153 | |
| 154 | **Tip:** The default extensions will be installed by the test image you use below. |
| 155 | |
| 156 | ## Set up the Chromium OS device |
| 157 | |
| 158 | Before you can deploy your build of Chromium to the device, it needs to have a |
James Cook | 3a2a063 | 2018-01-18 06:21:56 | [diff] [blame^] | 159 | "test" OS image loaded on it. A test image has tools like rsync that are not part |
| 160 | of the end-user image. |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 161 | |
| 162 | ### Create a bootable USB stick |
| 163 | |
James Cook | 3a2a063 | 2018-01-18 06:21:56 | [diff] [blame^] | 164 | Use your browser to download a test image from the URL |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 165 | `https://storage.cloud.google.com/chromeos-image-archive/$BOARD-release/<version>/chromiumos_test_image.tar.xz` |
James Cook | 4c7510f | 2017-09-11 17:00:11 | [diff] [blame] | 166 | where `$BOARD` and `<version>` come from your SDK prompt. For example (`sdk link |
James Cook | ba126f1 | 2017-08-21 19:59:07 | [diff] [blame] | 167 | R62-9800.0.0`) is the board `link` using version `R62-9800.0.0`). |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 168 | |
James Cook | b181cf7 | 2017-08-04 19:41:53 | [diff] [blame] | 169 | Googlers: Prefer the above link for public boards. Images for non-public boards |
| 170 | are available on go/goldeneye. |
| 171 | |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 172 | After you download the compressed tarball containing the test image (it should |
| 173 | have "test" somewhere in the file name), extract the image by running: |
| 174 | |
| 175 | ``` |
James Cook | 3a2a063 | 2018-01-18 06:21:56 | [diff] [blame^] | 176 | (outside) tar xf ~/Downloads/<image-you-downloaded> |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 177 | ``` |
| 178 | |
Satoru Takabayashi | 7cc76c9 | 2017-06-26 04:46:05 | [diff] [blame] | 179 | Copy the image to your drive using `cros flash`: |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 180 | |
| 181 | ``` |
| 182 | (inside) cros flash usb:// chromiumos_test_image.bin |
| 183 | ``` |
| 184 | |
Satoru Takabayashi | 7cc76c9 | 2017-06-26 04:46:05 | [diff] [blame] | 185 | If `cros flash` does not work you can do it the old-fashioned way using `dd`. |
James Cook | ba126f1 | 2017-08-21 19:59:07 | [diff] [blame] | 186 | See below. |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 187 | |
| 188 | ### Put your Chrome OS device in dev mode |
| 189 | |
James Cook | 93506b0 | 2018-01-17 06:13:07 | [diff] [blame] | 190 | Most recent devices can use the [generic instructions]. To summarize: |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 191 | |
James Cook | 93506b0 | 2018-01-17 06:13:07 | [diff] [blame] | 192 | 1. With the device on, hit Esc + Refresh (F2 or F3) + power button |
| 193 | 2. Wait for the scary "recovery screen" |
| 194 | 3. Hit Ctrl-D to switch to developer mode (there's no prompt) |
| 195 | 4. Press enter to confirm |
James Cook | 3a2a063 | 2018-01-18 06:21:56 | [diff] [blame^] | 196 | 5. Once it is done, hit Ctrl-D again to boot, then wait |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 197 | |
James Cook | 93506b0 | 2018-01-17 06:13:07 | [diff] [blame] | 198 | From this point on you'll always see the scary screen when you turn on |
James Cook | 3a2a063 | 2018-01-18 06:21:56 | [diff] [blame^] | 199 | the device. Press Ctrl-D to boot. |
James Cook | 93506b0 | 2018-01-17 06:13:07 | [diff] [blame] | 200 | |
| 201 | Older devices may have [device-specific instructions]. |
| 202 | |
James Cook | 3a2a063 | 2018-01-18 06:21:56 | [diff] [blame^] | 203 | Googlers: If the device asks you to "enterprise enroll" it, click the X |
| 204 | in the top-right of the dialog to skip it. Trying to use your google.com |
| 205 | credentials will result in an error. |
| 206 | |
James Cook | 93506b0 | 2018-01-17 06:13:07 | [diff] [blame] | 207 | ### Enable booting from USB |
| 208 | |
James Cook | 3a2a063 | 2018-01-18 06:21:56 | [diff] [blame^] | 209 | By default Chromebooks will not boot off a USB stick for security reasons. |
| 210 | You need to turn that on. |
| 211 | |
James Cook | 93506b0 | 2018-01-17 06:13:07 | [diff] [blame] | 212 | 1. Start the device |
James Cook | 3a2a063 | 2018-01-18 06:21:56 | [diff] [blame^] | 213 | 2. Press Ctrl-Alt-F2 to get a terminal. (You can use Ctrl-Alt-F1 to switch |
| 214 | back if you need to.) |
| 215 | 3. Login as `root` (no password yet, there will be one later) |
| 216 | 4. `enable_dev_usb_boot` |
James Cook | 3d13538 | 2017-10-16 16:58:01 | [diff] [blame] | 217 | |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 218 | ### Install the test image onto your device |
| 219 | |
James Cook | 3a2a063 | 2018-01-18 06:21:56 | [diff] [blame^] | 220 | **NOTE:** |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 221 | |
| 222 | * Installing Chromium OS onto your hard disk will **WIPE YOUR HARD DISK CLEAN**. |
| 223 | * *DO NOT* log into this test image with a username and password you care |
Satoru Takabayashi | 7cc76c9 | 2017-06-26 04:46:05 | [diff] [blame] | 224 | about. **The root password is public** ("test0000"), so anyone with SSH |
| 225 | access could compromise the device. |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 226 | |
James Cook | 3a2a063 | 2018-01-18 06:21:56 | [diff] [blame^] | 227 | 1. Plug the USB stick into the machine and reboot. |
| 228 | 2. At the dev-mode warning screen, press Ctrl-U to boot from the USB stick. |
| 229 | 3. Switch to terminal by pressing Ctrl-Alt-F2 |
| 230 | 4. Login as user `chronos`, password `test0000`. |
| 231 | 5. `/usr/sbin/chromeos-install` |
| 232 | 6. Wait for it to copy the image |
| 233 | 7. `shutdown -h now` |
| 234 | |
| 235 | You can now unplug the USB stick. |
| 236 | |
James Cook | ba126f1 | 2017-08-21 19:59:07 | [diff] [blame] | 237 | ### Connect device to Ethernet |
| 238 | |
James Cook | 3a2a063 | 2018-01-18 06:21:56 | [diff] [blame^] | 239 | Use your USB-to-Ethernet adapter to connect the device to a network. |
James Cook | ba126f1 | 2017-08-21 19:59:07 | [diff] [blame] | 240 | |
| 241 | Googlers: You can use a corp Ethernet jack, which will place you on a special |
| 242 | restricted network. |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 243 | |
| 244 | ## Deploying Chrome to the device |
| 245 | |
Satoru Takabayashi | 7cc76c9 | 2017-06-26 04:46:05 | [diff] [blame] | 246 | To deploy the build to a device, you will need direct SSH access to it from your |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 247 | computer. The scripts below handle everything else. |
| 248 | |
| 249 | ### Checking the IP address |
| 250 | |
| 251 | 1. Click the status area in the lower-right corner |
| 252 | 2. Click the network icon |
Satoru Takabayashi | 7cc76c9 | 2017-06-26 04:46:05 | [diff] [blame] | 253 | 3. Click the circled `i` symbol in the lower-right corner |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 254 | 4. A small window pops up that shows the IP address |
| 255 | |
Satoru Takabayashi | 7cc76c9 | 2017-06-26 04:46:05 | [diff] [blame] | 256 | This also works both before and after login. Another option is to run `ifconfig` |
| 257 | from `crosh` (Ctrl-Alt-t) after guest login. |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 258 | |
James Cook | 3a2a063 | 2018-01-18 06:21:56 | [diff] [blame^] | 259 | Try pinging that IP address from your Linux workstation. |
| 260 | |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 261 | ### Using deploy_chrome |
| 262 | |
| 263 | Just type `deploy_chrome` from with your chrome-sdk shell. It will use rsync to |
| 264 | incrementally deploy to the device. |
| 265 | |
| 266 | Specify the build output directory to deploy from using `--build-dir`, and the |
| 267 | IP address of the target device (which must be ssh-able as user 'root') using |
| 268 | `--to`, where `%CHROME_DIR%` is the path to your Chrome checkout: |
| 269 | |
| 270 | ``` |
| 271 | (inside) cd %CHROME_DIR%/src |
| 272 | (inside) deploy_chrome --build-dir=out_${SDK_BOARD}/Release --to=172.11.11.11 |
| 273 | ``` |
| 274 | |
| 275 | **Tip:** `deploy_chrome` lives under |
| 276 | `$CHROME_DIR/src/third_party/chromite/bin`. You can run `deploy_chrome` outside |
| 277 | of a `chrome-sdk` shell as well. |
| 278 | |
| 279 | **Tip:** Specify the `--target-dir` flag to deploy to a custom location on the |
| 280 | target device. |
| 281 | |
| 282 | **NOTE for GN**: The gn build outputs .so files (for component builds) and some |
| 283 | test files in a different location than the gyp build. In order for |
| 284 | `deploy_chrome` to successfully locate these files, it needs to know that chrome |
| 285 | was built using gn. Currently cros chrome-sdk looks for |
| 286 | `GYP_CHROMIUM_NO_ACTION=1` as a hint to set `USE="gn"` which will cause |
| 287 | deploy_chrome to look for files in the correct place. If you do not have |
| 288 | `GYP_CHROMIUM_NO_ACTION=1` set or if you do but have build chrome with gyp, you |
| 289 | can set `USE="gn"` or `USE=""` to indicate where deploy_chrome should look for |
| 290 | output files. |
| 291 | |
James Cook | ba126f1 | 2017-08-21 19:59:07 | [diff] [blame] | 292 | ## Updating the OS image |
| 293 | |
James Cook | d1babeb | 2017-08-31 20:14:10 | [diff] [blame] | 294 | Every week you should update the Chrome OS image on the device so that |
| 295 | Chrome and Chrome OS don't get out of sync. Follow the above instructions. |
| 296 | (When http://crbug.com/761102 is fixed you'll be able to do this over the |
| 297 | network with `cros flash`.) |
James Cook | ba126f1 | 2017-08-21 19:59:07 | [diff] [blame] | 298 | |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 299 | ## Debugging |
| 300 | |
Satoru Takabayashi | 7cc76c9 | 2017-06-26 04:46:05 | [diff] [blame] | 301 | ### Log files |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 302 | |
Satoru Takabayashi | 7cc76c9 | 2017-06-26 04:46:05 | [diff] [blame] | 303 | Chrome-related logs are written to several locations on the device: |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 304 | |
Satoru Takabayashi | 7cc76c9 | 2017-06-26 04:46:05 | [diff] [blame] | 305 | * `/var/log/ui/ui.LATEST` contains messages written to stderr by Chrome |
| 306 | before its log file has been initialized. |
| 307 | * `/var/log/chrome/chrome` contains messages logged by Chrome before a |
| 308 | user has logged in. |
| 309 | * `/home/chronos/user/log/chrome` contains messages logged by Chrome |
| 310 | after a user has logged in. |
| 311 | * `/var/log/messages` contains messages logged by `session_manager` |
| 312 | (which is responsible for starting Chrome), in addition to kernel |
| 313 | messages when a Chrome process crashes. |
| 314 | |
| 315 | ### Command-line flags and environment variables |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 316 | |
| 317 | If you want to tweak the command line of Chrome or its environment, you have to |
| 318 | do this on the device itself. |
| 319 | |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 320 | Edit the `/etc/chrome_dev.conf` (device) file. Instructions on using it are in |
| 321 | the file itself. |
| 322 | |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 323 | ### Debug build |
| 324 | |
| 325 | For cros chrome-sdk GN configurations, Release is the default. A debug build of |
| 326 | Chrome will include useful tools like DCHECK and debug logs like DVLOG. For a |
| 327 | Debug configuration, specify |
Maksim Ivanov | e066b39 | 2017-07-18 14:12:30 | [diff] [blame] | 328 | `--args="$GN_ARGS is_debug=true is_component_build=false"` (inside). |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 329 | |
| 330 | Alternately, you can just turn on DCHECKs for a release build. You can do this |
| 331 | with `--args="$GN_ARGS dcheck_always_on=true"`. |
| 332 | |
| 333 | ### Deploying debug build without stripping symbols |
| 334 | |
| 335 | You need to add `--nostrip` to `deploy_chrome` because otherwise it will strip |
| 336 | symbols even from a debug build. The rootfs will probably not be big enough to |
| 337 | hold all the binaries so you need to put it on the stateful partition and bind |
Satoru Takabayashi | 7cc76c9 | 2017-06-26 04:46:05 | [diff] [blame] | 338 | mount over the real directory. Create the directory `/usr/local/chrome` on your |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 339 | device and run: |
| 340 | |
| 341 | ``` |
| 342 | (inside) deploy_chrome --build-dir=out_$BOARD/Debug \ |
| 343 | --to=<ip-address> \ |
| 344 | --target-dir=/usr/local/chrome \ |
| 345 | --mount-dir=/opt/google/chrome \ |
| 346 | --nostrip |
| 347 | ``` |
| 348 | |
| 349 | Notes: |
| 350 | |
| 351 | * If you just want crash backtraces in the logs you can deploy a release build |
| 352 | with `--nostrip`. You don't need a debug build. |
| 353 | * The remount from `/usr/local/chrome` to `/opt/google/chrome` is transient, so |
| 354 | you need to remount after reboot. Simplest way is to run the same command |
| 355 | after reboot (It will not redeploy binaries less there is a change) |
| 356 | * You may hit `DCHECKs` during startup time, or when you login, which eventually |
| 357 | may reboot the device. Please check log files in `/var/log/chrome` or |
| 358 | `/home/chronos/user/log`. |
Mike Frysinger | 6579006 | 2017-10-23 20:20:56 | [diff] [blame] | 359 | * You may create `/run/disable_chrome_restart` to prevent restart |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 360 | loop and investigate. |
| 361 | * You can temporarily disable these `DCHECKs` to proceed, but please |
| 362 | file a bug for such `DCHECK` because it's most likely a bug. |
| 363 | * You may not be able to create `/usr/local/chrome` until |
| 364 | [rootfs has been removed] on the device, and the device has been |
| 365 | [remounted as read-write]. The mounting will need to be applied on each |
| 366 | boot. If the startup needs to be tested a symbolic link will be needed instead |
| 367 | * ssh to device |
| 368 | * `mkdir /home/chrome` |
| 369 | * `rm -R /opt/google/chrome` |
| 370 | * `ln -s /home/chrome /opt/google/chrome` |
| 371 | * `deploy_chrome --build-dir=out_${SDK_BOARD}/Release --to=172.11.11.11` |
| 372 | |
| 373 | ### Remote GDB |
| 374 | |
Satoru Takabayashi | 7cc76c9 | 2017-06-26 04:46:05 | [diff] [blame] | 375 | Core dumps are disabled by default. See [additional debugging tips] for how to |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 376 | enable core files. |
| 377 | |
| 378 | On the target machine, open up a port for the gdb server to listen on, and |
Satoru Takabayashi | 7cc76c9 | 2017-06-26 04:46:05 | [diff] [blame] | 379 | attach the gdb server to the top-level Chrome process. |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 380 | |
| 381 | ``` |
| 382 | (device) sudo /sbin/iptables -A INPUT -p tcp --dport 1234 -j ACCEPT |
| 383 | (device) sudo gdbserver --attach :1234 $(pgrep chrome -P $(pgrep session_manager)) |
| 384 | ``` |
| 385 | |
| 386 | On your host machine (inside the chrome-sdk shell), run gdb and start the Python |
| 387 | interpreter: |
| 388 | |
| 389 | ``` |
| 390 | (inside) cd %CHROME_DIR%/src |
| 391 | (inside) gdb out_${SDK_BOARD}/Release/chrome |
| 392 | Reading symbols from /usr/local/google2/chromium2/src/out_link/Release/chrome... |
| 393 | (gdb) pi |
| 394 | >>> |
| 395 | ``` |
| 396 | |
| 397 | **Note: These instructions are for targeting an x86_64 device. For now, to target |
| 398 | an ARM device, you need to run the cross-compiled gdb from within a chroot.** |
| 399 | |
| 400 | Then from within the Python interpreter, run these commands: |
| 401 | |
| 402 | ``` |
| 403 | import os |
| 404 | sysroot = os.environ['SYSROOT'] |
| 405 | gdb.execute('set sysroot %s' % sysroot) |
| 406 | gdb.execute('set solib-absolute-prefix %s' % sysroot) |
| 407 | gdb.execute('set debug-file-directory %s/usr/lib/debug' % sysroot) |
| 408 | gdb.execute('set solib-search-path out_%s/Release/lib' % os.environ['SDK_BOARD']) # Or "Debug" for a debug build |
| 409 | gdb.execute('target remote 12.34.56.78:1234') |
| 410 | ``` |
| 411 | |
| 412 | If you wish, after you connect, you can Ctrl-D out of the Python shell. |
| 413 | |
| 414 | Extra debugging instructions are located at http://www.chromium.org/chromium-os/how-tos-and-troubleshooting/debugging-tips. |
| 415 | |
| 416 | ## Additional instructions |
| 417 | |
| 418 | ### Updating the version of the Chrome OS SDK |
| 419 | |
| 420 | When you invoke `cros chrome-sdk`, the script fetches the version of the SDK |
| 421 | that corresponds to your Chrome checkout. To update the SDK, sync your Chrome |
| 422 | checkout and re-run `cros chrome-sdk`. |
| 423 | |
| 424 | **IMPORTANT NOTES:** |
| 425 | |
| 426 | * Every time that you update Chrome or the Chrome OS SDK, it is possible that |
| 427 | Chrome may start depending on new features from a new Chrome OS image. This |
| 428 | can cause unexpected problems, so it is important to update your image |
| 429 | regularly. Instructions for updating your Chrome OS image are above in |
| 430 | [Set Up the Chromium OS device]. |
| 431 | * Don't forget to re-configure your build directories (See |
Satoru Takabayashi | 7cc76c9 | 2017-06-26 04:46:05 | [diff] [blame] | 432 | **Configure a build directory** section above) |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 433 | |
| 434 | ### Specifying the version of the Chrome OS SDK to use |
| 435 | |
| 436 | You can specify a version of Chrome OS to build against. This is handy for |
| 437 | tracking down when a particular bug was introduced. |
| 438 | |
| 439 | ``` |
| 440 | (outside) cros chrome-sdk --board=$BOARD --version=3680.0.0 |
| 441 | ``` |
| 442 | |
| 443 | Once you are finished testing the old version of the chrome-sdk, you can always start a new shell with the latest version again. Here's an example: |
| 444 | |
| 445 | ``` |
| 446 | (outside) cros chrome-sdk --board=$BOARD |
| 447 | ``` |
| 448 | |
| 449 | ### Updating Chrome |
| 450 | |
| 451 | **Tip:** If you update Chrome inside the chrome-sdk, you may then be using an SDK |
| 452 | that is out of date with the current Chrome. |
| 453 | See **Updating the version of the Chrome OS SDK** section above. |
| 454 | |
| 455 | ``` |
| 456 | (inside) git rebase-update |
| 457 | (inside) gclient sync |
| 458 | ``` |
| 459 | |
| 460 | ### Updating Deployed Files |
| 461 | |
| 462 | Since the gyp files don't define which targets get installed, that information |
| 463 | is maintained in the [chromite repo] as part of Chromium OS. That repo is also |
| 464 | integrated into the Chromium source tree via the `DEPS` file. |
| 465 | |
| 466 | In order to add/remove a file from the installed list: |
| 467 | |
| 468 | 1. Go into the chromite directory and modify `lib/chrome_util.py` |
| 469 | 1. Look for the `_COPY_PATHS` list |
| 470 | 2. Add your new file with optional=True |
| 471 | 2. Commit your change locally using git |
| 472 | 3. Upload your change to gerrit<br> |
| 473 | `git push origin master:refs/for/master` |
| 474 | 4. Get it reviewed by someone on the Chromium OS build team |
| 475 | (e-mail chromium-os-dev@ if you can't find anyone) |
| 476 | 5. Merge the change into Chromium OS via gerrit |
| 477 | 6. Update the DEPS file in Chromium to use the new chromite sha1 |
Satoru Takabayashi | 7cc76c9 | 2017-06-26 04:46:05 | [diff] [blame] | 478 | 7. Check in the Chromium change like normal |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 479 | 8. Once everything has settled, then go back and remove the `optional=True` |
| 480 | from the file list<br> |
| 481 | Unless the file is actually optional, then keep it |
| 482 | |
James Cook | ba126f1 | 2017-08-21 19:59:07 | [diff] [blame] | 483 | ### Using a custom Chromium OS build from your Chromium OS chroot (optional) |
| 484 | |
| 485 | If you are making changes to Chromium OS and have a Chromium OS build inside a |
| 486 | chroot that you want to build against, run `cros chrome-sdk` with the `--chroot` |
| 487 | option. |
| 488 | |
| 489 | ``` |
| 490 | (outside) cros chrome-sdk --board=$BOARD --chroot=/path/to/chromiumos/chroot |
| 491 | ``` |
| 492 | |
| 493 | ### Flashing an image to USB using dd |
| 494 | |
| 495 | In the below command, the X in sdX is the path to your usb key, and you can use |
| 496 | dmesg to figure out the right path (it'll show when you plug it in). Make sure |
| 497 | that the USB stick is not mounted before running this. You might have to turn |
| 498 | off automounting in your operating system. |
| 499 | |
| 500 | ``` |
| 501 | (inside) sudo dd if=chromiumos_test_image.bin of=/dev/sdX bs=1G |
| 502 | ``` |
| 503 | |
| 504 | Be careful - you don't want to have `dd` write over your root partition! |
| 505 | |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 506 | ### Using cros flash with xbuddy to download images |
| 507 | |
| 508 | `cros flash` with `xbuddy` will automatically download an image and write it to |
| 509 | USB for you. It's very convenient, but for now it requires a full Chrome OS |
| 510 | checkout and must be run inside the Chrome OS chroot. ([issue 437877]) |
| 511 | |
| 512 | ``` |
Satoru Takabayashi | e0af9cb | 2017-06-23 05:26:08 | [diff] [blame] | 513 | (chroot) cros flash usb:// xbuddy://remote/$BOARD/<version>/test |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 514 | ``` |
| 515 | |
| 516 | Replace `$BOARD` and `<version>` with the right values. Both can be seen in your |
| 517 | SDK prompt (e.g. `(sdk lumpy R27-3789.0.0)` is the lumpy board using version |
| 518 | R27-3789.0.0). |
| 519 | |
| 520 | See the [Cros Flash page] for more details. |
| 521 | |
| 522 | ### Setting a custom prompt (optional) |
| 523 | |
| 524 | By default, cros chrome-sdk prepends something like '`(sdk link R52-8315.0.0)`' |
Satoru Takabayashi | 7cc76c9 | 2017-06-26 04:46:05 | [diff] [blame] | 525 | to the prompt (with the version of the prebuilt system being used). |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 526 | |
| 527 | If you prefer to colorize the prompt, you can set `PS1` in |
| 528 | `~/.chromite/chrome_sdk.bashrc`, e.g. to prepend a yellow '`(sdk link 8315.0.0)`' |
| 529 | to the prompt: |
| 530 | |
| 531 | ``` |
| 532 | PS1='\[\033[01;33m\](sdk ${SDK_BOARD} ${SDK_VERSION})\[\033[00m\] \w \[\033[01;36m\]$(__git_ps1 "(%s)")\[\033[00m\] \$ ' |
| 533 | ``` |
| 534 | NOTE: Currently the release version (e.g. 52) is not available as an environment variable. |
| 535 | |
James Cook | ba126f1 | 2017-08-21 19:59:07 | [diff] [blame] | 536 | ### GYP |
| 537 | |
| 538 | The legacy `GYP` build system is no longer supported. You don't need |
| 539 | `gclient runhooks` any more. |
| 540 | |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 541 | [instructions in the development guide]: https://www.chromium.org/chromium-os/developer-guide#TOC-Making-changes-to-the-Chromium-web- |
James Cook | ba126f1 | 2017-08-21 19:59:07 | [diff] [blame] | 542 | [Local copy of the Chromium source code and depot_tools]: https://chromium.googlesource.com/chromium/src/+/master/docs/linux_build_instructions.md |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 543 | [Chromium OS board name]: http://www.chromium.org/chromium-os/developer-information-for-chrome-os-devices |
| 544 | [GN build configuration]: http://www.chromium.org/developers/gn-build-configuration |
| 545 | [quick start guide]: https://chromium.googlesource.com/chromium/src/+/master/tools/gn/docs/quick_start.md |
James Cook | 3d13538 | 2017-10-16 16:58:01 | [diff] [blame] | 546 | [device-specific instructions]: https://www.chromium.org/chromium-os/developer-information-for-chrome-os-devices |
| 547 | [generic instructions]: https://www.chromium.org/a/chromium.org/dev/chromium-os/developer-information-for-chrome-os-devices/generic |
Satoru Takabayashi | eef6f59 | 2017-06-23 04:16:36 | [diff] [blame] | 548 | [rootfs has been removed]: https://www.chromium.org/chromium-os/poking-around-your-chrome-os-device#TOC-Making-changes-to-the-filesystem |
| 549 | [remounted as read-write]: http://www.chromium.org/chromium-os/how-tos-and-troubleshooting/debugging-tips#TOC-Setting-up-the-device |
| 550 | [additional debugging tips]: http://www.chromium.org/chromium-os/how-tos-and-troubleshooting/debugging-tips#TOC-Enabling-core-dumps |
| 551 | [Set Up the Chromium OS device]: http://www.chromium.org/chromium-os/how-tos-and-troubleshooting/building-chromium-browser#TOC-Set-up-the-Chromium-OS-device |
| 552 | [chromite repo]: https://chromium.googlesource.com/chromiumos/chromite/ |
| 553 | [issue 437877]: https://bugs.chromium.org/p/chromium/issues/detail?id=403086 |
| 554 | [Cros Flash page]: http://www.chromium.org/chromium-os/build/cros-flash |