diff --git a/Makefile.work b/Makefile.work index cfcf803329ab..7716baf60b67 100644 --- a/Makefile.work +++ b/Makefile.work @@ -280,6 +280,7 @@ SONIC_BUILD_INSTRUCTION := make \ SONIC_ENABLE_IMAGE_SIGNATURE=$(ENABLE_IMAGE_SIGNATURE) \ ENABLE_HOST_SERVICE_ON_START=$(ENABLE_HOST_SERVICE_ON_START) \ SLAVE_DIR=$(SLAVE_DIR) \ + BUILD_MULTIASIC_KVM=$(BUILD_MULTIASIC_KVM) \ $(SONIC_OVERRIDE_BUILD_VARS) .PHONY: sonic-slave-build sonic-slave-bash init reset diff --git a/build_image.sh b/build_image.sh index 5353e85ab2f3..8ad484cdba39 100755 --- a/build_image.sh +++ b/build_image.sh @@ -25,6 +25,47 @@ fi IMAGE_VERSION="${SONIC_IMAGE_VERSION}" +generate_kvm_image() +{ + NUM_ASIC=$1 + if [ $NUM_ASIC == 4 ]; then + KVM_IMAGE=$OUTPUT_KVM_4ASIC_IMAGE + RECOVERY_ISO=$onie_recovery_kvm_4asic_image + elif [ $NUM_ASIC == 6 ]; then + KVM_IMAGE=$OUTPUT_KVM_6ASIC_IMAGE + RECOVERY_ISO=$onie_recovery_kvm_6asic_image + else + KVM_IMAGE=$OUTPUT_KVM_IMAGE + RECOVERY_ISO=$onie_recovery_image + NUM_ASIC=1 + fi + + echo "Build $NUM_ASIC-asic KVM image" + KVM_IMAGE_DISK=${KVM_IMAGE%.gz} + sudo rm -f $KVM_IMAGE_DISK $KVM_IMAGE_DISK.gz + + SONIC_USERNAME=$USERNAME PASSWD=$PASSWORD sudo -E ./scripts/build_kvm_image.sh $KVM_IMAGE_DISK $RECOVERY_ISO $OUTPUT_ONIE_IMAGE $KVM_IMAGE_DISK_SIZE + + if [ $? -ne 0 ]; then + echo "Error : build kvm image failed" + exit 1 + fi + + [ -r $KVM_IMAGE_DISK ] || { + echo "Error : $KVM_IMAGE_DISK not generated!" + exit 1 + } + + gzip $KVM_IMAGE_DISK + + [ -r $KVM_IMAGE_DISK.gz ] || { + echo "Error : gzip $KVM_IMAGE_DISK failed!" + exit 1 + } + + echo "The compressed kvm image is in $KVM_IMAGE_DISK.gz" +} + generate_onie_installer_image() { # Copy platform-specific ONIE installer config files where onie-mk-demo.sh expects them @@ -93,32 +134,16 @@ elif [ "$IMAGE_TYPE" = "raw" ]; then elif [ "$IMAGE_TYPE" = "kvm" ]; then - echo "Build KVM image" - KVM_IMAGE_DISK=${OUTPUT_KVM_IMAGE%.gz} - sudo rm -f $KVM_IMAGE_DISK $KVM_IMAGE_DISK.gz - generate_onie_installer_image - - SONIC_USERNAME=$USERNAME PASSWD=$PASSWORD sudo -E ./scripts/build_kvm_image.sh $KVM_IMAGE_DISK $onie_recovery_image $OUTPUT_ONIE_IMAGE $KVM_IMAGE_DISK_SIZE - - if [ $? -ne 0 ]; then - echo "Error : build kvm image failed" - exit 1 + # Generate single asic KVM image + generate_kvm_image + if [ "$BUILD_MULTIASIC_KVM" == "y" ]; then + # Genrate 4-asic KVM image + generate_kvm_image 4 + # Generate 6-asic KVM image + generate_kvm_image 6 fi - [ -r $KVM_IMAGE_DISK ] || { - echo "Error : $KVM_IMAGE_DISK not generated!" - exit 1 - } - - gzip $KVM_IMAGE_DISK - - [ -r $KVM_IMAGE_DISK.gz ] || { - echo "Error : gzip $KVM_IMAGE_DISK failed!" - exit 1 - } - - echo "The compressed kvm image is in $KVM_IMAGE_DISK.gz" ## Use 'aboot' as target machine category which includes Aboot as bootloader elif [ "$IMAGE_TYPE" = "aboot" ]; then diff --git a/onie-image.conf b/onie-image.conf index 5d32226371fd..73deded2027e 100644 --- a/onie-image.conf +++ b/onie-image.conf @@ -50,3 +50,9 @@ OUTPUT_ABOOT_IMAGE=target/sonic-aboot-$TARGET_MACHINE.swi ## Aboot boot image name ABOOT_BOOT_IMAGE=.sonic-boot.swi + +## Output file name for 4-asic kvm image +OUTPUT_KVM_4ASIC_IMAGE=target/sonic-4asic-$TARGET_MACHINE.img + +### Output file name for 6-asic kvm image +OUTPUT_KVM_6ASIC_IMAGE=target/sonic-6asic-$TARGET_MACHINE.img diff --git a/rules/config b/rules/config index 9c77aee1f0c0..6171894cff7d 100644 --- a/rules/config +++ b/rules/config @@ -196,3 +196,6 @@ SONIC_VERSION_CONTROL_COMPONENTS ?= none # Set the env variable ENABLE_DOCKER_BASE_PULL = y to enable pulling sonic-slave docker from registry REGISTRY_PORT ?= 443 REGISTRY_SERVER ?= sonicdev-microsoft.azurecr.io + +# BUILD_MULTIASIC_KVM - if set to y multi-asic KVM images will be generated. +BUILD_MULTIASIC_KVM = n diff --git a/slave.mk b/slave.mk index 8417d7aa47da..9e4bf532bfda 100644 --- a/slave.mk +++ b/slave.mk @@ -218,6 +218,10 @@ endif MAKEFLAGS += -j $(SONIC_BUILD_JOBS) export SONIC_CONFIG_MAKE_JOBS +ifeq ($(CONFIGURED_PLATFORM),vs) +export BUILD_MULTIASIC_KVM=$(BUILD_MULTIASIC_KVM) +endif + ############################################################################### ## Routing stack related exports ############################################################################### @@ -281,6 +285,9 @@ $(info "TELEMETRY_WRITABLE" : "$(TELEMETRY_WRITABLE)") $(info "PDDF_SUPPORT" : "$(PDDF_SUPPORT)") $(info "MULTIARCH_QEMU_ENVIRON" : "$(MULTIARCH_QEMU_ENVIRON)") $(info "SONIC_VERSION_CONTROL_COMPONENTS": "$(SONIC_VERSION_CONTROL_COMPONENTS)") +ifeq ($(CONFIGURED_PLATFORM),vs) +$(info "BUILD_MULTIASIC_KVM" : "$(BUILD_MULTIASIC_KVM)") +endif $(info ) else $(info SONiC Build System for $(CONFIGURED_PLATFORM):$(CONFIGURED_ARCH)) @@ -933,6 +940,8 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \ export initramfs_tools="$(IMAGE_DISTRO_DEBS_PATH)/$(INITRAMFS_TOOLS)" export linux_kernel="$(IMAGE_DISTRO_DEBS_PATH)/$(LINUX_KERNEL)" export onie_recovery_image="$(FILES_PATH)/$(ONIE_RECOVERY_IMAGE)" + export onie_recovery_kvm_4asic_image="$(FILES_PATH)/$(ONIE_RECOVERY_KVM_4ASIC_IMAGE)" + export onie_recovery_kvm_6asic_image="$(FILES_PATH)/$(ONIE_RECOVERY_KVM_4ASIC_IMAGE)" export kversion="$(KVERSION)" export image_type="$($*_IMAGE_TYPE)" export sonicadmin_user="$(USERNAME)"