Linux嵌入式uboot使用tftp网络启动加载zImage、设备树

文章目录

    • 一、前言
    • 二、Linux U-boot 相关命令
      • (1)help 命令
      • (2)printenv 命令
      • (3)setenv 函数
      • (4)saveenv 函数
    • 三、tftp启动linux内核步骤
      • (1)进入u-boot模式
      • (2)ping通主机
      • (3)修改IP
      • (4)从网络启动


一、前言

先来讲一下为什么要使用tftp网络启动加载zImage和设备树。

在做驱动开发学习的时候,我们每次涉及到一个学习目标,比如学习led灯设备驱动开发,我们需要去设备树中添加节点,然后进行编译,编译好之后需要将我们的设备树和zImage文件上传到开发板,替换掉开发板上面相对应的文件,然后进行sudo reboot重新启动。

所以为了方便,可以使用Linux嵌入式uboot使用tftp网络启动加载zImage、设备树。也就是每次开启的时候,会从我们虚拟机tftpboot路径下去寻找我们的zImage和设备树启动,就不需要每次都下载然后重新reboot了。

如何搭建tftp服务器可以参考这篇文章:wpa_supplicant无线网络配置imx6ull以及搭建tftp服务器

在重启开发板的时候,随意按键即可进入u-boot模式。


二、Linux U-boot 相关命令

  • help: printenv命令描述/用法
  • printenv: 打印环境变量
  • setenv: 设置环境变量
  • saveenv: 将环境变量保存到持久存储

接下来我们详细讲解这几个命令。

(1)help 命令

可用于察看当前开发板所支持的命令。

[u-boot@igkboard]# help 
?         - alias for 'help'
base      - print or set address offset
bdinfo    - print Board Info structure
blkcache  - block cache diagnostics and control
bmode     - sd1|sd2|qspi1|normal|usb|sata|ecspi1:0|ecspi1:1|ecspi1:2|ecspi1:3|esdhc1|esdhc2|esdhc3|esdhc4
bmode - getprisec
bmp       - manipulate BMP image data
boot      - boot default, i.e., run 'bootcmd'
bootd     - boot default, i.e., run 'bootcmd'
bootefi   - Boots an EFI payload from memory
bootelf   - Boot from an ELF image in memory
bootm     - boot application image from memory
bootp     - boot image via network using BOOTP/TFTP protocol
bootvx    - Boot vxWorks from an ELF image
bootz     - boot Linux zImage image from memory
clocks    - display clocks
cmp       - memory compare
coninfo   - print console devices and information
cp        - memory copy
crc32     - checksum calculation
dcache    - enable or disable data cache
dhcp      - boot image via network using DHCP/TFTP protocol
dm        - Driver model low level access
echo      - echo args to console
editenv   - edit environment variable
env       - environment handling commands
erase     - erase FLASH memory
exit      - exit script
ext2load  - load binary file from a Ext2 filesystem
ext2ls    - list files in a directory (default /)
ext4load  - load binary file from a Ext4 filesystem
ext4ls    - list files in a directory (default /)
ext4size  - determine a file's size
ext4write - create a file in the root directory
false     - do nothing, unsuccessfully
fastboot  - run as a fastboot usb or udp device
fatinfo   - print information about filesystem
fatload   - load binary file from a dos filesystem
fatls     - list files in a directory (default /)
fatmkdir  - create a directory
fatrm     - delete a file
fatsize   - determine a file's size
fatwrite  - write file into a dos filesystem
fdt       - flattened device tree utility commands
flinfo    - print FLASH memory information
fstype    - Look up a filesystem type
fstypes   - List supported filesystem types
fuse      - Fuse sub-system
go        - start application at address 'addr'
gpio      - query and control gpio pins
gpt       - GUID Partition Table
help      - print command description/usage
i2c       - I2C sub-system
icache    - enable or disable instruction cache
iminfo    - print header information for application image
imxtract  - extract a part of a multi-image
itest     - return true/false on integer compare
lcdputs   - print string on video framebuffer
ln        - Create a symbolic link
load      - load binary file from a filesystem
loadb     - load binary file over serial line (kermit mode)
loads     - load S-Record file over serial line
loadx     - load binary file over serial line (xmodem mode)
loady     - load binary file over serial line (ymodem mode)
loop      - infinite loop on address range
ls        - list files in a directory (default /)
md        - memory display
mm        - memory modify (auto-incrementing address)
mmc       - MMC sub system
mmcinfo   - display MMC info
mtest     - simple RAM read/write test
mw        - memory write (fill)
net       - NET sub-system
nfs       - boot image via network using NFS protocol
nm        - memory modify (constant address)
panic     - Panic with optional message
ping      - send ICMP ECHO_REQUEST to network host
pinmux    - show pin-controller muxing
printenv  - print environment variables
protect   - enable or disable FLASH write protection
qspihdr   - Q(F)SPI Boot Config sub-system
random    - fill memory with random pattern
read      - Load binary data from a partition
reset     - Perform RESET of the CPU
run       - run commands in an environment variable
save      - save file to a filesystem
saveenv   - save environment variables to persistent storage
setcurs   - set cursor position within screen
setenv    - set environment variables
setexpr   - set environment variable as the result of eval expression
sf        - SPI flash sub-system
showvar   - print local hushshell variables
size      - determine a file's size
sleep     - delay execution for some time
source    - run script from memory
test      - minimal test like /bin/sh
tftpboot  - boot image via network using TFTP protocol
true      - do nothing, successfully
ums       - Use the UMS [USB Mass Storage]
usb       - USB sub-system
usbboot   - boot from USB device
version   - print monitor, compiler and linker version
videolink - list and select video link

