Advertisement
c32

make_kernel.sh

c32
Nov 2nd, 2018
702
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.43 KB | None | 0 0
  1. if [ $# != 2 ]
  2. then
  3.     #echo
  4.     #echo IMPORTANT!!  IF THIS IS YOUR FIRST TIME COMPILING A KERNEL, DO NOT USE THIS SCRIPT.
  5.     #echo look around, search and try doing it yourself!
  6.     #echo
  7.     echo Usage:
  8.     echo -e \\\tmake_kernel \<compiler prefix\> \< url of tar archive of the linux kernel \>
  9. else
  10.     which $1gcc &> /dev/null
  11.     if [ $? != 0 ]
  12.     then
  13.         echo incorrect compiler prefix
  14.     else
  15.         echo $(tput setaf 6)Script for version 4.4.X$(tput sgr 0)
  16.         echo -n $(tput setaf 6)downloading kernel$(tput sgr 0)\ \
  17.         wget $2 -q -O /tmp/kern.tar.xz
  18.         if [ $? != 0 ]
  19.         then
  20.             echo $(tput setaf 6)failed $(tput sgr 0)
  21.             echo Incorrect link
  22.         else
  23.             NAME=`tar -tf /tmp/kern.tar.xz  | head -n 1`
  24.             echo
  25.             echo -n $(tput setaf 6)extracting kernel\ \ $(tput sgr 0)
  26.             cont=1
  27.             if [ -d $NAME ]
  28.             then
  29.                 echo -n $(tput setaf 6)Dir exists.Delete directory ? \(y\/n\)+enter\ $(tput sgr 0)
  30.                 read ans
  31.                 if [ "$ans" == "y" ]
  32.                 then
  33.                     rm -r $NAME
  34.                     if [ $? != 0 ]
  35.                     then
  36.                         echo $(tput setaf 6)failed$(tput sgr 0)
  37.                         cont=0
  38.                     fi
  39.                 else
  40.                     cont=0
  41.                 fi
  42.             fi
  43.             if [ $cont == 1 ]
  44.             then
  45.                 tar xf /tmp/kern.tar.xz
  46.                 if [ $? != 0 ]
  47.                 then
  48.                     echo -n $(tput setaf 6)fail$(tput sgr 0)
  49.                 else
  50.                     echo
  51.                     #rm /tmp/kern.tar.xz
  52.                     echo -n $(tput setaf 6)getting patches from openwrt github repo\ \ $(tput sgr 0)
  53.                     CONT=1
  54.                     if [ -d openwrt-pxa-target ]
  55.                     then
  56.                         echo -n $(tput setaf 6)Repo exists.Delete directory ? \(y\/n\)+enter\ $(tput sgr 0)
  57.                         read ans
  58.                         if [ "$ans" == "y" ]
  59.                         then
  60.                             rm -r openwrt-pxa-target
  61.                             if [ $? != 0 ]
  62.                             then
  63.                                 echo $(tput setaf 6)failed$(tput sgr 0)
  64.                                 cont=0
  65.                             fi
  66.                         else
  67.                             cont=0
  68.                         fi
  69.                     fi
  70.                     if [ $CONT == 1 ]
  71.                     then
  72.                         git clone https://github.com/openwrt-zipit/openwrt-pxa-target &> /dev/null
  73.                         if [ $? != 0 ]
  74.                         then
  75.                             echo $(tput setaf 6)fail$(tput sgr 0)
  76.                         else
  77.                             echo
  78.                             echo $(tput setaf 6)Patching the kernel$(tput sgr 0)
  79.                             cd $NAME
  80.                             OK=1
  81.                             for f in ../openwrt-pxa-target/pxa/patches-4.4/*
  82.                             do
  83.                                 if [ $OK == 1 ]
  84.                                 then
  85.                                     patch -p1 < "${f}"
  86.                                 fi
  87.                                 if [ $? != 0 ]
  88.                                 then
  89.                                     OK=0
  90.                                 fi
  91.                             done
  92.                             if [ $OK == 1 ]
  93.                             then
  94.                                 echo $(tput setaf 6)getting config for 4.4 from mozzwald\'s website$(tput sgr 0)
  95.                                 curl https://mozzwald.com/zipit/kernel/config.4.4 > .config
  96.                                 if [ $? != 0 ]
  97.                                 then
  98.                                     echo $(tput setaf 6)fail$(tput sgr 0)
  99.                                 else
  100.                                     echo $(tput setaf 6)compiling the kernel$(tput sgr 0)
  101.                                     mkdir ../kernel
  102.                                     cont=1
  103.                                     if [ $? != 0 ]
  104.                                     then
  105.                                         if [ -d ../kenrel ]
  106.                                         then
  107.                                             echo -n $(tput setaf 6)Folder ../kernel exists\(Used for output\).Delete directory ? \(y\/n\)+enter\ $(tput sgr 0)
  108.                                             read ans
  109.                                             if [ "$ans" == "y" ]
  110.                                             then
  111.                                                 rm -r ../kernel
  112.                                                 if [ $? != 0 ]
  113.                                                 then
  114.                                                     echo $(tput setaf 6)failed$(tput sgr 0)
  115.                                                     cont=0
  116.                                                 fi
  117.                                             else
  118.                                                 cont=0
  119.                                             fi
  120.                                         else
  121.                                             echo $(tput setaf 6)error$(tput sgr 0)
  122.                                             cont=0
  123.                                         fi
  124.                                     fi
  125.                                     if [ $cont == 1 ]
  126.                                     then
  127.                                         echo $(tput setaf 6)run make menuconfig before building kernel? \(y\/n\)$(tput sgr 0)
  128.                                         read ans
  129.                                         while [ $ans == "y" ]
  130.                                         do
  131.                                             make ARCH=arm CROSS_COMPILE=$1 INSTALL_MOD_PATH=../kernel/ menuconfig
  132.                                             if [ $? != 0 ]
  133.                                             then
  134.                                                 echo -n $(tput setaf 6)Something went wrong. Try again? \(y\/n\)$(tput sgr 0)
  135.                                                 read ans
  136.                                             else
  137.                                                 ans="ok, we can move on"
  138.                                             fi
  139.                                         done
  140.                                         make ARCH=arm CROSS_COMPILE=$1 INSTALL_MOD_PATH=../kernel/ zImage modules dtbs modules_install
  141.                                         if [ $? != 0 ]
  142.                                         then
  143.                                             echo $(tput setaf 6)Error compiling kernel$(tput sgr 0)
  144.                                         else
  145.                                             cat arch/arm/boot/zImage arch/arm/boot/dts/zipit-z2.dtb >zImage-dtb
  146.                                             mkimage -A Arm -O linux \
  147.                                                 -C none \
  148.                                                 -T kernel \
  149.                                                 -a 0xA0008000 -e 0xA0008000 \
  150.                                                 -n uImage -d zImage-dtb uImage
  151.                                             mkdir ../kernel/boot
  152.                                             cp uImage ../kernel/boot
  153.                                             cd ..
  154.                                         fi
  155.                                     fi
  156.                                 fi
  157.                             fi
  158.                         fi
  159.                     fi
  160.                 fi
  161.             fi
  162.         fi
  163.     fi
  164. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement