Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1136162
  • 博文数量: 276
  • 博客积分: 8317
  • 博客等级: 少将
  • 技术积分: 2329
  • 用 户 组: 普通用户
  • 注册时间: 2006-09-12 08:17
个人简介

http://ads.buzzcity.net/adpage.php?partnerid=40096

文章分类

全部博文(276)

文章存档

2013年(1)

2012年(38)

2011年(102)

2010年(85)

2009年(45)

2008年(5)

分类: 嵌入式

2011-05-18 12:51:09

Chromium OS Developer Guide

目录

  1. 1 Introduction
    1. 1.1 Target audience
    2. 1.2 Organization & content
    3. 1.3 Typography conventions
    4. 1.4 Modifying this document
    5. 1.5 Additional information
  2. 2 Preliminary requirements
  3. 3 Getting the source code
    1. 3.1 Install depot_tools
    2. 3.2 Install git
    3. 3.3 Configure git
    4. 3.4 Preparations if you are committer
    5. 3.5 Double-check that you are running a 64-bit architecture
    6. 3.6 Decide where your source will live
    7. 3.7 Decide if you want the minilayout
    8. 3.8 Get the source code
  4. 4 Building Chromium OS
    1. 4.1 Create a chroot
    2. 4.2 Enter the chroot
    3. 4.3 Select a board
    4. 4.4 Initialize the build for a board
    5. 4.5 Set the chronos user password
    6. 4.6 Build the packages for your board
    7. 4.7 Build a disk image for your board
    8. 4.8 Look at your disk image (optional)
  5. 5 Running your image
    1. 5.1 Getting your image running on a computer without verified boot
    2. 5.2 Getting your image running on a Chrome OS Notebook
    3. 5.3 Build your own recovery image
    4. 5.4 Getting to a command prompt on Chromium OS
    5. 5.5 Installing your Chromium OS image to your hard disk
    6. 5.6 Building an image to run in a virtual machine
  6. 6 Making changes to packages whose source code is checked into Chromium OS git repositories
    1. 6.1 Keep the tree green
    2. 6.2 Run cros_workon start
    3. 6.3 Run repo sync
    4. 6.4 Figure out where the ebuild / source code for the project is located
    5. 6.5 Create a branch for your changes
    6. 6.6 Make your changes
    7. 6.7 Set your editor
    8. 6.8 Submit changes locally
    9. 6.9 Upload your changes and get a code review
    10. 6.10 Try seeing the mainline again
    11. 6.11 Work on something else while you're waiting
    12. 6.12 Push your changes
    13. 6.13 Make sure your changes didn't break things
    14. 6.14 (Non-committers) Submit your changes
    15. 6.15 Clean up after you're done with your changes
  7. 7 Making changes to non-cros_workon-able packages
    1. 7.1 Making changes to the way that the chroot is constructed
    2. 7.2 Building an individual package
    3. 7.3 Making changes to the Chromium web browser on Chromium OS
  8. 8 Troubleshooting
    1. 8.1 My build is failing, what's the problem?
    2. 8.2 How do I fix network problems in the chroot?
    3. 8.3 I lost my developer tools on the stateful partition, can I get them back?
  9. 9 Running Tests
    1. 9.1 Getting an image that has been modified for test
    2. 9.2 Creating a recovery image that has been modified for test
    3. 9.3 Creating a new test
    4. 9.4 Seeing which tests are implemented by an ebuild
    5. 9.5 Additional testing information
  10. 10 Additional information
    1. 10.1 Developer mode
    2. 10.2 Attribution requirements
    3. 10.3 Documentation on this site
    4. 10.4 External documentation
