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)
28 3. NAND controller (FMC)
29 4. NOR controller (QSPI)
30 5. USB controller (OTG DWC2)
31 6. Ethernet controller
33 And the necessary drivers
35 2. STPMIC1 (PMIC and regulator)
36 3. Clock, Reset, Sysreset
39 Currently the following boards are supported:
44 + stm32mp157a-avenger96
49 BootRom => FSBL in SYSRAM => SSBL in DDR => OS (Linux Kernel)
51 with FSBL = First Stage Bootloader
52 SSBL = Second Stage Bootloader
54 3 boot configurations are supported:
56 1) The "Trusted" boot chain (defconfig_file : stm32mp15_trusted_defconfig)
57 BootRom => FSBL = Trusted Firmware-A (TF-A) => SSBL = U-Boot
58 TF-A performs a full initialization of Secure peripherals and installs a
60 U-Boot is running in normal world and uses TF-A monitor
61 to access to secure resources.
63 2) The "Trusted" boot chain with OP-TEE
64 (defconfig_file : stm32mp15_optee_defconfig)
65 BootRom => FSBL = Trusted Firmware-A (TF-A) => SSBL = U-Boot
66 TF-A performs a full initialization of Secure peripherals and installs OP-TEE
67 from specific partitions (teeh, teed, teex).
68 U-Boot is running in normal world and uses OP-TEE monitor to access
71 3) The "Basic" boot chain (defconfig_file : stm32mp15_basic_defconfig)
72 BootRom => FSBL = U-Boot SPL => SSBL = U-Boot
73 SPL has limited security initialisation
74 U-Boot is running in secure mode and provide a secure monitor to the kernel
75 with only PSCI support (Power State Coordination Interface defined by ARM).
77 All the STM32MP1 boards supported by U-Boot use the same generic board
78 stm32mp1 which support all the bootable devices.
80 Each board is configurated only with the associated device tree.
82 4. Device Tree Selection
83 ========================
85 You need to select the appropriate device tree for your board,
86 the supported device trees for stm32mp157 are:
88 + ev1: eval board with pmic stpmic1 (ev1 = mother board + daughter ed1)
91 + ed1: daughter board with pmic stpmic1
94 + dk1: Discovery board
97 + dk2: Discovery board = dk1 with a BT/WiFI combo and a DSI panel
100 + avenger96: Avenger96 board from Arrow Electronics
101 dts: stm32mp157a-avenger96
106 1. Install required tools for U-Boot
108 + install package needed in U-Boot makefile
109 (libssl-dev, swig, libpython-dev...)
110 + install ARMv7 toolchain for 32bit Cortex-A (from Linaro,
111 from SDK for STM32MP1, or any crosstoolchains from your distribution)
113 2. Set the cross compiler:
115 # export CROSS_COMPILE=/path/to/toolchain/arm-linux-gnueabi-
116 (you can use any gcc cross compiler compatible with U-Boot)
118 3. Select the output directory (optional)
120 # export KBUILD_OUTPUT=/path/to/output
122 for example: use one output directory for each configuration
123 # export KBUILD_OUTPUT=stm32mp15_trusted
124 # export KBUILD_OUTPUT=stm32mp15_optee
125 # export KBUILD_OUTPUT=stm32mp15_basic
127 you can build outside of code directory:
128 # export KBUILD_OUTPUT=../build/stm32mp15_trusted
132 # make <defconfig_file>
134 - For trusted boot mode : "stm32mp15_trusted_defconfig"
135 - For trusted with OP-TEE boot mode : "stm32mp15_optee_defconfig"
136 - For basic boot mode: "stm32mp15_basic_defconfig"
138 5. Configure the device-tree and build the U-Boot image:
140 # make DEVICE_TREE=<name> all
143 a) trusted boot on ev1
144 # export KBUILD_OUTPUT=stm32mp15_trusted
145 # make stm32mp15_trusted_defconfig
146 # make DEVICE_TREE=stm32mp157c-ev1 all
148 b) trusted with OP-TEE boot on dk2
149 # export KBUILD_OUTPUT=stm32mp15_optee
150 # make stm32mp15_optee_defconfig
151 # make DEVICE_TREE=stm32mp157c-dk2 all
154 # export KBUILD_OUTPUT=stm32mp15_basic
155 # make stm32mp15_basic_defconfig
156 # make DEVICE_TREE=stm32mp157c-ev1 all
159 # export KBUILD_OUTPUT=stm32mp15_basic
160 # make stm32mp15_basic_defconfig
161 # make DEVICE_TREE=stm32mp157c-ed1 all
164 # export KBUILD_OUTPUT=stm32mp15_basic
165 # make stm32mp15_basic_defconfig
166 # make DEVICE_TREE=stm32mp157a-dk1 all
168 f) basic boot on avenger96
169 # export KBUILD_OUTPUT=stm32mp15_basic
170 # make stm32mp15_basic_defconfig
171 # make DEVICE_TREE=stm32mp157a-avenger96 all
175 BootRom and TF-A expect binaries with STM32 image header
176 SPL expects file with U-Boot uImage header
178 So in the output directory (selected by KBUILD_OUTPUT),
179 you can found the needed files:
181 a) For Trusted boot (with or without OP-TEE)
182 + FSBL = tf-a.stm32 (provided by TF-A compilation)
183 + SSBL = u-boot.stm32
186 + FSBL = spl/u-boot-spl.stm32
189 6. Switch Setting for Boot Mode
190 ===============================
192 You can select the boot mode, on the board with one switch :
194 - on the daugther board ed1 with the switch SW1 : BOOT0, BOOT1, BOOT2
196 -----------------------------------
197 Boot Mode BOOT2 BOOT1 BOOT0
198 -----------------------------------
207 - on board DK1/DK2 with the switch SW1 : BOOT0, BOOT2
208 (BOOT1 forced to 0, NOR not supported)
210 --------------------------
211 Boot Mode BOOT2 BOOT0
212 --------------------------
217 - Boot mode of Avenger96 can be selected using switch S3
219 -----------------------------------
220 Boot Mode BOOT2 BOOT1 BOOT0
221 -----------------------------------
231 Recovery is a boot from serial link (UART/USB) and it is used with
232 STM32CubeProgrammer tool to load executable in RAM and to update the flash
233 devices available on the board (NOR/NAND/eMMC/SDCARD).
234 The communication between HOST and board is based on
235 - for UARTs : the uart protocol used with all MCU STM32
236 - for USB : based on USB DFU 1.1 (without the ST extensions used on MCU STM32)
241 The minimal requirements for STMP32MP1 boot up to U-Boot are:
242 - GPT partitioning (with gdisk or with sgdisk)
243 - 2 fsbl partitions, named fsbl1 and fsbl2, size at least 256KiB
244 - one ssbl partition for U-Boot
246 Then the minimal GPT partition is:
247 ----- ------- --------- --------------
248 | Num | Name | Size | Content |
249 ----- ------- -------- ---------------
250 | 1 | fsbl1 | 256 KiB | TF-A or SPL |
251 | 2 | fsbl2 | 256 KiB | TF-A or SPL |
252 | 3 | ssbl | enought | U-Boot |
253 | * | - | - | Boot/Rootfs |
254 ----- ------- --------- --------------
256 (*) add bootable partition for extlinux.conf
257 following Generic Distribution
258 (doc/README.distro for use)
260 according the used card reader select the block device
261 (/dev/sdx or /dev/mmcblk0)
262 in the next example I use /dev/mmcblk0
264 for example: with gpt table with 128 entries
266 a) remove previous formatting
267 # sgdisk -o /dev/<SDCard dev>
269 b) create minimal image
270 # sgdisk --resize-table=128 -a 1 \
271 -n 1:34:545 -c 1:fsbl1 \
272 -n 2:546:1057 -c 2:fsbl2 \
273 -n 3:1058:5153 -c 3:ssbl \
276 you can add other partitions for kernel
277 one partition rootfs for example:
278 -n 4:5154: -c 4:rootfs \
280 c) copy the FSBL (2 times) and SSBL file on the correct partition.
281 in this example in partition 1 to 3
283 for basic boot mode : <SDCard dev> = /dev/mmcblk0
284 # dd if=u-boot-spl.stm32 of=/dev/mmcblk0p1
285 # dd if=u-boot-spl.stm32 of=/dev/mmcblk0p2
286 # dd if=u-boot.img of=/dev/mmcblk0p3
288 for trusted boot mode :
289 # dd if=tf-a.stm32 of=/dev/mmcblk0p1
290 # dd if=tf-a.stm32 of=/dev/mmcblk0p2
291 # dd if=u-boot.stm32 of=/dev/mmcblk0p3
293 To boot from SDCard, select BootPinMode = 1 0 1 and reset.
297 You can use U-Boot to copy binary in eMMC.
299 In the next example, you need to boot from SDCARD and the images (u-boot-spl.stm32, u-boot.img)
300 are presents on SDCARD (mmc 0) in ext4 partition 4 (bootfs).
302 To boot from SDCard, select BootPinMode = 1 0 1 and reset.
304 Then you update the eMMC with the next U-Boot command :
306 a) prepare GPT on eMMC,
307 example with 2 partitions, bootfs and roots:
309 # setenv emmc_part "name=ssbl,size=2MiB;name=bootfs,type=linux,bootable,size=64MiB;name=rootfs,type=linux,size=512"
310 # gpt write mmc 1 ${emmc_part}
312 b) copy SPL on eMMC on firts boot partition
313 (SPL max size is 256kB, with LBA 512, 0x200)
315 # ext4load mmc 0:4 0xC0000000 u-boot-spl.stm32
317 # mmc partconf 1 1 1 1
318 # mmc write ${fileaddr} 0 200
319 # mmc partconf 1 1 1 0
321 c) copy U-Boot in first GPT partition of eMMC
323 # ext4load mmc 0:4 0xC0000000 u-boot.img
325 # part start mmc 1 1 partstart
326 # part size mmc 1 1 partsize
327 # mmc write ${fileaddr} ${partstart} ${partsize}
329 To boot from eMMC, select BootPinMode = 0 1 0 and reset.
334 Please read doc/README.enetaddr for the implementation guidelines for mac id
335 usage. Basically, environment has precedence over board specific storage.
337 Mac id storage and retrieval in stm32mp otp :
338 - OTP_57[31:0] = MAC_ADDR[31:0]
339 - OTP_58[15:0] = MAC_ADDR[47:32]
341 To program a MAC address on virgin OTP words above, you can use the fuse command
342 on bank 0 to access to internal OTP:
344 example to set mac address "12:34:56:78:9a:bc"
347 STM32MP> fuse prog -y 0 57 0x78563412 0x0000bc9a
350 STM32MP> fuse sense 0 57 2
352 Word 0x00000039: 78563412 0000bc9a
355 ### Setting environment from OTP MAC address = "12:34:56:78:9a:bc"
358 STM32MP> print ethaddr
359 ethaddr=12:34:56:78:9a:bc
361 10. Coprocessor firmware
362 ========================
364 U-Boot can boot the coprocessor before the kernel (coprocessor early boot).
366 A/ Manuallly by using rproc commands (update the bootcmd)
368 # env set name_copro "rproc-m4-fw.elf"
369 # env set dev_copro 0
370 # env set loadaddr_copro 0xC1000000
372 Load binary from bootfs partition (number 4) on SDCard (mmc 0)
373 # ext4load mmc 0:4 ${loadaddr_copro} ${name_copro}
374 => ${filesize} updated with the size of the loaded file
376 Start M4 firmware with remote proc command
378 # rproc load ${dev_copro} ${loadaddr_copro} ${filesize}
379 # rproc start ${dev_copro}
381 B/ Automatically by using FIT feature and generic DISTRO bootcmd
383 see examples in this directory :
385 Generate FIT including kernel + device tree + M4 firmware
386 with cfg with M4 boot
387 $> mkimage -f fit_copro_kernel_dtb.its fit_copro_kernel_dtb.itb
389 Then using DISTRO configuration file: see extlinux.conf to select
390 the correct configuration
391 => stm32mp157c-ev1-m4
392 => stm32mp157c-dk2-m4
397 The DFU is supported on ST board.
398 The env variable dfu_alt_info is automatically build, and all
399 the memory present on the ST boards are exported.
401 The mode is started by
409 DFU alt settings list:
410 dev: RAM alt: 0 name: uImage layout: RAM_ADDR
411 dev: RAM alt: 1 name: devicetree.dtb layout: RAM_ADDR
412 dev: RAM alt: 2 name: uramdisk.image.gz layout: RAM_ADDR
413 dev: eMMC alt: 3 name: sdcard_fsbl1 layout: RAW_ADDR
414 dev: eMMC alt: 4 name: sdcard_fsbl2 layout: RAW_ADDR
415 dev: eMMC alt: 5 name: sdcard_ssbl layout: RAW_ADDR
416 dev: eMMC alt: 6 name: sdcard_bootfs layout: RAW_ADDR
417 dev: eMMC alt: 7 name: sdcard_vendorfs layout: RAW_ADDR
418 dev: eMMC alt: 8 name: sdcard_rootfs layout: RAW_ADDR
419 dev: eMMC alt: 9 name: sdcard_userfs layout: RAW_ADDR
420 dev: eMMC alt: 10 name: emmc_fsbl1 layout: RAW_ADDR
421 dev: eMMC alt: 11 name: emmc_fsbl2 layout: RAW_ADDR
422 dev: eMMC alt: 12 name: emmc_ssbl layout: RAW_ADDR
423 dev: eMMC alt: 13 name: emmc_bootfs layout: RAW_ADDR
424 dev: eMMC alt: 14 name: emmc_vendorfs layout: RAW_ADDR
425 dev: eMMC alt: 15 name: emmc_rootfs layout: RAW_ADDR
426 dev: eMMC alt: 16 name: emmc_userfs layout: RAW_ADDR
427 dev: MTD alt: 17 name: nor_fsbl1 layout: RAW_ADDR
428 dev: MTD alt: 18 name: nor_fsbl2 layout: RAW_ADDR
429 dev: MTD alt: 19 name: nor_ssbl layout: RAW_ADDR
430 dev: MTD alt: 20 name: nor_env layout: RAW_ADDR
431 dev: MTD alt: 21 name: nand_fsbl layout: RAW_ADDR
432 dev: MTD alt: 22 name: nand_ssbl1 layout: RAW_ADDR
433 dev: MTD alt: 23 name: nand_ssbl2 layout: RAW_ADDR
434 dev: MTD alt: 24 name: nand_UBI layout: RAW_ADDR
435 dev: VIRT alt: 25 name: OTP layout: RAW_ADDR
436 dev: VIRT alt: 26 name: PMIC layout: RAW_ADDR
438 All the supported device are exported for dfu-util tool:
441 Found DFU: [0483:5720] ver=9999, devnum=99, cfg=1, intf=0, alt=26, name="PMIC", serial="002700333338511934383330"
442 Found DFU: [0483:5720] ver=9999, devnum=99, cfg=1, intf=0, alt=25, name="OTP", serial="002700333338511934383330"
443 Found DFU: [0483:5720] ver=9999, devnum=99, cfg=1, intf=0, alt=24, name="nand_UBI", serial="002700333338511934383330"
444 Found DFU: [0483:5720] ver=9999, devnum=99, cfg=1, intf=0, alt=23, name="nand_ssbl2", serial="002700333338511934383330"
445 Found DFU: [0483:5720] ver=9999, devnum=99, cfg=1, intf=0, alt=22, name="nand_ssbl1", serial="002700333338511934383330"
446 Found DFU: [0483:5720] ver=9999, devnum=99, cfg=1, intf=0, alt=21, name="nand_fsbl", serial="002700333338511934383330"
447 Found DFU: [0483:5720] ver=9999, devnum=99, cfg=1, intf=0, alt=20, name="nor_env", serial="002700333338511934383330"
448 Found DFU: [0483:5720] ver=9999, devnum=99, cfg=1, intf=0, alt=19, name="nor_ssbl", serial="002700333338511934383330"
449 Found DFU: [0483:5720] ver=9999, devnum=99, cfg=1, intf=0, alt=18, name="nor_fsbl2", serial="002700333338511934383330"
450 Found DFU: [0483:5720] ver=9999, devnum=99, cfg=1, intf=0, alt=17, name="nor_fsbl1", serial="002700333338511934383330"
451 Found DFU: [0483:5720] ver=9999, devnum=99, cfg=1, intf=0, alt=16, name="emmc_userfs", serial="002700333338511934383330"
452 Found DFU: [0483:5720] ver=9999, devnum=99, cfg=1, intf=0, alt=15, name="emmc_rootfs", serial="002700333338511934383330"
453 Found DFU: [0483:5720] ver=9999, devnum=99, cfg=1, intf=0, alt=14, name="emmc_vendorfs", serial="002700333338511934383330"
454 Found DFU: [0483:5720] ver=9999, devnum=99, cfg=1, intf=0, alt=13, name="emmc_bootfs", serial="002700333338511934383330"
455 Found DFU: [0483:5720] ver=9999, devnum=99, cfg=1, intf=0, alt=12, name="emmc_ssbl", serial="002700333338511934383330"
456 Found DFU: [0483:5720] ver=9999, devnum=99, cfg=1, intf=0, alt=11, name="emmc_fsbl2", serial="002700333338511934383330"
457 Found DFU: [0483:5720] ver=9999, devnum=99, cfg=1, intf=0, alt=10, name="emmc_fsbl1", serial="002700333338511934383330"
458 Found DFU: [0483:5720] ver=9999, devnum=99, cfg=1, intf=0, alt=9, name="sdcard_userfs", serial="002700333338511934383330"
459 Found DFU: [0483:5720] ver=9999, devnum=99, cfg=1, intf=0, alt=8, name="sdcard_rootfs", serial="002700333338511934383330"
460 Found DFU: [0483:5720] ver=9999, devnum=99, cfg=1, intf=0, alt=7, name="sdcard_vendorfs", serial="002700333338511934383330"
461 Found DFU: [0483:5720] ver=9999, devnum=99, cfg=1, intf=0, alt=6, name="sdcard_bootfs", serial="002700333338511934383330"
462 Found DFU: [0483:5720] ver=9999, devnum=99, cfg=1, intf=0, alt=5, name="sdcard_ssbl", serial="002700333338511934383330"
463 Found DFU: [0483:5720] ver=9999, devnum=99, cfg=1, intf=0, alt=4, name="sdcard_fsbl2", serial="002700333338511934383330"
464 Found DFU: [0483:5720] ver=9999, devnum=99, cfg=1, intf=0, alt=3, name="sdcard_fsbl1", serial="002700333338511934383330"
465 Found DFU: [0483:5720] ver=9999, devnum=99, cfg=1, intf=0, alt=2, name="uramdisk.image.gz", serial="002700333338511934383330"
466 Found DFU: [0483:5720] ver=9999, devnum=99, cfg=1, intf=0, alt=1, name="devicetree.dtb", serial="002700333338511934383330"
467 Found DFU: [0483:5720] ver=9999, devnum=99, cfg=1, intf=0, alt=0, name="uImage", serial="002700333338511934383330"
469 You can update the boot device:
472 $> dfu-util -d 0483:5720 -a 3 -D tf-a-stm32mp157c-ev1-trusted.stm32
473 $> dfu-util -d 0483:5720 -a 4 -D tf-a-stm32mp157c-ev1-trusted.stm32
474 $> dfu-util -d 0483:5720 -a 5 -D u-boot-stm32mp157c-ev1-trusted.img
475 $> dfu-util -d 0483:5720 -a 6 -D st-image-bootfs-openstlinux-weston-stm32mp1.ext4
476 $> dfu-util -d 0483:5720 -a 7 -D st-image-vendorfs-openstlinux-weston-stm32mp1.ext4
477 $> dfu-util -d 0483:5720 -a 8 -D st-image-weston-openstlinux-weston-stm32mp1.ext4
478 $> dfu-util -d 0483:5720 -a 9 -D st-image-userfs-openstlinux-weston-stm32mp1.ext4
481 $> dfu-util -d 0483:5720 -a 10 -D tf-a-stm32mp157c-ev1-trusted.stm32
482 $> dfu-util -d 0483:5720 -a 11 -D tf-a-stm32mp157c-ev1-trusted.stm32
483 $> dfu-util -d 0483:5720 -a 12 -D u-boot-stm32mp157c-ev1-trusted.img
484 $> dfu-util -d 0483:5720 -a 13 -D st-image-bootfs-openstlinux-weston-stm32mp1.ext4
485 $> dfu-util -d 0483:5720 -a 14 -D st-image-vendorfs-openstlinux-weston-stm32mp1.ext4
486 $> dfu-util -d 0483:5720 -a 15 -D st-image-weston-openstlinux-weston-stm32mp1.ext4
487 $> dfu-util -d 0483:5720 -a 16 -D st-image-userfs-openstlinux-weston-stm32mp1.ext4
490 $> dfu-util -d 0483:5720 -a 17 -D tf-a-stm32mp157c-ev1-trusted.stm32
491 $> dfu-util -d 0483:5720 -a 18 -D tf-a-stm32mp157c-ev1-trusted.stm32
492 $> dfu-util -d 0483:5720 -a 19 -D u-boot-stm32mp157c-ev1-trusted.img
494 #NAND (UBI partition used for NAND only boot or NOR + NAND boot)
495 $> dfu-util -d 0483:5720 -a 21 -D tf-a-stm32mp157c-ev1-trusted.stm32
496 $> dfu-util -d 0483:5720 -a 22 -D u-boot-stm32mp157c-ev1-trusted.img
497 $> dfu-util -d 0483:5720 -a 23 -D u-boot-stm32mp157c-ev1-trusted.img
498 $> dfu-util -d 0483:5720 -a 24 -D st-image-weston-openstlinux-weston-stm32mp1_nand_4_256_multivolume.ubi
500 And you can also dump the OTP and the PMIC NVM with:
502 $> dfu-util -d 0483:5720 -a 25 -U otp.bin
503 $> dfu-util -d 0483:5720 -a 26 -U pmic.bin