当前位置:   article > 正文

嵌入式开发模拟器:qemu使用,仿真多种方式启动内核kernel (超详细,tftp/nfs等方式)_qemu tftp

qemu tftp

适用于:

  • 想学习嵌入式开发,但又没有购买开发板的情况
  • 开发测试阶段避免繁琐耗时下载到主板
  • 便于调试驱动及内核
  • 与外设关联不大时

环 境:

  • vmare 15 pro
  • ubuntu 18.04
  • qemu 6.2.0

测试虚拟主板 :vexpress-a9 (ARM Versatile Express for Cortex-A9)

源码下载:

  • qemu : https://download.qemu.org
  • u-boot: ftp://ftp.denx.de/pub/u-boot/
  • buildroot: https://buildroot.org/downloads/

需要的支持库:

  1. apt-get install libpixman-1-dev
  2. sudo apt-get install zlib1g-dev
  3. sudo apt-get install libglib2.0-0
  4. sudo apt-get install libglib2.0-dev

大概步骤:

  • 一、下载安装qemu
  • 二、下载安装交叉编译器
  • 三、下载、编译u-boot (bootloader)
  • 四、下载、编译、安装文件系统(buildroot制作)
  • 五、内核zImage启动测试:(方法一,sd参数)
  • 六、启动内核方法二(initrd参数)
  • 七、启动内核方法三:(先启动u-boot - 加载内核到DRAM - bootz启动)
  • 八、启动内核方法四:tftp-手动
  • 九、启动内核方法五:nfs-手动
  • 十、启动内核方法七:自动用tftp加载内核到DRAM并启动
  • 十一、启动内核方法七:自动用nfs加载内核到DRAM并启动
  • 十二、问题
  • 十三、其它说明

安装qemu :

安装方法一:

命令:sudo apt-get install qemu

  1. biren@ubuntu:~$ sudo apt-get install qemu
  2. The following additional packages will be installed:
  3. binfmt-support cpu-checker ibverbs-providers ipxe-qemu
  4. ipxe-qemu-256k-compat-efi-roms libaio1 libcacard0 libfdt1 libibverbs1
  5. libiscsi7 libnl-route-3-200 librados2 librbd1 librdmacm1 libsdl1.2debian
  6. libspice-server1 libusbredirparser1 libxen-4.9 libxenstore3.0 msr-tools
  7. qemu-block-extra qemu-slof qemu-system qemu-system-arm qemu-system-common
  8. qemu-system-mips qemu-system-misc qemu-system-ppc qemu-system-s390x
  9. qemu-system-sparc qemu-system-x86 qemu-user qemu-user-binfmt qemu-utils
  10. seabios sharutils
  11. Suggested packages:
  12. qemu-user-static samba vde2 qemu-efi openbios-ppc openhackware
  13. openbios-sparc sgabios ovmf debootstrap sharutils-doc bsd-mailx | mailx
  14. 0 upgraded, 37 newly installed, 0 to remove and 148 not upgraded.
  15. Need to get 62.4 MB of archives.
  16. After this operation, 341 MB of additional disk space will be used.
  17. Do you want to continue? [Y/n]

此种安装方法的缺点是不能自主确定安装的版本。

安装方法二:

从qemu官网下载源码文件qemu-6.2.0.tar.xz

解压:

biren@ubuntu:~$ tar -xvf qemu-6.2.0.tar.xz

编 译:

命令:./configure --prefix=/usr/local/qemu6.2.0

问题一

ERROR: pkg-config binary 'pkg-config' not found

  1. biren@ubuntu:~$ cd qemu-6.2.0/
  2. biren@ubuntu:~/qemu-6.2.0$ ./configure --prefix=/usr/local/qemu6.2.0
  3. ERROR: pkg-config binary 'pkg-config' not found

解决:

安装pkg-config

  1. biren@ubuntu:~/qemu-6.2.0$ sudo apt-get install pkg-config
  2. The following NEW packages will be installed:
  3. pkg-config
  4. 0 upgraded, 1 newly installed, 0 to remove and 235 not upgraded.
  5. Need to get 45.0 kB of archives.
  6. After this operation, 185 kB of additional disk space will be used.
  7. Get:1 http://mirrors.aliyun.com/ubuntu bionic/main amd64 pkg-config amd64 0.29.1-0ubuntu2 [45.0 kB]
  8. Fetched 45.0 kB in 0s (176 kB/s)
  9. Selecting previously unselected package pkg-config.
  10. (Reading database ... 140996 files and directories currently installed.)
  11. Preparing to unpack .../pkg-config_0.29.1-0ubuntu2_amd64.deb ...
  12. Unpacking pkg-config (0.29.1-0ubuntu2) ...
  13. Setting up pkg-config (0.29.1-0ubuntu2) ...
  14. Processing triggers for man-db (2.8.3-2ubuntu0.1) ...

问题二:ERROR: Cannot find Ninja

  1. biren@ubuntu:~/qemu-6.2.0$ ./configure --prefix=/usr/local/qemu6.2.0
  2. Using './build' as the directory for build output
  3. ERROR: Cannot find Ninja

解决:

安装ninja-build

biren@ubuntu:~/qemu-6.2.0$ sudo apt-get install ninja-build 

问题三:ERROR: glib-2.56 gthread-2.0 is required to compile QEMU

  1. biren@ubuntu:~/qemu-6.2.0$ ./configure --prefix=/usr/local/qemu6.2.0
  2. Using './build' as the directory for build output
  3. ERROR: glib-2.56 gthread-2.0 is required to compile QEMU

解决:

  1. biren@ubuntu:~/qemu-6.2.0$ sudo apt-get install libglib2.0
  2. Note, selecting 'libglib2.0-cil-dev' for regex 'libglib2.0'
  3. Note, selecting 'libglib2.0-tests' for regex 'libglib2.0'
  4. Note, selecting 'libglib2.0-0-dbg' for regex 'libglib2.0'
  5. Note, selecting 'libglib2.0-dev-bin' for regex 'libglib2.0'
  6. Note, selecting 'libglib2.0-bin' for regex 'libglib2.0'
  7. Note, selecting 'libglib2.0-cil' for regex 'libglib2.0'
  8. Note, selecting 'libglib2.0-dev' for regex 'libglib2.0'
  9. Note, selecting 'libglib2.0-doc' for regex 'libglib2.0'
  10. Note, selecting 'libglib2.0-data' for regex 'libglib2.0'
  11. Note, selecting 'libglib2.0-0' for regex 'libglib2.0'
  12. The following additional packages will be installed:
  13. binfmt-support ca-certificates-mono cli-common libmono-corlib4.5-cil
  14. libmono-i18n-west4.0-cil libmono-i18n4.0-cil libmono-security4.0-cil
  15. libmono-system-configuration4.0-cil libmono-system-security4.0-cil
  16. libmono-system-xml4.0-cil libmono-system4.0-cil mono-4.0-gac mono-gac
  17. mono-runtime mono-runtime-common mono-runtime-sgen
  18. Suggested packages:
  19. monodoc-gtk2.0-manual devhelp libmono-i18n4.0-all libgamin0
  20. The following NEW packages will be installed:
  21. binfmt-support ca-certificates-mono cli-common libglib2.0-cil
  22. libglib2.0-cil-dev libglib2.0-dev libglib2.0-dev-bin libglib2.0-doc
  23. libglib2.0-tests libmono-corlib4.5-cil libmono-i18n-west4.0-cil
  24. libmono-i18n4.0-cil libmono-security4.0-cil
  25. libmono-system-configuration4.0-cil libmono-system-security4.0-cil
  26. libmono-system-xml4.0-cil libmono-system4.0-cil mono-4.0-gac mono-gac
  27. mono-runtime mono-runtime-common mono-runtime-sgen
  28. The following packages will be upgraded:
  29. libglib2.0-0 libglib2.0-bin libglib2.0-data
  30. 3 upgraded, 22 newly installed, 0 to remove and 232 not upgraded.
  31. Need to get 10.1 MB/10.2 MB of archives.
  32. After this operation, 56.2 MB of additional disk space will be used.
  33. Do you want to continue? [Y/n]

问题四:ERROR: Dependency "pixman-1" not found

  1. Run-time dependency appleframeworks found: NO (tried framework)
  2. Found pkg-config: /usr/bin/pkg-config (0.29.1)
  3. Run-time dependency pixman-1 found: NO (tried pkgconfig)
  4. ../meson.build:415:2: ERROR: Dependency "pixman-1" not found, tried pkgconfig
  5. A full log can be found at /home/biren/qemu-6.2.0/build/meson-logs/meson-log.txt
  6. ERROR: meson setup failed

