Will Drewry | 69563b7 | 2010-06-24 16:12:58 -0500 | [diff] [blame] | 1 | #!/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 | |
| 11 | get_default_board |
| 12 | |
| 13 | # Flags. |
| 14 | DEFINE_string arch "x86" \ |
| 15 | "The boot architecture: arm or x86. (Default: x86)" |
| 16 | DEFINE_string to "/tmp/vmlinuz.image" \ |
| 17 | "The path to the kernel image to be created. (Default: /tmp/vmlinuz.image)" |
| 18 | DEFINE_string vmlinuz "vmlinuz" \ |
| 19 | "The path to the kernel (Default: vmlinuz)" |
| 20 | DEFINE_string working_dir "/tmp/vmlinuz.working" \ |
| 21 | "Working directory for in-progress files. (Default: /tmp/vmlinuz.working)" |
| 22 | DEFINE_boolean keep_work ${FLAGS_FALSE} \ |
| 23 | "Keep temporary files (*.keyblock, *.vbpubk). (Default: false)" |
| 24 | DEFINE_string keys_dir "${SRC_ROOT}/platform/vboot_reference/tests/testkeys" \ |
Bill Richardson | 2ace49e | 2010-07-01 10:23:27 -0700 | [diff] [blame^] | 25 | "Directory with the RSA signing keys. (Defaults to test keys)" |
Will Drewry | 69563b7 | 2010-06-24 16:12:58 -0500 | [diff] [blame] | 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 |
| 29 | DEFINE_string boot_args "noinitrd" \ |
| 30 | "Additional boot arguments to pass to the commandline (Default: noinitrd)" |
| 31 | DEFINE_string root "/dev/sd%D%P" \ |
| 32 | "Expected device root (Default: root=/dev/sd%D%P)" |
| 33 | |
| 34 | # Parse flags |
| 35 | FLAGS "$@" || exit 1 |
| 36 | eval set -- "${FLAGS_ARGV}" |
| 37 | |
| 38 | # Die on error |
| 39 | set -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. |
| 43 | if [[ "${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. |
| 49 | mkdir -p ${FLAGS_working_dir} |
| 50 | cat <<EOF > "${FLAGS_working_dir}/config.txt" |
| 51 | earlyprintk=serial,ttyS0,115200 |
| 52 | console=ttyS0,115200 |
| 53 | init=/sbin/init |
| 54 | add_efi_memmap |
| 55 | boot=local |
| 56 | rootwait |
| 57 | root=${FLAGS_root} |
| 58 | ro |
| 59 | noresume |
| 60 | noswap |
| 61 | i915.modeset=1 |
| 62 | loglevel=7 |
| 63 | cros_secure |
| 64 | ${FLAGS_boot_args} |
| 65 | EOF |
| 66 | WORK="${FLAGS_working_dir}/config.txt" |
| 67 | |
Bill Richardson | 2ace49e | 2010-07-01 10:23:27 -0700 | [diff] [blame^] | 68 | |
| 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 Drewry | 69563b7 | 2010-06-24 16:12:58 -0500 | [diff] [blame] | 73 | vbutil_key \ |
Bill Richardson | 2ace49e | 2010-07-01 10:23:27 -0700 | [diff] [blame^] | 74 | --pack "${FLAGS_working_dir}/kernel_data_key.vbpubk" \ |
| 75 | --key "${FLAGS_keys_dir}/key_rsa2048.keyb" \ |
Will Drewry | 69563b7 | 2010-06-24 16:12:58 -0500 | [diff] [blame] | 76 | --version 1 \ |
Bill Richardson | 2ace49e | 2010-07-01 10:23:27 -0700 | [diff] [blame^] | 77 | --algorithm 4 |
| 78 | WORK="${WORK} ${FLAGS_working_dir}/kernel_data_key.vbpubk" |
Will Drewry | 69563b7 | 2010-06-24 16:12:58 -0500 | [diff] [blame] | 79 | |
| 80 | vbutil_key \ |
Bill Richardson | 2ace49e | 2010-07-01 10:23:27 -0700 | [diff] [blame^] | 81 | --pack "${FLAGS_working_dir}/kernel_data_key.vbprivk" \ |
| 82 | --key "${FLAGS_keys_dir}/key_rsa2048.pem" \ |
| 83 | --algorithm 4 |
| 84 | WORK="${WORK} ${FLAGS_working_dir}/kernel_data_key.vbprivk" |
Will Drewry | 69563b7 | 2010-06-24 16:12:58 -0500 | [diff] [blame] | 85 | |
Bill Richardson | 2ace49e | 2010-07-01 10:23:27 -0700 | [diff] [blame^] | 86 | |
| 87 | # Wrap the kernel subkey pair, used for the kernel's keyblock |
| 88 | vbutil_key \ |
| 89 | --pack "${FLAGS_working_dir}/kernel_subkey.vbpubk" \ |
| 90 | --key "${FLAGS_keys_dir}/key_rsa4096.keyb" \ |
| 91 | --version 1 \ |
| 92 | --algorithm 8 |
| 93 | WORK="${WORK} ${FLAGS_working_dir}/kernel_subkey.vbpubk" |
| 94 | |
| 95 | vbutil_key \ |
| 96 | --pack "${FLAGS_working_dir}/kernel_subkey.vbprivk" \ |
| 97 | --key "${FLAGS_keys_dir}/key_rsa4096.pem" \ |
| 98 | --algorithm 8 |
| 99 | WORK="${WORK} ${FLAGS_working_dir}/kernel_subkey.vbprivk" |
| 100 | |
| 101 | |
| 102 | # Create the kernel keyblock, containing the kernel data key |
Will Drewry | 69563b7 | 2010-06-24 16:12:58 -0500 | [diff] [blame] | 103 | vbutil_keyblock \ |
Bill Richardson | 2ace49e | 2010-07-01 10:23:27 -0700 | [diff] [blame^] | 104 | --pack "${FLAGS_working_dir}/kernel.keyblock" \ |
| 105 | --datapubkey "${FLAGS_working_dir}/kernel_data_key.vbpubk" \ |
| 106 | --signprivate "${FLAGS_working_dir}/kernel_subkey.vbprivk" \ |
Randall Spangler | d51f39f | 2010-06-29 18:03:30 -0700 | [diff] [blame] | 107 | --flags 15 |
Bill Richardson | 2ace49e | 2010-07-01 10:23:27 -0700 | [diff] [blame^] | 108 | WORK="${WORK} ${FLAGS_working_dir}/kernel.keyblock" |
Will Drewry | 69563b7 | 2010-06-24 16:12:58 -0500 | [diff] [blame] | 109 | |
| 110 | # Verify the keyblock. |
| 111 | vbutil_keyblock \ |
Bill Richardson | 2ace49e | 2010-07-01 10:23:27 -0700 | [diff] [blame^] | 112 | --unpack "${FLAGS_working_dir}/kernel.keyblock" \ |
| 113 | --signpubkey "${FLAGS_working_dir}/kernel_subkey.vbpubk" |
Will Drewry | 69563b7 | 2010-06-24 16:12:58 -0500 | [diff] [blame] | 114 | |
Bill Richardson | 2ace49e | 2010-07-01 10:23:27 -0700 | [diff] [blame^] | 115 | # 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 Drewry | 69563b7 | 2010-06-24 16:12:58 -0500 | [diff] [blame] | 122 | vbutil_kernel \ |
| 123 | --pack "${FLAGS_to}" \ |
Bill Richardson | 2ace49e | 2010-07-01 10:23:27 -0700 | [diff] [blame^] | 124 | --keyblock "${FLAGS_working_dir}/kernel.keyblock" \ |
| 125 | --signprivate "${FLAGS_working_dir}/kernel_data_key.vbprivk" \ |
Will Drewry | 69563b7 | 2010-06-24 16:12:58 -0500 | [diff] [blame] | 126 | --version 1 \ |
| 127 | --config "${FLAGS_working_dir}/config.txt" \ |
| 128 | --bootloader /lib64/bootstub/bootstub.efi \ |
| 129 | --vmlinuz "${FLAGS_vmlinuz}" |
| 130 | |
| 131 | # And verify it. |
| 132 | vbutil_kernel \ |
| 133 | --verify "${FLAGS_to}" \ |
Bill Richardson | 2ace49e | 2010-07-01 10:23:27 -0700 | [diff] [blame^] | 134 | --signpubkey "${FLAGS_working_dir}/kernel_subkey.vbpubk" |
Will Drewry | 69563b7 | 2010-06-24 16:12:58 -0500 | [diff] [blame] | 135 | |
| 136 | else |
| 137 | # FIXME: For now, ARM just uses the unsigned kernel by itself. |
| 138 | cp -f "${FLAGS_vmlinuz}" "${FLAGS_to}" |
| 139 | fi |
| 140 | |
| 141 | set +e # cleanup failure is a-ok |
| 142 | |
| 143 | if [[ ${FLAGS_keep_work} -eq ${FLAGS_FALSE} ]]; then |
| 144 | echo "Cleaning up temporary files: ${WORK}" |
| 145 | rm ${WORK} |
| 146 | rmdir ${FLAGS_working_dir} |
| 147 | fi |
| 148 | |
| 149 | echo "Kernel partition image emitted: ${FLAGS_to}" |