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 # TODO(wad) once extlinux is dead, we can remove this. |
| 17 DEFINE_boolean install ${FLAGS_FALSE} \ |
| 18 "Controls whether extlinux is run on 'to'. (Default: false)" |
| 19 DEFINE_string to "/tmp/boot" \ |
| 20 "Path to populate with bootloader templates (Default: /tmp/boot)" |
| 21 DEFINE_string usb_disk /dev/sdb3 \ |
| 22 "Path syslinux should use to do a usb boot. Default: /dev/sdb3" |
| 23 DEFINE_string boot_args "" \ |
| 24 "Additional boot arguments to pass to the commandline (Default: '')" |
| 25 DEFINE_boolean use_vboot ${FLAGS_FALSE} \ |
| 26 "Controls whether the default boot targets are verified (Default: false)" |
| 27 DEFINE_integer vboot_error_behavior 2 \ |
| 28 "Verified boot error behavior [0: I/O errors, 1: reboot, 2: nothing] \ |
| 29 (Default: 2)" |
| 30 DEFINE_integer vboot_max_ios 1024 \ |
| 31 "Optional number of outstanding I/O operations. (Default: 1024)" |
| 32 |
| 33 # Parse flags |
| 34 FLAGS "$@" || exit 1 |
| 35 eval set -- "${FLAGS_ARGV}" |
| 36 set -e |
| 37 |
| 38 # Common kernel command-line args |
| 39 common_args="quiet console=tty2 init=/sbin/init boot=local rootwait ro noresume" |
| 40 common_args="${common_args} noswap loglevel=1" |
| 41 |
| 42 # Common verified boot command-line args |
| 43 vboot_common="dm_verity.error_behavior=${FLAGS_vboot_error_behavior}" |
| 44 vboot_common="${vboot_common} dm_verity.max_bios=${FLAGS_vboot_max_ios}" |
| 45 |
| 46 # Populate the x86 rootfs to support legacy and EFI bios config templates. |
| 47 # The templates are used by the installer to populate partition 12 with |
| 48 # the correct bootloader configuration. |
| 49 # While we transition to that model, extlinux.conf will still be used |
| 50 # on the root filesystem. |
| 51 if [[ "${FLAGS_arch}" == "x86" ]]; then |
| 52 # Setup extlinux configuration. |
| 53 # TODO: For some reason the /dev/disk/by-uuid is not being generated by udev |
| 54 # in the initramfs. When we figure that out, switch to root=UUID=${UUID}. |
| 55 sudo mkdir -p ${FLAGS_to} |
| 56 # TODO(adlr): use initramfs for booting. |
| 57 cat <<EOF | sudo dd of="${FLAGS_to}"/extlinux.conf 2>/dev/null |
| 58 DEFAULT chromeos-usb |
| 59 PROMPT 0 |
| 60 TIMEOUT 0 |
| 61 |
| 62 label chromeos-usb |
| 63 menu label chromeos-usb |
| 64 kernel vmlinuz |
| 65 append ${common_args} root=/dev/sdb3 i915.modeset=1 cros_legacy |
| 66 |
| 67 label chromeos-hd |
| 68 menu label chromeos-hd |
| 69 kernel vmlinuz |
| 70 append ${common_args} root=HDROOT i915.modeset=1 cros_legacy |
| 71 EOF |
| 72 |
| 73 # Make partition bootable and label it. |
| 74 # TODO(wad) remove this after we've transitioned everyone to syslinux. |
| 75 if [[ ${FLAGS_install} -eq ${FLAGS_TRUE} ]]; then |
| 76 sudo extlinux -z --install "${FLAGS_to}" |
| 77 fi |
| 78 |
| 79 # /boot/syslinux must be installed in partition 12 as /syslinux/. |
| 80 SYSLINUX_DIR="${FLAGS_to}/syslinux" |
| 81 sudo mkdir -p "${SYSLINUX_DIR}" |
| 82 |
| 83 cat <<EOF | sudo dd of="${SYSLINUX_DIR}/syslinux.cfg" 2>/dev/null |
| 84 PROMPT 0 |
| 85 TIMEOUT 0 |
| 86 |
| 87 # the actual target |
| 88 include /syslinux/default.cfg |
| 89 |
| 90 # chromeos-usb.A |
| 91 include /syslinux/usb.A.cfg |
| 92 |
| 93 # chromeos-hd.A / chromeos-vhd.A |
| 94 include /syslinux/root.A.cfg |
| 95 |
| 96 # chromeos-hd.B / chromeos-vhd.B |
| 97 include /syslinux/root.B.cfg |
| 98 EOF |
| 99 info "Emitted ${SYSLINUX_DIR}/syslinux.cfg" |
| 100 |
| 101 if [[ ${FLAGS_use_vboot} -eq ${FLAGS_TRUE} ]]; then |
| 102 # To change the active target, only this file needs to change. |
| 103 cat <<EOF | sudo dd of="${SYSLINUX_DIR}/default.cfg" 2>/dev/null |
| 104 DEFAULT chromeos-vusb.A |
| 105 EOF |
| 106 else |
| 107 cat <<EOF | sudo dd of="${SYSLINUX_DIR}/default.cfg" 2>/dev/null |
| 108 DEFAULT chromeos-usb.A |
| 109 EOF |
| 110 fi |
| 111 info "Emitted ${SYSLINUX_DIR}/default.cfg" |
| 112 |
| 113 cat <<EOF | sudo dd of="${SYSLINUX_DIR}/usb.A.cfg" 2>/dev/null |
| 114 label chromeos-usb.A |
| 115 menu label chromeos-usb.A |
| 116 kernel vmlinuz.A |
| 117 append ${common_args} root=${FLAGS_usb_disk} i915.modeset=1 cros_legacy |
| 118 |
| 119 label chromeos-vusb.A |
| 120 menu label chromeos-vusb.A |
| 121 kernel vmlinuz.A |
| 122 append ${common_args} ${vboot_common} root=/dev/dm-0 i915.modeset=1 cros_legac
y dm="DMTABLEA" |
| 123 EOF |
| 124 info "Emitted ${SYSLINUX_DIR}/usb.A.cfg" |
| 125 |
| 126 # Different files are used so that the updater can only touch the file it |
| 127 # needs to for a given change. This will minimize any potential accidental |
| 128 # updates issues, hopefully. |
| 129 cat <<EOF | sudo dd of="${SYSLINUX_DIR}/root.A.cfg" 2>/dev/null |
| 130 label chromeos-hd.A |
| 131 menu label chromeos-hd.A |
| 132 kernel vmlinuz.A |
| 133 append ${common_args} root=HDROOTA i915.modeset=1 cros_legacy |
| 134 |
| 135 label chromeos-vhd.A |
| 136 menu label chromeos-vhd.A |
| 137 kernel vmlinuz.A |
| 138 append ${common_args} ${vboot_common} root=/dev/dm-0 i915.modeset=1 cros_legac
y dm="DMTABLEA" |
| 139 EOF |
| 140 info "Emitted ${SYSLINUX_DIR}/root.A.cfg" |
| 141 |
| 142 cat <<EOF | sudo dd of="${SYSLINUX_DIR}/root.B.cfg" 2>/dev/null |
| 143 label chromeos-hd.B |
| 144 menu label chromeos-hd.B |
| 145 kernel vmlinuz.B |
| 146 append ${common_args} root=HDROOTB i915.modeset=1 cros_legacy |
| 147 |
| 148 label chromeos-vhd.B |
| 149 menu label chromeos-vhd.B |
| 150 kernel vmlinuz.B |
| 151 append ${common_args} ${vboot_common} root=/dev/dm-0 i915.modeset=1 cros_legac
y dm="DMTABLEB" |
| 152 EOF |
| 153 info "Emitted ${SYSLINUX_DIR}/root.B.cfg" |
| 154 |
| 155 cat <<EOF | sudo dd of="${SYSLINUX_DIR}/README" 2>/dev/null |
| 156 Partition 12 contains the active bootloader configuration when |
| 157 booting from a non-Chrome OS BIOS. EFI BIOSes use /efi/* |
| 158 and legacy BIOSes use this syslinux configuration. |
| 159 EOF |
| 160 info "Emitted ${SYSLINUX_DIR}/README" |
| 161 |
| 162 # To cover all of our bases, now populate templated boot support for efi. |
| 163 sudo mkdir -p "${FLAGS_to}"/efi/boot |
| 164 sudo grub-mkimage -p /efi/boot -o "${FLAGS_to}/efi/boot/bootx64.efi" \ |
| 165 part_gpt fat ext2 normal boot sh chain configfile linux |
| 166 # Templated variables: |
| 167 # DMTABLEA, DMTABLEB -> '0 xxxx verity ... ' |
| 168 # This should be replaced during postinst when updating the ESP. |
| 169 cat <<EOF | sudo dd of="${FLAGS_to}/efi/boot/grub.cfg" 2>/dev/null |
| 170 set default=0 |
| 171 set timeout=2 |
| 172 |
| 173 # NOTE: These magic grub variables are a Chrome OS hack. They are not portable. |
| 174 |
| 175 menuentry "local image A" { |
| 176 linux \$grubpartA/boot/vmlinuz ${common_args} i915.modeset=1 cros_efi root=/de
v/\$linuxpartA |
| 177 } |
| 178 |
| 179 menuentry "local image B" { |
| 180 linux \$grubpartB/boot/vmlinuz ${common_args} i915.modeset=1 cros_efi root=/de
v/\$linuxpartB |
| 181 } |
| 182 |
| 183 menuentry "verified image A" { |
| 184 linux \$grubpartA/boot/vmlinuz ${common_args} ${vboot_common} i915.modeset=1 c
ros_efi root=/dev/dm-0 dm="DMTABLEA" |
| 185 } |
| 186 |
| 187 menuentry "verified image B" { |
| 188 linux \$grubpartB/boot/vmlinuz ${common_args} ${vboot_common} i915.modeset=1 c
ros_efi root=/dev/dm-0 dm="DMTABLEB" |
| 189 } |
| 190 |
| 191 # FIXME: usb doesn't support verified boot for now |
| 192 menuentry "Alternate USB Boot" { |
| 193 linux (hd0,3)/boot/vmlinuz ${common_args} root=/dev/sdb3 i915.modeset=1 cros_e
fi |
| 194 } |
| 195 EOF |
| 196 if [[ ${FLAGS_use_vboot} -eq ${FLAGS_TRUE} ]]; then |
| 197 sed -i -e 's/^set default=.*/set default=2/' "${FLAGS_to}/efi/boot/grub.cfg" |
| 198 fi |
| 199 info "Emitted ${FLAGS_to}/efi/boot/grub.cfg" |
| 200 exit 0 |
| 201 fi |
| 202 |
| 203 info "The target platform does not use bootloader templates." |
OLD | NEW |