Neil Armstrong | 0ce3639 | 2020-06-11 10:53:49 +0200 | [diff] [blame] | 1 | .. SPDX-License-Identifier: GPL-2.0+ |
| 2 | |
Christian Hewitt | 2cdd4e7 | 2023-03-20 11:45:47 +0000 | [diff] [blame] | 3 | U-Boot for Khadas VIM3L (S905D3) |
| 4 | ================================ |
Neil Armstrong | 0ce3639 | 2020-06-11 10:53:49 +0200 | [diff] [blame] | 5 | |
Christian Hewitt | 2cdd4e7 | 2023-03-20 11:45:47 +0000 | [diff] [blame] | 6 | Khadas VIM3L is a Single Board Computer manufactured by Shenzhen Wesion Technology Co. Ltd |
| 7 | with the following specifications: |
Neil Armstrong | 0ce3639 | 2020-06-11 10:53:49 +0200 | [diff] [blame] | 8 | |
| 9 | - Amlogic S905D3 Arm Cortex-A55 quad-core SoC |
| 10 | - 2GB LPDDR4 SDRAM |
| 11 | - Gigabit Ethernet |
| 12 | - HDMI 2.1 display |
| 13 | - 40-pin GPIO header |
| 14 | - 1 x USB 3.0 Host, 1 x USB 2.0 Host |
| 15 | - eMMC, microSD |
| 16 | - M.2 |
| 17 | - Infrared receiver |
| 18 | |
| 19 | Schematics are available on the manufacturer website. |
| 20 | |
Neil Armstrong | adbff64 | 2020-09-21 09:34:15 +0200 | [diff] [blame] | 21 | PCIe Setup |
| 22 | ---------- |
Neil Armstrong | adbff64 | 2020-09-21 09:34:15 +0200 | [diff] [blame] | 23 | |
Christian Hewitt | 2cdd4e7 | 2023-03-20 11:45:47 +0000 | [diff] [blame] | 24 | The on-board MCU can mux the PCIe/USB3.0 shared differential lines using a FUSB340TMX USB |
| 25 | 3.1 SuperSpeed Data Switch between a USB3.0 Type-A connector and an M.2 Key-M slot. The |
| 26 | PHY driving these differential lines is shared between the USB3.0 controller and the PCIe |
| 27 | Controller, thus only a single controller can use it. |
| 28 | |
| 29 | To setup for PCIe run the following commands from U-Boot then power-cycle the board: |
Neil Armstrong | adbff64 | 2020-09-21 09:34:15 +0200 | [diff] [blame] | 30 | |
| 31 | .. code-block:: none |
| 32 | |
| 33 | i2c dev i2c@5000 |
| 34 | i2c mw 0x18 0x33 1 |
| 35 | |
Christian Hewitt | 2cdd4e7 | 2023-03-20 11:45:47 +0000 | [diff] [blame] | 36 | To revert to USB3.0 run the following commands from U-Boot then power-cycle the board: |
Neil Armstrong | adbff64 | 2020-09-21 09:34:15 +0200 | [diff] [blame] | 37 | |
| 38 | .. code-block:: none |
| 39 | |
| 40 | i2c dev i2c@5000 |
| 41 | i2c mw 0x18 0x33 0 |
| 42 | |
Christian Hewitt | 2cdd4e7 | 2023-03-20 11:45:47 +0000 | [diff] [blame] | 43 | U-Boot Compilation |
Neil Armstrong | 0ce3639 | 2020-06-11 10:53:49 +0200 | [diff] [blame] | 44 | ------------------ |
| 45 | |
Neil Armstrong | 72f2283 | 2020-11-05 16:18:57 +0100 | [diff] [blame] | 46 | .. code-block:: bash |
| 47 | |
Neil Armstrong | 0ce3639 | 2020-06-11 10:53:49 +0200 | [diff] [blame] | 48 | $ export CROSS_COMPILE=aarch64-none-elf- |
| 49 | $ make khadas-vim3l_defconfig |
| 50 | $ make |
| 51 | |
Christian Hewitt | 2cdd4e7 | 2023-03-20 11:45:47 +0000 | [diff] [blame] | 52 | U-Boot Signing with Pre-Built FIP repo |
| 53 | -------------------------------------- |
Neil Armstrong | 0ce3639 | 2020-06-11 10:53:49 +0200 | [diff] [blame] | 54 | |
Christian Hewitt | 2cdd4e7 | 2023-03-20 11:45:47 +0000 | [diff] [blame] | 55 | .. code-block:: bash |
Neil Armstrong | 4c60512 | 2022-03-02 10:42:22 +0100 | [diff] [blame] | 56 | |
Christian Hewitt | 2cdd4e7 | 2023-03-20 11:45:47 +0000 | [diff] [blame] | 57 | $ git clone https://github.com/LibreELEC/amlogic-boot-fip --depth=1 |
| 58 | $ cd amlogic-boot-fip |
| 59 | $ mkdir my-output-dir |
| 60 | $ ./build-fip.sh khadas-vim3l /path/to/u-boot/u-boot.bin my-output-dir |
| 61 | |
| 62 | U-Boot Manual Signing |
| 63 | --------------------- |
| 64 | |
| 65 | Amlogic does not provide sources for the firmware and tools needed to create a bootloader |
| 66 | image so it is necessary to obtain binaries from sources published by the board vendor: |
Neil Armstrong | 0ce3639 | 2020-06-11 10:53:49 +0200 | [diff] [blame] | 67 | |
| 68 | .. code-block:: bash |
| 69 | |
| 70 | $ wget https://releases.linaro.org/archive/13.11/components/toolchain/binaries/gcc-linaro-aarch64-none-elf-4.8-2013.11_linux.tar.xz |
| 71 | $ wget https://releases.linaro.org/archive/13.11/components/toolchain/binaries/gcc-linaro-arm-none-eabi-4.8-2013.11_linux.tar.xz |
| 72 | $ tar xvfJ gcc-linaro-aarch64-none-elf-4.8-2013.11_linux.tar.xz |
| 73 | $ tar xvfJ gcc-linaro-arm-none-eabi-4.8-2013.11_linux.tar.xz |
| 74 | $ export PATH=$PWD/gcc-linaro-aarch64-none-elf-4.8-2013.11_linux/bin:$PWD/gcc-linaro-arm-none-eabi-4.8-2013.11_linux/bin:$PATH |
| 75 | |
| 76 | $ DIR=vim3l-u-boot |
Christian Hewitt | 2cdd4e7 | 2023-03-20 11:45:47 +0000 | [diff] [blame] | 77 | $ git clone --depth 1 https://github.com/khadas/u-boot.git -b khadas-vims-v2015.01 $DIR |
Neil Armstrong | 0ce3639 | 2020-06-11 10:53:49 +0200 | [diff] [blame] | 78 | |
| 79 | $ cd vim3l-u-boot |
| 80 | $ make kvim3l_defconfig |
Neil Armstrong | 72f2283 | 2020-11-05 16:18:57 +0100 | [diff] [blame] | 81 | $ make CROSS_COMPILE=aarch64-none-elf- |
Neil Armstrong | 0ce3639 | 2020-06-11 10:53:49 +0200 | [diff] [blame] | 82 | $ export UBOOTDIR=$PWD |
| 83 | |
Christian Hewitt | 2cdd4e7 | 2023-03-20 11:45:47 +0000 | [diff] [blame] | 84 | Go back to the mainline U-Boot source tree then: |
Neil Armstrong | 0ce3639 | 2020-06-11 10:53:49 +0200 | [diff] [blame] | 85 | |
| 86 | .. code-block:: bash |
| 87 | |
| 88 | $ mkdir fip |
| 89 | |
Neil Armstrong | 72f2283 | 2020-11-05 16:18:57 +0100 | [diff] [blame] | 90 | $ wget https://github.com/BayLibre/u-boot/releases/download/v2017.11-libretech-cc/blx_fix_g12a.sh -O fip/blx_fix.sh |
Neil Armstrong | 0ce3639 | 2020-06-11 10:53:49 +0200 | [diff] [blame] | 91 | $ cp $UBOOTDIR/build/scp_task/bl301.bin fip/ |
| 92 | $ cp $UBOOTDIR/build/board/khadas/kvim3l/firmware/acs.bin fip/ |
| 93 | $ cp $UBOOTDIR/fip/g12a/bl2.bin fip/ |
| 94 | $ cp $UBOOTDIR/fip/g12a/bl30.bin fip/ |
| 95 | $ cp $UBOOTDIR/fip/g12a/bl31.img fip/ |
| 96 | $ cp $UBOOTDIR/fip/g12a/ddr3_1d.fw fip/ |
| 97 | $ cp $UBOOTDIR/fip/g12a/ddr4_1d.fw fip/ |
| 98 | $ cp $UBOOTDIR/fip/g12a/ddr4_2d.fw fip/ |
| 99 | $ cp $UBOOTDIR/fip/g12a/diag_lpddr4.fw fip/ |
| 100 | $ cp $UBOOTDIR/fip/g12a/lpddr3_1d.fw fip/ |
| 101 | $ cp $UBOOTDIR/fip/g12a/lpddr4_1d.fw fip/ |
| 102 | $ cp $UBOOTDIR/fip/g12a/lpddr4_2d.fw fip/ |
| 103 | $ cp $UBOOTDIR/fip/g12a/piei.fw fip/ |
| 104 | $ cp $UBOOTDIR/fip/g12a/aml_ddr.fw fip/ |
| 105 | $ cp u-boot.bin fip/bl33.bin |
| 106 | |
Neil Armstrong | 72f2283 | 2020-11-05 16:18:57 +0100 | [diff] [blame] | 107 | $ bash fip/blx_fix.sh \ |
Christian Hewitt | 2cdd4e7 | 2023-03-20 11:45:47 +0000 | [diff] [blame] | 108 | fip/bl30.bin \ |
| 109 | fip/zero_tmp \ |
| 110 | fip/bl30_zero.bin \ |
| 111 | fip/bl301.bin \ |
| 112 | fip/bl301_zero.bin \ |
| 113 | fip/bl30_new.bin \ |
| 114 | bl30 |
Neil Armstrong | 0ce3639 | 2020-06-11 10:53:49 +0200 | [diff] [blame] | 115 | |
Neil Armstrong | 72f2283 | 2020-11-05 16:18:57 +0100 | [diff] [blame] | 116 | $ bash fip/blx_fix.sh \ |
Christian Hewitt | 2cdd4e7 | 2023-03-20 11:45:47 +0000 | [diff] [blame] | 117 | fip/bl2.bin \ |
| 118 | fip/zero_tmp \ |
| 119 | fip/bl2_zero.bin \ |
| 120 | fip/acs.bin \ |
| 121 | fip/bl21_zero.bin \ |
| 122 | fip/bl2_new.bin \ |
| 123 | bl2 |
Neil Armstrong | 0ce3639 | 2020-06-11 10:53:49 +0200 | [diff] [blame] | 124 | |
| 125 | $ $UBOOTDIR/fip/g12a/aml_encrypt_g12a --bl30sig --input fip/bl30_new.bin \ |
Christian Hewitt | 2cdd4e7 | 2023-03-20 11:45:47 +0000 | [diff] [blame] | 126 | --output fip/bl30_new.bin.g12a.enc \ |
| 127 | --level v3 |
Neil Armstrong | 0ce3639 | 2020-06-11 10:53:49 +0200 | [diff] [blame] | 128 | $ $UBOOTDIR/fip/g12a/aml_encrypt_g12a --bl3sig --input fip/bl30_new.bin.g12a.enc \ |
Christian Hewitt | 2cdd4e7 | 2023-03-20 11:45:47 +0000 | [diff] [blame] | 129 | --output fip/bl30_new.bin.enc \ |
| 130 | --level v3 --type bl30 |
Neil Armstrong | 0ce3639 | 2020-06-11 10:53:49 +0200 | [diff] [blame] | 131 | $ $UBOOTDIR/fip/g12a/aml_encrypt_g12a --bl3sig --input fip/bl31.img \ |
Christian Hewitt | 2cdd4e7 | 2023-03-20 11:45:47 +0000 | [diff] [blame] | 132 | --output fip/bl31.img.enc \ |
| 133 | --level v3 --type bl31 |
Neil Armstrong | 0ce3639 | 2020-06-11 10:53:49 +0200 | [diff] [blame] | 134 | $ $UBOOTDIR/fip/g12a/aml_encrypt_g12a --bl3sig --input fip/bl33.bin --compress lz4 \ |
Christian Hewitt | 2cdd4e7 | 2023-03-20 11:45:47 +0000 | [diff] [blame] | 135 | --output fip/bl33.bin.enc \ |
| 136 | --level v3 --type bl33 --compress lz4 |
Neil Armstrong | 0ce3639 | 2020-06-11 10:53:49 +0200 | [diff] [blame] | 137 | $ $UBOOTDIR/fip/g12a/aml_encrypt_g12a --bl2sig --input fip/bl2_new.bin \ |
Christian Hewitt | 2cdd4e7 | 2023-03-20 11:45:47 +0000 | [diff] [blame] | 138 | --output fip/bl2.n.bin.sig |
Neil Armstrong | 0ce3639 | 2020-06-11 10:53:49 +0200 | [diff] [blame] | 139 | $ $UBOOTDIR/fip/g12a/aml_encrypt_g12a --bootmk \ |
Christian Hewitt | 2cdd4e7 | 2023-03-20 11:45:47 +0000 | [diff] [blame] | 140 | --output fip/u-boot.bin \ |
| 141 | --bl2 fip/bl2.n.bin.sig \ |
| 142 | --bl30 fip/bl30_new.bin.enc \ |
| 143 | --bl31 fip/bl31.img.enc \ |
| 144 | --bl33 fip/bl33.bin.enc \ |
| 145 | --ddrfw1 fip/ddr4_1d.fw \ |
| 146 | --ddrfw2 fip/ddr4_2d.fw \ |
| 147 | --ddrfw3 fip/ddr3_1d.fw \ |
| 148 | --ddrfw4 fip/piei.fw \ |
| 149 | --ddrfw5 fip/lpddr4_1d.fw \ |
| 150 | --ddrfw6 fip/lpddr4_2d.fw \ |
| 151 | --ddrfw7 fip/diag_lpddr4.fw \ |
| 152 | --ddrfw8 fip/aml_ddr.fw \ |
| 153 | --ddrfw9 fip/lpddr3_1d.fw \ |
| 154 | --level v3 |
Neil Armstrong | 0ce3639 | 2020-06-11 10:53:49 +0200 | [diff] [blame] | 155 | |
Christian Hewitt | 2cdd4e7 | 2023-03-20 11:45:47 +0000 | [diff] [blame] | 156 | Then write U-Boot to SD or eMMC with: |
Neil Armstrong | 0ce3639 | 2020-06-11 10:53:49 +0200 | [diff] [blame] | 157 | |
| 158 | .. code-block:: bash |
| 159 | |
Christian Hewitt | 2cdd4e7 | 2023-03-20 11:45:47 +0000 | [diff] [blame] | 160 | $ DEV=/dev/boot_device |
Neil Armstrong | 0ce3639 | 2020-06-11 10:53:49 +0200 | [diff] [blame] | 161 | $ dd if=fip/u-boot.bin.sd.bin of=$DEV conv=fsync,notrunc bs=512 skip=1 seek=1 |
Christian Hewitt | 2cdd4e7 | 2023-03-20 11:45:47 +0000 | [diff] [blame] | 162 | $ dd if=fip/u-boot.bin.sd.bin of=$DEV conv=fsync,notrunc bs=1 count=440 |