From 14889ce436a343860ceff64dfbe475da0b39804f Mon Sep 17 00:00:00 2001 From: dflynn-Nokia <60479697+dflynn-Nokia@users.noreply.github.com> Date: Thu, 9 Dec 2021 00:34:33 -0500 Subject: [PATCH] [soft-reboot] Add support for platforms based on Device Tree (#1963) What I did Add soft-reboot command support for the armhf and arm64 platforms How I did it Add logic to retrieve kernel boot arguments from the Device Tree rather than from the GRUB config for these platforms How to verify it Execute the soft-reboot command on an armhf or arm64 platform --- scripts/soft-reboot | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/scripts/soft-reboot b/scripts/soft-reboot index 504c58caffee..06311b04b9a9 100755 --- a/scripts/soft-reboot +++ b/scripts/soft-reboot @@ -117,15 +117,33 @@ function setup_reboot_variables() if grep -q aboot_platform= /host/machine.conf; then KERNEL_IMAGE="$(ls $IMAGE_PATH/boot/vmlinuz-*)" BOOT_OPTIONS="$(cat "$IMAGE_PATH/kernel-cmdline" | tr '\n' ' ') SONIC_BOOT_TYPE=${BOOT_TYPE_ARG}" + INITRD=$(echo $KERNEL_IMAGE | sed 's/vmlinuz/initrd.img/g') elif grep -q onie_platform= /host/machine.conf; then - KERNEL_OPTIONS=$(cat /host/grub/grub.cfg | sed "/$NEXT_SONIC_IMAGE'/,/}/"'!'"g" | grep linux) - KERNEL_IMAGE="/host$(echo $KERNEL_OPTIONS | cut -d ' ' -f 2)" - BOOT_OPTIONS="$(echo $KERNEL_OPTIONS | sed -e 's/\s*linux\s*/BOOT_IMAGE=/') SONIC_BOOT_TYPE=${BOOT_TYPE_ARG}" + if [ -r /host/grub/grub.cfg ]; then + KERNEL_OPTIONS=$(cat /host/grub/grub.cfg | sed "/$NEXT_SONIC_IMAGE'/,/}/"'!'"g" | grep linux) + KERNEL_IMAGE="/host$(echo $KERNEL_OPTIONS | cut -d ' ' -f 2)" + BOOT_OPTIONS="$(echo $KERNEL_OPTIONS | sed -e 's/\s*linux\s*/BOOT_IMAGE=/') SONIC_BOOT_TYPE=${BOOT_TYPE_ARG}" + INITRD=$(echo $KERNEL_IMAGE | sed 's/vmlinuz/initrd.img/g') + # Handle architectures supporting Device Tree + elif [ -f /sys/firmware/devicetree/base/chosen/bootargs ]; then + KERNEL_IMAGE="$(ls $IMAGE_PATH/boot/vmlinuz-*)" + BOOT_OPTIONS="$(cat /sys/firmware/devicetree/base/chosen/bootargs | sed 's/.$//') SONIC_BOOT_TYPE=${BOOT_TYPE_ARG}" + INITRD=$(echo $KERNEL_IMAGE | sed 's/vmlinuz/initrd.img/g') + + # If initrd is a U-Boot uImage, remove the uImage header + if file ${INITRD} | grep -q uImage; then + INITRD_RAW=$(echo $KERNEL_IMAGE | sed 's/vmlinuz/initrd-raw.img/g') + tail -c+65 < ${INITRD} > ${INITRD_RAW} + INITRD=${INITRD_RAW} + fi + else + error "Unknown ONIE platform bootloader. ${REBOOT_TYPE} is not supported." + exit "${EXIT_NOT_SUPPORTED}" + fi else error "Unknown bootloader. ${REBOOT_TYPE} is not supported." exit "${EXIT_NOT_SUPPORTED}" fi - INITRD=$(echo $KERNEL_IMAGE | sed 's/vmlinuz/initrd.img/g') } function load_kernel() {