Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mellanox]: Add KVM image target #21477

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions build_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ elif [ "$IMAGE_TYPE" = "raw" ]; then
echo "The raw image is in $OUTPUT_RAW_IMAGE"

elif [ "$IMAGE_TYPE" = "kvm" ]; then
if [ "$TARGET_MACHINE" = "mellanox" ]; then
echo "Enable Mellanox KVM build"
export MLNX_KVM_IMAGE="yes"
fi

generate_device_list "./installer/platforms_asic"

Expand Down
70 changes: 57 additions & 13 deletions install_sonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,66 @@
import sys
import time

class OnieInterface:
"""ONiE Telnet Interface"""

#KEY_UP = '\x1b[A'
KEY_DOWN = '\x1b[B'
#KEY_RIGHT = '\x1b[C'
#KEY_LEFT = '\x1b[D'

ONIE_INSTALL_OS = 'ONIE: Install OS'
ONIE_CONSOLE = 'Please press Enter to activate this console'
ONIE_RESCUE = 'Rescue Mode Enabled'
ONIE_SHELL = 'ONIE:/ #'
ONIE_PROMPT = 'Do you still wish to install this image?'

GRUB_SELECTION = 'The highlighted entry will be executed'

INSTALL_CMD = [
'tmpdir=$(mktemp -d)',
'mount LABEL=INSTALLER $tmpdir',
'onie-nos-install $tmpdir/onie-installer.bin'
]

def __init__(self, telnet_session, arg_list):
self.args = arg_list
self.onie = telnet_session

def wait_grub(self):
self.onie.expect([self.GRUB_SELECTION])

def embed_onie(self):
self.wait_grub()
self.onie.sendline(self.KEY_DOWN)

def install_os(self):
self.onie.expect([self.ONIE_INSTALL_OS])
self.wait_grub()
if self.args.f: # manual installation
# enable rescue mode
self.onie.sendline(self.KEY_DOWN)
self.onie.expect([self.ONIE_CONSOLE])
self.onie.sendline()
self.onie.expect([self.ONIE_RESCUE])
self.onie.expect([self.ONIE_SHELL])
# install image
self.onie.sendline(' ; '.join(self.INSTALL_CMD))
# handle unsupported platform
self.onie.expect([self.ONIE_PROMPT])
self.onie.sendline('y')
else: # automatic discovery installation
self.onie.sendline()


def main():

parser = argparse.ArgumentParser(description='test_login cmdline parser')
parser.add_argument('-p', type=int, default=9000, help='local port')
parser.add_argument('-f', action='store_true', help='force image installation')

args = parser.parse_args()

#KEY_UP = '\x1b[A'
KEY_DOWN = '\x1b[B'
#KEY_RIGHT = '\x1b[C'
#KEY_LEFT = '\x1b[D'

grub_selection = "The highlighted entry will be executed"

i = 0
while True:
try:
Expand All @@ -32,17 +77,16 @@ def main():
raise
time.sleep(1)

onie = OnieInterface(p, args)

# select ONIE embed
p.expect(grub_selection)
p.sendline(KEY_DOWN)
onie.embed_onie()

# select ONIE install
p.expect(['ONIE: Install OS'])
p.expect([grub_selection])
p.sendline()
onie.install_os()

# wait for grub, and exit
p.expect([grub_selection])
onie.wait_grub()


if __name__ == '__main__':
Expand Down
2 changes: 2 additions & 0 deletions platform/mellanox/kvm-image.dep
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# DPKG FRK
$(SONIC_KVM_IMAGE)_CACHE_MODE := none
32 changes: 32 additions & 0 deletions platform/mellanox/kvm-image.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#
# SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES
# Copyright (c) 2017-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# sonic mellanox kvm image