(2)printenv 命令

printenv 命令查看环境变量也可以使用缩写:print

[u-boot@igkboard]# printenv    
author=weihuihong
baudrate=115200
bbl=tftp ${loadaddr} u-boot-igkboard.imx && mmc dev ${mmcdev} 1 && mmc write ${loadaddr} 2 0x500
bdtb=tftp $fdt_addr $fdt_file && fatwrite mmc 1:1 $fdt_addr $fdt_file $filesize
bker=tftp $loadaddr $image&& fatwrite mmc 1:1 $loadaddr $image $filesize
board_name=EVK
board_rev=14X14
bootcmd=run mmcbootdto
bootdelay=3
bsys=run bdtb && run bker
console=ttymxc0
dtbo_addr=0x83010000
dtbo_dir=overlays
emmc_ack=1
emmc_dev=1
env_conf=config.txt
eth1addr=be:19:97:40:6d:ff
ethact=ethernet@20b4000
ethaddr=3e:0a:c4:12:ae:e2
ethprime=eth1
fastboot_dev=mmc1
fdt_addr=0x83000000
fdt_file=igkboard.dtb
fdt_size=0x10000
fdtcontroladdr=9de744c0
image=zImage
ipaddr=192.168.137.213
loadaddr=0x80800000
loadenvconf=fatload mmc ${mmcdev}:${mmcpart} ${loadaddr} ${env_conf};env import -t ${loadaddr} ${filesize}
loadfdt=fatload mmc ${mmcdev}:${mmcpart} ${fdt_addr} ${fdt_file}
loadimage=fatload mmc ${mmcdev}:${mmcpart} ${loadaddr} ${image}
mmc_no=1
mmcargs=setenv bootargs console=${console},${baudrate} root=/dev/mmcblk${mmc_no}p2 rootwait rw net.ifnames=0
mmcboot=echo Booting from mmc ...; mmc dev ${mmcdev}; run mmcargs; run loadenvconf;run loadimage; run loadfdt; bootz ${loadaddr} - ${fdt_addr}
mmcbootdto=echo Booting from mmc with overlay...; mmc dev ${mmcdev}; run mmcargs; run loadenvconf; run loadimage; run loadfdt; if env exists dtoverlay_lcd && test ${dtoverlay_lcd} = 1 -o ${dtoverlay_lcd} = yes ; then setenv dtbo_file lcd.dtbo; echo Applying DT overlay ==> ${dtbo_file}; fatload mmc ${mmcdev}:${mmcpart} ${dtbo_addr} ${dtbo_dir}/${dtbo_file}; fdt addr ${fdt_addr}; fdt resize ${fdt_size}; fdt apply ${dtbo_addr}; fi; if env exists dtoverlay_cam && test ${dtoverlay_cam} = 1 -o ${dtoverlay_cam} = yes ; then setenv dtbo_file cam.dtbo; echo Applying DT overlay ==> ${dtbo_file}; fatload mmc ${mmcdev}:${mmcpart} ${dtbo_addr} ${dtbo_dir}/${dtbo_file}; fdt addr ${fdt_addr}; fdt resize ${fdt_size}; fdt apply ${dtbo_addr}; fi; if env exists dtoverlay_i2c1 && test ${dtoverlay_i2c1} = 1 -o ${dtoverlay_i2c1} = yes ; then setenv dtbo_file i2c1.dtbo; echo Applying DT overlay ==> ${dtbo_file}; fatload mmc ${mmcdev}:${mmcpart} ${dtbo_addr} ${dtbo_dir}/${dtbo_file}; fdt addr ${fdt_addr}; fdt resize ${fdt_size}; fdt apply ${dtbo_addr}; fi; if env exists dtoverlay_spi1 && test ${dtoverlay_spi1} = 1 -o ${dtoverlay_spi1} = yes ; then setenv dtbo_file spi1.dtbo; echo Applying DT overlay ==> ${dtbo_file}; fatload mmc ${mmcdev}:${mmcpart} ${dtbo_addr} ${dtbo_dir}/${dtbo_file}; fdt addr ${fdt_addr}; fdt resize ${fdt_size}; fdt apply ${dtbo_addr}; fi; if env exists dtoverlay_uart; then for i in ${dtoverlay_uart}; do setenv dtbo_file uart$i.dtbo; echo Applying DT overlay ==> ${dtbo_file}; fatload mmc ${mmcdev}:${mmcpart} ${dtbo_addr} ${dtbo_dir}/${dtbo_file}; fdt addr ${fdt_addr}; fdt resize ${fdt_size}; fdt apply ${dtbo_addr};  done;fi; if env exists dtoverlay_can; then for i in ${dtoverlay_can}; do setenv dtbo_file can$i.dtbo; echo Applying DT overlay ==> ${dtbo_file}; fatload mmc ${mmcdev}:${mmcpart} ${dtbo_addr} ${dtbo_dir}/${dtbo_file}; fdt addr ${fdt_addr}; fdt resize ${fdt_size}; fdt apply ${dtbo_addr};  done;fi; if env exists dtoverlay_pwm; then for i in ${dtoverlay_pwm}; do setenv dtbo_file pwm$i.dtbo; echo Applying DT overlay ==> ${dtbo_file}; fatload mmc ${mmcdev}:${mmcpart} ${dtbo_addr} ${dtbo_dir}/${dtbo_file}; fdt addr ${fdt_addr}; fdt resize ${fdt_size}; fdt apply ${dtbo_addr};  done;fi; if env exists dtoverlay_extra; then for f in ${dtoverlay_extra}; do setenv dtbo_file $f.dtbo; echo Applying DT overlay ==> ${dtbo_file}; fatload mmc ${mmcdev}:${mmcpart} ${dtbo_addr} ${dtbo_dir}/${dtbo_file}; fdt addr ${fdt_addr}; fdt resize ${fdt_size}; fdt apply ${dtbo_addr};  done;fi; bootz ${loadaddr} - ${fdt_addr}
mmcdev=1
mmcpart=1
netboot=echo Booting from net ...; tftp $loadaddr $image; tftp $fdt_addr ${fdt_file};run mmcargs; bootz ${loadaddr} - ${fdt_addr}
serial#=303769d759a6d668
serverip=192.168.137.91
splashimage=0x8c000000
tee=no
upmode=fastboot 0

