summaryrefslogtreecommitdiff
path: root/scripts/image_signing/resign_image.sh
blob: 9cdc1deff75e0d45ecb34b2b6cb522c84d77c3d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash

# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# Standalone version of cros_resign_image.sh script from
# chromeos/src/scripts/bin/ for use on signing servers.

# Both the cgpt tool and vbutil_kernel should be in the system path.

# Load common constants and variables.
. "$(dirname "$0")/common.sh"

# Abort on error
set -e

# Check arguments
if [ $# -lt 4 ] || [ $# -gt 5 ] ; then
  echo "usage: $PROG src_bin dst_bin kernel_datakey kernel_keyblock [version]"
  exit 1
fi

# Make sure the tools we need are available.
for prereqs in vbutil_kernel cgpt;
do
  type -P "${prereqs}" &>/dev/null || \
    { echo "${prereqs} tool not found."; exit 1; }
done

SRC_BIN=$1
DST_BIN=$2
KERNEL_DATAKEY=$3
KERNEL_KEYBLOCK=$4
VERSION=$5

if [ -z $VERSION ]; then
  VERSION=1
fi
echo "Using kernel version: $VERSION"

temp_kimage=$(make_temp_file)
extract_image_partition ${SRC_BIN} 2 ${temp_kimage}
updated_kimage=$(make_temp_file)

vbutil_kernel --repack "${updated_kimage}" \
  --keyblock "${KERNEL_KEYBLOCK}" \
  --signprivate "${KERNEL_DATAKEY}" \
  --version "${VERSION}" \
  --oldblob "${temp_kimage}"

# Create a copy of the input image and put in the new vblock
cp "${SRC_BIN}" "${DST_BIN}"
replace_image_partition ${DST_BIN} 2 ${updated_kimage}
echo "New signed image was output to ${DST_BIN}"