Skip to content

Build Broadcom Opennsl and SAI

Ying Xie edited this page Aug 30, 2019 · 16 revisions

Intended audience

Almost all users could build SONiC image by following guide on Building Guide, except those who has access to Broadcom Opennsl and SAI source code and are working on bringing up a new SAI version.

Relevant SAI version: Broadcom SAI 3.3 and above.

  • NOTE: building opennsl is no longer needed for SAI 3.3

Prepare build environment

  1. Clone SONiC Build Image Repo

  2. Build 201803 branch: git checkout 201803; make init; make configure PLATFORM=broadcom; KEEP_SLAVE_ON=yes SOURCE_FOLDER=<your source folder, e.g. /var/<username>/src>. (Following Building Guide).

  3. Inside the socket build slave, save following script and run it from inside the slave docker to build:

#!/bin/bash -x

function set_kernel_version()
{
    COMMON=`ls /sonic/target/debs/linux-headers*common*.deb`
    TMP=${COMMON//\/sonic\/target\/debs\/linux-headers-/}
    VERSION=${TMP//-common*/}
    
    echo "Version: $VERSION"
}

function fix_build_symbolic_links()
{
    # Fix source code symbolic links until Broadcom fix build issue.
    sudo rm -rf /lib/modules/$VERSION-amd64/build
    sudo rm -rf /lib/modules/$VERSION-amd64/source
    sudo ln -s /usr/src/linux-headers-$VERSION-common/ /lib/modules/$VERSION-amd64/source
    sudo ln -s /usr/src/linux-headers-$VERSION-amd64/  /lib/modules/$VERSION-amd64/build
    sudo ln -s /usr/src/linux-headers-$VERSION-amd64/include/generated/ /usr/src/linux-headers-$VERSION-common/include/generated
    sudo ln -s /usr/src/linux-headers-$VERSION-amd64/arch/x86/include/generated/ /usr/src/linux-headers-$VERSION-common/arch/x86/include/generated
    sudo ln -s /usr/src/linux-headers-$VERSION-amd64/include/config/ /usr/src/linux-headers-$VERSION-common/include/config
    sudo cp /usr/src/linux-headers-$VERSION-amd64/Module.symvers /usr/src/linux-headers-$VERSION-common/Module.symvers
    
    ls /lib/modules
}

sudo apt-get -y install linux-kbuild-3.16 linux-compiler-gcc-4.8-x86
sudo dpkg -i /sonic/target/debs/linux-headers-*.deb

set_kernel_version
fix_build_symbolic_links

export KERNEL_SRC=/usr/src/linux-headers-$VERSION-common

fakeroot debian/rules -j20 -B binary'

Known issues

  • With current SAI 3.3. You are unable to clean and rebuilt. To rebuild:
rm -rf output
git checkout output
# and run the above script again.

Use newly created packages to build a new SONiC image

  1. Clone SONiC Build Image Repo
  2. Follow Building Guide, issue make init, make config PLATFORM=broadcom.
  3. copy the newly built opennsl and SAI debian packages to <build image repo root>/target/debs/
  4. Edit <build image repo root>/platform/broadcom/sdk.mk, change BRCM_OPENNSL_KERNEL to match the name of the new opennsl package.
  5. Edit <build image repo root>/platform/broadcom/sai.mk, change BRCM_SAI and BRCM_SAI_DEV respectively to match the new SAI packages names.
  6. Follow normal build procedure to build SONiC image.
Clone this wiki locally