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 # Script must be run inside the chroot. | 15 # Script must be run inside the chroot. |
16 restart_in_chroot_if_needed $* | 16 restart_in_chroot_if_needed $* |
17 | 17 |
18 DEFINE_string board "" "Override board reported by target" | 18 DEFINE_string board "" "Override board reported by target" |
| 19 DEFINE_string device "" "Override boot device reported by target" |
19 DEFINE_string partition "" "Override kernel partition reported by target" | 20 DEFINE_string partition "" "Override kernel partition reported by target" |
| 21 DEFINE_string arch "" "Override architecture reported by target" |
20 DEFINE_boolean modules false "Update modules on target" | 22 DEFINE_boolean modules false "Update modules on target" |
21 DEFINE_boolean firmware false "Update firmware on target" | 23 DEFINE_boolean firmware false "Update firmware on target" |
22 | 24 |
23 # Parse command line. | 25 # Parse command line. |
24 FLAGS "$@" || exit 1 | 26 FLAGS "$@" || exit 1 |
25 eval set -- "${FLAGS_ARGV}" | 27 eval set -- "${FLAGS_ARGV}" |
26 | 28 |
27 # Only now can we die on error. shflags functions leak non-zero error codes, | 29 # 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. | 30 # so will die prematurely if 'set -e' is specified before now. |
29 set -e | 31 set -e |
30 | 32 |
31 function cleanup { | 33 function cleanup { |
32 cleanup_remote_access | 34 cleanup_remote_access |
33 rm -rf "${TMP}" | 35 rm -rf "${TMP}" |
34 } | 36 } |
35 | 37 |
| 38 function learn_device() { |
| 39 [ -n "${FLAGS_device}" ] && return |
| 40 remote_sh df /mnt/stateful_partition |
| 41 FLAGS_device=$(echo "${REMOTE_OUT}" | awk '/dev/ {print $1}' | sed s/1\$//) |
| 42 info "Target reports root device is ${FLAGS_device}" |
| 43 } |
| 44 |
36 # Ask the target what the kernel partition is | 45 # Ask the target what the kernel partition is |
37 function learn_partition() { | 46 function learn_partition() { |
38 [ -n "${FLAGS_partition}" ] && return | 47 [ -n "${FLAGS_partition}" ] && return |
39 remote_sh cat /proc/cmdline | 48 remote_sh cat /proc/cmdline |
40 if echo "${REMOTE_OUT}" | grep -q "/dev/sda3"; then | 49 if echo "${REMOTE_OUT}" | egrep -q "${FLAGS_device}3"; then |
41 FLAGS_partition="/dev/sda2" | 50 FLAGS_partition="${FLAGS_device}2" |
42 else | 51 else |
43 FLAGS_partition="/dev/sda4" | 52 FLAGS_partition="${FLAGS_device}4" |
44 fi | 53 fi |
45 if [ -z "${FLAGS_partition}" ]; then | 54 if [ -z "${FLAGS_partition}" ]; then |
46 error "Partition required" | 55 error "Partition required" |
47 exit 1 | 56 exit 1 |
48 fi | 57 fi |
49 info "Target reports kernel partition is ${FLAGS_partition}" | 58 info "Target reports kernel partition is ${FLAGS_partition}" |
50 } | 59 } |
51 | 60 |
| 61 function make_kernelimage() { |
| 62 |
| 63 if [[ "${FLAGS_arch}" == "arm" ]]; then |
| 64 ./build_kernel_image.sh --arch=arm \ |
| 65 --root='/dev/${devname}${rootpart}' \ |
| 66 --vmlinuz=/build/${FLAGS_board}/boot/vmlinux.uimg --to new_kern.bin |
| 67 else |
| 68 vbutil_kernel --pack new_kern.bin \ |
| 69 --keyblock /usr/share/vboot/devkeys/kernel.keyblock \ |
| 70 --signprivate /usr/share/vboot/devkeys/kernel_data_key.vbprivk \ |
| 71 --version 1 \ |
| 72 --config ../build/images/${FLAGS_board}/latest/config.txt \ |
| 73 --bootloader /lib64/bootstub/bootstub.efi \ |
| 74 --vmlinuz /build/${FLAGS_board}/boot/vmlinuz |
| 75 fi |
| 76 } |
| 77 |
52 function main() { | 78 function main() { |
53 trap cleanup EXIT | 79 trap cleanup EXIT |
54 | 80 |
55 TMP=$(mktemp -d /tmp/image_to_live.XXXX) | 81 TMP=$(mktemp -d /tmp/image_to_live.XXXX) |
56 | 82 |
57 remote_access_init | 83 remote_access_init |
58 | 84 |
| 85 learn_arch |
| 86 |
59 learn_board | 87 learn_board |
60 | 88 |
| 89 learn_device |
| 90 |
| 91 learn_partition |
| 92 |
61 remote_sh uname -r -v | 93 remote_sh uname -r -v |
62 | 94 |
63 old_kernel="${REMOTE_OUT}" | 95 old_kernel="${REMOTE_OUT}" |
64 | 96 |
65 vbutil_kernel --pack new_kern.bin \ | 97 make_kernelimage |
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 | |
72 | |
73 learn_partition | |
74 | 98 |
75 remote_cp_to new_kern.bin /tmp | 99 remote_cp_to new_kern.bin /tmp |
76 | 100 |
77 remote_sh dd if=/tmp/new_kern.bin of="${FLAGS_partition}" | 101 remote_sh dd if=/tmp/new_kern.bin of="${FLAGS_partition}" |
78 | 102 |
79 if [[ ${FLAGS_modules} -eq ${FLAGS_TRUE} ]]; then | 103 if [[ ${FLAGS_modules} -eq ${FLAGS_TRUE} ]]; then |
80 echo "copying modules" | 104 echo "copying modules" |
81 tar -C /build/"${FLAGS_board}"/lib/modules -cjf new_modules.tar . | 105 tar -C /build/"${FLAGS_board}"/lib/modules -cjf /tmp/new_modules.tar . |
82 | 106 |
83 remote_cp_to new_modules.tar /tmp/ | 107 remote_cp_to /tmp/new_modules.tar /tmp/ |
84 | 108 |
85 remote_sh mount -o remount,rw / | 109 remote_sh mount -o remount,rw / |
86 remote_sh tar -C /lib/modules -xjf /tmp/new_modules.tar | 110 remote_sh tar -C /lib/modules -xjf /tmp/new_modules.tar |
87 fi | 111 fi |
88 | 112 |
89 if [[ ${FLAGS_firmware} -eq ${FLAGS_TRUE} ]]; then | 113 if [[ ${FLAGS_firmware} -eq ${FLAGS_TRUE} ]]; then |
90 echo "copying firmware" | 114 echo "copying firmware" |
91 tar -C /build/"${FLAGS_board}"/lib/firmware -cjf new_firmware.tar . | 115 tar -C /build/"${FLAGS_board}"/lib/firmware -cjf /tmp/new_firmware.tar . |
92 | 116 |
93 remote_cp_to new_firmware.tar /tmp/ | 117 remote_cp_to /tmp/new_firmware.tar /tmp/ |
94 | 118 |
95 remote_sh mount -o remount,rw / | 119 remote_sh mount -o remount,rw / |
96 remote_sh tar -C /lib/firmware -xjf /tmp/new_firmware.tar | 120 remote_sh tar -C /lib/firmware -xjf /tmp/new_firmware.tar |
97 fi | 121 fi |
98 | 122 |
99 remote_reboot | 123 remote_reboot |
100 | 124 |
101 remote_sh uname -r -v | 125 remote_sh uname -r -v |
102 info "old kernel: ${old_kernel}" | 126 info "old kernel: ${old_kernel}" |
103 info "new kernel: ${REMOTE_OUT}" | 127 info "new kernel: ${REMOTE_OUT}" |
104 } | 128 } |
105 | 129 |
106 main $@ | 130 main "$@" |
OLD | NEW |