rp2040-boot2 icon indicating copy to clipboard operation
rp2040-boot2 copied to clipboard

Incomplete documentation for BOOT_LOADER_RAM_MEMCPY

Open jannic opened this issue 4 years ago • 14 comments

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.

jannic avatar Nov 01 '21 21:11 jannic

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

thejpster avatar Dec 05 '21 16:12 thejpster

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

d0ntrash avatar Mar 03 '22 09:03 d0ntrash

@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.

jannic avatar Mar 03 '22 09:03 jannic

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

d0ntrash avatar Mar 03 '22 09:03 d0ntrash

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

jannic avatar Mar 03 '22 10:03 jannic

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

sszilvasi avatar Mar 09 '22 19:03 sszilvasi

@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.

d0ntrash avatar Mar 09 '22 20:03 d0ntrash

@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 avatar Mar 11 '22 13:03 sszilvasi

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.

sszilvasi avatar Mar 18 '22 13:03 sszilvasi

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.

jannic avatar Mar 18 '22 14:03 jannic

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.

sszilvasi avatar Mar 20 '22 14:03 sszilvasi

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

elfmimi avatar May 05 '22 02:05 elfmimi

Hello

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

BR

debuti avatar May 05 '22 16:05 debuti

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...

AkiyukiOkayasu avatar Sep 08 '23 15:09 AkiyukiOkayasu