2016-03-08 13:42:20 -06:00
|
|
|
#!/bin/bash
|
|
|
|
## This script is to generate an ONIE installer image based on a file system overload
|
|
|
|
|
2019-07-29 23:07:54 -05:00
|
|
|
## Enable debug output for script
|
|
|
|
set -x -e
|
|
|
|
|
2016-03-08 13:42:20 -06:00
|
|
|
## Read ONIE image related config file
|
2019-07-26 00:06:41 -05:00
|
|
|
|
|
|
|
CONFIGURED_ARCH=$([ -f .arch ] && cat .arch || echo amd64)
|
|
|
|
|
|
|
|
if [[ $CONFIGURED_ARCH == armhf || $CONFIGURED_ARCH == arm64 ]]; then
|
|
|
|
. ./onie-image-${CONFIGURED_ARCH}.conf
|
|
|
|
else
|
|
|
|
. ./onie-image.conf
|
|
|
|
fi
|
|
|
|
|
2016-03-08 13:42:20 -06:00
|
|
|
[ -n "$ONIE_IMAGE_PART_SIZE" ] || {
|
|
|
|
echo "Error: Invalid ONIE_IMAGE_PART_SIZE in onie image config file"
|
|
|
|
exit 1
|
|
|
|
}
|
2023-12-04 16:41:52 -06:00
|
|
|
[ -n "$INSTALLER_PAYLOAD" ] || {
|
|
|
|
echo "Error: Invalid INSTALLER_PAYLOAD in onie image config file"
|
2016-03-08 13:42:20 -06:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2020-09-16 12:47:26 -05:00
|
|
|
IMAGE_VERSION="${SONIC_IMAGE_VERSION}"
|
2016-03-08 13:42:20 -06:00
|
|
|
|
2021-09-01 19:28:13 -05:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2022-12-17 16:38:31 -06:00
|
|
|
$GZ_COMPRESS_PROGRAM $KVM_IMAGE_DISK
|
2021-09-01 19:28:13 -05:00
|
|
|
|
|
|
|
[ -r $KVM_IMAGE_DISK.gz ] || {
|
2022-12-17 16:38:31 -06:00
|
|
|
echo "Error : $GZ_COMPRESS_PROGRAM $KVM_IMAGE_DISK failed!"
|
2021-09-01 19:28:13 -05:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
echo "The compressed kvm image is in $KVM_IMAGE_DISK.gz"
|
|
|
|
}
|
|
|
|
|
2017-08-27 22:13:38 -05:00
|
|
|
generate_onie_installer_image()
|
|
|
|
{
|
2022-03-08 07:15:43 -06:00
|
|
|
output_file=$OUTPUT_ONIE_IMAGE
|
|
|
|
[ -n "$1" ] && output_file=$1
|
2017-03-29 06:17:49 -05:00
|
|
|
# Copy platform-specific ONIE installer config files where onie-mk-demo.sh expects them
|
2022-10-26 04:03:29 -05:00
|
|
|
rm -rf ./installer/platforms/
|
|
|
|
mkdir -p ./installer/platforms/
|
2017-03-29 06:17:49 -05:00
|
|
|
for VENDOR in `ls ./device`; do
|
2022-06-14 10:56:27 -05:00
|
|
|
for PLATFORM in `ls ./device/$VENDOR | grep ^${TARGET_PLATFORM}`; do
|
2017-03-29 06:17:49 -05:00
|
|
|
if [ -f ./device/$VENDOR/$PLATFORM/installer.conf ]; then
|
2022-10-26 04:03:29 -05:00
|
|
|
cp ./device/$VENDOR/$PLATFORM/installer.conf ./installer/platforms/$PLATFORM
|
2017-03-29 06:17:49 -05:00
|
|
|
fi
|
2017-08-27 22:13:38 -05:00
|
|
|
|
2017-03-29 06:17:49 -05:00
|
|
|
done
|
|
|
|
done
|
|
|
|
|
2016-03-16 01:38:26 -05:00
|
|
|
## Generate an ONIE installer image
|
|
|
|
## Note: Don't leave blank between lines. It is single line command.
|
2022-07-12 17:00:57 -05:00
|
|
|
./onie-mk-demo.sh $CONFIGURED_ARCH $TARGET_MACHINE $TARGET_PLATFORM-$TARGET_MACHINE-$ONIEIMAGE_VERSION \
|
2022-03-08 07:15:43 -06:00
|
|
|
installer platform/$TARGET_MACHINE/platform.conf $output_file OS $IMAGE_VERSION $ONIE_IMAGE_PART_SIZE \
|
2023-12-04 16:41:52 -06:00
|
|
|
$INSTALLER_PAYLOAD $SECURE_UPGRADE_SIGNING_CERT $SECURE_UPGRADE_DEV_SIGNING_KEY
|
2017-08-27 22:13:38 -05:00
|
|
|
}
|
|
|
|
|
2021-10-24 21:12:17 -05:00
|
|
|
# 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
|
2022-01-20 21:54:48 -06:00
|
|
|
if [ "$TARGET_MACHINE" = "generic" ] || grep -Fxq "$TARGET_MACHINE" $d/platform_asic; then
|
2021-10-24 21:12:17 -05:00
|
|
|
echo "${d##*/}" >> "$platforms_asic";
|
|
|
|
fi;
|
|
|
|
fi;
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2017-08-27 22:13:38 -05:00
|
|
|
if [ "$IMAGE_TYPE" = "onie" ]; then
|
|
|
|
echo "Build ONIE installer"
|
|
|
|
mkdir -p `dirname $OUTPUT_ONIE_IMAGE`
|
|
|
|
sudo rm -f $OUTPUT_ONIE_IMAGE
|
|
|
|
|
2022-07-12 17:00:57 -05:00
|
|
|
generate_device_list "./installer/platforms_asic"
|
2021-10-24 21:12:17 -05:00
|
|
|
|
2017-08-27 22:13:38 -05:00
|
|
|
generate_onie_installer_image
|
|
|
|
|
|
|
|
## Build a raw partition dump image using the ONIE installer that can be
|
|
|
|
## used to dd' in-lieu of using the onie-nos-installer. Used while migrating
|
|
|
|
## into SONiC from other NOS.
|
|
|
|
elif [ "$IMAGE_TYPE" = "raw" ]; then
|
|
|
|
|
|
|
|
echo "Build RAW image"
|
2022-03-08 07:15:43 -06:00
|
|
|
tmp_output_onie_image=${OUTPUT_ONIE_IMAGE}.tmp
|
2017-08-27 22:13:38 -05:00
|
|
|
mkdir -p `dirname $OUTPUT_RAW_IMAGE`
|
|
|
|
sudo rm -f $OUTPUT_RAW_IMAGE
|
|
|
|
|
2022-07-12 17:00:57 -05:00
|
|
|
generate_device_list "./installer/platforms_asic"
|
2021-10-24 21:12:17 -05:00
|
|
|
|
2022-03-08 07:15:43 -06:00
|
|
|
generate_onie_installer_image "$tmp_output_onie_image"
|
2017-08-27 22:13:38 -05:00
|
|
|
|
|
|
|
echo "Creating SONiC raw partition : $OUTPUT_RAW_IMAGE of size $RAW_IMAGE_DISK_SIZE MB"
|
|
|
|
fallocate -l "$RAW_IMAGE_DISK_SIZE"M $OUTPUT_RAW_IMAGE
|
|
|
|
|
2020-04-15 05:57:04 -05:00
|
|
|
# ensure proc is mounted
|
|
|
|
sudo mount proc /proc -t proc || true
|
|
|
|
|
2018-02-07 08:07:01 -06:00
|
|
|
## Generate a partition dump that can be used to 'dd' in-lieu of using the onie-nos-installer
|
2020-04-15 05:57:04 -05:00
|
|
|
## Run the installer
|
2017-08-27 22:13:38 -05:00
|
|
|
## The 'build' install mode of the installer is used to generate this dump.
|
2022-03-08 07:15:43 -06:00
|
|
|
sudo chmod a+x $tmp_output_onie_image
|
2023-09-07 11:15:03 -05:00
|
|
|
sudo ./$tmp_output_onie_image || {
|
|
|
|
## Failure during 'build' install mode of the installer results in an incomplete raw image.
|
|
|
|
## Delete the incomplete raw image.
|
|
|
|
sudo rm -f $OUTPUT_RAW_IMAGE
|
|
|
|
}
|
2022-03-08 07:15:43 -06:00
|
|
|
rm $tmp_output_onie_image
|
2017-08-27 22:13:38 -05:00
|
|
|
|
|
|
|
[ -r $OUTPUT_RAW_IMAGE ] || {
|
|
|
|
echo "Error : $OUTPUT_RAW_IMAGE not generated!"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2023-09-07 11:19:17 -05:00
|
|
|
echo "The raw image is in $OUTPUT_RAW_IMAGE"
|
2017-08-27 22:13:38 -05:00
|
|
|
|
2018-11-21 00:32:40 -06:00
|
|
|
elif [ "$IMAGE_TYPE" = "kvm" ]; then
|
|
|
|
|
2022-07-12 17:00:57 -05:00
|
|
|
generate_device_list "./installer/platforms_asic"
|
2021-10-24 21:12:17 -05:00
|
|
|
|
2018-11-21 00:32:40 -06:00
|
|
|
generate_onie_installer_image
|
2021-09-01 19:28:13 -05:00
|
|
|
# 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
|
2018-11-25 13:33:00 -06:00
|
|
|
fi
|
|
|
|
|
2018-11-21 00:32:40 -06:00
|
|
|
|
2016-03-16 01:38:26 -05:00
|
|
|
## Use 'aboot' as target machine category which includes Aboot as bootloader
|
2017-01-29 13:33:33 -06:00
|
|
|
elif [ "$IMAGE_TYPE" = "aboot" ]; then
|
2017-02-05 17:59:59 -06:00
|
|
|
echo "Build Aboot installer"
|
|
|
|
mkdir -p `dirname $OUTPUT_ABOOT_IMAGE`
|
|
|
|
sudo rm -f $OUTPUT_ABOOT_IMAGE
|
|
|
|
sudo rm -f $ABOOT_BOOT_IMAGE
|
|
|
|
## Add main payload
|
2023-12-04 16:41:52 -06:00
|
|
|
cp $INSTALLER_PAYLOAD $OUTPUT_ABOOT_IMAGE
|
2017-02-05 17:59:59 -06:00
|
|
|
## Add Aboot boot0 file
|
|
|
|
j2 -f env files/Aboot/boot0.j2 ./onie-image.conf > files/Aboot/boot0
|
2017-04-21 19:23:36 -05:00
|
|
|
sed -i -e "s/%%IMAGE_VERSION%%/$IMAGE_VERSION/g" files/Aboot/boot0
|
2017-02-05 17:59:59 -06:00
|
|
|
pushd files/Aboot && zip -g $OLDPWD/$OUTPUT_ABOOT_IMAGE boot0; popd
|
|
|
|
pushd files/Aboot && zip -g $OLDPWD/$ABOOT_BOOT_IMAGE boot0; popd
|
2020-06-13 02:10:13 -05:00
|
|
|
pushd files/image_config/secureboot && zip -g $OLDPWD/$OUTPUT_ABOOT_IMAGE allowlist_paths.conf; popd
|
2017-04-05 18:14:41 -05:00
|
|
|
echo "$IMAGE_VERSION" >> .imagehash
|
2017-02-05 17:59:59 -06:00
|
|
|
zip -g $OUTPUT_ABOOT_IMAGE .imagehash
|
|
|
|
zip -g $ABOOT_BOOT_IMAGE .imagehash
|
2016-03-16 01:38:26 -05:00
|
|
|
rm .imagehash
|
2017-02-03 18:33:33 -06:00
|
|
|
echo "SWI_VERSION=42.0.0" > version
|
2022-09-22 19:52:40 -05:00
|
|
|
echo "BUILD_DATE=$(date -d "${build_date}" -u +%Y%m%dT%H%M%SZ)" >> version
|
2018-09-05 00:33:50 -05:00
|
|
|
echo "SWI_MAX_HWEPOCH=2" >> version
|
2017-02-08 16:13:44 -06:00
|
|
|
echo "SWI_VARIANT=US" >> version
|
2017-02-05 17:59:59 -06:00
|
|
|
zip -g $OUTPUT_ABOOT_IMAGE version
|
|
|
|
zip -g $ABOOT_BOOT_IMAGE version
|
2017-02-03 18:33:33 -06:00
|
|
|
rm version
|
2017-02-05 17:59:59 -06:00
|
|
|
|
2021-10-24 21:12:17 -05:00
|
|
|
generate_device_list ".platforms_asic"
|
|
|
|
zip -g $OUTPUT_ABOOT_IMAGE .platforms_asic
|
|
|
|
|
2022-06-02 02:35:17 -05:00
|
|
|
if [ "$ENABLE_FIPS" = "y" ]; then
|
2023-05-11 04:30:32 -05:00
|
|
|
echo "sonic_fips=1" >> kernel-cmdline-append
|
2022-06-02 02:35:17 -05:00
|
|
|
else
|
2023-05-11 04:30:32 -05:00
|
|
|
echo "sonic_fips=0" >> kernel-cmdline-append
|
2022-06-02 02:35:17 -05:00
|
|
|
fi
|
2023-05-11 04:30:32 -05:00
|
|
|
zip -g $OUTPUT_ABOOT_IMAGE kernel-cmdline-append
|
|
|
|
rm kernel-cmdline-append
|
2022-06-02 02:35:17 -05:00
|
|
|
|
2017-02-05 17:59:59 -06:00
|
|
|
zip -g $OUTPUT_ABOOT_IMAGE $ABOOT_BOOT_IMAGE
|
|
|
|
rm $ABOOT_BOOT_IMAGE
|
2020-06-09 02:25:17 -05:00
|
|
|
if [ "$SONIC_ENABLE_IMAGE_SIGNATURE" = "y" ]; then
|
|
|
|
TARGET_CA_CERT="$TARGET_PATH/ca.cert"
|
|
|
|
rm -f "$TARGET_CA_CERT"
|
|
|
|
[ -f "$CA_CERT" ] && cp "$CA_CERT" "$TARGET_CA_CERT"
|
|
|
|
./scripts/sign_image.sh -i "$OUTPUT_ABOOT_IMAGE" -k "$SIGNING_KEY" -c "$SIGNING_CERT" -a "$TARGET_CA_CERT"
|
|
|
|
fi
|
2023-12-04 16:41:52 -06:00
|
|
|
|
|
|
|
elif [ "$IMAGE_TYPE" = "dsc" ]; then
|
|
|
|
echo "Build DSC installer"
|
|
|
|
|
|
|
|
dsc_installer_dir=files/dsc
|
|
|
|
dsc_installer=$dsc_installer_dir/install_debian
|
|
|
|
dsc_installer_manifest=$dsc_installer_dir/MANIFEST
|
|
|
|
|
|
|
|
mkdir -p `dirname $OUTPUT_DSC_IMAGE`
|
|
|
|
sudo rm -f $OUTPUT_DSC_IMAGE
|
|
|
|
|
|
|
|
source ./onie-image.conf
|
|
|
|
|
|
|
|
j2 $dsc_installer.j2 > $dsc_installer
|
|
|
|
export installer_sha=$(sha512sum "$dsc_installer" | awk '{print $1}')
|
|
|
|
|
|
|
|
export build_date=$(date -u)
|
|
|
|
export build_user=$(id -un)
|
|
|
|
export installer_payload_sha=$(sha512sum "$INSTALLER_PAYLOAD" | awk '{print $1}')
|
|
|
|
j2 $dsc_installer_manifest.j2 > $dsc_installer_manifest
|
|
|
|
|
|
|
|
cp $INSTALLER_PAYLOAD $dsc_installer_dir
|
|
|
|
tar cf $OUTPUT_DSC_IMAGE -C files/dsc $(basename $dsc_installer_manifest) $INSTALLER_PAYLOAD $(basename $dsc_installer)
|
|
|
|
|
|
|
|
echo "Build ONIE installer"
|
|
|
|
mkdir -p `dirname $OUTPUT_ONIE_IMAGE`
|
|
|
|
sudo rm -f $OUTPUT_ONIE_IMAGE
|
|
|
|
|
|
|
|
generate_device_list "./installer/platforms_asic"
|
|
|
|
|
|
|
|
generate_onie_installer_image
|
|
|
|
|
2016-03-16 01:38:26 -05:00
|
|
|
else
|
2018-11-21 00:32:40 -06:00
|
|
|
echo "Error: Non supported image type $IMAGE_TYPE"
|
2016-03-16 01:38:26 -05:00
|
|
|
exit 1
|
|
|
|
fi
|