Top Banner
Rusting up your GreatFET richö butts dominic stupid
47

Rusting up your GreatFET - TROOPERS18 · ‣ Senior Computer Jerk ... haha! it's a golang joke Making it go ... ‣ Incremental compilation, coherent module system

Aug 31, 2018

Download

Documents

vankhue
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Rusting up your GreatFET - TROOPERS18 · ‣ Senior Computer Jerk ... haha! it's a golang joke Making it go ... ‣ Incremental compilation, coherent module system

Rusting up your GreatFET

richö butts dominic stupid

Page 2: Rusting up your GreatFET - TROOPERS18 · ‣ Senior Computer Jerk ... haha! it's a golang joke Making it go ... ‣ Incremental compilation, coherent module system

Who are these jerks‣ dominic stupid

‣ "Extraordinary"

‣ Senior Computer Jerk

‣ Great Scott Gadgets

‣ Ubertooth stuff

‣ Second best hair in this talk

‣ richö butts

‣ slightly less"Extraordinary"‣ Senior Computer Jerk

‣ Stripe

‣ The umlaut is a historical artifact

‣ Got up a bit late to write this slide

Page 3: Rusting up your GreatFET - TROOPERS18 · ‣ Senior Computer Jerk ... haha! it's a golang joke Making it go ... ‣ Incremental compilation, coherent module system

Who are these jerks

Page 4: Rusting up your GreatFET - TROOPERS18 · ‣ Senior Computer Jerk ... haha! it's a golang joke Making it go ... ‣ Incremental compilation, coherent module system

Who are these jerks

Page 5: Rusting up your GreatFET - TROOPERS18 · ‣ Senior Computer Jerk ... haha! it's a golang joke Making it go ... ‣ Incremental compilation, coherent module system

Who are these jerks

Page 6: Rusting up your GreatFET - TROOPERS18 · ‣ Senior Computer Jerk ... haha! it's a golang joke Making it go ... ‣ Incremental compilation, coherent module system

Why do you care‣ Embedded stuff sucks

‣ Lol how do I pointers

‣ Lol how do I buffers

‣ Updates are hard

‣ Operability

‣ Tooling support

‣ Compile times

Presumably you're in this talk

Page 7: Rusting up your GreatFET - TROOPERS18 · ‣ Senior Computer Jerk ... haha! it's a golang joke Making it go ... ‣ Incremental compilation, coherent module system

Why do you care

‣ Credit: Haroon Meer

Page 8: Rusting up your GreatFET - TROOPERS18 · ‣ Senior Computer Jerk ... haha! it's a golang joke Making it go ... ‣ Incremental compilation, coherent module system

We swear we sort of know what we're doingDisclaimer

‣ richö is not a very hardware person

‣ dominic sort of knows how to program computers

Page 9: Rusting up your GreatFET - TROOPERS18 · ‣ Senior Computer Jerk ... haha! it's a golang joke Making it go ... ‣ Incremental compilation, coherent module system

GreatFET‣ Hardware hacking platform

‣ LPC4330 breakout board

‣ Firmware based on HackRF

‣ SPI, JTAG, UART, ADC, DAC, GPIO, USB x2

‣ SGPIO, DMA, Logic Analyser

Page 10: Rusting up your GreatFET - TROOPERS18 · ‣ Senior Computer Jerk ... haha! it's a golang joke Making it go ... ‣ Incremental compilation, coherent module system

Neighborly afGreatFET

Page 11: Rusting up your GreatFET - TROOPERS18 · ‣ Senior Computer Jerk ... haha! it's a golang joke Making it go ... ‣ Incremental compilation, coherent module system

why not _____?‣Micropython:

‣ Concurrency issues

‣ Code size

‣ Still have to write a lot of C

‣ Overheads

‣ Debugging hassles

‣ Incremental C

‣ shares many pain points of C

‣ Template hell

‣ µrubby

Page 12: Rusting up your GreatFET - TROOPERS18 · ‣ Senior Computer Jerk ... haha! it's a golang joke Making it go ... ‣ Incremental compilation, coherent module system

