From b76c2437f1017bda4879a3a8ee6ddd00fdb5c281 Mon Sep 17 00:00:00 2001 From: Karin Hedlund Date: Fri, 20 May 2011 16:56:58 +0200 Subject: Initial commit --- riff/Command.h | 52 ++++++ riff/Config.cpp | 95 ++++++++++ riff/Config.h | 76 ++++++++ riff/DUT.cpp | 115 ++++++++++++ riff/DUT.h | 123 +++++++++++++ riff/DumpArea.cpp | 73 ++++++++ riff/DumpArea.h | 67 +++++++ riff/DutManager.cpp | 65 +++++++ riff/DutManager.h | 63 +++++++ riff/EraseArea.cpp | 50 ++++++ riff/EraseArea.h | 56 ++++++ riff/InitializeDut.cpp | 452 +++++++++++++++++++++++++++++++++++++++++++++++ riff/InitializeDut.h | 85 +++++++++ riff/Logger.cpp | 85 +++++++++ riff/Logger.h | 85 +++++++++ riff/ProcessRawImage.cpp | 79 +++++++++ riff/ProcessRawImage.h | 61 +++++++ riff/SequenceFactory.cpp | 105 +++++++++++ riff/SequenceFactory.h | 92 ++++++++++ riff/Shutdown.cpp | 47 +++++ riff/Shutdown.h | 50 ++++++ riff/constants.h | 29 +++ riff/main.cpp | 240 +++++++++++++++++++++++++ riff/main.h | 75 ++++++++ riff/riff.mk | 85 +++++++++ 25 files changed, 2405 insertions(+) create mode 100755 riff/Command.h create mode 100755 riff/Config.cpp create mode 100755 riff/Config.h create mode 100755 riff/DUT.cpp create mode 100755 riff/DUT.h create mode 100755 riff/DumpArea.cpp create mode 100755 riff/DumpArea.h create mode 100755 riff/DutManager.cpp create mode 100755 riff/DutManager.h create mode 100755 riff/EraseArea.cpp create mode 100755 riff/EraseArea.h create mode 100755 riff/InitializeDut.cpp create mode 100755 riff/InitializeDut.h create mode 100755 riff/Logger.cpp create mode 100755 riff/Logger.h create mode 100755 riff/ProcessRawImage.cpp create mode 100755 riff/ProcessRawImage.h create mode 100755 riff/SequenceFactory.cpp create mode 100755 riff/SequenceFactory.h create mode 100755 riff/Shutdown.cpp create mode 100755 riff/Shutdown.h create mode 100755 riff/constants.h create mode 100755 riff/main.cpp create mode 100755 riff/main.h create mode 100755 riff/riff.mk (limited to 'riff') diff --git a/riff/Command.h b/riff/Command.h new file mode 100755 index 0000000..e97d043 --- /dev/null +++ b/riff/Command.h @@ -0,0 +1,52 @@ +/* + * Command.h + * + * Copyright (C) ST-Ericsson SA 2011 + * Authors: Srimanta Panda , + * Ola Borgelin , + * Karin Hedlund , + * Markus Andersson for ST-Ericsson. + * License terms: 3-clause BSD license + * + */ + +/* + * @addtogroup Command + * @{ + */ + +#pragma once + +// DUT class declaration +class DUT; + +/** + * @brief Abstract class providing base for all command implementations. + */ +class Command +{ +public: + /** + * @brief Pure virtual method implemented by concrete command implementation. + * + * This method should be implemented in the inherited command class providing + * specific command behavior. + * + * @param[in] dut - Specific DUT instance on which to execute the command. + * @return int - Command execution error (0 on success, non-0 otherwise). + */ + virtual int run(DUT* dut) = 0; + + /** + * @brief Default virtual destructor. + */ + virtual ~Command() {} + + /** + * @brief Get the command name + */ + virtual const char * get_command_name() = 0; + +}; + +/* @} */ diff --git a/riff/Config.cpp b/riff/Config.cpp new file mode 100755 index 0000000..c35f333 --- /dev/null +++ b/riff/Config.cpp @@ -0,0 +1,95 @@ +/* + * Config.cpp + * + * Copyright (C) ST-Ericsson SA 2011 + * Authors: Srimanta Panda , + * Ola Borgelin , + * Karin Hedlund , + * Markus Andersson for ST-Ericsson. + * License terms: 3-clause BSD license + * + */ + +/* + * @addtogroup Config + * @{ + */ + +#include "Config.h" +#include "Utilities.h" +#include +#include +#include +using namespace std; + +Config::Config(): logger_("Config") +{ +} + +Config::Config(const string& path): logger_("Config") +{ + load(path); +} + +bool Config::load(const string& path) +{ + ifstream file; + file.open(path.c_str()); + + if (file.is_open()) { + + string line; + string command; + string key; + string value; + + while (getline(file, line)) { + Utilities::trim(line); + + if (line.length() == 0 || line[0] != '!') + continue; + + line.erase(0, 1); + + command = getToken(line); + + if (command == "set") { + key = getToken(line); + values_[key] = line; + } + } + + return true; + } else { + logger_.log(Logger::ERROR, "Failed to open configuration file \"%s\"", path.c_str()); + return false; + } +} + +const char* Config::getValue(const string& key) const +{ + map::const_iterator i = values_.find(key); + + if (i != values_.end()) { + return i->second.c_str(); + } else { + return ""; + } +} + +std::string Config::getToken(std::string& line) +{ + size_t pos = line.find_first_of(" "); + string token = line.substr(0, pos); + line.erase(0, pos + 1); + Utilities::trim(token); + return token; +} + +bool Config::valueExists(const string& key) const +{ + string value = getValue(key); + return value.size() != 0; +} + +/* @} */ diff --git a/riff/Config.h b/riff/Config.h new file mode 100755 index 0000000..33799f0 --- /dev/null +++ b/riff/Config.h @@ -0,0 +1,76 @@ +/* + * Config.h + * + * Copyright (C) ST-Ericsson SA 2011 + * Authors: Srimanta Panda , + * Ola Borgelin , + * Karin Hedlund , + * Markus Andersson for ST-Ericsson. + * License terms: 3-clause BSD license + * + */ + +/* + * @addtogroup Config + * @{ + */ + +#pragma once +#include "Logger.h" +#include +#include +#include + +/** + * @brief Class used for storing application configuration parameters. + * + * This class support reading and storing configuration parameters from/to + * configuration files. It also supports overriding of configuration parameters + * from command line. + */ +class Config +{ +public: + /** + * @brief Default constructor creating empty configuration. + */ + Config(); + + /** + * @brief Constructor that reads configuration parameters form file. + * + * @param[in] path - Path to the configuration file. + */ + Config(const std::string& path); + + /** + * @brief Function to load configuration from file. + * + * @param[in] path - Path to the configuration file. + */ + bool load(const std::string& path); + + /** + * @brief Gets the configuration value as C-style string. + * + * @param[in] key - Key of the configuration value. + * @return Configuration value as C-style string. + */ + const char* getValue(const std::string& key) const; + + /** + * @brief Checks if the configuration value exists. + * + * @param[in] key - Key of the configuration value. + * @return True if value exists, otherwise false. + */ + bool valueExists(const std::string& key) const; + +private: + std::map values_; + Logger logger_; + + std::string getToken(std::string& line); +}; + +/* @} */ diff --git a/riff/DUT.cpp b/riff/DUT.cpp new file mode 100755 index 0000000..6019518 --- /dev/null +++ b/riff/DUT.cpp @@ -0,0 +1,115 @@ +/* + * DUT.cpp + * + * Copyright (C) ST-Ericsson SA 2011 + * Authors: Srimanta Panda , + * Ola Borgelin , + * Karin Hedlund , + * Markus Andersson for ST-Ericsson. + * License terms: 3-clause BSD license + * + */ + +/* + * @addtogroup DUT + * @{ + */ + +#include "DUT.h" +#include "CDAL.h" +#include "LCDriver.h" +#include "Config.h" +#include +#include +#include +using namespace std; + +/** + * @brief Macro used by all command implementations to verify the Command return values. + */ +#define COMMAND_ERROR_VERIFY(error, message) \ + do { \ + if (0 != error) \ + { \ + logger_.log(Logger::ERROR,"COMMAND ERROR: %s %d", message, error); \ + usb_destroy_device(commDevice_, error); \ + errorcode_ = error; \ + return; \ + } \ + } while (0); + +DUT::DUT(Device_t commDevice, const string& id, CommandSequence_t sequence): + commDevice_(commDevice), + id_(id), + lcdContext_(0), + executionThread_(0), + shutdown_(false), + sequence_(sequence), + logger_(id) +{ + +} + +DUT::~DUT() +{ + shutdown_ = true; + executionThread_->wait(1000); + + logger_.log(Logger::INFO, "Destroying LCD context..."); + int error = DestroyContext(&lcdContext_); + + if (0 != error) { + logger_.log(Logger::ERROR, "LCD ERROR: Failed to destroy LCD context %d", error); + } else { + logger_.log(Logger::INFO, "LCD context destroyed successfully"); + } + + executionThread_->wait(1000); + + for (CommandSequence_t::iterator i = sequence_.begin(); i != sequence_.end(); ++i) { + delete *i; + } + + delete executionThread_; +} + +void DUT::startExecution() +{ + executionThread_ = new Thread(ExecutionThreadFunction, this); +} + +int DUT::getErrorCode() const +{ + return errorcode_; +} + +void DUT::executeSequence() +{ + int error = 0; + + for (CommandSequence_t::iterator i = sequence_.begin(); !shutdown_ && i != sequence_.end(); ++i) { + error = (*i)->run(this); + + // When the initialize DUT is failed, just set the error and exit (because + // the DUT is not started yet). But when other execution is failed, do a + // smooth exit by shutting down the DUT. + if ((error != 0) && (!strcmp((*i)->get_command_name(), "INITIALIZE_DUT"))) { + errorcode_ = error; + } else if ((error != 0) && (strcmp((*i)->get_command_name(), "SHUTDOWN"))) { + continue; + } + + COMMAND_ERROR_VERIFY(error, "Command execution failed"); + } + + return; +} + +void* DUT::ExecutionThreadFunction(void* arg) +{ + DUT* dut = static_cast(arg); + dut->executeSequence(); + return 0; +} + +/* @} */ diff --git a/riff/DUT.h b/riff/DUT.h new file mode 100755 index 0000000..98ddd1b --- /dev/null +++ b/riff/DUT.h @@ -0,0 +1,123 @@ +/* + * DUT.h + * + * Copyright (C) ST-Ericsson SA 2011 + * Authors: Srimanta Panda , + * Ola Borgelin , + * Karin Hedlund , + * Markus Andersson for ST-Ericsson. + * License terms: 3-clause BSD license + * + */ + +/* + * @addtogroup DUT + * @{ + */ + +#pragma once + +#include "CDAL.h" +#include "LCDriver.h" +#include "Thread.h" +#include "Config.h" +#include "Logger.h" +#include "Command.h" +#include "SequenceFactory.h" +#include +#include + +/** + * @brief Class that wraps all parameters related to the connected device. + * + * It also executes the command sequence that is set for this device. + */ +class DUT +{ +public: + + /** + * @brief Constructor. + * + * Constructor for the DUT class. It associates the newly created DUT with the + * communication device and sets the ID of the DUT. + * + * @param[in] commDevice - Communication device associated with the DUT. + * @param[in] id - ID of the DUT. + * @param[in] sequence - Execution sequence for the DUT. + */ + DUT(Device_t commDevice, const std::string& id, CommandSequence_t sequence); + + /** + * @brief Destructor. + * + * De-initializes the DUT by releasing all the resources used, stopping the execution + * of command sequence and destroying related LCD context. + */ + ~DUT(); + + /** + * @brief Start of execution of command sequence. + * + * Creates and starts new command execution thread. Each DUT instance is associated + * with separate command execution thread. + */ + void startExecution(); + + /** + * @brief This method returns the communication device associated with the DUT. + * + * @return Device_t - Communication device associated with the DUT. + */ + Device_t getCommDevice() const { + return commDevice_; + } + + /** + * @brief This method returns the ID of the DUT. + * + * @return const char* - string that contains the ID. + */ + const char* getId() const { + return id_.c_str(); + } + + /** + * @brief This method returns the LCD Context associated with the DUT. + * + * @return LCDContext - LCD Context associated with the DUT. + */ + LCDContext getLCDContext() { + return lcdContext_; + } + + /** + * @brief This method associates the DUT with a new LCDContext. + * + * @param[in] LCDContext - LCD Context that will be associated with the DUT. + */ + void setLCDContext(LCDContext lcdContext) { + lcdContext_ = lcdContext; + } + + /** + * @brief This method returns the errorcode produced by the sequence execution. + */ + int getErrorCode() const; + +private: + Device_t commDevice_; + std::string id_; + LCDContext lcdContext_; + Logger logger_; + CommandSequence_t sequence_; + int errorcode_; + + // command execution thread + Thread* executionThread_; + bool shutdown_; + static void* ExecutionThreadFunction(void* arg); + void executeSequence(); +}; + +/* @} */ diff --git a/riff/DumpArea.cpp b/riff/DumpArea.cpp new file mode 100755 index 0000000..2f7fcf6 --- /dev/null +++ b/riff/DumpArea.cpp @@ -0,0 +1,73 @@ +/* + * DumpArea.cpp + * + * Copyright (C) ST-Ericsson SA 2011 + * Authors: Srimanta Panda , + * Ola Borgelin , + * Karin Hedlund , + * Markus Andersson for ST-Ericsson. + * License terms: 3-clause BSD license + * + */ + +/* + * @addtogroup Commands + * @{ + */ + +/******************************************************************************* + * Includes + ******************************************************************************/ +#include "DumpArea.h" +#include +#include +#include "LCDriver.h" +using namespace flash; + +DumpArea::DumpArea(const char* path, uint64 start, uint64 length, const char* filepath, uint32 redundant, int useBulk): + logger_("DumpArea") +{ + pchPath = path; + uiStart = start; + uiLength = length; + pchFilePath = filepath; + uiRedundantArea = redundant; + iUseBulk = useBulk;; +} + +int DumpArea::run(DUT* dut) +{ + logger_.log(Logger::PROGRESS, "Dumping area..."); + logger_.log(Logger::PROGRESS, "Dump path is %s", pchFilePath); + int error = checkInput(); + if (error == -1) { + return error; + } + error = Flash_DumpArea(dut->getLCDContext(), pchPath, uiStart, uiLength, pchFilePath, uiRedundantArea, iUseBulk); + if (0 != error) + { + logger_.log(Logger::ERROR,"LCD ERROR: Dump area failed %d", error); + return error; + } + // Need a new line braek after the progress bar + logger_.logRaw("\n"); + logger_.log(Logger::INFO, "Dump area finished successfully"); + return error; +} + +int DumpArea::checkInput() +{ + if (uiLength <= 0) { + logger_.log(Logger::ERROR, "Length of the dump not specified. Use -l or --length option"); + return -1; + } + return 0; +} + +const char * DumpArea::get_command_name() +{ + return (char *)"DUMPAREA"; +} + + +/* @} */ diff --git a/riff/DumpArea.h b/riff/DumpArea.h new file mode 100755 index 0000000..bd37638 --- /dev/null +++ b/riff/DumpArea.h @@ -0,0 +1,67 @@ +/* + * DumpArea.h + * + * Copyright (C) ST-Ericsson SA 2011 + * Authors: Srimanta Panda , + * Ola Borgelin , + * Karin Hedlund , + * Markus Andersson for ST-Ericsson. + * License terms: 3-clause BSD license + * + */ + +/* + * @addtogroup Commands + * @{ + */ + +#pragma once +#include "DUT.h" +#include "Command.h" + +namespace flash +{ +/** + * @brief Class implementing Dump Area command from Flash group. + */ +class DumpArea : public Command +{ +public: + /** + * @brief Constructor initializing command parameters. + * + * @param[in] path - Path to the device to dump. + * @param[in] start - Start of the dump relative to the start of the device indicated by Path [Byte]. + * @param[in] lenght - Length of the dump [Byte]. Actual length is determined by the device block size. + * @param[in] filepath - File path on PC to store dump data to. + * @param[in] redundant - dump with redundant data, 1-> dump without redundant data. + * @param[in] useBulk - 1 = use bulk protocol. + */ + DumpArea(const char* path, uint64 start, uint64 length, const char* filepath, uint32 redundant, int useBulk); + + /** + * @brief Method that executes the dump process. + * + * @param[in] dut - Specific DUT instance on which to execute the command. + * @return int - Command execution error (0 on success, non-0 otherwise). + */ + int run(DUT* dut); + + const char * get_command_name(); + +private: + + int checkInput(); + + Logger logger_; + const char* pchPath; + uint64 uiStart; + uint64 uiLength; + const char* pchFilePath; + char dumpPath[50]; + uint32 uiRedundantArea; + int iUseBulk; +}; +} + +/* @} */ diff --git a/riff/DutManager.cpp b/riff/DutManager.cpp new file mode 100755 index 0000000..86a96c4 --- /dev/null +++ b/riff/DutManager.cpp @@ -0,0 +1,65 @@ +/* + * DUTManager.cpp + * + * Copyright (C) ST-Ericsson SA 2011 + * Authors: Srimanta Panda , + * Ola Borgelin , + * Karin Hedlund , + * Markus Andersson for ST-Ericsson. + * License terms: 3-clause BSD license + * + */ + +/* + * @addtogroup DUT Manager + * @{ + */ + +#include "DutManager.h" +#include "Utilities.h" +#include +using namespace std; + +vector DutManager::devices_; + +DUT* DutManager::createDut(Device_t device) +{ + string dutId = getDutId(device); + + DUT* dut = new DUT(device, dutId, SequenceFactory::getProfileSequence()); + devices_.push_back(dut); + + dut->startExecution(); + + return dut; +} + +const DUT* DutManager::getDut(Device_t device) +{ + for (vector::iterator i = devices_.begin(); i != devices_.end(); ++i) { + if ((*i)->getCommDevice() == device) { + return *i; + } + } + + return 0; +} + +void DutManager::destroyDut(Device_t device) +{ + for (vector::iterator i = devices_.begin(); i != devices_.end(); ++i) { + if ((*i)->getCommDevice() == device) { + delete *i; + devices_.erase(i); + break; + } + } +} + +string DutManager::getDutId(Device_t device) +{ + string physicalId = "Device@" + Utilities::convert(comm_get_physical_address(device)); + return physicalId; +} + +/* @} */ diff --git a/riff/DutManager.h b/riff/DutManager.h new file mode 100755 index 0000000..6a8009d --- /dev/null +++ b/riff/DutManager.h @@ -0,0 +1,63 @@ +/* + * DUTManager.h + * + * Copyright (C) ST-Ericsson SA 2011 + * Authors: Srimanta Panda , + * Ola Borgelin , + * Karin Hedlund , + * Markus Andersson for ST-Ericsson. + * License terms: 3-clause BSD license + * + */ + +/* + * @addtogroup DUT Manager + * @{ + */ + +#pragma once + +#include "DUT.h" +#include "CDAL.h" +#include "Logger.h" +#include + +class DutManager +{ +public: + /** + * @brief Creates new DUT instance, starts execution and adds the DUT in the list of active devices. + * + * @param[in] Device_t - Communication device on which the DUT will be created. + * + */ + static DUT* createDut(Device_t device); + + /** + * @brief Get the DUT instance that is associated with the connected devices.. + * + * @param[in] Device_t - Communication device. + * @return DUT* - pointer to the DUT. + * @return 0 - if the DUT can't be find in the list. + */ + static const DUT* getDut(Device_t device); + + /** + * @brief Destroys the DUT instance that is associated with the communication device. + * + * @param[in] Device_t - Communication device. + */ + static void destroyDut(Device_t device); + +private: + DutManager(); + ~DutManager(); + + /*list of connected devices*/ + static std::vector devices_; + + static std::string getDutId(Device_t device); +}; + +/* @} */ + diff --git a/riff/EraseArea.cpp b/riff/EraseArea.cpp new file mode 100755 index 0000000..3de8ed0 --- /dev/null +++ b/riff/EraseArea.cpp @@ -0,0 +1,50 @@ +/* + * EraseArea.cpp + * + * Copyright (C) ST-Ericsson SA 2011 + * Authors: Srimanta Panda , + * Ola Borgelin , + * Karin Hedlund , + * Markus Andersson for ST-Ericsson. + * License terms: 3-clause BSD license + * + */ + +/* + * @addtogroup Commands + * @{ + */ + +#include "EraseArea.h" +using namespace flash; + + +EraseArea::EraseArea(const char* path, uint64 start, uint64 length): + logger_("EraseArea") +{ + pchPath = path; + uiStart = start; + uiLength = length; +} + +int EraseArea::run(DUT* dut) +{ + logger_.log(Logger::PROGRESS, "Erasing area..."); + int error = Flash_EraseArea(dut->getLCDContext(), pchPath, uiStart, uiLength); + + if (0 != error) + { + logger_.log(Logger::ERROR,"LCD ERROR: Erase area failed %d", error); + return error; + } + + logger_.log(Logger::PROGRESS, "Erase area finished successfully"); + return error; +} + +const char * EraseArea::get_command_name() +{ + return (char *)"ERASEAREA"; +} + +/* @} */ diff --git a/riff/EraseArea.h b/riff/EraseArea.h new file mode 100755 index 0000000..d44e27a --- /dev/null +++ b/riff/EraseArea.h @@ -0,0 +1,56 @@ +/* + * EraseArea.h + * + * Copyright (C) ST-Ericsson SA 2011 + * Authors: Srimanta Panda , + * Ola Borgelin , + * Karin Hedlund , + * Markus Andersson for ST-Ericsson. + * License terms: 3-clause BSD license + * + */ + +/* + * @addtogroup Commands + * @{ + */ + +#pragma once +#include "DUT.h" +#include "Command.h" + +namespace flash +{ +/** + * @brief Class implementing Erase Area command from Flash group. + */ +class EraseArea : public Command +{ +public: + /** + * @brief Constructor initializing command parameters. + * + * @param[in] path - Path to the device to erase. + * @param[in] start - Start of the erase relative to the start of the device. + * @param[in] length - 1 = use bulk protocol. + */ + EraseArea(const char* path, uint64 start, uint64 length); + + /** + * @brief Method that executes the erase process. + * + * @param[in] dut - Specific DUT instance on which to execute the command. + * @return int - Command execution error (0 on success, non-0 otherwise). + */ + int run(DUT* dut); + + const char * get_command_name(); +private: + Logger logger_; + const char* pchPath; + uint64 uiStart; + uint64 uiLength; +}; +} + +/* @} */ diff --git a/riff/InitializeDut.cpp b/riff/InitializeDut.cpp new file mode 100755 index 0000000..e2feb18 --- /dev/null +++ b/riff/InitializeDut.cpp @@ -0,0 +1,452 @@ +/* + * InitializeDut.cpp + * + * Copyright (C) ST-Ericsson SA 2011 + * Authors: Srimanta Panda , + * Ola Borgelin , + * Karin Hedlund , + * Markus Andersson for ST-Ericsson. + * License terms: 3-clause BSD license + * + */ + +/* + * @addtogroup Commands + * @{ + */ + +#include "InitializeDut.h" +#include "Logger.h" +#include "DUT.h" +#include "Utilities.h" +#include +#include +#include +#include +#include + +using namespace std; + + +int InitializeDut::readIsswFile(char* buf) +{ + int res = 0; + FILE* isswImage; + + isswImage = fopen(isswPath_, "rb"); + + if (isswImage == NULL) { + logger_.log(Logger::ERROR, "InitializeDut.cpp (%d) %s() error while opening file %s", __LINE__, __FUNCTION__, isswPath_); + return -1; + } + + res = fread(buf, 1, issw_.size, isswImage); + + fclose(isswImage); + return 0; +} + +int InitializeDut::readSecondIsswFile(char* buf) +{ + int res = 0; + FILE* xloaderImage; + + xloaderImage = fopen(xloaderPath_, "rb"); + + if (xloaderImage == NULL) { + logger_.log(Logger::ERROR, "InitializeDut.cpp (%d) %s() error while opening file %s", __LINE__, __FUNCTION__, xloaderPath_); + return -1; + } + + res = fread(buf, 1, xload_.size, xloaderImage); + fclose(xloaderImage); + return 0; +} + +int InitializeDut::readPwrMgtFile(char* buf) +{ + FILE* pwrmgmtImage; + + pwrmgmtImage = fopen(pwrmgmtPath_, "rb"); + + if (pwrmgmtImage == NULL) { + logger_.log(Logger::ERROR, "InitializeDut.cpp (%d) %s() error while opening file %s", __LINE__, __FUNCTION__, pwrmgmtPath_); + return -1; + } + + fread(buf, 1, pwrMgt_.size, pwrmgmtImage); + fclose(pwrmgmtImage); + return 0; +} + +int InitializeDut::readMeminitFile(char* buf) +{ + FILE* meminitImage; + + meminitImage = fopen(meminitPath_, "rb"); + + if (meminitImage == NULL) { + logger_.log(Logger::ERROR, "InitializeDut.cpp (%d) %s() error while opening file %s", __LINE__, __FUNCTION__, meminitPath_); + return -1; + } + + fread(buf, 1, meminit_.size, meminitImage); + fclose(meminitImage); + return 0; +} + +int InitializeDut::readNormal(char* buf) +{ + FILE* normalImage; + + normalImage = fopen(normalPath_, "rb"); + + if (normalImage == NULL) { + logger_.log(Logger::ERROR, "InitializeDut.cpp (%d) %s() error while opening file %s", __LINE__, __FUNCTION__, normalPath_); + return -1; + } + + fread(buf, 1, normal_.size, normalImage); + fclose(normalImage); + return 0; +} + +int InitializeDut::commWrite2kChunks(Device_t device, void* buffer, size_t size) +{ + char* buf = static_cast(buffer); + + while (size) { + size_t toSend = size > 2048 ? 2048 : size; + + if (comm_write(device, buf, toSend) < 0) + return -1; + + size -= toSend; + buf += toSend; + } + + return 0; +} + +int InitializeDut::sendTocIssw(Device_t device) +{ + //Send TOC+ISSW to the board + int index = 0; + tocSection* tocSections = (tocSection*)tocArea; + unsigned int bootIndication; + char* sendBuffer = NULL; + int sendBufferSize = 0; + char* tempNORMAL = (char*) "NORMAL"; + + memset(tocSections, 0xff, 512); + + //Build TOC Sections List + tocSections[index++] = issw_; + + // X-Loader section + tocSections[index++] = xload_; + tocSections[index++] = meminit_; + + if (strcmp(pwrMgt_.filename, tempNORMAL) == 0) { + tocSections[index++] = normal_; + } else { + tocSections[index++] = pwrMgt_; + tocSections[index++] = normal_; + } + + sendBufferSize = 512 + issw_.size; + sendBuffer = (char*)malloc(sendBufferSize); + + bootIndication = 0xf0030002; + + if (comm_write(device, (char*)&bootIndication, 4) < 0) + return -1; + + if (comm_write(device, (char*)&sendBufferSize, 4) < 0) + return -1; + + memcpy(sendBuffer, tocSections, 512); + readIsswFile(sendBuffer + 512); + + commWrite2kChunks(device, sendBuffer, sendBufferSize); + + return 0; +} + +int InitializeDut::createTocEntry(tocSection* issw, tocSection* xload, tocSection* meminit, tocSection* normal, tocSection* pwrMgt) +{ + int offset = 512; + + createTocFile(issw, isswPath_, "ISSW", &offset); //ISSW TOC + createTocFile(xload, xloaderPath_, "X-LOADER", &offset); //X-LOADER TOC + createTocFile(meminit, meminitPath_, "MEM_INIT", &offset); //MEMINIT TOC + + if (strlen(pwrmgmtPath_) != 0) { + createTocFile(pwrMgt, pwrmgmtPath_, "PWR_MGT", &offset); //PWR_MGT TOC + createTocFile(normal, normalPath_, "NORMAL", &offset); //NORMAL TOC + } else { + createTocFile(pwrMgt, normalPath_, "NORMAL", &offset); //NORMAL TOC + *normal = *pwrMgt; + } + + return 0; +} + +int InitializeDut::createTocFile(tocSection* toc, const char* filePath, const char* tocName, int* offset) +{ + size_t size = 0; + + if ((filePath == NULL) || (strlen(filePath) == 0)) + return -1; + + size = getFileSize(filePath); + + // Create the TOC entry + toc->start = *offset; + toc->size = size; + toc->flags = 0; + toc->align = 0; + toc->loadAddress = 0; + strcpy(toc->filename, tocName); + + *offset += size; + + return 0; +} + +int InitializeDut::getFileSize(const char* filePath) +{ + + struct stat filestatus; + stat(filePath, &filestatus); + + return filestatus.st_size; + +} + +int InitializeDut::initializeHardware(Device_t device) +{ + + char asicIdUsb[65]; + unsigned char secureMode; + + unsigned int byteSynchro = 0x53548815; + + Config config(configPath_); + + isswPath_ = config.getValue("ISSWPATH"); + xloaderPath_ = config.getValue("XLOADERPATH"); + meminitPath_ = config.getValue("MEMINITPATH"); + pwrmgmtPath_ = config.getValue("PWRMGMTPATH"); + normalPath_ = config.getValue("NORMALPATH"); + + if (comm_write(device, (char*)&byteSynchro, 4) < 0) + return -1; + + if (comm_read(device, asicIdUsb, 65) < 0) + return -1; + + secureMode = asicIdUsb[11]; + + if (createTocEntry(&issw_, &xload_, &meminit_, &normal_, &pwrMgt_)) + return -1; + + if (sendTocIssw(device)) + return -1; + + while (1) { + unsigned int reqId; + + if (comm_read(device, (char*)&reqId, 4) < 0) + return -1; + + char *sendBuffer = NULL; + + switch (reqId) { + case 0xA0400000: + /* 2nd Loader ISSW Requested XLoader */ + logger_.log(Logger::INFO, "X-LOADER token"); + + if (comm_write(device, (char*)&xload_.size, 4) < 0) + return -1; + + sendBuffer = (char*)malloc(xload_.size); + + if (readSecondIsswFile(sendBuffer) < 0) + { + free(sendBuffer); + return -1; + } + + + + commWrite2kChunks(device, sendBuffer, xload_.size); + logger_.log(Logger::INFO, "X-LOADER sent"); + free(sendBuffer); + + break; + + case 0xA0300002: + /*PWR_MGT token*/ + logger_.log(Logger::INFO, "PWR_MGT token"); + + if (comm_write(device, (char*)&pwrMgt_.size, 4) < 0) + return -1; + + sendBuffer = (char*)malloc(pwrMgt_.size); + + if (readPwrMgtFile(sendBuffer) < 0) + { + free(sendBuffer); + return -1; + } + + commWrite2kChunks(device, sendBuffer, pwrMgt_.size); + logger_.log(Logger::INFO, "PWR_MGT sent"); + free(sendBuffer); + + break; + + case 0xA0300000: + /* Mem Init token */ + logger_.log(Logger::INFO, "MEM_INIT token"); + + if (comm_write(device, (char*)&meminit_.size, 4) < 0) + return -1; + + sendBuffer = (char*)malloc(meminit_.size); + + if (readMeminitFile(sendBuffer) < 0) + { + free(sendBuffer); + return -1; + } + + commWrite2kChunks(device, sendBuffer, meminit_.size); + logger_.log(Logger::INFO, "MEM_INIT sent"); + free(sendBuffer); + + break; + + case 0xA0300001: + /* Application token */ + logger_.log(Logger::INFO, "NORMAL token"); + + if (comm_write(device, (char*)&normal_.size, 4) < 0) + return -1; + + sendBuffer = (char*)malloc(normal_.size); + + if (readNormal(sendBuffer) < 0) + { + free(sendBuffer); + return -1; + } + + commWrite2kChunks(device, sendBuffer, normal_.size); + logger_.log(Logger::INFO, "NORMAL sent"); + free(sendBuffer); + + return 0; + + break; + + default: + logger_.log(Logger::INFO, "UNKNOWN token"); + } + } +} +InitializeDut::InitializeDut(const char* configPath): + logger_("InitializeDut") +{ + configPath_ = configPath; +} + +int InitializeDut::run(DUT* dut) +{ + int error = 0; + Device_t commDevice = dut->getCommDevice(); + LCDContext lcdContext = 0; + + char version[100] = {0}; + int versionSize = 100; + char protocol[100] = {0}; + int protocolSize = 100; + + logger_.log(Logger::INFO, "Initializing device..."); + + error = initializeHardware(commDevice); + if (0 != error) + { + logger_.log(Logger::ERROR,"LCD ERROR: Error while initializing device %d", error); + return error; + } + + logger_.log(Logger::INFO, "Initializing finished"); + + logger_.log(Logger::INFO, "Starting initialization of LCD..."); + void** deviceObjectStorage = comm_get_object_storage(commDevice); + error = CreateContext(&lcdContext, dut->getId()); + if (0 != error) + { + logger_.log(Logger::ERROR,"LCD ERROR: Error while creating LCD context %d", error); + return error; + } + + dut->setLCDContext(lcdContext); + error = ConfigureCommunicationDevice(lcdContext, (void*)comm_read_nowait, (void*)comm_write_nowait, (void*)comm_cancel); + if (0 != error) + { + logger_.log(Logger::ERROR,"LCD ERROR: Error while configuring communication device %d", error); + return error; + } + + + error = SwitchProtocolFamily(lcdContext, R15_PROTOCOL_FAMILY); + if (0 != error) + { + logger_.log(Logger::ERROR,"LCD ERROR: Error while setting protocol family %d", error); + return error; + } + + + error = StartContext(lcdContext, deviceObjectStorage); + if (0 != error) + { + logger_.log(Logger::ERROR,"LCD ERROR: Error while starting LCD context %d", error); + return error; + } + + logger_.log(Logger::INFO, "LCD initialization finished successfully"); + + error = SetProgressCallback(lcdContext, (void*)comm_progress); + if (0 != error) + { + logger_.log(Logger::ERROR,"LCD ERROR: Error while setting Progress listener %d", error); + return error; + } + + logger_.log(Logger::INFO, "Progress listener added successfully"); + + error = System_LoaderStartupStatus(dut->getLCDContext(), version, &versionSize, protocol, &protocolSize); + if (0 != error) + { + logger_.log(Logger::ERROR,"LCD ERROR: Failed to receive loader startup status %d", error); + return error; + } + + logger_.log(Logger::INFO, "Loader successfully started"); + logger_.log(Logger::INFO, " Version: %s", version); + logger_.log(Logger::INFO, " Protocol: %s", protocol); + + Utilities::sleep(100); + + return error; +} + +const char * InitializeDut::get_command_name() +{ + return (char *)"INITIALIZE_DUT"; +} + +/* @} */ diff --git a/riff/InitializeDut.h b/riff/InitializeDut.h new file mode 100755 index 0000000..6e0ab31 --- /dev/null +++ b/riff/InitializeDut.h @@ -0,0 +1,85 @@ +/* + * InitializeDut.h + * + * Copyright (C) ST-Ericsson SA 2011 + * Authors: Srimanta Panda , + * Ola Borgelin , + * Karin Hedlund , + * Markus Andersson for ST-Ericsson. + * License terms: 3-clause BSD license + * + */ + +/* + * @addtogroup Commands + * @{ + */ + +#pragma once +#include "Command.h" +#include "Config.h" +#include "DUT.h" +#include +#include +using namespace std; + +struct tocSection { + int start; + int size; + int flags; + int align; + int loadAddress; + char filename[12]; +}; + +/** + * @brief Class implementing command for DUT initialization. + */ +class InitializeDut : public Command +{ +public: + /** + * @brief Default constructor taking a config file path as parameter. + */ + InitializeDut(const char* configPath); + + /** + * @brief Method that executes the DUT initialization. + * + * This method initializes new LCD context and sets the DUT in service mode. + * + * @param[in] dut - Specific DUT instance on which to execute the command. + * @return int - Command execution error (0 on success, non-0 otherwise). + */ + int run(DUT* dut); + + const char * get_command_name(); + +private: + const char* configPath_; + const char* isswPath_; + const char* xloaderPath_; + const char* meminitPath_; + const char* pwrmgmtPath_; + const char* normalPath_; + + char tocArea[512]; + tocSection issw_, xload_, meminit_, normal_, pwrMgt_; + + Logger logger_; + + int commWrite2kChunks(Device_t device, void* buffer, size_t size); + int sendTocIssw(Device_t device); + int createTocEntry(tocSection* issw, tocSection* xload, tocSection* meminit, tocSection* normal, tocSection* pwrMgt); + int createTocFile(tocSection* toc, const char* filePath, const char* tocName, int* offset); + int getFileSize(const char* filePath); + int readIsswFile(char* buf); + int readSecondIsswFile(char* buf); + int readPwrMgtFile(char* buf); + int readMeminitFile(char* buf); + int readNormal(char* buf); + int initializeHardware(Device_t device); + +}; + +/* @} */ diff --git a/riff/Logger.cpp b/riff/Logger.cpp new file mode 100755 index 0000000..a54e447 --- /dev/null +++ b/riff/Logger.cpp @@ -0,0 +1,85 @@ +/* + * Logger.cpp + * + * Copyright (C) ST-Ericsson SA 2011 + * Authors: Srimanta Panda , + * Ola Borgelin , + * Karin Hedlund , + * Markus Andersson for ST-Ericsson. + * License terms: 3-clause BSD license + * + */ + +/* + * @addtogroup Logger + * @{ + */ + +#include "Logger.h" +#include +#include +#include +#include +#include +using namespace std; + +bool Logger::verbose_; + +Logger::Logger(const string& name): + name_(name) +{ + console_ = stdout; + +} + +Logger::~Logger() +{ +} + +void Logger::log(LogSeverity severity, const char* format, ...) const +{ + time_t t = time(0); + tm lt; + localtime_r(&t, <); + + if (verbose_ || severity == Logger::PROGRESS || severity == Logger::ERROR) { + flockfile(console_); + fprintf(console_, "%02d:%02d:%02d ", lt.tm_hour, lt.tm_min, lt.tm_sec); + + fprintf(console_, " - "); + + va_list args; + va_start(args, format); + vfprintf(console_, format, args); + va_end(args); + fprintf(console_, "\n"); + fflush(console_); + funlockfile(console_); + + } +} + +void Logger::hex(const unsigned char* buffer, size_t size) const +{ + flockfile(console_); + + for (size_t i = 0; i < size; i++) { + fprintf(console_, "%02x ", buffer[i]); + + if ((i + 1) % 16 == 0 || (i + 1) == size) + fprintf(console_, "\n"); + } + + fflush(console_); + funlockfile(console_); +} + +void Logger::logRaw(const char* message) const +{ + flockfile(console_); + fprintf(console_, "%s", message); + fflush(console_); + funlockfile(console_); +} + +/* @} */ diff --git a/riff/Logger.h b/riff/Logger.h new file mode 100755 index 0000000..c995abc --- /dev/null +++ b/riff/Logger.h @@ -0,0 +1,85 @@ +/* + * Logger.h + * + * Copyright (C) ST-Ericsson SA 2011 + * Authors: Srimanta Panda , + * Ola Borgelin , + * Karin Hedlund , + * Markus Andersson for ST-Ericsson. + * License terms: 3-clause BSD license + * + */ + +/* + * @addtogroup Logger + * @{ + */ + +#pragma once +#include + +/** + * @brief Class for storing and displaying logging information. + * + * This class implements simple command line logger that can display logging + * information either to the application console or separate logging console. + */ +class Logger +{ +public: + + enum LogSeverity { + PROGRESS, + ERROR, + WARNING, + INFO + }; + + + /** + * @brief Creates logger with the specified name. + * + * @param[in] name - Name of the logger. + */ + Logger(const std::string& name); + + /** + * @brief Destroys the logger. + */ + ~Logger(); + + /** + * @brief printf style log function to print formated message. + * + * It prints the message on separate line adding timestamp and logger name + * if printing in a shared console. + * + * @param[in] severity - the severity of the log message. + * @param[in] format - printf style format of the message. + * @param[in] ... - variable argument list. + */ + void log(LogSeverity severity, const char* format, ...) const __attribute__((format(printf, 3, 0))); + + /** + * @brief Print hex dump of the buffer. + * + * @param[in] buffer - buffer to be printed to the log. + * @param[in] size - size of the buffer. + */ + void hex(const unsigned char* buffer, size_t size) const; + + /** + * @brief Print raw message string to the logging console. + * + * @param[in] message - raw messsage to be printed. + */ + void logRaw(const char* message) const; + + static bool verbose_; + +private: + FILE* console_; + std::string name_; +}; + +/* @} */ diff --git a/riff/ProcessRawImage.cpp b/riff/ProcessRawImage.cpp new file mode 100755 index 0000000..a46337b --- /dev/null +++ b/riff/ProcessRawImage.cpp @@ -0,0 +1,79 @@ +/* + * ProcessRawImage.cpp + * + * Copyright (C) ST-Ericsson SA 2011 + * Authors: Srimanta Panda , + * Ola Borgelin , + * Karin Hedlund , + * Markus Andersson for ST-Ericsson. + * License terms: 3-clause BSD license + * + */ + +/* + * @addtogroup Commands + * @{ + */ + +/******************************************************************************* + * Includes + ******************************************************************************/ +#include "ProcessRawImage.h" +#include +#include +#include "LCDriver.h" +using namespace flash; + +ProcessRawImage::ProcessRawImage(const char* path, uint64 start, int useBulk, int deleteBuffers): + logger_("ProcessRawImage") +{ + pchPath = path; + uiStart = start; + uiDevice = 0; // Flashing the flash0 device + iUseBulk = useBulk; + iDeleteBuffers = deleteBuffers; +} + +int ProcessRawImage::run(DUT* dut) +{ + logger_.log(Logger::PROGRESS, "Flashing raw image..."); + uint64 length = filesize(pchPath); + int error = 0; + + if (length != 0) { + error = Flash_FlashRaw(dut->getLCDContext(), pchPath, uiStart, length, uiDevice, iUseBulk, iDeleteBuffers); + if (0 != error) + { + logger_.log(Logger::ERROR,"LCD ERROR: Process raw image failed %d", error); + return error; + } + + // Need a new line braek after the progress bar + logger_.logRaw("\n"); + logger_.log(Logger::PROGRESS, "Flashing finished successfully"); + } else { + error = -1; + logger_.log(Logger::ERROR,"LCD ERROR: Flash image is empty or doesn't exist %d", error); + return error; + } + + return error; +} + +size_t ProcessRawImage::filesize(const char* filename) +{ + struct stat st; + + if (stat(filename, &st) == 0) + return st.st_size; + + return 0; +} + +const char * ProcessRawImage::get_command_name() +{ + return (char *)"PROCESSRAWIMAGE"; +} + + +/* @} */ diff --git a/riff/ProcessRawImage.h b/riff/ProcessRawImage.h new file mode 100755 index 0000000..b429b88 --- /dev/null +++ b/riff/ProcessRawImage.h @@ -0,0 +1,61 @@ +/* + * ProcessRawImage.h + * + * Copyright (C) ST-Ericsson SA 2011 + * Authors: Srimanta Panda , + * Ola Borgelin , + * Karin Hedlund , + * Markus Andersson for ST-Ericsson. + * License terms: 3-clause BSD license + * + */ + +/* + * @addtogroup Commands + * @{ + */ + +#pragma once +#include "DUT.h" +#include "Command.h" + +namespace flash +{ +/** + * @brief Class implementing Process Raw Image command from Flash group. + */ +class ProcessRawImage : public Command +{ +public: + /** + * @brief Constructor initializing command parameters. + * + * @param[in] path - Path to the image file. + * @param[in] start - Address where flashing should start. + * @param[in] useBulk - 1 = use bulk protocol. + * @param[in] deleteBuffers - 1 = release flash archive buffers after finish. + */ + ProcessRawImage(const char* path, uint64 start, int useBulk, int deleteBuffers); + + /** + * @brief Method that executes the flashing process. + * + * @param[in] dut - Specific DUT instance on which to execute the command. + * @return int - Command execution error (0 on success, non-0 otherwise). + */ + int run(DUT* dut); + + const char * get_command_name(); + +private: + Logger logger_; + size_t filesize(const char* filename); + const char* pchPath; + uint64 uiStart; + uint32 uiDevice; + int iUseBulk; + int iDeleteBuffers; +}; +} + +/* @} */ diff --git a/riff/SequenceFactory.cpp b/riff/SequenceFactory.cpp new file mode 100755 index 0000000..8c42f78 --- /dev/null +++ b/riff/SequenceFactory.cpp @@ -0,0 +1,105 @@ +/* + * SequenceFactory.cpp + * + * Copyright (C) ST-Ericsson SA 2011 + * Authors: Srimanta Panda , + * Ola Borgelin , + * Karin Hedlund , + * Markus Andersson for ST-Ericsson. + * License terms: 3-clause BSD license + * + */ + +/* + * @addtogroup SequenceFactory + * @{ + */ + +#include "Config.h" +#include "SequenceFactory.h" +#include "Command.h" +#include "InitializeDut.h" +#include "ProcessRawImage.h" +#include "Shutdown.h" +#include "EraseArea.h" +#include "DumpArea.h" +#include "constants.h" +#include +#include +#include +#include +using namespace std; + +const SequenceFactory::SequenceId SequenceFactory::defaultSequence_ = SequenceFactory::BOARD_FLASH; + +const char* SequenceFactory::configPath_; +const char* SequenceFactory::flashmode_; +const char* SequenceFactory::flashImgPath_; +const char* SequenceFactory::dumpHostPath_; +int SequenceFactory::address_ = 0; +int SequenceFactory::length_ = 0; + +void SequenceFactory::setArguments(const char* configPath, const char* mode, const char* flashImg, const char* address, const char* length, const char* dumpPath) +{ + SequenceFactory::configPath_ = configPath; + SequenceFactory::flashmode_ = mode; + SequenceFactory::flashImgPath_ = flashImg; + SequenceFactory::address_ = strtol(address, NULL, 16); + SequenceFactory::length_ = strtol(length, NULL, 16); + SequenceFactory::dumpHostPath_ = dumpPath; +} + +CommandSequence_t SequenceFactory::getSequence(SequenceId id) +{ + CommandSequence_t sequence; + + // Initialize DUT + sequence.push_back(new InitializeDut(configPath_)); + + + switch (id) { + case BOARD_FLASH: { + // Process raw software image + sequence.push_back(new flash::ProcessRawImage(flashImgPath_, address_, USE_BULK_PROTOCOL, DELETE_BUFFER_YES)); + } + break; + case BOARD_ERASE: { + // erase complete flash + sequence.push_back(new flash::EraseArea(flash::FLASH_DEVICE_TYPE, 0, -1)); + } + break; + case BOARD_DUMP: { + // dump flash area + sequence.push_back(new flash::DumpArea(flash::FLASH_DEVICE_TYPE, address_, length_, dumpHostPath_, 1, USE_BULK_PROTOCOL)); + } + break; + + default: + cout << "No action to be performed" << endl; + + } + + // shut down + sequence.push_back(new System::Shutdown()); + + return sequence; +} + +CommandSequence_t SequenceFactory::getProfileSequence() +{ + if (SequenceFactory::flashmode_ == string("flash")) { + return getSequence(BOARD_FLASH); + } + + if (SequenceFactory::flashmode_ == string("erase")) { + return getSequence(BOARD_ERASE); + } + + if (SequenceFactory::flashmode_ == string("dump")) { + return getSequence(BOARD_DUMP); + } else { + return getSequence(defaultSequence_); + } +} + +/* @} */ diff --git a/riff/SequenceFactory.h b/riff/SequenceFactory.h new file mode 100755 index 0000000..a208f90 --- /dev/null +++ b/riff/SequenceFactory.h @@ -0,0 +1,92 @@ +/* + * SequenceFactory.h + * + * Copyright (C) ST-Ericsson SA 2011 + * Authors: Srimanta Panda , + * Ola Borgelin , + * Karin Hedlund , + * Markus Andersson for ST-Ericsson. + * License terms: 3-clause BSD license + * + */ + +/* + * @addtogroup SequenceFactory + * @{ + * + * Setup execution sequence for different mode (erase/flash). + */ + +#pragma once +#include "Config.h" +#include + +// Command class forward declaration +class Command; + +typedef std::vector CommandSequence_t; + +class SequenceFactory +{ +public: + /** + * @brief Sequence ID. + */ + enum SequenceId { + BOARD_FLASH, /**< Board flash sequence.> */ + BOARD_ERASE, /**< Board erase sequence. > */ + BOARD_DUMP /**< Board dump sequence. > */ + }; + + /** + * @brief Protocol type. + */ + enum UseBulk { + USE_COMMAND_PROTOCOL, /**< Use command protocol. > */ + USE_BULK_PROTOCOL /**< Use bulk protocol. > */ + }; + + /** + * @brief Delete buffer mode. + */ + enum DeleteBuffer { + DELETE_BUFFER_NO, /**< Don't delete buffer. > */ + DELETE_BUFFER_YES /**< Delete buffer. > */ + }; + + /** + * @brief Get new command sequence for the specified sequence ID. + * + * @param[in] id - ID of the sequence. + * @return Newly created command sequence. + */ + static CommandSequence_t getSequence(SequenceId id); + + /** + * @brief Get new command sequence for the sequence ID specified in the profile. + * + * @return Newly created command sequence. + */ + static CommandSequence_t getProfileSequence(); + + /** + * + */ + static void setArguments(const char* configPath, const char* mode, const char* flashImg, const char* address, const char* length, const char* dumpPath); + + static const char* configPath_; + static const char* flashmode_; + static const char* flashImgPath_; + static const char* dumpHostPath_; + static int address_; + static int length_; +private: + SequenceFactory(); + SequenceFactory(const SequenceFactory&); + ~SequenceFactory(); + + static const SequenceId defaultSequence_; + +}; + +/* @} */ diff --git a/riff/Shutdown.cpp b/riff/Shutdown.cpp new file mode 100755 index 0000000..3dcd1a9 --- /dev/null +++ b/riff/Shutdown.cpp @@ -0,0 +1,47 @@ +/* + * Shutdown.cpp + * + * Copyright (C) ST-Ericsson SA 2011 + * Authors: Srimanta Panda , + * Ola Borgelin , + * Karin Hedlund , + * Markus Andersson for ST-Ericsson. + * License terms: 3-clause BSD license + * + */ + +/* + * @addtogroup Commands + * @{ + */ + +#include "Shutdown.h" +#include "DUT.h" +using namespace System; + +Shutdown::Shutdown(): + logger_("ShutDown") +{ + +} + +int Shutdown::run(DUT* dut) +{ + logger_.log(Logger::INFO, "Shutting down device..."); + int error = System_Shutdown(dut->getLCDContext()); + if (0 != error) + { + logger_.log(Logger::ERROR,"LCD ERROR: Device shutdown failed %d", error); + return error; + } + + logger_.log(Logger::INFO, "Device shutdown finished successfully"); + return error; +} + +const char * Shutdown::get_command_name() +{ + return (char *)"SHUTDOWN"; +} + +/* @} */ diff --git a/riff/Shutdown.h b/riff/Shutdown.h new file mode 100755 index 0000000..812ffb5 --- /dev/null +++ b/riff/Shutdown.h @@ -0,0 +1,50 @@ +/* + * Shutdown.h + * + * Copyright (C) ST-Ericsson SA 2011 + * Authors: Srimanta Panda , + * Ola Borgelin , + * Karin Hedlund , + * Markus Andersson for ST-Ericsson. + * License terms: 3-clause BSD license + * + */ + +/* + * @addtogroup Commands + * @{ + */ + +#pragma once + +#include "Command.h" +#include "Logger.h" + +namespace System +{ +/** + * @brief Class implementing Shutdown command from System group. + */ +class Shutdown : public Command +{ +public: + /** + * @brief Default constructor taking no parameters. + */ + Shutdown(); + + /** + * @brief Method that executes the shutdown of the platform. + * + * @param[in] dut - Specific DUT instance on which to execute the command. + * @return int - Command execution error (0 on success, non-0 otherwise). + */ + int run(DUT* dut); + + const char * get_command_name(); +private: + Logger logger_; +}; +} + +/* @} */ diff --git a/riff/constants.h b/riff/constants.h new file mode 100755 index 0000000..28111af --- /dev/null +++ b/riff/constants.h @@ -0,0 +1,29 @@ +/* + * constants.h + * + * Copyright (C) ST-Ericsson SA 2011 + * Authors: Srimanta Panda , + * Ola Borgelin , + * Karin Hedlund , + * Markus Andersson for ST-Ericsson. + * License terms: 3-clause BSD license + * + */ + +/* + * @addtogroup Constants + * @{ + */ + +#pragma once + +namespace flash +{ +// flash archive type defined by the loader. +const char* const FLASH_ARCHIVE_TYPE = "x-empflash/flasharchive"; + +// device id +const char* const FLASH_DEVICE_TYPE = "/flash0"; +} + +/* @} */ diff --git a/riff/main.cpp b/riff/main.cpp new file mode 100755 index 0000000..076a65f --- /dev/null +++ b/riff/main.cpp @@ -0,0 +1,240 @@ +/* + * main.cpp + * + * Copyright (C) ST-Ericsson SA 2011 + * Authors: Srimanta Panda , + * Ola Borgelin , + * Karin Hedlund , + * Markus Andersson for ST-Ericsson. + * License terms: 3-clause BSD license + * + */ + +/* + * @addtogroup main + * @{ + */ +#include "main.h" +#include "CDAL.h" +#include "DutManager.h" +#include +#include +#include +#include +#include +#include +#include +using namespace std; + +bool isDone = false; +const string info = \ + "\n \ +----------------------- riff - Raw Image File Flasher -------------------------\n \ +Version: 0.4.1\n \ +" + "Flash a device. Try `riff --help' for more information. \n \ +" + "-------------------------------------------------------------------------------"; + +const string cmdHelpString = " \n \ +Usage: riff [OPTION]...[FILE]...\n\n \ +Available command line arguments are:\n\n \ + -h, --help\t Display this help message.\n \ + -m, --mode ACTION\t Select the mode.\n \ + ACTION is `flash`, `erase` or `dump`\n \ + -c, --config PATH\t Give path to configuration file.\n \ + -f, --flashimage IMAGEPATH\t Give path to flashimage.\n \ + -a, --address FLASHADDR\t Give a start address in hex.\n \ + -l, --length HEXLENGTH Length of the dump [Byte] in hex.\n \ + -d, --dumppath DUMPPATH File path on PC where to store dump.\n \ + -v, --verbose\t Shows more detailed information.\n \ + --version\t Shows version information.\n \ +"; + + +int main(int argc, char* argv[]) +{ + signal(SIGINT, interrupt); + + cout << info << endl; + + handleCmdLineInput(argc, argv); + + logger_ = new Logger("Application"); + logger_->log(Logger::INFO, "Using config file %s", configFile); + + //Parse the config file. + config_ = new Config(configFile); + + // if flashimage path has not been set from commandline + //then use the path in the config file if it is set there. + if (!strlen(flashimage)) { + if (config_->valueExists("FLASH_IMG_PATH")) { + strcpy(flashimage, config_->getValue("FLASH_IMG_PATH")); + } + } + + // Set the LCM path from ConfigFile, init the USB driver and set the callback function + SetLCMLibPath(config_->getValue("LCMLIBPATH")); + usb_init_driver(config_->getValue("VENDORID"), config_->getValue("PRODUCTID")); + usb_set_listen_callback(UsbDeviceEventCallback); + + + logger_->log(Logger::PROGRESS, "Listening on USB for device connection..."); + + while (!isDone) { + sleep(1); + } + + usb_deinit_driver(); + + _exit(exitstatus); +} + +void interrupt(int param) +{ + logger_->log(Logger::PROGRESS, "Program interrupted..."); + exitstatus = 1; + isDone = true; +} + +void UsbDeviceEventCallback(DeviceStatus_t status, DeviceEvent_t event, Device_t device) +{ + if (COMM_DEVICE_SUCCESS == status) { + const DUT* dut; + + switch (event) { + case LIBUSB_DEVICE_CONNECTED: + + logger_->log(Logger::INFO, "Device detected on USB@%u", comm_get_physical_address(device)); + dut = DutManager::createDut(device); + + if (0 != dut) { + logger_->log(Logger::PROGRESS, "Connected %s", dut->getId()); + } + + break; + case LIBUSB_DEVICE_DISCONNECTED: { + logger_->log(Logger::INFO, "Disconnect detected on USB@%u", comm_get_physical_address(device)); + dut = DutManager::getDut(device); + + if (0 != dut) { + exitstatus = dut->getErrorCode(); + logger_->log(Logger::PROGRESS, "Disconnected %s", dut->getId()); + DutManager::destroyDut(device); + } + + isDone = true; + } + break; + default: + logger_->log(Logger::ERROR, "Unknown USB event %d", event); + break; + } + } else { + logger_->log(Logger::ERROR, "USB device error %d", status); + } +} +void handleCmdLineInput(int argc, char* argv[]) +{ + string input; + bool configPathSet = false; + + for (int i = 1; i != argc; ++i) { + input = argv[i]; + + if ("-h" == input || "--help" == input) { + cout << cmdHelpString << endl; + _exit(0); + } + + else if ("-v" == input || "--verbose" == input) { + Logger::verbose_ = true; + } + + else if ("--version" == input) { + _exit(0); + } + + else if ("-m" == input || "--mode" == input) { + i = checkCmdLineArgument(argc, i, argv, mode); + } + + else if ("-c" == input || "--config" == input) { + configPathSet = true; + i = checkCmdLineArgument(argc, i, argv, configFile); + + } + + else if ("-f" == input || "--flashimage" == input) { + i = checkCmdLineArgument(argc, i, argv, flashimage); + } + + else if ("-a" == input || "--address" == input) { + i = checkCmdLineArgument(argc, i, argv, address); + } + + else if ("-l" == input || "--length" == input) { + i = checkCmdLineArgument(argc, i, argv, length); + } + + else if ("-d" == input || "--dumppath" == input) { + i = checkCmdLineArgument(argc, i, argv, dumpPath); + } else { + cout << "Unknown option: " << input << endl; + } + } + + if (!configPathSet) { + FILE* userConfig; + char* home = getenv("HOME"); + char homeConfigPath[50]; + strcpy(homeConfigPath, home); + strcat(homeConfigPath, "/.riff/config"); + + + userConfig = fopen(homeConfigPath, "rb"); + + if (userConfig != NULL) { + strcpy(configFile, homeConfigPath); + fclose(userConfig); + } + else + { + // It will check the default config in /usr/share folder otherwise + userConfig = fopen(configFile, "r"); + if(userConfig == NULL) + { + cout << cmdHelpString << endl; + _exit(0); + } + } + + + } + if (*dumpPath == '\0') { + //Sets default dump path if not provided + char* home = getenv("HOME"); + strcpy(dumpPath, home); + strcat(dumpPath, "/flashdump.bin"); + } + SequenceFactory::setArguments(configFile, mode, flashimage, address, length, dumpPath); +} + +int checkCmdLineArgument(int argc, int counter, char* argv[], char* var) +{ + counter++; + + if (counter < argc) + + { + strcpy(var, argv[counter]); + } else { + cout << "Please give a parameter to the option" << endl; + counter--; + } + + return counter; +} + +/* @} */ diff --git a/riff/main.h b/riff/main.h new file mode 100755 index 0000000..7826eb4 --- /dev/null +++ b/riff/main.h @@ -0,0 +1,75 @@ +/* + * main.h + * + * Copyright (C) ST-Ericsson SA 2011 + * Authors: Srimanta Panda , + * Ola Borgelin , + * Karin Hedlund , + * Markus Andersson for ST-Ericsson. + * License terms: 3-clause BSD license + * + */ + +/* + * @addtogroup main + * @{ + */ +#pragma once + +#include "CDAL.h" +#include "Config.h" +#include +#include "Logger.h" +#include +#define PATH_LENGTH 256 +#define MODE_STR_LENGTH 6 + +enum ConnectionType { + USB_CONNECTION, /**< USB connection. */ +}; + + +Logger* logger_; +Config* config_; +char configFile[PATH_LENGTH] = "/usr/share/riff/config"; +char flashimage[PATH_LENGTH] = "\0"; +char address[PATH_LENGTH] = "0"; +char length[PATH_LENGTH] = "0"; +char dumpPath[PATH_LENGTH] = "\0"; +char mode[MODE_STR_LENGTH]; +int exitstatus = 0; + +/** + * @brief USB device event callback function. + * + * This function is called when USB device is connected or disconnected. + * + * @param[in] status - Status of the device. + * @param[in] event - Event that was triggered. + * @param[in] device - The device that triggered the event. + */ +void UsbDeviceEventCallback(DeviceStatus_t status, DeviceEvent_t event, Device_t device); + +/** + * @brief Handling user commands from commandline + * + * This function is called to handle the commands typed by the user from commandline. + * + * @param[in] argc - number of inparameters + * @param[in] argv[] - inparameters given by user + */ +void handleCmdLineInput(int argc, char* argv[]); + +/** + * @brief Checking commandline arguments to the options + * + */ +int checkCmdLineArgument(int argc, int counter, char* argv[], char* var); + +/** + * @brief Handles user interupts (CTRL+C) + * + */ +void interrupt(int param); + +/* @} */ diff --git a/riff/riff.mk b/riff/riff.mk new file mode 100755 index 0000000..f083879 --- /dev/null +++ b/riff/riff.mk @@ -0,0 +1,85 @@ +# Makefile - riff + +CXX=g++ +CFLAGS=-I../os_wrappers -I../CDAL -D_FILE_OFFSET_BITS=64 +CXXFLAGS=$(CFLAGS) +LD=$(CXX) $(CXXFLAGS) +LDFLAGS=-L../CDAL +LIBS+=-llcdriver -lcdal -lstdc++ -lc + +ifndef TARGET +TARGET=riff +endif + +.PHONY: all +all: $(TARGET) + +%.o: %.cpp + $(CXX) $(CXXFLAGS) $(CPPFLAGS) -o $@ -c $< + +SOURCE_FILES= \ + ./Config.cpp \ + ./DumpArea.cpp \ + ./DUT.cpp \ + ./DUTManager.cpp \ + ./EraseArea.cpp \ + ./InitializeDut.cpp \ + ./Logger.cpp \ + ./main.cpp \ + ./ProcessRawImage.cpp \ + ./SequenceFactory.cpp \ + ./Shutdown.cpp \ + ../os_wrappers/CriticalSection.cpp \ + ../os_wrappers/Event.cpp \ + ../os_wrappers/Thread.cpp + +HEADER_FILES= \ + ./Command.h \ + ./Config.h \ + ./constants.h \ + ./DumpArea.h \ + ./DUT.h \ + ./DUTManager.h \ + ./EraseArea.h \ + ./InitializeDut.h \ + ./Logger.h \ + ./main.h \ + ./ProcessRawImage.h \ + ./SequenceFactory.h \ + ./Shutdown.h \ + ../os_wrappers/CriticalSection.h \ + ../os_wrappers/Event.h \ + ../os_wrappers/Thread.h \ + ../os_wrappers/Utilities.h \ + +OBJS= \ + ./Config.o \ + ./DumpArea.o \ + ./DUT.o \ + ./DutManager.o \ + ./EraseArea.o \ + ./InitializeDut.o \ + ./Logger.o \ + ./main.o \ + ./ProcessRawImage.o \ + ./SequenceFactory.o \ + ./Shutdown.o \ + ../os_wrappers/CriticalSection.o \ + ../os_wrappers/Event.o \ + ../os_wrappers/Thread.o \ + +SRCS=$(SOURCE_FILES) $(HEADER_FILES) + +$(TARGET): $(OBJS) + $(LD) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) + +.PHONY: clean +clean: + -rm -f -v $(OBJS) $(TARGET) riff.dep *.orig + +.PHONY: depends +depends: + -$(CXX) $(CXXFLAGS) $(CPPFLAGS) -MM $(filter %.c %.cc %.cpp %.cxx,$(SRCS)) > riff.dep + +-include riff.dep + -- cgit v1.2.3