OLD | NEW |
---|---|
1 #!/bin/bash | 1 #!/bin/bash |
2 | 2 |
3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 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 | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 # Helper script that generates the signed kernel image | 7 # Helper script that generates the signed kernel image |
8 | 8 |
9 # --- BEGIN COMMON.SH BOILERPLATE --- | 9 # --- BEGIN COMMON.SH BOILERPLATE --- |
10 # Load common CrOS utilities. Inside the chroot this file is installed in | 10 # Load common CrOS utilities. Inside the chroot this file is installed in |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
62 DEFINE_integer verity_error_behavior 2 \ | 62 DEFINE_integer verity_error_behavior 2 \ |
63 "Verified boot error behavior [0: I/O errors, 1: reboot, 2: nothing] \ | 63 "Verified boot error behavior [0: I/O errors, 1: reboot, 2: nothing] \ |
64 (Default: 2)" | 64 (Default: 2)" |
65 DEFINE_integer verity_tree_depth 1 \ | 65 DEFINE_integer verity_tree_depth 1 \ |
66 "Optional Verified boot hash tree depth. (Default: 1)" | 66 "Optional Verified boot hash tree depth. (Default: 1)" |
67 DEFINE_integer verity_max_ios 1024 \ | 67 DEFINE_integer verity_max_ios 1024 \ |
68 "Optional number of outstanding I/O operations. (Default: 1024)" | 68 "Optional number of outstanding I/O operations. (Default: 1024)" |
69 DEFINE_string verity_hash_alg "sha1" \ | 69 DEFINE_string verity_hash_alg "sha1" \ |
70 "Cryptographic hash algorithm used for dm-verity. (Default: sha1)" | 70 "Cryptographic hash algorithm used for dm-verity. (Default: sha1)" |
71 | 71 |
72 # TODO(clchiou): Change default to FLAGS_TRUE once ARM verify boot is stable? | |
73 DEFINE_boolean enable_kernel_signing ${FLAGS_FALSE} \ | |
Will Drewry
2011/02/17 16:54:09
This flag, at best, should be called something lik
Che-Liang Chiou
2011/02/21 11:08:39
Done.
| |
74 "Sign kernel partition for ARM images." | |
75 | |
72 # Parse flags | 76 # Parse flags |
73 FLAGS "$@" || exit 1 | 77 FLAGS "$@" || exit 1 |
74 eval set -- "${FLAGS_ARGV}" | 78 eval set -- "${FLAGS_ARGV}" |
75 | 79 |
76 # Die on error | 80 # Die on error |
77 set -e | 81 set -e |
78 | 82 |
79 verity_args= | 83 verity_args= |
80 # Even with a rootfs_image, root= is not changed unless specified. | 84 # Even with a rootfs_image, root= is not changed unless specified. |
81 if [[ -n "${FLAGS_rootfs_image}" && -n "${FLAGS_rootfs_hash}" ]]; then | 85 if [[ -n "${FLAGS_rootfs_image}" && -n "${FLAGS_rootfs_hash}" ]]; then |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
136 dm_verity.error_behavior=${FLAGS_verity_error_behavior} | 140 dm_verity.error_behavior=${FLAGS_verity_error_behavior} |
137 dm_verity.max_bios=${FLAGS_verity_max_ios} | 141 dm_verity.max_bios=${FLAGS_verity_max_ios} |
138 dm_verity.dev_wait=${dev_wait} | 142 dm_verity.dev_wait=${dev_wait} |
139 ${verity_args} | 143 ${verity_args} |
140 ${FLAGS_boot_args} | 144 ${FLAGS_boot_args} |
141 EOF | 145 EOF |
142 | 146 |
143 WORK="${WORK} ${FLAGS_working_dir}/boot.config" | 147 WORK="${WORK} ${FLAGS_working_dir}/boot.config" |
144 info "Emitted cross-platform boot params to ${FLAGS_working_dir}/boot.config" | 148 info "Emitted cross-platform boot params to ${FLAGS_working_dir}/boot.config" |
145 | 149 |
146 # FIXME: At the moment, we're working on signed images for x86 only. ARM will | 150 # FIXME: At the moment, we're working on signed images for x86 only, and |
147 # support this before shipping, but at the moment they don't. | 151 # signed images for ARM if enabled. |
148 if [[ "${FLAGS_arch}" = "x86" ]]; then | 152 if [[ "${FLAGS_arch}" = "x86" || |
153 ${FLAGS_enable_kernel_signing} -eq ${FLAGS_TRUE} ]]; then | |
Will Drewry
2011/02/17 16:54:09
This is making things pretty complex.
Why can't w
Che-Liang Chiou
2011/02/21 11:08:39
I rewrote this part of logic. I hope I did not mis
| |
149 | 154 |
150 # Legacy BIOS will use the kernel in the rootfs (via syslinux), as will | 155 # Legacy BIOS will use the kernel in the rootfs (via syslinux), as will |
151 # standard EFI BIOS (via grub, from the EFI System Partition). Chrome OS | 156 # standard EFI BIOS (via grub, from the EFI System Partition). Chrome OS |
152 # BIOS will use a separate signed kernel partition, which we'll create now. | 157 # BIOS will use a separate signed kernel partition, which we'll create now. |
153 # FIXME: remove serial output, debugging messages. | 158 # FIXME: remove serial output, debugging messages. |
154 mkdir -p ${FLAGS_working_dir} | 159 mkdir -p ${FLAGS_working_dir} |
155 cat <<EOF | cat - "${FLAGS_working_dir}/boot.config" \ | 160 if [[ "${FLAGS_arch}" = "x86" ]]; then |
156 > "${FLAGS_working_dir}/config.txt" | 161 cat <<EOF | cat - "${FLAGS_working_dir}/boot.config" \ |
162 > "${FLAGS_working_dir}/config.txt" | |
157 console=tty2 | 163 console=tty2 |
158 init=/sbin/init | 164 init=/sbin/init |
159 add_efi_memmap | 165 add_efi_memmap |
160 boot=local | 166 boot=local |
161 noresume | 167 noresume |
162 noswap | 168 noswap |
163 i915.modeset=1 | 169 i915.modeset=1 |
164 cros_secure | 170 cros_secure |
165 kern_guid=%U | 171 kern_guid=%U |
166 tpm_tis.force=1 | 172 tpm_tis.force=1 |
167 tpm_tis.interrupts=0 | 173 tpm_tis.interrupts=0 |
168 EOF | 174 EOF |
175 | |
176 bootloader_path="/lib64/bootstub/bootstub.efi" | |
177 notx86="" | |
178 kernel_image="${FLAGS_vmlinuz}" | |
179 elif [[ "${FLAGS_arch}" = "arm" ]]; then | |
180 cp "${FLAGS_working_dir}/boot.config" "${FLAGS_working_dir}/config.txt" | |
181 | |
182 # FIXME: Build boot script image as bootloader. Remove this. | |
183 kernel_script="${FLAGS_working_dir}/kernel.scr" | |
184 kernel_script_img="${FLAGS_working_dir}/kernel.scr.uimg" | |
185 WORK="${WORK} ${kernel_script} ${kernel_script_img}" | |
186 echo -n 'setenv bootargs ${bootargs} ' > "${kernel_script}" | |
187 tr '\n' ' ' <"${FLAGS_working_dir}/boot.config" >> "${kernel_script}" | |
188 mkimage -A arm -O linux -T script -C none -a 0 -e 0 \ | |
189 -n kernel_script -d "${kernel_script}" "${kernel_script_img}" | |
190 | |
191 bootloader_path="${kernel_script_img}" | |
192 notx86="--notx86" | |
Will Drewry
2011/02/17 16:54:09
? Why isn't this an --arch arm flag?
Che-Liang Chiou
2011/02/21 11:08:39
Because it was meant to turn-off x86-only operatio
| |
193 # FIXME: Change from uImage to zImage | |
194 kernel_image="${FLAGS_vmlinuz/vmlinuz/vmlinux.uimg}" | |
195 else | |
196 error "Unknown arch: ${FLAGS_arch}" | |
197 fi | |
169 WORK="${WORK} ${FLAGS_working_dir}/config.txt" | 198 WORK="${WORK} ${FLAGS_working_dir}/config.txt" |
170 | 199 |
171 # We sign the image with the recovery_key, because this is what goes onto the | 200 # We sign the image with the recovery_key, because this is what goes onto the |
172 # USB key. We can only boot from the USB drive in recovery mode. | 201 # USB key. We can only boot from the USB drive in recovery mode. |
173 # For dev install shim, we need to use the installer keyblock instead of | 202 # For dev install shim, we need to use the installer keyblock instead of |
174 # the recovery keyblock because of the difference in flags. | 203 # the recovery keyblock because of the difference in flags. |
175 if [ ${FLAGS_use_dev_keys} -eq ${FLAGS_TRUE} ]; then | 204 if [ ${FLAGS_use_dev_keys} -eq ${FLAGS_TRUE} ]; then |
176 USB_KEYBLOCK=installer_kernel.keyblock | 205 USB_KEYBLOCK=installer_kernel.keyblock |
177 info "DEBUG: use dev install signing key" | 206 info "DEBUG: use dev install signing key" |
178 else | 207 else |
179 USB_KEYBLOCK=recovery_kernel.keyblock | 208 USB_KEYBLOCK=recovery_kernel.keyblock |
180 info "DEBUG: use recovery signing key" | 209 info "DEBUG: use recovery signing key" |
181 fi | 210 fi |
182 | 211 |
183 # Create and sign the kernel blob | 212 # Create and sign the kernel blob |
184 vbutil_kernel \ | 213 vbutil_kernel \ |
185 --pack "${FLAGS_to}" \ | 214 --pack "${FLAGS_to}" \ |
186 --keyblock "${FLAGS_keys_dir}/${USB_KEYBLOCK}" \ | 215 --keyblock "${FLAGS_keys_dir}/${USB_KEYBLOCK}" \ |
187 --signprivate "${FLAGS_keys_dir}/recovery_kernel_data_key.vbprivk" \ | 216 --signprivate "${FLAGS_keys_dir}/recovery_kernel_data_key.vbprivk" \ |
188 --version 1 \ | 217 --version 1 \ |
189 --config "${FLAGS_working_dir}/config.txt" \ | 218 --config "${FLAGS_working_dir}/config.txt" \ |
190 --bootloader /lib64/bootstub/bootstub.efi \ | 219 --bootloader "${bootloader_path}" \ |
191 --vmlinuz "${FLAGS_vmlinuz}" | 220 --vmlinuz "${kernel_image}" \ |
221 ${notx86} | |
Will Drewry
2011/02/17 16:54:09
If this just used the arch, then you wouldn't need
Che-Liang Chiou
2011/02/21 11:08:39
Done.
| |
192 | 222 |
193 # And verify it. | 223 # And verify it. |
194 vbutil_kernel \ | 224 vbutil_kernel \ |
195 --verify "${FLAGS_to}" \ | 225 --verify "${FLAGS_to}" \ |
196 --signpubkey "${FLAGS_keys_dir}/recovery_key.vbpubk" | 226 --signpubkey "${FLAGS_keys_dir}/recovery_key.vbpubk" |
197 | 227 |
198 | 228 |
199 # Now we re-sign the same image using the normal keys. This is the kernel | 229 # Now we re-sign the same image using the normal keys. This is the kernel |
200 # image that is put on the hard disk by the installer. Note: To save space on | 230 # image that is put on the hard disk by the installer. Note: To save space on |
201 # the USB image, we're only emitting the new verfication block, and the | 231 # the USB image, we're only emitting the new verfication block, and the |
(...skipping 12 matching lines...) Expand all Loading... | |
214 cat "${FLAGS_hd_vblock}" > $tempfile | 244 cat "${FLAGS_hd_vblock}" > $tempfile |
215 dd if="${FLAGS_to}" bs=65536 skip=1 >> $tempfile | 245 dd if="${FLAGS_to}" bs=65536 skip=1 >> $tempfile |
216 | 246 |
217 vbutil_kernel \ | 247 vbutil_kernel \ |
218 --verify $tempfile \ | 248 --verify $tempfile \ |
219 --signpubkey "${FLAGS_keys_dir}/kernel_subkey.vbpubk" | 249 --signpubkey "${FLAGS_keys_dir}/kernel_subkey.vbpubk" |
220 | 250 |
221 rm -f $tempfile | 251 rm -f $tempfile |
222 trap - EXIT | 252 trap - EXIT |
223 | 253 |
224 elif [[ "${FLAGS_arch}" = "arm" ]]; then | 254 elif [[ "${FLAGS_arch}" = "arm" && \ |
225 # FIXME: This stuff is unsigned, and will likely change with vboot_reference | 255 ${FLAGS_enable_kernel_signing} -eq ${FLAGS_FALSE} ]]; then |
226 # but it doesn't technically have to. | 256 # FIXME: This stuff is unsigned. This part should be removed or made |
257 # non-default after ARM verified boot is stable. | |
227 | 258 |
228 kernel_script="${FLAGS_working_dir}/kernel.scr" | 259 kernel_script="${FLAGS_working_dir}/kernel.scr" |
229 kernel_script_img="${FLAGS_working_dir}/kernel.scr.uimg" | 260 kernel_script_img="${FLAGS_working_dir}/kernel.scr.uimg" |
230 # HACK: !! Kernel image construction requires some stuff from portage, not | 261 # HACK: !! Kernel image construction requires some stuff from portage, not |
231 # sure how to get that information here cleanly !! | 262 # sure how to get that information here cleanly !! |
232 kernel_image="${FLAGS_vmlinuz/vmlinuz/vmlinux.uimg}" | 263 kernel_image="${FLAGS_vmlinuz/vmlinuz/vmlinux.uimg}" |
233 WORK="${WORK} ${kernel_script} ${kernel_script_img}" | 264 WORK="${WORK} ${kernel_script} ${kernel_script_img}" |
234 | 265 |
235 kernel_size=$((($(stat -c %s "${kernel_image}") + 511) / 512)) | 266 kernel_size=$((($(stat -c %s "${kernel_image}") + 511) / 512)) |
236 script_size=16 | 267 script_size=16 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
270 info "Cleaning up temporary files: ${WORK}" | 301 info "Cleaning up temporary files: ${WORK}" |
271 rm ${WORK} | 302 rm ${WORK} |
272 rmdir ${FLAGS_working_dir} | 303 rmdir ${FLAGS_working_dir} |
273 fi | 304 fi |
274 | 305 |
275 info "Kernel partition image emitted: ${FLAGS_to}" | 306 info "Kernel partition image emitted: ${FLAGS_to}" |
276 | 307 |
277 if [[ -f ${FLAGS_rootfs_hash} ]]; then | 308 if [[ -f ${FLAGS_rootfs_hash} ]]; then |
278 info "Root filesystem hash emitted: ${FLAGS_rootfs_hash}" | 309 info "Root filesystem hash emitted: ${FLAGS_rootfs_hash}" |
279 fi | 310 fi |
OLD | NEW |