Android内核的编译和调试

Posted Fly20141201

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android内核的编译和调试相关的知识,希望对你有一定的参考价值。

本文博客地址:http://blog.csdn.net/qq1084283172/article/details/70500488


一、Android内核源码的选择

android手机设备内核源码的调试需要外部硬件设备的支持,调试步骤比较麻烦。相对来说,Android模拟器内核源码的调试就比较简单了,这里以Android模拟器内核源码的调试为例。首先创建一个Android API 19(Android 4.4.x版本)的Android模拟器,然后运行该Android模拟器。在 ubuntu 14.04.5系统或者 Windows 系统上打开命令行终端,执行下面的命令,获取移动设备使用的芯片即获取移动设备内核源码的版本信息。

$ adb shell

# 查看设备使用的芯片
$ ls /dev/block/platform
windows系统上执行的结果如下图:



二、Android内核源码的下载

根据 ls /dev/block/platform 获取到的Android设备的芯片平台为 goldfish ,然后查阅google官方提供的Android内核源码的编译文档,执行下面的命令进行Android内核源码和Android内核源码交叉编译工具链的下载。

$ git clone https://android.googlesource.com/kernel/goldfish.git
$ cd goldfish/

# 查看可以下载的Linux内核源码的版本
$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/android-3.10
  remotes/origin/android-3.18
  remotes/origin/android-goldfish-2.6.29
  remotes/origin/android-goldfish-3.10
  remotes/origin/android-goldfish-3.10-l-mr1-dev
  remotes/origin/android-goldfish-3.10-m-dev
  remotes/origin/android-goldfish-3.10-n-dev
  remotes/origin/android-goldfish-3.18
  remotes/origin/android-goldfish-3.18-dev
  remotes/origin/android-goldfish-3.4
  remotes/origin/android-goldfish-3.4-l-mr1-dev
  remotes/origin/android-goldfish-4.4-dev
  remotes/origin/heads/for/android-goldfish-3.18-dev
  remotes/origin/linux-goldfish-3.0-wip
  remotes/origin/master

# 选择下载android-goldfish-3.4的内核源码
$ git checkout remotes/origin/android-goldfish-3.4  
# 或
$ git checkout -t remotes/origin/android-goldfish-3.4 -b goldfish3.4

# 下载编译工具链
$ git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-eabi-4.7/  

三、Android内核源码的配置和编译

设置环境变量,导出Android内核交叉编译工具的路径,生成内核编译时使用的配置文件。可以将配置的相关命令行保存为脚本文件run_make_config.sh 。有关Android内核源码的编译环境的配置可以参考google官方的文档:https://source.android.com/source/building-kernels#building

export CROSS_COMPILE=$(pwd)/arm-eabi-4.7/bin/arm-eabi-   
export ARCH=arm  
export SUBARCH=arm  

# 生成编译配置文件
make goldfish_armv7_defconfig
赋予脚本文件 run_make_config.sh  以可执行权限,然后执行该脚本生成Android内核编译的配置文件 .config 。

$ chmod +x run_make_config.sh  
$ source run_make_config.sh  
提示

1.根据《Android安全攻防权威指南》中文版第251页的提示了解到,在编译Android内核时要使用 arm-eabi 编译器而不是 arm-linux-androideabi 编译器。使用不正确的 EABI 会导致编译失败。



2.在生成Android内核编译的配置文件 .config 时,make 命令的选择既可以参考google官方的文档:https://source.android.com/source/building-kernels#building,也可以参考Android内核源码下帮助文件,这里是 /goldfish/README 文件,关于make命令生成编译配置文件的说明如下:



在当前Android内核源码的根目录下,执行 make help 命令,获取到Android内核编译配置命令的信息。

$ make help
Cleaning targets:
  clean		  - Remove most generated files but keep the config and
                    enough build support to build external modules
  mrproper	  - Remove all generated files + config + various backup files
  distclean	  - mrproper + remove editor backup and patch files

Configuration targets:
  config	  - Update current config utilising a line-oriented program
  nconfig         - Update current config utilising a ncurses menu based program
  menuconfig	  - Update current config utilising a menu based program
  xconfig	  - Update current config utilising a QT based front-end
  gconfig	  - Update current config utilising a GTK based front-end
  oldconfig	  - Update current config utilising a provided .config as base
  localmodconfig  - Update current config disabling modules not loaded
  localyesconfig  - Update current config converting local mods to core
  silentoldconfig - Same as oldconfig, but quietly, additionally update deps
  defconfig	  - New config with default from ARCH supplied defconfig
  savedefconfig   - Save current config as ./defconfig (minimal config)
  allnoconfig	  - New config where all options are answered with no
  allyesconfig	  - New config where all options are accepted with yes
  allmodconfig	  - New config selecting modules when possible
  alldefconfig    - New config with all symbols set to default
  randconfig	  - New config with random answer to all options
  listnewconfig   - List new options
  oldnoconfig     - Same as silentoldconfig but set new symbols to n (unset)

Other generic targets:
  all		  - Build all targets marked with [*]
* vmlinux	  - Build the bare kernel
* modules	  - Build all modules
  modules_install - Install all modules to INSTALL_MOD_PATH (default: /)
  firmware_install- Install all firmware to INSTALL_FW_PATH
                    (default: $(INSTALL_MOD_PATH)/lib/firmware)
  dir/            - Build all files in dir and below
  dir/file.[oisS] - Build specified target only
  dir/file.lst    - Build specified mixed source/assembly target only
                    (requires a recent binutils and recent build (System.map))
  dir/file.ko     - Build module including final link
  modules_prepare - Set up for building external modules
  tags/TAGS	  - Generate tags file for editors
  cscope	  - Generate cscope index
  gtags           - Generate GNU GLOBAL index
  kernelrelease	  - Output the release version string
  kernelversion	  - Output the version stored in Makefile
  headers_install - Install sanitised kernel headers to INSTALL_HDR_PATH
                    (default: /home/fly2016/Android4.4.4r1/goldfish-kernel-3.4/goldfish/usr)

Static analysers
  checkstack      - Generate a list of stack hogs
  namespacecheck  - Name space analysis on compiled kernel
  versioncheck    - Sanity check on version.h usage
  includecheck    - Check for duplicate included header files
  export_report   - List the usages of all exported symbols
  headers_check   - Sanity check on exported headers
  headerdep       - Detect inclusion cycles in headers
  coccicheck      - Check with Coccinelle.

Kernel packaging:
  rpm-pkg             - Build both source and binary RPM kernel packages
  binrpm-pkg          - Build only the binary kernel package
  deb-pkg             - Build the kernel as a deb package
  tar-pkg             - Build the kernel as an uncompressed tarball
  targz-pkg           - Build the kernel as a gzip compressed tarball
  tarbz2-pkg          - Build the kernel as a bzip2 compressed tarball
  tarxz-pkg           - Build the kernel as a xz compressed tarball
  perf-tar-src-pkg    - Build perf-3.4.67.tar source tarball
  perf-targz-src-pkg  - Build perf-3.4.67.tar.gz source tarball
  perf-tarbz2-src-pkg - Build perf-3.4.67.tar.bz2 source tarball
  perf-tarxz-src-pkg  - Build perf-3.4.67.tar.xz source tarball

