Odroid N2

From Gentoo Wiki
Jump to: navigation, search
Warning
This article is incomplete an unfinished
Note
Btrfs crashes the kernel in current hardkernel's kernel version 4.9.170+ but there is some effort to get basic Odroid-N2 support into 5.2 mainline kernel.


This Page describes the necessary steps to take to install gentoo 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.

Prerequisites

  • Computer running linux (gentoo)
  • Option to access the SD-Card from this computer

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.

Partition Table

The desired partition tables looks like this:

Area Name Size From (sector #) To (sector #) device
Bootloader1 / MBR 512B 0 0 -
U-Boot 959.5K 1 1919 /dev/block/bootloader
U-Boot Environment 64KB 1920 2047 /dev/block/env
FAT32 for boot 128MB 2048 264191 /dev/mmcblk0p1
swap 4GB todo todo /dev/mmcblk0p2
BTRFS root - todo remaining blocks /dev/mmcblk0p3

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.

user $xz ubuntu-18.04.2-4.9-minimal-odroid-n2-20190329.img.xz
user $dd if=ubuntu-18.04.2-4.9-minimal-odroid-n2-20190329.img of=/dev/mmcblk0 bs=1M count=150 status=progress
150+0 records in
150+0 records out
157286400 bytes (157 MB, 150 MiB) copied, 0,241063 s, 652 MB/s
user $fdisk /dev/mmcblk0

Welcome to fdisk (util-linux 2.33).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p
Disk /dev/mmcblk0: 29,2 GiB, 31306285056 bytes, 61145088 sectors
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: 0x03823826

Device         Boot  Start     End Sectors  Size Id Type
/dev/mmcblk0p1        2048  264191  262144  128M  c W95 FAT32 (LBA)
/dev/mmcblk0p2      264192 7045119 6780928  3,2G 83 Linux

Command (m for help): d
Partition number (1,2, default 2): 2

Partition 2 has been deleted.

Command (m for help): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2): 2
First sector (264192-61145087, default 264192): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (264192-61145087, default 61145087): +4G

Created a new partition 2 of type 'Linux' and of size 4 GiB.
Partition #2 contains a ext4 signature.

Do you want to remove the signature? [Y]es/[N]o: y

The signature will be removed by a write command.

