Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Taylor Hutt | 60da642 | 2011-06-02 13:54:43 -0700 | [diff] [blame] | 3 | # Copyright (c) 2009-2011 The Chromium OS Authors. All rights reserved. |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 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 | |
Brian Harring | aa13ea4 | 2012-03-15 18:31:03 -0700 | [diff] [blame] | 9 | SCRIPT_ROOT=$(dirname $(readlink -f "$0")) |
David James | 359d3e1 | 2012-07-10 13:09:48 -0700 | [diff] [blame] | 10 | . "${SCRIPT_ROOT}/common.sh" || exit 1 |
| 11 | . "${SCRIPT_ROOT}/remote_access.sh" || exit 1 |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 12 | |
Mandeep Singh Baines | 2f3b5fc | 2011-01-14 14:20:12 -0800 | [diff] [blame] | 13 | # Script must be run inside the chroot. |
Greg Spencer | 798d75f | 2011-02-01 22:04:49 -0800 | [diff] [blame] | 14 | restart_in_chroot_if_needed "$@" |
Mandeep Singh Baines | 2f3b5fc | 2011-01-14 14:20:12 -0800 | [diff] [blame] | 15 | |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 16 | DEFINE_string board "" "Override board reported by target" |
Olof Johansson | f53fa0d | 2011-01-26 13:06:46 -0800 | [diff] [blame] | 17 | DEFINE_string device "" "Override boot device reported by target" |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 18 | DEFINE_string partition "" "Override kernel partition reported by target" |
Doug Anderson | fcaed8a | 2014-07-09 11:34:29 -0700 | [diff] [blame] | 19 | DEFINE_string rootoff "" "Override root offset" |
Stephen Boyd | f16cd6b | 2019-03-08 09:27:10 -0800 | [diff] [blame] | 20 | DEFINE_string rootfs "" "Override rootfs partition reported by target" |
Olof Johansson | f53fa0d | 2011-01-26 13:06:46 -0800 | [diff] [blame] | 21 | DEFINE_string arch "" "Override architecture reported by target" |
Jack Rosenthal | 9541b8c | 2019-07-26 10:45:55 -0600 | [diff] [blame] | 22 | DEFINE_boolean clean $FLAGS_FALSE "Remove old files before sending new files" |
Tomasz Jeznach | bc9c5a4 | 2020-01-30 10:19:40 -0800 | [diff] [blame] | 23 | DEFINE_boolean hv $FLAGS_TRUE "Use hypervisor kernel if available." |
Nicolas Boichat | 78383c0 | 2020-10-21 10:04:31 +0800 | [diff] [blame] | 24 | DEFINE_boolean ignore_verity $FLAGS_FALSE "Update kernel even if system is using verity \ |
| 25 | (WARNING: likely to make the system unable to boot)" |
Olof Johansson | 8488f5a | 2011-04-20 17:27:37 -0700 | [diff] [blame] | 26 | DEFINE_boolean reboot $FLAGS_TRUE "Reboot system after update" |
Doug Anderson | 5a21b44 | 2012-12-07 11:47:31 -0800 | [diff] [blame] | 27 | DEFINE_boolean vboot $FLAGS_TRUE "Update the vboot kernel" |
Douglas Anderson | b57a9d3 | 2019-06-04 13:50:17 -0700 | [diff] [blame] | 28 | DEFINE_boolean syslinux $FLAGS_TRUE "Update the syslinux kernel (including /boot)" |
Olof Johansson | 45225c9 | 2013-10-15 17:32:48 -0700 | [diff] [blame] | 29 | DEFINE_boolean bootonce $FLAGS_FALSE "Mark kernel partition as boot once" |
Olof Johansson | 4a7b288 | 2013-10-16 11:59:58 -0700 | [diff] [blame] | 30 | DEFINE_boolean remote_bootargs $FLAGS_FALSE "Use bootargs from running kernel on target" |
Nicolas Boichat | a595deb | 2017-02-07 18:53:44 +0800 | [diff] [blame] | 31 | DEFINE_boolean firmware $FLAGS_FALSE "Also update firmwares (/lib/firmware)" |
Anand K Mistry | 388f9c8 | 2021-01-08 16:35:10 +1100 | [diff] [blame] | 32 | DEFINE_boolean ab_update $FLAGS_FALSE "Update the kernel in the non-booting \ |
| 33 | kernel slot, similar to an AB update" |
Sean Paul | 29e8e62 | 2019-03-19 12:20:49 -0400 | [diff] [blame] | 34 | DEFINE_string boot_command "" "Command to run on remote after update (after reboot if applicable)" |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 35 | |
Doug Anderson | 549f3b5 | 2013-09-26 14:46:18 -0700 | [diff] [blame] | 36 | ORIG_ARGS=("$@") |
| 37 | |
Mandeep Singh Baines | 2f3b5fc | 2011-01-14 14:20:12 -0800 | [diff] [blame] | 38 | # Parse command line. |
| 39 | FLAGS "$@" || exit 1 |
| 40 | eval set -- "${FLAGS_ARGV}" |
| 41 | |
| 42 | # Only now can we die on error. shflags functions leak non-zero error codes, |
Brian Harring | 7f175a5 | 2012-03-02 05:37:00 -0800 | [diff] [blame] | 43 | # so will die prematurely if 'switch_to_strict_mode' is specified before now. |
| 44 | switch_to_strict_mode |
Mandeep Singh Baines | 2f3b5fc | 2011-01-14 14:20:12 -0800 | [diff] [blame] | 45 | |
Mike Frysinger | 6b1abb2 | 2012-05-11 13:44:06 -0400 | [diff] [blame] | 46 | cleanup() { |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 47 | cleanup_remote_access |
| 48 | rm -rf "${TMP}" |
| 49 | } |
| 50 | |
Jack Rosenthal | 9541b8c | 2019-07-26 10:45:55 -0600 | [diff] [blame] | 51 | # If rsync errors due to no space on the device, suggest running with the clean |
| 52 | # flag to make space before copying |
| 53 | handle_no_space() { |
| 54 | if [[ ${FLAGS_clean} -ne ${FLAGS_TRUE} ]]; then |
| 55 | warn "There is not enough space to copy all necessary files." |
| 56 | warn "Try running again with the --clean flag." |
| 57 | fi |
| 58 | die_notrace "No space left on device." |
| 59 | } |
| 60 | |
Mike Frysinger | 6b1abb2 | 2012-05-11 13:44:06 -0400 | [diff] [blame] | 61 | learn_device() { |
Olof Johansson | f53fa0d | 2011-01-26 13:06:46 -0800 | [diff] [blame] | 62 | [ -n "${FLAGS_device}" ] && return |
| 63 | remote_sh df /mnt/stateful_partition |
| 64 | FLAGS_device=$(echo "${REMOTE_OUT}" | awk '/dev/ {print $1}' | sed s/1\$//) |
| 65 | info "Target reports root device is ${FLAGS_device}" |
| 66 | } |
| 67 | |
Ben Zhang | 15fa4b1 | 2017-06-19 20:02:57 -0700 | [diff] [blame] | 68 | # Delete the fixed numbers after R65 when we don't care about <R57 upgrades. |
| 69 | load_default_partition_numbers() { |
| 70 | PARTITION_NUM_KERN_A=2 |
| 71 | PARTITION_NUM_ROOT_A=3 |
| 72 | PARTITION_NUM_KERN_B=4 |
Anand K Mistry | 388f9c8 | 2021-01-08 16:35:10 +1100 | [diff] [blame] | 73 | PARTITION_NUM_ROOT_B=5 |
Ben Zhang | 15fa4b1 | 2017-06-19 20:02:57 -0700 | [diff] [blame] | 74 | PARTITION_NUM_EFI_SYSTEM=12 |
| 75 | } |
| 76 | |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 77 | # Ask the target what the kernel partition is |
Mike Frysinger | 6b1abb2 | 2012-05-11 13:44:06 -0400 | [diff] [blame] | 78 | learn_partition_and_ro() { |
Mandeep Singh Baines | e39579a | 2011-03-04 15:58:57 -0800 | [diff] [blame] | 79 | ! remote_sh rootdev |
Paul Taysom | a64d9db | 2012-09-21 13:30:43 -0700 | [diff] [blame] | 80 | if [ "${REMOTE_OUT%%-*}" == "/dev/dm" ]; then |
| 81 | remote_sh rootdev -s |
Olof Johansson | 8488f5a | 2011-04-20 17:27:37 -0700 | [diff] [blame] | 82 | REMOTE_VERITY=${FLAGS_TRUE} |
Nicolas Boichat | abdf664 | 2016-07-04 11:30:44 +0800 | [diff] [blame] | 83 | if [[ ${FLAGS_ignore_verity} -eq ${FLAGS_TRUE} ]]; then |
| 84 | warn "System is using verity: not updating firmware/modules" |
| 85 | else |
| 86 | warn "System is using verity: First remove rootfs verification using" |
| 87 | warn "/usr/share/vboot/bin/make_dev_ssd.sh --remove_rootfs_verification" |
Nicolas Boichat | 78383c0 | 2020-10-21 10:04:31 +0800 | [diff] [blame] | 88 | warn "on the DUT." |
Brian Norris | ed75157 | 2018-03-30 13:48:43 -0700 | [diff] [blame] | 89 | die_notrace |
Nicolas Boichat | abdf664 | 2016-07-04 11:30:44 +0800 | [diff] [blame] | 90 | fi |
Olof Johansson | 8488f5a | 2011-04-20 17:27:37 -0700 | [diff] [blame] | 91 | else |
| 92 | REMOTE_VERITY=${FLAGS_FALSE} |
| 93 | info "System is not using verity: updating firmware and modules" |
Mandeep Singh Baines | e39579a | 2011-03-04 15:58:57 -0800 | [diff] [blame] | 94 | fi |
Anand K Mistry | 388f9c8 | 2021-01-08 16:35:10 +1100 | [diff] [blame] | 95 | if [[ ${FLAGS_ab_update} -eq ${FLAGS_TRUE} ]]; then |
| 96 | if [[ "${REMOTE_OUT}" == "${FLAGS_device}${PARTITION_NUM_ROOT_A}" ]]; then |
| 97 | FLAGS_partition="${FLAGS_device}${PARTITION_NUM_KERN_B}" |
| 98 | FLAGS_rootfs="${FLAGS_device}${PARTITION_NUM_ROOT_B}" |
| 99 | else |
| 100 | FLAGS_partition="${FLAGS_device}${PARTITION_NUM_KERN_A}" |
| 101 | FLAGS_rootfs="${FLAGS_device}${PARTITION_NUM_ROOT_A}" |
| 102 | fi |
| 103 | fi |
Stephen Boyd | f16cd6b | 2019-03-08 09:27:10 -0800 | [diff] [blame] | 104 | if [[ -z "${FLAGS_rootfs}" ]]; then |
| 105 | FLAGS_rootfs="${REMOTE_OUT}" |
| 106 | fi |
| 107 | # If rootfs is for different partition than we're currently running on |
| 108 | # mount it manually to update the right modules, firmware, etc. |
| 109 | REMOTE_NEEDS_ROOTFS_MOUNTED=${FLAGS_FALSE} |
| 110 | if [[ "${REMOTE_OUT}" != "${FLAGS_rootfs}" ]]; then |
| 111 | REMOTE_NEEDS_ROOTFS_MOUNTED=${FLAGS_TRUE} |
| 112 | fi |
Olof Johansson | 4996bfb | 2013-11-13 12:58:52 -0800 | [diff] [blame] | 113 | [ -n "${FLAGS_partition}" ] && return |
Steven 'Steve' Kendall | 019f38f | 2016-06-09 12:43:28 -0400 | [diff] [blame] | 114 | if [ "${REMOTE_OUT}" == "${FLAGS_device}${PARTITION_NUM_ROOT_A}" ]; then |
| 115 | FLAGS_partition="${FLAGS_device}${PARTITION_NUM_KERN_A}" |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 116 | else |
Steven 'Steve' Kendall | 019f38f | 2016-06-09 12:43:28 -0400 | [diff] [blame] | 117 | FLAGS_partition="${FLAGS_device}${PARTITION_NUM_KERN_B}" |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 118 | fi |
| 119 | if [ -z "${FLAGS_partition}" ]; then |
Brian Norris | ed75157 | 2018-03-30 13:48:43 -0700 | [diff] [blame] | 120 | die_notrace "Partition required" |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 121 | fi |
Doug Anderson | 5a21b44 | 2012-12-07 11:47:31 -0800 | [diff] [blame] | 122 | if [ ${REMOTE_VERITY} -eq ${FLAGS_TRUE} ]; then |
| 123 | info "Target reports kernel partition is ${FLAGS_partition}" |
| 124 | if [ ${FLAGS_vboot} -eq ${FLAGS_FALSE} ]; then |
Brian Norris | ed75157 | 2018-03-30 13:48:43 -0700 | [diff] [blame] | 125 | die_notrace "Must update vboot when target is using verity" |
Doug Anderson | 5a21b44 | 2012-12-07 11:47:31 -0800 | [diff] [blame] | 126 | fi |
| 127 | fi |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 128 | } |
| 129 | |
Olof Johansson | 4a7b288 | 2013-10-16 11:59:58 -0700 | [diff] [blame] | 130 | get_bootargs() { |
Mike Frysinger | d4b6f95 | 2017-04-10 16:42:17 -0400 | [diff] [blame] | 131 | local local_config="${SRC_ROOT}/build/images/${FLAGS_board}/latest/config.txt" |
| 132 | |
| 133 | # Autodetect by default. https://crbug.com/316239 |
| 134 | # This isn't quite right if people use --noremote_bootargs, but that's not |
| 135 | # a scenario people do today, so we won't worry about it. |
| 136 | if [[ ${FLAGS_remote_bootargs} -eq ${FLAGS_FALSE} && \ |
| 137 | ! -e "${local_config}" ]]; then |
| 138 | warn "Local kernel config does not exist: ${local_config}" |
| 139 | FLAGS_remote_bootargs=${FLAGS_TRUE} |
| 140 | fi |
| 141 | |
Olof Johansson | 4a7b288 | 2013-10-16 11:59:58 -0700 | [diff] [blame] | 142 | if [ ${FLAGS_remote_bootargs} -eq ${FLAGS_TRUE} ] ; then |
| 143 | info "Using remote bootargs" |
Stephen Boyd | f4e70f9 | 2019-11-18 09:38:20 -0800 | [diff] [blame] | 144 | remote_sh dump_kernel_config "${FLAGS_partition}" |
| 145 | printf '%s' "${REMOTE_OUT}" |
Olof Johansson | 4a7b288 | 2013-10-16 11:59:58 -0700 | [diff] [blame] | 146 | else |
Doug Anderson | fcaed8a | 2014-07-09 11:34:29 -0700 | [diff] [blame] | 147 | if [ -n "${FLAGS_rootoff}" ]; then |
Mike Frysinger | d4b6f95 | 2017-04-10 16:42:17 -0400 | [diff] [blame] | 148 | sed "s/PARTNROFF=1/PARTNROFF=${FLAGS_rootoff}/" "${local_config}" |
Doug Anderson | fcaed8a | 2014-07-09 11:34:29 -0700 | [diff] [blame] | 149 | else |
Mike Frysinger | d4b6f95 | 2017-04-10 16:42:17 -0400 | [diff] [blame] | 150 | cat "${local_config}" |
Doug Anderson | fcaed8a | 2014-07-09 11:34:29 -0700 | [diff] [blame] | 151 | fi |
Olof Johansson | 4a7b288 | 2013-10-16 11:59:58 -0700 | [diff] [blame] | 152 | fi |
| 153 | } |
| 154 | |
Stephen Boyd | 6241f70 | 2019-07-26 07:05:25 -0700 | [diff] [blame] | 155 | learn_arch() { |
| 156 | [ -n "${FLAGS_arch}" ] && return |
| 157 | FLAGS_arch=$(sed -n -E 's/^CONFIG_(ARM|ARM64|X86)=y/\1/p' \ |
| 158 | /build/"${FLAGS_board}"/boot/config-* | \ |
| 159 | uniq | awk '{print tolower($0)}') |
| 160 | if [ -z "${FLAGS_arch}" ]; then |
| 161 | error "Arch required" |
| 162 | exit 1 |
| 163 | fi |
| 164 | info "Target reports arch is ${FLAGS_arch}" |
| 165 | } |
| 166 | |
Mike Frysinger | 6b1abb2 | 2012-05-11 13:44:06 -0400 | [diff] [blame] | 167 | make_kernelimage() { |
Tom Wai-Hong Tam | 6b50a07 | 2011-05-25 17:00:15 +0800 | [diff] [blame] | 168 | local bootloader_path |
| 169 | local kernel_image |
Tomasz Jeznach | fc3b714 | 2020-09-01 13:18:30 -0700 | [diff] [blame] | 170 | local boot_path="/build/${FLAGS_board}" |
Olof Johansson | 4a7b288 | 2013-10-16 11:59:58 -0700 | [diff] [blame] | 171 | local config_path="$(mktemp /tmp/config.txt.XXXXX)" |
Tomasz Jeznach | fc3b714 | 2020-09-01 13:18:30 -0700 | [diff] [blame] | 172 | if [[ ${FLAGS_hv} -eq ${FLAGS_TRUE} && \ |
| 173 | -d "${boot_path}/build/manatee/boot" ]]; then |
| 174 | boot_path+="/build/manatee/boot" |
| 175 | else |
| 176 | boot_path+="/boot" |
Micah Morton | 878861f | 2020-09-09 13:21:42 -0700 | [diff] [blame] | 177 | fi |
Stephen Boyd | 6241f70 | 2019-07-26 07:05:25 -0700 | [diff] [blame] | 178 | if [[ "${FLAGS_arch}" == "arm" || "${FLAGS_arch}" == "arm64" ]]; then |
Taylor Hutt | 60da642 | 2011-06-02 13:54:43 -0700 | [diff] [blame] | 179 | name="bootloader.bin" |
| 180 | bootloader_path="${SRC_ROOT}/build/images/${FLAGS_board}/latest/${name}" |
Mike Frysinger | 085c5d9 | 2017-08-16 17:29:12 -0400 | [diff] [blame] | 181 | # If there is no local bootloader stub, create a dummy file. This matches |
| 182 | # build_kernel_image.sh. If we wanted to be super paranoid, we could copy |
| 183 | # and extract it from the remote image, if it had one. |
| 184 | if [[ ! -e "${bootloader_path}" ]]; then |
Stephen Boyd | 5324e26 | 2020-01-29 08:51:35 -0800 | [diff] [blame] | 185 | warn "Bootloader does not exist; creating a stub" |
| 186 | bootloader_path="${TMP}/${name}" |
Mike Frysinger | 085c5d9 | 2017-08-16 17:29:12 -0400 | [diff] [blame] | 187 | truncate -s 512 "${bootloader_path}" |
| 188 | fi |
Tomasz Jeznach | bc9c5a4 | 2020-01-30 10:19:40 -0800 | [diff] [blame] | 189 | kernel_image="${boot_path}/vmlinux.uimg" |
Olof Johansson | f53fa0d | 2011-01-26 13:06:46 -0800 | [diff] [blame] | 190 | else |
Tom Wai-Hong Tam | 6b50a07 | 2011-05-25 17:00:15 +0800 | [diff] [blame] | 191 | bootloader_path="/lib64/bootstub/bootstub.efi" |
Tomasz Jeznach | bc9c5a4 | 2020-01-30 10:19:40 -0800 | [diff] [blame] | 192 | kernel_image="${boot_path}/vmlinuz" |
Tom Wai-Hong Tam | 6b50a07 | 2011-05-25 17:00:15 +0800 | [diff] [blame] | 193 | fi |
Olof Johansson | 4a7b288 | 2013-10-16 11:59:58 -0700 | [diff] [blame] | 194 | get_bootargs > "${config_path}" |
Kees Cook | 43a3213 | 2011-10-18 13:17:11 -0700 | [diff] [blame] | 195 | vbutil_kernel --pack $TMP/new_kern.bin \ |
Olof Johansson | f53fa0d | 2011-01-26 13:06:46 -0800 | [diff] [blame] | 196 | --keyblock /usr/share/vboot/devkeys/kernel.keyblock \ |
| 197 | --signprivate /usr/share/vboot/devkeys/kernel_data_key.vbprivk \ |
| 198 | --version 1 \ |
Olof Johansson | 4a7b288 | 2013-10-16 11:59:58 -0700 | [diff] [blame] | 199 | --config ${config_path} \ |
Tom Wai-Hong Tam | 6b50a07 | 2011-05-25 17:00:15 +0800 | [diff] [blame] | 200 | --bootloader "${bootloader_path}" \ |
| 201 | --vmlinuz "${kernel_image}" \ |
| 202 | --arch "${FLAGS_arch}" |
Olof Johansson | 4a7b288 | 2013-10-16 11:59:58 -0700 | [diff] [blame] | 203 | rm "${config_path}" |
Olof Johansson | f53fa0d | 2011-01-26 13:06:46 -0800 | [diff] [blame] | 204 | } |
| 205 | |
Edward Hyunkoo Jee | a979a90 | 2017-03-08 13:44:26 -0800 | [diff] [blame] | 206 | copy_kernelmodules() { |
Stephen Boyd | f16cd6b | 2019-03-08 09:27:10 -0800 | [diff] [blame] | 207 | local basedir="$1" # rootfs directory (could be in /tmp) or empty string |
Edward Hyunkoo Jee | a979a90 | 2017-03-08 13:44:26 -0800 | [diff] [blame] | 208 | local modules_dir=/build/"${FLAGS_board}"/lib/modules/ |
| 209 | if [ ! -d "${modules_dir}" ]; then |
Jack Rosenthal | 9541b8c | 2019-07-26 10:45:55 -0600 | [diff] [blame] | 210 | info "No modules. Skipping." |
Edward Hyunkoo Jee | a979a90 | 2017-03-08 13:44:26 -0800 | [diff] [blame] | 211 | return |
| 212 | fi |
Jack Rosenthal | 9541b8c | 2019-07-26 10:45:55 -0600 | [diff] [blame] | 213 | if [[ ${FLAGS_clean} -eq ${FLAGS_TRUE} ]]; then |
| 214 | info "Cleaning /lib/modules" |
| 215 | remote_sh rm -rf "${basedir}/lib/modules/*" |
| 216 | fi |
| 217 | info "Copying modules" |
Stephen Boyd | f16cd6b | 2019-03-08 09:27:10 -0800 | [diff] [blame] | 218 | remote_send_to "${modules_dir}" "${basedir}"/lib/modules |
Edward Hyunkoo Jee | a979a90 | 2017-03-08 13:44:26 -0800 | [diff] [blame] | 219 | } |
| 220 | |
Mike Frysinger | 6b1abb2 | 2012-05-11 13:44:06 -0400 | [diff] [blame] | 221 | copy_kernelimage() { |
Doug Anderson | adf8a00 | 2012-12-17 11:40:34 -0800 | [diff] [blame] | 222 | remote_sh dd of="${FLAGS_partition}" bs=4K < "${TMP}/new_kern.bin" |
Olof Johansson | 8488f5a | 2011-04-20 17:27:37 -0700 | [diff] [blame] | 223 | } |
| 224 | |
Jonathan Kliegman | 775bc8e | 2012-08-14 12:30:49 -0400 | [diff] [blame] | 225 | check_kernelbuildtime() { |
| 226 | local version=$(readlink "/build/${FLAGS_board}/boot/vmlinuz" | cut -d- -f2-) |
| 227 | local build_dir="/build/${FLAGS_board}/lib/modules/${version}/build" |
| 228 | if [ "${build_dir}/Makefile" -nt "/build/${FLAGS_board}/boot/vmlinuz" ]; then |
| 229 | warn "Your build directory has been built more recently than" |
| 230 | warn "the installed kernel being updated to. Did you forget to" |
| 231 | warn "run 'cros_workon_make chromeos-kernel --install'?" |
| 232 | fi |
| 233 | } |
| 234 | |
Olof Johansson | 45225c9 | 2013-10-15 17:32:48 -0700 | [diff] [blame] | 235 | mark_boot_once() { |
| 236 | local idx=${FLAGS_partition##*[^0-9]} |
Chirantan Ekbote | f25b440 | 2014-05-06 12:42:18 -0700 | [diff] [blame] | 237 | remote_sh cgpt add -i ${idx} -S 0 -T 1 -P 15 ${FLAGS_device%p} |
Olof Johansson | 45225c9 | 2013-10-15 17:32:48 -0700 | [diff] [blame] | 238 | } |
| 239 | |
Olof Johansson | 68cbfaf | 2013-04-23 14:06:28 -0700 | [diff] [blame] | 240 | update_syslinux_kernel() { |
Daniil Lunev | fbe444a | 2020-04-24 21:47:20 +1000 | [diff] [blame] | 241 | local basedir="$1" # rootfs directory (could be in /tmp) or empty string |
Olof Johansson | 68cbfaf | 2013-04-23 14:06:28 -0700 | [diff] [blame] | 242 | # ARM does not have the syslinux directory, so skip it when the |
Evan Green | fd9652b | 2018-10-01 13:36:02 -0700 | [diff] [blame] | 243 | # partition is missing, the file system fails to mount, or the syslinux |
| 244 | # vmlinuz target is missing. |
Steven 'Steve' Kendall | 019f38f | 2016-06-09 12:43:28 -0400 | [diff] [blame] | 245 | remote_sh grep $(echo ${FLAGS_device}${PARTITION_NUM_EFI_SYSTEM} | cut -d/ -f3) /proc/partitions |
Olof Johansson | 68cbfaf | 2013-04-23 14:06:28 -0700 | [diff] [blame] | 246 | if [ $(echo "$REMOTE_OUT" | wc -l) -eq 1 ]; then |
Steven 'Steve' Kendall | 019f38f | 2016-06-09 12:43:28 -0400 | [diff] [blame] | 247 | remote_sh mkdir -p /tmp/${PARTITION_NUM_EFI_SYSTEM} |
Evan Green | fd9652b | 2018-10-01 13:36:02 -0700 | [diff] [blame] | 248 | if remote_sh mount ${FLAGS_device}${PARTITION_NUM_EFI_SYSTEM} \ |
| 249 | /tmp/${PARTITION_NUM_EFI_SYSTEM}; then |
Olof Johansson | 68cbfaf | 2013-04-23 14:06:28 -0700 | [diff] [blame] | 250 | |
Evan Green | fd9652b | 2018-10-01 13:36:02 -0700 | [diff] [blame] | 251 | if [ "$FLAGS_partition" = "${FLAGS_device}${PARTITION_NUM_KERN_A}" ]; then |
| 252 | target="/tmp/${PARTITION_NUM_EFI_SYSTEM}/syslinux/vmlinuz.A" |
| 253 | else |
| 254 | target="/tmp/${PARTITION_NUM_EFI_SYSTEM}/syslinux/vmlinuz.B" |
| 255 | fi |
Daniil Lunev | fbe444a | 2020-04-24 21:47:20 +1000 | [diff] [blame] | 256 | remote_sh "test ! -f ${target} || \ |
| 257 | cp ${basedir}/boot/vmlinuz ${target}" |
Evan Green | fd9652b | 2018-10-01 13:36:02 -0700 | [diff] [blame] | 258 | |
| 259 | remote_sh umount /tmp/${PARTITION_NUM_EFI_SYSTEM} |
Olof Johansson | 68cbfaf | 2013-04-23 14:06:28 -0700 | [diff] [blame] | 260 | fi |
Steven 'Steve' Kendall | 019f38f | 2016-06-09 12:43:28 -0400 | [diff] [blame] | 261 | remote_sh rmdir /tmp/${PARTITION_NUM_EFI_SYSTEM} |
Olof Johansson | 68cbfaf | 2013-04-23 14:06:28 -0700 | [diff] [blame] | 262 | fi |
| 263 | } |
| 264 | |
Doug Anderson | 549f3b5 | 2013-09-26 14:46:18 -0700 | [diff] [blame] | 265 | multi_main() { |
| 266 | local host |
| 267 | |
| 268 | IFS="," |
| 269 | for host in ${FLAGS_remote}; do |
| 270 | "$0" "${ORIG_ARGS[@]}" --remote="${host}" \ |
| 271 | |& sed "s/^/${V_BOLD_YELLOW}${host}: ${V_VIDOFF}/" & |
| 272 | done |
| 273 | wait |
| 274 | } |
| 275 | |
Mike Frysinger | 6b1abb2 | 2012-05-11 13:44:06 -0400 | [diff] [blame] | 276 | main() { |
Doug Anderson | 549f3b5 | 2013-09-26 14:46:18 -0700 | [diff] [blame] | 277 | # If there are commas in the --remote, run the script in parallel. |
| 278 | if [[ ${FLAGS_remote} == *,* ]]; then |
| 279 | multi_main |
| 280 | return $? |
| 281 | fi |
| 282 | |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 283 | trap cleanup EXIT |
| 284 | |
Kees Cook | 43a3213 | 2011-10-18 13:17:11 -0700 | [diff] [blame] | 285 | TMP=$(mktemp -d /tmp/update_kernel.XXXXXX) |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 286 | |
| 287 | remote_access_init |
| 288 | |
Brian Norris | 4ce176f | 2019-08-22 17:48:18 -0700 | [diff] [blame] | 289 | learn_board |
| 290 | |
Stephen Boyd | 6241f70 | 2019-07-26 07:05:25 -0700 | [diff] [blame] | 291 | learn_arch |
| 292 | |
Olof Johansson | f53fa0d | 2011-01-26 13:06:46 -0800 | [diff] [blame] | 293 | learn_device |
| 294 | |
Ian Coolidge | c3d5d91 | 2017-03-07 14:21:28 -0800 | [diff] [blame] | 295 | learn_partition_layout |
Ben Zhang | 15fa4b1 | 2017-06-19 20:02:57 -0700 | [diff] [blame] | 296 | if [[ -z "${PARTITION_NUM_KERN_A}" ]]; then |
| 297 | info "Target has no partition number info, use default instead" |
| 298 | load_default_partition_numbers |
| 299 | fi |
Ian Coolidge | c3d5d91 | 2017-03-07 14:21:28 -0800 | [diff] [blame] | 300 | |
Olof Johansson | 8488f5a | 2011-04-20 17:27:37 -0700 | [diff] [blame] | 301 | learn_partition_and_ro |
Olof Johansson | f53fa0d | 2011-01-26 13:06:46 -0800 | [diff] [blame] | 302 | |
Brian Norris | 9774b0d | 2017-06-15 13:44:26 -0700 | [diff] [blame] | 303 | if ! remote_sh "test -e '${FLAGS_partition}'"; then |
| 304 | die_notrace "Could not find kernel partition on DUT; path='${FLAGS_partition}'" |
| 305 | fi |
| 306 | |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 307 | remote_sh uname -r -v |
| 308 | |
| 309 | old_kernel="${REMOTE_OUT}" |
| 310 | |
Jonathan Kliegman | 775bc8e | 2012-08-14 12:30:49 -0400 | [diff] [blame] | 311 | check_kernelbuildtime |
| 312 | |
Doug Anderson | 5a21b44 | 2012-12-07 11:47:31 -0800 | [diff] [blame] | 313 | if [ ${FLAGS_vboot} -eq ${FLAGS_TRUE} ]; then |
| 314 | make_kernelimage |
| 315 | fi |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 316 | |
Olof Johansson | 8488f5a | 2011-04-20 17:27:37 -0700 | [diff] [blame] | 317 | if [[ ${REMOTE_VERITY} -eq ${FLAGS_FALSE} ]]; then |
Stephen Boyd | f16cd6b | 2019-03-08 09:27:10 -0800 | [diff] [blame] | 318 | local remote_basedir |
| 319 | if [[ ${REMOTE_NEEDS_ROOTFS_MOUNTED} -eq ${FLAGS_TRUE} ]]; then |
Stephen Boyd | 0758d1a | 2020-01-14 19:30:57 -0800 | [diff] [blame] | 320 | remote_sh mktemp -d /tmp/rootfs_mounted.XXXXXX |
Stephen Boyd | f16cd6b | 2019-03-08 09:27:10 -0800 | [diff] [blame] | 321 | remote_basedir="${REMOTE_OUT}" |
| 322 | remote_sh mount "${FLAGS_rootfs}" "${remote_basedir}" |
| 323 | else |
| 324 | remote_sh mount -o remount,rw / |
| 325 | fi |
Kees Cook | 7d7d2ef | 2011-10-18 13:12:12 -0700 | [diff] [blame] | 326 | |
Douglas Anderson | b57a9d3 | 2019-06-04 13:50:17 -0700 | [diff] [blame] | 327 | if [[ ${FLAGS_syslinux} -eq ${FLAGS_TRUE} ]]; then |
Jack Rosenthal | 9541b8c | 2019-07-26 10:45:55 -0600 | [diff] [blame] | 328 | if [[ ${FLAGS_clean} -eq ${FLAGS_TRUE} ]]; then |
| 329 | info "Cleaning /boot" |
| 330 | remote_sh rm -rf "${remote_basedir}"/boot/{System,config,vmlinuz}'*' |
| 331 | fi |
Douglas Anderson | b57a9d3 | 2019-06-04 13:50:17 -0700 | [diff] [blame] | 332 | info "Copying syslinux and /boot" |
| 333 | remote_send_to /build/"${FLAGS_board}"/boot/ "${remote_basedir}"/boot/ |
Daniil Lunev | fbe444a | 2020-04-24 21:47:20 +1000 | [diff] [blame] | 334 | update_syslinux_kernel "${remote_basedir}" |
Douglas Anderson | b57a9d3 | 2019-06-04 13:50:17 -0700 | [diff] [blame] | 335 | else |
| 336 | info "Skipping syslinux and /boot (per request)" |
Kees Cook | 7d7d2ef | 2011-10-18 13:12:12 -0700 | [diff] [blame] | 337 | fi |
Olof Johansson | 9a83e4e | 2012-08-17 02:45:12 -0700 | [diff] [blame] | 338 | |
Stephen Boyd | f16cd6b | 2019-03-08 09:27:10 -0800 | [diff] [blame] | 339 | copy_kernelmodules "${remote_basedir}" |
Olof Johansson | 9a83e4e | 2012-08-17 02:45:12 -0700 | [diff] [blame] | 340 | |
Nicolas Boichat | a595deb | 2017-02-07 18:53:44 +0800 | [diff] [blame] | 341 | if [[ ${FLAGS_firmware} -eq ${FLAGS_TRUE} ]]; then |
Jack Rosenthal | 9541b8c | 2019-07-26 10:45:55 -0600 | [diff] [blame] | 342 | if [[ ${FLAGS_clean} -eq ${FLAGS_TRUE} ]]; then |
| 343 | info "Cleaning /lib/firmware" |
| 344 | remote_sh rm -rf "${remote_basedir}/lib/firmware/*" |
| 345 | fi |
Stephen Boyd | 1d8ed67 | 2019-07-26 06:58:00 -0700 | [diff] [blame] | 346 | info "Copying firmware (per request)" |
Stephen Boyd | f16cd6b | 2019-03-08 09:27:10 -0800 | [diff] [blame] | 347 | remote_send_to /build/"${FLAGS_board}"/lib/firmware/ \ |
| 348 | "${remote_basedir}"/lib/firmware/ |
Nicolas Boichat | a595deb | 2017-02-07 18:53:44 +0800 | [diff] [blame] | 349 | fi |
Stephen Boyd | f16cd6b | 2019-03-08 09:27:10 -0800 | [diff] [blame] | 350 | if [[ ${REMOTE_NEEDS_ROOTFS_MOUNTED} -eq ${FLAGS_TRUE} ]]; then |
| 351 | remote_sh umount "${remote_basedir}" |
| 352 | remote_sh rmdir "${remote_basedir}" |
| 353 | fi |
Olof Johansson | 5a46bfb | 2010-12-22 12:14:21 -0800 | [diff] [blame] | 354 | fi |
| 355 | |
Doug Anderson | 5a21b44 | 2012-12-07 11:47:31 -0800 | [diff] [blame] | 356 | if [ ${FLAGS_vboot} -eq ${FLAGS_TRUE} ]; then |
| 357 | info "Copying vboot kernel image" |
| 358 | copy_kernelimage |
| 359 | else |
| 360 | info "Skipping update of vboot (per request)" |
| 361 | fi |
Olof Johansson | 8488f5a | 2011-04-20 17:27:37 -0700 | [diff] [blame] | 362 | |
Olof Johansson | 45225c9 | 2013-10-15 17:32:48 -0700 | [diff] [blame] | 363 | if [ ${FLAGS_bootonce} -eq ${FLAGS_TRUE} ]; then |
| 364 | info "Marking kernel partition ${FLAGS_partition} as boot once" |
| 365 | mark_boot_once |
| 366 | fi |
| 367 | |
Jonathan Kliegman | d6f3d07 | 2012-07-12 12:45:33 -0400 | [diff] [blame] | 368 | # An early kernel panic can prevent the normal sync on reboot. Explicitly |
| 369 | # sync for safety to avoid random file system corruption. |
| 370 | remote_sh sync |
| 371 | |
Doug Anderson | b2fe465 | 2012-12-07 17:33:56 -0800 | [diff] [blame] | 372 | if [ ${FLAGS_reboot} -eq ${FLAGS_TRUE} ]; then |
Olof Johansson | 8488f5a | 2011-04-20 17:27:37 -0700 | [diff] [blame] | 373 | remote_reboot |
| 374 | |
| 375 | remote_sh uname -r -v |
| 376 | info "old kernel: ${old_kernel}" |
| 377 | info "new kernel: ${REMOTE_OUT}" |
| 378 | else |
| 379 | info "Not rebooting (per request)" |
| 380 | fi |
Sean Paul | 29e8e62 | 2019-03-19 12:20:49 -0400 | [diff] [blame] | 381 | |
| 382 | if [ -n "${FLAGS_boot_command}" ]; then |
| 383 | info "Running boot command on remote" |
| 384 | remote_sh "${FLAGS_boot_command}" |
| 385 | fi |
Mandeep Singh Baines | a63cd2d | 2010-12-02 11:58:26 -0800 | [diff] [blame] | 386 | } |
| 387 | |
Olof Johansson | f53fa0d | 2011-01-26 13:06:46 -0800 | [diff] [blame] | 388 | main "$@" |