The Funtoo Linux project has transitioned to "Hobby Mode" and this wiki is now read-only.
Difference between revisions of "Funtoo Linux Installation on RPI"
(66 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
{{Important|This documentation is unofficial and not supported by Funtoo. It needs to be improved to be more straightforward as there are too many manual steps and it relies on a non-Funtoo project for setup.}} | |||
== Introduction == | == 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 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. | ||
== Installation Overview == | == Installation Overview == | ||
Line 12: | Line 11: | ||
# [[#Install Binary Kernel, Modules and dtbs]] | # [[#Install Binary Kernel, Modules and dtbs]] | ||
# [[#Cross-compile Kernel, Modules and dtbs from Source]] | # [[#Cross-compile Kernel, Modules and dtbs from Source]] | ||
# [[# | # [[#Use QEMU]] | ||
# [[#Partition and Format an SDCard]] | # [[#Partition and Format an SDCard]] | ||
# [[#Deploy Installation to SDCard]] | # [[#Deploy Installation to SDCard]] | ||
# [[#Transfer the SDCard to the Raspberry Pi and Boot]] | |||
# [[#Enjoy!]] | |||
== Get the Bash Script == | == Get the Bash Script == | ||
Line 20: | Line 21: | ||
Development code is available on [https://github.com/d4g33z/sysroot.git github]. The structure of the file {{c|sysroot.sh}} should roughly correspond to the information contained here. | Development code is available on [https://github.com/d4g33z/sysroot.git github]. The structure of the file {{c|sysroot.sh}} should roughly correspond to the information contained here. | ||
Too use the script, edit the {{c|config}} file and then | |||
{{console|body= | |||
###i## source sysroot.sh && sysroot_install | |||
}} | |||
== Create Your Installation Settings == | |||
Confguration your installation. These variables are referencecd by the {{c|sysroot.sh}} script and by this document. | Confguration your installation. These variables are referencecd by the {{c|sysroot.sh}} script and by this document. | ||
{{file|name=config | {{file|name=config|lang=bash|desc=Set your install configuration variables|body= | ||
KERNEL_WORK=/ | |||
KERNEL_WORK=/mnt/shared/rpi_kernel | |||
RPI_KERN_BRANCH=rpi-4.14.y | RPI_KERN_BRANCH=rpi-4.14.y | ||
SYSROOT_WORK=/ | SYSROOT_WORK=/mnt/shared/sysroots | ||
STAGE3_URL=http://ftp.osuosl.org/pub/funtoo/funtoo-current/arm-32bit/raspi3/stage3-latest.tar.xz | |||
CHOST=armv7a-hardfloat-linux-gnueabi | CHOST=armv7a-hardfloat-linux-gnueabi | ||
CFLAGS="-O2 -pipe -march=armv7-a -mtune=cortex-a53 -mfpu=neon-vfpv4 -mfloat-abi=hard" | CFLAGS="-O2 -pipe -march=armv7-a -mtune=cortex-a53 -mfpu=neon-vfpv4 -mfloat-abi=hard" | ||
Line 38: | Line 44: | ||
SDCARD_DEV=sdb | SDCARD_DEV=sdb | ||
INSTALL_VARS=(KERNEL_WORK RPI_KERN_BRANCH SYSROOT_WORK STAGE3_URL CHOST CFLAGS SDCARD_DEV) | |||
}} | }} | ||
== 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. | 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. | ||
Line 60: | Line 64: | ||
}} | }} | ||
== 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. | 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. | ||
Line 74: | Line 78: | ||
}} | }} | ||
== 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 {{c|$SYSROOT/etc}} directly. We could also chroot into $SYSROOT using QEMU as described below to install | 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 {{c|$SYSROOT/etc}} directly. | ||
We could also chroot into $SYSROOT using QEMU as described [[#Install a QEMU Chroot|below]] to install packages, edit files and use {{c|rc-update}} directly to set up services. | |||
==== Set Up Mount Points ==== | ==== Set Up Mount Points ==== | ||
Line 82: | Line 88: | ||
{{file|name=$SYSROOT/etc/fstab|body= | {{file|name=$SYSROOT/etc/fstab|body= | ||
/dev/mmcblk0p1 /boot vfat noauto,noatime 1 2 | /dev/mmcblk0p1 /boot vfat noauto,noatime 1 2 | ||
/dev/mmcblk0p2 / | /dev/mmcblk0p2 / ext4 noatime 0 1 | ||
}} | }} | ||
We can use the following {{ | We can use the following {{Package|sys-apps/sed}} code. | ||
{{console|body= | {{console|body= | ||
###i## sed -i "s/\/dev\/sda1.*/\/dev\/mmcblk0p1 \/boot vfat defaults 0 2/" ${SYSROOT}/etc/fstab | ###i## sed -i "s/\/dev\/sda1.*/\/dev\/mmcblk0p1 \/boot vfat defaults 0 2/" ${SYSROOT}/etc/fstab | ||
Line 94: | Line 100: | ||
==== Set Up Root Password ==== | ==== Set Up Root Password ==== | ||
Here we interactively add a root password to log in with to {{c|$SYSROOT/etc/shadow}}. | |||
{{warning|Occasionally this fails due to an unescaped sed control character in the password hash. Just try it until it works, or run the password generation separately from the shadow file editing, or actually fix it.}} | |||
{{console|body= | {{console|body= | ||
###i## sed -i "s/root\:\*/root\:`(openssl passwd -1)`/" $SYSROOT/etc/shadow | ###i## sed -i "s/root\:\*/root\:`(openssl passwd -1)`/" $SYSROOT/etc/shadow | ||
}} | }} | ||
==== Set Up Networking ==== | ==== Set Up Networking ==== | ||
We add dhcpcd as a default runlevel service. | |||
{{console|body= | {{console|body= | ||
###i## ln -sf /etc/init.d/dhcpcd ${SYSROOT}/etc/runlevels/default | ###i## ln -sf /etc/init.d/dhcpcd ${SYSROOT}/etc/runlevels/default | ||
}} | }} | ||
==== Set Up SSH Access ==== | ==== Set Up SSH Access ==== | ||
If you want to ssh to the board as root, you need to allow it explicitly and we add sshd as a default runlevel service. | |||
{{console|body= | {{console|body= | ||
###i## echo "PermitRootLogin yes" >> ${SYSROOT}/etc/ssh/sshd_config | ###i## echo "PermitRootLogin yes" >> ${SYSROOT}/etc/ssh/sshd_config | ||
Line 107: | Line 117: | ||
}} | }} | ||
==== Set Up the Software Clock ==== | ==== Set Up the Software Clock ==== | ||
Let's set up the software clock. This is Raspberry Pi specific, and due to its lack of a stock RTC chipset. This has ramifications for maintaining the correct time via a pacakge like {{Package|net-misc/openntpd}}. | |||
{{console|body= | {{console|body= | ||
###i## ln -sf /etc/init.d/swclock ${SYSROOT}/etc/runlevels/boot | ###i## ln -sf /etc/init.d/swclock ${SYSROOT}/etc/runlevels/boot | ||
Line 114: | Line 125: | ||
}} | }} | ||
==== Disable Serial Console Access ==== | ==== Disable Serial Console Access ==== | ||
If you | Let's prevent serial consoles from spawning. If you have a need for this, you'll be able to set it up yourself. | ||
{{console|body= | {{console|body= | ||
###i## sed -i "s/s0\:.*/\#&/" ${SYSROOT}/etc/inittab | ###i## sed -i "s/s0\:.*/\#&/" ${SYSROOT}/etc/inittab | ||
}} | }} | ||
==== Link to Accelerated Video Libraries ==== | ==== Link to Accelerated Video Libraries ==== | ||
You must add {{c|/opt/vc/lib}} to {{c|$LD_LIBRARY_PATH}} in the shell, or use the {{c|env-update}} functionality of Funtoo if you want to link against these firmware libraries. This is critical if you want to do any accelerated graphics or gpu level work. | |||
Here we add an entry to the appropriate configuration file which {{c|env-update}} will pick up whenever we {{c|source /etc/profile}}. | |||
{{console|body= | {{console|body= | ||
###i## echo "LDPATH=\"/opt/vc/lib\"" > ${SYSROOT}/etc/env.d/99vc | ###i## echo "LDPATH=\"/opt/vc/lib\"" > ${SYSROOT}/etc/env.d/99vc | ||
}} | }} | ||
If you want to try building native vc4 acceleration with media-libs/mesa you must unmask the appropriate USE flags at the profile level and VIDEO_CARDS="vc4" in make.conf. | |||
{{console|body= | |||
###i## cat > /etc/portage/profile/portage.use.mask << EOF | |||
##i##media-libs/mesa -video_cards_vc4 | |||
##i##x11-libs/libdrm -video_cards_vc4 | |||
##i##EOF | |||
}} | |||
If the file /var/log/Xorg.0.log are flooded with the same messages. The file are huge. The messages are: | |||
(EE) modeset(0): Failed to get GBM bo for flip to new front. | |||
(EE) modeset(0): present flip failed | |||
Workaround: Disable PageFlip for modesetting | |||
It is preferred to keep using "modesetting" driver, but disabling page flipping is necessary. | |||
To do this, as a root user create a file 20-displaylink.conf under /usr/share/X11/xorg.conf.d/ with the following content: | |||
{{file|name=$SYSROOT/usr/share/X11/xorg.conf.d/20-displaylink.conf|body= | |||
Section "Device" | |||
Identifier "DisplayLink" | |||
Driver "modesetting" | |||
Option "PageFlip" "false" | |||
EndSection | |||
}} | |||
==== Configure the Boot Parameters ==== | ==== Configure the Boot Parameters ==== | ||
{{console|body= | {{console|body= | ||
Line 128: | Line 170: | ||
##i## EOF | ##i## EOF | ||
}} | }} | ||
== Install Binary Kernel, Modules and dtbs == | |||
{{console|body= | {{console|body= | ||
###i## mkdir -p ${SYSROOT}/boot/overlays | ###i## mkdir -p ${SYSROOT}/boot/overlays | ||
Line 136: | Line 178: | ||
###i## cp ${KERNEL_WORK}/firmware/boot/kernel7.img ${SYSROOT}/boot/ | ###i## cp ${KERNEL_WORK}/firmware/boot/kernel7.img ${SYSROOT}/boot/ | ||
}} | }} | ||
== Cross-compile Kernel, Modules and dtbs from Source == | |||
==== Install Crossdev ==== | ==== Install Crossdev ==== | ||
{{Package|sys-devel/crossdev}} 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 [https://bugs.funtoo.org/browse/FL-3787 solution], but there has been no follow up on a complete implementation. | {{Package|sys-devel/crossdev}} 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 [https://bugs.funtoo.org/browse/FL-3787 solution], but there has been no follow up on a complete implementation. | ||
Line 146: | Line 188: | ||
}} | }} | ||
==== Make a Local Overlay ==== | |||
Let's follow the directions from [[Local_Overlay]], and remove the .git subdirectory.~ | Let's follow the directions from [[Local_Overlay]], and remove the .git subdirectory.~ | ||
{{console|body= | {{console|body= | ||
Line 164: | Line 206: | ||
}} | }} | ||
==== Sparse Checkout Gentoo GCC Ebuilds ==== | |||
Let's make a [https://stackoverflow.com/questions/600079/how-do-i-clone-a-subdirectory-only-of-a-git-repository/28039894#28039894 sparse checkout] of the main Gentoo repo. | Let's make a [https://stackoverflow.com/questions/600079/how-do-i-clone-a-subdirectory-only-of-a-git-repository/28039894#28039894 sparse checkout] of the main Gentoo repo. | ||
Line 176: | Line 218: | ||
}} | }} | ||
==== Unmask and Emerge Crossdev ==== | |||
{{console|body= | {{console|body= | ||
###i## echo "sys-devel/crossdev **" >> /etc/portage/package.keywords/crossdev | ###i## echo "sys-devel/crossdev **" >> /etc/portage/package.keywords/crossdev | ||
Line 188: | Line 230: | ||
}} | }} | ||
==== Retrive Raspberry Pi Kernel Sources ==== | |||
{{console|body= | {{console|body= | ||
###i## git clone https://github.com/raspberrypi/linux.git ${KERNEL_WORK}/linux | ###i## git clone https://github.com/raspberrypi/linux.git ${KERNEL_WORK}/linux | ||
Line 203: | Line 245: | ||
==== Make the Default Config ==== | ==== Make the Default Config ==== | ||
The next set of {{c|make}} commands take place in the kernel source directory. | |||
{{console|body= | |||
###i## cd ${KERNEL_WORK}/linux | |||
}} | |||
There are many useful make targets to control kernel configs. In particular, the architecture specific ones are most useful in cross-compiling applications. You can see all available architecture specfic default configurations with the following command. | |||
{{console|body= | |||
###i## make -j$(nproc) \ | |||
##i## ARCH=arm \ | |||
##i## CROSS_COMPILE=${CHOST}- \ | |||
##i## make_defconfig_help | |||
# Architecture specific targets (arm): | |||
... <targets we don't need> ... | |||
acs5k_defconfig - Build for acs5k | |||
acs5k_tiny_defconfig - Build for acs5k_tiny | |||
am200epdkit_defconfig - Build for am200epdkit | |||
assabet_defconfig - Build for assabet | |||
at91_dt_defconfig - Build for at91_dt | |||
axm55xx_defconfig - Build for axm55xx | |||
badge4_defconfig - Build for badge4 | |||
##r##bcm2709_defconfig - Build for bcm2709 | |||
bcm2835_defconfig - Build for bcm2835 | |||
bcm_defconfig - Build for bcm | |||
bcmrpi_defconfig - Build for bcmrpi | |||
cerfcube_defconfig - Build for cerfcube | |||
clps711x_defconfig - Build for clps711x | |||
...<lots o configs>... | |||
zeus_defconfig - Build for zeus | |||
zx_defconfig - Build for zx | |||
...<more targets we don't need> ... | |||
}} | |||
{{console|body= | {{console|body= | ||
###i## make -j$(nproc) \ | ###i## make -j$(nproc) \ | ||
Line 220: | Line 297: | ||
==== Build and Install the Kernel ==== | ==== Build and Install the Kernel ==== | ||
{{console|body= | {{console|body= | ||
###i## make -j$(nproc) \ | ###i## make -j$(nproc) \ | ||
Line 250: | Line 323: | ||
}} | }} | ||
==== Remove Kernel Headers and Source Links ==== | |||
{{console|body= | {{console|body= | ||
###i## rm ${SYSROOT}/lib/modules/`get_kernel_release`/{build,source} | ###i## rm ${SYSROOT}/lib/modules/`get_kernel_release`/{build,source} | ||
}} | }} | ||
==== Backup Kernel Config ==== | |||
{{console|body= | {{console|body= | ||
###i## mkdir -p ${SYSROOT}/etc/kernels | ###i## mkdir -p ${SYSROOT}/etc/kernels | ||
Line 261: | Line 334: | ||
}} | }} | ||
=== Partition and Format an SDCard | == Use QEMU == | ||
{{Package|app-emulation/qemu}} relies upon KVM and the associated kernel module, called either {{c|kvm_intel}} or {{c|kvm_amd}}, depending on the architecture the kernel is running on. Please see [[KVM]] to find out how to get these kernel modules loaded and virtualization working. | |||
=== Install a QEMU Chroot === | |||
{{console|body= | |||
###i## echo "app-emulation/qemu static-user" > /etc/portage/package.use/qemu | |||
###i## echo "dev-libs/libpcre static-libs" >> /etc/portage/package.use/qemu | |||
###i## echo "sys-apps/attr static-libs" >> /etc/portage/package.use/qemu | |||
###i## echo "dev-libs/glib static-libs" >> /etc/portage/package.use/qemu | |||
###i## echo "sys-libs/zlib static-libs" >> /etc/portage/package.use/qemu | |||
###i## echo "QEMU_SOFTMMU_TARGETS=\"arm\"" >> /etc/portage/make.conf | |||
###i## echo "QEMU_SOFTMMU_TARGETS=\"\${QEMU_SOFTMMU_TARGETS} arm\"" >> /etc/portage/make.conf | |||
###i## echo 'QEMU_USER_TARGETS="arm"' >> /etc/portage/make.conf | |||
###i## echo 'QEMU_USER_TARGETS="${QEMU_USER_TARGETS} arm"' >> /etc/portage/make.conf | |||
###i## emerge -q app-emulation/qemu | |||
###i## quickpkg app-emulation/qemu | |||
###i## ROOT=${SYSROOT}/ emerge -q --usepkgonly --oneshot --nodeps qemu | |||
}} | |||
=== Example: Chroot with ARM Emulation === | |||
{{console|body= | |||
###i## source sysroot.sh && sysroot_chroot $SYSROOT_WORK/$CHOST | |||
###i## export PS1="(chroot) $PS1" | |||
(chroot) ###i## ego profile | |||
=== Enabled Profiles: === | |||
arch: arm-32bit | |||
build: current | |||
subarch: raspi3 | |||
flavor: core | |||
mix-ins: (not set) | |||
NOTE: Meta-repo has not yet been cloned, so no kit information is available. Type ego sync to perform an initial | |||
clone of meta-repo. | |||
(chroot) ###i## ego sync | |||
(chroot) ###i## exit | |||
}} | |||
=== Example: Run a Shell Script in the ARM Chroot === | |||
{{console|body= | |||
###i## cat > /tmp/shell_test.sh << EOF | |||
##i## #!/bin/sh | |||
##i## ego profile | |||
##i## EOF | |||
###i## . sysroot.sh && sysroot_run_in_chroot $SYSROOT_WORK/$CHOST /tmp/shell_test.sh | |||
=== Enabled Profiles: === | |||
arch: arm-32bit | |||
build: current | |||
subarch: raspi3 | |||
flavor: core | |||
mix-ins: (not set) | |||
=== Python kit: === | |||
branch: 3.4-prime | |||
=== All inherited flavor from core flavor: === | |||
minimal (from core flavor) | |||
}} | |||
== Partition and Format an SDCard == | |||
{{console|body= | {{console|body= | ||
###i## export SDCARD=/dev/SDCARD_DEV | ###i## export SDCARD=/dev/SDCARD_DEV | ||
Line 286: | Line 423: | ||
}} | }} | ||
== Deploy Installation to SDCard == | |||
{{console|body= | {{console|body= | ||
###i## mkdir -p /mnt/ | ###i## mkdir -p /mnt/rpi | ||
###i## mount ${SDCARD}2 /mnt/ | ###i## mount ${SDCARD}2 /mnt/rpi | ||
###i## mkdir -p /mnt/ | ###i## mkdir -p /mnt/rpi/boot | ||
###i## mount ${SDCARD}1 /mnt/ | ###i## mount ${SDCARD}1 /mnt/rpi/boot | ||
###i## rsync --archive \ | ###i## rsync --archive \ | ||
##i## --verbose \ | ##i## --verbose \ | ||
##i## --progress \ | ##i## --progress \ | ||
##i## --exclude "var/git/*" \ | ##i## --exclude "var/git/*" \ | ||
##i## ${SYSROOT}/{boot,bin,etc,home,lib,mnt,opt,root,run,sbin,srv,tmp,usr,var,dev} \ | ##i## ${SYSROOT}/{boot,bin,etc,home,lib,mnt,opt,root,run,sbin,srv,tmp,usr,var,dev,proc,sys} \ | ||
##i## /mnt/ | ##i## /mnt/rpi | ||
###i## umount /mnt/rpi/boot | |||
###i## umount /mnt/rpi | |||
}} | }} | ||
== Transfer the SDCard to the Raspberry Pi and Boot== | |||
== Enjoy! == |
Latest revision as of 23:52, January 20, 2022
This documentation is unofficial and not supported by Funtoo. It needs to be improved to be more straightforward as there are too many manual steps and it relies on a non-Funtoo project for setup.
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.
Installation Overview
- #Create Your Installation Settings
- #Install the Stage 3 Tarball
- #Install the Firmware
- #Configure Your System
- #Install Binary Kernel, Modules and dtbs
- #Cross-compile Kernel, Modules and dtbs from Source
- #Use QEMU
- #Partition and Format an SDCard
- #Deploy Installation to SDCard
- #Transfer the SDCard to the Raspberry Pi and Boot
- #Enjoy!
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.
Too use the script, edit the config
file and then
root # source sysroot.sh && sysroot_install
Create Your Installation Settings
Confguration your installation. These variables are referencecd by the sysroot.sh
script and by this document.
config
(bash source code) - Set your install configuration variablesKERNEL_WORK=/mnt/shared/rpi_kernel
RPI_KERN_BRANCH=rpi-4.14.y
SYSROOT_WORK=/mnt/shared/sysroots
STAGE3_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
INSTALL_VARS=(KERNEL_WORK RPI_KERN_BRANCH SYSROOT_WORK STAGE3_URL CHOST CFLAGS SDCARD_DEV)
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 packages, edit files and use rc-update
directly to set up services.
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 No results 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
Here we interactively add a root password to log in with to $SYSROOT/etc/shadow
.
Occasionally this fails due to an unescaped sed control character in the password hash. Just try it until it works, or run the password generation separately from the shadow file editing, or actually fix it.
root # sed -i "s/root\:\*/root\:`(openssl passwd -1)`/" $SYSROOT/etc/shadow
Set Up Networking
We add dhcpcd as a default runlevel service.
root # ln -sf /etc/init.d/dhcpcd ${SYSROOT}/etc/runlevels/default
Set Up SSH Access
If you want to ssh to the board as root, you need to allow it explicitly and we add sshd as a default runlevel service.
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
Let's set up the software clock. This is Raspberry Pi specific, and due to its lack of a stock RTC chipset. This has ramifications for maintaining the correct time via a pacakge like No results.
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
Let's prevent serial consoles from spawning. If you have a need for this, you'll be able to set it up yourself.
root # sed -i "s/s0\:.*/\#&/" ${SYSROOT}/etc/inittab
Link to Accelerated Video Libraries
You must add /opt/vc/lib
to $LD_LIBRARY_PATH
in the shell, or use the env-update
functionality of Funtoo if you want to link against these firmware libraries. This is critical if you want to do any accelerated graphics or gpu level work.
Here we add an entry to the appropriate configuration file which env-update
will pick up whenever we source /etc/profile
.
root # echo "LDPATH=\"/opt/vc/lib\"" > ${SYSROOT}/etc/env.d/99vc
If you want to try building native vc4 acceleration with media-libs/mesa you must unmask the appropriate USE flags at the profile level and VIDEO_CARDS="vc4" in make.conf.
root # cat > /etc/portage/profile/portage.use.mask << EOF root ##i##media-libs/mesa -video_cards_vc4 root ##i##x11-libs/libdrm -video_cards_vc4 root ##i##EOF
If the file /var/log/Xorg.0.log are flooded with the same messages. The file are huge. The messages are:
(EE) modeset(0): Failed to get GBM bo for flip to new front. (EE) modeset(0): present flip failed
Workaround: Disable PageFlip for modesetting
It is preferred to keep using "modesetting" driver, but disabling page flipping is necessary. To do this, as a root user create a file 20-displaylink.conf under /usr/share/X11/xorg.conf.d/ with the following content:
$SYSROOT/usr/share/X11/xorg.conf.d/20-displaylink.conf
Section "Device"
Identifier "DisplayLink"
Driver "modesetting"
Option "PageFlip" "false"
EndSection
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.~
Please ensure that /etc/portage{package.keywords,package.mask,package.use}
are all directories.
Make a 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
root # crossdev -S --ov-gcc /var/git/overlay/crossdev -t ${CHOST}
Retrive Raspberry Pi Kernel Sources
root # git clone https://github.com/raspberrypi/linux.git ${KERNEL_WORK}/linux
Clean and Update Kernel Sources
root # git --git-dir=${KERNEL_WORK}/linux/.git --work-tree=${KERNEL_WORK}/linux clean -fdx root # git --git-dir=${KERNEL_WORK}/linux/.git --work-tree=${KERNEL_WORK}/linux checkout master root # git --git-dir=${KERNEL_WORK}/linux/.git --work-tree=${KERNEL_WORK}/linux fetch --all root # git --git-dir=${KERNEL_WORK}/linux/.git --work-tree=${KERNEL_WORK}/linux branch -D ${RPI_KERN_BRANCH} root # git --git-dir=${KERNEL_WORK}/linux/.git --work-tree=${KERNEL_WORK}/linux checkout ${RPI_KERN_BRANCH}
Make the Default Config
The next set of make
commands take place in the kernel source directory.
root # cd ${KERNEL_WORK}/linux
There are many useful make targets to control kernel configs. In particular, the architecture specific ones are most useful in cross-compiling applications. You can see all available architecture specfic default configurations with the following command.
root # make -j$(nproc) \ root ##i## ARCH=arm \ root ##i## CROSS_COMPILE=${CHOST}- \ root ##i## make_defconfig_help root # Architecture specific targets (arm): ... <targets we don't need> ... acs5k_defconfig - Build for acs5k acs5k_tiny_defconfig - Build for acs5k_tiny am200epdkit_defconfig - Build for am200epdkit assabet_defconfig - Build for assabet at91_dt_defconfig - Build for at91_dt axm55xx_defconfig - Build for axm55xx badge4_defconfig - Build for badge4 root ##r##bcm2709_defconfig - Build for bcm2709 bcm2835_defconfig - Build for bcm2835 bcm_defconfig - Build for bcm bcmrpi_defconfig - Build for bcmrpi cerfcube_defconfig - Build for cerfcube clps711x_defconfig - Build for clps711x ...<lots o configs>... zeus_defconfig - Build for zeus zx_defconfig - Build for zx ...<more targets we don't need> ...
root # make -j$(nproc) \ root ##i## ARCH=arm \ root ##i## CROSS_COMPILE=${CHOST}- \ root ##i## bcm2709_defconfig
Configure the Kernel
root # make -j$(nproc) \ root ##i## ARCH=arm \ root ##i## CROSS_COMPILE=${CHOST}- \ root ##i## MENUCONFIG_COLOR=mono \ root ##i## menuconfig
Build and Install the Kernel
root # make -j$(nproc) \ root ##i## ARCH=arm \ root ##i## CROSS_COMPILE=${CHOST}- \ root ##i## zImage dtbs modules
root # make -j$(nproc) \ root ##i## ARCH=arm \ root ##i## CROSS_COMPILE=${CHOST}- \ root ##i## INSTALL_MOD_PATH=${SYSROOT} \ root ##i## modules_install
root # mkdir -p ${SYSROOT}/boot/overlays root ##i## cp arch/arm/boot/dts/*.dtb ${SYSROOT}/boot/ root ##i## cp arch/arm/boot/dts/overlays/*.dtb* ${SYSROOT}/boot/overlays/ root ##i## cp arch/arm/boot/dts/overlays/README ${SYSROOT}/boot/overlays/
root # scripts/mkknlimg arch/arm/boot/zImage ${SYSROOT}/boot/kernel7.img
Remove Kernel Headers and Source Links
root # rm ${SYSROOT}/lib/modules/`get_kernel_release`/{build,source}
Backup Kernel Config
root # mkdir -p ${SYSROOT}/etc/kernels root # cp -i ${KERNEL_WORK}/linux/.config ${SYSROOT}/etc/kernels
Use QEMU
No results relies upon KVM and the associated kernel module, called either kvm_intel
or kvm_amd
, depending on the architecture the kernel is running on. Please see KVM to find out how to get these kernel modules loaded and virtualization working.
Install a QEMU Chroot
root # echo "app-emulation/qemu static-user" > /etc/portage/package.use/qemu root # echo "dev-libs/libpcre static-libs" >> /etc/portage/package.use/qemu root # echo "sys-apps/attr static-libs" >> /etc/portage/package.use/qemu root # echo "dev-libs/glib static-libs" >> /etc/portage/package.use/qemu root # echo "sys-libs/zlib static-libs" >> /etc/portage/package.use/qemu root # echo "QEMU_SOFTMMU_TARGETS=\"arm\"" >> /etc/portage/make.conf root # echo "QEMU_SOFTMMU_TARGETS=\"\${QEMU_SOFTMMU_TARGETS} arm\"" >> /etc/portage/make.conf root # echo 'QEMU_USER_TARGETS="arm"' >> /etc/portage/make.conf root # echo 'QEMU_USER_TARGETS="${QEMU_USER_TARGETS} arm"' >> /etc/portage/make.conf root # emerge -q app-emulation/qemu root # quickpkg app-emulation/qemu root # ROOT=${SYSROOT}/ emerge -q --usepkgonly --oneshot --nodeps qemu
Example: Chroot with ARM Emulation
root # source sysroot.sh && sysroot_chroot $SYSROOT_WORK/$CHOST root # export PS1="(chroot) $PS1" (chroot) # ego profile === Enabled Profiles: === arch: arm-32bit build: current subarch: raspi3 flavor: core mix-ins: (not set) NOTE: Meta-repo has not yet been cloned, so no kit information is available. Type ego sync to perform an initial clone of meta-repo. (chroot) # ego sync (chroot) # exit
Example: Run a Shell Script in the ARM Chroot
root # cat > /tmp/shell_test.sh << EOF root ##i## #!/bin/sh root ##i## ego profile root ##i## EOF root # . sysroot.sh && sysroot_run_in_chroot $SYSROOT_WORK/$CHOST /tmp/shell_test.sh === Enabled Profiles: === arch: arm-32bit build: current subarch: raspi3 flavor: core mix-ins: (not set) === Python kit: === branch: 3.4-prime === All inherited flavor from core flavor: === minimal (from core flavor)
Partition and Format an SDCard
root # export SDCARD=/dev/SDCARD_DEV
Randomize SDCard
root # dd if=/dev/urandom of=${SDCARD} bs=1M status=progress
Write Parition Scheme to SDCard
root # umount -Rl ${SDCARD} root # sfdisk --no-reread --wipe always ${SDCARD} << EOF root ##i## label: dos root ##i## unit: sectors root ##i## ${SDCARD}1 : start= 2048, size= 1048576, type=c root ##i## ${SDCARD}2 : start= 1050624, type=83 root ##i## EOF
Format SDCard
Make sure you have No results installed.
root # mkfs.ext4 ${SDCARD}2 root # mkfs.vfat ${SDCARD}1
Deploy Installation to SDCard
root # mkdir -p /mnt/rpi root # mount ${SDCARD}2 /mnt/rpi root # mkdir -p /mnt/rpi/boot root # mount ${SDCARD}1 /mnt/rpi/boot root # rsync --archive \ root ##i## --verbose \ root ##i## --progress \ root ##i## --exclude "var/git/*" \ root ##i## ${SYSROOT}/{boot,bin,etc,home,lib,mnt,opt,root,run,sbin,srv,tmp,usr,var,dev,proc,sys} \ root ##i## /mnt/rpi root # umount /mnt/rpi/boot root # umount /mnt/rpi