在TST板卡上测试uboot指令

TST板卡 uboot启动openEuler内核镜像

开发环境介绍

硬件: TST板卡
操作系统: openEuler 23.09 (飞腾BSP定制)
BSP源码: Gitee仓库
编译工具链: aarch64-openeuler-linux-gcc
测试工具: LDRA Testbed

应用开发:

  1. Voter: https://gitee.com/tjopenlab/como-fscp-voter
  2. Ander: https://gitee.com/tjopenlab/como-fscp-ander
  3. COMO Runtime: https://gitee.com/tjopenlab/como

参考资料

  1. 原子嵌入式Linux驱动开发详解
  2. 泰雷兹-汉为板卡BSP使用手册

1 基础指令

在板子启动的autoboot阶段按Enter键进入uboot命令行模式:

flash tpye = default flash, jedec_id = 0xc81840c8
get flash speed = 0
power on reset done!

U-Boot 2022.01-v2.03 (Jan 23 2024 - 15:02:32 +0800)

DRAM:  u-boot : send cmd to cpld : 1
Phytium ddr init
  CH 0 :
force spd, dimm info is from parm
  tAAmim    = 13750ps
  tRCDmin   = 13750ps
  tRPmin    = 13750ps
  tRASmin   = 32000ps
  tRCmin    = 45500ps
  tFAWmin   = 21000ps
  tRRD_Smin = 3000ps
  tRRD_Lmin = 4900ps
  tCCD_Lmin = 5000ps
  tWRmin    = 15000ps
  tWTR_Smin = 2500ps
  tWTR_Lmin = 7500ps
  tRFC1min  = 350000ps
  tRFC2min  = 260000ps
  tRFC4min  = 160000ps
        Dimm_Capacity = 4GB
        DDR4    UDIMM/4 Bank Groups/4 Banks/Column 10/Row 16/X8/1 Rank/ECC/Standard
        Modual:Unknown=0x0
PBF relocate done
1.9 GiB
SGMII TRAINING(time cost: 20ms)
MMC:   clk = 1200000000Hz
clk = 1200000000Hz
PHYTIUM MCI: 0, PHYTIUM MCI: 1
Loading Environment from SPIFlash... OK
In:    serial
Out:   serial
Err:   serial
Net:   eth0: ethernet@32010000, eth1: ethernet@3200c000, eth2: ethernet@32012000, eth3: ethernet@3200e000
  pci_0:0.0         00:00.00  - 1db7:dc01     pcie@40000000    0x06 (Bridge device)
  pci_0:2.0         00:02.00  - 1db7:dc01     pcie@40000000    0x06 (Bridge device)
  pci_0:3.0         00:03.00  - 1db7:dc01     pcie@40000000    0x06 (Bridge device)
  pci_0:4.0         00:04.00  - 1db7:dc01     pcie@40000000    0x06 (Bridge device)
  pci_0:5.0         00:05.00  - 1db7:dc01     pcie@40000000    0x06 (Bridge device)
  pci_1:0.0         01:00.00  - 10ec:8168     pci_0:0.0    0x02 (Network controller)
  pci_2:0.0         02:00.00  - 10ec:8168     pci_0:2.0    0x02 (Network controller)
smc call return: x0 = 0, x1 = 0, x2 = c070000, x3 = 0
 _    _          _   ___          ________ _____
