| 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 # --- BEGIN COMMON.SH BOILERPLATE --- | 10 # --- BEGIN COMMON.SH BOILERPLATE --- |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 FLAGS "$@" || exit 1 | 70 FLAGS "$@" || exit 1 |
| 71 eval set -- "${FLAGS_ARGV}" | 71 eval set -- "${FLAGS_ARGV}" |
| 72 set -e | 72 set -e |
| 73 | 73 |
| 74 # If not provided by chromeos-common.sh, this will update all of the | 74 # If not provided by chromeos-common.sh, this will update all of the |
| 75 # boot loader files (both A and B) with the data pulled | 75 # boot loader files (both A and B) with the data pulled |
| 76 # from the kernel_partition. The default boot target should | 76 # from the kernel_partition. The default boot target should |
| 77 # be set when the rootfs is stuffed. | 77 # be set when the rootfs is stuffed. |
| 78 if ! type -p update_x86_bootloaders; then | 78 if ! type -p update_x86_bootloaders; then |
| 79 update_x86_bootloaders() { | 79 update_x86_bootloaders() { |
| 80 local old_root="$1" # e.g., sd%D%P | 80 local old_root="$1" # e.g., /dev/sd%D%P or %U+1 |
| 81 local kernel_cmdline="$2" | 81 local kernel_cmdline="$2" |
| 82 local esp_fs_dir="$3" | 82 local esp_fs_dir="$3" |
| 83 local template_dir="$4" | 83 local template_dir="$4" |
| 84 | 84 |
| 85 # Pull out the dm="" values | 85 # Pull out the dm="" values |
| 86 dm_table= | 86 dm_table= |
| 87 if echo "$kernel_cmdline" | grep -q 'dm="'; then | 87 if echo "$kernel_cmdline" | grep -q 'dm="'; then |
| 88 dm_table=$(echo "$kernel_cmdline" | sed -s 's/.*dm="\([^"]*\)".*/\1/') | 88 dm_table=$(echo "$kernel_cmdline" | sed -s 's/.*dm="\([^"]*\)".*/\1/') |
| 89 fi | 89 fi |
| 90 | 90 |
| 91 # Rewrite grub table | 91 # Rewrite grub table |
| 92 grub_dm_table_a=${dm_table//${old_root}/\$linuxpartA} | 92 grub_dm_table_a=${dm_table//${old_root}/\/dev\/\$linuxpartA} |
| 93 grub_dm_table_b=${dm_table//${old_root}/\$linuxpartB} | 93 grub_dm_table_b=${dm_table//${old_root}/\/dev\/\$linuxpartB} |
| 94 sed -e "s|DMTABLEA|${grub_dm_table_a}|g" \ | 94 sed -e "s|DMTABLEA|${grub_dm_table_a}|g" \ |
| 95 -e "s|DMTABLEB|${grub_dm_table_b}|g" \ | 95 -e "s|DMTABLEB|${grub_dm_table_b}|g" \ |
| 96 "${template_dir}"/efi/boot/grub.cfg | | 96 "${template_dir}"/efi/boot/grub.cfg | |
| 97 sudo dd of="${esp_fs_dir}"/efi/boot/grub.cfg | 97 sudo dd of="${esp_fs_dir}"/efi/boot/grub.cfg |
| 98 | 98 |
| 99 # Rewrite syslinux DM_TABLE | 99 # Rewrite syslinux DM_TABLE |
| 100 syslinux_dm_table_usb=${dm_table//\/dev\/${old_root}/${FLAGS_usb_disk}} | 100 syslinux_dm_table_usb=${dm_table//${old_root}/${FLAGS_usb_disk}} |
| 101 sed -e "s|DMTABLEA|${syslinux_dm_table_usb}|g" \ | 101 sed -e "s|DMTABLEA|${syslinux_dm_table_usb}|g" \ |
| 102 "${template_dir}"/syslinux/usb.A.cfg | | 102 "${template_dir}"/syslinux/usb.A.cfg | |
| 103 sudo dd of="${esp_fs_dir}"/syslinux/usb.A.cfg | 103 sudo dd of="${esp_fs_dir}"/syslinux/usb.A.cfg |
| 104 | 104 |
| 105 syslinux_dm_table_a=${dm_table//\/dev\/${old_root}/HDROOTA} | 105 syslinux_dm_table_a=${dm_table//${old_root}/HDROOTA} |
| 106 sed -e "s|DMTABLEA|${syslinux_dm_table_a}|g" \ | 106 sed -e "s|DMTABLEA|${syslinux_dm_table_a}|g" \ |
| 107 "${template_dir}"/syslinux/root.A.cfg | | 107 "${template_dir}"/syslinux/root.A.cfg | |
| 108 sudo dd of="${esp_fs_dir}"/syslinux/root.A.cfg | 108 sudo dd of="${esp_fs_dir}"/syslinux/root.A.cfg |
| 109 | 109 |
| 110 syslinux_dm_table_b=${dm_table//\/dev\/${old_root}/HDROOTB} | 110 syslinux_dm_table_b=${dm_table//${old_root}/HDROOTB} |
| 111 sed -e "s|DMTABLEB|${syslinux_dm_table_b}|g" \ | 111 sed -e "s|DMTABLEB|${syslinux_dm_table_b}|g" \ |
| 112 "${template_dir}"/syslinux/root.B.cfg | | 112 "${template_dir}"/syslinux/root.B.cfg | |
| 113 sudo dd of="${esp_fs_dir}"/syslinux/root.B.cfg | 113 sudo dd of="${esp_fs_dir}"/syslinux/root.B.cfg |
| 114 | 114 |
| 115 # Copy the vmlinuz's into place for syslinux | 115 # Copy the vmlinuz's into place for syslinux |
| 116 sudo cp -f "${template_dir}"/vmlinuz "${esp_fs_dir}"/syslinux/vmlinuz.A | 116 sudo cp -f "${template_dir}"/vmlinuz "${esp_fs_dir}"/syslinux/vmlinuz.A |
| 117 sudo cp -f "${template_dir}"/vmlinuz "${esp_fs_dir}"/syslinux/vmlinuz.B | 117 sudo cp -f "${template_dir}"/vmlinuz "${esp_fs_dir}"/syslinux/vmlinuz.B |
| 118 | 118 |
| 119 # The only work left for the installer is to pick the correct defaults | 119 # The only work left for the installer is to pick the correct defaults |
| 120 # and replace HDROOTA and HDROOTB with the correct /dev/sd%D%P. | 120 # and replace HDROOTA and HDROOTB with the correct /dev/sd%D%P/%U+1 |
| 121 } | 121 } |
| 122 fi | 122 fi |
| 123 | 123 |
| 124 ESP_DEV= | 124 ESP_DEV= |
| 125 if [[ ! -e "${FLAGS_to}" ]]; then | 125 if [[ ! -e "${FLAGS_to}" ]]; then |
| 126 error "The ESP doesn't exist" | 126 error "The ESP doesn't exist" |
| 127 # This shouldn't happen. | 127 # This shouldn't happen. |
| 128 info "Creating a new esp image at ${FLAGS_to}" anyway. | 128 info "Creating a new esp image at ${FLAGS_to}" anyway. |
| 129 # Create EFI System Partition to boot stock EFI BIOS (but not ChromeOS EFI | 129 # Create EFI System Partition to boot stock EFI BIOS (but not ChromeOS EFI |
| 130 # BIOS). ARM uses this space to determine which partition is bootable. | 130 # BIOS). ARM uses this space to determine which partition is bootable. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 # after the rootfs work is done. | 180 # after the rootfs work is done. |
| 181 sudo mkdir -p "${ESP_FS_DIR}"/syslinux | 181 sudo mkdir -p "${ESP_FS_DIR}"/syslinux |
| 182 sudo cp -r "${FLAGS_from}"/syslinux/. "${ESP_FS_DIR}"/syslinux | 182 sudo cp -r "${FLAGS_from}"/syslinux/. "${ESP_FS_DIR}"/syslinux |
| 183 | 183 |
| 184 # Stage both kernels with the only one we built. | 184 # Stage both kernels with the only one we built. |
| 185 sudo cp -f "${FLAGS_vmlinuz}" "${ESP_FS_DIR}"/syslinux/vmlinuz.A | 185 sudo cp -f "${FLAGS_vmlinuz}" "${ESP_FS_DIR}"/syslinux/vmlinuz.A |
| 186 sudo cp -f "${FLAGS_vmlinuz}" "${ESP_FS_DIR}"/syslinux/vmlinuz.B | 186 sudo cp -f "${FLAGS_vmlinuz}" "${ESP_FS_DIR}"/syslinux/vmlinuz.B |
| 187 | 187 |
| 188 # Extract kernel flags | 188 # Extract kernel flags |
| 189 kernel_cfg= | 189 kernel_cfg= |
| 190 old_root="sd%D%P" | 190 old_root="%U+1" |
| 191 if [[ -n "${FLAGS_kernel_cmdline}" ]]; then | 191 if [[ -n "${FLAGS_kernel_cmdline}" ]]; then |
| 192 info "Using supplied kernel_cmdline to update templates." | 192 info "Using supplied kernel_cmdline to update templates." |
| 193 kernel_cfg="${FLAGS_kernel_cmdline}" | 193 kernel_cfg="${FLAGS_kernel_cmdline}" |
| 194 elif [[ -n "${FLAGS_kernel_partition}" ]]; then | 194 elif [[ -n "${FLAGS_kernel_partition}" ]]; then |
| 195 info "Extracting the kernel command line from ${FLAGS_kernel_partition}" | 195 info "Extracting the kernel command line from ${FLAGS_kernel_partition}" |
| 196 kernel_cfg=$(dump_kernel_config "${FLAGS_kernel_partition}") | 196 kernel_cfg=$(dump_kernel_config "${FLAGS_kernel_partition}") |
| 197 fi | 197 fi |
| 198 update_x86_bootloaders "${old_root}" \ | 198 update_x86_bootloaders "${old_root}" \ |
| 199 "${kernel_cfg}" \ | 199 "${kernel_cfg}" \ |
| 200 "${ESP_FS_DIR}" \ | 200 "${ESP_FS_DIR}" \ |
| (...skipping 10 matching lines...) Expand all Loading... |
| 211 elif [[ "${FLAGS_arch}" = "arm" ]]; then | 211 elif [[ "${FLAGS_arch}" = "arm" ]]; then |
| 212 # Copy u-boot script to ESP partition | 212 # Copy u-boot script to ESP partition |
| 213 if [ -r "${FLAGS_from}/boot-A.scr.uimg" ]; then | 213 if [ -r "${FLAGS_from}/boot-A.scr.uimg" ]; then |
| 214 sudo mkdir -p "${ESP_FS_DIR}/u-boot" | 214 sudo mkdir -p "${ESP_FS_DIR}/u-boot" |
| 215 sudo cp "${FLAGS_from}/boot-A.scr.uimg" \ | 215 sudo cp "${FLAGS_from}/boot-A.scr.uimg" \ |
| 216 "${ESP_FS_DIR}/u-boot/boot.scr.uimg" | 216 "${ESP_FS_DIR}/u-boot/boot.scr.uimg" |
| 217 fi | 217 fi |
| 218 fi | 218 fi |
| 219 | 219 |
| 220 set +e | 220 set +e |
| OLD | NEW |