当前位置: 首页 > news >正文

WSL2中安装的ubuntu搭建tftp服务器uboot通过tftp下载

Windows中安装wsl2,wsl2里安装ubuntu。

1. Wsl启动后

1)Windows下ip

ipconfig
以太网适配器 vEthernet (WSL (Hyper-V firewall)):

连接特定的 DNS 后缀 . . . . . . . :
IPv4 地址 . . . . . . . . . . . . : 172.19.32.1
子网掩码 . . . . . . . . . . . . : 255.255.240.0
默认网关. . . . . . . . . . . . . :
该虚拟网卡在网络邻居里是看不到的。
ping 172.19.32.1

正在 Ping 172.19.32.1 具有 32 字节的数据:
来自 172.19.32.1 的回复: 字节=32 时间<1ms TTL=128
来自 172.19.32.1 的回复: 字节=32 时间<1ms TTL=128
来自 172.19.32.1 的回复: 字节=32 时间<1ms TTL=128
来自 172.19.32.1 的回复: 字节=32 时间<1ms TTL=128

2)Ubuntu下ip

ip addr show eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.19.37.221 netmask 255.255.240.0 broadcast 172.19.47.255
RX packets 56 bytes 10337 (10.3 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 18 bytes 1256 (1.2 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

ping 172.19.32.1
PING 172.19.32.1 (172.19.32.1) 56(84) bytes of data.
64 bytes from 172.19.32.1: icmp_seq=1 ttl=128 time=0.330 ms
64 bytes from 172.19.32.1: icmp_seq=2 ttl=128 time=0.298 ms
64 bytes from 172.19.32.1: icmp_seq=3 ttl=128 time=0.383 ms
64 bytes from 172.19.32.1: icmp_seq=4 ttl=128 time=0.351 ms
64 bytes from 172.19.32.1: icmp_seq=5 ttl=128 time=0.286 ms

2. 分析

1)把WSL的虚拟交换机桥接到物理网卡上

WSL的虚拟交换机连接到物理网卡
在windows搜索框中搜索“Hyper-V 管理器 ”,点击虚拟交换机,把内部网络改为外部网络。
在这里插入图片描述

在这里插入图片描述

2)ubuntu设置静态IP
#!/bin/bash
# 清空现有 IP 配置
sudo ip addr flush dev eth0
# 设置静态 IP 和子网掩码
sudo ip addr add 192.168.32.100/24 dev eth0
# 设置默认网关(通常为路由器 IP)
sudo ip route add default via 192.168.32.1

保存并退出(Ctrl+OEnterCtrl+X)。

步骤 2:赋予脚本执行权限
sudo chmod +x /usr/local/bin/set_static_ip.sh
步骤 3:设置脚本开机自动运行

编辑 ~/.bashrc 或全局配置文件 /etc/profile

echo "/usr/local/bin/set_static_ip.sh" >> ~/.bashrc
步骤 4:立即执行脚本
source ~/.bashrc
4. 验证静态 IP
ip addr show eth0 | grep "inet "
# 应输出类似:inet 192.168.32.100/24 scope global eth0

以下脚本待测试

# 创建脚本
sudo tee /usr/local/bin/set_static_ip.sh << 'EOF'
#!/bin/bash
sudo ip addr flush dev eth0
sudo ip addr add 192.168.32.100/24 dev eth0
sudo ip route add default via 192.168.32.1
EOF# 设置权限并添加到启动项
sudo chmod +x /usr/local/bin/set_static_ip.sh
echo "/usr/local/bin/set_static_ip.sh" >> ~/.bashrc# 立即生效
source ~/.bashrc

3. Ubuntu搭建tftp服务器

tftp 命令的作用和 nfs 命令一样,都是用于通过网络下载东西到 DRAM 中,只是 tftp 命令使用的 TFTP 协议, Ubuntu 主机作为 TFTP 服务器。因此需要在 Ubuntu 上搭建 TFTP 服务器,需要安装 tftp-hpa 和 tftpd-hpa,命令如下

sudo apt-get install tftp-hpa tftpd-hpa 
sudo apt-get install xinetd 

和 NFS 一样, TFTP 也需要一个文件夹来存放文件,在用户目录下新建一个目录,/home/xxx/tftp ,xxx为用户名,命令如下

mkdir tftp 
chmod 777 tftp 

新建文件夹/etc/xinetd.d,

sudo mkdir /etc/xinetd.d