| |  | |   /\   | \ | \ \        / /  ____|_   _|
| |__| |  /  \  |  \| |\ \  /\  / /| |__    | |
|  __  | / /\ \ | . ` | \ \/  \/ / |  __|   | |
| |  | |/ ____ \| |\  |  \  /\  /  | |____ _| |_
|_|  |_/_/    \_\_| \_|   \/  \/   |______|_____|
                Hanwei LibVer v1.1
PAD VERSION :    V0.4
BOARD       :    FT-E2KQ-CORE
Hit any key to stop autoboot:  0

1.1 bdinfo(查看开发板信息)

HANWEI_E2K#bdinfo
boot_params = 0x0000000000000000
DRAM bank   = 0x0000000000000000
-> start    = 0x0000000080000000
-> size     = 0x000000007b000000
flashstart  = 0x0000000000000000
flashsize   = 0x0000000000000000
flashoffset = 0x0000000000000000
baudrate    = 115200 bps
relocaddr   = 0x00000000f9d2a000
reloc off   = 0x00000000c1a2a000
Build       = 64-bit
current eth = ethernet@32010000
ethaddr     = 9c:69:b4:c0:44:f6
IP addr     = 192.168.1.101
fdt_blob    = 0x00000000f9c265b0
new_fdt     = 0x00000000f9c265b0
fdt_size    = 0x0000000000001820
lmb_dump_all:
 memory.cnt  = 0x1
 memory[0]      [0x80000000-0xfaffffff], 0x7b000000 bytes flags: 0
 reserved.cnt  = 0x1
 reserved[0]    [0xf9c216d0-0xfaffffff], 0x013de930 bytes flags: 0
arch_number = 0x0000000000000000
TLB addr    = 0x00000000faff0000
irq_sp      = 0x00000000f9c265a0
sp start    = 0x00000000f9c265a0
Early malloc usage: 2b0 / 400

1.2 printenv(查看环境变量)

HANWEI_E2K#printenv
arch=arm
baudrate=115200
board=e2000
board_name=e2000
boot_os=$boottype $kernel_addr -:- $kernel_fdt_addr
bootargs=earlycon=pl011,0x2800d000 console=ttyAMA1,115200 loglevel=1 rootwait root=/dev/mmcblk0p2 rw
bootcmd=fatload mmc 0:1 0x90000000 bspfte2000_Phytium_Tst_Dcs_x64.elf;bootelf
bootdelay=2
boottype=bootm
cpu=armv8
distro_bootcmd=run load_kernel; run load_fdt; run boot_os
eth0addr=9c:69:b4:c0:44:f6
eth1addr=9c:69:b4:c0:44:f7
eth2addr=9c:69:b4:c0:44:f8
eth3addr=9c:69:b4:c0:44:f9
ethaddr=9c:69:b4:c0:44:f6
fdtcontroladdr=f9c265b0
gatewayip=192.168.1.1
ipaddr=192.168.1.101
kernel_addr=0x80080000
kernel_fdt_addr=0x92000000
kernel_fdt_name=dtb
kernel_name=uImage
load_fdt=load $loadtype 0:1 $kernel_fdt_addr $kernel_fdt_name
load_kernel=load $loadtype 0:1 $kernel_addr $kernel_name
loadaddr=0x90000000
loadtype=mmc
netdev=eth0
netmask=255.255.255.0
serverip=192.168.1.100
show_pad_ver=1
use_eeprom_mac=1
vendor=phytium
Environment size: 928/4092 bytes

1.3 version(查看uboot版本号)

 HANWEI_E2K#version
 _    _          _   ___          ________ _____
| |  | |   /\   | \ | \ \        / /  ____|_   _|
| |__| |  /  \  |  \| |\ \  /\  / /| |__    | |
|  __  | / /\ \ | . ` | \ \/  \/ / |  __|   | |
| |  | |/ ____ \| |\  |  \  /\  /  | |____ _| |_
|_|  |_/_/    \_\_| \_|   \/  \/   |______|_____|
                Hanwei LibVer v1.1
U-Boot 2022.01-v2.03 (Jan 23 2024 - 15:02:32 +0800)
gcc (Ubuntu 9.3.0-10kylin2) 9.3.0
GNU ld (GNU Binutils for Ubuntu) 2.34

2 网络与TFTP

2.1 网络指令

使用setenv配置板子、网关和服务器(PC)的IP:

HANWEI_E2K#setenv ipaddr 192.168.0.50
HANWEI_E2K#setenv gatewayip 192.168.0.1
HANWEI_E2K#setenv serverip 192.168.0.10
HANWEI_E2K#saveenv
Saving Environment to SPIFlash... done
OK

使用printenv查看修改后的变量:

HANWEI_E2K#printenv
arch=arm
...
gatewayip=192.168.0.1
ipaddr=192.168.0.50
...
netmask=255.255.255.0
serverip=192.168.0.10

无需重启,ping网关(192.168.0.1),可以ping通:

HANWEI_E2K#ping 192.168.0.1
ethernet@32010000: PHY present at 0
ethernet@32010000: Starting autonegotiation...
ethernet@32010000: Autonegotiation complete
ethernet@32010000: link up, 100Mbps full-duplex (lpa: 0x4de1)
ft rgmii speed 100M!
Using ethernet@32010000 device
host 192.168.0.1 is alive

