Building a toolchain for Android (Compiling an Android kernel) – crosstool-ng

Summary:

sudo apt-get install gawk bison flex texinfo automake libtool cvs curl aria2 patch lzma libncurses5-dev g++ openjdk-7-jre-headless build-essential libcloog-ppl-dev gettext help2man
cd ~/
git clone https://github.com/crosstool-ng/crosstool-ng.git
cd crosstool-ng/
./bootstrap
mkdir ../crosstoolactual
./configure --prefix=$HOME/crosstoolactual
make
make install
export PATH="${PATH}:$HOME/crosstoolactual/bin"
mkdir ~/work-dir
cd ~/work-dir
ct-ng help
ct-ng menuconfig
ct-ng build

Listing my .config here:

#
# Automatically generated file; DO NOT EDIT.
# Crosstool-NG Configuration
#
CT_CONFIGURE_has_static_link=y
CT_CONFIGURE_has_wget=y
CT_CONFIGURE_has_curl=y
CT_CONFIGURE_has_stat_flavor_GNU=y
CT_CONFIGURE_has_make_3_81_or_newer=y
CT_CONFIGURE_has_libtoolize_2_4_or_newer=y
CT_CONFIGURE_has_autoconf_2_63_or_newer=y
CT_CONFIGURE_has_autoreconf_2_63_or_newer=y
CT_CONFIGURE_has_gnu_m4_1_4_12_or_newer=y
CT_CONFIGURE_has_cvs=y
CT_CONFIGURE_has_svn=y
CT_CONFIGURE_has_git=y
CT_MODULES=y

#
# Paths and misc options
#

#
# crosstool-NG behavior
#
# CT_OBSOLETE is not set
CT_EXPERIMENTAL=y
# CT_ALLOW_BUILD_AS_ROOT is not set
# CT_DEBUG_CT is not set

#
# Paths
#
CT_LOCAL_TARBALLS_DIR="${HOME}/src"
CT_SAVE_TARBALLS=y
CT_WORK_DIR="${CT_TOP_DIR}/.build"
CT_BUILD_TOP_DIR="${CT_WORK_DIR}/${CT_HOST:+HOST-${CT_HOST}/}${CT_TARGET}"
CT_PREFIX_DIR="${CT_PREFIX:-${HOME}/x-tools}/${CT_HOST:+HOST-${CT_HOST}/}${CT_TARGET}"
CT_RM_RF_PREFIX_DIR=y
CT_REMOVE_DOCS=y
CT_PREFIX_DIR_RO=y
CT_STRIP_HOST_TOOLCHAIN_EXECUTABLES=y
# CT_STRIP_TARGET_TOOLCHAIN_EXECUTABLES is not set

#
# Downloading
#
CT_DOWNLOAD_AGENT_WGET=y
# CT_DOWNLOAD_AGENT_CURL is not set
# CT_DOWNLOAD_AGENT_NONE is not set
# CT_FORBID_DOWNLOAD is not set
# CT_FORCE_DOWNLOAD is not set
CT_CONNECT_TIMEOUT=10
CT_DOWNLOAD_WGET_OPTIONS="--passive-ftp --tries=3 -nc --progress=dot:binary"
# CT_ONLY_DOWNLOAD is not set
# CT_USE_MIRROR is not set

#
# Extracting
#
# CT_FORCE_EXTRACT is not set
CT_OVERRIDE_CONFIG_GUESS_SUB=y
# CT_ONLY_EXTRACT is not set
CT_PATCH_BUNDLED=y
# CT_PATCH_LOCAL is not set
# CT_PATCH_BUNDLED_LOCAL is not set
# CT_PATCH_LOCAL_BUNDLED is not set
# CT_PATCH_BUNDLED_FALLBACK_LOCAL is not set
# CT_PATCH_LOCAL_FALLBACK_BUNDLED is not set
# CT_PATCH_NONE is not set
CT_PATCH_ORDER="bundled"

#
# Build behavior
#
CT_PARALLEL_JOBS=0
CT_LOAD=""
CT_USE_PIPES=y
CT_EXTRA_CFLAGS_FOR_BUILD=""
CT_EXTRA_LDFLAGS_FOR_BUILD=""
CT_EXTRA_CFLAGS_FOR_HOST=""
CT_EXTRA_LDFLAGS_FOR_HOST=""
# CT_CONFIG_SHELL_SH is not set
# CT_CONFIG_SHELL_ASH is not set
CT_CONFIG_SHELL_BASH=y
# CT_CONFIG_SHELL_CUSTOM is not set
CT_CONFIG_SHELL="${bash}"

#
# Logging
#
# CT_LOG_ERROR is not set
# CT_LOG_WARN is not set
# CT_LOG_INFO is not set
CT_LOG_EXTRA=y
# CT_LOG_ALL is not set
# CT_LOG_DEBUG is not set
CT_LOG_LEVEL_MAX="EXTRA"
# CT_LOG_SEE_TOOLS_WARN is not set
CT_LOG_PROGRESS_BAR=y
CT_LOG_TO_FILE=y
CT_LOG_FILE_COMPRESS=y

#
# Target options
#
CT_ARCH="arm"
# CT_ARCH_alpha is not set
CT_ARCH_arm=y
# CT_ARCH_avr is not set
# CT_ARCH_m68k is not set
# CT_ARCH_microblaze is not set
# CT_ARCH_mips is not set
# CT_ARCH_nios2 is not set
# CT_ARCH_powerpc is not set
# CT_ARCH_s390 is not set
# CT_ARCH_sh is not set
# CT_ARCH_sparc is not set
# CT_ARCH_x86 is not set
# CT_ARCH_xtensa is not set
CT_ARCH_alpha_AVAILABLE=y
CT_ARCH_arm_AVAILABLE=y
CT_ARCH_avr_AVAILABLE=y
CT_ARCH_m68k_AVAILABLE=y
CT_ARCH_microblaze_AVAILABLE=y
CT_ARCH_mips_AVAILABLE=y
CT_ARCH_nios2_AVAILABLE=y
CT_ARCH_powerpc_AVAILABLE=y
CT_ARCH_s390_AVAILABLE=y
CT_ARCH_sh_AVAILABLE=y
CT_ARCH_sparc_AVAILABLE=y
CT_ARCH_x86_AVAILABLE=y
CT_ARCH_xtensa_AVAILABLE=y
CT_ARCH_SUFFIX=""

#
# Generic target options
#
# CT_MULTILIB is not set
CT_DEMULTILIB=y
CT_ARCH_SUPPORTS_BOTH_MMU=y
CT_ARCH_DEFAULT_HAS_MMU=y
CT_ARCH_USE_MMU=y
CT_ARCH_SUPPORTS_BOTH_ENDIAN=y
CT_ARCH_DEFAULT_LE=y
# CT_ARCH_BE is not set
CT_ARCH_LE=y
CT_ARCH_ENDIAN="little"
CT_ARCH_SUPPORTS_32=y
CT_ARCH_SUPPORTS_64=y
CT_ARCH_DEFAULT_32=y
CT_ARCH_BITNESS=64
# CT_ARCH_32 is not set
CT_ARCH_64=y

#
# Target optimisations
#
CT_ARCH_SUPPORTS_WITH_ARCH=y
CT_ARCH_SUPPORTS_WITH_CPU=y
CT_ARCH_SUPPORTS_WITH_TUNE=y
CT_ARCH_EXCLUSIVE_WITH_CPU=y
CT_ARCH_ARCH=""
CT_ARCH_CPU=""
CT_ARCH_TUNE=""
CT_TARGET_CFLAGS=""
CT_TARGET_LDFLAGS=""
CT_ARCH_FLOAT=""

#
# arm other options
#
CT_ARCH_ARM_MODE="arm"
CT_ARCH_ARM_MODE_ARM=y
# CT_ARCH_ARM_MODE_THUMB is not set
# CT_ARCH_ARM_INTERWORKING is not set
CT_ARCH_ARM_EABI_FORCE=y
CT_ARCH_ARM_EABI=y

