1# 2# Copyright (C) 2018 STMicroelectronics - All Rights Reserved 3# 4# SPDX-License-Identifier: GPL-2.0+ BSD-3-Clause 5# 6 7U-Boot on STMicroelectronics STM32MP1 8====================================== 9 101. Summary 11========== 12This is a quick instruction for setup stm32mp1 boards. 13 142. Supported devices 15==================== 16U-Boot supports one STMP32MP1 SoCs: STM32MP157 17 18The STM32MP157 is a Cortex-A MPU aimed at various applications. 19It features: 20- Dual core Cortex-A7 application core 21- 2D/3D image composition with GPU 22- Standard memories interface support 23- Standard connectivity, widely inherited from the STM32 MCU family 24- Comprehensive security support 25 26Everything is supported in Linux but U-Boot is limited to: 271. UART 282. SDCard/MMC controller (SDMMC) 29 30And the necessary drivers 311. I2C 322. STPMU1 333. Clock, Reset 34 35Currently the following boards are supported: 36+ stm32mp157c-ed1 37 383. Boot Sequences 39================= 40 41BootRom => FSBL in SYSRAM => SSBL in DDR => OS (Linux Kernel) 42 43with FSBL = First Stage Bootloader 44 SSBL = Second Stage Bootloader 45 46One boot configuration is supported: 47 48 The "Basic" boot chain (defconfig_file : stm32mp15_basic_defconfig) 49 BootRom => FSBL = U-Boot SPL => SSBL = U-Boot 50 SPL has limited security initialisation 51 U-Boot is running in secure mode and provide a secure monitor to the kernel 52 with only PSCI support (Power State Coordination Interface defined by ARM) 53 54All the STM32MP1 board supported by U-Boot use the same generic board 55stm32mp1 which support all the bootable devices. 56 57Each board is configurated only with the associated device tree. 58 594. Device Tree Selection 60======================== 61 62You need to select the appropriate device tree for your board, 63the supported device trees for stm32mp157 are: 64 65+ ed1: daughter board with pmic stpmu1 66 dts: stm32mp157c-ed1 67 685. Build Procedure 69================== 70 711. Install required tools for U-Boot 72 73 + install package needed in U-Boot makefile 74 (libssl-dev, swig, libpython-dev...) 75 + install ARMv7 toolchain for 32bit Cortex-A (from Linaro, 76 from SDK for STM32MP1, or any crosstoolchains from your distribution) 77 782. Set the cross compiler: 79 80 # export CROSS_COMPILE=/path/to/toolchain/arm-linux-gnueabi- 81 (you can use any gcc cross compiler compatible with U-Boot) 82 833. Select the output directory (optional) 84 85 # export KBUILD_OUTPUT=/path/to/output 86 87 for example: use one output directory for each configuration 88 # export KBUILD_OUTPUT=stm32mp15_basic 89 904. Configure the U-Boot: 91 92 # make <defconfig_file> 93 94 - For basic boot mode: "stm32mp15_basic_defconfig" 95 965. Configure the device-tree and build the U-Boot image: 97 98 # make DEVICE_TREE=<name> all 99 100 101 example: 102 basic boot on ed1 103 # export KBUILD_OUTPUT=stm32mp15_basic 104 # make stm32mp15_basic_defconfig 105 # make DEVICE_TREE=stm32mp157c-ed1 all 106 1076. Output files 108 109 BootRom and ATF expect binaries with STM32 image header 110 SPL expects file with U-Boot uImage header 111 112 So in the output directory (selected by KBUILD_OUTPUT), 113 you can found the needed files: 114 115 + FSBL = spl/u-boot-spl.stm32 116 + SSBL = u-boot.img 117 1186. Switch Setting for Boot Mode 119=============================== 120 121You can select the boot mode, on the board ed1 with the switch SW1 122 123 ----------------------------------- 124 Boot Mode BOOT2 BOOT1 BOOT0 125 ----------------------------------- 126 Reserved 0 0 0 127 NOR 0 0 1 128 SD-Card 1 1 1 129 SD-Card 1 0 1 130 eMMC 0 1 0 131 NAND 0 1 1 132 Recovery 1 1 0 133 Recovery 0 0 0 134 135Recovery is a boot from serial link (UART/USB) and it is used with 136STM32CubeProgrammer tool to load executable in RAM and to update the flash 137devices available on the board (NOR/NAND/eMMC/SDCARD). 138The communication between HOST and board is based on 139- for UARTs : the uart protocol used with all MCU STM32 140- for USB : based on USB DFU 1.1 (without the ST extensions used on MCU STM32) 141 1427. Prepare an SDCard 143=================== 144 145The minimal requirements for STMP32MP1 boot up to U-Boot are: 146- GPT partitioning (with gdisk or with sgdisk) 147- 2 fsbl partitions, named fsbl1 and fsbl2, size at least 256KiB 148- one ssbl partition for U-Boot 149 150Then the minimal GPT partition is: 151 ----- ------- --------- ------------- 152 | Num | Name | Size | Content | 153 ----- ------- -------- -------------- 154 | 1 | fsbl1 | 256 KiB | ATF or SPL | 155 | 2 | fsbl2 | 256 KiB | ATF or SPL | 156 | 3 | ssbl | enought | U-Boot | 157 | * | - | - | Boot/Rootfs| 158 ----- ------- --------- ------------- 159 160(*) add bootable partition for extlinux.conf 161 following Generic Distribution 162 (doc/README.distro for use) 163 164 according the used card reader select the block device 165 (/dev/sdx or /dev/mmcblk0) 166 in the next example I use /dev/mmcblk0 167 168for example: with gpt table with 128 entries 169 170 a) remove previous formatting 171 # sgdisk -o /dev/<SDCard dev> 172 173 b) create minimal image 174 # sgdisk --resize-table=128 -a 1 \ 175 -n 1:34:545 -c 1:fsbl1 \ 176 -n 2:546:1057 -c 2:fsbl2 \ 177 -n 3:1058:5153 -c 3:ssbl \ 178 -p /dev/<SDCard dev> 179 180 you can add other partition for kernel (rootfs for example) 181 182 c) copy the FSBL (2 times) and SSBL file on the correct partition. 183 in this example in partition 1 to 3 184 185 for basic boot mode : <SDCard dev> = /dev/mmcblk0 186 # dd if=u-boot-spl.stm32 of=/dev/mmcblk0p1 187 # dd if=u-boot-spl.stm32 of=/dev/mmcblk0p2 188 # dd if=u-boot.img of=/dev/mmcblk0p3 189 190To boot from SDCard, select BootPinMode = 1 1 1 and reset. 191 1928. Prepare eMMC 193=============== 194You can use U-Boot to copy binary in eMMC. 195 196In the next example, you need to boot from SDCARD and the images (u-boot-spl.stm32, u-boot.img) 197are presents on SDCARD (mmc 0) in ext4 partition 4 (bootfs). 198 199To boot from SDCard, select BootPinMode = 1 1 1 and reset. 200 201Then you update the eMMC with the next U-Boot command : 202 203a) prepare GPT on eMMC, 204 example with 2 partitions, bootfs and roots: 205 206 # setenv emmc_part "name=ssbl,size=2MiB;name=bootfs,type=linux,bootable,size=64MiB;name=rootfs,type=linux,size=512" 207 # gpt write mmc 1 ${emmc_part} 208 209b) copy SPL on eMMC on firts boot partition 210 (SPL max size is 256kB, with LBA 512, 0x200) 211 212 # ext4load mmc 0:4 0xC0000000 u-boot-spl.stm32 213 # mmc dev 1 214 # mmc partconf 1 1 1 1 215 # mmc write ${fileaddr} 0 200 216 # mmc partconf 1 1 1 0 217 218b) copy U-Boot in first GPT partition of eMMC 219 220 # ext4load mmc 0:4 0xC0000000 u-boot.img 221 # mmc dev 1 222 # part start mmc 1 1 partstart 223 # part size mmc 1 1 partsize 224 # mmc write ${fileaddr} ${partstart} ${partsize} 225 226To boot from eMMC, select BootPinMode = 0 1 0 and reset. 227