#!/usr/bin/ruby # # NVRAM WakeUp - Code generator for mainboard "database" # # Copyright (c) 2008 Tobias Grimm # # $Id$ # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # require 'yaml' require 'pp' require 'keys' @infowriters = [] @boards = [] @auto_infowriter_number = 0 def add_or_get_infowriter(board) infowriter_name = board['infowriter'] if infowriter_name == 'AUTO' # find info write with matching settings infowriter = @infowriters.find {|iw| board.slice(@biosinfo_keys) == infowriter} if not infowriter @auto_infowriter_number = @auto_infowriter_number + 1 infowriter_name = "infowriter_%.4d" % @auto_infowriter_number end else # find info write with same name infowriter = @infowriters.find {|iw| iw.iw_name == infowriter_name} end if not infowriter infowriter = { 'iw_name' => infowriter_name } infowriter.merge!(board.slice(@biosinfo_keys)) @infowriters << infowriter end return infowriter end def generate_info_writers file = File.new('infowriters.c.inc', 'w') for infowriter in @infowriters if infowriter.iw_name == 'AUTO' puts "ERROR" exit end file.puts file.puts "void #{infowriter.iw_name}(struct biosinfo *b)" file.puts "{" for key_value in @biosinfo_keys if infowriter[key_value] file.puts " b->#{key_value} = #{infowriter[key_value]};" end end file.puts "}" end file.close end def format_string(string) if string != "NULL" return '"' + string.gsub('\\', '\\\\\\') + '"' else return string end end def generate_boards file = File.new('boards.c.inc', 'w') file.puts "static struct mainboard boards[] = {" for board in @boards 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)}}," end file.puts" { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }" file.puts "};" file.close end # # main() # for board_data in YAML.load(File.new(File.dirname(__FILE__)+'/boards.yaml', 'r')) board = { 'infowriter' => add_or_get_infowriter(board_data) } board.merge!(board_data.slice(@dmi_keys)) @boards << board end generate_info_writers generate_boards