首页 > 系统相关 >qemu使用uboot通过网络加载 linux kernel

qemu使用uboot通过网络加载 linux kernel

时间:2023-01-09 01:00:25浏览次数:44  
标签:kernel uboot sudo boot sh linux path qemu

qemu使用uboot通过网络加载 linux kernel。

参考文章:

https://www.zhaixue.cc/qemu/qemu-u-boot.html

https://zhuanlan.zhihu.com/p/547338158

 

  1 #!/bin/sh
  2  
  3  
  4 # 参考网址:
  5 # https://www.zhaixue.cc/qemu/qemu-u-boot.html
  6 # https://zhuanlan.zhihu.com/p/547338158
  7  
  8  
  9 # 1.
 10 # 修改busybox的Makefile的两个变量为:
 11 #   ARCH ?= arm
 12 #   CROSS_COMPILE ?= arm-linux-gnueabi-
 13 #
 14 cd u-boot-2022.10/
 15 vim Makefile
 16  
 17  
 18  
 19 # 2.
 20 # 编译, 如果出现错误, 安装: sudo apt install libssl-dev
 21 make vexpress_ca9x4_defconfig
 22 make -j 4
 23  
 24  
 25  
 26 # 3.
 27 # 使用qemu启动u-boot进行测试
 28 sh testiboot/test_uboot.sh
 29 #       test_uboot.sh内容
 30 #       #!/bin/sh
 31 #       # 测试u-boot
 32 #       # 上级路径
 33 #       top_path="/home/thinks2/ProgramProject/qemu_study/"
 34 #       src_path="tftpboot/u-boot"
 35 #       # 内核文件路径
 36 #       kernel_path=${top_path}${src_path}
 37 #       qemu-system-arm \
 38 #           -M vexpress-a9 \
 39 #           -m 512M \
 40 #           -kernel ${kernel_path} \
 41 #           -sd rootfs.ext3 \
 42 #           -nographic \
 43  
 44  
 45  
 46 # 4. 
 47 # 准备uImage内核, 指定加载地址, 编译uImage
 48 cd ..
 49 cd linux-4.19.269/
 50 make LOADADDR=0x60003000 uImage  -j 4
 51  
 52  
 53  
 54 # 5.
 55 # 细心的朋友发现, 目前加载u-boot的方法使用还是-kernel选项, 也就是把u-boot当做内核挂载的,
 56 # 而真实的系统启动, 不可能同时挂载两个内核启动(只能选择一个启动). 那么, 如何来模拟呢?
 57 #
 58 # u-boot实体机中, 我们常常采用tftp引导内核, 我们也可以在启动u-boot以后, 让u-boot通过tftp引导内核.
 59 # 需要做两件事情:
 60 #   1.搭建好tftp环境
 61 #   2.构建网桥, 让qemu可以访问, 从而让qemu和ubuntu之间可以通过该网桥来访问
 62  
 63 # 安装tftp和相关依赖, 设置好路径
 64 sudo apt install tftp-hpa tftpd-hpa xinetd uml-utilities bridge-utils
 65  
 66 # 设置tftp配置路径文件
 67 sudo vim /etc/default/tftpd-hpa
 68 # 将下面的内容复制近来
 69 TFTP_USERNAME="tftp"
 70 TFTP_DIRECTORY="/home/thinks2/ProgramProject/qemu_study/tftpboot" # 该路径即为tftp可以访问到的路径
 71 TFTP_ADDRESS="0.0.0.0:69"
 72 TFTP_OPTIONS="-l -c -s"
 73  
 74 # 配置完以后, 创建tftp目录, 给最高权限. 把内核, 设备树, 根文件系统,u-boot全部复制到这里
 75 cd ..
 76 mkdir tftpboot
 77 cd tftpboot
 78 cp ../u-boot-2022.10/u-boot ./
 79 cp ../linux-4.19.269/arch/arm/boot/uImage ./
 80 cp ../linux-4.19.269/arch/arm/boot/dts/vexpress-v2p-ca9.dtb ./
 81 # 重启tftp服务
 82 sudo /etc/init.d/tftpd-hpa restart
 83  
 84  
 85  
 86 # 6.
 87 # 修改网卡信息, 设置桥接
 88 ifconfig    # 查看网卡名
 89  
 90 # 修改/etc/netplan/01-network-manager-all.yaml的信息配置:
 91 sudo vim /etc/netplan/01-network-manager-all.yaml
 92 # t添加以下内容:
 93 ethernets:
 94   # 这里设置的是你还需要上网的网卡, ifconfig查看
 95   wlp0s20f3:
 96     dhcp4: yes
 97   # 这里设置的是br0桥接到的网卡
 98   enp0s31f6:
 99     dhcp4: yes
