pastebin - collaborative debugging tool
rovema.kpaste.net RSS


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