gpdaniels / spike-prime

Experiments with the LEGO Mindstorms (51515) and SPIKE Prime (45678)
MIT License
282 stars 39 forks source link

Firmware dump #1

Closed GianCann closed 3 years ago

GianCann commented 4 years ago

Hi @gpdaniels , Can you explain to me how to dump the Spike Prime Hub firmware?

gpdaniels commented 4 years ago

Sure.

To get a specific byte or bytes of the firmware:

  1. I connected the Spike Prime Hub over a USB connection to my laptop.
  2. Using a serial terminal you can access the REPL interface of the micropython firmware running on the hub.
  3. Using the REPL interface if you run the following commands then it will print out a 32 bytes of the firmware.
    import firmware
    firmware.flash_read(BYTE_NUMBER)

To dump the whole firmware I wrote a short program in C++ that performs the above sequence over and over again and saved the output. It would also possible to use python for this which at some point I'll get around to doing and add to this repo.

GianCann commented 4 years ago

Ok, but BYTE_NUMBER is not defined. Which is the corrispondent value? 32? or 0?

gpdaniels commented 4 years ago

It's the first byte you want to read. So to get the first byte of the firmware (and the next 31 bytes), you'd call.

firmware.flash_read(0)

Then to get the next 32 bytes you'd do.

firmware.flash_read(32)

Continuing in 32 byte chunks until the function returns false.

byte = 0
while True:
    if (firmware.flash_read(byte) == false):
        break;
    byte += 32
gpdaniels commented 3 years ago

I've added new instructions to the readme that explain how to use the DFU mode to dump the firmware, which is probably easier than this method.