Difference between revisions of "Funtoo Linux Installation on RPI"

From Funtoo
Jump to navigation Jump to search
Line 1: Line 1:
== Introduction ==
== Introduction ==
This is the updated quick and dirty HOWTO covering the automation of cross-compiling, kernel building, emulation and booting of arbitrary architectures, but specifically focused on the cross compiling the Raspeberry Pi linux kernel sources for target arm-linux-gnueabihf and booting it on Raspberry Pi boards with a funtoo stage 3. It's so quick and dirty you probably won't be able replicate the results here on your first try. But it is possible!
This is an extension and amplification of [[Funtoo_Linux_Installation_on_ARM]]. It attempts to systematize and automate as much as possible of steps required to get Funtoo running on the 32 bit ARM Raspberry Pi device.


This is an update of [[Crossdev_Automation]], reflecting the changes needed to accomodate the new kits structure of Funtoo, and to clean up the scripting used for automation. The document will remain available for reference purposes.  
This is an update of [[Crossdev_Automation]], reflecting the changes needed to accomodate the new kits structure of Funtoo, and to clean up the scripting used for automation. The document will remain available for reference purposes.  


[[Funtoo_Linux_Installation_on_ARM]] is an important document as well.


== Installation Overview ==
== Installation Overview ==

Revision as of 22:06, July 23, 2018

Introduction

This is an extension and amplification of Funtoo_Linux_Installation_on_ARM. It attempts to systematize and automate as much as possible of steps required to get Funtoo running on the 32 bit ARM Raspberry Pi device.

This is an update of Crossdev_Automation, reflecting the changes needed to accomodate the new kits structure of Funtoo, and to clean up the scripting used for automation. The document will remain available for reference purposes.


Installation Overview

  1. Create Your Installation Settings
  2. Install the Stage 3 Tarball
  3. Install the Firmware
  4. Configure Your System
  5. Install Binary Kernel, Modules, and dtbs or Cross-Compile from Source
  6. Optionally Install Distcc via QEMU Chroot
  7. Partition and Format an SDCard
  8. Deploy Installation to SDCard

Get the Bash Script

Development code is available on github. The structure of the file sysroot.sh should roughly correspond to the information contained here.

Follow the Installation Steps

Create Your Installation Settings

Confguration your installation. These variables are referencecd by the sysroot.sh script and by this document.

   config.sh (bash source code) - Set your install configuration variables
KERNEL_WORK=/usr/src/rpi_kernel
RPI_KERN_BRANCH=rpi-4.14.y

SYSROOT_WORK=/usr/src/sysroots
STAGE_URL=http://ftp.osuosl.org/pub/funtoo/funtoo-current/arm-32bit/raspi3/stage3-latest.tar.xz
CHOST=armv7a-hardfloat-linux-gnueabi
CFLAGS="-O2 -pipe -march=armv7-a -mtune=cortex-a53 -mfpu=neon-vfpv4 -mfloat-abi=hard"

#SDCARD_DEV=mmcblk0p
SDCARD_DEV=sdb

#optional
DISTCC_REMOTE_JOBS=21
DISTCC_REMOTE_HOSTS="10.0.0.1,cpp,lzo"


Install the Stage 3 Tarball

Download the current Funtoo stage 3 build appropriate for your Raspberry Pi device. Check the Subarches#arm32 page, to see the version available for versions 1,2 and 3 of the Pi. Here we download the version for version 3 by setting the STAGE_URL variable in our configuration file.

We need to save the archive to $STAGE3_ARCHIVE and unpack it to $SYSROOT. Back up or remove any previous work in that local.

root # export SYSROOT=$SYSROOT_WORK/$CHOST
root # export STAGE3_ARCHIVE=/tmp/stage3-latest.tar.xz
root # mv -n $SYSROOT $SYSROOT.old
root # mkdir -p $SYSROOT
root # wget ${STAGE_URL} -O ${STAGE3_ARCHIVE}
root # tar xpfv ${STAGE3_ARCHIVE} -C ${SYSROOT}

Install the Firmware

Make your work directory and clone the official firmware repo into it. Copy the appropriate boot firmware files to the sysroot, along with the video acceleration binaries. If you want to use the wireless networking function, you need the bcrm firmware as well.

root # mkdir -p ${KERNEL_WORK}
root # git clone --depth 1 git://github.com/raspberrypi/firmware/ ${KERNEL_WORK}/firmware
root # cp ${KERNEL_WORK}/firmware/boot/{bootcode.bin,fixup*.dat,start*.elf} ${SYSROOT}/boot
root # cp -r ${KERNEL_WORK}/firmware/hardfp/opt ${SYSROOT}
root # git clone --depth 1 https://github.com/RPi-Distro/firmware-nonfree ${KERNEL_WORK}/firmware-nonfree
root # git --git-dir=${KERNEL_WORK}/firmware-nonfree/.git --work-tree=${KERNEL_WORK}/firmware-nonfree pull origin
root # mkdir -p ${SYSROOT}/lib/firmware/brcm
root # cp -r ${KERNEL_WORK}/firmware-nonfree/brcm/brcmfmac43430-sdio.{bin,txt} ${SYSROOT}/lib/firmware/brcm

Configure Your System

