1*4882a593SmuzhiyunBooting U-Boot on a MXS processor 2*4882a593Smuzhiyun================================= 3*4882a593Smuzhiyun 4*4882a593SmuzhiyunThis document describes the MXS U-Boot port. This document mostly covers topics 5*4882a593Smuzhiyunrelated to making the module/board bootable. 6*4882a593Smuzhiyun 7*4882a593SmuzhiyunTerminology 8*4882a593Smuzhiyun----------- 9*4882a593Smuzhiyun 10*4882a593SmuzhiyunThe term "MXS" refers to a family of Freescale SoCs that is composed by MX23 11*4882a593Smuzhiyunand MX28. 12*4882a593Smuzhiyun 13*4882a593SmuzhiyunThe dollar symbol ($) introduces a snipped of shell code. This shall be typed 14*4882a593Smuzhiyuninto the unix command prompt in U-Boot source code root directory. 15*4882a593Smuzhiyun 16*4882a593SmuzhiyunThe (=>) introduces a snipped of code that should by typed into U-Boot command 17*4882a593Smuzhiyunprompt 18*4882a593Smuzhiyun 19*4882a593SmuzhiyunContents 20*4882a593Smuzhiyun-------- 21*4882a593Smuzhiyun 22*4882a593Smuzhiyun1) Prerequisites 23*4882a593Smuzhiyun2) Compiling U-Boot for a MXS based board 24*4882a593Smuzhiyun3) Installation of U-Boot for a MXS based board to SD card 25*4882a593Smuzhiyun4) Installation of U-Boot into NAND flash on a MX28 based board 26*4882a593Smuzhiyun5) Installation of U-Boot into SPI NOR flash on a MX28 based board 27*4882a593Smuzhiyun 28*4882a593Smuzhiyun1) Prerequisites 29*4882a593Smuzhiyun---------------- 30*4882a593Smuzhiyun 31*4882a593SmuzhiyunTo make a MXS based board bootable, some tools are necessary. The only 32*4882a593Smuzhiyunmandatory tool is the "mxsboot" tool found in U-Boot source tree. The 33*4882a593Smuzhiyuntool is built automatically when compiling U-Boot for i.MX23 or i.MX28. 34*4882a593Smuzhiyun 35*4882a593SmuzhiyunThe production of BootStream image is handled via "mkimage", which is 36*4882a593Smuzhiyunalso part of the U-Boot source tree. The "mkimage" requires OpenSSL 37*4882a593Smuzhiyundevelopment libraries to be installed. In case of Debian and derivates, 38*4882a593Smuzhiyunthis is installed by running: 39*4882a593Smuzhiyun 40*4882a593Smuzhiyun $ sudo apt-get install libssl-dev 41*4882a593Smuzhiyun 42*4882a593SmuzhiyunNOTE: The "elftosb" tool distributed by Freescale Semiconductor is no 43*4882a593Smuzhiyun longer necessary for general use of U-Boot on i.MX23 and i.MX28. 44*4882a593Smuzhiyun The mkimage supports generation of BootStream images encrypted 45*4882a593Smuzhiyun with a zero key, which is the vast majority of use-cases. In 46*4882a593Smuzhiyun case you do need to produce image encrypted with non-zero key 47*4882a593Smuzhiyun or other special features, please use the "elftosb" tool, 48*4882a593Smuzhiyun otherwise continue to section 2). The installation procedure of 49*4882a593Smuzhiyun the "elftosb" is outlined below: 50*4882a593Smuzhiyun 51*4882a593SmuzhiyunFirstly, obtain the elftosb archive from the following location: 52*4882a593Smuzhiyun 53*4882a593Smuzhiyun ftp://ftp.denx.de/pub/tools/elftosb-10.12.01.tar.gz 54*4882a593Smuzhiyun 55*4882a593SmuzhiyunWe use a $VER variable here to denote the current version. At the time of 56*4882a593Smuzhiyunwriting of this document, that is "10.12.01". To obtain the file from command 57*4882a593Smuzhiyunline, use: 58*4882a593Smuzhiyun 59*4882a593Smuzhiyun $ VER="10.12.01" 60*4882a593Smuzhiyun $ wget ftp://ftp.denx.de/pub/tools/elftosb-${VER}.tar.gz 61*4882a593Smuzhiyun 62*4882a593SmuzhiyunExtract the file: 63*4882a593Smuzhiyun 64*4882a593Smuzhiyun $ tar xzf elftosb-${VER}.tar.gz 65*4882a593Smuzhiyun 66*4882a593SmuzhiyunCompile the file. We need to manually tell the linker to use also libm: 67*4882a593Smuzhiyun 68*4882a593Smuzhiyun $ cd elftosb-${VER}/ 69*4882a593Smuzhiyun $ make LIBS="-lstdc++ -lm" elftosb 70*4882a593Smuzhiyun 71*4882a593SmuzhiyunOptionally, remove debugging symbols from elftosb: 72*4882a593Smuzhiyun 73*4882a593Smuzhiyun $ strip bld/linux/elftosb 74*4882a593Smuzhiyun 75*4882a593SmuzhiyunFinally, install the "elftosb" binary. The "install" target is missing, so just 76*4882a593Smuzhiyuncopy the binary by hand: 77*4882a593Smuzhiyun 78*4882a593Smuzhiyun $ sudo cp bld/linux/elftosb /usr/local/bin/ 79*4882a593Smuzhiyun 80*4882a593SmuzhiyunMake sure the "elftosb" binary can be found in your $PATH, in this case this 81*4882a593Smuzhiyunmeans "/usr/local/bin/" has to be in your $PATH. 82*4882a593Smuzhiyun 83*4882a593Smuzhiyun2) Compiling U-Boot for a MXS based board 84*4882a593Smuzhiyun------------------------------------------- 85*4882a593Smuzhiyun 86*4882a593SmuzhiyunCompiling the U-Boot for a MXS board is straightforward and done as compiling 87*4882a593SmuzhiyunU-Boot for any other ARM device. For cross-compiler setup, please refer to 88*4882a593SmuzhiyunELDK5.0 documentation. First, clean up the source code: 89*4882a593Smuzhiyun 90*4882a593Smuzhiyun $ make mrproper 91*4882a593Smuzhiyun 92*4882a593SmuzhiyunNext, configure U-Boot for a MXS based board 93*4882a593Smuzhiyun 94*4882a593Smuzhiyun $ make <mxs_based_board_name>_config 95*4882a593Smuzhiyun 96*4882a593SmuzhiyunExamples: 97*4882a593Smuzhiyun 98*4882a593Smuzhiyun1. For building U-Boot for Aries M28EVK board: 99*4882a593Smuzhiyun 100*4882a593Smuzhiyun $ make m28evk_config 101*4882a593Smuzhiyun 102*4882a593Smuzhiyun2. For building U-Boot for Freescale MX28EVK board: 103*4882a593Smuzhiyun 104*4882a593Smuzhiyun $ make mx28evk_config 105*4882a593Smuzhiyun 106*4882a593Smuzhiyun3. For building U-Boot for Freescale MX23EVK board: 107*4882a593Smuzhiyun 108*4882a593Smuzhiyun $ make mx23evk_config 109*4882a593Smuzhiyun 110*4882a593Smuzhiyun4. For building U-Boot for Olimex MX23 Olinuxino board: 111*4882a593Smuzhiyun 112*4882a593Smuzhiyun $ make mx23_olinuxino_config 113*4882a593Smuzhiyun 114*4882a593SmuzhiyunLastly, compile U-Boot and prepare a "BootStream". The "BootStream" is a special 115*4882a593Smuzhiyuntype of file, which MXS CPUs can boot. This is handled by the following 116*4882a593Smuzhiyuncommand: 117*4882a593Smuzhiyun 118*4882a593Smuzhiyun $ make u-boot.sb 119*4882a593Smuzhiyun 120*4882a593SmuzhiyunHINT: To speed-up the build process, you can add -j<N>, where N is number of 121*4882a593Smuzhiyun compiler instances that'll run in parallel. 122*4882a593Smuzhiyun 123*4882a593SmuzhiyunThe code produces "u-boot.sb" file. This file needs to be augmented with a 124*4882a593Smuzhiyunproper header to allow successful boot from SD or NAND. Adding the header is 125*4882a593Smuzhiyundiscussed in the following chapters. 126*4882a593Smuzhiyun 127*4882a593SmuzhiyunNOTE: The process that produces u-boot.sb uses the mkimage to generate the 128*4882a593Smuzhiyun BootStream. The BootStream is encrypted with zero key. In case you need 129*4882a593Smuzhiyun some special features of the BootStream and plan on using the "elftosb" 130*4882a593Smuzhiyun tool instead, the invocation to produce a compatible BootStream with the 131*4882a593Smuzhiyun one produced by mkimage is outlined below. For further details, refer to 132*4882a593Smuzhiyun the documentation bundled with the "elftosb" package. 133*4882a593Smuzhiyun 134*4882a593Smuzhiyun $ elftosb -zf imx23 -c arch/arm/cpu/arm926ejs/mxs/u-boot-imx23.bd \ 135*4882a593Smuzhiyun -o u-boot.sb 136*4882a593Smuzhiyun $ elftosb -zf imx28 -c arch/arm/cpu/arm926ejs/mxs/u-boot-imx28.bd \ 137*4882a593Smuzhiyun -o u-boot.sb 138*4882a593Smuzhiyun 139*4882a593Smuzhiyun3) Installation of U-Boot for a MXS based board to SD card 140*4882a593Smuzhiyun---------------------------------------------------------- 141*4882a593Smuzhiyun 142*4882a593SmuzhiyunTo boot a MXS based board from SD, set the boot mode DIP switches according to 143*4882a593Smuzhiyunto MX28 manual, section 12.2.1 (Table 12-2) or MX23 manual, section 35.1.2 144*4882a593Smuzhiyun(Table 35-3). 145*4882a593Smuzhiyun 146*4882a593SmuzhiyunThe SD card used to boot U-Boot must contain a DOS partition table, which in 147*4882a593Smuzhiyunturn carries a partition of special type and which contains a special header. 148*4882a593SmuzhiyunThe rest of partitions in the DOS partition table can be used by the user. 149*4882a593Smuzhiyun 150*4882a593SmuzhiyunTo prepare such partition, use your favourite partitioning tool. The partition 151*4882a593Smuzhiyunmust have the following parameters: 152*4882a593Smuzhiyun 153*4882a593Smuzhiyun * Start sector .......... sector 2048 154*4882a593Smuzhiyun * Partition size ........ at least 1024 kb 155*4882a593Smuzhiyun * Partition type ........ 0x53 (sometimes "OnTrack DM6 Aux3") 156*4882a593Smuzhiyun 157*4882a593SmuzhiyunFor example in Linux fdisk, the sequence for a clear card follows. Be sure to 158*4882a593Smuzhiyunrun fdisk with the option "-u=sectors" to set units to sectors: 159*4882a593Smuzhiyun 160*4882a593Smuzhiyun * o ..................... create a clear partition table 161*4882a593Smuzhiyun * n ..................... create new partition 162*4882a593Smuzhiyun * p ............. primary partition 163*4882a593Smuzhiyun * 1 ............. first partition 164*4882a593Smuzhiyun * 2048 .......... first sector is 2048 165*4882a593Smuzhiyun * +1M ........... make the partition 1Mb big 166*4882a593Smuzhiyun * t 1 ................... change first partition ID 167*4882a593Smuzhiyun * 53 ............ change the ID to 0x53 (OnTrack DM6 Aux3) 168*4882a593Smuzhiyun * <create other partitions> 169*4882a593Smuzhiyun * w ..................... write partition table to disk 170*4882a593Smuzhiyun 171*4882a593SmuzhiyunThe partition layout is ready, next the special partition must be filled with 172*4882a593Smuzhiyunproper contents. The contents is generated by running the following command 173*4882a593Smuzhiyun(see chapter 2)): 174*4882a593Smuzhiyun 175*4882a593Smuzhiyun $ ./tools/mxsboot sd u-boot.sb u-boot.sd 176*4882a593Smuzhiyun 177*4882a593SmuzhiyunThe resulting file, "u-boot.sd", shall then be written to the partition. In this 178*4882a593Smuzhiyuncase, we assume the first partition of the SD card is /dev/mmcblk0p1: 179*4882a593Smuzhiyun 180*4882a593Smuzhiyun $ dd if=u-boot.sd of=/dev/mmcblk0p1 181*4882a593Smuzhiyun 182*4882a593SmuzhiyunLast step is to insert the card into the MXS based board and boot. 183*4882a593Smuzhiyun 184*4882a593SmuzhiyunNOTE: If the user needs to adjust the start sector, the "mxsboot" tool contains 185*4882a593Smuzhiyun a "-p" switch for that purpose. The "-p" switch takes the sector number as 186*4882a593Smuzhiyun an argument. 187*4882a593Smuzhiyun 188*4882a593Smuzhiyun4) Installation of U-Boot into NAND flash on a MX28 based board 189*4882a593Smuzhiyun--------------------------------------------------------------- 190*4882a593Smuzhiyun 191*4882a593SmuzhiyunTo boot a MX28 based board from NAND, set the boot mode DIP switches according 192*4882a593Smuzhiyunto MX28 manual section 12.2.1 (Table 12-2), PORT=GPMI, NAND 1.8 V. 193*4882a593Smuzhiyun 194*4882a593SmuzhiyunThere are two possibilities when preparing an image writable to NAND flash. 195*4882a593Smuzhiyun 196*4882a593Smuzhiyun I) The NAND wasn't written at all yet or the BCB is broken 197*4882a593Smuzhiyun ---------------------------------------------------------- 198*4882a593Smuzhiyun In this case, both BCB (FCB and DBBT) and firmware needs to be 199*4882a593Smuzhiyun written to NAND. To generate NAND image containing all these, 200*4882a593Smuzhiyun there is a tool called "mxsboot" in the "tools/" directory. The tool 201*4882a593Smuzhiyun is invoked on "u-boot.sb" file from chapter 2): 202*4882a593Smuzhiyun 203*4882a593Smuzhiyun $ ./tools/mxsboot nand u-boot.sb u-boot.nand 204*4882a593Smuzhiyun 205*4882a593Smuzhiyun NOTE: The above invokation works for NAND flash with geometry of 206*4882a593Smuzhiyun 2048b per page, 64b OOB data, 128kb erase size. If your chip 207*4882a593Smuzhiyun has a different geometry, please use: 208*4882a593Smuzhiyun 209*4882a593Smuzhiyun -w <size> change page size (default 2048 b) 210*4882a593Smuzhiyun -o <size> change oob size (default 64 b) 211*4882a593Smuzhiyun -e <size> change erase size (default 131072 b) 212*4882a593Smuzhiyun 213*4882a593Smuzhiyun The geometry information can be obtained from running U-Boot 214*4882a593Smuzhiyun on the MX28 board by issuing the "nand info" command. 215*4882a593Smuzhiyun 216*4882a593Smuzhiyun The resulting file, "u-boot.nand" can be written directly to NAND 217*4882a593Smuzhiyun from the U-Boot prompt. To simplify the process, the U-Boot default 218*4882a593Smuzhiyun environment contains script "update_nand_full" to update the system. 219*4882a593Smuzhiyun 220*4882a593Smuzhiyun This script expects a working TFTP server containing the file 221*4882a593Smuzhiyun "u-boot.nand" in it's root directory. This can be changed by 222*4882a593Smuzhiyun adjusting the "update_nand_full_filename" variable. 223*4882a593Smuzhiyun 224*4882a593Smuzhiyun To update the system, run the following in U-Boot prompt: 225*4882a593Smuzhiyun 226*4882a593Smuzhiyun => run update_nand_full 227*4882a593Smuzhiyun 228*4882a593Smuzhiyun In case you would only need to update the bootloader in future, 229*4882a593Smuzhiyun see II) below. 230*4882a593Smuzhiyun 231*4882a593Smuzhiyun II) The NAND was already written with a good BCB 232*4882a593Smuzhiyun ------------------------------------------------ 233*4882a593Smuzhiyun This part applies after the part I) above was done at least once. 234*4882a593Smuzhiyun 235*4882a593Smuzhiyun If part I) above was done correctly already, there is no need to 236*4882a593Smuzhiyun write the FCB and DBBT parts of NAND again. It's possible to upgrade 237*4882a593Smuzhiyun only the bootloader image. 238*4882a593Smuzhiyun 239*4882a593Smuzhiyun To simplify the process of firmware update, the U-Boot default 240*4882a593Smuzhiyun environment contains script "update_nand_firmware" to update only 241*4882a593Smuzhiyun the firmware, without rewriting FCB and DBBT. 242*4882a593Smuzhiyun 243*4882a593Smuzhiyun This script expects a working TFTP server containing the file 244*4882a593Smuzhiyun "u-boot.sb" in it's root directory. This can be changed by 245*4882a593Smuzhiyun adjusting the "update_nand_firmware_filename" variable. 246*4882a593Smuzhiyun 247*4882a593Smuzhiyun To update the system, run the following in U-Boot prompt: 248*4882a593Smuzhiyun 249*4882a593Smuzhiyun => run update_nand_firmware 250*4882a593Smuzhiyun 251*4882a593Smuzhiyun III) Special settings for the update scripts 252*4882a593Smuzhiyun -------------------------------------------- 253*4882a593Smuzhiyun There is a slight possibility of the user wanting to adjust the 254*4882a593Smuzhiyun STRIDE and COUNT options of the NAND boot. For description of these, 255*4882a593Smuzhiyun see MX28 manual section 12.12.1.2 and 12.12.1.3. 256*4882a593Smuzhiyun 257*4882a593Smuzhiyun The update scripts take this possibility into account. In case the 258*4882a593Smuzhiyun user changes STRIDE by blowing fuses, the user also has to change 259*4882a593Smuzhiyun "update_nand_stride" variable. In case the user changes COUNT by 260*4882a593Smuzhiyun blowing fuses, the user also has to change "update_nand_count" 261*4882a593Smuzhiyun variable for the update scripts to work correctly. 262*4882a593Smuzhiyun 263*4882a593Smuzhiyun In case the user needs to boot a firmware image bigger than 1Mb, the 264*4882a593Smuzhiyun user has to adjust the "update_nand_firmware_maxsz" variable for the 265*4882a593Smuzhiyun update scripts to work properly. 266*4882a593Smuzhiyun 267*4882a593Smuzhiyun5) Installation of U-Boot into SPI NOR flash on a MX28 based board 268*4882a593Smuzhiyun------------------------------------------------------------------ 269*4882a593Smuzhiyun 270*4882a593SmuzhiyunThe u-boot.sb file can be directly written to SPI NOR from U-Boot prompt. 271*4882a593Smuzhiyun 272*4882a593SmuzhiyunLoad u-boot.sb into RAM, this can be done in several ways and one way is to use 273*4882a593Smuzhiyuntftp: 274*4882a593Smuzhiyun => tftp u-boot.sb 0x42000000 275*4882a593Smuzhiyun 276*4882a593SmuzhiyunProbe the SPI NOR flash: 277*4882a593Smuzhiyun => sf probe 278*4882a593Smuzhiyun 279*4882a593Smuzhiyun(SPI NOR should be succesfully detected in this step) 280*4882a593Smuzhiyun 281*4882a593SmuzhiyunErase the blocks where U-Boot binary will be written to: 282*4882a593Smuzhiyun => sf erase 0x0 0x80000 283*4882a593Smuzhiyun 284*4882a593SmuzhiyunWrite u-boot.sb to SPI NOR: 285*4882a593Smuzhiyun => sf write 0x42000000 0 0x80000 286*4882a593Smuzhiyun 287*4882a593SmuzhiyunPower off the board and set the boot mode DIP switches to boot from the SPI NOR 288*4882a593Smuzhiyunaccording to MX28 manual section 12.2.1 (Table 12-2) 289*4882a593Smuzhiyun 290*4882a593SmuzhiyunLast step is to power up the board and U-Boot should start from SPI NOR. 291