OLD | NEW |
1 #!/bin/bash | 1 #!/bin/bash |
2 | 2 |
3 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 # Script to build a bootable keyfob-based chromeos system image from within | 7 # Script to build a bootable keyfob-based chromeos system image from within |
8 # a chromiumos setup. This assumes that all needed packages have been built into | 8 # a chromiumos setup. This assumes that all needed packages have been built into |
9 # the given target's root with binary packages turned on. This script will | 9 # the given target's root with binary packages turned on. This script will |
10 # build the Chrome OS image using only pre-built binary packages. | 10 # build the Chrome OS image using only pre-built binary packages. |
(...skipping 21 matching lines...) Expand all Loading... |
32 DEFINE_boolean withdev $FLAGS_TRUE \ | 32 DEFINE_boolean withdev $FLAGS_TRUE \ |
33 "Include useful developer friendly utilities in the image." | 33 "Include useful developer friendly utilities in the image." |
34 DEFINE_boolean installmask $FLAGS_TRUE \ | 34 DEFINE_boolean installmask $FLAGS_TRUE \ |
35 "Use INSTALL_MASK to shrink the resulting image." | 35 "Use INSTALL_MASK to shrink the resulting image." |
36 DEFINE_integer jobs -1 \ | 36 DEFINE_integer jobs -1 \ |
37 "How many packages to build in parallel at maximum." | 37 "How many packages to build in parallel at maximum." |
38 DEFINE_boolean statefuldev $FLAGS_TRUE \ | 38 DEFINE_boolean statefuldev $FLAGS_TRUE \ |
39 "Install development packages on stateful partition rather than the rootfs" | 39 "Install development packages on stateful partition rather than the rootfs" |
40 DEFINE_string to "" \ | 40 DEFINE_string to "" \ |
41 "The target image file or device" | 41 "The target image file or device" |
42 DEFINE_boolean withtest $FLAGS_FALSE \ | |
43 "Include packages required for testing and prepare image for testing" | |
44 DEFINE_string arm_extra_bootargs "" \ | 42 DEFINE_string arm_extra_bootargs "" \ |
45 "Additional command line options to pass to the ARM kernel." | 43 "Additional command line options to pass to the ARM kernel." |
46 | 44 |
47 # Parse command line. | 45 # Parse command line. |
48 FLAGS "$@" || exit 1 | 46 FLAGS "$@" || exit 1 |
49 eval set -- "${FLAGS_ARGV}" | 47 eval set -- "${FLAGS_ARGV}" |
50 | 48 |
51 # Only now can we die on error. shflags functions leak non-zero error codes, | 49 # Only now can we die on error. shflags functions leak non-zero error codes, |
52 # so will die prematurely if 'set -e' is specified before now. | 50 # so will die prematurely if 'set -e' is specified before now. |
53 set -e | 51 set -e |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 echo "Not deleting $OUTPUT_DIR. Note dev server updates will not work" \ | 158 echo "Not deleting $OUTPUT_DIR. Note dev server updates will not work" \ |
161 "until you successfully build another image or delete this directory" | 159 "until you successfully build another image or delete this directory" |
162 fi | 160 fi |
163 } | 161 } |
164 | 162 |
165 # ${DEV_IMAGE_ROOT} specifies the location of where developer packages will | 163 # ${DEV_IMAGE_ROOT} specifies the location of where developer packages will |
166 # be installed on the stateful dir. On a Chromium OS system, this will | 164 # be installed on the stateful dir. On a Chromium OS system, this will |
167 # translate to /usr/local | 165 # translate to /usr/local |
168 DEV_IMAGE_ROOT= | 166 DEV_IMAGE_ROOT= |
169 | 167 |
170 # Sets up symlinks for the stateful partition based on the root specified by | |
171 # ${1} and var directory specified by ${2}. | |
172 setup_symlinks_on_root() { | |
173 echo "Setting up symlinks on the stateful partition rooted at ${1} with"\ | |
174 "var directory located at ${2}" | |
175 | |
176 for path in usr local; do | |
177 if [ -h "${DEV_IMAGE_ROOT}/${path}" ] ; then | |
178 sudo unlink "${DEV_IMAGE_ROOT}/${path}" | |
179 elif [ -e "${DEV_IMAGE_ROOT}/${path}" ] ; then | |
180 echo "*** ERROR: ${DEV_IMAGE_ROOT}/${path} should be a symlink if exists" | |
181 return 1 | |
182 fi | |
183 sudo ln -s ${1} "${DEV_IMAGE_ROOT}/${path}" | |
184 done | |
185 | |
186 # Setup var. Var is on the stateful partition at /var for both non-developer | |
187 # builds and developer builds. | |
188 if [ -h "${DEV_IMAGE_ROOT}/var" ] ; then | |
189 sudo unlink "${DEV_IMAGE_ROOT}/var" | |
190 elif [ -e "${DEV_IMAGE_ROOT}/var" ] ; then | |
191 echo "*** ERROR: ${DEV_IMAGE_ROOT}/var should be a symlink if it exists" | |
192 return 1 | |
193 fi | |
194 | |
195 sudo ln -s "${2}" "${DEV_IMAGE_ROOT}/var" | |
196 } | |
197 | |
198 trap "cleanup && delete_prompt" EXIT | 168 trap "cleanup && delete_prompt" EXIT |
199 | 169 |
200 mkdir -p "$ROOT_FS_DIR" | 170 mkdir -p "$ROOT_FS_DIR" |
201 | 171 |
202 # Create and format the root file system. | 172 # Create and format the root file system. |
203 | 173 |
204 # Check for loop device before creating image. | 174 # Check for loop device before creating image. |
205 LOOP_DEV=$(sudo losetup -f) | 175 LOOP_DEV=$(sudo losetup -f) |
206 if [ -z "$LOOP_DEV" ] ; then | 176 if [ -z "$LOOP_DEV" ] ; then |
207 echo "No free loop device. Free up a loop device or reboot. exiting. " | 177 echo "No free loop device. Free up a loop device or reboot. exiting. " |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 if [[ $FLAGS_jobs -ne -1 ]]; then | 262 if [[ $FLAGS_jobs -ne -1 ]]; then |
293 EMERGE_JOBS="--jobs=$FLAGS_jobs" | 263 EMERGE_JOBS="--jobs=$FLAGS_jobs" |
294 fi | 264 fi |
295 | 265 |
296 # Prepare stateful partition with some pre-created directories | 266 # Prepare stateful partition with some pre-created directories |
297 sudo mkdir -p "${DEV_IMAGE_ROOT}" | 267 sudo mkdir -p "${DEV_IMAGE_ROOT}" |
298 sudo mkdir -p "${STATEFUL_DIR}/var" | 268 sudo mkdir -p "${STATEFUL_DIR}/var" |
299 | 269 |
300 # Create symlinks so that /usr/local/usr based directories are symlinked to | 270 # Create symlinks so that /usr/local/usr based directories are symlinked to |
301 # /usr/local/ directories e.g. /usr/local/usr/bin -> /usr/local/bin, etc. | 271 # /usr/local/ directories e.g. /usr/local/usr/bin -> /usr/local/bin, etc. |
302 setup_symlinks_on_root "${DEV_IMAGE_ROOT}" "${STATEFUL_DIR}/var" | 272 setup_symlinks_on_root "${DEV_IMAGE_ROOT}" "${STATEFUL_DIR}/var" \ |
| 273 "${STATEFUL_DIR}" |
303 | 274 |
304 # Perform binding rather than symlinking because directories must exist | 275 # Perform binding rather than symlinking because directories must exist |
305 # on rootfs so that we can bind at run-time since rootfs is read-only | 276 # on rootfs so that we can bind at run-time since rootfs is read-only |
306 echo "Binding directories from stateful partition onto the rootfs" | 277 echo "Binding directories from stateful partition onto the rootfs" |
307 sudo mkdir -p "${ROOT_FS_DIR}/usr/local" | 278 sudo mkdir -p "${ROOT_FS_DIR}/usr/local" |
308 sudo mount --bind "${DEV_IMAGE_ROOT}" "${ROOT_FS_DIR}/usr/local" | 279 sudo mount --bind "${DEV_IMAGE_ROOT}" "${ROOT_FS_DIR}/usr/local" |
309 sudo mkdir -p "${ROOT_FS_DIR}/var" | 280 sudo mkdir -p "${ROOT_FS_DIR}/var" |
310 sudo mount --bind "${STATEFUL_DIR}/var" "${ROOT_FS_DIR}/var" | 281 sudo mount --bind "${STATEFUL_DIR}/var" "${ROOT_FS_DIR}/var" |
311 | 282 |
312 # We "emerge --root=$ROOT_FS_DIR --root-deps=rdeps --usepkgonly" all of the | 283 # We "emerge --root=$ROOT_FS_DIR --root-deps=rdeps --usepkgonly" all of the |
(...skipping 15 matching lines...) Expand all Loading... |
328 --usepkgonly chromeos-dev $EMERGE_JOBS | 299 --usepkgonly chromeos-dev $EMERGE_JOBS |
329 | 300 |
330 # TODO(sosa@chromium.org) - Re-hide under statefuldev after switch | 301 # TODO(sosa@chromium.org) - Re-hide under statefuldev after switch |
331 # Flag will mount /usr/local on target device | 302 # Flag will mount /usr/local on target device |
332 sudo mkdir -p "$ROOT_FS_DIR/root" | 303 sudo mkdir -p "$ROOT_FS_DIR/root" |
333 | 304 |
334 # The ldd tool is a useful shell script but lives in glibc; just copy it. | 305 # The ldd tool is a useful shell script but lives in glibc; just copy it. |
335 sudo cp -a "$(which ldd)" "${ROOT_DEV_DIR}/usr/bin" | 306 sudo cp -a "$(which ldd)" "${ROOT_DEV_DIR}/usr/bin" |
336 fi | 307 fi |
337 | 308 |
338 # Install packages required for testing. | |
339 if [[ $FLAGS_withtest -eq $FLAGS_TRUE ]] ; then | |
340 sudo INSTALL_MASK="$INSTALL_MASK" emerge-${BOARD} \ | |
341 --root="$ROOT_DEV_DIR" --root-deps=rdeps \ | |
342 --usepkgonly chromeos-test $EMERGE_JOBS | |
343 fi | |
344 | |
345 # Extract the kernel from the root filesystem for use by the GPT image. Legacy | 309 # Extract the kernel from the root filesystem for use by the GPT image. Legacy |
346 # BIOS will use the kernel in the rootfs (via syslinux), Chrome OS BIOS will | 310 # BIOS will use the kernel in the rootfs (via syslinux), Chrome OS BIOS will |
347 # use the kernel partition. | 311 # use the kernel partition. |
348 sudo cp -f "${ROOT_FS_DIR}/boot/vmlinuz" "${OUTPUT_DIR}/vmlinuz.image" | 312 sudo cp -f "${ROOT_FS_DIR}/boot/vmlinuz" "${OUTPUT_DIR}/vmlinuz.image" |
349 | 313 |
350 # Create EFI System Partition to boot stock EFI BIOS (but not ChromeOS EFI | 314 # Create EFI System Partition to boot stock EFI BIOS (but not ChromeOS EFI |
351 # BIOS). We only need this for x86, but it's simpler and safer to keep the disk | 315 # BIOS). We only need this for x86, but it's simpler and safer to keep the disk |
352 # images the same for both x86 and ARM. | 316 # images the same for both x86 and ARM. |
353 ESP_IMG=${OUTPUT_DIR}/esp.image | 317 ESP_IMG=${OUTPUT_DIR}/esp.image |
354 # NOTE: The size argument for mkfs.vfat is in 1024-byte blocks. We'll hard-code | 318 # NOTE: The size argument for mkfs.vfat is in 1024-byte blocks. We'll hard-code |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 --board="$BOARD" | 371 --board="$BOARD" |
408 | 372 |
409 # Check that the image has been correctly created. | 373 # Check that the image has been correctly created. |
410 "${SCRIPTS_DIR}/test_image" \ | 374 "${SCRIPTS_DIR}/test_image" \ |
411 --root="$ROOT_FS_DIR" \ | 375 --root="$ROOT_FS_DIR" \ |
412 --target="$ARCH" | 376 --target="$ARCH" |
413 | 377 |
414 # Clean up symlinks so they work on a running target rooted at "/". | 378 # Clean up symlinks so they work on a running target rooted at "/". |
415 # Here development packages are rooted at /usr/local. However, do not | 379 # Here development packages are rooted at /usr/local. However, do not |
416 # create /usr/local or /var on host (already exist on target). | 380 # create /usr/local or /var on host (already exist on target). |
417 setup_symlinks_on_root "/usr/local" "/var" | 381 setup_symlinks_on_root "/usr/local" "/var" "${STATEFUL_DIR}" |
418 | 382 |
419 # Cleanup loop devices. | 383 # Cleanup loop devices. |
420 cleanup | 384 cleanup |
421 | 385 |
422 trap delete_prompt EXIT | 386 trap delete_prompt EXIT |
423 | 387 |
424 # Create the GPT-formatted image | 388 # Create the GPT-formatted image |
425 ${SCRIPTS_DIR}/build_gpt.sh \ | 389 ${SCRIPTS_DIR}/build_gpt.sh \ |
426 --arch=${ARCH} \ | 390 --arch=${ARCH} \ |
427 --board=${FLAGS_board} \ | 391 --board=${FLAGS_board} \ |
428 --arm_extra_bootargs="${FLAGS_arm_extra_bootargs}" \ | 392 --arm_extra_bootargs="${FLAGS_arm_extra_bootargs}" \ |
429 "${OUTPUT_DIR}" \ | 393 "${OUTPUT_DIR}" \ |
430 "${OUTPUT_IMG}" | 394 "${OUTPUT_IMG}" |
431 | 395 |
432 # Clean up temporary files. | 396 # Clean up temporary files. |
433 rm -f "${ROOT_FS_IMG}" "${STATEFUL_IMG}" "${OUTPUT_DIR}/vmlinuz.image" \ | 397 rm -f "${ROOT_FS_IMG}" "${STATEFUL_IMG}" "${OUTPUT_DIR}/vmlinuz.image" \ |
434 "${ESP_IMG}" | 398 "${ESP_IMG}" |
435 rmdir "${ROOT_FS_DIR}" "${STATEFUL_DIR}" "${ESP_DIR}" | 399 rmdir "${ROOT_FS_DIR}" "${STATEFUL_DIR}" "${ESP_DIR}" |
436 | 400 |
437 OUTSIDE_OUTPUT_DIR="../build/images/${FLAGS_board}/${IMAGE_SUBDIR}" | 401 OUTSIDE_OUTPUT_DIR="../build/images/${FLAGS_board}/${IMAGE_SUBDIR}" |
438 echo "Done. Image created in ${OUTPUT_DIR}" | 402 echo "Done. Image created in ${OUTPUT_DIR}" |
439 echo "To copy to USB keyfob, OUTSIDE the chroot, do something like:" | 403 echo "To copy to USB keyfob, OUTSIDE the chroot, do something like:" |
440 echo " ./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR} --to=/dev/sdX" | 404 echo " ./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR} --to=/dev/sdX" |
441 echo "To convert to VMWare image, OUTSIDE the chroot, do something like:" | 405 echo "To convert to VMWare image, OUTSIDE the chroot, do something like:" |
442 echo " ./image_to_vmware.sh --from=${OUTSIDE_OUTPUT_DIR}" | 406 echo " ./image_to_vmware.sh --from=${OUTSIDE_OUTPUT_DIR}" |
443 echo "from the scripts directory where you entered the chroot." | 407 echo "from the scripts directory where you entered the chroot." |
444 | 408 |
445 trap - EXIT | 409 trap - EXIT |
OLD | NEW |