Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/bin/sh | 1 #!/bin/sh |
| 2 # | 2 # |
| 3 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2011 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_minimal.sh" | 11 . "$SCRIPT_BASE/common_minimal.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="<auto>" |
|
Randall Spangler
2011/03/07 20:44:21
Using '<auto>' intentionally because it's hard to
Hung-Te
2011/03/08 01:21:46
Yes.
| |
| 18 DEFAULT_BACKUP_FOLDER='/mnt/stateful_partition/backups' | 18 DEFAULT_BACKUP_FOLDER='/mnt/stateful_partition/backups' |
| 19 DEFAULT_FIRMWARE_UPDATER='/usr/sbin/chromeos-firmwareupdate' | |
| 19 | 20 |
| 20 # DEFINE_string name default_value description flag | 21 # DEFINE_string name default_value description flag |
| 21 DEFINE_string from "" "Path of input file (empty for system live firmware)" "f" | 22 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" | 23 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" | 24 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" "" | 25 DEFINE_string bmpfv "$DEFAULT_BMPFV_FILE" \ |
| 26 "Path to the new bitmaps, <auto> to extract from system, empty to keep." "" | |
| 25 DEFINE_boolean force_backup \ | 27 DEFINE_boolean force_backup \ |
| 26 $FLAGS_TRUE "Create backup even if source is not live" "" | 28 $FLAGS_TRUE "Create backup even if source is not live" "" |
| 27 DEFINE_string backup_dir \ | 29 DEFINE_string backup_dir \ |
| 28 "$DEFAULT_BACKUP_FOLDER" "Path of directory to store firmware backups" "" | 30 "$DEFAULT_BACKUP_FOLDER" "Path of directory to store firmware backups" "" |
| 29 | 31 |
| 30 # Parse command line | 32 # Parse command line |
| 31 FLAGS "$@" || exit 1 | 33 FLAGS "$@" || exit 1 |
| 32 eval set -- "$FLAGS_ARGV" | 34 eval set -- "$FLAGS_ARGV" |
| 33 | 35 |
| 34 # Globals | 36 # Globals |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 # a "{GUID} DEV" will become "{GUID} " in that case. | 104 # a "{GUID} DEV" will become "{GUID} " in that case. |
| 103 | 105 |
| 104 if [ "$hwid" != "$hwid_no_dev" ]; then | 106 if [ "$hwid" != "$hwid_no_dev" ]; then |
| 105 hwid="$hwid_no_dev" | 107 hwid="$hwid_no_dev" |
| 106 fi | 108 fi |
| 107 local hwid_dev="$hwid DEV" | 109 local hwid_dev="$hwid DEV" |
| 108 debug_msg "echo_dev_hwid: [$1] -> [$hwid_dev]" | 110 debug_msg "echo_dev_hwid: [$1] -> [$hwid_dev]" |
| 109 echo "$hwid_dev" | 111 echo "$hwid_dev" |
| 110 } | 112 } |
| 111 | 113 |
| 114 # Explores compatible firmware bitmaps | |
| 115 explore_bmpfv() { | |
| 116 local tmp_folder="" | |
| 117 | |
| 118 if [ -s "$DEFAULT_FIRMWARE_UPDATER" ]; then | |
| 119 # try to extract from built-in firmware updater | |
| 120 debug_msg "found default firmware updater, trying to fetch bitmap..." | |
| 121 tmp_folder=$("$DEFAULT_FIRMWARE_UPDATER" --sb_extract | sed "s'[^/]*''") | |
| 122 debug_msg "updater resources extrated to: $tmp_folder" | |
| 123 | |
| 124 if [ -d "$tmp_folder" -a -s "$tmp_folder/bios.bin" ]; then | |
| 125 new_bmpfv="$tmp_folder/bmpfv.bin" | |
| 126 echo "$new_bmpfv" | |
| 127 gbb_utility --bmpfv="$new_bmpfv" "$tmp_folder/bios.bin" >/dev/null 2>&1 | |
| 128 else | |
| 129 debug_msg "failed to find valid BIOS image file." | |
| 130 fi | |
| 131 else | |
| 132 debug_msg "no firmware updater in system. not changing bitmaps." | |
| 133 fi | |
| 134 } | |
| 135 | |
| 112 # Main | 136 # Main |
| 113 # ---------------------------------------------------------------------------- | 137 # ---------------------------------------------------------------------------- |
| 114 main() { | 138 main() { |
| 115 # Check parameters | 139 # Check parameters |
| 116 local root_pubkey="$FLAGS_keys/root_key.vbpubk" | 140 local root_pubkey="$FLAGS_keys/root_key.vbpubk" |
| 117 local recovery_pubkey="$FLAGS_keys/recovery_key.vbpubk" | 141 local recovery_pubkey="$FLAGS_keys/recovery_key.vbpubk" |
| 118 local firmware_keyblock="$FLAGS_keys/firmware.keyblock" | 142 local firmware_keyblock="$FLAGS_keys/firmware.keyblock" |
| 119 local firmware_prvkey="$FLAGS_keys/firmware_data_key.vbprivk" | 143 local firmware_prvkey="$FLAGS_keys/firmware_data_key.vbprivk" |
| 120 local kernel_sub_pubkey="$FLAGS_keys/kernel_subkey.vbpubk" | 144 local kernel_sub_pubkey="$FLAGS_keys/kernel_subkey.vbpubk" |
| 121 local new_bmpfv="$FLAGS_bmpfv" | 145 local new_bmpfv="$FLAGS_bmpfv" |
| 122 local is_from_live=0 | 146 local is_from_live=0 |
| 123 local backup_image= | 147 local backup_image= |
| 148 local opt_bmpfv="" | |
| 149 | |
| 150 if [ "$new_bmpfv" = "$DEFAULT_BMPFV_FILE" ]; then | |
| 151 new_bmpfv=$(explore_bmpfv) && | |
| 152 debug_msg "Using bitmaps from $new_bmpfv" | |
| 153 fi | |
| 124 | 154 |
| 125 debug_msg "Prerequisite check" | 155 debug_msg "Prerequisite check" |
| 126 ensure_files_exist \ | 156 ensure_files_exist \ |
| 127 "$root_pubkey" \ | 157 "$root_pubkey" \ |
| 128 "$recovery_pubkey" \ | 158 "$recovery_pubkey" \ |
| 129 "$firmware_keyblock" \ | 159 "$firmware_keyblock" \ |
| 130 "$firmware_prvkey" \ | 160 "$firmware_prvkey" \ |
| 131 "$kernel_sub_pubkey" \ | 161 "$kernel_sub_pubkey" || |
| 132 "$new_bmpfv" || | |
| 133 exit 1 | 162 exit 1 |
| 134 | 163 |
| 164 if [ -n "$new_bmpfv" ]; then | |
| 165 opt_bmpfv="--bmpfv=$new_bmpfv" | |
| 166 ensure_files_exist "$new_bmpfv" || exit 1 | |
| 167 fi | |
| 168 | |
| 135 if [ -z "$FLAGS_from" ]; then | 169 if [ -z "$FLAGS_from" ]; then |
| 136 is_from_live=1 | 170 is_from_live=1 |
| 137 else | 171 else |
| 138 ensure_files_exist "$FLAGS_from" | 172 ensure_files_exist "$FLAGS_from" || exit 1 |
| 139 fi | 173 fi |
| 140 | 174 |
| 141 debug_msg "Checking software write protection status" | 175 debug_msg "Checking software write protection status" |
| 142 disable_write_protection || | 176 disable_write_protection || |
| 143 if is_debug_mode; then | 177 if is_debug_mode; then |
| 144 err_die "Failed to disable WP. Diagnose Message: $(cat "$EXEC_LOG")" | 178 err_die "Failed to disable WP. Diagnose Message: $(cat "$EXEC_LOG")" |
| 145 else | 179 else |
| 146 err_die "Write protection is still enabled. " \ | 180 err_die "Write protection is still enabled. " \ |
| 147 "Please verify that hardware write protection is disabled." | 181 "Please verify that hardware write protection is disabled." |
| 148 fi | 182 fi |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 170 | 204 |
| 171 debug_msg "Decide new HWID" | 205 debug_msg "Decide new HWID" |
| 172 if [ -z "$old_hwid" ]; then | 206 if [ -z "$old_hwid" ]; then |
| 173 err_die "Cannot find current HWID. (message: $(cat "$EXEC_LOG"))" | 207 err_die "Cannot find current HWID. (message: $(cat "$EXEC_LOG"))" |
| 174 fi | 208 fi |
| 175 local new_hwid="$(echo_dev_hwid "$old_hwid")" | 209 local new_hwid="$(echo_dev_hwid "$old_hwid")" |
| 176 | 210 |
| 177 debug_msg "Replace GBB parts (gbb_utility allows changing on-the-fly)" | 211 debug_msg "Replace GBB parts (gbb_utility allows changing on-the-fly)" |
| 178 gbb_utility --set \ | 212 gbb_utility --set \ |
| 179 --hwid="$new_hwid" \ | 213 --hwid="$new_hwid" \ |
| 180 --bmpfv="$new_bmpfv" \ | |
| 181 --rootkey="$root_pubkey" \ | 214 --rootkey="$root_pubkey" \ |
| 182 --recoverykey="$recovery_pubkey" \ | 215 --recoverykey="$recovery_pubkey" \ |
| 216 $opt_bmpfv \ | |
| 183 "$IMAGE" >"$EXEC_LOG" 2>&1 || | 217 "$IMAGE" >"$EXEC_LOG" 2>&1 || |
| 184 err_die "Failed to change GBB Data. (message: $(cat "$EXEC_LOG"))" | 218 err_die "Failed to change GBB Data. (message: $(cat "$EXEC_LOG"))" |
| 185 | 219 |
| 186 debug_msg "Resign the firmware code (A/B) with new keys" | 220 debug_msg "Resign the firmware code (A/B) with new keys" |
| 187 local unsigned_image="$(make_temp_file)" | 221 local unsigned_image="$(make_temp_file)" |
| 188 cp -f "$IMAGE" "$unsigned_image" | 222 cp -f "$IMAGE" "$unsigned_image" |
| 189 "$SCRIPT_BASE/resign_firmwarefd.sh" \ | 223 "$SCRIPT_BASE/resign_firmwarefd.sh" \ |
| 190 "$unsigned_image" \ | 224 "$unsigned_image" \ |
| 191 "$IMAGE" \ | 225 "$IMAGE" \ |
| 192 "$firmware_prvkey" \ | 226 "$firmware_prvkey" \ |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 236 | 270 |
| 237 debug_msg "Complete." | 271 debug_msg "Complete." |
| 238 if [ -z "$FLAGS_to" ]; then | 272 if [ -z "$FLAGS_to" ]; then |
| 239 echo "Successfully changed firmware to Developer Keys. New HWID: $new_hwid" | 273 echo "Successfully changed firmware to Developer Keys. New HWID: $new_hwid" |
| 240 else | 274 else |
| 241 echo "Firmware '$FLAGS_to' now uses Developer Keys. New HWID: $new_hwid" | 275 echo "Firmware '$FLAGS_to' now uses Developer Keys. New HWID: $new_hwid" |
| 242 fi | 276 fi |
| 243 } | 277 } |
| 244 | 278 |
| 245 main | 279 main |
| OLD | NEW |