Introduction
This guide describes how to work on Chromium OS. If you want to help develop Chromium OS and you're looking for information about how to get started, you're in the right place.
Target audience
The target audience of this guide is anyone who wants to obtain, build, or contribute to Chromium OS. That includes new developers who are interested in the project and who simply want to browse through the Chromium OS code, as well as developers who have been working on Chromium OS for a long time.
Organization & content
This guide describes the common tasks required to develop Chromium OS. The guide is organized linearly, so that developers who are new to Chromium OS can follow the tasks in sequence. The tasks are grouped into the following sections:
Typography conventions
  • Paths, files, and commands are shown in different colors to indicate whether they apply to (1) your build computer (the computer on which you're doing development), (2) the chroot on your build computer, or (3) your Chromium OS computer (the device on which you run the images you build):
  • Color Paths, files, and commands:
    green text on your build computer
    purple text inside the chroot on your build computer
    crimson text on your Chromium OS computer
  • Notes are shown using the following conventions:
    • IMPORTANT NOTE describes required actions and critical information
    • SIDE NOTE describes explanations, related information, and alternative options
    • TODO describes questions or work that is needed on this document
Modifying this document
Only people with @chromium.org accounts can edit this document. Everyone else should post to the Chromium OS dev group.
If you're a Chromium OS developer, YOU SHOULD UPDATE THIS DOCUMENT and fix things as appropriate.  There's a "Sign In" text button at the very bottom of this page.  Sign in (with your @chromium.org account, of course) and you'll get an "Edit" button at the top of the page.  Bias towards action: 
  • If you see a red TODO and you know the right answer, fix it!
  • If you see something wrong, fix it. 
  • If you're not sure of the perfect answer, still fix it.   Stick in a red TODO noting your uncertainty if you aren't sure, but  don't let anything you know to be wrong stick around.
Please try to abide by the following guidelines when you modify this document:
  • Put all general "getting started" information directly on this page. It's OK if this document grows big.
  • If some information is also relevant for other documents, put the information in this document and add links from the other documents to this document. If you do not have a choice and must put information relevant to getting started in other documents, add links in this document to discrete chunks of information in the other documents. Following a web of links can be very confusing, especially for people who are new to a project, so it's very important to maintain a linear flow as much as possible.
  • Where possible, describe a single way of doing things. If you specify multiple options, provide a clear explanation why someone following the instructions would pick one option over the others. If there is disagreement about how to do things, consider listing alternative options in a SIDE NOTE.
  • Keep Google-specific references to a minimum. A large number of the people working on Chromium OS work at Google, and this document may occasionally contain references that are only relevant to engineers at Google. Google engineers, please keep such references to a minimum – Chromium OS is an open source project that should stay as open as possible.
Additional information
This document provides an overview of the tasks required to develop Chromium OS. After you've learned the basics, check out the links in the additional information section at the end of this document for tips and tricks, FAQs, and important details (e.g., the Chromium OS directory structure, using the dev server, etc.).

Finally, if you build a Chromium OS image, please read this important note about attribution requirements.


Preliminary requirements
You must have Linux to develop Chromium OS. Specifically, the supported environment is:
  •  Linux (version 10.04 - Lucid)
  • Most developers working on Chromium OS are using Lucid (the LTS version of Ubuntu) and will not be updating to 10.10. It is possible that things will work if you're running a different Linux distribution, but you will probably find life easier if you're on Lucid. Please note that Ubuntu 9.10 (Karmic) is known not to work.
  • a 64-bit system for performing the build
  • 32-bit systems may be supported down the road.
  • an account with sudo access
  • You need root access to run the chroot command and to modify the mount table. NOTE: Do not run any of the commands listed in this document as root – the commands themselves will run sudo to get root access when needed.
You will have a much nicer time if you also have:
  • a fast multi-processor machine with lots of memory
  • The build system is optimized to make good use of all processors, and an 8 core machine will build nearly 8x faster than a single core machine. If you are building the full Chromium OS including Chrome (the browser), your machine should have at least 4GB of RAM, and 8GB is better. If you only have 4GB of RAM make sure you have at least 4GB of swap. There have been reports of even getting by with 2GB of RAM on a Linux box not running a GUI.
  • a good Internet connection
  • This will help for the initial download (minimum of about 2GB) and any further updates.
You must also install the following Ubuntu and Google packages to develop Chromium OS (installation instructions are provided below):
  • git - source control client
  • keychain - ssh key management (for committers)
  • depot_tools - Google-maintained set of tools used by Chromium OS


Getting the source code
Install depot_tools
To get started, follow the instructions at install depot_tools. This step is required so that you can use the repo command to get/sync the source code.

Install git
Install the git revision control system. On Ubuntu, the magic incantation to do this is:

sudo aptitude install git-core gitk git-gui

This command also installs git's graphical front end (git gui) and revision history browser (gitk).

Configure git
Setup git now. If you don't do this, you may run into errors/issues later.  Replace you@example.com and Your Name with your information:

git config --global user.email "you@example.com"
git config --global user.name "Your Name"


Preparations if you are committer
IMPORTANT NOTE: If you are new to Chromium OS, you are NOT a committer. Skip this step (go to "decide where your source will live"). Feel free to revisit this step if/when you .
Create your ssh key Committers access the git repositories through an ssh connection, which means you need to setup an ssh key. Create a key using ssh-keygen. You will be asked for a password – please create one in order to protect your key. Don't worry, with the keychain program (see below) you won't need to enter this password very often.

ssh-keygen -t rsa -f ~/.ssh/chromium
Submit your public key to the gitmaster
You must submit the public key that was generated (in ~/.ssh/chromium.pub) to the Chromium OS gitmaster and wait until this key is accepted. Whoever approved you as a committer should have given you instructions on how to do this. They are purposely not listed here to avoid lots of spamming of the gitmaster.
Automate usage of your key with keychain
You should protect your chromium ssh key with a password, but of course you don't want to type that password all the time.  This is where the keychain command can help you.  

On Ubuntu, install keychain with this command (assumes apt is configured with universe):

sudo aptitude install keychain

To use the keychain command, add this to the end of your ~/.bashrc file:

eval `keychain --eval ~/.ssh/chromium`

Run the above keychain command now so that your current terminal will have access.

SIDE NOTES:
  • The keychain command is really just a wrapper around ssh-agent.  You could use ssh-agent directly, but the instructions for how to use ssh-agent are more complicated and thus don't belong here. If you're passionate about ssh-agent, feel free to make a sub-page about how to use ssh-agent instead of keychain.
  • People wonder why these instructions tell you to password-protect your key, then turn around and tell you how to avoid entering the password. The thing to note is that keychain keeps the decrypted version of your ssh key only in RAM (hopefully in protected memory). RAM is more secure than disk storage, since someone who has physical access to your machine can access the disk without your password (by rebooting from a CD-based Linux distribution), but cannot access the RAM so easily.

Double-check that you are running a 64-bit architecture

Run the following command:

uname -m

You should see the result: x86_64

If you see something else (for example, i686, which means you are on a 32-bit machine or a 64-bit machine running a 32-bit OS) then you won't be able to build Chromium OS.  The project would happily welcome patches to fix this.

Decide where your source will live
Chromium OS developers commonly put their source code in ${HOME}/chromiumos. If you feel strongly, put your own source elsewhere, but note that all commands in this document assume that your source code is in ${HOME}/chromiumos.

Create the directory for your source code with this command:

mkdir -p ${HOME}/chromiumos

IMPORTANT NOTE: If your home directory is on NFS (as is true for engineers at Google), you must place your code somewhere else. Not only is it a bad idea to build directly from NFS for performance reasons, but builds won't actually work (builds use sudo, and root doesn't have access to your NFS mount, unless your NFS server has the no_root_squash option). Wherever you place your source, you can still add a symbolic link to it from your home directory (this is suggested), like so:

mkdir -p /usr/local/path/to/source/chromiumos
ln -s /usr/local/path/to/source/chromiumos ${HOME}/chromiumos

SIDE NOTE: There were some suggestions about putting the source in ${HOME}/trunk (and the instructions suggested this for a while).  Having the source in ${HOME}/trunk allows you to have some sloppiness later (you can enter the same commands inside the build chroot and outside).  Though this is convenient, it is dangerous because it might lead to you to submit a change to a build script that works on your machine, but that doesn't work on other machines (where the source code is not in ${HOME}/trunk).

Decide if you want the minilayout

Before you get the source code, you must decide whether you want to the "minilayout" or the "full layout:"

  • The minilayout starts you out with the minimum amount of source code (you can hand-pick additional source code later with cros_workon).
  • The full layout gets you all the Chromium OS-related source code on your hard disk.
You should probably pick the full layout if:
  • You think you might want to grep through the source code to help you get oriented.  
    • Note: This is not as important as you think, since you can always use the  to search the full code.
  • You just like to have all of the source you can.
  • You've got lots of extra disk space.
  • You've got a fast network connection.
    • Note: Not only will the first sync be very slow, but even subsequent syncs will be slow.
You should probably pick the minilayout if:
  • You have a slow network connection or a small hard disk.
  • You will probably only work on a few packages.
  • You would prefer your syncs to be quick.
  • You don't mind waiting a little longer for the first sync when you start working on a package you haven't worked on before.
Remember: Even if you choose the minilayout, you can still hand pick packages whose source code you want later by using cros_workon.

Get the source code
Chromium OS uses to sync down source code. repo is effectively a wrapper for the  that helps deal with a large number of git repositories. You already installed repo when you installed depot_tools above.

Add the host keys to your known hosts file:
Both of the options below run SSH in a noninteractive shell, which makes accepting their host keys tricky; you won't be able to type "yes" to tell SSH that the key is OK.   You can do this step by manually SSHing to the hosts first:
ssh -p 29418 gerrit.chromium.org
You won't be able to log in to either host, but you'll have an opportunity to add the host keys.

Alternately, you can paste this into your .ssh/known_hosts:
[gerrit.chromium.org]:29418 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQCfRn+J+e9mU0c4bxFD8v2rhhd3O9WPk435xEtG9FD8a8fOnIubJcpObvQJhfSgYkxVUQOKk97V8b2eGjf72AGBhDQVJMiaLQc8ZGomeNlK/7cWjkJFDoIKQHilHQidz/pgZc/Pu+7Tl2emVGd6425QRK1h47CYtT9IUPt3Jtdv4w==

Once the keys are added to your known_hosts file, choose one of the options below.

Option #1: If you want a copy of the minilayout, enter the following commands:

cd ${HOME}/chromiumos
repo init -u -m minilayout.xml
repo sync

Option #2: If you want a copy of the full layout, enter the following commands:

cd ${HOME}/chromiumos
repo init -u
repo sync

Googlers: See for internal notes.

SIDE NOTES:
  • If you want to build on a branch, pass the branch name to repo init (e.g: repo init -u [-m minilayout.xml] -b 0.9.94.T).