解决:

  1. biren@ubuntu:~/qemu-6.2.0$ sudo apt-get install libpixman-1-dev
  2. The following NEW packages will be installed:
  3. libpixman-1-dev
  4. 0 upgraded, 1 newly installed, 0 to remove and 232 not upgraded.
  5. Need to get 244 kB of archives.
  6. After this operation, 959 kB of additional disk space will be used.

继续安装qemu...:

  1. biren@ubuntu:~/qemu-6.2.0$ ./configure --prefix=/usr/local/qemu6.2.0
  2. biren@ubuntu:~/qemu-6.2.0$ make -j4
  3. biren@ubuntu:~/qemu-6.2.0$ make install

将bin目录添加到环境变量PATH:

  1. biren@ubuntu:~$ export PATH=$PATH:/usr/local/qemu6.2.0/bin
  2. 或在home目录下的.bashrc文件里加入上面这句。

qemu安装完成。

查看支持的主板:qemu-system-arm -machine help

  1. biren@ubuntu:~$ qemu-system-arm -machine help
  2. Supported machines are:
  3. akita Sharp SL-C1000 (Akita) PDA (PXA270)
  4. ast2500-evb Aspeed AST2500 EVB (ARM1176)
  5. ast2600-evb Aspeed AST2600 EVB (Cortex-A7)
  6. borzoi Sharp SL-C3100 (Borzoi) PDA (PXA270)
  7. canon-a1100 Canon PowerShot A1100 IS (ARM946)
  8. cheetah Palm Tungsten|E aka. Cheetah PDA (OMAP310)
  9. collie Sharp SL-5500 (Collie) PDA (SA-1110)
  10. connex Gumstix Connex (PXA255)
  11. cubieboard cubietech cubieboard (Cortex-A8)
  12. emcraft-sf2 SmartFusion2 SOM kit from Emcraft (M2S010)
  13. fp5280g2-bmc Inspur FP5280G2 BMC (ARM1176)
  14. fuji-bmc Facebook Fuji BMC (Cortex-A7)
  15. g220a-bmc Bytedance G220A BMC (ARM1176)
  16. highbank Calxeda Highbank (ECX-1000)
  17. imx25-pdk ARM i.MX25 PDK board (ARM926)
  18. integratorcp ARM Integrator/CP (ARM926EJ-S)
  19. kudo-bmc Kudo BMC (Cortex-A9)
  20. kzm ARM KZM Emulation Baseboard (ARM1136)
  21. lm3s6965evb Stellaris LM3S6965EVB (Cortex-M3)
  22. lm3s811evb Stellaris LM3S811EVB (Cortex-M3)
  23. mainstone Mainstone II (PXA27x)
  24. mcimx6ul-evk Freescale i.MX6UL Evaluation Kit (Cortex-A7)
  25. mcimx7d-sabre Freescale i.MX7 DUAL SABRE (Cortex-A7)
  26. microbit BBC micro:bit (Cortex-M0)
  27. midway Calxeda Midway (ECX-2000)
  28. mps2-an385 ARM MPS2 with AN385 FPGA image for Cortex-M3
  29. mps2-an386 ARM MPS2 with AN386 FPGA image for Cortex-M4
  30. mps2-an500 ARM MPS2 with AN500 FPGA image for Cortex-M7
  31. mps2-an505 ARM MPS2 with AN505 FPGA image for Cortex-M33
  32. mps2-an511 ARM MPS2 with AN511 DesignStart FPGA image for Cortex-M3
  33. mps2-an521 ARM MPS2 with AN521 FPGA image for dual Cortex-M33
  34. mps3-an524 ARM MPS3 with AN524 FPGA image for dual Cortex-M33
  35. mps3-an547 ARM MPS3 with AN547 FPGA image for Cortex-M55
  36. musca-a ARM Musca-A board (dual Cortex-M33)
  37. musca-b1 ARM Musca-B1 board (dual Cortex-M33)
  38. musicpal Marvell 88w8618 / MusicPal (ARM926EJ-S)
  39. n800 Nokia N800 tablet aka. RX-34 (OMAP2420)
  40. n810 Nokia N810 tablet aka. RX-44 (OMAP2420)
  41. netduino2 Netduino 2 Machine (Cortex-M3)
  42. netduinoplus2 Netduino Plus 2 Machine (Cortex-M4)
  43. none empty machine
  44. npcm750-evb Nuvoton NPCM750 Evaluation Board (Cortex-A9)
  45. nuri Samsung NURI board (Exynos4210)
  46. orangepi-pc Orange Pi PC (Cortex-A7)
  47. palmetto-bmc OpenPOWER Palmetto BMC (ARM926EJ-S)
  48. quanta-gbs-bmc Quanta GBS (Cortex-A9)
  49. quanta-gsj Quanta GSJ (Cortex-A9)
  50. quanta-q71l-bmc Quanta-Q71l BMC (ARM926EJ-S)
  51. rainier-bmc IBM Rainier BMC (Cortex-A7)
  52. raspi0 Raspberry Pi Zero (revision 1.2)
  53. raspi1ap Raspberry Pi A+ (revision 1.1)
  54. raspi2b Raspberry Pi 2B (revision 1.1)
  55. realview-eb ARM RealView Emulation Baseboard (ARM926EJ-S)
  56. realview-eb-mpcore ARM RealView Emulation Baseboard (ARM11MPCore)
  57. realview-pb-a8 ARM RealView Platform Baseboard for Cortex-A8
  58. realview-pbx-a9 ARM RealView Platform Baseboard Explore for Cortex-A9
  59. romulus-bmc OpenPOWER Romulus BMC (ARM1176)
  60. sabrelite Freescale i.MX6 Quad SABRE Lite Board (Cortex-A9)
  61. smdkc210 Samsung SMDKC210 board (Exynos4210)
  62. sonorapass-bmc OCP SonoraPass BMC (ARM1176)
  63. spitz Sharp SL-C3000 (Spitz) PDA (PXA270)
  64. stm32vldiscovery ST STM32VLDISCOVERY (Cortex-M3)
  65. supermicrox11-bmc Supermicro X11 BMC (ARM926EJ-S)
  66. swift-bmc OpenPOWER Swift BMC (ARM1176) (deprecated)
  67. sx1 Siemens SX1 (OMAP310) V2
  68. sx1-v1 Siemens SX1 (OMAP310) V1
  69. tacoma-bmc OpenPOWER Tacoma BMC (Cortex-A7)
  70. terrier Sharp SL-C3200 (Terrier) PDA (PXA270)
  71. tosa Sharp SL-6000 (Tosa) PDA (PXA255)
  72. verdex Gumstix Verdex (PXA270)
  73. versatileab ARM Versatile/AB (ARM926EJ-S)
  74. versatilepb ARM Versatile/PB (ARM926EJ-S)
  75. vexpress-a15 ARM Versatile Express for Cortex-A15
  76. vexpress-a9 ARM Versatile Express for Cortex-A9
  77. virt-2.10 QEMU 2.10 ARM Virtual Machine
  78. virt-2.11 QEMU 2.11 ARM Virtual Machine
  79. virt-2.12 QEMU 2.12 ARM Virtual Machine
  80. virt-2.6 QEMU 2.6 ARM Virtual Machine
  81. virt-2.7 QEMU 2.7 ARM Virtual Machine
  82. virt-2.8 QEMU 2.8 ARM Virtual Machine
  83. virt-2.9 QEMU 2.9 ARM Virtual Machine
  84. virt-3.0 QEMU 3.0 ARM Virtual Machine
  85. virt-3.1 QEMU 3.1 ARM Virtual Machine
  86. virt-4.0 QEMU 4.0 ARM Virtual Machine
  87. virt-4.1 QEMU 4.1 ARM Virtual Machine
  88. virt-4.2 QEMU 4.2 ARM Virtual Machine
  89. virt-5.0 QEMU 5.0 ARM Virtual Machine
  90. virt-5.1 QEMU 5.1 ARM Virtual Machine
  91. virt-5.2 QEMU 5.2 ARM Virtual Machine
  92. virt-6.0 QEMU 6.0 ARM Virtual Machine
  93. virt-6.1 QEMU 6.1 ARM Virtual Machine
  94. virt QEMU 6.2 ARM Virtual Machine (alias of virt-6.2)
  95. virt-6.2 QEMU 6.2 ARM Virtual Machine
  96. witherspoon-bmc OpenPOWER Witherspoon BMC (ARM1176)
  97. xilinx-zynq-a9 Xilinx Zynq Platform Baseboard for Cortex-A9
  98. z2 Zipit Z2 (PXA27x)

安装交叉编译器:

