Raspberry pi

The Raspberry PI http://www.raspberrypi.org/ uses the SoC (System on Chip) from Broadcom BCM2835 having an ARM CPU, a GPU and Peripherals.

Figure 3.2. Raspberry PI


Other sites than the ones from the Raspberry foundation exist as:https://elinux.org/R-Pi_Hub

Gentoo on Raspberry

The best way to install Gentoo Linux on a Raspberry is following https://wiki.gentoo.org/wiki/Raspberry_Pi_Quick_Install_Guide some other help can be found at https://wiki.gentoo.org/wiki/Raspberry_Pi.

An SD card of at least 4GByte, better 8GByte is required. The SD card is prepared in at PC and needs at least two partitions. The around 100MB bootable boot partition is FAT32 id c and the root partition can luckily be a Linux partition as type 83. An issue is to create a swap partition or not, since swap partition could damage the SD card due to too many write cycles. Since swap can also be a file on the root partition, this decision can be postponed and no swap partition can be created.

The https://wiki.gentoo.org/wiki/Raspberry_Pi_Quick_Install_Guide creates a running Gentoo system very similar as a Gentoo system on a PC. The only differences are pre-compiled binaries for the kernel, its modules and the boot loader.


The easiest way is using pre-compiled binaries that can be replaced once the system is up and running. The other much more complex way would be getting the sources of the kernel and boot loader and then create and use a cross compiler to create the binaries.

Since it is a complete Gentoo installation it is autonomously. This means nothing else is required to install new packages, do updates and do the regular system administration work. The only drawbacks are:

  • Compilation takes much longer than on a full blown PC, so distcc with cross compilation would improve it but is not a must. If the raspberry runs anyway all day long than it could do this task. From an energy point of view it might even makes sense.

    Example 3.1. Compilation Raspberry versus PC

    A full blown PC does compilation in 1min but uses around 200W for that (ignoring the fact that also Raspberry needs to run in parallel). Raspberry uses 5W but could take 40 times longer. If Raspberry could it would do it in less than 40min it would be the more energy efficient way to compile on the Raspberry.

  • The memory space on the SD card is much higher than required for an embedded system since also things as kernel sources, gcc and the complete portage is there. However the today available smallest SD cards are big so this is really no more a key argument. If there is a concern to not have those things on the SD card, then it could be on a memory stick (or a network drive) that can be removed during regular operation an be mounted when administration work takes place.

Once the Raspberry PI is up and running Gentoo Linux. It might be time switching from pre-compiled binaries to source code hosted on https://github.com/raspberrypi/. For those there are:

  • sys-kernel/raspberrypi-sources (it takes about 6 hours to compile it on the raspberry)

  • sys-kernel/raspberrypi-image other pre-compiled kernel images

  • sys-boot/raspberrypi-mkimage Raspberry Pi kernel mangling tool mkimage/imagetool-uncompressed.py

  • sys-boot/raspberrypi-firmware the bootloader and firmware

  • media-libs/raspberrypi-userland Raspberry Pi userspace tools and libraries

Since the package management of Gentoo was not aware of the binary files that have been installed manually, conflicts and left overs might occur. Conflicts can be avoided by renaming the manually installed files or directories. Left overs are harder to detect and can deleted manually. To be sure it is wise to re-emerge the packet again so no files get accidentally deleted.

emerge cpufrequtils allows to reduce clock frequency on demand as defined in /etc/conf.d/cpufrequtils and started with rc-update add cpufrequtils default and verify it using cpufreq-info

To attach something to the GPIO see https://elinux.org/RPi_Low-level_peripherals. As most high density microchips the level are 3V3 so do not attach 5V Logic. There is on pin 1 a 3V3 50mA Power output and on poin2 and pin 4 a 5V power output. The 5V power comes more or less from the 5V power supply and can therefore supply up to 300mA current. Signals on the connector can be programmed as parallel IO, UART, I2C or SPI.

UART appears as /dev/ttyAMA0 . The pins are:

  • pin 6 is ground

  • pin 8 is TXD GPIO14

  • pin 10 RXD GPIO15

There is a DSI (Display Serial Interface) on S2 and a MIPI CSI-2 (Camera Serial Interface) on S5.

Debian on Raspberry

Raspian is Debian on Raspberry. Since the SDcard will probably be bigger than the Raspian image this can be fixed. During the first boot or sudo raspi-config after later boots pops up on option menu. Expanding the image to the SD card size is one option, local setting to have the keyboard working as desired is an other option.

Follow the instruction https://www.raspberrypi.org/documentation/installation/installing-images/linux.md except do not truncate the image. This can be done more easily on the Raspberry. truncate is misleading since it can be negative and therefore make the image larger.

dd bs=4M if=2016-11-25-raspbian-jessie.img of=/dev/sdd is finally a possible command that puts the image to the disk.

The raspberry has a HDMI port but you might use a HDMI to VGA adapter to use an older VGA screen and you find out that it does not work. Read and modify contig.txt in the root partition. See also https://thepihut.com/blogs/raspberry-pi-tutorials/34512708-troubleshooting-a-raspberry-pi-hdmi-vga-adapter for a solution.

The default user is called pi and its password raspberry. To login over the net ssh -l pi rasp (assuming the host can convert rasp in the known IP address). To run commands as root: sudo <command>

sudo su changes to the root console and after this entering sudo is no more required.

Working with Debian

To see what packages are installed type

sudo dpkg-query -l

or for a specific package

sudo dpkg-query -l | rep <packagename>

To update it sudo aptitude update followed by sudo aptitude full-upgrade

Debian networking

See https://www.raspberrypi.org/documentation/configuration/wireless/wireless-cli.md

The network settings are done in /etc/network/interfaces . Instead editing save it to a name as interfaces_orig and create a new on with the name interfaces_static containing:

iface eth0 inet static

Then delete interfaces and create a symbolic link ln -s interfaces_static interfaces. If it works then it is ok, otherwise just bend the link back to interfaces_orig

For wifi the two packages wireless-tools and wpasupplicant are required and are already installed using raspian. With a bit luck also the driver for the USB WLAN adapter is also already installed (as ralink). The settings in /etc/network/interfaces do do are:

auto wlan0
iface wlan0 inet dhcp
  wpa-ssid <my wlan name>
  wpa-psk <its password>

To test it

ifup wlan0

ifconfig wlan0

ping <some IP>

Or restart it with its scripts /etc/init.d/networking <restart|stop|start> to see more details iwconfig wlan0 and to scan iwlist wlan0 scan

To do a smooth (not risk corrupt file systems) power down a ssh shell can be opened ssh pi@<ip address> sudo init 0 will prepare it for safe power down

Linurs Servernest startpage