QEMU模擬ARM


https://blog.csdn.net/qq_24188351/article/details/77891353

https://blog.csdn.net/qq_24188351/article/details/77921653

 

https://www.jianshu.com/p/040459d94e2a

https://www.jianshu.com/p/cd7d9a753433

https://www.jianshu.com/p/ca95d8c771e8

 

https://www.right.com.cn/forum/thread-341079-1-1.html

 

https://www.cnblogs.com/schips/p/12345431.html

 https://www.cnblogs.com/schips/p/12347820.html

 

https://blog.csdn.net/FJDJFKDJFKDJFKD/article/details/82713588

 

https://blog.csdn.net/qq_24188351/article/details/77891353

https://blog.csdn.net/qq_24188351/article/details/77921653

QEMU 安裝

 

Build instructions

 

To download and build QEMU 4.2.0:

 

wget https://download.qemu.org/qemu-4.2.0.tar.xz
tar xJvf qemu-4.2.0.tar.xz
cd qemu-4.2.0
./configure
make

 

To download and build QEMU from git:

 

git clone https://git.qemu.org/git/qemu.git
cd qemu
git submodule init
git submodule update --recursive
./configure
make

 

sudo apt-get install build-essential pkg-config zlib1g-dev libglib2.0-0 libglib2.0-dev  libsdl2-dev libpixman-1-dev libfdt-dev autoconf automake libtool librbd-dev libaio-dev flex bison -y
wget https://download.qemu.org/qemu-4.2.0.tar.xz
tar xJvf qemu-4.2.0.tar.xz

cd qemu-4.2.0

.
/configure --prefix=/usr/local/qemu --target-list=arm-softmmu --audio-drv-list=

sudo make -j 8 && sudo make install

sudo ln -s /usr/local/qemu/bin/* /usr/local/bin/

# --target-list:選擇目標機器的架構。默認是將所有的架構都編譯,但為了更快的完成編譯,指定需要的架構即可。
# 或者執行
./configure --prefix=/usr/local/qemu --audio-drv-list=

# 測試
qemu-img -V
 
        

 

退出QEMU

輸入ctrl + a 后按 x 退出 QEMU

 

 

 

更新gcc

 

安裝之前要卸載掉老版本的gcc、g++

sudo apt-get remove gcc gcc-xx   #可能有多個版本,都要刪掉   

sudo apt-get remove g++
安裝gcc

sudo apt-get install gcc
安裝g++編譯器,可以通過命令

sudo apt-get install build-essential
 

執行完后,就完成了gcc,g++,make的安裝。

build-essential是一整套工具,gcc,libc等等

通過“g++ -v”可以查看g++是否安裝成功。

 

#安裝debug工具

sudo apt-get install gdb

 

推薦: https://www.linuxidc.com/Linux/2016-11/136840.htm

 

https://www.cnblogs.com/osbreak/p/10127059.html

 

 

qemu + gdb調試uboot 和 kernel

1.調試命令
我們之前qemu啟動uboot的命令為:

qemu-system-arm -M vexpress-a9 -m 256M -nographic -kernel u-boot

現在變為:

qemu-system-arm -M vexpress-a9 -m 256M -nographic -kernel u-boot -gdb tcp::1234 -S


-S指在啟動的時候釋放CPU。
qemu會在啟動的時候卡住。

2.進行連接
新打開一個終端,依次輸入:

gdb-multiarch u-boot
target remote : 1234

 

uboot中打開debug調試信息的方法

根目錄/include/common.h中

增加 

#define DEBUG

修改后為

#ifdef DEBUG
#define _DEBUG 1
#else
#define _DEBUG 0
#endif

 

UBOOT調試方法

 https://www.denx.de/wiki/DULG/DebuggingUBoot

https://wiki.st.com/stm32mpu/index.php?title=U-Boot_-_How_to_debug&oldid=46925

 

https://blog.csdn.net/aggresss/article/details/74834155

 

 

高版本編譯uboot報錯

include/linux/compiler-gcc.h:114:1: fatal error: linux/compiler-gcc7.h: No such file or directory
#include gcc_header(__GNUC__)
^~~~
compilation terminated.

 

修改include/linux/compiler-gcc.h   

(修改為系統gcc版本,include/linux/目錄下有compiler-gcc3.h、compiler-gcc4.h、compiler-gcc5.h)

#define __gcc_header(x) #x
#define _gcc_header(x) __gcc_header(linux/compiler-gcc##x.h)
#define gcc_header(x) _gcc_header(x)
//#include gcc_header(__GNUC__)
#include gcc_header(4)
 

 

 


調試u-boot-2015.10

 

 

0x60800000 reset地址

0x7ff7f000 After Relocation地址

log信息也會顯示該地址

 

Relocation Offset is: 1f751000
Relocating to 7ff51000, new gd at 7feb0f00, sp at 7feb0ee0

 

 

Reserving 450k for U-Boot at: 7ff7f000

 

"struct global_data" 的地址保存在r9中
print/x ((gd_t *)$r9)->relocaddr

 


注意 改地址會根據優化級別不有而有區別

add-symbol-file u-boot 0x7ff51000

 

修改  /Makefile文件

位置1

ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
KBUILD_CFLAGS += -O0
else
KBUILD_CFLAGS += -O0
endif

 

位置2  (該位置需要測試   最好不要修改  只修改位置1)

HOSTCC = cc
HOSTCXX = c++
HOSTCFLAGS = -Wall -Wstrict-prototypes -O1 -fomit-frame-pointer
HOSTCXXFLAGS = -O1



 

/home/user/Project/u-boot-2015.10/arch/arm/lib/relocate.S

ENTRY(relocate_code)
ldr r1, =__image_copy_start /* r1 <- SRC &__image_copy_start */
subs r4, r0, r1 /* r4 <- relocation offset */
beq relocate_done /* skip relocation */
ldr r2, =__image_copy_end /* r2 <- SRC &__image_copy_end */

