im-tomu / foboot

Bootloader for Fomu
Apache License 2.0
100 stars 32 forks source link

Booting from RAM #25

Closed mateusz-holenko closed 4 years ago

mateusz-holenko commented 4 years ago

@xobs I was recently working on a support for foboot in Renode. The current master, available on github supports Fomu platform capable of running foboot and booting software uploaded from host using dfu-util. The setup requires exporting virtual fomu device from Renode to the host system using USB/IP and from that moment on you interact with it the same way as with the real board.

During my adventure I tested two scenarios:

As I understood from the sources, in order to direct the image to the RAM memory it must begin with a magic sequence followed by the address where this image should be stored. What makes me wonder is that the whole image, inluding the magic sequence and the address, is written to RAM and then on reboot the CPU starts from it.

It seems to me that the first instruction CPU executes after reboot is the magic sequence. Shouldn't the start address be shifted by 8 to skip the metadata?

xobs commented 4 years ago

@mateusz-holenko The magic sequence must exist within the first 64 bytes. You don't want to place it at the start, since you're right that would cause it to execute the magic sequence as an opcode. It's documented somewhat in https://github.com/im-tomu/foboot/blob/master/doc/BOOT-SEQUENCE.md#ram-boot

Instead, you should place it a few words after the start, similar to how flags are implemented at https://github.com/im-tomu/foboot/blob/c7ee25b3d10dba0c1df67e793c4e2585577e7a39/examples/riscv-blink/src/crt0-vexriscv.S#L13

mateusz-holenko commented 4 years ago

I see. I wasn't precise enough - it's clear from the source code that the magic does not have to be exactly at the beginning of the image. I simply didn't recognize the implications of this fact and the possibility to add a jump instruction before the magic - my bad.

Thanks for the clarification!