ping server(192.168.0.10),可以ping通:

HANWEI_E2K#ping 192.168.0.10
ethernet@32010000: PHY present at 0
ethernet@32010000: Starting autonegotiation...
ethernet@32010000: Autonegotiation complete
ethernet@32010000: link up, 100Mbps full-duplex (lpa: 0x4de1)
ft rgmii speed 100M!
Using ethernet@32010000 device
host 192.168.0.10 is alive

ping自身(192.168.0.50),ping不通,原因未知:

HANWEI_E2K#ping 192.168.0.50
ethernet@32010000: PHY present at 0
ethernet@32010000: Starting autonegotiation...
ethernet@32010000: Autonegotiation complete
ethernet@32010000: link up, 100Mbps full-duplex (lpa: 0x4de1)
ft rgmii speed 100M!
Using ethernet@32010000 device

ARP Retry count exceeded; starting again
ping failed; host 192.168.0.50 is not alive

注1:如果ping不通PC端,尝试重新设置IP地址:setenv ipaddr 192.168.0.50

注2:uboot没有对ping命令作处理,只能在uboot中ping其他机器,其他机器不能ping uboot,否则失败。

2.2 MMC指令

使用mmc info查看当前选中的MMC信息:

HANWEI_E2K#mmc info
Device: PHYTIUM MCI
Manufacturer ID: 9b
OEM: 100
Name: Y2P03
Bus Speed: 50000000
Mode: MMC High Speed (52MHz)
Rd Block Len: 512
MMC version 5.1
High Capacity: Yes
Capacity: 29.1 GiB
Bus Width: 8-bit
Erase Group Size: 512 KiB
HC WP Group Size: 8 MiB
User Capacity: 29.1 GiB
Boot Capacity: 4 MiB ENH
RPMB Capacity: 16 MiB ENH
Boot area 0 is not write protected
Boot area 1 is not write protected

使用mmc list查看开发板MMC设备数量:

HANWEI_E2K#mmc list
PHYTIUM MCI: 0 (eMMC)
PHYTIUM MCI: 1

可以看到有2个MMC设备,即EMMC(MMC 0)和SD卡(MMC 1)

使用mmc dev切换MMC设备:

HANWEI_E2K#mmc dev 1
MMC: no card present

没有插入SD卡时,会提示切换未成功。

2.3 FAT格式文件系统操作命令

使用fatinfo查询指定MMC设备分区的文件系统信息:

HANWEI_E2K#fatinfo mmc 0
Interface:  mmc
  Device 0: Vendor: Man 00009b Snr 0b7496a7 Rev: 0.0 Prod: Y2P032
            Type: Removable Hard Disk
            Capacity: 29820.0 MB = 29.1 GB (61071360 x 512)
Filesystem: FAT32 "NO NAME    "

使用fstype查看MMC设备某个分区的系统格式(实测MMC 0只有1个分区,即mmc 0:1):

HANWEI_E2K#fstype mmc 0:1
fat

mmc 0:1分区为FAT格式。
使用fatwrite将DRAM中的数据写入到MMC中,如将90000000处的Image写入EMMC中:

HANWEI_E2K#fatwrite mmc 0:1 90000000 Image e02200
14688768 bytes written in 1245 ms (11.3 MiB/s)

使用fatls查看FAT格式设备的目录和文件信息:

HANWEI_E2K#fatls mmc 0:1
  5750880   bspfte2000_Phytium_Tst_Dcs_x64.elf
    24584   e2000q-hanwei-qcore.dtb
 14688768   Image

3 file(s), 0 dir(s)

使用fatload将MMC中的文件读取到DRAM中,如将dtb文件从EMMC读取到80800000处:

HANWEI_E2K#fatload mmc 0:1 80800000 e2000q-hanwei-qcore.dtb
24584 bytes read in 3 ms (7.8 MiB/s)

2.4 加载dtb的命令

使用fdt addr将DRAM地址设置为设备树的首地址(也可不设置,在booti参数中指定dtb内存地址):

HANWEI_E2K#fdt addr 80800000

使用fdt header查看设备树的头信息:

HANWEI_E2K#fdt header
magic:                  0xd00dfeed
totalsize:              0x6008 (24584)
off_dt_struct:          0x48
off_dt_strings:         0x5b88
off_mem_rsvmap:         0x28
version:                17
last_comp_version:      16
boot_cpuid_phys:        0x0
size_dt_strings:        0x480
size_dt_struct:         0x5b40
number mem_rsv:         0x1