SONIC_KVM_IMAGE = sonic-mellanox.img.gz
$(SONIC_KVM_IMAGE)_MACHINE = mellanox
$(SONIC_KVM_IMAGE)_IMAGE_TYPE = kvm
$(SONIC_KVM_IMAGE)_INSTALLS += $(SX_KERNEL) $(KERNEL_MFT) $(MFT_OEM) $(MFT) $(MFT_FWTRACE_CFG) $(MLNX_HW_MANAGEMENT) $(MLNX_RSHIM)
$(SONIC_KVM_IMAGE)_INSTALLS += $(SYSTEMD_SONIC_GENERATOR)
ifeq ($(INSTALL_DEBUG_TOOLS),y)
$(SONIC_KVM_IMAGE)_DOCKERS += $(SONIC_INSTALL_DOCKER_DBG_IMAGES)
$(SONIC_KVM_IMAGE)_DOCKERS += $(filter-out $(patsubst %-$(DBG_IMAGE_MARK).gz,%.gz, $(SONIC_INSTALL_DOCKER_DBG_IMAGES)), $(SONIC_INSTALL_DOCKER_IMAGES))
else
$(SONIC_KVM_IMAGE)_DOCKERS = $(SONIC_INSTALL_DOCKER_IMAGES)
endif
$(SONIC_KVM_IMAGE)_FILES = $(MLNX_FILES) $(MLNX_CPLD_ARCHIVES) $(ONIE_RECOVERY_IMAGE)
SONIC_INSTALLERS += $(SONIC_KVM_IMAGE)
2 changes: 2 additions & 0 deletions platform/mellanox/onie.dep
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# DPKG FRK
$(ONIE_RECOVERY_IMAGE)_CACHE_MODE := none
22 changes: 22 additions & 0 deletions platform/mellanox/onie.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES
# Copyright (c) 2017-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

ONIE_RECOVERY_IMAGE = onie-recovery-x86_64-kvm_x86_64-r0.iso
$(ONIE_RECOVERY_IMAGE)_URL = "https://sonicstorage.blob.core.windows.net/public/onie/$(ONIE_RECOVERY_IMAGE)"

SONIC_ONLINE_FILES += $(ONIE_RECOVERY_IMAGE)
6 changes: 5 additions & 1 deletion platform/mellanox/rules.mk
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#
# Copyright (c) 2016-2024 NVIDIA CORPORATION & AFFILIATES.
# SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES
# Copyright (c) 2016-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -26,6 +27,8 @@ include $(PLATFORM_PATH)/docker-syncd-mlnx.mk
include $(PLATFORM_PATH)/docker-syncd-mlnx-rpc.mk
include $(PLATFORM_PATH)/docker-saiserver-mlnx.mk
include $(PLATFORM_PATH)/one-image.mk
include $(PLATFORM_PATH)/onie.mk
include $(PLATFORM_PATH)/kvm-image.mk
include $(PLATFORM_PATH)/libsaithrift-dev.mk
include $(PLATFORM_PATH)/mlnx-ffb.mk
include $(PLATFORM_PATH)/issu-version.mk
Expand All @@ -39,6 +42,7 @@ include $(PLATFORM_PATH)/rshim.mk
include $(PLATFORM_PATH)/mlnx-sonic-bfb-installer.mk

SONIC_ALL += $(SONIC_ONE_IMAGE) \
$(SONIC_KVM_IMAGE) \
$(DOCKER_FPM)

# Inject mlnx sai into syncd
Expand Down
15 changes: 13 additions & 2 deletions scripts/build_kvm_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ prepare_installer_disk()
{
fallocate -l 4096M $INSTALLER_DISK

mkfs.vfat $INSTALLER_DISK
mkfs.vfat -n INSTALLER $INSTALLER_DISK

tmpdir=$(mktemp -d)

Expand Down Expand Up @@ -109,10 +109,21 @@ wait_kvm_ready

echo "to kill kvm: sudo kill $kvm_pid"

./install_sonic.py
if [ "$MLNX_KVM_IMAGE" = "yes" ]; then
echo "Mellanox KVM build: use force image installation routine"
./install_sonic.py -f
else
echo "Generic KVM build: use regular image installation routine"
./install_sonic.py
fi

kill $kvm_pid

if [ "$MLNX_KVM_IMAGE" = "yes" ]; then
echo "Skip SONiC boot for Mellanox KVM build"
exit 0
fi

echo "Booting up SONiC"

/usr/bin/kvm -m $MEM \
Expand Down
Loading