#
# Toolchain options
#

#
# General toolchain options
#
CT_FORCE_SYSROOT=y
CT_USE_SYSROOT=y
CT_SYSROOT_NAME="sysroot"
CT_SYSROOT_DIR_PREFIX=""
CT_WANTS_STATIC_LINK=y
CT_WANTS_STATIC_LINK_CXX=y
# CT_STATIC_TOOLCHAIN is not set
CT_TOOLCHAIN_PKGVERSION=""
CT_TOOLCHAIN_BUGURL=""

#
# Tuple completion and aliasing
#
CT_TARGET_VENDOR=""
CT_TARGET_ALIAS_SED_EXPR=""
CT_TARGET_ALIAS="arm-one"

#
# Toolchain type
#
# CT_NATIVE is not set
CT_CROSS=y
# CT_CROSS_NATIVE is not set
# CT_CANADIAN is not set
CT_TOOLCHAIN_TYPE="cross"

#
# Build system
#
CT_BUILD=""
CT_BUILD_PREFIX=""
CT_BUILD_SUFFIX=""

#
# Misc options
#
# CT_TOOLCHAIN_ENABLE_NLS is not set

#
# Operating System
#
CT_KERNEL_SUPPORTS_SHARED_LIBS=y
CT_KERNEL="linux"
CT_KERNEL_VERSION="4.10.8"
# CT_KERNEL_bare_metal is not set
CT_KERNEL_linux=y
CT_KERNEL_bare_metal_AVAILABLE=y
CT_KERNEL_linux_AVAILABLE=y
# CT_KERNEL_LINUX_CUSTOM is not set
CT_KERNEL_V_4_10=y
# CT_KERNEL_V_4_9 is not set
# CT_KERNEL_V_4_4 is not set
# CT_KERNEL_V_4_1 is not set
# CT_KERNEL_V_3_16 is not set
# CT_KERNEL_V_3_12 is not set
# CT_KERNEL_V_3_10 is not set
# CT_KERNEL_V_3_4 is not set
# CT_KERNEL_V_3_2 is not set
CT_KERNEL_windows_AVAILABLE=y

#
# Common kernel options
#
CT_SHARED_LIBS=y

#
# linux other options
#
CT_KERNEL_LINUX_VERBOSITY_0=y
# CT_KERNEL_LINUX_VERBOSITY_1 is not set
# CT_KERNEL_LINUX_VERBOSITY_2 is not set
CT_KERNEL_LINUX_VERBOSE_LEVEL=0
# CT_KERNEL_LINUX_INSTALL_CHECK is not set

#
# Binary utilities
#
CT_ARCH_BINFMT_ELF=y
CT_BINUTILS="binutils"
CT_BINUTILS_binutils=y

#
# GNU binutils
#
# CT_BINUTILS_CUSTOM is not set
CT_BINUTILS_VERSION="2.28"
# CT_BINUTILS_SHOW_LINARO is not set
CT_BINUTILS_V_2_28=y
# CT_BINUTILS_V_2_27 is not set
# CT_BINUTILS_V_2_26 is not set
CT_BINUTILS_2_27_or_later=y
CT_BINUTILS_2_26_or_later=y
CT_BINUTILS_2_25_1_or_later=y
CT_BINUTILS_2_25_or_later=y
CT_BINUTILS_2_24_or_later=y
CT_BINUTILS_2_23_2_or_later=y
CT_BINUTILS_HAS_HASH_STYLE=y
CT_BINUTILS_HAS_GOLD=y
CT_BINUTILS_GOLD_SUPPORTS_ARCH=y
CT_BINUTILS_GOLD_SUPPORT=y
CT_BINUTILS_HAS_PLUGINS=y
CT_BINUTILS_HAS_PKGVERSION_BUGURL=y
CT_BINUTILS_FORCE_LD_BFD_DEFAULT=y
CT_BINUTILS_LINKER_LD=y
# CT_BINUTILS_LINKER_LD_GOLD is not set
# CT_BINUTILS_LINKER_GOLD_LD is not set
CT_BINUTILS_LINKERS_LIST="ld"
CT_BINUTILS_LINKER_DEFAULT="bfd"
# CT_BINUTILS_PLUGINS is not set
CT_BINUTILS_EXTRA_CONFIG_ARRAY=""
# CT_BINUTILS_FOR_TARGET is not set

#
# binutils other options
#

#
# C-library
#
CT_LIBC="glibc"
CT_LIBC_VERSION="2.25"
CT_LIBC_glibc=y
# CT_LIBC_musl is not set
# CT_LIBC_uClibc is not set
CT_LIBC_avr_libc_AVAILABLE=y
CT_LIBC_glibc_AVAILABLE=y
CT_THREADS="nptl"
# CT_LIBC_GLIBC_CUSTOM is not set
# CT_CC_GLIBC_SHOW_LINARO is not set
CT_LIBC_GLIBC_V_2_25=y
# CT_LIBC_GLIBC_V_2_24 is not set
# CT_LIBC_GLIBC_V_2_23 is not set
CT_LIBC_GLIBC_2_23_or_later=y
CT_LIBC_GLIBC_2_20_or_later=y
CT_LIBC_GLIBC_2_17_or_later=y
CT_LIBC_mingw_AVAILABLE=y
CT_LIBC_musl_AVAILABLE=y
CT_LIBC_newlib_AVAILABLE=y
CT_LIBC_none_AVAILABLE=y
CT_LIBC_uClibc_AVAILABLE=y
CT_LIBC_SUPPORT_THREADS_ANY=y
CT_LIBC_SUPPORT_THREADS_NATIVE=y

#
# Common C library options
#
CT_THREADS_NATIVE=y
# CT_CREATE_LDSO_CONF is not set
CT_LIBC_XLDD=y

#
# glibc other options
#
CT_LIBC_GLIBC_NEEDS_PORTS=y
CT_LIBC_glibc_family=y
CT_LIBC_GLIBC_EXTRA_CONFIG_ARRAY=""
CT_LIBC_GLIBC_CONFIGPARMS=""
CT_LIBC_GLIBC_EXTRA_CFLAGS=""
# CT_LIBC_ENABLE_FORTIFIED_BUILD is not set
# CT_LIBC_DISABLE_VERSIONING is not set
CT_LIBC_OLDEST_ABI=""
CT_LIBC_GLIBC_FORCE_UNWIND=y
CT_LIBC_ADDONS_LIST=""
# CT_LIBC_LOCALES is not set
# CT_LIBC_GLIBC_KERNEL_VERSION_NONE is not set
CT_LIBC_GLIBC_KERNEL_VERSION_AS_HEADERS=y
# CT_LIBC_GLIBC_KERNEL_VERSION_CHOSEN is not set
CT_LIBC_GLIBC_MIN_KERNEL="4.10.8"

#
# C compiler
#
CT_CC="gcc"
CT_CC_CORE_PASSES_NEEDED=y
CT_CC_CORE_PASS_1_NEEDED=y
CT_CC_CORE_PASS_2_NEEDED=y
CT_CC_gcc=y
# CT_CC_GCC_CUSTOM is not set
CT_CC_GCC_VERSION="6.3.0"
# CT_CC_GCC_SHOW_LINARO is not set
CT_CC_GCC_V_6_3_0=y
# CT_CC_GCC_V_5_4_0 is not set
# CT_CC_GCC_V_4_9_4 is not set
CT_CC_GCC_4_8_or_later=y
CT_CC_GCC_4_9_or_later=y
CT_CC_GCC_5_or_later=y
CT_CC_GCC_6=y
CT_CC_GCC_6_or_later=y
CT_CC_GCC_HAS_LIBMPX=y
CT_CC_GCC_ENABLE_CXX_FLAGS=""
CT_CC_GCC_CORE_EXTRA_CONFIG_ARRAY=""
CT_CC_GCC_EXTRA_CONFIG_ARRAY=""
CT_CC_GCC_STATIC_LIBSTDCXX=y
# CT_CC_GCC_SYSTEM_ZLIB is not set
CT_CC_GCC_CONFIG_TLS=m