When you use repo init you will be asked to confirm your name, email address, and whether you want color in your terminal. This command runs quickly. The repo sync command takes a lot longer. 
Building Chromium OS
Create a chroot
To make sure everyone uses the same exact environment and tools to build Chromium OS, all building is done inside a .  This chroot is its own little world: it contains its own compiler, its own tools (its own copy of bash, it's own copy of sudo), etc.. Now that you've synced down the source code, you need to create this chroot. Assuming you're already in ${HOME}/chromiumos (or wherever your source lives), the commands to setup the chroot are:

cd src/scripts
./make_chroot

This command takes about half an hour to run on a four core machine. It compiles quite a bit of software, which it installs into your chroot, and downloads some additional items (around 300MB). While it is building you will see a regular update of the number of packages left to build. Once the command finishes, the chroot will take up total disk space of a little over 3GB.

The chroot lives at ${HOME}/chromiumos/chroot. Inside that directory you will find system directories like /usr/bin and /etc. These are local to the chroot and are separate from the system directories on your machine. For example, the chroot has its own version of the ls utility. It will be very similar, but it is actually a different binary than the normal one you use on your machine.

SIDE NOTES:
  • You shouldn't have to create the chroot very often. Most developers create it once and never touch it again unless someone explicitly sends out an email telling them to recreate their chroot. Recreating a chroot can be very disruptive to developers and doesn't happen very often.
  • If you've already got a chroot when you run make_chroot, the command will attempt to "update" your existing chroot. This works reasonably well in most cases. However, if you really want to force a clean chroot to be built, pass the --replace flag to make_chroot. This flag will delete any old chroot that might have been present, before re-creating a new one.
  • The make_chroot command currently doesn't work behind a proxy server, but there is a .

Enter the chroot
Most of the commands that Chromium OS developers use on a day-to-day basis (including the commands to build a Chromium OS image) expect to be run from within the chroot. You can enter the chroot by using one of the commands in the src/scripts directory:

./enter_chroot.sh

This command will probably prompt you for your password for the sudo command (entering the chroot requires root privileges). Once the command finishes, that terminal is in the chroot and you'll be in the ~/trunk/src/scripts directory, where most build commands live. In the chroot you can only see a subset of the filesystem on your machine. However, through some trickery (bind mounts), you will have access to the whole src directory from within the chroot – this is so that you can build the software within the chroot.

Note in particular that the src/scripts directory is the same src/scripts directory as you were in before you entered the chroot, even though it looks like a different location. That's because when you enter the chroot, the ~/trunk directory in the chroot is mounted such that it points to the main Chromium OS directory ${HOME}/chromiumos. That means that changes that you make to the source code outside of the chroot immediately take effect inside the chroot.

While in the chroot you will see a special "(cros-chroot)" prompt to remind you that you are there:

(cros-chroot) johnnyrotten@flyingkite ~/trunk/src/scripts $ 

You cannot run programs on your filesystem from within the chroot. For example, if you are using eclipse as an IDE, or gedit to edit a text file, you will need to run those programs outside the chroot. As a consolation, you can use vim. If you are desperate for emacs, try typing sudo emerge emacs. Of course this command will build emacs from source so allow 5-10mins.

IMPORTANT NOTES:
  • In this document, commands that are intended to be entered inside the chroot, and paths inside the chroot, are colored purple.
  • If you need to delete your chroot, use ./make_chroot --delete to delete it properly. Using rm -rf could end up deleting your source tree.

SIDE NOTES:
  • You can run some commands from outside the chroot, even if the commands expect to be run inside the chroot. Such commands are smart enough to enter the chroot for the duration of the command.
  • If you need to share lots of files inside and outside chroot (for example, settings for your favorite editor / tools, or files downloaded by browser outside chroot, etc.), read Tips and Tricks.
  • There is a file system loop because inside ~/trunk you will find the chroot again. Don't think about this for too long. If you try to use du -s ${HOME}/chromiumos/chroot/home you might get a message about a corrupted file system. This is nothing to worry about, and just means that your computer doesn't understand this loop either. (If you can understand this loop, try .)

Select a boardBuilding Chromium OS produces a disk image (usually just called an "image") that can be copied directly onto the boot disk of a computer intended to run Chromium OS.  Depending on the specifics of that computer, you may want different files in the disk image. For example, if your computer has an ARM processor, you'll want to make sure that all executables in the image are compiled for the ARM instruction set. Similarly, if your computer has special hardware, you'll want to include a matching set of device drivers.
Different classes of computers are referred to by Chromium OS as different target "boards."  The following are some example boards:
  • x86-generic - builds a generic image suitable for computers with a x86-compatible CPU
  • arm-generic - builds a generic image suitable for computers with an ARM CPU
You need to choose a board for your first build. Don't worry too much about this choice – you can always build for another board later. If you want a list of known boards, you can look in ~/trunk/src/overlays.

Each command in the build processes takes a --board parameter.  To facilitate this, it can be helpful to keep the name of the board in a shell variable. This is not strictly necessary, but if you do this, you can simply copy and paste the commands below into your terminal program. Enter the following inside your chroot (note: change x86-generic to whatever board you want to build for):

BOARD=x86-generic

This setting only holds while you stay in the chroot. If you leave and come back, you need to do specify this setting again.

Initialize the build for a board
To start building for a given board, issue the following command inside your chroot (you should be in the ~/trunk/src/scripts directory):

./setup_board --board=${BOARD}

This command sets up the board target with a default sysroot of /build/${BOARD}. The command downloads a small amount of stuff and takes a few minutes to complete.


SIDE NOTES:
  • If you pass the --default flag to setup_board, the command writes the board name in the file ~/trunk/src/scripts/.default_board (it does the same thing as echo ${BOARD} > ~/trunk/src/scripts/.default_board). This makes it so that you don't need to specify a --board argument to subsequent commands. These instructions do not use the --default flag so that you can explicitly see what commands are board-specific.
  • If you have previously set up this board, the setup_board command will fail. If you really want to clobber your old board files and start fresh, try passing the --force flag, which deletes the old /build/${BOARD} directory for you. Like make_chroot.sh, most people only re-run setup_board when told to (they don't re-run it even after a repo sync).
  • You can delete the board sysroot at any time with: sudo rm -rf /build/${BOARD}.

Set the chronos user password
On a Chromium OS computer, you can get command line access (and root access through the sudo command) by logging in with the shared user account "chronos".  You should set a password for the chronos user by entering the command below from inside the ~/trunk/src/scripts directory:

./set_shared_user_password.sh

You will be prompted for a password, which will be stored in encrypted form in /etc/shared_user_password.txt

SIDE NOTES:
  • The encrypted password is stored inside chroot. That means that if you recreate your chroot, you have to run this command again.
  • If you don't set a shared user password, the password for the chronos account may end up being any number of things depending on some complicated (and constantly evolving) formula that includes whether you build a developer image, whether you boot into developer mode, and the current state of the scripts.  The password might be empty, or a well-known string, or it might be impossible to login with chronos.  It is strongly recommended that you simply set a shared user password.  TODO: put a link to some place with more info about this.

Build the packages for your board
To build all the packages for your board, run the following command from inside the ~/trunk/src/scripts directory:

./build_packages --board=${BOARD} --oldchromebinary

This step is the rough equivalent of make all in a standard Makefile system.  This command handles incremental builds; you should run it whenever you change something and need to rebuild it (or after you run repo sync). 

Normally, the build_packages command builds the stable version of a package (i.e., from committed git sources), unless you are working on a package (with cros_workon). If you are working on a package, build_packages will build using your local sources. See below for information about cros_workon.


SIDE NOTES:
  • The --oldchromebinary flag is not strictly necessary, but it will make your build faster in some rare instances (when the Chrome/Chromium browser has recently been revved), at the cost of a slightly older version of Chrome/Chromium.  This flag may become the default in the future.
  • Even though there are some flags that can optimize your build (like --nowithdev, --nowithautotest, etc), you should not use these flags (even if you don't plan on building a developer / test image). There are some that can cause some hard-to-debug differences if you use one of these flags.
  • The first time you run the build_packages command, it will take a long time (around 90 minutes on a four core machine), as it must build every package, and also download about 1.7GB of source packages and 1.3GB of binary packages. for more information about what the build_packages command actually does. In short, it tries to download existing binary packages to avoid building anything (and puts them in/build/${BOARD}/packages for subsequent builds). Failing that, it downloads source packages, puts them in /var/lib/portage/distfiles-target, and builds them.

Build a disk image for your board
Once the build_packages step is finished, you can make an image by running the command below from inside the ~/trunk/src/scripts directory:

./build_image --board=${BOARD} --withdev --noenable_rootfs_verification

This command creates an image with developer tools that allow you to freely modify the root file system. The image that is produced will not be a secure version of Chromium OS, but will give you fairly liberal access. If you would like a more secure, locked-down version of Chromium OS, you should leave off the --withdev and --noenable_rootfs_verification options.

The image produced by build_image will be located in ~/trunk/src/build/images/${BOARD}/versionNum/ (where versionNum will actually be a version number).  The most recent image produced for a given board will be symlinked to ~/trunk/src/build/images/${BOARD}/latest.

IMPORTANT NOTE: It's up to you to delete old builds that you don't need. Every time you run build_image, the command creates files that take up over 4GB of space(!).

Look at your disk image (optional)
If you want, you can look at the rootfs of the disk image that you just created by using the following commands:

cd ~/trunk/src/build/images/${BOARD}/latest
./unpack_partitions.sh chromiumos_image.bin
mkdir -p rootfs
sudo mount -o loop part_3 rootfs

This will do a loopback mount of the rootfs from your image to the location ~/trunk/src/build/images/${BOARD}/latest/rootfs in your chroot.

If you built an x86 Chromium OS image, you can probably even try chrooting into the image:

sudo chroot ~/trunk/src/build/images/${BOARD}/latest/rootfs

This is a little hacky (the Chromium OS rootfs isn't really designed to be a chroot for your host machine), but it seems to work pretty well. Don't forget to exit this chroot when you're done.

When you're done, unmount the root filesystem:

sudo umount ~/trunk/src/build/images/${BOARD}/latest/rootfs 

If you don't want to unpack the partitions (which takes up extra disk space), you can also mount directly without unpacking:

cd ~/trunk/src/build/images/${BOARD}/latest
ROOTA_START=`grep 'ROOT-A' unpack_partitions.sh | awk '{print $2;}'`
mkdir -p rootfs
sudo mount -o loop,offset=$((512 * ${ROOTA_START})) chromiumos_image.bin rootfs

Again, don't forget to unmount the root filesystem when you're done:

sudo umount ~/trunk/src/build/images/${BOARD}/latest/rootfs 

TODO: I think most/all of the above is handled in src/scripts/mount_gpt_image.sh.  Rewrite the above using that script.


Running your image
Getting your image running on a computer without verified boot
If you are trying to run your image on a normal computer, laptop, or netbook (one that didn't come installed with Google Chrome OS), follow the instructions in this section. Said another way:

This section is NOT for use on the Google Cr-48 Notebook. See below if you have a Cr-48 Notebook.
Put your image on a USB disk
The easiest way to get your image running on your target computer is to put the image on a USB flash disk (sometimes called a USB key), and boot the target computer from the flash disk. The first step is to insert a USB flash disk (4GB or bigger) into your build computer. This disk will be completely erased, so make sure it doesn't have anything important on it.  Wait ~10 seconds for the USB disk to register, then type the following command in the ~/trunk/src/scripts directory:

./image_to_usb.sh --board=${BOARD}

Since you didn't pass a --to parameter, the image_to_usb.sh command lists all the USB disks that it finds.  If your USB disk is not listed, wait a few seconds and try the command again. Note that your USB disk may show up as something like /dev/sdc. Once the command finds your USB disk, run the command again with the --to parameter (you should replace ${MY_USB_KEY_LOCATION} with the location for your disk, like /dev/sdc):

./image_to_usb.sh --board=${BOARD} --to=${MY_USB_KEY_LOCATION}

When the image_to_usb.sh command finishes, you can simply unplug your USB key and it's ready to boot from.

IMPORTANT NOTE: To emphasize again, image_to_usb.sh completely replaces the contents of your USB disk. Make sure there is nothing important on your USB disk before you run this command.

SIDE NOTES:
  • By default, image_to_usb.sh uses the latest image for the given board. If you want to use an image from a different directory, you can specify the directory with the --from flag.
  • If you want to create a test image (used for allowing Chromium OS to talk to autotest), see the Running Tests section.
Boot from your USB disk
You should be able to configure your target computer's BIOS to boot from your USB key. After you've done that, simply plug in your newly minted USB key and reboot your target computer – it should now boot from the Chromium OS image on your USB key. Your Chromium OS image may not have all the drivers to run all of the peripherals on your computer, but it should at least boot.

For specific information about what works on various different machines, see the Developer Hardware page.


Getting your image running on a Chrome OS Notebook
Follow the instructions in this section if you are trying to get your image running on a system has an official Chrome OS BIOS; eg, the . Said another way:

Use the previous section for a normal computer. This section is ONLY for use on computers that have an official Google Chrome OS BIOS such as the .
A quick primer on verified boot
You must understand a bit about verified boot before you can go any further. Unless you crack open the hardware on your notebook (which probably voids any warranty you might have), having a computer with verified boot means:
  • You can only boot from a USB disk if the boot image on the USB disk has been signed by the "recovery key" for your device. Since the recovery key is tightly controlled, that means you'll need to obtain a Recovery Kernel built and signed by a person with access to the key (like your hardware manufacturer).
  • If your device is in "release mode":
    • You can only boot from the internal SSD if the boot image on the SSD has been signed by the "release key". The release key is also tightly controlled, so that means devices in "release" mode can only boot official images.
  • If your device is in "developer mode":
    • You can boot any self-signed image from the internal SSD.
If you're quick, then you've probably figured out that one way to boot your image on your device is:
  1. Switch your device to Developer Mode.
  2. Use an officially-signed Recovery Kernel for your device to flash your self-signed image onto the device's SSD.
Let's go through that one step at a time.
Get your Chrome OS Notebook into Developer Mode
This is different for each computer, but it usually involves flipping a switch that's under the battery (and sometimes also under a sticker).  You'll want to reference the documentation for your Chrome OS Notebook.

SIDE NOTE: Switching into Developer Mode does a lot of stuff (erasing your stateful partition, disabling some of the checks that make sure you're running official code, etc). See the documentation for your Chrome OS Notebook for details.
Get an officially-signed Recovery Kernel for your Chrome OS Notebook
The recovery key is different for every version of Chrome OS Notebook, which means you'll need to get a different Recovery Kernel for the type of Chrome OS Notebook you have. You might be able to find a link to download a Recovery Kernel in the documentation for your Chrome OS Notebook. If not, you might be able to extract an officially-signed Recovery Kernel from an officially-signed Recovery Image (Recovery Images are sometimes easier to find).

As an example, you can get an officially-signed Recovery Kernel for the  (AKA Mario) by running the steps below from inside the chroot:

curl > ~/trunk/mario_recovery_kernel.zip
unzip -d ~/trunk ~/trunk/mario_recovery_kernel.zip

RECOVERY_KERNEL=~/trunk/mario_recovery_kernel.bin

The instructions below assume that you've set the RECOVERY_KERNEL variable as above.
Build your own recovery image
Now that you have a built image and an officially-signed Recovery Kernel, you can build your own recovery image using mod_image_for_recovery.sh.  This image will have the officially-signed Recovery Kernel (so you can boot from USB) and will install a self-signed SSD image (so you can boot only with developer mode).  Here's the magic set of steps (assuming that you've got a path to the recovery kernel in ${RECOVERY_KERNEL} and that the recovery kernel is a match for the ${BOARD} you built):

./mod_image_for_recovery.sh \
    --board=${BOARD} \
    --nominimize_image \
    --kernel_image ${RECOVERY_KERNEL} \
    --image ~/trunk/src/build/images/${BOARD}/latest/chromiumos_image.bin

SIDE NOTE: If you're interested in creating a test image (used for allowing Chromium OS to talk to autotest), you can use mod_image_for_test.sh to manually modify your image before combining it with the recovery image.  TODO: Document this.
Copy the recovery image to a USB key
The first step is to insert a USB flash disk (4 GB or bigger) into your build computer. This disk will be completely erased, so make sure it doesn't have anything important on it.  Wait ~10 seconds for the USB disk to register, then type the following command in the ~/trunk/src/scripts directory:

./image_to_usb.sh --board=${BOARD}

Since you didn't pass a --to parameter, the image_to_usb.sh command lists all the USB disks that it finds.  If your USB disk is not listed, wait a few seconds and try the command again. Note that your USB disk may show up as something like /dev/sdc. Once the command finds your USB disk, run the command again with the --to parameter (you should replace ${MY_USB_KEY_LOCATION} with the location for your disk, like /dev/sdc):

./image_to_usb.sh --board=${BOARD} --image_name=recovery_image.bin --to=${MY_USB_KEY_LOCATION}

When the image_to_usb.sh command finishes, you can simply unplug your USB key and it's ready to boot from.

IMPORTANT NOTE: To emphasize again, image_to_usb.sh completely replaces the contents of your USB disk. Make sure there is nothing important on your USB disk before you run this command.

SIDE NOTES:
  • By default, image_to_usb.sh uses the latest image for the given board. If you want to use an image from a different directory, you can specify the directory with the --from flag.
  • If you want to create a test image (used for allowing Chromium OS to talk to autotest), see the Running Tests section.
  • If you inspect the USB flash disk from outside the chroot before running image_to_usb.sh the script will be unable to mount the disk within the chroot.  Simply unmount the disk and try again.
Install your image to the SSD
In developer mode, your Chrome OS Notebook gives you an option to use a recovery image every time the machine boots. To install your recovery image, do the following:
  1. Turn your Chrome OS Notebook off.
  2. Turn it back on.
  3. During the boot warning, press space to enter recovery mode.
  4. Wait until prompted to put your USB disk in.
  5. Put the USB disk in.
  6. Wait while the image is copied to the SSD.
If you reboot now, you'll be booting from your image (you may need to wait past the recovery screen).  Congratulations!

IMPORTANT NOTE: You must stay in Developer Mode to continue booting your image. Since your image was not signed by the release keys (it's self-signed image), it will only boot in Developer Mode. If you want to go back to Release Mode, just copy (/bin/dd) the .bin file that you first extracted from the .zip file above directly to a USB drive, without making any modifications to it.

Getting to a command prompt on Chromium OS
Since you set the shared user password (with set_shared_user_password.sh) when you built your image, you have the ability to login as the chronos user:
  1. After your computer has booted to the Chromium OS login screen, press [ Ctrl ] [ Alt ] [ F2 ] to get a text-based login prompt.
  2. Login with the chronos user and enter the password you set earlier.
Because you built an image with developer tools, you also have an alternate way to get a terminal prompt. The alternate shell is a little nicer (in the very least, it keeps your screen from dimming on you), even if it is a little harder to get to. To use this alternate shell:
  1. Go through the standard Chromium OS login screen (you'll need to setup a network, etc.) and get to the web browser.  It's OK to login as guest.
  2. Press [ Ctrl ] [ Alt ] [ T ] to get the crosh shell.
  3. Use the shell command to get the shell prompt. NOTE: you don't need to enter the chronos password here, though you will still need the password if you want to use the sudo command.

Installing your Chromium OS image to your hard disk
If you followed the set of instructions for a Chrome OS Notebook, the image is already on your hard disk. However, if you booted Chromium OS straight from a USB key, you might want to put your image onto the hard disk.

Once you've booted from your USB key and gotten to the command prompt, you can install your Chromium OS image to the hard disk on your computer with this command:

/usr/sbin/chromeos-install

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

Building an image to run in a virtual machine
Many times it is easier to simply run Chromium OS in a virtual machine like kvm.  You can adapt the previously built Chromium OS image so that it is usable by kvm (which uses qemu images) by entering this command from the ~/trunk/src/scripts directory:

./image_to_vm.sh --board=${BOARD}

This command creates the file ~/trunk/src/build/images/${BOARD}/latest/chromiumos_qemu_image.bin.

SIDE NOTES:
  • If you want to adapt the image for other virtual machines, see the --format=vmware and --format=virtualbox options. [Note: Only KVM/QEMU VM's are actively supported at the moment, other formats may or may not work on a given build]
  • You can specify source/destination paths with the --from and --to parameters.
  • If you're interested in creating a test image (used for allowing Chromium OS to talk to autotest), see the Running Tests section.


Making changes to packages whose source code is checked into Chromium OS git repositories
Keep the tree green
Now that you can build and run Chromium OS, you're ready to start making changes to the code.

Before you start, take a moment to understand Chromium's source management strategy of "keeping the tree green." For the Chromium OS project, keeping the tree green means:
  1. Any new commits should not destabilize the build:
    • Images built from the tree should always have basic functionality working.
    • There may be minor functionality not working, and it may be the case, for example, that you will need to use Terminal to fix or work around some of the problems. 

  2. If you must introduce unstable changes to the tree (which should happen infrequently), you should use parameterization to hide new, unstable functionality behind a flag that's turned off by default. The Chromium OS team leaders may need to develop mechanisms for parameterizing different parts of the system (such as the init script).

  3. Internal "dev channel" releases will be produced directly from the tree, with a quick branch to check-point the release version. Any fixes required for a release will be pulled from the tree, avoiding merges back to tree.
This strategy has many benefits, including avoiding separate build trains for parallel development (and the cost of supporting such development), as well as avoiding large, costly merges from forked branches.

SIDE NOTE: "Keep the tree green" means something a bit different for Chromium OS than for Chromium, which is much further along in its life cycle.
 


The steps in this section describe how to make changes to a Chromium OS package whose source is checked into the Chromium OS source control system. Specifically, this is a package where:
  • The ebuild for the package lives in the src/third_party/chromiumos-overlay or src/overlays/overlay-${BOARD} directories.
  • There is an ebuild for the package that ends with 9999.ebuild.
  • The ebuild inherits from the cros-workon class.
  • The ebuild has a KEYWORD in the ebuild containing this architecture name (like "x86").
You can see a list of all such packages by running the following command from inside the ~/trunk/src/scripts directory:

cros_workon --board=${BOARD} list --all

Run cros_workon start
The first thing you need to do is to mark the package as active. Use the command below, replacing ${PACKAGE_NAME} with your package name (e.g., chromeos-wm):

cros_workon --board=${BOARD} start ${PACKAGE_NAME}

This command:
  • Indicates that you'd like to build the 9999 version of the ebuild instead of the stable, committed version.
  • Indicates that you'd like to build from source every time.
  • If you specified that you wanted the minilayout when you did your repo init, this command adds a clause to your .repo/local_manifest.xml to tell repo to sync down the source code for this package next time you do a repo sync.

Run repo sync
After running cros_workon, sync down the sources. This is critical if you're using the minilayout, but is probably a good idea in any case to make sure that you're working with the latest code (it'll help avoid merge conflicts later).  Run the command below from outside the chroot, anywhere under your~/chromiumos directory:

repo sync

Figure out where the ebuild / source code for the project is located
It can be a little tricky to figure out where the source code and ebuild for your project is located. Luckily, some magic portage commands can help you.

To find out where the ebuild lives:

equery-${BOARD} which ${PACKAGE_NAME}

As an example, for PACKAGE_NAME=chromeos-wm, the above command might display:
    /home/.../trunk/src/third_party/chromiumos-overlay/chromeos-base/chromeos-wm/chromeos-wm-9999.ebuild

SIDE NOTE: If you run the same command without running cros_workon first, you can see the difference:
    /home/.../trunk/src/third_party/chromiumos-overlay/chromeos-base/chromeos-wm/chromeos-wm-0.0.1-r134.ebuild

To find out where the source code lives (and what git repo it's under):

ebuild-${BOARD} `equery-${BOARD} which ${PACKAGE_NAME}` info

Trying this command with PACKAGE_NAME=chromeos-wm, you might see something like:
    CROS_WORKON_SRCDIR="/home/.../trunk/src/platform/window_manager"
    CROS_WORKON_PROJECT="chromiumos/third_party/window_manager"

SIDE NOTE: The shell script below can be interesting/useful if you want to see info about all packages (it's a little slow, though):

ALL_PACKAGES=`cros_workon --board=${BOARD} list --all`
for package in ${ALL_PACKAGES}; do
  ebuildPath=`equery-${BOARD} which ${package}`
  eval `ebuild-${BOARD} "${ebuildPath}" info`
  echo "${package} - $CROS_WORKON_PROJECT - $CROS_WORKON_SRCDIR"
done

Create a branch for your changes
Since Chromium OS uses repo/git, you should always create a local branch whenever you make changes.

You can run the command to create a local branch from outside the chroot (anywhere under your ~/chromiumos directory), or from within the chroot. In the command below, replace ${CROS_WORKON_PROJECT} with the project name you found in the previous step, and replace ${BRANCH_NAME} with a name that is meaningful to you and that describes your changes (nobody else will see this name):

repo start ${BRANCH_NAME} ${CROS_WORKON_PROJECT}

If you want to work on something that is not checked into the Chromium OS tree (e.g., ebuild files in third_party/chromium-overlay), cd to the directory where you want to make your change, and use '.' in place of ${CROS_WORKON_PROJECT}, as shown below:

repo start ${BRANCH_NAME} .

The branch that this creates will be based on the remote branch. If you've made any other local changes, they will not be present in this branch.

Make your changes
You should be able to make your changes to the source code now.  To incrementally compile your changes, use 

./bin/cros_workon_make --board=${BOARD} ${PACKAGE_NAME}

This will build your package inside your source directory.  Change a single file, and it will rebuild only that file and re-link.  If your package contains test binaries, using

./bin/cros_workon_make --board=${BOARD} ${PACKAGE_NAME} --tests

will build and run those binaries as well.  Call cros_workon_make --help to see other options that are supported.

You probably want to get your changes onto your device now.  You can certainly now rebuild an image with build_image and then reimage your device.  ...but you might also want to take a peek at the devserver instructions if you want something a little quicker.

Set your editor
Many of the commands below (in particular git) open up an editor. You probably want to run one of the three commands below depending on your favorite editor. 

If you're not a *nix expert, nano is a reasonable editor:

export EDITOR='nano'

If you love vi:

export EDITOR='vi'

If you love emacs (and don't want an XWindow to open up every time you do something):

export EDITOR='emacs -nw'

You should probably add one of those lines to your .bashrc (or similar file) too.

Submit changes locally
When your changes look good, commit them to your local branch using git. Full documentation of how to use git is beyond the scope of this guide, but you might be able to commit your changes by running something like the command below from the project directory:

git commit -a

The git commit command brings up a text editor. You should describe your changes, save, and exit the editor. Note that the description you provide is only for your own use. When you upload your changes for code review, the repo upload command grabs all of your previous descriptions, and gives you a chance to edit them.

Upload your changes and get a code review
Once your changes are committed locally, upload your changes using repo upload. The repo upload command takes all of the changes that are unmerged and asks them if you want to upload them.  You can specifically say to only look for unmerged changes in your current repo by passing in '.'.  Please note that you must have a Gerrit account before you can upload changes.

repo upload [.|project-name]

Note it important to note that repo uses the Change-Id in your git commits to track code reviews.  So in order to work on a CL the standard work flow is to use git commit --amend rather than make a new commit.  This differs from our old git-cl style. 

In your local commit logs make sure to add a BUG= field and TEST= field.  For BUG=, you should put something that looks like: BUG=bug-tracker:number. You can get a tracker name by looking in the upper-left corner of the tracker page (e.g. in the image on the right, the tracker name is "chromium-os"). If your changes are related to more than one tracker issue, you can list all the issues separated with commas.

For TEST=, you should describe what you did to test the changes.

Here's what a sample description should look like:

# Enter a description of the change.
# This will displayed on the codereview site.
# The first line will also be used as the subject of the review.
Here's a SHORT, one-line summary of my change.

And here are more details
...this can be as long as I want.

BUG=chromium-os:99999, chromium:88888
TEST=Ran all the white box tests

Change-Id: I8d7f86d716f1da76f4c85259f401c3ccc9a031ff
Once you run repo upload, this uploads the changes and prints out a URL for the code review (if its a new code review). Go to that URL (log in with your chromium.org account, which you might want to do in an "incognito" window in Chrome), and use the "Review->Publish Comments" link to mail your changes to your reviewers.

You should pick reviewers that know the code you're working on well and that will do the best reviews. Picking reviewers who will just rubber-stamp your changes is a bad idea. The point of submitting changes is to submit good code, not to submit as much code as you can. If you don't know who should review your changes, start by looking at the git log for the project that you're working on. Simply type the command below in a directory related to your project:

git log


Your reviewers will likely provide comments about changes that you should make before submitting your code. You should make such changes, submit them locally, and then re-upload your changes for code review by amending your changes to your git commit and re-running repo upload.

Try seeing the mainline again
While you're working on your changes, you might want to go back to the mainline for a little while (maybe you want to see if some bug you are seeing is related to your changes, or if the bug was always there). If you want to go back to the mainline without abandoning your changes, you can run the following command from within a directory associated with your project:

git checkout cros/master

When you're done, you can get back to your changes by running:

git checkout ${BRANCH_NAME} 

Work on something else while you're waiting
If you want to start on another (unrelated) change while waiting for your code review, you can repo start another branch. When you want to get back to your first branch, run the following command from within a directory associated with your project:

git checkout ${BRANCH_NAME} 

Push your changes
Eventually, all your reviewers will be happy and will give you a Looks Good and Approved (the latter is only available to owners of the code) message in Gerrit.  If they choose to test it they can also mark Verify.  Both Looks Good and Approved + Verified must be set in order to commit your CL.  Once they are set you'll see a Submit Patch (or Publish and Submit in the review panel) appear for your patch.  Gerrit will then commit your CL for you.

Note it is possible that your change is rejected because of a merge conflict.  If it is, rebase against any new changes and re-upload your patch.  This patch will have to be re-approved before it is allowed to be committed.

IMPORTANT NOTE: After you push your changes, make sure that you can be reached (by IM, phone, IRC, etc.) in case something is wrong. DO NOT push your changes and then go to lunch or go home for the day!

Make sure your changes didn't break things
After you commit, make sure you didn't break the build by checking the .

(Non-committers) Submit your changes
If you're not a committer, you must push your changes by submitting a patch to the the Chromium OS dev group.  However, the patch should go through the standard Gerrit review process before-hand and you'll have to ask one of the reviewers (who is a committer) to submit it for you.

Clean up after you're done with your changes
After you're done with your changes, you're ready to clean up. The most important thing to do is to tell cros_workon that you're done by running the following command:

cros_workon --board=${BOARD} stop ${PACKAGE_NAME}

This command tells cros_workon to stop forcing the -9999.ebuild and to stop forcing a build from source every time.

You can also delete the branch that repo created. There are a number of ways to do so; here is one way:

repo abandon ${BRANCH_NAME} ${CROS_WORKON_PROJECT}


SIDE NOTES:
  • If you don't specify a project name, the repo abandon command will throw out any local changes across all projects. You might also want to look at git branch -D or repo prune.
  • If you're using the minilayout, doing a cros_workon stop will not remove your source code. The code will continue to stay on your hard disk and get synced down.

Making changes to non-cros_workon-able packages
If you want to make to changes to something other than packages whose source is checked into the Chromium OS source control system, you can follow the instructions in the previous section, but skip the cros_workon step. Note specifically that you still need to run repo start to create a branch for your changes.

The types of changes that fall into this category include:
  • changes to build scripts (pretty much anything in src/scripts)
  • changes to ebuild files themselves (like the onesin src/third_party/chromiumos-overlay)
  • adding small patches to existing packages whose source code is NOT checked into Chromium OS git repositories
  • changes to eclass files (like the ones in src/third_party/chromiumos-overlay/eclass)
  • changes to the buildbot infrastructure (in crostools)
  • TODO: anything else?

Making changes to the way that the chroot is constructed
TODO: This section is currently a placeholder, waiting for someone to fill it in.  However, a few notes:
  • Many of the commands that take a --board=${BOARD} parameter also take a --host parameter, which makes the commands affect the host (i.e., the chroot) rather than the board.
    • Most notably, cros_workon --host says that you want to build a package used in the chroot from source.
  • If you modify the make_chroot script, remember that most developers won't get your change for a long time. People tend to build their chroot once, then never again. The Chromium OS team is moving away from having the make_chroot script do much.

Building an individual package
TODO: Document this better, and add the new cros_workon_make.

SIDE NOTE:To build an individual portage package, for a particular board, use emerge-${BOARD}.
For example, if you want to build dash to test on your device:

emerge-${BOARD} dash


Making changes to the Chromium web browser on Chromium OS
If you want to make modifications to the Chromium web browser and run your custom version of the Chromium web browser on Chromium OS, see .


Troubleshooting
My build is failing, what's the problem?
Your build may break because of transient failures introduced when an upstream dependency is in-flight while your dependent is built. These types of failures are often manifested as missing files or configuration information. Try re-running your build.

If re-running doesn't help,  to see if the problem exists there as well.

How do I fix network problems in the chroot?
TODO: This troubleshooting tip was from the old instructions.  Is it still relevant?

When running emerge inside the chroot, the command uses wget to fetch packages. The wget process is run as the portage user, and if that user is unable to talk on the network the command will be unable to resolve hostnames, among other things. This can happen if the machine is using a local firewall service such as UncomplicatedFireWall (ufw package on Ubuntu) that limits network traffic to a specific set of users.

This network traffic limitation can be verified by looking at the output of iptables, for example with ufw:

$ sudo iptables -L ufw-after-output | grep owner
ACCEPT     all  --  anywhere             anywhere            owner UID match root
ACCEPT     all  --  anywhere             anywhere            owner UID match yourname

One way to get around this limitation is to add the portage user to the list of allowed users:

First, create the user on the build machine:

sudo useradd -d /var/tmp/portage -N -s /bin/false portage

Then add the user to the list of allowed users in /etc/ufw/after.rules and /etc/ufw/after6.rules:

# allow outbound connections by portage user for building chromiumos
-A ufw-after-output -m owner --uid-owner portage -j ACCEPT

Finally, restart the firewall:

sudo restart ufw


I lost my developer tools on the stateful partition, can I get them back?
This happens sometimes because the security system likes to wipe out the stateful partition and a lot of developer tools are in /usr/local/bin. But all is not lost because there is a tool for updating the stateful partition from an image created by the auto-update part of the dev_server. Sadly, it is normally found in /usr/local so will have been lost too and you need to copy it over manually. This works for me:

$ cd /tmp
$ scp me@myworkstation:/path/to/chromiumos/chroot/build/x86-whatever/usr/bin/stateful_update .
$ sudo sh stateful_update
$ sudo reboot

Note you can clobber the stateful partition (remove user accounts etc and force OOBE) as part of this process by using a flag:

$ cd /tmp
$ scp me@myworkstation:/path/to/chromiumos/chroot/build/x86-whatever/usr/bin/stateful_update .
$ sudo sh stateful_update --stateful_change=clean
$ sudo reboot


Running Tests
Many of the automated tests that are part of the Chromium OS project run using the autotest framework.  TODO: add more details.  In order to run the autotests on your Chromium OS machine (or virtual machine), you must use an image that has been modified for test.  

Getting an image that has been modified for test
This doesn't work if you want to create a recovery image and boot a Cr48 with it, see below

The easiest way to get an image that has been modified for testing is to add the --test_image flag to either image_to_vm.sh or image_to_usb.sh, like so:

./image_to_usb.sh --board=${BOARD} --test_image --to=${MY_USB_KEY_LOCATION}

...or...

./image_to_vm.sh --board=${BOARD} --test_image 

Note that the --test_image flag will change the root password of the image to test0000.  The --test_image flag causes the image_to_xxx commands to make a copy of your chromiumos_image.bin file called chromiumos_test_image.bin (if that file doesn't already exist), modify that image for test, and use the test image as the source of the command.

SIDE NOTES:
  • When creating a VM image for testing purposes, it is highly recommended that you expand its stateful partition with the --statefulfs_size parameter. Otherwise, certain autotest scenarios will run out of stateful partition disk space since its default size on ChromeOS image files is equal to rootfs size of 2G. TODO: Is this still needed?  I don't think so now that the default stateful size is 2G.
  • If the directory already has a file called chromiumos_test_image.bin, that file is reused. That means that calling both image_to_usb.sh and image_to_vm.sh doesn't waste time by creating the test image twice.
  • If you are so inclined, you can call the mod_image_for_test.sh script directly. That causes the script, by default, to modify your existing chromiumos_image.bin for test. There is no good reason to do this, unless you are low on disk space and know that you won't ever need the non-modified image.

Creating a recovery image that has been modified for test
After building your usual image, you need to create a test version of it.  By default mod_image_for_test.sh blows away your existing image, you probably don't want that but see below, so we copy it first.

cp ~/trunk/src/build/images/${BOARD}/latest/chromiumos_image.bin \
    ~/trunk/src/build/images/${BOARD}/latest/chromiumos_test_image.bin

Now we can modify that to turn it into an actual test image:

./mod_image_for_test.sh \
    --board=${BOARD} \
    --image ~/trunk/src/build/images/${BOARD}/latest/chromiumos_test_image.bin

And this test image can be into a recovery image, again being careful not to overwrite the non-test variety:

./mod_image_for_recovery.sh \
    --board=${BOARD} \
    --nominimize_image \
    --kernel_image ${RECOVERY_KERNEL} \
    --image ~/trunk/src/build/images/${BOARD}/latest/chromiumos_test_image.bin \
    --to ~/trunk/src/build/images/${BOARD}/latest/recovery_test_image.bin

Finally to write out to the USB device:

./image_to_usb.sh --board=${BOARD} --image_name=recovery_test_image.bin --to=${MY_USB_KEY_LOCATION}

So this seems ideal, since it matches the image_to_usb.sh method, however there's a downside to this approach which you should keep in mind.
  • Your USB image will be a recovery mode/test image, but the ordinary image in your directory will be a non-test image.
  • If you use devserver, this will serve the non-test image not the test-image.
  • This means a machine installed with a test-enabled USB image will update to a non-test-enabled one.
Creating a new test
TODO: Validate that these instructions are still right.  They were copied from an old instructions page.

To create a new test, follow these steps:
  1. Create the source inside git repository R.
  2. Find out which ebuild builds test from repository R. If R is a new repository, create a new ebuild for it (see below).
  3. Edit the ebuild, and add tests_${testname} into the IUSE_TESTS variable. Prefix your test with a + if you want it to be enabled by default.
  4. Recompile (see modifying a test), make sure it runs, commit, etc.
To create a new ebuild, you must use the autotest eclass, which wraps all the necessary steps to compile your tests. If you are starting a new repository with tests, you may have to create a new ebuild. Please refer to existing ebuilds for details.

If you create a new ebuild for test X, you must run cros_workon start X. Mysterious failures mode will occur otherwise.

Seeing which tests are implemented by an ebuild
TODO: Validate that these instructions are still right.  They were copied from an old instructions page.

Run the command below and look at the "USE=" output. The command tells emerge to "pretend" to build the tests and print out verbose output. Replace ${EBUILD_NAME} with the name of an ebuild containing tests (see just below), like autotest-tests.

emerge-${BOARD} -pv ${EBUILD_NAME}

The only ebuilds containing tests are:
  • chromeos-base/autotest-tests - the default set of tests, that did not fall anywhere else
  • chromeos-base/chromeos-chrome - chrome tests; the tests that are part of chrome

Additional testing information
The document Running Smoke Suite On a VM Image contains the most up-to-date information about autotests.
TODO: It would be nice if some of that information migrated here?


Additional information
Developer mode
It can be confusing to figure out what "developer mode" means: Some parts of this document talk about switching your hardware to developer mode, while other parts talk about entering developer mode by running an image built with the --withdev flag. For the most part, the two actions enable the same set of things (like the shell command in crosh). Thus, you can think of either action as enabling developer mode.

To provide some details:
  • Putting your hardware into developer mode makes /bin/cros_boot_mode print developer. It also makes the file /mnt/stateful_partition/.developer_mode appear.
  • Building with the --withdev flag creates a file called /root/.dev_mode (in addition to adding a whole bunch of useful developer tools to your stateful partition). The presence of the /root/.dev_mode file enables developer mode and also prevents wiping of the stateful partition when you switch your hardware between developer mode and release mode.

Attribution requirements When you produce a Chromium OS image, you need to fulfill various attribution requirements of third party licenses. Currently, the images generated by a build don't do this for you automatically. You must modify .

Documentation on this site
You now understand the basics of building, running, modifying, and testing Chromium OS, but you've still got a lot to learn. Here are links to a few other pages on the chromium.org site that you are likely to find helpful (somewhat ordered by relevance):
  • The Tips And Tricks for Chromium OS Developers page has a lot of useful information to help you optimize your workflow.
  • If you haven't read the page about the devserver already, read it now.
  • Learn about the Chromium OS .
  • The Chromium OS developer FAQ might have useful info.  TODO: Double-check that the FAQ is still accurate, and resolve it with this page.
  •  might also have useful info.  TODO: Double-check that the FAQ is still accurate, and resolve it with this page.
  •  If you have questions about the --noenable_rootfs_verification option, you might find answers on this thread on chromium-os-dev.
  • Running Smoke Suite on a VM Image has good information about how to get up and running with autotest tests and VMs.
  • contains information about how to debug the Chromium browser on your Chromium OS device.  TODO: Validate that the instructions are still accurate.
  • has tips for working on branches.
  • talks about adding new git repositories.

External documentation Below are a few links to external sites that you might also find helpful (somewhat ordered by relevance):
  • Definitely look at the Chromium OS dev group to see what people are talking about.
  • Check out the  to report bugs, look for known issues, or look for things to fix.
  • Get an idea of what's actively happening by looking at the  site. (Note that this is the combined site for both Chromium and Chromium OS.)
  • Browse the source code on the .
  • Check the current status of the builds by looking at the .
  • Check out the  on freenode.net (this is the IRC channel that Chromium OS developers like to hang out on).
  • If you're learning git, check out , , or the .
  • The Gentoo Development Guide might be useful for (TODO: short description)
  •  might be useful for (TODO: short description)
  •  might be useful for (TODO: short description)
  • The Gentoo Wiki on Cross-Compiling might be useful for (TODO: short description)
  •  might be useful for (TODO: short description)
  • The  might help you if you're curious about repo. Or you can go straight to the .
  • The repo-discuss group is a good place to talk about repo.

阅读(3539) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~