Stm32f746-disco:
片內Flash:1MB
片內SRAM:340KB
SDRAM: 8MB
QSPI Flash: 16MBlinux
U-Boot2019.07 源碼 https://ftp.denx.de/pub/u-boot/
交叉編譯鏈 gcc-arm-none-eabi-7-2018-q2-update-linux.tar.bz2
系統:Fedoragit
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 便可使能快速啓動。github
- 取消快速啓動; 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中。dom
- 註釋掉 configs/stm32f746-sico.h 第72行
//#define CONFIG_SYS_UBOOT_START 0x080083FD
主要參考了這位同窗的實現:https://github.com/huayuguo/uboot-stm32h743_ethelectron
解壓源碼進入根目錄,依次執行下列命令code
- 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處。
由於修改了部分代碼,打印信息可能與官方不一樣。server
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