Skip to content

Build Broadcom Opennsl and SAI

Ying Xie edited this page Oct 30, 2017 · 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.

Prepare build environment

  1. Clone SONiC Build Image Repo
  2. Edit buildimage repo root/Makefile, change DOCKER_RUN variable, remove option "--rm=true".
  3. Then follow Building Guide to finish one full build of SONiC image. This build takes long time, but some built packages are needed for next steps, so be patient.
  4. While the build is running, issue "docker ps" and note down the name of docker image "sonic-slave-:". The name is usually a two word combo, like "admiring_pare".
  5. After build is done, the container will disappear from "docker ps", but will still be visible from "docker ps -a".
  6. check out Makefile to revert the change we made in step 2. We don't need to leave any other docker images behind.
  7. Restart the docker image and map your local source code repos in the docker image, suppose your source code repos are all under /home//src/, following one of the following 2 commands to map this folder to /var/src in container:

docker run -t -i -v /home/<user name>/src:/var/src <image name, e.g. admiring_pare> bash

docker run -t -i -v /home/<user name>/src:/var/src sonic-slave-<user name>:<sha> bash

  1. Inside the socket build slave, issue following command:

docker run -t -i -v /home/<user name>/src:/var/src <image name, e.g. admiring_pare> bash

  1. cd to /sonic/target/debs, install following 2 debian packages into the build slave:

sudo dpkg -i linux-headers-3.16.0-4-amd64_3.16.36-1+deb8u2_amd64.deb linux-headers-3.16.0-4-common_3.16.36-1+deb8u2_amd64.deb

  1. You can issue "docker rm <image name, e.g. admiring_pare>" to remove this image, when you are done with building SAI.

Build opennsl

  1. Start the SONiC build slave following instruction in step 7 of previous step, if you haven't done so.
  2. cd into /var/src
  3. You can choose to clone/unzip opennsl repo from inside the docker, or from your base image.
  4. If you cloned a git repo, make sure you check out the right branch to build. SAI and opennsl are tightly coupled, their versions needs to match.
  5. cd into the root of your opennsl repo, e.g. /var/src/opennsl/, issue fakeroot debian/rules -B binary to build opennsl debian packages. If the build failed with privilege error, use sudo fakeroot debian/rules -B binary to build. Build will take 30-45 minutes.
  6. When build succeeded, the built debian packages are stored at the folder one level above opennsl repo, in our case, /var/src/
  7. cd to /var/src, issue sudo dpkg -i libopennsl* to install the newly built opennsl debian packages to get ready for SAI compile.

Build SAI

  1. Start the SONiC build slave following instruction in step 7 of prepare build environment step, if you haven't done so.

  2. If you haven't succeeded in "Build opennsl", please do so first.

  3. cd /var/src

  4. clone/unzip SAI package here.

  5. cd into SAI repo root, say /var/log/sai/

  6. When building from source code packages directly downloaded from Broadcom, you need to setup environment variable OPENNSL_BASE, if you had to use 'sudo' to build opennsl in step 5, issue sudo bash and do everything afterwards as root.

    6.1 issue export OPENNSL_BASE=<opennsl source tree root, e.g. /var/log/opennsl>

  7. Issue fakeroot debian/rules -B binary to build SAI. This build should only take a minute or so.

  8. The built SAI debian pakcages will be at one level above SAI repo root, in this case /var/src/

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 /target/debs/
  4. Edit /platform/broadcom/sdk.mk, change BRCM_OPENNSL_KERNEL to match the name of the new opennsl package.
  5. Edit /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