Reverse generated PCB GERBER files

Posted by

What Are PCB GERBER Files?

PCB Gerber files are the standard file format used to describe the printed circuit board (PCB) layers and drilling information needed for PCB fabrication. Gerber files contain vector image data that defines copper traces, solder masks, silkscreen legends, drilled holes, and board outlines. Each Gerber file corresponds to one layer of the PCB – for example, the top copper layer, bottom solder mask, or drill file.

A typical PCB design will have multiple Gerber files that together fully describe how to manufacture the bare circuit board:

Gerber File Layer
.GTL Top Copper
.GBL Bottom Copper
.GTO Top Silkscreen
.GBO Bottom Silkscreen
.GTS Top Solder Mask
.GBS Bottom Solder Mask
.GKO Board Outline
.DRL Drill File

The Gerber file format was originally developed by Gerber Systems Corp. in the 1960s for their vector photo plotters used for PCB fabrication. It has since evolved into an open standard and is supported by all major PCB design tools and manufacturers. The official current Gerber format specification is RS-274X maintained by Ucamco.

Why Reverse Engineer Gerber Files?

In some cases, you may need to reverse engineer PCB Gerber files back into schematic and layout design files. Some reasons include:

  • The original PCB design files were lost and only the manufacturing Gerber files remain
  • Analyzing how a third-party PCB was designed without having access to the original EDA files
  • Modifying or repairing an existing PCB when the design source is unavailable
  • Examining a competitor’s product to see how it was constructed
  • Recreating design files in a different PCB EDA package than originally used

Whatever the reason, the Gerber files provide the complete data needed to reconstruct the PCB design, even if it takes some detective work. The reverse engineered design can then be modified and updated Gerber files generated for a new version of the board.

The Gerber File Structure

A Gerber file is a plain text file consisting of a sequence of commands that describe the image in a vector format. The commands define when to move the plotter, turn on or off the light source, set apertures, etc.

There are three main types of Gerber statements:

  • Parameter Commands – Set modes and define apertures, e.g. %FSLAX25Y25%, %IPPOS%
  • Coordinate Data – Move plotter and turn aperture on/off, e.g. X2000Y3000D02*
  • Miscellaneous Commands – Step and repeat, end of file, e.g. %SR%, M02

Parameter commands start with a % and end with a *. Coordinate data uses X,Y for position and D01/D02/D03 for pen down/move/flash. Miscellaneous commands like M02 indicate end of file.

Here’s a simple example of a Gerber file that draws a 1x1mm rectangle:

%FSLAX25Y25*%
%MOMM*%
%ADD10C,1.0000*%
D10*
G01*
X0Y0D02*
Y1000D01*
X1000D01*
Y0D01*
X0D01*
M02*

Breaking this down:
%FSLAX25Y25*% – Set coordinate format to 2.5 integer digits
%MOMM*% – Set units to millimeters
%ADD10C,1.0000*% – Define aperture D10 as a 1mm circle
D10* – Select aperture D10
G01* – Set linear interpolation mode
X0Y0D02* – Move to (0,0)
Y1000D01* – Pen down, draw line to (0,1)
X1000D01* – Draw line to (1,1)
Y0D01* – Draw line to (1,0)
X0D01* – Draw line to (0,0)
M02* – End of file

So this Gerber file will draw a 1x1mm outline when photo plotted. A PCB Gerber file works the same way, just with many more vectors to define the copper traces and planes.

Interpreting Gerber Layers

To reverse engineer a PCB from its Gerber files, you first need to understand what each file represents. By convention, Gerber file extensions indicate their layer:

  • .GTL – Top copper
  • .GBL – Bottom copper
  • .GTO – Top silkscreen
  • .GBO – Bottom silkscreen
  • .GTS – Top soldermask
  • .GBS – Bottom soldermask
  • .GKO – Board outline
  • .DRL – NC drill file

The top and bottom copper layers (.GTL/.GBL) show the actual metal traces that interconnect component pins. The silkscreens (.GTO/.GBO) provide reference designators and labels. The soldermasks (.GTS/.GBS) show areas masked off from solder. The board outline (.GKO) defines the shape of the PCB. And the drill file (.DRL) has the locations and sizes of through holes and vias.

Here’s an example PCB visualized from its Gerber layers:

You can see how the individual Gerber layers combine to fully define the physical PCB. Copper traces on the top and bottom layers are routed between component pads. Drilled holes allow signals to pass between layers. Larger holes are for through-hole component pins. Smaller ones are vias. Silkscreen provides component outlines and labels. Soldermask opens up copper at component pads and leaves the rest masked off.

To reconstruct the schematic, you’ll need to analyze the connectivity between component pins and trace the point-to-point nets across the layers. The drill file locations and silkscreen component outlines provide reference points to map out components and their connections.

Viewing Gerber Layers

To get started reverse engineering a PCB from its manufacturing files, you’ll first need to view the individual Gerber layers. There are several free Gerber viewer applications available:

These let you load the layer files and inspect them visually. You can toggle layers on/off, measure distances, view apertures, check alignments, etc.

