| 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 | 18 |
| 19 # DEFINE_string name default_value description flag | 19 # DEFINE_string name default_value description flag |
| 20 DEFINE_string image "/dev/sda" "Path to device or image file" "i" | 20 DEFINE_string image "/dev/sda" "Path to device or image file" "i" |
| 21 DEFINE_string keys "$DEFAULT_KEYS_FOLDER" "Path to folder of dev keys" "k" | 21 DEFINE_string keys "$DEFAULT_KEYS_FOLDER" "Path to folder of dev keys" "k" |
| 22 DEFINE_boolean remove_rootfs_verification \ | 22 DEFINE_boolean remove_rootfs_verification \ |
| 23 $FLAGS_FALSE "Modify kernel boot config to disable rootfs verification" "" | 23 $FLAGS_FALSE "Modify kernel boot config to disable rootfs verification" "" |
| 24 DEFINE_string backup_dir \ | 24 DEFINE_string backup_dir \ |
| 25 "$DEFAULT_BACKUP_FOLDER" "Path of directory to store kernel backups" "" | 25 "$DEFAULT_BACKUP_FOLDER" "Path of directory to store kernel backups" "" |
| 26 DEFINE_boolean debug $FLAGS_FALSE "Provide debug messages" "d" | |
| 27 DEFINE_string save_config "" \ | 26 DEFINE_string save_config "" \ |
| 28 "Base filename to store kernel configs to, instead of resigning." "" | 27 "Base filename to store kernel configs to, instead of resigning." "" |
| 29 DEFINE_string set_config "" \ | 28 DEFINE_string set_config "" \ |
| 30 "Base filename to load kernel configs from" "" | 29 "Base filename to load kernel configs from" "" |
| 31 | 30 |
| 32 # Parse command line | 31 # Parse command line |
| 33 FLAGS "$@" || exit 1 | 32 FLAGS "$@" || exit 1 |
| 34 eval set -- "$FLAGS_ARGV" | 33 eval set -- "$FLAGS_ARGV" |
| 35 | 34 |
| 36 # Globals | 35 # Globals |
| 37 # ---------------------------------------------------------------------------- | 36 # ---------------------------------------------------------------------------- |
| 38 set -e | 37 set -e |
| 39 | 38 |
| 40 # a log file to keep the output results of executed command | 39 # a log file to keep the output results of executed command |
| 41 EXEC_LOG="$(make_temp_file)" | 40 EXEC_LOG="$(make_temp_file)" |
| 42 | 41 |
| 43 # Functions | 42 # Functions |
| 44 # ---------------------------------------------------------------------------- | 43 # ---------------------------------------------------------------------------- |
| 45 # Reports error message and exit(1) | |
| 46 err_die() { | |
| 47 echo "ERROR: $*" 1>&2 | |
| 48 exit 1 | |
| 49 } | |
| 50 | |
| 51 # Returns true if we're running in debug mode | |
| 52 is_debug_mode() { | |
| 53 [ "$FLAGS_debug" = $FLAGS_TRUE ] | |
| 54 } | |
| 55 | |
| 56 # Prints messages (in parameters) in debug mode | |
| 57 debug_msg() { | |
| 58 if is_debug_mode; then | |
| 59 echo "DEBUG: $*" 1>&2 | |
| 60 fi | |
| 61 } | |
| 62 | 44 |
| 63 # Removes rootfs verification from kernel boot parameter | 45 # Removes rootfs verification from kernel boot parameter |
| 64 remove_rootfs_verification() { | 46 remove_rootfs_verification() { |
| 65 echo "$*" | sed ' | 47 echo "$*" | sed ' |
| 66 s| root=/dev/dm-0 | root=/dev/sd%D%P | | 48 s| root=/dev/dm-0 | root=/dev/sd%D%P | |
| 67 s| dm_verity[^=]*=[-0-9]*||g | 49 s| dm_verity[^=]*=[-0-9]*||g |
| 68 s| dm="[^"]*"|| | 50 s| dm="[^"]*"|| |
| 69 s| ro | rw |' | 51 s| ro | rw |' |
| 70 } | 52 } |
| 71 | 53 |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 debug_msg "Complete." | 265 debug_msg "Complete." |
| 284 if [ $num_signed -gt 0 -a $num_signed -le 2 ]; then | 266 if [ $num_signed -gt 0 -a $num_signed -le 2 ]; then |
| 285 # signed 1 or two kernels | 267 # signed 1 or two kernels |
| 286 echo "Successfully re-signed $num_signed kernel(s) on device $FLAGS_image". | 268 echo "Successfully re-signed $num_signed kernel(s) on device $FLAGS_image". |
| 287 else | 269 else |
| 288 err_die "Failed re-signing kernels." | 270 err_die "Failed re-signing kernels." |
| 289 fi | 271 fi |
| 290 } | 272 } |
| 291 | 273 |
| 292 main | 274 main |
| OLD | NEW |