Skip to content

Commit bada798

Browse files
committed
[202411_RC.1100] [mellanox]: Add KVM image target (sonic-net#21477)
1 parent 1b74b7f commit bada798

File tree

8 files changed

+137
-16
lines changed

8 files changed

+137
-16
lines changed

build_image.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ elif [ "$IMAGE_TYPE" = "raw" ]; then
162162
echo "The raw image is in $OUTPUT_RAW_IMAGE"
163163

164164
elif [ "$IMAGE_TYPE" = "kvm" ]; then
165+
if [ "$TARGET_MACHINE" = "mellanox" ]; then
166+
echo "Enable Mellanox KVM build"
167+
export MLNX_KVM_IMAGE="yes"
168+
fi
165169

166170
generate_device_list "./installer/platforms_asic"
167171

install_sonic.py

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,66 @@
55
import sys
66
import time
77

8+
class OnieInterface:
9+
"""ONiE Telnet Interface"""
10+
11+
#KEY_UP = '\x1b[A'
12+
KEY_DOWN = '\x1b[B'
13+
#KEY_RIGHT = '\x1b[C'
14+
#KEY_LEFT = '\x1b[D'
15+
16+
ONIE_INSTALL_OS = 'ONIE: Install OS'
17+
ONIE_CONSOLE = 'Please press Enter to activate this console'
18+
ONIE_RESCUE = 'Rescue Mode Enabled'
19+
ONIE_SHELL = 'ONIE:/ #'
20+
ONIE_PROMPT = 'Do you still wish to install this image?'
21+
22+
GRUB_SELECTION = 'The highlighted entry will be executed'
23+
24+
INSTALL_CMD = [
25+
'tmpdir=$(mktemp -d)',
26+
'mount LABEL=INSTALLER $tmpdir',
27+
'onie-nos-install $tmpdir/onie-installer.bin'
28+
]
29+
30+
def __init__(self, telnet_session, arg_list):
31+
self.args = arg_list
32+
self.onie = telnet_session
33+
34+
def wait_grub(self):
35+
self.onie.expect([self.GRUB_SELECTION])
36+
37+
def embed_onie(self):
38+
self.wait_grub()
39+
self.onie.sendline(self.KEY_DOWN)
40+
41+
def install_os(self):
42+
self.onie.expect([self.ONIE_INSTALL_OS])
43+
self.wait_grub()
44+
if self.args.f: # manual installation
45+
# enable rescue mode
46+
self.onie.sendline(self.KEY_DOWN)
47+
self.onie.expect([self.ONIE_CONSOLE])
48+
self.onie.sendline()
49+
self.onie.expect([self.ONIE_RESCUE])
50+
self.onie.expect([self.ONIE_SHELL])
51+
# install image
52+
self.onie.sendline(' ; '.join(self.INSTALL_CMD))
53+
# handle unsupported platform
54+
self.onie.expect([self.ONIE_PROMPT])
55+
self.onie.sendline('y')
56+
else: # automatic discovery installation
57+
self.onie.sendline()
58+
859

960
def main():
1061

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

1466
args = parser.parse_args()
1567

16-
#KEY_UP = '\x1b[A'
17-
KEY_DOWN = '\x1b[B'
18-
#KEY_RIGHT = '\x1b[C'
19-
#KEY_LEFT = '\x1b[D'
20-
21-
grub_selection = "The highlighted entry will be executed"
22-
2368
i = 0
2469
while True:
2570
try:
@@ -32,17 +77,16 @@ def main():
3277
raise
3378
time.sleep(1)
3479

80+
onie = OnieInterface(p, args)
81+
3582
# select ONIE embed
36-
p.expect(grub_selection)
37-
p.sendline(KEY_DOWN)
83+
onie.embed_onie()
3884

3985
# select ONIE install
40-
p.expect(['ONIE: Install OS'])
41-
p.expect([grub_selection])
42-
p.sendline()
86+
onie.install_os()
4387

4488
# wait for grub, and exit
45-
p.expect([grub_selection])
89+
onie.wait_grub()
4690

4791

4892
if __name__ == '__main__':

platform/mellanox/kvm-image.dep

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# DPKG FRK
2+
$(SONIC_KVM_IMAGE)_CACHE_MODE := none

platform/mellanox/kvm-image.mk

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#
2+
# SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES
3+
# Copyright (c) 2017-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
4+
# Apache-2.0
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
# sonic mellanox kvm image
19+
20+
SONIC_KVM_IMAGE = sonic-mellanox.img.gz
21+
$(SONIC_KVM_IMAGE)_MACHINE = mellanox
22+
$(SONIC_KVM_IMAGE)_IMAGE_TYPE = kvm
23+
$(SONIC_KVM_IMAGE)_INSTALLS += $(SX_KERNEL) $(KERNEL_MFT) $(MFT_OEM) $(MFT) $(MFT_FWTRACE_CFG) $(MLNX_HW_MANAGEMENT) $(MLNX_RSHIM)
24+
$(SONIC_KVM_IMAGE)_INSTALLS += $(SYSTEMD_SONIC_GENERATOR)
25+
ifeq ($(INSTALL_DEBUG_TOOLS),y)
26+
$(SONIC_KVM_IMAGE)_DOCKERS += $(SONIC_INSTALL_DOCKER_DBG_IMAGES)
27+
$(SONIC_KVM_IMAGE)_DOCKERS += $(filter-out $(patsubst %-$(DBG_IMAGE_MARK).gz,%.gz, $(SONIC_INSTALL_DOCKER_DBG_IMAGES)), $(SONIC_INSTALL_DOCKER_IMAGES))
28+
else
29+
$(SONIC_KVM_IMAGE)_DOCKERS = $(SONIC_INSTALL_DOCKER_IMAGES)
30+
endif
31+
$(SONIC_KVM_IMAGE)_FILES = $(MLNX_FILES) $(MLNX_CPLD_ARCHIVES) $(ONIE_RECOVERY_IMAGE)
32+
SONIC_INSTALLERS += $(SONIC_KVM_IMAGE)

platform/mellanox/onie.dep

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# DPKG FRK
2+
$(ONIE_RECOVERY_IMAGE)_CACHE_MODE := none

platform/mellanox/onie.mk

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#
2+
# SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES
3+
# Copyright (c) 2017-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
4+
# Apache-2.0
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
19+
ONIE_RECOVERY_IMAGE = onie-recovery-x86_64-kvm_x86_64-r0.iso
20+
$(ONIE_RECOVERY_IMAGE)_URL = "https://sonicstorage.blob.core.windows.net/public/onie/$(ONIE_RECOVERY_IMAGE)"
21+
22+
SONIC_ONLINE_FILES += $(ONIE_RECOVERY_IMAGE)

platform/mellanox/rules.mk

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#
2-
# Copyright (c) 2016-2024 NVIDIA CORPORATION & AFFILIATES.
2+
# SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES
3+
# Copyright (c) 2016-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
34
# Apache-2.0
45
#
56
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -26,6 +27,8 @@ include $(PLATFORM_PATH)/docker-syncd-mlnx.mk
2627
include $(PLATFORM_PATH)/docker-syncd-mlnx-rpc.mk
2728
include $(PLATFORM_PATH)/docker-saiserver-mlnx.mk
2829
include $(PLATFORM_PATH)/one-image.mk
30+
include $(PLATFORM_PATH)/onie.mk
31+
include $(PLATFORM_PATH)/kvm-image.mk
2932
include $(PLATFORM_PATH)/libsaithrift-dev.mk
3033
include $(PLATFORM_PATH)/mlnx-ffb.mk
3134
include $(PLATFORM_PATH)/issu-version.mk
@@ -39,6 +42,7 @@ include $(PLATFORM_PATH)/rshim.mk
3942
include $(PLATFORM_PATH)/mlnx-sonic-bfb-installer.mk
4043

4144
SONIC_ALL += $(SONIC_ONE_IMAGE) \
45+
$(SONIC_KVM_IMAGE) \
4246
$(DOCKER_FPM)
4347

4448
# Inject mlnx sai into syncd

scripts/build_kvm_image.sh

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ prepare_installer_disk()
3838
{
3939
fallocate -l 4096M $INSTALLER_DISK
4040

41-
mkfs.vfat $INSTALLER_DISK
41+
mkfs.vfat -n INSTALLER $INSTALLER_DISK
4242

4343
tmpdir=$(mktemp -d)
4444

@@ -109,10 +109,21 @@ wait_kvm_ready
109109

110110
echo "to kill kvm: sudo kill $kvm_pid"
111111

112-
./install_sonic.py
112+
if [ "$MLNX_KVM_IMAGE" = "yes" ]; then
113+
echo "Mellanox KVM build: use force image installation routine"
114+
./install_sonic.py -f
115+
else
116+
echo "Generic KVM build: use regular image installation routine"
117+
./install_sonic.py
118+
fi
113119

114120
kill $kvm_pid
115121

122+
if [ "$MLNX_KVM_IMAGE" = "yes" ]; then
123+
echo "Skip SONiC boot for Mellanox KVM build"
124+
exit 0
125+
fi
126+
116127
echo "Booting up SONiC"
117128

118129
/usr/bin/kvm -m $MEM \

0 commit comments

Comments
 (0)