Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 # Common constants for build scripts | 5 # Common constants for build scripts |
| 6 # This must evaluate properly for both /bin/bash and /bin/sh | 6 # This must evaluate properly for both /bin/bash and /bin/sh |
| 7 | 7 |
| 8 # All scripts should die on error unless commands are specifically excepted | 8 # All scripts should die on error unless commands are specifically excepted |
| 9 # by prefixing with '!' or surrounded by 'set +e' / 'set -e'. | 9 # by prefixing with '!' or surrounded by 'set +e' / 'set -e'. |
| 10 # TODO: Re-enable this once shflags is less prone to dying. | 10 # TODO: Re-enable this once shflags is less prone to dying. |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 316 } | 316 } |
| 317 | 317 |
| 318 V_RED="\e[31m" | 318 V_RED="\e[31m" |
| 319 V_YELLOW="\e[33m" | 319 V_YELLOW="\e[33m" |
| 320 V_BOLD_GREEN="\e[1;32m" | 320 V_BOLD_GREEN="\e[1;32m" |
| 321 V_BOLD_RED="\e[1;31m" | 321 V_BOLD_RED="\e[1;31m" |
| 322 V_BOLD_YELLOW="\e[1;33m" | 322 V_BOLD_YELLOW="\e[1;33m" |
| 323 | 323 |
| 324 function info { | 324 function info { |
| 325 echo -e >&2 "${V_BOLD_GREEN}INFO : $1${V_VIDOFF}" | 325 echo -e >&2 "${V_BOLD_GREEN}INFO : $1${V_VIDOFF}" |
| 326 } | 326 } |
| 327 | 327 |
| 328 function warn { | 328 function warn { |
| 329 echo -e >&2 "${V_BOLD_YELLOW}WARNING: $1${V_VIDOFF}" | 329 echo -e >&2 "${V_BOLD_YELLOW}WARNING: $1${V_VIDOFF}" |
| 330 } | 330 } |
| 331 | 331 |
| 332 function error { | 332 function error { |
| 333 echo -e >&2 "${V_BOLD_RED}ERROR : $1${V_VIDOFF}" | 333 echo -e >&2 "${V_BOLD_RED}ERROR : $1${V_VIDOFF}" |
| 334 } | 334 } |
| 335 | 335 |
| 336 function die { | 336 function die { |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 442 # Setup var symlink. | 442 # Setup var symlink. |
| 443 if [ -h "${dev_image_root}/var" ]; then | 443 if [ -h "${dev_image_root}/var" ]; then |
| 444 sudo unlink "${dev_image_root}/var" | 444 sudo unlink "${dev_image_root}/var" |
| 445 elif [ -e "${dev_image_root}/var" ]; then | 445 elif [ -e "${dev_image_root}/var" ]; then |
| 446 die "${dev_image_root}/var should be a symlink if it exists" | 446 die "${dev_image_root}/var should be a symlink if it exists" |
| 447 fi | 447 fi |
| 448 | 448 |
| 449 sudo ln -s "${var_target}" "${dev_image_root}/var" | 449 sudo ln -s "${var_target}" "${dev_image_root}/var" |
| 450 } | 450 } |
| 451 | 451 |
| 452 # These two helpers clobber the ro compat value in our root filesystem. | |
| 453 # | |
| 454 # When the system is built with --enable_rootfs_verification, bit-precise | |
| 455 # integrity checking is performed. That precision poses a usability issue on | |
| 456 # systems that automount partitions with recognizable filesystems, such as | |
| 457 # ext2/3/4. When the filesystem is mounted 'rw', ext2 metadata will be | |
| 458 # automatically updated even if no other writes are performed to the | |
| 459 # filesystem. In addition, ext2+ does not support a "read-only" flag for a | |
| 460 # given filesystem. That said, forward and backward compatibility of | |
| 461 # filesystem features are supported by tracking if a new feature breaks r/w or | |
| 462 # just write compatibility. We abuse the read-only compatibility flag[1] in | |
| 463 # the filesystem header by setting the high order byte (le) to FF. This tells | |
| 464 # the kernel that features R24-R31 are all enabled. Since those features are | |
| 465 # undefined on all ext-based filesystem, all standard kernels will refuse to | |
| 466 # mount the filesystem as read-write -- only read-only[2]. | |
| 467 # | |
| 468 # [1] 32-bit flag we are modifying: | |
| 469 # http://git.chromium.org/cgi-bin/gitweb.cgi?p=kernel.git;a=blob;f=include/linu x/ext2_fs.h#l417 | |
| 470 # [2] Mount behavior is enforced here: | |
| 471 # http://git.chromium.org/cgi-bin/gitweb.cgi?p=kernel.git;a=blob;f=fs/ext2/supe r.c#l857 | |
| 472 # | |
| 473 # N.B., if the high order feature bits are used in the future, we will need to | |
| 474 # revisit this technique. | |
| 475 disable_rw_mount() { | |
|
gauravsh
2010/10/20 19:06:55
Both these helpers don't have any external depende
Will Drewry
2010/10/20 19:11:49
cool
| |
| 476 local rootfs="$1" | |
| 477 local offset="${2-0}" # in bytes | |
| 478 local ro_compat_offset=$((0x467 + 3)) # Set 'highest' byte | |
| 479 echo -ne '\xff' | | |
| 480 sudo dd of="$rootfs" seek=$((offset + ro_compat_offset)) \ | |
| 481 conv=notrunc count=1 bs=1 | |
| 482 } | |
| 483 | |
| 484 enable_rw_mount() { | |
| 485 local rootfs="$1" | |
| 486 local offset="${2-0}" | |
| 487 local ro_compat_offset=$((0x467 + 3)) # Set 'highest' byte | |
| 488 echo -ne '\x00' | | |
| 489 sudo dd of="$rootfs" seek=$((offset + ro_compat_offset)) \ | |
| 490 conv=notrunc count=1 bs=1 | |
| 491 } | |
| 492 | |
| 452 # Get current timestamp. Assumes common.sh runs at startup. | 493 # Get current timestamp. Assumes common.sh runs at startup. |
| 453 start_time=$(date +%s) | 494 start_time=$(date +%s) |
| 454 | 495 |
| 455 # Print time elsapsed since start_time. | 496 # Print time elsapsed since start_time. |
| 456 print_time_elapsed() { | 497 print_time_elapsed() { |
| 457 end_time=$(date +%s) | 498 end_time=$(date +%s) |
| 458 elapsed_seconds="$(( $end_time - $start_time ))" | 499 elapsed_seconds="$(( $end_time - $start_time ))" |
| 459 minutes="$(( $elapsed_seconds / 60 ))" | 500 minutes="$(( $elapsed_seconds / 60 ))" |
| 460 seconds="$(( $elapsed_seconds % 60 ))" | 501 seconds="$(( $elapsed_seconds % 60 ))" |
| 461 echo "Elapsed time: ${minutes}m${seconds}s" | 502 echo "Elapsed time: ${minutes}m${seconds}s" |
| 462 } | 503 } |
| OLD | NEW |