From 62b1eb927e5b2fb7a32a13eb4564457fa3adf3a0 Mon Sep 17 00:00:00 2001 From: Nik Date: Mon, 5 Sep 2022 22:09:23 +0200 Subject: [PATCH] patterns: Added Xilinx bitstream pattern --- README.md | 1 + patterns/xilinx_bit.hexpat | 52 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 patterns/xilinx_bit.hexpat diff --git a/README.md b/README.md index 811e89a..7eb6adf 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ Hex patterns, include patterns and magic files for the use with the ImHex Hex Ed | VHDX | | `patterns/vhdx.hexpat` | Microsoft Hyper-V Virtual Hard Disk format | | NTAG | | `patterns/ntag.hexpat` | NTAG213/NTAG215/NTAG216, NFC Forum Type 2 Tag compliant IC | | Shell Link | `application/x-ms-shortcut` | `patterns/lnk.hexpat` | Windows Shell Link file format | +| Xilinx BIT | | `patterns/xilinx_bit.hexpat` | Xilinx FPGA Bitstreams | ### Scripts diff --git a/patterns/xilinx_bit.hexpat b/patterns/xilinx_bit.hexpat new file mode 100644 index 0000000..7bff09d --- /dev/null +++ b/patterns/xilinx_bit.hexpat @@ -0,0 +1,52 @@ +#include +#include + +struct Flags { + be u16 length; + u8 value[length]; +}; + +struct TLV { + char tag[parent.keySize]; + be u16 length; + char value[length]; +}; + +struct Command { + be u32 value; +} [[static, sealed, format("format_command")]]; + +fn format_command(Command command) { + u32 x = command.value; + + if (x == 0x20000000) return "NOP"; + if (x == 0xAA995566) return "SYNC"; + if (x == 0x000000BB) return "Bus Width Sync"; + if (x == 0x11220044) return "Bus Width Detect"; + if (x == 0x30002001) return "Write to FAR"; + if (x == 0x28006000) return "Write to FDRO"; + if (x == 0x30000001) return "Write to CRC"; + if (x == 0x30018001) return "Write to IDCODE"; + if (x == 0x30004000) return "Write to FDRI"; + if (x == 0x30008001) return "Write to CMD"; + + if ((x & 0xF0000000) == 0x30000000) + return std::format("Write to Register {}", (x & 0x0003E000) >> 13); + + return std::format("0x{:08X}", x); +}; + +struct Commands { + char tag[parent.keySize]; + be u32 length; + Command commands[length / 4]; +}; + +struct Header { + Flags flags; + be u16 keySize; + TLV tlv[4]; + Commands data; +}; + +Header header @ 0x00; \ No newline at end of file