Documentation targets:
 Linux kernel internal documentation in different formats:
  htmldocs        - HTML
  pdfdocs         - PDF
  psdocs          - Postscript
  xmldocs         - XML DocBook
  mandocs         - man pages
  installmandocs  - install man pages generated by mandocs
  cleandocs       - clean all generated DocBook files

Architecture specific targets (arm):
* zImage        - Compressed kernel image (arch/arm/boot/zImage)
  Image         - Uncompressed kernel image (arch/arm/boot/Image)
* xipImage      - XIP kernel image, if configured (arch/arm/boot/xipImage)
  uImage        - U-Boot wrapped zImage
  bootpImage    - Combined zImage and initial RAM disk
                  (supply initrd image via make variable INITRD=<path>)
  dtbs          - Build device tree blobs for enabled boards
  install       - Install uncompressed kernel
  zinstall      - Install compressed kernel
  uinstall      - Install U-Boot wrapped compressed kernel
                  Install using (your) ~/bin/installkernel or
                  (distribution) /sbin/installkernel or
                  install to $(INSTALL_PATH) and run lilo

  acs5k_defconfig          - Build for acs5k
  acs5k_tiny_defconfig     - Build for acs5k_tiny
  afeb9260_defconfig       - Build for afeb9260
  ag5evm_defconfig         - Build for ag5evm
  am200epdkit_defconfig    - Build for am200epdkit
  ap4evb_defconfig         - Build for ap4evb
  assabet_defconfig        - Build for assabet
  at91rm9200_defconfig     - Build for at91rm9200
  at91sam9260_defconfig    - Build for at91sam9260
  at91sam9261_defconfig    - Build for at91sam9261
  at91sam9263_defconfig    - Build for at91sam9263
  at91sam9g20_defconfig    - Build for at91sam9g20
  at91sam9g45_defconfig    - Build for at91sam9g45
  at91sam9rl_defconfig     - Build for at91sam9rl
  at91x40_defconfig        - Build for at91x40
  badge4_defconfig         - Build for badge4
  bcmring_defconfig        - Build for bcmring
  bonito_defconfig         - Build for bonito
  cam60_defconfig          - Build for cam60
  cerfcube_defconfig       - Build for cerfcube
  cm_x2xx_defconfig        - Build for cm_x2xx
  cm_x300_defconfig        - Build for cm_x300
  cns3420vb_defconfig      - Build for cns3420vb
  colibri_pxa270_defconfig - Build for colibri_pxa270
  colibri_pxa300_defconfig - Build for colibri_pxa300
  collie_defconfig         - Build for collie
  corgi_defconfig          - Build for corgi
  cpu9260_defconfig        - Build for cpu9260
  cpu9g20_defconfig        - Build for cpu9g20
  da8xx_omapl_defconfig    - Build for da8xx_omapl
  davinci_all_defconfig    - Build for davinci_all
  dove_defconfig           - Build for dove
  ebsa110_defconfig        - Build for ebsa110
  edb7211_defconfig        - Build for edb7211
  em_x270_defconfig        - Build for em_x270
  ep93xx_defconfig         - Build for ep93xx
  eseries_pxa_defconfig    - Build for eseries_pxa
  exynos4_defconfig        - Build for exynos4
  ezx_defconfig            - Build for ezx
  footbridge_defconfig     - Build for footbridge
  fortunet_defconfig       - Build for fortunet
  g3evm_defconfig          - Build for g3evm
  g4evm_defconfig          - Build for g4evm
  goldfish_armv7_defconfig - Build for goldfish_armv7
  goldfish_defconfig       - Build for goldfish
  h3600_defconfig          - Build for h3600
  h5000_defconfig          - Build for h5000
  h7201_defconfig          - Build for h7201
  h7202_defconfig          - Build for h7202
  hackkit_defconfig        - Build for hackkit
  imote2_defconfig         - Build for imote2
  imx_v4_v5_defconfig      - Build for imx_v4_v5
  imx_v6_v7_defconfig      - Build for imx_v6_v7
  integrator_defconfig     - Build for integrator
  iop13xx_defconfig        - Build for iop13xx
  iop32x_defconfig         - Build for iop32x
  iop33x_defconfig         - Build for iop33x
  ixp2000_defconfig        - Build for ixp2000
  ixp23xx_defconfig        - Build for ixp23xx
  ixp4xx_defconfig         - Build for ixp4xx
  jornada720_defconfig     - Build for jornada720
  kirkwood_defconfig       - Build for kirkwood
  kota2_defconfig          - Build for kota2
  ks8695_defconfig         - Build for ks8695
  lart_defconfig           - Build for lart
  lpc32xx_defconfig        - Build for lpc32xx
  lpd270_defconfig         - Build for lpd270
  lubbock_defconfig        - Build for lubbock
  mackerel_defconfig       - Build for mackerel
  magician_defconfig       - Build for magician
  mainstone_defconfig      - Build for mainstone
  marzen_defconfig         - Build for marzen
  mini2440_defconfig       - Build for mini2440
  mmp2_defconfig           - Build for mmp2
  msm_defconfig            - Build for msm
  mv78xx0_defconfig        - Build for mv78xx0
  mxs_defconfig            - Build for mxs
  neponset_defconfig       - Build for neponset
  netwinder_defconfig      - Build for netwinder
  netx_defconfig           - Build for netx
  nhk8815_defconfig        - Build for nhk8815
  nuc910_defconfig         - Build for nuc910
  nuc950_defconfig         - Build for nuc950
  nuc960_defconfig         - Build for nuc960
  omap1_defconfig          - Build for omap1
  omap2plus_defconfig      - Build for omap2plus
  orion5x_defconfig        - Build for orion5x
  palmz72_defconfig        - Build for palmz72
  pcm027_defconfig         - Build for pcm027
  pleb_defconfig           - Build for pleb
  pnx4008_defconfig        - Build for pnx4008
  pxa168_defconfig         - Build for pxa168
  pxa255-idp_defconfig     - Build for pxa255-idp
  pxa3xx_defconfig         - Build for pxa3xx
  pxa910_defconfig         - Build for pxa910
  qil-a9260_defconfig      - Build for qil-a9260
  raumfeld_defconfig       - Build for raumfeld
  realview_defconfig       - Build for realview
  realview-smp_defconfig   - Build for realview-smp
  rpc_defconfig            - Build for rpc
  s3c2410_defconfig        - Build for s3c2410
  s3c6400_defconfig        - Build for s3c6400
  s5p64x0_defconfig        - Build for s5p64x0
  s5pc100_defconfig        - Build for s5pc100
  s5pv210_defconfig        - Build for s5pv210
  sam9_l9260_defconfig     - Build for sam9_l9260
  shannon_defconfig        - Build for shannon
  shark_defconfig          - Build for shark
  simpad_defconfig         - Build for simpad
  spear3xx_defconfig       - Build for spear3xx
  spear6xx_defconfig       - Build for spear6xx
  spitz_defconfig          - Build for spitz
  stamp9g20_defconfig      - Build for stamp9g20
  tct_hammer_defconfig     - Build for tct_hammer
  tegra_defconfig          - Build for tegra
  trizeps4_defconfig       - Build for trizeps4
  u300_defconfig           - Build for u300
  u8500_defconfig          - Build for u8500
  usb-a9260_defconfig      - Build for usb-a9260
  versatile_defconfig      - Build for versatile
  vexpress_defconfig       - Build for vexpress
  viper_defconfig          - Build for viper
  xcep_defconfig           - Build for xcep
  zeus_defconfig           - Build for zeus

  make V=0|1 [targets] 0 => quiet build (default), 1 => verbose build
  make V=2   [targets] 2 => give reason for rebuild of target
  make O=dir [targets] Locate all output files in "dir", including .config
  make C=1   [targets] Check all c source with $CHECK (sparse by default)
  make C=2   [targets] Force check of all c source with $CHECK
  make RECORDMCOUNT_WARN=1 [targets] Warn about ignored mcount sections
  make W=n   [targets] Enable extra gcc checks, n=1,2,3 where
		1: warnings which may be relevant and do not occur too often
		2: warnings which occur quite often but may still be relevant
		3: more obscure warnings, can most likely be ignored
		Multiple levels can be combined with W=12 or W=123

