OLD | NEW |
(Empty) | |
| 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" \ |
| 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 |
| 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 |
| 68 # Wrap the public keys with VbPublicKey headers. |
| 69 vbutil_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" |
| 75 WORK="${WORK} ${FLAGS_working_dir}/key_alg4.vbpubk" |
| 76 |
| 77 vbutil_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" |
| 83 WORK="${WORK} ${FLAGS_working_dir}/key_alg8.vbpubk" |
| 84 |
| 85 vbutil_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 \ |
| 90 --flags 3 |
| 91 WORK="${WORK} ${FLAGS_working_dir}/data4_sign8.keyblock" |
| 92 |
| 93 # Verify the keyblock. |
| 94 vbutil_keyblock \ |
| 95 --unpack "${FLAGS_working_dir}/data4_sign8.keyblock" \ |
| 96 --signpubkey "${FLAGS_working_dir}/key_alg8.vbpubk" |
| 97 |
| 98 # Sign the kernel: |
| 99 vbutil_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. |
| 109 vbutil_kernel \ |
| 110 --verify "${FLAGS_to}" \ |
| 111 --signpubkey "${FLAGS_working_dir}/key_alg8.vbpubk" |
| 112 |
| 113 else |
| 114 # FIXME: For now, ARM just uses the unsigned kernel by itself. |
| 115 cp -f "${FLAGS_vmlinuz}" "${FLAGS_to}" |
| 116 fi |
| 117 |
| 118 set +e # cleanup failure is a-ok |
| 119 |
| 120 if [[ ${FLAGS_keep_work} -eq ${FLAGS_FALSE} ]]; then |
| 121 echo "Cleaning up temporary files: ${WORK}" |
| 122 rm ${WORK} |
| 123 rmdir ${FLAGS_working_dir} |
| 124 fi |
| 125 |
| 126 echo "Kernel partition image emitted: ${FLAGS_to}" |
OLD | NEW |