Mozilla research project, out of controlRust

‣Memory safe

‣ Static lifetimes

‣ Coherent package management

‣ C interoperability

‣ Big boy generics

‣ Powerful macro system

‣ Prevents non-exploitable bugs too!

Page 13: Rusting up your GreatFET - TROOPERS18 · ‣ Senior Computer Jerk ... haha! it's a golang joke Making it go ... ‣ Incremental compilation, coherent module system

Mozilla research project, out of controlRust

‣✨lifetimes✨

Page 14: Rusting up your GreatFET - TROOPERS18 · ‣ Senior Computer Jerk ... haha! it's a golang joke Making it go ... ‣ Incremental compilation, coherent module system

Mozilla research project, out of controlRust

‣✨lifetimes✨

Page 15: Rusting up your GreatFET - TROOPERS18 · ‣ Senior Computer Jerk ... haha! it's a golang joke Making it go ... ‣ Incremental compilation, coherent module system

Mozilla research project, out of controlRust

‣✨lifetimes✨

Page 16: Rusting up your GreatFET - TROOPERS18 · ‣ Senior Computer Jerk ... haha! it's a golang joke Making it go ... ‣ Incremental compilation, coherent module system

his ubertooth still has blutack on itLast time richo did hardware

Page 17: Rusting up your GreatFET - TROOPERS18 · ‣ Senior Computer Jerk ... haha! it's a golang joke Making it go ... ‣ Incremental compilation, coherent module system

haha! it's a golang jokeMaking it go

‣ Two main goals:

‣ Be able to write a pure rust firmware for GreatFET

‣ Embed rust code into an existing firmware codebase

Page 18: Rusting up your GreatFET - TROOPERS18 · ‣ Senior Computer Jerk ... haha! it's a golang joke Making it go ... ‣ Incremental compilation, coherent module system

jerks who beat us to the punchPrior art

‣ zinc

‣ hardware abstraction layer for embedded platforms

‣ tock

‣ experimental RTOS

‣ http://www.acrawford.com/2017/03/09/rust-on-the-cortex-m3.html

‣ bare metal rust on cortex m3

Page 19: Rusting up your GreatFET - TROOPERS18 · ‣ Senior Computer Jerk ... haha! it's a golang joke Making it go ... ‣ Incremental compilation, coherent module system

zero to hero‣ Pick a project that seems plausible

‣ Randomly twiddle bits in linker scripts until you're satisfied with the results

‣ ?????

‣ Speak at TROOPERS!

Page 20: Rusting up your GreatFET - TROOPERS18 · ‣ Senior Computer Jerk ... haha! it's a golang joke Making it go ... ‣ Incremental compilation, coherent module system

protip: Forget shit you need, find brianGet you a greatfet

Page 21: Rusting up your GreatFET - TROOPERS18 · ‣ Senior Computer Jerk ... haha! it's a golang joke Making it go ... ‣ Incremental compilation, coherent module system

Look into your GreatFET‣ Black Magic Probe

‣Natively talks gdb

‣ Exactly zero openocd is the right amount

Page 22: Rusting up your GreatFET - TROOPERS18 · ‣ Senior Computer Jerk ... haha! it's a golang joke Making it go ... ‣ Incremental compilation, coherent module system

Blink some LEDsGoal 1

‣ Configure GPIO (poke memory)

‣ Configure the pin (poke memory)

‣ lpc4330 has 8 gpio ports, each with 32 pins

‣ greatfet package has 144 pins

‣ not all can be used for GPIO

‣ Selfishly, it needs power and stuff

‣ Set Direction (poke memory)

‣Write data to pin (poke memory)

Page 23: Rusting up your GreatFET - TROOPERS18 · ‣ Senior Computer Jerk ... haha! it's a golang joke Making it go ... ‣ Incremental compilation, coherent module system

Execute code on a greatfetGoal 0

‣ Futz around with the existing build pipeline for GreatFET to translate an elf object into something that can be written to flash

‣ ... or!

