Posts Tagged ‘read fpga ic embeded firmware’

PostHeaderIcon Read FPGA Bitstream: Why There Is No Software Inside

A bitstream is often described as the FPGA’s software. The metaphor is convenient and it misleads in a specific way: it suggests that the bitstream is a program, that it has a structure analogous to instructions, and that recovering the design is a matter of applying the right decompiler.

None of that is true. A bitstream is a configuration of physical resources. It says which lookup table implements which function, which switch connects which wire to which, and which flip-flop is enabled. There is no instruction stream, no execution order, and no variables in the software sense.

What a bitstream actually specifies

Resource What the bits configure
Lookup table A truth table, as a bit mask
Flip-flop Whether the output is registered, and its initial state
Routing multiplexer Which of several inputs reaches an output
Clock network Which clock drives which region
I/O block Drive strength, standard, and direction
Block memory Width, depth, and port configuration
DSP block Mode and pipelining

The third row is the one that makes recovery hard. A routing multiplexer’s configuration is a selection among alternatives, and knowing which alternative was selected tells you the connection but not why. A netlist recovered from routing is a valid graph and a poor explanation.

Why the LUT is not a program

A lookup table with four inputs stores sixteen bits: the output for each combination. Those sixteen bits are a truth table, and any function of four variables can be represented.

Property Consequence
Sixteen bits per four-input LUT The function is arbitrary, not structured
Any function fits The original expression is not recoverable
Cascaded LUTs implement wider functions The decomposition is a synthesis choice
The same function has many LUT decompositions Recovery is not unique

The fourth row is the fundamental obstacle, and it is the same obstacle as in CPLD work but larger. Synthesis chooses a decomposition; many decompositions produce identical behaviour; the bitstream records only the chosen one.

The recoverable ceiling

There is a hierarchy of what can be obtained, and the levels are far apart.

Level Achievable Effort
The bitstream itself Yes, exactly Low
Resource utilisation counts Yes Low
A netlist of LUTs and routes Partly, with vendor-specific knowledge Very high
A gate-level netlist Sometimes, by re-mapping Very high
RTL No Not achievable
Original HDL No Not achievable

The third row deserves a caveat: recovering the routing is possible in principle and requires a detailed model of the device’s configuration frame format, which vendors do not publish. The information exists in reverse-engineering projects for some families and not for others.

The scale problem

Even where the frame format is known, the volume is the obstacle.

Device size LUTs Routing bits Practical recovery
Small Hundreds Thousands Feasible
Medium Tens of thousands Hundreds of thousands Difficult
Large Hundreds of thousands Millions Not practical by hand
Largest Millions Tens of millions Not practical at all

This is the practical answer to most requests. A design in a large device has more routing bits than a person can examine, and the recovered graph would be too large to be useful even if it were correct.

What is actually useful

The techniques that produce value on a real project are not netlist recovery. They are behavioural.

Approach What it yields
Stimulate inputs, capture outputs A truth table for the implemented interface
Capture internal signals with a logic analyser Protocol and timing
Use the vendor’s debug tools if present Internal signal visibility
Compare two bitstreams Which regions changed between builds

The fourth row is underused and often decisive. Two bitstreams from the same project, differing by one feature, differ in a bounded set of frames, and that localisation answers questions that a full recovery cannot.

Bitstream comparison in practice

Comparison Interpretation
Identical Same build, or a rebuild with no functional change
Small frame differences A localised logic change
Large differences with the same function A different synthesis run or a different tool version
Differences only in memory initialisation frames A changed constant table

The fourth row is genuinely informative: block memory contents appear in identifiable frames, and a change there is a change to a table rather than to logic. That is often exactly what a project needs to know.

The one structural thing that does survive

Amid the losses there is one property that comes through intact and is genuinely useful: the partitioning of the design into clock domains. Clock networks are configured explicitly and their routing is identifiable, which means the number of clocks and the regions each one serves can be recovered from the bitstream with modest effort.

Observation Meaning
A clock net spanning most of the fabric A global clock, probably the system clock
Several disjoint clock regions Multiple domains, likely asynchronous
A clock derived from another through a configured buffer A divided or gated domain
Clock regions that never interact A genuine domain boundary, useful for timing analysis

The fourth row is the practical payoff. Knowing where the domain boundaries are tells an engineer where the timing risk is, and that is usually the question behind a request to understand a bitstream: not what the logic does, but why the design is marginal.

Where the container and the copy sit

The bitstream’s home is usually an external flash, and reading FPGA firmware explains why. Copying a bitstream into a blank device is covered in extracting FPGA configuration, which also compares the three physical routes. Where the device combines a processor with fabric, the software half is genuinely decompilable and the split is described in reading SoC FPGA firmware.

Services at this boundary

Work covers bitstream acquisition and validation, utilisation analysis, build-to-build comparison with frame localisation, interface-level behavioural extraction, and documented statements of what could not be recovered. It does not cover producing RTL from a bitstream, and it does not cover full netlist recovery on large devices.

The honest framing is that a bitstream can be copied exactly and understood approximately, and the approximation is at the level of behaviour rather than structure.