pcb-rnd knowledge pool

 

Makefile for batch mode import

make_import by Tibor 'Igor2' Palinkas on 2018-08-13

Tags: howto, import, schematics, batch, make, makefile

node source

 

 

Abstract: How to emulate gsch2pcb-rnd with a batch-mode action script using the pcb-rnd executable, and how to hook this all up in a Makefile. Many pcb-rnd users use Makefiles to automate annotation between tools. A common path is generating a netlist from various sources (e.g. schematics) and importing the changes to an existing board. This can be done using gsch2pcb-rnd, but that tool supports only one flow, importing from gschem, using gnetlist. This article presents an example on how to implement a generic setup that can import from any source.

  This method assumes the same setup as gsch2pcb-rnd does:

The goal is to get pcb-rnd to import the extended netlist (nets, footprints, values, other attributes; a.k.a "import schematics") using any supported import format. This can be done by following three steps:

  1. load the board
  2. import the schematics and update the board (remove excess subcircuits, place missing subcircuits, update the input netlist, etc.)
  3. save the new version of the board

This can be automated by an action script that does these three steps. Since at the end this is all ran from a shell, step 1 can be done even without an action script: telling pcb-rnd which file to load using command line arguments. Thus the action script will consist of two commands:


echo 'LoadTedaxFrom(netlist, netlist.tdx); SaveTo(Layout)' | pcb-rnd --gui batch board.lht

The first action assumes the netlist is already generated in the tEDAx format and loads it from file netlist.tdx; by the time pcb-rnd reads this action on its standard input, it has already loaded PCB from board.lht. After the import, SaveTo(Layout) simply saves back the updated file on the original name, using the original format.

Note: this script assumes board.lht is an existing, valid board file. It can be initially created by copying default4.lht (or any other board file) to board.lht. This is a critical step, as SaveTo() needs a valid board file to be loaded to know the file format to use on save.

Note: the only way to run actions from the shell command line is to feed it in on the standard input. This is easiest to do with the batch HID, but when staretd with --listen, it is also possible with the GUI HIDs.

The next step is to craft a Makefile that automates generating the netlist (which depends on the schematics) and then updating the board file from that netlist:


# config
NETLIST=netlist.tdx
BOARD=board.lht
SCH=foo.sch bar.sch

# default rule
all: $(BOARD)

# rules to create the netlist and update the board file
$(BOARD): $(NETLIST)
	echo 'LoadTedaxFrom(netlist, "$(NETLIST)"); SaveTo(Layout)' | pcb-rnd -c rc/silently_create_on_load=1 --gui batch "$(BOARD)"

$(NETLIST): $(SCH)
	netlister -t tedax $(SCH) -o $(NETLIST)

clean:
	rm -f $(NETLIST)

The netlister line obviously needs to be replaced with a command line, specific to the schematics capture system in use, that produces the netlist. If that system does not support tEDAx, any other format can be used, but the LoadTedaxFrom() action shall be replaced with the action corresponding to the format (e.g. LoadLTSpiceFrom(), LoadTinyCADFrom(), etc).

Note: -c rc/silently_create_on_load=1 will supress the error message about the board file not exists at the first run. This config setting is avaialble since version 2.2.1 (svn rev 29595). With older versions of pcb-rnd please omit this part.