#
# Optimisation features
#
CT_CC_GCC_USE_GRAPHITE=y
CT_CC_GCC_USE_LTO=y

#
# Settings for libraries running on target
#
CT_CC_GCC_ENABLE_TARGET_OPTSPACE=y
# CT_CC_GCC_LIBMUDFLAP is not set
# CT_CC_GCC_LIBGOMP is not set
# CT_CC_GCC_LIBSSP is not set
# CT_CC_GCC_LIBQUADMATH is not set
# CT_CC_GCC_LIBSANITIZER is not set

#
# Misc. obscure options.
#
CT_CC_CXA_ATEXIT=y
# CT_CC_GCC_DISABLE_PCH is not set
CT_CC_GCC_SJLJ_EXCEPTIONS=m
CT_CC_GCC_LDBL_128=m
# CT_CC_GCC_BUILD_ID is not set
CT_CC_GCC_LNK_HASH_STYLE_DEFAULT=y
# CT_CC_GCC_LNK_HASH_STYLE_SYSV is not set
# CT_CC_GCC_LNK_HASH_STYLE_GNU is not set
# CT_CC_GCC_LNK_HASH_STYLE_BOTH is not set
CT_CC_GCC_LNK_HASH_STYLE=""
CT_CC_GCC_DEC_FLOAT_AUTO=y
# CT_CC_GCC_DEC_FLOAT_BID is not set
# CT_CC_GCC_DEC_FLOAT_DPD is not set
# CT_CC_GCC_DEC_FLOATS_NO is not set
CT_CC_SUPPORT_CXX=y
CT_CC_SUPPORT_FORTRAN=y
CT_CC_SUPPORT_JAVA=y
CT_CC_SUPPORT_ADA=y
CT_CC_SUPPORT_OBJC=y
CT_CC_SUPPORT_OBJCXX=y
CT_CC_SUPPORT_GOLANG=y

#
# Additional supported languages:
#
CT_CC_LANG_CXX=y
# CT_CC_LANG_FORTRAN is not set
# CT_CC_LANG_JAVA is not set
# CT_CC_LANG_ADA is not set
# CT_CC_LANG_OBJC is not set
# CT_CC_LANG_OBJCXX is not set
# CT_CC_LANG_GOLANG is not set
CT_CC_LANG_OTHERS=""

#
# Debug facilities
#
# CT_DEBUG_duma is not set
# CT_DEBUG_gdb is not set
# CT_DEBUG_ltrace is not set
# CT_DEBUG_strace is not set

#
# Companion libraries
#
CT_COMPLIBS_NEEDED=y
CT_LIBICONV_NEEDED=y
CT_GETTEXT_NEEDED=y
CT_GMP_NEEDED=y
CT_MPFR_NEEDED=y
CT_ISL_NEEDED=y
CT_MPC_NEEDED=y
CT_NCURSES_NEEDED=y
CT_COMPLIBS=y
CT_LIBICONV=y
CT_GETTEXT=y
CT_GMP=y
CT_MPFR=y
CT_ISL=y
CT_MPC=y
CT_NCURSES=y
# CT_ZLIB is not set
CT_LIBICONV_V_1_15=y
# CT_LIBICONV_V_1_14 is not set
CT_LIBICONV_VERSION="1.15"
CT_GETTEXT_V_0_19_8_1=y
CT_GETTEXT_VERSION="0.19.8.1"
CT_GMP_V_6_1_2=y
CT_GMP_5_0_2_or_later=y
CT_GMP_VERSION="6.1.2"
CT_MPFR_V_3_1_5=y
CT_MPFR_VERSION="3.1.5"
CT_ISL_V_0_18=y
# CT_ISL_V_0_17_1 is not set
# CT_ISL_V_0_16_1 is not set
# CT_ISL_V_0_15 is not set
CT_ISL_V_0_16_or_later=y
CT_ISL_V_0_15_or_later=y
CT_ISL_V_0_14_or_later=y
CT_ISL_V_0_12_or_later=y
CT_ISL_VERSION="0.18"
CT_MPC_V_1_0_3=y
CT_MPC_VERSION="1.0.3"
CT_NCURSES_V_6_0=y
CT_NCURSES_VERSION="6.0"
# CT_NCURSES_NEW_ABI is not set
CT_NCURSES_HOST_CONFIG_ARGS=""
CT_NCURSES_HOST_DISABLE_DB=y
CT_NCURSES_HOST_FALLBACKS="linux,xterm,xterm-color,xterm-256color,vt100"
CT_NCURSES_TARGET_CONFIG_ARGS=""
# CT_NCURSES_TARGET_DISABLE_DB is not set
CT_NCURSES_TARGET_FALLBACKS=""

#
# Companion libraries common options
#
# CT_COMPLIBS_CHECK is not set

#
# Companion tools
#
# CT_COMP_TOOLS_FOR_HOST is not set
# CT_COMP_TOOLS_autoconf is not set
CT_COMP_TOOLS_automake=y
CT_AUTOMAKE_V_1_15=y
CT_AUTOMAKE_VERSION="1.15"
CT_COMP_TOOLS_libtool=y
CT_LIBTOOL_V_2_4_6=y
CT_LIBTOOL_VERSION="2.4.6"
# CT_COMP_TOOLS_m4 is not set
# CT_COMP_TOOLS_make is not set

#
# Test suite
#
# CT_TEST_SUITE_GCC is not set

For compiling anything on Android, you need a good toolchain to cross compile files. To just compile a kernel, you may try using the precompiled toolchain that comes with Android NDK (easy way out). However that one is not optimized for your machine. Neither does it have many prerequisites required if you want to compile other Linux binaries like dosfstools, Over the course of your Android development life, you’ll find yourself missing many linux utilities on Android and will not even find precompiled versions online. So you need to be able to build Linux utilites which can work on your phone too (cross compiling).

Thanks to Ahmet Ipkin (TheGanymedes on XDA), you now have a good guide to making a toolchain for Android. My post is based entirely on his original post, and I urge you to read his opening post completely to understand the details. If it helped you, please consider a paypal donation to him. I will be quoting his post on the actual guide to compile a toolchain, after I add some notes that I felt needed to be inserted to help newbies. ūüôā

Prerequisites:

sudo apt-get install gawk bison flex texinfo automake libtool cvs curl aria2 patch lzma libncurses5-dev g++ openjdk-7-jre-headless build-essential libcloog-ppl-dev gettext

To debug issues, it is good to watch the build.log

 

tail -f /home/droidzone/x-tools/arm-msm-linux-gnueabi/build.log

 

Some Notes:

List of Toolchain Options: (Also includes Compatibility Table for different tool versions)

https://docs.google.com/spreadsheet/pub?hl=en_US&hl=en_US&key=0Amlyrhh3vKt7dF9COXVCdTc4VzJ1eGtWSWZueFB4MWc&output=html

Sources for tarballs:

I found that ct-ng allowed you to select only very old versions of included requirements like gcc. So I downloaded them from:

http://ftp.gnu.org/gnu/gcc/  for gcc

http://ftp.gnu.org/gnu/binutils/

http://ftp.gnu.org/gnu/gmp/

http://ftp.gnu.org/gnu/glibc/

http://ftp.gnu.org/gnu/gmp/

http://ftp.gnu.org/gnu/mpfr/

Libelf from http://www.mr511.de/software/

 

Note that once you add them, you have to go to the actual source dir of ct-ng from where you execute ./configure, and execute the following cmd lines:

Adding Latest Versions of Included software

./scripts/addToolVersion.sh --binutils -s -c 2.20.1a
./scripts/addToolVersion.sh --gcc -s -c 4.6.1
./scripts/addToolVersion.sh --glibc -s -c 2.1.3

Note that after you do this, you have to run

