Code Monkey home page Code Monkey logo

rpi's Introduction

Booting straight into a custom Raspberry Pi/ARM binary with QEMU.

Running the demo:

cd v0   # important
bash doit.sh

Screenshot:

The dots on the last line are a "heartbeat": one dot per second. See start.c.

Custom binary on QEMU

If you want to type the commands instead, here's just the commands (see below for a commented version):

# See 'doit.sh'
sudo apt install gcc-arm-linux-gnueabi qemu-system-arm
mkdir -p boot boot/dev
arm-linux-gnueabi-gcc -static start.c -o boot/command.com
dd if=/dev/zero of=rawfs.img bs=1M count=8
mkfs.ext2 -d boot rawfs.img
qemu-system-arm rawfs.img -kernel ../kernel-qemu-4.4.34-jessie -cpu arm1176 -m 256 -M versatilepb -serial stdio -append "init=command.com root=/dev/sda rootfstype=ext2 ro" -no-reboot

Commented version of doit.sh:

#!/bin/bash

set -e
set -x

# Avoid annoying output from apt if the packages are already
# present if we had just written:
# sudo apt install gcc-arm-linux-gnueabi qemu-system-arm
which qemu-system-arm arm-linux-gnueabi-gcc || { echo "do sudo apt install gcc-arm-linux-gnueabi qemu-system-arm"; exit 1; }

# create a staging dir: see the '-d' option of 'mkfs.ext2' below.
mkdir -p boot boot/dev

# create a static binary that the kernel will start.
arm-linux-gnueabi-gcc -static start.c -o boot/command.com

# create a raw ext2 filesystem image in a file like an old-school
# DOS floppy disk. No partitions. LOL.
dd if=/dev/zero of=rawfs.img bs=1M count=8

# -d copies the the directory into the root of the filesystem after creating it.
mkfs.ext2 -d boot rawfs.img

[[ -n "$DISPLAY" ]] || echo -e "\n\n\n\n**** No DISPLAY set. The next command may fail. Try ssh -X, VNC?\n\n\n\n"

# enjoy! note we used /dev/sda without a numeric partition suffix because this
# is a raw filesystem.
qemu-system-arm rawfs.img -kernel ../kernel-qemu-4.4.34-jessie -cpu arm1176 -m 256 -M versatilepb -serial stdio -append "init=command.com root=/dev/sda rootfstype=ext2 ro" -no-reboot

# PRESS Ctrl-Alt-Q from the window to quit qemu.

QEMU note: I'm using QEMU's generic 'versatilepb' ARM machine because it's sufficient, and I wasn't able to get the emulated Raspberry Pi working. But I was able to boot a downloaded Raspberry Pi image as is on the 'versatilepb' target. Since my goal is run this on real hardware and ideally on multiple boards, using 'versatilepb' here might actually be a good thing.

TODO: Add references.

eof

rpi's People

Watchers

Ranganathan Sankaralingam avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.