Odroid N2

This Page describes the necessary steps to take to install gentoo with a recent mainline kernel on an ODROID-N2 by Hardkernel Co., LTD.. It's a small ARM based single board computer with 6 cores and 2 or 4 GB of RAM. As it has a 64-bit CPU the experimental aarch64 gentoo is used.

Prerequisites

 * Computer running linux (gentoo)
 * Option to access the SD-Card from this computer
 * Option use USB drive.

Micro SD-Card preparation
The boot process of the N2 is described in the ODROID-N2 wiki and requires a certain partition structure of the micro SD-Card. First the boot software loads U-Boot, which as to be a specific location, which then loads the actual kernel from the boot partition.

USB drive
If the systems petitboot(20191127) has a recent version on it you can boot to a USB drive. I am not sure about the type of drive but SSD and HDD style USB drives work. I had problem with a USB stick type drive. In this case you can use the Ubuntu or other imagine to boot the system. And install like explained below. But in this case you will not need to install the tool chain etc as you are already on an ARM system. But you will have to install some Packages to be able to build if it does not come with the right tools installed.

Partition Table
The desired partition tables looks like this:

The swap partition is optional an depends on the use case.

Option 1 - Extract from Image
In this section, the desired partition table is acquired by using an available ubuntu boot image. This has the advantage of not needing to build U-Boot.

Download an ubuntu image to extract the bootloader from.

Extract the image.

Copy the first MBs which contain the partition table and the bootloader to the sd-card.

Change the copied partition table as needed.

Create swap partition.

Create btrfs partition.

Prepare directory structure for mounting the partitions.

Mount the partitions.

Create a subvolume for the root filesystem.

Mount the root filesystem.

Change the default subvolume to be mounted if no subvolume is mentioned while mounting to root.

Option 2 - Building u-boot
todo

Building the Kernel
Disable all unneeded architectures and DEBUG/NOUVEAU drivers as they are not needed.

Enable Amlogic architecture and multiplexer. Mark btrfs to be compiled into the kernel as the root filesystem is btrfs.

Compile the kernel.

Write a uboot readable uImage with the mkimage tool from dev-embedded/u-boot-tools.

Copy the device tree blob to the boot partition.

Install the modules to the root partition

Preparing the boot partition
Some addtional break down of the above. The mkImage command is part of the u-boot-tools package in gentoo. My udnerstanding this just puts a wrapper around the kernel file. The 0x1080000 addresses is the entry point for the linux kernel. If you want to make an Initrd you can use genkernel once the system is online and then use mkImage to generate the wrapped file. Something like this:

-C = compression -a and -e are basicaly not used for initrd -n is a Name -d is the source file and the last part is the output.

The above file is the boot.ini for uboot. it appears that petitboot can read different filesystems for this information. While most things referencce using vfat, It does appear to work on ext4 even looking for the /boot dir if your root filesystem is the flat. I also noticed that petitboot, picked up my EFI bootable kernel directly so might be something that works as well.

The .ini file really is more of a shell script. setevn is setting variables. fatload reads something off of a device and puts it in memory where you tell it. and booti/bootm/bootz try to boot what was boot into memory. booti is for a kernel that was not wrapped with mkImage bootm is for one that is wrapped. and bootz allows you to use a compressed kernel image. Options are the .dtb file which I assume some Architecture information. second file is the initrd or - for none last is the kernel. And of course this is the memory location that you put them. the 1080000 should not be confused with the one that was put on the mkImage command. These are just locations. It would seem you just need to have an idea if there is enough space between the things you are copying to RAM. Disclaimer I don't fully understand it all and probably have mistakes.

Stage 3 copy
Remove * from root user to reset root password to empty.

edit

Resources

 * Official ORDOID-N2 wiki