Cross Compilation for the Raspberry Pi


Computing Machinery II Tutorial:
Week of March 11th, 2019
Review
- we played with general purpose linux OS
- viable squirrel game strategy: do nothing
- Pi is general purpose computer hardware
- it has USB, MicroUSB, and HDMI connections for IO
- we saw the process of putting programs on an SD card
- firmware files that sets up the Pi's GPU and CPU, every time it boots (refer to lecture).
-
"Bare-metal" program (kernel8.img) that shows a Homer Simpson image.
- The Pi ran that program when you have the SD card in and you turn it on (plugged in the micro-usb power).
Recall:
- Lab computer (host) has an Intel CPU (x86 64-bit)
- Pi has an ARMv8 CPU (AArch64)
- We typically compile a high level program down to machine code for the type of CPU that we're writing the code on (usually Intel).
-
What if we want to distribute a compiled program to use on computers with a different type of CPU than the one we're writing the program on?
- We use a cross-compiler to generate machine code for other specific CPU architectures
- That kernel8.img file we put on our SD cards was a bare-metal program that displayed Homer Simpson to the screen.. that was machine code specifically for an ARM CPU!
Today:
- We're going to get familiar with our process of cross compilation for the Pi.
- Furthermore we'll compile a program that communicates with the host computer through the Pi's mini UART pins.

Pi Host
- Pi's has GPIO pins that serve as a communication interface just like USB and HDMI.
- We have a Breakout Board to group those pins so that we can easily attach USB to Serial Cable on the mini UART pins and SNES controller on some other general purpose IO pins.
- Our host machines have the minicom program installed which works with the USB to Serial Cable to open up a communication session between our host machine and our Pi.
mini UART
Pi Host
- We can write programs for the Pi that use the UART pins
- Example code on D2L for transferring ASCII characters over those wires via the mini UART pins.
mini UART
Makefile
- To save keystrokes in the cross compilation process software developers use Makefiles. See our Makefile.
- All the cross compilation details are hidden in here.
QEMU
- The importance of testing while developing non trivial programs cannot be understated.
- To test our cross compiled Pi program directly on our host computer we can use the software called QEMU.
- This is called emulation
- It's not a perfect simulation but it's useful
- To test our cross compiled Pi program directly on our host computer we can use the software called QEMU.
- Run example code in QEMU
Use the Pi
with a minicom session now
Change the Pi program
so that you're sure I'm not lying about what's happening
Summary of Today
- Pi's has ____(4) pins that serve as a communication interface just like USB and HDMI. Our host machines have the minicom program and we have a USB to Serial cable to directly interface our host machine with our Pi.
- We can write programs for the Pi that send and receive information via the Mini UART ___(4) to a minicom session.
- Cross Compilation
- Why Makefiles?
- Two examples of why you would want to cross-compile and use QEMU?
Next time:
Programming LED lights on breadboards.
Pi_1
By pathomas
Pi_1
- 395