Updater.h
/*
* Copyright (c) 2013-14, Freescale Semiconductor, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* o Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
*
* o Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#if !defined(_Updater_h_)
#define _Updater_h_
#include "Bootloader.h"
#include "SourceFile.h"
using namespace blfwk;
namespace blfwk
{
struct updater_enum_t
{
uint32_t value;
std::string description;
updater_enum_t()
: value(0)
, description("")
{
}
updater_enum_t(uint32_t value, const char *description)
: value(value)
, description(description)
{
}
updater_enum_t(const updater_enum_t &old_enum)
{
value = old_enum.value;
description = old_enum.description.c_str();
}
};
const updater_enum_t kUpdaterState_NotReady(0, "Not ready");
const updater_enum_t kUpdaterState_Ready(1, "Ready");
const updater_enum_t kUpdaterState_Working(2, "Working");
const updater_enum_t kUpdaterState_Idle(3, "Idle");
const updater_enum_t kUpdaterState_Complete(4, "Complete");
const updater_enum_t kUpdaterTask_Erasing(0, "Erasing");
const updater_enum_t kUpdaterTask_Flashing(1, "Writing");
const updater_enum_t kUpdaterTask_Reseting(2, "Reseting");
const updater_enum_t kUpdaterTask_Executing(3, "Jumping");
struct updater_task_t
{
updater_enum_t task_desc;
uint32_t current;
uint32_t total;
updater_task_t(const updater_enum_t &task_desc, uint32_t total)
: task_desc(task_desc)
, current(0)
, total(total)
{
}
updater_task_t()
: task_desc()
, current(0)
, total(0)
{
}
};
typedef std::vector<updater_task_t> updater_task_vector_t;
const updater_enum_t kUpdaterOperation_Update(0, "Update");
struct updater_operation_t
{
updater_enum_t operation_desc;
updater_task_vector_t tasks;
uint32_t current_task;
bool user_stopped;
uint32_t current()
{
uint32_t current = 0;
for (uint32_t i = 0; i < current_task; ++i)
{
current += tasks[i].total;
}
current += tasks[current_task].current;
return current;
}
uint32_t total()
{
uint32_t total = 0;
for (uint32_t i = 0; i < tasks.size(); ++i)
{
total += tasks[i].total;
}
return total;
}
updater_operation_t(updater_enum_t operation_desc)
: operation_desc(operation_desc)
, tasks()
, current_task(0)
, user_stopped(false)
{
}
updater_operation_t(uint32_t value, const char *description)
: operation_desc(value, description)
, tasks()
, current_task(0)
, user_stopped(false)
{
}
};
class Updater : public Bootloader
{
public:
Updater(const Peripheral::PeripheralConfigData &config);
virtual ~Updater();
typedef void (*progress_callback_t)(updater_operation_t *op);
updater_operation_t m_operation;
void setCallback(progress_callback_t callback) { m_progressCallback = callback; }
void registerCallback(void (*callback)(int, int, int), bool *abort)
{
m_progress.registerCallback(callback, abort);
}
status_t flashFirmware(const char *filename, uint32_t base_address);
void eraseAllUnsecure();
void unlock(string backdoor_key);
bool isCommandSupported(const cmd_t &command);
//
uint32_vector_t getProperty(property_t tag);
uint32_t getSectorSize() { return m_sector_size; };
uint32_t getFlshSize() { return m_flashSize; };
void eraseFlashRegion(uint32_t start, uint32_t length);
void eraseFlashAll(uint32_t memoryId);
void programOnce(uint32_t index, uint32_t byteCount, string data);
//
protected:
void writeMemory(DataSource::Segment *segment);
void writeMemory(uint32_t address, const uchar_vector_t &data);
status_t flashFromSourceFile();
status_t flashFromSBFile(const char *filename);
protected:
uint32_t m_base_address;
uint32_t m_sector_size;
uint32_t m_flashStart;
uint32_t m_flashSize;
SourceFile *m_sourceFile;
progress_callback_t m_progressCallback;
Progress m_progress;
};
}; // namespace blfwk
#endif // _Updater_h_
blfwk::Updater::m_sourceFile
SourceFile * m_sourceFile
SourceFile object.
Definition: Updater.h:315
blfwk::Bootloader
Represents the host bootloader.
Definition: src/blfwk/Bootloader.h:52
blfwk::Updater::m_progress
Progress m_progress
Progress control.
Definition: Updater.h:317
blfwk
Definition: BlfwkErrors.h:16
blfwk::Updater
Update class contains the functionality necessary to update the firmware on a device running Bootload...
Definition: Updater.h:167
blfwk::Updater::getFlshSize
uint32_t getFlshSize()
get Device&#39;s flash size.
Definition: Updater.h:252
blfwk::Updater::m_sector_size
uint32_t m_sector_size
Sector size of the flash on the device.
Definition: Updater.h:312
blfwk::Updater::m_base_address
uint32_t m_base_address
Base address of the image.
Definition: Updater.h:311
blfwk::Updater::m_operation
updater_operation_t m_operation
Struct used to monitor the Operation progress.
Definition: Updater.h:182
blfwk::Updater::m_flashSize
uint32_t m_flashSize
The flash size (in bytes) of the device.
Definition: Updater.h:314
blfwk::cmd_t
Definition: Command.h:53
blfwk::updater_operation_t
Definition: Updater.h:111
blfwk::updater_task_t
Definition: Updater.h:82
blfwk::updater_enum_t
Definition: Updater.h:45
blfwk::SourceFile
Abstract base class for a source file containing executable code.
Definition: src/blfwk/SourceFile.h:56
blfwk::Updater::getSectorSize
uint32_t getSectorSize()
get Device&#39;s flash sector size.
Definition: Updater.h:248
blfwk::DataSource::Segment
Discrete, contiguous part of the source&#39;s data.
Definition: src/blfwk/DataSource.h:65
blfwk::Progress
Contains the callback function for progress and abort phase.
Definition: Command.h:225
blfwk::Updater::setCallback
void setCallback(progress_callback_t callback)
Set the user-defined function to call on progress events.
Definition: Updater.h:187
blfwk::property_t
Definition: Command.h:117
blfwk::Updater::m_flashStart
uint32_t m_flashStart
Start address of the flash on the device.
Definition: Updater.h:313
blfwk::Updater::registerCallback
void registerCallback(void(*callback)(int, int, int), bool *abort)
Set callback for progress and abort control.
Definition: Updater.h:192
blfwk::Updater::m_progressCallback
progress_callback_t m_progressCallback
Callback used to report update progress.
Definition: Updater.h:316
blfwk::Peripheral::PeripheralConfigData
Definition: Peripheral.h:60