Environment size: 4012/8188 bytes

里面的内容也是学长之前写好的或者添加的,直接拿来用就可。

也可以查看某一个环境变量的值:

[u-boot@igkboard]# printenv serverip
serverip=192.168.137.91

(3)setenv 函数

setenv name value 添加/修改环境变量:

[u-boot@igkboard]# setenv serverip 192.168.137.99

修改后:
在这里插入图片描述

setenv name 删除环境变量:

[u-boot@igkboard]# setenv serverip

修改后:
在这里插入图片描述

(4)saveenv 函数

保存环境变量,将当前定义的所有变量及其值存入flash中。

[u-boot@igkboard]# saveenv
Saving Environment to MMC... Writing to MMC(1)... OK

当设置完环境变量之后,如果执行了saveenv的话,则下次重新运行的时候环境变量则会被保存为上次保存的值;如果不保存,只会在设置好时还没重启之前生效,重启之后设置值会恢复成原来的值。


三、tftp启动linux内核步骤

(1)进入u-boot模式

开始启动的时候在倒数三秒时间按随机键进入到u-boot模式:

Hit any key to stop autoboot:  0 
[u-boot@igkboard]# 

(2)ping通主机

查看是否ping通tftp所在服务器主机:

[u-boot@igkboard]# ping 192.168.137.91
Using ethernet@20b4000 device
host 192.168.137.91 is alive

