rp-rs / rp2040-boot2

Second stage bootloader for the RP2040, suitable for use with a Rust application.
75 stars 17 forks source link

Incomplete documentation for BOOT_LOADER_RAM_MEMCPY #14

Open jannic opened 3 years ago

jannic commented 3 years ago

As mentioned in https://github.com/rp-rs/rp2040-boot2/pull/3#issuecomment-922084869, the documentation of BOOT_LOADER_RAM_MEMCPY seems to be incomplete.

thejpster commented 2 years ago

Paging @debuti, who wrote I think wrote the memcpy bootloader.

d0ntrash commented 2 years ago

@jannic, do you have an update on this? Do you have an working copy-to-ram example?

jannic commented 2 years ago

@d0ntrash no, sorry, I don't have a working example ready. I don't really have a use case for this and only tried it out last September out of curiosity. The git branch I used back then probably still is somewhere on my hard drive, so I could dig it out if it would help you. But it wouldn't be documented at all, and I'm not sure if it was correct - all I verified was that I got a LED blinking, after applying some ugly hacks.

d0ntrash commented 2 years ago

@jannic If that wouldn't be a big hassle for you, that would help a lot.

jannic commented 2 years ago

@d0ntrash not at all. You can find the code here: https://github.com/jannic/rp2040-project-template/tree/run-from-ram

sszilvasi commented 2 years ago

@d0ntrash Have you had any luck with getting this to work?

d0ntrash commented 2 years ago

@sszilvasi I am not sure yet. I tried a few things but was not able to verify yet. I might have another look the next few days.

sszilvasi commented 2 years ago

@d0ntrash and @jannic: Do you know if there has been any rp-rs effort to implement the equivalent of the pico-sdk NO_FLASH option?

sszilvasi commented 2 years ago

For the no-FLASH option, I ended up creating a proof-of-concept RAM-only project template by comparing two memory layouts in pico-sdk:

  1. https://github.com/raspberrypi/pico-sdk/blob/master/src/rp2_common/pico_standard_link/memmap_default.ld
  2. https://github.com/raspberrypi/pico-sdk/blob/master/src/rp2_common/pico_standard_link/memmap_no_flash.ld

As the RP Pico used for development does actually have a FLASH, I "disabled" it by flashing picoblank to the boot loader region.

The RAM-only project currently works with elf2uf2-rs but not with probe-run.

jannic commented 2 years ago

Just to avoid confusion: @sszilvasi, if I understand your project correctly, you built something different, not really related to this ticket:

The BOOT_LOADER_RAM_MEMCPY is a second stage boot loader meant to be written to flash, which just copies the firmware from flash to RAM before calling it. That boot loader is not well documented, and that's what this ticket is about.

What you made is a firmware which can run on an RP2040 without accessing flash at all - i.e. on powerup, the boot ROM doesn't find a flash image and jumps to the USB boot mode implemented in ROM. Then you can push the firmware via USB and jump directly to the entry point, without a second stage boot loader at all.

Both approaches have their use cases and are perfectly valid, but they are different things and should not be confused.

sszilvasi commented 2 years ago

Correct, the above mentioned RAM-only project was a deviation from the original topic. It is very loosely related in that the firmware gets copied to RAM by some means before execution, but has otherwise little to do with the BOOT_LOADER_RAM_MEMCPY second stage boot loader implementation or its documentation.

elfmimi commented 2 years ago

Thanks @jannic , your run-from-ram example helped much. though it didn't work as-is.

First, .vector_table has to be copied to RAM as well.

and there were some alignment related problems.

Finally, to convince elf2uf2 or elf2uf2-rs that your binary is meant to be placed into flash memory, you need to change entry point of the binary. That is , to change

ENTRY(Reset);

to

ENTRY(BOOT2_FIRMWARE);

Here is a complete working example. https://github.com/elfmimi/rust-dap/tree/ram-lto-asm-unsafe/boards/rp2040_ram

debuti commented 2 years ago

Hello

Sorry to be away, you can see how it is used in this project: https://github.com/debuti/keso

BR

AkiyukiOkayasu commented 1 year ago

Is there any further information on this?

The @jannic and @elfmimi samples are great, but the cortex-m-rt version is also up and I am having trouble getting it to work in my environment.
Yes, I'm not familiar with linker scripts...