‣ Use black magic probe + gdb's support for writing an elf into memory

Page 24: Rusting up your GreatFET - TROOPERS18 · ‣ Senior Computer Jerk ... haha! it's a golang joke Making it go ... ‣ Incremental compilation, coherent module system

Execute code on a greatfetGoal 0.5

‣On a "normal computer" having a stack, heap, executable mapped into memory, etc is free

‣On embedded, you need to setup your own stack, install interrupt handlers, etc before you get too carried away

‣ zinc::hal::mem_init::init_stack(); ‣ zinc::hal::mem_init::init_data();

Page 25: Rusting up your GreatFET - TROOPERS18 · ‣ Senior Computer Jerk ... haha! it's a golang joke Making it go ... ‣ Incremental compilation, coherent module system

This metaphor has gotten away from me a littleGoal 0.7

Page 26: Rusting up your GreatFET - TROOPERS18 · ‣ Senior Computer Jerk ... haha! it's a golang joke Making it go ... ‣ Incremental compilation, coherent module system

Blink some LEDsGoal 1

‣ Configure GPIO (poke memory)

‣ Configure the pin (poke memory)

‣ lpc4330 has 8 gpio ports, each with 32 pins

‣ greatfet package has 144 pins

‣ not all can be used for GPIO

‣ Selfishly, it needs power and stuff

‣ Set Direction (poke memory)

‣Write data to pin (poke memory)

Page 27: Rusting up your GreatFET - TROOPERS18 · ‣ Senior Computer Jerk ... haha! it's a golang joke Making it go ... ‣ Incremental compilation, coherent module system

unsafety

Page 28: Rusting up your GreatFET - TROOPERS18 · ‣ Senior Computer Jerk ... haha! it's a golang joke Making it go ... ‣ Incremental compilation, coherent module system

The HAL

Page 29: Rusting up your GreatFET - TROOPERS18 · ‣ Senior Computer Jerk ... haha! it's a golang joke Making it go ... ‣ Incremental compilation, coherent module system

Blink some LEDsGoal 1 revisited

‣Write Rust abstraction over GreatFETs GPIO

‣ Expose logical LEDs to userland code!

‣ Great success

‣Once we had a "read to"/"write from" register abstraction, we can build anything

Page 30: Rusting up your GreatFET - TROOPERS18 · ‣ Senior Computer Jerk ... haha! it's a golang joke Making it go ... ‣ Incremental compilation, coherent module system

demo timeDon't get excited, it's blinking LEDs

Page 31: Rusting up your GreatFET - TROOPERS18 · ‣ Senior Computer Jerk ... haha! it's a golang joke Making it go ... ‣ Incremental compilation, coherent module system

demo timeRust on GreatFET

Page 32: Rusting up your GreatFET - TROOPERS18 · ‣ Senior Computer Jerk ... haha! it's a golang joke Making it go ... ‣ Incremental compilation, coherent module system

demo timeRust on GreatFET

Page 33: Rusting up your GreatFET - TROOPERS18 · ‣ Senior Computer Jerk ... haha! it's a golang joke Making it go ... ‣ Incremental compilation, coherent module system

demo timeOur demo probably failed, have an otter

Page 34: Rusting up your GreatFET - TROOPERS18 · ‣ Senior Computer Jerk ... haha! it's a golang joke Making it go ... ‣ Incremental compilation, coherent module system

demo timeRust on GreatFET on GreatFET

Page 35: Rusting up your GreatFET - TROOPERS18 · ‣ Senior Computer Jerk ... haha! it's a golang joke Making it go ... ‣ Incremental compilation, coherent module system

objcopy is bad software‣ 337kb elf -> 257mb bin (WTF objcopy?)

‣ Probably some hilarious underflow.

‣ .... Should have written it in rust

Page 36: Rusting up your GreatFET - TROOPERS18 · ‣ Senior Computer Jerk ... haha! it's a golang joke Making it go ... ‣ Incremental compilation, coherent module system

objcopy is bad software

