blob: 03243a933cf349ea763a7891379e15b17df4ef35 [file] [log] [blame]
Mandeep Singh Bainesa63cd2d2010-12-02 11:58:26 -08001#!/bin/bash
2
Taylor Hutt60da6422011-06-02 13:54:43 -07003# Copyright (c) 2009-2011 The Chromium OS Authors. All rights reserved.
Mandeep Singh Bainesa63cd2d2010-12-02 11:58:26 -08004# 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 Harringaa13ea42012-03-15 18:31:03 -07009SCRIPT_ROOT=$(dirname $(readlink -f "$0"))
David James359d3e12012-07-10 13:09:48 -070010. "${SCRIPT_ROOT}/common.sh" || exit 1
11. "${SCRIPT_ROOT}/remote_access.sh" || exit 1
Mandeep Singh Bainesa63cd2d2010-12-02 11:58:26 -080012
Mandeep Singh Baines2f3b5fc2011-01-14 14:20:12 -080013# Script must be run inside the chroot.
Greg Spencer798d75f2011-02-01 22:04:49 -080014restart_in_chroot_if_needed "$@"
Mandeep Singh Baines2f3b5fc2011-01-14 14:20:12 -080015
Mandeep Singh Bainesa63cd2d2010-12-02 11:58:26 -080016DEFINE_string board "" "Override board reported by target"
Olof Johanssonf53fa0d2011-01-26 13:06:46 -080017DEFINE_string device "" "Override boot device reported by target"
Mandeep Singh Bainesa63cd2d2010-12-02 11:58:26 -080018DEFINE_string partition "" "Override kernel partition reported by target"
Doug Andersonfcaed8a2014-07-09 11:34:29 -070019DEFINE_string rootoff "" "Override root offset"
Stephen Boydf16cd6b2019-03-08 09:27:10 -080020DEFINE_string rootfs "" "Override rootfs partition reported by target"
Olof Johanssonf53fa0d2011-01-26 13:06:46 -080021DEFINE_string arch "" "Override architecture reported by target"
Jack Rosenthal9541b8c2019-07-26 10:45:55 -060022DEFINE_boolean clean $FLAGS_FALSE "Remove old files before sending new files"
Tomasz Jeznachbc9c5a42020-01-30 10:19:40 -080023DEFINE_boolean hv $FLAGS_TRUE "Use hypervisor kernel if available."
Nicolas Boichat78383c02020-10-21 10:04:31 +080024DEFINE_boolean ignore_verity $FLAGS_FALSE "Update kernel even if system is using verity \
25(WARNING: likely to make the system unable to boot)"
Olof Johansson8488f5a2011-04-20 17:27:37 -070026DEFINE_boolean reboot $FLAGS_TRUE "Reboot system after update"
Doug Anderson5a21b442012-12-07 11:47:31 -080027DEFINE_boolean vboot $FLAGS_TRUE "Update the vboot kernel"
Douglas Andersonb57a9d32019-06-04 13:50:17 -070028DEFINE_boolean syslinux $FLAGS_TRUE "Update the syslinux kernel (including /boot)"
Olof Johansson45225c92013-10-15 17:32:48 -070029DEFINE_boolean bootonce $FLAGS_FALSE "Mark kernel partition as boot once"
Olof Johansson4a7b2882013-10-16 11:59:58 -070030DEFINE_boolean remote_bootargs $FLAGS_FALSE "Use bootargs from running kernel on target"
Nicolas Boichata595deb2017-02-07 18:53:44 +080031DEFINE_boolean firmware $FLAGS_FALSE "Also update firmwares (/lib/firmware)"
Sean Paul29e8e622019-03-19 12:20:49 -040032DEFINE_string boot_command "" "Command to run on remote after update (after reboot if applicable)"
Mandeep Singh Bainesa63cd2d2010-12-02 11:58:26 -080033
Doug Anderson549f3b52013-09-26 14:46:18 -070034ORIG_ARGS=("$@")
35
Mandeep Singh Baines2f3b5fc2011-01-14 14:20:12 -080036# Parse command line.
37FLAGS "$@" || exit 1
38eval set -- "${FLAGS_ARGV}"
39
40# Only now can we die on error. shflags functions leak non-zero error codes,
Brian Harring7f175a52012-03-02 05:37:00 -080041# so will die prematurely if 'switch_to_strict_mode' is specified before now.
42switch_to_strict_mode
Mandeep Singh Baines2f3b5fc2011-01-14 14:20:12 -080043
Mike Frysinger6b1abb22012-05-11 13:44:06 -040044cleanup() {
Mandeep Singh Bainesa63cd2d2010-12-02 11:58:26 -080045 cleanup_remote_access
46 rm -rf "${TMP}"
47}
48
Jack Rosenthal9541b8c2019-07-26 10:45:55 -060049# If rsync errors due to no space on the device, suggest running with the clean
50# flag to make space before copying
51handle_no_space() {
52 if [[ ${FLAGS_clean} -ne ${FLAGS_TRUE} ]]; then
53 warn "There is not enough space to copy all necessary files."
54 warn "Try running again with the --clean flag."
55 fi
56 die_notrace "No space left on device."
57}
58
Mike Frysinger6b1abb22012-05-11 13:44:06 -040059learn_device() {
Olof Johanssonf53fa0d2011-01-26 13:06:46 -080060 [ -n "${FLAGS_device}" ] && return
61 remote_sh df /mnt/stateful_partition
62 FLAGS_device=$(echo "${REMOTE_OUT}" | awk '/dev/ {print $1}' | sed s/1\$//)
63 info "Target reports root device is ${FLAGS_device}"
64}
65
Ben Zhang15fa4b12017-06-19 20:02:57 -070066# Delete the fixed numbers after R65 when we don't care about <R57 upgrades.
67load_default_partition_numbers() {
68 PARTITION_NUM_KERN_A=2
69 PARTITION_NUM_ROOT_A=3
70 PARTITION_NUM_KERN_B=4
71 PARTITION_NUM_EFI_SYSTEM=12
72}
73
Mandeep Singh Bainesa63cd2d2010-12-02 11:58:26 -080074# Ask the target what the kernel partition is
Mike Frysinger6b1abb22012-05-11 13:44:06 -040075learn_partition_and_ro() {
Mandeep Singh Bainese39579a2011-03-04 15:58:57 -080076 ! remote_sh rootdev
Paul Taysoma64d9db2012-09-21 13:30:43 -070077 if [ "${REMOTE_OUT%%-*}" == "/dev/dm" ]; then
78 remote_sh rootdev -s
Olof Johansson8488f5a2011-04-20 17:27:37 -070079 REMOTE_VERITY=${FLAGS_TRUE}
Nicolas Boichatabdf6642016-07-04 11:30:44 +080080 if [[ ${FLAGS_ignore_verity} -eq ${FLAGS_TRUE} ]]; then
81 warn "System is using verity: not updating firmware/modules"
82 else
83 warn "System is using verity: First remove rootfs verification using"
84 warn "/usr/share/vboot/bin/make_dev_ssd.sh --remove_rootfs_verification"
Nicolas Boichat78383c02020-10-21 10:04:31 +080085 warn "on the DUT."
Brian Norrised751572018-03-30 13:48:43 -070086 die_notrace
Nicolas Boichatabdf6642016-07-04 11:30:44 +080087 fi
Olof Johansson8488f5a2011-04-20 17:27:37 -070088 else
89 REMOTE_VERITY=${FLAGS_FALSE}
90 info "System is not using verity: updating firmware and modules"
Mandeep Singh Bainese39579a2011-03-04 15:58:57 -080091 fi
Stephen Boydf16cd6b2019-03-08 09:27:10 -080092 if [[ -z "${FLAGS_rootfs}" ]]; then
93 FLAGS_rootfs="${REMOTE_OUT}"
94 fi
95 # If rootfs is for different partition than we're currently running on
96 # mount it manually to update the right modules, firmware, etc.
97 REMOTE_NEEDS_ROOTFS_MOUNTED=${FLAGS_FALSE}
98 if [[ "${REMOTE_OUT}" != "${FLAGS_rootfs}" ]]; then
99 REMOTE_NEEDS_ROOTFS_MOUNTED=${FLAGS_TRUE}
100 fi
Olof Johansson4996bfb2013-11-13 12:58:52 -0800101 [ -n "${FLAGS_partition}" ] && return
Steven 'Steve' Kendall019f38f2016-06-09 12:43:28 -0400102 if [ "${REMOTE_OUT}" == "${FLAGS_device}${PARTITION_NUM_ROOT_A}" ]; then
103 FLAGS_partition="${FLAGS_device}${PARTITION_NUM_KERN_A}"
Mandeep Singh Bainesa63cd2d2010-12-02 11:58:26 -0800104 else
Steven 'Steve' Kendall019f38f2016-06-09 12:43:28 -0400105 FLAGS_partition="${FLAGS_device}${PARTITION_NUM_KERN_B}"
Mandeep Singh Bainesa63cd2d2010-12-02 11:58:26 -0800106 fi
107 if [ -z "${FLAGS_partition}" ]; then
Brian Norrised751572018-03-30 13:48:43 -0700108 die_notrace "Partition required"
Mandeep Singh Bainesa63cd2d2010-12-02 11:58:26 -0800109 fi
Doug Anderson5a21b442012-12-07 11:47:31 -0800110 if [ ${REMOTE_VERITY} -eq ${FLAGS_TRUE} ]; then
111 info "Target reports kernel partition is ${FLAGS_partition}"
112 if [ ${FLAGS_vboot} -eq ${FLAGS_FALSE} ]; then
Brian Norrised751572018-03-30 13:48:43 -0700113 die_notrace "Must update vboot when target is using verity"
Doug Anderson5a21b442012-12-07 11:47:31 -0800114 fi
115 fi
Mandeep Singh Bainesa63cd2d2010-12-02 11:58:26 -0800116}
117
Olof Johansson4a7b2882013-10-16 11:59:58 -0700118get_bootargs() {
Mike Frysingerd4b6f952017-04-10 16:42:17 -0400119 local local_config="${SRC_ROOT}/build/images/${FLAGS_board}/latest/config.txt"
120
121 # Autodetect by default. https://crbug.com/316239
122 # This isn't quite right if people use --noremote_bootargs, but that's not
123 # a scenario people do today, so we won't worry about it.
124 if [[ ${FLAGS_remote_bootargs} -eq ${FLAGS_FALSE} && \
125 ! -e "${local_config}" ]]; then
126 warn "Local kernel config does not exist: ${local_config}"
127 FLAGS_remote_bootargs=${FLAGS_TRUE}
128 fi
129
Olof Johansson4a7b2882013-10-16 11:59:58 -0700130 if [ ${FLAGS_remote_bootargs} -eq ${FLAGS_TRUE} ] ; then
131 info "Using remote bootargs"
Stephen Boydf4e70f92019-11-18 09:38:20 -0800132 remote_sh dump_kernel_config "${FLAGS_partition}"
133 printf '%s' "${REMOTE_OUT}"
Olof Johansson4a7b2882013-10-16 11:59:58 -0700134 else
Doug Andersonfcaed8a2014-07-09 11:34:29 -0700135 if [ -n "${FLAGS_rootoff}" ]; then
Mike Frysingerd4b6f952017-04-10 16:42:17 -0400136 sed "s/PARTNROFF=1/PARTNROFF=${FLAGS_rootoff}/" "${local_config}"
Doug Andersonfcaed8a2014-07-09 11:34:29 -0700137 else
Mike Frysingerd4b6f952017-04-10 16:42:17 -0400138 cat "${local_config}"
Doug Andersonfcaed8a2014-07-09 11:34:29 -0700139 fi
Olof Johansson4a7b2882013-10-16 11:59:58 -0700140 fi
141}
142
Stephen Boyd6241f702019-07-26 07:05:25 -0700143learn_arch() {
144 [ -n "${FLAGS_arch}" ] && return
145 FLAGS_arch=$(sed -n -E 's/^CONFIG_(ARM|ARM64|X86)=y/\1/p' \
146 /build/"${FLAGS_board}"/boot/config-* | \
147 uniq | awk '{print tolower($0)}')
148 if [ -z "${FLAGS_arch}" ]; then
149 error "Arch required"
150 exit 1
151 fi
152 info "Target reports arch is ${FLAGS_arch}"
153}
154
Mike Frysinger6b1abb22012-05-11 13:44:06 -0400155make_kernelimage() {
Tom Wai-Hong Tam6b50a072011-05-25 17:00:15 +0800156 local bootloader_path
157 local kernel_image
Tomasz Jeznachfc3b7142020-09-01 13:18:30 -0700158 local boot_path="/build/${FLAGS_board}"
Olof Johansson4a7b2882013-10-16 11:59:58 -0700159 local config_path="$(mktemp /tmp/config.txt.XXXXX)"
Tomasz Jeznachfc3b7142020-09-01 13:18:30 -0700160 if [[ ${FLAGS_hv} -eq ${FLAGS_TRUE} && \
161 -d "${boot_path}/build/manatee/boot" ]]; then
162 boot_path+="/build/manatee/boot"
163 else
164 boot_path+="/boot"
Micah Morton878861f2020-09-09 13:21:42 -0700165 fi
Stephen Boyd6241f702019-07-26 07:05:25 -0700166 if [[ "${FLAGS_arch}" == "arm" || "${FLAGS_arch}" == "arm64" ]]; then
Taylor Hutt60da6422011-06-02 13:54:43 -0700167 name="bootloader.bin"
168 bootloader_path="${SRC_ROOT}/build/images/${FLAGS_board}/latest/${name}"
Mike Frysinger085c5d92017-08-16 17:29:12 -0400169 # If there is no local bootloader stub, create a dummy file. This matches
170 # build_kernel_image.sh. If we wanted to be super paranoid, we could copy
171 # and extract it from the remote image, if it had one.
172 if [[ ! -e "${bootloader_path}" ]]; then
Stephen Boyd5324e262020-01-29 08:51:35 -0800173 warn "Bootloader does not exist; creating a stub"
174 bootloader_path="${TMP}/${name}"
Mike Frysinger085c5d92017-08-16 17:29:12 -0400175 truncate -s 512 "${bootloader_path}"
176 fi
Tomasz Jeznachbc9c5a42020-01-30 10:19:40 -0800177 kernel_image="${boot_path}/vmlinux.uimg"
Olof Johanssonf53fa0d2011-01-26 13:06:46 -0800178 else
Tom Wai-Hong Tam6b50a072011-05-25 17:00:15 +0800179 bootloader_path="/lib64/bootstub/bootstub.efi"
Tomasz Jeznachbc9c5a42020-01-30 10:19:40 -0800180 kernel_image="${boot_path}/vmlinuz"
Tom Wai-Hong Tam6b50a072011-05-25 17:00:15 +0800181 fi
Olof Johansson4a7b2882013-10-16 11:59:58 -0700182 get_bootargs > "${config_path}"
Kees Cook43a32132011-10-18 13:17:11 -0700183 vbutil_kernel --pack $TMP/new_kern.bin \
Olof Johanssonf53fa0d2011-01-26 13:06:46 -0800184 --keyblock /usr/share/vboot/devkeys/kernel.keyblock \
185 --signprivate /usr/share/vboot/devkeys/kernel_data_key.vbprivk \
186 --version 1 \
Olof Johansson4a7b2882013-10-16 11:59:58 -0700187 --config ${config_path} \
Tom Wai-Hong Tam6b50a072011-05-25 17:00:15 +0800188 --bootloader "${bootloader_path}" \
189 --vmlinuz "${kernel_image}" \
190 --arch "${FLAGS_arch}"
Olof Johansson4a7b2882013-10-16 11:59:58 -0700191 rm "${config_path}"
Olof Johanssonf53fa0d2011-01-26 13:06:46 -0800192}
193
Edward Hyunkoo Jeea979a902017-03-08 13:44:26 -0800194copy_kernelmodules() {
Stephen Boydf16cd6b2019-03-08 09:27:10 -0800195 local basedir="$1" # rootfs directory (could be in /tmp) or empty string
Edward Hyunkoo Jeea979a902017-03-08 13:44:26 -0800196 local modules_dir=/build/"${FLAGS_board}"/lib/modules/
197 if [ ! -d "${modules_dir}" ]; then
Jack Rosenthal9541b8c2019-07-26 10:45:55 -0600198 info "No modules. Skipping."
Edward Hyunkoo Jeea979a902017-03-08 13:44:26 -0800199 return
200 fi
Jack Rosenthal9541b8c2019-07-26 10:45:55 -0600201 if [[ ${FLAGS_clean} -eq ${FLAGS_TRUE} ]]; then
202 info "Cleaning /lib/modules"
203 remote_sh rm -rf "${basedir}/lib/modules/*"
204 fi
205 info "Copying modules"
Stephen Boydf16cd6b2019-03-08 09:27:10 -0800206 remote_send_to "${modules_dir}" "${basedir}"/lib/modules
Edward Hyunkoo Jeea979a902017-03-08 13:44:26 -0800207}
208
Mike Frysinger6b1abb22012-05-11 13:44:06 -0400209copy_kernelimage() {
Doug Andersonadf8a002012-12-17 11:40:34 -0800210 remote_sh dd of="${FLAGS_partition}" bs=4K < "${TMP}/new_kern.bin"
Olof Johansson8488f5a2011-04-20 17:27:37 -0700211}
212
Jonathan Kliegman775bc8e2012-08-14 12:30:49 -0400213check_kernelbuildtime() {
214 local version=$(readlink "/build/${FLAGS_board}/boot/vmlinuz" | cut -d- -f2-)
215 local build_dir="/build/${FLAGS_board}/lib/modules/${version}/build"
216 if [ "${build_dir}/Makefile" -nt "/build/${FLAGS_board}/boot/vmlinuz" ]; then
217 warn "Your build directory has been built more recently than"
218 warn "the installed kernel being updated to. Did you forget to"
219 warn "run 'cros_workon_make chromeos-kernel --install'?"
220 fi
221}
222
Olof Johansson45225c92013-10-15 17:32:48 -0700223mark_boot_once() {
224 local idx=${FLAGS_partition##*[^0-9]}
Chirantan Ekbotef25b4402014-05-06 12:42:18 -0700225 remote_sh cgpt add -i ${idx} -S 0 -T 1 -P 15 ${FLAGS_device%p}
Olof Johansson45225c92013-10-15 17:32:48 -0700226}
227
Olof Johansson68cbfaf2013-04-23 14:06:28 -0700228update_syslinux_kernel() {
Daniil Lunevfbe444a2020-04-24 21:47:20 +1000229 local basedir="$1" # rootfs directory (could be in /tmp) or empty string
Olof Johansson68cbfaf2013-04-23 14:06:28 -0700230 # ARM does not have the syslinux directory, so skip it when the
Evan Greenfd9652b2018-10-01 13:36:02 -0700231 # partition is missing, the file system fails to mount, or the syslinux
232 # vmlinuz target is missing.
Steven 'Steve' Kendall019f38f2016-06-09 12:43:28 -0400233 remote_sh grep $(echo ${FLAGS_device}${PARTITION_NUM_EFI_SYSTEM} | cut -d/ -f3) /proc/partitions
Olof Johansson68cbfaf2013-04-23 14:06:28 -0700234 if [ $(echo "$REMOTE_OUT" | wc -l) -eq 1 ]; then
Steven 'Steve' Kendall019f38f2016-06-09 12:43:28 -0400235 remote_sh mkdir -p /tmp/${PARTITION_NUM_EFI_SYSTEM}
Evan Greenfd9652b2018-10-01 13:36:02 -0700236 if remote_sh mount ${FLAGS_device}${PARTITION_NUM_EFI_SYSTEM} \
237 /tmp/${PARTITION_NUM_EFI_SYSTEM}; then
Olof Johansson68cbfaf2013-04-23 14:06:28 -0700238
Evan Greenfd9652b2018-10-01 13:36:02 -0700239 if [ "$FLAGS_partition" = "${FLAGS_device}${PARTITION_NUM_KERN_A}" ]; then
240 target="/tmp/${PARTITION_NUM_EFI_SYSTEM}/syslinux/vmlinuz.A"
241 else
242 target="/tmp/${PARTITION_NUM_EFI_SYSTEM}/syslinux/vmlinuz.B"
243 fi
Daniil Lunevfbe444a2020-04-24 21:47:20 +1000244 remote_sh "test ! -f ${target} || \
245 cp ${basedir}/boot/vmlinuz ${target}"
Evan Greenfd9652b2018-10-01 13:36:02 -0700246
247 remote_sh umount /tmp/${PARTITION_NUM_EFI_SYSTEM}
Olof Johansson68cbfaf2013-04-23 14:06:28 -0700248 fi
Steven 'Steve' Kendall019f38f2016-06-09 12:43:28 -0400249 remote_sh rmdir /tmp/${PARTITION_NUM_EFI_SYSTEM}
Olof Johansson68cbfaf2013-04-23 14:06:28 -0700250 fi
251}
252
Doug Anderson549f3b52013-09-26 14:46:18 -0700253multi_main() {
254 local host
255
256 IFS=","
257 for host in ${FLAGS_remote}; do
258 "$0" "${ORIG_ARGS[@]}" --remote="${host}" \
259 |& sed "s/^/${V_BOLD_YELLOW}${host}: ${V_VIDOFF}/" &
260 done
261 wait
262}
263
Mike Frysinger6b1abb22012-05-11 13:44:06 -0400264main() {
Doug Anderson549f3b52013-09-26 14:46:18 -0700265 # If there are commas in the --remote, run the script in parallel.
266 if [[ ${FLAGS_remote} == *,* ]]; then
267 multi_main
268 return $?
269 fi
270
Mandeep Singh Bainesa63cd2d2010-12-02 11:58:26 -0800271 trap cleanup EXIT
272
Kees Cook43a32132011-10-18 13:17:11 -0700273 TMP=$(mktemp -d /tmp/update_kernel.XXXXXX)
Mandeep Singh Bainesa63cd2d2010-12-02 11:58:26 -0800274
275 remote_access_init
276
Brian Norris4ce176f2019-08-22 17:48:18 -0700277 learn_board
278
Stephen Boyd6241f702019-07-26 07:05:25 -0700279 learn_arch
280
Olof Johanssonf53fa0d2011-01-26 13:06:46 -0800281 learn_device
282
Ian Coolidgec3d5d912017-03-07 14:21:28 -0800283 learn_partition_layout
Ben Zhang15fa4b12017-06-19 20:02:57 -0700284 if [[ -z "${PARTITION_NUM_KERN_A}" ]]; then
285 info "Target has no partition number info, use default instead"
286 load_default_partition_numbers
287 fi
Ian Coolidgec3d5d912017-03-07 14:21:28 -0800288
Olof Johansson8488f5a2011-04-20 17:27:37 -0700289 learn_partition_and_ro
Olof Johanssonf53fa0d2011-01-26 13:06:46 -0800290
Brian Norris9774b0d2017-06-15 13:44:26 -0700291 if ! remote_sh "test -e '${FLAGS_partition}'"; then
292 die_notrace "Could not find kernel partition on DUT; path='${FLAGS_partition}'"
293 fi
294
Mandeep Singh Bainesa63cd2d2010-12-02 11:58:26 -0800295 remote_sh uname -r -v
296
297 old_kernel="${REMOTE_OUT}"
298
Jonathan Kliegman775bc8e2012-08-14 12:30:49 -0400299 check_kernelbuildtime
300
Doug Anderson5a21b442012-12-07 11:47:31 -0800301 if [ ${FLAGS_vboot} -eq ${FLAGS_TRUE} ]; then
302 make_kernelimage
303 fi
Mandeep Singh Bainesa63cd2d2010-12-02 11:58:26 -0800304
Olof Johansson8488f5a2011-04-20 17:27:37 -0700305 if [[ ${REMOTE_VERITY} -eq ${FLAGS_FALSE} ]]; then
Stephen Boydf16cd6b2019-03-08 09:27:10 -0800306 local remote_basedir
307 if [[ ${REMOTE_NEEDS_ROOTFS_MOUNTED} -eq ${FLAGS_TRUE} ]]; then
Stephen Boyd0758d1a2020-01-14 19:30:57 -0800308 remote_sh mktemp -d /tmp/rootfs_mounted.XXXXXX
Stephen Boydf16cd6b2019-03-08 09:27:10 -0800309 remote_basedir="${REMOTE_OUT}"
310 remote_sh mount "${FLAGS_rootfs}" "${remote_basedir}"
311 else
312 remote_sh mount -o remount,rw /
313 fi
Kees Cook7d7d2ef2011-10-18 13:12:12 -0700314
Douglas Andersonb57a9d32019-06-04 13:50:17 -0700315 if [[ ${FLAGS_syslinux} -eq ${FLAGS_TRUE} ]]; then
Jack Rosenthal9541b8c2019-07-26 10:45:55 -0600316 if [[ ${FLAGS_clean} -eq ${FLAGS_TRUE} ]]; then
317 info "Cleaning /boot"
318 remote_sh rm -rf "${remote_basedir}"/boot/{System,config,vmlinuz}'*'
319 fi
Douglas Andersonb57a9d32019-06-04 13:50:17 -0700320 info "Copying syslinux and /boot"
321 remote_send_to /build/"${FLAGS_board}"/boot/ "${remote_basedir}"/boot/
Daniil Lunevfbe444a2020-04-24 21:47:20 +1000322 update_syslinux_kernel "${remote_basedir}"
Douglas Andersonb57a9d32019-06-04 13:50:17 -0700323 else
324 info "Skipping syslinux and /boot (per request)"
Kees Cook7d7d2ef2011-10-18 13:12:12 -0700325 fi
Olof Johansson9a83e4e2012-08-17 02:45:12 -0700326
Stephen Boydf16cd6b2019-03-08 09:27:10 -0800327 copy_kernelmodules "${remote_basedir}"
Olof Johansson9a83e4e2012-08-17 02:45:12 -0700328
Nicolas Boichata595deb2017-02-07 18:53:44 +0800329 if [[ ${FLAGS_firmware} -eq ${FLAGS_TRUE} ]]; then
Jack Rosenthal9541b8c2019-07-26 10:45:55 -0600330 if [[ ${FLAGS_clean} -eq ${FLAGS_TRUE} ]]; then
331 info "Cleaning /lib/firmware"
332 remote_sh rm -rf "${remote_basedir}/lib/firmware/*"
333 fi
Stephen Boyd1d8ed672019-07-26 06:58:00 -0700334 info "Copying firmware (per request)"
Stephen Boydf16cd6b2019-03-08 09:27:10 -0800335 remote_send_to /build/"${FLAGS_board}"/lib/firmware/ \
336 "${remote_basedir}"/lib/firmware/
Nicolas Boichata595deb2017-02-07 18:53:44 +0800337 fi
Stephen Boydf16cd6b2019-03-08 09:27:10 -0800338 if [[ ${REMOTE_NEEDS_ROOTFS_MOUNTED} -eq ${FLAGS_TRUE} ]]; then
339 remote_sh umount "${remote_basedir}"
340 remote_sh rmdir "${remote_basedir}"
341 fi
Olof Johansson5a46bfb2010-12-22 12:14:21 -0800342 fi
343
Doug Anderson5a21b442012-12-07 11:47:31 -0800344 if [ ${FLAGS_vboot} -eq ${FLAGS_TRUE} ]; then
345 info "Copying vboot kernel image"
346 copy_kernelimage
347 else
348 info "Skipping update of vboot (per request)"
349 fi
Olof Johansson8488f5a2011-04-20 17:27:37 -0700350
Olof Johansson45225c92013-10-15 17:32:48 -0700351 if [ ${FLAGS_bootonce} -eq ${FLAGS_TRUE} ]; then
352 info "Marking kernel partition ${FLAGS_partition} as boot once"
353 mark_boot_once
354 fi
355
Jonathan Kliegmand6f3d072012-07-12 12:45:33 -0400356 # An early kernel panic can prevent the normal sync on reboot. Explicitly
357 # sync for safety to avoid random file system corruption.
358 remote_sh sync
359
Doug Andersonb2fe4652012-12-07 17:33:56 -0800360 if [ ${FLAGS_reboot} -eq ${FLAGS_TRUE} ]; then
Olof Johansson8488f5a2011-04-20 17:27:37 -0700361 remote_reboot
362
363 remote_sh uname -r -v
364 info "old kernel: ${old_kernel}"
365 info "new kernel: ${REMOTE_OUT}"
366 else
367 info "Not rebooting (per request)"
368 fi
Sean Paul29e8e622019-03-19 12:20:49 -0400369
370 if [ -n "${FLAGS_boot_command}" ]; then
371 info "Running boot command on remote"
372 remote_sh "${FLAGS_boot_command}"
373 fi
Mandeep Singh Bainesa63cd2d2010-12-02 11:58:26 -0800374}
375
Olof Johanssonf53fa0d2011-01-26 13:06:46 -0800376main "$@"