blob: e7e771160c32825a8655069e4e0a15a976b9da36 [file] [log] [blame]
Will Drewry69563b72010-06-24 16:12:58 -05001#!/bin/bash
2
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
5# found in the LICENSE file.
6
7# Helper script that generates the signed kernel image
8
9. "$(dirname "$0")/common.sh"
10
11get_default_board
12
13# Flags.
14DEFINE_string arch "x86" \
15 "The boot architecture: arm or x86. (Default: x86)"
16DEFINE_string to "/tmp/vmlinuz.image" \
17 "The path to the kernel image to be created. (Default: /tmp/vmlinuz.image)"
18DEFINE_string vmlinuz "vmlinuz" \
19 "The path to the kernel (Default: vmlinuz)"
20DEFINE_string working_dir "/tmp/vmlinuz.working" \
21 "Working directory for in-progress files. (Default: /tmp/vmlinuz.working)"
22DEFINE_boolean keep_work ${FLAGS_FALSE} \
23 "Keep temporary files (*.keyblock, *.vbpubk). (Default: false)"
24DEFINE_string keys_dir "${SRC_ROOT}/platform/vboot_reference/tests/testkeys" \
Bill Richardson2ace49e2010-07-01 10:23:27 -070025 "Directory with the RSA signing keys. (Defaults to test keys)"
Will Drewry69563b72010-06-24 16:12:58 -050026# Note, to enable verified boot, the caller would pass:
27# --boot_args='dm="... /dev/sd%D%P /dev/sd%D%P ..." \
28# --root=/dev/dm-0
29DEFINE_string boot_args "noinitrd" \
30 "Additional boot arguments to pass to the commandline (Default: noinitrd)"
31DEFINE_string root "/dev/sd%D%P" \
32 "Expected device root (Default: root=/dev/sd%D%P)"
33
34# Parse flags
35FLAGS "$@" || exit 1
36eval set -- "${FLAGS_ARGV}"
37
38# Die on error
39set -e
40
41# FIXME: At the moment, we're working on signed images for x86 only. ARM will
42# support this before shipping, but at the moment they don't.
43if [[ "${FLAGS_arch}" = "x86" ]]; then
44
45# Legacy BIOS will use the kernel in the rootfs (via syslinux), as will
46# standard EFI BIOS (via grub, from the EFI System Partition). Chrome OS
47# BIOS will use a separate signed kernel partition, which we'll create now.
48# FIXME: remove serial output, debugging messages.
49mkdir -p ${FLAGS_working_dir}
50cat <<EOF > "${FLAGS_working_dir}/config.txt"
51earlyprintk=serial,ttyS0,115200
52console=ttyS0,115200
53init=/sbin/init
54add_efi_memmap
55boot=local
56rootwait
57root=${FLAGS_root}
58ro
59noresume
60noswap
61i915.modeset=1
62loglevel=7
63cros_secure
64${FLAGS_boot_args}
65EOF
66WORK="${FLAGS_working_dir}/config.txt"
67
Bill Richardson2ace49e2010-07-01 10:23:27 -070068
69# FIX: The .vbprivk files are not encrypted, so we shouldn't just leave them
70# lying around as a general thing.
71
72# Wrap the kernel data keypair, used for the kernel body
Will Drewry69563b72010-06-24 16:12:58 -050073vbutil_key \
Bill Richardson2ace49e2010-07-01 10:23:27 -070074 --pack "${FLAGS_working_dir}/kernel_data_key.vbpubk" \
75 --key "${FLAGS_keys_dir}/key_rsa2048.keyb" \
Will Drewry69563b72010-06-24 16:12:58 -050076 --version 1 \
Bill Richardson2ace49e2010-07-01 10:23:27 -070077 --algorithm 4
78WORK="${WORK} ${FLAGS_working_dir}/kernel_data_key.vbpubk"
Will Drewry69563b72010-06-24 16:12:58 -050079
80vbutil_key \
Bill Richardson2ace49e2010-07-01 10:23:27 -070081 --pack "${FLAGS_working_dir}/kernel_data_key.vbprivk" \
82 --key "${FLAGS_keys_dir}/key_rsa2048.pem" \
83 --algorithm 4
84WORK="${WORK} ${FLAGS_working_dir}/kernel_data_key.vbprivk"
Will Drewry69563b72010-06-24 16:12:58 -050085
Bill Richardson2ace49e2010-07-01 10:23:27 -070086
87# Wrap the kernel subkey pair, used for the kernel's keyblock
88vbutil_key \
89 --pack "${FLAGS_working_dir}/kernel_subkey.vbpubk" \
90 --key "${FLAGS_keys_dir}/key_rsa4096.keyb" \
91 --version 1 \
92 --algorithm 8
93WORK="${WORK} ${FLAGS_working_dir}/kernel_subkey.vbpubk"
94
95vbutil_key \
96 --pack "${FLAGS_working_dir}/kernel_subkey.vbprivk" \
97 --key "${FLAGS_keys_dir}/key_rsa4096.pem" \
98 --algorithm 8
99WORK="${WORK} ${FLAGS_working_dir}/kernel_subkey.vbprivk"
100
101
102# Create the kernel keyblock, containing the kernel data key
Will Drewry69563b72010-06-24 16:12:58 -0500103vbutil_keyblock \
Bill Richardson2ace49e2010-07-01 10:23:27 -0700104 --pack "${FLAGS_working_dir}/kernel.keyblock" \
105 --datapubkey "${FLAGS_working_dir}/kernel_data_key.vbpubk" \
106 --signprivate "${FLAGS_working_dir}/kernel_subkey.vbprivk" \
Randall Spanglerd51f39f2010-06-29 18:03:30 -0700107 --flags 15
Bill Richardson2ace49e2010-07-01 10:23:27 -0700108WORK="${WORK} ${FLAGS_working_dir}/kernel.keyblock"
Will Drewry69563b72010-06-24 16:12:58 -0500109
110# Verify the keyblock.
111vbutil_keyblock \
Bill Richardson2ace49e2010-07-01 10:23:27 -0700112 --unpack "${FLAGS_working_dir}/kernel.keyblock" \
113 --signpubkey "${FLAGS_working_dir}/kernel_subkey.vbpubk"
Will Drewry69563b72010-06-24 16:12:58 -0500114
Bill Richardson2ace49e2010-07-01 10:23:27 -0700115# TODO: We should sign the kernel blob using the recovery root key and recovery
116# kernel data key instead (to create the recovery image), and then re-sign it
117# this way for the install image. But we'll want to keep the install vblock
118# separate, so we can just copy that part over separately when we install it
119# instead of the whole kernel blob.
120
121# Create and sign the kernel blob
Will Drewry69563b72010-06-24 16:12:58 -0500122vbutil_kernel \
123 --pack "${FLAGS_to}" \
Bill Richardson2ace49e2010-07-01 10:23:27 -0700124 --keyblock "${FLAGS_working_dir}/kernel.keyblock" \
125 --signprivate "${FLAGS_working_dir}/kernel_data_key.vbprivk" \
Will Drewry69563b72010-06-24 16:12:58 -0500126 --version 1 \
127 --config "${FLAGS_working_dir}/config.txt" \
128 --bootloader /lib64/bootstub/bootstub.efi \
129 --vmlinuz "${FLAGS_vmlinuz}"
130
131# And verify it.
132vbutil_kernel \
133 --verify "${FLAGS_to}" \
Bill Richardson2ace49e2010-07-01 10:23:27 -0700134 --signpubkey "${FLAGS_working_dir}/kernel_subkey.vbpubk"
Will Drewry69563b72010-06-24 16:12:58 -0500135
136else
137 # FIXME: For now, ARM just uses the unsigned kernel by itself.
138 cp -f "${FLAGS_vmlinuz}" "${FLAGS_to}"
139fi
140
141set +e # cleanup failure is a-ok
142
143if [[ ${FLAGS_keep_work} -eq ${FLAGS_FALSE} ]]; then
144 echo "Cleaning up temporary files: ${WORK}"
145 rm ${WORK}
146 rmdir ${FLAGS_working_dir}
147fi
148
149echo "Kernel partition image emitted: ${FLAGS_to}"