| 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) in a firmware binary | 7 # This script can change key (usually developer keys) in a firmware binary |
| 8 # image or system live firmware (EEPROM), and assign proper HWID, BMPFV as well. | 8 # image or system live firmware (EEPROM), and assign proper HWID, BMPFV as well. |
| 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_BMPFV_FILE="$DEFAULT_KEYS_FOLDER/firmware_bmpfv.bin" | 17 DEFAULT_BMPFV_FILE="$DEFAULT_KEYS_FOLDER/firmware_bmpfv.bin" |
| 18 DEFAULT_BACKUP_FOLDER='/mnt/stateful_partition/backups' | 18 DEFAULT_BACKUP_FOLDER='/mnt/stateful_partition/backups' |
| 19 | 19 |
| 20 # DEFINE_string name default_value description flag | 20 # DEFINE_string name default_value description flag |
| 21 DEFINE_string from "" "Path of input file (empty for system live firmware)" "f" | 21 DEFINE_string from "" "Path of input file (empty for system live firmware)" "f" |
| 22 DEFINE_string to "" "Path of output file (empty for system live firmware)" "t" | 22 DEFINE_string to "" "Path of output file (empty for system live firmware)" "t" |
| 23 DEFINE_string keys "$DEFAULT_KEYS_FOLDER" "Path to folder of dev keys" "k" | 23 DEFINE_string keys "$DEFAULT_KEYS_FOLDER" "Path to folder of dev keys" "k" |
| 24 DEFINE_string bmpfv "$DEFAULT_BMPFV_FILE" "Path to the new bitmap FV" "" | 24 DEFINE_string bmpfv "$DEFAULT_BMPFV_FILE" "Path to the new bitmap FV" "" |
| 25 DEFINE_boolean force_backup \ | 25 DEFINE_boolean force_backup \ |
| 26 $FLAGS_TRUE "Create backup even if source is not live" "" | 26 $FLAGS_TRUE "Create backup even if source is not live" "" |
| 27 DEFINE_string backup_dir \ | 27 DEFINE_string backup_dir \ |
| 28 "$DEFAULT_BACKUP_FOLDER" "Path of directory to store firmware backups" "" | 28 "$DEFAULT_BACKUP_FOLDER" "Path of directory to store firmware backups" "" |
| 29 DEFINE_boolean debug $FLAGS_FALSE "Provide debug messages" "d" | |
| 30 | 29 |
| 31 # Parse command line | 30 # Parse command line |
| 32 FLAGS "$@" || exit 1 | 31 FLAGS "$@" || exit 1 |
| 33 eval set -- "$FLAGS_ARGV" | 32 eval set -- "$FLAGS_ARGV" |
| 34 | 33 |
| 35 # Globals | 34 # Globals |
| 36 # ---------------------------------------------------------------------------- | 35 # ---------------------------------------------------------------------------- |
| 37 set -e | 36 set -e |
| 38 | 37 |
| 39 # the image we are (temporary) working with | 38 # the image we are (temporary) working with |
| 40 IMAGE="$(make_temp_file)" | 39 IMAGE="$(make_temp_file)" |
| 41 | 40 |
| 42 # a log file to keep the output results of executed command | 41 # a log file to keep the output results of executed command |
| 43 EXEC_LOG="$(make_temp_file)" | 42 EXEC_LOG="$(make_temp_file)" |
| 44 | 43 |
| 45 # Functions | 44 # Functions |
| 46 # ---------------------------------------------------------------------------- | 45 # ---------------------------------------------------------------------------- |
| 47 # Reports error message and exit(1) | |
| 48 err_die() { | |
| 49 echo "ERROR: $*" 1>&2 | |
| 50 exit 1 | |
| 51 } | |
| 52 | |
| 53 # Returns true if we're running in debug mode | |
| 54 is_debug_mode() { | |
| 55 [ "$FLAGS_debug" = $FLAGS_TRUE ] | |
| 56 } | |
| 57 | |
| 58 # Prints messages (in parameters) in debug mode | |
| 59 debug_msg() { | |
| 60 if is_debug_mode; then | |
| 61 echo "DEBUG: $*" 1>&2 | |
| 62 fi | |
| 63 } | |
| 64 | 46 |
| 65 # Reads $IMAGE from $FLAGS_from | 47 # Reads $IMAGE from $FLAGS_from |
| 66 read_image() { | 48 read_image() { |
| 67 if [ -z "$FLAGS_from" ]; then | 49 if [ -z "$FLAGS_from" ]; then |
| 68 echo "Reading system live firmware..." | 50 echo "Reading system live firmware..." |
| 69 if is_debug_mode; then | 51 if is_debug_mode; then |
| 70 flashrom -V -r "$IMAGE" | 52 flashrom -V -r "$IMAGE" |
| 71 else | 53 else |
| 72 flashrom -r "$IMAGE" >"$EXEC_LOG" 2>&1 | 54 flashrom -r "$IMAGE" >"$EXEC_LOG" 2>&1 |
| 73 fi | 55 fi |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 | 214 |
| 233 debug_msg "Complete." | 215 debug_msg "Complete." |
| 234 if [ -z "$FLAGS_to" ]; then | 216 if [ -z "$FLAGS_to" ]; then |
| 235 echo "Successfully changed firmware to Developer Keys. New HWID: $new_hwid" | 217 echo "Successfully changed firmware to Developer Keys. New HWID: $new_hwid" |
| 236 else | 218 else |
| 237 echo "Firmware '$FLAGS_to' now uses Developer Keys. New HWID: $new_hwid" | 219 echo "Firmware '$FLAGS_to' now uses Developer Keys. New HWID: $new_hwid" |
| 238 fi | 220 fi |
| 239 } | 221 } |
| 240 | 222 |
| 241 main | 223 main |
| OLD | NEW |