[Desire Android Development] Droidzone:
Kernel Build Menu

Thanks! I use an interactive menu.. saves a lot of keystrokes in the process

Attached as kmen..

Installing:

Copy it to anywhere in your path-preferably /usr/bin

Then,

mv /usr/bin/kmen.txt /usr/bin/kmen
chmod +x /usr/bin/kmen
kmen

#!/bin/bash

function msg {
echo -e '\E[37;44m'"\033[1m$welcome\033[0m" ; tput sgr0
}

function msg_blue {
echo -e '\E[37;44m'"\033[1m$welcome\033[0m" ; tput sgr0
}

function msg_green {
echo -e '\E[38;42m'"\033[1m$welcome\033[0m" ; tput sgr0
}

function msg_green_wait {
echo -ne '\E[38;42m'"\033[1m$welcome\033[0m" ; tput sgr0
}

function pushmin {
echo "Last kernel pack with no mods:"
echo "$lastminpack"
echo
read -p "Push to SD card?" -n 1
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
adb push $lastminpack /sdcard/
fi
echo
read -p "Hit a key to continue.."
menu
}

function backup_menuconfig {
echo
if [ -e $kstartpath/.config ]
then
date_str=`date '+%d%m%y_%H%M%S'`
nname="config_$mnameflag_$date_str.txt"
echo "Your menuconfig information resides in .config"
echo "It will be backed up as $nname"
echo "You can change the name to config_[yournametag]_$date_str"
echo
read -p "Change the name?" -n 1
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo
read -p "Enter new nametag:"
mnameflag=$REPLY
nname="config_"$mnameflag"_"$date_str".txt"
echo "New name will be $nname"
echo
read -p "Hit a key to continue.."
fi
echo
cp $kstartpath/.config $kstartpath/$nname
if [ -e $kstartpath/$nname ]
then
echo "Current menuconfig info successfully backed up as $kstartpath/$nname"
echo
else
echo "Warning! An error occured while trying to backup .config"
echo "Read Only filesystems/permissions error?"
echo
fi
else
echo
echo "No .config information found at $kstartpath"
echo "Are you in the kernel source root directory? "
echo "Rerun script from correct location...Aborting!"
echo
fi
read -p "Hit a key to continue.."
menu
}

function pushmax {
echo "Last kernel pack with mods: "
echo "$lastmaxpack"
echo
read -p "Push to SD card?" -n 1
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
adb push $lastmaxpack /sdcard/
fi
echo
read -p "Hit a key to continue.."
menu
}

function openlast {
echo
if [ ! "$lastfolder" = "" ]
then
echo "Last output folder is $lastfolder"
echo
read -p "Open it in file manager?" -n 1
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
if [ -e /usr/bin/dolphin ]
then
echo "Opening output folder in Dolphon"
dolphin $lastfolder
elif [ -e /usr/bin/nautilus ]
then
echo "Opening output folder in Nautilus"
nautilus $lastfolder
elif [ -e /usr/local/bin/mc ]
then
echo "Opening output folder in Midnight Commander"
mc $lastfolder
else
echo "No compatible file managers found. Aborting.."
fi
fi
else
echo "There is no logged last output folder!"
echo "Compile a kernel/create flashable zips before choosing this option!!"
fi
echo
read -p "Hit a key to continue.."
menu
}

function pushzip {
echo
echo "Push last packed zips to sdcard"
echo "==============================="

if [ "$lastminpack" = "" ] && [ "$lastmaxpack" = "" ]
then
echo "Generate a zip pack before trying to push it!"
read -p "Hit a key to continue.."
menu
elif [ "$lastminpack" = "" ]
then
pushmax
elif [ "$lastmaxpack" = "" ]
then
pushmin
else
pushmin
pushmax
fi

#menu
}

function disp_kfiles {
echo
echo "Display compiled files in Kernel directory"
echo "=========================================="
echo "Current Kernel path is : $kstartpath"
cd $kstartpath
echo
echo "Locating zImage:"
echo
find . -name 'zImage' -exec echo '{}' \; to temp
echo
echo "Locating Modules:"
echo
find . -name '*.ko' -exec echo '{}' \;
read -p "Hit a key to continue.."
menu
}

