antmicro / zynq-mkbootimage

An open source replacement of the Xilinx bootgen application.
BSD 2-Clause "Simplified" License
97 stars 49 forks source link

Extracting fpga bitstream from boot.bin #9

Closed jameshilliard closed 3 years ago

jameshilliard commented 6 years ago

I have a boot.bin which contains a fsbl, u-boot and fpga bitstream, I'm trying to extract the fpga bitstream .bit file from it so I can rebuild the boot.bin with a new u-boot. Is it be possible to extract the various components from a boot.bin file?

tgorochowik commented 6 years ago

Hi James,

This should be doable, but AFAIK there is no tool to automate this.

You can use the bootgen_utility tool from the Vivado suite (unfortunately no open source equivalent yet) to find the offset at which the bitstream is put in the boot.bin file (and then use e.g. dd to extract it).

Note that not the whole bitstream is embedded in the boot.bin file, only the 'e' or 'data' section is used.

You can then hack this function: https://github.com/antmicro/zynq-mkbootimage/blob/4490a1816f6f6c0bf98b0097dff1eb2f83c21f6a/src/file/bitstream.c#L51

And make it not extract this section and just use the file you extracted from your original boot.bin as a whole.

Maybe implementing a way to do this automatically would be useful, contributions are welcome!

Hope this helps!

tgorochowik commented 3 years ago

Added in #15