| OLD | NEW |
| 1 #!/bin/bash | 1 #!/bin/bash |
| 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 # Standalone version of cros_resign_image.sh script from | 7 # Standalone version of cros_resign_image.sh script from |
| 8 # from chromeos/src/scripts/bin/ for use on signing servers. | 8 # chromeos/src/scripts/bin/ for use on signing servers. |
| 9 | 9 |
| 10 # Both the cgpt tool and vbutil_kernel should be in the system path. | 10 # Both the cgpt tool and vbutil_kernel should be in the system path. |
| 11 | 11 |
| 12 # Abort on error | 12 # Abort on error |
| 13 set -e | 13 set -e |
| 14 | 14 |
| 15 # Check arguments | 15 # Check arguments |
| 16 if [ $# -ne 4 ] ; then | 16 if [ $# -ne 4 ] ; then |
| 17 echo "usage: $0 src_bin dst_bin kernel_datakey kernel_keyblock" | 17 echo "usage: $0 src_bin dst_bin kernel_datakey kernel_keyblock" |
| 18 exit 1 | 18 exit 1 |
| 19 fi | 19 fi |
| 20 | 20 |
| 21 # Make sure the tools we need are available. | 21 # Make sure the tools we need are available. |
| 22 type -P cgpt &>/dev/null || \ | 22 type -P cgpt &>/dev/null || \ |
| 23 { echo "cgpt tool not found."; exit 1; } | 23 { echo "cgpt tool not found."; exit 1; } |
| 24 type -P vbutil_kernel &>/dev/null || \ | 24 type -P vbutil_kernel &>/dev/null || \ |
| 25 { echo "vbutil_kernel tool not found."; exit 1; } | 25 { echo "vbutil_kernel tool not found."; exit 1; } |
| 26 | 26 |
| 27 sector_size=512 # sector size in bytes | 27 sector_size=512 # sector size in bytes |
| 28 num_sectors_vb=128 # number of sectors in kernel verification blob | 28 num_sectors_vb=128 # number of sectors in kernel verification blob |
| 29 src_bin=$1 | 29 src_bin=$1 |
| 30 dst_bin=$2 | 30 dst_bin=$2 |
| 31 datakey=$3 | 31 kernel_datakey=$3 |
| 32 keyblock=$4 | 32 kernel_keyblock=$4 |
| 33 | 33 |
| 34 koffset="$(cgpt show -b -i 2 $1)" | 34 koffset="$(cgpt show -b -i 2 $1)" |
| 35 ksize="$(cgpt show -s -i 2 $1)" | 35 ksize="$(cgpt show -s -i 2 $1)" |
| 36 | 36 |
| 37 echo "Re-signing image ${src_bin} and outputting ${dst_bin}" | 37 echo "Re-signing image ${src_bin} and outputting ${dst_bin}" |
| 38 temp_kimage=$(mktemp) | 38 temp_kimage=$(mktemp) |
| 39 trap "rm -f ${temp_kimage}" EXIT | 39 trap "rm -f ${temp_kimage}" EXIT |
| 40 temp_out_vb=$(mktemp) | 40 temp_out_vb=$(mktemp) |
| 41 trap "rm -f ${temp_out_vb}" EXIT | 41 trap "rm -f ${temp_out_vb}" EXIT |
| 42 | 42 |
| 43 # Grab the kernel image in preparation for resigning | 43 # Grab the kernel image in preparation for resigning |
| 44 dd if="${src_bin}" of="${temp_kimage}" skip=$koffset bs=$sector_size \ | 44 dd if="${src_bin}" of="${temp_kimage}" skip=$koffset bs=$sector_size \ |
| 45 count=$ksize | 45 count=$ksize |
| 46 vbutil_kernel \ | 46 vbutil_kernel \ |
| 47 --repack "${temp_out_vb}" \ | 47 --repack "${temp_out_vb}" \ |
| 48 --vblockonly \ | 48 --vblockonly \ |
| 49 --keyblock "${kernel_keyblock}" \ | 49 --keyblock "${kernel_keyblock}" \ |
| 50 --signprivate "${kernel_datakey}" \ | 50 --signprivate "${kernel_datakey}" \ |
| 51 --oldblob "${temp_kimage}" | 51 --oldblob "${temp_kimage}" |
| 52 | 52 |
| 53 # Create a copy of the input image and put in the new vblock | 53 # Create a copy of the input image and put in the new vblock |
| 54 cp "${src_bin}" "${dst_bin}" | 54 cp "${src_bin}" "${dst_bin}" |
| 55 dd if="${temp_out_vb}" of="${dst_bin}" seek=$koffset bs=$sector_size \ | 55 dd if="${temp_out_vb}" of="${dst_bin}" seek=$koffset bs=$sector_size \ |
| 56 count=$num_sectors_vb conv=notrunc | 56 count=$num_sectors_vb conv=notrunc |
| 57 | 57 |
| 58 echo "New signed image was output to ${dst_bin}" | 58 echo "New signed image was output to ${dst_bin}" |
| 59 | 59 |
| OLD | NEW |