From patchwork Wed Dec 13 06:03:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 847769 X-Patchwork-Delegate: jagannadh.teki@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=amarulasolutions-com.20150623.gappssmtp.com header.i=@amarulasolutions-com.20150623.gappssmtp.com header.b="V70aVs6D"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3yxR5N10R3z9sBZ for ; Wed, 13 Dec 2017 17:06:00 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id C6D64C21DA3; Wed, 13 Dec 2017 06:04:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 0EFCFC21DBA; Wed, 13 Dec 2017 06:03:53 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id E755FC21DAA; Wed, 13 Dec 2017 06:03:29 +0000 (UTC) Received: from mail-pl0-f65.google.com (mail-pl0-f65.google.com [209.85.160.65]) by lists.denx.de (Postfix) with ESMTPS id CB3E1C21DDB for ; Wed, 13 Dec 2017 06:03:28 +0000 (UTC) Received: by mail-pl0-f65.google.com with SMTP id s10so430356plj.5 for ; Tue, 12 Dec 2017 22:03:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=LXdTLKGHZ2B/GKAbjEsZy1Mlwe1RtFpvYWhb+WKFp7g=; b=V70aVs6DLOJVX+aXYU0aFD3fQZOEGXSWFTbLrYLrqLj5ftHYVA8hZTwBqnIMZ6zklk zDAO6O9Vb6ib/YioVjpvNB1wNRYc5PooJqsToT5HWMlhw7Ak8IYv5xzp8AD7r/7/Ts34 jEv1Rmtw6nRRc36Sg8aS1coqND1r72XYlYfcPuV47+c04yA5XuA3RtaREoRdl3G8x5ET n8uqmSY7N4+ueOo0POnGiI3A96YXQLUMSXKnSYijAD5eoZMIxSS74YHvOI/k4WR8RdfU pt0x1AnJQ64xBP1yrpljf9tY2fb6OwGnKIWqTG3pnuIWtYynRoxHmKSVCkDpPDqkdN8V w35w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=LXdTLKGHZ2B/GKAbjEsZy1Mlwe1RtFpvYWhb+WKFp7g=; b=fws/M13Y7nvvD70C8DQRguC/Kgyg8G8sArRwdnuUzhgPr4JCUnsOIcCW2l7qB1Cbrn IjnoQ8spCkMJyf9XWFwpiGv6zPN20wlLNjuNWEVP2fl4qBZGD3n7h9GyO4OWX7yC1c/j iMuT+9Ktb+NCqA0iic8PIS6JzMD6pHVuq4eYLUswbioYPBURRDzRjtVBsPvdpBmbVCA0 nu04nvUjiak4U+EtBnML+FfxB8BShQU8jPo7Edym93jJZDlWFE3z4/WYH+5Argi75a67 m5a9i48jfwBclXYe4cF4Jn10OlC1Yr0V238y9/s5iyE7k1Te0usf8l2Lh5bCxXpTg5lN rFsg== X-Gm-Message-State: AKGB3mIoTU/fDugrH33DjMrcpKtH+h9exX7nvSL6+qTclHHpnMwttMHQ Wdpv9uQoP8PA+T8joC36DVfQBQ== X-Google-Smtp-Source: ACJfBotoYY1aRjoVe0V6AoK7+FvOxIQwWJimB0cJ70krB/9S6dfd5u9H9Z2AiImfTm4hCti5tTpBEw== X-Received: by 10.159.246.7 with SMTP id b7mr4629817pls.81.1513145006974; Tue, 12 Dec 2017 22:03:26 -0800 (PST) Received: from localhost.localdomain ([115.97.180.212]) by smtp.gmail.com with ESMTPSA id v25sm1136810pgc.78.2017.12.12.22.03.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 12 Dec 2017 22:03:26 -0800 (PST) From: Jagan Teki To: Maxime Ripard Date: Wed, 13 Dec 2017 11:33:05 +0530 Message-Id: <1513144986-13619-4-git-send-email-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513144986-13619-1-git-send-email-jagan@amarulasolutions.com> References: <1513144986-13619-1-git-send-email-jagan@amarulasolutions.com> Cc: u-boot@lists.denx.de, linux-sunxi@googlegroups.com Subject: [U-Boot] [PATCH v3 4/5] docs: README.sunxi: Move sunxi64 documentation X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Move documentation of README.sunxi64 from board files into docs/README.sunxi Signed-off-by: Jagan Teki --- Changes for v3: - New patch board/sunxi/README.sunxi64 | 165 ------------------------------------------ doc/README.sunxi | 173 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 170 insertions(+), 168 deletions(-) delete mode 100644 board/sunxi/README.sunxi64 diff --git a/board/sunxi/README.sunxi64 b/board/sunxi/README.sunxi64 deleted file mode 100644 index c492f74..0000000 --- a/board/sunxi/README.sunxi64 +++ /dev/null @@ -1,165 +0,0 @@ -Allwinner 64-bit boards README -============================== - -Newer Allwinner SoCs feature ARMv8 cores (ARM Cortex-A53) with support for -both the 64-bit AArch64 mode and the ARMv7 compatible 32-bit AArch32 mode. -Examples are the Allwinner A64 (used for instance on the Pine64 board) or -the Allwinner H5 SoC (as used on the OrangePi PC 2). -These SoCs are wired to start in AArch32 mode on reset and execute 32-bit -code from the Boot ROM (BROM). As this has some implications on U-Boot, this -file describes how to make full use of the 64-bit capabilities. - -Quick Start / Overview -====================== -- Build the ARM Trusted Firmware binary (see "ARM Trusted Firmware (ATF)" below) -- Build U-Boot (see "SPL/U-Boot" below) -- Transfer to an uSD card (see "microSD card" below) -- Boot and enjoy! - -Building the firmware -===================== - -The Allwinner A64/H5 firmware consists of three parts: U-Boot's SPL, an -ARM Trusted Firmware (ATF) build and the U-Boot proper. -The SPL will load both ATF and U-Boot proper along with the right device -tree blob (.dtb) and will pass execution to ATF (in EL3), which in turn will -drop into the U-Boot proper (in EL2). -As the ATF binary will become part of the U-Boot image file, you will need -to build it first. - - ARM Trusted Firmware (ATF) ----------------------------- -Checkout the "allwinner" branch from the github repository [1] and build it: -$ export CROSS_COMPILE=aarch64-linux-gnu- -$ make PLAT=sun50iw1p1 DEBUG=1 bl31 -The resulting binary is build/sun50iw1p1/debug/bl31.bin. Either put the -location of this file into the BL31 environment variable or copy this to -the root of your U-Boot build directory (or create a symbolic link). -$ export BL31=/src/arm-trusted-firmware/build/sun50iw1p1/debug/bl31.bin - (adjust the actual path accordingly) - - SPL/U-Boot ------------- -Both U-Boot proper and the SPL are using the 64-bit mode. As the boot ROM -enters the SPL still in AArch32 secure SVC mode, there is some shim code to -enter AArch64 very early. The rest of the SPL runs in AArch64 EL3. -U-Boot proper runs in EL2 and can load any AArch64 code (using the "go" -command), EFI applications (with "bootefi") or arm64 Linux kernel images -(often named "Image"), using the "booti" command. - -$ make clean -$ export CROSS_COMPILE=aarch64-linux-gnu- -$ make pine64_plus_defconfig -$ make - -This will build the SPL in spl/sunxi-spl.bin and a FIT image called u-boot.itb, -which contains the rest of the firmware. - - -Boot process -============ -The on-die BROM code will try several methods to load and execute the firmware. -On a typical board like the Pine64 this will result in the following boot order: - -1) Reading 32KB from sector 16 (@8K) of the microSD card to SRAM A1. If the -BROM finds the magic "eGON" header in the first bytes, it will execute that -code. If not (no SD card at all or invalid magic), it will: -2) Try to read 32KB from sector 16 (@8K) of memory connected to the MMC2 -controller, typically an on-board eMMC chip. If there is no eMMC or it does -not contain a valid boot header, it will: -3) Initialize the SPI0 controller and try to access a NOR flash connected to -it (using the CS0 pin). If a flash chip is found, the BROM will load the -first 32KB (from offset 0) into SRAM A1. Now it checks for the magic eGON -header and checksum and will execute the code upon finding it. If not, it will: -4) Initialize the USB OTG controller and will wait for a host to connect to -it, speaking the Allwinner proprietary (but deciphered) "FEL" USB protocol. - - -To boot the Pine64 board, you can use U-Boot and any of the described methods. - -FEL boot (USB OTG) ------------------- -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. -As the FEL mode is controlled by the boot ROM, it expects to be running in -AArch32. For now the AArch64 SPL cannot properly return into FEL mode, so the -feature is disabled in the configuration at the moment. - -microSD card ------------- -Transfer the SPL and the U-Boot FIT image directly to an uSD card: -# dd if=spl/sunxi-spl.bin of=/dev/sdx bs=8k seek=1 -# dd if=u-boot.itb of=/dev/sdx bs=8k seek=5 -# sync -(replace /dev/sdx with you SD card device file name, which could be -/dev/mmcblk[x] as well). - -Alternatively you can concatenate the SPL and the U-Boot FIT image into a -single file and transfer that instead: -$ cat spl/sunxi-spl.bin u-boot.itb > u-boot-sunxi-with-spl.bin -# dd if=u-boot-sunxi-with-spl.bin of=/dev/sdx bs=8k seek=1 - -You can partition the microSD card, but leave the first MB unallocated (most -partitioning tools will do this anyway). - -NOR flash ---------- -Some boards (like the SoPine, Pinebook or the OrangePi PC2) come with a -soldered SPI NOR flash chip. On other boards like the Pine64 such a chip -can be connected to the SPI0/CS0 pins on the PI-2 headers. -Create the SPL and FIT image like described above for the SD card. -Now connect either an "A to A" USB cable to the upper USB port on the Pine64 -or get an adaptor and use a regular A-microB cable connected to it. Other -boards often have a proper micro-B USB socket connected to the USB OTB port. -Remove a microSD card from the slot and power on the board. -On your host computer download and build the sunxi-tools package[2], then -use "sunxi-fel" to access the board: -$ ./sunxi-fel ver -v -p -This should give you an output starting with: AWUSBFEX soc=00001689(A64) ... -Now use the sunxi-fel tool to write to the NOR flash: -$ ./sunxi-fel spiflash-write 0 spl/sunxi-spl.bin -$ ./sunxi-fel spiflash-write 32768 u-boot.itb -Now boot the board without an SD card inserted and you should see the -U-Boot prompt on the serial console. - -(Legacy) 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 from an microSD card. -For some time using boot0 was the only option to get the Pine64 booted. -With working DRAM init code in U-Boot's SPL this is no longer necessary, -but this method is described here for the sake of completeness. -Please note that this method works only with the boot0 files shipped with -A64 based boards, the H5 uses an incompatible layout which is not supported -by this method. - -The boot0 binary is a 32 KByte blob and contained in the official Pine64 images -distributed by Pine64 or Allwinner. It can be easily extracted from a micro -SD card or an image file: -# dd if=/dev/sd of=boot0.bin bs=8k skip=1 count=4 -where /dev/sd 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". -This boot0 blob takes care of DRAM initialisation and loads the remaining -firmware parts, then 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[3] 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). -$ ./boot0img -o firmware.img -B boot0.img -u u-boot-dtb.bin -e -s bl31.bin \ --a 0x44008 -d trampoline64:0x44000 -Then write this image to a microSD card, replacing /dev/sdx with the right -device file (see above): -$ dd if=firmware.img of=/dev/sdx bs=8k seek=1 - -[1] https://github.com/apritzel/arm-trusted-firmware.git -[2] git://github.com/linux-sunxi/sunxi-tools.git -[3] https://github.com/apritzel/pine64/ diff --git a/doc/README.sunxi b/doc/README.sunxi index ef4f735..48f82cb 100644 --- a/doc/README.sunxi +++ b/doc/README.sunxi @@ -9,9 +9,170 @@ U-Boot on SunXi Tutorial describe all details relevant for U-Boot on Allwinner SunXi platform. - 1. Verified Boot - -1. Verified Boot + 1. Allwinner 64-bit boards + 2. Verified Boot + +1. Allwinner 64-bit boards +========================== + +Newer Allwinner SoCs feature ARMv8 cores (ARM Cortex-A53) with support for +both the 64-bit AArch64 mode and the ARMv7 compatible 32-bit AArch32 mode. +Examples are the Allwinner A64 (used for instance on the Pine64 board) or +the Allwinner H5 SoC (as used on the OrangePi PC 2). +These SoCs are wired to start in AArch32 mode on reset and execute 32-bit +code from the Boot ROM (BROM). As this has some implications on U-Boot, this +file describes how to make full use of the 64-bit capabilities. + +Quick Start / Overview +====================== +- Build the ARM Trusted Firmware binary (see "ARM Trusted Firmware (ATF)" below) +- Build U-Boot (see "SPL/U-Boot" below) +- Transfer to an uSD card (see "microSD card" below) +- Boot and enjoy! + +Building the firmware +===================== + +The Allwinner A64/H5 firmware consists of three parts: U-Boot's SPL, an +ARM Trusted Firmware (ATF) build and the U-Boot proper. +The SPL will load both ATF and U-Boot proper along with the right device +tree blob (.dtb) and will pass execution to ATF (in EL3), which in turn will +drop into the U-Boot proper (in EL2). +As the ATF binary will become part of the U-Boot image file, you will need +to build it first. + + ARM Trusted Firmware (ATF) +---------------------------- +Checkout the "allwinner" branch from the github repository [1] and build it: +$ export CROSS_COMPILE=aarch64-linux-gnu- +$ make PLAT=sun50iw1p1 DEBUG=1 bl31 +The resulting binary is build/sun50iw1p1/debug/bl31.bin. Either put the +location of this file into the BL31 environment variable or copy this to +the root of your U-Boot build directory (or create a symbolic link). +$ export BL31=/src/arm-trusted-firmware/build/sun50iw1p1/debug/bl31.bin + (adjust the actual path accordingly) + +SPL/U-Boot +---------- +Both U-Boot proper and the SPL are using the 64-bit mode. As the boot ROM +enters the SPL still in AArch32 secure SVC mode, there is some shim code to +enter AArch64 very early. The rest of the SPL runs in AArch64 EL3. +U-Boot proper runs in EL2 and can load any AArch64 code (using the "go" +command), EFI applications (with "bootefi") or arm64 Linux kernel images +(often named "Image"), using the "booti" command. + +$ make clean +$ export CROSS_COMPILE=aarch64-linux-gnu- +$ make pine64_plus_defconfig +$ make + +This will build the SPL in spl/sunxi-spl.bin and a FIT image called u-boot.itb, +which contains the rest of the firmware. + +Boot process +============ +The on-die BROM code will try several methods to load and execute the firmware. +On a typical board like the Pine64 this will result in the following boot order: + +1) Reading 32KB from sector 16 (@8K) of the microSD card to SRAM A1. If the +BROM finds the magic "eGON" header in the first bytes, it will execute that +code. If not (no SD card at all or invalid magic), it will: +2) Try to read 32KB from sector 16 (@8K) of memory connected to the MMC2 +controller, typically an on-board eMMC chip. If there is no eMMC or it does +not contain a valid boot header, it will: +3) Initialize the SPI0 controller and try to access a NOR flash connected to +it (using the CS0 pin). If a flash chip is found, the BROM will load the +first 32KB (from offset 0) into SRAM A1. Now it checks for the magic eGON +header and checksum and will execute the code upon finding it. If not, it will: +4) Initialize the USB OTG controller and will wait for a host to connect to +it, speaking the Allwinner proprietary (but deciphered) "FEL" USB protocol. + +To boot the Pine64 board, you can use U-Boot and any of the described methods. + +FEL boot (USB OTG) +------------------ +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. +As the FEL mode is controlled by the boot ROM, it expects to be running in +AArch32. For now the AArch64 SPL cannot properly return into FEL mode, so the +feature is disabled in the configuration at the moment. + +microSD card +------------ +Transfer the SPL and the U-Boot FIT image directly to an uSD card: +# dd if=spl/sunxi-spl.bin of=/dev/sdx bs=8k seek=1 +# dd if=u-boot.itb of=/dev/sdx bs=8k seek=5 +# sync +(replace /dev/sdx with you SD card device file name, which could be +/dev/mmcblk[x] as well). + +Alternatively you can concatenate the SPL and the U-Boot FIT image into a +single file and transfer that instead: +$ cat spl/sunxi-spl.bin u-boot.itb > u-boot-sunxi-with-spl.bin +# dd if=u-boot-sunxi-with-spl.bin of=/dev/sdx bs=8k seek=1 + +You can partition the microSD card, but leave the first MB unallocated (most +partitioning tools will do this anyway). + +NOR flash +--------- +Some boards (like the SoPine, Pinebook or the OrangePi PC2) come with a +soldered SPI NOR flash chip. On other boards like the Pine64 such a chip +can be connected to the SPI0/CS0 pins on the PI-2 headers. +Create the SPL and FIT image like described above for the SD card. +Now connect either an "A to A" USB cable to the upper USB port on the Pine64 +or get an adaptor and use a regular A-microB cable connected to it. Other +boards often have a proper micro-B USB socket connected to the USB OTB port. +Remove a microSD card from the slot and power on the board. +On your host computer download and build the sunxi-tools package[2], then +use "sunxi-fel" to access the board: +$ ./sunxi-fel ver -v -p +This should give you an output starting with: AWUSBFEX soc=00001689(A64) ... +Now use the sunxi-fel tool to write to the NOR flash: +$ ./sunxi-fel spiflash-write 0 spl/sunxi-spl.bin +$ ./sunxi-fel spiflash-write 32768 u-boot.itb +Now boot the board without an SD card inserted and you should see the +U-Boot prompt on the serial console. + +(Legacy) 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 from an microSD card. +For some time using boot0 was the only option to get the Pine64 booted. +With working DRAM init code in U-Boot's SPL this is no longer necessary, +but this method is described here for the sake of completeness. +Please note that this method works only with the boot0 files shipped with +A64 based boards, the H5 uses an incompatible layout which is not supported +by this method. + +The boot0 binary is a 32 KByte blob and contained in the official Pine64 images +distributed by Pine64 or Allwinner. It can be easily extracted from a micro +SD card or an image file: +# dd if=/dev/sd of=boot0.bin bs=8k skip=1 count=4 +where /dev/sd 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". +This boot0 blob takes care of DRAM initialisation and loads the remaining +firmware parts, then 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[3] 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). +$ ./boot0img -o firmware.img -B boot0.img -u u-boot-dtb.bin -e -s bl31.bin \ +-a 0x44008 -d trampoline64:0x44000 +Then write this image to a microSD card, replacing /dev/sdx with the right +device file (see above): +$ dd if=firmware.img of=/dev/sdx bs=8k seek=1 + +2. Verified Boot ================ U-Boot supports an image verification method called "Verified Boot". @@ -188,6 +349,12 @@ for kernel and DTB. If they are not displayed, the Verified Boot is not working. +References +========== +[1] https://github.com/apritzel/arm-trusted-firmware.git +[2] git://github.com/linux-sunxi/sunxi-tools.git +[3] https://github.com/apritzel/pine64/ + -- Jagan Teki 13 Dec 2017