Command (m for help): n
Partition type
   p   primary (2 primary, 0 extended, 2 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (3,4, default 3): 3
First sector (8652800-61145087, default 8652800): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (8652800-61145087, default 61145087): 

Created a new partition 3 of type 'Linux' and of size 25 GiB.

Command (m for help): t
Partition number (1-3, default 3): 2
Hex code (type L to list all codes): 82

Changed type of partition 'Linux' to 'Linux swap / Solaris'.

Command (m for help): p
Disk /dev/mmcblk0: 29,2 GiB, 31306285056 bytes, 61145088 sectors
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: 0x03823826

Device         Boot   Start      End  Sectors  Size Id Type
/dev/mmcblk0p1         2048   264191   262144  128M  c W95 FAT32 (LBA)
/dev/mmcblk0p2       264192  8652799  8388608    4G 82 Linux swap / Solaris
/dev/mmcblk0p3      8652800 61145087 52492288   25G 83 Linux

Filesystem/RAID signature on partition 2 will be wiped.

Command (m for help): w
The partition table has been altered.
Syncing disks.

...

user $mkswap /dev/mmcblk0p2
mkswap: /dev/mmcblk0p2: warning: wiping old btrfs signature.
Setting up swapspace version 1, size = 4 GiB (4294963200 bytes)
no label, UUID=536be908-9479-42fc-a45f-bdc109a90984
user $mkfs.btrfs -L sd_pool /dev/mmcblk0p3
btrfs-progs v4.19 
See http://btrfs.wiki.kernel.org for more information.

Detected a SSD, turning off metadata duplication.  Mkfs with -m dup if you want to force metadata duplication.
Label:              sd_pool
UUID:               ef4e6022-44bf-4581-a219-ca82beb198b9
Node size:          16384
Sector size:        4096
Filesystem size:    25.03GiB
Block group profiles:
  Data:             single            8.00MiB
  Metadata:         single            8.00MiB
  System:           single            4.00MiB
SSD detected:       yes
Incompat features:  extref, skinny-metadata
Number of devices:  1
Devices:
   ID        SIZE  PATH
    1    25.03GiB  /dev/mmcblk0p3

user $mkdir -p /mnt/odroid/boot
user $mkdir /mnt/odroid/sd_pool
user $mkdir /mnt/odroid/root
user $mount /dev/mmcblk0p1 /mnt/odroid/boot
user $mount /dev/mmcblk0p3 /mnt/odroid/sd_pool
user $btrfs subvolume create /mnt/odroid/sd_pool/root
Create subvolume '/mnt/odroid/sd_pool/root'
user $mount /dev/mmcblk0p3 -o subvol=/root /mnt/odroid/root
user $btrfs subvolume set-default /mnt/odroid/root/



Option 2 - Building u-boot

todo

Building the Kernel

user $mkdir -p /mnt/odroid/root/usr/src
user $cd /mnt/odroid/root/usr/src
user $git clone --depth 1 https://github.com/hardkernel/linux.git -b odroidn2-4.9.y
user $mkdir -p /tmp/toolchain
user $cd /tmp/toolchain
user $tar -xf gcc-linaro-6.3.1-2017.02-x86_64_aarch64-linux-gnu.tar.xz
user $export ARCH=arm64
user $export CROSS_COMPILE=aarch64-linux-gnu-
user $export PATH=/tmp/toolchain/gcc-linaro-6.3.1-2017.02-x86_64_aarch64-linux-gnu/bin/:$PATH
user $aarch64-linux-gnu-gcc -v
Using built-in specs.
COLLECT_GCC=aarch64-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/tmp/toolchain/gcc-linaro-6.3.1-2017.02-x86_64_aarch64-linux-gnu/bin/../libexec/gcc/aarch64-linux-gnu/6.3.1/lto-wrapper
Target: aarch64-linux-gnu
Configured with: /home/tcwg-buildslave/workspace/tcwg-make-release/label/docker-trusty-amd64-tcwg-build/target/aarch64-linux-gnu/snapshots/gcc-linaro-6.3-2017.02/configure SHELL=/bin/bash --with-mpc=/home/tcwg-buildslave/workspace/tcwg-make-release/label/docker-trusty-amd64-tcwg-build/target/aarch64-linux-gnu/_build/builds/destdir/x86_64-unknown-linux-gnu --with-mpfr=/home/tcwg-buildslave/workspace/tcwg-make-release/label/docker-trusty-amd64-tcwg-build/target/aarch64-linux-gnu/_build/builds/destdir/x86_64-unknown-linux-gnu --with-gmp=/home/tcwg-buildslave/workspace/tcwg-make-release/label/docker-trusty-amd64-tcwg-build/target/aarch64-linux-gnu/_build/builds/destdir/x86_64-unknown-linux-gnu --with-gnu-as --with-gnu-ld --disable-libmudflap --enable-lto --enable-objc-gc --enable-shared --without-included-gettext --enable-nls --disable-sjlj-exceptions --enable-gnu-unique-object --enable-linker-build-id --disable-libstdcxx-pch --enable-c99 --enable-clocale=gnu --enable-libstdcxx-debug --enable-long-long --with-cloog=no --with-ppl=no --with-isl=no --disable-multilib --enable-fix-cortex-a53-835769 --enable-fix-cortex-a53-843419 --with-arch=armv8-a --enable-threads=posix --enable-multiarch --enable-libstdcxx-time=yes --enable-gnu-indirect-function --with-build-sysroot=/home/tcwg-buildslave/workspace/tcwg-make-release/label/docker-trusty-amd64-tcwg-build/target/aarch64-linux-gnu/_build/sysroots/aarch64-linux-gnu --with-sysroot=/home/tcwg-buildslave/workspace/tcwg-make-release/label/docker-trusty-amd64-tcwg-build/target/aarch64-linux-gnu/_build/builds/destdir/x86_64-unknown-linux-gnu/aarch64-linux-gnu/libc --enable-checking=release --disable-bootstrap --enable-languages=c,c++,fortran,lto --build=x86_64-unknown-linux-gnu --host=x86_64-unknown-linux-gnu --target=aarch64-linux-gnu --prefix=/home/tcwg-buildslave/workspace/tcwg-make-release/label/docker-trusty-amd64-tcwg-build/target/aarch64-linux-gnu/_build/builds/destdir/x86_64-unknown-linux-gnu
Thread model: posix
gcc version 6.3.1 20170109 (Linaro GCC 6.3-2017.02)
user $cd /mnt/odroid/root/usr/src/linux/
user $make odroidn2_defconfig
#
# configuration written to .config
#
user $make menuconfig
KERNEL
File systems --->
  <*> Btrfs filesystem support
user $make -j4 Image modules dtbs
user $cp arch/arm64/boot/Image arch/arm64/boot/dts/amlogic/meson64_odroidn2.dtb /mnt/odroid/boot/
user $make modules_install ARCH=arm64 INSTALL_MOD_PATH=/mnt/odroid/root

Preparing the boot partition

user $lsblk -f
NAME        FSTYPE      LABEL   UUID                                 FSAVAIL FSUSE% MOUNTPOINT
mmcblk0                                                                             
├─mmcblk0p1 vfat        BOOT    F702-39CB                             110,4M    14% /mnt/odroid/boot
├─mmcblk0p2 swap                536be908-9479-42fc-a45f-bdc109a90984                
└─mmcblk0p3 btrfs       sd_pool ef4e6022-44bf-4581-a219-ca82beb198b9   24,8G     0% /mnt/odroid/sd_pool
FILE /mnt/odroid/boot/boot.ini
# Boot Args
setenv bootargs "root=/dev/mmcblk1p3 rootwait rw ${condev} ${amlogic} no_console_suspend fsck.repair=yes elevator=noop hdmimode=${hdmimode} cvbsmode=576cvbs max_freq_a53=${max_freq_a53} max_freq_a73=${max_freq_a73} maxcpus=${maxcpus} voutmode=${voutmode} ${cmode} disablehpd=${disablehpd} cvbscable=${cvbscable} overscan=${overscan}"

...

# Load kernel, dtb and initrd
fatload mmc ${devno}:1 ${loadaddr} Image
fatload mmc ${devno}:1 ${dtb_loadaddr} meson64_odroidn2.dtb
# fatload mmc ${devno}:1 ${initrd_loadaddr} uInitrd
fdt addr ${dtb_loadaddr}
# unzip the kernel
# unzip ${k_addr} ${loadaddr}


# boot
# booti ${loadaddr} ${initrd_loadaddr} ${dtb_loadaddr}
booti ${loadaddr} - ${dtb_loadaddr}

Stage 3 copy

user $cd /mnt/odroid/root
user $tar -xjf stage3-armv7a_hardfp-20180831.tar.bz2

Ressources