新建文件/etc/xinetd.d/tftp

sudo vi /etc/xinetd.d/tftp
server tftp
{
socket_type = dgram                                                                                                     
protocol = udp
wait = yes                                                                                                              
user = root                                                                                                             
server = /usr/sbin/in.tftpd
server_args = -s /home/xxx/tftp/
disable = no
per_source = 11
cps = 100 2                                                                                                             
flags = IPv4                                                                                                            
} 

:wq保存退出,:q仅退出
完了以后启动 tftp 服务,命令如下:

sudo service tftpd-hpa start 

打开/etc/default/tftpd-hpa 文件 ,修改

sudo vi /etc/default/tftpd-hpa
# /etc/default/tftpd-hpa
TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/home/xxx/tftp"
TFTP_ADDRESS=":69"
TFTP_OPTIONS="-l -c -s"

TFTP_DIRECTORY 就是我们上面创建的 tftp 文件夹目录,以后我们就将所有需要通过TFTP 传输的文件都放到这个文件夹里面,并且要给予这些文件相应的权限。
最后输入如下命令, 重启 tftp 服务器:

sudo service tftpd-hpa restart 

tftp 服务器已经搭建好了,接下来就是使用了。将 zImage 镜像文件拷贝到 tftp文件夹中,并且给予 zImage 相应的权限,命令如下:

cp zImage /home/xxx/tftp/
cd /home/xxx/tftp/
chmod 777 zImage 

4. uboot设置ip

修改环境变量

setenv ipaddr 192.168.32.50 
setenv ethaddr 00:04:9f:04:d2:35 
setenv gatewayip 192.168.32.1 
setenv netmask 255.255.255.0 
setenv serverip 192.168.32.100 
saveenv 

查看环境变量

print

只能在 uboot 中 ping 其他的机器,其他机器不能 ping uboot,因为 uboot 没有对 ping命令做处理,如果用其他的机器 ping uboot 的话会失败!

=> ping 192.168.32.100
Using FEC1 device
host 192.168.32.100 is alive

5. Uboot中通过tftp下载镜像

tftp 命令不需要输入文件在 Ubuntu 中的完整路径,只需要输入文件名即可。比如我们现在将 tftp文件夹里面的 zImage 文件下载到开发板 DRAM 的 0X80800000 地址处,命令如下

tftp 80800000 zImage 

在这里插入图片描述

http://www.lryc.cn/news/530607.html

相关文章:

  • 机器学习优化算法:从梯度下降到Adam及其变种
  • [SAP ABAP] 静态断点的使用
  • 129.求根节点到叶节点数字之和(遍历思想)
  • NCCL、HCCL、通信、优化
  • unity学习21:Application类与文件存储的位置
  • 17 一个高并发的系统架构如何设计
  • Spring Boot 实例解析:配置文件
  • pytorch图神经网络处理图结构数据
  • 计算机网络一点事(23)
  • (9)下:学习与验证 linux 里的 epoll 对象里的 EPOLLIN、 EPOLLHUP 与 EPOLLRDHUP 的不同。小例子的实验
  • DeepSeek-R1模型1.5b、7b、8b、14b、32b、70b和671b有啥区别?
  • 一、html笔记
  • AI大模型开发原理篇-2:语言模型雏形之词袋模型
  • 基于微信小程序的实习记录系统设计与实现(LW+源码+讲解)
  • 【LLM】DeepSeek-R1-Distill-Qwen-7B部署和open webui
  • 【Elasticsearch】 Intervals Query
  • DeepSeek技术深度解析:从不同技术角度的全面探讨
  • Docker 部署 Starrocks 教程
  • 【LLM-agent】(task6)构建教程编写智能体
  • 29.Word:公司本财年的年度报告【13】
  • 14 2D矩形模块( rect.rs)
  • 【Unity3D】实现2D角色/怪物死亡消散粒子效果
  • Linux - 进程间通信(3)
  • 3、C#基于.net framework的应用开发实战编程 - 实现(三、三) - 编程手把手系列文章...
  • C++编程语言:抽象机制:泛型编程(Bjarne Stroustrup)
  • Python面试宝典13 | Python 变量作用域,从入门到精通
  • 基于最近邻数据进行分类
  • DeepSeek V3 vs R1:大模型技术路径的“瑞士军刀“与“手术刀“进化
  • 一、TensorFlow的建模流程
  • 指导初学者使用Anaconda运行GitHub上One - DM项目的步骤