How to prepare minimal software to run linux on Amlogic S905X(DRAFT!!!)

U-Boot boot loader preparation

We need the boot loader to load afterward built linux kernel, u-boot is the ARM bootloader which we need to configure for Amlogic S905X chip. In u-boot we have configuration file which we will use afterwards.

The official steps for u-boot configuration and compilation described here‘ [https://github.com/libre-computer-project/libretech-u-boot/blob/u-boot/master/doc/board/amlogic/p212.rst]
Let’s create the directory where all the actions will be done.

  • Compile the mainline u-boot which img we will need afterwards
git clone https://github.com/u-boot/u-boot.git
cd u-boot
export CROSS_COMPILE=aarch64-none-elf-
make p212_defconfig
make
cd ..
  • We need to be ready with ARM toolchain and clone u-boot repo which prepared by Amlogic
wget https://releases.linaro.org/archive/13.11/components/toolchain/binaries/gcc-linaro-aarch64-none-elf-4.8-2013.11_linux.tar.xz
wget https://releases.linaro.org/archive/13.11/components/toolchain/binaries/gcc-linaro-arm-none-eabi-4.8-2013.11_linux.tar.xz
tar xvfJ gcc-linaro-aarch64-none-elf-4.8-2013.11_linux.tar.xz
tar xvfJ gcc-linaro-arm-none-eabi-4.8-2013.11_linux.tar.xz
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
git clone https://github.com/BayLibre/u-boot.git -b n-amlogic-openlinux-20170606 amlogic-u-boot
cd amlogic-u-boot
make gxl_p212_v1_defconfig
make
export FIPDIR=$PWD/fip
  • Lets create u-boot image
cd ../u-boot #mainline u-boot directory 
mkdir fip
cp $FIPDIR/gxl/bl2.bin fip/
cp $FIPDIR/gxl/acs.bin fip/
cp $FIPDIR/gxl/bl21.bin fip/
cp $FIPDIR/gxl/bl30.bin fip/
cp $FIPDIR/gxl/bl301.bin fip/
cp $FIPDIR/gxl/bl31.img fip/
cp u-boot.bin fip/bl33.bin
$FIPDIR/blx_fix.sh \
  fip/bl30.bin \
  fip/zero_tmp \
  fip/bl30_zero.bin \
  fip/bl301.bin \
  fip/bl301_zero.bin \
  fip/bl30_new.bin \
  bl30
$FIPDIR/acs_tool.pyc fip/bl2.bin fip/bl2_acs.bin fip/acs.bin 0
$FIPDIR/blx_fix.sh \
  fip/bl2_acs.bin \
  fip/zero_tmp \
  fip/bl2_zero.bin \
  fip/bl21.bin \
  fip/bl21_zero.bin \
  fip/bl2_new.bin \
  bl2
$FIPDIR/gxl/aml_encrypt_gxl --bl3enc --input fip/bl30_new.bin
$FIPDIR/gxl/aml_encrypt_gxl --bl3enc --input fip/bl31.img
$FIPDIR/gxl/aml_encrypt_gxl --bl3enc --input fip/bl33.bin
$FIPDIR/gxl/aml_encrypt_gxl --bl2sig --input fip/bl2_new.bin --output fip/bl2.n.bin.sig
$FIPDIR/gxl/aml_encrypt_gxl --bootmk \
          --output fip/u-boot.bin \
          --bl2 fip/bl2.n.bin.sig \
          --bl30 fip/bl30_new.bin.enc \
          --bl31 fip/bl31.img.enc \
          --bl33 fip/bl33.bin.enc
  • Create flash drive partitions

If you have any information on flash driver you need to back it, because the flash driver will be erased.
For flash drive partitioning on Debian machine you can use fdisk utility or find some other analog in case of other OS.

Use fdisk -l to get all disk drives connected to machine.
The output should be something like this

Disk /dev/sda: 223.57 GiB, 240057409536 bytes, 468862128 sectors
Disk model: KINGSTON SA400S3
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x8463950a

Device     Boot    Start       End   Sectors   Size Id Type
/dev/sda1  *        2048  58593279  58591232  27.9G 83 Linux
/dev/sda2       58595326 468860927 410265602 195.6G  5 Extended
/dev/sda5       58595328  60594175   1998848   976M 82 Linux swap / Solaris
/dev/sda6       60596224 468860927 408264704 194.7G 83 Linux

Disk /dev/sdb: 29.54 GiB, 31719424000 bytes, 61952000 sectors
Disk model: Storage Device  
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xba4d885d

Device     Boot   Start      End  Sectors  Size Id Type
/dev/sdb1  *       2048  2099199  2097152    1G  c W95 FAT32 (LBA)
/dev/sdb2       2099200 61951999 59852800 28.5G  b W95 FAT32

In this case we have 2 devices attached to machine, first one is the main device which used by Debian OS and second one is the flash drive which will be partitioned afterwards. We need to delete all the partitions on the /dev/sdb.
Run the following command to manage partitions on specified device fdisk /dev/sdX (replace the X to suite you flash drive device), probably you need to run this command you super user privileges. After this the interactive menu of the fdisk will be opened:
press "d" after select the partition which you want to delete and do this for all partitions, at the end the all changes must written to device with "w" command. Now we have clean flash drive and need to create partitions,

Linux kernel preparation

First step is to clone linux mainline kernel from the following resource

git clone https://github.com/torvalds/linux.git