命令:sudo apt-get install gcc-arm-linux-gnueabi

  1. biren@ubuntu:~$ sudo apt-get install gcc-arm-linux-gnueabi
  2. The following additional packages will be installed:
  3. binutils binutils-arm-linux-gnueabi binutils-common
  4. binutils-x86-64-linux-gnu cpp-7-arm-linux-gnueabi cpp-arm-linux-gnueabi
  5. gcc-7-arm-linux-gnueabi gcc-7-arm-linux-gnueabi-base gcc-7-cross-base
  6. gcc-8-cross-base libasan4-armel-cross libatomic1-armel-cross libbinutils
  7. libc6-armel-cross libc6-dev-armel-cross libcilkrts5-armel-cross
  8. libgcc-7-dev-armel-cross libgcc1-armel-cross libgomp1-armel-cross
  9. libstdc++6-armel-cross libubsan0-armel-cross linux-libc-dev-armel-cross
  10. Suggested packages:
  11. binutils-doc gcc-7-locales cpp-doc gcc-7-multilib-arm-linux-gnueabi
  12. gcc-7-doc libgcc1-dbg-armel-cross libgomp1-dbg-armel-cross
  13. libitm1-dbg-armel-cross libatomic1-dbg-armel-cross libasan4-dbg-armel-cross
  14. liblsan0-dbg-armel-cross libtsan0-dbg-armel-cross libubsan0-dbg-armel-cross
  15. libcilkrts5-dbg-armel-cross libmpx2-dbg-armel-cross
  16. libquadmath0-dbg-armel-cross gdb-arm-linux-gnueabi gcc-doc
  17. The following packages will be REMOVED:
  18. gcc-multilib
  19. The following NEW packages will be installed:
  20. binutils-arm-linux-gnueabi cpp-7-arm-linux-gnueabi cpp-arm-linux-gnueabi
  21. gcc-7-arm-linux-gnueabi gcc-7-arm-linux-gnueabi-base gcc-7-cross-base
  22. gcc-8-cross-base gcc-arm-linux-gnueabi libasan4-armel-cross
  23. libatomic1-armel-cross libc6-armel-cross libc6-dev-armel-cross
  24. libcilkrts5-armel-cross libgcc-7-dev-armel-cross libgcc1-armel-cross
  25. libgomp1-armel-cross libstdc++6-armel-cross libubsan0-armel-cross
  26. linux-libc-dev-armel-cross
  27. The following packages will be upgraded:
  28. binutils binutils-common binutils-x86-64-linux-gnu libbinutils
  29. 4 upgraded, 19 newly installed, 1 to remove and 228 not upgraded.
  30. Need to get 23.9 MB of archives.
  31. After this operation, 69.9 MB of additional disk space will be used.
  32. Do you want to continue? [Y/n]

也可以直接下载对应文件后配置:

下载地址:

  • http://releases.linaro.org/components/toolchain/binaries/
  • https://launchpad.net/gcc-arm-embedded/+download

查询安装情况:

  1. biren@ubuntu:~$ arm-linux-gnueabi-
  2. arm-linux-gnueabi-addr2line arm-linux-gnueabi-gcov-7
  3. arm-linux-gnueabi-ar arm-linux-gnueabi-gcov-dump
  4. arm-linux-gnueabi-as arm-linux-gnueabi-gcov-dump-7
  5. arm-linux-gnueabi-c++filt arm-linux-gnueabi-gcov-tool
  6. arm-linux-gnueabi-cpp arm-linux-gnueabi-gcov-tool-7
  7. arm-linux-gnueabi-cpp-7 arm-linux-gnueabi-gprof
  8. arm-linux-gnueabi-dwp arm-linux-gnueabi-ld
  9. arm-linux-gnueabi-elfedit arm-linux-gnueabi-ld.bfd
  10. arm-linux-gnueabi-gcc arm-linux-gnueabi-ld.gold
  11. arm-linux-gnueabi-gcc-7 arm-linux-gnueabi-nm
  12. arm-linux-gnueabi-gcc-ar arm-linux-gnueabi-objcopy
  13. arm-linux-gnueabi-gcc-ar-7 arm-linux-gnueabi-objdump
  14. arm-linux-gnueabi-gcc-nm arm-linux-gnueabi-ranlib
  15. arm-linux-gnueabi-gcc-nm-7 arm-linux-gnueabi-readelf
  16. arm-linux-gnueabi-gcc-ranlib arm-linux-gnueabi-size
  17. arm-linux-gnueabi-gcc-ranlib-7 arm-linux-gnueabi-strings
  18. arm-linux-gnueabi-gcov arm-linux-gnueabi-strip

下载、编译uboot :

下载地址:ftp://ftp.denx.de/pub/u-boot/

解压:

  1. biren@ubuntu:~$ tar -xvf u-boot-2019.10.tar.bz2
  2. biren@ubuntu:~$ cd u-boot-2019.10/
  3. biren@ubuntu:~/u-boot-2019.10$ ll configs/vexp*
  4. -rw-rw-r-- 1 biren biren 1251 Oct 8 2019 configs/vexpress_aemv8a_juno_defconfig
  5. -rw-rw-r-- 1 biren biren 1120 Oct 8 2019 configs/vexpress_aemv8a_semi_defconfig
  6. -rw-rw-r-- 1 biren biren 963 Oct 8 2019 configs/vexpress_ca15_tc2_defconfig
  7. -rw-rw-r-- 1 biren biren 905 Oct 8 2019 configs/vexpress_ca5x2_defconfig
  8. -rw-rw-r-- 1 biren biren 936 Oct 8 2019 configs/vexpress_ca9x4_defconfig

以vexpress_ca9x4_defconfig为示例

编译u-boot :

  1. biren@ubuntu:~/u-boot-2019.10$ make vexpress_ca9x4_defconfig
  2. #
  3. # configuration written to .config
  4. #
  5. biren@ubuntu:~/u-boot-2019.10$ make CROSS_COMPILE=arm-linux-gnueabi- all

结果:

产生的主要文件:u-boot , u-boot.bin ...

  1. biren@ubuntu:~/u-boot-2019.10$ ls
  2. api doc Kbuild README u-boot.cfg.configs
  3. arch Documentation Kconfig scripts u-boot.lds
  4. board drivers lib System.map u-boot.map
  5. cmd dts Licenses test u-boot-nodtb.bin
  6. common env MAINTAINERS tools u-boot.srec
  7. config.mk examples Makefile u-boot u-boot.sym
  8. configs fs net u-boot.bin
  9. disk include post u-boot.cfg

测试u_boot启动:

命令:qemu-system-arm -M vexpress-a9 -m 512M -kernel ~/u-boot-2019.10/u-boot -nographic

  1. biren@ubuntu:~/buildroot-2019.11-rc1/output/images$ qemu-system-arm -M vexpress-a9 -m 512M -kernel ~/u-boot-2019.10/u-boot -nographic
  2. U-Boot 2019.10 (Jun 23 2022 - 22:56:12 +0800)
  3. DRAM: 512 MiB
  4. WARNING: Caches not enabled
  5. Flash: 128 MiB
  6. MMC: MMC: 0
  7. *** Warning - bad CRC, using default environment
  8. In: serial
  9. Out: serial
  10. Err: serial
  11. Net: smc911x-0
  12. Hit any key to stop autoboot: 0
  13. MMC Device 1 not found
  14. no mmc device at slot 1
  15. Card did not respond to voltage select!
  16. smc911x: MAC 52:54:00:12:34:56
  17. smc911x: detected LAN9118 controller
  18. smc911x: phy initialized
  19. smc911x: MAC 52:54:00:12:34:56
  20. BOOTP broadcast 1
  21. DHCP client bound to address 10.0.2.15 (5 ms)
  22. *** Warning: no boot file name; using '0A00020F.img'
  23. Using smc911x-0 device
  24. TFTP from server 10.0.2.2; our IP address is 10.0.2.15
  25. Filename '0A00020F.img'.
  26. smc911x: MAC 52:54:00:12:34:56
  27. 。。。。。。
  28. Wrong Image Format for bootm command
  29. ERROR: can't get kernel image! (此时还不能启动内核)
  30. =>

