summaryrefslogtreecommitdiff
path: root/scripts/image_signing/sign_firmware.sh
blob: 1d20e10cf089f4a7326f319c205b4b69a2cbdbea (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
#!/bin/bash

# Copyright (c) 2011 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.

# Wrapper script for re-signing a firmware image.

# Determine script directory
SCRIPT_DIR=$(dirname $0)

# Abort on error.
set -e

FIRMWARE_VERSION=1

if [ $# -ne 3 ]; then
  cat<<EOF
Usage: $0 <input_firmware> <key_dir> <output_firmware>

Signs <input_firmware> with keys in <key_dir> and outputs signed firmware to 
<output_firmware>.
EOF
  exit 1
fi

IN_FIRMWARE=$1
KEY_DIR=$2
OUT_FIRMWARE=$3

temp_fw=$(mktemp)
trap "rm ${temp_fw}" EXIT

# Replace the root and recovery key in the Google Binary Block of the firmware.
gbb_utility -s \
  --rootkey=${KEY_DIR}/root_key.vbpubk \
  --recoverykey=${KEY_DIR}/recovery_key.vbpubk \
  ${IN_FIRMWARE} ${temp_fw}

# Resign the firmware with new keys
${SCRIPT_DIR}/resign_firmwarefd.sh ${temp_fw} ${OUT_FIRMWARE} \
  ${KEY_DIR}/firmware_data_key.vbprivk \
  ${KEY_DIR}/firmware.keyblock \
  ${KEY_DIR}/dev_firmware_data_key.vbprivk \
  ${KEY_DIR}/dev_firmware.keyblock \
  ${KEY_DIR}/kernel_subkey.vbpubk \
  ${FIRMWARE_VERSION}