./configure --prefix="path to dir where you will be building ct-ng"
make install
cd [to dir where you will make ct-ng"
./ct-ng menuconfig
./ct-ng build

Then, moving to the tarballs dir, wget the latest packages…

wget http://ftp.gnu.org/gnu/glibc/glibc-2.1.3.tar.gz
wget http://ftp.gnu.org/gnu/gcc/gcc-4.6.1/gcc-4.6.1.tar.bz2
wget http://ftp.gnu.org/gnu/binutils/binutils-2.20.1a.tar.bz2
wget http://ftp.gnu.org/gnu/glibc/glibc-2.1.3.tar.gz
wget http://www.mr511.de/software/libelf-0.8.13.tar.gz

Errors I got while building:

Tip: The first time you build, it is good to check the following options:

Menuconfig>Paths and Misc options:

[x]Debug crosstool-ng
[x]Save intermediary steps

This will allow you to continue without redoing the steps which succeeded!

 

  • Error: Installing C library headers,¬†Linux version is unavailable in installed headers files
Installing C library headers
[ERROR] Linux version is unavailable in installed headers files
[ERROR] Build failed in step 'Installing C library headers'
[ERROR] Error happened in '/home/droidzone/ct-ng/lib/ct-ng-1.9.3/scripts/build/libc/glibc.sh' in function 'do_libc_headers' (line unknown, sorry)
[ERROR] called from '/home/droidzone/ct-ng/lib/ct-ng-1.9.3/scripts/crosstool-NG.sh' at line # 597 in function 'main'

According to TheGanymedes, the solution is:

It shows that it couldn’t validate version of the linux kernel. Just open a terminal, go to the kernel directory and write “make ARCH=arm menuconfig”. After writing this, look through all options – you shall find one that allows you to pick your board model, cpu model etc. Pick board model as Qualcomm/msm and as cpu model pick qsd8x50. Sorry that I don’t know the exact names of the options.

After this, quit from that menu with esc-esc keys, and save config. The other options are unnecessary, just board and cpu type is all we need.

Now, write make ARCH=arm CROSS_COMPILE=arm-linux- . It’s going to fail, but will create the necessary version files and this was all we need. Now you can use crosstool-ng.

This is the location to find those options:

System type>ARM System type> Qualcomm MSM/QSD
Qualcomm MSM Soc tyoe: QSD8x50
  • Error: Errors with PPL/CLOOG. This was a tough one, since TheGanymedes forgot to mention that this would happen. ;). This is apparently (according to him) because ct-ng for some reason cannot build PPL/CLOOG. For this, you have to disable Graphite loop optimizations. Only then will ct-ng build
