blob: 4166709aea65be6fabd654f08f1bdbfeca25635e [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"
17
18function cleanup {
19 cleanup_remote_access
20 rm -rf "${TMP}"
21}
22
23# Ask the target what the kernel partition is
24function learn_partition() {
25 [ -n "${FLAGS_partition}" ] && return
26 remote_sh cat /proc/cmdline
27 if echo "${REMOTE_OUT}" | grep -q "/dev/sda3"; then
28 FLAGS_partition="/dev/sda2"
29 else
30 FLAGS_partition="/dev/sda4"
31 fi
32 if [ -z "${FLAGS_partition}" ]; then
33 error "Partition required"
34 exit 1
35 fi
36 info "Target reports kernel partition is ${FLAGS_partition}"
37}
38
39function main() {
40 assert_outside_chroot
41
42 cd $(dirname "$0")
43
44 FLAGS "$@" || exit 1
45 eval set -- "${FLAGS_ARGV}"
46
47 set -e
48
49 trap cleanup EXIT
50
51 TMP=$(mktemp -d /tmp/image_to_live.XXXX)
52
53 remote_access_init
54
55 learn_board
56
57 remote_sh uname -r -v
58
59 old_kernel="${REMOTE_OUT}"
60
61 cmd="vbutil_kernel --pack new_kern.bin \
62 --keyblock /usr/share/vboot/devkeys/kernel.keyblock \
63 --signprivate /usr/share/vboot/devkeys/kernel_data_key.vbprivk \
64 --version 1 \
65 --config ../build/images/${FLAGS_board}/latest/config.txt \
66 --bootloader /lib64/bootstub/bootstub.efi \
67 --vmlinuz /build/${FLAGS_board}/boot/vmlinuz"
68
Doug Andersonebe1baa2010-12-15 13:56:09 -080069 ./enter_chroot.sh -- ${cmd}
Mandeep Singh Bainesa63cd2d2010-12-02 11:58:26 -080070
71 learn_partition
72
73 remote_cp_to new_kern.bin /tmp
74
75 remote_sh dd if=/tmp/new_kern.bin of="${FLAGS_partition}"
76
77 remote_reboot
78
79 remote_sh uname -r -v
80
81 info "old kernel: ${old_kernel}"
82
83 info "new kernel: ${REMOTE_OUT}"
84}
85
86main $@