1 SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
3 # Copyright (C) 2018 STMicroelectronics - All Rights Reserved
6 U-Boot on STMicroelectronics STM32MP1
7 ======================================
11 This is a quick instruction for setup stm32mp1 boards.
15 U-Boot supports one STMP32MP1 SoCs: STM32MP157
17 The STM32MP157 is a Cortex-A MPU aimed at various applications.
19 - Dual core Cortex-A7 application core
20 - 2D/3D image composition with GPU
21 - Standard memories interface support
22 - Standard connectivity, widely inherited from the STM32 MCU family
23 - Comprehensive security support
25 Everything is supported in Linux but U-Boot is limited to:
27 2. SDCard/MMC controller (SDMMC)
29 And the necessary drivers
31 2. STPMIC1 (PMIC and regulator)
32 3. Clock, Reset, Sysreset
35 Currently the following boards are supported:
42 BootRom => FSBL in SYSRAM => SSBL in DDR => OS (Linux Kernel)
44 with FSBL = First Stage Bootloader
45 SSBL = Second Stage Bootloader
47 2 boot configurations are supported:
49 1) The "Trusted" boot chain (defconfig_file : stm32mp15_trusted_defconfig)
50 BootRom => FSBL = Trusted Firmware-A (TF-A) => SSBL = U-Boot
51 TF-A performs a full initialization of Secure peripherals and installs a
53 U-Boot is running in normal world and uses TF-A monitor
54 to access to secure resources
56 2) The "Basic" boot chain (defconfig_file : stm32mp15_basic_defconfig)
57 BootRom => FSBL = U-Boot SPL => SSBL = U-Boot
58 SPL has limited security initialisation
59 U-Boot is running in secure mode and provide a secure monitor to the kernel
60 with only PSCI support (Power State Coordination Interface defined by ARM)
62 All the STM32MP1 boards supported by U-Boot use the same generic board
63 stm32mp1 which support all the bootable devices.
65 Each board is configurated only with the associated device tree.
67 4. Device Tree Selection
68 ========================
70 You need to select the appropriate device tree for your board,
71 the supported device trees for stm32mp157 are:
73 + ev1: eval board with pmic stpmic1 (ev1 = mother board + daughter ed1)
76 + ed1: daughter board with pmic stpmic1
82 1. Install required tools for U-Boot
84 + install package needed in U-Boot makefile
85 (libssl-dev, swig, libpython-dev...)
86 + install ARMv7 toolchain for 32bit Cortex-A (from Linaro,
87 from SDK for STM32MP1, or any crosstoolchains from your distribution)
89 2. Set the cross compiler:
91 # export CROSS_COMPILE=/path/to/toolchain/arm-linux-gnueabi-
92 (you can use any gcc cross compiler compatible with U-Boot)
94 3. Select the output directory (optional)
96 # export KBUILD_OUTPUT=/path/to/output
98 for example: use one output directory for each configuration
99 # export KBUILD_OUTPUT=stm32mp15_trusted
100 # export KBUILD_OUTPUT=stm32mp15_basic
104 # make <defconfig_file>
106 - For trusted boot mode : "stm32mp15_trusted_defconfig"
107 - For basic boot mode: "stm32mp15_basic_defconfig"
109 5. Configure the device-tree and build the U-Boot image:
111 # make DEVICE_TREE=<name> all
115 a) trusted boot on ev1
116 # export KBUILD_OUTPUT=stm32mp15_trusted
117 # make stm32mp15_trusted_defconfig
118 # make DEVICE_TREE=stm32mp157c-ev1 all
121 # export KBUILD_OUTPUT=stm32mp15_basic
122 # make stm32mp15_basic_defconfig
123 # make DEVICE_TREE=stm32mp157c-ev1 all
126 # export KBUILD_OUTPUT=stm32mp15_basic
127 # make stm32mp15_basic_defconfig
128 # make DEVICE_TREE=stm32mp157c-ed1 all
132 BootRom and TF-A expect binaries with STM32 image header
133 SPL expects file with U-Boot uImage header
135 So in the output directory (selected by KBUILD_OUTPUT),
136 you can found the needed files:
139 + FSBL = tf-a.stm32 (provided by TF-A compilation)
140 + SSBL = u-boot.stm32
143 + FSBL = spl/u-boot-spl.stm32
146 6. Switch Setting for Boot Mode
147 ===============================
149 You can select the boot mode, on the board ed1 with the switch SW1
151 -----------------------------------
152 Boot Mode BOOT2 BOOT1 BOOT0
153 -----------------------------------
162 Recovery is a boot from serial link (UART/USB) and it is used with
163 STM32CubeProgrammer tool to load executable in RAM and to update the flash
164 devices available on the board (NOR/NAND/eMMC/SDCARD).
165 The communication between HOST and board is based on
166 - for UARTs : the uart protocol used with all MCU STM32
167 - for USB : based on USB DFU 1.1 (without the ST extensions used on MCU STM32)
172 The minimal requirements for STMP32MP1 boot up to U-Boot are:
173 - GPT partitioning (with gdisk or with sgdisk)
174 - 2 fsbl partitions, named fsbl1 and fsbl2, size at least 256KiB
175 - one ssbl partition for U-Boot
177 Then the minimal GPT partition is:
178 ----- ------- --------- --------------
179 | Num | Name | Size | Content |
180 ----- ------- -------- ---------------
181 | 1 | fsbl1 | 256 KiB | TF-A or SPL |
182 | 2 | fsbl2 | 256 KiB | TF-A or SPL |
183 | 3 | ssbl | enought | U-Boot |
184 | * | - | - | Boot/Rootfs |
185 ----- ------- --------- --------------
187 (*) add bootable partition for extlinux.conf
188 following Generic Distribution
189 (doc/README.distro for use)
191 according the used card reader select the block device
192 (/dev/sdx or /dev/mmcblk0)
193 in the next example I use /dev/mmcblk0
195 for example: with gpt table with 128 entries
197 a) remove previous formatting
198 # sgdisk -o /dev/<SDCard dev>
200 b) create minimal image
201 # sgdisk --resize-table=128 -a 1 \
202 -n 1:34:545 -c 1:fsbl1 \
203 -n 2:546:1057 -c 2:fsbl2 \
204 -n 3:1058:5153 -c 3:ssbl \
207 you can add other partitions for kernel
208 one partition rootfs for example:
209 -n 4:5154: -c 4:rootfs \
211 c) copy the FSBL (2 times) and SSBL file on the correct partition.
212 in this example in partition 1 to 3
214 for basic boot mode : <SDCard dev> = /dev/mmcblk0
215 # dd if=u-boot-spl.stm32 of=/dev/mmcblk0p1
216 # dd if=u-boot-spl.stm32 of=/dev/mmcblk0p2
217 # dd if=u-boot.img of=/dev/mmcblk0p3
219 for trusted boot mode :
220 # dd if=tf-a.stm32 of=/dev/mmcblk0p1
221 # dd if=tf-a.stm32 of=/dev/mmcblk0p2
222 # dd if=u-boot.stm32 of=/dev/mmcblk0p3
224 To boot from SDCard, select BootPinMode = 1 1 1 and reset.
228 You can use U-Boot to copy binary in eMMC.
230 In the next example, you need to boot from SDCARD and the images (u-boot-spl.stm32, u-boot.img)
231 are presents on SDCARD (mmc 0) in ext4 partition 4 (bootfs).
233 To boot from SDCard, select BootPinMode = 1 0 1 and reset.
235 Then you update the eMMC with the next U-Boot command :
237 a) prepare GPT on eMMC,
238 example with 2 partitions, bootfs and roots:
240 # setenv emmc_part "name=ssbl,size=2MiB;name=bootfs,type=linux,bootable,size=64MiB;name=rootfs,type=linux,size=512"
241 # gpt write mmc 1 ${emmc_part}
243 b) copy SPL on eMMC on firts boot partition
244 (SPL max size is 256kB, with LBA 512, 0x200)
246 # ext4load mmc 0:4 0xC0000000 u-boot-spl.stm32
248 # mmc partconf 1 1 1 1
249 # mmc write ${fileaddr} 0 200
250 # mmc partconf 1 1 1 0
252 c) copy U-Boot in first GPT partition of eMMC
254 # ext4load mmc 0:4 0xC0000000 u-boot.img
256 # part start mmc 1 1 partstart
257 # part size mmc 1 1 partsize
258 # mmc write ${fileaddr} ${partstart} ${partsize}
260 To boot from eMMC, select BootPinMode = 0 1 0 and reset.
265 Please read doc/README.enetaddr for the implementation guidelines for mac id
266 usage. Basically, environment has precedence over board specific storage.
268 Mac id storage and retrieval in stm32mp otp :
269 - OTP_57[31:0] = MAC_ADDR[31:0]
270 - OTP_58[15:0] = MAC_ADDR[47:32]
272 To program a MAC address on virgin OTP words above, you can use the fuse command
273 on bank 0 to access to internal OTP:
275 example to set mac address "12:34:56:78:9a:bc"
278 STM32MP> fuse prog -y 0 57 0x78563412 0x0000bc9a
281 STM32MP> fuse sense 0 57 2
283 Word 0x00000039: 78563412 0000bc9a
286 ### Setting environment from OTP MAC address = "12:34:56:78:9a:bc"
289 STM32MP> print ethaddr
290 ethaddr=12:34:56:78:9a:bc