diff --git a/build_image.sh b/build_image.sh index 8ad484cdba39..10c19addc23d 100755 --- a/build_image.sh +++ b/build_image.sh @@ -87,11 +87,30 @@ generate_onie_installer_image() $ONIE_INSTALLER_PAYLOAD } +# Generate asic-specific device list +generate_device_list() +{ + local platforms_asic=$1 + + # Create an empty function, and later append to it + echo -n > $platforms_asic + + for d in `find -L ./device -maxdepth 2 -mindepth 2 -type d`; do + if [ -f $d/platform_asic ]; then + if [ "$CONFIGURED_PLATFORM" = "generic" ] || grep -Fxq "$CONFIGURED_PLATFORM" $d/platform_asic; then + echo "${d##*/}" >> "$platforms_asic"; + fi; + fi; + done +} + if [ "$IMAGE_TYPE" = "onie" ]; then echo "Build ONIE installer" mkdir -p `dirname $OUTPUT_ONIE_IMAGE` sudo rm -f $OUTPUT_ONIE_IMAGE + generate_device_list "./installer/$TARGET_PLATFORM/platforms_asic" + generate_onie_installer_image ## Build a raw partition dump image using the ONIE installer that can be @@ -103,6 +122,8 @@ elif [ "$IMAGE_TYPE" = "raw" ]; then mkdir -p `dirname $OUTPUT_RAW_IMAGE` sudo rm -f $OUTPUT_RAW_IMAGE + generate_device_list "./installer/$TARGET_PLATFORM/platforms_asic" + generate_onie_installer_image echo "Creating SONiC raw partition : $OUTPUT_RAW_IMAGE of size $RAW_IMAGE_DISK_SIZE MB" @@ -134,6 +155,8 @@ elif [ "$IMAGE_TYPE" = "raw" ]; then elif [ "$IMAGE_TYPE" = "kvm" ]; then + generate_device_list "./installer/$TARGET_PLATFORM/platforms_asic" + generate_onie_installer_image # Generate single asic KVM image generate_kvm_image @@ -170,6 +193,9 @@ elif [ "$IMAGE_TYPE" = "aboot" ]; then zip -g $ABOOT_BOOT_IMAGE version rm version + generate_device_list ".platforms_asic" + zip -g $OUTPUT_ABOOT_IMAGE .platforms_asic + zip -g $OUTPUT_ABOOT_IMAGE $ABOOT_BOOT_IMAGE rm $ABOOT_BOOT_IMAGE if [ "$SONIC_ENABLE_IMAGE_SIGNATURE" = "y" ]; then diff --git a/installer/arm64/install.sh b/installer/arm64/install.sh index c1e20b62bf42..dee3ceec9038 100755 --- a/installer/arm64/install.sh +++ b/installer/arm64/install.sh @@ -64,6 +64,28 @@ VAR_LOG_SIZE=4096 [ -r platforms/$onie_platform ] && . platforms/$onie_platform +# Verify image platform is inside devices list +if [ "$install_env" = "onie" ]; then + if ! grep -Fxq "$onie_platform" platforms_asic; then + echo "The image you're trying to install is of a different ASIC type as the running platform's ASIC" + while true; do + read -r -p "Do you still wish to install this image? [y/n]: " input + case $input in + [Yy]) + echo "Force installing..." + break + ;; + [Nn]) + echo "Exited installation!" + exit 1 + ;; + *) + echo "Error: Invalid input" + ;; + esac + done + fi +fi # If running in ONIE if [ "$install_env" = "onie" ]; then diff --git a/installer/armhf/install.sh b/installer/armhf/install.sh index c85170ff256e..9ade40d5149e 100755 --- a/installer/armhf/install.sh +++ b/installer/armhf/install.sh @@ -64,6 +64,28 @@ VAR_LOG_SIZE=4096 [ -r platforms/$onie_platform ] && . platforms/$onie_platform +# Verify image platform is inside devices list +if [ "$install_env" = "onie" ]; then + if ! grep -Fxq "$onie_platform" platforms_asic; then + echo "The image you're trying to install is of a different ASIC type as the running platform's ASIC" + while true; do + read -r -p "Do you still wish to install this image? [y/n]: " input + case $input in + [Yy]) + echo "Force installing..." + break + ;; + [Nn]) + echo "Exited installation!" + exit 1 + ;; + *) + echo "Error: Invalid input" + ;; + esac + done + fi +fi # If running in ONIE if [ "$install_env" = "onie" ]; then diff --git a/installer/x86_64/install.sh b/installer/x86_64/install.sh index d40dedc9a160..4b58a24b087d 100755 --- a/installer/x86_64/install.sh +++ b/installer/x86_64/install.sh @@ -92,6 +92,29 @@ VAR_LOG_SIZE=4096 [ -r platforms/$onie_platform ] && . platforms/$onie_platform +# Verify image platform is inside devices list +if [ "$install_env" = "onie" ]; then + if ! grep -Fxq "$onie_platform" platforms_asic; then + echo "The image you're trying to install is of a different ASIC type as the running platform's ASIC" + while true; do + read -r -p "Do you still wish to install this image? [y/n]: " input + case $input in + [Yy]) + echo "Force installing..." + break + ;; + [Nn]) + echo "Exited installation!" + exit 1 + ;; + *) + echo "Error: Invalid input" + ;; + esac + done + fi +fi + # Pick up console port and speed from install enviroment if not defined yet. # Console port and speed setting in cmdline is like "console=ttyS0,9600n", # so we can use pattern 'console=ttyS[0-9]+,[0-9]+' to match it.