Raspberry Pi - ArchWiki

# Raspberry Pi

This article is being considered for archiving.

Reason: Merged to [1].[2] Redirect to Category:ARM architecture. (Discuss in Talk:Raspberry Pi#)

From Wikipedia:

  The Raspberry Pi is a series of credit card-sized single-board computers developed in the UK by the Raspberry Pi Foundation with the intention of promoting the teaching of basic computer science in schools.

The original models, released in 2012, are based on the Broadcom SoC BCM2835 (ARM11 architecture). The Raspberry Pi 2, released in 2015, is shipped with a BCM2836 SoC (quad-core ARM Cortex-A7 architecture). In February 2016, the Pi 3 was launched which contains a BCM2837 SoC (quad-core ARM Cortex-A53 architecture) and built in WiFi and Bluetooth.

## Article preface

This article is not meant to be an exhaustive setup guide and assumes that the reader has setup an Arch system before.

Note: Support for the ARM architecture is provided on http://archlinuxarm.org not through posts to the official Arch Linux Forum. Any posts related to ARM specific issues will be promptly closed per the Code of conduct#Arch Linux distribution support *only* policy.

## System architecture

The Raspberry Pi is an ARM-based device and therefore needs binaries compiled for this architecture. These binaries are provided by the Arch Linux ARM project which ports Arch Linux to ARM-based devices. They also have a separate community and forum on their website, while original forum does not support ARM specific issues. With the introduction of the Raspberry Pi 2 the packages needed now depend on which architecture the devices has:

- ARMv6 (BCM2835): Raspberry Pi Model A, A+, B, B+, Zero, Zero W
- ARMv7 (BCM2836): Raspberry Pi 2 (based on Model B+)
- ARMv8 (BCM2837): Raspberry Pi 3

## SD card performance

System responsiveness, particularly during operations involving disk I/O such as updating the system, can be adversely affected by poor quality/slow SD media. This is characterized by frequent, often extended pauses as pacman writes out files to the file system. The pauses are not due to saturation of the bus, they are likely caused by a slow micro SD card. See the Benchmarking#Flash media for measuring performance. The recommended solution is use so-called "Pro" class media classified as UHS-I U3 or better. As well, performance and system responsiveness can be tweaked by making adjustments to the system configuration. See Improving performance.

### Enable fsck on boot

Follow fsck#Boot time checking. Remember that kernel parameters are specified in `/boot/cmdline.txt`.

## Installing Arch Linux ARM

See the Arch Linux ARM Pi documentation or Arch Linux ARM Pi2 documentation or Arch Linux ARM Pi3 documentation.

Note: Although the RPi3 can run either ARMv7 (32-bit) or AArch64 (64-bit) architectures, there is currently no support for the vendor-provided libraries, extensions, or related software for AArch64 and some hardware on the board may not work, or may perform poorly. ARMv7 is recommended at this time.

## Network

The fresh install comes preconfigured to use the onboard NIC in dhcp mode via systemd-networkd. This should allow access to an official installation through Secure Shell. The default hostname is alarmpi. The root user's password is "root" and it is highly recommended to change the password and optionally set up SSH keys.

### Configure WLAN without ethernet

Users needing to establish a wireless internet connection will need to use a wireless daemon such as WPA supplicant. See also Wireless network configuration.

## Audio

alsa-utils should supply the needed programs to use onboard sound. Default volume can be adjusted using `alsamixer`.

A key change with Linux kernel version 4.4.x for ARM related to ALSA and to the needed sound module: in order to use tools such as `alsamixer` with the current kernel, users must modify `/boot/config.txt` to contain the following line:

    dtparam=audio=on

Tip: Ensure that the sole source "PCM" is not muted (denoted by `MM` if muted, press `M` to unmute).

Select an audio source for output:

    $ amixer cset numid=3 x

Where `x` corresponds to:

- 0 for Auto
- 1 for Analog out
- 2 for HDMI

### Caveats for HDMI audio

Some applications require a setting in `/boot/config.txt` to force audio over HDMI:

    hdmi_drive=2

### Caveats for Analogue audio

Sometimes audio from the 3.5mm analogue output can be terribly distorted. Adding the following to `/boot/config.txt` may fix the problem.

    audio_pwm_mode=2

## Video

### CPU/GPU RAM split

Memory split between the CPU and GPU of the SoC can be set in `boot/config.txt` by adjusting the parameter `gpu_mem` which stands for the amount of RAM in MB that is available to the GPU (minimum 16, default 64) and the rest is available to the ARM CPU.

### HDMI / analog TV-Out

With the default configuration, the Raspberry Pi uses HDMI video if a HDMI monitor is connected. Otherwise, it uses analog TV-Out (also known as composite output or RCA)

To turn the HDMI or analog TV-Out on or off, have a look at

    /opt/vc/bin/tvservice

Use the -s parameter to check the status; the -o parameter to turn the display off and -p parameter to power on HDMI with preferred settings.

Adjustments are likely required to correct proper overscan/underscan and are easily achieved in `boot/config.txt` in which many tweaks are set. To fix, simply uncomment the corresponding lines and setup per the commented instructions:

    # uncomment the following to adjust overscan. Use positive numbers if console
    # goes off screen, and negative if there is too much border
    #overscan_left=16
    overscan_right=8
    overscan_top=-16
    overscan_bottom=-16

Or simply disable overscan if the TV/monitor has a "fit to screen" option.

    disable_overscan=1

Users wishing to use the analog video out should consult this config file which contains options for non-NTSC outputs.

A reboot is needed for new settings to take effect.

### Caveats for analog TV-Out

Since Raspberry Pi 1 Model B+ and Raspberry Pi 2 Model B, the composite video socket was removed, with the replacement of composite signal through the 3.5mm video/audio jack. Some RCA cables do not follow the same standard as Raspberry Pi, in which case connect the red or white audio plug for video.[3]

### X.org driver

The X.org driver for Raspberry Pi can be installed with the xf86-video-fbdev or xf86-video-fbturbo-git package.

## Onboard hardware sensors

### Temperature

Temperatures sensors can be queried with utils in the raspberrypi-firmware package. The RPi offers a sensor on the BCM2835 SoC (CPU/GPU):

    $ /opt/vc/bin/vcgencmd measure_temp

    temp=49.8'C

Alternatively, simply read from the file system:

    $ cat /sys/class/thermal/thermal_zone0/temp

    49768

For human readable output:

    $ awk '{printf "%3.1f°C\n", $1/1000}' /sys/class/thermal/thermal_zone0/temp

    54.1°C

### Voltage

Four different voltages can be monitored via `/opt/vc/bin/vcgencmd` as well:

    $ /opt/vc/bin/vcgencmd measure_volts <id>

Where `<id>` is:

- core for core voltage
- sdram_c for sdram Core voltage
- sdram_i for sdram I/O voltage
- sdram_p for sdram PHY voltage

### Watchdog

BCM2708 has a hardware watchdog which can be utilized by enabling the `bcm2708_wdog` kernel module.

For proper operation, install the watchdog package, configure it (by uncommenting the "watchdog-device" line in `/etc/watchdog.conf`) and enable `watchdog.service`.

This should also apply for Raspberry Pi 2 by using the `bcm2709_wdog` module and Raspberry Pi 3 by using the `bcm2835_wdt` module.

### Lightweight monitoring suite

monitorixAUR has specific support for the RPi since v3.2.0 through the `raspberrypi = y` setting in `/etc/monitorix/monitorix.conf`. Temperature, voltages, and frequencies are logged; screenshots available here.

## Overclocking/underclocking

The RPi can be overclocked by editing `/boot/config.txt`, for example:

Raspberry Pi 1: Defaults

    arm_freq=700
    core_freq=250
    sdram_freq=400

Raspberry Pi 1: Overclocked

    arm_freq=800
    arm_freq_min=100
    core_freq=300
    core_freq_min=75
    sdram_freq=400
    over_voltage=0

Raspberry Pi 3: Defaults:

    arm_freq=1200
    core_freq=400
    sdram_freq=450

Raspberry Pi 3: Overclocked

    arm_freq=1350
    core_freq=500
    sdram_freq=500 # test required
    over_voltage=4

The optional `*_min` lines define the minimum frequency to be used for the given component. When the system is not under load, the frequencies will drop down to the minimum value. Consult the Overclocking article on elinux for additional options and examples.

A reboot is needed for new settings to take effect.

The overclocked setting for CPU clock applies only when the governor throttles up the CPU, i.e. under load. To query the current frequency of the CPU:

    $ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq

See CPU frequency scaling for details on scaling governors.

Tip: The following script will show all frequencies set on the RPi:

    #/bin/bash
    for src in arm core h264 isp v3d uart pwm emmc pixel vec hdmi dpi ; do
        echo -e "$src:\t$(/opt/vc/bin/vcgencmd  measure_clock $src)"
    done

## Serial console

Edit the default `/boot/cmdline.txt`, change `loglevel` to `5` to see boot messages:

    loglevel=5

Note: The Pi3 requires `enable_uart=1` be added to `/boot/config.txt` in order to display boot messages.

If the default speed of 115200 does not work properly, try changing it to 38400:

    console=ttyAMA0,38400 kgdboc=ttyAMA0,38400

Start and enable the `getty@ttyAMA0` systemd service on the Pi.

Creating the proper service link:

    # ln -s /usr/lib/systemd/system/serial-getty@.service /etc/systemd/system/getty.target.wants/serial-getty@ttyAMA0.service

From a PC, connect:

    # screen /dev/ttyUSB0 38400

## Raspberry Pi camera module

The commands for the camera module are included as part of the raspberrypi-firmware package - which is installed by default.

    $ /opt/vc/bin/raspistill
    $ /opt/vc/bin/raspivid

Append to `/boot/config.txt`:

    gpu_mem=128
    start_file=start_x.elf
    fixup_file=fixup_x.dat

Optionally

    disable_camera_led=1

The following is a common error:

    mmal: mmal_vc_component_enable: failed to enable component: ENOSPC
    mmal: camera component couldn't be enabled
    mmal: main: Failed to create camera component
    mmal: Failed to run camera app. Please check for firmware updates

which can be corrected by setting these values in `/boot/config.txt`:

    cma_lwm=
    cma_hwm=
    cma_offline_start=

Another common error:

    mmal: mmal_vc_component_create: failed to create component 'vc.ril.camera' (1:ENOMEM)
    mmal: mmal_component_create_core: could not create component 'vc.ril.camera' (1)
    mmal: Failed to create camera component
    mmal: main: Failed to create camera component
    mmal: Only 64M of gpu_mem is configured. Try running "sudo raspi-config" and ensure that "memory_split" has a value of 128 or greater

can be corrected by adding the following line:

    /etc/modprobe.d/blacklist.conf

    blacklist i2c_bcm2708

In order to use standard applications (those that look for `/dev/video0`) the V4L2 driver must be loaded. This can be done automatically at boot by creating an autoload file such as the following.

    /etc/modules-load.d/rpi-camera.conf

    bcm2835-v4l2

The V4L2 driver by default only allows video recording up to 1280x720, else it glues together consecutive still screens resulting in videos of 4 fps or lower. Adding the following options removes this limitation.

    /etc/modprobe.d/rpi-camera.conf

    options bcm2835-v4l2 max_video_width=3240 max_video_height=2464

## Hardware random number generator

Arch Linux ARM for the Raspberry Pi had the `bcm2708-rng` module set to load at boot (see this); starting with kernel 4.4.7 the `bcm2835_rng` module replaces the former on Raspberry Pi 2 and Raspberry Pi 3 units.

Install the rng-tools and tell the Hardware RNG Entropy Gatherer Daemon (rngd) where to find the hardware random number generator.

This can be done by editing `/etc/conf.d/rngd`:

    RNGD_OPTS="-o /dev/random -r /dev/hwrng"

and enabling and starting the rngd service.

If haveged is running, it should be stopped and disabled, as it might compete with rngd and is only preferred when there is no hardware random number generator available.

Once completed, this change ensures that data from the hardware random number generator is fed into the kernel's entropy pool at `/dev/random`. To check the available entropy, run:

    # cat /proc/sys/kernel/random/entropy_avail

The number it reports should be around 3000, whereas before setting up rngd it would have been closer to 1000.

## I/O pins

### GPIO

To be able to use the GPIO pins from Python, use the RPi.GPIO library. Install the python-raspberry-gpioAUR package.

### SPI

To enable the `/dev/spidev*` devices, uncomment the following line:

    /boot/config.txt

    device_tree_param=spi=on

### I2C

Install i2c-tools and lm_sensors packages.

Configure the bootloader to enable the i2c hardware by appending `/boot/config.txt`:

     dtparam=i2c_arm=on

Configure the `i2c-dev` and `i2c-bcm2708` (if not blacklisted for the camera) modules to be loaded at boot:

    /etc/modules-load.d/raspberrypi.conf

    i2c-dev
    i2c-bcm2708

Reboot the Raspberry Pi and issue the following command to get the hardware address:

     i2cdetect -y 0

Note: When using the I2C1 port instead of I2C0, one will need to run `i2cdetect -y 1` instead and replace `i2c-0` with `i2c-1` in the following steps.

Now we need to tell Linux to instantiate the device. Change the hardware address to the address found in the previous step with '0x' as prefix (e.g. 0x48) and choose a device name:

     echo <devicename> <hardware address> >/sys/class/i2c-adapter/i2c-0/new_device

Check the dmesg command for a new entry:

     i2c-0: new_device: Instantiated device ds1621 at 0x48

Finally, read the sensor output:

     sensors

## Compiling on the RPi

Compiling can be very slow on a RPi. Distcc can greatly improve compilation times if other nodes are on the network. For users with x86_64 or i686 boxes, Distcc#Arch ARM describes the proper setup for distcc to use these resources.

## QEMU chroot

Sometimes it is easier to work directly on a disk image instead of the real Raspberry Pi. This can be achieved by mounting an SD card containing the RPi root partition and chrooting into it. From the chroot it should be possible to run pacman and install more packages, compile large libraries etc. Since the executables are for the ARM architecture, the translation to x86 needs to be performed by QEMU.

Note that only 64 bit Raspberry Pi models can use `aarch64`, the rest need to use `arm`.

Install binfmt-supportAUR and qemu-user-staticAUR from the AUR.

Enable and start the binfmt-support service:

    # systemctl enable binfmt-support
    # systemctl start binfmt-support

qemu-user-staticAUR is needed to allow the execution of compiled programs from other architectures. This is similar to what is provided by qemu-arch-extra, but the "static" variant is required for chroot. Examples:

    qemu-arm-static path_to_sdcard/usr/bin/ls
    qemu-aarch64-static path_to_sdcard/usr/bin/ls

These two lines execute the `ls` command compiled for 32-bit ARM and 64-bit ARM respectively. Note that this will not work without chrooting, because it will look for libraries not present in the host system.

qemu-user-staticAUR allows automatically prefixing the ARM exectuable with `qemu-arm-static` or `qemu-aarch64-static`. See for example `/var/lib/binfmts/qemu-arm` and the `qemu-user-static` PKGBUILD.

Make sure that the ARM executable support is active:

    # update-binfmts --display qemu-arm
    # update-binfmts --display qemu-aarch64

If it is not active, enable it using update-binfmts:

    # update-binfmts --enable qemu-arm
    # update-binfmts --enable qemu-aarch64

Mount the SD card to `mnt/` (the device name may be different).

    # mkdir mnt
    # mount /dev/mmcblk0p2 mnt

Mount boot partition if needed (again, use the suitable device name):

    # mount /dev/mmcblk0p1 mnt/boot

Copy the QEMU executables, which will handle the translation from ARM, to the SD card root:

    # cp /usr/bin/qemu-arm-static /usr/bin/qemu-aarch64-static mnt/usr/bin

Finally chroot into the SD card root as described in Change root#Using chroot:

    # chroot mnt/ /bin/bash

Alternatively, you can use `arch-chroot` from arch-install-scripts, as it will provide network support:

    # arch-chroot mnt/ /bin/bash

## See also

- Raspberry Pi - Official website
- RPi Config - Excellent source of info relating to under-the-hood tweaks.
- RPi vcgencmd usage - Overview of firmware command vcgencmd.
- Arch Linux ARM on Raspberry PI - A FAQ style site with hints and tips for running Arch Linux on the RPi

Category:

- ARM architecture

Hidden category:

- Pages flagged with Template:Archive