rbf2h.py
1 import sys, getopt 2 3 GPL=0 4 LGPL=0 5 EXTRA=[] 6 opts, args = getopt.getopt(sys.argv[1:], "glc:") 7 for k, v in opts: 8 if k == "-g": 9 GPL = 1 10 elif k == "-l": 11 LGPL = 1 12 elif k == "-c": 13 EXTRA.append("// " + v) 14 else: 15 raise SystemExit, "Unknown argument: %r" % k 16 17 sys.stdout.write("\n".join(EXTRA)) 18 19 print """ 20 // This is a generated file; the "corresponding source code" is the set of 21 // files used by Altera's Quartus software to generate an .rbf-format 22 // fpga firmware file. 23 """ 24 25 if GPL: 26 print """\ 27 // This program is free software; you can redistribute it and/or modify 28 // it under the terms of the GNU General Public License as published by 29 // the Free Software Foundation; either version 2 of the License, or 30 // (at your option) any later version. 31 // 32 // This program is distributed in the hope that it will be useful, 33 // but WITHOUT ANY WARRANTY; without even the implied warranty of 34 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 35 // GNU General Public License for more details. 36 // 37 // You should have received a copy of the GNU General Public License 38 // along with this program; if not, write to the Free Software 39 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 40 """ 41 42 if LGPL: 43 print """\ 44 // This library is free software; you can redistribute it and/or 45 // modify it under the terms of the GNU Lesser General Public 46 // License as published by the Free Software Foundation; either 47 // version 2.1 of the License, or (at your option) any later version. 48 // 49 // This library is distributed in the hope that it will be useful, 50 // but WITHOUT ANY WARRANTY; without even the implied warranty of 51 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 52 // Lesser General Public License for more details. 53 // 54 // You should have received a copy of the GNU Lesser General Public 55 // License along with this library; if not, write to the Free Software 56 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 57 """ 58 59 h = open(args[0]).read(); 60 61 print "static unsigned char firmware[] = {" 62 for i, c in enumerate(h): 63 print "%3d," % ord(c), 64 if i % 16 == 15: print 65 print "};"