Apply patch from Cirilo Bernardo with some minor changes: mainly allows also the solder mask layer and keep ref and value fields on the silk layer.