u-boot-brain/board/sunxi
Andre Przywara 83843c9b3a sunxi: A64: do an RMR switch if started in AArch32 mode
The Allwinner A64 SoC starts execution in AArch32 mode, and both
the boot ROM and Allwinner's boot0 keep running in this mode.
So U-Boot gets entered in 32-bit, although we want it to run in AArch64.

By using a "magic" instruction, which happens to be an almost-NOP in
AArch64 and a branch in AArch32, we differentiate between being
entered in 64-bit or 32-bit mode.
If in 64-bit mode, we proceed with the branch to reset, but in 32-bit
mode we trigger an RMR write to bring the core into AArch64/EL3 and
re-enter U-Boot at CONFIG_SYS_TEXT_BASE.
This allows a 64-bit U-Boot to be both entered in 32 and 64-bit mode,
so we can use the same start code for the SPL and the U-Boot proper.

We use the existing custom header (boot0.h) functionality, but restrict
the existing boot0 header reservation to the non-SPL build now. A SPL
wouldn't need such header anyway. This allows to have both options
defined and lets us use one for the SPL and the other for U-Boot proper.

Also add arch/arm/mach-sunxi/rmr_switch.S, which contains the original
ARM assembly code and instructions how to re-generate the encoded
version.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Acked-by: Maxime Ripard <maxime.ripard@free-electrons.com>
Reviewed-by: Jagan Teki <jagan@openedev.com>
2017-01-04 16:37:42 +01:00
..
ahci.c sunxi: Turn satapwr on from board_init 2016-03-23 22:04:13 +01:00
board.c sunxi: add MMC pinmux setup for SDC2 on sun9i 2016-10-30 11:38:04 +01:00
dram_sun4i_auto.c Kill unneeded #include <linux/kconfig.h> 2015-07-27 15:02:12 -04:00
dram_sun5i_auto.c Kill unneeded #include <linux/kconfig.h> 2015-07-27 15:02:12 -04:00
dram_timings_sun4i.h sunxi: dram: Optionally use standard JEDEC timings for sun[457]i 2015-02-02 14:04:15 +01:00
gmac.c sunxi: Fix gmac not working due to cpu_eth_init no longer being called 2016-03-23 22:04:13 +01:00
Kconfig sunxi: A64: do an RMR switch if started in AArch32 mode 2017-01-04 16:37:42 +01:00
MAINTAINERS sunxi: add support for Nintendo NES Classic Edition 2016-11-28 15:10:30 -05:00
Makefile sunxi: Convert sun5i boards to use auto dram configuration 2015-02-02 13:55:14 +01:00
README.pine64 doc: ARMv8: add README.pine64 2016-07-11 10:57:45 -04:00

Pine64 board README
====================

The Pine64(+) is a single board computer equipped with an AArch64 capable ARMv8
compliant Allwinner A64 SoC.
This chip has ARM Cortex A-53 cores and thus can run both in AArch32
(compatible to 32-bit ARMv7) and AArch64 modes. Upon reset the SoC starts
in AArch32 mode and executes 32-bit code from the Boot ROM (BROM).
This has some implications on U-Boot.

Quick start
============
- Get hold of a boot0.img file (see below for more details).
- Get the boot0img tool source from the tools directory in [1] and compile
  that on your host.
- Build U-Boot:
$ export CROSS_COMPILE=aarch64-linux-gnu-
$ make pine64_plus_defconfig
$ make
- You also need a compiled ARM Trusted Firmware (ATF) binary. Checkout the
  "allwinner" branch from the github repository [2] and build it:
$ export CROSS_COMPILE=aarch64-linux-gnu-
$ make PLAT=sun50iw1p1 DEBUG=1 bl31
  The resulting binary is build/sun50iw1p1/debug/bl31.bin.

Now put an empty (or disposable) micro SD card in your card reader and learn
its device file name, replacing /dev/sd<x> below with the result (that could
be /dev/mmcblk<x> as well):

$ ./boot0img --device /dev/sd<x> -e -u u-boot.bin -B boot0.img \
	-d trampoline64:0x44000 -s bl31.bin -a 0x44008 -p 100
(either copying the respective files to the working directory or specifying
the paths directly)

This will create a new partition table (with a 100 MB FAT boot partition),
copies boot0.img, ATF and U-Boot to the proper locations on the SD card and
will fill in the magic Allwinner header to be recognized by boot0.
Prefix the above call with "sudo" if you don't have write access to the
uSD card. You can also use "-o output.img" instead of "--device /dev/sd<x>"
to create an image file and "dd" that to the uSD card.
Omitting the "-p" option will skip the partition table.

Now put this uSD card in the board and power it on. You should be greeted by
the U-Boot prompt.


Main U-Boot
============
The main U-Boot proper is a real 64-bit ARMv8 port and runs entirely in the
64-bit AArch64 mode. It can load any AArch64 code, EFI applications or arm64
Linux kernel images (often named "Image") using the booti command.
Launching 32-bit code and kernels is technically possible, though not without
drawbacks (or hacks to avoid them) and currently not implemented.

SPL support
============
The main task of the SPL support is to bring up the DRAM controller and make
DRAM actually accessible. At the moment there is no documentation or source
code available which would do this.
There are currently two ways to overcome this situation: using a tainted 32-bit
SPL (involving some hacks and resulting in a non-redistributable binary, thus
not described here) or using the Allwinner boot0 blob.

boot0 method
-------------
boot0 is Allwiner's secondary program loader and it can be used as some kind
of SPL replacement to get U-Boot up and running.
The binary is a 32 KByte blob and contained on every Pine64 image distributed
so far. It can be easily extracted from a micro SD card or an image file:
# dd if=/dev/sd<x> of=boot0.bin bs=8k skip=1 count=4
where /dev/sd<x> is the device name of the uSD card or the name of the image
file. Apparently Allwinner allows re-distribution of this proprietary code
as-is.
For the time being this boot0 blob is the only redistributable way of making
U-Boot work on the Pine64. Beside loading the various parts of the (original)
firmware it also switches the core into AArch64 mode.
The original boot0 code looks for U-Boot at a certain place on an uSD card
(at 19096 KB), also it expects a header with magic bytes and a checksum.
There is a tool called boot0img[1] which takes a boot0.bin image and a compiled
U-Boot binary (plus other binaries) and will populate that header accordingly.
To make space for the magic header, the pine64_plus_defconfig will make sure
there is sufficient space at the beginning of the U-Boot binary.
boot0img will also take care of putting the different binaries at the right
places on the uSD card and works around unused, but mandatory parts by using
trampoline code. See the output of "boot0img -h" for more information.
boot0img can also patch boot0 to avoid loading U-Boot from 19MB, instead
fetching it from just behind the boot0 binary (-B option).

FEL boot
=========
FEL is the name of the Allwinner defined USB boot protocol built-in the
mask ROM of most Allwinner SoCs. It allows to bootstrap a board solely
by using the USB-OTG interface and a host port on another computer.
Since FEL boot does not work with boot0, it requires the libdram hack, which
is not described here.

[1] https://github.com/apritzel/pine64/
[2] https://github.com/apritzel/arm-trusted-firmware.git