100 bridges:
101   #这里设置的是br0网桥        
102   br0:
103     dhcp4: yes
104     interfaces:
105       # 声明br0网桥接入的网卡是wlp0s20f3
106       - wlp0s20f3
107  
108 # 输入sudo netplan apply使其生效, 再输入ifconfig查看网卡信息
109 sudo netplan apply
110 ifconfig
111  
112  
113  
114 # 7.
115 # 修改/etc/qemu-ifdown信息配置
116 sudo vim /etc/qemu-ifdown
117 # 添加以下内容:
118 echo sudo brctl delif br0 $1
119 sudo brctl delif br0 $1
120  
121 echo sudo tunctl -d $1
122 sudo tunctl -d $1
123  
124 echo brctl show
125 brctl show
126  
127  
128  
129 # 8.
130 # 修改/etc/qemu-ifup信息配置
131 sudo vim /etc/qemu-ifup
132 # 添加以下内容:
133 echo sudo tunctl -u $(id -un) -t $1
134 sudo tunctl -u $(id -un) -t $1
135  
136 echo sudo ifconfig $1 0.0.0.0 promisc up
137 sudo ifconfig $1 0.0.0.0 promisc up
138  
139 echo sudo brctl addif br0 $1
140 sudo brctl addif br0 $1
141  
142 echo brctl show
143 brctl show
144  
145 # 这里设置的是网桥br0的地址
146 sudo ifconfig br0 192.168.2.13
147  
148  
149  
150 # 9.
151 # 修改test_uboot.sh, 添加:
152 #   -nic tap,ifname=tap0 \
153 #   -append "root=/dev/mmcblk0 rw console=ttyAMA0" \
154 vim test_uboot.sh
155 # 输入启动指令, 需要以sudo方式启动test_uboot.sh再启动
156 sudo sh test_uboot.sh
157 #       test_uboot.sh内容:
158 #       #!/bin/sh
159 #       # 测试u-boot
160 #       # 上级路径
161 #       top_path="/home/thinks2/ProgramProject/qemu_study/"
162 #       src_path="tftpboot/u-boot"
163 #       # 内核文件路径
164 #       kernel_path=${top_path}${src_path}
165 #       qemu-system-arm \
166 #           -M vexpress-a9 \
167 #           -m 512M \
168 #           -kernel ${kernel_path} \
169 #           -nic tap,ifname=tap0 \
170 #           -append "root=/dev/mmcblk0 rw console=ttyAMA0" \
171 #           -sd rootfs.ext3 \
172 #           -nographic \
173  
174  
175  
176 # 10.
177 # 此时敲击enter键, 进入u-boot交互模式, 输入以下内容:
178  
179 # 设置u-boot这边的地址(和br0同一网段即可)
180 setenv ipaddr   192.168.2.15
181 # 设置服务器地址(br0网桥的地址)
182 setenv serverip 192.168.2.13
183  
184 # 从tftpboot下载uImage
185 tftpboot 0x60003000 uImage
186 # 从tftpboot下载设备树
187 tftpboot 0x60500000 vexpress-v2p-ca9.dtb
188  
189 # 设置根文件系统挂载位置、权限、控制台设备
190 setenv bootargs "root=/dev/mmcblk0 rw console=ttyAMA0"
191  
192 # 设置启动地址
193 bootm 0x60003000 - 0x60500000
194  

