Build#

Compiling the Kernel (Canonical Kernel 6.8)#

You can compile the Linux kernel source in your Linux SDK product.

  1. Set up the environment macros; the LOCAL_VERSION environment variable appends -rt-tegra to the kernel version and modules:

    export NV_WORKSPACE=${PWD}
    export ARCH=arm64
    export CORE_KERNEL_DIR=canonical-6.8
    export OUT_DIR=/tmp/${CORE_KERNEL_DIR}
    export KERNEL_OUT_BUILD_DIR=${OUT_DIR}
    export BUILD_CONFIG=prod_nsr # or test_nsr or dev_nsr
    # for prod_nsr, test_nsr
    export PROD_SUFFIX=_prod
    # for dev_nsr
    export PROD_SUFFIX=""
    
  2. Compile Kernel

    cd ${NV_WORKSPACE}/drive-linux/kernel
    
    # Note:
    # The "--update-sdk" option in the command below copies the newly built images and kernel modules into the default SDK paths.
    # Before proceeding, ensure you back up the existing default kernel modules located at ${NV_WORKSPACE}/drive-linux/kernel/canonical-6.8/preempt_rt${PROD_SUFFIX}/modules/*
    ./compile_kernel.sh --nv-workspace ${NV_WORKSPACE} --core-kernel-dir ${CORE_KERNEL_DIR} --nv-build-config ${BUILD_CONFIG} --out-dir ${OUT_DIR} --update-sdk
    
  3. Copy built modules to the root file system by rebuilding the filesystem based on <pct_variant> (which can be prod_nsr, test_nsr, or dev_nsr):

    /drive/drive-linux/filesystem/create_linux_targetfs.sh -p <pct_variant>
    
  4. Update initramfs with built modules:

    # If Building a production kernel for prod_nsr/test_nsr PCTs, then please set:
    export INITRAMFS_IMAGE=${NV_WORKSPACE}/drive-linux/filesystem/initramfs/prod-initramfs-canonical-6.8.cpio
    
    # Else If building a standard kernel for dev_nsr PCT, please set:
    export INITRAMFS_IMAGE=${NV_WORKSPACE}/drive-linux/filesystem/initramfs/initramfs-canonical-6.8.cpio
    
    # Extract the initramfs.
    cd ${NV_WORKSPACE}/drive-linux/filesystem/initramfs
    mkdir -p tmp; cd tmp; cpio -imdu --quiet < ${INITRAMFS_IMAGE}
    
    # Run copytarget to copy kernel modules.
    export NVRTKERNELNAME=$(basename ${NV_WORKSPACE}/drive-linux/kernel/canonical-6.8/preempt_rt${PROD_SUFFIX}/modules/*rt*-tegra)
    export NV_SDK_NAME_LINUX=drive-linux
    # for prod_nsr, test_nsr
    export INITRAMFS_FS_TYPE=prod_boot_initramfs
    # for dev_nsr
    export INITRAMFS_FS_TYPE=boot_initramfs
    rm -rf lib/modules/*
    ${NV_WORKSPACE}/drive-common/filesystems/copytarget/1.4/copytarget.py $PWD ${NV_WORKSPACE}/ ${NV_WORKSPACE}/drive-linux/filesystem/copytarget/manifest/copytarget-initramfs.yaml --filesystem-type ${INITRAMFS_FS_TYPE}
    
    # Create the depmod and alias
    for k in $(ls -d ./lib/modules/*); do
      echo "Running depmod for kernel modules at $k"
      depmod -b . -a $(basename $k)
    done
    
  5. Rebuild updated initramfs:

    find . | cpio --quiet -H newc -o > ${INITRAMFS_IMAGE}
    cd ${NV_WORKSPACE}/drive-linux/filesystem/initramfs; rm -rf tmp
    
  6. Run bind_partitions based on <pct_variant> (which can be prod_nsr, test_nsr, or dev_nsr):

    cd /drive/drive-foundation
    ./make/bind_partitions -b <board name> drive_av.linux -p <pct_variant>
    
  7. Flash the target to the board using the SDK bootburn tool.

  8. Boot the board. The built kernel modules will auto-load on boot.