C compiler> Untick “Enable Graphite loop optimizations”
  • Error: Other errors with specific components. This may occur if your net connection is crappy and downloads files. In these cases, though the error message may be rather obscure, you can usually find out what step it failed at, by examining the file ~/x-tools/crosscompilername/.build/build.log. Note that .build is a hidden folder.
  • Error: [ERROR]¬† Build failed in step ‘Retrieving needed toolchain components’ tarballs’ called in step ‘(top-level)’
    • Now, this is a rather obscure issue which happened both on my local system and on the ssh at sourceforge. The reason was the compiler trying to create a symbolic link that already existed.
    • Solution: Go to ct-ng dir where you execute ./ct-ng build. Within it, do an rm -rf ./build/* ; rmdir ./build
  • Workarounds for getting crosstool itself to build under an ssh environment. The issue was that many dependencies of ct-ng, like autoconf, automake, lzma, texinfo (makeinfo) are not installed on the target system and we have no way of using aptitude. So the solution is to build all these utilities from source. A nice hint to do this to:
    • mkdir -p ~/bin
    • Add a path to your ~/.bashrc, and add the line: PATH=$PATH:~/bin:~/bin/bin
    • Now, configure each dependency while building with: ./configure –prefix=/absolutepath_to_$HOME/bin. Note that instead of building binaries in ~/bin, this builds them in ~/bin/bin. This is a good substitution when you dont have Write rights to /usr/bin (cant do a ‘sudo make install’).
    • Then, make
    • make install. Make install will install to $HOME/bin/bin ūüôā

 

The following is a quote of TheGanymedes’s post at XDA. All credits to him.

NOTE
Before you start anything, don’t forget to install build-essentials package. Under ubuntu, the command necessary for it is:sudo apt-get install build-essential¬†– I don’t know about other distros..

 

————————-

Well, as promised, now we should write the steps; right?… Now, before we begin, I should really warn that the process is really head spinning if you’re to do all by yourself; so take heed to the warnings I give you (I learned the hard way)¬†

Well, first thing is first, we need a Cross Compiler Toolchain, properly built that allows us to build applications, libraries etc. There is one toolchain that’s already given to you with Android Native Development Kit (called NDK) but that one is quite restricted because it’s built with support for Bionic (trimmed C library that is presented in Android), not Glibc or uGlibC. If you want to develop more native-like applications (especially linux programs) you need GlibC or uGlibC. You can try to build these libraries with that toolchain too, but don’t do that, because it’s going to fail as well. The reason is that some sort of Chicken-Egg problem is eminent in GlibC-GCC compilation¬†

Let’s put the steps to be followed first to build a nice toolchain. I assume you’re using Linux – because the tools are developed for this platform only. If you’re going to use them in Windows, you need Cygwin or such tools but I can’t supply help about that, for since I didn’t use them before at all. Google is your friend about this¬†

(Note, the packages I wrote at this list are available at GNU’s website¬†www.gnu.org¬†freely, open source)
1- We’re going to build “binutils” first. This package includes some important stuff like assembler, linker, archiver (for libraries) etc..
2- We’re going to build GCC’s prerequisites. These are GMP, MPRF and MPC packages.
3- We’re going to build a “bootstap” gcc (God, I hate that name. I like to call it “naked gcc” more¬†¬†). This GCC just converts source codes to pure assemblies: thus cannot generate linkages or such. We’re going to use it to build “actual” tools we’re going to use.
4- We’re going to extract Kernel source/headers – use Desire Kernel’s here. There is some copying, and such to be done tho.
5- We’re going to make GlibC headers installed, which will allow us to build more “complex” gcc, which can link applications with those libraries when the library binaries are given (so such thing is there yet, but we fool it¬†¬†)
6- We’re going to build a very limited GlibC which will give us support for building more “complex” gcc.
7- We’re going to build GCC again. This is called “Pass 1 GCC” or “GCC Stage 1”. This GCC can link applications to libraries, with the information in Kernel headers and library headers (it’s why we give it the headers, so it can create applications suitable with the Kernel architecture).
8- We’re to build actual GlibC now. This glibC will be used for our compiled applications, statically or dynamically. You can, at the end of this step, copy the files to your devices and they would work, but picking files here is harder, so I’d recommend you to leave this alone for now¬†
9- We’re going to build “Pass 2 GCC” or “GCC Step 2” This is a full fledged GCC that can do anything we want¬†

Complex isn’t it? This is precisely why I recommend you to use¬†Crostool-NG. The other tools (like Buildtools or Crosstool) (sadly) don’t create GlibC based toolchains, or use old versions of them, so using this one is recommended. This package automatically will download, setup and link your all toolchain without you worrying about something (believe me, this is what you need. I gave 8 days without this to create a working GCC and Crosstool-NG made another one to me in 50 minutes.¬†¬†)

Well, however, Crosstool-NG won’t create “nice” applications (they’ll run allright, but they won’t be optimized) without some settings done, so, let’s go there. First, we need to install Crosstool-NG itself. To do that; go to¬†http://crosstool-ng.org/website, download and extract it to some place. Even though the steps are written in Crosstool website, you don’t need all commands there (like setting PATH is unnecessary). The commands you should use is, after CD’ing to the Crosstool dir;

./configure –prefix=”</some/place>”
make
make install
cd “</some/place/bin>”
./ct-ng menuconfig

I used prefix as /home/ahmet/crosstool for instance. Note that this is not going to be where your toolchain is, this is where your “toolchain creator” is¬†.
—- NECESSARY KERNEL HEADER CHANGES —-

OK now, before we start compiling; we need to make some folder moving, copying etc. in Kernel directory. This is needed, because tree structure changed a tad in 2.6 kernels and unless you compiled this kernel before, some directories won’t be in their correct place for our cross compiler. Switch to the directory which you extracted the kernel image. Now, from now on, I’m going to assume you’re an Qualcomm/MSM board (like Desire, Nexus One etc.) user; but if you’re not, change my descriptions accordingly:

1- Go to <kernel dir>/arch/arm/include folder. Copy “asm” directory and paste it into <kernel dir>/include directory.
2- Go to <kernel dir>/arch/arm/mach-msm/include folder. Copy “mach” directory and paste it to <kernel dir>/include/asm directory. It’s going to complain that there is another mach folder there and will ask if you want to merge/overwrite. Say yes to all questions.

Now our kernel headers folder is showing a Desire device. Note that if you’re not a Desire user, you should use your cpu folder instead of ARM and your board manufacturer in mach-xxxxx instead of mach-msm.

Note this kernel directory, we’re going to use it to configure crosstool..

— CONFIGURING CROSSTOOL —

After issuing the commands, the crosstool-ng will give you a configuration menu. Most of the setting here are unchanged, but the ones you should change are given below.

1- Paths and misc options
a) Try features marked as EXPERIMENTAL (this is needed to build a toolchain with the latest GlibC support) -> Enabled
b) Local Tarballs directory -> The folder address that you want downloaded stuff to be kept. You might use them again (like for compiling GlibC again for device, you will use them 
c) Save New Tarballs -> Enabled ( so that new downloaded files aren’t erased¬†¬†)
d) Working Directory and Prefix directory -> Normally you don’t have to change them, but you can if you want to install your toolchain to some other location. CT_TARGET signifies your target name (like arm-msm-linux-gnueabi – arm is cpu model, msm is vendor (can be anything), linux is showing the binaries are for linux system (you can use android, but then you’ll get not GlibC but Bionic) and gnueabi shows you’re going to use open-source EABI structure for your executables. The other option is ELF but EABI is more flexible (because also supports ELF).
e) Strip all toolchain executables -> do it if you don’t want to debug GCC itself. this makes toolchain smaller of size, and a tad faster.

The other options can stay the way they are, or you can change them accordingly here. You can get help with ? key, and if you don’t understand anything, just leave them default – there are very complex things there that you don’t need to know if you’re not planning to be a expert on subject¬†

2- Target options
a) Target Architecture -> arm should be selected, cos Desire uses ARM. If you plan to make toolchain for, say, powerpc, pick that.
b) Endianness -> Should be little. ARM processors in Desire uses little endian system.
c) Architecture level -> “armv7-a” this is should be written. Desire uses ARMv7 based instructions and if you leave here empty, the applications will be built with armv5 support – they’re still going to run but not use advanced v7 features.
d) Use Specific FPU -> “neon” . Desire uses NEON structure for floating point arithmetic, and if you leave here empty, the applications will not use Desire’s FPU abilities (everything will be software based, which is slower)
e) Default instruction set mode -> arm . You can use thumb here for allegedly faster code but not every build system supports it. Leave it ARM.
f) Use EABI -> enabled. EABI is necessary for most flexible desing of binaries.

The other settings be as they were.

3- Toolchain options
a) Tuple’s vendor string -> You can leave here empty if you don’t want to; it’s not necessary to use a string here. I used “msm” but you can write anything. This string here is used in toolchain name as arm-xxxxx-linux-gnueabi, so make it short, I recommend¬†
b) Tuple’s alias -> make it something short like “arm-linux” This alias string is used to make calls to your toolchain easier. Instead of writing arm-msm-linux-gnueabi-gcc everytime, you can use arm-linux-gcc to compile your applications. Can write anything here (like toolchain if you want to use toolchain-gcc to compile your applications)

The other settings can stay as they are, for since default values are the best in our case. You can tweak them only if you know Desire cpu like the back of your hand 

4- Operating system
a) Target OS -> Use “linux” if you want the applications to run in Android and Linux; use “bare metal” if you’re to compile low level applications which won’t use linux headers. Default is linux.
b) Get Kernel headers from -> say “pre installed” because otherwise it’s going to download standard Linux headers from internet. We needed some changes, so this option is compulsory to be “pre installed”
c) Path to custom headers directory/tarball -> Path to your kernel source folder – which you made changes above.WARNING:¬†I say specifically extracted, because standart tarball won’t work for us. We’re going to make some changes in kernel directories, which is non-standart (Instructions were above).
d) This is a tarball -> No . We’re going to use extracted folder.
e) Build shared libraries -> say “yes”; because we want dynamic linkage, not static one¬†
f) Check kernel headers -> say “no” otherwise some unnecessary check causes compilation to stop.

5- Binary utilities
a) Binutils version – pick the latest one, 2.20.1a. If you use older versions with newer GCC/GlibC, it’s not going to succeed.

Leave others as they are, they are not big deal..

6- C Compiler
a) GCC Version -> pick 4.6.1 for since it’s the latest and most bug free. Just stay away from 4.5¬†
b) Pick the languages you want support for. I’ve read online that Java is a tad troublesome in Android platform, for since Java in Android uses Dalvik, not Sun systems. You can try it at your second toolchain if you want¬†¬†Definitely pick C++ tho
c) Link libstdc++ statically -> say yes; it really saves you from big configure scripts later  Рapparently needed to avoid PPL problems as well 
d) Compile lidmudflap/libgomp/libssp -> say no. These libraries are not the most suitable libraries for ARM platform (at least at cross-compiler level. You can compile them later, if you want, with your cross-toolchain.)

You can leave others as default

7- C library
a) C library -> gLibC (recommended). You can use other libraries which are eGlibC (embedded Glibc, like Bionic) and uGlibC (micro-glibc) too, but GlibC is the most spanning solution above those. The libraries are bigger, but they support more.
b) glibC version -> Use 2.13 (experimental) it compiles just fine, and you get a new version of GlibC. Not the newest, but that’s ok¬†
c) Threading implementation -> nptl (recommended) . You can use linuxthreads too, but nptl is more advanced ( like giving support to Thread-Local-Storage and such)
d) Force Unwind Support¬†-> Enabled . If you don’t use this option, for since we’re making this toolchain from scratch, it’s going to give you error during compiling that it couldn’t find necessary headers (we’re building them now, dumbass!)

Leave others default if you don’t know what they’re about

8- Companion Libraries
Well, go and pick the latest versions, even though when it says “Experimental”, otherwise your GCC compilation will give you error about these libraries being old.

After setting these settings, press ESC key twice till it goes way back and ask if you want to save configuration; say yes.

— STARTING COMPILATION —
Now to start compilation write
./ct-ng build.

This is going to take approx. 45 minutes, so go watch some episodes of Big Bang Theory or something. Normally, there should be no errors but if there is; most probably either you made a wrong configuration, or didn’t set your kernel folders well. Try again with other settings, google your problem etc..¬†

After this process, you’re going to have a cross-compiler at your use at /home/<username>/x-tool/arm-<vendor>-linux-gnueabi/bin folder. Note that Crosstool-NG automatically makes this folder read only to make you prevent screwing your toolchain¬†¬†You must edit your path variable to show “/home/<username>/x-tool/arm-<vendor>-linux-gnueabi/bin” folder as well for less headaches during compiling later¬†

Whilst compiling other application, most used configure options you’re going to use is “–host=arm-<vendor>-linux-gnueabi” and “–prefix=/some/folder/you/want/this/application/copied”. After compilation, you can send binaries to your phone from prefix folder.

More options about GCC and Configure is available at GCC and Autoconf man pages; check them as well 

Happy cross-compiling people 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Install qt3 for make xconfig

sudo apt-get install qt3-dev-tools[/code]


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Kernel compilation error – ‘BRAVO_TPS65023_MAX_UV_MV’ undeclared (first use in this function)

arch/arm/mach-msm/avs.c: In function 'avs_update_voltage_table':
arch/arm/mach-msm/avs.c:231:22: error: 'BRAVO_TPS65023_MAX_UV_MV' undeclared (first use in this function)
arch/arm/mach-msm/avs.c:231:22: note: each undeclared identifier is reported only once for each function it appears in
arch/arm/mach-msm/avs.c:246:38: error: 'BRAVO_TPS65023_MIN_UV_MV' undeclared (first use in this function)
arch/arm/mach-msm/avs.c: In function 'avs_get_target_voltage':
arch/arm/mach-msm/avs.c:276:46: error: 'BRAVO_TPS65023_MAX_UV_MV' undeclared (first use in this function)
arch/arm/mach-msm/avs.c: In function 'avs_init':
arch/arm/mach-msm/avs.c:437:24: error: 'BRAVO_TPS65023_MAX_UV_MV' undeclared (first use in this function)
make[1]: *** [arch/arm/mach-msm/avs.o] Error 1
make[1]: *** Waiting for unfinished jobs....
LD lib/zlib_inflate/zlib_inflate.o
LD lib/zlib_inflate/built-in.o
LD lib/zlib_deflate/zlib_deflate.o
LD lib/zlib_deflate/built-in.o
LD lib/built-in.o
AR lib/lib.a
make: *** [arch/arm/mach-msm] Error 2[/code]

This only meant that arch/arm/mach-msm/board-bravo.h wasnt modified to include this declaration!


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Kernel compilation error – Undefined reference to `swap_info’

mm/built-in.o: In function `frontswap_curr_pages':
/home/droidzone/android/kernel/banana/bravo_2.6.35_gb-mr/mm/frontswap.c:235: undefined reference to `swap_list'
/home/droidzone/android/kernel/banana/bravo_2.6.35_gb-mr/mm/frontswap.c:235: undefined reference to `swap_info'
mm/built-in.o: In function `frontswap_shrink':
/home/droidzone/android/kernel/banana/bravo_2.6.35_gb-mr/mm/frontswap.c:207: undefined reference to `try_to_unuse'
/home/droidzone/android/kernel/banana/bravo_2.6.35_gb-mr/mm/frontswap.c:214: undefined reference to `swap_list'
/home/droidzone/android/kernel/banana/bravo_2.6.35_gb-mr/mm/frontswap.c:214: undefined reference to `swap_info'
mm/built-in.o: In function `__frontswap_put_page':
/home/droidzone/android/kernel/banana/bravo_2.6.35_gb-mr/mm/frontswap.c:104: undefined reference to `swap_info'
mm/built-in.o: In function `__frontswap_get_page':
/home/droidzone/android/kernel/banana/bravo_2.6.35_gb-mr/mm/frontswap.c:125: undefined reference to `swap_info'
mm/built-in.o: In function `__frontswap_flush_page':
/home/droidzone/android/kernel/banana/bravo_2.6.35_gb-mr/mm/frontswap.c:139: undefined reference to `swap_info'
mm/built-in.o: In function `__frontswap_flush_area':
/home/droidzone/android/kernel/banana/bravo_2.6.35_gb-mr/mm/frontswap.c:153: undefined reference to `swap_info'
make: *** [.tmp_vmlinux1] Error 1
ERROR: An error occured. Kernel was not compiled.[/code]

Disable the following options in menuconfig:
Kernel Features>Enable frontswap driver, Enable Cachecleaner driver


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Adding a new CPU governor

Let’s suppose that we want to add the two governors Smartass and Interactive. Your first step is to locate the required source code for the same class of CPU.

Next, add the source code for the governor. Eg: drivers/cpufreq/cpufreq_interactive.c and drivers/cpufreq/cpufreq_smartass.c

Then add the choice for menuconfig to drivers/cpufreq/Kconfig:

config CPU_FREQ_DEFAULT_GOV_INTERACTIVE
bool "interactive"
select CPU_FREQ_GOV_INTERACTIVE
help
Use the CPUFreq governor 'interactive' as default. This allows
you to get a full dynamic cpu frequency capable system by simply
loading your cpufreq low-level hardware driver, using the
'interactive' governor for latency-sensitive workloads.[/code]

OR

config CPU_FREQ_DEFAULT_GOV_SMARTASS
bool "smartass"
select CPU_FREQ_GOV_SMARTASS
select CPU_FREQ_GOV_PERFORMANCE
help
Use the CPUFreq governor 'smartass' as default.[/code]

and
drivers/cpufreq/Kconfig

config CPU_FREQ_GOV_SMARTASS
tristate "'smartass' cpufreq governor"
depends on CPU_FREQ
help
smartass' - a "smart" optimized governor![/code]

OR

config CPU_FREQ_GOV_SMARTASS2
tristate "'smartass2' cpufreq policy governor"
help
'smartassV2' - a "smart" governor[/code]

 

If in doubt, say N.

Then, the rules to compile the source code, in Makefile

obj-$(CONFIG_CPU_FREQ_GOV_SMARTASS) += cpufreq_smartass.o[/code]

Then, the definitions in the header file include/linux/cpufreq.h

#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_SMARTASS)[/code]

extern struct cpufreq_governor cpufreq_gov_smartass;

#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_smartass)

 

After adding these, dont forget to enable them in CPU Power Management tab of menuconfig
While compiling, check whether the .o file for the particular freq is being made. Otherwise, it may mean you have forgotten to add the rules in the drivers/cpufreq/Kconfig file

Enabling HAVS:
Dont forget:
System type:
QSD Static Voltage Scaling
PMIC default output voltage
Enable Adaptive Voltage Scaling (AVS)

How does it work?

driver/cpufreq/Kconfig contains menuitems for adding to .config. Based on the selection of these items when menuconfig is done, at build it looks for these rules within the header files located in include/linux/cpufreq.h

include/linux/cpufreq.h

/*********************************************************************
* CPUFREQ DEFAULT GOVERNOR *
*********************************************************************/

