Create a new command update_kernel.sh

This command can be used to update the kernel of a ChromiumOS target.

Much thanks to snanda for the inspiration and instructions.

BUG=9864
TEST=Verified that it works.

Change-Id: I66f7d940e0dc59b0e1a50409a7155fe0ba7157fe

Review URL: http://codereview.chromium.org/5550001
This commit is contained in:
Mandeep Singh Baines 2010-12-02 11:58:26 -08:00
parent c15b609efa
commit a63cd2d648
3 changed files with 111 additions and 25 deletions

View File

@ -291,31 +291,6 @@ function run_auto_update {
fi
}
function remote_reboot {
info "Rebooting."
remote_sh "touch /tmp/awaiting_reboot; reboot"
local output_file
output_file="${TMP}/output"
while true; do
REMOTE_OUT=""
# This may fail while the machine is down so generate output and a
# boolean result to distinguish between down/timeout and real failure
! remote_sh_allow_changed_host_key \
"echo 0; [ -e /tmp/awaiting_reboot ] && echo '1'; true"
echo "${REMOTE_OUT}" > "${output_file}"
if grep -q "0" "${output_file}"; then
if grep -q "1" "${output_file}"; then
info "Not yet rebooted"
else
info "Rebooted and responding"
break
fi
fi
sleep .5
done
}
function verify_image {
info "Verifying image."
"${SCRIPTS_DIR}/mount_gpt_image.sh" --from "$(dirname ${IMAGE_PATH})" \

View File

@ -68,6 +68,31 @@ function learn_board() {
info "Target reports board is ${FLAGS_board}"
}
function remote_reboot {
info "Rebooting."
remote_sh "touch /tmp/awaiting_reboot; reboot"
local output_file
output_file="${TMP}/output"
while true; do
REMOTE_OUT=""
# This may fail while the machine is down so generate output and a
# boolean result to distinguish between down/timeout and real failure
! remote_sh_allow_changed_host_key \
"echo 0; [ -e /tmp/awaiting_reboot ] && echo '1'; true"
echo "${REMOTE_OUT}" > "${output_file}"
if grep -q "0" "${output_file}"; then
if grep -q "1" "${output_file}"; then
info "Not yet rebooted"
else
info "Rebooted and responding"
break
fi
fi
sleep .5
done
}
function cleanup_remote_access() {
# Call this function from the exit trap of the main script.
# Iff we started ssh-agent, be nice and clean it up.

86
update_kernel.sh Executable file
View File

@ -0,0 +1,86 @@
#!/bin/bash
# Copyright (c) 2009-2010 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Script to update the kernel on a live running ChromiumOS instance.
# Load common constants. This should be the first executable line.
# The path to common.sh should be relative to your script's location.
. "$(dirname $0)/common.sh"
. "$(dirname $0)/remote_access.sh"
DEFINE_string board "" "Override board reported by target"
DEFINE_string partition "" "Override kernel partition reported by target"
function cleanup {
cleanup_remote_access
rm -rf "${TMP}"
}
# Ask the target what the kernel partition is
function learn_partition() {
[ -n "${FLAGS_partition}" ] && return
remote_sh cat /proc/cmdline
if echo "${REMOTE_OUT}" | grep -q "/dev/sda3"; then
FLAGS_partition="/dev/sda2"
else
FLAGS_partition="/dev/sda4"
fi
if [ -z "${FLAGS_partition}" ]; then
error "Partition required"
exit 1
fi
info "Target reports kernel partition is ${FLAGS_partition}"
}
function main() {
assert_outside_chroot
cd $(dirname "$0")
FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
set -e
trap cleanup EXIT
TMP=$(mktemp -d /tmp/image_to_live.XXXX)
remote_access_init
learn_board
remote_sh uname -r -v
old_kernel="${REMOTE_OUT}"
cmd="vbutil_kernel --pack new_kern.bin \
--keyblock /usr/share/vboot/devkeys/kernel.keyblock \
--signprivate /usr/share/vboot/devkeys/kernel_data_key.vbprivk \
--version 1 \
--config ../build/images/${FLAGS_board}/latest/config.txt \
--bootloader /lib64/bootstub/bootstub.efi \
--vmlinuz /build/${FLAGS_board}/boot/vmlinuz"
./enter_chroot.sh -- "${cmd}"
learn_partition
remote_cp_to new_kern.bin /tmp
remote_sh dd if=/tmp/new_kern.bin of="${FLAGS_partition}"
remote_reboot
remote_sh uname -r -v
info "old kernel: ${old_kernel}"
info "new kernel: ${REMOTE_OUT}"
}
main $@