1c265db7dSAndre PrzywaraAllwinner 64-bit boards README 2c265db7dSAndre Przywara============================== 3c265db7dSAndre Przywara 4c265db7dSAndre PrzywaraNewer Allwinner SoCs feature ARMv8 cores (ARM Cortex-A53) with support for 5c265db7dSAndre Przywaraboth the 64-bit AArch64 mode and the ARMv7 compatible 32-bit AArch32 mode. 6c265db7dSAndre PrzywaraExamples are the Allwinner A64 (used for instance on the Pine64 board) or 7c265db7dSAndre Przywarathe Allwinner H5 SoC (as used on the OrangePi PC 2). 8c265db7dSAndre PrzywaraThese SoCs are wired to start in AArch32 mode on reset and execute 32-bit 9c265db7dSAndre Przywaracode from the Boot ROM (BROM). As this has some implications on U-Boot, this 10c265db7dSAndre Przywarafile describes how to make full use of the 64-bit capabilities. 11c265db7dSAndre Przywara 12c265db7dSAndre PrzywaraQuick Start / Overview 13c265db7dSAndre Przywara====================== 14c265db7dSAndre Przywara- Build the ARM Trusted Firmware binary (see "ARM Trusted Firmware (ATF)" below) 15*8a6121eaSAndre Przywara $ cd /src/arm-trusted-firmware 16*8a6121eaSAndre Przywara $ make PLAT=sun50i_a64 DEBUG=1 bl31 17c265db7dSAndre Przywara- Build U-Boot (see "SPL/U-Boot" below) 18*8a6121eaSAndre Przywara $ export BL31=/path/to/bl31.bin 19*8a6121eaSAndre Przywara $ make pine64_plus_defconfig && make -j5 20c265db7dSAndre Przywara- Transfer to an uSD card (see "microSD card" below) 21*8a6121eaSAndre Przywara $ dd if=u-boot-sunxi-with-spl.bin of=/dev/sdx bs=8k seek=1 22c265db7dSAndre Przywara- Boot and enjoy! 23c265db7dSAndre Przywara 24c265db7dSAndre PrzywaraBuilding the firmware 25c265db7dSAndre Przywara===================== 26c265db7dSAndre Przywara 27c265db7dSAndre PrzywaraThe Allwinner A64/H5 firmware consists of three parts: U-Boot's SPL, an 28c265db7dSAndre PrzywaraARM Trusted Firmware (ATF) build and the U-Boot proper. 29c265db7dSAndre PrzywaraThe SPL will load both ATF and U-Boot proper along with the right device 30c265db7dSAndre Przywaratree blob (.dtb) and will pass execution to ATF (in EL3), which in turn will 31c265db7dSAndre Przywaradrop into the U-Boot proper (in EL2). 32c265db7dSAndre PrzywaraAs the ATF binary will become part of the U-Boot image file, you will need 33c265db7dSAndre Przywarato build it first. 34c265db7dSAndre Przywara 35c265db7dSAndre Przywara ARM Trusted Firmware (ATF) 36c265db7dSAndre Przywara---------------------------- 37*8a6121eaSAndre PrzywaraCheckout the latest master branch from the official ATF repository [1] and 38*8a6121eaSAndre Przywarabuild it: 39c265db7dSAndre Przywara$ export CROSS_COMPILE=aarch64-linux-gnu- 40*8a6121eaSAndre Przywara$ make PLAT=sun50i_a64 DEBUG=1 bl31 41*8a6121eaSAndre PrzywaraThe resulting binary is build/sun50i_a64/debug/bl31.bin. Either put the 42c265db7dSAndre Przywaralocation of this file into the BL31 environment variable or copy this to 43c265db7dSAndre Przywarathe root of your U-Boot build directory (or create a symbolic link). 44*8a6121eaSAndre Przywara$ export BL31=/src/arm-trusted-firmware/build/sun50i_a64/debug/bl31.bin 45c265db7dSAndre Przywara (adjust the actual path accordingly) 46*8a6121eaSAndre PrzywaraThe platform target "sun50i_a64" covers all boards with either an Allwinner 47*8a6121eaSAndre PrzywaraA64 or H5 SoC (since they are very similar). For boards with an Allwinner H6 48*8a6121eaSAndre PrzywaraSoC use "sun50i_h6". 49c265db7dSAndre Przywara 5035debf8aSAndre PrzywaraIf you run into size issues with the resulting U-Boot image file, it might 5135debf8aSAndre Przywarahelp to use a release build, by using "DEBUG=0" when building bl31.bin. 5235debf8aSAndre PrzywaraAs sometimes the ATF build process is a bit picky about the toolchain used, 5335debf8aSAndre Przywaraor if you can't be bothered with building ATF, there are known working 5435debf8aSAndre Przywarabinaries in the firmware repository[3], purely for convenience reasons. 5535debf8aSAndre Przywara 56c265db7dSAndre Przywara SPL/U-Boot 57c265db7dSAndre Przywara------------ 58c265db7dSAndre PrzywaraBoth U-Boot proper and the SPL are using the 64-bit mode. As the boot ROM 59c265db7dSAndre Przywaraenters the SPL still in AArch32 secure SVC mode, there is some shim code to 60c265db7dSAndre Przywaraenter AArch64 very early. The rest of the SPL runs in AArch64 EL3. 61c265db7dSAndre PrzywaraU-Boot proper runs in EL2 and can load any AArch64 code (using the "go" 62c265db7dSAndre Przywaracommand), EFI applications (with "bootefi") or arm64 Linux kernel images 63c265db7dSAndre Przywara(often named "Image"), using the "booti" command. 64c265db7dSAndre Przywara 65c265db7dSAndre Przywara$ make clean 66c265db7dSAndre Przywara$ export CROSS_COMPILE=aarch64-linux-gnu- 67c265db7dSAndre Przywara$ make pine64_plus_defconfig 68c265db7dSAndre Przywara$ make 69c265db7dSAndre Przywara 70c265db7dSAndre PrzywaraThis will build the SPL in spl/sunxi-spl.bin and a FIT image called u-boot.itb, 71*8a6121eaSAndre Przywarawhich contains the rest of the firmware. u-boot-sunxi-with-spl.bin joins those 72*8a6121eaSAndre Przywaratwo components in one convenient image file. 73c265db7dSAndre Przywara 74c265db7dSAndre Przywara 75c265db7dSAndre PrzywaraBoot process 76c265db7dSAndre Przywara============ 77c265db7dSAndre PrzywaraThe on-die BROM code will try several methods to load and execute the firmware. 78c265db7dSAndre PrzywaraOn a typical board like the Pine64 this will result in the following boot order: 79c265db7dSAndre Przywara 80c265db7dSAndre Przywara1) Reading 32KB from sector 16 (@8K) of the microSD card to SRAM A1. If the 81c265db7dSAndre PrzywaraBROM finds the magic "eGON" header in the first bytes, it will execute that 82c265db7dSAndre Przywaracode. If not (no SD card at all or invalid magic), it will: 83c265db7dSAndre Przywara2) Try to read 32KB from sector 16 (@8K) of memory connected to the MMC2 84c265db7dSAndre Przywaracontroller, typically an on-board eMMC chip. If there is no eMMC or it does 85c265db7dSAndre Przywaranot contain a valid boot header, it will: 86c265db7dSAndre Przywara3) Initialize the SPI0 controller and try to access a NOR flash connected to 87c265db7dSAndre Przywarait (using the CS0 pin). If a flash chip is found, the BROM will load the 88c265db7dSAndre Przywarafirst 32KB (from offset 0) into SRAM A1. Now it checks for the magic eGON 89c265db7dSAndre Przywaraheader and checksum and will execute the code upon finding it. If not, it will: 90c265db7dSAndre Przywara4) Initialize the USB OTG controller and will wait for a host to connect to 91c265db7dSAndre Przywarait, speaking the Allwinner proprietary (but deciphered) "FEL" USB protocol. 92c265db7dSAndre Przywara 93c265db7dSAndre Przywara 94c265db7dSAndre PrzywaraTo boot the Pine64 board, you can use U-Boot and any of the described methods. 95c265db7dSAndre Przywara 96c265db7dSAndre PrzywaraFEL boot (USB OTG) 97c265db7dSAndre Przywara------------------ 98c265db7dSAndre PrzywaraFEL is the name of the Allwinner defined USB boot protocol built in the 99c265db7dSAndre Przywaramask ROM of most Allwinner SoCs. It allows to bootstrap a board solely 100c265db7dSAndre Przywaraby using the USB-OTG interface and a host port on another computer. 101c265db7dSAndre PrzywaraAs the FEL mode is controlled by the boot ROM, it expects to be running in 102c265db7dSAndre PrzywaraAArch32. For now the AArch64 SPL cannot properly return into FEL mode, so the 103c265db7dSAndre Przywarafeature is disabled in the configuration at the moment. 104*8a6121eaSAndre PrzywaraThe repository in [3] contains FEL capable SPL binaries, built using an 105*8a6121eaSAndre Przywaraoff-tree branch to generate 32-bit ARM code (along with instructions 106*8a6121eaSAndre Przywarahow to re-create them). 107c265db7dSAndre Przywara 108c265db7dSAndre PrzywaramicroSD card 109c265db7dSAndre Przywara------------ 110c265db7dSAndre PrzywaraTransfer the SPL and the U-Boot FIT image directly to an uSD card: 111c265db7dSAndre Przywara# dd if=spl/sunxi-spl.bin of=/dev/sdx bs=8k seek=1 112c265db7dSAndre Przywara# dd if=u-boot.itb of=/dev/sdx bs=8k seek=5 113c265db7dSAndre Przywara# sync 114c265db7dSAndre Przywara(replace /dev/sdx with you SD card device file name, which could be 115c265db7dSAndre Przywara/dev/mmcblk[x] as well). 116c265db7dSAndre Przywara 117b0b0d22fSTuomas TynkkynenAlternatively you can use the SPL and the U-Boot FIT image combined into a 118c265db7dSAndre Przywarasingle file and transfer that instead: 119c265db7dSAndre Przywara# dd if=u-boot-sunxi-with-spl.bin of=/dev/sdx bs=8k seek=1 120c265db7dSAndre Przywara 121c265db7dSAndre PrzywaraYou can partition the microSD card, but leave the first MB unallocated (most 122c265db7dSAndre Przywarapartitioning tools will do this anyway). 123c265db7dSAndre Przywara 124c265db7dSAndre PrzywaraNOR flash 125c265db7dSAndre Przywara--------- 126c265db7dSAndre PrzywaraSome boards (like the SoPine, Pinebook or the OrangePi PC2) come with a 127c265db7dSAndre Przywarasoldered SPI NOR flash chip. On other boards like the Pine64 such a chip 128c265db7dSAndre Przywaracan be connected to the SPI0/CS0 pins on the PI-2 headers. 129c265db7dSAndre PrzywaraCreate the SPL and FIT image like described above for the SD card. 130c265db7dSAndre PrzywaraNow connect either an "A to A" USB cable to the upper USB port on the Pine64 131c265db7dSAndre Przywaraor get an adaptor and use a regular A-microB cable connected to it. Other 132c265db7dSAndre Przywaraboards often have a proper micro-B USB socket connected to the USB OTB port. 133c265db7dSAndre PrzywaraRemove a microSD card from the slot and power on the board. 134c265db7dSAndre PrzywaraOn your host computer download and build the sunxi-tools package[2], then 135c265db7dSAndre Przywarause "sunxi-fel" to access the board: 136c265db7dSAndre Przywara$ ./sunxi-fel ver -v -p 137c265db7dSAndre PrzywaraThis should give you an output starting with: AWUSBFEX soc=00001689(A64) ... 138c265db7dSAndre PrzywaraNow use the sunxi-fel tool to write to the NOR flash: 139c265db7dSAndre Przywara$ ./sunxi-fel spiflash-write 0 spl/sunxi-spl.bin 140c265db7dSAndre Przywara$ ./sunxi-fel spiflash-write 32768 u-boot.itb 141c265db7dSAndre PrzywaraNow boot the board without an SD card inserted and you should see the 142c265db7dSAndre PrzywaraU-Boot prompt on the serial console. 143c265db7dSAndre Przywara 144c265db7dSAndre Przywara(Legacy) boot0 method 145c265db7dSAndre Przywara--------------------- 146297963f5SPriit Laesboot0 is Allwinner's secondary program loader and it can be used as some kind 147c265db7dSAndre Przywaraof SPL replacement to get U-Boot up and running from an microSD card. 148c265db7dSAndre PrzywaraFor some time using boot0 was the only option to get the Pine64 booted. 149c265db7dSAndre PrzywaraWith working DRAM init code in U-Boot's SPL this is no longer necessary, 150c265db7dSAndre Przywarabut this method is described here for the sake of completeness. 151c265db7dSAndre PrzywaraPlease note that this method works only with the boot0 files shipped with 152c265db7dSAndre PrzywaraA64 based boards, the H5 uses an incompatible layout which is not supported 153c265db7dSAndre Przywaraby this method. 154c265db7dSAndre Przywara 155c265db7dSAndre PrzywaraThe boot0 binary is a 32 KByte blob and contained in the official Pine64 images 156c265db7dSAndre Przywaradistributed by Pine64 or Allwinner. It can be easily extracted from a micro 157c265db7dSAndre PrzywaraSD card or an image file: 158c265db7dSAndre Przywara# dd if=/dev/sd<x> of=boot0.bin bs=8k skip=1 count=4 159c265db7dSAndre Przywarawhere /dev/sd<x> is the device name of the uSD card or the name of the image 160c265db7dSAndre Przywarafile. Apparently Allwinner allows re-distribution of this proprietary code 161c265db7dSAndre Przywara"as-is". 162c265db7dSAndre PrzywaraThis boot0 blob takes care of DRAM initialisation and loads the remaining 163c265db7dSAndre Przywarafirmware parts, then switches the core into AArch64 mode. 164c265db7dSAndre PrzywaraThe original boot0 code looks for U-Boot at a certain place on an uSD card 165c265db7dSAndre Przywara(at 19096 KB), also it expects a header with magic bytes and a checksum. 166c265db7dSAndre PrzywaraThere is a tool called boot0img[3] which takes a boot0.bin image and a compiled 167c265db7dSAndre PrzywaraU-Boot binary (plus other binaries) and will populate that header accordingly. 168c265db7dSAndre PrzywaraTo make space for the magic header, the pine64_plus_defconfig will make sure 169c265db7dSAndre Przywarathere is sufficient space at the beginning of the U-Boot binary. 170c265db7dSAndre Przywaraboot0img will also take care of putting the different binaries at the right 171c265db7dSAndre Przywaraplaces on the uSD card and works around unused, but mandatory parts by using 172c265db7dSAndre Przywaratrampoline code. See the output of "boot0img -h" for more information. 173c265db7dSAndre Przywaraboot0img can also patch boot0 to avoid loading U-Boot from 19MB, instead 174c265db7dSAndre Przywarafetching it from just behind the boot0 binary (-B option). 175c265db7dSAndre Przywara$ ./boot0img -o firmware.img -B boot0.img -u u-boot-dtb.bin -e -s bl31.bin \ 176c265db7dSAndre Przywara-a 0x44008 -d trampoline64:0x44000 177c265db7dSAndre PrzywaraThen write this image to a microSD card, replacing /dev/sdx with the right 178c265db7dSAndre Przywaradevice file (see above): 179c265db7dSAndre Przywara$ dd if=firmware.img of=/dev/sdx bs=8k seek=1 180c265db7dSAndre Przywara 181*8a6121eaSAndre Przywara[1] https://github.com/ARM-software/arm-trusted-firmware.git 182c265db7dSAndre Przywara[2] git://github.com/linux-sunxi/sunxi-tools.git 183c265db7dSAndre Przywara[3] https://github.com/apritzel/pine64/ 184