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 | |
Brian Harring | aa13ea4 | 2012-03-15 18:31:03 -0700 | [diff] [blame] | 9 | SCRIPT_ROOT=$(dirname $(readlink -f "$0")) |
David James | 359d3e1 | 2012-07-10 13:09:48 -0700 | [diff] [blame] | 10 | . "${SCRIPT_ROOT}/common.sh" || exit 1 |
Will Drewry | 69563b7 | 2010-06-24 16:12:58 -0500 | [diff] [blame] | 11 | |
Will Drewry | 69563b7 | 2010-06-24 16:12:58 -0500 | [diff] [blame] | 12 | # Flags. |
| 13 | DEFINE_string arch "x86" \ |
Sonny Rao | 0679b36 | 2011-10-12 13:53:19 -0700 | [diff] [blame] | 14 | "The boot architecture: arm, x86, or amd64. (Default: x86)" |
Will Drewry | 69563b7 | 2010-06-24 16:12:58 -0500 | [diff] [blame] | 15 | DEFINE_string to "/tmp/vmlinuz.image" \ |
| 16 | "The path to the kernel image to be created. (Default: /tmp/vmlinuz.image)" |
Louis Yung-Chieh Lo | 3602040 | 2010-07-05 13:23:34 +0800 | [diff] [blame] | 17 | DEFINE_string hd_vblock "/tmp/vmlinuz_hd.vblock" \ |
| 18 | "The path to the installed kernel's vblock (Default: /tmp/vmlinuz_hd.vblock)" |
Will Drewry | 69563b7 | 2010-06-24 16:12:58 -0500 | [diff] [blame] | 19 | DEFINE_string vmlinuz "vmlinuz" \ |
| 20 | "The path to the kernel (Default: vmlinuz)" |
| 21 | DEFINE_string working_dir "/tmp/vmlinuz.working" \ |
| 22 | "Working directory for in-progress files. (Default: /tmp/vmlinuz.working)" |
| 23 | DEFINE_boolean keep_work ${FLAGS_FALSE} \ |
| 24 | "Keep temporary files (*.keyblock, *.vbpubk). (Default: false)" |
| 25 | DEFINE_string keys_dir "${SRC_ROOT}/platform/vboot_reference/tests/testkeys" \ |
Bill Richardson | 2ace49e | 2010-07-01 10:23:27 -0700 | [diff] [blame] | 26 | "Directory with the RSA signing keys. (Defaults to test keys)" |
Tan Gao | 843b70a | 2010-08-17 09:41:48 -0700 | [diff] [blame] | 27 | DEFINE_boolean use_dev_keys ${FLAGS_FALSE} \ |
| 28 | "Use developer keys for signing. (Default: false)" |
Will Drewry | bcbf1c4 | 2010-07-03 10:23:30 -0500 | [diff] [blame] | 29 | # Note, to enable verified boot, the caller would manually pass: |
Will Drewry | b910de8 | 2011-02-23 13:26:50 -0600 | [diff] [blame] | 30 | # --boot_args='dm="... %U+1 %U+1 ..." \ |
Will Drewry | 69563b7 | 2010-06-24 16:12:58 -0500 | [diff] [blame] | 31 | # --root=/dev/dm-0 |
| 32 | DEFINE_string boot_args "noinitrd" \ |
| 33 | "Additional boot arguments to pass to the commandline (Default: noinitrd)" |
Will Drewry | bcbf1c4 | 2010-07-03 10:23:30 -0500 | [diff] [blame] | 34 | # If provided, will automatically add verified boot arguments. |
| 35 | DEFINE_string rootfs_image "" \ |
| 36 | "Optional path to the rootfs device or image.(Default: \"\")" |
| 37 | DEFINE_string rootfs_hash "" \ |
| 38 | "Optional path to output the rootfs hash to. (Default: \"\")" |
Liam McLoughlin | e81a232 | 2012-09-24 10:37:34 +0000 | [diff] [blame] | 39 | DEFINE_integer verity_error_behavior 3 \ |
Will Drewry | bcbf1c4 | 2010-07-03 10:23:30 -0500 | [diff] [blame] | 40 | "Verified boot error behavior [0: I/O errors, 1: reboot, 2: nothing] \ |
Liam McLoughlin | e81a232 | 2012-09-24 10:37:34 +0000 | [diff] [blame] | 41 | (Default: 3)" |
Will Drewry | b910de8 | 2011-02-23 13:26:50 -0600 | [diff] [blame] | 42 | DEFINE_integer verity_max_ios -1 \ |
| 43 | "Optional number of outstanding I/O operations. (Default: -1)" |
Will Drewry | 1670d48 | 2010-07-09 13:08:38 -0700 | [diff] [blame] | 44 | DEFINE_string verity_hash_alg "sha1" \ |
| 45 | "Cryptographic hash algorithm used for dm-verity. (Default: sha1)" |
Elly Jones | 9ca3e4c | 2011-09-26 15:18:19 -0400 | [diff] [blame] | 46 | DEFINE_string verity_salt "" \ |
| 47 | "Salt to use for rootfs hash (Default: \"\")" |
Paul Taysom | 5b2c7e9 | 2012-09-05 10:13:03 -0700 | [diff] [blame] | 48 | DEFINE_boolean enable_rootfs_verification ${FLAGS_TRUE} \ |
| 49 | "Enable kernel-based root fs integrity checking. (Default: true)" |
Paul Taysom | 00df6f6 | 2012-11-20 12:35:40 -0800 | [diff] [blame] | 50 | DEFINE_boolean enable_bootcache ${FLAGS_FALSE} \ |
| 51 | "Enable boot cache to accelerate booting. (Default: false)" |
Paul Taysom | 5e39bb6 | 2013-01-18 07:39:25 -0800 | [diff] [blame] | 52 | DEFINE_string enable_serial "" \ |
| 53 | "Enable serial port for printks. Example values: ttyS0" |
Will Drewry | bcbf1c4 | 2010-07-03 10:23:30 -0500 | [diff] [blame] | 54 | |
Will Drewry | 69563b7 | 2010-06-24 16:12:58 -0500 | [diff] [blame] | 55 | # Parse flags |
| 56 | FLAGS "$@" || exit 1 |
| 57 | eval set -- "${FLAGS_ARGV}" |
| 58 | |
| 59 | # Die on error |
Brian Harring | 7f175a5 | 2012-03-02 05:37:00 -0800 | [diff] [blame] | 60 | switch_to_strict_mode |
Will Drewry | 69563b7 | 2010-06-24 16:12:58 -0500 | [diff] [blame] | 61 | |
Paul Taysom | 00df6f6 | 2012-11-20 12:35:40 -0800 | [diff] [blame] | 62 | rootdigest() { |
| 63 | local digest=${table#*root_hexdigest=} |
| 64 | echo ${digest% salt*} |
| 65 | } |
| 66 | |
| 67 | salt() { |
| 68 | local salt=${table#*salt=} |
| 69 | echo ${salt%} |
| 70 | } |
| 71 | |
| 72 | hashstart() { |
| 73 | local hash=${table#*hashstart=} |
| 74 | echo ${hash% alg*} |
| 75 | } |
| 76 | |
| 77 | # Estimate of sectors used by verity |
| 78 | # (num blocks) * 32 (bytes per hash) * 2 (overhead) / 512 (bytes per sector) |
| 79 | veritysize() { |
| 80 | echo $((root_fs_blocks * 32 * 2 / 512)) |
| 81 | } |
| 82 | |
| 83 | device_mapper_args= |
Will Drewry | bcbf1c4 | 2010-07-03 10:23:30 -0500 | [diff] [blame] | 84 | # Even with a rootfs_image, root= is not changed unless specified. |
| 85 | if [[ -n "${FLAGS_rootfs_image}" && -n "${FLAGS_rootfs_hash}" ]]; then |
Will Drewry | bcbf1c4 | 2010-07-03 10:23:30 -0500 | [diff] [blame] | 86 | # Gets the number of blocks. 4096 byte blocks _are_ expected. |
Da Zheng | 87465ea | 2011-07-30 16:25:28 -0700 | [diff] [blame] | 87 | if [ -f "${FLAGS_rootfs_image}" ]; then |
| 88 | root_fs_block_sz=4096 |
| 89 | root_fs_sz=$(stat -c '%s' ${FLAGS_rootfs_image}) |
| 90 | root_fs_blocks=$((root_fs_sz / ${root_fs_block_sz})) |
| 91 | else |
| 92 | root_fs_blocks=$(sudo dumpe2fs "${FLAGS_rootfs_image}" 2> /dev/null | |
Will Drewry | bcbf1c4 | 2010-07-03 10:23:30 -0500 | [diff] [blame] | 93 | grep "Block count" | |
| 94 | tr -d ' ' | |
| 95 | cut -f2 -d:) |
Da Zheng | 87465ea | 2011-07-30 16:25:28 -0700 | [diff] [blame] | 96 | root_fs_block_sz=$(sudo dumpe2fs "${FLAGS_rootfs_image}" 2> /dev/null | |
Will Drewry | bcbf1c4 | 2010-07-03 10:23:30 -0500 | [diff] [blame] | 97 | grep "Block size" | |
| 98 | tr -d ' ' | |
| 99 | cut -f2 -d:) |
Da Zheng | 87465ea | 2011-07-30 16:25:28 -0700 | [diff] [blame] | 100 | fi |
| 101 | |
Will Drewry | 78992a3 | 2010-07-21 14:02:20 -0500 | [diff] [blame] | 102 | info "rootfs is ${root_fs_blocks} blocks of ${root_fs_block_sz} bytes" |
Will Drewry | bcbf1c4 | 2010-07-03 10:23:30 -0500 | [diff] [blame] | 103 | if [[ ${root_fs_block_sz} -ne 4096 ]]; then |
| 104 | error "Root file system blocks are not 4k!" |
| 105 | fi |
| 106 | |
Elly Jones | 9ca3e4c | 2011-09-26 15:18:19 -0400 | [diff] [blame] | 107 | info "Generating root fs hash tree (salt '${FLAGS_verity_salt}')." |
Will Drewry | bcbf1c4 | 2010-07-03 10:23:30 -0500 | [diff] [blame] | 108 | # Runs as sudo in case the image is a block device. |
Mandeep Singh Baines | 118692a | 2011-04-28 13:50:33 -0700 | [diff] [blame] | 109 | # First argument to verity is reserved/unused and MUST be 0 |
Elly Jones | 5e7a430 | 2011-05-27 16:08:16 -0400 | [diff] [blame] | 110 | table=$(sudo verity mode=create \ |
| 111 | alg=${FLAGS_verity_hash_alg} \ |
| 112 | payload=${FLAGS_rootfs_image} \ |
| 113 | payload_blocks=${root_fs_blocks} \ |
Elly Jones | f4e4833 | 2011-09-02 13:25:04 -0400 | [diff] [blame] | 114 | hashtree=${FLAGS_rootfs_hash} \ |
Elly Jones | 9ca3e4c | 2011-09-26 15:18:19 -0400 | [diff] [blame] | 115 | salt=${FLAGS_verity_salt}) |
Will Drewry | 821d07c | 2010-07-03 17:14:58 -0700 | [diff] [blame] | 116 | if [[ -f "${FLAGS_rootfs_hash}" ]]; then |
| 117 | sudo chmod a+r "${FLAGS_rootfs_hash}" |
| 118 | fi |
Paul Taysom | 5b2c7e9 | 2012-09-05 10:13:03 -0700 | [diff] [blame] | 119 | # Don't claim the root device unless verity is enabled. |
| 120 | # Doing so will claim /dev/sdDP out from under the system. |
| 121 | if [[ ${FLAGS_enable_rootfs_verification} -eq ${FLAGS_TRUE} ]]; then |
Paul Taysom | 00df6f6 | 2012-11-20 12:35:40 -0800 | [diff] [blame] | 122 | if [[ ${FLAGS_enable_bootcache} -eq ${FLAGS_TRUE} ]]; then |
| 123 | base_root='254:0' # major:minor numbers for /dev/dm-0 |
| 124 | else |
Paul Taysom | a59a0b3 | 2013-07-24 15:56:18 -0700 | [diff] [blame^] | 125 | base_root='PARTUUID=%U/PARTNROFF=1' # kern_guid + 1 |
Paul Taysom | 00df6f6 | 2012-11-20 12:35:40 -0800 | [diff] [blame] | 126 | fi |
Kenneth Waters | ed54d93 | 2010-09-21 10:29:54 -0700 | [diff] [blame] | 127 | table=${table//HASH_DEV/${base_root}} |
| 128 | table=${table//ROOT_DEV/${base_root}} |
Will Drewry | bcbf1c4 | 2010-07-03 10:23:30 -0500 | [diff] [blame] | 129 | fi |
Paul Taysom | 00df6f6 | 2012-11-20 12:35:40 -0800 | [diff] [blame] | 130 | verity_dev="vroot none ro 1,${table}" |
| 131 | if [[ ${FLAGS_enable_bootcache} -eq ${FLAGS_TRUE} ]]; then |
| 132 | signature=$(rootdigest) |
| 133 | cachestart=$(($(hashstart) + $(veritysize))) |
| 134 | size_limit=512 |
| 135 | max_trace=20000 |
| 136 | max_pages=100000 |
Paul Taysom | a59a0b3 | 2013-07-24 15:56:18 -0700 | [diff] [blame^] | 137 | bootcache_args="PARTUUID=%U/PARTNROFF=1" |
| 138 | bootcache_args+=" ${cachestart} ${signature} ${size_limit}" |
| 139 | bootcache_args+=" ${max_trace} ${max_pages}" |
Paul Taysom | 00df6f6 | 2012-11-20 12:35:40 -0800 | [diff] [blame] | 140 | bootcache_dev="vboot none ro 1,0 ${cachestart} bootcache ${bootcache_args}" |
| 141 | device_mapper_args="dm=\"2 ${bootcache_dev}, ${verity_dev}\"" |
| 142 | else |
| 143 | device_mapper_args="dm=\"1 ${verity_dev}\"" |
| 144 | fi |
| 145 | info "device mapper configuration: ${device_mapper_args}" |
Will Drewry | bcbf1c4 | 2010-07-03 10:23:30 -0500 | [diff] [blame] | 146 | fi |
| 147 | |
| 148 | mkdir -p "${FLAGS_working_dir}" |
Will Drewry | d6435d4 | 2010-10-20 15:37:46 -0500 | [diff] [blame] | 149 | |
| 150 | # Only let dm-verity block if rootfs verification is configured. |
Paul Taysom | 5b2c7e9 | 2012-09-05 10:13:03 -0700 | [diff] [blame] | 151 | # By default, we use a firmware enumerated value, but it isn't reliable for |
| 152 | # production use. If +%d can be added upstream, then we can use: |
| 153 | # root_dev=PARTUID=uuid+1 |
Will Drewry | d6435d4 | 2010-10-20 15:37:46 -0500 | [diff] [blame] | 154 | dev_wait=0 |
Paul Taysom | 5b2c7e9 | 2012-09-05 10:13:03 -0700 | [diff] [blame] | 155 | root_dev="PARTUUID=%U/PARTNROFF=1" |
| 156 | if [[ ${FLAGS_enable_rootfs_verification} -eq ${FLAGS_TRUE} ]]; then |
Will Drewry | d6435d4 | 2010-10-20 15:37:46 -0500 | [diff] [blame] | 157 | dev_wait=1 |
Paul Taysom | 00df6f6 | 2012-11-20 12:35:40 -0800 | [diff] [blame] | 158 | if [[ ${FLAGS_enable_bootcache} -eq ${FLAGS_TRUE} ]]; then |
| 159 | root_dev=/dev/dm-1 |
| 160 | else |
| 161 | root_dev=/dev/dm-0 |
| 162 | fi |
| 163 | else |
| 164 | if [[ ${FLAGS_enable_bootcache} -eq ${FLAGS_TRUE} ]]; then |
| 165 | die "Having bootcache without verity is not supported" |
| 166 | fi |
Will Drewry | d6435d4 | 2010-10-20 15:37:46 -0500 | [diff] [blame] | 167 | fi |
| 168 | |
Paul Taysom | a59a0b3 | 2013-07-24 15:56:18 -0700 | [diff] [blame^] | 169 | # kern_guid should eventually be changed to use PARTUUID |
Will Drewry | bcbf1c4 | 2010-07-03 10:23:30 -0500 | [diff] [blame] | 170 | cat <<EOF > "${FLAGS_working_dir}/boot.config" |
Paul Taysom | 5b2c7e9 | 2012-09-05 10:13:03 -0700 | [diff] [blame] | 171 | root=${root_dev} |
Olof Johansson | e0b7551 | 2011-01-26 14:31:26 -0800 | [diff] [blame] | 172 | rootwait |
| 173 | ro |
Will Drewry | 1670d48 | 2010-07-09 13:08:38 -0700 | [diff] [blame] | 174 | dm_verity.error_behavior=${FLAGS_verity_error_behavior} |
| 175 | dm_verity.max_bios=${FLAGS_verity_max_ios} |
Will Drewry | d6435d4 | 2010-10-20 15:37:46 -0500 | [diff] [blame] | 176 | dm_verity.dev_wait=${dev_wait} |
Paul Taysom | 00df6f6 | 2012-11-20 12:35:40 -0800 | [diff] [blame] | 177 | ${device_mapper_args} |
Will Drewry | bcbf1c4 | 2010-07-03 10:23:30 -0500 | [diff] [blame] | 178 | ${FLAGS_boot_args} |
Pawel Osciak | a2c2375 | 2011-11-15 15:09:45 -0800 | [diff] [blame] | 179 | vt.global_cursor_default=0 |
Doug Anderson | 2dd2e8e | 2012-01-06 09:32:24 -0800 | [diff] [blame] | 180 | kern_guid=%U |
Will Drewry | bcbf1c4 | 2010-07-03 10:23:30 -0500 | [diff] [blame] | 181 | EOF |
| 182 | |
| 183 | WORK="${WORK} ${FLAGS_working_dir}/boot.config" |
| 184 | info "Emitted cross-platform boot params to ${FLAGS_working_dir}/boot.config" |
| 185 | |
Olof Johansson | 1eafb5a | 2012-08-01 00:04:30 -0700 | [diff] [blame] | 186 | # Add common boot options first. |
Paul Taysom | 5e39bb6 | 2013-01-18 07:39:25 -0800 | [diff] [blame] | 187 | config="${FLAGS_working_dir}/config.txt" |
| 188 | if [[ -n ${FLAGS_enable_serial} ]]; then |
| 189 | console=${FLAGS_enable_serial} |
| 190 | if [[ ${console} != *,* ]]; then |
| 191 | console+=",115200n8" |
| 192 | fi |
| 193 | cat <<EOF > "${config}" |
| 194 | console=${console} |
| 195 | earlyprintk=${console} |
| 196 | console=tty1 |
Vadim Bendebury | 90b6ec4 | 2013-07-17 10:53:46 -0700 | [diff] [blame] | 197 | keep_bootcon |
Paul Taysom | 5e39bb6 | 2013-01-18 07:39:25 -0800 | [diff] [blame] | 198 | EOF |
| 199 | else |
| 200 | cat <<EOF > "${config}" |
Sameer Nanda | 542cb53 | 2012-08-22 16:11:12 -0700 | [diff] [blame] | 201 | console= |
Paul Taysom | 5e39bb6 | 2013-01-18 07:39:25 -0800 | [diff] [blame] | 202 | EOF |
| 203 | fi |
| 204 | |
| 205 | cat <<EOF - "${FLAGS_working_dir}/boot.config" >> "${config}" |
| 206 | loglevel=7 |
Will Drewry | 69563b7 | 2010-06-24 16:12:58 -0500 | [diff] [blame] | 207 | init=/sbin/init |
Olof Johansson | 1eafb5a | 2012-08-01 00:04:30 -0700 | [diff] [blame] | 208 | cros_secure |
Paul Taysom | 984acd7 | 2013-04-02 09:41:26 -0700 | [diff] [blame] | 209 | oops=panic |
| 210 | panic=-1 |
Olof Johansson | 1eafb5a | 2012-08-01 00:04:30 -0700 | [diff] [blame] | 211 | EOF |
| 212 | |
| 213 | if [[ "${FLAGS_arch}" = "x86" || "${FLAGS_arch}" = "amd64" ]]; then |
| 214 | # Legacy BIOS will use the kernel in the rootfs (via syslinux), as will |
| 215 | # standard EFI BIOS (via grub, from the EFI System Partition). Chrome OS |
| 216 | # BIOS will use a separate signed kernel partition, which we'll create now. |
Olof Johansson | d7a8aaf | 2012-08-02 20:35:47 -0700 | [diff] [blame] | 217 | cat <<EOF >> "${FLAGS_working_dir}/config.txt" |
Will Drewry | 69563b7 | 2010-06-24 16:12:58 -0500 | [diff] [blame] | 218 | add_efi_memmap |
| 219 | boot=local |
Will Drewry | 69563b7 | 2010-06-24 16:12:58 -0500 | [diff] [blame] | 220 | noresume |
| 221 | noswap |
| 222 | i915.modeset=1 |
Luigi Semenzato | 195aebe | 2010-10-20 17:35:00 -0700 | [diff] [blame] | 223 | tpm_tis.force=1 |
| 224 | tpm_tis.interrupts=0 |
Vadim Bendebury | 8e623f6 | 2011-02-28 10:28:31 -0800 | [diff] [blame] | 225 | nmi_watchdog=panic,lapic |
Will Drewry | 69563b7 | 2010-06-24 16:12:58 -0500 | [diff] [blame] | 226 | EOF |
Will Drewry | bcbf1c4 | 2010-07-03 10:23:30 -0500 | [diff] [blame] | 227 | WORK="${WORK} ${FLAGS_working_dir}/config.txt" |
Will Drewry | 69563b7 | 2010-06-24 16:12:58 -0500 | [diff] [blame] | 228 | |
Che-Liang Chiou | 75ac2be | 2011-02-24 12:00:16 +0800 | [diff] [blame] | 229 | bootloader_path="/lib64/bootstub/bootstub.efi" |
| 230 | kernel_image="${FLAGS_vmlinuz}" |
Che-Liang Chiou | 75ac2be | 2011-02-24 12:00:16 +0800 | [diff] [blame] | 231 | elif [[ "${FLAGS_arch}" = "arm" ]]; then |
Che-Liang Chiou | 75ac2be | 2011-02-24 12:00:16 +0800 | [diff] [blame] | 232 | WORK="${WORK} ${FLAGS_working_dir}/config.txt" |
| 233 | |
Che-Liang Chiou | 69faa26 | 2011-06-01 11:52:21 +0800 | [diff] [blame] | 234 | # arm does not need/have a bootloader in kernel partition |
| 235 | dd if="/dev/zero" of="${FLAGS_working_dir}/bootloader.bin" bs=512 count=1 |
| 236 | WORK="${WORK} ${FLAGS_working_dir}/bootloader.bin" |
Che-Liang Chiou | 75ac2be | 2011-02-24 12:00:16 +0800 | [diff] [blame] | 237 | |
Che-Liang Chiou | 69faa26 | 2011-06-01 11:52:21 +0800 | [diff] [blame] | 238 | bootloader_path="${FLAGS_working_dir}/bootloader.bin" |
Che-Liang Chiou | 75ac2be | 2011-02-24 12:00:16 +0800 | [diff] [blame] | 239 | kernel_image="${FLAGS_vmlinuz/vmlinuz/vmlinux.uimg}" |
Che-Liang Chiou | 75ac2be | 2011-02-24 12:00:16 +0800 | [diff] [blame] | 240 | else |
| 241 | error "Unknown arch: ${FLAGS_arch}" |
| 242 | fi |
| 243 | |
Che-Liang Chiou | e51bdf2 | 2011-07-26 21:19:24 +0800 | [diff] [blame] | 244 | # We sign the image with the recovery_key, because this is what goes onto the |
| 245 | # USB key. We can only boot from the USB drive in recovery mode. |
| 246 | # For dev install shim, we need to use the installer keyblock instead of |
| 247 | # the recovery keyblock because of the difference in flags. |
| 248 | if [ ${FLAGS_use_dev_keys} -eq ${FLAGS_TRUE} ]; then |
| 249 | USB_KEYBLOCK=installer_kernel.keyblock |
| 250 | info "DEBUG: use dev install signing key" |
Che-Liang Chiou | 75ac2be | 2011-02-24 12:00:16 +0800 | [diff] [blame] | 251 | else |
Che-Liang Chiou | e51bdf2 | 2011-07-26 21:19:24 +0800 | [diff] [blame] | 252 | USB_KEYBLOCK=recovery_kernel.keyblock |
| 253 | info "DEBUG: use recovery signing key" |
Will Drewry | 69563b7 | 2010-06-24 16:12:58 -0500 | [diff] [blame] | 254 | fi |
| 255 | |
Paul Taysom | 94e36c5 | 2013-07-16 15:55:23 -0700 | [diff] [blame] | 256 | # Create and sign the kernel blob |
| 257 | vbutil_kernel \ |
| 258 | --pack "${FLAGS_to}" \ |
| 259 | --keyblock "${FLAGS_keys_dir}/${USB_KEYBLOCK}" \ |
| 260 | --signprivate "${FLAGS_keys_dir}/recovery_kernel_data_key.vbprivk" \ |
| 261 | --version 1 \ |
| 262 | --config "${FLAGS_working_dir}/config.txt" \ |
| 263 | --bootloader "${bootloader_path}" \ |
| 264 | --vmlinuz "${kernel_image}" \ |
| 265 | --arch "${FLAGS_arch}" |
Che-Liang Chiou | e51bdf2 | 2011-07-26 21:19:24 +0800 | [diff] [blame] | 266 | |
Paul Taysom | 94e36c5 | 2013-07-16 15:55:23 -0700 | [diff] [blame] | 267 | # And verify it. |
| 268 | vbutil_kernel \ |
| 269 | --verify "${FLAGS_to}" \ |
| 270 | --signpubkey "${FLAGS_keys_dir}/recovery_key.vbpubk" |
Che-Liang Chiou | e51bdf2 | 2011-07-26 21:19:24 +0800 | [diff] [blame] | 271 | |
Paul Taysom | 94e36c5 | 2013-07-16 15:55:23 -0700 | [diff] [blame] | 272 | |
| 273 | # Now we re-sign the same image using the normal keys. This is the kernel |
| 274 | # image that is put on the hard disk by the installer. Note: To save space on |
| 275 | # the USB image, we're only emitting the new verfication block, and the |
| 276 | # installer just replaces that part of the hard disk's kernel partition. |
| 277 | vbutil_kernel \ |
| 278 | --repack "${FLAGS_hd_vblock}" \ |
| 279 | --vblockonly \ |
| 280 | --keyblock "${FLAGS_keys_dir}/kernel.keyblock" \ |
| 281 | --signprivate "${FLAGS_keys_dir}/kernel_data_key.vbprivk" \ |
| 282 | --oldblob "${FLAGS_to}" |
| 283 | |
| 284 | |
| 285 | # To verify it, we have to replace the vblock from the original image. |
| 286 | tempfile=$(mktemp) |
| 287 | trap "rm -f $tempfile" EXIT |
| 288 | cat "${FLAGS_hd_vblock}" > $tempfile |
| 289 | dd if="${FLAGS_to}" bs=65536 skip=1 >> $tempfile |
| 290 | |
| 291 | vbutil_kernel \ |
| 292 | --verify $tempfile \ |
| 293 | --signpubkey "${FLAGS_keys_dir}/kernel_subkey.vbpubk" |
| 294 | |
| 295 | rm -f $tempfile |
Che-Liang Chiou | e51bdf2 | 2011-07-26 21:19:24 +0800 | [diff] [blame] | 296 | trap - EXIT |
| 297 | |
Will Drewry | 69563b7 | 2010-06-24 16:12:58 -0500 | [diff] [blame] | 298 | set +e # cleanup failure is a-ok |
| 299 | |
| 300 | if [[ ${FLAGS_keep_work} -eq ${FLAGS_FALSE} ]]; then |
Will Drewry | bcbf1c4 | 2010-07-03 10:23:30 -0500 | [diff] [blame] | 301 | info "Cleaning up temporary files: ${WORK}" |
Will Drewry | 69563b7 | 2010-06-24 16:12:58 -0500 | [diff] [blame] | 302 | rm ${WORK} |
| 303 | rmdir ${FLAGS_working_dir} |
| 304 | fi |
| 305 | |
Will Drewry | bcbf1c4 | 2010-07-03 10:23:30 -0500 | [diff] [blame] | 306 | info "Kernel partition image emitted: ${FLAGS_to}" |
| 307 | |
| 308 | if [[ -f ${FLAGS_rootfs_hash} ]]; then |
| 309 | info "Root filesystem hash emitted: ${FLAGS_rootfs_hash}" |
| 310 | fi |