Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide an option to rebuild the kernel without downloading it again #104

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 28 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ LINUX_IMAGE = linux-image-$(KVERSION)-unsigned_$(KERNEL_VERSION)-$(KERNEL_SUBVER
MAIN_TARGET = $(LINUX_HEADER_COMMON)
DERIVED_TARGETS = $(LINUX_HEADER_AMD64) $(LINUX_IMAGE)

ifneq ($(kernel_procure_method), build)
ifeq ($(kernel_procure_method), download)
# Downloading kernel

# TBD, need upload the new kernel packages
Expand Down Expand Up @@ -52,16 +52,29 @@ DSC_FILE_URL = "http://security.debian.org/debian-security/pool/updates/main/l/l
DEBIAN_FILE_URL = "http://security.debian.org/debian-security/pool/updates/main/l/linux/linux_4.19.67-2+deb10u2.debian.tar.xz"
ORIG_FILE_URL = "http://security.debian.org/debian-security/pool/updates/main/l/linux/linux_4.19.67.orig.tar.xz"

ifneq ($(wildcard $(BUILD_DIR)),)
ifeq ($(kernel_procure_method), incremental)
INCR_BUILD = YES
endif
endif

$(addprefix $(DEST)/, $(MAIN_TARGET)): $(DEST)/% :
# Obtaining the Debian kernel source
ifeq ($(INCR_BUILD),)
rm -rf $(BUILD_DIR)
wget -O $(DSC_FILE) $(DSC_FILE_URL)
wget -O $(ORIG_FILE) $(ORIG_FILE_URL)
wget -O $(DEBIAN_FILE) $(DEBIAN_FILE_URL)

dpkg-source -x $(DSC_FILE)
endif

pushd $(BUILD_DIR)

ifneq ($(INCR_BUILD),)
# Force kernel build
rm -f debian/stamps/build_amd64_none_amd64
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in this incremetal build, it looks like we are not re-applying the patch series. what if the developer add a new kernel patch? Can you do stg pop and then re-apply all the patches?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The theory is that, the user will first try the patch by directly applying the changes to the staged repo "sonic-linux-kernel/linux-4.9.189". Re-build, test the image. In fact, to create the patch itself, the staged repo "sonic-linux-kernel/linux-4.9.189" shall be used and when all change set is ready the patches are moved to the patch directory and series file updated. The staged repo is transient in nature till the point patches are tried manually, tested and finalized.

else
git init
git add -f *
git commit -qm "check in all loose files and diffs"
Expand All @@ -74,13 +87,13 @@ $(addprefix $(DEST)/, $(MAIN_TARGET)): $(DEST)/% :
debian/bin/gencontrol.py

# generate linux build file for amd64_none_amd64
# fakeroot make -f debian/rules.gen setup_armhf_none_armmp
# fakeroot make -f debian/rules.gen setup_arm64_none
fakeroot make -f debian/rules.gen setup_amd64_none_amd64
fakeroot make -f debian/rules.gen DEB_HOST_ARCH=armhf setup_armhf_none_armmp
fakeroot make -f debian/rules.gen DEB_HOST_ARCH=arm64 setup_arm64_none_arm64
fakeroot make -f debian/rules.gen DEB_HOST_ARCH=amd64 setup_amd64_none_amd64

# Applying patches and configuration changes
# git add debian/build/build_armhf_none_armmp/.config -f
# git add debian/build/build_arm64_none_arm64/.config -f
git add debian/build/build_armhf_none_armmp/.config -f
git add debian/build/build_arm64_none_arm64/.config -f
git add debian/build/build_amd64_none_amd64/.config -f
git add debian/config.defines.dump -f
git add debian/control -f
Expand All @@ -92,12 +105,18 @@ $(addprefix $(DEST)/, $(MAIN_TARGET)): $(DEST)/% :
stg repair
stg import -s ../patch/series

# Optionally add/remove kernel options
if [ -f ../manage-config ]; then
../manage-config amd64
fi
endif

# Building a custom kernel from Debian kernel source
DO_DOCS=False fakeroot make -f debian/rules -j $(shell nproc) binary-indep
ARCH=$(CONFIGURED_ARCH) DEB_HOST_ARCH=$(CONFIGURED_ARCH) DEB_BUILD_PROFILES=nodoc fakeroot make -f debian/rules -j $(shell nproc) binary-indep
ifeq ($(CONFIGURED_ARCH), armhf)
fakeroot make -f debian/rules.gen -j $(shell nproc) binary-arch_$(CONFIGURED_ARCH)_none_armmp
ARCH=$(CONFIGURED_ARCH) DEB_HOST_ARCH=$(CONFIGURED_ARCH) fakeroot make -f debian/rules.gen -j $(shell nproc) binary-arch_$(CONFIGURED_ARCH)_none_armmp
else
fakeroot make -f debian/rules.gen -j $(shell nproc) binary-arch_$(CONFIGURED_ARCH)_none
ARCH=$(CONFIGURED_ARCH) DEB_HOST_ARCH=$(CONFIGURED_ARCH) fakeroot make -f debian/rules.gen -j $(shell nproc) binary-arch_$(CONFIGURED_ARCH)_none_$(CONFIGURED_ARCH)
endif
popd

Expand Down
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,27 @@
## Description
This repository contains the scripts and patches to build the kernel for SONiC. SONiC uses the same kernel for all platforms. We prefer to out-of-tree kernel platform modules. We accept kernel patches on following conditions:

- Existing kernel modules need to be enabled.
- Existing kernel modules need to be patched and those patches are available in upstream.
- Please include the original upstream commit id and message in the patch. This allows the maintainer to remove upstream patches during the kernel upgrade.
- New kernel modules which are common to all platforms.
- Platform specific kernel modules which are impossible or very difficul to be built out of kernel tree.
- Existing kernel modules need to be enabled
- Existing kernel modules need to be patched and those patches are available in upstream
- New kernel modules which are common to all platforms
- Platform specific kernel modules which are impossible or very difficul to be built out of kernel tree

Platform specific kernel modules are expected to develop out-of-tree kernel modules, provide them in debian packages to be embeded into SONiC ONE image and installed on their platforms.

For all patches, please ensure you have run the patch with `checkpatch.pl` and pass it.

Usage:

make DEST=<destination path>

If DEST is not set, package will stay in current directory.

## Incremental Kernel Build

Normally, rebuilding the kernel involves removing the previously built kernel source tree, downloading the stock kernel, applying all the SONiC patches, and compiling the kernel and the kernel modules. In a development environment, you might want to skip downloading the kernel and applying all the patches, and just rebuild the kernel. This option is enabled by setting the value for DEFAULT_KERNEL_PROCURE_METHOD to "incremental" in the rules/config file.

Procedure to rebuild the kernel:

make target/debs/stretch/linux-headers-4.9.0-9-2-common_4.9.168-1+deb9u5_all.deb-clean
make target/debs/stretch/linux-headers-4.9.0-9-2-common_4.9.168-1+deb9u5_all.deb

You can then upload and install the kernel archive in the switch:
target/debs/stretch/linux-image-4.9.0-9-2-amd64_4.9.168-1+deb9u5_amd64.deb