Like my predecessors, I had to this time neither a HDMI enabled monitor, or keyboard or mouse available. Only my laptop which is running on Gentoo-amd64 and I was thus forced to cross compiling. But because the Raspi was indeed designed to preserve resources and thus not exactly shine with performance during the compile, it is generally a good idea to pre-compile packages on a more powerful computer and then copy.
Attention: Using the following steps to create a Gentoo based Raspberry Pi box assumes to have some advanced Linux, Gentoo and Portage experience. Also some basic operating system knowledge is needed. Be careful if you are no expert and you do not know what a single step matters, do not just copy, paste and execute it!
Prepare SD card
As first step "fdisk" is needed for partitioning. I also used the recommendation for heads, sectors and cylinders @eLinux - RPi Advanced Setup. Afterwards my SD card partition table looks like this:
Device Boot Start Ende Blocks Id System
/dev/mmcblk0p1 * 2048 104447 51200 c W95 FAT32 (LBA)
/dev/mmcblk0p2 104448 1128447 512000 82 Linux swap / Solaris
/dev/mmcblk0p3 1128448 15546367 7208960 83 Linux
Because this was my first "Raspi" try, I used the SD Card as swap device too. But concerning the write limitation of NAND flash based drives, it should be moved to another device later.
Format SD card
In my next step, the SD card partitions had to be formatted:
mkfs.vfat -F 16 /dev/mmcblk0p1
mkfs.ext4 /dev/mmcblk0p3 # IF USING 4GB SD Card: -N 803200
mkswap /dev/mmcblk0p2
As already said, this was my first setup, so I decided to ext4 as root file system. F2FS or another NAND flash optimized system should be recommended for a longer lifetime. It might also be a good idea to move the some directories to other devices, like /tmp, /var, /home to reduce writing access.
Download
So far so good, now I had to download and install the stage3 arm release, as also the latest portage tree.
cd /home/myuser/Downloads/raspberrypi
wget -c http://ftp.uni-erlangen.de/mirrors/gentoo/releases/arm/autobuilds/current-stage3-armv6j_hardfp/stage3-armv6j_hardfp-20140818.tar.bz2
wget -c http://distfiles.gentoo.org/snapshots/portage-latest.tar.bz2
Mount, copy, extract & (cross)-compile
I used two separate directories to mount my SD card partitions and extracted the archives into them:
mount /dev/mmcblk0p3 /mnt/gentoo
mount /dev/mmcblk0p1 /mnt/gentooboot
cp portage-latest.tar.bz2 portage-latest.tar.bz2.backup
cp stage3-armv6j_hardfp-20140818.tar.bz2 stage3-armv6j_hardfp-20140818.tar.bz2.backup
tar xfpj stage3-armv6j_hardfp-*.tar.bz2 -C /mnt/gentoo
tar xjf portage-latest.tar.bz2 -C /mnt/gentoo/usr
To compile the kernel by a "foreign" architecture, cross compile tool chain is needed, see references for links and additional information. After the challenge to get the tool chain running correctly, it was quite easy to compile the kernel on my amd64 based laptop:
cd /usr/src/linux-3.16.9999-raspberrypi
make ARCH=arm bcmrpi_defconfig
make ARCH=arm CROSS_COMPILE=/usr/bin/armv6j-hardfloat-linux-gnueabi- oldconfig
make ARCH=arm CROSS_COMPILE=/usr/bin/armv6j-hardfloat-linux-gnueabi- -j2
make ARCH=arm CROSS_COMPILE=/usr/bin/armv6j-hardfloat-linux-gnueabi- modules_install INSTALL_MOD_PATH=/mnt/gentooimagetool-uncompressed.py /usr/src/linux-3.16.9999-raspberrypi/arch/arm/boot/Image /mnt/gentooboot/kernel.img
Config preparations
The next steps should be self-explanatory and may be adjusted according the current context.Portage - Compiler settings - /mnt/gentoo/etc/portage/make.conf
CFLAGS="-O2 -pipe -march=armv6j -mfpu=vfp -mfloat-abi=hard"
CXXFLAGS="${CFLAGS}"
LINGUAS="de"
CHOST="armv6j-hardfloat-linux-gnueabi"
USE="bindist"
PORTDIR="/usr/portage"
DISTDIR="${PORTDIR}/distfiles"
PKGDIR="${PORTDIR}/packages"
GENTOO_MIRRORS="http://ftp.halifax.rwth-aachen.de/gentoo/"
SYNC="rsync://rsync16.de.gentoo.org/gentoo-portage"
FEATURES="${FEATURES} parallel-fetch"
EMERGE_DEFAULT_OPTS="--with-bdeps=y"
Timezone
cp /mnt/gentoo/usr/share/zoneinfo/Europe/Berlin /mnt/gentoo/etc/localtime
echo "Europe/Berlin" > /mnt/gentoo/etc/timezone
SD card setup - /mnt/gentoo/etc/fstab
# /dev/mmcblk0p1
UUID=1F3C-0E60 /boot auto noauto,noatime 1 2
# /dev/mmcblk0p3
UUID=00db1598-09ed-49a0-bd5d-0a3f92142dcf / ext4 noatime 0 1
# /dev/mmcblk0p2
UUID=3314c1f0-a9a2-4368-9dc6-abd604cef99c none swap sw 0 0
Kernel Parameters
touch /mnt/gentooboot/cmdline.txt
echo "dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p3 rootfstype=ext4 elevator=deadline rootwait" > /mnt/gentooboot/cmdline.txt
Copy needed firmware
git clone --depth 1 git://github.com/raspberrypi/firmware/
cp firmware/boot/* /mnt/gentooboot
cp -r firmware/modules /mnt/gentoo/lib/
Enter via chroot
cp /usr/bin/qemu-arm /mnt/gentoo/usr/bin
mount -o bind /dev /mnt/gentoo/dev && mount -t sysfs none /mnt/gentoo/sys && mount -t proc none /mnt/gentoo/proc
chroot /mnt/gentoo /usr/bin/qemu-arm /bin/bash
uname -ra # to check new environment
source /etc/profile
update-env
passwd
General config
ln -s /etc/init.d/net.lo /etc/init.d/net.eth0
rc-update add net.eth0 boot
# rc-update del hwclock boot && rc-update add swclock boot -> was not needed for me as already set
rc-update add sshd default
eselect profile list # if change needed, my setting was already correct
Exit chroot
exit
umount /mnt/gentoo/dev && umount /mnt/gentoo/proc && umount /mnt/gentoo/sys && umount /mnt/gentoo/
umount /mnt/gentooboot
After moving the SD card to the Raspi it it easy to connect via SSH.SSH Connect
My LAN adapter is configured to 192.168.3.1 so I had to search the Raspi there:
nmap 192.168.3.0/24 # to find IP of the raspi
ssh root@192.168.3.13
Post-Config
Configure clock
The Raspi has no hardware clock to NTP seams to be the choice for synchronisation:
emerge ntp && rc-update add ntp-client default
Force GPU to minimun RAM
mount /boot/
nano /boot/config.txt
->
gpu_mem=16
arm_freq=900
core_freq=333
sdram_freq=450
over_voltage=2
force_turbo=1
Hostnanme
By default the hostname is "localhost", but it should be set to unique name in /etc/conf.d/hostnameLocales
I switched my locale to have German based keyboards and behaviour:/etc/env.d/02locale
LANG="de_DE.UTF-8"
LC_COLLATE="C"
LC_CTYPE="de_DE.UTF-8"
LC_NUMERIC="de_DE.UTF-8"
LC_TIME="de_DE.UTF-8"
LC_MONETARY="de_DE.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="de_DE.UTF-8"
LC_NAME="de_DE.UTF-8"
LC_ADDRESS="de_DE.UTF-8"
LC_TELEPHONE="de_DE.UTF-8"
LC_MEASUREMENT="de_DE.UTF-8"
LC_IDENTIFICATION="de_DE.UTF-8"
LANGUAGE="de_DE:de:en_US:en"
COUNTRY=DE
GDM_LANG="de_DE.utf8"
LC_ALL="de_DE.utf8"
/etc/locale.gen
en_US.UTF-8 UTF-8
de_DE.UTF-8 UTF-8
env-update && source /etc/profile
Common Tools
To have a nice known environment I installed common used tools and also used the opportunity to clean the system a bit:
emerge eix
eix-remote update && eix-sync && emerge -uDNa @world && emerge --depclean -a && revdep-rebuild -p
emerge links htop portpeek usbutils pciutils gentoolkit genlop perl-cleaner raspberrypi-userland wireless-tools wpa_supplicant
portpeek -arq
eix-test-obsolete
eclean -pd distfiles && perl-cleaner --reallyall -p
WIFI
For flexibility I connected a little tiny wireless LAN device, Edimax EW-7811Un (7392:7811). To find the correct driver and module I used "dmesg": dmesg | grep -C 3 WLAN
[3.189968] usb 1-1.2: new high-speed USB device number 4 using dwc_otg
[3.311697] usb 1-1.2: New USB device found, idVendor=7392, idProduct=7811
[3.329911] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[3.338946] usb 1-1.2: Product: 802.11n WLAN Adapter
[3.359819] usb 1-1.2: Manufacturer: Realtek
[3.365804] usb 1-1.2: SerialNumber: 00e04c000001
[5.095714] usb 1-1.2: USB disconnect, device number 4
After some googling I found the needed module, named RTL8192cu. So I added the "8192cu" to "/etc/conf.d/modules" for autoloading it. By some testing with wpa_supplicant with the nl80211 driver (as I expected to be compatible with my 8192 device). After:
wpa_supplicant -Dnl80211 -iwlan0 -C/var/run/wpa_supplicant/ -c/etc/wpa_supplicant/wpa_supplicant.conf -dd
I received:
rtl8192 Could not open file /sys/class/net/wlan0/phy80211/name
Then I tried the default driver, which worked nicely:
wpa_supplicant -iwlan0 -C/var/run/wpa_supplicant/ -c/etc/wpa_supplicant/wpa_supplicant.conf -dd
At the end I was able to symlink in init.d to have autostart:
ln -s /etc/init.d/net.lo /etc/init.d/net.wlan0
rc-update add net.wlan0 boot
References
- Gentoo Wiki: Raspberry_Pi_Quick_Install_Guide
- Gentoo Wiki: Raspberry_Pi_Kernel_Compilation
- Gentoo Wiki: Raspberry_Pi
- Gentoo Wiki: Raspberry_Pi_Cross_building
- Gentoo Wiki: Embedded handbook
- Gentoo Wiki: Crossdev_qemu-static-user-chroot
- Gentoo Wiki: Wpa_supplicant
- Faster-emerge-on-the-raspberry-pi-part-i/
- http://www.mobileapes.com/gentoo/raspberry-pi
- http://www.mobileapes.com/gentoo/crossdev
- http://www.boynux.com/45/
- gentoo-on-raspberry-pi/
- Gentoo_Installation_auf_dem_Raspberry_Pi_ohne_Monitor
- http://cqlug.linux.org.au/node/19
- http://www.raspberrypi.org/forums/viewtopic.php?f=26&t=18447
- http://www.raspberrypi.org/forums/viewtopic.php?f=54&t=707&start=75
- minimalist-gentoo-for-the-raspberry-pi
- build kernel
No comments:
Post a Comment