Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 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 |
| 5 | # found in the LICENSE file. |
| 6 | |
| 7 | # Script to update the kernel on a live running ChromiumOS instance. |
| 8 | |
Greg Spencer | 798d75f | 2011-02-01 22:04:49 -0800 | [diff] [blame] | 9 | # --- BEGIN COMMON.SH BOILERPLATE --- |
| 10 | # Load common CrOS utilities. Inside the chroot this file is installed in |
| 11 | # /usr/lib/crosutils. Outside the chroot we find it relative to the script's |
| 12 | # location. |
| 13 | find_common_sh() { |
| 14 | local common_paths=(/usr/lib/crosutils $(dirname "$(readlink -f "$0")")) |
| 15 | local path |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 16 | |
Greg Spencer | 798d75f | 2011-02-01 22:04:49 -0800 | [diff] [blame] | 17 | SCRIPT_ROOT= |
| 18 | for path in "${common_paths[@]}"; do |
| 19 | if [ -r "${path}/common.sh" ]; then |
| 20 | SCRIPT_ROOT=${path} |
| 21 | break |
| 22 | fi |
| 23 | done |
| 24 | } |
| 25 | |
| 26 | find_common_sh |
| 27 | . "${SCRIPT_ROOT}/common.sh" || (echo "Unable to load common.sh" && exit 1) |
| 28 | # --- END COMMON.SH BOILERPLATE --- |
| 29 | |
| 30 | . "${SCRIPT_ROOT}/remote_access.sh" |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 31 | |
Mandeep Singh Baines | 2f3b5fc | 2011-01-14 14:20:12 -0800 | [diff] [blame] | 32 | # Script must be run inside the chroot. |
Greg Spencer | 798d75f | 2011-02-01 22:04:49 -0800 | [diff] [blame] | 33 | restart_in_chroot_if_needed "$@" |
Mandeep Singh Baines | 2f3b5fc | 2011-01-14 14:20:12 -0800 | [diff] [blame] | 34 | |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 35 | DEFINE_string board "" "Override board reported by target" |
Olof Johansson | f53fa0d | 2011-01-26 13:06:46 -0800 | [diff] [blame] | 36 | DEFINE_string device "" "Override boot device reported by target" |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 37 | DEFINE_string partition "" "Override kernel partition reported by target" |
Olof Johansson | f53fa0d | 2011-01-26 13:06:46 -0800 | [diff] [blame] | 38 | DEFINE_string arch "" "Override architecture reported by target" |
Olof Johansson | 5a46bfb | 2010-12-22 12:14:21 -0800 | [diff] [blame] | 39 | DEFINE_boolean modules false "Update modules on target" |
| 40 | DEFINE_boolean firmware false "Update firmware on target" |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 41 | |
Mandeep Singh Baines | 2f3b5fc | 2011-01-14 14:20:12 -0800 | [diff] [blame] | 42 | # Parse command line. |
| 43 | FLAGS "$@" || exit 1 |
| 44 | eval set -- "${FLAGS_ARGV}" |
| 45 | |
| 46 | # 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. |
| 48 | set -e |
| 49 | |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 50 | function cleanup { |
| 51 | cleanup_remote_access |
| 52 | rm -rf "${TMP}" |
| 53 | } |
| 54 | |
Olof Johansson | f53fa0d | 2011-01-26 13:06:46 -0800 | [diff] [blame] | 55 | function learn_device() { |
| 56 | [ -n "${FLAGS_device}" ] && return |
| 57 | remote_sh df /mnt/stateful_partition |
| 58 | FLAGS_device=$(echo "${REMOTE_OUT}" | awk '/dev/ {print $1}' | sed s/1\$//) |
| 59 | info "Target reports root device is ${FLAGS_device}" |
| 60 | } |
| 61 | |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 62 | # Ask the target what the kernel partition is |
| 63 | function learn_partition() { |
| 64 | [ -n "${FLAGS_partition}" ] && return |
Mandeep Singh Baines | e39579a | 2011-03-04 15:58:57 -0800 | [diff] [blame^] | 65 | ! remote_sh rootdev |
| 66 | if [ "${REMOTE_OUT}" == "/dev/dm-0" ]; then |
| 67 | remote_sh ls /sys/block/dm-0/slaves |
| 68 | REMOTE_OUT="/dev/${REMOTE_OUT}" |
| 69 | fi |
| 70 | if [ "${REMOTE_OUT}" == "${FLAGS_device}3" ]; then |
Olof Johansson | f53fa0d | 2011-01-26 13:06:46 -0800 | [diff] [blame] | 71 | FLAGS_partition="${FLAGS_device}2" |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 72 | else |
Olof Johansson | f53fa0d | 2011-01-26 13:06:46 -0800 | [diff] [blame] | 73 | FLAGS_partition="${FLAGS_device}4" |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 74 | fi |
| 75 | if [ -z "${FLAGS_partition}" ]; then |
| 76 | error "Partition required" |
| 77 | exit 1 |
| 78 | fi |
| 79 | info "Target reports kernel partition is ${FLAGS_partition}" |
| 80 | } |
| 81 | |
Olof Johansson | f53fa0d | 2011-01-26 13:06:46 -0800 | [diff] [blame] | 82 | function make_kernelimage() { |
| 83 | |
| 84 | if [[ "${FLAGS_arch}" == "arm" ]]; then |
| 85 | ./build_kernel_image.sh --arch=arm \ |
| 86 | --root='/dev/${devname}${rootpart}' \ |
| 87 | --vmlinuz=/build/${FLAGS_board}/boot/vmlinux.uimg --to new_kern.bin |
| 88 | else |
| 89 | vbutil_kernel --pack new_kern.bin \ |
| 90 | --keyblock /usr/share/vboot/devkeys/kernel.keyblock \ |
| 91 | --signprivate /usr/share/vboot/devkeys/kernel_data_key.vbprivk \ |
| 92 | --version 1 \ |
| 93 | --config ../build/images/${FLAGS_board}/latest/config.txt \ |
| 94 | --bootloader /lib64/bootstub/bootstub.efi \ |
| 95 | --vmlinuz /build/${FLAGS_board}/boot/vmlinuz |
| 96 | fi |
| 97 | } |
| 98 | |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 99 | function main() { |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 100 | trap cleanup EXIT |
| 101 | |
| 102 | TMP=$(mktemp -d /tmp/image_to_live.XXXX) |
| 103 | |
| 104 | remote_access_init |
| 105 | |
Olof Johansson | f53fa0d | 2011-01-26 13:06:46 -0800 | [diff] [blame] | 106 | learn_arch |
| 107 | |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 108 | learn_board |
| 109 | |
Olof Johansson | f53fa0d | 2011-01-26 13:06:46 -0800 | [diff] [blame] | 110 | learn_device |
| 111 | |
| 112 | learn_partition |
| 113 | |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 114 | remote_sh uname -r -v |
| 115 | |
| 116 | old_kernel="${REMOTE_OUT}" |
| 117 | |
Olof Johansson | f53fa0d | 2011-01-26 13:06:46 -0800 | [diff] [blame] | 118 | make_kernelimage |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 119 | |
| 120 | remote_cp_to new_kern.bin /tmp |
| 121 | |
| 122 | remote_sh dd if=/tmp/new_kern.bin of="${FLAGS_partition}" |
| 123 | |
Olof Johansson | 5a46bfb | 2010-12-22 12:14:21 -0800 | [diff] [blame] | 124 | if [[ ${FLAGS_modules} -eq ${FLAGS_TRUE} ]]; then |
| 125 | echo "copying modules" |
Olof Johansson | f53fa0d | 2011-01-26 13:06:46 -0800 | [diff] [blame] | 126 | tar -C /build/"${FLAGS_board}"/lib/modules -cjf /tmp/new_modules.tar . |
Olof Johansson | 5a46bfb | 2010-12-22 12:14:21 -0800 | [diff] [blame] | 127 | |
Olof Johansson | f53fa0d | 2011-01-26 13:06:46 -0800 | [diff] [blame] | 128 | remote_cp_to /tmp/new_modules.tar /tmp/ |
Olof Johansson | 5a46bfb | 2010-12-22 12:14:21 -0800 | [diff] [blame] | 129 | |
| 130 | remote_sh mount -o remount,rw / |
| 131 | remote_sh tar -C /lib/modules -xjf /tmp/new_modules.tar |
| 132 | fi |
| 133 | |
| 134 | if [[ ${FLAGS_firmware} -eq ${FLAGS_TRUE} ]]; then |
| 135 | echo "copying firmware" |
Olof Johansson | f53fa0d | 2011-01-26 13:06:46 -0800 | [diff] [blame] | 136 | tar -C /build/"${FLAGS_board}"/lib/firmware -cjf /tmp/new_firmware.tar . |
Olof Johansson | 5a46bfb | 2010-12-22 12:14:21 -0800 | [diff] [blame] | 137 | |
Olof Johansson | f53fa0d | 2011-01-26 13:06:46 -0800 | [diff] [blame] | 138 | remote_cp_to /tmp/new_firmware.tar /tmp/ |
Olof Johansson | 5a46bfb | 2010-12-22 12:14:21 -0800 | [diff] [blame] | 139 | |
| 140 | remote_sh mount -o remount,rw / |
| 141 | remote_sh tar -C /lib/firmware -xjf /tmp/new_firmware.tar |
| 142 | fi |
| 143 | |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 144 | remote_reboot |
| 145 | |
| 146 | remote_sh uname -r -v |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 147 | info "old kernel: ${old_kernel}" |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 148 | info "new kernel: ${REMOTE_OUT}" |
| 149 | } |
| 150 | |
Olof Johansson | f53fa0d | 2011-01-26 13:06:46 -0800 | [diff] [blame] | 151 | main "$@" |