OLD | NEW |
---|---|
1 #!/bin/bash | 1 #!/bin/bash |
2 | 2 |
3 # Copyright (c) 2009-2010 The Chromium OS Authors. All rights reserved. | 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 | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 # Script to update the kernel on a live running ChromiumOS instance. | 7 # Script to update the kernel on a live running ChromiumOS instance. |
8 | 8 |
9 # Load common constants. This should be the first executable line. | 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. | 10 # The path to common.sh should be relative to your script's location. |
11 | 11 |
12 . "$(dirname $0)/common.sh" | 12 . "$(dirname $0)/common.sh" |
13 . "$(dirname $0)/remote_access.sh" | 13 . "$(dirname $0)/remote_access.sh" |
14 | 14 |
15 DEFINE_string board "" "Override board reported by target" | 15 DEFINE_string board "" "Override board reported by target" |
16 DEFINE_string device "" "Override boot device reported by target" | |
16 DEFINE_string partition "" "Override kernel partition reported by target" | 17 DEFINE_string partition "" "Override kernel partition reported by target" |
18 DEFINE_string arch "" "Override architecture reported by target" | |
17 DEFINE_boolean modules false "Update modules on target" | 19 DEFINE_boolean modules false "Update modules on target" |
18 DEFINE_boolean firmware false "Update firmware on target" | 20 DEFINE_boolean firmware false "Update firmware on target" |
19 | 21 |
20 function cleanup { | 22 function cleanup { |
21 cleanup_remote_access | 23 cleanup_remote_access |
22 rm -rf "${TMP}" | 24 rm -rf "${TMP}" |
23 } | 25 } |
24 | 26 |
27 function learn_device() { | |
28 [ -n "${FLAGS_device}" ] && return | |
29 remote_sh df /mnt/stateful_partition | |
30 FLAGS_device=$(echo "${REMOTE_OUT}" | awk '/dev/ {print $1}' | sed s/1\$//) | |
31 info "Target reports root device is ${FLAGS_device}" | |
Kenneth Waters
2010/12/23 18:14:06
This is a bit misleading. It doesn't learn the de
Olof Johansson
2010/12/23 18:48:33
Sure, will do
| |
32 } | |
33 | |
25 # Ask the target what the kernel partition is | 34 # Ask the target what the kernel partition is |
26 function learn_partition() { | 35 function learn_partition() { |
27 [ -n "${FLAGS_partition}" ] && return | 36 [ -n "${FLAGS_partition}" ] && return |
28 remote_sh cat /proc/cmdline | 37 remote_sh cat /proc/cmdline |
29 if echo "${REMOTE_OUT}" | grep -q "/dev/sda3"; then | 38 if echo "${REMOTE_OUT}" | egrep -q "${FLAGS_device}3"; then |
30 FLAGS_partition="/dev/sda2" | 39 FLAGS_partition="${FLAGS_device}2" |
31 else | 40 else |
32 FLAGS_partition="/dev/sda4" | 41 FLAGS_partition="${FLAGS_device}4" |
33 fi | 42 fi |
34 if [ -z "${FLAGS_partition}" ]; then | 43 if [ -z "${FLAGS_partition}" ]; then |
35 error "Partition required" | 44 error "Partition required" |
36 exit 1 | 45 exit 1 |
37 fi | 46 fi |
38 info "Target reports kernel partition is ${FLAGS_partition}" | 47 info "Target reports kernel partition is ${FLAGS_partition}" |
39 } | 48 } |
40 | 49 |
50 function make_kernelimage() { | |
51 | |
52 if [[ "${FLAGS_arch}" == "arm" ]]; then | |
53 cmd="./build_kernel_image.sh --arch=arm \ | |
54 --root='/dev/\\\${devname}\\\${rootpart}' \ | |
55 --vmlinuz=/build/${FLAGS_board}/boot/vmlinux.uimg --to new_kern.bin" | |
Kenneth Waters
2010/12/23 18:14:06
The quoting it burns. Maybe this one instead? It
Olof Johansson
2010/12/23 18:48:33
Yeah, it's bad. Yours is a little less nasty thoug
| |
56 | |
57 else | |
58 cmd="vbutil_kernel --pack new_kern.bin \ | |
Kenneth Waters
2010/12/23 18:14:06
I was somewhat upset that this didn't use build_ke
Olof Johansson
2010/12/23 18:48:33
msb, care to comment? I didn't go down that route
Mandeep Singh Baines
2010/12/23 21:34:19
Never considered it. If it works, let's do it. Wou
| |
59 --keyblock /usr/share/vboot/devkeys/kernel.keyblock \ | |
60 --signprivate /usr/share/vboot/devkeys/kernel_data_key.vbprivk \ | |
61 --version 1 \ | |
62 --config ../build/images/${FLAGS_board}/latest/config.txt \ | |
63 --bootloader /lib64/bootstub/bootstub.efi \ | |
64 --vmlinuz /build/${FLAGS_board}/boot/vmlinuz" | |
65 fi | |
66 | |
67 ./enter_chroot.sh -- ${cmd} | |
68 } | |
69 | |
41 function main() { | 70 function main() { |
42 assert_outside_chroot | 71 assert_outside_chroot |
43 | 72 |
44 cd $(dirname "$0") | 73 cd $(dirname "$0") |
45 | 74 |
46 FLAGS "$@" || exit 1 | 75 FLAGS "$@" || exit 1 |
47 eval set -- "${FLAGS_ARGV}" | 76 eval set -- "${FLAGS_ARGV}" |
48 | 77 |
49 set -e | 78 set -e |
50 | 79 |
51 trap cleanup EXIT | 80 trap cleanup EXIT |
52 | 81 |
53 TMP=$(mktemp -d /tmp/image_to_live.XXXX) | 82 TMP=$(mktemp -d /tmp/image_to_live.XXXX) |
54 | 83 |
55 remote_access_init | 84 remote_access_init |
56 | 85 |
86 learn_arch | |
87 | |
57 learn_board | 88 learn_board |
58 | 89 |
59 remote_sh uname -r -v | 90 remote_sh uname -r -v |
60 | 91 |
61 old_kernel="${REMOTE_OUT}" | 92 old_kernel="${REMOTE_OUT}" |
62 | 93 |
63 cmd="vbutil_kernel --pack new_kern.bin \ | 94 learn_device |
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 | |
71 ./enter_chroot.sh -- ${cmd} | |
72 | 95 |
73 learn_partition | 96 learn_partition |
74 | 97 |
98 make_kernelimage | |
99 | |
75 remote_cp_to new_kern.bin /tmp | 100 remote_cp_to new_kern.bin /tmp |
76 | 101 |
77 remote_sh dd if=/tmp/new_kern.bin of="${FLAGS_partition}" | 102 remote_sh dd if=/tmp/new_kern.bin of="${FLAGS_partition}" |
78 | 103 |
79 if [[ ${FLAGS_modules} -eq ${FLAGS_TRUE} ]]; then | 104 if [[ ${FLAGS_modules} -eq ${FLAGS_TRUE} ]]; then |
80 echo "copying modules" | 105 echo "copying modules" |
81 cmd="tar -C /build/${FLAGS_board}/lib/modules -cjf new_modules.tar ." | 106 cmd="sudo tar -C /build/${FLAGS_board}/lib/modules -cjf new_modules.tar ." |
82 ./enter_chroot.sh -- ${cmd} | 107 ./enter_chroot.sh -- ${cmd} |
83 | 108 |
84 remote_cp_to new_modules.tar /tmp/ | 109 remote_cp_to new_modules.tar /tmp/ |
85 | 110 |
86 remote_sh mount -o remount,rw / | 111 remote_sh mount -o remount,rw / |
87 remote_sh tar -C /lib/modules -xjf /tmp/new_modules.tar | 112 remote_sh tar -C /lib/modules -xjf /tmp/new_modules.tar |
88 fi | 113 fi |
89 | 114 |
90 if [[ ${FLAGS_firmware} -eq ${FLAGS_TRUE} ]]; then | 115 if [[ ${FLAGS_firmware} -eq ${FLAGS_TRUE} ]]; then |
91 echo "copying firmware" | 116 echo "copying firmware" |
92 cmd="tar -C /build/${FLAGS_board}/lib/firmware -cjf new_firmware.tar ." | 117 cmd="sudo tar -C /build/${FLAGS_board}/lib/firmware -cjf new_firmware.tar ." |
93 ./enter_chroot.sh -- ${cmd} | 118 ./enter_chroot.sh -- ${cmd} |
94 | 119 |
95 remote_cp_to new_firmware.tar /tmp/ | 120 remote_cp_to new_firmware.tar /tmp/ |
96 | 121 |
97 remote_sh mount -o remount,rw / | 122 remote_sh mount -o remount,rw / |
98 remote_sh tar -C /lib/firmware -xjf /tmp/new_firmware.tar | 123 remote_sh tar -C /lib/firmware -xjf /tmp/new_firmware.tar |
99 fi | 124 fi |
100 | 125 |
101 remote_reboot | 126 remote_reboot |
102 | 127 |
103 remote_sh uname -r -v | 128 remote_sh uname -r -v |
104 | 129 |
105 info "old kernel: ${old_kernel}" | 130 info "old kernel: ${old_kernel}" |
106 | 131 |
107 info "new kernel: ${REMOTE_OUT}" | 132 info "new kernel: ${REMOTE_OUT}" |
108 } | 133 } |
109 | 134 |
110 main $@ | 135 main $@ |
Kenneth Waters
2010/12/23 18:14:06
I know this isn't your mistake but this needs to b
Olof Johansson
2010/12/23 18:48:33
Will do.
| |
OLD | NEW |