Template:ArticleMainWriter Template:ArticleFirstDraftVersion Template:ReviewersList
1. Purpose[edit source]
This article explains how to update boot binaries/stages in case of use of a "custom" devicetree.
As exemple, CubeMX is able to generate custom devicetree.
Information |
Even if STMicroelectronics strongly recommends to use a Linux® environment, this article works in WSL2 (Windows Sub-system Linux 2) from Windows 10® (builds 2019 or later) |
2. Rationale[edit source]
The rationale to not use the devicetree provided by OpenSTLinux distribution and prefer a "custom" devicetree is various;
- You built your own board
- You need to swap some IPs from MCU side to MPU side (or reverse)
- For any other reason...
3. Pre-requisites[edit source]
- Install a cross-compiler
- A cross compiler is needed to parse and prepare the device tree (.dts) file.
- System Workbench for STM32 is recommended.
- The zip file with the gcc can be found at <INSTALL_DIR>\plugins\fr.ac6.mcu.externaltools.arm-none.win32_1.16.0.201807130628\tools
- mingw64 is also a good alternative.
- System Workbench for STM32 is recommended.
- A cross compiler is needed to parse and prepare the device tree (.dts) file.
- Install a device tree compiler
- To install a community device tree compiler, please refer to Device Tree Compiler (MSYS2 version)
- Upon request, STMicroelectronics may provide an executable binary, without warranty nor support.
4. Kernel device tree update[edit source]
######################################### ######################################### ######################################### KERNEL ######################################### ######################################### ################### ################### UNPACK + PATCH ################### [frq09494@lmecxl0985 ~/views/DTC] $ mkdir -p kernel $ tar xf SOURCES-st-image-weston-openstlinux-weston-stm32mp1-openstlinux-4.19-thud-mp1-19-05-31/st-image-weston-openstlinux-weston-stm32mp1-openstlinux-4.19-thud-mp1-19-05-31/sources/arm-openstlinux_weston-linux-gnueabi/linux-stm32mp-4.19-r0/linux-4.19.43.tar.xz -C kernel $ mv kernel/linux-* kernel/kernel-sources/ $ pushd kernel/kernel-sources/ for p in $(ls -1 ../../SOURCES-st-image-weston-openstlinux-weston-stm32mp1-openstlinux-4.19-thud-mp1-19-05-31/st-image-weston-openstlinux-weston-stm32mp1-openstlinux-4.19-thud-mp1-19-05-31/sources/arm-openstlinux_weston-linux-gnueabi/linux-stm32mp-4.19-r0/*.patch); do patch -p1 < $p; done $ popd ################### ################### GENERATE DTB ################### [frq09494@lmecxl0985 ~/views/DTC/kernel] $ mkdir -p u-boot $ pushd u-boot $ cp -r ../MyDeviceTree_fromCubeMX/kernel dts [frq09494@lmecxl0985 ~/views/DTC/kernel] $ ll dts/ total 28 -rw-r--r-- 1 frq09494 frq09494 27156 Jun 17 17:10 stm32mp157c-mydevicetree-mx.dts $ gcc -E -nostdinc -I kernel-sources/include/ -I kernel-sources/arch/arm/boot/dts -I dts -undef -D__DTS__ -x assembler-with-cpp -o stm32mp157c-mydevicetree-mx.dts.tmp dts/stm32mp157c-mydevicetree-mx.dts $ dtc -I dts -O dtb -o stm32mp157c-mydevicetree-mx.dtb stm32mp157c-mydevicetree-mx.dts.tmp ################### ################### COPY DTB on target ################### $ scp stm32mp157c-mydevicetree-mx.dtb root@<Target_IP>:/boot/
Then [#update extlinux] of target according this new dtb filename
Information |
Steps 1 and 2 have to be done in a Windows® 10 git bash session (patch is natively supported by git bash) |
- Get the Linux® source code
- Apply patches to the Linux® source code
- Create a workdir directory
- mkdir workdir
- Copy from source code of Linux the dt-bindings and dt files
- cp <KernelSources>/include/dt-bindinds workdir
- cp <KernelSources>/arch/arm/boot/dts/* workdir/
- Copy your dts into workdir
- cp <Your/dts/file.dts> workdir/
- Prepare dts
- cd workdir
- arm-none-eabi-gcc.exe -E -nostdinc -I . -undef -D__DTS__ -x assembler-with-cpp -o <yourDTS.dts>.tmp <yourDTS.dts>
- compile dts.tmp with dtc.exe
- dtc.exe -I dts -O dtb -o <DTBresult.dtb> <yourDTS.dts>.tmp
5. U-Boot device tree update[edit source]
This operation depends on the use of a mkimage with stm32 support for Windows® which is not officially available.
- The usage of a a cross-compiler for Windows® and mingw64, the latest mkimage version (provided by U-Boot) will allow you to generate a mkimage version
- Upon request, STMicroelectronics may provide an executable binary, without warranty nor support.
Here a procedure to rebuild U-Boot with a new DTS (generated with CubeMX for exemple).
- inputs: u-boot sources + patches, u-boot-nodtb.bin, u-boot dts
- host tools required: tar, patch, gcc (anyone), mkimage (with stm32 support), dtc
Here a zipfile with all inputs files used for testing Below the procedure with a mkimage with support of stm32image:
- U-Boot trusted
######################################### ######################################### ######################################### UBOOT ######################################### ######################################### ################### ################### UNPACK + PATCH ################### [frq09494@lmecxl0985 ~/views/DTC] $ mkdir -p u-boot $ tar xf SOURCES-st-image-weston-openstlinux-weston-stm32mp1-openstlinux-4.19-thud-mp1-19-05-31/st-image-weston-openstlinux-weston-stm32mp1-openstlinux-4.19-thud-mp1-19-05-31/sources/arm-openstlinux_weston-linux-gnueabi/u-boot-stm32mp-2018.11-r0/v2018.11.tar.gz -C u-boot $ mv u-boot/u-boot* u-boot/u-boot-sources/ $ pushd u-boot/u-boot-sources for p in $(ls -1 ../../SOURCES-st-image-weston-openstlinux-weston-stm32mp1-openstlinux-4.19-thud-mp1-19-05-31/st-image-weston-openstlinux-weston-stm32mp1-openstlinux-4.19-thud-mp1-19-05-31/sources/arm-openstlinux_weston-linux-gnueabi/u-boot-stm32mp-2018.11-r0/*.patch); do patch -p1 < $p; done $ popd ################### ################### GENERATE DTB ################### [frq09494@lmecxl0985 ~/views/DTC/u-boot] $ mkdir -p u-boot $ pushd u-boot $ cp -r ../MyDeviceTree_fromCubeMX/u-boot dts [frq09494@lmecxl0985 ~/views/DTC/u-boot] $ ll dts total 36 -rw-r--r-- 1 frq09494 frq09494 25968 Jun 7 17:32 stm32mp157c-mydevicetree-mx.dts -rw-r--r-- 1 frq09494 frq09494 3642 Jun 7 17:32 stm32mp157c-mydevicetree-mx-u-boot.dtsi -rw-r--r-- 1 frq09494 frq09494 3511 Jun 7 17:32 stm32mp15-mx.h ## include dtsi u-boot file into dts of u-boot $ echo '#include "stm32mp157c-mydevicetree-mx-u-boot.dtsi"' >> dts/stm32mp157c-mydevicetree-mx.dts $ gcc -E -nostdinc -I u-boot-sources/include/ -I u-boot-sources/arch/arm/dts -I dts -undef -D__DTS__ -x assembler-with-cpp -o stm32mp157c-mydevicetree-mx.dts.tmp dts/stm32mp157c-mydevicetree-mx.dts $ dtc -I dts -O dtb -o u-boot.dtb stm32mp157c-mydevicetree-mx.dts.tmp ################### ################### REBUILD UBOOT.stm32 ################### [frq09494@lmecxl0985 ~/views/DTC/u-boot] $ cat u-boot-nodtb.bin u-boot.dtb > u-boot-dtb.bin ## SYS_TEXT_BASE=0xC0100000 is the addr of u-boot in memory (should never change) $ export SYS_TEXT_BASE=0xC0100000 $ mkimage -T stm32image -a $SYS_TEXT_BASE -e $SYS_TEXT_BASE -d u-boot-dtb.bin u-boot.stm32
- Because of 'extlinux' before flashing the new u-boot.stm32, an extlinux entry should be add in bootfs to be able to boot on new devicetree
- First get the 'compatible' of the devicetree from dts file. At the head of the file, look for the 'compatible = ' line. The compatible should looks like something as : "st,stm32mp157c-mydevicetree-mx"
* Add a new entry in extlinux.conf file located in /boot/mmc0_stm32mp157c-dk2_extlinux/. If the mmc0_<something> directory is not available, add the new entry in /boot/extlinux/extlinux.conf.
menu title Select the boot mode MENU BACKGROUND ../splash.bmp TIMEOUT 20 DEFAULT stm32mp157c-mydevicetree-mx LABEL stm32mp157c-dk2-sdcard KERNEL /uImage FDT /stm32mp157c-dk2.dtb APPEND root=/dev/mmcblk0p6 rootwait rw console=ttySTM0,115200 LABEL stm32mp157c-dk2-a7-examples-sdcard KERNEL /uImage FDT /stm32mp157c-dk2-a7-examples.dtb APPEND root=/dev/mmcblk0p6 rootwait rw console=ttySTM0,115200 LABEL stm32mp157c-dk2-m4-examples-sdcard KERNEL /uImage FDT /stm32mp157c-dk2-m4-examples.dtb APPEND root=/dev/mmcblk0p6 rootwait rw console=ttySTM0,115200 LABEL stm32mp157c-mydevicetree-mx KERNEL /uImage FDT /stm32mp157c-mydevicetree-mx.dtb APPEND root=/dev/mmcblk0p6 rootwait rw console=ttySTM0,115200
6. TF-A device tree update[edit source]
This operation is not supported. It is currently not possible to modify TF-A device tree without recompiling TF-A module.