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