copy_loop:
ldmia r1!, {r10-r11} /* copy from source address [r1] */
stmia r0!, {r10-r11} /* copy to target address [r0] */
cmp r1, r2 /* until source end address [r2] */
blo copy_loop

/*
* fix .rel.dyn relocations
*/
ldr r2, =__rel_dyn_start /* r2 <- SRC &__rel_dyn_start */
ldr r3, =__rel_dyn_end /* r3 <- SRC &__rel_dyn_end */
fixloop:
ldmia r2!, {r0-r1} /* (r0,r1) <- (SRC location,fixup) */
and r1, r1, #0xff
cmp r1, #23 /* relative fixup? */
bne fixnext

/* relative fix: increase location by offset */
add r0, r0, r4
ldr r1, [r0]
add r1, r1, r4
str r1, [r0]
fixnext:
cmp r2, r3
blo fixloop

relocate_done:

 

 


http://www.denx.de/wiki/view/DULG/DebuggingUBoot

執行命令 

b relocate_code //在內部調試 獲取relocate addr 0x7ff7f000
 

> print/x ((gd_t *)$r9)->relocaddr
$1 = 0x7ff51000



b relocate_done

 

> print/x ((gd_t *)$r9)->relocaddr
$2 = 0x7ff51000



add-symbol-file u-boot 0x7ff7f000
#根據上面地址獲取

add-symbol-file u-boot 0x7ff51000

b board_init_r
b efi_runtime_relocate b bootp_request

 






Todo

https://blog.csdn.net/BakerTheGreat/article/details/101146657

https://blog.csdn.net/chungle2011/article/details/103696431

 

 

 

 

https://www.cnblogs.com/microxiami/p/11093241.html

5. 安裝TFTP服務器

創建TFTP服務器,用來給Qemu模擬開發板啟動uImage時,下載uImage到內存中。

1) 安裝Linux主機Host的TFTP服務器工具:

# sudo apt install tftp-hpa tftpd-hpa xinetd

2) 修改配置文件,設置TFTP服務器目錄:

# sudo vim /etc/default/tftpd-hpa ...... TFTP_DIRECTORY="/home/mcy/tftpboot" ......

3) Linux主機上創建tftp目錄:

# mkdir /home/mcy/tftpboot # chmod 777 /home/mcy/tftpboot

4) 重啟tftp服務:

# sudo /etc/init.d/tftpd-hpa restart



setenv命令可以修改主機和目標機的ip地址。
#setenv ipaddr 10.0.2.16
#setenv serverip 10.0.2.15  //該命令可設置主機ip,該命令只是把設置保存到RAM中,如果重啟的話設置會重新回到原來的設置。
這時我們用saveenv命令把設置保存到flash中。
#saveenv
 
配置好各個參數后,我們在uboot命令窗口中使用tftp命令把內核,文件系統拷貝到RAM中。
#tftp 30008000 zImage  //在主機 /tftpboot目錄中的zImage文件下載到目標板內存的30008000地址中。

https://www.qemu.org/2018/05/31/nic-parameter/

