pastebin - collaborative debugging tool
rovema.kpaste.net RSS


Build Debian kernel manually from source
Posted by Anonymous on Tue 22nd Mar 2022 14:33
raw | new post
view followups (newest first): Build Debian kernel manually from source by Anonymous
modification of post by Anonymous (view diff)

  1. #!/usr/bin/ksh93
  2.  
  3. #
  4. # Build Debian RT kernel from source,
  5. # and retain the kernel build including source and *.o
  6. # files so we can build custom kernel modules from
  7. # that
  8. #
  9.  
  10. compound bconfig=(
  11.         # config
  12.         typeset kernel_maj_min='5.10'
  13.         typeset igb_avb_src_gitbundle='/home/test001/work/dev_current/dev026/elbe/igb_avb/rovema_igb_avb_git20220302_001.bundle'
  14.         typeset simatic_src_gitbundle='/home/test001/work/dev_current/dev026/elbe/simatickernelmodules/rovema_simatickernelmodules_git20220304_001.bundle'
  15.        
  16.         # calculated values
  17.         typeset kernel_build_path
  18. )
  19.  
  20. function build_debian_kernel_from_src
  21. {
  22.         set -o xtrace
  23.         set -o errexit
  24.         set -o nounset
  25.  
  26.         integer res
  27.         integer num_cpus=$(getconf '_NPROCESSORS_CONF')
  28.  
  29.         tar xf "/usr/src/linux-source-${bconfig.kernel_maj_min}.tar.xz"
  30.        
  31.         cd "linux-source-${bconfig.kernel_maj_min}"
  32.  
  33.         unxz <"/usr/src/linux-patch-${bconfig.kernel_maj_min}-rt.patch.xz" | patch -p1
  34.  
  35.         cp "/usr/src/linux-config-${bconfig.kernel_maj_min}/config.amd64_rt_amd64.xz" .
  36.         unxz 'config.amd64_rt_amd64.xz'
  37.  
  38.         # copy config and make kernel build accept it without
  39.         # jumping to the $ make menu # menu
  40.         cp 'config.amd64_rt_amd64' '.config'
  41.         make oldconfig <'/dev/null'
  42.        
  43.         # show any modifications $ make oldconfig # did to the kernel config
  44.         print '--------------------------------------'
  45.         diff -u 'config.amd64_rt_amd64' '.config' || true
  46.         print '--------------------------------------'
  47.  
  48.         make clean
  49.         time nice -n 19 make -j$((num_cpus*2)) deb-pkg 2>&1 | tee -a buildlog.log
  50.         (( res=$? ))
  51.  
  52.         printf '#### Kernel build finished, return code = %d\n' res
  53.  
  54.         if (( res == 0 )) ; then
  55.                 # remember the path to the kernel build, but only if we were successful
  56.                 bconfig.kernel_build_path="$PWD/"
  57.         fi
  58.  
  59.         return $res
  60. }
  61.  
  62. function build_simatic_kernel_modules
  63. {
  64.         set -o xtrace
  65.         set -o errexit
  66.         set -o nounset
  67.  
  68.         # dummy for now
  69.         #simatic-ipc-modules-lsp-v1.2.0RC1$ make -C /home/test001/work/kernel_test001/linux-5.10.52/ M=$PWD
  70.  
  71.         rm -Rf simatic_build
  72.         mkdir simatic_build
  73.         cd simatic_build
  74.  
  75.         cp "${bconfig.simatic_src_gitbundle}" .
  76.         git clone rovema_simatickernelmodules_git20220304_001.bundle
  77.  
  78.         cd rovema_simatickernelmodules_git20220304_001/simatic-ipc-modules-lsp-v1.2.0RC1/
  79.         make -C "${bconfig.kernel_build_path}" KSRC="${bconfig.kernel_build_path}" M=$PWD
  80.  
  81.         #
  82.         # ToDo: Install in root/ dir, and turn that filesystem hieracy into a
  83.         # Debian package
  84.         # see https://unix.stackexchange.com/questions/30303/how-to-create-a-deb-file-manually
  85.         #
  86.  
  87.         return 1
  88. }
  89.  
  90.  
  91. function build_igb_avb_kernel_module
  92. {
  93.         set -o xtrace
  94.         set -o errexit
  95.         set -o nounset
  96.  
  97.         rm -Rf igb_avb_build
  98.         mkdir igb_avb_build
  99.         cd igb_avb_build
  100.  
  101.         cp "${bconfig.igb_avb_src_gitbundle}" .
  102.         git clone rovema_igb_avb_git20220302_001.bundle
  103.  
  104.         cd rovema_igb_avb_git20220302_001/kmod
  105.  
  106.         make -C "${bconfig.kernel_build_path}" KSRC="${bconfig.kernel_build_path}" M=$PWD clean
  107.         make -C ${bconfig.kernel_build_path} KSRC="${bconfig.kernel_build_path}" M=$PWD
  108.  
  109.  
  110.         cd ../lib
  111.         make
  112.  
  113.         #
  114.         # ToDo: Install in root/ dir, and turn that filesystem hieracy into a
  115.         # Debian package
  116.         #
  117.  
  118.         # dummy for now
  119.         # see https://unix.stackexchange.com/questions/30303/how-to-create-a-deb-file-manually
  120.  
  121.         return 1
  122. }
  123.  
  124. function main
  125. {
  126.         set -o xtrace
  127.         set -o errexit
  128.  
  129.         if (( 0 )) ; then
  130.                 build_debian_kernel_from_src
  131.         else
  132.                 bconfig.kernel_build_path="$PWD/linux-source-${bconfig.kernel_maj_min}/"
  133.         fi
  134.         build_simatic_kernel_modules || true
  135.         build_igb_avb_kernel_module
  136. }
  137.  
  138. #
  139. # main
  140. #
  141. builtin getconf
  142.  
  143. main "$@"
  144.  
  145. # EOF.

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at