uBoot
是一个裸机程序
用于启动Linux或者其他的系统, 最重要的是初始化DDR, 因为Linux运行在DDR中, 一般Linux镜像zImage(uImage)+设备树(.dtb)存放在SD, EMMC, NAND, SPIFLASH中
需要将系统镜像从外部的Flash拷贝到DDR中, 然后才能启动
uboot就是为了启动系统, 不知可以启动Linux, 也可以其他系统, Linux不止可以从uBoot启动, uboot是一个通用的bootloader, 支持多种架构
获取
-
官网, 支持的芯片不完善, 支持少, 某一款的芯片驱动不完善
- SOC厂商会下载某一个版本, 然后进行修改, 加上SOC以及驱动, 定制版的uBoot
- 开发板的厂商, 开发板会参考SOC厂商的板子, 开发板必然会和官方的不一样, 又会去修改
编译
在编译Uboot的时候要先编译
jiao@jiao-virtual-machine:~/linux/IMX6ULL/uboot/alientek_uboot$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- distclean
设置为arm架构, 设定使用的编译器, 进行第一次清理
jiao@jiao-virtual-machine:~/linux/IMX6ULL/uboot/alientek_uboot$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- mx6ull_14x14_ddr512_emmc_defconfig
HOSTCC scripts/basic/fixdep
HOSTCC scripts/kconfig/conf.o
SHIPPED scripts/kconfig/zconf.tab.c
SHIPPED scripts/kconfig/zconf.lex.c
SHIPPED scripts/kconfig/zconf.hash.c
HOSTCC scripts/kconfig/zconf.tab.o
HOSTLD scripts/kconfig/conf
#
# configuration written to .config
#
根据配置文件进行编译
直接接生成文件, 加上参数显示编译过程
jiao@jiao-virtual-machine:~/linux/IMX6ULL/uboot/alientek_uboot$ make V=1 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-
生成u-boot.bin文件, 向他添加头部信息, 在编译的时候会通过./tools/mkimage工具自动添加, 生成u-boot.imx文件也就是最终烧写的文件
注意
通过图形界面配置之后不要使用清除命令, 配置文件也会被删除
为了方便开发可以直接在makefile中更改变量
在之后带有调试作用的开发可以吧uboot烧写到SD卡
使用
在启动之前按任意键可以进入uboot界面
help: 进入帮助界面
U-Boot 2016.03-gee88051 (Nov 05 2021 - 17:59:02 +0800)
CPU: Freescale i.MX6ULL rev1.1 792 MHz (running at 396 MHz)
CPU: Industrial temperature grade (-40C to 105C) at 35C
Reset cause: POR
Board: I.MX6U ALPHA|MINI
I2C: ready
DRAM: 512 MiB
MMC: FSL_SDHC: 0, FSL_SDHC: 1
*** Warning - bad CRC, using default environment
In: serial
Out: serial
Err: serial
switch to partitions #0, OK
mmc1(part 0) is current device
Net: FEC1
Error: FEC1 address not set.
Normal Boot
Hit any key to stop autoboot: 0
-
第一行是Uboot版本以及编译时间
-
之后是CPU的格式以及运行的频率
-
然后是运行的温度以及现在的温度
-
复位模式POR
-
开发板名字
-
DRAM频率
-
两个MMC, 一个SD卡, 一个EMMC
-
没有找到定义的此变量, 使用默认环境变量
-
标准输出输入, 错误都是串口
-
切换到0分区
-
mmc0是当前的设备(命令mmc list)
=> mmc list FSL_SDHC: 0 FSL_SDHC: 1 (eMMC)
命令
帮助
查看帮助信息: help或者?
查看某一个命令: ?命令名
=> ? help help - print command description/usage Usage: help - print brief description of all commands help command ... - print detailed usage of 'command'
查询
bdinfo: 查看板子的信息
printenv: 查看当前的环境变量
设置
setenv: 设置环境变量
设置有空格的变量, 要用单引号括起来
保存
saveenv: 保存环境变量
=> setenv bootdelay 5 => saveenv
设置倒计时为五秒
自定义环境变量
setenv也可以用来设置, 也可以用来删除, 把值设置为空就是删除
内存命令
查看
用于显示命令值
=> ? md
md - memory display
Usage:
md [.b, .w, .l] address [# of objects]
.b字节, .w字, .l四个字节显示内存, address起始地址, of objects 内存的大小, 长度的大小是单位和大小一同决定
注: 命令中的数字是十六进制
=> md.b 0x80000000 20
80000000: ff ff ff ff ff ff ef ff ff ff ff ff ff ff ff ff ................
80000010: ff ff ff ff fe bf ff ff ff ff ff ff ff ff ff ff ................
=> md.b 0x80000000 14
80000000: ff ff ff ff ff ff ef ff ff ff ff ff ff ff ff ff ................
80000010: ff ff ff ff ....
=> md.w 0x80000000 14
80000000: ffff ffff ffff ffef ffff ffff ffff ffff ................
80000010: ffff ffff bffe ffff ffff ffff ffff ffff ................
80000020: ffff ffff fbbf ffff ........
=> md.l 0x80000000 14
80000000: ffffffff ffefffff ffffffff ffffffff ................
80000010: ffffffff ffffbffe ffffffff ffffffff ................
80000020: ffffffff fffffbbf ffffffff ffffffff ................
80000030: fffffff7 ffbbbfaf fff7ffff afffffff ................
80000040: ff5ffdff ffffbeff dfffffff ffffffbf .._.............
显示20个数据
设置
=> ? nm
nm - memory modify (constant address)
Usage:
nm [.b, .w, .l] address
输入地址回车进入修改模式, 输入q回车退出, 只修改一个地址
=> ? mm
mm - memory modify (auto-incrementing address)
Usage:
mm [.b, .w, .l] address
递增的修改
=> ? mw
mw - memory write (fill)
Usage:
mw [.b, .w, .l] address value [count]
用指定的值填充一段地址
=> ? cp
cp - memory copy
Usage:
cp [.b, .w, .l] source target count
赋值 原地址, 目标值, 长度
=> ? cmp
cmp - memory compare
Usage:
cmp [.b, .w, .l] addr1 addr2 count
用来比较两段地址
网络命令
网线插在ENET2上, 保证在同一个网段
使用setenv设置ip地址
setenv ipaddr 地址
设置mac地址
setenv ethaddr
windows设置为WIFI的共享网络, 可以连接到Ubuntu的网络, 但是连接不上windows
=> setenv ethaddr 00:04:9f:04:d2:25
IP address is 192.168.137.164; sending through gateway 192.168.137.1
setenv ipaddr 192.168.1.50
setenv ethaddr b8:ae:1d:01:00:00
setenv gatewayip 192.168.1.1
setenv netmask 255.255.255.0
setenv serverip 192.168.1.253
saveenv
=> ? ping
ping - send ICMP ECHO_REQUEST to network host
Usage:
ping pingAddress
用于测试网络链接是不是成功
=> ? dhcp
dhcp - boot image via network using DHCP/TFTP protocol
Usage:
dhcp [loadAddress] [[hostIPaddr:]bootfilename]
从路由器获取一个网络ip地址, 这是一个临时的地址, 不会影响环境变量中的地址, 下一次连接使用的是环境变量
=> ? nfs
nfs - boot image via network using NFS protocol
Usage:
nfs [loadAddress] [[hostIPaddr:]bootfilename]
目的是为了调试代码, 把系统镜像以及设备树下载到开发板中
但是不能使用????
==可以使用==
=> tftp 80800000 zImage
Using FEC1 device
TFTP from server 192.168.31.187; our IP address is 192.168.137.52; sending through gateway 192.168.137.1
Filename 'zImage'.
Load address: 0x80800000
Loading: #########################################################################################################################################################################################################################################################################################################################################################################################
#############
2.2 MiB/s
done
Bytes transferred = 5901752 (5a0db8 hex)
sudo apt-get install tftp-hpa tftpd-hpa
下载
mkdir/home/zuozhongkai/linux/tftpbootchmod777 /home/zuozhongkai/linux/tftpboot
建文件夹
建立文件设置/etc/xinetd.d/tftp
1 server tftp
2 {
3 socket_type =dgram
4 protocol =udp
5 wait =yes
6 user =root
7 server =/usr/sbin/in.tftpd
8 server_args =-s /home/zuozhongkai/linux/tftpboot/
9 disable =no
10 per_source =1111cps =1002
12 flags =IPv4
13 }
文件中
sudo service tftpd-hpa star
/etc/default/tftpd-hpa文件
1 # /etc/default/tftpd-hpa
2
3 TFTP_USERNAME="tftp"
4 TFTP_DIRECTORY="/home/zuozhongkai/linux/tftpboot"
5 TFTP_ADDRESS=":69"
6 TFTP_OPTIONS="-l -c -s"
sudo service tftpd-hpa restart
EMMC和SD卡操作
只要驱动写好 就支持EMMC和SD卡
=> ? mmc
mmc - MMC sub system
Usage:
mmc info - display info of the current MMC device
mmc read addr blk# cnt
mmc write addr blk# cnt
mmc erase blk# cnt
mmc rescan
mmc part - lists available partition on current mmc device
mmc dev [dev] [part] - show or set current mmc device [partition]
mmc list - lists available devices
mmc hwpartition [args...] - does hardware partitioning
arguments (sizes in 512-byte blocks):
[user [enh start cnt] [wrrel {on|off}]] - sets user data area attributes
[gp1|gp2|gp3|gp4 cnt [enh] [wrrel {on|off}]] - general purpose partition
[check|set|complete] - mode, complete set partitioning completed
WARNING: Partitioning is a write-once setting once it is set to complete.
Power cycling is required to initialize partitions after set to complete.
mmc bootbus dev boot_bus_width reset_boot_bus_width boot_mode
- Set the BOOT_BUS_WIDTH field of the specified device
mmc bootpart-resize <dev> <boot part size MB> <RPMB part size MB>
- Change sizes of boot and RPMB partitions of specified device
mmc partconf dev boot_ack boot_partition partition_access
- Change the bits of the PARTITION_CONFIG field of the specified device
mmc rst-function dev value
- Change the RST_n_FUNCTION field of the specified device
WARNING: This is a write-once field and 0 / 1 / 2 are the only valid values.
mmc setdsr <value> - set DSR register value
mmc info
打印当前设备的信息
mmc rescan
重新扫描
mmc list
所有可用的
mmc dev 设备号 [块地址]
设置当前的设备
mmc part
显示分区
mmc read addr blk# cnt
: addr是数据写入DRAM中的地址, blk是读取的块起始地址, cnt是块的数量
mmc write addr blk# cnt
: 用来把内容写入
mmc erase
: 擦除少用
文件系统有关
FAT文件格式命令
对于i.mxdull有三个分区, 第一个是uboot, 第二个是Linux内核和设备树FAT格式, 第三个系统的根文件系统EXT4格式
=> ? fatinfo
fatinfo - print information about filesystem
Usage:
fatinfo <interface> [<dev[:part]>]
- print information about filesystem from 'dev' on 'interface'
查看文件某一个分区的信息, 查某一个设备的某一个分区
fatinfo mmc 1:1 => fatinfo mmc 0:1 Interface: MMC Device 0: Vendor: Man 000000 Snr 00011801 Rev: 10.11 Prod: APPSD Type: Removable Hard Disk Capacity: 7680.0 MB = 7.5 GB (15728640 x 512) Filesystem: FAT32 "NO NAME "
检查mmc设备一的分区一, 第一个分区没有格式, 第二个是FAT格式,
查看某一个分区的所有的文件
=> ? fatls fatls - list files in a directory (default /) Usage: fatls <interface> [<dev[:part]>] [directory] - list files from 'dev' on 'interface' in a 'directory'
=> ? fstype fstype - Look up a filesystem type Usage: fstype <interface> <dev>:<part> - print filesystem type fstype <interface> <dev>:<part> <varname> - set environment variable to filesystem type
查看文件格式
=> fstype mmc 0:1 fat => fstype mmc 0:0 Failed to mount ext2 filesystem... ** Unrecognized filesystem type **
fatload 把指定的文件读取到MMC中, 就是读取系统的命令
fatload mmc 1:1 80800000 zImage
fatwrite写入文件
fatwrite <interface> <dev[:part]> <addr> <filename> <bytes>
EXT格式的文件, 有四个常用, ext2load, ext2ls, ext4load, ext4write
NAND命令
nand info 查看信息
nand device 切换NADA Flash
nand erase 擦除
nand write 写
boot指令
bootz命令
用于启动zImage
bootz 要启动Linux首先要把Linux镜像zImage和设备树dtb拷贝到DRAM中, 设备树也要拷贝到DRAM中, 或者通过tftp下载
=> ? bootz
bootz - boot Linux zImage image from memory
Usage:
bootz [addr [initrd[:size]] [fdt]]
- boot Linux zImage stored in memory
The argument 'initrd' is optional and specifies the address
of the initrd in memory. The optional argument ':size' allows
specifying the size of RAW initrd.
When booting a Linux kernel which requires a flat device-tree
a third argument is required which is the address of the
device-tree blob. To boot that kernel without an initrd image,
use a '-' for the second argument. If you do not pass a third
a bd_info struct will be passed instead
addr是镜像在DRAM中的位置, initrd就是initrd文件的位置, 不用的话使用一个-代替, fdt是设备树的地址,
- 网络启动
把镜像存放至0x80800000, 设备树在0x83000000地址
=> dhcp
BOOTP broadcast 1
*** Unhandled DHCP Option in OFFER/ACK: 46
*** Unhandled DHCP Option in OFFER/ACK: 46
DHCP client bound to address 192.168.137.247 (27 ms)
Using FEC1 device
TFTP from server 192.168.31.187; our IP address is 192.168.137.247; sending through gateway 192.168.137.1
Filename 'zImage'.
Load address: 0x80800000
Loading: ########################################################################################################################################################################################################################################################################################################################### ###############################################################
2.2 MiB/s
done
Bytes transferred = 5901752 (5a0db8 hex)
=> tftp 83000000 imx6ull-alientek-emmc.dtb
Using FEC1 device
TFTP from server 192.168.31.187; our IP address is 192.168.137.247; sending through gateway 192.168.137.1
Filename 'imx6ull-alientek-emmc.dtb'.
Load address: 0x83000000
Loading: ###
1 MiB/s
done
Bytes transferred = 39280 (9970 hex)
=> bootz 80800000 - 83000000
Kernel image @ 0x80800000 [ 0x000000 - 0x5a0db8 ]
## Flattened Device Tree blob at 83000000
Booting using the fdt blob at 0x83000000
Using Device Tree in place at 83000000, end 8300c96f
bootm
用于启动uImage
boot
会读取变量bootcmd变量来启动系统,
setenv bootcmd 'tftp 80800000 zImage; tftp 83000000 imx6ull-14x14-emmc-7-1024x600-c.dtb; bootz 80800000 -83000000'
saveenv
boot
起始就是调用一个命令集合
reset
复位
go
跳转进行运行
run
运行自己设计的变量
mtest
测试内存, 重复读写内存