pastebin - collaborative debugging tool
rovema.kpaste.net RSS


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