Skip to content

Commit 5fe6d92

Browse files
authored
[warm/fast-reboot] Fix kexec portion to support platforms based on Device Tree (#1966)
The warm-reboot and fast-reboot commands currently expect a platform that uses GRUB. Information about the current kernel boot arguments is extracted from the GRUB config file. This commit adds support for platforms that do not use GRUB but rather use Device Tree to define the current kernel boot arguments. Example platform architectures using Device Tree include armhf and arm64. This commit also includes a minor improvement to a similar change made to the soft-reboot command in PR# 1963
1 parent 74d2a09 commit 5fe6d92

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

scripts/fast-reboot

+24-5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ SSD_FW_UPDATE="ssd-fw-upgrade"
2727
TAG_LATEST=yes
2828
DETACH=no
2929
LOG_PATH="/var/log/${REBOOT_TYPE}.txt"
30+
UIMAGE_HDR_SIZE=64
3031

3132
# Require 100M available on the hard drive for warm reboot temp files,
3233
# Size is in 1K blocks:
@@ -327,15 +328,33 @@ function setup_reboot_variables()
327328
KERNEL_IMAGE="$(ls $IMAGE_PATH/boot/vmlinuz-*)"
328329
BOOT_OPTIONS="$(cat "$IMAGE_PATH/kernel-cmdline" | tr '\n' ' ') SONIC_BOOT_TYPE=${BOOT_TYPE_ARG}"
329330
fi
331+
INITRD=$(echo $KERNEL_IMAGE | sed 's/vmlinuz/initrd.img/g')
330332
elif grep -q onie_platform= /host/machine.conf; then
331-
KERNEL_OPTIONS=$(cat /host/grub/grub.cfg | sed "/$NEXT_SONIC_IMAGE'/,/}/"'!'"g" | grep linux)
332-
KERNEL_IMAGE="/host$(echo $KERNEL_OPTIONS | cut -d ' ' -f 2)"
333-
BOOT_OPTIONS="$(echo $KERNEL_OPTIONS | sed -e 's/\s*linux\s*/BOOT_IMAGE=/') SONIC_BOOT_TYPE=${BOOT_TYPE_ARG}"
333+
if [ -r /host/grub/grub.cfg ]; then
334+
KERNEL_OPTIONS=$(cat /host/grub/grub.cfg | sed "/$NEXT_SONIC_IMAGE'/,/}/"'!'"g" | grep linux)
335+
KERNEL_IMAGE="/host$(echo $KERNEL_OPTIONS | cut -d ' ' -f 2)"
336+
BOOT_OPTIONS="$(echo $KERNEL_OPTIONS | sed -e 's/\s*linux\s*/BOOT_IMAGE=/') SONIC_BOOT_TYPE=${BOOT_TYPE_ARG}"
337+
INITRD=$(echo $KERNEL_IMAGE | sed 's/vmlinuz/initrd.img/g')
338+
# Handle architectures supporting Device Tree
339+
elif [ -f /sys/firmware/devicetree/base/chosen/bootargs ]; then
340+
KERNEL_IMAGE="$(ls $IMAGE_PATH/boot/vmlinuz-*)"
341+
BOOT_OPTIONS="$(cat /sys/firmware/devicetree/base/chosen/bootargs | sed 's/.$//') SONIC_BOOT_TYPE=${BOOT_TYPE_ARG}"
342+
INITRD=$(echo $KERNEL_IMAGE | sed 's/vmlinuz/initrd.img/g')
343+
344+
# If initrd is a U-Boot uImage, remove the uImage header
345+
if file ${INITRD} | grep -q uImage; then
346+
INITRD_RAW=$(echo $KERNEL_IMAGE | sed 's/vmlinuz/initrd-raw.img/g')
347+
tail -c+$((${UIMAGE_HDR_SIZE}+1)) < ${INITRD} > ${INITRD_RAW}
348+
INITRD=${INITRD_RAW}
349+
fi
350+
else
351+
error "Unknown ONIE platform bootloader. ${REBOOT_TYPE} is not supported."
352+
exit "${EXIT_NOT_SUPPORTED}"
353+
fi
334354
else
335355
error "Unknown bootloader. ${REBOOT_TYPE} is not supported."
336356
exit "${EXIT_NOT_SUPPORTED}"
337357
fi
338-
INITRD=$(echo $KERNEL_IMAGE | sed 's/vmlinuz/initrd.img/g')
339358
}
340359
341360
function check_docker_exec()
@@ -393,7 +412,7 @@ function reboot_pre_check()
393412
error "Failed to verify next image. Exit code: $INSTALLER_VERIFY_RC"
394413
exit ${EXIT_SONIC_INSTALLER_VERIFY_REBOOT}
395414
fi
396-
415+
397416
# Make sure ASIC configuration has not changed between images
398417
ASIC_CONFIG_CHECK_SCRIPT="/usr/local/bin/asic_config_check"
399418
ASIC_CONFIG_CHECK_SUCCESS=0

scripts/soft-reboot

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ REBOOT_TIME=$(date)
55
REBOOT_METHOD="/sbin/kexec -e"
66
LOG_SSD_HEALTH="/usr/local/bin/log_ssd_health"
77
WATCHDOG_UTIL="/usr/local/bin/watchdogutil"
8+
UIMAGE_HDR_SIZE=64
89

910
EXIT_SUCCESS=0
1011
EXIT_FAILURE=1
@@ -133,7 +134,7 @@ function setup_reboot_variables()
133134
# If initrd is a U-Boot uImage, remove the uImage header
134135
if file ${INITRD} | grep -q uImage; then
135136
INITRD_RAW=$(echo $KERNEL_IMAGE | sed 's/vmlinuz/initrd-raw.img/g')
136-
tail -c+65 < ${INITRD} > ${INITRD_RAW}
137+
tail -c+$((${UIMAGE_HDR_SIZE}+1)) < ${INITRD} > ${INITRD_RAW}
137138
INITRD=${INITRD_RAW}
138139
fi
139140
else

0 commit comments

Comments
 (0)