14549e789STom RiniSPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause 2f8598d98SPatrick Delaunay# 3f8598d98SPatrick Delaunay# Copyright (C) 2018 STMicroelectronics - All Rights Reserved 4f8598d98SPatrick Delaunay# 5f8598d98SPatrick Delaunay 6f8598d98SPatrick DelaunayU-Boot on STMicroelectronics STM32MP1 7f8598d98SPatrick Delaunay====================================== 8f8598d98SPatrick Delaunay 9f8598d98SPatrick Delaunay1. Summary 10f8598d98SPatrick Delaunay========== 11f8598d98SPatrick DelaunayThis is a quick instruction for setup stm32mp1 boards. 12f8598d98SPatrick Delaunay 13f8598d98SPatrick Delaunay2. Supported devices 14f8598d98SPatrick Delaunay==================== 15f8598d98SPatrick DelaunayU-Boot supports one STMP32MP1 SoCs: STM32MP157 16f8598d98SPatrick Delaunay 17f8598d98SPatrick DelaunayThe STM32MP157 is a Cortex-A MPU aimed at various applications. 18f8598d98SPatrick DelaunayIt features: 19f8598d98SPatrick Delaunay- Dual core Cortex-A7 application core 20f8598d98SPatrick Delaunay- 2D/3D image composition with GPU 21f8598d98SPatrick Delaunay- Standard memories interface support 22f8598d98SPatrick Delaunay- Standard connectivity, widely inherited from the STM32 MCU family 23f8598d98SPatrick Delaunay- Comprehensive security support 24f8598d98SPatrick Delaunay 25f8598d98SPatrick DelaunayEverything is supported in Linux but U-Boot is limited to: 26f8598d98SPatrick Delaunay1. UART 27f8598d98SPatrick Delaunay2. SDCard/MMC controller (SDMMC) 28f8598d98SPatrick Delaunay 29f8598d98SPatrick DelaunayAnd the necessary drivers 30f8598d98SPatrick Delaunay1. I2C 31f8598d98SPatrick Delaunay2. STPMU1 32*5f16f655SPatrick Delaunay2. STPMU1 (PMIC and regulator) 33*5f16f655SPatrick Delaunay3. Clock, Reset, Sysreset 34*5f16f655SPatrick Delaunay4. Fuse 35f8598d98SPatrick Delaunay 36f8598d98SPatrick DelaunayCurrently the following boards are supported: 37*5f16f655SPatrick Delaunay+ stm32mp157c-ev1 38f8598d98SPatrick Delaunay+ stm32mp157c-ed1 39f8598d98SPatrick Delaunay 40f8598d98SPatrick Delaunay3. Boot Sequences 41f8598d98SPatrick Delaunay================= 42f8598d98SPatrick Delaunay 43f8598d98SPatrick DelaunayBootRom => FSBL in SYSRAM => SSBL in DDR => OS (Linux Kernel) 44f8598d98SPatrick Delaunay 45f8598d98SPatrick Delaunaywith FSBL = First Stage Bootloader 46f8598d98SPatrick Delaunay SSBL = Second Stage Bootloader 47f8598d98SPatrick Delaunay 48f8598d98SPatrick DelaunayOne boot configuration is supported: 49f8598d98SPatrick Delaunay 50f8598d98SPatrick Delaunay The "Basic" boot chain (defconfig_file : stm32mp15_basic_defconfig) 51f8598d98SPatrick Delaunay BootRom => FSBL = U-Boot SPL => SSBL = U-Boot 52f8598d98SPatrick Delaunay SPL has limited security initialisation 53f8598d98SPatrick Delaunay U-Boot is running in secure mode and provide a secure monitor to the kernel 54f8598d98SPatrick Delaunay with only PSCI support (Power State Coordination Interface defined by ARM) 55f8598d98SPatrick Delaunay 56f8598d98SPatrick DelaunayAll the STM32MP1 board supported by U-Boot use the same generic board 57f8598d98SPatrick Delaunaystm32mp1 which support all the bootable devices. 58f8598d98SPatrick Delaunay 59f8598d98SPatrick DelaunayEach board is configurated only with the associated device tree. 60f8598d98SPatrick Delaunay 61f8598d98SPatrick Delaunay4. Device Tree Selection 62f8598d98SPatrick Delaunay======================== 63f8598d98SPatrick Delaunay 64f8598d98SPatrick DelaunayYou need to select the appropriate device tree for your board, 65f8598d98SPatrick Delaunaythe supported device trees for stm32mp157 are: 66f8598d98SPatrick Delaunay 67*5f16f655SPatrick Delaunay+ ev1: eval board with pmic stpmu1 (ev1 = mother board + daughter ed1) 68*5f16f655SPatrick Delaunay dts: stm32mp157c-ev1 69*5f16f655SPatrick Delaunay 70f8598d98SPatrick Delaunay+ ed1: daughter board with pmic stpmu1 71f8598d98SPatrick Delaunay dts: stm32mp157c-ed1 72f8598d98SPatrick Delaunay 73f8598d98SPatrick Delaunay5. Build Procedure 74f8598d98SPatrick Delaunay================== 75f8598d98SPatrick Delaunay 76f8598d98SPatrick Delaunay1. Install required tools for U-Boot 77f8598d98SPatrick Delaunay 78f8598d98SPatrick Delaunay + install package needed in U-Boot makefile 79f8598d98SPatrick Delaunay (libssl-dev, swig, libpython-dev...) 80f8598d98SPatrick Delaunay + install ARMv7 toolchain for 32bit Cortex-A (from Linaro, 81f8598d98SPatrick Delaunay from SDK for STM32MP1, or any crosstoolchains from your distribution) 82f8598d98SPatrick Delaunay 83f8598d98SPatrick Delaunay2. Set the cross compiler: 84f8598d98SPatrick Delaunay 85f8598d98SPatrick Delaunay # export CROSS_COMPILE=/path/to/toolchain/arm-linux-gnueabi- 86f8598d98SPatrick Delaunay (you can use any gcc cross compiler compatible with U-Boot) 87f8598d98SPatrick Delaunay 88f8598d98SPatrick Delaunay3. Select the output directory (optional) 89f8598d98SPatrick Delaunay 90f8598d98SPatrick Delaunay # export KBUILD_OUTPUT=/path/to/output 91f8598d98SPatrick Delaunay 92f8598d98SPatrick Delaunay for example: use one output directory for each configuration 93f8598d98SPatrick Delaunay # export KBUILD_OUTPUT=stm32mp15_basic 94f8598d98SPatrick Delaunay 95f8598d98SPatrick Delaunay4. Configure the U-Boot: 96f8598d98SPatrick Delaunay 97f8598d98SPatrick Delaunay # make <defconfig_file> 98f8598d98SPatrick Delaunay 99f8598d98SPatrick Delaunay - For basic boot mode: "stm32mp15_basic_defconfig" 100f8598d98SPatrick Delaunay 101f8598d98SPatrick Delaunay5. Configure the device-tree and build the U-Boot image: 102f8598d98SPatrick Delaunay 103f8598d98SPatrick Delaunay # make DEVICE_TREE=<name> all 104f8598d98SPatrick Delaunay 105f8598d98SPatrick Delaunay 106f8598d98SPatrick Delaunay example: 107*5f16f655SPatrick Delaunay basic boot on ev1 108*5f16f655SPatrick Delaunay # export KBUILD_OUTPUT=stm32mp15_basic 109*5f16f655SPatrick Delaunay # make stm32mp15_basic_defconfig 110*5f16f655SPatrick Delaunay # make DEVICE_TREE=stm32mp157c-ev1 all 111*5f16f655SPatrick Delaunay 112f8598d98SPatrick Delaunay basic boot on ed1 113f8598d98SPatrick Delaunay # export KBUILD_OUTPUT=stm32mp15_basic 114f8598d98SPatrick Delaunay # make stm32mp15_basic_defconfig 115f8598d98SPatrick Delaunay # make DEVICE_TREE=stm32mp157c-ed1 all 116f8598d98SPatrick Delaunay 117f8598d98SPatrick Delaunay6. Output files 118f8598d98SPatrick Delaunay 119*5f16f655SPatrick Delaunay BootRom and TF-A expect binaries with STM32 image header 120f8598d98SPatrick Delaunay SPL expects file with U-Boot uImage header 121f8598d98SPatrick Delaunay 122f8598d98SPatrick Delaunay So in the output directory (selected by KBUILD_OUTPUT), 123f8598d98SPatrick Delaunay you can found the needed files: 124f8598d98SPatrick Delaunay 125f8598d98SPatrick Delaunay + FSBL = spl/u-boot-spl.stm32 126f8598d98SPatrick Delaunay + SSBL = u-boot.img 127f8598d98SPatrick Delaunay 1280ed232b1SPatrick Delaunay6. Switch Setting for Boot Mode 1290ed232b1SPatrick Delaunay=============================== 1300ed232b1SPatrick Delaunay 1310ed232b1SPatrick DelaunayYou can select the boot mode, on the board ed1 with the switch SW1 1320ed232b1SPatrick Delaunay 1330ed232b1SPatrick Delaunay ----------------------------------- 1340ed232b1SPatrick Delaunay Boot Mode BOOT2 BOOT1 BOOT0 1350ed232b1SPatrick Delaunay ----------------------------------- 1360ed232b1SPatrick Delaunay Reserved 0 0 0 1370ed232b1SPatrick Delaunay NOR 0 0 1 1380ed232b1SPatrick Delaunay SD-Card 1 1 1 1390ed232b1SPatrick Delaunay SD-Card 1 0 1 1400ed232b1SPatrick Delaunay eMMC 0 1 0 1410ed232b1SPatrick Delaunay NAND 0 1 1 1420ed232b1SPatrick Delaunay Recovery 1 1 0 1430ed232b1SPatrick Delaunay Recovery 0 0 0 1440ed232b1SPatrick Delaunay 1450ed232b1SPatrick DelaunayRecovery is a boot from serial link (UART/USB) and it is used with 1460ed232b1SPatrick DelaunaySTM32CubeProgrammer tool to load executable in RAM and to update the flash 1470ed232b1SPatrick Delaunaydevices available on the board (NOR/NAND/eMMC/SDCARD). 1480ed232b1SPatrick DelaunayThe communication between HOST and board is based on 1490ed232b1SPatrick Delaunay- for UARTs : the uart protocol used with all MCU STM32 1500ed232b1SPatrick Delaunay- for USB : based on USB DFU 1.1 (without the ST extensions used on MCU STM32) 1510ed232b1SPatrick Delaunay 1520ed232b1SPatrick Delaunay7. Prepare an SDCard 153f8598d98SPatrick Delaunay=================== 154f8598d98SPatrick Delaunay 155f8598d98SPatrick DelaunayThe minimal requirements for STMP32MP1 boot up to U-Boot are: 156f8598d98SPatrick Delaunay- GPT partitioning (with gdisk or with sgdisk) 157f8598d98SPatrick Delaunay- 2 fsbl partitions, named fsbl1 and fsbl2, size at least 256KiB 158f8598d98SPatrick Delaunay- one ssbl partition for U-Boot 159f8598d98SPatrick Delaunay 160f8598d98SPatrick DelaunayThen the minimal GPT partition is: 161f8598d98SPatrick Delaunay ----- ------- --------- ------------- 162f8598d98SPatrick Delaunay | Num | Name | Size | Content | 163f8598d98SPatrick Delaunay ----- ------- -------- -------------- 164*5f16f655SPatrick Delaunay | 1 | fsbl1 | 256 KiB | TF-A or SPL | 165*5f16f655SPatrick Delaunay | 2 | fsbl2 | 256 KiB | TF-A or SPL | 166f8598d98SPatrick Delaunay | 3 | ssbl | enought | U-Boot | 167f8598d98SPatrick Delaunay | * | - | - | Boot/Rootfs| 168f8598d98SPatrick Delaunay ----- ------- --------- ------------- 169f8598d98SPatrick Delaunay 170f8598d98SPatrick Delaunay(*) add bootable partition for extlinux.conf 171f8598d98SPatrick Delaunay following Generic Distribution 172f8598d98SPatrick Delaunay (doc/README.distro for use) 173f8598d98SPatrick Delaunay 174f8598d98SPatrick Delaunay according the used card reader select the block device 175f8598d98SPatrick Delaunay (/dev/sdx or /dev/mmcblk0) 176f8598d98SPatrick Delaunay in the next example I use /dev/mmcblk0 177f8598d98SPatrick Delaunay 178f8598d98SPatrick Delaunayfor example: with gpt table with 128 entries 179f8598d98SPatrick Delaunay 180f8598d98SPatrick Delaunay a) remove previous formatting 181f8598d98SPatrick Delaunay # sgdisk -o /dev/<SDCard dev> 182f8598d98SPatrick Delaunay 183f8598d98SPatrick Delaunay b) create minimal image 184f8598d98SPatrick Delaunay # sgdisk --resize-table=128 -a 1 \ 185f8598d98SPatrick Delaunay -n 1:34:545 -c 1:fsbl1 \ 186f8598d98SPatrick Delaunay -n 2:546:1057 -c 2:fsbl2 \ 187f8598d98SPatrick Delaunay -n 3:1058:5153 -c 3:ssbl \ 188f8598d98SPatrick Delaunay -p /dev/<SDCard dev> 189f8598d98SPatrick Delaunay 190*5f16f655SPatrick Delaunay you can add other partitions for kernel 191*5f16f655SPatrick Delaunay one partition rootfs for example: 192*5f16f655SPatrick Delaunay -n 3:5154: -c 4:rootfs 193f8598d98SPatrick Delaunay 194f8598d98SPatrick Delaunay c) copy the FSBL (2 times) and SSBL file on the correct partition. 195f8598d98SPatrick Delaunay in this example in partition 1 to 3 196f8598d98SPatrick Delaunay 197f8598d98SPatrick Delaunay for basic boot mode : <SDCard dev> = /dev/mmcblk0 198f8598d98SPatrick Delaunay # dd if=u-boot-spl.stm32 of=/dev/mmcblk0p1 199f8598d98SPatrick Delaunay # dd if=u-boot-spl.stm32 of=/dev/mmcblk0p2 200f8598d98SPatrick Delaunay # dd if=u-boot.img of=/dev/mmcblk0p3 201f8598d98SPatrick Delaunay 2020ed232b1SPatrick DelaunayTo boot from SDCard, select BootPinMode = 1 1 1 and reset. 203f8598d98SPatrick Delaunay 2040ed232b1SPatrick Delaunay8. Prepare eMMC 2050ed232b1SPatrick Delaunay=============== 2060ed232b1SPatrick DelaunayYou can use U-Boot to copy binary in eMMC. 207f8598d98SPatrick Delaunay 2080ed232b1SPatrick DelaunayIn the next example, you need to boot from SDCARD and the images (u-boot-spl.stm32, u-boot.img) 2090ed232b1SPatrick Delaunayare presents on SDCARD (mmc 0) in ext4 partition 4 (bootfs). 210f8598d98SPatrick Delaunay 211f8598d98SPatrick DelaunayTo boot from SDCard, select BootPinMode = 1 1 1 and reset. 212f8598d98SPatrick Delaunay 2130ed232b1SPatrick DelaunayThen you update the eMMC with the next U-Boot command : 2140ed232b1SPatrick Delaunay 2150ed232b1SPatrick Delaunaya) prepare GPT on eMMC, 2160ed232b1SPatrick Delaunay example with 2 partitions, bootfs and roots: 2170ed232b1SPatrick Delaunay 2180ed232b1SPatrick Delaunay # setenv emmc_part "name=ssbl,size=2MiB;name=bootfs,type=linux,bootable,size=64MiB;name=rootfs,type=linux,size=512" 2190ed232b1SPatrick Delaunay # gpt write mmc 1 ${emmc_part} 2200ed232b1SPatrick Delaunay 2210ed232b1SPatrick Delaunayb) copy SPL on eMMC on firts boot partition 2220ed232b1SPatrick Delaunay (SPL max size is 256kB, with LBA 512, 0x200) 2230ed232b1SPatrick Delaunay 2240ed232b1SPatrick Delaunay # ext4load mmc 0:4 0xC0000000 u-boot-spl.stm32 2250ed232b1SPatrick Delaunay # mmc dev 1 2260ed232b1SPatrick Delaunay # mmc partconf 1 1 1 1 2270ed232b1SPatrick Delaunay # mmc write ${fileaddr} 0 200 2280ed232b1SPatrick Delaunay # mmc partconf 1 1 1 0 2290ed232b1SPatrick Delaunay 2300ed232b1SPatrick Delaunayb) copy U-Boot in first GPT partition of eMMC 2310ed232b1SPatrick Delaunay 2320ed232b1SPatrick Delaunay # ext4load mmc 0:4 0xC0000000 u-boot.img 2330ed232b1SPatrick Delaunay # mmc dev 1 2340ed232b1SPatrick Delaunay # part start mmc 1 1 partstart 2350ed232b1SPatrick Delaunay # part size mmc 1 1 partsize 2360ed232b1SPatrick Delaunay # mmc write ${fileaddr} ${partstart} ${partsize} 2370ed232b1SPatrick Delaunay 2380ed232b1SPatrick DelaunayTo boot from eMMC, select BootPinMode = 0 1 0 and reset. 239*5f16f655SPatrick Delaunay 240*5f16f655SPatrick Delaunay9. MAC Address 241*5f16f655SPatrick Delaunay============== 242*5f16f655SPatrick Delaunay 243*5f16f655SPatrick DelaunayPlease read doc/README.enetaddr for the implementation guidelines for mac id 244*5f16f655SPatrick Delaunayusage. Basically, environment has precedence over board specific storage. 245*5f16f655SPatrick Delaunay 246*5f16f655SPatrick DelaunayMac id storage and retrieval in stm32mp otp : 247*5f16f655SPatrick Delaunay- OTP_57[31:0] = MAC_ADDR[31:0] 248*5f16f655SPatrick Delaunay- OTP_58[15:0] = MAC_ADDR[47:32] 249*5f16f655SPatrick Delaunay 250*5f16f655SPatrick DelaunayTo program a MAC address on virgin OTP words above, you can use the fuse command 251*5f16f655SPatrick Delaunayon bank 0 to access to internal OTP: 252*5f16f655SPatrick Delaunay 253*5f16f655SPatrick Delaunay example to set mac address "12:34:56:78:9a:bc" 254*5f16f655SPatrick Delaunay 255*5f16f655SPatrick Delaunay 1- Write OTP 256*5f16f655SPatrick Delaunay STM32MP> fuse prog -y 0 57 0x78563412 0x0000bc9a 257*5f16f655SPatrick Delaunay 258*5f16f655SPatrick Delaunay 2- Read OTP 259*5f16f655SPatrick Delaunay STM32MP> fuse sense 0 57 2 260*5f16f655SPatrick Delaunay Sensing bank 0: 261*5f16f655SPatrick Delaunay Word 0x00000039: 78563412 0000bc9a 262*5f16f655SPatrick Delaunay 263*5f16f655SPatrick Delaunay 3- next REBOOT : 264*5f16f655SPatrick Delaunay ### Setting environment from OTP MAC address = "12:34:56:78:9a:bc" 265*5f16f655SPatrick Delaunay 266*5f16f655SPatrick Delaunay 4 check env update 267*5f16f655SPatrick Delaunay STM32MP> print ethaddr 268*5f16f655SPatrick Delaunay ethaddr=12:34:56:78:9a:bc 269