http://wiki.sylixos.com/index.php/Linux%E7%8E%AF%E5%A2%83%E5%BC%80%E5%8F%91%E6%8C%87%E5%8D%97#.E7.BC.96.E8.AF.91_qemu-mini2440
https://blog.51cto.com/lnsane784/1958356



qemu 支持多種網絡鏈接方式,其中最常用的就是橋接(bridge)。 這需要依賴內核的 tun/tap 模塊的支持。
  • 輸入如下命令安裝必要的工具包:
sudo apt-get install uml-utilities
sudo apt-get install bridge-utils
  • 輸入如下命令查看 /dev/net/tun 文件:

  modinfo tap   ## 查詢是否有tap模塊

ls -l /dev/net/tun  ## 查詢內核是否編譯進tun
crw-rw-rwT 1 root root 10, 200 Apr 15 02:23 /dev/net/tun
如果該文件存在,這表明內核已經支持開啟了 tun 支持,在 ubuntu-16.04/18.04 中,這個功能默認已經開啟。
如果該文件不存在,則需要加載 tun 模塊,並創建 /dev/net/tun 文件。

sudo gvim /etc/network/interfaces
auto lo
iface lo inet loopback

#auto enp0s3

auto br0
iface br0 inet dhcp
bridge_ports enp0s3
bridge_stp on
bridge_fd 0
bridge_maxwait 0
 

 

 

sudo gvim /etc/qemu-ifup 

#!/bin/sh

echo sudo ifconfig $1 0.0.0.0 promisc up
sudo ifconfig $1 0.0.0.0 promisc up

echo sudo brctl addif br0 $1
sudo brctl addif br0 $1

echo brctl show
sudo brctl show

#sudo ifconfig br0 192.168.56.123

 

sudo gvim /etc/qemu-ifdown    #新版QEMU 的/qemu-ifdown內容為空即可  如下

#!/bin/sh

#echo sudo brctl delif br0 $1
#sudo brctl delif br0 $1
 
#echo brctl show
#brctl show

 

https://wiki.qemu.org/Documentation/Networking#Network_Basics

Setting up taps on Linux

For Linux with iproute2 and tap/tun support, this can be configured as below, and assumes the reader has experience using iproute2 (at least ip-addr and ip-link). Take note of the host's physical devices' configuration, as the bridge created will become the new endpoint for the physical device. Note that this WILL cause the host's networking on that physical device to go out, possibly requiring a reboot for remote systems!

 # modprobe tun tap                  # unnecessary if tun/tap is built-in
 # ip link add br0 type bridge
 # ip tuntap add dev tap0 mode tap
 # ip link set dev tap0 master br0   # set br0 as the target bridge for tap0
 # ip link set dev eth0 master br0   # set br0 as the target bridge for eth0
 # ip link set dev br0 up

At this point, the bridge works, but is not usable as it does not have an IP address. For reassigning the physical device's addresses for the bridge to be usable:

 # ip address delete $PREFIX dev eth0
 # ip address add $PREFIX dev br0
 # ip route add default via $ROUTE dev br0

This can be automated with a shell script to setup tap networking on remote hosts; as mentioned above, connection will be lost upon setting the physical device's master to a bridge.

Please note that the newly-created tap device's link may need to be set to UP via ip-link after a virtual machine has been started. Furthermore, as a bridge device basically acts as the new endpoint for a physical device, most normal networking commands, such as a DHCP client or packet sniffer, must be ran on the bridge instead of the physical device. Creating multiple bridges per interface is known (anecdotally) to be problematic; instead, create a tap for each virtual machine using a single bridge for each physical device to be used.

 

https://www.cnblogs.com/cxchanpin/p/6795616.html

(1)linux要工作在網橋模式,所以必須安裝:bridge-utils和tunctl。它們提供所需的brctl、tunctl命令行工具

 

(2)查看tun模塊是否載入,例如以下:

[root@server3 ~]# lsmod | grep tun
tun  16577 2 vhost_net

假設tun模塊沒有載入,則執行“modprobe tun”命令來載入就可以;

假設已經將tun編譯到內核(可查看內核config文件  /boot/config-5.3.0-28-generic  里是否有“CONFIG_TUN=y” 選項),則不須要載入了;而假設內核全然沒有配置TUN模塊,則須要又一次編譯內核才行了。 

(3)檢查/dev/net/tun的權限,須要讓當前用戶擁有可讀可寫的權限。

[root@server3 ~]# ll /dev/net/tun
crw-rw-rw- . 1 root root 10, 200 4月 23 10:35 /dev/net/tun



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM