Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/bin/bash | 1 #!/bin/bash |
| 2 | 2 |
| 3 # Copyright (c) 2009-2010 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2009-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 # Script to update the kernel on a live running ChromiumOS instance. | 7 # Script to update the kernel on a live running ChromiumOS instance. |
| 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 18 matching lines...) Expand all Loading... | |
| 29 | 29 |
| 30 . "${SCRIPT_ROOT}/remote_access.sh" | 30 . "${SCRIPT_ROOT}/remote_access.sh" |
| 31 | 31 |
| 32 # Script must be run inside the chroot. | 32 # Script must be run inside the chroot. |
| 33 restart_in_chroot_if_needed "$@" | 33 restart_in_chroot_if_needed "$@" |
| 34 | 34 |
| 35 DEFINE_string board "" "Override board reported by target" | 35 DEFINE_string board "" "Override board reported by target" |
| 36 DEFINE_string device "" "Override boot device reported by target" | 36 DEFINE_string device "" "Override boot device reported by target" |
| 37 DEFINE_string partition "" "Override kernel partition reported by target" | 37 DEFINE_string partition "" "Override kernel partition reported by target" |
| 38 DEFINE_string arch "" "Override architecture reported by target" | 38 DEFINE_string arch "" "Override architecture reported by target" |
| 39 DEFINE_boolean modules false "Update modules on target" | 39 DEFINE_boolean reboot $FLAGS_TRUE "Reboot system after update" |
|
Mandeep Singh Baines
2011/04/20 22:54:36
Why would you not want to reboot?
Olof Johansson
2011/04/20 23:03:09
Mostly useful when testing the script, but seemed
| |
| 40 DEFINE_boolean firmware false "Update firmware on target" | |
| 41 | 40 |
| 42 # Parse command line. | 41 # Parse command line. |
| 43 FLAGS "$@" || exit 1 | 42 FLAGS "$@" || exit 1 |
| 44 eval set -- "${FLAGS_ARGV}" | 43 eval set -- "${FLAGS_ARGV}" |
| 45 | 44 |
| 46 # Only now can we die on error. shflags functions leak non-zero error codes, | 45 # Only now can we die on error. shflags functions leak non-zero error codes, |
| 47 # so will die prematurely if 'set -e' is specified before now. | 46 # so will die prematurely if 'set -e' is specified before now. |
| 48 set -e | 47 set -e |
| 49 | 48 |
| 50 function cleanup { | 49 function cleanup { |
| 51 cleanup_remote_access | 50 cleanup_remote_access |
| 52 rm -rf "${TMP}" | 51 rm -rf "${TMP}" |
| 53 } | 52 } |
| 54 | 53 |
| 55 function learn_device() { | 54 function learn_device() { |
| 56 [ -n "${FLAGS_device}" ] && return | 55 [ -n "${FLAGS_device}" ] && return |
| 57 remote_sh df /mnt/stateful_partition | 56 remote_sh df /mnt/stateful_partition |
| 58 FLAGS_device=$(echo "${REMOTE_OUT}" | awk '/dev/ {print $1}' | sed s/1\$//) | 57 FLAGS_device=$(echo "${REMOTE_OUT}" | awk '/dev/ {print $1}' | sed s/1\$//) |
| 59 info "Target reports root device is ${FLAGS_device}" | 58 info "Target reports root device is ${FLAGS_device}" |
| 60 } | 59 } |
| 61 | 60 |
| 62 # Ask the target what the kernel partition is | 61 # Ask the target what the kernel partition is |
| 63 function learn_partition() { | 62 function learn_partition_and_ro() { |
| 64 [ -n "${FLAGS_partition}" ] && return | 63 [ -n "${FLAGS_partition}" ] && return |
| 65 ! remote_sh rootdev | 64 ! remote_sh rootdev |
| 66 if [ "${REMOTE_OUT}" == "/dev/dm-0" ]; then | 65 if [ "${REMOTE_OUT}" == "/dev/dm-0" ]; then |
| 67 remote_sh ls /sys/block/dm-0/slaves | 66 remote_sh ls /sys/block/dm-0/slaves |
| 68 REMOTE_OUT="/dev/${REMOTE_OUT}" | 67 REMOTE_OUT="/dev/${REMOTE_OUT}" |
| 68 REMOTE_VERITY=${FLAGS_TRUE} | |
| 69 info "System is using verity: not updating firmware" | |
| 70 else | |
| 71 REMOTE_VERITY=${FLAGS_FALSE} | |
| 72 info "System is not using verity: updating firmware and modules" | |
| 69 fi | 73 fi |
| 70 if [ "${REMOTE_OUT}" == "${FLAGS_device}3" ]; then | 74 if [ "${REMOTE_OUT}" == "${FLAGS_device}3" ]; then |
| 71 FLAGS_partition="${FLAGS_device}2" | 75 FLAGS_partition="${FLAGS_device}2" |
| 72 else | 76 else |
| 73 FLAGS_partition="${FLAGS_device}4" | 77 FLAGS_partition="${FLAGS_device}4" |
| 74 fi | 78 fi |
| 75 if [ -z "${FLAGS_partition}" ]; then | 79 if [ -z "${FLAGS_partition}" ]; then |
| 76 error "Partition required" | 80 error "Partition required" |
| 77 exit 1 | 81 exit 1 |
| 78 fi | 82 fi |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 89 vbutil_kernel --pack new_kern.bin \ | 93 vbutil_kernel --pack new_kern.bin \ |
| 90 --keyblock /usr/share/vboot/devkeys/kernel.keyblock \ | 94 --keyblock /usr/share/vboot/devkeys/kernel.keyblock \ |
| 91 --signprivate /usr/share/vboot/devkeys/kernel_data_key.vbprivk \ | 95 --signprivate /usr/share/vboot/devkeys/kernel_data_key.vbprivk \ |
| 92 --version 1 \ | 96 --version 1 \ |
| 93 --config ../build/images/${FLAGS_board}/latest/config.txt \ | 97 --config ../build/images/${FLAGS_board}/latest/config.txt \ |
| 94 --bootloader /lib64/bootstub/bootstub.efi \ | 98 --bootloader /lib64/bootstub/bootstub.efi \ |
| 95 --vmlinuz /build/${FLAGS_board}/boot/vmlinuz | 99 --vmlinuz /build/${FLAGS_board}/boot/vmlinuz |
| 96 fi | 100 fi |
| 97 } | 101 } |
| 98 | 102 |
| 103 function copy_kernelimage() { | |
| 104 if [ "${FLAGS_arch}" == "arm" -a ${REMOTE_VERITY} -eq ${FLAGS_FALSE} ]; then | |
| 105 remote_cp_to /build/${FLAGS_board}/boot/vmlinux.uimg /boot | |
| 106 fi | |
| 107 | |
| 108 remote_cp_to new_kern.bin /tmp | |
| 109 | |
| 110 remote_sh dd if=/tmp/new_kern.bin of="${FLAGS_partition}" | |
| 111 } | |
| 112 | |
| 99 function main() { | 113 function main() { |
| 100 trap cleanup EXIT | 114 trap cleanup EXIT |
| 101 | 115 |
| 102 TMP=$(mktemp -d /tmp/image_to_live.XXXX) | 116 TMP=$(mktemp -d /tmp/image_to_live.XXXX) |
| 103 | 117 |
| 104 remote_access_init | 118 remote_access_init |
| 105 | 119 |
| 106 learn_arch | 120 learn_arch |
| 107 | 121 |
| 108 learn_board | 122 learn_board |
| 109 | 123 |
| 110 learn_device | 124 learn_device |
| 111 | 125 |
| 112 learn_partition | 126 learn_partition_and_ro |
| 113 | 127 |
| 114 remote_sh uname -r -v | 128 remote_sh uname -r -v |
| 115 | 129 |
| 116 old_kernel="${REMOTE_OUT}" | 130 old_kernel="${REMOTE_OUT}" |
| 117 | 131 |
| 118 make_kernelimage | 132 make_kernelimage |
| 119 | 133 |
| 120 remote_cp_to new_kern.bin /tmp | 134 if [[ ${REMOTE_VERITY} -eq ${FLAGS_FALSE} ]]; then |
| 135 tar -C /build/"${FLAGS_board}"/lib/modules -cjf /tmp/new_modules.tar . | |
| 136 tar -C /build/"${FLAGS_board}"/lib/firmware -cjf /tmp/new_firmware.tar . | |
| 121 | 137 |
| 122 remote_sh dd if=/tmp/new_kern.bin of="${FLAGS_partition}" | 138 remote_sh mount -o remount,rw / |
| 123 | |
| 124 if [[ ${FLAGS_modules} -eq ${FLAGS_TRUE} ]]; then | |
| 125 echo "copying modules" | 139 echo "copying modules" |
| 126 tar -C /build/"${FLAGS_board}"/lib/modules -cjf /tmp/new_modules.tar . | |
| 127 | |
| 128 remote_cp_to /tmp/new_modules.tar /tmp/ | 140 remote_cp_to /tmp/new_modules.tar /tmp/ |
| 129 | 141 |
| 130 remote_sh mount -o remount,rw / | |
| 131 remote_sh tar -C /lib/modules -xjf /tmp/new_modules.tar | 142 remote_sh tar -C /lib/modules -xjf /tmp/new_modules.tar |
| 132 fi | |
| 133 | 143 |
| 134 if [[ ${FLAGS_firmware} -eq ${FLAGS_TRUE} ]]; then | |
| 135 echo "copying firmware" | 144 echo "copying firmware" |
| 136 tar -C /build/"${FLAGS_board}"/lib/firmware -cjf /tmp/new_firmware.tar . | |
| 137 | |
| 138 remote_cp_to /tmp/new_firmware.tar /tmp/ | 145 remote_cp_to /tmp/new_firmware.tar /tmp/ |
| 139 | 146 |
| 140 remote_sh mount -o remount,rw / | |
| 141 remote_sh tar -C /lib/firmware -xjf /tmp/new_firmware.tar | 147 remote_sh tar -C /lib/firmware -xjf /tmp/new_firmware.tar |
| 142 fi | 148 fi |
| 143 | 149 |
| 144 remote_reboot | 150 echo "copying kernel" |
| 145 | 151 |
| 146 remote_sh uname -r -v | 152 copy_kernelimage |
| 147 info "old kernel: ${old_kernel}" | 153 |
| 148 info "new kernel: ${REMOTE_OUT}" | 154 if [ "${FLAGS_reboot}" -eq ${FLAGS_TRUE} ]; then |
| 155 echo "rebooting" | |
| 156 | |
| 157 remote_reboot | |
| 158 | |
| 159 remote_sh uname -r -v | |
| 160 info "old kernel: ${old_kernel}" | |
| 161 info "new kernel: ${REMOTE_OUT}" | |
| 162 else | |
| 163 info "Not rebooting (per request)" | |
| 164 fi | |
| 149 } | 165 } |
| 150 | 166 |
| 151 main "$@" | 167 main "$@" |
| OLD | NEW |