Skip to content

Commit 14889ce

Browse files
authored
[soft-reboot] Add support for platforms based on Device Tree (sonic-net#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
1 parent 7ceccd7 commit 14889ce

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

scripts/soft-reboot

+22-4
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,33 @@ function setup_reboot_variables()
117117
if grep -q aboot_platform= /host/machine.conf; then
118118
KERNEL_IMAGE="$(ls $IMAGE_PATH/boot/vmlinuz-*)"
119119
BOOT_OPTIONS="$(cat "$IMAGE_PATH/kernel-cmdline" | tr '\n' ' ') SONIC_BOOT_TYPE=${BOOT_TYPE_ARG}"
120+
INITRD=$(echo $KERNEL_IMAGE | sed 's/vmlinuz/initrd.img/g')
120121
elif grep -q onie_platform= /host/machine.conf; then
121-
KERNEL_OPTIONS=$(cat /host/grub/grub.cfg | sed "/$NEXT_SONIC_IMAGE'/,/}/"'!'"g" | grep linux)
122-
KERNEL_IMAGE="/host$(echo $KERNEL_OPTIONS | cut -d ' ' -f 2)"
123-
BOOT_OPTIONS="$(echo $KERNEL_OPTIONS | sed -e 's/\s*linux\s*/BOOT_IMAGE=/') SONIC_BOOT_TYPE=${BOOT_TYPE_ARG}"
122+
if [ -r /host/grub/grub.cfg ]; then
123+
KERNEL_OPTIONS=$(cat /host/grub/grub.cfg | sed "/$NEXT_SONIC_IMAGE'/,/}/"'!'"g" | grep linux)
124+
KERNEL_IMAGE="/host$(echo $KERNEL_OPTIONS | cut -d ' ' -f 2)"
125+
BOOT_OPTIONS="$(echo $KERNEL_OPTIONS | sed -e 's/\s*linux\s*/BOOT_IMAGE=/') SONIC_BOOT_TYPE=${BOOT_TYPE_ARG}"
126+
INITRD=$(echo $KERNEL_IMAGE | sed 's/vmlinuz/initrd.img/g')
127+
# Handle architectures supporting Device Tree
128+
elif [ -f /sys/firmware/devicetree/base/chosen/bootargs ]; then
129+
KERNEL_IMAGE="$(ls $IMAGE_PATH/boot/vmlinuz-*)"
130+
BOOT_OPTIONS="$(cat /sys/firmware/devicetree/base/chosen/bootargs | sed 's/.$//') SONIC_BOOT_TYPE=${BOOT_TYPE_ARG}"
131+
INITRD=$(echo $KERNEL_IMAGE | sed 's/vmlinuz/initrd.img/g')
132+
133+
# If initrd is a U-Boot uImage, remove the uImage header
134+
if file ${INITRD} | grep -q uImage; then
135+
INITRD_RAW=$(echo $KERNEL_IMAGE | sed 's/vmlinuz/initrd-raw.img/g')
136+
tail -c+65 < ${INITRD} > ${INITRD_RAW}
137+
INITRD=${INITRD_RAW}
138+
fi
139+
else
140+
error "Unknown ONIE platform bootloader. ${REBOOT_TYPE} is not supported."
141+
exit "${EXIT_NOT_SUPPORTED}"
142+
fi
124143
else
125144
error "Unknown bootloader. ${REBOOT_TYPE} is not supported."
126145
exit "${EXIT_NOT_SUPPORTED}"
127146
fi
128-
INITRD=$(echo $KERNEL_IMAGE | sed 's/vmlinuz/initrd.img/g')
129147
}
130148
131149
function load_kernel() {

0 commit comments

Comments
 (0)