Here, we attempt to encapsulate the instructions from Funtoo_Linux_Installation_on_ARM. There are two ways to do this. Here we alter files and symlinks in $SYSROOT/etc directly. We could also chroot into $SYSROOT using QEMU as described below to install No results, use rc-update directly. However the method used here doesn't depend upon a functioning QEMU chroot, which can be slow and tricky to implement for beginners.

Set Up Mount Points

Alter $SYSROOT/etc/fstab as follows. We remove the swap (for now), and alter the storage device name and parition file types. We also remove the /dev/cdrom device.

   $SYSROOT/etc/fstab
/dev/mmcblk0p1  /boot   vfat    noauto,noatime  1 2
/dev/mmcblk0p2  /   ext4    noatime 0 1

We can use the following sed code.

root # sed -i "s/\/dev\/sda1.*/\/dev\/mmcblk0p1 \/boot vfat defaults 0 2/" ${SYSROOT}/etc/fstab
root # sed -i "s/\/dev\/sda2.*//" ${SYSROOT}/etc/fstab
root # sed -i "s/\/dev\/sda3.*/\/dev\/mmcblk0p2 \/ ext4  defaults 0 1/" ${SYSROOT}/etc/fstab
root # sed -i "s/\#\/dev\/cdrom.*//" ${SYSROOT}/etc/fstab

Set Up Root Password

root # sed -i "s/root\:\*/root\:`(openssl passwd -1)`/" $SYSROOT/etc/shadow

Set Up Networking

root # ln -sf /etc/init.d/dhcpcd ${SYSROOT}/etc/runlevels/default

Set Up SSH Access

root # echo "PermitRootLogin yes" >> ${SYSROOT}/etc/ssh/sshd_config
root # ln -sf /etc/init.d/sshd ${SYSROOT}/etc/runlevels/default

Set Up the Software Clock

root # ln -sf /etc/init.d/swclock ${SYSROOT}/etc/runlevels/boot
root # rm ${SYSROOT}/etc/runlevels/boot/hwclock
root # mkdir -p ${SYSROOT}/lib/rc/cache
root # touch ${SYSROOT}/lib/rc/cache/shutdowntime

Disable Serial Console Access

If you want this, set it up yourself.

root # sed -i "s/s0\:.*/\#&/" ${SYSROOT}/etc/inittab

Link to Accelerated Video Libraries

root # echo "LDPATH=\"/opt/vc/lib\"" > ${SYSROOT}/etc/env.d/99vc

Configure the Boot Parameters

root # cat > ${SYSROOT}/boot/cmdline.txt << EOF
root ##i## dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
root ##i## EOF

Install Binary Kernel, Modules and dtbs

root # mkdir -p ${SYSROOT}/boot/overlays
root # cp ${KERNEL_WORK}/firmware/boot/dts/*.dtb ${SYSROOT}/boot/
root # cp ${KERNEL_WORK}/firmware/boot/dts/overlays/*.dtb* ${SYSROOT}/boot/overlays/
root # cp ${KERNEL_WORK}/firmware/boot/dts/overlays/README ${SYSROOT}/boot/overlays/
root # cp ${KERNEL_WORK}/firmware/boot/kernel7.img  ${SYSROOT}/boot/

Cross-compile Kernel, Modules and dtbs from Source

Install Crossdev

No results is a wonderful script for managing cross-compiling environments on Gentoo, but it is incompatible with Funtoo's improved gcc ebuilds. There is incomplete documentation of a pure Funtoo solution, but there has been no follow up on a complete implementation.

A simple solution is to create a local overlay named "crossdev", store gentoo ebuilds and patches in it, and use a crossdev command line switch to direct it to search the overlay for the appropriate ebuilds. This has the advantage of isolating all gentoo files and resulting binaries in a single directory.~

   Note

Please ensure that /etc/portage{package.keywords,package.mask,package.us} are all directories, containing files with the appropriate content.

Make a Local Local_Overlay

Let's follow the directions from Local_Overlay, and remove the .git subdirectory.~

root # mkdir /var/git/overlay
root # cd /var/git/overlay
root # git clone  https://github.com/funtoo/skeleton-overlay.git crossdev
root # rm -rf /var/git/overlay/crossdev/.git
root # echo "crossdev" > /var/git/overlay/crossdev/profiles/repo_name

Edit config files to match.

   /etc/portage/repos.conf/crossdev.conf - Add the crossdev overlay to portage
[crossdev]
location = /var/git/overlay/crossdev
auto-sync = no
priority = 10
Sparse Checkout Gentoo GCC Ebuilds

Let's make a sparse checkout of the main Gentoo repo.

root # cd /var/git/overlay/crossdev
root # git init
root # git remote add origin git://github.com/gentoo/gentoo.git
root # git config core.sparseCheckout true
root # echo "sys-devel/gcc" >> .git/info/sparse-checkout
root # git pull --depth=1 origin master
Unmask and Emerge Crossdev
root # echo "sys-devel/crossdev **" >> /etc/portage/package.keywords/crossdev
root # echo "=sys-devel/crossdev-99999999" >> /etc/portage/package.unmask/crossdev
root # emerge crossdev

Install Cross Compilation Tool Chain

Retrieving Necessary Source Trees

Optionally Install Distcc via QEMU Chroot

Partition and Format an SDCard

Deploy Installation to SDCard