/******************************************************************************* NAME BiosPlatInfo.cc VERSION %version: 2 % UPDATE DATE %date_modified: Fri Jan 29 22:54:58 2016 % PROGRAMMER %created_by: dhoyer % Copyright 2015-2016 NetApp, Inc. All Rights Reserved. DESCRIPTION: Class which determines what the platform is and basis the product parameters based on that information *******************************************************************************/ #include #include #include #include #include #include #include "hwlLineLib.h" #include #include "biosLib.h" #include "biosPlatInfo.h" //const std::string bios::BiosPlatInfo::m_DefaultPath("/etc/eseries-platforms"); /** * \brief Default constructor * * \param[in] biosInfoPath is a string containing path to the bios info (optional) * * \throws bios::BiosFail various messages indicating failure to initialize via logErr */ bios::BiosPlatInfo::BiosPlatInfo ( const std::string& biosInfoPath ) : //m_PlatformPath(biosInfoPath), m_BiosFile(biosInfoPath), //m_BiosName(), m_BiosSize(BIOS_SIZE), //m_BiosVersion(), //m_BoardName(0), m_Buffer(0) //m_BiosPrefix() { if (access(m_BiosFile.c_str(), F_OK ) == -1) { bios::logErr("BIOS image file path not specified"); } } /** * \brief This function reads in the BIOS file into memory and returns pointer to that memory * * \return Pointer to bios image in memory * * \throws bios::BiosFail Actual size does not match expected size via logErr */ UINT32* bios::BiosPlatInfo::readBiosFile ( ) { std::ifstream infile(m_BiosFile.c_str(), std::ifstream::binary); infile.seekg(0, infile.end); if (infile.tellg() != m_BiosSize) { bios::logErr("BIOS image size: %dM does not match expected size: %dM", infile.tellg()/0x100000, m_BiosSize/0x100000); } infile.seekg(0, infile.beg); // If previously allocated, then free it if (m_Buffer) free(m_Buffer); //m_Buffer = reinterpret_cast(aligned_alloc(sizeof(UINT32), m_BiosSize)); m_Buffer = (UINT32*)memalign(sizeof(UINT32), m_BiosSize); if (m_Buffer == 0) { bios::logErr("Could not allocate enough memory for BIOS image"); } infile.read(reinterpret_cast(m_Buffer), m_BiosSize); return m_Buffer; } /** * \brief This function takes in a line from the bootInfo.txt file and returns the * string after the '=' sign * * \param[in] line input line from bootInfo.txt file * * \return string containing value retrieved from line string */ const std::string bios::BiosPlatInfo::getValueFromString ( const std::string& line ) { // This routine will get the information after the = sign, strip off leading and // trailing spaces, then return that value std::string result(line); // First strip off all before = sign result = result.substr(result.find_first_of("=") + 1); // Now trim off leading and trailing spaces result.erase(0, result.find_first_not_of(" \t")); result.erase(result.find_last_not_of(" \t") + 1); return result; }