| OLD | NEW |
| 1 #!/bin/bash | 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 # Script to resign a firmware image using a different set of keys | 7 # Script to resign a firmware image using a different set of keys |
| 8 # for use on signing servers. | 8 # for use on signing servers. |
| 9 # | 9 # |
| 10 # arguments: src_fd, dst_fd, firmware_datakey, and firmware_keyblock | 10 # arguments: src_fd, dst_fd, firmware_datakey, and firmware_keyblock |
| 11 # | 11 # |
| (...skipping 29 matching lines...) Expand all Loading... |
| 41 # area_flags_raw="0x03" area_flags="static,compressed" | 41 # area_flags_raw="0x03" area_flags="static,compressed" |
| 42 # area_offset="0x00005200" area_size="0x00001000" area_name="RW VPD" \ | 42 # area_offset="0x00005200" area_size="0x00001000" area_name="RW VPD" \ |
| 43 # area_flags_raw="0x00" area_flags="" | 43 # area_flags_raw="0x00" area_flags="" |
| 44 # | 44 # |
| 45 # This shows that Firmware A Data is at offset 0x0000a0000 in the .fd image | 45 # This shows that Firmware A Data is at offset 0x0000a0000 in the .fd image |
| 46 # and is of size 0x0009e000 bytes. This can be extracted to generate new vblocks | 46 # and is of size 0x0009e000 bytes. This can be extracted to generate new vblocks |
| 47 # which can then replace old vblock for Firmware A ("Firmware A Key" region at | 47 # which can then replace old vblock for Firmware A ("Firmware A Key" region at |
| 48 # offset 0x00008000 and size 0x00002000). | 48 # offset 0x00008000 and size 0x00002000). |
| 49 | 49 |
| 50 # Load common constants and variables. | 50 # Load common constants and variables. |
| 51 . "$(dirname "$0")/common.sh" | 51 . "$(dirname "$0")/common_minimal.sh" |
| 52 | 52 |
| 53 # Abort on error | 53 # Abort on error |
| 54 set -e | 54 set -e |
| 55 | 55 |
| 56 # Check arguments | 56 # Check arguments |
| 57 if [ $# -ne 5 ] ; then | 57 if [ $# -ne 5 ] ; then |
| 58 echo \ | 58 echo \ |
| 59 "Usage: $0 src_fd dst_fd firmware_datakey firmware_keyblock kernel_subkey" | 59 "Usage: $0 src_fd dst_fd firmware_datakey firmware_keyblock kernel_subkey" |
| 60 exit 1 | 60 exit 1 |
| 61 fi | 61 fi |
| 62 | 62 |
| 63 # Make sure the tools we need are available. | 63 # Make sure the tools we need are available. |
| 64 for prog in mosys vbutil_firmware; do | 64 for prog in mosys vbutil_firmware; do |
| 65 type -P "${prog}" &>/dev/null || \ | 65 type "${prog}" &>/dev/null || \ |
| 66 { echo "${prog} tool not found."; exit 1; } | 66 { echo "${prog} tool not found."; exit 1; } |
| 67 done | 67 done |
| 68 | 68 |
| 69 src_fd=$1 | 69 src_fd=$1 |
| 70 dst_fd=$2 | 70 dst_fd=$2 |
| 71 firmware_datakey=$3 | 71 firmware_datakey=$3 |
| 72 firmware_keyblock=$4 | 72 firmware_keyblock=$4 |
| 73 kernel_subkey=$5 | 73 kernel_subkey=$5 |
| 74 | 74 |
| 75 # TODO(gauravsh): Figure out where the version comes from. | 75 # TODO(gauravsh): Figure out where the version comes from. |
| 76 # Do we rev it manually? | 76 # Do we rev it manually? |
| 77 VERSION=1 | 77 VERSION=1 |
| 78 | 78 |
| 79 # Parse offsets and size of firmware data and vblocks | 79 # Parse offsets and size of firmware data and vblocks |
| 80 for i in "A" "B" | 80 for i in "A" "B" |
| 81 do | 81 do |
| 82 match_str="$i Key" | 82 match_str="$i Key" |
| 83 line=$(mosys -f -k eeprom map $1 | grep "$match_str") | 83 line=$(mosys -f -k eeprom map $1 | grep "$match_str") |
| 84 offset="$(echo $line | sed -e 's/.*area_offset=\"\([a-f0-9x]*\)\".*/\1/')" | 84 offset="$(echo $line | sed -e 's/.*area_offset=\"\([a-f0-9x]*\)\".*/\1/')" |
| 85 eval let \ | 85 eval fw${i}_vblock_offset=$((offset)) |
| 86 fw${i}_vblock_offset="$offset" | |
| 87 size="$(echo $line | sed -e 's/.*area_size=\"\([a-f0-9x]*\)\".*/\1/')" | 86 size="$(echo $line | sed -e 's/.*area_size=\"\([a-f0-9x]*\)\".*/\1/')" |
| 88 eval let \ | 87 eval fw${i}_vblock_size=$((size)) |
| 89 fw${i}_vblock_size="$size" | |
| 90 | 88 |
| 91 match_str="$i Data" | 89 match_str="$i Data" |
| 92 line=$(mosys -f -k eeprom map $1 | grep "$match_str") | 90 line=$(mosys -f -k eeprom map $1 | grep "$match_str") |
| 93 offset="$(echo $line | sed -e 's/.*area_offset=\"\([a-f0-9x]*\)\".*/\1/')" | 91 offset="$(echo $line | sed -e 's/.*area_offset=\"\([a-f0-9x]*\)\".*/\1/')" |
| 94 eval let \ | 92 eval fw${i}_offset=$((offset)) |
| 95 fw${i}_offset="$offset" | |
| 96 size="$(echo $line | sed -e 's/.*area_size=\"\([a-f0-9x]*\)\".*/\1/')" | 93 size="$(echo $line | sed -e 's/.*area_size=\"\([a-f0-9x]*\)\".*/\1/')" |
| 97 eval let \ | 94 eval fw${i}_size=$((size)) |
| 98 fw${i}_size="$size" | |
| 99 done | 95 done |
| 100 | 96 |
| 101 temp_fwimage=$(make_temp_file) | 97 temp_fwimage=$(make_temp_file) |
| 102 temp_out_vb=$(make_temp_file) | 98 temp_out_vb=$(make_temp_file) |
| 103 | 99 |
| 104 # Extract out Firmware A data and generate signature using the right keys | 100 # Extract out Firmware A data and generate signature using the right keys |
| 105 dd if="${src_fd}" of="${temp_fwimage}" skip="${fwA_offset}" bs=1 \ | 101 dd if="${src_fd}" of="${temp_fwimage}" skip="${fwA_offset}" bs=1 \ |
| 106 count="${fwA_size}" | 102 count="${fwA_size}" |
| 107 | 103 |
| 108 echo "Re-calculating Firmware A vblock" | 104 echo "Re-calculating Firmware A vblock" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 129 --signprivate "${firmware_datakey}" \ | 125 --signprivate "${firmware_datakey}" \ |
| 130 --version "${VERSION}" \ | 126 --version "${VERSION}" \ |
| 131 --fv "${temp_fwimage}" \ | 127 --fv "${temp_fwimage}" \ |
| 132 --kernelkey "${kernel_subkey}" | 128 --kernelkey "${kernel_subkey}" |
| 133 | 129 |
| 134 # Destination image has already been created. | 130 # Destination image has already been created. |
| 135 dd if="${temp_out_vb}" of="${dst_fd}" seek="${fwB_vblock_offset}" bs=1 \ | 131 dd if="${temp_out_vb}" of="${dst_fd}" seek="${fwB_vblock_offset}" bs=1 \ |
| 136 count="${fwB_vblock_size}" conv=notrunc | 132 count="${fwB_vblock_size}" conv=notrunc |
| 137 | 133 |
| 138 echo "New signed image was output to ${dst_fd}" | 134 echo "New signed image was output to ${dst_fd}" |
| OLD | NEW |