function lflashery {
clear

if [ ! -d $ksource/arch ]
then
echo "The kernel location could not be located. Please re-run script from within kernel source root."
echo "Script will now terminate!"
exit 1
fi

echo " =============================================="
welcome=" FLASHABLE ZIP MAKER 1.0 by Droidzone "
msg
#echo "	FLASHABLE ZIP MAKER 1.0 by Droidzone"
echo " =============================================="
echo "Output dir is " $outdir/home/droidzone/kernel_flashable
echo "Anykernel source is at " $anykdir
echo "Kernel source is at " $ksource
echo " "
#echo -e '\E[38;42mThis prints in blue.'; tput sgr0
welcome="Creating a flashable zip in temporary location..."
msg_green
#echo "Creating a flashable zip in temporary location..."

if [ ! -d $outdir ]; then mkdir $outdir; fi
if [ ! -d $packagedir ]; then mkdir $packagedir; fi
if [ ! -d $tempdir ]; then mkdir $tempdir; fi
#Copying the new kernel files

if [ ls $outdir/*.zip > /dev/null 2>&1 ]
then
rm $outdir/*.zip
fi

if [ ls $tempdir/README > /dev/null 2>&1 ]
then
rm $tempdir/README
fi

#echo "Working in temporary directory: $tempdir"
echo
cp -a $anykdir/* $tempdir/

sync

#echo "Cleaning up remnants..."
if [ -e $outdir/kernel/zImage ]; then rm $outdir/kernel/zImage; fi

if [ ls $outdir/system/lib/modules/* > /dev/null 2>&1 ]
then
rm $outdir/system/lib/modules/*
fi

if [ -d $ksource ]
then
if [ ! -e $ksource/arch/arm/boot/zImage ]
then
echo "Kernel source location: $ksource/arch/arm/boot/zImage"

echo "zImage was not located at kernel location. Please re-run script from within kernel source root."
echo "Script will now terminate!"
exit 1
else
#echo "Copying zImage..."
cp $ksource/arch/arm/boot/zImage $outdir/kernel/
err=$?
if [ ! $err -eq 0 ]
then
echo "An error occured while copying zImage!"
echo "A flashable zip cannot be created!"
echo
read -p "Hit a key to continue!"
menu
else
echo " zImage copied"
fi
fi
else
echo "Kernel source folder: $ksource"

echo "Kernel source folder not found! Please re-run script from within kernel source root."
echo "Script will now terminate!"
exit 1
fi
cd $outdir
#echo "At temp location: $(pwd)...About to cleanup!"
#read -p "Hit a key to continue!"

#Precleaning temp folder
find . -name '*.ko' -exec rm '{}' \;
find . -name '*~' -exec rm '{}' \;
find . -name 'README*' -exec rm '{}' \;

#echo
#echo "Cleaned up the temp directory."
#echo "Temp directory contains the following modules:"
#find . -name '*.ko' -exec echo '{}' \;
#read -p "Hit a key to continue!"

cd $ksource

#find . -name '*.ko' -exec cp '{}' $outdir/system/lib/modules/ \;
#echo "Adding Network Driver..."
find . -name 'bcm4329.ko' -exec cp '{}' $outdir/system/lib/modules/ \;
if [ ! -e $outdir/system/lib/modules/bcm4329.ko ]
then
echo "WARNING! Wifi module was not compiled. Aborting.."
exit 1
else
echo " Network driver (bcm4329.ko) copied"
fi

date_str=`date '+%d%m%y_%H%M%S'`
dirname="kernel_$nameflag_$date_str"
echo
echo "Current kernel output dir name is $dirname"
echo "You can change the name to kernel_[yourname]_$date_str"
echo
read -p "Change the name?" -n 1
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
read -p "Enter new name:"
#echo "Repy is " $REPLY
nameflag=$REPLY
dirname="kernel_"$nameflag"_"$date_str
echo "New name will be $dirname"
echo
read -p "Hit a key to continue.."
fi

pckdir="$packagedir/$dirname"
mkdir $pckdir

lastfolder=$pckdir
cd $outdir/
echo
zipnoname="kbase_"$nameflag"_"$date_str
zipaddnoname="kmods_"$nameflag"_"$date_str
zipname=$zipnoname".zip"
zipaddname=$zipaddnoname".zip"
echo "Creating $zipname from $(pwd)"
zip -r $zipnoname ./
mv $zipname $pckdir/
#echo $packagedir
echo
welcome="Created flashable zip: $pckdir/$zipname"
msg_green

read -p "Push to sdcard(N/y)?" -n 1
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
lastminpack=$pckdir"/"$zipname
adb push $pckdir/$zipname /sdcard/
fi

#welcome="Make Package with Additional Modules (N/y)?"
#msg_green_wait
read -p "Make Package with Additional Modules (N/y)?" -n 1
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo
cd $ksource
echo "Kernel source is at $ksource"

#find . -name '*.ko' -exec cp '{}' $outdir/system/lib/modules/ \;
echo "Adding Additional Modules (if any)..."
echo
echo "Found the following modules:"
find . -name '*.ko' -exec echo '{}' \;
echo
read -p "Hit a key to continue!"
find . -name '*.ko' -exec cp '{}' $outdir/system/lib/modules/ \;
read -p "Copying over. Hit a key to continue!"
cd $outdir/

echo "Creating $zipaddname from $(pwd)"
zip -r $zipaddnoname ./
mv $zipaddname $pckdir/
###############################

welcome="Created a Full flashable package at $pckdir/$zipaddname"
msg
echo

read -p "Push to sdcard(N/y)?" -n 1
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
lastmaxpack=$pckdir"/"$zipname
adb push $pckdir/$zipaddname /sdcard/
fi
fi

read -p "Open Output folder in Dolphin (N/y)?" -n 1
echo
if [[ $REPLY =~ ^[Nn]$ ]]
then
menu
exit 0
else
dolphin $pckdir &
exit 0
fi
menu
exit 0
}

function menuconf {
cd $kstartpath
echo
echo "Entering Menuconfig..."
#Working on Kubuntu
#make ARCH=arm CC="arm-linux-gcc" LD="arm-linux-ld" AR="arm-linux-ar" RANLIB="arm-linux-ranlib" AS="arm-linux-as" -j10 -i all
if [ ! -e ./Makefile ]
then
echo "This script should be executed from within the root directory of kernel"
echo "Makefile could not be located in your current location. Aborting..."
exit 1
fi
make ARCH=arm CROSS_COMPILE=$toolchain menuconfig
menu
}

function defconf {
cd $kstartpath
echo
echo "Generating defconfig"
make ARCH=arm CROSS_COMPILE=$toolchain bravo_defconfig
echo "Entering Menuconfig..."
#Working on Kubuntu
#make ARCH=arm CC="arm-linux-gcc" LD="arm-linux-ld" AR="arm-linux-ar" RANLIB="arm-linux-ranlib" AS="arm-linux-as" -j10 -i all
if [ ! -e ./Makefile ]
then
echo "This script should be executed from within the root directory of kernel"
echo "Makefile could not be located in your current location. Aborting..."
exit 1
fi
make ARCH=arm CROSS_COMPILE=$toolchain menuconfig
menu
}

function cleanup {
echo
echo "Cleaning up.."
make ARCH=arm CROSS_COMPILE=$toolchain clean
read -p "Hit a key to continue.."
menu
}

function toolch {
echo
echo "Current toolchain prefix is:$toolchain"
echo "Note that script will not add paths for you. Do it manually!"
echo
read -p "Enter new toolchain (including the -):"
tempchain=$REPLY
echo
echo "New toolchain will be set as $tempchain"
read -p "Confirm (y/N)?" -n 1
if [[ $REPLY =~ ^[Yy]$ ]]
then
toolchain=$tempchain
echo
echo "New toolchain prefix is now :$toolchain"
else
echo
echo "Ok, Nothing will be modified!"
fi
read -p "Hit a key to continue.."
menu
}

function disp_path () {
echo
echo "Current PATH is :"
echo "$PATH"
echo
read -p "Hit a key to continue.."
menu
}

function findcompilestatus {
echo
welcome="Post compilation status"
msg_blue
welcome="Generated the following files:"
msg_green
cd $ksource
find . -name 'zImage' -exec echo '{}' \;
find . -name '*.ko' -exec echo '{}' \;
echo
read -p "Hit a key to continue.."
menu

}

function comp () {
echo
echo "Compiling Kernel..."
if [ ! -e ./Makefile ]
then
echo "This script should be executed from within the root directory of kernel"
echo "Makefile could not be located in your current location. Aborting..."
exit 1
fi
make ARCH=arm CROSS_COMPILE=$toolchain -j$jobs
if [ ! -e arch/arm/boot/zImage ]
then
echo "ERROR: An error occured. Kernel was not compiled."
exit 1
else
echo "Making Modules..."
echo
make ARCH=arm CROSS_COMPILE="arm-bravo-" modules
echo -en "\007"
fi
findcompilestatus
read -p "Hit a key to continue.."
menu
}

function menu () {
clear
echo
echo " ======================================================="
welcome=" Kernel Compilation Script by Droidzone 01-11-2011 "
msg
echo " ======================================================="
echo
echo " (D)efault config"
echo " (E)rase - Make Clean"
echo " (M)enuconfig"
echo " (C)ompile now"
echo " (F)lashable zip maker"
echo " (P)ush last zip to sdcard"
echo " (O)pen last output folder"
echo
echo " (Q)uit"
echo
echo " Advanced Compilation Options"
echo " ----------------------------"
echo " 1. Change Toolchain prefix (Current : $toolchain )"
echo " 2. Pick a Toolchain from menu"
echo " 3. Change Number of simultaneous jobs (Current : $jobs )"
echo " 4. Display Current path"
echo " 5. Display Kernel Files"
echo " 6. Backup Menuconfig/.config"
echo
read -p " Choose an option :" -n 1
if [[ $REPLY =~ ^[1]$ ]]
then
echo
toolch
elif [[ $REPLY =~ ^[2]$ ]]
then
echo
tcmenu
elif [[ $REPLY =~ ^[4]$ ]]
then
echo
disp_path
elif [[ $REPLY =~ ^[5]$ ]]
then
echo
disp_kfiles
elif [[ $REPLY =~ ^[6]$ ]]
then
echo
backup_menuconfig
elif [[ $REPLY =~ ^[Dd]$ ]]
then
echo
defconf
elif [[ $REPLY =~ ^[Ee]$ ]]
then
echo
cleanup
elif [[ $REPLY =~ ^[Mm]$ ]]
then
echo
menuconf
elif [[ $REPLY =~ ^[Cc]$ ]]
then
echo
comp
elif [[ $REPLY =~ ^[Ff]$ ]]
then
echo
lflashery
elif [[ $REPLY =~ ^[Pp]$ ]]
then
echo
pushzip
elif [[ $REPLY =~ ^[Oo]$ ]]
then
echo
openlast
elif [[ $REPLY =~ ^[Qq]$ ]]
then
echo
exit 0
else
menu
fi
}

function additional () {
ksource=$(pwd)
read -p "Configure Menuconfig?" -n 1
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
menuconf
fi

if [ ! -d $outdir ]; then mkdir $outdir; fi
if [ ! -d $packagedir ]; then mkdir $packagedir; fi
if [ ! -d $tempdir ]; then mkdir $tempdir; fi
#Copying the new kernel files>

if ls $outdir/*.zip > /dev/null 2>&1
then
rm $outdir/*.zip
fi

if ls $tempdir/README > /dev/null 2>&1
then
rm $tem
fi
read -p "Compile Kernel now?" -n 1
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
comp
fi

echo
echo "Kernel compilation is over.."
welcome="Generated the following files:"
msgMm
find . -name 'zImage' -exec echo '{}' \;
find . -name '*.ko' -exec echo '{}' \;
echo ""
read -p "Make Flashable zip now?" -n 1
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]
then
lflashery
fi
menu
exit 0
}

function tcmenu () {
echo
echo "Available Toolchains"
echo "===================="
echo "1. arm-bravo-"
echo "2. NDK Toolchain: arm-linux-androideabi-"
echo
echo "Currently selected toolchain: $toolchain"
echo
read -p "Pick your toolchain:" -n 1
echo
if [[ $REPLY =~ ^[1]$ ]]
then
toolchain="arm-bravo-"
elif [[ $REPLY =~ ^[2]$ ]]
then
toolchain="arm-linux-androideabi-"
else
echo "Invalid choice!"
fi
echo
echo "Currently set as toolchain :$toolchain"
echo
read -p "Hit a key to continue.."
menu
}

#Compiled toolchain:
toolchain="arm-bravo-"

#NDK
#toolchain="arm-linux-androideabi-"
jobs=50
kstartpath=$(pwd)
lastfolder=""
nameflag=""
anykdir=/home/droidzone/flasher/AnyKernel
ksource=$kstartpath
outdir=~/kernel_flashable
packagedir=/home/droidzone/flasher/outdir
tempdir=~/kernel_flashable
mnameflag=""

#Main menu
menu
exit 0