User:Hirotaka/Rasberry Pi
The Raspberry Pi is an ARM device (BCM2835, ARMv6) with 512 MB RAM (earlier models had 256 MB RAM) and uses an SD(HC) card for storage. This document describes how to install Gentoo on the Raspberry Pi.
Raspberry Piは、ARMデバイス(BCM2835, ARMv6)の一つで 512 MB RAM (初期のモデルは、256 MB RAM)のメモリを備えており、ストレージとしてSD(HC)カードを使用しています。このドキュメントでは、どのように Raspberry Pi に Gentoo をインストールするかを説明いたします。
Preparing the SD card (SDカードの準備)
Partitioning (パーティション分け)
Check that your SD card is compatible: [1]
準備したSDカードに互換性があるかどうかをチェックしましょう: [2]
Create at least two partitions on the card. One FAT32 for the boot partition, and one (with your preferred filesystem) for the root partition:
カードに少なくとも2つのパーティションを作成します。一つは FAT32 でbootパーティションとして、もう一つは(お好みのfilesystemで) rootパーティションとして使用します:
Disk /dev/sdb: 16.6 GB, 16574840832 bytes
255 heads, 63 sectors/track, 2015 cylinders, total 32372736 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x1db42224
Device Boot Start End Blocks Id System
/dev/sdb1 * 2048 835379 416666 c W95 FAT32 (LBA)
/dev/sdb2 835380 31889024 15526822+ 83 Linux
/dev/sdb3 31889025 32372735 241855+ 5 Extended
/dev/sdb5 31889088 32372735 241824 82 Linux swap / Solaris
For optimal compatibility, it is recommended to use 255H/63S geometry: [3]
互換性のことを考えて、 255H/63S ジオメトリを使用することをお薦めします: [4]
SD cards are very different from rotational devices. So it is non-trivial to achieve best I/O-performance, see for example [5] to start understanding the difficulties. Also be aware that there are a lot of contradicting advices regarding partitioning and suitable filesystems for SD cards.
boot
The /boot partition needs the following proprietary firmware files, provided by the Raspberry Pi foundation.
- bootcode.bin
- fixup.dat
- start.elf
If you want to be able to boot the board with the setting gpu_mem=16 in config.txt, you will also need these files:
- fixup_cd.dat
- start_cd.elf
Create a file called cmdline.txt containing the necessary kernel parameters. Example:
root=/dev/mmcblk0p2 rootdelay=2
These are available as
root #
emerge sys-boot/raspberrypi-firmware
Stage 3
Download the appropriate Stage 3:
root #
wget http://distfiles.gentoo.org/releases/arm/autobuilds/current-stage3-armv6j_hardfp/stage3-armv6j_hardfp-YYYYMMDD.tar.bz2
Extract to the root filesystem on the SD card:
root #
tar xpjf stage3-armv6j_hardfp-YYYYMMDD.tar.bz2 -C /mnt/raspberrypiroot/
CFLAGS="-O2 -march=armv6j -mfpu=vfp -mfloat-abi=hard"
CXXFLAGS="${CFLAGS}"
Don't forget to adjust fstab (the SD card is recognized as /dev/mmcblk0) and add to /etc/shadow the root password hash generated by:
root #
openssl passwd -1
Stage 4
If you'd prefer a self-booting Gentoo tarball (Stage 4), it can be downloaded from here. Please note this image is outdated and unmaintained however
NOOBS image. The NOOBS image will be created on a daily basis. I'd be pleased to get feedback...
You can install NOOBS from here: https://github.com/raspberrypi/noobs and untar the NOOBS image from above in the OS folder (/os/Gentoo).
Portage tree
Download the latest portage tree:
Ensure you have enough inode blocks free on the root partition. Portage takes up approximately 154K.
root #
df -ih | egrep 'Mounted|mmc'
Untar portage on the SD card:
root #
tar xjvpf portage-latest.tar.bz2 -C /mnt/raspberrypiroot/usr
Compiling the kernel(カーネルをコンパイルする)
crossdev
Install sys-devel/crossdev:
root #
emerge --ask crossdev
Create a cross toolchain for ARM: (drop -S if you plan to run an unstable system) (make sure you have defined PORTDIR_OVERLAY in your make.conf first):
root #
crossdev -S -v -t armv6j-hardfloat-linux-gnueabi
If you get any errors or portage warnings here, please fix them. It takes a while until the cross toolchain is successfully set up, so go grab a coffee. :-)
Kernel and modules (カーネルとモジュール)
Download kernel sources for Raspberry Pi from github [6]
root #
emerge sys-kernel/raspberrypi-sources
or
root #
git clone --depth 1 git://github.com/raspberrypi/linux.git
then configure, compile and install:
root #
make ARCH=arm bcmrpi_defconfig
root #
make ARCH=arm CROSS_COMPILE=/usr/bin/armv6j-hardfloat-linux-gnueabi- oldconfig
root #
make ARCH=arm CROSS_COMPILE=/usr/bin/armv6j-hardfloat-linux-gnueabi- -j2
root #
make ARCH=arm CROSS_COMPILE=/usr/bin/armv6j-hardfloat-linux-gnueabi- modules_install INSTALL_MOD_PATH=/mnt/raspberrypiroot/
Raspberry Pi A, B, B+ (Not 2 B)
Create a kernel.img file by
root #
emerge sys-boot/raspberrypi-mkimage
root #
imagetool-uncompressed.py arch/arm/boot/Image /mnt/raspberrypiroot/boot/kernel.img
or using the Raspberry Pi mkimage tool from github:
root #
chmod a+x imagetool-uncompressed.py
root #
./imagetool-uncompressed.py arch/arm/boot/Image
root #
cp kernel.img /mnt/raspberrypiroot/boot/
That's it! You should all be set now.
Raspberry Pi 2 B
Just copy arch/arm/boot/zImage to /boot/kernel7.img
root #
cp arch/arm/boot/zImage /mnt/raspberrypiroot/boot/kernel7.img
That's it!
Tips and Tricks (ヒント)
- Storage is rather slow, even with the couple of compatible SDHC class 10 cards. If you want to run emerge on the Raspberry Pi, putting /usr/portage on squashfs will speed up things dramatically.
- There is no hardware RTC on the Raspberry Pi. Use the ntp-client init script to set correct system time on boot. A fallback incremental clock can be archived by swclock (replaces hwclock).
- If you require more RAM for Linux, set the option gpu_mem in config.txt. The smallest amount you can set is 16 MB, default is 64 MB [7]
- More recent, unofficial kernel releases for the Raspberry Pi might be found at Chris Boot's repository: [8]
- Be sure to test the performance - if your numbers don't match up (for instance in the LINPACK benchmark), something is very wrong.
- For instructions on how to build binary packages for the Raspberry Pi on an Android phone see this blog post: [9]
- If you cannot create a working ARM cross-toolchain, a precompiled kernel image is available from the firmware repository. You need to place boot/kernel.img in your boot partition and copy the contents of the modules directory to /lib/modules/ on the SD card.
- Put the root-fs on a NFS-share and put only the kernel image on SD card (PXE boot client).
Troubleshooting (問題が起こった時は)
- Problem: dmesg is full of smsc95xx 1-1.1:1.0: eth0: kevent 2 may have been dropped and/or page allocation failure messages
- Solution: Try to update all firmware files in /boot, especially fixup.dat.
- Solution if the former fails: Add smsc95xx.turbo_mode=N to kernel parameters, or vm.min_free_kbytes = 4096 to /etc/sysctl.conf
- Problem: the follwing error shows up when running the command
root #
crossdev -S -v -t armv6j-hardfloat-linux-gnueabi
(...) configure: error: cannot compute suffix of object files: cannot compile (...)
- Solution: Try the following command instead:
root #
CFLAGS="-O2 -pipe -march=armv6j -mfpu=vfp -mfloat-abi=hard" crossdev --stage3 -S -v -t armv6j-hardfloat-linux-gnueabi
- Solution: Try the following command instead:
See also (参照)
External resources (その他のリソース)
- Gentoo Embedded Handbook with more information about embedded hardware, cross compiling and other related topics.
- Raspberry Pi Hub at eLinux wiki, with more advanced tutorials to get the most out of your Raspberry Pi
Books (書籍)
- Heitz, Ryan. Hello! Raspberry Pi. Manning Publications (2015). pp. 225. ISBN 9781617292453