#!/usr/bin/env bash # Copyright (c) 2000-2020 Synology Inc. All rights reserved. # shellcheck source=/dev/null source "SynoBuildConf/_env" source "SynoBuildConf/_kconfig" case ${MakeClean:-} in [Yy][Ee][Ss]) make distclean ;; esac case ${CleanOnly:-} in [Yy][Ee][Ss]) return ;; esac build_public_key() { # shellcheck disable=SC2154 # lnxscripts/include/applyEnv: SysRootInclude="${ToolChainSysRoot}/usr/include" # lnxscripts/include/platforms: KernelDir="/source/${SYNO_KERNEL_SOURCE_DIR}" if [ "$PLATFORM_FAMILY" = "SYNOPLAT_F_X86_64" ]; then ln -fsv "$SysRootInclude/hydrogen/hydrogen.h" "$KernelDir/include/crypto/hydrogen.h" ln -fsv "$SysRootInclude/hydrogen/hydrogen.c" "$KernelDir/crypto/hydrogen/hydrogen.c" ln -fsv "$SysRootInclude/hydrogen/impl" "$KernelDir/crypto/hydrogen/impl" sed -i "s/__RAMDISK_SIGN_PUBLIC_KEY__/$(cat < "$ScriptsDir/config/rd_sign.pub" | xxd -i -c 32)/" \ "$KernelDir/init/initramfs.c" fi } build_certification() { ln -fsv "$ScriptsDir/config/signing_key.pem" "$KernelDir/synology/certs/signing_key.pem" ln -fsv "$ScriptsDir/config/trusted_certificates.pem" "$KernelDir/synology/certs/trusted_certificates.pem" } build_seed() { # shellcheck disable=SC2154 # lnxscripts/include/platforms: KernelDir="/source/${SYNO_KERNEL_SOURCE_DIR}" if [ "$PLATFORM_FAMILY" = "SYNOPLAT_F_X86_64" ]; then DECOMPRESSION_TYPE=$(shuf -i 1001-2147483647 -n 1) sed -i "s/__DECOMPRESSION_TYPE__/${DECOMPRESSION_TYPE}/" \ "${KernelDir}/arch/x86/boot/compressed/head_64.S" sed -i "s/__DECOMPRESSION_TYPE__/${DECOMPRESSION_TYPE}/" \ "${KernelDir}/lib/synolib/syno_kexec_test.c" fi } build_version() { local _protect_ver _dsm_ver if [ -f "${VERSION_FILE:-/source/synoversion/VERSION}" ]; then # originally ".version" is updated by scripts/link-vmlinux.sh # we forcely overwrite it with DSM build number at every build. echo $(($(GetDSMBuildNumber) - 1)) > ".version" fi [ -f ".debug" ] || return _protect_ver="$(dpkg -l | grep "synoprotection-$PLATFORM_ABBR-" | awk '{print $3}' | cut -d'-' -f2 | head -n1)" _dsm_ver="$(GetDSMBuildNumber)" if [ -z "$_protect_ver" ]; then ERROR "Unable to detect dpkg 'synoprotection'" exit 1 fi if [ "$_dsm_ver" != "$_protect_ver" ]; then ERROR "buildnumber in synoversion/VERSION doesn't match dpkg 'synoprotection'" exit 1 fi } # shellcheck disable=SC2086 build_kernel() { [ -f ".config" ] || return 1 make prepare $MAKE_FLAGS make vmlinux $MAKE_FLAGS make modules $MAKE_FLAGS make "$(platform_target)" $MAKE_FLAGS } # shellcheck disable=SC2086 build_device_tree() { # Usually only arm platform needs this action if [ "$BUILD_TARGET" = "REALTEK_RTD1619B" ]; then make $MAKE_FLAGS dtbs fi } INFO "Generate .config for architecture $ARCH platform $PLATFORM_ABBR" kconfig_generate # INFO "Copying signing_key and certification from build system" # build_certification # build_public_key # build_seed build_version INFO "Build Synology linux kernel $(make -s kernelversion)" build_kernel INFO "Build device tree" build_device_tree INFO "Compare kernel config with re-generated one" kconfig_check_diff INFO "Check Synology kernel configs" kconfig_check_syno_macro kconfig_check_rule