当前位置:   article > 正文

Android内核的编译和调试_android模拟器内核调试

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 系统上打开命令行终端,执行下面的命令,获取移动设备使用的芯片即获取移动设备内核源码的版本信息。

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



二、Android内核源码的下载

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

  1. $ git clone https://android.googlesource.com/kernel/goldfish.git
  2. $ cd goldfish/
  3. # 查看可以下载的Linux内核源码的版本
  4. $ git branch -a
  5. * master
  6. remotes/origin/HEAD -> origin/master
  7. remotes/origin/android-3.10
  8. remotes/origin/android-3.18
  9. remotes/origin/android-goldfish-2.6.29
  10. remotes/origin/android-goldfish-3.10
  11. remotes/origin/android-goldfish-3.10-l-mr1-dev
  12. remotes/origin/android-goldfish-3.10-m-dev
  13. remotes/origin/android-goldfish-3.10-n-dev
  14. remotes/origin/android-goldfish-3.18
  15. remotes/origin/android-goldfish-3.18-dev
  16. remotes/origin/android-goldfish-3.4
  17. remotes/origin/android-goldfish-3.4-l-mr1-dev
  18. remotes/origin/android-goldfish-4.4-dev
  19. remotes/origin/heads/for/android-goldfish-3.18-dev
  20. remotes/origin/linux-goldfish-3.0-wip
  21. remotes/origin/master
  22. # 选择下载android-goldfish-3.4的内核源码
  23. $ git checkout remotes/origin/android-goldfish-3.4
  24. # 或
  25. $ git checkout -t remotes/origin/android-goldfish-3.4 -b goldfish3.4
  26. # 下载编译工具链
  27. $ 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

  1. export CROSS_COMPILE=$(pwd)/arm-eabi-4.7/bin/arm-eabi-
  2. export ARCH=arm
  3. export SUBARCH=arm
  4. # 生成编译配置文件
  5. make goldfish_armv7_defconfig
赋予脚本文件 run_make_config.sh  以可执行权限,然后执行该脚本生成Android内核编译的配置文件 .config 。

  1. $ chmod +x run_make_config.sh
  2. $ 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内核编译配置命令的信息。

  1. $ make help
  2. Cleaning targets:
  3. clean - Remove most generated files but keep the config and
  4. enough build support to build external modules
  5. mrproper - Remove all generated files + config + various backup files
  6. distclean - mrproper + remove editor backup and patch files
  7. Configuration targets:
  8. config - Update current config utilising a line-oriented program
  9. nconfig - Update current config utilising a ncurses menu based program
  10. menuconfig - Update current config utilising a menu based program
  11. xconfig - Update current config utilising a QT based front-end
  12. gconfig - Update current config utilising a GTK based front-end
  13. oldconfig - Update current config utilising a provided .config as base
  14. localmodconfig - Update current config disabling modules not loaded
  15. localyesconfig - Update current config converting local mods to core
  16. silentoldconfig - Same as oldconfig, but quietly, additionally update deps
  17. defconfig - New config with default from ARCH supplied defconfig
  18. savedefconfig - Save current config as ./defconfig (minimal config)
  19. allnoconfig - New config where all options are answered with no
  20. allyesconfig - New config where all options are accepted with yes
  21. allmodconfig - New config selecting modules when possible
  22. alldefconfig - New config with all symbols set to default
  23. randconfig - New config with random answer to all options
  24. listnewconfig - List new options
  25. oldnoconfig - Same as silentoldconfig but set new symbols to n (unset)
  26. Other generic targets:
  27. all - Build all targets marked with [*]
  28. * vmlinux - Build the bare kernel
  29. * modules - Build all modules
  30. modules_install - Install all modules to INSTALL_MOD_PATH (default: /)
  31. firmware_install- Install all firmware to INSTALL_FW_PATH
  32. (default: $(INSTALL_MOD_PATH)/lib/firmware)
  33. dir/ - Build all files in dir and below
  34. dir/file.[oisS] - Build specified target only
  35. dir/file.lst - Build specified mixed source/assembly target only
  36. (requires a recent binutils and recent build (System.map))
  37. dir/file.ko - Build module including final link
  38. modules_prepare - Set up for building external modules
  39. tags/TAGS - Generate tags file for editors
  40. cscope - Generate cscope index
  41. gtags - Generate GNU GLOBAL index
  42. kernelrelease - Output the release version string
  43. kernelversion - Output the version stored in Makefile
  44. headers_install - Install sanitised kernel headers to INSTALL_HDR_PATH
  45. (default: /home/fly2016/Android4.4.4r1/goldfish-kernel-3.4/goldfish/usr)
  46. Static analysers
  47. checkstack - Generate a list of stack hogs
  48. namespacecheck - Name space analysis on compiled kernel
  49. versioncheck - Sanity check on version.h usage
  50. includecheck - Check for duplicate included header files
  51. export_report - List the usages of all exported symbols
  52. headers_check - Sanity check on exported headers
  53. headerdep - Detect inclusion cycles in headers
  54. coccicheck - Check with Coccinelle.
  55. Kernel packaging:
  56. rpm-pkg - Build both source and binary RPM kernel packages
  57. binrpm-pkg - Build only the binary kernel package
  58. deb-pkg - Build the kernel as a deb package
  59. tar-pkg - Build the kernel as an uncompressed tarball
  60. targz-pkg - Build the kernel as a gzip compressed tarball
  61. tarbz2-pkg - Build the kernel as a bzip2 compressed tarball
  62. tarxz-pkg - Build the kernel as a xz compressed tarball
  63. perf-tar-src-pkg - Build perf-3.4.67.tar source tarball
  64. perf-targz-src-pkg - Build perf-3.4.67.tar.gz source tarball
  65. perf-tarbz2-src-pkg - Build perf-3.4.67.tar.bz2 source tarball
  66. perf-tarxz-src-pkg - Build perf-3.4.67.tar.xz source tarball
  67. Documentation targets:
  68. Linux kernel internal documentation in different formats:
  69. htmldocs - HTML
  70. pdfdocs - PDF
  71. psdocs - Postscript
  72. xmldocs - XML DocBook
  73. mandocs - man pages
  74. installmandocs - install man pages generated by mandocs
  75. cleandocs - clean all generated DocBook files
  76. Architecture specific targets (arm):
  77. * zImage - Compressed kernel image (arch/arm/boot/zImage)
  78. Image - Uncompressed kernel image (arch/arm/boot/Image)
  79. * xipImage - XIP kernel image, if configured (arch/arm/boot/xipImage)
  80. uImage - U-Boot wrapped zImage
  81. bootpImage - Combined zImage and initial RAM disk
  82. (supply initrd image via make variable INITRD=<path>)
  83. dtbs - Build device tree blobs for enabled boards
  84. install - Install uncompressed kernel
  85. zinstall - Install compressed kernel
  86. uinstall - Install U-Boot wrapped compressed kernel
  87. Install using (your) ~/bin/installkernel or
  88. (distribution) /sbin/installkernel or
  89. install to $(INSTALL_PATH) and run lilo
  90. acs5k_defconfig - Build for acs5k
  91. acs5k_tiny_defconfig - Build for acs5k_tiny
  92. afeb9260_defconfig - Build for afeb9260
  93. ag5evm_defconfig - Build for ag5evm
  94. am200epdkit_defconfig - Build for am200epdkit
  95. ap4evb_defconfig - Build for ap4evb
  96. assabet_defconfig - Build for assabet
  97. at91rm9200_defconfig - Build for at91rm9200
  98. at91sam9260_defconfig - Build for at91sam9260
  99. at91sam9261_defconfig - Build for at91sam9261
  100. at91sam9263_defconfig - Build for at91sam9263
  101. at91sam9g20_defconfig - Build for at91sam9g20
  102. at91sam9g45_defconfig - Build for at91sam9g45
  103. at91sam9rl_defconfig - Build for at91sam9rl
  104. at91x40_defconfig - Build for at91x40
  105. badge4_defconfig - Build for badge4
  106. bcmring_defconfig - Build for bcmring
  107. bonito_defconfig - Build for bonito
  108. cam60_defconfig - Build for cam60
  109. cerfcube_defconfig - Build for cerfcube
  110. cm_x2xx_defconfig - Build for cm_x2xx
  111. cm_x300_defconfig - Build for cm_x300
  112. cns3420vb_defconfig - Build for cns3420vb
  113. colibri_pxa270_defconfig - Build for colibri_pxa270
  114. colibri_pxa300_defconfig - Build for colibri_pxa300
  115. collie_defconfig - Build for collie
  116. corgi_defconfig - Build for corgi
  117. cpu9260_defconfig - Build for cpu9260
  118. cpu9g20_defconfig - Build for cpu9g20
  119. da8xx_omapl_defconfig - Build for da8xx_omapl
  120. davinci_all_defconfig - Build for davinci_all
  121. dove_defconfig - Build for dove
  122. ebsa110_defconfig - Build for ebsa110
  123. edb7211_defconfig - Build for edb7211
  124. em_x270_defconfig - Build for em_x270
  125. ep93xx_defconfig - Build for ep93xx
  126. eseries_pxa_defconfig - Build for eseries_pxa
  127. exynos4_defconfig - Build for exynos4
  128. ezx_defconfig - Build for ezx
  129. footbridge_defconfig - Build for footbridge
  130. fortunet_defconfig - Build for fortunet
  131. g3evm_defconfig - Build for g3evm
  132. g4evm_defconfig - Build for g4evm
  133. goldfish_armv7_defconfig - Build for goldfish_armv7
  134. goldfish_defconfig - Build for goldfish
  135. h3600_defconfig - Build for h3600
  136. h5000_defconfig - Build for h5000
  137. h7201_defconfig - Build for h7201
  138. h7202_defconfig - Build for h7202
  139. hackkit_defconfig - Build for hackkit
  140. imote2_defconfig - Build for imote2
  141. imx_v4_v5_defconfig - Build for imx_v4_v5
  142. imx_v6_v7_defconfig - Build for imx_v6_v7
  143. integrator_defconfig - Build for integrator
  144. iop13xx_defconfig - Build for iop13xx
  145. iop32x_defconfig - Build for iop32x
  146. iop33x_defconfig - Build for iop33x
  147. ixp2000_defconfig - Build for ixp2000
  148. ixp23xx_defconfig - Build for ixp23xx
  149. ixp4xx_defconfig - Build for ixp4xx
  150. jornada720_defconfig - Build for jornada720
  151. kirkwood_defconfig - Build for kirkwood
  152. kota2_defconfig - Build for kota2
  153. ks8695_defconfig - Build for ks8695
  154. lart_defconfig - Build for lart
  155. lpc32xx_defconfig - Build for lpc32xx
  156. lpd270_defconfig - Build for lpd270
  157. lubbock_defconfig - Build for lubbock
  158. mackerel_defconfig - Build for mackerel
  159. magician_defconfig - Build for magician
  160. mainstone_defconfig - Build for mainstone
  161. marzen_defconfig - Build for marzen
  162. mini2440_defconfig - Build for mini2440
  163. mmp2_defconfig - Build for mmp2
  164. msm_defconfig - Build for msm
  165. mv78xx0_defconfig - Build for mv78xx0
  166. mxs_defconfig - Build for mxs
  167. neponset_defconfig - Build for neponset
  168. netwinder_defconfig - Build for netwinder
  169. netx_defconfig - Build for netx
  170. nhk8815_defconfig - Build for nhk8815
  171. nuc910_defconfig - Build for nuc910
  172. nuc950_defconfig - Build for nuc950
  173. nuc960_defconfig - Build for nuc960
  174. omap1_defconfig - Build for omap1
  175. omap2plus_defconfig - Build for omap2plus
  176. orion5x_defconfig - Build for orion5x
  177. palmz72_defconfig - Build for palmz72
  178. pcm027_defconfig - Build for pcm027
  179. pleb_defconfig - Build for pleb
  180. pnx4008_defconfig - Build for pnx4008
  181. pxa168_defconfig - Build for pxa168
  182. pxa255-idp_defconfig - Build for pxa255-idp
  183. pxa3xx_defconfig - Build for pxa3xx
  184. pxa910_defconfig - Build for pxa910
  185. qil-a9260_defconfig - Build for qil-a9260
  186. raumfeld_defconfig - Build for raumfeld
  187. realview_defconfig - Build for realview
  188. realview-smp_defconfig - Build for realview-smp
  189. rpc_defconfig - Build for rpc
  190. s3c2410_defconfig - Build for s3c2410
  191. s3c6400_defconfig - Build for s3c6400
  192. s5p64x0_defconfig - Build for s5p64x0
  193. s5pc100_defconfig - Build for s5pc100
  194. s5pv210_defconfig - Build for s5pv210
  195. sam9_l9260_defconfig - Build for sam9_l9260
  196. shannon_defconfig - Build for shannon
  197. shark_defconfig - Build for shark
  198. simpad_defconfig - Build for simpad
  199. spear3xx_defconfig - Build for spear3xx
  200. spear6xx_defconfig - Build for spear6xx
  201. spitz_defconfig - Build for spitz
  202. stamp9g20_defconfig - Build for stamp9g20
  203. tct_hammer_defconfig - Build for tct_hammer
  204. tegra_defconfig - Build for tegra
  205. trizeps4_defconfig - Build for trizeps4
  206. u300_defconfig - Build for u300
  207. u8500_defconfig - Build for u8500
  208. usb-a9260_defconfig - Build for usb-a9260
  209. versatile_defconfig - Build for versatile
  210. vexpress_defconfig - Build for vexpress
  211. viper_defconfig - Build for viper
  212. xcep_defconfig - Build for xcep
  213. zeus_defconfig - Build for zeus
  214. make V=0|1 [targets] 0 => quiet build (default), 1 => verbose build
  215. make V=2 [targets] 2 => give reason for rebuild of target
  216. make O=dir [targets] Locate all output files in "dir", including .config
  217. make C=1 [targets] Check all c source with $CHECK (sparse by default)
  218. make C=2 [targets] Force check of all c source with $CHECK
  219. make RECORDMCOUNT_WARN=1 [targets] Warn about ignored mcount sections
  220. make W=n [targets] Enable extra gcc checks, n=1,2,3 where
  221. 1: warnings which may be relevant and do not occur too often
  222. 2: warnings which occur quite often but may still be relevant
  223. 3: more obscure warnings, can most likely be ignored
  224. Multiple levels can be combined with W=12 or W=123
  225. Execute "make" or "make all" to build all targets marked with [*]
  226. For further info see the ./README file
