summaryrefslogtreecommitdiff
path: root/riff/SequenceFactory.cpp
blob: 8c42f7831725f55392d3ccb9839a0f8beedcbd5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
 * SequenceFactory.cpp
 *
 * Copyright (C) ST-Ericsson SA 2011
 * Authors: Srimanta Panda <srimanta.panda@stericsson.com>,
 *          Ola Borgelin <ola.borgelin@stericsson.com>,
 *          Karin Hedlund <karin.hedlund@stericsson.com>,
 *          Markus Andersson <markus.m.andersson@stericsson.com> 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 <vector>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
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_);
    }
}

/* @} */