diff options
author | David 'Digit' Turner <digit@android.com> | 2011-03-08 04:52:11 -0800 |
---|---|---|
committer | Android Code Review <code-review@android.com> | 2011-03-08 04:52:11 -0800 |
commit | 33d930c6f4e0df362c46ddbb366204746d82dd0b (patch) | |
tree | 12b113958622f5692fcb3af392c91d8788fbee9e | |
parent | 8f47a8c9b7f1077f3c34c54daa29a34ba53314ef (diff) | |
parent | 5c25d3d60c64efb11709b625714ca1dac7c043f4 (diff) | |
download | external_qemu-33d930c6f4e0df362c46ddbb366204746d82dd0b.zip external_qemu-33d930c6f4e0df362c46ddbb366204746d82dd0b.tar.gz external_qemu-33d930c6f4e0df362c46ddbb366204746d82dd0b.tar.bz2 |
Merge "Add kernel-rebuilding script for the emulator."
-rwxr-xr-x | distrib/build-kernel.sh | 150 | ||||
-rw-r--r-- | docs/KERNEL.TXT | 33 |
2 files changed, 182 insertions, 1 deletions
diff --git a/distrib/build-kernel.sh b/distrib/build-kernel.sh new file mode 100755 index 0000000..769a9a6 --- /dev/null +++ b/distrib/build-kernel.sh @@ -0,0 +1,150 @@ +#!/bin/sh +# +# A small script used to rebuild the Android goldfish kernel image +# See docs/KERNEL.TXT for usage instructions. +# +MACHINE=goldfish +VARIANT=goldfish +OUTPUT=/tmp/kernel-qemu +CROSSPREFIX=arm-eabi- +CONFIG=goldfish + +# Extract number of processors +JOBS=`grep -c "processor" /proc/cpuinfo` +JOBS=$(( $JOBS*2 )) + +ARCH=arm + +OPTION_HELP=no +OPTION_ARMV7=no +OPTION_OUT= +OPTION_CROSS= +OPTION_ARCH= +OPTION_CONFIG= + +for opt do + optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)') + case $opt in + --help|-h|-\?) OPTION_HELP=yes + ;; + --armv7) + OPTION_ARMV7=yes + ;; + --out=*) + OPTION_OUT=$optarg + ;; + --cross=*) + OPTION_CROSS=$optarg + ;; + --arch=*) + OPTION_ARCH=$optarg + ;; + --config=*) + OPTION_CONFIG=$optarg + ;; + -j*) + JOBS=$optarg + ;; + *) + echo "unknown option '$opt', use --help" + exit 1 + esac +done + +if [ $OPTION_HELP = "yes" ] ; then + echo "Rebuild the prebuilt kernel binary for Android's emulator." + echo "" + echo "options (defaults are within brackets):" + echo "" + echo " --help print this message" + echo " --arch=<arch> change target architecture [$ARCH]" + echo " --armv7 build ARMv7 binaries (see note below)" + echo " --out=<directory> output directory [$OUTPUT]" + echo " --cross=<prefix> cross-toolchain prefix [$CROSSPREFIX]" + echo " --config=<name> kernel config name [$CONFIG]" + echo "" + echo "NOTE: --armv7 is equivalent to --config=goldfish_armv7. It is" + echo " ignored if --config=<name> is used." + echo "" + exit 0 +fi + +if [ -n "$OPTION_ARCH" ]; then + ARCH="$OPTION_ARCH" +fi + +if [ -n "$OPTION_CONFIG" ]; then + CONFIG="$OPTION_CONFIG" +elif [ "$OPTION_ARMV7" = "yes" ]; then + CONFIG=goldfish_armv7 +fi + +# Check that we are in the kernel directory +if [ ! -d arch/$ARCH/mach-$MACHINE ] ; then + echo "Cannot find arch/$ARCH/mach-$MACHINE. Please cd to the kernel source directory." + echo "Aborting." + #exit 1 +fi + +# Check output directory. +if [ -n "$OPTION_OUT" ] ; then + if [ ! -d "$OPTION_OUT" ] ; then + echo "Output directory '$OPTION_OUT' does not exist ! Aborting." + exit 1 + fi + OUTPUT=$OPTION_OUT +else + mkdir -p $OUTPUT +fi + +if [ -n "$OPTION_CROSS" ] ; then + CROSSPREFIX="$OPTION_CROSS" +else + case $ARCH in + arm) + CROSSPREFIX=arm-eabi- + ZIMAGE=zImage + ;; + x86) + CROSSPREFIX=i686-android-linux- + ZIMAGE=bzImage + ;; + *) + echo "ERROR: Unsupported architecture!" + exit 1 + ;; + esac +fi + +export CROSS_COMPILE="$CROSSPREFIX" ARCH SUBARCH=$ARCH + +# Check that the cross-compiler is in our path +# +CROSS_COMPILER="${CROSS_COMPILE}gcc" +CROSS_COMPILER_VERSION=$($CROSS_COMPILER --version 2>/dev/null) +if [ $? != 0 ] ; then + echo "It looks like $CROSS_COMPILER is not in your path ! Aborting." + exit 1 +fi + +rm -f include/asm && +make ${CONFIG}_defconfig && # configure the kernel +make -j$JOBS # build it + +if [ $? != 0 ] ; then + echo "Could not build the kernel. Aborting !" + exit 1 +fi + +OUTPUT_KERNEL=kernel-qemu +OUTPUT_VMLINUX=vmlinux-qemu +if [ "$OPTION_ARMV7" = "yes" ] ; then + OUTPUT_KERNEL=${OUTPUT_KERNEL}-armv7 + OUTPUT_VMLINUX=${OUTPUT_VMLINUX}-armv7 +fi + +cp -f arch/$ARCH/boot/$ZIMAGE $OUTPUT/$OUTPUT_KERNEL +cp -f vmlinux $OUTPUT/$OUTPUT_VMLINUX + +echo "Kernel $CONFIG prebuilt image copied to $OUTPUT successfully !" +exit 0 diff --git a/docs/KERNEL.TXT b/docs/KERNEL.TXT index e174fe5..35d1f1f 100644 --- a/docs/KERNEL.TXT +++ b/docs/KERNEL.TXT @@ -1,6 +1,37 @@ HOW TO REBUILT THE ANDROID EMULATOR-SPECIFIC KERNEL: ==================================================== +I. Helper script: +----------------- + +We now provide a helper script to rebuild the kernel, +it is under distrib/rebuild-kernel.sh. + +You need the sources in android.git.kernel.org/kernel/common.git, +in branch origin/archive/android-gldfish-2.6.29 (note the typo!) + +To rebuild the ARM kernel: + + cd $KERNEL_SOURCES + /path/to/rebuild-kernel.sh --out=$ANDROID/prebuilt/android-arm/kernel + +To rebuild the x86 kernel: + + cd $KERNEL_SOURCES + /path/to/rebuild-kernel.sh --arch=x86 --out=$ANDROID/prebuilt/android-x86/kernel + +Note that you will need to have your cross-toolchain in your path. +If this is not the case, the script will complain and give you the +expected name. Use --cross=<prefix> to specify a different toolchain. + +See rebuild-kernel.sh --help for more options and details. + + +II. Rebuilding from scratch: +---------------------------- + +If you don't or can't use the script, here are manual instructions: + You need to have the Android toolchain in your path (i.e. 'arm-eabi-gcc --version' must work) @@ -8,7 +39,7 @@ then: git clone git://android.git.kernel.org/kernel/common.git kernel-common cd kernel-common -git checkout origin/android-goldfish-2.6.29 +git checkout origin/archive/android-gldfish-2.6.29 export CROSS_COMPILE=arm-eabi- export ARCH=arm |