| OLD | NEW |
| 1 #!/bin/sh | 1 #!/bin/sh |
| 2 # | 2 # |
| 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2010 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 # This script can change key (usually developer keys) and kernel config | 7 # This script can change key (usually developer keys) and kernel config |
| 8 # of a kernels on SSD. | 8 # of a kernels on SSD. |
| 9 | 9 |
| 10 SCRIPT_BASE="$(dirname "$0")" | 10 SCRIPT_BASE="$(dirname "$0")" |
| 11 . "$SCRIPT_BASE/common.sh" | 11 . "$SCRIPT_BASE/common.sh" |
| 12 load_shflags || exit 1 | 12 load_shflags || exit 1 |
| 13 | 13 |
| 14 # Constants used by DEFINE_* | 14 # Constants used by DEFINE_* |
| 15 VBOOT_BASE='/usr/share/vboot' | 15 VBOOT_BASE='/usr/share/vboot' |
| 16 DEFAULT_KEYS_FOLDER="$VBOOT_BASE/devkeys" | 16 DEFAULT_KEYS_FOLDER="$VBOOT_BASE/devkeys" |
| 17 DEFAULT_BACKUP_FOLDER='/mnt/stateful_partition/backups' | 17 DEFAULT_BACKUP_FOLDER='/mnt/stateful_partition/backups' |
| 18 DEFAULT_PARTITIONS='2 4' | 18 DEFAULT_PARTITIONS='2 4' |
| 19 | 19 |
| 20 # DEFINE_string name default_value description flag | 20 # DEFINE_string name default_value description flag |
| 21 DEFINE_string image "/dev/sda" "Path to device or image file" "i" | 21 DEFINE_string image "/dev/sda" "Path to device or image file" "i" |
| 22 DEFINE_string keys "$DEFAULT_KEYS_FOLDER" "Path to folder of dev keys" "k" | 22 DEFINE_string keys "$DEFAULT_KEYS_FOLDER" "Path to folder of dev keys" "k" |
| 23 DEFINE_boolean remove_rootfs_verification \ | 23 DEFINE_boolean remove_rootfs_verification \ |
| 24 $FLAGS_FALSE "Modify kernel boot config to disable rootfs verification" "" | 24 $FLAGS_FALSE "Modify kernel boot config to disable rootfs verification" "" |
| 25 DEFINE_string backup_dir \ | 25 DEFINE_string backup_dir \ |
| 26 "$DEFAULT_BACKUP_FOLDER" "Path of directory to store kernel backups" "" | 26 "$DEFAULT_BACKUP_FOLDER" "Path of directory to store kernel backups" "" |
| 27 DEFINE_boolean debug $FLAGS_FALSE "Provide debug messages" "d" | |
| 28 DEFINE_string save_config "" \ | 27 DEFINE_string save_config "" \ |
| 29 "Base filename to store kernel configs to, instead of resigning." "" | 28 "Base filename to store kernel configs to, instead of resigning." "" |
| 30 DEFINE_string set_config "" \ | 29 DEFINE_string set_config "" \ |
| 31 "Base filename to load kernel configs from" "" | 30 "Base filename to load kernel configs from" "" |
| 32 DEFINE_string partitions "$DEFAULT_PARTITIONS" \ | 31 DEFINE_string partitions "$DEFAULT_PARTITIONS" \ |
| 33 "List of partitions to examine" "" | 32 "List of partitions to examine" "" |
| 34 | 33 |
| 35 # Parse command line | 34 # Parse command line |
| 36 FLAGS "$@" || exit 1 | 35 FLAGS "$@" || exit 1 |
| 37 eval set -- "$FLAGS_ARGV" | 36 eval set -- "$FLAGS_ARGV" |
| 38 | 37 |
| 39 # Globals | 38 # Globals |
| 40 # ---------------------------------------------------------------------------- | 39 # ---------------------------------------------------------------------------- |
| 41 set -e | 40 set -e |
| 42 | 41 |
| 43 # a log file to keep the output results of executed command | 42 # a log file to keep the output results of executed command |
| 44 EXEC_LOG="$(make_temp_file)" | 43 EXEC_LOG="$(make_temp_file)" |
| 45 | 44 |
| 46 # Functions | 45 # Functions |
| 47 # ---------------------------------------------------------------------------- | 46 # ---------------------------------------------------------------------------- |
| 48 # Reports error message and exit(1) | |
| 49 err_die() { | |
| 50 echo "ERROR: $*" 1>&2 | |
| 51 exit 1 | |
| 52 } | |
| 53 | |
| 54 # Returns true if we're running in debug mode | |
| 55 is_debug_mode() { | |
| 56 [ "$FLAGS_debug" = $FLAGS_TRUE ] | |
| 57 } | |
| 58 | |
| 59 # Prints messages (in parameters) in debug mode | |
| 60 debug_msg() { | |
| 61 if is_debug_mode; then | |
| 62 echo "DEBUG: $*" 1>&2 | |
| 63 fi | |
| 64 } | |
| 65 | 47 |
| 66 # Removes rootfs verification from kernel boot parameter | 48 # Removes rootfs verification from kernel boot parameter |
| 67 remove_rootfs_verification() { | 49 remove_rootfs_verification() { |
| 68 echo "$*" | sed ' | 50 echo "$*" | sed ' |
| 69 s| root=/dev/dm-0 | root=/dev/sd%D%P | | 51 s| root=/dev/dm-0 | root=/dev/sd%D%P | |
| 70 s| dm_verity[^=]*=[-0-9]*||g | 52 s| dm_verity[^=]*=[-0-9]*||g |
| 71 s| dm="[^"]*"|| | 53 s| dm="[^"]*"|| |
| 72 s| ro | rw |' | 54 s| ro | rw |' |
| 73 } | 55 } |
| 74 | 56 |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 if [ $num_signed -gt 0 -a $num_signed -le $num_given ]; then | 273 if [ $num_signed -gt 0 -a $num_signed -le $num_given ]; then |
| 292 # signed something at least | 274 # signed something at least |
| 293 echo "Successfully re-signed $num_signed of $num_given kernel(s)" \ | 275 echo "Successfully re-signed $num_signed of $num_given kernel(s)" \ |
| 294 " on device $FLAGS_image". | 276 " on device $FLAGS_image". |
| 295 else | 277 else |
| 296 err_die "Failed re-signing kernels." | 278 err_die "Failed re-signing kernels." |
| 297 fi | 279 fi |
| 298 } | 280 } |
| 299 | 281 |
| 300 main | 282 main |
| OLD | NEW |