CROSS-COMPILING.md (6948B)
1 # CROSS-COMPILING 2 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/). 3 4 5 ## TOC 6 1. [CROSS COMPILATION TOOLS](#cross-compilation-tools) 7 2. [PARTITIONING](#partitioning) 8 3. [MOUNTING](#mounting) 9 4. [ROOT PARTITION](#root-partition) 10 5. [BOOT PARTITION](#boot-partition) 11 6. [COMPILING KERNEL](#compiling-kernel) 12 7. [BOOTLOADER](#bootloader) 13 14 15 ## CROSS COMPILATION TOOLS 16 Installing GCC cross compilation tools (for the X86 machine, not target ARM). Includes binutils. 17 18 * OPTION 1: Proportioned by [Linaro](https://releases.linaro.org/components/toolchain/binaries/latest/aarch64-linux-gnu/) 19 ``` 20 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 21 aunpack gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz 22 ``` 23 24 * OPTION 2: From repository (Devuan example) 25 `sudo apt-get install gcc-arm-none-eabi` 26 NOTE: Check your tools are up-to-date to prevent errors like the lack of option _"-mgeneral-regs-only"_. 27 28 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-_" 29 30 31 ## PARTITIONING 32 * Clear the section for the bootloader 33 `dd if=/dev/zero of=/dev/sdX bs=1M count=8` 34 * Enter fdisk 35 `fdisk /dev/sdX` 36 * Help 37 `m` 38 * Create new MBR partition table 39 `o` 40 * Create boot partition 41 `n` 42 * Make primary partition 43 `p` 44 * Choose partition number 45 `1` 46 * Assign start of boot partition at the end of the bootloader space 47 `3073` 48 * Assign end of boot partition 49 `+128M` 50 * Create root partition 51 `n` 52 * Make primary partition 53 `p` 54 * Choose partition number 55 `2` 56 * Assign start of root partition at the end of the boot partition 57 `134220802` 58 * Assign end of root partition (the rest of the drive by default) by pressing ENTER 59 * Show the partitions 60 `p` 61 * If you agree save and exit 62 `w` 63 * If you disagree delete a partition and start from that partition 64 `d` 65 * or exit without saving 66 `q` 67 * Make root filesystem 68 `mkfs.<ROOT_FILESYSTEM> /dev/sdX2` 69 * Make boot filesystem according to supported bootloader (only "_mkfs.vfat_") 70 `mkfs.<BOOTLOADER_FILESYSTEM> /dev/sdX1` 71 72 73 ## MOUNTING 74 * Mount root filesystem 75 `mount /dev/sdX2 /mnt` 76 * Create boot directory 77 `mkdir /mnt/boot` 78 * Mount boot filesystem 79 `mount /dev/sdX1 /mnt/boot` 80 81 82 ## ROOT PARTITION 83 Can be the rest of the disk. 84 85 * Go to root directory 86 `cd /mnt/` 87 * Download CRUX image 88 `wget -c http://resources.crux-arm.nu/files/devel-test/3.3/crux-arm-rootfs-3.3-64b-RC2.tar.xz` 89 * Extract CRUX image to root directory 90 `aunpack crux-arm-rootfs-3.3-64b-RC2.tar.xz --extract-to=/mnt` 91 * Change network interface with the rules you want (IP, gateway, domain, etc). 92 `elvis /etc/rc.d/net` 93 * On the "/etc/resolv.conf.head" file set your preferred DNS provider (this example is from OpenNIC). 94 `nameserver 185.121.177.177` 95 * Change the "/etc/fstab" file with appropriate filesystems. 96 ``` 97 /dev/sda1 /boot <BOOTLOADER_FILESYSTEM> defaults 0 1 98 /dev/sda2 / <ROOT_FILESYSTEM> errors=remount-ro,noatime 0 1 99 ``` 100 * Uncomment the lines referring to "devpts", "tmp", and "shm" as some programs require it (Firefox), also "USB" and or "cdrom" if using those. 101 * Change the font, keyboard, timezone, hostname and services on the "/etc/rc.conf" file. 102 `ls /usr/share/kbd/keymaps/` 103 104 105 ## BOOT PARTITION 106 Must be FAT32 and 64 MB minimum. 107 108 * Clone kernel repo to destination "odroidc2-kernel-folder" 109 `git clone --depth 1 --single-branch https://github.com/hardkernel/linux.git --branch odroidc2-v3.16.y odroidc2-kernel-folder` 110 * Enter destination folder 111 `cd odroidc2-kernel-folder` 112 113 * OPTION 1: Make kernel config (oneliner) 114 `make ARCH=arm64 CROSS_COMPILE=<LINARO_TOOLS_DIRECTORY>/bin/aarch64-linux-gnu- odroidc2_defconfig` 115 116 * OPTION 2: Make kernel config 117 ``` 118 export ARCH=arm64 119 export CROSS_COMPILE=<LINARO_TOOLS_DIRECTORY>/bin/aarch64-linux-gnu- 120 make odroidc2_defconfig 121 ``` 122 123 * Refine configuration 124 `make menuconfig` 125 126 127 ## COMPILING KERNEL 128 * Compiling the devicetree blobs 129 `make -j $(nproc) ARCH=arm64 CROSS_COMPILE=<LINARO_TOOLS_DIRECTORY>/bin/aarch64-linux-gnu- INSTALL_DTBS_PATH=/mnt/boot/dtbs/ dtbs` 130 * Compiling the kernel 131 `make -j $(nproc) ARCH=arm64 CROSS_COMPILE=<LINARO_TOOLS_DIRECTORY>/bin/aarch64-linux-gnu- INSTALL_PATH=/mnt/boot/ Image` 132 * Compiling the modules 133 `make -j $(nproc) ARCH=arm64 CROSS_COMPILE=<LINARO_TOOLS_DIRECTORY>/bin/aarch64-linux-gnu- INSTALL_MOD_PATH=/mnt/ modules` 134 * Installing the kernel to destination "/mnt/boot/Image" 135 `cp arch/arm64/boot/Image /mnt/boot/` 136 * Creating the devicetree directory 137 `mkdir /mnt/boot/dtbs/` 138 * Installing the devicetree blobs to destination "/mnt/boot/dtbs/meson64_odroidc2.dtb" 139 `cp arch/arm64/boot/dts/meson64_odroidc2.dtb /mnt/boot/dtbs/` 140 * Installing the modules to destination "INSTALL_MOD_PATH=/mnt/" 141 `make -j $(nproc) ARCH=arm64 CROSS_COMPILE=<LINARO_TOOLS_DIRECTORY>/bin/aarch64-linux-gnu- INSTALL_MOD_PATH=/mnt/ modules_install` 142 * Compiling the firmware to destination "INSTALL_FW_PATH=/mnt/lib/firmware/" 143 `make -j $(nproc) ARCH=arm64 CROSS_COMPILE=<LINARO_TOOLS_DIRECTORY>/bin/aarch64-linux-gnu- INSTALL_FW_PATH=/mnt/lib/firmware/ firmware_install` 144 * Compiling the kernel C headers to destination "INSTALL_HDR_PATH=/mnt/usr/" 145 `make -j $(nproc) ARCH=arm64 CROSS_COMPILE=<LINARO_TOOLS_DIRECTORY>/bin/aarch64-linux-gnu- INSTALL_HDR_PATH=/mnt/usr/ headers_install` 146 147 148 ## BOOTLOADER 149 Minimum 3072 bytes free at the start of the drive and before the boot partition. 150 151 * OPTION 1: Download and extract the binary 152 ``` 153 wget -c http://mirror.archlinuxarm.org/aarch64/alarm/uboot-odroid-c2-2015.01-17-aarch64.pkg.tar.xz 154 aunpack uboot-odroid-c2-2015.01-17-aarch64.pkg.tar.xz --extract-to=/mnt/boot 155 cd /mnt/boot 156 ``` 157 158 * OPTION 2: Compile the bootloader yourself 159 ``` 160 git clone https://github.com/hardkernel/u-boot.git -b odroidc2-v2015.01 161 cd u-boot 162 make ARCH=arm64 CROSS_COMPILE=<LINARO_TOOLS_DIRECTORY>/bin/aarch64-linux-gnu- odroidc2_defconfig 163 make -j $(nproc) 164 cd boot 165 ``` 166 167 * Flash the bootloader 168 ``` 169 chmod +x sd_fusing.sh 170 ./sd_fusing.sh /dev/sdX 171 ``` 172 * Notice the target is the device NOT a partition 173 * Set resolution by editing file root/boot/boot.ini 174 * Might want to comment out the display-autodetect option 175 176 177 And done. Next follow the distro tweaks: https://github.com/mayfrost/guides/blob/master/DISTROS.md 178 Also check the list of software alternative to bloatware and support minimalism https://github.com/mayfrost/guides/blob/master/ALTERNATIVES.md