Debian Codegraph @

boards/create-boards

raw
1 #!/usr/bin/ruby
2
3 #
4 # NVRAM WakeUp - Code generator for mainboard "database"
5 #
6 # Copyright (c) 2008 Tobias Grimm
7 #
8 # $Id$
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License along
20 # with this program; if not, write to the Free Software Foundation, Inc.,
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #
23
24 require 'yaml'
25 require 'pp'
26 require 'keys'
27
28 @infowriters = []
29 @boards = []
30 @auto_infowriter_number = 0
31
32 def add_or_get_infowriter(board)
33 infowriter_name = board['infowriter']
34 if infowriter_name == 'AUTO'
35 # find info write with matching settings
36 infowriter = @infowriters.find {|iw| board.slice(@biosinfo_keys) == infowriter}
37 if not infowriter
38 @auto_infowriter_number = @auto_infowriter_number + 1
39 infowriter_name = "infowriter_%.4d" % @auto_infowriter_number
40 end
41 else
42 # find info write with same name
43 infowriter = @infowriters.find {|iw| iw.iw_name == infowriter_name}
44 end
45
46 if not infowriter
47 infowriter = { 'iw_name' => infowriter_name }
48 infowriter.merge!(board.slice(@biosinfo_keys))
49 @infowriters << infowriter
50 end
51
52 return infowriter
53 end
54
55 def generate_info_writers
56 file = File.new('infowriters.c.inc', 'w')
57 for infowriter in @infowriters
58 if infowriter.iw_name == 'AUTO'
59 puts "ERROR"
60 exit
61 end
62 file.puts
63 file.puts "void #{infowriter.iw_name}(struct biosinfo *b)"
64 file.puts "{"
65 for key_value in @biosinfo_keys
66 if infowriter[key_value]
67 file.puts " b->#{key_value} = #{infowriter[key_value]};"
68 end
69 end
70 file.puts "}"
71 end
72 file.close
73 end
74
75 def format_string(string)
76 if string != "NULL"
77 return '"' + string.gsub('\\', '\\\\\\') + '"'
78 else
79 return string
80 end
81 end
82
83 def generate_boards
84 file = File.new('boards.c.inc', 'w')
85 file.puts "static struct mainboard boards[] = {"
86 for board in @boards
87 file.puts " { IW(#{board.infowriter.iw_name}), #{format_string(board.vendor)}, #{format_string(board['type'])}, #{format_string(board.version)}, #{format_string(board.biosvendor)}, #{format_string(board.biosversion)}, #{format_string(board.biosrelease)}},"
88 end
89 file.puts" { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }"
90 file.puts "};"
91 file.close
92 end
93
94 #
95 # main()
96 #
97
98 for board_data in YAML.load(File.new(File.dirname(__FILE__)+'/boards.yaml', 'r'))
99 board = { 'infowriter' => add_or_get_infowriter(board_data) }
100 board.merge!(board_data.slice(@dmi_keys))
101 @boards << board
102 end
103
104 generate_info_writers
105 generate_boards