/*
Performance governor is fallback governor if any other gov failed to
auto load due latency restrictions
*/
#ifdef CONFIG_CPU_FREQ_GOV_PERFORMANCE
extern struct cpufreq_governor cpufreq_gov_performance;
#endif
#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE
#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_performance)
#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE)
extern struct cpufreq_governor cpufreq_gov_powersave;
#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_powersave)
#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE)
extern struct cpufreq_governor cpufreq_gov_userspace;
#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_userspace)
#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND)
extern struct cpufreq_governor cpufreq_gov_ondemand;
#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_ondemand)
#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE)
extern struct cpufreq_governor cpufreq_gov_conservative;
#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_conservative)
#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_INTERACTIVE)
extern struct cpufreq_governor cpufreq_gov_interactive;
#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_interactive)
#endif[/code]

drivers/cpufreq/Kconfig

config CPU_FREQ
bool "CPU Frequency scaling"
help
CPU Frequency scaling allows you to change the clock speed of
CPUs on the fly. This is a nice method to save power, because
the lower the CPU clock speed, the less power the CPU consumes.

Note that this driver doesn't automatically change the CPU
clock speed, you need to either enable a dynamic cpufreq governor
(see below) after boot, or use a userspace tool.

For details, take a look at .

If in doubt, say N.

if CPU_FREQ

config CPU_FREQ_TABLE
tristate

config CPU_FREQ_DEBUG
bool "Enable CPUfreq debugging"
help
Say Y here to enable CPUfreq subsystem (including drivers)
debugging. You will need to activate it via the kernel
command line by passing
cpufreq.debug=

To get , add
1 to activate CPUfreq core debugging,
2 to activate CPUfreq drivers debugging, and
4 to activate CPUfreq governor debugging

config CPU_FREQ_STAT
tristate "CPU frequency translation statistics"
select CPU_FREQ_TABLE
default y
help
This driver exports CPU frequency statistics information through sysfs
file system.

