blob: b5e26d3198c1ea6aa20a9a5a8eb50dadc985f9da [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
15DEFINE_string board "" "Override board reported by target"
16DEFINE_string partition "" "Override kernel partition reported by target"
Olof Johansson5a46bfb2010-12-22 12:14:21 -080017DEFINE_boolean modules false "Update modules on target"
18DEFINE_boolean firmware false "Update firmware on target"
Mandeep Singh Bainesa63cd2d2010-12-02 11:58:26 -080019
20function cleanup {
21 cleanup_remote_access
22 rm -rf "${TMP}"
23}
24
25# Ask the target what the kernel partition is
26function learn_partition() {
27 [ -n "${FLAGS_partition}" ] && return
28 remote_sh cat /proc/cmdline
29 if echo "${REMOTE_OUT}" | grep -q "/dev/sda3"; then
30 FLAGS_partition="/dev/sda2"
31 else
32 FLAGS_partition="/dev/sda4"
33 fi
34 if [ -z "${FLAGS_partition}" ]; then
35 error "Partition required"
36 exit 1
37 fi
38 info "Target reports kernel partition is ${FLAGS_partition}"
39}
40
41function main() {
42 assert_outside_chroot
43
44 cd $(dirname "$0")
45
46 FLAGS "$@" || exit 1
47 eval set -- "${FLAGS_ARGV}"
48
49 set -e
50
51 trap cleanup EXIT
52
53 TMP=$(mktemp -d /tmp/image_to_live.XXXX)
54
55 remote_access_init
56
57 learn_board
58
59 remote_sh uname -r -v
60
61 old_kernel="${REMOTE_OUT}"
62
63 cmd="vbutil_kernel --pack new_kern.bin \
64 --keyblock /usr/share/vboot/devkeys/kernel.keyblock \
65 --signprivate /usr/share/vboot/devkeys/kernel_data_key.vbprivk \
66 --version 1 \
67 --config ../build/images/${FLAGS_board}/latest/config.txt \
68 --bootloader /lib64/bootstub/bootstub.efi \
69 --vmlinuz /build/${FLAGS_board}/boot/vmlinuz"
70
Doug Andersonebe1baa2010-12-15 13:56:09 -080071 ./enter_chroot.sh -- ${cmd}
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"
81 cmd="tar -C /build/${FLAGS_board}/lib/modules -cjf new_modules.tar ."
82 ./enter_chroot.sh -- ${cmd}
83
84 remote_cp_to new_modules.tar /tmp/
85
86 remote_sh mount -o remount,rw /
87 remote_sh tar -C /lib/modules -xjf /tmp/new_modules.tar
88 fi
89
90 if [[ ${FLAGS_firmware} -eq ${FLAGS_TRUE} ]]; then
91 echo "copying firmware"
92 cmd="tar -C /build/${FLAGS_board}/lib/firmware -cjf new_firmware.tar ."
93 ./enter_chroot.sh -- ${cmd}
94
95 remote_cp_to new_firmware.tar /tmp/
96
97 remote_sh mount -o remount,rw /
98 remote_sh tar -C /lib/firmware -xjf /tmp/new_firmware.tar
99 fi
100
Mandeep Singh Bainesa63cd2d2010-12-02 11:58:26 -0800101 remote_reboot
102
103 remote_sh uname -r -v
104
105 info "old kernel: ${old_kernel}"
106
107 info "new kernel: ${REMOTE_OUT}"
108}
109
110main $@