最终的qemu的加载运行脚本test_uboot.sh:

 1 #!/bin/sh
 2 
 3 
 4 # 测试u-boot
 5 
 6 # 上级路径
 7 top_path="/home/thinks2/ProgramProject/qemu_study/"
 8 src_path="tftpboot/u-boot"
 9 
10 # 内核文件路径
11 kernel_path=${top_path}${src_path}
12 
13 qemu-system-arm \
14     -M vexpress-a9 \
15     -m 512M \
16     -kernel ${kernel_path} \
17     -nic tap,ifname=tap0 \
18     -append "root=/dev/mmcblk0 rw console=ttyAMA0" \
19     -sd rootfs.ext3 \
20     -nographic \

 

标签:kernel,uboot,sudo,boot,sh,linux,path,qemu
From: https://www.cnblogs.com/weitao-miao/p/17035857.html

相关文章

  • Linux反弹shell总结
    前言反弹shell(reverseshell)时控制端监听某TCP/UDP端口,受控端发起连接到控制端口,并将其命令行的输入输出转到控制端。我们不管在平时的CTF比赛中,还是在做渗透测试,反弹she......
  • 腾讯TencentOS Linux修改主机名hostname的方法
    腾讯TencentOSLinux修改主机名hostname的方法正常情况下修改Linux服务器的主机名是很容易的,只需要hostnamectlset-hostname命令就可以完成,但是我们要知其然知其所以然,L......
  • 腾讯云TencentOS Linux 服务器操作系统下使用hostnamectl设置大写主机名
    腾讯云TencentOSServer服务器操作系统下使用hostnamectl设置大写主机名。TencentOSServer镜像版本目前腾讯云上有3款TencentOSServer镜像供用户选择:镜像版本说明Tencen......
  • linux
    linux操作系统linux的文件结构在linux当中,所有的设备,所有的硬件,软件,网卡等。。。一切皆文件在Linux系统中,有几个目录是比较重要的,平时需要注意不要误删除或者随意更......
  • JDK8下载安装与配置环境变量(linux)
    一、前言基于Linux平台的MySQL安装文件有三个版本,分别是RPM软件、GenericBinaries软件包、源码包,具体介绍如下:①RPM软件包是一种Linux平台下的安装文件,通过相关命令可以......
  • MySQL8免安装版下载安装与配置(linux)
    一、前言基于Linux平台的MySQL安装文件有三个版本,分别是RPM软件、GenericBinaries软件包、源码包,具体介绍如下:①RPM软件包是一种Linux平台下的安装文件,通过相关命令可以......
  • 读书笔记_鸟哥的Linux私房菜_基础学习篇_第4版_第4章
    目录目录目录命令行模式下的命令执行命令格式示例基础命令date示例cal示例bc示例热键[TAB]示例[Ctrl]-c示例[Ctrl]-d示例命令求助--help示例man示例命令行模式下的命令......
  • Linux DNS服务Bind
    一、环境CentOS7.9BIND9.11.41.BINDhttps://www.isc.org/bind/BIND是BerkeleyInternetNameDomain的简称,是一个开源的DNS服务器。这是一个历史悠久的软件,它诞生......
  • Linux命令中 > 和 >> 的区别
    1、> 是清空并添加新内容,即重定向。2、>>是在文件内容后面追加新内容,即追加重定向。......
  • linux中的-和--参数
    linux中的-和--参数 在linux中,利用man查看某个命令的使用手册的时候,该命令参数通常会有-和--两种情况。通常而言,-说明参数是字符形式,后面接的是单字母命令。而--说明......