打印环境变量:

  1. => printenv
  2. arch=arm
  3. baudrate=38400
  4. board=vexpress
  5. board_name=vexpress
  6. boot_a_script=load ${devtype} ${devnum}:${distro_bootpart} ${scriptaddr} ${prefix}${script}; source ${scriptaddr}
  7. boot_extlinux=sysboot ${devtype} ${devnum}:${distro_bootpart} any ${scriptaddr} ${prefix}${boot_syslinux_conf}
  8. boot_prefixes=/ /boot/
  9. boot_script_dhcp=boot.scr.uimg
  10. boot_scripts=boot.scr.uimg boot.scr
  11. boot_syslinux_conf=extlinux/extlinux.conf
  12. boot_targets=mmc1 mmc0 pxe dhcp
  13. bootargs=root=/dev/sda1 rw console=ttyAMA0,38400n8 mem=1024M mtdparts=armflash:1M@0x800000(uboot),7M@0x1000000(kernel),24M@0x2000000(initrd) mmci.fmax=190000 devtmpfs.mount=0 vmalloc=256M
  14. bootcmd=run distro_bootcmd; run bootflash
  15. bootcmd_dhcp=if dhcp ${scriptaddr} ${boot_script_dhcp}; then source ${scriptaddr}; fi;
  16. bootcmd_mmc0=devnum=0; run mmc_boot
  17. bootcmd_mmc1=devnum=1; run mmc_boot
  18. bootcmd_pxe=dhcp; if pxe get; then pxe boot; fi
  19. bootdelay=2 自动启动内核延时
  20. bootfile=boot.scr.uimg
  21. bootflash=run flashargs; cp ${ramdisk_addr} ${ramdisk_addr_r} ${maxramdisk}; bootm ${kernel_addr} ${ramdisk_addr_r}
  22. console=ttyAMA0,38400n8
  23. cpu=armv7
  24. distro_bootcmd=for target in ${boot_targets}; do run bootcmd_${target}; done
  25. dram=1024M
  26. ethact=smc911x-0
  27. ethaddr=52:54:00:12:34:56
  28. flashargs=setenv bootargs root=${root} console=${console} mem=${dram} mtdparts=${mtd} mmci.fmax=190000 devtmpfs.mount=0 vmalloc=256M
  29. kernel_addr=0x44100000 内核地址
  30. kernel_addr_r=0x80008000
  31. loadaddr=0x80008000
  32. maxramdisk=0x1800000
  33. mmc_boot=if mmc dev ${devnum}; then devtype=mmc; run scan_dev_for_boot_part; fi
  34. mtd=armflash:1M@0x800000(uboot),7M@0x1000000(kernel),24M@0x2000000(initrd)
  35. pxefile_addr_r=0x88000000
  36. ramdisk_addr=0x44800000 根文件系统地址
  37. ramdisk_addr_r=0x61000000
  38. root=/dev/sda1 rw
  39. 。。。

启动成功

退出qemu或u-boot命令模式:

  • ctrl + a, 然后按x
  • 另一终端窗口中输入killall qemu-system-arm
  • poweroff

=====================================

下载、编译、安装文件系统(buildroot制作):

下载:https://buildroot.org/downloads/

(buildroot可用于制作交叉编译、根文件系统、kernel内核、设备树dtb等)

解压:

biren@ubuntu:~ $ tar -xvf buildroot-2019.11-rc1.bz2

制作根文件、kernel方法一:自定义配置

配置:

  1. biren@ubuntu:~$ cd buildroot-2019.11-rc1/
  2. biren@ubuntu:~/buildroot-2019.11-rc1$ make menuconfig

Target options --->

Toolchain --->

 

 System configuration --->

 

Filesystem images --->

 

......

执行make:

biren@ubuntu:~/buildroot-2019.11-rc1$ make -j4

制作根文件、kernel方法二:用预定义的配置

  1. biren@ubuntu:~/buildroot-2019.11-rc1$ make qemu_arm_vexpress_defconfig
  2. biren@ubuntu:~/buildroot-2019.11-rc1$ make -j4
  3. 。。。。。。
  4. mke2fs 1.45.4 (23-Sep-2019)
  5. Creating regular file /home/biren/buildroot-2019.11-rc1/output/images/rootfs.ext2
  6. Creating filesystem with 61440 1k blocks and 15360 inodes
  7. Filesystem UUID: 0bb88659-037f-4f5e-be71-e6117cb08767
  8. Superblock backups stored on blocks:
  9. 8193, 24577, 40961, 57345
  10. Allocating group tables: done
  11. Writing inode tables: done
  12. Copying files into the device: done
  13. Writing superblocks and filesystem accounting information: done

buildroot编译结果:

生成关键的三个文件:rootfs.ext2(根文件系统), vexpress-v2p-ca9.dtb(设备树), zImage(kernel内核)

  1. biren@ubuntu:~/buildroot-2019.11-rc1$ ls
  2. arch Config.in DEVELOPERS linux package toolchain
  3. board Config.in.legacy dl Makefile README utils
  4. boot configs docs Makefile.legacy support
  5. CHANGES COPYING fs output system
  6. biren@ubuntu:~/buildroot-2019.11-rc1$ ls output
  7. build host images staging target
  8. biren@ubuntu:~/buildroot-2019.11-rc1$ ll output/images/
  9. total 7884
  10. -rw-r--r-- 1 biren biren 62914560 Jun 25 11:37 rootfs.ext2
  11. -rw-r--r-- 1 biren biren 14430 Jun 25 11:37 vexpress-v2p-ca9.dtb
  12. -rw-r--r-- 1 biren biren 4134576 Jun 25 11:37 zImage

====================================

内核zImage启动测试:(方法一,用到-sd, mmcblk0参数)

启动命令:qemu-system-arm -M vexpress-a9 -m 512M -kernel zImage -dtb vexpress-v2p-ca9.dtb -nographic -sd rootfs.ext2 -append "root=/dev/mmcblk0 rw console=ttyAMA0 init=/linuxrc"

参数说明 :

  • -kernel : 指定内核文件
  • -dtb: 指定设备树文件
  • -sd : 指定sd设备文件(此处存放根文件系统),类似有-hda(对应root=/dev/sda)
  • -nographic : 非图形模式
  • -append : 即bootargs启动命令行配置,root指定根文件系统挂载点,console指定输出接口,init指定启动后运行的第一个命令(程序 )
  • -m : 内存大小
  • -M : 指定虚拟主板
  1. biren@ubuntu:~/buildroot-2019.11-rc1/output/images$ qemu-system-arm -M vexpress-a9 -m 512M -kernel zImage -dtb vexpress-v2p-ca9.dtb -append "root=/dev/mmcblk0 console=tty0 init=/linuxrc" -nographic -sd rootfs.ext2
  2. WARNING: Image format was not specified for 'rootfs.ext2' and probing guessed raw.
  3. Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
  4. Specify the 'raw' format explicitly to remove the restrictions.
  5. qemu-system-arm: Invalid SD card size: 60 MiB
  6. SD card size has to be a power of 2, e.g. 64 MiB.
  7. You can resize disk images with 'qemu-img resize <imagefile> <new-size>'
  8. (note that this will lose data if you make the image smaller than it currently is).

出现错误 :SD card size has to be a power of 2, e.g. 64 MiB.

即SD文件的大小应是2的n次方

解决:修改文件大小

命令:qemu-img resize <imagefile> <new-size>

  1. biren@ubuntu:~/buildroot-2019.11-rc1/output/images$ cp rootfs.ext2 rootfs-copy.ext2
  2. biren@ubuntu:~/buildroot-2019.11-rc1/output/images$ qemu-img resize rootfs.ext2 64M
  3. Image resized.

或者用dd命令新建一个64M的rootfs.img镜像文件,然后将数据复制进去:

