Difference between revisions of "Raspberry Pi"

From Embedded Xinu
Jump to navigation Jump to search
(Started rewriting page to take into account actual XinuPi work; added general information section)
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 gives an overview of the port of Embedded Xinu to the Raspberry Pi, or '''XinuPi'''.  XinuPi provides a simple, lightweight operating system for the Raspberry Pi that contains several orders of magnitude fewer lines of code than the Linux-based software stacks that normally run on the device.  Its purpose is to provide an inexpensive, convenient platform for various areas of computer science education at a University level, including operating systems, embedded systems, networking, and programming languages.
  
= Hardware =
+
= General Raspberry Pi information =
  
You will need the device itselfAs 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).
+
This section provides some important details about the Raspberry Pi in the context of those interested in running Embedded Xinu on itReaders unfamiliar with the Raspberry Pi are advised to also see other sources such as the [http://www.raspberrypi.org/ Raspberry Pi foundation's website].
  
== Power Supply ==
+
== Acquiring the hardware ==
  
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]
+
=== Model A vs. Model B ===
  
== Serial Port ==
+
The Raspberry Pi Model A costs $25, whereas the Raspberry Pi Model B costs $35.  Since Embedded Xinu is very lightweight, differences in memory are essentially irrelevant. However, we 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.
  
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).
+
=== Hardware accessories ===
  
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].
+
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, Embedded Xinu has no SD card driver; therefore, when running Embedded Xinu 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.
|[[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).]]
+
* 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 Embedded Xinu.
|[[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.]]
 
|}
 
  
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:
+
Other useful hardware and accessories include the following:
  
<syntaxhighlight lang="text">
+
* Monitor or TV to show graphics output. While important for Linux, this is less important for Embedded Xinu, which is primarily intended to produce text output over a serial connection. However, Embedded Xinu does support a framebuffer console and a turtle graphics application for those interested.
[    0.000000] Initializing cgroup subsys cpuset
+
* USB devices, such as mouse and keyboardNote: as of this writing, Embedded Xinu does not have working mouse and keyboard drivers, so the serial connection remains the only way to send input to XinuPi.
[    0.000000] Initializing cgroup subsys cpu
+
* Case to enclose the Raspberry Pi inThis protects the board and adds aesthetic value; otherwise it has no purpose.
[    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 onTotal 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 platformHowever, 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 so.  Several boot files, which are not distributed with Embedded Xinu, 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 them.  For 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.  <strike>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).</strike> It seems that [https://github.com/gonzoua/u-boot-pi/tree/rpi gonzoua] has added preliminary Raspberry Pi support for Das U-Boot, I have confirmed that it compiles and executes using my cross-compiler, moreover is can get an IP address and ping hosts.  It should also be able to TFTP boot a kernel, but I haven't been able to confirm that yet (as my network configuration is a bit weird).
 
 
 
To compile Das U-Boot, I ran two commands:
 
 
 
<source lang="bash">
 
$ make ARCH=arm CROSS_COMPILER=<cross-compiler location> raspberry_pi_config
 
$ make ARCH=arm CROSS_COMPILER=<cross-compiler location>
 
</source>
 
 
 
Then copy the u-boot.bin file to the SD card as kernel.img, reboot and you should have serial access to U-Boot.  Type `usb start` to bring up the USB subsystem (which includes the Ethernet adapter) and `dhcp` will acquire an IP address/tftp server (it might also attempt to download a boot image).
 
 
 
= 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.  Xinu 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 Xinu 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 Xinu 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 the initial stages of porting Xinu to the Raspberry Pi; 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 Embedded Xinu, 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>
 

Revision as of 20:16, 2 August 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 gives an overview of the port of Embedded Xinu to the Raspberry Pi, or XinuPi. XinuPi provides a simple, lightweight operating system for the Raspberry Pi that contains several orders of magnitude fewer lines of code than the Linux-based software stacks that normally run on the device. Its purpose is to provide an inexpensive, convenient platform for various areas of computer science education at a University level, including operating systems, embedded systems, networking, and programming languages.

General Raspberry Pi information

This section provides some important details about the Raspberry Pi in the context of those interested in running Embedded Xinu 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. Since Embedded Xinu is very lightweight, differences in memory are essentially irrelevant. However, we 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.

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, Embedded Xinu has no SD card driver; therefore, when running Embedded Xinu 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 Embedded Xinu.

Other useful hardware and accessories include the following:

  • Monitor or TV to show graphics output. While important for Linux, this is less important for Embedded Xinu, which is primarily intended to produce text output over a serial connection. However, Embedded Xinu does support a framebuffer console and a turtle graphics application for those interested.
  • USB devices, such as mouse and keyboard. Note: as of this writing, Embedded Xinu does not have working mouse and keyboard drivers, so the serial connection remains the only way to send input to XinuPi.
  • Case to enclose the Raspberry Pi in. This protects the board and adds aesthetic value; otherwise it has no purpose.

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 Embedded Xinu, 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. Xinu 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 Xinu 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 Xinu 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 the initial stages of porting Xinu to the Raspberry Pi; 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 Embedded Xinu, 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.