2018-08-14 06:49:20 +00:00
# CROSS-COMPILING
2018-09-09 22:30:05 +00:00
Installing a distro for ARM. The distro is CRUX, the target is an Odroid C2. The device will appears as "_/dev/mmcblk0_" (with "_/dev/mmcblk0p1_" and "_/dev/mmcblk0p2_" as the partitions) in the target machine, but it can be seen as "_/dev/sdX_" in your x86 computer. The unpacking tool is provided by [Atool ](http://www.nongnu.org/atool/ ).
2018-08-14 06:49:20 +00:00
## TOC
1. [CROSS COMPILATION TOOLS ](#cross-compilation-tools )
2. [PARTITIONING ](#partitioning )
2018-09-10 00:48:09 +00:00
3. [MOUNTING ](#mounting )
4. [ROOT PARTITION ](#root-partition )
5. [BOOT PARTITION ](#boot-partition )
6. [COMPILING KERNEL ](#compiling-kernel )
7. [BOOTLOADER ](#bootloader )
2018-08-14 06:49:20 +00:00
## CROSS COMPILATION TOOLS
2018-09-06 00:11:33 +00:00
Installing GCC cross compilation tools (for the X86 machine, not target ARM). Includes binutils.
2018-08-14 06:49:20 +00:00
2018-09-09 22:30:05 +00:00
* OPTION 1: Proportioned by [Linaro ](https://releases.linaro.org/components/toolchain/binaries/latest/aarch64-linux-gnu/ )
2018-08-14 06:49:20 +00:00
```
2018-09-09 22:30:05 +00:00
wget -c https://releases.linaro.org/components/toolchain/binaries/latest/aarch64-linux-gnu/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz
aunpack gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz
2018-08-14 06:49:20 +00:00
```
2018-09-09 22:30:05 +00:00
* OPTION 2: From repository (Devuan example)
`sudo apt-get install gcc-arm-none-eabi`
NOTE: Check your tools are up-to-date to prevent errors like the lack of option _"-mgeneral-regs-only"_ .
2018-09-09 22:40:41 +00:00
Name of "_CROSS_COMPILE_" variable will change depending on the choosen option. This guide assumes cross-compilation tools are from Linaro and therefore will equal to "_CROSS\_COMPILE=< LINARO \_TOOLS \_DIRECTORY > /bin/aarch64-linux-gnu-_"
2018-08-14 06:49:20 +00:00
## PARTITIONING
2018-09-06 00:35:26 +00:00
* Clear the section for the bootloader
`dd if=/dev/zero of=/dev/sdX bs=1M count=8`
* Enter fdisk
`fdisk /dev/sdX`
* Help
2018-08-14 06:49:20 +00:00
`m`
2018-09-06 00:35:26 +00:00
* Create new MBR partition table
2018-08-14 06:49:20 +00:00
`o`
2018-09-06 00:35:26 +00:00
* Create boot partition
2018-08-14 06:49:20 +00:00
`n`
2018-09-06 00:35:26 +00:00
* Make primary partition
2018-09-05 23:30:33 +00:00
`p`
2018-09-06 00:35:26 +00:00
* Choose partition number
2018-09-05 23:30:33 +00:00
`1`
2018-09-06 00:35:26 +00:00
* Assign start of boot partition at the end of the bootloader space
2018-08-14 06:49:20 +00:00
`3073`
2018-09-06 00:35:26 +00:00
* Assign end of boot partition
2018-08-14 06:49:20 +00:00
`+128M`
2018-09-06 00:35:26 +00:00
* Create root partition
2018-08-14 06:49:20 +00:00
`n`
2018-09-06 00:35:26 +00:00
* Make primary partition
2018-09-05 23:30:33 +00:00
`p`
2018-09-06 00:35:26 +00:00
* Choose partition number
2018-09-05 23:30:33 +00:00
`2`
2018-09-18 05:39:28 +00:00
* Assign start of boot partition at the end of the bootloader space
`134220802`
2018-09-06 00:35:26 +00:00
* Assign end of boot partition (default) by pressing ENTER
* Show the partitions
2018-09-05 23:30:33 +00:00
`p`
2018-09-06 00:35:26 +00:00
* If you agree save and exit
2018-09-05 23:30:33 +00:00
`w`
2018-09-06 00:35:26 +00:00
* If you disagree delete a partition and start from that partition
2018-09-05 23:30:33 +00:00
`d`
* or exit without saving
`q`
2018-08-14 06:55:13 +00:00
* Make root filesystem
2018-09-06 00:35:26 +00:00
`mkfs.<ROOT_FILESYSTEM> /dev/sdX2`
2018-08-14 06:55:13 +00:00
* Make boot filesystem according to supported bootloader (only "_mkfs.vfat_")
2018-09-06 00:35:26 +00:00
`mkfs.<BOOTLOADER_FILESYSTEM> /dev/sdX1`
2018-08-14 06:49:20 +00:00
2018-09-06 00:11:33 +00:00
## MOUNTING
2018-09-06 00:35:26 +00:00
* Mount root filesystem
`mount /dev/sdX2 /mnt`
* Create boot directory
2018-09-06 00:13:42 +00:00
`mkdir /mnt/boot`
2018-09-06 00:35:26 +00:00
* Mount boot filesystem
`mount /dev/sdX1 /mnt/boot`
2018-09-06 00:11:33 +00:00
2018-09-10 00:00:09 +00:00
## ROOT PARTITION
Can be the rest of the disk.
* Go to root directory
`cd /mnt/`
* Download CRUX image
`wget -c http://resources.crux-arm.nu/files/devel-test/3.3/crux-arm-rootfs-3.3-64b-RC2.tar.xz`
* Extract CRUX image to root directory
`aunpack crux-arm-rootfs-3.3-64b-RC2.tar.xz --extract-to=/mnt`
2018-09-18 05:39:28 +00:00
* Change network interface with the rules you want (IP, gateway, domain, etc).
2018-09-10 00:00:09 +00:00
`elvis /etc/rc.d/net`
2018-09-18 05:39:28 +00:00
* On the "/etc/resolv.conf.head" file set your preferred DNS provider (this example is from OpenNIC).
2018-09-10 00:00:09 +00:00
`nameserver 185.121.177.177`
2018-09-18 05:39:28 +00:00
* Change the "/etc/fstab" file with appropriate filesystems.
2018-09-10 00:00:09 +00:00
```
/dev/sda1 /boot < BOOTLOADER_FILESYSTEM > defaults 0 1
/dev/sda2 / < ROOT_FILESYSTEM > errors=remount-ro,noatime 0 1
```
* Uncomment the lines referring to "devpts", "tmp", and "shm" as some programs require it (Firefox), also "USB" and or "cdrom" if using those.
* Change the font, keyboard, timezone, hostname and services on the "/etc/rc.conf" file.
`ls /usr/share/kbd/keymaps/`
2018-08-14 06:49:20 +00:00
## BOOT PARTITION
Must be FAT32 and 64 MB minimum.
2018-09-06 00:35:26 +00:00
* Clone kernel repo to destination "odroidc2-kernel-folder"
2018-08-14 06:49:20 +00:00
`git clone --depth 1 --single-branch https://github.com/hardkernel/linux.git --branch odroidc2-v3.16.y odroidc2-kernel-folder`
2018-09-06 00:35:26 +00:00
* Enter destination folder
2018-08-14 06:49:20 +00:00
`cd odroidc2-kernel-folder`
2018-09-06 00:35:26 +00:00
* OPTION 1: Make kernel config (oneliner)
2018-09-09 22:38:50 +00:00
`make ARCH=arm64 CROSS_COMPILE=<LINARO_TOOLS_DIRECTORY>/bin/aarch64-linux-gnu- odroidc2_defconfig`
2018-08-14 06:49:20 +00:00
2018-09-06 00:35:26 +00:00
* OPTION 2: Make kernel config
2018-08-14 06:49:20 +00:00
```
export ARCH=arm64
2018-09-09 22:38:50 +00:00
export CROSS_COMPILE=< LINARO_TOOLS_DIRECTORY > /bin/aarch64-linux-gnu-
2018-08-14 06:49:20 +00:00
make odroidc2_defconfig
```
2018-08-14 06:55:13 +00:00
* Refine configuration
2018-08-14 06:49:20 +00:00
`make menuconfig`
2018-09-05 23:34:44 +00:00
## COMPILING KERNEL
2018-09-10 00:40:15 +00:00
* Compiling the devicetree blobs
2018-09-09 22:38:50 +00:00
`make -j 4 ARCH=arm64 CROSS_COMPILE=<LINARO_TOOLS_DIRECTORY>/bin/aarch64-linux-gnu- INSTALL_DTBS_PATH=/mnt/boot/dtbs/ dtbs`
2018-09-10 00:40:15 +00:00
* Compiling the kernel
2018-09-09 22:38:50 +00:00
`make -j 4 ARCH=arm64 CROSS_COMPILE=<LINARO_TOOLS_DIRECTORY>/bin/aarch64-linux-gnu- INSTALL_PATH=/mnt/boot/ Image`
2018-09-10 00:40:15 +00:00
* Compiling the modules
2018-09-09 22:38:50 +00:00
`make -j 4 ARCH=arm64 CROSS_COMPILE=<LINARO_TOOLS_DIRECTORY>/bin/aarch64-linux-gnu- INSTALL_MOD_PATH=/mnt/ modules`
2018-09-10 00:40:15 +00:00
* Installing the kernel to destination "/mnt/boot/Image"
`cp arch/arm64/boot/Image /mnt/boot/`
2018-09-18 05:39:28 +00:00
* Creating the devicetree directory
`mkdir /mnt/boot/dtbs/`
2018-09-10 00:40:15 +00:00
* Installing the devicetree blobs to destination "/mnt/boot/dtbs/meson64_odroidc2.dtb"
`cp arch/arm64/boot/dts/meson64_odroidc2.dtb /mnt/boot/dtbs/`
2018-09-09 22:30:05 +00:00
* Installing the modules to destination "INSTALL_MOD_PATH=/mnt/"
2018-09-09 22:38:50 +00:00
`make -j 4 ARCH=arm64 CROSS_COMPILE=<LINARO_TOOLS_DIRECTORY>/bin/aarch64-linux-gnu- INSTALL_MOD_PATH=/mnt/ modules_install`
2018-09-10 00:40:15 +00:00
* Compiling the firmware to destination "INSTALL_FW_PATH=/mnt/lib/firmware/"
2018-09-09 22:38:50 +00:00
`make -j 4 ARCH=arm64 CROSS_COMPILE=<LINARO_TOOLS_DIRECTORY>/bin/aarch64-linux-gnu- INSTALL_FW_PATH=/mnt/lib/firmware/ firmware_install`
2018-09-10 00:40:15 +00:00
* Compiling the kernel C headers to destination "INSTALL_HDR_PATH=/mnt/usr/"
2018-09-10 00:00:09 +00:00
`make -j 4 ARCH=arm64 CROSS_COMPILE=<LINARO_TOOLS_DIRECTORY>/bin/aarch64-linux-gnu- INSTALL_HDR_PATH=/mnt/usr/ headers_install`
2018-08-14 06:49:20 +00:00
2018-09-10 00:48:09 +00:00
## BOOTLOADER
Minimum 3072 bytes free at the start of the drive and before the boot partition.
* OPTION 1: Download and extract the binary
```
wget http://odroid.in/guides/ubuntu-lfs/boot.tar.gz
tar -zxvf boot.tar.gz
cd boot
```
Alternative download link: http://dn.odroid.com/S905/BootLoader/ODROID-C2/c2_boot_release_ubuntu.tar.gz
* OPTION 2: Compile the bootloader yourself
```
git clone https://github.com/hardkernel/u-boot.git -b odroidc2-v2015.01
cd u-boot
make ARCH=arm64 CROSS_COMPILE=< LINARO_TOOLS_DIRECTORY > /bin/aarch64-linux-gnu- odroidc2_defconfig
make -j4
cd boot
```
* Flash the bootloader
```
chmod +x sd_fusing.sh
./sd_fusing.sh /dev/sdX
```
* Notice the target is the device NOT a partition
* Set resolution by editing file root/boot/boot.ini
* Might want to comment out the display-autodetect option
2018-09-10 00:00:09 +00:00
And done. Next follow the distro tweaks: https://github.com/mayfrost/guides/blob/master/DISTROS.md
Also check the list of software alternative to bloatware and support minimalism https://github.com/mayfrost/guides/blob/master/ALTERNATIVES.md