blob: d0c3599feaf5ad9c7e4da29f3daad325c2d2ed0f [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" \
25 "Directory with the signing keys. (Defaults to test keys)"
26# 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
68# Wrap the public keys with VbPublicKey headers.
69vbutil_key \
70 --pack \
71 --in "${FLAGS_keys_dir}/key_rsa2048.keyb" \
72 --version 1 \
73 --algorithm 4 \
74 --out "${FLAGS_working_dir}/key_alg4.vbpubk"
75WORK="${WORK} ${FLAGS_working_dir}/key_alg4.vbpubk"
76
77vbutil_key \
78 --pack \
79 --in "${FLAGS_keys_dir}/key_rsa4096.keyb" \
80 --version 1 \
81 --algorithm 8 \
82 --out "${FLAGS_working_dir}/key_alg8.vbpubk"
83WORK="${WORK} ${FLAGS_working_dir}/key_alg8.vbpubk"
84
85vbutil_keyblock \
86 --pack "${FLAGS_working_dir}/data4_sign8.keyblock" \
87 --datapubkey "${FLAGS_working_dir}/key_alg4.vbpubk" \
88 --signprivate "${FLAGS_keys_dir}/key_rsa4096.pem" \
89 --algorithm 8 \
Randall Spanglerd51f39f2010-06-29 18:03:30 -070090 --flags 15
Will Drewry69563b72010-06-24 16:12:58 -050091WORK="${WORK} ${FLAGS_working_dir}/data4_sign8.keyblock"
92
93# Verify the keyblock.
94vbutil_keyblock \
95 --unpack "${FLAGS_working_dir}/data4_sign8.keyblock" \
96 --signpubkey "${FLAGS_working_dir}/key_alg8.vbpubk"
97
98# Sign the kernel:
99vbutil_kernel \
100 --pack "${FLAGS_to}" \
101 --keyblock "${FLAGS_working_dir}/data4_sign8.keyblock" \
102 --signprivate "${FLAGS_keys_dir}/key_rsa2048.pem" \
103 --version 1 \
104 --config "${FLAGS_working_dir}/config.txt" \
105 --bootloader /lib64/bootstub/bootstub.efi \
106 --vmlinuz "${FLAGS_vmlinuz}"
107
108# And verify it.
109vbutil_kernel \
110 --verify "${FLAGS_to}" \
111 --signpubkey "${FLAGS_working_dir}/key_alg8.vbpubk"
112
113else
114 # FIXME: For now, ARM just uses the unsigned kernel by itself.
115 cp -f "${FLAGS_vmlinuz}" "${FLAGS_to}"
116fi
117
118set +e # cleanup failure is a-ok
119
120if [[ ${FLAGS_keep_work} -eq ${FLAGS_FALSE} ]]; then
121 echo "Cleaning up temporary files: ${WORK}"
122 rm ${WORK}
123 rmdir ${FLAGS_working_dir}
124fi
125
126echo "Kernel partition image emitted: ${FLAGS_to}"