STM32F746-DISCO移植U-Boot 2019.07
硬件平台介绍
Stm32f746-disco:
片内Flash:1MB
片内SRAM:340KB
SDRAM: 8MB
QSPI Flash: 16MB
源码及编译器
U-Boot2019.07 源码 https://ftp.denx.de/pub/u-boot/
交叉编译链 gcc-arm-none-eabi-7-2018-q2-update-linux.tar.bz2
系统:Fedora
U-Boot启动过程及分析
U-Boot 编译完成后会生成2个文件 spl/u-boot-spl.bin和u-boot.bin,分别烧录在两段地址,或者合并后烧录;也即U-Boot实际是分成两个阶段,SPL阶段+UBOOT阶段。
其中,SPL阶段负责解析设备树(设备树中具有dm-pre-reloc属性的元素会在SPL阶段解析),初始化SDRAM,配置时钟,引导UBOOT。SPL必须烧写在0x08000000处,即片内FLASH首地址,因为STM32会自动从该地址处执行第一行代码。
开发过IAP的同学应该比较清楚,开发第二阶段代码需要设置中断向量表偏移量,使用MDK时需要在设置页设置偏移,使用GCC则需要配合LDS脚本搬移代码。
UBOOT阶段,相对于SPL阶段就是第二段代码,负责 relocate自身向量表等操作,因为uboot.bin不可能烧写在FLASH首地址,必须重定向中断向量表,才能正确响应中断。该偏移地址实际是在配置uboot时设置,即在make menuconfig 后 Boot images->Text Base设置的地址。
是否可以不进入SPL直接进入UBOOT阶段,答案是不行的,因为SDRAM的配置(包含dm-pre-reloc属性)等实在SPL阶段完成,UBOOT阶段不在配置SDRAM,直接搬移自身至SDRAM,可想而知,SDRAM尚未配置,搬移自身也不可能发生。如果需要快速启动,实际上可以不进入UBOOT阶段,直接从SPL阶段引导系统,只需 make menuconfig 后SPL/TPL -> Activate Falcon Mode 即可使能快速启动。
代码或配置修改
- 取消快速启动; make menuconfig 取消 SPL/TPL -> Activate Falcon Mode
只修改上述1处,发现u-boot.bin只能烧写在 0x08008000处即片内flash 第2个bank才能正常启动uboot,修改Text Base烧写在其他位置会导致错误不能启动uboot。查看代码发现 configs/stm32f746-sico.h 第72行 #define CONFIG_SYS_UBOOT_START 0x080083FD
实际上 0x83FD=0x8000+2554+1; 如果CONFIG_SYS_UBOOT_START未定义,则CONFIG_SYS_UBOOT_START才等于CONFIG_SYS_TEXT_BASE,即之前定义的Text Base才能生效。因此第72行代码注释,即可设置任意地址烧写u-boot.bin。最后,分析下为什么偏移至0x83FD就能进入,8000为烧写u-boot.bin的地址,2554为中断向量表的地址(vector_m.S),+1即将最后1位置1,应该是用thumb指令,跳转到reset中。
- 注释掉 configs/stm32f746-sico.h 第72行
//#define CONFIG_SYS_UBOOT_START 0x080083FD
主要参考了这位同学的实现:https://github.com/huayuguo/uboot-stm32h743_eth
编译过程及烧写
解压源码进入根目录,依次执行下列命令
- make ARCH=arm CROSS_COMPILE=arm-none-eabi- stm32f746-disco_defconfig
- make ARCH=arm CROSS_COMPILE=arm-none-eabi- menuconfig
- make
- 使用ST-Link(Linux平台) 或者 STM32 ST-LINK Utility(Win平台)将 spl/u-boot-spl.bin烧写在0x08000000,u-boot.bin烧写在0x08008000处。
执行及打印信息
因为修改了部分代码,打印信息可能与官方不同。
U-Boot SPL 2019.07 (Sep 04 2019 - 11:59:40 +0800)
Trying to boot from XIP
mkimage signature not found - ih_magic = 20050000
Jumping to U-Boot
loaded - jumping to U-Boot...
image entry point: 0x8010001
U-Boot 2019.07 (Sep 02 2019 - 11:49:34 +0800)
Model: STMicroelectronics STM32F746-DISCO board
DRAM: 8 MiB
set_rate not implemented for clock index 4
set_rate not implemented for clock index 4
set_rate not implemented for clock index 4
Flash: 1 MiB
MMC: sdio1@40012c00: 0
In: serial
Out: serial
Err: serial
usr button is at LOW LEVEL
Net:
Warning: ethernet@40028000 (eth0) using random MAC address - 2a:e6:dd:03:0c:36
eth0: ethernet@40028000
Hit SPACE in 3 seconds to stop autoboot.
U-Boot > setenv ipaddr 192.168.66.69
U-Boot > setenv serverip 192.168.66.66
U-Boot > tftp c0300000 uImage
Speed: 100, full duplex
Using ethernet@40028000 device
TFTP from server 192.168.66.66; our IP address is 192.168.66.69
Filename 'uImage'.
Load address: 0xc0300000
Loading: #################################################################
#################################################################
#################################################################
#################################################################
#####################################
727.5 KiB/s
done
Bytes transferred = 1519448 (172f58 hex)
U-Boot > tftp c0500000 stm32f746-disco.dtb
Speed: 100, full duplex
Using ethernet@40028000 device
TFTP from server 192.168.66.66; our IP address is 192.168.66.69
Filename 'stm32f746-disco.dtb'.
Load address: 0xc0500000
Loading: ###
580.1 KiB/s
done
Bytes transferred = 14858 (3a0a hex)
U-Boot > env set bootargs "root=/dev/ram console=ttySTM0,115200"
U-Boot > bootm c0300000 - c0500000
## Booting kernel from Legacy Image at c0300000 ...
Image Name: linux
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 1519384 Bytes = 1.4 MiB
Load Address: c0300000
Entry Point: c0300000
Verifying Checksum ... OK
## Flattened Device Tree blob at c0500000
Booting using the fdt blob at 0xc0500000
Loading Kernel Image ... OK
Using Device Tree in place at c0500000, end c0506a09
Starting kernel ...
[ 0.000000] Booting Linux on physical CPU 0x0
[ 0.000000] Linux version 4.19.69 (yhang@localhost.localdomain) (gcc version 7.3.1 20180622 (release) [ARM/embedded-7-branch revision 261907] (GNU Tools for Arm Embedded Processors 7-2018-q2-update)) #1 PREEMPT Thu Sep 5 09:03:24 CST 2019
[ 0.000000] CPU: ARMv7-M [410fc271] revision 1 (ARMv7M), cr=00000000
[ 0.000000] CPU: PIPT / VIPT nonaliasing data
来源:oschina
链接:https://my.oschina.net/u/4232364/blog/3134261