rust-console / gba

A crate that helps you make GBA games
https://docs.rs/gba
Apache License 2.0
658 stars 50 forks source link

ROM not working after objcopy + gbafix #170

Closed ids1024 closed 2 years ago

ids1024 commented 2 years ago
rustup run nightly cargo build --examples --release
arm-none-eabi-objcopy -O binary target/thumbv4t-none-eabi/release/examples/hello hello.gba
gbafix hello.gba

If I open the hello elf file in mgba, it runs as expected. If I open the .gba file, it errors with "Jumped to invalid address".

These commands should be correct, right? I guess an issue like this would have to be related to the linker script, or asm_runtime.rs?

Lokathor commented 2 years ago

When I do that mGBA crashes with a jump to 0x0800_0298, which if you dump the ELF file is the address of main in a release build.

The logs also show that it was doing a bunch of out of bounds reads to copy the IWRAM data before it crashes by trying to jump out of bounds. And if you set a breakpoint in the debugger (eg: break 0x08000000) you can pause the emulation before the crash and view the loaded rom. the rom data is extremely regular, like things didn't load right.

However, the ELF version of both the debug and release builds of the example work fine in mGBA.

So, I suspect we're doing objcopy wrong somehow? I haven't used the tool in so long I can't remember if there's some other flag to set or something. I'll link this on the GBA discord and hopefully we can get it sorted out soon.

Lokathor commented 2 years ago

This appears to have been fixed on mGBA's side in 0.10.0 when I run the hello example after an objcopy, @ids1024 can you update your own mGBA and confirm?

ids1024 commented 2 years ago

Yep. Not sure exactly what was going on and what change in mGBA fixed it, but it seems to be fine now in 0.10.0. And it seemed to be file size that's the issue in any case, so the solution would be padding with zeros and not any change in the gba crate.