使用fdt print查看设备树文件的内容:

HANWEI_E2K#fdt print
/ {
        compatible = "phytium,e2000", "phytium,pe2204";
        interrupt-parent = <0x00000001>;
        ...

2.5 TFTP

2.5.1 搭建TFTP环境

在与板子同一局域网下的Linux PC(以Ubuntu为例)上搭建TFTP服务器:

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

创建一个目录存放tftp文件并开放权限(使uboot可以从tftpboot中下载文件):

mkdir tftpboot
chmod 777 tftboot

新建文件/etc/xinetd.d/tftp,输入如下内容:

server tftp
{
        socket_type = dgram
        protocol    = udp
        wait        = yes
        user        = root
        server      = /usr/sbin/in.tftpd
        server_args = -s ~/Work/7-2024/tftpboot
        disable     = no
        per_source  = 11
        cps         = 100 2
        flags       = IPv4
}

启动tftp服务:

sudo systemctl start tftpd-hpa

打开/etc/default/tftpd-hpa,修改为如下内容(TFTP_DIRECTORY需为绝对路径):

# /etc/default/tftpd-hpa

TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/home/xilong/Work/7-2024/tftpboot"
TFTP_ADDRESS=":69"
TFTP_OPTIONS="-l -c -s"

重启tftp服务器:

sudo systemctl restart tftpd-hpa

2.5.2 传输Image镜像

将编译(前置工作)生成的Image镜像文件拷贝到tftpboot文件夹中,并开放权限:

cp Image ~/Work/7-2024/tftpboot
sudo chmod 777 ./tftpboot/Image

tftpboot(或简写为tftp)命令用法:

HANWEI_E2K#? tftp
tftpboot - boot image via network using TFTP protocol

Usage:
tftpboot [loadAddress] [[hostIPaddr:]bootfilename]

使用tftp命令从PC端将Image下载至开发板DRAM 90000000处,如下:

HANWEI_E2K#tftp 90000000 192.168.0.10:Image
ethernet@32010000: PHY present at 0
ethernet@32010000: Starting autonegotiation...
ethernet@32010000: Autonegotiation complete
ethernet@32010000: link up, 100Mbps full-duplex (lpa: 0x4de1)
ft rgmii speed 100M!
Using ethernet@32010000 device
TFTP from server 192.168.0.10; our IP address is 192.168.0.50
Filename 'Image'.
Load address: 0x90000000
Loading: #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         ##########################
         378.9 KiB/s
done
Bytes transferred = 14688768 (e02200 hex)

执行bootp的输出与tftp相同。

2.5.3 验证传输

比较十六进制数据

在PC端使用vim打开Image,输入:%!xxd转为十六进制显示(:%!xxd -r恢复ASCII显示):

00000000: 4d5a 0091 ffbf 2f14 0000 0000 0000 0000  MZ..../.........
00000010: 0000 f400 0000 0000 0a00 0000 0000 0000  ................
00000020: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000030: 0000 0000 0000 0000 4152 4d64 4000 0000  ........ARMd@...
...

在板端使用md.b命令查看DRAM 0x90000000处的数据:

HANWEI_E2K#md.b 90000000
90000000: 4d 5a 00 91 ff bf 2f 14 00 00 00 00 00 00 00 00  MZ..../.........
90000010: 00 00 f4 00 00 00 00 00 0a 00 00 00 00 00 00 00  ................
90000020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
90000030: 00 00 00 00 00 00 00 00 41 52 4d 64 40 00 00 00  ........ARMd@...

与PC端Image一致,传输成功。稍后将dtb也加载至DRAM中,即可启动新的Image。

2.6 加载新系统的Image

首先ping通PC端:

HANWEI_E2K#ping 192.168.0.10
ethernet@32010000: PHY present at 0
ethernet@32010000: Starting autonegotiation...
ethernet@32010000: Autonegotiation complete
ethernet@32010000: link up, 100Mbps full-duplex (lpa: 0x4de1)
ft rgmii speed 100M!
Using ethernet@32010000 device
host 192.168.0.10 is alive

之后将Image文件从PC端的tftpboot文件夹传输到开发板DRAM的90000000处:

HANWEI_E2K#tftp 90000000 192.168.0.10:Image
ethernet@32010000: PHY present at 0
ethernet@32010000: Starting autonegotiation...
ethernet@32010000: Autonegotiation complete
ethernet@32010000: link up, 100Mbps full-duplex (lpa: 0x4de1)
ft rgmii speed 100M!
Using ethernet@32010000 device
TFTP from server 192.168.0.10; our IP address is 192.168.0.50
Filename 'Image'.
Load address: 0x90000000
Loading: #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         ##########################
         415 KiB/s
done
Bytes transferred = 14688768 (e02200 hex)

使用fatload将MMC中的文件读取到DRAM中,如将dtb文件从EMMC读取到80800000处:

HANWEI_E2K#fatload mmc 0:1 80800000 e2000q-hanwei-qcore.dtb
24584 bytes read in 3 ms (7.8 MiB/s)

查看booti的用法:

HANWEI_E2K#? booti
booti - boot Linux kernel 'Image' format from memory

Usage:
booti [addr [initrd[:size]] [fdt]]
    - boot Linux flat or compressed 'Image' stored at 'addr'
        The argument 'initrd' is optional and specifies the address
        of an initrd in memory. The optional parameter ':size' allows
        specifying the size of a RAW initrd.
        Currently only booting from gz, bz2, lzma and lz4 compression
        types are supported. In order to boot from any of these compressed
        images, user have to set kernel_comp_addr_r and kernel_comp_size environment
        variables beforehand.
        Since booting a Linux kernel requires a flat device-tree, a
        third argument providing the address of the device-tree blob
        is required. To boot a kernel with a device-tree blob but
        without an initrd image, use a '-' for the initrd argument.

使用booti命令启动(Image在90000000处,不指定根文件系统,dtb在80800000处):

HANWEI_E2K#booti 90000000 - 80800000
## Flattened Device Tree blob at 80800000
   Booting using the fdt blob at 0x80800000
using: FDT
   Loading Device Tree to 00000000f9c19000, end 00000000f9c22007 ... OK
run in ft_board_setup
fdt_addr 00000000f9c19000
mb_count = 0x2
mb_blocks[0].mb_size = 0x7c000000
mb_blocks[1].mb_size = 0x80000000
fdt : can not find /memory@01  node
fdt : add node memory@01
fdt : dram size 0x100000000 update successfully
## Transferring control to Linux (at address 90000000)...

Starting kernel ...

[    0.000000] Booting Linux on physical CPU 0x0000000000 [0x701f6643]
[    0.000000] Linux version 5.10.0-openeuler (oe-user@oe-host) (aarch64-openeuler-linux-gnu-gcc (crosstool-NG 1.25.0) 10.3.1, GNU ld (crosstool-NG 1.25.0) 2.37) #1 SMP PREEMPT Wed Mar 6 10:35:44 UTC 2024
[    0.000000] Machine model: HANWEI QCORE
[    0.000000] earlycon: pl11 at MMIO 0x000000002800d000 (options '')
[    0.000000] printk: bootconsole [pl11] enabled
[    0.375586] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(179,2)
[    0.384016] CPU: 0 PID: 1 Comm: swapper/0 Tainted: G S                5.10.0-openeuler #1
[    0.392181] Hardware name: HANWEI QCORE (DT)
[    0.396439] Call trace:
[    0.398882]  dump_backtrace+0x0/0x17c
[    0.402535]  show_stack+0x14/0x1c
[    0.405842]  dump_stack+0xbc/0xfc
[    0.409146]  panic+0x160/0x358
[    0.412193]  mount_block_root+0x370/0x3e4
[    0.416192]  mount_root+0x6c/0x78
[    0.419497]  prepare_namespace+0x154/0x164
[    0.423583]  kernel_init_freeable+0x33c/0x3a0
[    0.427930]  kernel_init+0x10/0xe0
[    0.431322]  ret_from_fork+0x10/0x18
[    0.434889] SMP: stopping secondary CPUs
[    0.438804] Kernel Offset: disabled
[    0.442282] CPU features: 0x0000,00000002,00002008
[    0.447061] Memory Limit: none
[    0.450107] ---[ end Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(179,2) ]---

Image内核镜像启动成功(由于没有加载根文件系统,之后会卡在end Kernel panic)。

posted @ 2025-12-25 14:46  Digitzh  阅读(16)  评论(0)    收藏  举报