dd if=/dev/zero of=rootfs.img bs=1M count=64

  1. biren@ubuntu:~/buildroot-2019.11-rc1/output/images$ dd if=/dev/zero of=rootfs.img bs=1M count=64
  2. 64+0 records in
  3. 64+0 records out
  4. 67108864 bytes (67 MB, 64 MiB) copied, 0.134254 s, 500 MB/s
  5. biren@ubuntu:~/buildroot-2019.11-rc1/output/images$ mkfs.ext2 rootfs.img
  6. mke2fs 1.44.1 (24-Mar-2018)
  7. Discarding device blocks: done
  8. Creating filesystem with 65536 1k blocks and 16384 inodes
  9. Filesystem UUID: 01d8344a-685d-420e-82f6-6b6d24c6d2d7
  10. Superblock backups stored on blocks:
  11. 8193, 24577, 40961, 57345
  12. Allocating group tables: done
  13. Writing inode tables: done
  14. Writing superblocks and filesystem accounting information: done
  15. biren@ubuntu:~/buildroot-2019.11-rc1/output/images$ mkdir tmpfs
  16. biren@ubuntu:~/buildroot-2019.11-rc1/output/images$ sudo mount rootfs-copy.ext2 tmpfs
  17. biren@ubuntu:~/buildroot-2019.11-rc1/output/images$ sudo mount -o loop rootfs.img /mnt
  18. biren@ubuntu:~/buildroot-2019.11-rc1/output/images$ sudo cp -a tmpfs/* /mnt
  19. biren@ubuntu:~/buildroot-2019.11-rc1/output/images$ sudo umount tmpfs
  20. biren@ubuntu:~/buildroot-2019.11-rc1/output/images$ sudo umount /mnt

新的文件:

  1. biren@ubuntu:~/buildroot-2019.11-rc1/output/images$ ll
  2. total 174457
  3. -rw-r--r-- 1 biren biren 62914560 Jun 30 17:04 rootfs-copy.ext2
  4. -rw-r--r-- 1 biren biren 67108864 Jun 30 16:54 rootfs.ext2 新的文件
  5. -rw-rw-r-- 1 biren biren 67108864 Jun 30 17:03 rootfs.img 新的文件
  6. -rw-rw-r-- 1 biren biren 134217728 Jun 28 16:49 sdcard.img
  7. drwxr-xr-x 18 root root 1024 Jun 25 11:37 tmpfs/
  8. -rw-r--r-- 1 biren biren 14430 Jun 25 11:37 vexpress-v2p-ca9.dtb
  9. -rw-r--r-- 1 biren biren 4134576 Jun 25 11:37 zImage

重新启动内核zImage:

根文件系统用rootfs.img或rootfs.ext2都行

(有些是没有dtb的,编译内核时有参数指定)

  1. biren@ubuntu:~/buildroot-2019.11-rc1/output/images$ qemu-system-arm -M vexpress-a9 -m 512M -kernel zImage -dtb vexpress-v2p-ca9.dtb -nographic -sd rootfs.img -append "root=/dev/mmcblk0 console=ttyAMA0 init=/linuxrc"
  2. WARNING: Image format was not specified for 'rootfs.img' and probing guessed raw.
  3. Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
  4. Specify the 'raw' format explicitly to remove the restrictions.
  5. Welcome to Buildroot 正常启动。。。。。。
  6. buildroot login: root (无密码)
  7. #
  8. # pwd
  9. /root
  10. # ls /
  11. bin lib lost+found opt run tmp
  12. dev lib32 media proc sbin usr
  13. etc linuxrc mnt root sys var

警告:Image format was not specified for 'rootfs.img' and probing guessed raw.

可以用 -drive format=raw,file=rootfs.img解决

==================================

启动内核方法二:(用到-initrd,ram0参数)

命令:

qemu-system-arm -M vexpress-a9 -m 512M -kernel zImage -dtb vexpress-v2p-ca9.dtb -initrd rootfs.ext3 -nographic -append "root=/dev/ram0 rw console=ttyAMA0 init=/linuxrc"

与前面区别:这里没有用-sd选项,用的是-initrd rootfs.ext3

另外挂载点改为:root=/dev/ram0或root=/dev/ram

(此处的rootfs.ext3是从rootfs.ext2复制过来重新制成ext3格式,大小4M,可用dd制作)

(rootfs.ext3, rootfs.ext3.gz, rootfs.ext3.ramdisk都可用)

  1. biren@ubuntu:~/buildroot-2019.11-rc1/output/images$ ll rootfs.ext3*
  2. -rw-rw-r-- 1 biren biren 4194304 Jul 13 22:29 rootfs.ext3
  3. -rw-rw-r-- 1 biren biren 789675 Jul 6 10:47 rootfs.ext3.gz gzip压缩文件
  4. -rw-rw-r-- 1 biren biren 4194368 Jul 6 11:24 rootfs.ext3.ramdisk 用mkimage制成的,加64字节头

值得注意的是编译内核时需要选上支持ram disk的相关选项:

配置buildroot:

命令:make qemu_arm_vexpress_defconfig

  1. biren@ubuntu:~/buildroot-2019.11-rc1$ make qemu_arm_vexpress_defconfig
  2. biren@ubuntu:~/buildroot-2019.11-rc1$ make menuconfig

> Filesystem images :

  • ext2/3/4 root filesystem
  • (60M) exact size 根文件系统的大小为60M(实际只占用几百K)

配置内核:

命令:make linux-menuconfig

biren@ubuntu:~/buildroot-2019.11-rc1$ make linux-menuconfig

> General setup :

  • Initial RAM filesystem and RAM disk (initramfs/initrd) support
  • Support initial ramdisk/ramfs compressed using gzip

> Device Drivers > Block devices :

Default RAM disk size (kbytes) 指定ramdisk的大小,启动时在-initrd参数中指定的文件大小不能超过此值

> File systems :

Second extended fs support (ext2) ...

 启动内核方法三:从MMC加载内核

(先启动u-boot - 加载内核到RAM - bootz启动)

一、先制作sdcard.img文件

  • 创建128M文件
  • 格式化为vfat
  • 挂载到/mnt
  • 复制zImage、rootfs.ext2、vexpress-v2p-ca9.dtb到/mnt
  • 取消挂载点/mnt
  1. biren@ubuntu:~/buildroot-2019.11-rc1/output/images$ dd if=/dev/zero of=sdcard.img bs=4096 count=32768
  2. 25600+0 records in
  3. 25600+0 records out
  4. 104857600 bytes (134 MB, 128 MiB) copied, 0.818929 s, 128 MB/s
  5. biren@ubuntu:~/buildroot-2019.11-rc1/output/images$ mkfs.vfat sdcard.img
  6. mkfs.fat 4.1 (2017-01-24)
  7. biren@ubuntu:~/buildroot-2019.11-rc1/output/images$ sudo mount -rw -o loop sdcard.img /mnt
  8. biren@ubuntu:~/buildroot-2019.11-rc1/output/images$ sudo cp zImage /mnt
  9. biren@ubuntu:~/buildroot-2019.11-rc1/output/images$ sudo cp rootfs.ext2 /mnt
  10. biren@ubuntu:~/buildroot-2019.11-rc1/output/images$ sudo cp vexpress-v2p-ca9.dtb /mnt
  11. biren@ubuntu:~/buildroot-2019.11-rc1/output/images$ ll /mnt
  12. total 65514
  13. -rwxr-xr-x 1 root root 62914560 Jun 28 16:44 rootfs.ext2*
  14. -rwxr-xr-x 1 root root 14430 Jun 28 16:44 vexpress-v2p-ca9.dtb*
  15. -rwxr-xr-x 1 root root 4134576 Jun 28 16:44 zImage*
  16. biren@ubuntu:~/buildroot-2019.11-rc1/output/images$ sudo umount /mnt

二、启动u-boot

命令:qemu-system-arm -M vexpress-a9 -m 512M -kernel /home/biren/u-boot-2019.10/u-boot -sd sdcard.img -nographic

  1. biren@ubuntu:~/buildroot-2019.11-rc1/output/images$ qemu-system-arm -M vexpress-a9 -m 512M -kernel /home/biren/u-boot-2019.10/u-boot -nographic -sd sdcard.img
  2. WARNING: Image format was not specified for 'sdcard.img' and probing guessed raw.
  3. Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
  4. Specify the 'raw' format explicitly to remove the restrictions.
  5. U-Boot 2019.10 (Jun 23 2022 - 22:56:12 +0800)
  6. DRAM: 512 MiB
  7. WARNING: Caches not enabled
  8. Flash: 128 MiB
  9. MMC: MMC: 0
  10. *** Warning - bad CRC, using default environment
  11. In: serial
  12. Out: serial
  13. Err: serial
  14. Net: smc911x-0
  15. Hit any key to stop autoboot: 0
  16. MMC Device 1 not found
  17. no mmc device at slot 1
  18. switch to partitions #0, OK
  19. mmc0 is current device
  20. ** Invalid partition 1 **
  21. smc911x: MAC 52:54:00:12:34:56
  22. smc911x: detected LAN9118 controller
  23. smc911x: phy initialized
  24. smc911x: MAC 52:54:00:12:34:56
  25. 。。。
  26. TFTP error: trying to overwrite reserved memory...
  27. smc911x: MAC 52:54:00:12:34:56
  28. Wrong Image Format for bootm command
  29. ERROR: can't get kernel image! (此时还没有启动内核)
  30. =>

三、将zImage、rootfs.ext2、vexpress-v2p-ca9.dtb从sd中加载到DRAM内存中:

命令:fatload mmc 0:0 0x62008000 zImage

(加载地址自拟,只要不重叠即可)

  1. => fatload mmc 0:0 0x62008000 zImage
  2. 4134576 bytes read in 2344 ms (1.7 MiB/s)
  3. => fatload mmc 0:0 0x62A08000 rootfs.ext2
  4. 62914560 bytes read in 36366 ms (1.6 MiB/s)
  5. => fatload mmc 0:0 0x68E08000 vexpress-v2p-ca9.dtb
  6. 14430 bytes read in 40 ms (351.6 KiB/s)

四、启动内核

命令:bootz [addr [initrd[:size]] [fdt]]

如:bootz 62008000 62A08000 68E08000

无initrd时用“-”代替

如:bootz 62008000 - 68E08000

  1. => bootz 62008000 62A08000 68E08000
  2. Kernel image @ 0x62008000 [ 0x000000 - 0x3f16b0 ]
  3. Wrong Ramdisk Image Format
  4. Ramdisk image is corrupt or invalid

错误 :Wrong Ramdisk Image Format

解决:使用mkimage命令将根文件系统制成uImage格式的文件

命令:mkimage -n 'uboot ext2 ramdisk rootfs' -A arm -O linux -T ramdisk -C none -d rootfs.ext2 rootfs.ext2.ramdisk

  1. biren@ubuntu:~/buildroot-2019.11-rc1/output/images$ mkimage -n 'uboot ext2 ramdisk rootfs' -A arm -O linux -T ramdisk -C none -d rootfs.ext2 rootfs.ext2.ramdisk
  2. Image Name: uboot ext2 ramdisk rootfs
  3. Created: Tue Jul 5 19:58:27 2022
  4. Image Type: ARM Linux RAMDisk Image (uncompressed)
  5. Data Size: 62914560 Bytes = 61440.00 KiB = 60.00 MiB
  6. Load Address: 00000000
  7. Entry Point: 00000000
  8. biren@ubuntu:~/buildroot-2019.11-rc1/output/images$ ll
  9. -rwxr-xr-x 1 biren biren 62914560 Jun 28 16:44 rootfs.ext2*
  10. -rw-rw-r-- 1 biren biren 62914624 Jul 5 19:58 rootfs.ext2.ramdisk
  11. -rw-rw-r-- 1 biren biren 134217728 Jul 5 19:57 sdcard.img
  12. drwxr-xr-x 2 root root 16384 Jan 1 1970 tmpfs/
  13. -rw-r--r-- 1 biren biren 14430 Jun 25 11:37 vexpress-v2p-ca9.dtb
  14. -rw-r--r-- 1 biren biren 4134576 Jun 25 11:37 zImage

新的根文件系统文件:rootfs.ext2.ramdisk

将rootfs.ext2.ramdisk存入sdcard.img中:

  1. biren@ubuntu:~/buildroot-2019.11-rc1/output/images$ sudo mount -o loop sdcard.img tmpfs
  2. biren@ubuntu:~/buildroot-2019.11-rc1/output/images$ sudo cp rootfs.ext2.ramdisk tmpfs
  3. biren@ubuntu:~/buildroot-2019.11-rc1/output/images$ sudo umount tmpfs

再运行二到四步

  1. qemu-system-arm -M vexpress-a9 -m 512M -kernel /home/biren/u-boot-2019.10/u-boot -sd sdcard.img -nographic
  2. fatload mmc 0:0 0x62008000 zImage;fatload mmc 0:0 0x62A08000 rootfs.ext2.ramdisk;fatload mmc 0:0 0x68E08000 vexpress-v2p-ca9.dtb
  3. setenv bootargs root=/dev/ram rw console=ttyAMA0,115200 init=/linuxrc
  4. bootz 62008000 62A08000 68E08000

启动内核方法四:用tftp加载内核

先进行qemu网络功能配置:

查看tun是否安装:

  1. biren@ubuntu:~/buildroot-2019.11-rc1/output/images$ grep CONFIG_TUN= /boot/config-`uname -r`
  2. CONFIG_TUN=y
  3. 或用如下查询 :
  4. biren@ubuntu:~/buildroot-2019.11-rc1/output/images$ ll /dev/net/tun
  5. crw-rw-rw- 1 root root 10, 200 Jul 17 10:51 /dev/net/tun
  6. 如果没有tun则用如下命令增加:
  7. mknod /dev/net/tun c 10 200

ubuntu里安装桥接工具:

命令:sudo apt-get install uml-utilities bridge-utils

ubuntu里创建tap0 :

查看当前网络:

命令:ip addr 或ip a 或ip address

或用:ifconfig

  1. biren@ubuntu:~$ ip a
  2. 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
  3. link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
  4. inet 127.0.0.1/8 scope host lo
  5. valid_lft forever preferred_lft forever
  6. inet6 ::1/128 scope host
  7. valid_lft forever preferred_lft forever
  8. 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
  9. link/ether 00:0c:29:ad:94:63 brd ff:ff:ff:ff:ff:ff
  10. inet 192.168.153.146/24 brd 192.168.153.255 scope global dynamic noprefixroute ens33
  11. valid_lft 1657sec preferred_lft 1657sec
  12. inet6 fe80::1800:85cd:fb23:2de/64 scope link noprefixroute
  13. valid_lft forever preferred_lft forever

网口名是ens33,ip是192.168.153.146

虚拟机ubuntu与win10连接用的是NAT方式

创建tap0命令:

  • sudo ip tuntap add dev tap0 mode tap
  • sudo ip link set dev tap0 up
  • sudo ip address add dev tap0 192.168.153.170/24
  1. biren@ubuntu:~$ sudo ip tuntap add dev tap0 mode tap
  2. biren@ubuntu:~$ sudo ip link set dev tap0 up
  3. biren@ubuntu:~$ sudo ip address add dev tap0 192.168.153.170/24
  4. biren@ubuntu:~$ ifconfig
  5. ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
  6. inet 192.168.153.146 netmask 255.255.255.0 broadcast 192.168.153.255
  7. inet6 fe80::1800:85cd:fb23:2de prefixlen 64 scopeid 0x20<link>
  8. ether 00:0c:29:ad:94:63 txqueuelen 1000 (Ethernet)
  9. RX packets 2430 bytes 3084008 (3.0 MB)
  10. RX errors 0 dropped 0 overruns 0 frame 0
  11. TX packets 1452 bytes 118503 (118.5 KB)
  12. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
  13. lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
  14. inet 127.0.0.1 netmask 255.0.0.0
  15. inet6 ::1 prefixlen 128 scopeid 0x10<host>
  16. loop txqueuelen 1000 (Local Loopback)
  17. RX packets 207 bytes 16767 (16.7 KB)
  18. RX errors 0 dropped 0 overruns 0 frame 0
  19. TX packets 207 bytes 16767 (16.7 KB)
  20. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
  21. tap0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
  22. inet 192.168.153.170 netmask 255.255.255.0 broadcast 0.0.0.0
  23. ether be:6a:b3:80:db:9d txqueuelen 1000 (Ethernet)
  24. RX packets 0 bytes 0 (0.0 B)
  25. RX errors 0 dropped 0 overruns 0 frame 0
  26. TX packets 0 bytes 0 (0.0 B)
  27. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

配置TFTP服务器:

一、在主机ubuntu上搭建tftp服务器

安装tftp-hpa、 tftpd-hpa、 xinetd三个包文件

biren@ubuntu:~$ sudo apt-get install tftp-hpa tftpd-hpa xinetd

二、建立ftp文件夹,并修改为777权限

  1. biren@ubuntu:~$ mkdir tftpFile
  2. biren@ubuntu:~$ chmod 777 tftpFile

三、修改/etc/default/tftpd-hpa

  1. # /etc/default/tftpd-hpa
  2. TFTP_USERNAME="tftp"
  3. TFTP_DIRECTORY="/var/lib/tftpboot"
  4. TFTP_ADDRESS=":69"
  5. TFTP_OPTIONS="--secure"

修改为:

  1. # /etc/default/tftpd-hpa
  2. TFTP_USERNAME="tftp"
  3. TFTP_DIRECTORY="/home/biren/tftpFile"
  4. TFTP_ADDRESS=":69"
  5. TFTP_OPTIONS="--secure"

四、新建/etc/xinetd.d/tftp文件,内容如下:

  1. server tftp
  2. {
  3. protocol = udp
  4. flags = IPv4
  5. socket_type = dgram
  6. user = root
  7. server = /usr/sbin/in.tftpd
  8. server_args = -s /home/biren/tftpFile
  9. wait = yes
  10. disable = no
  11. per_source = 11
  12. cps = 100 2
  13. }

五、启动tftp服务

  1. sudo service tftpd-hpa start
  2. 出现tftp>命令符正常:
  3. biren@ubuntu:~$ tftp localhost
  4. tftp>

六、将zImage、rootfs.ext3.ramdisk、vexpress-v2p-ca9.dtb复制到/home/biren/tftpFile/里

  1. biren@ubuntu:~/tftpFile$ pwd
  2. /home/biren/tftpFile
  3. biren@ubuntu:~/tftpFile$ ll
  4. total 8296
  5. drwxrwxrwx 2 biren biren 4096 Aug 18 18:59 ./
  6. drwxr-xr-x 32 biren biren 4096 Aug 18 16:15 ../
  7. -rw-rw-r-- 1 biren biren 4194368 Jul 6 11:24 rootfs.ext3.ramdisk
  8. -rw-r--r-- 1 biren biren 14430 Jul 13 17:24 vexpress-v2p-ca9.dtb
  9. -rw-r--r-- 1 biren biren 4268720 Jul 13 17:24 zImage

带网络参数的启动u-boot :

命令:sudo /usr/local/qemu6.2.0/bin/qemu-system-arm -M vexpress-a9 -m 512M -kernel /home/biren/u-boot-2019.10/u-boot -sd sdcard.img -nographic -net nic -net tap,ifname=tap0,script=no,downscript=no

参数说明:

  • -net nic 建立虚拟网卡
  • -net tap,ifname=tap0 在host上产生一个tap0接口
  • script, donwscript指定启动时的网络配置脚本,如果不指定时则会自动查找/etc/qemu-ifup和/etc/qemu-ifdown来运行

启动后,设置qemu的ip为192.168.153.160 ,

设置serverip为192.168.153.170 :

  1. => setenv ipaddr 192.168.153.160
  2. => setenv serverip 192.168.153.170
  3. => ping 192.168.153.170
  4. smc911x: MAC 52:54:00:12:34:56
  5. smc911x: detected LAN9118 controller
  6. smc911x: phy initialized
  7. smc911x: MAC 52:54:00:12:34:56
  8. Using smc911x-0 device
  9. smc911x: MAC 52:54:00:12:34:56
  10. host 192.168.153.170 is alive
  11. =>

设置启动参数:

=> setenv bootargs  'root=/dev/mmcblk0 rw console=ttyAMA0 init=/linuxrc'

用tftp命令加载启动文件到内存:

:192.168.153.170:/home/biren/tftpFile/

目的地:qemu的起始地址为0x62008000、0x62508000、0x62a08000的内存处

命令:

  • tftp 62008000 zImage 从/home/biren/tftpFile/加载内核
  • tftp 62508000 rootfs.ext3.ramdisk 加载根文件系统
  • tftp 62a08000 vexpress-v2p-ca9.dtb 加载设备树
  1. => tftp 62008000 zImage
  2. smc911x: MAC 52:54:00:12:34:56
  3. smc911x: detected LAN9118 controller
  4. smc911x: phy initialized
  5. smc911x: MAC 52:54:00:12:34:56
  6. Using smc911x-0 device
  7. TFTP from server 192.168.153.170; our IP address is 192.168.153.160
  8. Filename 'zImage'.
  9. Load address: 0x62008000
  10. Loading: #########################
  11. 1.4 MiB/s
  12. done
  13. Bytes transferred = 4268720 (4122b0 hex)
  14. smc911x: MAC 52:54:00:12:34:56
  15. => tftp 62508000 rootfs.ext3.ramdisk
  16. => tftp 62a08000 vexpress-v2p-ca9.dtb

启动内核:

=> bootz 62008000 62508000 62a08000

启动到最后时出现错误

can't open /dev/ttyAMA0: No such file or directory

解决方法一

将启动bootargs参数

setenv bootargs 'root=/dev/mmcblk0 rw console=ttyAMA0 init=/linuxrc'

改为:

setenv bootargs 'root=/dev/ram rw console=ttyAMA0 init=/linuxrc'

解决方法二

将启动命令:

sudo /usr/local/qemu6.2.0/bin/qemu-system-arm -M vexpress-a9 -m 512M -kernel /home/biren/u-boot-2019.10/u-boot -sd sdcard.img -nographic -net nic -net tap,ifname=tap0,script=no,downscript=no

改为:(即用-sd挂载根文件系统)

sudo /usr/local/qemu6.2.0/bin/qemu-system-arm -M vexpress-a9 -m 512M -kernel /home/biren/u-boot-2019.10/u-boot -sd rootfs.ext3 -nographic -net nic -net tap,ifname=tap0,script=no,downscript=no

将启动内核命令改为即可:

bootz 62008000 - 62a08000

另一个可能的原因是:

没有勾选devtmpfs filesystem

通过以下方式选中并重新编译

biren@ubuntu:~/buildroot-2019.11-rc1$ make linux-menuconfig

Device Drivers ---> Generic Driver Options --->

[*] Maintain a devtmpfs filesystem to mount at /dev

    [*] Automount devtmpfs at /dev, after the kernel mounted the rootfs

启动内核方法五:用nfs加载内核(自动)

1、安装nfs-kernel-server , nfs-common

命令:sudo apt-get install nfs-kernel-server nfs-common

2、创建共享文件夹:

  1. biren@ubuntu:~$ mkdir nfsFile
  2. biren@ubuntu:~/nfsFile$ pwd
  3. /home/biren/nfsFile

3、在/etc/exports中加入一行:

/home/biren/nfsFile *(rw,sync,no_root_squash)

4、重启nfs服务:

sudo service nfs-kernel-server restart

5、配置tap0网络命令(ubuntu):

  • sudo ip tuntap add dev tap0 mode tap
  • sudo ip link set dev tap0 up
  • sudo ip address add dev tap0 192.168.153.170/24

也可以使用以下命令:

  1. sudo tunctl -u $USER -t tap0      (生成一个tap0接口)
  2. sudo ifconfig tap0 192.168.153.170
  3. 删除tap0接口:
  4. sudo tunctl -d tap0
  5. sudo ifconfig tap0 192.168.153.170 down 卸载网卡
  6. 删除网桥:
  7. sudo brctl delbr br0

6、启动仿真qemu

命令:
sudo /usr/local/qemu6.2.0/bin/qemu-system-arm -M vexpress-a9 -m 512M -kernel zImage -dtb vexpress-v2p-ca9.dtb -sd sdcard.img -nographic -net nic -net tap,ifname=tap0,script=no,downscript=no -append "root=/dev/nfs rw nfsroot=192.168.153.170:/home/biren/nfsFile ip=192.168.153.160:192.168.153.170::::eth0:off console=ttyAMA0 init=/linuxrc"

错误一

VFS: Cannot open root device "nfs" or unknown-block(2,0): error -6

  1. VFS: Unable to mount root fs via NFS, trying floppy.
  2. VFS: Cannot open root device "nfs" or unknown-block(2,0): error -6
  3. Please append a correct "root=" boot option;
  4. Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(2,0)

原因:

内核的nfs版本要与ubuntu中的server nfs版本一致

内核支持的nfs版本:

> File systems > Network File Systems

ubuntu server nfs版本查询命令:nfsstat

解决:

在启动命令上加入nfs版本v3

sudo /usr/local/qemu6.2.0/bin/qemu-system-arm -M vexpress-a9 -m 512M -kernel zImage -dtb vexpress-v2p-ca9.dtb -sd sdcard.img -nographic -net nic -net tap,ifname=tap0,script=no,downscript=no -append "root=/dev/nfs rw nfsroot=192.168.153.170:/home/biren/nfsFile,v3 ip=192.168.153.160:192.168.153.170::::eth0:off console=ttyAMA0 init=/linuxrc" -rtc base=localtime,clock=host

错误二:

devtmpfs: error mounting -2

end Kernel panic - not syncing: Requested init /linuxrc failed (error -2)

解决方法一:

将根文件系统挂载到nfsFile目录下

biren@ubuntu:~$ sudo mount buildroot-2019.11-rc1/output/images/rootfs.ext3 ./nfsFile

或者直接将根文件系统里所有的资料都复制到/home/biren/nfsFile里面

  1. biren@ubuntu:~$ sudo mount buildroot-2019.11-rc1/output/images/rootfs.ext3 ./nfsFile/
  2. biren@ubuntu:~$ ls ./nfsFile/
  3. bin etc lib32 lost+found mnt proc run sys usr
  4. dev lib linuxrc media opt root sbin tmp var

解决方法二:(可能的原因之一)

重新将busybox编译成静态的:

biren@ubuntu:~/buildroot-2019.11-rc1$ make qemu_arm_vexpress_defconfig

biren@ubuntu:~/buildroot-2019.11-rc1$ make help (查看可用的命令)

biren@ubuntu:~/buildroot-2019.11-rc1$ make busybox-menuconfig

位置:Settings ---> [*] Build static binary (no shared libs)

biren@ubuntu:~/buildroot-2019.11-rc1$ make -j4

启动内核方法五:用nfs加载内核(手动)

1、将rootfs.ext3 vexpress-v2p-ca9.dtb zImage复制到nfsFile目录里

2、tap0设置:与前同

3、启动u-boot命令:

sudo /usr/local/qemu6.2.0/bin/qemu-system-arm -M vexpress-a9 -m 512M -kernel /home/biren/u-boot-2019.10/u-boot -nographic -net nic -net tap,ifname=tap0,script=no,downscript=no -rtc base=localtime,clock=host

4、设置网址(以下在虚拟qemu里操作)

=> setenv ipaddr 192.168.153.160

=> setenv serverip 192.168.153.170

5、加载内核到DRAM内存

=> nfs 62008000 192.168.153.170:/home/biren/nfsFile/zImage

=> nfs 62a08000 192.168.153.170:/home/biren/nfsFile/vexpress-v2p-ca9.dtb

6、ubuntu里挂载根文件系统rootfs.ext3到nfsFile

biren@ubuntu:~$ sudo mount buildroot-2019.11-rc1/output/images/rootfs.ext3 ./nfsFile/

7、设置bootcmd/bootargs

=> setenv bootargs 'root=/dev/nfs rw nfsroot=192.168.153.170:/home/biren/nfsFile,v3 ip=192.168.153.160:192.168.153.170::::eth0:off console=ttyAMA0 init=/linuxrc'

8、启动内核:

=> bootz 62008000 - 62a08000

启动内核方法六:自动用tftp加载内核到DRAM并启动

1、修改/home/biren/u-boot-2019.10/include/configs/vexpress_common.h,加入以下内容:

  1. #define CONFIG_BOOTCOMMAND \
  2. "tftp 0x62008000 zImage;\
  3. tftp 0x62508000 rootfs.ext3.ramdisk;\
  4. tftp 0x62a08000 vexpress-v2p-ca9.dtb;\
  5. setenv bootargs 'root=/dev/ram rw console=ttyAMA0 init=/linuxrc';\
  6. bootz 0x62008000 0x62508000 0x62a08000;"
  7. #define CONFIG_IPADDR 192.168.153.160
  8. #define CONFIG_NETMASK 255.255.255.0
  9. #define CONFIG_SERVERIP 192.168.153.170

重新编译u-boot:

biren@ubuntu:~/u-boot-2019.10$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi-  -j4

2、tap0设置:与前同

3、启动u-boot(同时自动启动内核)命令:

sudo /usr/local/qemu6.2.0/bin/qemu-system-arm -M vexpress-a9 -m 512M -kernel /home/biren/u-boot-2019.10/u-boot -nographic -net nic -net tap,ifname=tap0,script=no,downscript=no -rtc base=localtime,clock=host

启动内核方法七:自动用nfs加载内核到DRAM并启动

1、修改/home/biren/u-boot-2019.10/include/configs/vexpress_common.h,加入以下内容:

  1. #define CONFIG_BOOTCOMMAND \
  2. "nfs 62008000 192.168.153.170:/home/biren/nfsFile/zImage;\
  3. nfs 62508000 192.168.153.170:/home/biren/nfsFile/rootfs.ext3.ramdisk;\
  4. nfs 62a08000 192.168.153.170:/home/biren/nfsFile/vexpress-v2p-ca9.dtb;\
  5. setenv bootargs 'root=/dev/ram rw console=ttyAMA0 init=/linuxrc';\
  6. bootz 0x62008000 0x62508000 0x62a08000;"
  7. #define CONFIG_IPADDR 192.168.153.160
  8. #define CONFIG_NETMASK 255.255.255.0
  9. #define CONFIG_SERVERIP 192.168.153.170

2、其它与“方法六”一样

==================================

问题说明

问题一:

end Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block

可能原因:

  • root=/dev/ram(mmcblk0, sda, vda等)设置出错
  • 编译内核时参数设置错误
  • 启动时缺乏dtb参数等
  1. ......
  2. VFS: Cannot open root device "(null)" or unknown-block(0,0): error -6
  3. Please append a correct "root=" boot option; here are the available partitions:
  4. 1f00 131072 mtdblock0
  5. (driver?)
  6. 1f01 32768 mtdblock1
  7. (driver?)
  8. Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
  9. CPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.19.16 #1
  10. Hardware name: ARM-Versatile Express
  11. [<80110dbc>] (unwind_backtrace) from [<8010c9f8>] (show_stack+0x10/0x14)
  12. [<8010c9f8>] (show_stack) from [<806a8a80>] (dump_stack+0x88/0x9c)
  13. [<806a8a80>] (dump_stack) from [<80120bf8>] (panic+0xf0/0x25c)
  14. [<80120bf8>] (panic) from [<809015e8>] (mount_block_root+0x210/0x2bc)
  15. [<809015e8>] (mount_block_root) from [<809017b4>] (mount_root+0x120/0x13c)
  16. [<809017b4>] (mount_root) from [<80901920>] (prepare_namespace+0x150/0x198)
  17. [<80901920>] (prepare_namespace) from [<80901190>] (kernel_init_freeable+0x354/0x364)
  18. [<80901190>] (kernel_init_freeable) from [<806bcee0>] (kernel_init+0x8/0x110)
  19. [<806bcee0>] (kernel_init) from [<801010e8>] (ret_from_fork+0x14/0x2c)
  20. Exception stack(0x9f48ffb0 to 0x9f48fff8)
  21. ffa0: 00000000 00000000 00000000 00000000
  22. ffc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
  23. ffe0: 00000000 00000000 00000000 00000000 00000013 00000000
  24. ---[ end Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0) ]---

问题二:

/etc/qemu-ifup failed with status 256

  1. biren@ubuntu:~/buildroot-2019.11-rc1/output/images$ sudo /usr/local/qemu6.2.0/bin/qemu-system-arm -M vexpress-a9 -m 512M -kernel /home/biren/u-boot-2019.10/u-boot -sd rootfs.ext3 -nographic -net nic -net tap,ifname=tap0
  2. WARNING: Image format was not specified for 'rootfs.ext3' and probing guessed raw.
  3. Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
  4. Specify the 'raw' format explicitly to remove the restrictions.
  5. qemu-system-arm: -net tap,ifname=tap0: network script /usr/local/qemu6.2.0/bin/../etc/qemu-ifup failed with status 256

原因:是qemu-system-arm启动时会去查找/etc/qemu-ifup和/etc/qemu-ifdown并执行,这两个文件缺失或配置错误导致。

解决:

加上script=no,downscript=no参数即可

sudo /usr/local/qemu6.2.0/bin/qemu-system-arm -M vexpress-a9 -m 512M -kernel /home/biren/u-boot-2019.10/u-boot -sd rootfs.ext3 -nographic -net nic -net tap,ifname=tap0,script=no,downscript=no

问题三:

sudo: qemu-system-arm: command not found

  1. biren@ubuntu:~/buildroot-2019.11-rc1/output/images$ sudo qemu-system-arm -M vexpress-a9 -m 512M -kernel /home/biren/u-boot-2019.10/u-boot -sd rootfs.ext3 -nographic -net nic -net tap,ifname=tap0,script=no,downscript=no
  2. sudo: qemu-system-arm: command not found

原因:

是配置网络需要root权限,所以要用上sudo,而sudo是默认开启了- -with-secure-path选项

解决:

方法一:qemu-system-arm加上绝对路径

方法二:修改/etc/sudoers文件,将qemu-system-arm所在的目录加入Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"中

问题四:

qemu-system-arm: -net tap,ifname=tap0: could not configure /dev/net/tun (tap0): Operation not permitted

解决:在命令前加上sudo

问题五:

Unknown command 'nfs' - try 'help'

  1. => nfs 62008000 192.168.153.170:/home/biren/nfsFile/zImage
  2. Unknown command 'nfs' - try 'help'
  3. => help nfs
  4. Unknown command 'nfs' - try 'help' without arguments for list of all known commands

原因:

编译u-boot时没选上nfs

解决:

选上nfs选项后重新编译u-boot

biren@ubuntu:~/u-boot-2019.10$ make vexpress_ca9x4_defconfig

biren@ubuntu:~/u-boot-2019.10$ make menuconfig

位置:Command line interface --> Network commands

重新编译即可:

make CROSS_COMPILE=arm-linux-gnueabi- all

=====================================

其它说明

initrd(initial ramdisk)是在系统引导过程中挂载的一个临时根文件系统 ,用来支持两阶段的引导过程。initrd文件中包含了各种可执行程序和驱动程序,一般被用来临时的引导硬件到实际内核vmlinuz能够接管并继续引导的状态,也可以用来挂载实际的根文件系统,然后再将这个 initrd RAM 磁盘卸载,并释放内存。在很多嵌入式Linux 系统中,initrd 就是最终的根文件系统。

接口:tty0, ttyAMA0, ttySAC0, ttyS0

AMA:是Advanced Microcontroller Bus Architecture的缩写,是ARM的一种 UART设备(ARM AMBA PL011)

设置:mknod /dev/ttyAMA0 c 204 64

编译内核命令:

  • make zImage //编译生成zImage镜像文件
  • make dtbs //编译生成设备树镜像文件
  • make LOADADDR=0x60003000 uImage -j4 指定uImage的加载地址

ubuntu中重启网络命令:

  1. sudo service networking restart
  2. sudo service network-manager restart
  3. /etc/init.d/networking restart
  4. sudo ifdown -a && sudo ifup -a

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

闽ICP备14008679号

        
cppcmd=keepalive&