執行人: hugo0406
專題解說影片
理解 Linux 核心在 STM32F429i-Discovery 系統晶片上運作的方式,探究相關的準備工作,特別是相關系統初始化的流程。
注意: 沒有 MMU
STM32F429i-Discovery 是意法半導體提供的開發板。
主要特點:
閱讀 No-MMU memory mapping support,闡述 Linux 執行於 Arm Cortex-M4 這樣的硬體,會有什麼限制,特別是記憶映射和其管理。
參考 STM32F429 的 Reference Manual
Boot mode selection pins: BOOT0,BOOT1
CPU reset 後會從這兩根 pin 的狀態來決定哪一塊 memory 當 boot space,STM32F429 選用的 default boot space 是 Main Flash memory
BOOT1 | BOOT0 | Boot Mode | Aliasing |
---|---|---|---|
X | 0 | Main Flash Memory | Main Flash Memory is selected as the boot space |
0 | 1 | System Memory | System Memory is selected as the boot space |
1 | 1 | Embedded SRAM | Embedded SRAM is selected as the boot space |
Flash memory 的 start address 是 0x08000000
等開機時,會自動將 0x08000000-0x080FFFFF
映射到 0x00000000-0x000FFFFF
,所以將 bin檔燒在 0x08000000
,STM32F429 就可以從 0x00000000
開始執行
應提及 GNU Toolchain, OpenOCD, st-link 等工具的使用。
STM32F42I-DISCO 內建 ST-LINK/V2,已經包含 ST-Link 了,所以 USB-mini 插上去後就可以直接燒錄,不需要額外的燒錄器。參考嵌入式系統建構:開發運作於 STM32 的韌體程式,確保能成功將檔案燒錄到開發版上
Start by plugging the STLINK device into the usb port, then run lsusb
.
There have several files in /lib/udev/rules.d
directory. The 49-stlinkv2.rules
file contains the following:
and the idVendor
of 0483
and idProduct
of 3748
matches the vendor id from the lsusb output.
Verify it by checking the installed version :
stlink
is an open source toolset to program and debug STM32 devices and boards manufactured by STMicroelectronics.To verify the successful installation
st-info
: a programmer and chip information tool
注意書寫規範:
hugo0406
已修正
blink.c
Makefile
blink.ld
執行 make
:
編譯完後會產生 blink.out
及 blink.bin
,將 blink.bin
燒進 flash
燒錄後按 RESET 即可看到 LD3(綠)
、LD4(紅)
開始交替閃爍
說明程式原理,特別要搭配 GPIO 說明。
介紹 u-boot 到 Linux 核心的初始化流程,要提及 device tree
用你的理解書寫,避免複製來路不明的文字片段。
When the processor is powered on, the memory doesn't hold an operating system, so special software is needed to bring the OS into memory from the media on which it resides. This software is normally a small piece of code called the boot loader.
On a desktop PC, the boot loader resides on the master boot record (MBR) of the hard drive and is executed after the PC's basic input output system (BIOS) performs system initialization tasks.
U-Boot is capable of booting images in two formats:
FIT 是 flattened image tree 的縮寫,類似於 FDT (flattened device tree)。它利用了Device Tree Source files(DTS)的語法,生成的 image 文件也和 dtb 文件類似(稱作 itb)
With U-Boot, "normal" build targets like "zImage" or "bzImage" are not used.
U-Boot supports the following STMP32 MCU SoCs:
The boot chain without SPL(Secondary Program Loader)
defconfig_file:
FSBL | OS |
---|---|
U-boot | Linux |
(Debian based) Depending on the build targets further packages maybe needed :
下載 U-boot 原始碼:
編譯 U-boot:
注意用語:
hugo0406
已修正
.config
預設配置.config
Filename | Description |
---|---|
u-boot.map | The symbol map |
u-boot | U-Boot executable in ELF binary format |
u-boot.bin | U-Boot raw binary image, which can be written to the boot storage device |
查看 u-boot.bin
大小
燒進 FLASH
STM32 PIN | VCP |
---|---|
PA9 | USART1_TX |
PA10 | USART1_RX |
USB to TTL 接線:
安裝 PUTTY:
查看 PUTTY版本
指名穩定版本的 Linux 核心超連結,如 https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
可以從 官方文件中 得知 Baud Rate 預設為 115200
,UART number 預設為 1
開啟 putty
, 選擇 serial , /dev/ttyUSB0 , Baud rate 選擇 115200
按開發版上的 RESET, 可看見 U-Boot 命令提示如下:
version
-> 顯示目前 U-Boot 版本
正確標注硬體名稱。
hugo0406
已修正
bdinfo
-> 顯示目前 STM32F429 資訊
針對系統啟動的需求,調整 Linux 核心組態,使其得以在 STM32F429-Discovery 運作。
詳細內容請參閱核心程式碼目錄下的文件 ./Documentation/kbuild/kconfig-language.rst
不能選擇 tinyconfig
,務必依循 stm32_defconfig 並針對 STM32F429 進行調整。
對照 移植 linux 5.5.3 到 stm32f429-discovery 板資料 的核心組態。
make tinyconfig
產生最小的核心,產生的 .config 非常小,不能展示訊息
Menu Config
When I try to menuconfig, but got some error message
libncurses5-dev need
to be installed before compiling the kernel
編譯核心:
編譯完後,可以在核心程式碼目錄下 ./arch/arm/boot/ 看到 xipImage
xip 代表 execute in place :
程式直接在 flash 上執行,而不必搬到 RAM 上,只有 data 搬到 RAM 。可以減少 memory 的使用,但執行速度較慢。
查看 xipImage 大小
xipImage 竟然有 1.8MB,幾乎佔了 Flash 大部分的空間,沒有足夠的空間來存放檔案系統,只能保留最基本的功能,盡量減小核心大小