Commit 92bd62fa authored by Alessandro Rubini's avatar Alessandro Rubini

fru-generator: several changes, to support user configuration

This addes command line support and environment support to specify the
values to be set in the EEPROM. Removes the dumping function
(tools/fru-dump will soon be there), removes generation of the fake
internal use area and supports the soon-to-be-documented defaults.

It is still missing a lot (i.e., power consumption is still hardwired)
but it can be used for the initial work on eeprom images.

Again, thanks to Manohar Vanga and Matthieu Cattin for libipmi and
this tools.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 943b545f
#! /usr/bin/env python #! /usr/bin/env python
# coding: utf8 #-*-python-*-
# Copyright CERN, 2011 # Copyright CERN, 2011, 2012
# Author: Matthieu Cattin <matthieu.cattin@cern.ch> # Author: Matthieu Cattin <matthieu.cattin@cern.ch>
# Licence: GPL v2 or later. # Modified and broken by Alessandro Rubini, still learning python
# Website: http://www.ohwr.org
# Last modifications: 16/5/2012
# Import system modules # Import system modules
import sys import sys
import getopt
import time import time
import datetime import datetime
import os import os
...@@ -17,24 +16,71 @@ from libipmi.fmc_eeprom import * ...@@ -17,24 +16,71 @@ from libipmi.fmc_eeprom import *
""" """
Tests IPMI formatting library. Creates a FRU binary file to be written into FMC EEPROM
""" """
def main (default_directory='.'): def main (argv0, argv):
# Constants declaration # Defaults
PART_NUMBER = "EDA-02063-V5-0" FRU_VENDOR = "fmc-example"
SERIAL = "HCCFFIA___-CR000003" FRU_NAME = "mezzanine"
EEPROM_BIN_FILENAME = "eeprom_content.out" FRU_SERIAL = "0001"
EEPROM_BIN_FILENAME = os.path.join(default_directory, EEPROM_BIN_FILENAME) FRU_PART = "sample-part"
EEPROM_SIZE = 8192 # in Bytes FRU_OUTPUT = "/dev/stdout"
verbose = 0
#================================================== # Override defaults with environment variables
# Serial number try:
serial = SERIAL FRU_VENDOR = os.environ['FRU_VENDOR']
print "Board's serial number: %s\n" % serial except:
pass
try:
FRU_NAME = os.environ['FRU_NAME']
except:
pass
try:
FRU_SERIAL = os.environ['FRU_SERIAL']
except:
pass
try:
FRU_PART = os.environ['FRU_PART']
except:
pass
try:
FRU_OUTPUT = os.environ['FRU_OUTPUT']
except:
pass
if os.getenv("FRU_VERBOSE") is not None:
verbose = 1
# Override defaults with command line arguments
try:
opts, args = getopt.getopt(argv,"v:n:s:p:o:",["--help"])
except getopt.GetoptError:
print "fru-generator: wrong arguments"
sys.exit(2)
for opt, arg in opts:
if opt == "--help":
print "fru-generator: no help yet"
sys.exit(1)
if opt == '-v':
FRU_VENDOR = arg
if opt == '-n':
FRU_NAME = arg
if opt == '-s':
FRU_SERIAL = arg
if opt == '-p':
FRU_PART = arg
if opt == '-o':
FRU_OUTPUT = arg
if verbose:
print "VENDOR = " + FRU_VENDOR
print "NAME = " + FRU_NAME
print "SERIAL = " + FRU_SERIAL
print "PART = " + FRU_PART
print "OUTPUT = " + FRU_OUTPUT
#================================================== #==================================================
# Calculate number of minutes since 0:00 1/1/96 # Calculate number of minutes since 0:00 1/1/96
...@@ -43,19 +89,14 @@ def main (default_directory='.'): ...@@ -43,19 +89,14 @@ def main (default_directory='.'):
diff_date = now_date - ref_date diff_date = now_date - ref_date
total_seconds = diff_date.days * 86400 + diff_date.seconds total_seconds = diff_date.days * 86400 + diff_date.seconds
current_date = int(total_seconds//60) current_date = int(total_seconds//60)
print "Current date/time: %d minutes (since 0:00 1/1/96)\n" % current_date
# Manufacturiing date = current date
print "Manufacturing date : %d 0x%06X" % (current_date, current_date)
mfg_date = current_date mfg_date = current_date
#================================================== #==================================================
# Create Board Info Area # Create Board Info Area
# FRU field is used to store the date of generation of the eeprom content # FRU field is used to store the date of generation of the eeprom content
# This could be used later to determine if the content has to be udated (bug fix, ...) # This could be used later to determine if the content has to be udated (bug fix, ...)
print "EEPROM content generated: %s\n" % now_date
fru = "%s" % now_date fru = "%s" % now_date
bia = BoardInfoArea(mfg_date, "CERN", "FmcAdc100m14b4cha", serial, PART_NUMBER, fru) bia = BoardInfoArea(mfg_date, FRU_VENDOR, FRU_NAME, FRU_SERIAL, FRU_PART, fru)
#================================================== #==================================================
# Multirecords Area # Multirecords Area
...@@ -85,55 +126,15 @@ def main (default_directory='.'): ...@@ -85,55 +126,15 @@ def main (default_directory='.'):
# max TCK freq : frequency in MHz # max TCK freq : frequency in MHz
oem = OEMRecord(0, 1, 3, 1, 68, 0, 0, 0, 0, 0, 0) oem = OEMRecord(0, 1, 3, 1, 68, 0, 0, 0, 0, 0, 0)
#==================================================
# Internal Use Area
# Takes an array of byte as parameter
iua_data = [0x1,0x2,0x3,0x4]
iua = InternalUseArea(iua_data)
#================================================== #==================================================
# Write eeprom content to a binary file # Write eeprom content to a binary file
ipmi_open_file(EEPROM_BIN_FILENAME) ipmi_open_file(FRU_OUTPUT)
#ipmi_set(bia, dcload, dcout, oem, iua) #ipmi_set(bia, dcload, dcout, oem, iua)
ipmi_set(bia, dcload, dcout, oem) ipmi_set(bia, dcload, dcout, oem)
ipmi_write() ipmi_write()
ipmi_close_file() ipmi_close_file()
#==================================================
# Read eeprom content from binary file
f_eeprom = open(EEPROM_BIN_FILENAME, "rb")
eeprom_data = []
byte = f_eeprom.read(1) # reads one byte
while byte:
eeprom_data.append(ord(byte))
byte = f_eeprom.read(1) # reads one byte
f_eeprom.close()
print "Raw EEPROM data:"
i = 0
for data in eeprom_data:
if i%8 == 0:
print "0x%02X (%3d) : %02X" % (i, i, data),
else:
print "%02X" % (data),
i += 1
if i%8 == 0:
print ""
print("\n")
dsum = 0
for data in eeprom_data[158:162]:
dsum += data
print("0x%02X 0x%X" % (data, dsum))
print("\n\nsum: 0x%02X" % dsum)
checksum = (0xff & (1 + ~dsum))
print("calculated checksum: 0x%02X" % checksum)
print("data checksum : 0x%02X" % eeprom_data[162])
print("")
print("check data: 0x%02X" % (dsum + eeprom_data[162]))
print("check data: 0x%02X" % (dsum + checksum))
if __name__ == '__main__' : if __name__ == '__main__' :
main() main(sys.argv[0], sys.argv[1:])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment