bullseye-arrowFirmware Creation

circle-check

Download the Project

Download Ulf's pcileech-fpgaarrow-up-right project, extract it and copy the folder you need for your DMA device to another location.

*I have a Captain DMA v4 35T, I will therefor use the PCIeSquirrel folder


Sometimes Vivado will fail to generate the project files or fail when generating the Bitstream copy the folder to a location that doesn't have any special characters in the folder names and isn't too long, keep it simple.

Example C:/PCIeSquirrel

This is where you'll be working on the firmware

Shadow Configuration Copy

circle-check

Saving the donor device with Telescan:

To copy the configuration space from a real donor device, start Telescanarrow-up-right and go step by step as shown below.

  • Click the Telescan_save_button.png save icon in the top left corner

  • Choose Telescan_Device_tree.png Device/Port Type Tree and look for the device you intend to copy

  • Check the box Telescan_device_list.png

  • Click Telescan_ok.png name it Donor.tlscan and save it to your desktop

example: C:/Users/Simonrak/Desktop/Donor.tlscan


circle-exclamation

To get the IDs needed in Vivado

We need these values to make the DMA show up as our donor device.

  • At the top of the header in your device, we need to write down:

    • Vendor ID

    • Device ID

    • Command

    • Revision ID

    • Class Code

Telescan_header.png (Write these down)


triangle-exclamation

Bar Sizing

Get the BAR sizing from Telescan