To compile this driver as a module, choose M here: the
module will be called cpufreq_stats.

If in doubt, say N.

config CPU_FREQ_STAT_DETAILS
bool "CPU frequency translation statistics details"
depends on CPU_FREQ_STAT
help
This will show detail CPU frequency translation table in sysfs file
system.

If in doubt, say N.

choice
prompt "Default CPUFreq governor"
default CPU_FREQ_DEFAULT_GOV_USERSPACE if CPU_FREQ_SA1100 || CPU_FREQ_SA1110
default CPU_FREQ_DEFAULT_GOV_PERFORMANCE
help
This option sets which CPUFreq governor shall be loaded at
startup. If in doubt, select 'performance'.

config CPU_FREQ_DEFAULT_GOV_PERFORMANCE
bool "performance"
select CPU_FREQ_GOV_PERFORMANCE
help
Use the CPUFreq governor 'performance' as default. This sets
the frequency statically to the highest frequency supported by
the CPU.

config CPU_FREQ_DEFAULT_GOV_POWERSAVE
bool "powersave"
depends on EMBEDDED
select CPU_FREQ_GOV_POWERSAVE
help
Use the CPUFreq governor 'powersave' as default. This sets
the frequency statically to the lowest frequency supported by
the CPU.

config CPU_FREQ_DEFAULT_GOV_USERSPACE
bool "userspace"
select CPU_FREQ_GOV_USERSPACE
help
Use the CPUFreq governor 'userspace' as default. This allows
you to set the CPU frequency manually or when a userspace
program shall be able to set the CPU dynamically without having
to enable the userspace governor manually.

config CPU_FREQ_DEFAULT_GOV_ONDEMAND
bool "ondemand"
select CPU_FREQ_GOV_ONDEMAND
select CPU_FREQ_GOV_PERFORMANCE
help
Use the CPUFreq governor 'ondemand' as default. This allows
you to get a full dynamic frequency capable system by simply
loading your cpufreq low-level hardware driver.
Be aware that not all cpufreq drivers support the ondemand
governor. If unsure have a look at the help section of the
driver. Fallback governor will be the performance governor.

config CPU_FREQ_DEFAULT_GOV_CONSERVATIVE
bool "conservative"
select CPU_FREQ_GOV_CONSERVATIVE
select CPU_FREQ_GOV_PERFORMANCE
help
Use the CPUFreq governor 'conservative' as default. This allows
you to get a full dynamic frequency capable system by simply
loading your cpufreq low-level hardware driver.
Be aware that not all cpufreq drivers support the conservative
governor. If unsure have a look at the help section of the
driver. Fallback governor will be the performance governor.

config CPU_FREQ_DEFAULT_GOV_INTERACTIVE
bool "interactive"
select CPU_FREQ_GOV_INTERACTIVE
help
Use the CPUFreq governor 'interactive' as default. This allows
you to get a full dynamic cpu frequency capable system by simply
loading your cpufreq low-level hardware driver, using the
'interactive' governor for latency-sensitive workloads.

config CPU_FREQ_DEFAULT_GOV_SMARTASS2
bool "smartass2"
select CPU_FREQ_GOV_SMARTASS2
help
Use the CPUFreq governor 'smartass2' as default. This allows
you to get a full dynamic cpu frequency capable system by simply
loading your cpufreq low-level hardware driver, using the
'interactive' governor for latency-sensitive workloads.

endchoice

config CPU_FREQ_GOV_PERFORMANCE
tristate "'performance' governor"
help
This cpufreq governor sets the frequency statically to the
highest available CPU frequency.

To compile this driver as a module, choose M here: the
module will be called cpufreq_performance.

If in doubt, say Y.

config CPU_FREQ_GOV_POWERSAVE
tristate "'powersave' governor"
help
This cpufreq governor sets the frequency statically to the
lowest available CPU frequency.

To compile this driver as a module, choose M here: the
module will be called cpufreq_powersave.

If in doubt, say Y.

config CPU_FREQ_GOV_USERSPACE
tristate "'userspace' governor for userspace frequency scaling"
help
Enable this cpufreq governor when you either want to set the
CPU frequency manually or when a userspace program shall
be able to set the CPU dynamically, like on LART
.

To compile this driver as a module, choose M here: the
module will be called cpufreq_userspace.

For details, take a look at .

If in doubt, say Y.

config CPU_FREQ_GOV_ONDEMAND
tristate "'ondemand' cpufreq policy governor"
select CPU_FREQ_TABLE
help
'ondemand' - This driver adds a dynamic cpufreq policy governor.
The governor does a periodic polling and
changes frequency based on the CPU utilization.
The support for this governor depends on CPU capability to
do fast frequency switching (i.e, very low latency frequency
transitions).

To compile this driver as a module, choose M here: the
module will be called cpufreq_ondemand.

For details, take a look at linux/Documentation/cpu-freq.

If in doubt, say N.

config CPU_FREQ_GOV_INTERACTIVE
tristate "'interactive' cpufreq policy governor"
help
'interactive' - This driver adds a dynamic cpufreq policy governor
designed for latency-sensitive workloads.

config CPU_FREQ_GOV_SMARTASS2
tristate "'smartass2' cpufreq policy governor"
help
'smartassV2' - a "smart" governor

config CPU_FREQ_GOV_CONSERVATIVE
tristate "'conservative' cpufreq governor"
depends on CPU_FREQ
help
'conservative' - this driver is rather similar to the 'ondemand'
governor both in its source code and its purpose, the difference is
its optimisation for better suitability in a battery powered
environment. The frequency is gracefully increased and decreased
rather than jumping to 100% when speed is required.

If you have a desktop machine then you should really be considering
the 'ondemand' governor instead, however if you are using a laptop,
PDA or even an AMD64 based computer (due to the unacceptable
step-by-step latency issues between the minimum and maximum frequency
transitions in the CPU) you will probably want to use this governor.

To compile this driver as a module, choose M here: the
module will be called cpufreq_conservative.

For details, take a look at linux/Documentation/cpu-freq.

If in doubt, say N.
config CPU_FREQ_MIN_TICKS
int "Ticks between governor polling interval."
default 10
help
Minimum number of ticks between polling interval for governors.

config CPU_FREQ_SAMPLING_LATENCY_MULTIPLIER
int "Sampling rate multiplier for governors."
default 1000
help
Sampling latency rate multiplied by the cpu switch latency.
Affects governor polling.

config CPU_FREQ_VDD_LEVELS
bool "CPU Vdd levels sysfs interface"
depends on CPU_FREQ_STAT
depends on ARCH_QSD8X50
default n
help
CPU Vdd levels sysfs interface

endif # CPU_FREQ[/code]

More notes:

/*
* Notes by Droidzone
*
* General format for adding governors
* -----------------------------------
*
* ifdef/elif Condition as per value in drivers/cpufreq/Kconfig
*
* CPUFREQ_DEFAULT_GOVERNOR is the variable pointing to the default governor
*
* Reads: if configured some governor as default, then define the governor
* by an object
*
* Thus: extern struc cpufreq_governor cpufreq_gov_interactive
* is pointed here.. the target is in cpufreq_interactive.c, the specific
* code in cpufreq/
*
* [extern struct cpufreq_governor] followed by the name as defined in its
* source code:
*
* Eg In cpufreq_smartass2.c is this:
* struct cpufreq_governor cpufreq_gov_smartass2 = {
. name = "smartassV2", *
.governor = cpufreq_governor_smartass,
*
*
*/
#ifdef CONFIG_CPU_FREQ_GOV_PERFORMANCE
extern struct cpufreq_governor cpufreq_gov_performance;
#endif
#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE
#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_performance)
#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE)
extern struct cpufreq_governor cpufreq_gov_powersave;
#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_powersave)
#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE)
extern struct cpufreq_governor cpufreq_gov_userspace;
#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_userspace)
#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND)
extern struct cpufreq_governor cpufreq_gov_ondemand;
#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_ondemand)
#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE)
extern struct cpufreq_governor cpufreq_gov_conservative;
#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_conservative)
#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_INTERACTIVE)
extern struct cpufreq_governor cpufreq_gov_interactive;
#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_interactive)
#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_SMARTASS2)
extern struct cpufreq_governor cpufreq_gov_smartass2;
#define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_smartass2)
#endif[/code]


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Menuconfig locations of important strings