提示 xxx alive说明成功,可以ping通。

(3)修改IP

需要修改环境变量中的主机IP和服务器IP,注意,一般服务器IP都是不会变的,主机IP会变,但是主机IP需要在一个网段内就可,不需要每次都去修改的。

[u-boot@igkboard]# setenv ipaddr 192.168.137.99
[u-boot@igkboard]# setenv serverip 192.168.137.91
[u-boot@igkboard]# print ipaddr
ipaddr=192.168.137.99
[u-boot@igkboard]# print serverip
serverip=192.168.137.91

然后我们需要保存一下saveenv

(4)从网络启动

执行命令run netboot

[u-boot@igkboard]# run netboot
Booting from net ...
Using ethernet@20b4000 device
TFTP from server 192.168.137.91; our IP address is 192.168.137.99
Filename 'zImage'.
Load address: 0x80800000
Loading: #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         ############################################################
         1.4 MiB/s
done
Bytes transferred = 9466232 (907178 hex)
Using ethernet@20b4000 device
TFTP from server 192.168.137.91; our IP address is 192.168.137.99
Filename 'igkboard.dtb'.
Load address: 0x83000000
Loading: ####
         1.1 MiB/s
done

说明成功了。

具体实现的代码在配置中写了,但是还不是很清楚,后面学到再补充。


本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/13917.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

vue:生成二维码 qrcode、vue-qr(二维码中间可带logo)