Page 37: Rusting up your GreatFET - TROOPERS18 · ‣ Senior Computer Jerk ... haha! it's a golang joke Making it go ... ‣ Incremental compilation, coherent module system

objcopy is bad software‣Whatever all those zeros are probably not important

‣ ¯\_(ツ)_/¯

Page 38: Rusting up your GreatFET - TROOPERS18 · ‣ Senior Computer Jerk ... haha! it's a golang joke Making it go ... ‣ Incremental compilation, coherent module system

demo timeRust on GreatFET on GreatFET

Page 39: Rusting up your GreatFET - TROOPERS18 · ‣ Senior Computer Jerk ... haha! it's a golang joke Making it go ... ‣ Incremental compilation, coherent module system

demo time.... yup. Otters.

Page 40: Rusting up your GreatFET - TROOPERS18 · ‣ Senior Computer Jerk ... haha! it's a golang joke Making it go ... ‣ Incremental compilation, coherent module system

demo timeBut not yet

‣ Go to mike and dominic's talk on thursday 4pm

Page 41: Rusting up your GreatFET - TROOPERS18 · ‣ Senior Computer Jerk ... haha! it's a golang joke Making it go ... ‣ Incremental compilation, coherent module system

Where does that leave us?‣ 100% rust code

‣ two interrupt handlers written in inline asm

‣ Still uses linker scripts to describe memory mapped registers to native Rust code

‣ Uses some unfortunate tricks to abstract over unsafe memory access

‣ Cargo works natively!

‣ Want to terminate TLS on your greatfet for some reason?

Page 42: Rusting up your GreatFET - TROOPERS18 · ‣ Senior Computer Jerk ... haha! it's a golang joke Making it go ... ‣ Incremental compilation, coherent module system

Subtitle TextWhy do you care

‣ Embedded stuff sucks

‣ Lol how do I pointers

‣ Lifetimes! Borrow Checker!

‣ Updates are hard

‣ Cargo!

‣ Operability

‣ hella static analysis

‣ Compile times

‣ Incremental compilation, coherent module system

‣ Generalisable code

Page 43: Rusting up your GreatFET - TROOPERS18 · ‣ Senior Computer Jerk ... haha! it's a golang joke Making it go ... ‣ Incremental compilation, coherent module system

Challenges for adoption‣ Unwillingness to rewrite your whole codebase in

Rust

‣ Incremental rewrites now possible

‣ Rust learning curve

‣ Support doesn't magically port existing software

Page 44: Rusting up your GreatFET - TROOPERS18 · ‣ Senior Computer Jerk ... haha! it's a golang joke Making it go ... ‣ Incremental compilation, coherent module system

things don't always go well‣ zinc has some serious tooling problems

‣ rust error messages are great

‣ ... unless the bug is in a compiler plugin

‣ Zinc is made of compiler plugins

‣ richö isn't very good at comprehension

‣ so we might have wasted 20% of the development time on writing randomly across memory mapped registers

Page 45: Rusting up your GreatFET - TROOPERS18 · ‣ Senior Computer Jerk ... haha! it's a golang joke Making it go ... ‣ Incremental compilation, coherent module system

things don't always go well‣ But seriously, do you read this and immediately know

how to interact with GPIO on greatfet?

Page 46: Rusting up your GreatFET - TROOPERS18 · ‣ Senior Computer Jerk ... haha! it's a golang joke Making it go ... ‣ Incremental compilation, coherent module system

Questions?

Page 47: Rusting up your GreatFET - TROOPERS18 · ‣ Senior Computer Jerk ... haha! it's a golang joke Making it go ... ‣ Incremental compilation, coherent module system

Feel free to take picturesResources

‣ github.com/richo/zinc

‣ The zinc fork with support for greatfet

‣ https://github.com/dominicgs/GreatFET-experimental/tree/rust/firmware

‣ GreatFET firmware with support for embedded rust

‣ speakerdeck.com/richo/rust-greatfet

‣ The slides for this talk

‣We're on twitter

‣ @dominicgs @rich0H

‣We'll release a docker image