User:GNUtoo/GTA04

From ParabolaWiki
Jump to: navigation, search

1 WIP

This is a work in progress, please see the TODO list at the end.

2 Rationale

This will show how to install Parabola on an armv7 device, here the GTA04. This device has a free software bootloader and can boot fully free.

It is a good example because it has:

  • Bootloader limtations.
  • A mainline kenrel that boots.

The idea is to show how to install Parabola on this device, while making the howto easy to adapt to other armv7 devices supported by mainline Linux.

Adding support for the GTA04 in parabola only required to to ask for the enabling its display driver in linux-libre.

Note that the internal wifi won't work on the GTA04 since its chip requires a non-free fimrware. Bluetooth might or might not work.

3 Requirements

This tutorial requires:

  • A microSD card. ALL ITS CONTENT WILL BE ERASED.
  • Parabola on a host machine, here it will be x86.
  • The serial cable (and an usb-serial adapter).

4 Installation strategy

Here the host machine is an x86 computer running Parabola, and the target machine is the ARM device. Becuase of that we will need to do the installation in several steps:

  • First we will bootstrap an "installer" from the host x86.
  • Then we will boot that "installer", and fix it to be able to get
 networking.
  • Then from that "installer", we will install the final system.

The half-working installer is due to the fact that the x86 host can't execute ARM code and therefore fails to execute the post-installation scripts.

5 Bootloader, partitioning and restrictions

The GTA04 ships with u-boot in NAND, it is also possible to run u-boot from the microSD.

Here we will have at least two partition:

  • One small partition at the end of the microSD card, to hold the parabola installer. Putting it at the end will permit us to reclaim its space easily, and allocate it to the partition right before it.
  • One partition holding the final installation.

While partitioning is very similar to x86, some differences have to be taken into account:

  • We have a bootloader that does an equivalent job than the BIOS and grub at the same time. This bootloader is u-boot.
  • As with x86, the bootloader needs to be able to load a Linux(-libre) kenrel from the filesystem. Unfortunately not all bootloaders have the same level of compatibilty than GRUB.
  • Here the default bootloader, which is an (old) modified version of u-boot, does support GPT and ext4. We will therefor stick to GPT and ext4 for simplicity.

6 Device tree

It is not always possible or practical to write code that auto-detect all hardware.

So in Linux, for ARM devices, we have a mechanism called "devicetree" to describe such hardware. Practically speaking you will have a .dtb file that describe your phone/tablet/whatever device. By separating it from the kenrel, a GNU/Linux distribution can ship many .dtb along with only one kenrel binary. The bootloader is then responsible for passing that file to the Linux kernel.

Unfortunately here, the old and modified u-boot version that we have doesn't seem to support that. So we will work around it.

7 Chosen partitioning

  • /dev/mmcblk0p1: Empty space for the parabola installation.
  • /dev/mmcblk0p2: Parabola installer: A basic installation takes about 600M at the time of writing, so we will use 1GB to be more confortable.

How to partition actually the SD card will be skipped, since it's very similar to how it's done for X86 with GPT.

8 Bootstraping the installer

Format the installer partition to ext4, and mount it:

 # mkfs.ext4 /dev/mmcblk0p2
 # mkdir mnt && mount /dev/mmcblk0p2 ./mnt

Copy the following content to a file named pacman.conf, in the current directory. Do not override the host's pacman.conf with that content(it's only for the target). [options]

HoldPkg     = pacman glibc
Architecture = armv7h
SigLevel    = Required DatabaseOptional
LocalFileSigLevel = Optional

[libre]
Include = /etc/pacman.d/mirrorlist
[core]
Include = /etc/pacman.d/mirrorlist
[extra]
Include = /etc/pacman.d/mirrorlist
[community]
Include = /etc/pacman.d/mirrorlist

Then actually bootstrap the installer(I'm not sure if this is still necessary to add archlinux-arm's key)

 # pacman-key --lsign-key builder@archlinuxarm.org
 # pacstrap -c -d -C ./pacman.conf ./mnt/ base archlinuxarm-keyring arch-install-scripts

9 Booting the installer

We're not done yet, we have to deal with the bootloader to boot the system. First install the mkimage utility if you don't have it:

# pacman -S uboot-tools

Then we will create some uImage.dtb containing both the kernel and a dtb:

# cat boot/vmlinuz-linux-libre boot/dtbs/linux-libre/omap3-gta04a3.dtb > boot/zImage.dtb
# mkimage -A arm -O linux -T kernel -C none -a 0x88000000 -e 0x88000000 -d boot/zImage.dtb boot/uImage.dtb

0x88000000 is the physical address we load the kenrel to. It needs to be in-ram and not be at already-used locations.

We now need to tell the bootloader to boot our kernel:

Add the following in boot.txt:

mmc part 0
ext4load mmc 0:2 ${loadaddr} /boot/uImage.dtb
setenv bootargs console=ttyO2,115200 ignore_loglevel
setenv bootargs console=ttyO2,115200 ignore_loglevel root=/dev/mmcblk0p2 rw rootwait
bootm

Then run:

mkimage -A arm -O linux -T script -C none -d boot.txt boot.scr

10 Installer network setup

To have networking, connect an usb cable between the host and the device, the type:

# modprobe g_ether

This will bring up an usb0 interface on both the host and the target. You then need to configure them both and to share the host Internet connection with the target.

11 Fixing the installer

Then make sure that the date is right, this is needed for SSL. The date command can help set that up without the network.

As it was explained earlier in the "Installation strategy" section, the installer is half working. So we will need to fix it. Here we need networking, and that requires SSL with most of the default mirrors. Since some ca-certificates post-install commands didn't run, we will then run them manually:

# update-ca-trust
# ln -srf /etc/ca-certificates/extracted/tls-ca-bundle.pem /etc/ssl/certs/ca-certificates.crt

Unrelated to the bootstrap procedure, the architecture is also not properly detected and we also need to fix it for pacman and pacstrap to work: In /etc/pacman.conf, change "Architecture = auto" to "armv7h".

This is necessary because the architecture is detected as armv7l (as uname -m shows), but the packages are named armv7h.

You will also need to do it again in the final install it.

12 Second install

Then you can finally pacstrap again:

# mount /dev/mmcblk0p1 /mnt
# pacstrap -cd /mnt base archlinuxarm-keyring uboot-tools

13 Booting the final system

Then boot on the installed system.

We will then need to:

  • Reclaim space
  • In /etc/pacman.conf, change "Architecture = auto" to "armv7h".

13.1 Reclaiming space

Delete the install partition and the current one.

# fdisk /dev/mmcblk0

Then re-create the current partition, adding to it the space of the install one. Then just resize the filesystem online:

# resize2fs /dev/mmcblk0p1

14 TODO

  • Document the network setup and internet connection sharing.
  • Document how to switch partitions before booting the final install
  • TODO: Automatic network setup.
  • Finish: Booting and installing
  • Explain how to boot on the installed partition from the installer (inverted the partition order trough fdisk expert -> f)
  • boot.scr: check the default bootloader setup. It might be a good idea to create a vfat partition even if we don't copy MLO to it. However we need to check if MLO still works when copied later.
  • Test the host->installer pacman.conf
  • Find how to automatically generates the /boot/uImage.dtb with pacman hooks
  • Get rid of the serial cable requirement.
  • Explain better the networking
  • Check if our old modified uboot supports dtb(possible), or zImage(unlikely)