[installer]: support platform driver lazy installation (#340)

allow one image to support multiple switch devices, install
corresponding platform driver during the first boot time.
This commit is contained in:
lguohan 2017-02-27 13:08:41 -08:00 committed by GitHub
parent 2a551d3c60
commit b9b7d7a295
8 changed files with 77 additions and 10 deletions

View File

@ -37,6 +37,7 @@ DOCKER_VERSION=1.11.1-0~jessie_amd64
## Working directory to prepare the file system ## Working directory to prepare the file system
FILESYSTEM_ROOT=./fsroot FILESYSTEM_ROOT=./fsroot
PLATFORM_DIR=platform
## Hostname for the linux image ## Hostname for the linux image
HOSTNAME=sonic HOSTNAME=sonic
DEFAULT_USERINFO="Default admin user,,," 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" sudo rm -rf $FILESYSTEM_ROOT || die "Failed to clean chroot directory"
fi fi
mkdir -p $FILESYSTEM_ROOT mkdir -p $FILESYSTEM_ROOT
mkdir -p $FILESYSTEM_ROOT/$PLATFORM_DIR
touch $FILESYSTEM_ROOT/$PLATFORM_DIR/firsttime
## Build a basic Debian system by debootstrap ## Build a basic Debian system by debootstrap
echo '[INFO] 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/ sudo cp files/dhcp/dhclient.conf $FILESYSTEM_ROOT/etc/dhcp/
if [ -f sonic_debian_extension.sh ]; then if [ -f sonic_debian_extension.sh ]; then
./sonic_debian_extension.sh $FILESYSTEM_ROOT ./sonic_debian_extension.sh $FILESYSTEM_ROOT $PLATFORM_DIR
fi fi
## Clean up apt ## Clean up apt
@ -268,11 +271,11 @@ sudo mkdir $FILESYSTEM_ROOT/host
sudo rm -f $ONIE_INSTALLER_PAYLOAD $FILESYSTEM_SQUASHFS sudo rm -f $ONIE_INSTALLER_PAYLOAD $FILESYSTEM_SQUASHFS
## Output the file system total size for diag purpose ## Output the file system total size for diag purpose
sudo du -hs $FILESYSTEM_ROOT 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 ## Compress docker files
pushd $FILESYSTEM_ROOT && sudo tar czf $OLDPWD/$FILESYSTEM_DOCKERFS -C var/lib/docker .; popd 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 ## 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/; popd pushd $FILESYSTEM_ROOT && sudo zip $OLDPWD/$ONIE_INSTALLER_PAYLOAD -r boot/ $PLATFORM_DIR/; popd
sudo zip -g $ONIE_INSTALLER_PAYLOAD $FILESYSTEM_SQUASHFS $FILESYSTEM_DOCKERFS sudo zip -g $ONIE_INSTALLER_PAYLOAD $FILESYSTEM_SQUASHFS $FILESYSTEM_DOCKERFS

View File

@ -4,7 +4,7 @@
## to debian file system. ## to debian file system.
## ##
## USAGE: ## USAGE:
## ./sonic_debian_extension.sh FILESYSTEM_ROOT ## ./sonic_debian_extension.sh FILESYSTEM_ROOT PLATFORM_DIR
## PARAMETERS: ## PARAMETERS:
## FILESYSTEM_ROOT ## FILESYSTEM_ROOT
## Path to debian file system root directory ## Path to debian file system root directory
@ -15,6 +15,12 @@ FILESYSTEM_ROOT=$1
exit 1 exit 1
} }
PLATFORM_DIR=$2
[ -n "$PLATFORM_DIR" ] || {
echo "Error: no or empty PLATFORM_DIR argument"
exit 1
}
## Enable debug output for script ## Enable debug output for script
set -x -e set -x -e
@ -22,7 +28,6 @@ set -x -e
BUILD_TEMPLATES=files/build_templates BUILD_TEMPLATES=files/build_templates
IMAGE_CONFIGS=files/image_config IMAGE_CONFIGS=files/image_config
{% if installer_debs.strip() -%}
clean_sys() { clean_sys() {
sudo umount $FILESYSTEM_ROOT/sys/fs/cgroup/* \ sudo umount $FILESYSTEM_ROOT/sys/fs/cgroup/* \
$FILESYSTEM_ROOT/sys/fs/cgroup \ $FILESYSTEM_ROOT/sys/fs/cgroup \
@ -130,6 +135,7 @@ exit 101
EOF EOF
sudo chmod a+x $FILESYSTEM_ROOT/usr/sbin/policy-rc.d sudo chmod a+x $FILESYSTEM_ROOT/usr/sbin/policy-rc.d
{% if installer_debs.strip() -%}
{% for deb in installer_debs.strip().split(' ') -%} {% for deb in installer_debs.strip().split(' ') -%}
if [ $sonic_asic_platform == "mellanox" ]; then if [ $sonic_asic_platform == "mellanox" ]; then
sudo dpkg --extract {{deb}} $FILESYSTEM_ROOT 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 sudo dpkg --root=$FILESYSTEM_ROOT -i {{deb}} || sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y install -f
fi fi
{% endfor %} {% endfor %}
{% endif %}
sudo rm -f $FILESYSTEM_ROOT/usr/sbin/policy-rc.d
## Run depmod command for target kernel modules ## Run depmod command for target kernel modules
sudo LANG=C chroot $FILESYSTEM_ROOT depmod -a {{kversion}} 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 %} {% 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() -%} {% if installer_images.strip() -%}
{% for image in installer_images.strip().split(' ') -%} {% for image in installer_images.strip().split(' ') -%}
sudo LANG=C chroot $FILESYSTEM_ROOT docker load < {{image}} sudo LANG=C chroot $FILESYSTEM_ROOT docker load < {{image}}

View File

@ -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

View File

@ -3,6 +3,9 @@
SONIC_ONE_IMAGE = sonic-broadcom.bin SONIC_ONE_IMAGE = sonic-broadcom.bin
$(SONIC_ONE_IMAGE)_MACHINE = broadcom $(SONIC_ONE_IMAGE)_MACHINE = broadcom
$(SONIC_ONE_IMAGE)_IMAGE_TYPE = onie $(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_ONE_IMAGE)_DOCKERS += $(SONIC_INSTALL_DOCKER_IMAGES)
SONIC_INSTALLERS += $(SONIC_ONE_IMAGE) SONIC_INSTALLERS += $(SONIC_ONE_IMAGE)

View File

@ -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 = 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)_SRC_PATH = $(PLATFORM_PATH)/sonic-platform-modules-dell
$(DELL_Z9100_PLATFORM_MODULE)_DEPENDS += $(LINUX_HEADERS) $(LINUX_HEADERS_COMMON) $(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) SONIC_DPKG_DEBS += $(DELL_Z9100_PLATFORM_MODULE)

View File

@ -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 = 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)_SRC_PATH = $(PLATFORM_PATH)/sonic-platform-modules-ingrasys-s9100
$(INGRASYS_S9100_PLATFORM_MODULE)_DEPENDS += $(LINUX_HEADERS) $(LINUX_HEADERS_COMMON) $(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) SONIC_DPKG_DEBS += $(INGRASYS_S9100_PLATFORM_MODULE)

View File

@ -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 = 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)_SRC_PATH = $(PLATFORM_PATH)/sonic-platform-modules-s6000
$(DELL_S6000_PLATFORM_MODULE)_DEPENDS += $(LINUX_HEADERS) $(LINUX_HEADERS_COMMON) $(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) SONIC_DPKG_DEBS += $(DELL_S6000_PLATFORM_MODULE)

View File

@ -286,13 +286,14 @@ $(DOCKER_LOAD_TARGETS) : $(TARGET_PATH)/%.gz-load : .platform docker-start $$(TA
############################################################################### ###############################################################################
# targets for building installers with base image # 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) $(HEADER)
## Pass initramfs and linux kernel explicitly. They are used for all platforms ## Pass initramfs and linux kernel explicitly. They are used for all platforms
export initramfs_tools="$(DEBS_PATH)/$(INITRAMFS_TOOLS)" export initramfs_tools="$(DEBS_PATH)/$(INITRAMFS_TOOLS)"
export linux_kernel="$(DEBS_PATH)/$(LINUX_KERNEL)" export linux_kernel="$(DEBS_PATH)/$(LINUX_KERNEL)"
export kversion="$(KVERSION)" export kversion="$(KVERSION)"
export installer_debs="$(addprefix $(DEBS_PATH)/,$($*_DEPENDS))" 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 installer_images="$(addprefix $(TARGET_PATH)/,$($*_DOCKERS))"
export config_engine="$(addprefix $(DEBS_PATH)/,$(SONIC_CONFIG_ENGINE))" export config_engine="$(addprefix $(DEBS_PATH)/,$(SONIC_CONFIG_ENGINE))"
export image_type="$($*_IMAGE_TYPE)" export image_type="$($*_IMAGE_TYPE)"