Version: General setup>local version
CPU Max and Min freq: System type > CPU Max and Min


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Getting the last kernel messages before a reboot

It is in /proc/last_kmsg

By the way to get .config from a running kernel:

adb pull /proc/config.gz

zcat config.gz > .config

[/code]


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Adding OpenVPN (tun.ko) module at kernel compilation time

Make menuconfig.

Look for the line:

CONFIG_TUN=m
[/code]

in .config

If not present, add it.

It usually comes as a block here:

CONFIG_BLK_DEV_DM=y
CONFIG_DM_DEBUG=y
CONFIG_DM_CRYPT=y
# CONFIG_DM_SNAPSHOT is not set
# CONFIG_DM_MIRROR is not set
# CONFIG_DM_ZERO is not set
# CONFIG_DM_MULTIPATH is not set
# CONFIG_DM_DELAY is not set
CONFIG_DM_UEVENT=y
CONFIG_NETDEVICES=y
CONFIG_IFB=y
CONFIG_DUMMY=y
# CONFIG_BONDING is not set
# CONFIG_MACVLAN is not set
# CONFIG_EQUALIZER is not set
CONFIG_TUN=m
# CONFIG_VETH is not set
# CONFIG_PHYLIB is not set
CONFIG_NET_ETHERNET=y
CONFIG_MII=y
# CONFIG_AX88796 is not set
# CONFIG_SMC91X is not set
# CONFIG_DM9000 is not set
# CONFIG_ENC28J60 is not set
# CONFIG_ETHOC is not set
# CONFIG_SMC911X is not set
# CONFIG_SMSC911X is not set
# CONFIG_DNET is not set
[/code]

You can use the following code to quickly make a TUN module setting in a virgin .config:

sed s/'# CONFIG_TUN is not set'/'CONFIG_TUN=m'/ mconfig
cp mconfig .config[/code]

 

 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Kernel compilation menu script

Latest version:

#!/bin/bash

function msg {
echo -e 'E[37;44m'"33[1m$welcome33[0m"
}

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
}

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

}

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 '{}' ;
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 "Creating target directories"

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"
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/
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
fi

date_str=`date '+%d%m%y_%H%M%S'`
dirname="kernel_$nameflag_$date_str"
echo
echo "Current 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
welcome="Created flashable zip: $pckdir/$zipname"
msg

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

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 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 "07"
fi
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="zImage"
anykdir=/home/droidzone/flasher/AnyKernel
ksource=$kstartpath
outdir=~/kernel_flashable
packagedir=/home/droidzone/flasher/outdir
tempdir=~/kernel_flashablezImage
mnameflag=""

#Main menu
menu
exit 0
[/code]

Older version follows:

#!/bin/bash

function msg {
echo -e 'E[37;44m'"33[1m$welcome33[0m"
}

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
}

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

}

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 lflashery {
nameflag=""
clear
anykdir=/home/droidzone/flasher/AnyKernel
if [ ! -d $(pwd)/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
ksource=$(pwd)
outdir=~/kernel_flashable
packagedir=/home/droidzone/flasher/outdir
tempdir=~/kernel_flashable

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 "Creating target directories"

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"
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/
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
find . -name '*~' -exec rm '{}' ;
find . -name 'README*' -exec rm '{}' ;
#Precleaning temp folder
find . -name '*.ko' -exec rm '{}' ;

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
fi

date_str=`date '+%d%m%y_%H%M%S'`
dirname="kernel_$nameflag_$date_str"

echo "Current 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

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
welcome="Created flashable zip: $pckdir/$zipname"
msg

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

read -p 'Make Package with Additional Modules (N/y)?' -n 1
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo
cd $ksource

#find . -name '*.ko' -exec cp '{}' $outdir/system/lib/modules/ ;
echo "Adding Additional Modules (if any)..."
find . -name '*.ko' -exec cp '{}' $outdir/system/lib/modules/ ;

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 {
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 {
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 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 "07"
fi
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 " (Q)uit"
echo
echo " Advanced Compilation Options"
echo " ----------------------------"
echo " Change Toolchain prefix (Current : $toolchain )"
echo " Change Number of simultaneous jobs (Current : $jobs )"
echo
read -p "Choose an option :" -n 1
if [[ $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 =~ ^[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
}

toolchain="arm-bravo-"
jobs=50
#Main menu
menu
exit 0
[/code]


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Kernel compilation flags – A pain in the a*

So I pulled snq’s froyo kernel (that guy is a marvel)..

Some kernel compilation errors:

    1. Treat warnings as errors-Solved by removing the string “-Werror” from all Makefiles of the file which failed to compile. Some people had said that the real error (Array out of bounds warning) was because of gcc optimizations. But putting -O2 to -O0 didnt do a thing. This can also be done from menuconfig: System type>Force warnings as errors
    2. No of jobs – ought not to exceed 50.
    3. “warning: variable set but not used [-Wunused-but-set-variable]”-Look at¬†KBUILD_CFLAGS in the main Makefile. Add -Wno-unused-but-set-variable to the existing set of flags. You can alternately add a line that says

Note the following from gcc manual:

Refer Preprocessor options

  • -Werror[/code]Make all warnings into hard errors. Source code which triggers warnings will be rejected.
  • -w[/code]Inhibit all warning messages.
  • -Werror[/code]Make all warnings into errors.
  • -Werror=[/code]Make the specified warning into an error. The specifier for a warning is appended, for example¬†-Werror=switch¬†turns the warnings controlled by¬†-Wswitch¬†into errors. This switch takes a negative form, to be used to negate¬†-Werror¬†for specific warnings, for example¬†-Wno-error=switch¬†makes¬†-Wswitch¬†warnings not be errors, even when¬†-Werror¬†is in effect. You can use the¬†-fdiagnostics-show-option¬†option to have each controllable warning amended with the option which controls it, to determine what to use with this option.
So what I did to suppress errors was to add:
KBUILD_CFLAGS += -w
KBUILD_CFLAGS += -Wno-error=unused-but-set-variable

 

Though the -Wunused-but-set-variable is not a real issue in itself, it generates so much "noise" that you may miss actual make errors.

This is what I was talking about in No 1.

drivers/net/wireless/bcm4329_204/wl_iw.c: In function 'wl_iw_set_pmksa':
drivers/net/wireless/bcm4329_204/wl_iw.c:5075:5: error: array subscript is above array bounds [-Werror=array-bounds]
drivers/net/wireless/bcm4329_204/wl_iw.c:5078:5: error: array subscript is above array bounds [-Werror=array-bounds]
[/code]

Solution:
Edit drivers/net/wireless/bcm4329_204/Makefile

Locate -Werror within DHDCFLAGS, and delete it.

DHDCFLAGS = -DLINUX -DBCMDRIVER -DBCMDONGLEHOST -DDHDTHREAD -DBCMWPA2
-DUNRELEASEDCHIP -Dlinux -DDHD_SDALIGN=64 -DMAX_HDR_READ=64
-DDHD_FIRSTREAD=64 -DDHD_GPL -DDHD_SCHED -DBDC -DTOE -DDHD_BCMEVENTS
-DSHOW_EVENTS -DBCMSDIO -DDHD_GPL -DBCMLXSDMMC -DBCMPLATFORM_BUS
-Wall -Wstrict-prototypes -Werror -DOOB_INTR_ONLY -DCUSTOMER_HW2
-DDHD_USE_STATIC_BUF -DMMC_SDIO_ABORT -DWLAN_PFN -DWLAN_PROTECT
-DBCMWAPI_WPI
[/code]

This will prevent gcc from treating mere warnings as errors.

-


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.