GithubHelp home page GithubHelp logo

laubed / c3r3s Goto Github PK

View Code? Open in Web Editor NEW

This project forked from stephengroat/c3r3s

0.0 0.0 0.0 520 KB

serial 64-bit bootloader for the raspberry pi 3

License: Other

Makefile 4.14% Rust 55.74% Assembly 39.81% Ruby 0.30%

c3r3s's Introduction

c3r3s

Build Status

c3r3s is a tiny (1KB binary) serial bootloader for loading "bare metal" 64-bit kernels on the Raspberry Pi 3. You can iterate on your own kernel code without constantly moving the SD card back and forth.

It's inspired by raspbootin, with these differences:

  • works on raspberry pi 3 (which changed a lot from the 1 and 2)
  • boots directly into 64-bit mode (ARM64 aka aarch64)
  • can load and execute into any address
  • does a CRC-32 check at the end

How to build

Building the bootloader requires an ARM64 cross-compiler toolchain. These are incredibly fussy to build -- I used the homebrew tap kindly made available by Sergio Benitez here.

You may have to edit the Makefile to indicate where the tools live.

make c3r3s

For your convenience, since the end result is a 1KB binary file, it's included in this repo as boot/kernel8.img.

The command-line tool for uploading a kernel is a rust program called "fling". Make sure you have rust installed.

make fling

How to use

Build an SD card with the basic raspberry pi 3 bootloader (https://github.com/raspberrypi/firmware).

Your config.txt file needs to have these lines in order to turn on the LED and the serial port:

enable_uart=1
dtoverlay=pi3-miniuart-bt
dtoverlay=pi3-act-led

Erase any kernel.img or kernel7.img and add the kernel8.img file from c3r3s.

When the raspi boots, the red power LED should start blinking. If you connect a terminal app at 115200 8N1, it should display a spinner saying "c3r3s".

Now use fling to send a kernel over the serial port:

sudo ./dist/fling /dev/cu.usbserial /path/to/your/kernel

How it works

The raspi bootloader loads kernel8.img from the SD card to $8_0000. c3r3s immediately moves itself down to $7_fc00 to make room for the real kernel, initializes the UART to 115200bps 8N1, and starts spinning a banner and toggling the red LED every half second, waiting for a wakeup.

Once it starts receiving a kernel, it toggles the LED for every block. If the CRC matches at the end, it sends an OK to the serial port, blinks the LED slowly one last time, and jumps into the downloaded kernel. The x0, x1, and x2 registers are preserved, in case there was anything interesting in them from the raspi bootloader.

fling will exit as soon as a kernel is loaded successfully, so you can launch your terminal app immediately afterward. tio is my favorite. c3r3s waits about one second after sending the OK before launching the next kernel, to give your terminal program time to get ready.

sudo fling /dev/cu.usbserial /path/to/your/kernel && sudo tio -b 115200 /dev/cu.usbserial

Protocol

The protocol is meant to be dumb and leave all configuration to the host (fling). It should be easy to write your own flinger if you don't like fling.

  1. c3r3s will send "c3r3s" to the serial port every 500 milliseconds.
  2. host: boot
  3. c3r3s: lstn

c3r3s is now ready to receive a kernel. The kernel must be a multiple of 4 bytes (32-bit word) long.

  1. host: send followed by:

    • starting address (u32 LE)
    • size (u32 LE)
  2. The host now sends blocks. Each block is:

    • host: length (u32 LE)
    • host: data (the number of bytes in length)
    • c3r3s: length of total data received so far (u32 LE)
  3. When the entire kernel is sent, the host sends a final checksum:

    • CRC-32 (u32 LE)

c3r3s will respond with fail if the CRC didn't match, or good if it succeeded.

License

Apache 2 (open-source) license, included in 'LICENSE.txt'.

Credit and blame: Robey Pointer [email protected]

https://github.com/robey/c3r3s

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.