Skip to content

Commit

Permalink
Add the baremetal target to the readme
Browse files Browse the repository at this point in the history
  • Loading branch information
alloncm committed May 19, 2023
1 parent 50ef758 commit b97a689
Showing 1 changed file with 72 additions and 9 deletions.
81 changes: 72 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ The main goal of this project is to be able to play Pokemon on my own emulator.

**More will be added if neccessary (and by neccessary I mean if games I want to play will require them)**

## How to use
## Building

### Building
### Desktop

```shell
cargo build --release --features [optional_features]
cargo build --release --package gb --features [optional_features]
```
#### Optional features:
* `sdl` - Link to sdl2 (On by default)
Expand All @@ -32,7 +32,7 @@ On by default

> **Note** to turn off on by default features pass `--no-default-features` when building
### Key bindings:
#### Key bindings:

| Joypad | Keyboard |
| ---------- | ----------- |
Expand All @@ -45,17 +45,38 @@ On by default
| Dpad Left | Left arrow |
| Dpad Right | Right arrow |

### Running
### Raspberry Pi Baremetal (with ili9341 display and gpio buttons)

#### Desktop
1. Install the rust nightly toolchain for `armv7a-none-eabihf`:
```shell
rustup target add armv7a-none-eabihf --toolchain nightly
rustup +nightly component add rust-src
```

Unfurtuantly `armv7a-none-eabihf` is a [tier3](https://doc.rust-lang.org/nightly/rustc/platform-support.html#tier-3) target for the Rust compiler so building for it requires the nightly toolchain - [source](https://stackoverflow.com/questions/67352828/how-to-build-for-tier-3-target-not-included-in-rustup-target-list)

> **Notice** Verify that you install the `armv7a-none-eabihf` target and not the `armv7a-none-eabi` target, as the later doesn't have support for hardware floats.
2. Install Cargo Binutils:
```shell
cargo install cargo-binutils
rustup component add llvm-tools-preview
```

3. Edit the relevant settings in `configuration.rs`
4. Run `build.sh` or `build.bat` which will compile and create an bootable image called `kernel7.img`

## Running

### Desktop
```sh
magenboy [path_to_rom] [other_optional_flags]
```

#### Raspberry Pi
### Raspberry Pi Desktop with peripherals
See - [RealMagenBoy](docs/RealMagenBoy.md)

### Optional flags
#### Optional flags

* `--file-audio` - Saves the audio to a file
* `--full-screen` - Full screen mode
Expand All @@ -66,6 +87,37 @@ Choose a game with the Joypad bindings (Dpad and A to confirm)
* `--mode [mahcine mode]` - Override the auto machine detection for the game (mode can be: `CGB` - Gameboy color | `DMG` - Original Gameboy | `ANY` - default)
* `--shutdown-rpi` - Requires `rpi` feature, shutdown the RPi upon shutdown of the program

### Raspberry Pi Baremetal

Currently only Raspberry Pi 4 is supported using the following instructions:
* Format a sd card and make a single `FAT32` partition called `boot`
* Copy the file `config.txt` to the root dir of the sd card
* Copy the following files from the [Raspberry Pi firmware repo](https://github.com/raspberrypi/firmware/tree/master/boot) onto the SD card:
- [fixup4.dat](https://github.com/raspberrypi/firmware/raw/master/boot/fixup4.dat)
- [start4.elf](https://github.com/raspberrypi/firmware/raw/master/boot/start4.elf)
- [bcm2711-rpi-4-b.dtb](https://github.com/raspberrypi/firmware/raw/master/boot/bcm2711-rpi-4-b.dtb)
* Copy `kernel7.img` onto the SD card
* Connect all the peripherals (ili9341 display and gpio buttons)
* Insert the SD card to the RPI4 and boot it

_**Note**: Should it not work on your RPi4, try renaming `start4.elf` to `start.elf` (without the 4)
on the SD card._

### QEMU

Currently Qemu doesn't support RPI4 in 32 bit mode, so in order to test it I added support for RPI2 mapping.
To change to RPI2 mode build with the `rpi2` feature and not the default `rpi4` feature.

running with qemu:
```shell
qemu-system-arm.exe -M raspi2b -serial null -serial mon:stdio -kernel path_to_elf
```

_**Note** Qemu takes the path to the elf generated by cargo not the image generated by binutils_
the UART output will be written to the console.

I think that not all the peripherals I use are implemented in QEMU so I used this mainly to debug boot and CPU initialization problems

## GameBoy

### Development Status
Expand Down Expand Up @@ -125,4 +177,15 @@ Choose a game with the Joypad bindings (Dpad and A to confirm)
- [Raspberry Pi docs](https://www.raspberrypi.com/documentation/computers/processors.html)
- [juj/fbcp-ili9341 as a refference](https://github.com/juj/fbcp-ili9341)
- [Raspberry Pi DMA programming in C](https://iosoft.blog/2020/05/25/raspberry-pi-dma-programming/)
- [Ili9341 docs](https://cdn-shop.adafruit.com/datasheets/ILI9341.pdf)
- [Ili9341 docs](https://cdn-shop.adafruit.com/datasheets/ILI9341.pdf)
#### BareMetal RaspberryPi
- [Bare-metal Boot Code for ARMv8-A](http://classweb.ece.umd.edu/enee447.S2021/baremetal_boot_code_for_ARMv8_A_processors.pdf)
- [Low performance Baremetal code Blog post](https://forums.raspberrypi.com/viewtopic.php?t=219212)
- [Raspberry-Pi-Multicode examples by LdB-ECM](https://github.com/LdB-ECM/Raspberry-Pi)
- [RaspberryPi official Linux fork](https://github.com/raspberrypi/linux)
- ARM official Docs
- [ARM Cortex-A72 manual](https://developer.arm.com/documentation/100095/0003)
- [ARMv7-A Architecture Reference Manual](https://developer.arm.com/documentation/ddi0406/cb/?lang=en)
- [ARMv8-A Architecture Reference Manual](https://developer.arm.com/documentation/ddi0487/ia/?lang=en)
- [ARMv8-A Registers](https://developer.arm.com/documentation/ddi0595/2021-12/AArch32-Registers/CCSIDR--Current-Cache-Size-ID-Register?lang=en)
- [ARMv7-A programmer Guide](https://developer.arm.com/documentation/den0013/latest/)

0 comments on commit b97a689

Please sign in to comment.