| 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 legacy/efi bootloader partitions. | 7 # Helper script that generates the legacy/efi bootloader partitions. |
| 8 # It does not populate the templates, but can update a loop device. | 8 # It does not populate the templates, but can update a loop device. |
| 9 | 9 |
| 10 . "$(dirname "$0")/common.sh" | 10 . "$(dirname "$0")/common.sh" |
| 11 . "$(dirname "$0")/chromeos-common.sh" # installer | 11 . "$(dirname "$0")/chromeos-common.sh" # installer |
| 12 | 12 |
| 13 get_default_board | 13 get_default_board |
| 14 | 14 |
| 15 # Flags. | 15 # Flags. |
| 16 DEFINE_string arch "x86" \ | 16 DEFINE_string arch "x86" \ |
| 17 "The boot architecture: arm or x86. (Default: x86)" | 17 "The boot architecture: arm or x86. (Default: x86)" |
| 18 # TODO(wad) once extlinux is dead, we can remove this. | 18 # TODO(wad) once extlinux is dead, we can remove this. |
| 19 DEFINE_boolean install_syslinux ${FLAGS_FALSE} \ | 19 DEFINE_boolean install_syslinux ${FLAGS_FALSE} \ |
| 20 "Controls whether syslinux is run on 'to'. (Default: false)" | 20 "Controls whether syslinux is run on 'to'. (Default: false)" |
| 21 DEFINE_string from "/tmp/boot" \ | 21 DEFINE_string from "/tmp/boot" \ |
| 22 "Path the legacy bootloader templates are copied from. (Default /tmp/boot)" | 22 "Path the legacy bootloader templates are copied from. (Default /tmp/boot)" |
| 23 DEFINE_string to "/tmp/esp.img" \ | 23 DEFINE_string to "/tmp/esp.img" \ |
| 24 "Path to esp image or ARM output MBR (Default: /tmp/esp.img)" | 24 "Path to esp image or ARM output MBR (Default: /tmp/esp.img)" |
| 25 DEFINE_integer to_offset 0 \ |
| 26 "Offset in bytes into 'to' if it is a file (Default: 0)" |
| 27 DEFINE_integer to_size -1 \ |
| 28 "Size in bytes of 'to' to use if it is a file. -1 is ignored. (Default: -1)" |
| 25 DEFINE_string vmlinuz "/tmp/vmlinuz" \ | 29 DEFINE_string vmlinuz "/tmp/vmlinuz" \ |
| 26 "Path to the vmlinuz file to use (Default: /tmp/vmlinuz)" | 30 "Path to the vmlinuz file to use (Default: /tmp/vmlinuz)" |
| 27 # The kernel_partition and the kernel_cmdline each are used to supply | 31 # The kernel_partition and the kernel_cmdline each are used to supply |
| 28 # verified boot configuration: dm="". | 32 # verified boot configuration: dm="". |
| 29 DEFINE_string kernel_partition "/tmp/vmlinuz.image" \ | 33 DEFINE_string kernel_partition "/tmp/vmlinuz.image" \ |
| 30 "Path to the signed kernel image. (Default: /tmp/vmlinuz.image)" | 34 "Path to the signed kernel image. (Default: /tmp/vmlinuz.image)" |
| 31 DEFINE_string kernel_cmdline "" \ | 35 DEFINE_string kernel_cmdline "" \ |
| 32 "Kernel commandline if no kernel_partition given. (Default: '')" | 36 "Kernel commandline if no kernel_partition given. (Default: '')" |
| 33 DEFINE_string kernel_partition_offset "0" \ | 37 DEFINE_string kernel_partition_offset "0" \ |
| 34 "Offset to the kernel partition [KERN-A] (Default: 0)" | 38 "Offset to the kernel partition [KERN-A] (Default: 0)" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 # This shouldn't happen. | 103 # This shouldn't happen. |
| 100 info "Creating a new esp image at ${FLAGS_to}" anyway. | 104 info "Creating a new esp image at ${FLAGS_to}" anyway. |
| 101 # Create EFI System Partition to boot stock EFI BIOS (but not ChromeOS EFI | 105 # Create EFI System Partition to boot stock EFI BIOS (but not ChromeOS EFI |
| 102 # BIOS). We only need this for x86, but it's simpler and safer to keep the | 106 # BIOS). We only need this for x86, but it's simpler and safer to keep the |
| 103 # disk images the same for both x86 and ARM. | 107 # disk images the same for both x86 and ARM. |
| 104 # NOTE: The size argument for mkfs.vfat is in 1024-byte blocks. | 108 # NOTE: The size argument for mkfs.vfat is in 1024-byte blocks. |
| 105 # We'll hard-code it to 16M for now. | 109 # We'll hard-code it to 16M for now. |
| 106 ESP_BLOCKS=16384 | 110 ESP_BLOCKS=16384 |
| 107 /usr/sbin/mkfs.vfat -C "${FLAGS_to}" ${ESP_BLOCKS} | 111 /usr/sbin/mkfs.vfat -C "${FLAGS_to}" ${ESP_BLOCKS} |
| 108 ESP_DEV=$(sudo losetup -f) | 112 ESP_DEV=$(sudo losetup -f) |
| 109 test -z "${ESP_DEV}" && error "No free loop devices." | 113 if [ -z "${ESP_DEV}" ]; then |
| 114 die "No free loop devices." |
| 115 fi |
| 110 sudo losetup "${ESP_DEV}" "${FLAGS_to}" | 116 sudo losetup "${ESP_DEV}" "${FLAGS_to}" |
| 111 else | 117 else |
| 112 if [[ -f "${FLAGS_to}" ]]; then | 118 if [[ -f "${FLAGS_to}" ]]; then |
| 113 ESP_DEV=$(sudo losetup -f) | 119 ESP_DEV=$(sudo losetup -f) |
| 114 test -z "${ESP_DEV}" && error "No free loop devices." | 120 if [ -z "${ESP_DEV}" ]; then |
| 115 sudo losetup "${ESP_DEV}" "${FLAGS_to}" | 121 die "No free loop devices." |
| 122 fi |
| 123 |
| 124 esp_offset="--offset ${FLAGS_to_offset}" |
| 125 esp_size="--sizelimit ${FLAGS_to_size}" |
| 126 if [ ${FLAGS_to_size} -lt 0 ]; then |
| 127 esp_size= |
| 128 fi |
| 129 sudo losetup ${esp_offset} ${esp_size} "${ESP_DEV}" "${FLAGS_to}" |
| 116 else | 130 else |
| 117 # If it is a block device or something else, try to mount it anyway. | 131 # If it is a block device or something else, try to mount it anyway. |
| 118 ESP_DEV="${FLAGS_to}" | 132 ESP_DEV="${FLAGS_to}" |
| 119 fi | 133 fi |
| 120 fi | 134 fi |
| 121 | 135 |
| 122 ESP_FS_DIR=$(mktemp -d /tmp/esp.XXXXXX) | 136 ESP_FS_DIR=$(mktemp -d /tmp/esp.XXXXXX) |
| 123 cleanup() { | 137 cleanup() { |
| 124 set +e | 138 set +e |
| 125 sudo umount "${ESP_FS_DIR}" | 139 sudo umount "${ESP_FS_DIR}" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 fi | 174 fi |
| 161 update_x86_bootloaders "${old_root}" \ | 175 update_x86_bootloaders "${old_root}" \ |
| 162 "${kernel_cfg}" \ | 176 "${kernel_cfg}" \ |
| 163 "${ESP_FS_DIR}" \ | 177 "${ESP_FS_DIR}" \ |
| 164 "${FLAGS_from}" | 178 "${FLAGS_from}" |
| 165 | 179 |
| 166 # Install the syslinux loader on the ESP image (part 12) so it is ready when | 180 # Install the syslinux loader on the ESP image (part 12) so it is ready when |
| 167 # we cut over from rootfs booting (extlinux). | 181 # we cut over from rootfs booting (extlinux). |
| 168 if [[ ${FLAGS_install_syslinux} -eq ${FLAGS_TRUE} ]]; then | 182 if [[ ${FLAGS_install_syslinux} -eq ${FLAGS_TRUE} ]]; then |
| 169 sudo umount "${ESP_FS_DIR}" | 183 sudo umount "${ESP_FS_DIR}" |
| 170 sudo syslinux -d /syslinux "${FLAGS_to}" | 184 sudo syslinux -d /syslinux "${ESP_DEV}" |
| 171 fi | 185 fi |
| 172 elif [[ "${FLAGS_arch}" = "arm" ]]; then | 186 elif [[ "${FLAGS_arch}" = "arm" ]]; then |
| 173 # Extract kernel flags | 187 # Extract kernel flags |
| 174 kernel_cfg= | 188 kernel_cfg= |
| 175 old_root="sd%D%P" | 189 old_root="sd%D%P" |
| 176 if [[ -n "${FLAGS_kernel_cmdline}" ]]; then | 190 if [[ -n "${FLAGS_kernel_cmdline}" ]]; then |
| 177 info "Using supplied kernel_cmdline to update templates." | 191 info "Using supplied kernel_cmdline to update templates." |
| 178 kernel_cfg="${FLAGS_kernel_cmdline}" | 192 kernel_cfg="${FLAGS_kernel_cmdline}" |
| 179 elif [[ -n "${FLAGS_kernel_partition}" ]]; then | 193 elif [[ -n "${FLAGS_kernel_partition}" ]]; then |
| 180 info "Extracting the kernel command line from ${FLAGS_kernel_partition}" | 194 info "Extracting the kernel command line from ${FLAGS_kernel_partition}" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 198 ${FLAGS_kernel_partition_offset} \ | 212 ${FLAGS_kernel_partition_offset} \ |
| 199 ${FLAGS_kernel_partition_sectors} \ | 213 ${FLAGS_kernel_partition_sectors} \ |
| 200 ${device} \ | 214 ${device} \ |
| 201 "'dm=\"${dm_table}\"'") | 215 "'dm=\"${dm_table}\"'") |
| 202 sudo dd bs=1 count=`stat --printf="%s" ${MBR_SCRIPT_UIMG}` \ | 216 sudo dd bs=1 count=`stat --printf="%s" ${MBR_SCRIPT_UIMG}` \ |
| 203 if="$MBR_SCRIPT_UIMG" of=${FLAGS_to} | 217 if="$MBR_SCRIPT_UIMG" of=${FLAGS_to} |
| 204 info "Emitted new ARM MBR to ${FLAGS_to}" | 218 info "Emitted new ARM MBR to ${FLAGS_to}" |
| 205 fi | 219 fi |
| 206 | 220 |
| 207 set +e | 221 set +e |
| OLD | NEW |