Difference between revisions of "Raspberry Pi"

From Embedded Xinu
Jump to navigation Jump to search
(→‎Serial Port: Added details about my serial port setup)
 
(13 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
[[File:RaspberryPi.jpg|200px|right|thumb|A freshly unpacked Raspberry Pi with additional SDHC card.]]
 
[[File:RaspberryPi.jpg|200px|right|thumb|A freshly unpacked Raspberry Pi with additional SDHC card.]]
The [http://www.raspberrypi.org/ Raspberry Pi] (RPi) does exist, but while waiting for it to be delivered here are some notes to make it easier to begin porting Xinu to the platform. (Work in Progress)
+
The '''Raspberry Pi''' is an inexpensive credit-card sized computer designed for educational use.  This page provides information about the Raspberry Pi in the context of those looking to run [[XinuPi]] on it.  Readers unfamiliar with the Raspberry Pi are advised to also see other sources such as the [http://www.raspberrypi.org/ Raspberry Pi foundation's website].
  
= Hardware =
+
== Acquiring the hardware ==
  
You will need the device itself.  As of mid-March 2012, this can be ordered for ~$40 from [http://www.newark.com/ Newark/element14] or [http://www.rs-online.com/ RS Components] and only includes the board itself (no power supply, cables, or case).
+
=== Model A vs. Model B ===
  
== Power Supply ==
+
The Raspberry Pi Model A costs $25, whereas the Raspberry Pi Model B costs $35.  We generally recommend the Model B because it includes an Ethernet port and 2 USB ports, as opposed to the Model A which merely has 1 USB port.  Also, currently the Model B has more memory (512 MiB) than the Model A (256 MiB), but since [[XinuPi]] is very lightweight and only uses a small amount of the available memory, the difference in memory is mostly irrelevant.
  
The RPi uses a fairly standard USB micro-B connector for power (only the power pins are physically present).  It needs 700 mA at 5 V, so most computers or cell phone chargers should work. [http://elinux.org/RPi_Hardware_Basic_Setup#Power_Supply Embedded Linux source]
+
=== Hardware accessories ===
  
== Serial Port ==
+
One way the cost of the Raspberry Pi was kept down was increasing modularity.  A consequence of this is that a Raspberry Pi board by itself is useless until at least two additional components have been added:
  
The shipped RPi board doesn't come with a serial port attached (no surprise there)But it does have an expansion header that includes pin outs for a serial port (and more)The details can be found on the [http://elinux.org/Rpi_Low-level_peripherals Embedded Linux RPi] page. <strike>You will probably just want to solder on the full 2x13 pin header then deal with the outputs later incase you want to take advantage of the other pins.</strike> Turns out the board has the 2x13 header already soldered on (I guess it didn't add too much to the cost of production).
+
* SD card.  To boot, the Raspberry Pi requires an appropriately formatted SD card containing certain boot files as well as the operating system or kernel to run.  Note: as of this writing, [[XinuPi]] has no SD card driver; therefore, when running [[XinuPi]] the SD card is only used for bootingUseful tip:  Since the SD card can easily be removed, it is trivial to have different SD cards and swap them out when neededThis trick can be used to easily use the same Raspberry Pis for different purposes.
 +
* Power source.  The Raspberry Pi requires 700 mA at 5V, delivered either through the microUSB port or through the GPIO pins.  For the microUSB port, most cell phone chargers should work.  For the GPIO pins, a useful trick is that a USB to TTL Serial converter, such as [http://www.adafruit.com/products/954 this one], can double as a power source  as well as a serial connection to the Raspberry Pi over which the console runs. We have primarily used the latter method while developing [[XinuPi]].
  
The computer I used does not have a serial port on it, so I ended up getting a serial to USB converter from [https://www.sparkfun.com/products/718 Sparkfun], along with some [https://www.sparkfun.com/products/8430 jumper wires].
+
Other useful hardware and accessories include the following:
  
{|
+
* Serial cable for text input/output to/from the Raspberry Pi, such as [http://www.adafruit.com/products/954 this one]. This is very important for [[XinuPi]] because this is its primary way to interact with a human.  Furthermore, as noted above, such a serial cable can double as a power source.  However, eventually a keyboard-and-monitor setup will be supported as well, providing an alternative to a serial cable when human interaction with the system is desired.
|[[File:Raspi-before.jpg|thumb|400px|Raspberry Pi before connecting the serial port. The upper left corner is the 2x13 GPIO/serial/SPI header (the pins are 1 on the bottom and 2 on the top).]]
+
* Monitor or TV to display graphics output from the Raspberry Pi. While important for Linux, this is less important for [[XinuPi]], which is primarily intended to produce text output over a serial connection as described above. However, [[XinuPi]] does support a framebuffer console and a turtle graphics application for those interested.
|[[File:Raspi-after.jpg|thumb|400px|Raspberry Pi after connecting the serial port. Connections are to Raspi ground to serial ground, Raspi Tx to serial Rx, Raspi Rx to serial Tx.]]
+
* [[USB]] devices can be plugged in and recognized, but the device driver support for specific devices is extremely limited at this point.  Support for USB keyboards as an input method is in development.
|}
+
* Ethernet cable to take advantage of the networking support.
 +
* Case to enclose the Raspberry Pi in.  This protects the board and adds aesthetic value; otherwise it has no purpose.
  
Once the serial transceiver board is wired up to the Raspberry Pi, connect a host system and use a terminal emulator (I used the [[Downloads|Xinu console tools]] `tty-connect`) with a baud rate of 115,200, 8 data bits, no parity, 1 stop bit.  During the Raspberry Pi boot (of a Fedora kernel at least), you will be able to see kernel log messages emitted to the serial console. There isn't anything too exciting in the boot messages, but on my install the first few lines look like:
+
[[File:Raspberry Pi in case with USB and Ethernet cables.jpg|thumb|Raspberry Pi Model B in a case with USB and Ethernet cables attached.]]
 
+
[[File:RaspberryPi in case with Ethernet cable.jpg|thumb|Another shot of a Raspberry Pi Model B in a case.]]
<syntaxhighlight lang="text">
 
[    0.000000] Initializing cgroup subsys cpuset
 
[    0.000000] Initializing cgroup subsys cpu
 
[    0.000000] Linux version 3.1.9 (mockbuild@cdot-panda-5-4) (gcc version 4.5.1 20101112 (Red Hat 4.5.1-5) (GCC) ) #1 PREEMPT Sat Mar 3 21:58:00 UTC 2012
 
[    0.000000] CPU: ARMv6-compatible processor [410fb767] revision 7 (ARMv7), cr=00c5387d
 
[    0.000000] CPU: VIPT nonaliasing data cache, VIPT nonaliasing instruction cache
 
[   0.000000] Machine: BCM2708
 
[   0.000000] Memory policy: ECC disabled, Data cache writeback
 
[    0.000000] Built 1 zonelists in Zone order, mobility grouping on. Total pages: 48768
 
[    0.000000] Kernel command line: dma.dmachans=0x3c bcm2708_fb.fbwidth=720 bcm2708_fb.fbheight=480 bcm2708.boardrev=0x0
 
bcm2708.serial=0x14be9109 smsc95xx.macaddr=B8:27:EB:BE:91:09 dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200
 
console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait
 
</syntaxhighlight>
 
 
 
== SD Card ==
 
 
 
You will want at least a Class 6 or above SD card (lower class cards have been known to have read failures).  I (Michael) ordered two Kingston 8 GB Class 4 SDHC memory cards from Amazon.  8 GB is probably excessive, but they only cost ~$7 each, and if you intend to have a full Linux install available it might not be a bad idea to go for > 4 GB.
 
 
 
= Software =
 
 
 
Xinu is, of course, the target operating system for the RPi platform.  However, there are some steps to take before we get there.
 
  
 
== Booting ==
 
== Booting ==
  
Sadly the RPi does not come with a standard bootloader.  Instead it simply boots off the SD card (and only the SD card) when power is applied, so a straight from the network boot is not an option.  However, SD cards are low cost so you should be able to install a bootloader on the SD card that enables a network boot.  It may "taint" the environment, but it shouldn't be horrible or worse than a typical boot loader.
+
The Raspberry Pi can only boot from its SD card, not from any external devices, and it requires several files in order to do soSeveral boot files, which are not distributed with [[XinuPi]], must be placed in the root directory of a FAT-formatted partition of the SD card.
 
 
It looks like the grub bootloader should be able to support network booting [http://wiki.linuxmce.org/index.php/GRUB_PXE_network_boot Grub PXE network boot].  This is probably the most viable option, but other options may exist and work better for the RPi.
 
 
 
The boot process seems to be as follows<ref name="rpiboot" />:
 
 
 
* Power applied to the Raspberry Pi
 
* Graphic Processor Unit (GPU) begins executing a stage 1 bootloader found in ROM on the chip
 
* The stage 1 bootloader reads the SD card and loads stage 2 (<tt>/boot/bootcode.bin</tt>) into on-chip cache (L2)
 
* GPU executes stage 2 bootloader which enables SDRAM and reads a stage 3 bootloader (<tt>/boot/loader.bin</tt>) into SDRAM
 
* GPU executes stage 3 bootloader which understands how to read ELF files and reads the GPU firmware bootloader (<tt>/boot/start.elf</tt>)
 
* <tt>/boot/start.elf</tt> reads <tt>/boot/config.txt</tt>, <tt>/boot/cmdline.txt</tt>, and <tt>/boot/kernel.img</tt>
 
* <tt>/boot/kernel.img</tt> is essentially the Linux zImage (i.e. ARM code), it contains some parameters in the first 32k but the rest is zImage proper
 
 
 
The bootcode.bin, loader.bin, and start.elf files are all opaque to ARM programmers because they are GPU code files meaning we cannot change themFor Linux the <tt>kernel.img</tt> file is loaded starting at 0x00000000, which puts the start of Linux code (head.S) at 0x00008000<ref name="rpilinux" />.  This file is built by the <tt>mkimage</tt><ref name="mkimage" /> tool associated with the Raspberry Pi distribution.  It *should not* be needed for non-Linux code because it only attaches some special code that is used for Linux kernel parameter passing so the kernel doesn't need extra modifications<ref name="linux32k" />.  As an example: [http://cgit.haiku-os.org/haiku/tree/src/system/boot/platform/raspberrypi_arm/entry.S HaikuOS] does not use the <tt>mkimage</tt> tool to get their kernel to boot.
 
 
 
As mentioned above, to get a network boot working we should be able to make a new kernel.img file that enables serial port access and network access then copies and jumps to a known offset for execution.  As a starting point [https://github.com/dwelch67/raspberrypi dwelch67] has something like this on github (though it seems to be very specific and not network oriented).
 
 
 
= Command Line Information =
 
  
== <tt>cat /proc/cpuinfo</tt> ==
+
The following binary blobs (created by Broadcom, but freely distributable, at least when using them on Raspberry Pis) must exist:
  
<syntaxhighlight lang="bash">
+
* "bootcode.bin" is a first-stage bootloader.  [[https://github.com/raspberrypi/firmware/raw/master/boot/bootcode.bin Download link]].
Processor : ARMv6-compatible processor rev 7 (v6l)
+
* "loader.bin" is a second-stage bootloader.  Apparently, this file is no longer required.
BogoMIPS : 697.95
+
* "start.elf" is the GPU firmware.[[https://github.com/raspberrypi/firmware/raw/master/boot/start.elf Download link]].
Features : swp half thumb fastmult vfp edsp java tls
 
CPU implementer : 0x41
 
CPU architecture: 7
 
CPU variant : 0x0
 
CPU part : 0xb76
 
CPU revision : 7
 
  
Hardware : BCM2708
+
The following text files are optional:
Revision : 0000
 
Serial : 0000000014xxxxxx
 
</syntaxhighlight>
 
  
== <tt>cat /proc/meminfo</tt> ==
+
* "config.txt" is parsed by the GPU firmware and is used to set various hardware parameters.  [[XinuPi]] runs fine with the default parameters, so "config.txt" need not exist.
 +
* "cmdline.txt" is used to pass a command line to the Linux kernel.  This file need not exist for the [[XinuPi]] kernel, which does not take command line parameters.
  
<syntaxhighlight lang="bash">
+
Finally, the actual kernel:
MemTotal:         186540 kB
 
MemFree:          130592 kB
 
Buffers:            9552 kB
 
Cached:            29360 kB
 
SwapCached:            0 kB
 
Active:            18404 kB
 
Inactive:          29176 kB
 
Active(anon):      9108 kB
 
Inactive(anon):        4 kB
 
Active(file):      9296 kB
 
Inactive(file):    29172 kB
 
Unevictable:          0 kB
 
Mlocked:              0 kB
 
HighTotal:            0 kB
 
HighFree:              0 kB
 
LowTotal:        186540 kB
 
LowFree:          130592 kB
 
SwapTotal:            0 kB
 
SwapFree:              0 kB
 
Dirty:                24 kB
 
Writeback:            0 kB
 
AnonPages:          8680 kB
 
Mapped:            10476 kB
 
Shmem:              448 kB
 
Slab:              5648 kB
 
SReclaimable:      2816 kB
 
SUnreclaim:        2832 kB
 
KernelStack:        568 kB
 
PageTables:          688 kB
 
NFS_Unstable:          0 kB
 
Bounce:                0 kB
 
WritebackTmp:          0 kB
 
CommitLimit:      93268 kB
 
Committed_AS:      94416 kB
 
VmallocTotal:    188416 kB
 
VmallocUsed:        896 kB
 
VmallocChunk:    186708 kB
 
</syntaxhighlight>
 
  
= Platform =
+
* "kernel.img" must exist and is loaded as raw data at physical memory address 0x8000 by the GPU firmware.  The ARM begins execution at the very first instruction in this loaded image.  "kernel.img" can be a [[XinuPi]] kernel (rename "xinu.boot" to "kernel.img"), a Linux kernel, or other bare-metal code such as the "raspbootin" bootloader.  "raspbootin" has been helpful in developing [[XinuPi]]; see [https://github.com/mrvn/raspbootin/blob/master/README.md its documentation] for more information.
  
* [http://www.broadcom.com/products/BCM2835 BCM2835] SoC
+
There are a couple ways you can actually achieve the final result of a properly set up SD card:
** Contains ARM 1176JZF-S processor ([http://infocenter.arm.com/help/topic/com.arm.doc.ddi0301h/DDI0301H_arm1176jzfs_r0p7_trm.pdf technical reference manual]; implements [http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0419c/index.html ARMv6] instruction set, you'll need to register with ARM for the PDF.)
 
** [[File:BCM2835-Peripherals.pdf|Peripheral guide]] should cover making the serial port work
 
* [http://www.smsc.com/index.php?tid=300&pid=135 SMSC LAN9512] USB Hub and 10/100 Ethernet
 
  
= References =
+
* Follow the installation instructions for a Linux distribution supported on the Raspberry Pi, such as Raspbian or Arch Linux ARM.  This will leave the appropriate boot files. To switch to [[XinuPi]], simply replace "kernel.img" on the FAT partition with "xinu.boot". (Perhaps rename "kernel.img" to "linux.img" to save a backup first.)
<references>
+
* Manually partition the SD card and create a FAT filesystem, then copy the boot files to the filesystem. The binary blobs can be downloaded using the links provided above.
  <ref name="rpiboot">http://www.raspberrypi.org/phpBB3/viewtopic.php?t=6685&p=85140</ref>
 
<ref name="rpilinux">https://github.com/raspberrypi/linux/issues/16</ref>
 
<ref name="mkimage">https://github.com/raspberrypi/tools/tree/master/mkimage</ref>
 
  <ref name="linux32k">https://github.com/raspberrypi/tools/issues/2</ref>
 
</references>
 

Latest revision as of 22:37, 11 September 2013

A freshly unpacked Raspberry Pi with additional SDHC card.

The Raspberry Pi is an inexpensive credit-card sized computer designed for educational use. This page provides information about the Raspberry Pi in the context of those looking to run XinuPi on it. Readers unfamiliar with the Raspberry Pi are advised to also see other sources such as the Raspberry Pi foundation's website.

Acquiring the hardware

Model A vs. Model B

The Raspberry Pi Model A costs $25, whereas the Raspberry Pi Model B costs $35. We generally recommend the Model B because it includes an Ethernet port and 2 USB ports, as opposed to the Model A which merely has 1 USB port. Also, currently the Model B has more memory (512 MiB) than the Model A (256 MiB), but since XinuPi is very lightweight and only uses a small amount of the available memory, the difference in memory is mostly irrelevant.

Hardware accessories

One way the cost of the Raspberry Pi was kept down was increasing modularity. A consequence of this is that a Raspberry Pi board by itself is useless until at least two additional components have been added:

  • SD card. To boot, the Raspberry Pi requires an appropriately formatted SD card containing certain boot files as well as the operating system or kernel to run. Note: as of this writing, XinuPi has no SD card driver; therefore, when running XinuPi the SD card is only used for booting. Useful tip: Since the SD card can easily be removed, it is trivial to have different SD cards and swap them out when needed. This trick can be used to easily use the same Raspberry Pis for different purposes.
  • Power source. The Raspberry Pi requires 700 mA at 5V, delivered either through the microUSB port or through the GPIO pins. For the microUSB port, most cell phone chargers should work. For the GPIO pins, a useful trick is that a USB to TTL Serial converter, such as this one, can double as a power source as well as a serial connection to the Raspberry Pi over which the console runs. We have primarily used the latter method while developing XinuPi.

Other useful hardware and accessories include the following:

  • Serial cable for text input/output to/from the Raspberry Pi, such as this one. This is very important for XinuPi because this is its primary way to interact with a human. Furthermore, as noted above, such a serial cable can double as a power source. However, eventually a keyboard-and-monitor setup will be supported as well, providing an alternative to a serial cable when human interaction with the system is desired.
  • Monitor or TV to display graphics output from the Raspberry Pi. While important for Linux, this is less important for XinuPi, which is primarily intended to produce text output over a serial connection as described above. However, XinuPi does support a framebuffer console and a turtle graphics application for those interested.
  • USB devices can be plugged in and recognized, but the device driver support for specific devices is extremely limited at this point. Support for USB keyboards as an input method is in development.
  • Ethernet cable to take advantage of the networking support.
  • Case to enclose the Raspberry Pi in. This protects the board and adds aesthetic value; otherwise it has no purpose.
Error creating thumbnail: Unable to save thumbnail to destination
Raspberry Pi Model B in a case with USB and Ethernet cables attached.
Error creating thumbnail: Unable to save thumbnail to destination
Another shot of a Raspberry Pi Model B in a case.

Booting

The Raspberry Pi can only boot from its SD card, not from any external devices, and it requires several files in order to do so. Several boot files, which are not distributed with XinuPi, must be placed in the root directory of a FAT-formatted partition of the SD card.

The following binary blobs (created by Broadcom, but freely distributable, at least when using them on Raspberry Pis) must exist:

  • "bootcode.bin" is a first-stage bootloader. [Download link].
  • "loader.bin" is a second-stage bootloader. Apparently, this file is no longer required.
  • "start.elf" is the GPU firmware.[Download link].

The following text files are optional:

  • "config.txt" is parsed by the GPU firmware and is used to set various hardware parameters. XinuPi runs fine with the default parameters, so "config.txt" need not exist.
  • "cmdline.txt" is used to pass a command line to the Linux kernel. This file need not exist for the XinuPi kernel, which does not take command line parameters.

Finally, the actual kernel:

  • "kernel.img" must exist and is loaded as raw data at physical memory address 0x8000 by the GPU firmware. The ARM begins execution at the very first instruction in this loaded image. "kernel.img" can be a XinuPi kernel (rename "xinu.boot" to "kernel.img"), a Linux kernel, or other bare-metal code such as the "raspbootin" bootloader. "raspbootin" has been helpful in developing XinuPi; see its documentation for more information.

There are a couple ways you can actually achieve the final result of a properly set up SD card:

  • Follow the installation instructions for a Linux distribution supported on the Raspberry Pi, such as Raspbian or Arch Linux ARM. This will leave the appropriate boot files. To switch to XinuPi, simply replace "kernel.img" on the FAT partition with "xinu.boot". (Perhaps rename "kernel.img" to "linux.img" to save a backup first.)
  • Manually partition the SD card and create a FAT filesystem, then copy the boot files to the filesystem. The binary blobs can be downloaded using the links provided above.