blob: d1b735daea471962299589722f609598307d39e7 [file] [log] [blame]
Mandeep Singh Bainesa63cd2d2010-12-02 11:58:26 -08001#!/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 Baines2f3b5fc2011-01-14 14:20:12 -080015# Script must be run inside the chroot.
16restart_in_chroot_if_needed $*
17
Mandeep Singh Bainesa63cd2d2010-12-02 11:58:26 -080018DEFINE_string board "" "Override board reported by target"
19DEFINE_string partition "" "Override kernel partition reported by target"
Olof Johansson5a46bfb2010-12-22 12:14:21 -080020DEFINE_boolean modules false "Update modules on target"
21DEFINE_boolean firmware false "Update firmware on target"
Mandeep Singh Bainesa63cd2d2010-12-02 11:58:26 -080022
Mandeep Singh Baines2f3b5fc2011-01-14 14:20:12 -080023# Parse command line.
24FLAGS "$@" || exit 1
25eval 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.
29set -e
30
Mandeep Singh Bainesa63cd2d2010-12-02 11:58:26 -080031function cleanup {
32 cleanup_remote_access
33 rm -rf "${TMP}"
34}
35
36# Ask the target what the kernel partition is
37function 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
52function main() {
Mandeep Singh Bainesa63cd2d2010-12-02 11:58:26 -080053 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 Baines2f3b5fc2011-01-14 14:20:12 -080065 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 Bainesa63cd2d2010-12-02 11:58:26 -080072
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 Johansson5a46bfb2010-12-22 12:14:21 -080079 if [[ ${FLAGS_modules} -eq ${FLAGS_TRUE} ]]; then
80 echo "copying modules"
Mandeep Singh Baines2f3b5fc2011-01-14 14:20:12 -080081 tar -C /build/"${FLAGS_board}"/lib/modules -cjf new_modules.tar .
Olof Johansson5a46bfb2010-12-22 12:14:21 -080082
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 Baines2f3b5fc2011-01-14 14:20:12 -080091 tar -C /build/"${FLAGS_board}"/lib/firmware -cjf new_firmware.tar .
Olof Johansson5a46bfb2010-12-22 12:14:21 -080092
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 Bainesa63cd2d2010-12-02 11:58:26 -080099 remote_reboot
100
101 remote_sh uname -r -v
Mandeep Singh Bainesa63cd2d2010-12-02 11:58:26 -0800102 info "old kernel: ${old_kernel}"
Mandeep Singh Bainesa63cd2d2010-12-02 11:58:26 -0800103 info "new kernel: ${REMOTE_OUT}"
104}
105
106main $@