This is a Gradle plugin which aspires to simplify building and deploying Java applications on to bare metal micros, such as Arduino compatibles and the Raspberry Pis. It uses the HaikuVM project to generate a deployable virtual machine embedded with the target application's bytecode. It also couples a serial bootloader and boot image bundlng (in the Raspberry Pi case) to reduce embedded deployment friction.
This project is in active development and more hosts, boards, and documentation are planned for the future. The ./samples projects contain simple Java applications that demonstrate basic hello world LED blinking applications using delays, timers, and interrupts on the the Raspberry Pi Zero. They were tested out cross-compiling on a Mac host.
- Java 1.8 or better
- Max OS/X or Windows 10 with WSL
- ARM cross compiler
- Pi Zero
- USB to TTL Serial Cable like this one from Adafruit
The delayblink Java project will blink the green ACT LED on the Rpi Zero.
- Clone this project.
- Change directory to samples/delayblink.
./gradlew buildPiImage
cd build/firmware/pi
- Transfer the built pi boot image file to an empty micro SD card. Use
sudo dd if=boot.img of=/dev/diskx bs=512
. Usesudo diskutil list
to find your SD card. Usesudo diskutil unmountDisk /dev/diskx
to make the card available for dd writing. - Plug card into Pi. Plug in USB serial adapter to workstation.
- Change directory back to samples/delayblink.
./gradlew deploy
A console window should launch with host bootloader ready to transfer kernel to Rpi.- Connect serial cable pins to Pi.
- Marvel at the blinking active LED on the Pi Zero board using bare metal Java code
See Embedded Java Hello World On Raspberry Pi Zero. For Windows setup considerations, see Embedded Java For Raspberry Pi Zero Setup On Windows 10 Hosts
This plugin is my own original work. My contribution was to add the missing bare-metal bootstrapping for boards like the Raspberry Pi and bundling/streamlining of the build/deploy operations into something familiar to Java developers, like Gradle tasks.
The plugin makes use of several projects and many educational sources:
- HaikuVM
- HaikuVM brought Java to Arduino platforms by taking compiled Java bytecode, the Arduino bootstrap, and the leJOS VM and combining them into a native C application that can be cross-compiled to a target.
- HaikuVM is based on work from leJOS. leJOS is published under the Mozilla Public License 1.0. leJOS was developed for the Lego Mindstorms ™.
- I forked HaikuVM version 1.4.3 and published it here, adding Raspberry Pi bootstrapping and the beginnings of BCM Java wrapper classes.
- The ARM® Architecture Reference Manual, obtainable free with registered account from https://developer.arm.com
- The ARM1176JZF-S Technical Reference Manual
- The Broadcom BCM2835 ARM Peripherals Manual
- The ELinux BCM2835 Datasheet Eratta
- A serial bootloader from which I patched pieces from several forks and published into my own fork here.
- Learnings from Bare metal Raspberry Pi 3 tutorials
- More learnings from Raspberry-Pi Bare Metal Tutorial. I can't give enough kudos. If you want to learn about bare-metal bring-ups, read this.
- A sample build.gradle demonstrating how to build native apps with Gradle.
- A Java library for manipulating FAT file systems. I fixed compatibility problems found in Raspberry Pi first and second stage bootloaders and fixed in this fork. You read more in my blog article Programmatically Building A FAT File System In Java