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 factory_install $FLAGS_FALSE \ |
| 43 "Build a smaller image to overlay the factory install shim on; this argument \ |
| 44 is also required in image_to_usb." |
42 DEFINE_string arm_extra_bootargs "" \ | 45 DEFINE_string arm_extra_bootargs "" \ |
43 "Additional command line options to pass to the ARM kernel." | 46 "Additional command line options to pass to the ARM kernel." |
44 | 47 |
45 # Parse command line. | 48 # Parse command line. |
46 FLAGS "$@" || exit 1 | 49 FLAGS "$@" || exit 1 |
47 eval set -- "${FLAGS_ARGV}" | 50 eval set -- "${FLAGS_ARGV}" |
48 | 51 |
49 # Only now can we die on error. shflags functions leak non-zero error codes, | 52 # Only now can we die on error. shflags functions leak non-zero error codes, |
50 # so will die prematurely if 'set -e' is specified before now. | 53 # so will die prematurely if 'set -e' is specified before now. |
51 set -e | 54 set -e |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 | 176 |
174 # Check for loop device before creating image. | 177 # Check for loop device before creating image. |
175 LOOP_DEV=$(sudo losetup -f) | 178 LOOP_DEV=$(sudo losetup -f) |
176 if [ -z "$LOOP_DEV" ] ; then | 179 if [ -z "$LOOP_DEV" ] ; then |
177 echo "No free loop device. Free up a loop device or reboot. exiting. " | 180 echo "No free loop device. Free up a loop device or reboot. exiting. " |
178 exit 1 | 181 exit 1 |
179 fi | 182 fi |
180 | 183 |
181 # Create root file system disk image to fit on a 1GB memory stick. | 184 # Create root file system disk image to fit on a 1GB memory stick. |
182 # 1 GB in hard-drive-manufacturer-speak is 10^9, not 2^30. 950MB < 10^9 bytes. | 185 # 1 GB in hard-drive-manufacturer-speak is 10^9, not 2^30. 950MB < 10^9 bytes. |
183 ROOT_SIZE_BYTES=$((1024 * 1024 * 720)) | 186 if [[ $FLAGS_factory_install -eq ${FLAGS_TRUE} ]] ; then |
| 187 ROOT_SIZE_BYTES=$((1024 * 1024 * 180)) |
| 188 else |
| 189 ROOT_SIZE_BYTES=$((1024 * 1024 * 720)) |
| 190 fi |
| 191 |
184 dd if=/dev/zero of="$ROOT_FS_IMG" bs=1 count=1 seek=$((ROOT_SIZE_BYTES - 1)) | 192 dd if=/dev/zero of="$ROOT_FS_IMG" bs=1 count=1 seek=$((ROOT_SIZE_BYTES - 1)) |
185 sudo losetup "$LOOP_DEV" "$ROOT_FS_IMG" | 193 sudo losetup "$LOOP_DEV" "$ROOT_FS_IMG" |
186 sudo mkfs.ext3 "$LOOP_DEV" | 194 sudo mkfs.ext3 "$LOOP_DEV" |
187 | 195 |
188 # Tune and mount rootfs. | 196 # Tune and mount rootfs. |
189 UUID=$(uuidgen) | 197 UUID=$(uuidgen) |
190 DISK_LABEL="C-KEYFOB" | 198 DISK_LABEL="C-KEYFOB" |
191 sudo tune2fs -L "$DISK_LABEL" -U "$UUID" -c 0 -i 0 "$LOOP_DEV" | 199 sudo tune2fs -L "$DISK_LABEL" -U "$UUID" -c 0 -i 0 "$LOOP_DEV" |
192 sudo mount "$LOOP_DEV" "$ROOT_FS_DIR" | 200 sudo mount "$LOOP_DEV" "$ROOT_FS_DIR" |
193 | 201 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 # We need to install libstdc++ manually from the cross toolchain. | 260 # We need to install libstdc++ manually from the cross toolchain. |
253 # TODO: Figure out a better way of doing this? | 261 # TODO: Figure out a better way of doing this? |
254 sudo cp -a "${BOARD_ROOT}"/lib/libgcc_s.so* "${ROOT_FS_DIR}/lib" | 262 sudo cp -a "${BOARD_ROOT}"/lib/libgcc_s.so* "${ROOT_FS_DIR}/lib" |
255 sudo cp -a "${BOARD_ROOT}"/usr/lib/libstdc++.so* "${ROOT_FS_DIR}/usr/lib" | 263 sudo cp -a "${BOARD_ROOT}"/usr/lib/libstdc++.so* "${ROOT_FS_DIR}/usr/lib" |
256 | 264 |
257 INSTALL_MASK="" | 265 INSTALL_MASK="" |
258 if [[ $FLAGS_installmask -eq ${FLAGS_TRUE} ]] ; then | 266 if [[ $FLAGS_installmask -eq ${FLAGS_TRUE} ]] ; then |
259 INSTALL_MASK="$DEFAULT_INSTALL_MASK" | 267 INSTALL_MASK="$DEFAULT_INSTALL_MASK" |
260 fi | 268 fi |
261 | 269 |
| 270 # Reduce the size of factory install shim. |
| 271 # TODO: Build a separated ebuild for the factory install shim to reduce size. |
| 272 if [[ $FLAGS_factory_install -eq ${FLAGS_TRUE} ]] ; then |
| 273 INSTALL_MASK="$INSTALL_MASK $FACTORY_INSTALL_MASK" |
| 274 fi |
| 275 |
262 if [[ $FLAGS_jobs -ne -1 ]]; then | 276 if [[ $FLAGS_jobs -ne -1 ]]; then |
263 EMERGE_JOBS="--jobs=$FLAGS_jobs" | 277 EMERGE_JOBS="--jobs=$FLAGS_jobs" |
264 fi | 278 fi |
265 | 279 |
266 # Prepare stateful partition with some pre-created directories | 280 # Prepare stateful partition with some pre-created directories |
267 sudo mkdir -p "${DEV_IMAGE_ROOT}" | 281 sudo mkdir -p "${DEV_IMAGE_ROOT}" |
268 sudo mkdir -p "${STATEFUL_DIR}/var" | 282 sudo mkdir -p "${STATEFUL_DIR}/var" |
269 | 283 |
270 # Create symlinks so that /usr/local/usr based directories are symlinked to | 284 # Create symlinks so that /usr/local/usr based directories are symlinked to |
271 # /usr/local/ directories e.g. /usr/local/usr/bin -> /usr/local/bin, etc. | 285 # /usr/local/ directories e.g. /usr/local/usr/bin -> /usr/local/bin, etc. |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 } | 356 } |
343 | 357 |
344 menuentry "local image B" { | 358 menuentry "local image B" { |
345 linux $grubpartB/boot/vmlinuz quiet console=tty2 init=/sbin/init boot=local ro
otwait root=/dev/$linuxpartB ro noresume noswap i915.modeset=1 loglevel=1 | 359 linux $grubpartB/boot/vmlinuz quiet console=tty2 init=/sbin/init boot=local ro
otwait root=/dev/$linuxpartB ro noresume noswap i915.modeset=1 loglevel=1 |
346 } | 360 } |
347 | 361 |
348 EOF | 362 EOF |
349 | 363 |
350 # By default, dev mode should be activated for either development builds or | 364 # By default, dev mode should be activated for either development builds or |
351 # test builds. | 365 # test builds. |
352 if [[ $FLAGS_withdev -eq $FLAGS_TRUE ]] ||\ | 366 if [[ $FLAGS_withdev -eq $FLAGS_TRUE ]] ; then |
353 [[ $FLAGS_withtest -eq $FLAGS_TRUE ]]; then | |
354 sudo touch "$ROOT_FS_DIR/root/.dev_mode" | 367 sudo touch "$ROOT_FS_DIR/root/.dev_mode" |
355 | 368 |
356 # Re-run ldconfig to fix /etc/ldconfig.so.cache. | 369 # Re-run ldconfig to fix /etc/ldconfig.so.cache. |
357 sudo /sbin/ldconfig -r "$ROOT_FS_DIR" | 370 sudo /sbin/ldconfig -r "$ROOT_FS_DIR" |
358 fi | 371 fi |
359 | 372 |
360 # Perform any customizations on the root file system that are needed. | 373 # Perform any customizations on the root file system that are needed. |
361 "${SCRIPTS_DIR}/customize_rootfs" \ | 374 "${SCRIPTS_DIR}/customize_rootfs" \ |
362 --root="$ROOT_FS_DIR" \ | 375 --root="$ROOT_FS_DIR" \ |
363 --target="$ARCH" \ | 376 --target="$ARCH" \ |
364 --board="$BOARD" | 377 --board="$BOARD" |
365 | 378 |
366 # Check that the image has been correctly created. | 379 # Don't test the factory install shim. |
367 "${SCRIPTS_DIR}/test_image" \ | 380 if [[ $FLAGS_factory_install -eq ${FLAGS_FALSE} ]] ; then |
368 --root="$ROOT_FS_DIR" \ | 381 # Check that the image has been correctly created. |
369 --target="$ARCH" | 382 "${SCRIPTS_DIR}/test_image" \ |
| 383 --root="$ROOT_FS_DIR" \ |
| 384 --target="$ARCH" |
| 385 fi |
370 | 386 |
371 # Clean up symlinks so they work on a running target rooted at "/". | 387 # Clean up symlinks so they work on a running target rooted at "/". |
372 # Here development packages are rooted at /usr/local. However, do not | 388 # Here development packages are rooted at /usr/local. However, do not |
373 # create /usr/local or /var on host (already exist on target). | 389 # create /usr/local or /var on host (already exist on target). |
374 setup_symlinks_on_root "/usr/local" "/var" "${STATEFUL_DIR}" | 390 setup_symlinks_on_root "/usr/local" "/var" "${STATEFUL_DIR}" |
375 | 391 |
376 # Cleanup loop devices. | 392 # Cleanup loop devices. |
377 cleanup | 393 cleanup |
378 | 394 |
379 trap delete_prompt EXIT | 395 trap delete_prompt EXIT |
(...skipping 13 matching lines...) Expand all Loading... |
393 | 409 |
394 OUTSIDE_OUTPUT_DIR="../build/images/${FLAGS_board}/${IMAGE_SUBDIR}" | 410 OUTSIDE_OUTPUT_DIR="../build/images/${FLAGS_board}/${IMAGE_SUBDIR}" |
395 echo "Done. Image created in ${OUTPUT_DIR}" | 411 echo "Done. Image created in ${OUTPUT_DIR}" |
396 echo "To copy to USB keyfob, OUTSIDE the chroot, do something like:" | 412 echo "To copy to USB keyfob, OUTSIDE the chroot, do something like:" |
397 echo " ./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR} --to=/dev/sdX" | 413 echo " ./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR} --to=/dev/sdX" |
398 echo "To convert to VMWare image, OUTSIDE the chroot, do something like:" | 414 echo "To convert to VMWare image, OUTSIDE the chroot, do something like:" |
399 echo " ./image_to_vmware.sh --from=${OUTSIDE_OUTPUT_DIR}" | 415 echo " ./image_to_vmware.sh --from=${OUTSIDE_OUTPUT_DIR}" |
400 echo "from the scripts directory where you entered the chroot." | 416 echo "from the scripts directory where you entered the chroot." |
401 | 417 |
402 trap - EXIT | 418 trap - EXIT |
OLD | NEW |