| 1 |
gxlimg |
| 2 |
====== |
| 3 |
|
| 4 |
Gxlimg is an amlogic s905x boot image creation tools. This has been made by |
| 5 |
reverse engineering the aml_encrypt_gxl binary used to create boot image as |
| 6 |
well as the BL2 arm binary that reads FIP header and loads BL3* and u-boot |
| 7 |
images. |
| 8 |
|
| 9 |
Some reverse engineering notes can be found in reveng directory, please note |
| 10 |
that because I decompiled aml_encrypt_gxl by hand (not using a tool like IDA), |
| 11 |
some mistakes could have slept in those notes. The purpose was first to |
| 12 |
familiarized myself with subject such as ARM assembly and Arm Trust Firmware |
| 13 |
(ATF). |
| 14 |
|
| 15 |
|
| 16 |
I - Build instructions |
| 17 |
---------------------- |
| 18 |
|
| 19 |
In order to build this tool just use the following: |
| 20 |
|
| 21 |
$ make |
| 22 |
|
| 23 |
If you want some debug information and print use the following instead: |
| 24 |
|
| 25 |
$ make DEBUG=1 |
| 26 |
|
| 27 |
II.A - Create a boot image - automated version |
| 28 |
---------------------------------------------- |
| 29 |
|
| 30 |
1) Compile u-boot: |
| 31 |
|
| 32 |
Compile mainline u-boot from http://git.denx.de/ |
| 33 |
|
| 34 |
$ make CROSS_COMPILE=aarch64-elf- libretech-cc_defconfig |
| 35 |
$ make CROSS_COMPILE=aarch64-elf- all |
| 36 |
|
| 37 |
Replace aarch64-elf- with the prefix of your aarch64 toolchain. |
| 38 |
This should produce a u-boot-dtb.bin file. |
| 39 |
|
| 40 |
2) Generate image |
| 41 |
|
| 42 |
Use the image target to generate the build/gxl-boot.bin image. |
| 43 |
|
| 44 |
$ make image UBOOT=<path/to/u-boot-dtb.bin> |
| 45 |
|
| 46 |
II.B - Create a boot image - manual version |
| 47 |
------------------------------------------- |
| 48 |
|
| 49 |
In order to create a boot image for s905x board such as lepotato board, you |
| 50 |
can follow those steps below. |
| 51 |
|
| 52 |
|
| 53 |
1) Get BL* binaries: |
| 54 |
|
| 55 |
Follow instructions from here https://github.com/BayLibre/u-boot that build |
| 56 |
vendor u-boot in order to get BL* binaries. |
| 57 |
|
| 58 |
2) Sign BL2: |
| 59 |
|
| 60 |
Use gxlimg as below to sign BL2 binary along with its DDR initialization |
| 61 |
datas: |
| 62 |
|
| 63 |
$ ./fip/blx_fix.sh fip/gxl/bl2_acs.bin zero_tmp fip/gxl/bl2_zero.bin \ |
| 64 |
fip/gxl/bl21.bin fip/gxl/bl21_zero.bin bl2_new.bin bl2 |
| 65 |
$ gxlimg -t bl2 -s bl2_new.bin bl2.bin.enc |
| 66 |
|
| 67 |
3) Encrypt BL3*: |
| 68 |
|
| 69 |
Use the following to encrypt BL3* binary |
| 70 |
|
| 71 |
$ gxlimg -t bl3x -c ./fip/gxl/bl30_new.bin bl30.bin.enc |
| 72 |
$ gxlimg -t bl3x -c ./fip/gxl/bl31.img bl31.img.enc |
| 73 |
|
| 74 |
4) Compile u-boot: |
| 75 |
|
| 76 |
Compile mainline u-boot from http://git.denx.de/ |
| 77 |
|
| 78 |
$ make CROSS_COMPILE=aarch64-elf- libretech-cc_defconfig |
| 79 |
$ make CROSS_COMPILE=aarch64-elf- all |
| 80 |
|
| 81 |
Replace aarch64-elf- with the prefix of your aarch64 toolchain. |
| 82 |
This should produce a u-boot-dtb.bin file. |
| 83 |
|
| 84 |
5) Encrypt u-boot: |
| 85 |
|
| 86 |
Encrypt the previously built u-boot image: |
| 87 |
|
| 88 |
$ gxlimg -t bl3x -c u-boot.bin u-boot.bin.enc |
| 89 |
|
| 90 |
6) Create the final boot image: |
| 91 |
|
| 92 |
To create the final image issue the command below: |
| 93 |
|
| 94 |
$ gxlimg -t fip --bl2 ./bl2.bin.enc --bl30 ./bl30.bin.enc \ |
| 95 |
--bl31 ./bl31.img.enc --bl33 ./u-boot.bin.enc ./gxl-boot.bin |
| 96 |
|
| 97 |
II.c - Create USB boot files |
| 98 |
---------------------------- |
| 99 |
|
| 100 |
The ROM USB Boot mode on GXL, GXM & AXG uses .usb.bl2 and .usb.tpl files to boot, |
| 101 |
as used by pyamlboot (https://github.com/superna9999/pyamlboot) |
| 102 |
|
| 103 |
The first binary contains the encrypted BL2 and the second the rest of the gxl-boot.bin |
| 104 |
|
| 105 |
To generate: |
| 106 |
|
| 107 |
$ dd if=gxl-boot.bin of=u-boot.bin.usb.bl2 bs=49152 count=1 |
| 108 |
$ dd if=gxl-boot.bin of=u-boot.bin.usb.tpl skip=49152 bs=1 |
| 109 |
|
| 110 |
Then copy them into files/<boardname>/u-boot.bin.usb.bl2 & files/<boardname>/u-boot.bin.usb.tpl |
| 111 |
in the checkout source of pyamlboot, then follow instructions at: |
| 112 |
https://github.com/superna9999/pyamlboot#booting-full-system-from-usb |
| 113 |
|
| 114 |
III - Write the image to the SD card |
| 115 |
------------------------------------ |
| 116 |
|
| 117 |
1) Prepare the SD card: |
| 118 |
|
| 119 |
First compute how many sectors gxl-boot.bin uses by getting its size and |
| 120 |
dividing it by 512. |
| 121 |
|
| 122 |
Let's say your gxl-boot.bin is 653312 Bytes thus you need 1276 sectors you |
| 123 |
can give you a little bit margin and choose a gap of 2048 sectors for your |
| 124 |
first partion. |
| 125 |
|
| 126 |
Then create the partition: |
| 127 |
|
| 128 |
$ sudo fdisk /dev/mmcpblk0 |
| 129 |
$ n |
| 130 |
$ p |
| 131 |
$ 1 |
| 132 |
$ 2048 # <- enter the number of sectors previously computed |
| 133 |
$ # <- take the whole remaining space for the partition |
| 134 |
$ w |
| 135 |
|
| 136 |
Then create a fs on it: |
| 137 |
|
| 138 |
$ mkfs.ext3 /dev/mmcblk0p1 |
| 139 |
|
| 140 |
And copy or install a linux ARM file system. |
| 141 |
|
| 142 |
2) Copy boot image to SD: |
| 143 |
|
| 144 |
The copy image to SD being careful to not erase the first 512 block (holding |
| 145 |
the MBR partition table) |
| 146 |
|
| 147 |
$ dd if=./gxl-boot.bin of=/dev/mmcblk0 bs=512 seek=1 |