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

bitread.py: fully parse type 1 and config packet length #53

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cfib
Copy link

@cfib cfib commented Sep 27, 2024

Setting a USR_ACCESS value that starts with the same bit pattern as a type-2 packet (0b010[...]) causes bitread.py to generate an incorrect .bits file and thus incorrect fault analysis data.

The reason for this is that the check for the type-2 configuration packet is incorrectly triggered by this user-defined number.

To address this issue and tries to prevent incorrect type-2 packets from being parsed, this PR:

  • fully parses and skips type-1 packets,
  • checks if a type-1 FDRI write of length 0 immediately precedes the type-2 packet
  • tracks the number of frames parsed from the type-2 packet in parse_config_packet() and checks if this matches the length of the type-2 packet supplied in the bitstream.

To reproduce using the original bitread.py, generate multiple variants of bitstreams of the bfat_demo_1 design using Vivado:

open_checkpoint demo_1.dcp
write_bitstream demo_1.mwe.original.bit
set_property BITSTREAM.CONFIG.USR_ACCESS 0x00000000 [current_design]
write_bitstream demo_1.mwe.edited.00000000.bit
set_property BITSTREAM.CONFIG.USR_ACCESS 0x40000000 [current_design]
write_bitstream demo_1.mwe.edited.40000000.bit

Now, running the original bitread.py

python3 bitread.py demo_1.mwe.original.bit
python3 bitread.py demo_1.mwe.edited.00000000.bit
python3 bitread.py demo_1.mwe.edited.40000000.bit

gives the following .bits files:

$ ls -l *.bits
-rw-rw-r-- 1 user user 57310500 Sep 27 13:59 demo_1.mwe.edited.00000000.bits
-rw-rw-r-- 1 user user 58114060 Sep 27 13:59 demo_1.mwe.edited.40000000.bits
-rw-rw-r-- 1 user user 57310500 Sep 27 13:59 demo_1.mwe.original.bits

$ head -3 *.bits
==> demo_1.mwe.edited.00000000.bits <==
bit_0000009b_050_21
bit_00000e00_000_11
bit_00000e00_000_17

==> demo_1.mwe.edited.40000000.bits <==
bit_00000000_000_00
bit_00000000_000_13
bit_00000000_000_14

==> demo_1.mwe.original.bits <==
bit_0000009b_050_21
bit_00000e00_000_11
bit_00000e00_000_17

$ sha1sum *.bits
6218857cb299ffe3e90e15c650f5b6a8e7e68d8d  demo_1.mwe.edited.00000000.bits
3957d261789e01d9c7b1c4b226b804903c68a4b6  demo_1.mwe.edited.40000000.bits
6218857cb299ffe3e90e15c650f5b6a8e7e68d8d  demo_1.mwe.original.bits

Running the version of bitread.py from this PR gives:

$ ls -l *.bits
-rw-rw-r-- 1 user user 57310500 Sep 27 14:09 demo_1.mwe.edited.00000000.bits
-rw-rw-r-- 1 user user 57310500 Sep 27 14:09 demo_1.mwe.edited.40000000.bits
-rw-rw-r-- 1 user user 57310500 Sep 27 14:09 demo_1.mwe.original.bits

$ head -3 *.bits
==> demo_1.mwe.edited.00000000.bits <==
bit_0000009b_050_21
bit_00000e00_000_11
bit_00000e00_000_17

==> demo_1.mwe.edited.40000000.bits <==
bit_0000009b_050_21
bit_00000e00_000_11
bit_00000e00_000_17

==> demo_1.mwe.original.bits <==
bit_0000009b_050_21
bit_00000e00_000_11
bit_00000e00_000_17

$ sha1sum *.bits
6218857cb299ffe3e90e15c650f5b6a8e7e68d8d  demo_1.mwe.edited.00000000.bits
6218857cb299ffe3e90e15c650f5b6a8e7e68d8d  demo_1.mwe.edited.40000000.bits
6218857cb299ffe3e90e15c650f5b6a8e7e68d8d  demo_1.mwe.original.bits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant