| 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 | 19 |
| 19 # DEFINE_string name default_value description flag | 20 # DEFINE_string name default_value description flag |
| 20 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" |
| 21 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" |
| 22 DEFINE_boolean remove_rootfs_verification \ | 23 DEFINE_boolean remove_rootfs_verification \ |
| 23 $FLAGS_FALSE "Modify kernel boot config to disable rootfs verification" "" | 24 $FLAGS_FALSE "Modify kernel boot config to disable rootfs verification" "" |
| 24 DEFINE_string backup_dir \ | 25 DEFINE_string backup_dir \ |
| 25 "$DEFAULT_BACKUP_FOLDER" "Path of directory to store kernel backups" "" | 26 "$DEFAULT_BACKUP_FOLDER" "Path of directory to store kernel backups" "" |
| 26 DEFINE_boolean debug $FLAGS_FALSE "Provide debug messages" "d" | 27 DEFINE_boolean debug $FLAGS_FALSE "Provide debug messages" "d" |
| 27 DEFINE_string save_config "" \ | 28 DEFINE_string save_config "" \ |
| 28 "Base filename to store kernel configs to, instead of resigning." "" | 29 "Base filename to store kernel configs to, instead of resigning." "" |
| 29 DEFINE_string set_config "" \ | 30 DEFINE_string set_config "" \ |
| 30 "Base filename to load kernel configs from" "" | 31 "Base filename to load kernel configs from" "" |
| 32 DEFINE_string partitions "$DEFAULT_PARTITIONS" \ |
| 33 "List of partitions to examine" "" |
| 31 | 34 |
| 32 # Parse command line | 35 # Parse command line |
| 33 FLAGS "$@" || exit 1 | 36 FLAGS "$@" || exit 1 |
| 34 eval set -- "$FLAGS_ARGV" | 37 eval set -- "$FLAGS_ARGV" |
| 35 | 38 |
| 36 # Globals | 39 # Globals |
| 37 # ---------------------------------------------------------------------------- | 40 # ---------------------------------------------------------------------------- |
| 38 set -e | 41 set -e |
| 39 | 42 |
| 40 # a log file to keep the output results of executed command | 43 # a log file to keep the output results of executed command |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 2) | 91 2) |
| 89 echo "Kernel A" | 92 echo "Kernel A" |
| 90 ;; | 93 ;; |
| 91 4) | 94 4) |
| 92 echo "Kernel B" | 95 echo "Kernel B" |
| 93 ;; | 96 ;; |
| 94 6) | 97 6) |
| 95 echo "Kernel C" | 98 echo "Kernel C" |
| 96 ;; | 99 ;; |
| 97 *) | 100 *) |
| 98 err_die "unknown kernel index: $1" | 101 echo "Partition $1" |
| 99 esac | 102 esac |
| 100 } | 103 } |
| 101 | 104 |
| 102 # Resigns a kernel on SSD or image. | 105 # Resigns a kernel on SSD or image. |
| 103 resign_ssd_kernel() { | 106 resign_ssd_kernel() { |
| 104 # bs=512 is the fixed block size for dd and cgpt | 107 # bs=512 is the fixed block size for dd and cgpt |
| 105 local bs=512 | 108 local bs=512 |
| 106 local ssd_device="$1" | 109 local ssd_device="$1" |
| 107 | 110 |
| 108 # reasonable size for current kernel partition | 111 # reasonable size for current kernel partition |
| 109 local min_kernel_size=32000 | 112 local min_kernel_size=32000 |
| 110 local max_kernel_size=65536 | 113 local max_kernel_size=65536 |
| 111 local resigned_kernels=0 | 114 local resigned_kernels=0 |
| 112 | 115 |
| 113 for kernel_index in 2 4 6; do | 116 for kernel_index in $FLAGS_partitions; do |
| 114 local old_blob="$(make_temp_file)" | 117 local old_blob="$(make_temp_file)" |
| 115 local new_blob="$(make_temp_file)" | 118 local new_blob="$(make_temp_file)" |
| 116 local name="$(cros_kernel_name $kernel_index)" | 119 local name="$(cros_kernel_name $kernel_index)" |
| 117 local rootfs_index="$(($kernel_index + 1))" | 120 local rootfs_index="$(($kernel_index + 1))" |
| 118 | 121 |
| 119 debug_msg "Probing $name information" | 122 debug_msg "Probing $name information" |
| 120 local offset size | 123 local offset size |
| 121 offset="$(partoffset "$ssd_device" "$kernel_index")" || | 124 offset="$(partoffset "$ssd_device" "$kernel_index")" || |
| 122 err_die "Failed to get partition $kernel_index offset from $ssd_device" | 125 err_die "Failed to get partition $kernel_index offset from $ssd_device" |
| 123 size="$(partsize "$ssd_device" "$kernel_index")" || | 126 size="$(partsize "$ssd_device" "$kernel_index")" || |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 exit 0 | 264 exit 0 |
| 262 fi | 265 fi |
| 263 | 266 |
| 264 return $resigned_kernels | 267 return $resigned_kernels |
| 265 } | 268 } |
| 266 | 269 |
| 267 # Main | 270 # Main |
| 268 # ---------------------------------------------------------------------------- | 271 # ---------------------------------------------------------------------------- |
| 269 main() { | 272 main() { |
| 270 local num_signed=0 | 273 local num_signed=0 |
| 274 local num_given=$(echo "$FLAGS_partitions" | wc -w) |
| 271 # Check parameters | 275 # Check parameters |
| 272 KERNEL_KEYBLOCK="$FLAGS_keys/kernel.keyblock" | 276 KERNEL_KEYBLOCK="$FLAGS_keys/kernel.keyblock" |
| 273 KERNEL_DATAKEY="$FLAGS_keys/kernel_data_key.vbprivk" | 277 KERNEL_DATAKEY="$FLAGS_keys/kernel_data_key.vbprivk" |
| 274 KERNEL_PUBKEY="$FLAGS_keys/kernel_subkey.vbpubk" | 278 KERNEL_PUBKEY="$FLAGS_keys/kernel_subkey.vbpubk" |
| 275 | 279 |
| 276 debug_msg "Prerequisite check" | 280 debug_msg "Prerequisite check" |
| 277 ensure_files_exist \ | 281 ensure_files_exist \ |
| 278 "$KERNEL_KEYBLOCK" \ | 282 "$KERNEL_KEYBLOCK" \ |
| 279 "$KERNEL_DATAKEY" \ | 283 "$KERNEL_DATAKEY" \ |
| 280 "$KERNEL_PUBKEY" \ | 284 "$KERNEL_PUBKEY" \ |
| 281 "$FLAGS_image" || | 285 "$FLAGS_image" || |
| 282 exit 1 | 286 exit 1 |
| 283 | 287 |
| 284 resign_ssd_kernel "$FLAGS_image" || num_signed=$? | 288 resign_ssd_kernel "$FLAGS_image" || num_signed=$? |
| 285 | 289 |
| 286 debug_msg "Complete." | 290 debug_msg "Complete." |
| 287 if [ $num_signed -gt 0 -a $num_signed -le 2 ]; then | 291 if [ $num_signed -gt 0 -a $num_signed -le $num_given ]; then |
| 288 # signed 1 or two kernels | 292 # signed something at least |
| 289 echo "Successfully re-signed $num_signed kernel(s) on device $FLAGS_image". | 293 echo "Successfully re-signed $num_signed of $num_given kernel(s)" \ |
| 294 " on device $FLAGS_image". |
| 290 else | 295 else |
| 291 err_die "Failed re-signing kernels." | 296 err_die "Failed re-signing kernels." |
| 292 fi | 297 fi |
| 293 } | 298 } |
| 294 | 299 |
| 295 main | 300 main |
| OLD | NEW |