1adfb2bfeSSimon Glass# 2adfb2bfeSSimon Glass# Copyright (C) 2015 Google. Inc 3adfb2bfeSSimon Glass# Written by Simon Glass <sjg@chromium.org> 4adfb2bfeSSimon Glass# 5adfb2bfeSSimon Glass# SPDX-License-Identifier: GPL-2.0+ 6adfb2bfeSSimon Glass# 7adfb2bfeSSimon Glass 8adfb2bfeSSimon GlassU-Boot on Rockchip 9adfb2bfeSSimon Glass================== 10adfb2bfeSSimon Glass 11adfb2bfeSSimon GlassThere are several repositories available with versions of U-Boot that support 12adfb2bfeSSimon Glassmany Rockchip devices [1] [2]. 13adfb2bfeSSimon Glass 14adfb2bfeSSimon GlassThe current mainline support is experimental only and is not useful for 15adfb2bfeSSimon Glassanything. It should provide a base on which to build. 16adfb2bfeSSimon Glass 17adfb2bfeSSimon GlassSo far only support for the RK3288 is provided. 18adfb2bfeSSimon Glass 19adfb2bfeSSimon Glass 20adfb2bfeSSimon GlassPrerequisites 21adfb2bfeSSimon Glass============= 22adfb2bfeSSimon Glass 23adfb2bfeSSimon GlassYou will need: 24adfb2bfeSSimon Glass 25adfb2bfeSSimon Glass - Firefly RK3288 baord 26adfb2bfeSSimon Glass - Power connection to 5V using the supplied micro-USB power cable 27adfb2bfeSSimon Glass - Separate USB serial cable attached to your computer and the Firefly 28adfb2bfeSSimon Glass (connect to the micro-USB connector below the logo) 29adfb2bfeSSimon Glass - rkflashtool [3] 30adfb2bfeSSimon Glass - openssl (sudo apt-get install openssl) 31adfb2bfeSSimon Glass - Serial UART connection [4] 32adfb2bfeSSimon Glass - Suitable ARM cross compiler, e.g.: 33adfb2bfeSSimon Glass sudo apt-get install gcc-4.7-arm-linux-gnueabi 34adfb2bfeSSimon Glass 35adfb2bfeSSimon Glass 36adfb2bfeSSimon GlassBuilding 37adfb2bfeSSimon Glass======== 38adfb2bfeSSimon Glass 39adfb2bfeSSimon GlassAt present three RK3288 boards are supported: 40adfb2bfeSSimon Glass 41adfb2bfeSSimon Glass - Firefly RK3288 - use firefly-rk3288 configuration 42f2b3017cSSjoerd Simons - Radxa Rock 2 - also uses firefly-rk3288 configuration 43adfb2bfeSSimon Glass - Haier Chromebook - use chromebook_jerry configuration 44adfb2bfeSSimon Glass 45adfb2bfeSSimon GlassFor example: 46adfb2bfeSSimon Glass 47adfb2bfeSSimon Glass CROSS_COMPILE=arm-linux-gnueabi- make O=firefly firefly-rk3288_defconfig all 48adfb2bfeSSimon Glass 49adfb2bfeSSimon Glass(or you can use another cross compiler if you prefer) 50adfb2bfeSSimon Glass 51f2b3017cSSjoerd SimonsNote that the Radxa Rock 2 uses the Firefly configuration for now as 52f2b3017cSSjoerd Simonsdevice tree files are not yet available for the Rock 2. Clearly the two 53adfb2bfeSSimon Glasshave hardware differences, so this approach will break down as more drivers 54adfb2bfeSSimon Glassare added. 55adfb2bfeSSimon Glass 56adfb2bfeSSimon Glass 57adfb2bfeSSimon GlassWriting to the board with USB 58adfb2bfeSSimon Glass============================= 59adfb2bfeSSimon Glass 60adfb2bfeSSimon GlassFor USB to work you must get your board into ROM boot mode, either by erasing 61adfb2bfeSSimon Glassyour MMC or (perhaps) holding the recovery button when you boot the board. 62adfb2bfeSSimon GlassTo erase your MMC, you can boot into Linux and type (as root) 63adfb2bfeSSimon Glass 64adfb2bfeSSimon Glass dd if=/dev/zero of=/dev/mmcblk0 bs=1M 65adfb2bfeSSimon Glass 66adfb2bfeSSimon GlassConnect your board's OTG port to your computer. 67adfb2bfeSSimon Glass 68adfb2bfeSSimon GlassTo create a suitable image and write it to the board: 69adfb2bfeSSimon Glass 70*f2acc55eSSimon Glass ./firefly-rk3288/tools/mkimage -T rkimage -d \ 71*f2acc55eSSimon Glass ./firefly-rk3288/spl/u-boot-spl-dtb.bin out && \ 72adfb2bfeSSimon Glass cat out | openssl rc4 -K 7c4e0304550509072d2c7b38170d1711 | rkflashtool l 73adfb2bfeSSimon Glass 74adfb2bfeSSimon GlassIf all goes well you should something like: 75adfb2bfeSSimon Glass 76adfb2bfeSSimon Glass U-Boot SPL 2015.07-rc1-00383-ge345740-dirty (Jun 03 2015 - 10:06:49) 77adfb2bfeSSimon Glass Card did not respond to voltage select! 78adfb2bfeSSimon Glass spl: mmc init failed with error: -17 79adfb2bfeSSimon Glass ### ERROR ### Please RESET the board ### 80adfb2bfeSSimon Glass 81adfb2bfeSSimon GlassYou will need to reset the board before each time you try. Yes, that's all 82adfb2bfeSSimon Glassit does so far. If support for the Rockchip USB protocol or DFU were added 83adfb2bfeSSimon Glassin SPL then we could in principle load U-Boot and boot to a prompt from USB 84adfb2bfeSSimon Glassas several other platforms do. However it does not seem to be possible to 85adfb2bfeSSimon Glassuse the existing boot ROM code from SPL. 86adfb2bfeSSimon Glass 87adfb2bfeSSimon Glass 88adfb2bfeSSimon GlassBooting from an SD card 89adfb2bfeSSimon Glass======================= 90adfb2bfeSSimon Glass 91adfb2bfeSSimon GlassTo write an image that boots from an SD card (assumed to be /dev/sdc): 92adfb2bfeSSimon Glass 93*f2acc55eSSimon Glass ./firefly-rk3288/tools/mkimage -T rksd -d \ 94*f2acc55eSSimon Glass firefly-rk3288/spl/u-boot-spl-dtb.bin out && \ 95*f2acc55eSSimon Glass sudo dd if=out of=/dev/sdc seek=64 && \ 96adfb2bfeSSimon Glass sudo dd if=firefly-rk3288/u-boot-dtb.img of=/dev/sdc seek=256 97adfb2bfeSSimon Glass 98adfb2bfeSSimon GlassThis puts the Rockchip header and SPL image first and then places the U-Boot 99adfb2bfeSSimon Glassimage at block 256 (i.e. 128KB from the start of the SD card). This 100adfb2bfeSSimon Glasscorresponds with this setting in U-Boot: 101adfb2bfeSSimon Glass 102adfb2bfeSSimon Glass #define CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR 256 103adfb2bfeSSimon Glass 104adfb2bfeSSimon GlassPut this SD (or micro-SD) card into your board and reset it. You should see 105adfb2bfeSSimon Glasssomething like: 106adfb2bfeSSimon Glass 107adfb2bfeSSimon Glass U-Boot SPL 2015.07-rc1-00383-ge345740-dirty (Jun 03 2015 - 11:04:40) 108adfb2bfeSSimon Glass 109adfb2bfeSSimon Glass 110adfb2bfeSSimon Glass U-Boot 2015.07-rc1-00383-ge345740-dirty (Jun 03 2015 - 11:04:40) 111adfb2bfeSSimon Glass 112adfb2bfeSSimon Glass DRAM: 2 GiB 113adfb2bfeSSimon Glass MMC: 114adfb2bfeSSimon Glass Using default environment 115adfb2bfeSSimon Glass 116adfb2bfeSSimon Glass In: serial@ff690000 117adfb2bfeSSimon Glass Out: serial@ff690000 118adfb2bfeSSimon Glass Err: serial@ff690000 119adfb2bfeSSimon Glass => 120adfb2bfeSSimon Glass 121adfb2bfeSSimon Glass 122adfb2bfeSSimon GlassBooting from SPI 123adfb2bfeSSimon Glass================ 124adfb2bfeSSimon Glass 125adfb2bfeSSimon GlassTo write an image that boots from SPI flash (e.g. for the Haier Chromebook): 126adfb2bfeSSimon Glass 127adfb2bfeSSimon Glass ./chromebook_jerry/tools/mkimage -T rkspi -d chromebook_jerry/spl/u-boot-spl-dtb.bin out 128adfb2bfeSSimon Glass dd if=spl.bin of=out.bin bs=128K conv=sync 129adfb2bfeSSimon Glass cat chromebook_jerry/u-boot-dtb.img out.bin 130adfb2bfeSSimon Glass dd if=out.bin of=out.bin.pad bs=4M conv=sync 131adfb2bfeSSimon Glass 132adfb2bfeSSimon GlassThis converts the SPL image to the required SPI format by adding the Rockchip 133adfb2bfeSSimon Glassheader and skipping every 2KB block. Then the U-Boot image is written at 134adfb2bfeSSimon Glassoffset 128KB and the whole image is padded to 4MB which is the SPI flash size. 135adfb2bfeSSimon GlassThe position of U-Boot is controlled with this setting in U-Boot: 136adfb2bfeSSimon Glass 137adfb2bfeSSimon Glass #define CONFIG_SYS_SPI_U_BOOT_OFFS (128 << 10) 138adfb2bfeSSimon Glass 139adfb2bfeSSimon GlassIf you have a Dediprog em100pro connected then you can write the image with: 140adfb2bfeSSimon Glass 141adfb2bfeSSimon Glass sudo em100 -s -c GD25LQ32 -d out.bin.pad -r 142adfb2bfeSSimon Glass 143adfb2bfeSSimon GlassWhen booting you should see something like: 144adfb2bfeSSimon Glass 145adfb2bfeSSimon Glass U-Boot SPL 2015.07-rc2-00215-g9a58220-dirty (Jun 23 2015 - 12:11:32) 146adfb2bfeSSimon Glass 147adfb2bfeSSimon Glass 148adfb2bfeSSimon Glass U-Boot 2015.07-rc2-00215-g9a58220-dirty (Jun 23 2015 - 12:11:32 -0600) 149adfb2bfeSSimon Glass 150adfb2bfeSSimon Glass Model: Google Jerry 151adfb2bfeSSimon Glass DRAM: 2 GiB 152adfb2bfeSSimon Glass MMC: 153adfb2bfeSSimon Glass Using default environment 154adfb2bfeSSimon Glass 155adfb2bfeSSimon Glass In: serial@ff690000 156adfb2bfeSSimon Glass Out: serial@ff690000 157adfb2bfeSSimon Glass Err: serial@ff690000 158adfb2bfeSSimon Glass => 159adfb2bfeSSimon Glass 160adfb2bfeSSimon Glass 161adfb2bfeSSimon GlassFuture work 162adfb2bfeSSimon Glass=========== 163adfb2bfeSSimon Glass 164adfb2bfeSSimon GlassImmediate priorities are: 165adfb2bfeSSimon Glass 166adfb2bfeSSimon Glass- GPIO (driver exists but is lightly tested) 167adfb2bfeSSimon Glass- I2C (driver exists but is non-functional) 168adfb2bfeSSimon Glass- USB host 169adfb2bfeSSimon Glass- USB device 170adfb2bfeSSimon Glass- PMIC and regulators (only ACT8846 is supported at present) 171adfb2bfeSSimon Glass- LCD and HDMI 172adfb2bfeSSimon Glass- Run CPU at full speed 173adfb2bfeSSimon Glass- Ethernet 174adfb2bfeSSimon Glass- NAND flash 175adfb2bfeSSimon Glass- Support for other Rockchip parts 176adfb2bfeSSimon Glass- Boot U-Boot proper over USB OTG (at present only SPL works) 177adfb2bfeSSimon Glass 178adfb2bfeSSimon Glass 179adfb2bfeSSimon GlassDevelopment Notes 180adfb2bfeSSimon Glass================= 181adfb2bfeSSimon Glass 182adfb2bfeSSimon GlassThere are plenty of patches in the links below to help with this work. 183adfb2bfeSSimon Glass 184adfb2bfeSSimon Glass[1] https://github.com/rkchrome/uboot.git 185adfb2bfeSSimon Glass[2] https://github.com/linux-rockchip/u-boot-rockchip.git branch u-boot-rk3288 186adfb2bfeSSimon Glass[3] https://github.com/linux-rockchip/rkflashtool.git 187adfb2bfeSSimon Glass[4] http://wiki.t-firefly.com/index.php/Firefly-RK3288/Serial_debug/en 188adfb2bfeSSimon Glass 189adfb2bfeSSimon Glassrkimage 190adfb2bfeSSimon Glass------- 191adfb2bfeSSimon Glass 192adfb2bfeSSimon Glassrkimage.c produces an SPL image suitable for sending directly to the boot ROM 193adfb2bfeSSimon Glassover USB OTG. This is a very simple format - just the string RK32 (as 4 bytes) 194adfb2bfeSSimon Glassfollowed by u-boot-spl-dtb.bin. 195adfb2bfeSSimon Glass 196adfb2bfeSSimon GlassThe boot ROM loads image to 0xff704000 which is in the internal SRAM. The SRAM 197adfb2bfeSSimon Glassstarts at 0xff700000 and extends to 0xff718000 where we put the stack. 198adfb2bfeSSimon Glass 199adfb2bfeSSimon Glassrksd 200adfb2bfeSSimon Glass---- 201adfb2bfeSSimon Glass 202adfb2bfeSSimon Glassrksd.c produces an image consisting of 32KB of empty space, a header and 203adfb2bfeSSimon Glassu-boot-spl-dtb.bin. The header is defined by 'struct header0_info' although 204adfb2bfeSSimon Glassmost of the fields are unused by U-Boot. We just need to specify the 205adfb2bfeSSimon Glasssignature, a flag and the block offset and size of the SPL image. 206adfb2bfeSSimon Glass 207adfb2bfeSSimon GlassThe header occupies a single block but we pad it out to 4 blocks. The header 208adfb2bfeSSimon Glassis encoding using RC4 with the key 7c4e0304550509072d2c7b38170d1711. The SPL 209adfb2bfeSSimon Glassimage can be encoded too but we don't do that. 210adfb2bfeSSimon Glass 211adfb2bfeSSimon GlassThe maximum size of u-boot-spl-dtb.bin which the boot ROM will read is 32KB, 212adfb2bfeSSimon Glassor 0x40 blocks. This is a severe and annoying limitation. There may be a way 213adfb2bfeSSimon Glassaround this limitation, since there is plenty of SRAM, but at present the 214adfb2bfeSSimon Glassboard refuses to boot if this limit is exceeded. 215adfb2bfeSSimon Glass 216adfb2bfeSSimon GlassThe image produced is padded up to a block boundary (512 bytes). It should be 217adfb2bfeSSimon Glasswritten to the start of an SD card using dd. 218adfb2bfeSSimon Glass 219adfb2bfeSSimon GlassSince this image is set to load U-Boot from the SD card at block offset, 220adfb2bfeSSimon GlassCONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR, dd should be used to write 221adfb2bfeSSimon Glassu-boot-dtb.img to the SD card at that offset. See above for instructions. 222adfb2bfeSSimon Glass 223adfb2bfeSSimon Glassrkspi 224adfb2bfeSSimon Glass----- 225adfb2bfeSSimon Glass 226adfb2bfeSSimon Glassrkspi.c produces an image consisting of a header and u-boot-spl-dtb.bin. The 227adfb2bfeSSimon Glassresulting image is then spread out so that only the first 2KB of each 4KB 228adfb2bfeSSimon Glasssector is used. The header is the same as with rksd and the maximum size is 229adfb2bfeSSimon Glassalso 32KB (before spreading). The image should be written to the start of 230adfb2bfeSSimon GlassSPI flash. 231adfb2bfeSSimon Glass 232adfb2bfeSSimon GlassSee above for instructions on how to write a SPI image. 233adfb2bfeSSimon Glass 234adfb2bfeSSimon Glass 235adfb2bfeSSimon GlassDevice tree and driver model 236adfb2bfeSSimon Glass---------------------------- 237adfb2bfeSSimon Glass 238adfb2bfeSSimon GlassWhere possible driver model is used to provide a structure to the 239adfb2bfeSSimon Glassfunctionality. Device tree is used for configuration. However these have an 240adfb2bfeSSimon Glassoverhead and in SPL with a 32KB size limit some shortcuts have been taken. 241adfb2bfeSSimon GlassIn general all Rockchip drivers should use these features, with SPL-specific 242adfb2bfeSSimon Glassmodifications where required. 243adfb2bfeSSimon Glass 244adfb2bfeSSimon Glass 245adfb2bfeSSimon Glass-- 246adfb2bfeSSimon GlassSimon Glass <sjg@chromium.org> 247adfb2bfeSSimon Glass24 June 2015 248