Execute "make" or "make all" to build all targets marked with [*] 
For further info see the ./README file
当前Android内核源码的帮助文件 README 的全部内容信息:

	Linux kernel release 3.x <http://kernel.org/>

These are the release notes for Linux version 3.  Read them carefully,
as they tell you what this is all about, explain how to install the
kernel, and what to do if something goes wrong. 

WHAT IS LINUX?

  Linux is a clone of the operating system Unix, written from scratch by
  Linus Torvalds with assistance from a loosely-knit team of hackers across
  the Net. It aims towards POSIX and Single UNIX Specification compliance.

  It has all the features you would expect in a modern fully-fledged Unix,
  including true multitasking, virtual memory, shared libraries, demand
  loading, shared copy-on-write executables, proper memory management,
  and multistack networking including IPv4 and IPv6.

  It is distributed under the GNU General Public License - see the
  accompanying COPYING file for more details. 

ON WHAT HARDWARE DOES IT RUN?

  Although originally developed first for 32-bit x86-based PCs (386 or higher),
  today Linux also runs on (at least) the Compaq Alpha AXP, Sun SPARC and
  UltraSPARC, Motorola 68000, PowerPC, PowerPC64, ARM, Hitachi SuperH, Cell,
  IBM S/390, MIPS, HP PA-RISC, Intel IA-64, DEC VAX, AMD x86-64, AXIS CRIS,
  Xtensa, Tilera TILE, AVR32 and Renesas M32R architectures.

  Linux is easily portable to most general-purpose 32- or 64-bit architectures
  as long as they have a paged memory management unit (PMMU) and a port of the
  GNU C compiler (gcc) (part of The GNU Compiler Collection, GCC). Linux has
  also been ported to a number of architectures without a PMMU, although
  functionality is then obviously somewhat limited.
  Linux has also been ported to itself. You can now run the kernel as a
  userspace application - this is called UserMode Linux (UML).

DOCUMENTATION:

 - There is a lot of documentation available both in electronic form on
   the Internet and in books, both Linux-specific and pertaining to
   general UNIX questions.  I'd recommend looking into the documentation
   subdirectories on any Linux FTP site for the LDP (Linux Documentation
   Project) books.  This README is not meant to be documentation on the
   system: there are much better sources available.

 - There are various README files in the Documentation/ subdirectory:
   these typically contain kernel-specific installation notes for some 
   drivers for example. See Documentation/00-INDEX for a list of what
   is contained in each file.  Please read the Changes file, as it
   contains information about the problems, which may result by upgrading
   your kernel.

 - The Documentation/DocBook/ subdirectory contains several guides for
   kernel developers and users.  These guides can be rendered in a
   number of formats:  PostScript (.ps), PDF, HTML, & man-pages, among others.
   After installation, "make psdocs", "make pdfdocs", "make htmldocs",
   or "make mandocs" will render the documentation in the requested format.

