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" |
| 19 | DEFINE_string partition "" "Override kernel partition reported by target" |
Olof Johansson | 5a46bfb | 2010-12-22 12:14:21 -0800 | [diff] [blame] | 20 | DEFINE_boolean modules false "Update modules on target" |
| 21 | DEFINE_boolean firmware false "Update firmware on target" |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 22 | |
Mandeep Singh Baines | 2f3b5fc | 2011-01-14 14:20:12 -0800 | [diff] [blame^] | 23 | # Parse command line. |
| 24 | FLAGS "$@" || exit 1 |
| 25 | eval set -- "${FLAGS_ARGV}" |
| 26 | |
| 27 | # Only now can we die on error. shflags functions leak non-zero error codes, |
| 28 | # so will die prematurely if 'set -e' is specified before now. |
| 29 | set -e |
| 30 | |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 31 | function cleanup { |
| 32 | cleanup_remote_access |
| 33 | rm -rf "${TMP}" |
| 34 | } |
| 35 | |
| 36 | # Ask the target what the kernel partition is |
| 37 | function learn_partition() { |
| 38 | [ -n "${FLAGS_partition}" ] && return |
| 39 | remote_sh cat /proc/cmdline |
| 40 | if echo "${REMOTE_OUT}" | grep -q "/dev/sda3"; then |
| 41 | FLAGS_partition="/dev/sda2" |
| 42 | else |
| 43 | FLAGS_partition="/dev/sda4" |
| 44 | fi |
| 45 | if [ -z "${FLAGS_partition}" ]; then |
| 46 | error "Partition required" |
| 47 | exit 1 |
| 48 | fi |
| 49 | info "Target reports kernel partition is ${FLAGS_partition}" |
| 50 | } |
| 51 | |
| 52 | function main() { |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 53 | trap cleanup EXIT |
| 54 | |
| 55 | TMP=$(mktemp -d /tmp/image_to_live.XXXX) |
| 56 | |
| 57 | remote_access_init |
| 58 | |
| 59 | learn_board |
| 60 | |
| 61 | remote_sh uname -r -v |
| 62 | |
| 63 | old_kernel="${REMOTE_OUT}" |
| 64 | |
Mandeep Singh Baines | 2f3b5fc | 2011-01-14 14:20:12 -0800 | [diff] [blame^] | 65 | vbutil_kernel --pack new_kern.bin \ |
| 66 | --keyblock /usr/share/vboot/devkeys/kernel.keyblock \ |
| 67 | --signprivate /usr/share/vboot/devkeys/kernel_data_key.vbprivk \ |
| 68 | --version 1 \ |
| 69 | --config ../build/images/"${FLAGS_board}"/latest/config.txt \ |
| 70 | --bootloader /lib64/bootstub/bootstub.efi \ |
| 71 | --vmlinuz /build/"${FLAGS_board}"/boot/vmlinuz |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 72 | |
| 73 | learn_partition |
| 74 | |
| 75 | remote_cp_to new_kern.bin /tmp |
| 76 | |
| 77 | remote_sh dd if=/tmp/new_kern.bin of="${FLAGS_partition}" |
| 78 | |
Olof Johansson | 5a46bfb | 2010-12-22 12:14:21 -0800 | [diff] [blame] | 79 | if [[ ${FLAGS_modules} -eq ${FLAGS_TRUE} ]]; then |
| 80 | echo "copying modules" |
Mandeep Singh Baines | 2f3b5fc | 2011-01-14 14:20:12 -0800 | [diff] [blame^] | 81 | tar -C /build/"${FLAGS_board}"/lib/modules -cjf new_modules.tar . |
Olof Johansson | 5a46bfb | 2010-12-22 12:14:21 -0800 | [diff] [blame] | 82 | |
| 83 | remote_cp_to new_modules.tar /tmp/ |
| 84 | |
| 85 | remote_sh mount -o remount,rw / |
| 86 | remote_sh tar -C /lib/modules -xjf /tmp/new_modules.tar |
| 87 | fi |
| 88 | |
| 89 | if [[ ${FLAGS_firmware} -eq ${FLAGS_TRUE} ]]; then |
| 90 | echo "copying firmware" |
Mandeep Singh Baines | 2f3b5fc | 2011-01-14 14:20:12 -0800 | [diff] [blame^] | 91 | tar -C /build/"${FLAGS_board}"/lib/firmware -cjf new_firmware.tar . |
Olof Johansson | 5a46bfb | 2010-12-22 12:14:21 -0800 | [diff] [blame] | 92 | |
| 93 | remote_cp_to new_firmware.tar /tmp/ |
| 94 | |
| 95 | remote_sh mount -o remount,rw / |
| 96 | remote_sh tar -C /lib/firmware -xjf /tmp/new_firmware.tar |
| 97 | fi |
| 98 | |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 99 | remote_reboot |
| 100 | |
| 101 | remote_sh uname -r -v |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 102 | info "old kernel: ${old_kernel}" |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 103 | info "new kernel: ${REMOTE_OUT}" |
| 104 | } |
| 105 | |
| 106 | main $@ |