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 | 5d190f7 | 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)" |
Gabe Black | e41371c | 2014-07-29 15:48:40 -0700 | [diff] [blame] | 19 | DEFINE_string hd_vblock "" \ |
| 20 | "The path to the installed kernel's 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)" |
Gabe Black | e41371c | 2014-07-29 15:48:40 -0700 | [diff] [blame] | 29 | DEFINE_string keyblock "kernel.keyblock" \ |
| 30 | "The keyblock to use. (Defaults to kernel.keyblock)" |
| 31 | DEFINE_string private "kernel_data_key.vbprivk" \ |
| 32 | "The private key to sign the kernel (Defaults to kernel_data_key.vbprivk)" |
| 33 | DEFINE_string public "kernel_subkey.vbpubk" \ |
| 34 | "The public key to verify the kernel (Defaults to kernel_subkey.vbpubk)" |
Will Drewry | bcbf1c4 | 2010-07-03 10:23:30 -0500 | [diff] [blame] | 35 | # Note, to enable verified boot, the caller would manually pass: |
Will Drewry | b910de8 | 2011-02-23 13:26:50 -0600 | [diff] [blame] | 36 | # --boot_args='dm="... %U+1 %U+1 ..." \ |
Will Drewry | 69563b7 | 2010-06-24 16:12:58 -0500 | [diff] [blame] | 37 | # --root=/dev/dm-0 |
| 38 | DEFINE_string boot_args "noinitrd" \ |
| 39 | "Additional boot arguments to pass to the commandline (Default: noinitrd)" |
Will Drewry | bcbf1c4 | 2010-07-03 10:23:30 -0500 | [diff] [blame] | 40 | # If provided, will automatically add verified boot arguments. |
| 41 | DEFINE_string rootfs_image "" \ |
| 42 | "Optional path to the rootfs device or image.(Default: \"\")" |
Alex Deymo | 87dced6 | 2015-03-03 12:54:58 -0800 | [diff] [blame] | 43 | DEFINE_string rootfs_image_size "" \ |
| 44 | "Optional size in bytes of the rootfs_image file. Must be a multiple of 4 \ |
| 45 | KiB. If omitted, the filesystem size detected from rootfs_image is used." |
Will Drewry | bcbf1c4 | 2010-07-03 10:23:30 -0500 | [diff] [blame] | 46 | DEFINE_string rootfs_hash "" \ |
| 47 | "Optional path to output the rootfs hash to. (Default: \"\")" |
Liam McLoughlin | e81a232 | 2012-09-24 10:37:34 +0000 | [diff] [blame] | 48 | DEFINE_integer verity_error_behavior 3 \ |
Will Drewry | bcbf1c4 | 2010-07-03 10:23:30 -0500 | [diff] [blame] | 49 | "Verified boot error behavior [0: I/O errors, 1: reboot, 2: nothing] \ |
Liam McLoughlin | e81a232 | 2012-09-24 10:37:34 +0000 | [diff] [blame] | 50 | (Default: 3)" |
Will Drewry | b910de8 | 2011-02-23 13:26:50 -0600 | [diff] [blame] | 51 | DEFINE_integer verity_max_ios -1 \ |
| 52 | "Optional number of outstanding I/O operations. (Default: -1)" |
Will Drewry | 1670d48 | 2010-07-09 13:08:38 -0700 | [diff] [blame] | 53 | DEFINE_string verity_hash_alg "sha1" \ |
| 54 | "Cryptographic hash algorithm used for dm-verity. (Default: sha1)" |
Elly Jones | 9ca3e4c | 2011-09-26 15:18:19 -0400 | [diff] [blame] | 55 | DEFINE_string verity_salt "" \ |
| 56 | "Salt to use for rootfs hash (Default: \"\")" |
Paul Taysom | 5b2c7e9 | 2012-09-05 10:13:03 -0700 | [diff] [blame] | 57 | DEFINE_boolean enable_rootfs_verification ${FLAGS_TRUE} \ |
| 58 | "Enable kernel-based root fs integrity checking. (Default: true)" |
Paul Taysom | 00df6f6 | 2012-11-20 12:35:40 -0800 | [diff] [blame] | 59 | DEFINE_boolean enable_bootcache ${FLAGS_FALSE} \ |
| 60 | "Enable boot cache to accelerate booting. (Default: false)" |
Paul Taysom | 5e39bb6 | 2013-01-18 07:39:25 -0800 | [diff] [blame] | 61 | DEFINE_string enable_serial "" \ |
| 62 | "Enable serial port for printks. Example values: ttyS0" |
Zach Reizner | f09d3d1 | 2014-09-24 10:45:19 -0700 | [diff] [blame] | 63 | DEFINE_integer loglevel 7 \ |
| 64 | "The loglevel to add to the kernel command line." |
Will Drewry | bcbf1c4 | 2010-07-03 10:23:30 -0500 | [diff] [blame] | 65 | |
Will Drewry | 69563b7 | 2010-06-24 16:12:58 -0500 | [diff] [blame] | 66 | # Parse flags |
| 67 | FLAGS "$@" || exit 1 |
| 68 | eval set -- "${FLAGS_ARGV}" |
| 69 | |
| 70 | # Die on error |
Brian Harring | 7f175a5 | 2012-03-02 05:37:00 -0800 | [diff] [blame] | 71 | switch_to_strict_mode |
Will Drewry | 69563b7 | 2010-06-24 16:12:58 -0500 | [diff] [blame] | 72 | |
Mike Frysinger | 94a82df | 2013-11-26 14:51:50 -0500 | [diff] [blame] | 73 | # N.B. Ordering matters for some of the libraries below, because |
| 74 | # some of the files contain initialization used by later files. |
| 75 | . "${BUILD_LIBRARY_DIR}/board_options.sh" || exit 1 |
Dan Ehrenberg | 21cee6e | 2014-11-18 17:29:16 -0800 | [diff] [blame] | 76 | . "${BUILD_LIBRARY_DIR}/disk_layout_util.sh" || exit 1 |
Mike Frysinger | 94a82df | 2013-11-26 14:51:50 -0500 | [diff] [blame] | 77 | |
Dan Ehrenberg | cdac45f | 2015-01-16 15:16:03 -0800 | [diff] [blame] | 78 | |
Paul Taysom | 00df6f6 | 2012-11-20 12:35:40 -0800 | [diff] [blame] | 79 | rootdigest() { |
| 80 | local digest=${table#*root_hexdigest=} |
| 81 | echo ${digest% salt*} |
| 82 | } |
| 83 | |
| 84 | salt() { |
| 85 | local salt=${table#*salt=} |
| 86 | echo ${salt%} |
| 87 | } |
| 88 | |
| 89 | hashstart() { |
| 90 | local hash=${table#*hashstart=} |
| 91 | echo ${hash% alg*} |
| 92 | } |
| 93 | |
| 94 | # Estimate of sectors used by verity |
| 95 | # (num blocks) * 32 (bytes per hash) * 2 (overhead) / 512 (bytes per sector) |
| 96 | veritysize() { |
| 97 | echo $((root_fs_blocks * 32 * 2 / 512)) |
| 98 | } |
| 99 | |
Chris Masone | 175a269 | 2014-01-21 16:06:44 -0800 | [diff] [blame] | 100 | # Munge the kernel command line. |
| 101 | # Intended to be overridden by boards that wish to add to the command line. |
| 102 | # $1 - Configuration file containing boot args. |
| 103 | modify_kernel_command_line() { |
| 104 | : |
| 105 | } |
| 106 | |
Dan Ehrenberg | 21cee6e | 2014-11-18 17:29:16 -0800 | [diff] [blame] | 107 | get_base_root() { |
| 108 | echo 'PARTUUID=%U/PARTNROFF=1' |
| 109 | } |
| 110 | |
Steve Fung | 88897cc | 2015-03-25 13:38:38 -0700 | [diff] [blame^] | 111 | load_board_specific_script "build_kernel_image.sh" |
Albert Chaulk | 5d190f7 | 2013-07-12 11:42:18 -0700 | [diff] [blame] | 112 | |
Dan Ehrenberg | 21cee6e | 2014-11-18 17:29:16 -0800 | [diff] [blame] | 113 | base_root=$(get_base_root) |
| 114 | |
Paul Taysom | 00df6f6 | 2012-11-20 12:35:40 -0800 | [diff] [blame] | 115 | device_mapper_args= |
Will Drewry | bcbf1c4 | 2010-07-03 10:23:30 -0500 | [diff] [blame] | 116 | # Even with a rootfs_image, root= is not changed unless specified. |
| 117 | if [[ -n "${FLAGS_rootfs_image}" && -n "${FLAGS_rootfs_hash}" ]]; then |
Will Drewry | bcbf1c4 | 2010-07-03 10:23:30 -0500 | [diff] [blame] | 118 | # Gets the number of blocks. 4096 byte blocks _are_ expected. |
Alex Deymo | 87dced6 | 2015-03-03 12:54:58 -0800 | [diff] [blame] | 119 | if [[ -n "${FLAGS_rootfs_image_size}" ]]; then |
| 120 | root_fs_size=${FLAGS_rootfs_image_size} |
Da Zheng | 87465ea | 2011-07-30 16:25:28 -0700 | [diff] [blame] | 121 | else |
Alex Deymo | 87dced6 | 2015-03-03 12:54:58 -0800 | [diff] [blame] | 122 | # We try to autodetect the rootfs_image filesystem size. |
| 123 | if [[ -f "${FLAGS_rootfs_image}" ]]; then |
| 124 | root_fs_size=$(stat -c '%s' ${FLAGS_rootfs_image}) |
| 125 | elif [[ -b "${FLAGS_rootfs_image}" ]]; then |
| 126 | root_fs_type="$(awk -v rootdev="${FLAGS_rootfs_image}" \ |
| 127 | '$1 == rootdev { print $3 }' /proc/mounts | head -n 1)" |
| 128 | case "${root_fs_type}" in |
| 129 | squashfs) |
| 130 | # unsquashfs returns the size in KiB as a float value with two |
| 131 | # decimals, rounded as printf() would do. To avoid corner cases like |
| 132 | # when the fractional part of the size in KiB is less than 0.005, |
| 133 | # instead of rounding up the value to the nearest 4KiB, we round it |
| 134 | # down and add 1 extra 4 KiB block. |
| 135 | root_fs_size_kib=$(sudo unsquashfs -stat "${FLAGS_rootfs_image}" | |
| 136 | grep -E -o 'Filesystem size [0-9\.]+ Kbytes' | |
| 137 | cut -f 3 -d ' ' | cut -f 1 -d '.') |
| 138 | root_fs_size=$(( (root_fs_size_kib / 4 + 1) * 4096 )) |
| 139 | ;; |
| 140 | ext[234]) |
| 141 | root_fs_blocks=$(sudo dumpe2fs "${FLAGS_rootfs_image}" 2>/dev/null | |
| 142 | grep "Block count" | |
| 143 | tr -d ' ' | |
| 144 | cut -f2 -d:) |
| 145 | root_fs_block_sz=$(sudo dumpe2fs "${FLAGS_rootfs_image}" 2>/dev/null | |
| 146 | grep "Block size" | |
| 147 | tr -d ' ' | |
| 148 | cut -f2 -d:) |
| 149 | root_fs_size=$(( root_fs_blocks * root_fs_block_sz )) |
| 150 | ;; |
| 151 | *) |
| 152 | die "Unknown root filesystem type ${root_fs_type}." |
| 153 | ;; |
| 154 | esac |
| 155 | else |
| 156 | die "Couldn't determine the size of ${FLAGS_rootfs_image}, pass the size \ |
| 157 | with --rootfs_image_size." |
| 158 | fi |
Da Zheng | 87465ea | 2011-07-30 16:25:28 -0700 | [diff] [blame] | 159 | fi |
Alex Deymo | 87dced6 | 2015-03-03 12:54:58 -0800 | [diff] [blame] | 160 | # Verity assumes a 4 KiB block size. |
| 161 | if [[ ! $(( root_fs_size % 4096 )) -eq 0 ]]; then |
| 162 | die "The root filesystem size (${root_fs_size}) must be a multiple of \ |
| 163 | 4 KiB." |
Will Drewry | bcbf1c4 | 2010-07-03 10:23:30 -0500 | [diff] [blame] | 164 | fi |
Alex Deymo | 87dced6 | 2015-03-03 12:54:58 -0800 | [diff] [blame] | 165 | root_fs_blocks=$((root_fs_size / 4096)) |
| 166 | info "rootfs is ${root_fs_blocks} blocks of 4096 bytes." |
Will Drewry | bcbf1c4 | 2010-07-03 10:23:30 -0500 | [diff] [blame] | 167 | |
Elly Jones | 9ca3e4c | 2011-09-26 15:18:19 -0400 | [diff] [blame] | 168 | info "Generating root fs hash tree (salt '${FLAGS_verity_salt}')." |
Will Drewry | bcbf1c4 | 2010-07-03 10:23:30 -0500 | [diff] [blame] | 169 | # Runs as sudo in case the image is a block device. |
Mandeep Singh Baines | 118692a | 2011-04-28 13:50:33 -0700 | [diff] [blame] | 170 | # First argument to verity is reserved/unused and MUST be 0 |
Elly Jones | 5e7a430 | 2011-05-27 16:08:16 -0400 | [diff] [blame] | 171 | table=$(sudo verity mode=create \ |
| 172 | alg=${FLAGS_verity_hash_alg} \ |
| 173 | payload=${FLAGS_rootfs_image} \ |
| 174 | payload_blocks=${root_fs_blocks} \ |
Elly Jones | f4e4833 | 2011-09-02 13:25:04 -0400 | [diff] [blame] | 175 | hashtree=${FLAGS_rootfs_hash} \ |
Elly Jones | 9ca3e4c | 2011-09-26 15:18:19 -0400 | [diff] [blame] | 176 | salt=${FLAGS_verity_salt}) |
Will Drewry | 821d07c | 2010-07-03 17:14:58 -0700 | [diff] [blame] | 177 | if [[ -f "${FLAGS_rootfs_hash}" ]]; then |
| 178 | sudo chmod a+r "${FLAGS_rootfs_hash}" |
| 179 | fi |
Paul Taysom | 5b2c7e9 | 2012-09-05 10:13:03 -0700 | [diff] [blame] | 180 | # Don't claim the root device unless verity is enabled. |
| 181 | # Doing so will claim /dev/sdDP out from under the system. |
| 182 | if [[ ${FLAGS_enable_rootfs_verification} -eq ${FLAGS_TRUE} ]]; then |
Paul Taysom | 00df6f6 | 2012-11-20 12:35:40 -0800 | [diff] [blame] | 183 | if [[ ${FLAGS_enable_bootcache} -eq ${FLAGS_TRUE} ]]; then |
| 184 | base_root='254:0' # major:minor numbers for /dev/dm-0 |
Paul Taysom | 00df6f6 | 2012-11-20 12:35:40 -0800 | [diff] [blame] | 185 | fi |
Kenneth Waters | ed54d93 | 2010-09-21 10:29:54 -0700 | [diff] [blame] | 186 | table=${table//HASH_DEV/${base_root}} |
| 187 | table=${table//ROOT_DEV/${base_root}} |
Will Drewry | bcbf1c4 | 2010-07-03 10:23:30 -0500 | [diff] [blame] | 188 | fi |
Paul Taysom | 00df6f6 | 2012-11-20 12:35:40 -0800 | [diff] [blame] | 189 | verity_dev="vroot none ro 1,${table}" |
| 190 | if [[ ${FLAGS_enable_bootcache} -eq ${FLAGS_TRUE} ]]; then |
| 191 | signature=$(rootdigest) |
| 192 | cachestart=$(($(hashstart) + $(veritysize))) |
| 193 | size_limit=512 |
| 194 | max_trace=20000 |
| 195 | max_pages=100000 |
Paul Taysom | a59a0b3 | 2013-07-24 15:56:18 -0700 | [diff] [blame] | 196 | bootcache_args="PARTUUID=%U/PARTNROFF=1" |
| 197 | bootcache_args+=" ${cachestart} ${signature} ${size_limit}" |
| 198 | bootcache_args+=" ${max_trace} ${max_pages}" |
Paul Taysom | 00df6f6 | 2012-11-20 12:35:40 -0800 | [diff] [blame] | 199 | bootcache_dev="vboot none ro 1,0 ${cachestart} bootcache ${bootcache_args}" |
| 200 | device_mapper_args="dm=\"2 ${bootcache_dev}, ${verity_dev}\"" |
| 201 | else |
| 202 | device_mapper_args="dm=\"1 ${verity_dev}\"" |
| 203 | fi |
| 204 | info "device mapper configuration: ${device_mapper_args}" |
Will Drewry | bcbf1c4 | 2010-07-03 10:23:30 -0500 | [diff] [blame] | 205 | fi |
| 206 | |
| 207 | mkdir -p "${FLAGS_working_dir}" |
Will Drewry | d6435d4 | 2010-10-20 15:37:46 -0500 | [diff] [blame] | 208 | |
| 209 | # Only let dm-verity block if rootfs verification is configured. |
Paul Taysom | 5b2c7e9 | 2012-09-05 10:13:03 -0700 | [diff] [blame] | 210 | # By default, we use a firmware enumerated value, but it isn't reliable for |
| 211 | # production use. If +%d can be added upstream, then we can use: |
| 212 | # root_dev=PARTUID=uuid+1 |
Will Drewry | d6435d4 | 2010-10-20 15:37:46 -0500 | [diff] [blame] | 213 | dev_wait=0 |
Dan Ehrenberg | 21cee6e | 2014-11-18 17:29:16 -0800 | [diff] [blame] | 214 | root_dev=${base_root} |
Paul Taysom | 5b2c7e9 | 2012-09-05 10:13:03 -0700 | [diff] [blame] | 215 | if [[ ${FLAGS_enable_rootfs_verification} -eq ${FLAGS_TRUE} ]]; then |
Will Drewry | d6435d4 | 2010-10-20 15:37:46 -0500 | [diff] [blame] | 216 | dev_wait=1 |
Paul Taysom | 00df6f6 | 2012-11-20 12:35:40 -0800 | [diff] [blame] | 217 | if [[ ${FLAGS_enable_bootcache} -eq ${FLAGS_TRUE} ]]; then |
| 218 | root_dev=/dev/dm-1 |
| 219 | else |
| 220 | root_dev=/dev/dm-0 |
| 221 | fi |
| 222 | else |
| 223 | if [[ ${FLAGS_enable_bootcache} -eq ${FLAGS_TRUE} ]]; then |
| 224 | die "Having bootcache without verity is not supported" |
| 225 | fi |
Will Drewry | d6435d4 | 2010-10-20 15:37:46 -0500 | [diff] [blame] | 226 | fi |
| 227 | |
Paul Taysom | a59a0b3 | 2013-07-24 15:56:18 -0700 | [diff] [blame] | 228 | # kern_guid should eventually be changed to use PARTUUID |
Will Drewry | bcbf1c4 | 2010-07-03 10:23:30 -0500 | [diff] [blame] | 229 | cat <<EOF > "${FLAGS_working_dir}/boot.config" |
Paul Taysom | 5b2c7e9 | 2012-09-05 10:13:03 -0700 | [diff] [blame] | 230 | root=${root_dev} |
Olof Johansson | e0b7551 | 2011-01-26 14:31:26 -0800 | [diff] [blame] | 231 | rootwait |
| 232 | ro |
Will Drewry | 1670d48 | 2010-07-09 13:08:38 -0700 | [diff] [blame] | 233 | dm_verity.error_behavior=${FLAGS_verity_error_behavior} |
| 234 | dm_verity.max_bios=${FLAGS_verity_max_ios} |
Will Drewry | d6435d4 | 2010-10-20 15:37:46 -0500 | [diff] [blame] | 235 | dm_verity.dev_wait=${dev_wait} |
Paul Taysom | 00df6f6 | 2012-11-20 12:35:40 -0800 | [diff] [blame] | 236 | ${device_mapper_args} |
Will Drewry | bcbf1c4 | 2010-07-03 10:23:30 -0500 | [diff] [blame] | 237 | ${FLAGS_boot_args} |
Pawel Osciak | a2c2375 | 2011-11-15 15:09:45 -0800 | [diff] [blame] | 238 | vt.global_cursor_default=0 |
Doug Anderson | 2dd2e8e | 2012-01-06 09:32:24 -0800 | [diff] [blame] | 239 | kern_guid=%U |
Will Drewry | bcbf1c4 | 2010-07-03 10:23:30 -0500 | [diff] [blame] | 240 | EOF |
| 241 | |
| 242 | WORK="${WORK} ${FLAGS_working_dir}/boot.config" |
| 243 | info "Emitted cross-platform boot params to ${FLAGS_working_dir}/boot.config" |
| 244 | |
Olof Johansson | 1eafb5a | 2012-08-01 00:04:30 -0700 | [diff] [blame] | 245 | # Add common boot options first. |
Paul Taysom | 5e39bb6 | 2013-01-18 07:39:25 -0800 | [diff] [blame] | 246 | config="${FLAGS_working_dir}/config.txt" |
| 247 | if [[ -n ${FLAGS_enable_serial} ]]; then |
| 248 | console=${FLAGS_enable_serial} |
| 249 | if [[ ${console} != *,* ]]; then |
| 250 | console+=",115200n8" |
| 251 | fi |
| 252 | cat <<EOF > "${config}" |
Paul Taysom | 5e39bb6 | 2013-01-18 07:39:25 -0800 | [diff] [blame] | 253 | earlyprintk=${console} |
| 254 | console=tty1 |
Doug Anderson | d65edf4 | 2014-07-09 15:00:53 -0700 | [diff] [blame] | 255 | console=${console} |
Paul Taysom | 5e39bb6 | 2013-01-18 07:39:25 -0800 | [diff] [blame] | 256 | EOF |
| 257 | else |
| 258 | cat <<EOF > "${config}" |
Sameer Nanda | 542cb53 | 2012-08-22 16:11:12 -0700 | [diff] [blame] | 259 | console= |
Paul Taysom | 5e39bb6 | 2013-01-18 07:39:25 -0800 | [diff] [blame] | 260 | EOF |
| 261 | fi |
| 262 | |
| 263 | cat <<EOF - "${FLAGS_working_dir}/boot.config" >> "${config}" |
Zach Reizner | f09d3d1 | 2014-09-24 10:45:19 -0700 | [diff] [blame] | 264 | loglevel=${FLAGS_loglevel} |
Will Drewry | 69563b7 | 2010-06-24 16:12:58 -0500 | [diff] [blame] | 265 | init=/sbin/init |
Olof Johansson | 1eafb5a | 2012-08-01 00:04:30 -0700 | [diff] [blame] | 266 | cros_secure |
Paul Taysom | 984acd7 | 2013-04-02 09:41:26 -0700 | [diff] [blame] | 267 | oops=panic |
| 268 | panic=-1 |
Olof Johansson | 1eafb5a | 2012-08-01 00:04:30 -0700 | [diff] [blame] | 269 | EOF |
| 270 | |
| 271 | if [[ "${FLAGS_arch}" = "x86" || "${FLAGS_arch}" = "amd64" ]]; then |
| 272 | # Legacy BIOS will use the kernel in the rootfs (via syslinux), as will |
| 273 | # standard EFI BIOS (via grub, from the EFI System Partition). Chrome OS |
| 274 | # 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] | 275 | cat <<EOF >> "${FLAGS_working_dir}/config.txt" |
Will Drewry | 69563b7 | 2010-06-24 16:12:58 -0500 | [diff] [blame] | 276 | add_efi_memmap |
| 277 | boot=local |
Will Drewry | 69563b7 | 2010-06-24 16:12:58 -0500 | [diff] [blame] | 278 | noresume |
| 279 | noswap |
| 280 | i915.modeset=1 |
Luigi Semenzato | 195aebe | 2010-10-20 17:35:00 -0700 | [diff] [blame] | 281 | tpm_tis.force=1 |
| 282 | tpm_tis.interrupts=0 |
Vadim Bendebury | 8e623f6 | 2011-02-28 10:28:31 -0800 | [diff] [blame] | 283 | nmi_watchdog=panic,lapic |
Will Drewry | 69563b7 | 2010-06-24 16:12:58 -0500 | [diff] [blame] | 284 | EOF |
Will Drewry | bcbf1c4 | 2010-07-03 10:23:30 -0500 | [diff] [blame] | 285 | WORK="${WORK} ${FLAGS_working_dir}/config.txt" |
Will Drewry | 69563b7 | 2010-06-24 16:12:58 -0500 | [diff] [blame] | 286 | |
Che-Liang Chiou | 75ac2be | 2011-02-24 12:00:16 +0800 | [diff] [blame] | 287 | bootloader_path="/lib64/bootstub/bootstub.efi" |
| 288 | kernel_image="${FLAGS_vmlinuz}" |
Gaurav Shah | ae5d4d2 | 2014-05-14 17:10:05 -0700 | [diff] [blame] | 289 | elif [[ "${FLAGS_arch}" = "arm" || "${FLAGS_arch}" = "mips" ]]; then |
Che-Liang Chiou | 75ac2be | 2011-02-24 12:00:16 +0800 | [diff] [blame] | 290 | WORK="${WORK} ${FLAGS_working_dir}/config.txt" |
| 291 | |
Che-Liang Chiou | 69faa26 | 2011-06-01 11:52:21 +0800 | [diff] [blame] | 292 | # arm does not need/have a bootloader in kernel partition |
| 293 | dd if="/dev/zero" of="${FLAGS_working_dir}/bootloader.bin" bs=512 count=1 |
| 294 | WORK="${WORK} ${FLAGS_working_dir}/bootloader.bin" |
Che-Liang Chiou | 75ac2be | 2011-02-24 12:00:16 +0800 | [diff] [blame] | 295 | |
Che-Liang Chiou | 69faa26 | 2011-06-01 11:52:21 +0800 | [diff] [blame] | 296 | bootloader_path="${FLAGS_working_dir}/bootloader.bin" |
Che-Liang Chiou | 75ac2be | 2011-02-24 12:00:16 +0800 | [diff] [blame] | 297 | kernel_image="${FLAGS_vmlinuz/vmlinuz/vmlinux.uimg}" |
Che-Liang Chiou | 75ac2be | 2011-02-24 12:00:16 +0800 | [diff] [blame] | 298 | else |
| 299 | error "Unknown arch: ${FLAGS_arch}" |
| 300 | fi |
| 301 | |
Dan Ehrenberg | cdac45f | 2015-01-16 15:16:03 -0800 | [diff] [blame] | 302 | for image_type in $(get_image_types); do |
| 303 | already_seen_rootfs=0 |
| 304 | for partition in $(get_partitions ${image_type}); do |
| 305 | format=$(get_format ${image_type} "${partition}") |
| 306 | if [[ "${format}" == "ubi" ]]; then |
| 307 | type=$(get_type ${image_type} "${partition}") |
| 308 | # cgpt.py ensures that the rootfs partitions are compatible, in that if |
| 309 | # one is ubi then both are, and they have the same number of reserved |
| 310 | # blocks. We only want to attach one of them in boot to save time, so |
| 311 | # attach %P and get the information for whichever rootfs comes first. |
| 312 | if [[ "${type}" == "rootfs" ]]; then |
| 313 | if [[ "${already_seen_rootfs}" -ne 0 ]]; then |
| 314 | continue |
| 315 | fi |
| 316 | already_seen_rootfs=1 |
| 317 | partname='%P' |
| 318 | else |
| 319 | partname="${partition}" |
Dan Ehrenberg | 21cee6e | 2014-11-18 17:29:16 -0800 | [diff] [blame] | 320 | fi |
Dan Ehrenberg | cdac45f | 2015-01-16 15:16:03 -0800 | [diff] [blame] | 321 | reserved=$(get_reserved_erase_blocks ${image_type} "${partition}") |
| 322 | echo "ubi.mtd=${partname},0,${reserved},${partname}" \ |
| 323 | >> "${FLAGS_working_dir}/config.txt" |
| 324 | fs_format=$(get_filesystem_format ${image_type} "${partition}") |
| 325 | if [[ "${fs_format}" != "ubifs" ]]; then |
| 326 | echo "ubi.block=${partname},0" >> "${FLAGS_working_dir}/config.txt" |
| 327 | fi |
Dan Ehrenberg | 21cee6e | 2014-11-18 17:29:16 -0800 | [diff] [blame] | 328 | fi |
Dan Ehrenberg | cdac45f | 2015-01-16 15:16:03 -0800 | [diff] [blame] | 329 | done |
Dan Ehrenberg | 21cee6e | 2014-11-18 17:29:16 -0800 | [diff] [blame] | 330 | done |
| 331 | |
Gabe Black | e41371c | 2014-07-29 15:48:40 -0700 | [diff] [blame] | 332 | config_file="${FLAGS_working_dir}/config.txt" |
| 333 | modify_kernel_command_line "${config_file}" |
| 334 | # Create and sign the kernel blob |
| 335 | vbutil_kernel \ |
| 336 | --pack "${FLAGS_to}" \ |
| 337 | --keyblock "${FLAGS_keys_dir}/${FLAGS_keyblock}" \ |
| 338 | --signprivate "${FLAGS_keys_dir}/${FLAGS_private}" \ |
| 339 | --version 1 \ |
| 340 | --config "${config_file}" \ |
| 341 | --bootloader "${bootloader_path}" \ |
| 342 | --vmlinuz "${kernel_image}" \ |
| 343 | --arch "${FLAGS_arch}" |
| 344 | |
| 345 | # And verify it. |
| 346 | vbutil_kernel \ |
| 347 | --verify "${FLAGS_to}" \ |
| 348 | --signpubkey "${FLAGS_keys_dir}/${FLAGS_public}" |
| 349 | |
| 350 | if [[ -n "${FLAGS_hd_vblock}" ]]; then |
| 351 | dd if="${FLAGS_to}" bs=65536 count=1 of="${FLAGS_hd_vblock}" |
Will Drewry | 69563b7 | 2010-06-24 16:12:58 -0500 | [diff] [blame] | 352 | fi |
| 353 | |
| 354 | set +e # cleanup failure is a-ok |
| 355 | |
| 356 | if [[ ${FLAGS_keep_work} -eq ${FLAGS_FALSE} ]]; then |
Will Drewry | bcbf1c4 | 2010-07-03 10:23:30 -0500 | [diff] [blame] | 357 | info "Cleaning up temporary files: ${WORK}" |
Will Drewry | 69563b7 | 2010-06-24 16:12:58 -0500 | [diff] [blame] | 358 | rm ${WORK} |
| 359 | rmdir ${FLAGS_working_dir} |
| 360 | fi |
| 361 | |
Will Drewry | bcbf1c4 | 2010-07-03 10:23:30 -0500 | [diff] [blame] | 362 | info "Kernel partition image emitted: ${FLAGS_to}" |
| 363 | |
| 364 | if [[ -f ${FLAGS_rootfs_hash} ]]; then |
| 365 | info "Root filesystem hash emitted: ${FLAGS_rootfs_hash}" |
| 366 | fi |