For example, here’s our earlier sample PCB loaded into the CircuitPeople online Gerber viewer:

The individual Gerber layers can be toggled in the left panel. Measurement tools are available to check trace widths and clearances. Drills are shown and cross-probing between layers indicates vias and through holes.

Being able to clearly visualize the PCB layer data is the first step to understanding how the board is constructed and extracting a schematic from it. Inspecting the Gerber layers reveals components, traces, and connectivity.

Gerber to PCB Editor

While dedicated Gerber viewers are useful for inspection, to properly reverse engineer a PCB you’ll want to get its layers imported into a PCB layout editor. Most PCB design applications can import Gerber files to varying degrees.

The open source KiCad EDA suite has an option under File->Import->Import Graphics that supports importing Gerber files into the PCB editor. You can import each layer one-by-one and assign them to copper, mask, silk, and outline layers in KiCad’s PCB editor.

Here are the steps to import Gerbers in KiCad:

  1. In PCB_New, select File->Import->Graphics
  2. Set Format to “RS274-X Gerber files”
  3. Click Load Layers and select the Gerber files
  4. Assign each one to a KiCad layer like F.Cu, B.Cu, etc.
  5. Adjust import options if needed and click Import All

The result is an editable recreation of the original PCB in KiCad’s PCB editor. From there you can inspect the design, add/modify traces, regenerate Gerbers, etc.

Other PCB design tools have similar Gerber import abilities. For example, to get Gerbers into Altium Designer:

  1. Open a new PCB project
  2. Select File->Import->Gerber
  3. Select the files, assign layers, and set options
  4. Review results in a 3D view and click Next
  5. Choose “Load imported data to current PCB”

The imported result may require some additional cleanup, like redrawing traces or regenerating copper pours. But the bulk of the reconstruction from Gerber to CAD is automated.

Having the PCB in a layout editor is a key step to reverse engineering its schematic. You may need to clean up the imported data and reconstruct planes. But now you can easily examine connectivity, trace nets, define components, and extract a schematic.

Extracting the Schematic

With the PCB Layers reconstructed in a PCB layout tool, the next step is to define components and extract a schematic. This is a manual process that requires visually tracing out nets on the board to determine the schematic connections.

Start by identifying components on the PCB by their silkscreen outlines. Locate their pins and map them to pad locations on the copper layers. Give each component a reference designator.

Then use the layout tool to trace out the copper connections between pins. Vias show connections passing between layers. As you identify point-to-point connections, build up an equivalent schematic by placing matching components and wiring their pins with nets.

Here are some tips for extracting a PCB Schematic:

  • Focus on one section of circuitry at a time, like power input, microcontroller, etc.
  • Begin with prominent SMD components that are easy to identify
  • Locate connected passives by visually tracing out copper traces
  • Extend power and ground nets first which tend to have the most branches
  • Define multi-pin components like ICs, connectors, etc. to organize extracted nets
  • Reconstructed planes and copper pours help identify circuit blocks
  • Double check schematics against PCB frequently to verify connections

Reverse engineering a schematic from a PCB can be a tedious process. The more complex the circuit, the longer it will take. Having a clear goal in mind for what level of detail is needed helps determine where to focus efforts.

FAQ

What if some of the Gerber files are missing?

In some cases you may not have a complete set of Gerber files, like missing silkscreen or drill layers. Copper layers are most important for reverse engineering since they contain the actual netlist. Missing drill data can be worked around by manually locating vias and measuring hole sizes. Silkscreen is very helpful for identifying components but its absence can be made up for with careful PCB Inspection and tracing.

Are there any automated tools to extract a PCB schematic?

Unfortunately, the process of reverse engineering a PCB schematic is still largely a manual visual process. There are some academic research papers on the topic, but no production-ready automated schematic extractors. Manually tracing out nets while simultaneously building the schematic is currently the most effective method.

How precise are measurements taken from Gerber files?

The Gerber file format is a vector image format, so it describes copper features and drill locations/sizes down to sub-mil precision. When imported into a PCB editor, these vectors are translated into the application’s native resolution. So measurements taken from an imported PCB are highly accurate, suitable for reproduction and manufacturing.

Can I generate Gerber files from a reverse engineered PCB?

Yes, once a PCB has been reconstructed in a PCB layout tool by importing Gerber files, you can export a new set of Gerbers that are equivalent to the original. These new Gerbers can be used for PCB fabrication, just like ones generated from a natively designed board. The reverse engineering process is complete when you have a schematic, board layout, and Gerbers suitable for manufacture.

What about Gerber files for PCBs with more than 2 layers?

The process for reverse engineering multi-layer PCBs is largely the same, there are just more Gerber files involved. 4-layer boards will have files like GBL, G1L, G2L, GTL for the top, inner1, inner2, and bottom layers. 6-layer adds G3L and G4L. Follow the same methods for viewing and importing these layer files. The schematic extraction process just requires tracing more vertical interconnects between inner layers.

I hope this article provides a good overview of the process of reverse engineering PCB Gerber files. Let me know if you have any other questions!

Leave a Reply

Your email address will not be published. Required fields are marked *