一、方法一 qrcode qrcode - npm 1.1、安装 yarn add qrcode 1.2、页面引入 import QRCode from qrcode; 1.3、方法里边使用 getQRCodeUrl(){ QRCode.toDataURL(hello world,{color: {dark:"#010599FF",light:"#FFBF60FF"}}).then((url) > {// 获…

基于Html+Css的图片展示25

准备项目 项目开发工具 Visual Studio Code 1.44.2 版本: 1.44.2 提交: ff915844119ce9485abfe8aa9076ec76b5300ddd 日期: 2020-04-16T16:36:23.138Z Electron: 7.1.11 Chrome: 78.0.3904.130 Node.js: 12.8.1 V8: 7.8.279.23-electron.0 OS: Windows_NT x64 10.0.19044 项目…

Linux+云服务器

目录 前言 一、Linux介绍 二、Linux 环境搭建 2.1 云服务器 2.2 XShell 终端 三、Linux 常用命令 3.1操作目录的命令 3.1.1 ls 【list的缩写】 双击某个目录 3.1.2 pwd 【print working directory的缩写】打印当前所处地址 3.1.3 cd 【change directory的缩写】切…

yolov5训练自己的目标检测模型

yolov5训练自己的目标检测模型 1.克隆项目并配置环境 1.1克隆项目 进入GitHub下载yolov5源码 点此进入 选择分支v5.0,并下载源码 anaconda激活相应环境 activate pytorch进入项目存放的地址 E: cd yolov5-master1.2 yolov5项目结构 ├── data:主…

Java版本工程管理系统软件源码 自主研发,工程行业适用

Java版工程项目管理系统 Spring CloudSpring BootMybatisVueElementUI前后端分离 功能清单如下: 首页 工作台:待办工作、消息通知、预警信息,点击可进入相应的列表 项目进度图表:选择(总体或单个)项目显示…

Zimbra 远程代码执行漏洞(CVE-2019-9670)漏洞分析

Zimbra 远程代码执行漏洞(CVE-2019-9670)漏洞分析 漏洞简介 Zimbra是著名的开源系统,提供了一套开源协同办公套件包括WebMail,日历,通信录,Web文档管理和创作。一体化地提供了邮件收发、文件共享、协同办公、即时聊天等一系列解决…

集合专题·拔高·壹

文章目录 1 Collection单列集合、Map双列集合1.1 Collection单列集合1.1.1 Collection单列集合及其实现类1.1.1.1 list集合与Array数组1.1.1.1.1 ArrayList1.1.1.1.2 LinekdList1.1.1.1.2 Vector1.1.1.1.2.1 ArrayList、Vector (线程安全)的区别是什么1.…

【elasticsearch部署】

安装elasticsearch 1.部署单点es1.1.创建网络1.2.加载镜像1.3.运行 2.部署kibana2.1.部署2.2.DevTools 3.安装IK分词器3.1.在线安装ik插件(较慢)3.2.离线安装ik插件(推荐)1)查看数据卷目录2)解压缩分词器安…

基于web的电动车租赁管理系统C#+asp.net+sqlserver

具体功能如下:个人信息管理:实现登陆后对个人信息进行修改和查看的功能。 修改登录密码:实现登陆后对个人密码进行修改的功能。 申请租车订单:客户用户登陆后可以申请租车订单。同时可以查看租赁订单信息。 售后评价管理&#xff…

【PR 基础】设置上下黑白边的两种方法

方法1 点击 文件-》新建-》旧版标题 点击确定 点击矩形工具 利用矩形工具框选出上下黑白边 款选完成后点击关闭 将刚创建的字幕拖入轨道 可以修改其持续时长与视频时长保持一致 如果想要修改字幕可以双击来修改 比如可以将颜色改为黑色 方法2 点击号,再选择安全边…

C语言入门篇——函数篇

目录 1、什么是函数 2、函数的分类 2.1库函数 2.2自定义函数 3、函数的参数 3.1实际参数(实参) 3.2形式参数(形参) 4、函数的调用 4.1传值调用 4.2传址调用 5、函数的嵌套调用和链式访问 5.1嵌套调用 5.2链式访问 6、…

【C++】模板

目录 前言 1.函数模板 1.1使用 1.2实现逻辑 1.3实例化 1.4匹配规则 2.类模板 2.1使用 实例化 前言 🎗️照以前的想法,若我们想实现一个交换函数,需要这样写。 void swap(int& x, int& y) {int tmp x;x y;y tmp; }int …

自动驾驶方案及相关对标

华为: 2021年4月18日,在华为智能汽车解决方案BU新品发布会上,华为智能汽车解决方案BU总裁王军表示,华为要持续加大对汽车行业的投入,今年在研发上的投资将达到10亿美元,未来每年保持30%左右增长&#xff0…

[Netty] Mpsc Queue (十七)

JCTools 是适用于 JVM 并发开发的工具,主要提供了一些 JDK 确实的并发数据结构,例如非阻塞 Map、非阻塞 Queue 等。其中非阻塞队列可以分为四种类型,可以根据不同的场景选择使用。 Spsc 单生产者单消费者Mpsc 多生产者单消费者Spmc 单生产者…

【AI生产力工具】Midjourney:为创意人士提供创造性灵感和支持的工具

文章目录 一、Midjourney是什么?二、Midjourney的优势三、Midjourney的应用四、结语 在现代社会,创意和创新成为越来越重要的能力。然而,创意灵感的获取却不是一件容易的事情,这就需要我们使用一些辅助工具来帮助我们发现和实现创…

Docker容器---网络、容器操作

Docker容器---网络、容器操作 一、docker实现原理二、docker网路模式1、Host模式2、container模式3、none模式4、bridge模式 三、自定义网络1、查看网络模式列表2、查看容器信息3、指定分配IP地址4、自定义网络固定IP 四、暴露端口五、容器端口映射1、创建端口映射 六、资源控制…

达梦数据迁移问题罗列

目录 一、前言 二、问题罗列 一、前言 最近小编接触到国产的数据库达梦数据库,然后在用达梦数据迁移工具MySQL迁移至达梦的时候遇到了一系列的问题现在罗列一下在这里。目前关于国产的数据库达梦这些资料比较少,希望能够帮到有需要的同志们&#xff01…

零代码是什么?零代码平台适合谁用?

随着信息技术的发展,软件开发领域也不断发生变革,零代码(No-Code)开发模式越来越受到关注。 零代码到底是什么,能不能用通俗的话来说?这就来给大家讲一讲! 01 零代码为什么出现? 随…

Java基础——缓冲流

(1)缓冲流概述: 缓冲流也称高效流,或者高级流。(字节流可称原始流)作用:缓冲流自带缓冲区,可以提高原始字节流,字符流读写数据的性能。 (2)字节缓…

【工作思考】如何提升自己的编程能力?

文章目录 前言一、代码评审为什么要进行代码评审? 二、持续学习能力三、良好的编程习惯代码注释避免深度嵌套拒绝长函数重视自测文档编写重构你的代码学会思考 四、多接触开源项目五、总结 前言 在工作中,我们大部分的时间都是在阅读代码,阅…