1*4882a593Smuzhiyun# 2*4882a593Smuzhiyun# Copyright (C) 2015 Google. Inc 3*4882a593Smuzhiyun# Written by Simon Glass <sjg@chromium.org> 4*4882a593Smuzhiyun# 5*4882a593Smuzhiyun# SPDX-License-Identifier: GPL-2.0+ 6*4882a593Smuzhiyun# 7*4882a593Smuzhiyun 8*4882a593SmuzhiyunU-Boot on Rockchip 9*4882a593Smuzhiyun================== 10*4882a593Smuzhiyun 11*4882a593SmuzhiyunThere are several repositories available with versions of U-Boot that support 12*4882a593Smuzhiyunmany Rockchip devices [1] [2]. 13*4882a593Smuzhiyun 14*4882a593SmuzhiyunThe current mainline support is experimental only and is not useful for 15*4882a593Smuzhiyunanything. It should provide a base on which to build. 16*4882a593Smuzhiyun 17*4882a593SmuzhiyunSo far only support for the RK3288 and RK3036 is provided. 18*4882a593Smuzhiyun 19*4882a593Smuzhiyun 20*4882a593SmuzhiyunPrerequisites 21*4882a593Smuzhiyun============= 22*4882a593Smuzhiyun 23*4882a593SmuzhiyunYou will need: 24*4882a593Smuzhiyun 25*4882a593Smuzhiyun - Firefly RK3288 board or something else with a supported RockChip SoC 26*4882a593Smuzhiyun - Power connection to 5V using the supplied micro-USB power cable 27*4882a593Smuzhiyun - Separate USB serial cable attached to your computer and the Firefly 28*4882a593Smuzhiyun (connect to the micro-USB connector below the logo) 29*4882a593Smuzhiyun - rkflashtool [3] 30*4882a593Smuzhiyun - openssl (sudo apt-get install openssl) 31*4882a593Smuzhiyun - Serial UART connection [4] 32*4882a593Smuzhiyun - Suitable ARM cross compiler, e.g.: 33*4882a593Smuzhiyun sudo apt-get install gcc-4.7-arm-linux-gnueabi 34*4882a593Smuzhiyun 35*4882a593Smuzhiyun 36*4882a593SmuzhiyunBuilding 37*4882a593Smuzhiyun======== 38*4882a593Smuzhiyun 39*4882a593SmuzhiyunAt present nine RK3288 boards are supported: 40*4882a593Smuzhiyun 41*4882a593Smuzhiyun - EVB RK3288 - use evb-rk3288 configuration 42*4882a593Smuzhiyun - Fennec RK3288 - use fennec-rk3288 configuration 43*4882a593Smuzhiyun - Firefly RK3288 - use firefly-rk3288 configuration 44*4882a593Smuzhiyun - Hisense Chromebook - use chromebook_jerry configuration 45*4882a593Smuzhiyun - MiQi RK3288 - use miqi-rk3288 configuration 46*4882a593Smuzhiyun - phyCORE-RK3288 RDK - use phycore-rk3288 configuration 47*4882a593Smuzhiyun - PopMetal RK3288 - use popmetal-rk3288 configuration 48*4882a593Smuzhiyun - Radxa Rock 2 - use rock2 configuration 49*4882a593Smuzhiyun - Tinker RK3288 - use tinker-rk3288 configuration 50*4882a593Smuzhiyun 51*4882a593SmuzhiyunTwo RK3036 board are supported: 52*4882a593Smuzhiyun 53*4882a593Smuzhiyun - EVB RK3036 - use evb-rk3036 configuration 54*4882a593Smuzhiyun - Kylin - use kylin_rk3036 configuration 55*4882a593Smuzhiyun 56*4882a593SmuzhiyunFor example: 57*4882a593Smuzhiyun 58*4882a593Smuzhiyun CROSS_COMPILE=arm-linux-gnueabi- make O=firefly firefly-rk3288_defconfig all 59*4882a593Smuzhiyun 60*4882a593Smuzhiyun(or you can use another cross compiler if you prefer) 61*4882a593Smuzhiyun 62*4882a593Smuzhiyun 63*4882a593SmuzhiyunWriting to the board with USB 64*4882a593Smuzhiyun============================= 65*4882a593Smuzhiyun 66*4882a593SmuzhiyunFor USB to work you must get your board into ROM boot mode, either by erasing 67*4882a593Smuzhiyunyour MMC or (perhaps) holding the recovery button when you boot the board. 68*4882a593SmuzhiyunTo erase your MMC, you can boot into Linux and type (as root) 69*4882a593Smuzhiyun 70*4882a593Smuzhiyun dd if=/dev/zero of=/dev/mmcblk0 bs=1M 71*4882a593Smuzhiyun 72*4882a593SmuzhiyunConnect your board's OTG port to your computer. 73*4882a593Smuzhiyun 74*4882a593SmuzhiyunTo create a suitable image and write it to the board: 75*4882a593Smuzhiyun 76*4882a593Smuzhiyun ./firefly-rk3288/tools/mkimage -n rk3288 -T rkimage -d \ 77*4882a593Smuzhiyun ./firefly-rk3288/spl/u-boot-spl-dtb.bin out && \ 78*4882a593Smuzhiyun cat out | openssl rc4 -K 7c4e0304550509072d2c7b38170d1711 | rkflashtool l 79*4882a593Smuzhiyun 80*4882a593SmuzhiyunIf all goes well you should something like: 81*4882a593Smuzhiyun 82*4882a593Smuzhiyun U-Boot SPL 2015.07-rc1-00383-ge345740-dirty (Jun 03 2015 - 10:06:49) 83*4882a593Smuzhiyun Card did not respond to voltage select! 84*4882a593Smuzhiyun spl: mmc init failed with error: -17 85*4882a593Smuzhiyun ### ERROR ### Please RESET the board ### 86*4882a593Smuzhiyun 87*4882a593SmuzhiyunYou will need to reset the board before each time you try. Yes, that's all 88*4882a593Smuzhiyunit does so far. If support for the Rockchip USB protocol or DFU were added 89*4882a593Smuzhiyunin SPL then we could in principle load U-Boot and boot to a prompt from USB 90*4882a593Smuzhiyunas several other platforms do. However it does not seem to be possible to 91*4882a593Smuzhiyunuse the existing boot ROM code from SPL. 92*4882a593Smuzhiyun 93*4882a593Smuzhiyun 94*4882a593SmuzhiyunBooting from an SD card 95*4882a593Smuzhiyun======================= 96*4882a593Smuzhiyun 97*4882a593SmuzhiyunTo write an image that boots from an SD card (assumed to be /dev/sdc): 98*4882a593Smuzhiyun 99*4882a593Smuzhiyun ./firefly-rk3288/tools/mkimage -n rk3288 -T rksd -d \ 100*4882a593Smuzhiyun firefly-rk3288/spl/u-boot-spl-dtb.bin out && \ 101*4882a593Smuzhiyun sudo dd if=out of=/dev/sdc seek=64 && \ 102*4882a593Smuzhiyun sudo dd if=firefly-rk3288/u-boot-dtb.img of=/dev/sdc seek=16384 103*4882a593Smuzhiyun 104*4882a593SmuzhiyunThis puts the Rockchip header and SPL image first and then places the U-Boot 105*4882a593Smuzhiyunimage at block 16384 (i.e. 8MB from the start of the SD card). This 106*4882a593Smuzhiyuncorresponds with this setting in U-Boot: 107*4882a593Smuzhiyun 108*4882a593Smuzhiyun #define CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR 0x4000 109*4882a593Smuzhiyun 110*4882a593SmuzhiyunPut this SD (or micro-SD) card into your board and reset it. You should see 111*4882a593Smuzhiyunsomething like: 112*4882a593Smuzhiyun 113*4882a593Smuzhiyun U-Boot 2016.01-rc2-00309-ge5bad3b-dirty (Jan 02 2016 - 23:41:59 -0700) 114*4882a593Smuzhiyun 115*4882a593Smuzhiyun Model: Radxa Rock 2 Square 116*4882a593Smuzhiyun DRAM: 2 GiB 117*4882a593Smuzhiyun MMC: dwmmc@ff0f0000: 0, dwmmc@ff0c0000: 1 118*4882a593Smuzhiyun *** Warning - bad CRC, using default environment 119*4882a593Smuzhiyun 120*4882a593Smuzhiyun In: serial 121*4882a593Smuzhiyun Out: vop@ff940000.vidconsole 122*4882a593Smuzhiyun Err: serial 123*4882a593Smuzhiyun Net: Net Initialization Skipped 124*4882a593Smuzhiyun No ethernet found. 125*4882a593Smuzhiyun Hit any key to stop autoboot: 0 126*4882a593Smuzhiyun => 127*4882a593Smuzhiyun 128*4882a593SmuzhiyunThe rockchip bootrom can load and boot an initial spl, then continue to 129*4882a593Smuzhiyunload a second-level bootloader(ie. U-BOOT) as soon as it returns to bootrom. 130*4882a593SmuzhiyunTherefore RK3288 has another loading sequence like RK3036. The option of 131*4882a593SmuzhiyunU-Boot is controlled with this setting in U-Boot: 132*4882a593Smuzhiyun 133*4882a593Smuzhiyun #define CONFIG_SPL_ROCKCHIP_BACK_TO_BROM 134*4882a593Smuzhiyun 135*4882a593SmuzhiyunYou can create the image via the following operations: 136*4882a593Smuzhiyun 137*4882a593Smuzhiyun ./firefly-rk3288/tools/mkimage -n rk3288 -T rksd -d \ 138*4882a593Smuzhiyun firefly-rk3288/spl/u-boot-spl-dtb.bin out && \ 139*4882a593Smuzhiyun cat firefly-rk3288/u-boot-dtb.bin >> out && \ 140*4882a593Smuzhiyun sudo dd if=out of=/dev/sdc seek=64 141*4882a593Smuzhiyun 142*4882a593SmuzhiyunIf you have an HDMI cable attached you should see a video console. 143*4882a593Smuzhiyun 144*4882a593SmuzhiyunFor evb_rk3036 board: 145*4882a593Smuzhiyun ./evb-rk3036/tools/mkimage -n rk3036 -T rksd -d evb-rk3036/spl/u-boot-spl.bin out && \ 146*4882a593Smuzhiyun cat evb-rk3036/u-boot-dtb.bin >> out && \ 147*4882a593Smuzhiyun sudo dd if=out of=/dev/sdc seek=64 148*4882a593Smuzhiyun 149*4882a593SmuzhiyunNote: rk3036 SDMMC and debug uart use the same iomux, so if you boot from SD, the 150*4882a593Smuzhiyun debug uart must be disabled 151*4882a593Smuzhiyun 152*4882a593Smuzhiyun 153*4882a593SmuzhiyunBooting from an SD card on RK3288 with TPL 154*4882a593Smuzhiyun========================================== 155*4882a593Smuzhiyun 156*4882a593SmuzhiyunSince the size of SPL can't be exceeded 0x8000 bytes in RK3288, it is not possible add 157*4882a593Smuzhiyunnew SPL features like Falcon mode or etc. 158*4882a593Smuzhiyun 159*4882a593SmuzhiyunSo introduce TPL so-that adding new features to SPL is possible because now TPL should 160*4882a593Smuzhiyunrun minimal with code like DDR, clock etc and rest of new features in SPL. 161*4882a593Smuzhiyun 162*4882a593SmuzhiyunAs of now TPL is added on Vyasa-RK3288 board. 163*4882a593Smuzhiyun 164*4882a593SmuzhiyunTo write an image that boots from an SD card (assumed to be /dev/mmcblk0): 165*4882a593Smuzhiyun 166*4882a593Smuzhiyun ./tools/mkimage -n rk3288 -T rksd -d ./tpl/u-boot-tpl.bin out && 167*4882a593Smuzhiyun cat ./spl/u-boot-spl-dtb.bin >> out && 168*4882a593Smuzhiyun sudo dd if=out of=/dev/mmcblk0 seek=64 && 169*4882a593Smuzhiyun sudo dd if=u-boot-dtb.img of=/dev/mmcblk0 seek=16384 170*4882a593Smuzhiyun 171*4882a593SmuzhiyunBooting from an SD card on RK3188 172*4882a593Smuzhiyun================================= 173*4882a593Smuzhiyun 174*4882a593SmuzhiyunFor rk3188 boards the general storage onto the card stays the same as 175*4882a593Smuzhiyundescribed above, but the image creation needs a bit more care. 176*4882a593Smuzhiyun 177*4882a593SmuzhiyunThe bootrom of rk3188 expects to find a small 1kb loader which returns 178*4882a593Smuzhiyuncontrol to the bootrom, after which it will load the real loader, which 179*4882a593Smuzhiyuncan then be up to 29kb in size and does the regular ddr init. This is 180*4882a593Smuzhiyunhandled by a single image (built as the SPL stage) that tests whether 181*4882a593Smuzhiyunit is handled for the first or second time via code executed from the 182*4882a593Smuzhiyunboot0-hook. 183*4882a593Smuzhiyun 184*4882a593SmuzhiyunAdditionally the rk3188 requires everything the bootrom loads to be 185*4882a593Smuzhiyunrc4-encrypted. Except for the very first stage the bootrom always reads 186*4882a593Smuzhiyunand decodes 2kb pages, so files should be sized accordingly. 187*4882a593Smuzhiyun 188*4882a593Smuzhiyun# copy tpl, pad to 1020 bytes and append spl 189*4882a593Smuzhiyuntools/mkimage -n rk3188 -T rksd -d spl/u-boot-spl.bin out 190*4882a593Smuzhiyun 191*4882a593Smuzhiyun# truncate, encode and append u-boot.bin 192*4882a593Smuzhiyuntruncate -s %2048 u-boot.bin 193*4882a593Smuzhiyuncat u-boot.bin | split -b 512 --filter='openssl rc4 -K 7C4E0304550509072D2C7B38170D1711' >> out 194*4882a593Smuzhiyun 195*4882a593Smuzhiyun 196*4882a593SmuzhiyunUsing fastboot on rk3288 197*4882a593Smuzhiyun======================== 198*4882a593Smuzhiyun- Write GPT partition layout to mmc device which fastboot want to use it to 199*4882a593Smuzhiyunstore the image 200*4882a593Smuzhiyun 201*4882a593Smuzhiyun => gpt write mmc 1 $partitions 202*4882a593Smuzhiyun 203*4882a593Smuzhiyun- Invoke fastboot command to prepare 204*4882a593Smuzhiyun 205*4882a593Smuzhiyun => fastboot 1 206*4882a593Smuzhiyun 207*4882a593Smuzhiyun- Start fastboot request on PC 208*4882a593Smuzhiyun 209*4882a593Smuzhiyun fastboot -i 0x2207 flash loader evb-rk3288/spl/u-boot-spl-dtb.bin 210*4882a593Smuzhiyun 211*4882a593SmuzhiyunYou should see something like: 212*4882a593Smuzhiyun 213*4882a593Smuzhiyun => fastboot 1 214*4882a593Smuzhiyun WARNING: unknown variable: partition-type:loader 215*4882a593Smuzhiyun Starting download of 357796 bytes 216*4882a593Smuzhiyun .. 217*4882a593Smuzhiyun downloading of 357796 bytes finished 218*4882a593Smuzhiyun Flashing Raw Image 219*4882a593Smuzhiyun ........ wrote 357888 bytes to 'loader' 220*4882a593Smuzhiyun 221*4882a593SmuzhiyunBooting from SPI 222*4882a593Smuzhiyun================ 223*4882a593Smuzhiyun 224*4882a593SmuzhiyunTo write an image that boots from SPI flash (e.g. for the Haier Chromebook): 225*4882a593Smuzhiyun 226*4882a593Smuzhiyun ./chromebook_jerry/tools/mkimage -n rk3288 -T rkspi \ 227*4882a593Smuzhiyun -d chromebook_jerry/spl/u-boot-spl-dtb.bin spl.bin && \ 228*4882a593Smuzhiyun dd if=spl.bin of=spl-out.bin bs=128K conv=sync && \ 229*4882a593Smuzhiyun cat spl-out.bin chromebook_jerry/u-boot-dtb.img >out.bin && \ 230*4882a593Smuzhiyun dd if=out.bin of=out.bin.pad bs=4M conv=sync 231*4882a593Smuzhiyun 232*4882a593SmuzhiyunThis converts the SPL image to the required SPI format by adding the Rockchip 233*4882a593Smuzhiyunheader and skipping every 2KB block. Then the U-Boot image is written at 234*4882a593Smuzhiyunoffset 128KB and the whole image is padded to 4MB which is the SPI flash size. 235*4882a593SmuzhiyunThe position of U-Boot is controlled with this setting in U-Boot: 236*4882a593Smuzhiyun 237*4882a593Smuzhiyun #define CONFIG_SYS_SPI_U_BOOT_OFFS (128 << 10) 238*4882a593Smuzhiyun 239*4882a593SmuzhiyunIf you have a Dediprog em100pro connected then you can write the image with: 240*4882a593Smuzhiyun 241*4882a593Smuzhiyun sudo em100 -s -c GD25LQ32 -d out.bin.pad -r 242*4882a593Smuzhiyun 243*4882a593SmuzhiyunWhen booting you should see something like: 244*4882a593Smuzhiyun 245*4882a593Smuzhiyun U-Boot SPL 2015.07-rc2-00215-g9a58220-dirty (Jun 23 2015 - 12:11:32) 246*4882a593Smuzhiyun 247*4882a593Smuzhiyun 248*4882a593Smuzhiyun U-Boot 2015.07-rc2-00215-g9a58220-dirty (Jun 23 2015 - 12:11:32 -0600) 249*4882a593Smuzhiyun 250*4882a593Smuzhiyun Model: Google Jerry 251*4882a593Smuzhiyun DRAM: 2 GiB 252*4882a593Smuzhiyun MMC: 253*4882a593Smuzhiyun Using default environment 254*4882a593Smuzhiyun 255*4882a593Smuzhiyun In: serial@ff690000 256*4882a593Smuzhiyun Out: serial@ff690000 257*4882a593Smuzhiyun Err: serial@ff690000 258*4882a593Smuzhiyun => 259*4882a593Smuzhiyun 260*4882a593SmuzhiyunFuture work 261*4882a593Smuzhiyun=========== 262*4882a593Smuzhiyun 263*4882a593SmuzhiyunImmediate priorities are: 264*4882a593Smuzhiyun 265*4882a593Smuzhiyun- USB host 266*4882a593Smuzhiyun- USB device 267*4882a593Smuzhiyun- Run CPU at full speed (code exists but we only see ~60 DMIPS maximum) 268*4882a593Smuzhiyun- NAND flash 269*4882a593Smuzhiyun- Support for other Rockchip parts 270*4882a593Smuzhiyun- Boot U-Boot proper over USB OTG (at present only SPL works) 271*4882a593Smuzhiyun 272*4882a593Smuzhiyun 273*4882a593SmuzhiyunDevelopment Notes 274*4882a593Smuzhiyun================= 275*4882a593Smuzhiyun 276*4882a593SmuzhiyunThere are plenty of patches in the links below to help with this work. 277*4882a593Smuzhiyun 278*4882a593Smuzhiyun[1] https://github.com/rkchrome/uboot.git 279*4882a593Smuzhiyun[2] https://github.com/linux-rockchip/u-boot-rockchip.git branch u-boot-rk3288 280*4882a593Smuzhiyun[3] https://github.com/linux-rockchip/rkflashtool.git 281*4882a593Smuzhiyun[4] http://wiki.t-firefly.com/index.php/Firefly-RK3288/Serial_debug/en 282*4882a593Smuzhiyun 283*4882a593Smuzhiyunrkimage 284*4882a593Smuzhiyun------- 285*4882a593Smuzhiyun 286*4882a593Smuzhiyunrkimage.c produces an SPL image suitable for sending directly to the boot ROM 287*4882a593Smuzhiyunover USB OTG. This is a very simple format - just the string RK32 (as 4 bytes) 288*4882a593Smuzhiyunfollowed by u-boot-spl-dtb.bin. 289*4882a593Smuzhiyun 290*4882a593SmuzhiyunThe boot ROM loads image to 0xff704000 which is in the internal SRAM. The SRAM 291*4882a593Smuzhiyunstarts at 0xff700000 and extends to 0xff718000 where we put the stack. 292*4882a593Smuzhiyun 293*4882a593Smuzhiyunrksd 294*4882a593Smuzhiyun---- 295*4882a593Smuzhiyun 296*4882a593Smuzhiyunrksd.c produces an image consisting of 32KB of empty space, a header and 297*4882a593Smuzhiyunu-boot-spl-dtb.bin. The header is defined by 'struct header0_info' although 298*4882a593Smuzhiyunmost of the fields are unused by U-Boot. We just need to specify the 299*4882a593Smuzhiyunsignature, a flag and the block offset and size of the SPL image. 300*4882a593Smuzhiyun 301*4882a593SmuzhiyunThe header occupies a single block but we pad it out to 4 blocks. The header 302*4882a593Smuzhiyunis encoding using RC4 with the key 7c4e0304550509072d2c7b38170d1711. The SPL 303*4882a593Smuzhiyunimage can be encoded too but we don't do that. 304*4882a593Smuzhiyun 305*4882a593SmuzhiyunThe maximum size of u-boot-spl-dtb.bin which the boot ROM will read is 32KB, 306*4882a593Smuzhiyunor 0x40 blocks. This is a severe and annoying limitation. There may be a way 307*4882a593Smuzhiyunaround this limitation, since there is plenty of SRAM, but at present the 308*4882a593Smuzhiyunboard refuses to boot if this limit is exceeded. 309*4882a593Smuzhiyun 310*4882a593SmuzhiyunThe image produced is padded up to a block boundary (512 bytes). It should be 311*4882a593Smuzhiyunwritten to the start of an SD card using dd. 312*4882a593Smuzhiyun 313*4882a593SmuzhiyunSince this image is set to load U-Boot from the SD card at block offset, 314*4882a593SmuzhiyunCONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR, dd should be used to write 315*4882a593Smuzhiyunu-boot-dtb.img to the SD card at that offset. See above for instructions. 316*4882a593Smuzhiyun 317*4882a593Smuzhiyunrkspi 318*4882a593Smuzhiyun----- 319*4882a593Smuzhiyun 320*4882a593Smuzhiyunrkspi.c produces an image consisting of a header and u-boot-spl-dtb.bin. The 321*4882a593Smuzhiyunresulting image is then spread out so that only the first 2KB of each 4KB 322*4882a593Smuzhiyunsector is used. The header is the same as with rksd and the maximum size is 323*4882a593Smuzhiyunalso 32KB (before spreading). The image should be written to the start of 324*4882a593SmuzhiyunSPI flash. 325*4882a593Smuzhiyun 326*4882a593SmuzhiyunSee above for instructions on how to write a SPI image. 327*4882a593Smuzhiyun 328*4882a593Smuzhiyunrkmux.py 329*4882a593Smuzhiyun-------- 330*4882a593Smuzhiyun 331*4882a593SmuzhiyunYou can use this script to create #defines for SoC register access. See the 332*4882a593Smuzhiyunscript for usage. 333*4882a593Smuzhiyun 334*4882a593Smuzhiyun 335*4882a593SmuzhiyunDevice tree and driver model 336*4882a593Smuzhiyun---------------------------- 337*4882a593Smuzhiyun 338*4882a593SmuzhiyunWhere possible driver model is used to provide a structure to the 339*4882a593Smuzhiyunfunctionality. Device tree is used for configuration. However these have an 340*4882a593Smuzhiyunoverhead and in SPL with a 32KB size limit some shortcuts have been taken. 341*4882a593SmuzhiyunIn general all Rockchip drivers should use these features, with SPL-specific 342*4882a593Smuzhiyunmodifications where required. 343*4882a593Smuzhiyun 344*4882a593SmuzhiyunGPT partition layout 345*4882a593Smuzhiyun---------------------------- 346*4882a593Smuzhiyun 347*4882a593SmuzhiyunRockchip use a unified GPT partition layout in open source support. 348*4882a593SmuzhiyunWith this GPT partition layout, uboot can be compatilbe with other components, 349*4882a593Smuzhiyunlike miniloader, trusted-os, arm-trust-firmware. 350*4882a593Smuzhiyun 351*4882a593SmuzhiyunThere are some documents about partitions in the links below. 352*4882a593Smuzhiyunhttp://rockchip.wikidot.com/partitions 353*4882a593Smuzhiyun 354*4882a593Smuzhiyun-- 355*4882a593SmuzhiyunSimon Glass <sjg@chromium.org> 356*4882a593Smuzhiyun24 June 2015 357