INSTALLING the kernel source:

 - If you install the full sources, put the kernel tarball in a
   directory where you have permissions (eg. your home directory) and
   unpack it:

		gzip -cd linux-3.X.tar.gz | tar xvf -

   or
		bzip2 -dc linux-3.X.tar.bz2 | tar xvf -


   Replace "XX" with the version number of the latest kernel.

   Do NOT use the /usr/src/linux area! This area has a (usually
   incomplete) set of kernel headers that are used by the library header
   files.  They should match the library, and not get messed up by
   whatever the kernel-du-jour happens to be.

 - You can also upgrade between 3.x releases by patching.  Patches are
   distributed in the traditional gzip and the newer bzip2 format.  To
   install by patching, get all the newer patch files, enter the
   top level directory of the kernel source (linux-3.x) and execute:

		gzip -cd ../patch-3.x.gz | patch -p1

   or
		bzip2 -dc ../patch-3.x.bz2 | patch -p1

   (repeat xx for all versions bigger than the version of your current
   source tree, _in_order_) and you should be ok.  You may want to remove
   the backup files (xxx~ or xxx.orig), and make sure that there are no
   failed patches (xxx# or xxx.rej). If there are, either you or me has
   made a mistake.

   Unlike patches for the 3.x kernels, patches for the 3.x.y kernels
   (also known as the -stable kernels) are not incremental but instead apply
   directly to the base 3.x kernel.  Please read
   Documentation/applying-patches.txt for more information.

   Alternatively, the script patch-kernel can be used to automate this
   process.  It determines the current kernel version and applies any
   patches found.

		linux/scripts/patch-kernel linux

   The first argument in the command above is the location of the
   kernel source.  Patches are applied from the current directory, but
   an alternative directory can be specified as the second argument.

 - If you are upgrading between releases using the stable series patches
   (for example, patch-3.x.y), note that these "dot-releases" are
   not incremental and must be applied to the 3.x base tree. For
   example, if your base kernel is 3.0 and you want to apply the
   3.0.3 patch, you do not and indeed must not first apply the
   3.0.1 and 3.0.2 patches. Similarly, if you are running kernel
   version 3.0.2 and want to jump to 3.0.3, you must first
   reverse the 3.0.2 patch (that is, patch -R) _before_ applying
   the 3.0.3 patch.
   You can read more on this in Documentation/applying-patches.txt

 - Make sure you have no stale .o files and dependencies lying around:

		cd linux
		make mrproper

   You should now have the sources correctly installed.

SOFTWARE REQUIREMENTS

   Compiling and running the 3.x kernels requires up-to-date
   versions of various software packages.  Consult
   Documentation/Changes for the minimum version numbers required
   and how to get updates for these packages.  Beware that using
   excessively old versions of these packages can cause indirect
   errors that are very difficult to track down, so don't assume that
   you can just update packages when obvious problems arise during
   build or operation.

BUILD directory for the kernel:

   When compiling the kernel all output files will per default be
   stored together with the kernel source code.
   Using the option "make O=output/dir" allow you to specify an alternate
   place for the output files (including .config).
   Example:
     kernel source code:	/usr/src/linux-3.N
     build directory:		/home/name/build/kernel

   To configure and build the kernel use:
   cd /usr/src/linux-3.N
   make O=/home/name/build/kernel menuconfig
   make O=/home/name/build/kernel
   sudo make O=/home/name/build/kernel modules_install install

   Please note: If the 'O=output/dir' option is used then it must be
   used for all invocations of make.

CONFIGURING the kernel:

   Do not skip this step even if you are only upgrading one minor
   version.  New configuration options are added in each release, and
   odd problems will turn up if the configuration files are not set up
   as expected.  If you want to carry your existing configuration to a
   new version with minimal work, use "make oldconfig", which will
   only ask you for the answers to new questions.

 - Alternate configuration commands are:
	"make config"      Plain text interface.
	"make menuconfig"  Text based color menus, radiolists & dialogs.
	"make nconfig"     Enhanced text based color menus.
	"make xconfig"     X windows (Qt) based configuration tool.
	"make gconfig"     X windows (Gtk) based configuration tool.
	"make oldconfig"   Default all questions based on the contents of
			   your existing ./.config file and asking about
			   new config symbols.
	"make silentoldconfig"
			   Like above, but avoids cluttering the screen
			   with questions already answered.
			   Additionally updates the dependencies.
	"make defconfig"   Create a ./.config file by using the default
			   symbol values from either arch/$ARCH/defconfig
			   or arch/$ARCH/configs/$PLATFORM_defconfig,
			   depending on the architecture.
	"make $PLATFORM_defconfig"
			  Create a ./.config file by using the default
			  symbol values from
			  arch/$ARCH/configs/$PLATFORM_defconfig.
			  Use "make help" to get a list of all available
			  platforms of your architecture.
	"make allyesconfig"
			   Create a ./.config file by setting symbol
			   values to 'y' as much as possible.
	"make allmodconfig"
			   Create a ./.config file by setting symbol
			   values to 'm' as much as possible.
	"make allnoconfig" Create a ./.config file by setting symbol
			   values to 'n' as much as possible.
	"make randconfig"  Create a ./.config file by setting symbol
			   values to random values.

   You can find more information on using the Linux kernel config tools
   in Documentation/kbuild/kconfig.txt.

	NOTES on "make config":
	- having unnecessary drivers will make the kernel bigger, and can
	  under some circumstances lead to problems: probing for a
	  nonexistent controller card may confuse your other controllers
	- compiling the kernel with "Processor type" set higher than 386
	  will result in a kernel that does NOT work on a 386.  The
	  kernel will detect this on bootup, and give up.
	- A kernel with math-emulation compiled in will still use the
	  coprocessor if one is present: the math emulation will just
	  never get used in that case.  The kernel will be slightly larger,
	  but will work on different machines regardless of whether they
	  have a math coprocessor or not. 
	- the "kernel hacking" configuration details usually result in a
	  bigger or slower kernel (or both), and can even make the kernel
	  less stable by configuring some routines to actively try to
	  break bad code to find kernel problems (kmalloc()).  Thus you
	  should probably answer 'n' to the questions for
          "development", "experimental", or "debugging" features.

COMPILING the kernel:

 - Make sure you have at least gcc 3.2 available.
   For more information, refer to Documentation/Changes.

   Please note that you can still run a.out user programs with this kernel.

 - Do a "make" to create a compressed kernel image. It is also
   possible to do "make install" if you have lilo installed to suit the
   kernel makefiles, but you may want to check your particular lilo setup first.

   To do the actual install you have to be root, but none of the normal
   build should require that. Don't take the name of root in vain.

 - If you configured any of the parts of the kernel as `modules', you
   will also have to do "make modules_install".

 - Verbose kernel compile/build output:

   Normally the kernel build system runs in a fairly quiet mode (but not
   totally silent).  However, sometimes you or other kernel developers need
   to see compile, link, or other commands exactly as they are executed.
   For this, use "verbose" build mode.  This is done by inserting
   "V=1" in the "make" command.  E.g.:

	make V=1 all

   To have the build system also tell the reason for the rebuild of each
   target, use "V=2".  The default is "V=0".

 - Keep a backup kernel handy in case something goes wrong.  This is 
   especially true for the development releases, since each new release
   contains new code which has not been debugged.  Make sure you keep a
   backup of the modules corresponding to that kernel, as well.  If you
   are installing a new kernel with the same version number as your
   working kernel, make a backup of your modules directory before you
   do a "make modules_install".
   Alternatively, before compiling, use the kernel config option
   "LOCALVERSION" to append a unique suffix to the regular kernel version.
   LOCALVERSION can be set in the "General Setup" menu.

 - In order to boot your new kernel, you'll need to copy the kernel
   image (e.g. .../linux/arch/i386/boot/bzImage after compilation)
   to the place where your regular bootable kernel is found. 

 - Booting a kernel directly from a floppy without the assistance of a
   bootloader such as LILO, is no longer supported.

   If you boot Linux from the hard drive, chances are you use LILO which
   uses the kernel image as specified in the file /etc/lilo.conf.  The
   kernel image file is usually /vmlinuz, /boot/vmlinuz, /bzImage or
   /boot/bzImage.  To use the new kernel, save a copy of the old image
   and copy the new image over the old one.  Then, you MUST RERUN LILO
   to update the loading map!! If you don't, you won't be able to boot
   the new kernel image.

   Reinstalling LILO is usually a matter of running /sbin/lilo. 
   You may wish to edit /etc/lilo.conf to specify an entry for your
   old kernel image (say, /vmlinux.old) in case the new one does not
   work.  See the LILO docs for more information. 

   After reinstalling LILO, you should be all set.  Shutdown the system,
   reboot, and enjoy!

   If you ever need to change the default root device, video mode,
   ramdisk size, etc.  in the kernel image, use the 'rdev' program (or
   alternatively the LILO boot options when appropriate).  No need to
   recompile the kernel to change these parameters. 

 - Reboot with the new kernel and enjoy. 

IF SOMETHING GOES WRONG:

 - If you have problems that seem to be due to kernel bugs, please check
   the file MAINTAINERS to see if there is a particular person associated
   with the part of the kernel that you are having trouble with. If there
   isn't anyone listed there, then the second best thing is to mail
   them to me (torvalds@linux-foundation.org), and possibly to any other
   relevant mailing-list or to the newsgroup.

 - In all bug-reports, *please* tell what kernel you are talking about,
   how to duplicate the problem, and what your setup is (use your common
   sense).  If the problem is new, tell me so, and if the problem is
   old, please try to tell me when you first noticed it.

 - If the bug results in a message like

	unable to handle kernel paging request at address C0000010
	Oops: 0002
	EIP:   0010:XXXXXXXX
	eax: xxxxxxxx   ebx: xxxxxxxx   ecx: xxxxxxxx   edx: xxxxxxxx
	esi: xxxxxxxx   edi: xxxxxxxx   ebp: xxxxxxxx
	ds: xxxx  es: xxxx  fs: xxxx  gs: xxxx
	Pid: xx, process nr: xx
	xx xx xx xx xx xx xx xx xx xx

   or similar kernel debugging information on your screen or in your
   system log, please duplicate it *exactly*.  The dump may look
   incomprehensible to you, but it does contain information that may
   help debugging the problem.  The text above the dump is also
   important: it tells something about why the kernel dumped code (in
   the above example it's due to a bad kernel pointer). More information
   on making sense of the dump is in Documentation/oops-tracing.txt

 - If you compiled the kernel with CONFIG_KALLSYMS you can send the dump
   as is, otherwise you will have to use the "ksymoops" program to make
   sense of the dump (but compiling with CONFIG_KALLSYMS is usually preferred).
   This utility can be downloaded from
   ftp://ftp.<country>.kernel.org/pub/linux/utils/kernel/ksymoops/ .
   Alternately you can do the dump lookup by hand:

 - In debugging dumps like the above, it helps enormously if you can
   look up what the EIP value means.  The hex value as such doesn't help
   me or anybody else very much: it will depend on your particular
   kernel setup.  What you should do is take the hex value from the EIP
   line (ignore the "0010:"), and look it up in the kernel namelist to
   see which kernel function contains the offending address.

   To find out the kernel function name, you'll need to find the system
   binary associated with the kernel that exhibited the symptom.  This is
   the file 'linux/vmlinux'.  To extract the namelist and match it against
   the EIP from the kernel crash, do:

		nm vmlinux | sort | less

   This will give you a list of kernel addresses sorted in ascending
   order, from which it is simple to find the function that contains the
   offending address.  Note that the address given by the kernel
   debugging messages will not necessarily match exactly with the
   function addresses (in fact, that is very unlikely), so you can't
   just 'grep' the list: the list will, however, give you the starting
   point of each kernel function, so by looking for the function that
   has a starting address lower than the one you are searching for but
   is followed by a function with a higher address you will find the one
   you want.  In fact, it may be a good idea to include a bit of
   "context" in your problem report, giving a few lines around the
   interesting one. 

   If you for some reason cannot do the above (you have a pre-compiled
   kernel image or similar), telling me as much about your setup as
   possible will help.  Please read the REPORTING-BUGS document for details.

 - Alternately, you can use gdb on a running kernel. (read-only; i.e. you
   cannot change values or set break points.) To do this, first compile the
   kernel with -g; edit arch/i386/Makefile appropriately, then do a "make
   clean". You'll also need to enable CONFIG_PROC_FS (via "make config").

   After you've rebooted with the new kernel, do "gdb vmlinux /proc/kcore".
   You can now use all the usual gdb commands. The command to look up the
   point where your system crashed is "l *0xXXXXXXXX". (Replace the XXXes
   with the EIP value.)

   gdb'ing a non-running kernel currently fails because gdb (wrongly)
   disregards the starting offset for which the kernel is compiled.

修改生成的Android内核编译配置文件.config,增加Android内核编译的config选项。默认的 make goldfish_armv7_defconfig 配置没有打开调试选项,也没有使用HIGHMEM等选项,因此为了使用 kgdb 调试Android内核必须增加这些选项。这里手动打开goldfish/.config文件,增加调试相关的选项配置。

# 打开Android内核编译的配置文件
$ gedit .config
增加的编译配置选项:

# 设置模拟器的运行内存-可选参数
CONFIG_HIGHMEM=y  

CONFIG_DEBUG_KERNEL=y  
CONFIG_KGDB=y  
CONFIG_DEBUG_INFO=y

# 真机设备调试需要设置这一项,模拟器不需要
#CONFIG_KGDB_SERIAL_CONSOLE=y

# 可以是直接在配置文件中去掉这一项
CONFIG_DEBUG_RODATA=n

具体每一个配置选项的作用,可以参考这篇博文《用 kGDB 调试 Linux 内核》,简单的描述如下图,其中打开 CONFIG_HIGHMEM=y  这个选项后,启动模拟器时 emulator -memory 参数才能发挥作用即可以设置Android模拟器启动时的运行内存的大小,是一个可选的参数,因为可以直接使用  Adt-bundle-x86_64 或者 Android Studio 提供的创建Andorid模拟器的工具设置,不需要手动添加 -memory参数 进行修改。



执行修改Android内核编译配置文件.config的结果如下图所示:



Android内核编译配置文件的修改也可以通过执行 make menuconfig 命令进行修改,只不过麻烦一下。上面修改.config完成以后,保存和关闭.config文件,然后执行下面的命令进行Android内核源码的编译。由于前面修改Android内核编译配置时,增加了几个配置,因此编译一开始会有提示让选择配置选项记得相关的配置全部选 y 就可以了。Android内核编译完成后,goldfish/arch/arm/boot/zImage文件出现,这个文件就是Android内核文件了。

$ make -j4
Android内核源码编译成功后的结果截图如下:



四、Android内核的调试

1.使用 Adt-bundle-x86_64 或者 Android Studio 开发Android程序时搭建的环境中的Android模拟器 emulator 来加载上面编译成功的Android内核镜像文件。根据Android内核源码 android-goldfish-3.4 支持的Android系统的版本,来创建Android 模拟器命名为 Debug_Kernel 。这里根据实际情况创建Android 4.4.4 API 19 版本的Android模拟器。首先使用Android综合开发工具 Android Studio 创建名称为 Debug_Kernel 的Android模拟器,设参数置如下图,后面用创建的这个模拟器来加载上面编译成功的Android内核镜像文件 goldfish/arch/arm/boot/zImage,进行Android内核的调试。



提示

1.在进行后面的实践中,需要添加Android  SDK到系统的环境变量中,否则执行 emulator 命令时需要使用全路径比较麻烦,下面是添加 Android SDK 到环境变量中的操作命令:

# 编辑环境变量配置文件
$ sudo gedit /etc/profile  

# 添加到环境变量配置文件/etc/profile中的内容

# Android SDK
export ANDROID_SDK=/home/fly2016/Android/Sdk
export PATH=$PATH:$ANDROID_SDK/platform-tools:$ANDROID_SDK/tools

# Android NDK(顺便添加)
export ANDROID_NDK=/home/fly2016/Android/Sdk/ndk-bundle
export PATH=$PATH:$ANDROID_NDK

# 更新系统环境变量
$ source /etc/profile 

# 测试Android SDK是否配置成功的命令
$ adb verison
$ emulator -help

# 测试Android NDK是否配置成功的命令
$ ndk-build
2.这里是用Android Studio的工具创建的Android虚拟机 Debug_Kernel,当然使用 Adt-bundle-x86_64的工具创建Android 虚拟机  Debug_Kernel 是可以的,甚至是使用 android create avd 命令进行Android模拟器的创建也是可以的。有关 android create avd 命令创建Android 虚拟机的使用帮助如下:

$ android create avd
Error: The parameters --name, --target must be defined for action 'create avd'

       Usage:
       android [global options] create avd [action options]
       Global options:
  -h --help       : Help on a specific command.
  -v --verbose    : Verbose mode, shows errors, warnings and all messages.
     --clear-cache: Clear the SDK Manager repository manifest cache.
  -s --silent     : Silent mode, shows errors only.

                     Action "create avd":
  Creates a new Android Virtual Device.
Options:
  -g --tag     : The sys-img tag to use for the AVD. The default is to
                 auto-select if the platform has only one tag for its system
                 images.
  -c --sdcard  : Path to a shared SD card image, or size of a new sdcard for
                 the new AVD.
  -n --name    : Name of the new AVD. [required]
  -a --snapshot: Place a snapshots file in the AVD, to enable persistence.
  -p --path    : Directory where the new AVD will be created.
  -f --force   : Forces creation (overwrites an existing AVD)
  -s --skin    : Skin for the new AVD.
  -t --target  : Target ID of the new AVD. [required]
  -b --abi     : The ABI to use for the AVD. The default is to auto-select the
                 ABI if the platform has only one ABI for its system images.
  -d --device  : The optional device definition to use. Can be a device index
                 or id.

使用 android create avd 命令,创建Android模拟器Debug_Kernel的示例,如下:

# 查看本地下载的Android SDK
$ android list targets
	 
# 创建Android模拟器 Debug_Kernel
$ android create avd -n Debug_Kernel -t android-19 -b default/armeabi-v7a -s HVGA

Android API 19的Android模拟器 Debug_Kernel 创建成功以后,使用下面的命令检查新创建的Android模拟器 Debug_Kernel 能否正常启动成功。

# 查看已经创建的Android模拟器
$ emulator -list-avds  

# 启动运行创建的Android模拟器Debug_Kernel
$ emulator -avd Debug_Kernel -gpu mesa

Android模拟器 Debug_Kernel 启动成功,说明准备工作已经做好了。现在可以在 Android内核源码的根目录下 执行下面的命令,以 -kernel参数 指定加载前面编译成功的Android内核镜像文件 goldfish/arch/arm/boot/zImage ,并以等待调试模式启动Android模拟器 Debug_Kernel 。
$ emulator -avd Debug_Kernel -verbose -netfast -show-kernel -kernel ./arch/arm/boot/zImage  -gpu mesa -qemu -s -S 

调试内核一般不需要显示图形界面和声音,因此增加启动选项 -no-window, no-audio ,增加 -verbose -show-kernel 选项 可以看到内核的详细输出信息,-kernel 选项 指定加载的内核镜像文件为前面编译的Android内核镜像文件,增加 -qemu -s -S 选项 启动调试监听即Android内核启动以后会监听端口 1234 ,暂停等待调试,这时需要打开另一个命令终端运行 gdb 程序,对Android内核进行调试,还可以增加 -memory 2048 选项 设置运行的内存大小,增加运行内存使调试运行更流畅。


执行结果输出信息,如下所示:

fly2016@ubuntu:~/Desktop/Android4.4.4r1/goldfish-kernel-3.4/goldfish$ emulator -avd Debug_Kernel -verbose -netfast -show-kernel -kernel ./arch/arm/boot/zImage  -gpu mesa -qemu -s -S     
emulator:Found AVD name 'Debug_Kernel'
emulator:Found AVD target architecture: arm
emulator:  Found directory: /home/fly2016/Android/Sdk/system-images/android-19/default/armeabi-v7a/

emulator:Probing for /home/fly2016/Android/Sdk/system-images/android-19/default/armeabi-v7a//kernel-ranchu: file missing
emulator:Auto-config: -engine classic (based on configuration)
emulator:  Found directory: /home/fly2016/Android/Sdk/system-images/android-19/default/armeabi-v7a/

emulator:Looking for emulator-arm to emulate 'arm' CPU
emulator:Probing program: /home/fly2016/Android/Sdk/tools/emulator64-arm
emulator:return result: /home/fly2016/Android/Sdk/tools/emulator64-arm
emulator:Found target-specific 64-bit emulator binary: /home/fly2016/Android/Sdk/tools/emulator64-arm
emulator:Adding library search path: '/home/fly2016/Android/Sdk/tools/lib64'
emulator:Adding library search path: '/home/fly2016/Android/Sdk/tools/lib64/libstdc++'
emulator:  Found directory: /home/fly2016/Android/Sdk/system-images/android-19/default/armeabi-v7a/

emulator:  Found directory: /home/fly2016/Android/Sdk/system-images/android-19/default/armeabi-v7a/

emulator:GPU emulation enabled using 'mesa' mode
WARNING: The Mesa software renderer is deprecated. Use Swiftshader (-gpu swiftshader) for software rendering.
emulator: Adding library search path for Qt: '/home/fly2016/Android/Sdk/tools/lib64/qt/lib'
emulator: Setting Qt plugin search path: QT_QPA_PLATFORM_PLUGIN_PATH=/home/fly2016/Android/Sdk/tools/lib64/qt/plugins
emulator: Running :/home/fly2016/Android/Sdk/tools/emulator64-arm
emulator: qemu backend: argv[00] = "/home/fly2016/Android/Sdk/tools/emulator64-arm"
emulator: qemu backend: argv[01] = "-avd"
emulator: qemu backend: argv[02] = "Debug_Kernel"
emulator: qemu backend: argv[03] = "-verbose"
emulator: qemu backend: argv[04] = "-netfast"
emulator: qemu backend: argv[05] = "-show-kernel"
emulator: qemu backend: argv[06] = "-kernel"
emulator: qemu backend: argv[07] = "./arch/arm/boot/zImage"
emulator: qemu backend: argv[08] = "-gpu"
emulator: qemu backend: argv[09] = "mesa"
emulator: qemu backend: argv[10] = "-qemu"
emulator: qemu backend: argv[11] = "-s"
emulator: qemu backend: argv[12] = "-S"
emulator: Concatenated backend parameters:
 /home/fly2016/Android/Sdk/tools/emulator64-arm -avd Debug_Kernel -verbose -netfast -show-kernel -kernel ./arch/arm/boot/zImage -gpu mesa -qemu -s -S
emulator: Android virtual device file at: /home/fly2016/.android/avd/Debug_Kernel.ini
emulator: virtual device content at /home/fly2016/.android/avd/Debug_Kernel.avd
emulator: virtual device config file: /home/fly2016/.android/avd/Debug_Kernel.avd/config.ini
emulator: using core hw config path: /home/fly2016/.android/avd/Debug_Kernel.avd/hardware-qemu.ini
emulator: Found AVD target API level: 19
emulator: Read property file at /home/fly2016/Android/Sdk/system-images/android-19/default/armeabi-v7a//build.prop
emulator: No boot.prop property file found.
emulator: found skin 'nexus_5' in directory: /opt/android-studio/plugins/android/lib/device-art-resources/
emulator: autoconfig: -skin nexus_5
emulator: autoconfig: -skindir /opt/android-studio/plugins/android/lib/device-art-resources/
emulator: Auto-detect: Kernel image requires legacy device naming scheme.
emulator: Auto-detect: Kernel does support YAFFS2 partitions.
emulator: autoconfig: -ramdisk /home/fly2016/Android/Sdk/system-images/android-19/default/armeabi-v7a//ramdisk.img
emulator: Using initial system image: /home/fly2016/Android/Sdk/system-images/android-19/default/armeabi-v7a//system.img
emulator: autoconfig: -initdata /home/fly2016/.android/avd/Debug_Kernel.avd/userdata.img
emulator: autoconfig: -cache /home/fly2016/.android/avd/Debug_Kernel.avd/cache.img
emulator: autoconfig: -sdcard /home/fly2016/.android/avd/Debug_Kernel.avd/sdcard.img
emulator: Physical RAM size: 1536MB

emulator: VM heap size 64MB is below hardware specified minimum of 384MB,setting it to that value
emulator: System image is read only
emulator: GPU emulation enabled using 'mesa' mode
emulator: Found 1 DNS servers: 192.168.170.2
emulator: trying to load skin file '/opt/android-studio/plugins/android/lib/device-art-resources//nexus_5/layout'
emulator: Found 1 DNS servers: 192.168.170.2
emulator: WARNING: Classic qemu does not support SMP. The hw.cpu.ncore option from your config file is ignored.
Content of hardware configuration file:
  hw.cpu.arch = arm
  hw.cpu.model = cortex-a8
  hw.cpu.ncore = 2
  hw.ramSize = 1536
  hw.screen = touch
  hw.mainKeys = false
  hw.trackBall = false
  hw.keyboard = true
  hw.keyboard.lid = false
  hw.keyboard.charmap = qwerty2
  hw.dPad = false
  hw.gsmModem = true
  hw.gps = true
  hw.battery = true
  hw.accelerometer = true
  hw.audioInput = true
  hw.audioOutput = true
  hw.sdCard = true
  hw.sdCard.path = /home/fly2016/.android/avd/Debug_Kernel.avd/sdcard.img
  disk.cachePartition = true
  disk.cachePartition.path = /home/fly2016/.android/avd/Debug_Kernel.avd/cache.img
  disk.cachePartition.size = 66m
  hw.lcd.width = 1080
  hw.lcd.height = 1920
  hw.lcd.depth = 16
  hw.lcd.density = 480
  hw.lcd.backlight = true
  hw.gpu.enabled = true
  hw.gpu.mode = mesa
  hw.gpu.blacklisted = no
  hw.initialOrientation = portrait
  hw.camera.back = none
  hw.camera.front = none
  vm.heapSize = 384
  hw.sensors.light = true
  hw.sensors.pressure = true
  hw.sensors.humidity = true
  hw.sensors.proximity = true
  hw.sensors.magnetic_field = true
  hw.sensors.orientation = true
  hw.sensors.temperature = true
  hw.useext4 = true
  kernel.path = ./arch/arm/boot/zImage
  kernel.newDeviceNaming = no
  kernel.supportsYaffs2 = yes
  disk.ramdisk.path = /home/fly2016/Android/Sdk/system-images/android-19/default/armeabi-v7a//ramdisk.img
  disk.systemPartition.initPath = /home/fly2016/Android/Sdk/system-images/android-19/default/armeabi-v7a//system.img
  disk.systemPartition.size = 550m
  disk.dataPartition.path = /home/fly2016/.android/avd/Debug_Kernel.avd/userdata-qemu.img
  disk.dataPartition.initPath = /home/fly2016/.android/avd/Debug_Kernel.avd/userdata.img
  disk.dataPartition.size = 550m
  avd.name = Debug_Kernel
.
emulator: WARNING: CPU acceleration only works with x86/x86_64 system images.
QEMU options list:
emulator: argv[00] = "/home/fly2016/Android/Sdk/tools/emulator64-arm"
emulator: argv[01] = "-netfast"
emulator: argv[02] = "-dns-server"
emulator: argv[03] = "192.168.170.2"
emulator: argv[04] = "-serial"
emulator: argv[05] = "android-kmsg"
emulator: argv[06] = "-serial"
emulator: argv[07] = "null"
emulator: argv[08] = "-android-hw"
emulator: argv[09] = "/home/fly2016/.android/avd/Debug_Kernel.avd/hardware-qemu.ini"
emulator: argv[10] = "-s"
emulator: argv[11] = "-S"
emulator: argv[12] = "-append"
emulator: argv[13] = "qemu=1 androidboot.hardware=goldfish console=ttyS0 android.qemud=1 android.checkjni=1 qemu.gles=1"
Concatenated QEMU options:
 /home/fly2016/Android/Sdk/tools/emulator64-arm -netfast -dns-server 192.168.170.2 -serial android-kmsg -serial null -android-hw /home/fly2016/.android/avd/Debug_Kernel.avd/hardware-qemu.ini -s -S -append 'qemu=1 androidboot.hardware=goldfish console=ttyS0 android.qemud=1 android.checkjni=1 qemu.gles=1'
emulator: Starting QEMU main loop
emulator: registered 'boot-properties' qemud service
emulator: Using kernel serial device prefix: ttyS
emulator: AVD Name: Debug_Kernel
emulator: Ramdisk image contains fstab.goldfish file
emulator: Found format of system partition: 'ext4'
emulator: Found format of userdata partition: 'ext4'
emulator: Found format of cache partition: 'ext4'
emulator: system partition format: ext4
emulator: nand_add_dev: system,size=0x22600000,file=/home/fly2016/Android/Sdk/system-images/android-19/default/armeabi-v7a//system.img,pagesize=512,extrasize=0,readonly
emulator: userdata partition format: ext4
emulator: nand_add_dev: userdata,size=0x22600000,file=/home/fly2016/.android/avd/Debug_Kernel.avd/userdata-qemu.img,pagesize=512,extrasize=0
emulator: cache partition format: ext4
emulator: Creating empty cache partition image at: /home/fly2016/.android/avd/Debug_Kernel.avd/cache.img
Creating filesystem with parameters:
    Size: 69206016
    Block size: 4096
    Blocks per group: 32768
    Inodes per group: 4224
    Inode size: 256
    Journal blocks: 1024
    Label: 
    Blocks: 16896
    Block groups: 1
    Reserved block group size: 7
Created filesystem with 11/4224 inodes and 1302/16896 blocks
emulator: nand_add_dev: cache,size=0x4200000,file=/home/fly2016/.android/avd/Debug_Kernel.avd/cache.img,pagesize=512,extrasize=0
emulator: Adding boot property: 'dalvik.vm.heapsize' = '384m'
emulator: Adding boot property: 'qemu.sf.lcd_density' = '480'
emulator: Adding boot property: 'qemu.hw.mainkeys' = '0'
emulator: Adding boot property: 'qemu.sf.fake_camera' = 'none'
emulator: Found 1 DNS servers: 192.168.170.2
emulator: Adding boot property: 'ro.opengles.version' = '131072'
emulator: Initializing hardware OpenGLES emulation support
emulator: Kernel parameters: qemu=1 androidboot.hardware=goldfish console=ttyS0 android.qemud=1 android.checkjni=1 qemu.gles=1
emulator: ro.adb.qemud invalid or not found, API >= 16, defaulting ro.adb.qemud = 0
emulator: (setup_console_and_adb_ports) trying console port 5554, adb port 5555 (legacy: true)
emulator: (android_console_start) initializing on port 5554
bind: Transport endpoint is not connected
emulator: (setup_console_and_adb_ports) trying console port 5556, adb port 5557 (legacy: true)
emulator: (android_console_start) initializing on port 5556
emulator: control console listening on port 5556, ADB on port 5557
emulator: sent '0012host:emulator:5557' to ADB server
emulator: Listening for console connections on port: 5556
emulator: Serial number of this emulator (for ADB): emulator-5556
emulator: android_hw_fingerprint_init: fingerprint qemud listen service initialized

emulator: Skipping metrics reporting: No user opt-in.

Android模拟器 emulator  命令的使用帮助说明如下,上面Android模拟器的各个启动参数的意思,可以参考下面命令帮助。

$ emulator -help
sh: 1: glxinfo: not found
Android Emulator usage: emulator [options] [-qemu args]
  options:
    -list-avds                     list available AVDs
    -sysdir <dir>                  search for system disk images in <dir>
    -system <file>                 read initial system image from <file>
    -writable-system               make system image writable after 'adb remount'
    -datadir <dir>                 write user data into <dir>
    -kernel <file>                 use specific emulated kernel
    -ramdisk <file>                ramdisk image (default <system>/ramdisk.img
    -image <file>                  obsolete, use -system <file> instead
    -initdata <file>               same as '-init-data <file>'
    -data <file>                   data image (default <datadir>/userdata-qemu.img
    -partition-size <size>         system/data partition size in MBs
    -cache <file>                  cache partition image (default is temporary file)
    -cache-size <size>             cache partition size in MBs
    -no-cache                      disable the cache partition
    -nocache                       same as -no-cache
    -sdcard <file>                 SD card image (default <datadir>/sdcard.img
    -snapstorage <file>            file that contains all state snapshots (default <datadir>/snapshots.img)
    -no-snapstorage                do not mount a snapshot storage file (this disables all snapshot functionality)
    -snapshot <name>               name of snapshot within storage file for auto-start and auto-save (default 'default-boot')
    -no-snapshot                   perform a full boot and do not do not auto-save, but qemu vmload and vmsave operate on snapstorage
    -no-snapshot-save              do not auto-save to snapshot on exit: abandon changed state
    -no-snapshot-load              do not auto-start from snapshot: perform a full boot
    -snapshot-list                 show a list of available snapshots
    -no-snapshot-update-time       do not do try to correct snapshot time on restore
    -wipe-data                     reset the user data image (copy it from initdata)
    -avd <name>                    use a specific android virtual device
    -skindir <dir>                 search skins in <dir> (default <system>/skins)
    -skin <name>                   select a given skin
    -no-skin                       deprecated: create an AVD with no skin instead
    -noskin                        same as -no-skin
    -memory <size>                 physical RAM size in MBs
    -accel <mode>                  Configure emulation acceleration
    -no-accel                      Same as '-accel off'
    -ranchu                        Use new emulator backend instead of the classic one
    -engine <engine>               Select engine. auto|classic|qemu2
    -netspeed <speed>              maximum network download/upload speeds
    -netdelay <delay>              network latency emulation
    -netfast                       disable network shaping
    -code-profile <name>           enable code profiling
    -show-kernel                   display kernel messages
    -shell                         enable root shell on current terminal
    -no-jni                        disable JNI checks in the Dalvik runtime
    -nojni                         same as -no-jni
    -logcat <tags>                 enable logcat output with given tags
    -use-system-libs               Use system libstdc++ instead of bundled one
    -no-audio                      disable audio support
    -noaudio                       same as -no-audio
    -audio <backend>               use specific audio backend
    -raw-keys                      disable Unicode keyboard reverse-mapping (deprecated)
    -radio <device>                redirect radio modem interface to character device
    -port <port>                   TCP port that will be used for the console
    -ports <consoleport>,<adbport> TCP ports used for the console and adb bridge
    -onion <image>                 use overlay PNG image over screen
    -onion-alpha <%age>            specify onion-skin translucency
    -onion-rotation 0|1|2|3        specify onion-skin rotation
    -dpi-device <dpi>              specify device's resolution in dpi (default 165)
    -scale <scale>                 scale emulator window (deprecated)
    -http-proxy <proxy>            make TCP connections through a HTTP/HTTPS proxy
    -timezone <timezone>           use this timezone instead of the host's default
    -dns-server <servers>          use this DNS server(s) in the emulated system
    -cpu-delay <cpudelay>          throttle CPU emulation
    -no-boot-anim                  disable animation for faster boot
    -no-window                     disable graphical window display
    -version                       display emulator version number
    -report-console <socket>       report console port to remote socket
    -gps <device>                  redirect NMEA GPS to character device
    -keyset <name>                 specify keyset file name
    -shell-serial <device>         specific character device for root shell
    -tcpdump <file>                capture network packets to file
    -bootchart <timeout>           enable bootcharting
    -charmap <file>                use specific key character map
    -prop <name>=<value>           set system property on boot
    -shared-net-id <number>        join the shared network, using IP address 10.1.2.<number>
    -nand-limits <nlimits>         enforce NAND/Flash read/write thresholds
    -gpu <mode>                    set hardware OpenGLES emulation mode
    -camera-back <mode>            set emulation mode for a camera facing back
    -camera-front <mode>           set emulation mode for a camera facing front
    -webcam-list                   lists web cameras available for emulation
    -screen <mode>                 set emulated screen mode
    -force-32bit                   always use 32-bit emulator
    -selinux <disabled|permissive> Set SELinux to either disabled or permissive mode
    -unix-pipe <path>              Add <path> to the list of allowed Unix pipes
    -fixed-scale                   Use fixed 1:1 scale for the initial emulator window.

     -qemu args...                 pass arguments to qemu
     -qemu -h                      display qemu help

     -verbose                      same as '-debug-init'
     -debug <tags>                 enable/disable debug messages
     -debug-<tag>                  enable specific debug messages
     -debug-no-<tag>               disable specific debug messages

     -help                         print this help
     -help-<option>                print option-specific help

     -help-disk-images             about disk images
     -help-keys                    supported key bindings
     -help-debug-tags              debug tags for -debug <tags>
     -help-char-devices            character <device> specification
     -help-environment             environment variables
     -help-keyset-file             key bindings configuration file
     -help-virtual-device          virtual device management
     -help-sdk-images              about disk images when using the SDK
     -help-build-i

以上是关于Android内核的编译和调试的主要内容,如果未能解决你的问题,请参考以下文章

Linux内核分析7

Android 逆向代码调试器开发 ( 使用 NDK 中的 ndk-build + Android.mk 编译 Android 平台的代码调试器可执行应用 )

Android 逆向代码调试器开发 ( 使用 NDK 中的 ndk-build + Android.mk 编译 Android 平台的代码调试器可执行应用 )

如何在Android设备中用NDK编译SQLite并且对SQLite进行操作

为啥delphi xe8 编译android软件非常慢

在qemu模拟的aarch32上使用kgtp