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 | |
| 9 | # Load common constants. This should be the first executable line. |
| 10 | # The path to common.sh should be relative to your script's location. |
| 11 | |
| 12 | . "$(dirname $0)/common.sh" |
| 13 | . "$(dirname $0)/remote_access.sh" |
| 14 | |
Mandeep Singh Baines | 2f3b5fc | 2011-01-14 14:20:12 -0800 | [diff] [blame] | 15 | # Script must be run inside the chroot. |
| 16 | restart_in_chroot_if_needed $* |
| 17 | |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 18 | DEFINE_string board "" "Override board reported by target" |
Olof Johansson | f53fa0d | 2011-01-26 13:06:46 -0800 | [diff] [blame^] | 19 | DEFINE_string device "" "Override boot device reported by target" |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 20 | DEFINE_string partition "" "Override kernel partition reported by target" |
Olof Johansson | f53fa0d | 2011-01-26 13:06:46 -0800 | [diff] [blame^] | 21 | DEFINE_string arch "" "Override architecture reported by target" |
Olof Johansson | 5a46bfb | 2010-12-22 12:14:21 -0800 | [diff] [blame] | 22 | DEFINE_boolean modules false "Update modules on target" |
| 23 | DEFINE_boolean firmware false "Update firmware on target" |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 24 | |
Mandeep Singh Baines | 2f3b5fc | 2011-01-14 14:20:12 -0800 | [diff] [blame] | 25 | # Parse command line. |
| 26 | FLAGS "$@" || exit 1 |
| 27 | eval set -- "${FLAGS_ARGV}" |
| 28 | |
| 29 | # Only now can we die on error. shflags functions leak non-zero error codes, |
| 30 | # so will die prematurely if 'set -e' is specified before now. |
| 31 | set -e |
| 32 | |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 33 | function cleanup { |
| 34 | cleanup_remote_access |
| 35 | rm -rf "${TMP}" |
| 36 | } |
| 37 | |
Olof Johansson | f53fa0d | 2011-01-26 13:06:46 -0800 | [diff] [blame^] | 38 | function learn_device() { |
| 39 | [ -n "${FLAGS_device}" ] && return |
| 40 | remote_sh df /mnt/stateful_partition |
| 41 | FLAGS_device=$(echo "${REMOTE_OUT}" | awk '/dev/ {print $1}' | sed s/1\$//) |
| 42 | info "Target reports root device is ${FLAGS_device}" |
| 43 | } |
| 44 | |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 45 | # Ask the target what the kernel partition is |
| 46 | function learn_partition() { |
| 47 | [ -n "${FLAGS_partition}" ] && return |
| 48 | remote_sh cat /proc/cmdline |
Olof Johansson | f53fa0d | 2011-01-26 13:06:46 -0800 | [diff] [blame^] | 49 | if echo "${REMOTE_OUT}" | egrep -q "${FLAGS_device}3"; then |
| 50 | FLAGS_partition="${FLAGS_device}2" |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 51 | else |
Olof Johansson | f53fa0d | 2011-01-26 13:06:46 -0800 | [diff] [blame^] | 52 | FLAGS_partition="${FLAGS_device}4" |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 53 | fi |
| 54 | if [ -z "${FLAGS_partition}" ]; then |
| 55 | error "Partition required" |
| 56 | exit 1 |
| 57 | fi |
| 58 | info "Target reports kernel partition is ${FLAGS_partition}" |
| 59 | } |
| 60 | |
Olof Johansson | f53fa0d | 2011-01-26 13:06:46 -0800 | [diff] [blame^] | 61 | function make_kernelimage() { |
| 62 | |
| 63 | if [[ "${FLAGS_arch}" == "arm" ]]; then |
| 64 | ./build_kernel_image.sh --arch=arm \ |
| 65 | --root='/dev/${devname}${rootpart}' \ |
| 66 | --vmlinuz=/build/${FLAGS_board}/boot/vmlinux.uimg --to new_kern.bin |
| 67 | else |
| 68 | vbutil_kernel --pack new_kern.bin \ |
| 69 | --keyblock /usr/share/vboot/devkeys/kernel.keyblock \ |
| 70 | --signprivate /usr/share/vboot/devkeys/kernel_data_key.vbprivk \ |
| 71 | --version 1 \ |
| 72 | --config ../build/images/${FLAGS_board}/latest/config.txt \ |
| 73 | --bootloader /lib64/bootstub/bootstub.efi \ |
| 74 | --vmlinuz /build/${FLAGS_board}/boot/vmlinuz |
| 75 | fi |
| 76 | } |
| 77 | |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 78 | function main() { |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 79 | trap cleanup EXIT |
| 80 | |
| 81 | TMP=$(mktemp -d /tmp/image_to_live.XXXX) |
| 82 | |
| 83 | remote_access_init |
| 84 | |
Olof Johansson | f53fa0d | 2011-01-26 13:06:46 -0800 | [diff] [blame^] | 85 | learn_arch |
| 86 | |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 87 | learn_board |
| 88 | |
Olof Johansson | f53fa0d | 2011-01-26 13:06:46 -0800 | [diff] [blame^] | 89 | learn_device |
| 90 | |
| 91 | learn_partition |
| 92 | |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 93 | remote_sh uname -r -v |
| 94 | |
| 95 | old_kernel="${REMOTE_OUT}" |
| 96 | |
Olof Johansson | f53fa0d | 2011-01-26 13:06:46 -0800 | [diff] [blame^] | 97 | make_kernelimage |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 98 | |
| 99 | remote_cp_to new_kern.bin /tmp |
| 100 | |
| 101 | remote_sh dd if=/tmp/new_kern.bin of="${FLAGS_partition}" |
| 102 | |
Olof Johansson | 5a46bfb | 2010-12-22 12:14:21 -0800 | [diff] [blame] | 103 | if [[ ${FLAGS_modules} -eq ${FLAGS_TRUE} ]]; then |
| 104 | echo "copying modules" |
Olof Johansson | f53fa0d | 2011-01-26 13:06:46 -0800 | [diff] [blame^] | 105 | tar -C /build/"${FLAGS_board}"/lib/modules -cjf /tmp/new_modules.tar . |
Olof Johansson | 5a46bfb | 2010-12-22 12:14:21 -0800 | [diff] [blame] | 106 | |
Olof Johansson | f53fa0d | 2011-01-26 13:06:46 -0800 | [diff] [blame^] | 107 | remote_cp_to /tmp/new_modules.tar /tmp/ |
Olof Johansson | 5a46bfb | 2010-12-22 12:14:21 -0800 | [diff] [blame] | 108 | |
| 109 | remote_sh mount -o remount,rw / |
| 110 | remote_sh tar -C /lib/modules -xjf /tmp/new_modules.tar |
| 111 | fi |
| 112 | |
| 113 | if [[ ${FLAGS_firmware} -eq ${FLAGS_TRUE} ]]; then |
| 114 | echo "copying firmware" |
Olof Johansson | f53fa0d | 2011-01-26 13:06:46 -0800 | [diff] [blame^] | 115 | tar -C /build/"${FLAGS_board}"/lib/firmware -cjf /tmp/new_firmware.tar . |
Olof Johansson | 5a46bfb | 2010-12-22 12:14:21 -0800 | [diff] [blame] | 116 | |
Olof Johansson | f53fa0d | 2011-01-26 13:06:46 -0800 | [diff] [blame^] | 117 | remote_cp_to /tmp/new_firmware.tar /tmp/ |
Olof Johansson | 5a46bfb | 2010-12-22 12:14:21 -0800 | [diff] [blame] | 118 | |
| 119 | remote_sh mount -o remount,rw / |
| 120 | remote_sh tar -C /lib/firmware -xjf /tmp/new_firmware.tar |
| 121 | fi |
| 122 | |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 123 | remote_reboot |
| 124 | |
| 125 | remote_sh uname -r -v |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 126 | info "old kernel: ${old_kernel}" |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 127 | info "new kernel: ${REMOTE_OUT}" |
| 128 | } |
| 129 | |
Olof Johansson | f53fa0d | 2011-01-26 13:06:46 -0800 | [diff] [blame^] | 130 | main "$@" |