The ¹BARs ( Base Address Registers ) has a specified size assigned to them from the donor device, to make our DMA firmware look like the real donor card we will also copy the sizing

  • Click on BAR0 Telescan_bar0.png

  • To the right, we can see Base Address Register 0

  • To get the sizing, we need to fill the bits in the white field with 1 s Telescan_bar0_bits.png (Before) Telescan_bar0_bits_1s.png (After)

  • Right click on the white section in Base Address Register 0:

    • Write

    • Dword at offset 010h

      Telescan_write_dword.png

      (Doing this will deactivate the device, it's normal)

Now we can see the sizing: Telescan_bar0_sizing_done.png (Write this down)

If a bar ends in: 01 = IO 04 = 64-bit 0C = 64-bit, prefetchable

The bar after a 64-bit bar (ending in 04 and 0C) is always FFFFFFFF Example: BAR0: FFFFE004 BAR1: FFFFFFFF

If you want to insert your BAR0 data into pcileech_bar_zero4k.coe, it won't work if you set BAR0 to 01 (IO)


circle-exclamation

circle-check

Max Payload Size Supported

Max Payload Size

This is the last step using Telescan, we need the bitsarrow-up-right value (1s and 0s) for Max_Payload_Size_Supported ,found in our donor devices Device Capabilities Register found in the PCI Express Capability

*¹We need this value to avoid Tiny pcie


  • Look to the left, in the device tree, find your device and open PCI Express Capability PCI_express_cap.png

  • Click on the second line Device Capabilities Register pcie_dev_cap_reg.png

  • On the right side, look for Max_Payload_Size_Supported max_payload_size_bit.png

  • Click on it and write down the value that's written in binary max_payload_bit.png In my case it's 010


triangle-exclamation

Convert the Telescan



Convert the Telescan file to use it with Vivado

Now we will convert our Telescan file donor.tlscan to a format that Vivado can handle, this is done automatically by the script.

  • Open CMD

  • Write cd Desktop cd_desktop.png

  • Write python telescan_to_coe.py donor.tlscan cmd_convert.png

  • If the script ran without any issues, it has now generated a file called output.coe on your desktop

  • Rename the file to pcileech_cfgspace.coe

  • Copy it to into the /ip/ folder in your project folder and replace the current file


circle-info

Note

Open up the file pcileech_cfgspace.coe and make sure it's not empty

Change Values

Recommended tools

Use VS Codearrow-up-right for this part


Changing values before opening Vivado GUI

Now we will change the "code" in the /src/ folder, to make it possible to generate a firmware using the shadow configuration file we copied into the /ip/ folder in the previous step.


Open the file src/pcileech_fifo.sv Change: rw[203] <- 1'b1; to -> 1'b0;


Open src/pcileech_pcie_cfg_a7.sv Change rw[20] <- 0; to 1; rw[21] <- 0; to 1; rw[143:128] <- 16'h0007; to your donor devices command value


circle-check

Batch file

Making a batch file

Make a batch file by creating a new document (.txt) and rename it to Generate.bat Right click it and click on edit, copy the text below into the .bat

The batch (Generate.bat) should be moved to your projects main folder.

When you're done with all the changes in the /src/and /ip/ folders in the previous step, run the batch file to launch Vivado and generate the project.


circle-info

Note

If the batch isn't working, look inside your Vivado folder and change the version 2023.2 to the same as you have in the Vivado folder

The batch launches Vivado and generates the project

Don't run the batch file before all changes are done, the project has to be generated after that part is completed

Don't close the cmd window, it will close Vivado!

Vivado GUI Generating

Vivado Project Generation

After we run the batch, Vivado will start generating the project, this takes a minute or so depending on what PC you have.

Data/Images/Vivado_generate.png Wait for Vivado to complete the building of the project files

Open Re-customize IP

How to find and open the Re-customize IP window

After the project is done generating, we will open the Re-customize IP window and fill out the information we saved from Telescan earlierarrow-up-right IDs & Class Code

To open the Re-customize IP window:

  • Click on > 🔵 pcileech_squirrel_top Vivado_squirrel_top.png

  • Click on > 🔵 i_pcileech_pcie_a7 (The option at the bottom) Vivado_pcie_a7.png

  • Double click 🟧 i_pcie_7x_0 to open the Re-customize IP window Customize_ip.png This will open the Re-customize IP window

Change ID's & Class Code in Re-customize IP

Adding ID's & Class Code in Re-customize IP

Inside Re-customize IP on the top :


Filling in the Class Code

Still inside the IDs tab, look further down to see Class Code

  • Class Code is filled out from up to down/left to right

    • (explanation below)

      Vivado_classcode.png

  • If our Class Code is as below, it will be:

    • Base Class Value -> 01

    • Sub Class Value -> 08

    • Interface Value -> 02

      Telescan_classcode.png

Save Changes in Re-customize IP

Leave Re-customize IP and generate

To close the Re-customize IP window:

  • Click Vivado_ok.png

  • A new window will appear (Generate Output Products)

  • Select Global¹

  • And click Generate² Vivado_generate_global.png

  • Wait for the generation to finish Vivado_generate_ip.png

  • Then click OK Vivado_generate_complete.png

Lock the Core

Locking the core

Now we will lock the core to prevent values from overwriting, it also allows us to make some manual changes not available in the Vivado GUI

  • At the bottom of the screen, click Tcl Console Vivado_TclConsole.png (If you can't see it, click the search box at the top Quick Access and search for Tcl Console)

  • Paste set_property is_managed false [get_files pcie_7x_0.xci] into the Tcl Console and press enter

  • This message will be displayed in the Tcl Console window: Vivado_lockedIP_msg.png (The core is now locked)

  • Click on > pcie_7x_0 : pcie:7x_0 Vivado_pcie_7x_locked_core.png

  • Double click > 🔵 inst: pcie_7x_0_core_top (pcie_7x_0_core_top.v) Vivado_core_top_blue.png

  • This will open up a new window to the right pcie_7x_core_top.v.png

Change Values in core_top.v

The last step

This is the last step before we can generate the firmware, we will use the BAR sizing and Max_Payload_Size_Supported we saved from earlier.

  • Go to line 87 to 92 and fill in the BAR sizings from earlierarrow-up-right

    • Fill in the BARs you have, leave the others as 00000000

      Vivado_bars0_bars5.png

      (Only remove the pink text)

  • Go to line 125 and 126 and change it to 0A

    • EXT_CFG_CAP_PTR = 6'h2A, -> EXT_CFG_CAP_PTR = 6'h0A,

    • EXT_CFG_XP_CAP_PTR = 10'h043, -> EXT_CFG_XP_CAP_PTR = 10'h0A,

      Vivado_ext_cfg.png

      (¹This moves the starting position of the shadow configuration)

  • Go to line 384 and set MPS_FORCE to TRUE

    • Change MPS_FORCE = "FALSE", -> MPS_FORCE = "TRUE",

      Vivado_mps_force_false.png

  • Go to line 1635 and change the the pink 0 to the same as mentioned earlierarrow-up-right Vivado_force_mps0.png (In my case it was 010)


circle-exclamation

Generate the Firmware

Generate the firmware

Now we're finally ready to generate our firmware.

  • To the left in the Vivado GUI PROGRAM AND DEBUG Vivado_Program_and_debug.png

  • We click Generate Bitstream Vivado_Generate_Bitstream.png

  • This will open a window called Launch Runs

    • Depending on your PC, you can change Number of jobs

      Vivado_Launchruns.png

      (I have 32 GB RAM and a Ryzen 5800x , 12 jobs maxes out my RAM)

  • Click Vivado_ok2.png and wait for the firmware to generate

    • A message box will appear after 10-30 minutes, telling us that the build was completed

    • The firmware can be found in: /pcileech_squirrel/pcileech_squirrel.runs/impl_1/

    • Named: pcileech_squirrel_top.bin

example: C:/pcileech_squirrel/pcileech_squirrel.runs/impl_1/pcileech_squirrel_top.bin

Last updated