linux 内核学习7-通过QEMU调试ARMV8的Linux内核

linux 内核学习7-通过QEMU调试ARMV8的Linux内核

1. 准备工作

$ sudo apt-get install gcc-aarch64-linux-gnu gcc-5-aarch64-linux-gnu

2. 切换GCC版本

默认的GCC版本是7.+的版本,现在要替换为5.+的版本

  1. 设置gcc-5的版本
sudo update-alternatives  --install /usr/bin/aarch64-linux-gnu-gcc aarch64-linux-gnu-gcc /usr/bin/aarch64-linux-gnu-gcc-5 5 

  1. 设置gcc-7的版本
sudo update-alternatives  --install /usr/bin/aarch64-linux-gnu-gcc aarch64-linux-gnu-gcc /usr/bin/aarch64-linux-gnu-gcc-7 7

  1. 选择GCC-5的版本
 $ sudo update-alternatives --config aarch64-linux-gnu-gcc

There are 2 choices for the alternative aarch64-linux-gnu-gcc (providing /usr/bin/aarch64-linux-gnu-gcc).

  Selection    Path                              Priority   Status
------------------------------------------------------------
* 0            /usr/bin/aarch64-linux-gnu-gcc-7   7         auto mode
  1            /usr/bin/aarch64-linux-gnu-gcc-5   5         manual mode
  2            /usr/bin/aarch64-linux-gnu-gcc-7   7         manual mode

Press  to keep the current choice[*], or type selection number: 1
update-alternatives: using /usr/bin/aarch64-linux-gnu-gcc-5 to provide /usr/bin/aarch64-linux-gnu-gcc (aarch64-linux-gnu-gcc) in manual mode
  1. 检查aarch64-linux-gnu-gcc版本是否为gcc-5的版本
$ aarch64-linux-gnu-gcc -v

Using built-in specs.
COLLECT_GCC=aarch64-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc-cross/aarch64-linux-gnu/5/lto-wrapper
Target: aarch64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 5.5.0-12ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libquadmath --enable-plugin --enable-default-pie --with-system-zlib --enable-multiarch --enable-fix-cortex-a53-843419 --disable-werror --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=aarch64-linux-gnu --program-prefix=aarch64-linux-gnu- --includedir=/usr/aarch64-linux-gnu/include
Thread model: posix
gcc version 5.5.0 20171010 (Ubuntu/Linaro 5.5.0-12ubuntu1) 

3. 编译系统

参照之前的文章-linux 内核学习3-自己编译一个ARM Linux内核
这里相比于32位的ARM内核,只是一些参数不同,其他参数都是相同的

  1. 配置环境变量
$ export ARCH=arm64
$ export CROSS_COMPILE=aarch64-linux-gnu-8o
  1. 编译
 cd linux-4.19.67 
export ARCH=arm64                      
export CROSS_COMPILE=aarch64-linux-gnu-
make menuconfig

General setup  --->  
          [*] Initial RAM filesystem and RAM disk (initramfs/initrd) support                   
                (_install_arm64) Initramfs source file(s)  
                
Boot options  --->  
      ()  Default kernel command string (NEW) 
      
Kernel Features  --->  
        Page size (4KB)  ---> 
                 Virtual address space size (48-bit)  --->  

修改内容

linux 内核学习7-通过QEMU调试ARMV8的Linux内核_第1张图片
linux 内核学习7-通过QEMU调试ARMV8的Linux内核_第2张图片

$ make -j2 
  1. 启动虚拟机
qemu-system-aarch64 -machine virt -cpu cortex-a57 -machine type=virt -nographic -m 2048 -smp 2 -kernel arch/arm64/boot/Image  --append "rdinit=/linuxrc console=ttyAMA0"
  1. 遇到的问题
  • 问题1

缺少vexpress_config文件,这个我个人的做法是从arm/configs文件夹拷贝vexpress_defconfig到arm64/configs

  • 问题2

$ make bzImage -j2 ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-
scripts/kconfig/conf  --syncconfig Kconfig
make: *** No rule to make target 'bzImage'.  Stop.

提示无法编译bzImage

这个时候通过make help发现并没有make bzImage命令


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
  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
  olddefconfig	  - Same as oldconfig but sets new symbols to their
                    default value without prompting
  kvmconfig	  - Enable additional options for kvm guest kernel support
  xenconfig       - Enable additional options for xen dom0 and guest kernel support
  tinyconfig	  - Configure the tiniest possible kernel
  testconfig	  - Run Kconfig unit tests (requires python3 and pytest)

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: /)
  dir/            - Build all files in dir and below
  dir/file.[ois]  - Build specified target only
  dir/file.ll     - Build the LLVM assembly file
                    (requires compiler support for LLVM assembly generation)
  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 (use with make -s)
  kernelversion	  - Output the version stored in Makefile (use with make -s)
  image_name	  - Output the image name (use with make -s)
  headers_install - Install sanitised kernel headers to INSTALL_HDR_PATH
                    (default: ./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 selftest:
  kselftest       - Build and run kernel selftest (run as root)
                    Build, install, and boot kernel before
                    running kselftest on it
  kselftest-clean - Remove all generated kselftest files
  kselftest-merge - Merge all the config dependencies of kselftest to existing
                    .config.

Userspace tools targets:
  use "make tools/help"
  or  "cd tools; make help"

Kernel packaging:
  rpm-pkg             - Build both source and binary RPM kernel packages
  binrpm-pkg          - Build only the binary kernel RPM package
  deb-pkg             - Build both source and binary deb kernel packages
  bindeb-pkg          - Build only the binary kernel deb package
  snap-pkg            - Build only the binary kernel snap package (will connect to external hosts)
  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-4.19.67.tar source tarball
  perf-targz-src-pkg  - Build perf-4.19.67.tar.gz source tarball
  perf-tarbz2-src-pkg - Build perf-4.19.67.tar.bz2 source tarball
  perf-tarxz-src-pkg  - Build perf-4.19.67.tar.xz source tarball

Documentation targets:
 Linux kernel internal documentation in different formats from ReST:
  htmldocs        - HTML
  latexdocs       - LaTeX
  pdfdocs         - PDF
  epubdocs        - EPUB
  xmldocs         - XML
  linkcheckdocs   - check for broken external links (will connect to external hosts)
  refcheckdocs    - check for references to non-existing files under Documentation
  cleandocs       - clean all generated files

  make SPHINXDIRS="s1 s2" [target] Generate only docs of folder s1, s2
  valid values for SPHINXDIRS are: driver-api networking sound media core-api userspace-api gpu maintainer process input crypto doc-guide vm sh dev-tools filesystems kernel-hacking x86 admin-guide

  make SPHINX_CONF={conf-file} [target] use *additional* sphinx-build
  configuration. This is e.g. useful to build with nit-picking config.

  Default location for the generated documents is Documentation/output

Architecture specific targets (arm64):
* Image.gz      - Compressed kernel image (arch/arm64/boot/Image.gz)
  Image         - Uncompressed kernel image (arch/arm64/boot/Image)
* dtbs          - Build device tree blobs for enabled boards
  dtbs_install  - Install dtbs to /boot/dtbs/4.19.67
  install       - Install uncompressed kernel
  zinstall      - Install compressed kernel
                  Install using (your) ~/bin/installkernel or
                  (distribution) /sbin/installkernel or
                  install to $(INSTALL_PATH) and run lilo

  vexpress_defconfig       - Build for vexpress

  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 re-compiled 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

这里使用


$ make Image -j2 ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-

来解决

你可能感兴趣的:(linux)