From b9b7d7a29590c9db1c3dd04cc5e55a6edc99fd0e Mon Sep 17 00:00:00 2001 From: lguohan Date: Mon, 27 Feb 2017 13:08:41 -0800 Subject: [PATCH] [installer]: support platform driver lazy installation (#340) allow one image to support multiple switch devices, install corresponding platform driver during the first boot time. --- build_debian.sh | 11 +++-- .../build_templates/sonic_debian_extension.j2 | 40 +++++++++++++++++-- files/image_config/platform/rc.local | 25 ++++++++++++ platform/broadcom/one-image.mk | 5 ++- platform/broadcom/platform-modules-dell.mk | 1 + .../platform-modules-ingrasys-s9100.mk | 1 + platform/broadcom/platform-modules-s6000.mk | 1 + slave.mk | 3 +- 8 files changed, 77 insertions(+), 10 deletions(-) create mode 100755 files/image_config/platform/rc.local diff --git a/build_debian.sh b/build_debian.sh index 2d6cc35533..16f31f980a 100755 --- a/build_debian.sh +++ b/build_debian.sh @@ -37,6 +37,7 @@ DOCKER_VERSION=1.11.1-0~jessie_amd64 ## Working directory to prepare the file system FILESYSTEM_ROOT=./fsroot +PLATFORM_DIR=platform ## Hostname for the linux image HOSTNAME=sonic DEFAULT_USERINFO="Default admin user,,," @@ -61,6 +62,8 @@ if [[ -d $FILESYSTEM_ROOT ]]; then sudo rm -rf $FILESYSTEM_ROOT || die "Failed to clean chroot directory" fi mkdir -p $FILESYSTEM_ROOT +mkdir -p $FILESYSTEM_ROOT/$PLATFORM_DIR +touch $FILESYSTEM_ROOT/$PLATFORM_DIR/firsttime ## Build a basic Debian system by debootstrap echo '[INFO] Debootstrap...' @@ -247,7 +250,7 @@ sudo cp files/dhcp/snmpcommunity $FILESYSTEM_ROOT/etc/dhcp/dhclient-exit-hooks.d sudo cp files/dhcp/dhclient.conf $FILESYSTEM_ROOT/etc/dhcp/ if [ -f sonic_debian_extension.sh ]; then - ./sonic_debian_extension.sh $FILESYSTEM_ROOT + ./sonic_debian_extension.sh $FILESYSTEM_ROOT $PLATFORM_DIR fi ## Clean up apt @@ -268,11 +271,11 @@ sudo mkdir $FILESYSTEM_ROOT/host sudo rm -f $ONIE_INSTALLER_PAYLOAD $FILESYSTEM_SQUASHFS ## Output the file system total size for diag purpose sudo du -hs $FILESYSTEM_ROOT -sudo mksquashfs $FILESYSTEM_ROOT $FILESYSTEM_SQUASHFS -e boot -e var/lib/docker +sudo mksquashfs $FILESYSTEM_ROOT $FILESYSTEM_SQUASHFS -e boot -e var/lib/docker -e $PLATFORM_DIR ## Compress docker files pushd $FILESYSTEM_ROOT && sudo tar czf $OLDPWD/$FILESYSTEM_DOCKERFS -C var/lib/docker .; popd -## Compress together with /boot and /var/lib/docker as an installer payload zip file -pushd $FILESYSTEM_ROOT && sudo zip $OLDPWD/$ONIE_INSTALLER_PAYLOAD -r boot/; popd +## Compress together with /boot, /var/lib/docker and $PLATFORM_DIR as an installer payload zip file +pushd $FILESYSTEM_ROOT && sudo zip $OLDPWD/$ONIE_INSTALLER_PAYLOAD -r boot/ $PLATFORM_DIR/; popd sudo zip -g $ONIE_INSTALLER_PAYLOAD $FILESYSTEM_SQUASHFS $FILESYSTEM_DOCKERFS diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index c02263d3e3..08aaae769f 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -4,7 +4,7 @@ ## to debian file system. ## ## USAGE: -## ./sonic_debian_extension.sh FILESYSTEM_ROOT +## ./sonic_debian_extension.sh FILESYSTEM_ROOT PLATFORM_DIR ## PARAMETERS: ## FILESYSTEM_ROOT ## Path to debian file system root directory @@ -15,6 +15,12 @@ FILESYSTEM_ROOT=$1 exit 1 } +PLATFORM_DIR=$2 +[ -n "$PLATFORM_DIR" ] || { + echo "Error: no or empty PLATFORM_DIR argument" + exit 1 +} + ## Enable debug output for script set -x -e @@ -22,7 +28,6 @@ set -x -e BUILD_TEMPLATES=files/build_templates IMAGE_CONFIGS=files/image_config -{% if installer_debs.strip() -%} clean_sys() { sudo umount $FILESYSTEM_ROOT/sys/fs/cgroup/* \ $FILESYSTEM_ROOT/sys/fs/cgroup \ @@ -130,6 +135,7 @@ exit 101 EOF sudo chmod a+x $FILESYSTEM_ROOT/usr/sbin/policy-rc.d +{% if installer_debs.strip() -%} {% for deb in installer_debs.strip().split(' ') -%} if [ $sonic_asic_platform == "mellanox" ]; then sudo dpkg --extract {{deb}} $FILESYSTEM_ROOT @@ -137,12 +143,38 @@ else sudo dpkg --root=$FILESYSTEM_ROOT -i {{deb}} || sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y install -f fi {% endfor %} - -sudo rm -f $FILESYSTEM_ROOT/usr/sbin/policy-rc.d +{% endif %} ## Run depmod command for target kernel modules sudo LANG=C chroot $FILESYSTEM_ROOT depmod -a {{kversion}} + +## download all dependency packages for platform debian packages +{% if lazy_installer_debs.strip() -%} +{% for file in lazy_installer_debs.strip().split(' ') -%} + +{% set dev = file.split('@')[0] -%} +{% set deb = file.split('@')[1] -%} +{% set debfilename = deb.split('/')|last -%} +{% set debname = debfilename.split('_')|first -%} + +sudo dpkg --root=$FILESYSTEM_ROOT -i {{deb}} || sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y install -f --download-only + +sudo mkdir -p $FILESYSTEM_ROOT/$PLATFORM_DIR/{{dev}} +sudo cp {{ deb }} $FILESYSTEM_ROOT/$PLATFORM_DIR/{{dev}}/ +for f in `find $FILESYSTEM_ROOT/var/cache/apt/archives -name "*.deb"`; do + sudo mv $f $FILESYSTEM_ROOT/$PLATFORM_DIR/{{dev}}/ +done + +sudo dpkg --root=$FILESYSTEM_ROOT -P {{ debname }} + +{% endfor %} {% endif %} + +sudo rm -f $FILESYSTEM_ROOT/usr/sbin/policy-rc.d + +## copy platform rc.local +sudo cp $IMAGE_CONFIGS/platform/rc.local $FILESYSTEM_ROOT/etc/ + {% if installer_images.strip() -%} {% for image in installer_images.strip().split(' ') -%} sudo LANG=C chroot $FILESYSTEM_ROOT docker load < {{image}} diff --git a/files/image_config/platform/rc.local b/files/image_config/platform/rc.local new file mode 100755 index 0000000000..dc5507fe23 --- /dev/null +++ b/files/image_config/platform/rc.local @@ -0,0 +1,25 @@ +#!/bin/sh -e +# +# rc.local +# +# This script is executed at the end of each multiuser runlevel. +# Make sure that the script will "exit 0" on success or any other +# value on error. +# +# In order to enable or disable this script just change the execution +# bits. +# +# By default this script does nothing. + +. /host/machine.conf + +echo "install platform dependent packages at the first boot time" + +if [ -f /host/platform/firsttime ]; then + if [ -d /host/platform/$onie_platform ]; then + dpkg -i /host/platform/$onie_platform/*.deb + fi + rm /host/platform/firsttime +fi + +exit 0 diff --git a/platform/broadcom/one-image.mk b/platform/broadcom/one-image.mk index 59939fb72e..4558d6669d 100644 --- a/platform/broadcom/one-image.mk +++ b/platform/broadcom/one-image.mk @@ -3,6 +3,9 @@ SONIC_ONE_IMAGE = sonic-broadcom.bin $(SONIC_ONE_IMAGE)_MACHINE = broadcom $(SONIC_ONE_IMAGE)_IMAGE_TYPE = onie -$(SONIC_ONE_IMAGE)_DEPENDS += $(BRCM_OPENNSL_KERNEL) $(DELL_S6000_PLATFORM_MODULE) +$(SONIC_ONE_IMAGE)_DEPENDS += $(BRCM_OPENNSL_KERNEL) +$(SONIC_ONE_IMAGE)_INSTALLS += $(DELL_S6000_PLATFORM_MODULE) \ + $(DELL_Z9100_PLATFORM_MODULE) \ + $(INGRASYS_S9100_PLATFORM_MODULE) $(SONIC_ONE_IMAGE)_DOCKERS += $(SONIC_INSTALL_DOCKER_IMAGES) SONIC_INSTALLERS += $(SONIC_ONE_IMAGE) diff --git a/platform/broadcom/platform-modules-dell.mk b/platform/broadcom/platform-modules-dell.mk index 36ca217f56..ce4c29651c 100644 --- a/platform/broadcom/platform-modules-dell.mk +++ b/platform/broadcom/platform-modules-dell.mk @@ -7,4 +7,5 @@ export DELL_Z9100_PLATFORM_MODULE_VERSION DELL_Z9100_PLATFORM_MODULE = platform-modules-z9100_$(DELL_Z9100_PLATFORM_MODULE_VERSION)_amd64.deb $(DELL_Z9100_PLATFORM_MODULE)_SRC_PATH = $(PLATFORM_PATH)/sonic-platform-modules-dell $(DELL_Z9100_PLATFORM_MODULE)_DEPENDS += $(LINUX_HEADERS) $(LINUX_HEADERS_COMMON) +$(DELL_Z9100_PLATFORM_MODULE)_PLATFORM = x86_64-dell_z9100_c2538-r0 SONIC_DPKG_DEBS += $(DELL_Z9100_PLATFORM_MODULE) diff --git a/platform/broadcom/platform-modules-ingrasys-s9100.mk b/platform/broadcom/platform-modules-ingrasys-s9100.mk index 1802290008..7c7df7b1cf 100755 --- a/platform/broadcom/platform-modules-ingrasys-s9100.mk +++ b/platform/broadcom/platform-modules-ingrasys-s9100.mk @@ -7,4 +7,5 @@ export INGRASYS_S9100_PLATFORM_MODULE_VERSION INGRASYS_S9100_PLATFORM_MODULE = sonic-platform-ingrasys-s9100_$(INGRASYS_S9100_PLATFORM_MODULE_VERSION)_amd64.deb $(INGRASYS_S9100_PLATFORM_MODULE)_SRC_PATH = $(PLATFORM_PATH)/sonic-platform-modules-ingrasys-s9100 $(INGRASYS_S9100_PLATFORM_MODULE)_DEPENDS += $(LINUX_HEADERS) $(LINUX_HEADERS_COMMON) +$(INGRASYS_S9100_PLATFORM_MODULE)_PLATFORM = x86_64-ingrasys_s9100-r0 SONIC_DPKG_DEBS += $(INGRASYS_S9100_PLATFORM_MODULE) diff --git a/platform/broadcom/platform-modules-s6000.mk b/platform/broadcom/platform-modules-s6000.mk index a32ab67c7a..d2c105ffdc 100644 --- a/platform/broadcom/platform-modules-s6000.mk +++ b/platform/broadcom/platform-modules-s6000.mk @@ -7,4 +7,5 @@ export DELL_S6000_PLATFORM_MODULE_VERSION DELL_S6000_PLATFORM_MODULE = platform-modules-s6000_$(DELL_S6000_PLATFORM_MODULE_VERSION)_amd64.deb $(DELL_S6000_PLATFORM_MODULE)_SRC_PATH = $(PLATFORM_PATH)/sonic-platform-modules-s6000 $(DELL_S6000_PLATFORM_MODULE)_DEPENDS += $(LINUX_HEADERS) $(LINUX_HEADERS_COMMON) +$(DELL_S6000_PLATFORM_MODULE)_PLATFORM = x86_64-dell_s6000_s1220-r0 SONIC_DPKG_DEBS += $(DELL_S6000_PLATFORM_MODULE) diff --git a/slave.mk b/slave.mk index a77c2f9818..529ece46f8 100644 --- a/slave.mk +++ b/slave.mk @@ -286,13 +286,14 @@ $(DOCKER_LOAD_TARGETS) : $(TARGET_PATH)/%.gz-load : .platform docker-start $$(TA ############################################################################### # targets for building installers with base image -$(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : .platform onie-image.conf $$(addprefix $(DEBS_PATH)/,$$($$*_DEPENDS)) $(addprefix $(DEBS_PATH)/,$(INITRAMFS_TOOLS) $(LINUX_KERNEL) $(IGB_DRIVER) $(SONIC_CONFIG_ENGINE) $(SONIC_DEVICE_DATA) $(SONIC_UTILS)) $$(addprefix $(TARGET_PATH)/,$$($$*_DOCKERS)) +$(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : .platform onie-image.conf $$(addprefix $(DEBS_PATH)/,$$($$*_DEPENDS)) $$(addprefix $(DEBS_PATH)/,$$($$*_INSTALLS)) $(addprefix $(DEBS_PATH)/,$(INITRAMFS_TOOLS) $(LINUX_KERNEL) $(IGB_DRIVER) $(SONIC_CONFIG_ENGINE) $(SONIC_DEVICE_DATA) $(SONIC_UTILS)) $$(addprefix $(TARGET_PATH)/,$$($$*_DOCKERS)) $(HEADER) ## Pass initramfs and linux kernel explicitly. They are used for all platforms export initramfs_tools="$(DEBS_PATH)/$(INITRAMFS_TOOLS)" export linux_kernel="$(DEBS_PATH)/$(LINUX_KERNEL)" export kversion="$(KVERSION)" export installer_debs="$(addprefix $(DEBS_PATH)/,$($*_DEPENDS))" + export lazy_installer_debs="$(foreach deb, $($*_INSTALLS),$(addprefix $($(deb)_PLATFORM)@, $(DEBS_PATH)/$(deb)))" export installer_images="$(addprefix $(TARGET_PATH)/,$($*_DOCKERS))" export config_engine="$(addprefix $(DEBS_PATH)/,$(SONIC_CONFIG_ENGINE))" export image_type="$($*_IMAGE_TYPE)"