当前Android内核源码的帮助文件 README 的全部内容信息:

  1. Linux kernel release 3.x <http://kernel.org/>
  2. These are the release notes for Linux version 3. Read them carefully,
  3. as they tell you what this is all about, explain how to install the
  4. kernel, and what to do if something goes wrong.
  5. WHAT IS LINUX?
  6. Linux is a clone of the operating system Unix, written from scratch by
  7. Linus Torvalds with assistance from a loosely-knit team of hackers across
  8. the Net. It aims towards POSIX and Single UNIX Specification compliance.
  9. It has all the features you would expect in a modern fully-fledged Unix,
  10. including true multitasking, virtual memory, shared libraries, demand
  11. loading, shared copy-on-write executables, proper memory management,
  12. and multistack networking including IPv4 and IPv6.
  13. It is distributed under the GNU General Public License - see the
  14. accompanying COPYING file for more details.
  15. ON WHAT HARDWARE DOES IT RUN?
  16. Although originally developed first for 32-bit x86-based PCs (386 or higher),
  17. today Linux also runs on (at least) the Compaq Alpha AXP, Sun SPARC and
  18. UltraSPARC, Motorola 68000, PowerPC, PowerPC64, ARM, Hitachi SuperH, Cell,
  19. IBM S/390, MIPS, HP PA-RISC, Intel IA-64, DEC VAX, AMD x86-64, AXIS CRIS,
  20. Xtensa, Tilera TILE, AVR32 and Renesas M32R architectures.
  21. Linux is easily portable to most general-purpose 32- or 64-bit architectures
  22. as long as they have a paged memory management unit (PMMU) and a port of the
  23. GNU C compiler (gcc) (part of The GNU Compiler Collection, GCC). Linux has
  24. also been ported to a number of architectures without a PMMU, although
  25. functionality is then obviously somewhat limited.
  26. Linux has also been ported to itself. You can now run the kernel as a
  27. userspace application - this is called UserMode Linux (UML).
  28. DOCUMENTATION:
  29. - There is a lot of documentation available both in electronic form on
  30. the Internet and in books, both Linux-specific and pertaining to
  31. general UNIX questions. I'd recommend looking into the documentation
  32. subdirectories on any Linux FTP site for the LDP (Linux Documentation
  33. Project) books. This README is not meant to be documentation on the
  34. system: there are much better sources available.
  35. - There are various README files in the Documentation/ subdirectory:
  36. these typically contain kernel-specific installation notes for some
  37. drivers for example. See Documentation/00-INDEX for a list of what
  38. is contained in each file. Please read the Changes file, as it
  39. contains information about the problems, which may result by upgrading
  40. your kernel.
  41. - The Documentation/DocBook/ subdirectory contains several guides for
  42. kernel developers and users. These guides can be rendered in a
  43. number of formats: PostScript (.ps), PDF, HTML, & man-pages, among others.
  44. After installation, "make psdocs", "make pdfdocs", "make htmldocs",
  45. or "make mandocs" will render the documentation in the requested format.
  46. INSTALLING the kernel source:
  47. - If you install the full sources, put the kernel tarball in a
  48. directory where you have permissions (eg. your home directory) and
  49. unpack it:
  50. gzip -cd linux-3.X.tar.gz | tar xvf -
  51. or
  52. bzip2 -dc linux-3.X.tar.bz2 | tar xvf -
  53. Replace "XX" with the version number of the latest kernel.
  54. Do NOT use the /usr/src/linux area! This area has a (usually
  55. incomplete) set of kernel headers that are used by the library header
  56. files. They should match the library, and not get messed up by
  57. whatever the kernel-du-jour happens to be.
  58. - You can also upgrade between 3.x releases by patching. Patches are
  59. distributed in the traditional gzip and the newer bzip2 format. To
  60. install by patching, get all the newer patch files, enter the
  61. top level directory of the kernel source (linux-3.x) and execute:
  62. gzip -cd ../patch-3.x.gz | patch -p1
  63. or
  64. bzip2 -dc ../patch-3.x.bz2 | patch -p1
  65. (repeat xx for all versions bigger than the version of your current
  66. source tree, _in_order_) and you should be ok. You may want to remove
  67. the backup files (xxx~ or xxx.orig), and make sure that there are no
  68. failed patches (xxx# or xxx.rej). If there are, either you or me has
  69. made a mistake.
  70. Unlike patches for the 3.x kernels, patches for the 3.x.y kernels
  71. (also known as the -stable kernels) are not incremental but instead apply
  72. directly to the base 3.x kernel. Please read
  73. Documentation/applying-patches.txt for more information.
  74. Alternatively, the script patch-kernel can be used to automate this
  75. process. It determines the current kernel version and applies any
  76. patches found.
  77. linux/scripts/patch-kernel linux
  78. The first argument in the command above is the location of the
  79. kernel source. Patches are applied from the current directory, but
  80. an alternative directory can be specified as the second argument.
  81. - If you are upgrading between releases using the stable series patches
  82. (for example, patch-3.x.y), note that these "dot-releases" are
  83. not incremental and must be applied to the 3.x base tree. For
  84. example, if your base kernel is 3.0 and you want to apply the
  85. 3.0.3 patch, you do not and indeed must not first apply the
  86. 3.0.1 and 3.0.2 patches. Similarly, if you are running kernel
  87. version 3.0.2 and want to jump to 3.0.3, you must first
  88. reverse the 3.0.2 patch (that is, patch -R) _before_ applying
  89. the 3.0.3 patch.
  90. You can read more on this in Documentation/applying-patches.txt
  91. - Make sure you have no stale .o files and dependencies lying around:
  92. cd linux
  93. make mrproper
  94. You should now have the sources correctly installed.
  95. SOFTWARE REQUIREMENTS
  96. Compiling and running the 3.x kernels requires up-to-date
  97. versions of various software packages. Consult
  98. Documentation/Changes for the minimum version numbers required
  99. and how to get updates for these packages. Beware that using
  100. excessively old versions of these packages can cause indirect
  101. errors that are very difficult to track down, so don't assume that
  102. you can just update packages when obvious problems arise during
  103. build or operation.
  104. BUILD directory for the kernel:
  105. When compiling the kernel all output files will per default be
  106. stored together with the kernel source code.
  107. Using the option "make O=output/dir" allow you to specify an alternate
  108. place for the output files (including .config).
  109. Example:
  110. kernel source code: /usr/src/linux-3.N
  111. build directory: /home/name/build/kernel
  112. To configure and build the kernel use:
  113. cd /usr/src/linux-3.N
  114. make O=/home/name/build/kernel menuconfig
  115. make O=/home/name/build/kernel
  116. sudo make O=/home/name/build/kernel modules_install install
  117. Please note: If the 'O=output/dir' option is used then it must be
  118. used for all invocations of make.
  119. CONFIGURING the kernel:
  120. Do not skip this step even if you are only upgrading one minor
  121. version. New configuration options are added in each release, and
  122. odd problems will turn up if the configuration files are not set up
  123. as expected. If you want to carry your existing configuration to a
  124. new version with minimal work, use "make oldconfig", which will
  125. only ask you for the answers to new questions.
  126. - Alternate configuration commands are:
  127. "make config" Plain text interface.
  128. "make menuconfig" Text based color menus, radiolists & dialogs.
  129. "make nconfig" Enhanced text based color menus.
  130. "make xconfig" X windows (Qt) based configuration tool.
  131. "make gconfig" X windows (Gtk) based configuration tool.
  132. "make oldconfig" Default all questions based on the contents of
  133. your existing ./.config file and asking about
  134. new config symbols.
  135. "make silentoldconfig"
  136. Like above, but avoids cluttering the screen
  137. with questions already answered.
  138. Additionally updates the dependencies.
  139. "make defconfig" Create a ./.config file by using the default
  140. symbol values from either arch/$ARCH/defconfig
  141. or arch/$ARCH/configs/${PLATFORM}_defconfig,
  142. depending on the architecture.
  143. "make ${PLATFORM}_defconfig"
  144. Create a ./.config file by using the default
  145. symbol values from
  146. arch/$ARCH/configs/${PLATFORM}_defconfig.
  147. Use "make help" to get a list of all available
  148. platforms of your architecture.
  149. "make allyesconfig"
  150. Create a ./.config file by setting symbol
  151. values to 'y' as much as possible.
  152. "make allmodconfig"
  153. Create a ./.config file by setting symbol
  154. values to 'm' as much as possible.
  155. "make allnoconfig" Create a ./.config file by setting symbol
  156. values to 'n' as much as possible.
  157. "make randconfig" Create a ./.config file by setting symbol
  158. values to random values.
  159. You can find more information on using the Linux kernel config tools
  160. in Documentation/kbuild/kconfig.txt.
  161. NOTES on "make config":
  162. - having unnecessary drivers will make the kernel bigger, and can
  163. under some circumstances lead to problems: probing for a
  164. nonexistent controller card may confuse your other controllers
  165. - compiling the kernel with "Processor type" set higher than 386
  166. will result in a kernel that does NOT work on a 386. The
  167. kernel will detect this on bootup, and give up.
  168. - A kernel with math-emulation compiled in will still use the
  169. coprocessor if one is present: the math emulation will just
  170. never get used in that case. The kernel will be slightly larger,
  171. but will work on different machines regardless of whether they
  172. have a math coprocessor or not.
  173. - the "kernel hacking" configuration details usually result in a
  174. bigger or slower kernel (or both), and can even make the kernel
  175. less stable by configuring some routines to actively try to
  176. break bad code to find kernel problems (kmalloc()). Thus you
  177. should probably answer 'n' to the questions for
  178. "development", "experimental", or "debugging" features.
  179. COMPILING the kernel:
  180. - Make sure you have at least gcc 3.2 available.
  181. For more information, refer to Documentation/Changes.
  182. Please note that you can still run a.out user programs with this kernel.
  183. - Do a "make" to create a compressed kernel image. It is also
  184. possible to do "make install" if you have lilo installed to suit the
  185. kernel makefiles, but you may want to check your particular lilo setup first.
  186. To do the actual install you have to be root, but none of the normal
  187. build should require that. Don't take the name of root in vain.
  188. - If you configured any of the parts of the kernel as `modules', you
  189. will also have to do "make modules_install".
  190. - Verbose kernel compile/build output:
  191. Normally the kernel build system runs in a fairly quiet mode (but not
  192. totally silent). However, sometimes you or other kernel developers need
  193. to see compile, link, or other commands exactly as they are executed.
  194. For this, use "verbose" build mode. This is done by inserting
  195. "V=1" in the "make" command. E.g.:
  196. make V=1 all
  197. To have the build system also tell the reason for the rebuild of each
  198. target, use "V=2". The default is "V=0".
  199. - Keep a backup kernel handy in case something goes wrong. This is
  200. especially true for the development releases, since each new release
  201. contains new code which has not been debugged. Make sure you keep a
  202. backup of the modules corresponding to that kernel, as well. If you
  203. are installing a new kernel with the same version number as your
  204. working kernel, make a backup of your modules directory before you
  205. do a "make modules_install".
  206. Alternatively, before compiling, use the kernel config option
  207. "LOCALVERSION" to append a unique suffix to the regular kernel version.
  208. LOCALVERSION can be set in the "General Setup" menu.
  209. - In order to boot your new kernel, you'll need to copy the kernel
  210. image (e.g. .../linux/arch/i386/boot/bzImage after compilation)
  211. to the place where your regular bootable kernel is found.
  212. - Booting a kernel directly from a floppy without the assistance of a
  213. bootloader such as LILO, is no longer supported.
  214. If you boot Linux from the hard drive, chances are you use LILO which
  215. uses the kernel image as specified in the file /etc/lilo.conf. The
  216. kernel image file is usually /vmlinuz, /boot/vmlinuz, /bzImage or
  217. /boot/bzImage. To use the new kernel, save a copy of the old image
  218. and copy the new image over the old one. Then, you MUST RERUN LILO
  219. to update the loading map!! If you don't, you won't be able to boot
  220. the new kernel image.
  221. Reinstalling LILO is usually a matter of running /sbin/lilo.
  222. You may wish to edit /etc/lilo.conf to specify an entry for your
  223. old kernel image (say, /vmlinux.old) in case the new one does not
  224. work. See the LILO docs for more information.
  225. After reinstalling LILO, you should be all set. Shutdown the system,
  226. reboot, and enjoy!
  227. If you ever need to change the default root device, video mode,
  228. ramdisk size, etc. in the kernel image, use the 'rdev' program (or
  229. alternatively the LILO boot options when appropriate). No need to
  230. recompile the kernel to change these parameters.
  231. - Reboot with the new kernel and enjoy.
  232. IF SOMETHING GOES WRONG:
  233. - If you have problems that seem to be due to kernel bugs, please check
  234. the file MAINTAINERS to see if there is a particular person associated
  235. with the part of the kernel that you are having trouble with. If there
  236. isn't anyone listed there, then the second best thing is to mail
  237. them to me (torvalds@linux-foundation.org), and possibly to any other
  238. relevant mailing-list or to the newsgroup.
  239. - In all bug-reports, *please* tell what kernel you are talking about,
  240. how to duplicate the problem, and what your setup is (use your common
  241. sense). If the problem is new, tell me so, and if the problem is
  242. old, please try to tell me when you first noticed it.
  243. - If the bug results in a message like
  244. unable to handle kernel paging request at address C0000010
  245. Oops: 0002
  246. EIP: 0010:XXXXXXXX
  247. eax: xxxxxxxx ebx: xxxxxxxx ecx: xxxxxxxx edx: xxxxxxxx
  248. esi: xxxxxxxx edi: xxxxxxxx ebp: xxxxxxxx
  249. ds: xxxx es: xxxx fs: xxxx gs: xxxx
  250. Pid: xx, process nr: xx
  251. xx xx xx xx xx xx xx xx xx xx
  252. or similar kernel debugging information on your screen or in your
  253. system log, please duplicate it *exactly*. The dump may look
  254. incomprehensible to you, but it does contain information that may
  255. help debugging the problem. The text above the dump is also
  256. important: it tells something about why the kernel dumped code (in
  257. the above example it's due to a bad kernel pointer). More information
  258. on making sense of the dump is in Documentation/oops-tracing.txt
  259. - If you compiled the kernel with CONFIG_KALLSYMS you can send the dump
  260. as is, otherwise you will have to use the "ksymoops" program to make
  261. sense of the dump (but compiling with CONFIG_KALLSYMS is usually preferred).
  262. This utility can be downloaded from
  263. ftp://ftp.<country>.kernel.org/pub/linux/utils/kernel/ksymoops/ .
  264. Alternately you can do the dump lookup by hand:
  265. - In debugging dumps like the above, it helps enormously if you can
  266. look up what the EIP value means. The hex value as such doesn't help
  267. me or anybody else very much: it will depend on your particular
  268. kernel setup. What you should do is take the hex value from the EIP
  269. line (ignore the "0010:"), and look it up in the kernel namelist to
  270. see which kernel function contains the offending address.
  271. To find out the kernel function name, you'll need to find the system
  272. binary associated with the kernel that exhibited the symptom. This is
  273. the file 'linux/vmlinux'. To extract the namelist and match it against
  274. the EIP from the kernel crash, do:
  275. nm vmlinux | sort | less
  276. This will give you a list of kernel addresses sorted in ascending
  277. order, from which it is simple to find the function that contains the
  278. offending address. Note that the address given by the kernel
  279. debugging messages will not necessarily match exactly with the
  280. function addresses (in fact, that is very unlikely), so you can't
  281. just 'grep' the list: the list will, however, give you the starting
  282. point of each kernel function, so by looking for the function that
  283. has a starting address lower than the one you are searching for but
  284. is followed by a function with a higher address you will find the one
  285. you want. In fact, it may be a good idea to include a bit of
  286. "context" in your problem report, giving a few lines around the
  287. interesting one.
  288. If you for some reason cannot do the above (you have a pre-compiled
  289. kernel image or similar), telling me as much about your setup as
  290. possible will help. Please read the REPORTING-BUGS document for details.
  291. - Alternately, you can use gdb on a running kernel. (read-only; i.e. you
  292. cannot change values or set break points.) To do this, first compile the
  293. kernel with -g; edit arch/i386/Makefile appropriately, then do a "make
  294. clean". You'll also need to enable CONFIG_PROC_FS (via "make config").
  295. After you've rebooted with the new kernel, do "gdb vmlinux /proc/kcore".
  296. You can now use all the usual gdb commands. The command to look up the
  297. point where your system crashed is "l *0xXXXXXXXX". (Replace the XXXes
  298. with the EIP value.)
  299. gdb'ing a non-running kernel currently fails because gdb (wrongly)
  300. disregards the starting offset for which the kernel is compiled.

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

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

  1. # 设置模拟器的运行内存-可选参数
  2. CONFIG_HIGHMEM=y
  3. CONFIG_DEBUG_KERNEL=y
  4. CONFIG_KGDB=y
  5. CONFIG_DEBUG_INFO=y
  6. # 真机设备调试需要设置这一项,模拟器不需要
  7. #CONFIG_KGDB_SERIAL_CONSOLE=y
  8. # 可以是直接在配置文件中去掉这一项
  9. 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 到环境变量中的操作命令:

  1. # 编辑环境变量配置文件
  2. $ sudo gedit /etc/profile
  3. # 添加到环境变量配置文件/etc/profile中的内容
  4. # Android SDK
  5. export ANDROID_SDK=/home/fly2016/Android/Sdk
  6. export PATH=$PATH:${ANDROID_SDK}/platform-tools:${ANDROID_SDK}/tools
  7. # Android NDK(顺便添加)
  8. export ANDROID_NDK=/home/fly2016/Android/Sdk/ndk-bundle
  9. export PATH=$PATH:${ANDROID_NDK}
  10. # 更新系统环境变量
  11. $ source /etc/profile
  12. # 测试Android SDK是否配置成功的命令
  13. $ adb verison
  14. $ emulator -help
  15. # 测试Android NDK是否配置成功的命令
  16. $ ndk-build
2.这里是用Android Studio的工具创建的Android虚拟机 Debug_Kernel,当然使用 Adt-bundle-x86_64的工具创建Android 虚拟机  Debug_Kernel 是可以的,甚至是使用 android create avd 命令进行Android模拟器的创建也是可以的。有关 android create avd 命令创建Android 虚拟机的使用帮助如下:

  1. $ android create avd
  2. Error: The parameters --name, --target must be defined for action 'create avd'
  3. Usage:
  4. android [global options] create avd [action options]
  5. Global options:
  6. -h --help : Help on a specific command.
  7. -v --verbose : Verbose mode, shows errors, warnings and all messages.
  8. --clear-cache: Clear the SDK Manager repository manifest cache.
  9. -s --silent : Silent mode, shows errors only.
  10. Action "create avd":
  11. Creates a new Android Virtual Device.
  12. Options:
  13. -g --tag : The sys-img tag to use for the AVD. The default is to
  14. auto-select if the platform has only one tag for its system
  15. images.
  16. -c --sdcard : Path to a shared SD card image, or size of a new sdcard for
  17. the new AVD.
  18. -n --name : Name of the new AVD. [required]
  19. -a --snapshot: Place a snapshots file in the AVD, to enable persistence.
  20. -p --path : Directory where the new AVD will be created.
  21. -f --force : Forces creation (overwrites an existing AVD)
  22. -s --skin : Skin for the new AVD.
  23. -t --target : Target ID of the new AVD. [required]
  24. -b --abi : The ABI to use for the AVD. The default is to auto-select the
  25. ABI if the platform has only one ABI for its system images.
  26. -d --device : The optional device definition to use. Can be a device index
  27. or id.

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

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

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

  1. # 查看已经创建的Android模拟器
  2. $ emulator -list-avds
  3. # 启动运行创建的Android模拟器Debug_Kernel
  4. $ 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 选项 设置运行的内存大小,增加运行内存使调试运行更流畅。


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

  1. 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
  2. emulator:Found AVD name 'Debug_Kernel'
  3. emulator:Found AVD target architecture: arm
  4. emulator: Found directory: /home/fly2016/Android/Sdk/system-images/android-19/default/armeabi-v7a/
  5. emulator:Probing for /home/fly2016/Android/Sdk/system-images/android-19/default/armeabi-v7a//kernel-ranchu: file missing
  6. emulator:Auto-config: -engine classic (based on configuration)
  7. emulator: Found directory: /home/fly2016/Android/Sdk/system-images/android-19/default/armeabi-v7a/
  8. emulator:Looking for emulator-arm to emulate 'arm' CPU
  9. emulator:Probing program: /home/fly2016/Android/Sdk/tools/emulator64-arm
  10. emulator:return result: /home/fly2016/Android/Sdk/tools/emulator64-arm
  11. emulator:Found target-specific 64-bit emulator binary: /home/fly2016/Android/Sdk/tools/emulator64-arm
  12. emulator:Adding library search path: '/home/fly2016/Android/Sdk/tools/lib64'
  13. emulator:Adding library search path: '/home/fly2016/Android/Sdk/tools/lib64/libstdc++'
  14. emulator: Found directory: /home/fly2016/Android/Sdk/system-images/android-19/default/armeabi-v7a/
  15. emulator: Found directory: /home/fly2016/Android/Sdk/system-images/android-19/default/armeabi-v7a/
  16. emulator:GPU emulation enabled using 'mesa' mode
  17. WARNING: The Mesa software renderer is deprecated. Use Swiftshader (-gpu swiftshader) for software rendering.
  18. emulator: Adding library search path for Qt: '/home/fly2016/Android/Sdk/tools/lib64/qt/lib'
  19. emulator: Setting Qt plugin search path: QT_QPA_PLATFORM_PLUGIN_PATH=/home/fly2016/Android/Sdk/tools/lib64/qt/plugins
  20. emulator: Running :/home/fly2016/Android/Sdk/tools/emulator64-arm
  21. emulator: qemu backend: argv[00] = "/home/fly2016/Android/Sdk/tools/emulator64-arm"
  22. emulator: qemu backend: argv[01] = "-avd"
  23. emulator: qemu backend: argv[02] = "Debug_Kernel"
  24. emulator: qemu backend: argv[03] = "-verbose"
  25. emulator: qemu backend: argv[04] = "-netfast"
  26. emulator: qemu backend: argv[05] = "-show-kernel"
  27. emulator: qemu backend: argv[06] = "-kernel"
  28. emulator: qemu backend: argv[07] = "./arch/arm/boot/zImage"
  29. emulator: qemu backend: argv[08] = "-gpu"
  30. emulator: qemu backend: argv[09] = "mesa"
  31. emulator: qemu backend: argv[10] = "-qemu"
  32. emulator: qemu backend: argv[11] = "-s"
  33. emulator: qemu backend: argv[12] = "-S"
  34. emulator: Concatenated backend parameters:
  35. /home/fly2016/Android/Sdk/tools/emulator64-arm -avd Debug_Kernel -verbose -netfast -show-kernel -kernel ./arch/arm/boot/zImage -gpu mesa -qemu -s -S
  36. emulator: Android virtual device file at: /home/fly2016/.android/avd/Debug_Kernel.ini
  37. emulator: virtual device content at /home/fly2016/.android/avd/Debug_Kernel.avd
  38. emulator: virtual device config file: /home/fly2016/.android/avd/Debug_Kernel.avd/config.ini
  39. emulator: using core hw config path: /home/fly2016/.android/avd/Debug_Kernel.avd/hardware-qemu.ini
  40. emulator: Found AVD target API level: 19
  41. emulator: Read property file at /home/fly2016/Android/Sdk/system-images/android-19/default/armeabi-v7a//build.prop
  42. emulator: No boot.prop property file found.
  43. emulator: found skin 'nexus_5' in directory: /opt/android-studio/plugins/android/lib/device-art-resources/
  44. emulator: autoconfig: -skin nexus_5
  45. emulator: autoconfig: -skindir /opt/android-studio/plugins/android/lib/device-art-resources/
  46. emulator: Auto-detect: Kernel image requires legacy device naming scheme.
  47. emulator: Auto-detect: Kernel does support YAFFS2 partitions.
  48. emulator: autoconfig: -ramdisk /home/fly2016/Android/Sdk/system-images/android-19/default/armeabi-v7a//ramdisk.img
  49. emulator: Using initial system image: /home/fly2016/Android/Sdk/system-images/android-19/default/armeabi-v7a//system.img
  50. emulator: autoconfig: -initdata /home/fly2016/.android/avd/Debug_Kernel.avd/userdata.img
  51. emulator: autoconfig: -cache /home/fly2016/.android/avd/Debug_Kernel.avd/cache.img
  52. emulator: autoconfig: -sdcard /home/fly2016/.android/avd/Debug_Kernel.avd/sdcard.img
  53. emulator: Physical RAM size: 1536MB
  54. emulator: VM heap size 64MB is below hardware specified minimum of 384MB,setting it to that value
  55. emulator: System image is read only
  56. emulator: GPU emulation enabled using 'mesa' mode
  57. emulator: Found 1 DNS servers: 192.168.170.2
  58. emulator: trying to load skin file '/opt/android-studio/plugins/android/lib/device-art-resources//nexus_5/layout'
  59. emulator: Found 1 DNS servers: 192.168.170.2
  60. emulator: WARNING: Classic qemu does not support SMP. The hw.cpu.ncore option from your config file is ignored.
  61. Content of hardware configuration file:
  62. hw.cpu.arch = arm
  63. hw.cpu.model = cortex-a8
  64. hw.cpu.ncore = 2
  65. hw.ramSize = 1536
  66. hw.screen = touch
  67. hw.mainKeys = false
  68. hw.trackBall = false
  69. hw.keyboard = true
  70. hw.keyboard.lid = false
  71. hw.keyboard.charmap = qwerty2
  72. hw.dPad = false
  73. hw.gsmModem = true
  74. hw.gps = true
  75. hw.battery = true
  76. hw.accelerometer = true
  77. hw.audioInput = true
  78. hw.audioOutput = true
  79. hw.sdCard = true
  80. hw.sdCard.path = /home/fly2016/.android/avd/Debug_Kernel.avd/sdcard.img
  81. disk.cachePartition = true
  82. disk.cachePartition.path = /home/fly2016/.android/avd/Debug_Kernel.avd/cache.img
  83. disk.cachePartition.size = 66m
  84. hw.lcd.width = 1080
  85. hw.lcd.height = 1920
  86. hw.lcd.depth = 16
  87. hw.lcd.density = 480
  88. hw.lcd.backlight = true
  89. hw.gpu.enabled = true
  90. hw.gpu.mode = mesa
  91. hw.gpu.blacklisted = no
  92. hw.initialOrientation = portrait
  93. hw.camera.back = none
  94. hw.camera.front = none
  95. vm.heapSize = 384
  96. hw.sensors.light = true
  97. hw.sensors.pressure = true
  98. hw.sensors.humidity = true
  99. hw.sensors.proximity = true
  100. hw.sensors.magnetic_field = true
  101. hw.sensors.orientation = true
  102. hw.sensors.temperature = true
  103. hw.useext4 = true
  104. kernel.path = ./arch/arm/boot/zImage
  105. kernel.newDeviceNaming = no
  106. kernel.supportsYaffs2 = yes
  107. disk.ramdisk.path = /home/fly2016/Android/Sdk/system-images/android-19/default/armeabi-v7a//ramdisk.img
  108. disk.systemPartition.initPath = /home/fly2016/Android/Sdk/system-images/android-19/default/armeabi-v7a//system.img
  109. disk.systemPartition.size = 550m
  110. disk.dataPartition.path = /home/fly2016/.android/avd/Debug_Kernel.avd/userdata-qemu.img
  111. disk.dataPartition.initPath = /home/fly2016/.android/avd/Debug_Kernel.avd/userdata.img
  112. disk.dataPartition.size = 550m
  113. avd.name = Debug_Kernel
  114. .
  115. emulator: WARNING: CPU acceleration only works with x86/x86_64 system images.
  116. QEMU options list:
  117. emulator: argv[00] = "/home/fly2016/Android/Sdk/tools/emulator64-arm"
  118. emulator: argv[01] = "-netfast"
  119. emulator: argv[02] = "-dns-server"
  120. emulator: argv[03] = "192.168.170.2"
  121. emulator: argv[04] = "-serial"
  122. emulator: argv[05] = "android-kmsg"
  123. emulator: argv[06] = "-serial"
  124. emulator: argv[07] = "null"
  125. emulator: argv[08] = "-android-hw"
  126. emulator: argv[09] = "/home/fly2016/.android/avd/Debug_Kernel.avd/hardware-qemu.ini"
  127. emulator: argv[10] = "-s"
  128. emulator: argv[11] = "-S"
  129. emulator: argv[12] = "-append"
  130. emulator: argv[13] = "qemu=1 androidboot.hardware=goldfish console=ttyS0 android.qemud=1 android.checkjni=1 qemu.gles=1"
  131. Concatenated QEMU options:
  132. /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'
  133. emulator: Starting QEMU main loop
  134. emulator: registered 'boot-properties' qemud service
  135. emulator: Using kernel serial device prefix: ttyS
  136. emulator: AVD Name: Debug_Kernel
  137. emulator: Ramdisk image contains fstab.goldfish file
  138. emulator: Found format of system partition: 'ext4'
  139. emulator: Found format of userdata partition: 'ext4'
  140. emulator: Found format of cache partition: 'ext4'
  141. emulator: system partition format: ext4
  142. 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
  143. emulator: userdata partition format: ext4
  144. emulator: nand_add_dev: userdata,size=0x22600000,file=/home/fly2016/.android/avd/Debug_Kernel.avd/userdata-qemu.img,pagesize=512,extrasize=0
  145. emulator: cache partition format: ext4
  146. emulator: Creating empty cache partition image at: /home/fly2016/.android/avd/Debug_Kernel.avd/cache.img
  147. Creating filesystem with parameters:
  148. Size: 69206016
  149. Block size: 4096
  150. Blocks per group: 32768
  151. Inodes per group: 4224
  152. Inode size: 256
  153. Journal blocks: 1024
  154. Label:
  155. Blocks: 16896
  156. Block groups: 1
  157. Reserved block group size: 7
  158. Created filesystem with 11/4224 inodes and 1302/16896 blocks
  159. emulator: nand_add_dev: cache,size=0x4200000,file=/home/fly2016/.android/avd/Debug_Kernel.avd/cache.img,pagesize=512,extrasize=0
  160. emulator: Adding boot property: 'dalvik.vm.heapsize' = '384m'
  161. emulator: Adding boot property: 'qemu.sf.lcd_density' = '480'
  162. emulator: Adding boot property: 'qemu.hw.mainkeys' = '0'
  163. emulator: Adding boot property: 'qemu.sf.fake_camera' = 'none'
  164. emulator: Found 1 DNS servers: 192.168.170.2
  165. emulator: Adding boot property: 'ro.opengles.version' = '131072'
  166. emulator: Initializing hardware OpenGLES emulation support
  167. emulator: Kernel parameters: qemu=1 androidboot.hardware=goldfish console=ttyS0 android.qemud=1 android.checkjni=1 qemu.gles=1
  168. emulator: ro.adb.qemud invalid or not found, API >= 16, defaulting ro.adb.qemud = 0
  169. emulator: (setup_console_and_adb_ports) trying console port 5554, adb port 5555 (legacy: true)
  170. emulator: (android_console_start) initializing on port 5554
  171. bind: Transport endpoint is not connected
  172. emulator: (setup_console_and_adb_ports) trying console port 5556, adb port 5557 (legacy: true)
  173. emulator: (android_console_start) initializing on port 5556
  174. emulator: control console listening on port 5556, ADB on port 5557
  175. emulator: sent '0012host:emulator:5557' to ADB server
  176. emulator: Listening for console connections on port: 5556
  177. emulator: Serial number of this emulator (for ADB): emulator-5556
  178. emulator: android_hw_fingerprint_init: fingerprint qemud listen service initialized
  179. emulator: Skipping metrics reporting: No user opt-in.

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

  1. $ emulator -help
  2. sh: 1: glxinfo: not found
  3. Android Emulator usage: emulator [options] [-qemu args]
  4. options:
  5. -list-avds list available AVDs
  6. -sysdir <dir> search for system disk images in <dir>
  7. -system <file> read initial system image from <file>
  8. -writable-system make system image writable after 'adb remount'
  9. -datadir <dir> write user data into <dir>
  10. -kernel <file> use specific emulated kernel
  11. -ramdisk <file> ramdisk image (default <system>/ramdisk.img
  12. -image <file> obsolete, use -system <file> instead
  13. -initdata <file> same as '-init-data <file>'
  14. -data <file> data image (default <datadir>/userdata-qemu.img
  15. -partition-size <size> system/data partition size in MBs
  16. -cache <file> cache partition image (default is temporary file)
  17. -cache-size <size> cache partition size in MBs
  18. -no-cache disable the cache partition
  19. -nocache same as -no-cache
  20. -sdcard <file> SD card image (default <datadir>/sdcard.img
  21. -snapstorage <file> file that contains all state snapshots (default <datadir>/snapshots.img)
  22. -no-snapstorage do not mount a snapshot storage file (this disables all snapshot functionality)
  23. -snapshot <name> name of snapshot within storage file for auto-start and auto-save (default 'default-boot')
  24. -no-snapshot perform a full boot and do not do not auto-save, but qemu vmload and vmsave operate on snapstorage
  25. -no-snapshot-save do not auto-save to snapshot on exit: abandon changed state
  26. -no-snapshot-load do not auto-start from snapshot: perform a full boot
  27. -snapshot-list show a list of available snapshots
  28. -no-snapshot-update-time do not do try to correct snapshot time on restore
  29. -wipe-data reset the user data image (copy it from initdata)
  30. -avd <name> use a specific android virtual device
  31. -skindir <dir> search skins in <dir> (default <system>/skins)
  32. -skin <name> select a given skin
  33. -no-skin deprecated: create an AVD with no skin instead
  34. -noskin same as -no-skin
  35. -memory <size> physical RAM size in MBs
  36. -accel <mode> Configure emulation acceleration
  37. -no-accel Same as '-accel off'
  38. -ranchu Use new emulator backend instead of the classic one
  39. -engine <engine> Select engine. auto|classic|qemu2
  40. -netspeed <speed> maximum network download/upload speeds
  41. -netdelay <delay> network latency emulation
  42. -netfast disable network shaping
  43. -code-profile <name> enable code profiling
  44. -show-kernel display kernel messages
  45. -shell enable root shell on current terminal
  46. -no-jni disable JNI checks in the Dalvik runtime
  47. -nojni same as -no-jni
  48. -logcat <tags> enable logcat output with given tags
  49. -use-system-libs Use system libstdc++ instead of bundled one
  50. -no-audio disable audio support
  51. -noaudio same as -no-audio
  52. -audio <backend> use specific audio backend
  53. -raw-keys disable Unicode keyboard reverse-mapping (deprecated)
  54. -radio <device> redirect radio modem interface to character device
  55. -port <port> TCP port that will be used for the console
  56. -ports <consoleport>,<adbport> TCP ports used for the console and adb bridge
  57. -onion <image> use overlay PNG image over screen
  58. -onion-alpha <%age> specify onion-skin translucency
  59. -onion-rotation 0|1|2|3 specify onion-skin rotation
  60. -dpi-device <dpi> specify device's resolution in dpi (default 165)
  61. -scale <scale> scale emulator window (deprecated)
  62. -http-proxy <proxy> make TCP connections through a HTTP/HTTPS proxy
  63. -timezone <timezone> use this timezone instead of the host's default
  64. -dns-server <servers> use this DNS server(s) in the emulated system
  65. -cpu-delay <cpudelay> throttle CPU emulation
  66. -no-boot-anim disable animation for faster boot
  67. -no-window disable graphical window display
  68. -version display emulator version number
  69. -report-console <socket> report console port to remote socket
  70. -gps <device> redirect NMEA GPS to character device
  71. -keyset <name> specify keyset file name
  72. -shell-serial <device> specific character device for root shell
  73. -tcpdump <file> capture network packets to file
  74. -bootchart <timeout> enable bootcharting
  75. -charmap <file> use specific key character map
  76. -prop <name>=<value> set system property on boot
  77. -shared-net-id <number> join the shared network, using IP address 10.1.2.<number>
  78. -nand-limits <nlimits> enforce NAND/Flash read/write thresholds
  79. -gpu <mode> set hardware OpenGLES emulation mode
  80. -camera-back <mode> set emulation mode for a camera facing back
  81. -camera-front <mode> set emulation mode for a camera facing front
  82. -webcam-list lists web cameras available for emulation
  83. -screen <mode> set emulated screen mode
  84. -force-32bit always use 32-bit emulator
  85. -selinux <disabled|permissive> Set SELinux to either disabled or permissive mode
  86. -unix-pipe <path> Add <path> to the list of allowed Unix pipes
  87. -fixed-scale Use fixed 1:1 scale for the initial emulator window.
  88. -qemu args... pass arguments to qemu
  89. -qemu -h display qemu help
  90. -verbose same as '-debug-init'
  91. -debug <tags> enable/disable debug messages
  92. -debug-<tag> enable specific debug messages
  93. -debug-no-<tag> disable specific debug messages
  94. -help print this help
  95. -help-<option> print option-specific help
  96. -help-disk-images about disk images
  97. -help-keys supported key bindings
  98. -help-debug-tags debug tags for -debug <tags>
  99. -help-char-devices character <device> specification
  100. -help-environment environment variables
  101. -help-keyset-file key bindings configuration file
  102. -help-virtual-device virtual device management
  103. -help-sdk-images about disk images when using the SDK
  104. -help-build-images about disk images when building Android
  105. -help-all prints all help content

其实Android模拟器 emulator 就是 基于qemu虚拟机 开发的,因此Android模拟器 emulator 在运行的时候也支持qemu虚拟机的命令,在上面以 调试模式启动 Android虚拟机 Debug_Kernel 时使用的启动选项 -qemu -s -S的作用,可以参考命令行的帮助,如下图:



Android模拟器 emulator 使用qemu虚拟机命令行参数 的详细帮助参考如下:

  1. fly2016@ubuntu:~$ emulator -qemu -h
  2. sh: 1: glxinfo: not found
  3. QEMU emulator version 2.2.0 , Copyright (c) 2003-2008 Fabrice Bellard
  4. usage: qemu-system-i386 [options] [disk_image]
  5. 'disk_image' is a raw hard disk image for IDE hard disk 0
  6. Standard options:
  7. -h or -help display this help and exit
  8. -version display version information and exit
  9. -machine [type=]name[,prop[=value][,...]]
  10. selects emulated machine ('-machine help' for list)
  11. property accel=accel1[:accel2[:...]] selects accelerator
  12. supported accelerators are kvm, xen, tcg (default: tcg)
  13. kernel_irqchip=on|off controls accelerated irqchip support
  14. vmport=on|off|auto controls emulation of vmport (default: auto)
  15. kvm_shadow_mem=size of KVM shadow MMU
  16. dump-guest-core=on|off include guest memory in a core dump (default=on)
  17. mem-merge=on|off controls memory merge support (default: on)
  18. iommu=on|off controls emulated Intel IOMMU (VT-d) support (default=off)
  19. -cpu cpu select CPU ('-cpu help' for list)
  20. -smp [cpus=]n[,maxcpus=cpus][,cores=cores][,threads=threads][,sockets=sockets]
  21. set the number of CPUs to 'n' [default=1]
  22. maxcpus= maximum number of total cpus, including
  23. offline CPUs for hotplug, etc
  24. cores= number of CPU cores on one socket
  25. threads= number of threads on one CPU core
  26. sockets= number of discrete sockets in the system
  27. -numa node[,mem=size][,cpus=cpu[-cpu]][,nodeid=node]
  28. -numa node[,memdev=id][,cpus=cpu[-cpu]][,nodeid=node]
  29. -add-fd fd=fd,set=set[,opaque=opaque]
  30. Add 'fd' to fd 'set'
  31. -set group.id.arg=value
  32. set <arg> parameter for item <id> of type <group>
  33. i.e. -set drive.$id.file=/path/to/image
  34. -global driver.prop=value
  35. set a global default for a driver property
  36. -boot [order=drives][,once=drives][,menu=on|off]
  37. [,splash=sp_name][,splash-time=sp_time][,reboot-timeout=rb_time][,strict=on|off]
  38. 'drives': floppy (a), hard disk (c), CD-ROM (d), network (n)
  39. 'sp_name': the file's name that would be passed to bios as logo picture, if menu=on
  40. 'sp_time': the period that splash picture last if menu=on, unit is ms
  41. 'rb_timeout': the timeout before guest reboot when boot failed, unit is ms
  42. -m[emory] [size=]megs[,slots=n,maxmem=size]
  43. configure guest RAM
  44. size: initial amount of guest memory (default: 128MiB)
  45. slots: number of hotplug slots (default: none)
  46. maxmem: maximum amount of guest memory (default: none)
  47. NOTE: Some architectures might enforce a specific granularity
  48. -mem-path FILE provide backing storage for guest RAM
  49. -mem-prealloc preallocate guest memory (use with -mem-path)
  50. -k language use keyboard layout (for example 'fr' for French)
  51. -audio-help print list of audio drivers and their options
  52. -soundhw c1,... enable audio support
  53. and only specified sound cards (comma separated list)
  54. use '-soundhw help' to get the list of supported cards
  55. use '-soundhw all' to enable all of them
  56. -balloon none disable balloon device
  57. -balloon virtio[,addr=str]
  58. enable virtio balloon device (default)
  59. -device driver[,prop[=value][,...]]
  60. add device (based on driver)
  61. prop=value,... sets driver properties
  62. use '-device help' to print all possible drivers
  63. use '-device driver,help' to print all possible properties
  64. -name string1[,process=string2][,debug-threads=on|off]
  65. set the name of the guest
  66. string1 sets the window title and string2 the process name (on Linux)
  67. When debug-threads is enabled, individual threads are given a separate name (on Linux)
  68. NOTE: The thread names are for debugging and not a stable API.
  69. -uuid %08x-%04x-%04x-%04x-%012x
  70. specify machine UUID
  71. Block device options:
  72. -fda/-fdb file use 'file' as floppy disk 0/1 image
  73. -hda/-hdb file use 'file' as IDE hard disk 0/1 image
  74. -hdc/-hdd file use 'file' as IDE hard disk 2/3 image
  75. -cdrom file use 'file' as IDE cdrom image (cdrom is ide1 master)
  76. -drive [file=file][,if=type][,bus=n][,unit=m][,media=d][,index=i]
  77. [,cyls=c,heads=h,secs=s[,trans=t]][,snapshot=on|off]
  78. [,cache=writethrough|writeback|none|directsync|unsafe][,format=f]
  79. [,serial=s][,addr=A][,rerror=ignore|stop|report]
  80. [,werror=ignore|stop|report|enospc][,id=name][,aio=threads|native]
  81. [,readonly=on|off][,copy-on-read=on|off]
  82. [,discard=ignore|unmap][,detect-zeroes=on|off|unmap]
  83. [[,bps=b]|[[,bps_rd=r][,bps_wr=w]]]
  84. [[,iops=i]|[[,iops_rd=r][,iops_wr=w]]]
  85. [[,bps_max=bm]|[[,bps_rd_max=rm][,bps_wr_max=wm]]]
  86. [[,iops_max=im]|[[,iops_rd_max=irm][,iops_wr_max=iwm]]]
  87. [[,iops_size=is]]
  88. use 'file' as a drive image
  89. -mtdblock file use 'file' as on-board Flash memory image
  90. -sd file use 'file' as SecureDigital card image
  91. -pflash file use 'file' as a parallel flash image
  92. -snapshot write to temporary files instead of disk image files
  93. -hdachs c,h,s[,t]
  94. force hard disk 0 physical geometry and the optional BIOS
  95. translation (t=none or lba) (usually QEMU can guess them)
  96. -fsdev fsdriver,id=id[,path=path,][security_model={mapped-xattr|mapped-file|passthrough|none}]
  97. [,writeout=immediate][,readonly][,socket=socket|sock_fd=sock_fd]
  98. -virtfs local,path=path,mount_tag=tag,security_model=[mapped-xattr|mapped-file|passthrough|none]
  99. [,writeout=immediate][,readonly][,socket=socket|sock_fd=sock_fd]
  100. -virtfs_synth Create synthetic file system image
  101. USB options:
  102. -usb enable the USB driver (will be the default soon)
  103. -usbdevice name add the host or guest USB device 'name'
  104. Display options:
  105. -display sdl[,frame=on|off][,alt_grab=on|off][,ctrl_grab=on|off]
  106. [,window_close=on|off]|curses|none|
  107. gtk[,grab_on_hover=on|off]|
  108. vnc=<display>[,<optargs>]
  109. select display type
  110. -nographic disable graphical output and redirect serial I/Os to console
  111. -curses use a curses/ncurses interface instead of SDL
  112. -no-frame open SDL window without a frame and window decorations
  113. -alt-grab use Ctrl-Alt-Shift to grab mouse (instead of Ctrl-Alt)
  114. -ctrl-grab use Right-Ctrl to grab mouse (instead of Ctrl-Alt)
  115. -no-quit disable SDL window close capability
  116. -sdl enable SDL
  117. -spice [port=port][,tls-port=secured-port][,x509-dir=<dir>]
  118. [,x509-key-file=<file>][,x509-key-password=<file>]
  119. [,x509-cert-file=<file>][,x509-cacert-file=<file>]
  120. [,x509-dh-key-file=<file>][,addr=addr][,ipv4|ipv6]
  121. [,tls-ciphers=<list>]
  122. [,tls-channel=[main|display|cursor|inputs|record|playback]]
  123. [,plaintext-channel=[main|display|cursor|inputs|record|playback]]
  124. [,sasl][,password=<secret>][,disable-ticketing]
  125. [,image-compression=[auto_glz|auto_lz|quic|glz|lz|off]]
  126. [,jpeg-wan-compression=[auto|never|always]]
  127. [,zlib-glz-wan-compression=[auto|never|always]]
  128. [,streaming-video=[off|all|filter]][,disable-copy-paste]
  129. [,disable-agent-file-xfer][,agent-mouse=[on|off]]
  130. [,playback-compression=[on|off]][,seamless-migration=[on|off]]
  131. enable spice
  132. at least one of {port, tls-port} is mandatory
  133. -portrait rotate graphical output 90 deg left (only PXA LCD)
  134. -rotate <deg> rotate graphical output some deg left (only PXA LCD)
  135. -vga [std|cirrus|vmware|qxl|xenfb|tcx|cg3|none]
  136. select video card type
  137. -full-screen start in full screen
  138. -vnc display start a VNC server on display
  139. i386 target only:
  140. -win2k-hack use it when installing Windows 2000 to avoid a disk full bug
  141. -no-fd-bootchk disable boot signature checking for floppy disks
  142. -no-acpi disable ACPI
  143. -no-hpet disable HPET
  144. -acpitable [sig=str][,rev=n][,oem_id=str][,oem_table_id=str][,oem_rev=n][,asl_compiler_id=str][,asl_compiler_rev=n][,{data|file}=file1[:file2]...]
  145. ACPI table description
  146. -smbios file=binary
  147. load SMBIOS entry from binary file
  148. -smbios type=0[,vendor=str][,version=str][,date=str][,release=%d.%d][,uefi=on|off]
  149. specify SMBIOS type 0 fields
  150. -smbios type=1[,manufacturer=str][,product=str][,version=str][,serial=str]
  151. [,uuid=uuid][,sku=str][,family=str]
  152. specify SMBIOS type 1 fields
  153. Network options:
  154. -net nic[,vlan=n][,macaddr=mac][,model=type][,name=str][,addr=str][,vectors=v]
  155. create a new Network Interface Card and connect it to VLAN 'n'
  156. -net user[,vlan=n][,name=str][,net=addr[/mask]][,host=addr][,restrict=on|off]
  157. [,hostname=host][,dhcpstart=addr][,dns=addr][,dnssearch=domain][,tftp=dir]
  158. [,bootfile=f][,hostfwd=rule][,guestfwd=rule][,smb=dir[,smbserver=addr]]
  159. connect the user mode network stack to VLAN 'n', configure its
  160. DHCP server and enabled optional services
  161. -net tap[,vlan=n][,name=str][,fd=h][,fds=x:y:...:z][,ifname=name][,script=file][,downscript=dfile][,helper=helper][,sndbuf=nbytes][,vnet_hdr=on|off][,vhost=on|off][,vhostfd=h][,vhostfds=x:y:...:z][,vhostforce=on|off][,queues=n]
  162. connect the host TAP network interface to VLAN 'n'
  163. use network scripts 'file' (default=/etc/qemu-ifup)
  164. to configure it and 'dfile' (default=/etc/qemu-ifdown)
  165. to deconfigure it
  166. use '[down]script=no' to disable script execution
  167. use network helper 'helper' (default=/opt2/digit/repo/studio-dev/prebuilts/android-emulator-build/qemu-android-deps/linux-x86_64/libexec/qemu-bridge-helper) to
  168. configure it
  169. use 'fd=h' to connect to an already opened TAP interface
  170. use 'fds=x:y:...:z' to connect to already opened multiqueue capable TAP interfaces
  171. use 'sndbuf=nbytes' to limit the size of the send buffer (the
  172. default is disabled 'sndbuf=0' to enable flow control set 'sndbuf=1048576')
  173. use vnet_hdr=off to avoid enabling the IFF_VNET_HDR tap flag
  174. use vnet_hdr=on to make the lack of IFF_VNET_HDR support an error condition
  175. use vhost=on to enable experimental in kernel accelerator
  176. (only has effect for virtio guests which use MSIX)
  177. use vhostforce=on to force vhost on for non-MSIX virtio guests
  178. use 'vhostfd=h' to connect to an already opened vhost net device
  179. use 'vhostfds=x:y:...:z to connect to multiple already opened vhost net devices
  180. use 'queues=n' to specify the number of queues to be created for multiqueue TAP
  181. -net bridge[,vlan=n][,name=str][,br=bridge][,helper=helper]
  182. connects a host TAP network interface to a host bridge device 'br'
  183. (default=br0) using the program 'helper'
  184. (default=/opt2/digit/repo/studio-dev/prebuilts/android-emulator-build/qemu-android-deps/linux-x86_64/libexec/qemu-bridge-helper)
  185. -net l2tpv3[,vlan=n][,name=str],src=srcaddr,dst=dstaddr[,srcport=srcport][,dstport=dstport],txsession=txsession[,rxsession=rxsession][,ipv6=on/off][,udp=on/off][,cookie64=on/off][,counter][,pincounter][,txcookie=txcookie][,rxcookie=rxcookie][,offset=offset]
  186. connect the VLAN to an Ethernet over L2TPv3 pseudowire
  187. Linux kernel 3.3+ as well as most routers can talk
  188. L2TPv3. This transport allows connecting a VM to a VM,
  189. VM to a router and even VM to Host. It is a nearly-universal
  190. standard (RFC3391). Note - this implementation uses static
  191. pre-configured tunnels (same as the Linux kernel).
  192. use 'src=' to specify source address
  193. use 'dst=' to specify destination address
  194. use 'udp=on' to specify udp encapsulation
  195. use 'srcport=' to specify source udp port
  196. use 'dstport=' to specify destination udp port
  197. use 'ipv6=on' to force v6
  198. L2TPv3 uses cookies to prevent misconfiguration as
  199. well as a weak security measure
  200. use 'rxcookie=0x012345678' to specify a rxcookie
  201. use 'txcookie=0x012345678' to specify a txcookie
  202. use 'cookie64=on' to set cookie size to 64 bit, otherwise 32
  203. use 'counter=off' to force a 'cut-down' L2TPv3 with no counter
  204. use 'pincounter=on' to work around broken counter handling in peer
  205. use 'offset=X' to add an extra offset between header and data
  206. -net socket[,vlan=n][,name=str][,fd=h][,listen=[host]:port][,connect=host:port]
  207. connect the vlan 'n' to another VLAN using a socket connection
  208. -net socket[,vlan=n][,name=str][,fd=h][,mcast=maddr:port[,localaddr=addr]]
  209. connect the vlan 'n' to multicast maddr and port
  210. use 'localaddr=addr' to specify the host address to send packets from
  211. -net socket[,vlan=n][,name=str][,fd=h][,udp=host:port][,localaddr=host:port]
  212. connect the vlan 'n' to another VLAN using an UDP tunnel
  213. -net dump[,vlan=n][,file=f][,len=n]
  214. dump traffic on vlan 'n' to file 'f' (max n bytes per packet)
  215. -net none use it alone to have zero network devices. If no -net option
  216. is provided, the default is '-net nic -net user'
  217. -netdev [user|tap|bridge|vhost-user|socket|hubport],id=str[,option][,option][,...]
  218. Character device options:
  219. -chardev null,id=id[,mux=on|off]
  220. -chardev socket,id=id[,host=host],port=port[,to=to][,ipv4][,ipv6][,nodelay][,reconnect=seconds]
  221. [,server][,nowait][,telnet][,reconnect=seconds][,mux=on|off] (tcp)
  222. -chardev socket,id=id,path=path[,server][,nowait][,telnet][,reconnect=seconds][,mux=on|off] (unix)
  223. -chardev udp,id=id[,host=host],port=port[,localaddr=localaddr]
  224. [,localport=localport][,ipv4][,ipv6][,mux=on|off]
  225. -chardev msmouse,id=id[,mux=on|off]
  226. -chardev vc,id=id[[,width=width][,height=height]][[,cols=cols][,rows=rows]]
  227. [,mux=on|off]
  228. -chardev ringbuf,id=id[,size=size]
  229. -chardev file,id=id,path=path[,mux=on|off]
  230. -chardev pipe,id=id,path=path[,mux=on|off]
  231. -chardev pty,id=id[,mux=on|off]
  232. -chardev stdio,id=id[,mux=on|off][,signal=on|off]
  233. -chardev serial,id=id,path=path[,mux=on|off]
  234. -chardev tty,id=id,path=path[,mux=on|off]
  235. -chardev parallel,id=id,path=path[,mux=on|off]
  236. -chardev parport,id=id,path=path[,mux=on|off]
  237. Device URL Syntax:
  238. -iscsi [user=user][,password=password]
  239. [,header-digest=CRC32C|CR32C-NONE|NONE-CRC32C|NONE
  240. [,initiator-name=initiator-iqn][,id=target-iqn]
  241. iSCSI session parameters
  242. Bluetooth(R) options:
  243. -bt hci,null dumb bluetooth HCI - doesn't respond to commands
  244. -bt hci,host[:id]
  245. use host's HCI with the given name
  246. -bt hci[,vlan=n]
  247. emulate a standard HCI in virtual scatternet 'n'
  248. -bt vhci[,vlan=n]
  249. add host computer to virtual scatternet 'n' using VHCI
  250. -bt device:dev[,vlan=n]
  251. emulate a bluetooth device 'dev' in scatternet 'n'
  252. TPM device options:
  253. -tpmdev passthrough,id=id[,path=path][,cancel-path=path]
  254. use path to provide path to a character device; default is /dev/tpm0
  255. use cancel-path to provide path to TPM's cancel sysfs entry; if
  256. not provided it will be searched for in /sys/class/misc/tpm?/device
  257. Linux/Multiboot boot specific:
  258. -kernel bzImage use 'bzImage' as kernel image
  259. -append cmdline use 'cmdline' as kernel command line
  260. -initrd file use 'file' as initial ram disk
  261. -dtb file use 'file' as device tree image
  262. Debug/Expert options:
  263. -serial dev redirect the serial port to char device 'dev'
  264. -parallel dev redirect the parallel port to char device 'dev'
  265. -monitor dev redirect the monitor to char device 'dev'
  266. -qmp dev like -monitor but opens in 'control' mode
  267. -mon [chardev=]name[,mode=readline|control][,default]
  268. -debugcon dev redirect the debug console to char device 'dev'
  269. -pidfile file write PID to 'file'
  270. -singlestep always run in singlestep mode
  271. -S freeze CPU at startup (use 'c' to start execution)
  272. -realtime [mlock=on|off]
  273. run qemu with realtime features
  274. mlock=on|off controls mlock support (default: on)
  275. -gdb dev wait for gdb connection on 'dev'
  276. -s shorthand for -gdb tcp::1234
  277. -d item1,... enable logging of specified items (use '-d help' for a list of log items)
  278. -D logfile output log to logfile (default stderr)
  279. -L path set the directory for the BIOS, VGA BIOS and keymaps
  280. -bios file set the filename for the BIOS
  281. -enable-kvm enable KVM full virtualization support
  282. -enable-hax enable HAX virtualization support
  283. -xen-domid id specify xen guest domain id
  284. -xen-create create domain using xen hypercalls, bypassing xend
  285. warning: should not be used when xend is in use
  286. -xen-attach attach to existing xen domain
  287. xend will use this when starting QEMU
  288. -no-reboot exit instead of rebooting
  289. -no-shutdown stop before shutdown
  290. -loadvm [tag|id]
  291. start right away with a saved state (loadvm in monitor)
  292. -daemonize daemonize QEMU after initializing
  293. -option-rom rom load a file, rom, into the option ROM space
  294. -rtc [base=utc|localtime|date][,clock=host|rt|vm][,driftfix=none|slew]
  295. set the RTC base and clock, enable drift fix for clock ticks (x86 only)
  296. -icount [shift=N|auto][,align=on|off]
  297. enable virtual instruction counter with 2^N clock ticks per
  298. instruction and enable aligning the host and virtual clocks
  299. -watchdog i6300esb|ib700
  300. enable virtual hardware watchdog [default=none]
  301. -watchdog-action reset|shutdown|poweroff|pause|debug|none
  302. action when watchdog fires [default=reset]
  303. -echr chr set terminal escape character instead of ctrl-a
  304. -virtioconsole c
  305. set virtio console
  306. -show-cursor show cursor
  307. -tb-size n set TB size
  308. -incoming p prepare for incoming migration, listen on port p
  309. -nodefaults don't create default devices
  310. -chroot dir chroot to dir just before starting the VM
  311. -runas user change to user id user just before starting the VM
  312. -sandbox <arg> Enable seccomp mode 2 system call filter (default 'off').
  313. -readconfig <file>
  314. -writeconfig <file>
  315. read/write config file
  316. -nodefconfig
  317. do not load default config files at startup
  318. -no-user-config
  319. do not load user-provided config files at startup
  320. -trace [events=<file>][,file=<file>]
  321. specify tracing options
  322. -enable-fips enable FIPS 140-2 compliance
  323. -object TYPENAME[,PROP1=VALUE1,...]
  324. create an new object of type TYPENAME setting properties
  325. in the order they are specified. Note that the 'id'
  326. property must be set. These objects are placed in the
  327. '/objects' path.
  328. -msg timestamp[=on|off]
  329. change the format of messages
  330. on|off controls leading timestamps (default:on)
  331. -dump-vmstate <file>
  332. Output vmstate information in JSON format to file.
  333. Use the scripts/vmstate-static-checker.py file to
  334. check for possible regressions in migration code
  335. by comparing two such vmstate dumps.
  336. -netspeed <speed> maximum network download/upload speeds
  337. -netdelay <delay> network latency emulation
  338. -netfast disable network shaping
  339. -boot-property <name>=<value> set system property on boot
  340. -lcd-density density
  341. select lcd display density value (default is 160)
  342. -android-ports <consoleport>,<adbport> TCP ports used for the emulator instance and adb bridge
  343. -android-report-console <socket> report console port to remote socket
  344. -http-proxy <proxy> make TCP connections through a HTTP/HTTPS proxy
  345. -dns-server <servers> use this DNS server(s) in the emulated system
  346. -list-webcam list web cameras available for emulation
  347. -android-hw <file>
  348. specify the hw config ini file location
  349. During emulation, the following keys are useful:
  350. ctrl-alt-f toggle full screen
  351. ctrl-alt-n switch to virtual console 'n'
  352. ctrl-alt toggle mouse and keyboard grab
  353. When using -nographic, press 'ctrl-a h' to get some help.
Android模拟器 Debug_Kernel 暂停运行,等待 gdb 连接调试。gdb 使用前面编译Android内核时下载的交叉编译工具链 arm-eabi-4.7 提供的 arm-eabi-gdb 。Android4.4.4r1的源码和Android NDK都提供了 gdb 工具,也可以使用他们提供的。为了方面起见,将 arm-eabi-gdb 工具的文件路径添加到ubuntu系统的环境变量中,如下所示:

  1. # 编辑环境变量配置文件
  2. $ sudo gedit /etc/profile
  3. # 添加到环境变量配置文件/etc/profile中的内容
  4. export ANDROID_TOOLCHAIN=/home/fly2016/Android4.4.4r1/goldfish-kernel-3.4/goldfish/arm-eabi-4.7
  5. export PATH=$PATH:${ANDROID_TOOLCHAIN}/bin/
  6. # 更新系统环境变量
  7. $ source /etc/profile
  8. # 测试是否配置成功
  9. $ arm-eabi-gdb
OK,arm-eabi-gdb 工具的问题解决了,下面在Android内核源码的根目录下,执行下面的命令进行Android内核的源码调试:

  1. # 在Android内核源码的根目录下执行
  2. # 加载内核符号信息
  3. $ arm-eabi-gdb vmlinux
  4. # 连接远端的调试器
  5. $ target remote :1234
  6. # 测试命令
  7. $ list
  8. $ n
前面在 配置config选项 时,设置 CONFIG_DEBUG_INFO=y,因此加载 vmlinux 后包含了内核符号信息,在 gdb 中可以进行源码级调试,执行结果如下图:



五、gdb的使用帮助

有关 gdb 的使用帮助可以参考文档 《GDBCheatSheet.pdf》,也可以参考 gdb 的命令帮助。《GNU GDB Debugger Command Cheat Sheet》也不错,资料比较详细,也可以好好参考和学习一下。

GDBCheatSheet 的具体内容见下图所示:




gdb 工具的命令使用帮助如下:

  1. $ arm-eabi-gdb --help
  2. This is the GNU debugger. Usage:
  3. gdb [options] [executable-file [core-file or process-id]]
  4. gdb [options] --args executable-file [inferior-arguments ...]
  5. Options:
  6. --args Arguments after executable-file are passed to inferior
  7. -b BAUDRATE Set serial port baud rate used for remote debugging.
  8. --batch Exit after processing options.
  9. --batch-silent As for --batch, but suppress all gdb stdout output.
  10. --return-child-result
  11. GDB exit code will be the child's exit code.
  12. --cd=DIR Change current directory to DIR.
  13. --command=FILE, -x Execute GDB commands from FILE.
  14. --eval-command=COMMAND, -ex
  15. Execute a single GDB command.
  16. May be used multiple times and in conjunction
  17. with --command.
  18. --core=COREFILE Analyze the core dump COREFILE.
  19. --pid=PID Attach to running process PID.
  20. --dbx DBX compatibility mode.
  21. --directory=DIR Search for source files in DIR.
  22. --epoch Output information used by epoch emacs-GDB interface.
  23. --exec=EXECFILE Use EXECFILE as the executable.
  24. --fullname Output information used by emacs-GDB interface.
  25. --help Print this message.
  26. --interpreter=INTERP
  27. Select a specific interpreter / user interface
  28. -l TIMEOUT Set timeout in seconds for remote debugging.
  29. --nw Do not use a window interface.
  30. --nx Do not read .gdbinit file.
  31. --quiet Do not print version number on startup.
  32. --readnow Fully read symbol files on first access.
  33. --se=FILE Use FILE as symbol file and executable file.
  34. --symbols=SYMFILE Read symbols from SYMFILE.
  35. --tty=TTY Use TTY for input/output by the program being debugged.
  36. --tui Use a terminal user interface.
  37. --version Print version information and then exit.
  38. -w Use a window interface.
  39. --write Set writing into executable and core files.
  40. --xdb XDB compatibility mode.
  41. --disable-gdb-index
  42. Disable the use of the .gdb_index section.
  43. At startup, GDB reads the following init files and executes their commands:
  44. For more information, type "help" from within GDB, or consult the
  45. GDB manual (available as on-line info or a printed manual).
  46. Report bugs to "<http://source.android.com/source/report-bugs.html>".


参考文档

Android内核编译调试
android 内核调试

Android Linux内核编译调试


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/261831
推荐阅读
相关标签
  

闽ICP备14008679号