Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xilinx Zynq: generated bitstreams do not work with (recent?) FPGA Manager #519

Closed
nfbraun opened this issue Nov 1, 2020 · 1 comment · Fixed by #523
Closed

Xilinx Zynq: generated bitstreams do not work with (recent?) FPGA Manager #519

nfbraun opened this issue Nov 1, 2020 · 1 comment · Fixed by #523
Labels
Milestone

Comments

@nfbraun
Copy link
Contributor

nfbraun commented Nov 1, 2020

On Xilinx Zynq, the task of loading bitstreams into the programmable logic part
of the device is typically handled by the Linux kernel, via the FPGA Manager
framework.

The bitstreams that nMigen generates (via Vivado) fail to load through FPGA
Manager, with an error message like this:

fpga_manager fpga0: writing zynq_image.bin to Xilinx Zynq FPGA Manager
fpga_manager fpga0: Invalid bitstream, could not find a sync word. Bitstream must be a byte swapped .bin file
fpga_manager fpga0: Error preparing FPGA for writing

As the error message says, that is due to the fact that FPGA Manager
expects a byte swapped .bin file, but the file produced by Vivados
write_bitstream -bin_file command is not byte swapped. The (obsolete) xdevcfg
interface in ancient Xilinx kernels seems to have detected this (via the sync
word) and corrected it if required, but this feature does not seem to have made
it into FPGA Manager. (See https://lore.kernel.org/patchwork/patch/605909/ for
the discussion.)

There is a tool called fpga-bit-to-bin.py floating around on the Internet
that people use to generate the correct .bin files; however, it can also be
done directly from Vivado.

My suggested fix would be to not generate the .bin file via the -bin_file
option to write_bitstream (in nmigen/vendor/xilinx_7series.py), but instead
issue a separate command to generate it,

write_cfgmem -force -format bin -interface smapx32 -disablebitswap -loadbit "up 0 {{name}}.bit" {{name}}.bin

This would give a .bin file that works with FPGA Manager.

If there are uses that require a non byte swapped .bin file, one could also
generate two different .bin files, but I don't think that is required (the
xdevcfg interface works with both variants).

If this solution is deemed acceptable, I can submit a PR.

@nfbraun nfbraun changed the title Xilinx Zynq: generated bitstreams do not work with (recent?) FPGA manager Xilinx Zynq: generated bitstreams do not work with (recent?) FPGA Manager Nov 2, 2020
@whitequark whitequark added the bug label Nov 2, 2020
@whitequark
Copy link
Member

Your solution seems good to me.

nfbraun added a commit to nfbraun/nmigen that referenced this issue Nov 2, 2020
The Zynq driver in the FPGA Manager framework on Linux expects bitstreams that
are byte swapped with respect to what the Vivado command `write_bitstream
-bin_file` produces. Thus, use the `write_cfgmem` command with appropriate
options to generate the bitstream (.bin file).

Fixes amaranth-lang#519.
nfbraun added a commit to nfbraun/nmigen that referenced this issue Nov 2, 2020
The Zynq driver in the FPGA Manager framework on Linux expects bitstreams that
are byte swapped with respect to what the Vivado command
`write_bitstream -bin_file` produces. Thus, use the `write_cfgmem` command with
appropriate options to generate the bitstream (.bin file).

Fixes amaranth-lang#519.
@whitequark whitequark added this to the 0.3 milestone Nov 3, 2020
whitequark pushed a commit that referenced this issue Nov 3, 2020
The Zynq driver in the FPGA Manager framework on Linux expects bitstreams that
are byte swapped with respect to what the Vivado command
`write_bitstream -bin_file` produces. Thus, use the `write_cfgmem` command with
appropriate options to generate the bitstream (.bin file).

Fixes #519.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

2 participants