apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h
/*
* Copyright (c) 2013-15, 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.
*/
#pragma once
#include "afxwin.h"
#include <vector>
#include <array>
#include "../../common/blfwkdll/blfwkdll.h"
using namespace std;
class Bootloader : public CWinThread
{
public:
struct TargetInformation
{
UINT32 targetVersion;
UINT32 procotolVersion;
UINT32 securityState;
UINT32 flashSize;
UINT32 flashSectorSize;
UINT32 ramSize;
UINT32 rsvRgnFlashStart;
UINT32 rsvRgnFlashEnd;
UINT32 rsvRgnRamStart;
UINT32 rsvRgnRamEnd;
UINT32 supportedCmd;
};
struct FlashFirmwareOption
{
BOOL autoConnect;
BOOL doErasetoUnlock;
BOOL useKeytoUnlock;
std::string backdoorkey;
std::string imageFilePath;
uint32_t baseAddress;
};
struct EraseOption
{
enum ERASE_OPERATION
{
erase_region = 0,
erase_all = 1,
erase_all_and_unsecure = 2
};
ERASE_OPERATION option;
uint32_t memoryID;
uint32_t startAddress;
uint32_t length;
};
struct ProgramOnceOption
{
uint32_t index;
uint32_t byteCount;
std::string data;
};
public:
Bootloader() { this->Open(); };
virtual ~Bootloader() { this->Close(); };
virtual BOOL InitInstance() { return CWinThread::InitInstance(); };
virtual int ExitInstance() { return CWinThread::ExitInstance(); };
enum KibbleStatusCode
{
KBL_Status_Success = 0x0,
KBL_Status_AbortDataPhase = 0x2712,
};
bool CanRun();
DWORD Open();
void Close();
static void progressCallback(int percentage, int segmentIndex, int segmentCount);
DWORD WaitForEvents(DWORD time);
void ResetEvents(DWORD events);
void Ping();
void Reset();
void Connect(blfwkdll::Updater::PeripheralConfig *config);
void UpdateStatus();
void UpdateImage(blfwkdll::Updater::PeripheralConfig *config, FlashFirmwareOption *option);
void Erase(EraseOption *option);
void ProgramOnce(ProgramOnceOption *option);
HANDLE m_pingEvent;
HANDLE m_statusEvent;
HANDLE m_resetEvent;
HANDLE m_connectEvent;
HANDLE m_updateEvent;
HANDLE m_eraseEvent;
HANDLE m_programOnceEvent;
HANDLE m_exitEvent;
CWinThread *m_pThread;
bool m_abort;
bool m_isRunning;
bool m_isExiting;
bool m_isConneted;
TargetInformation m_targetInfo;
FlashFirmwareOption m_firmwareConfig;
EraseOption m_eraseOption;
ProgramOnceOption m_programOnceOption;
blfwkdll::Updater::PeripheralConfig m_config;
blfwkdll::Updater *m_updater;
};
extern Bootloader *g_pBootloader;
Bootloader::EraseOption::length
uint32_t length
Length in bytes to erase.
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:91
Bootloader::ProgramOnceOption::data
std::string data
IFR data to write. 4 or 8 hex digits with on leading "0x".
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:101
Bootloader::EraseOption::memoryID
uint32_t memoryID
Memory ID used for flash-erase-all command.
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:89
Bootloader::EraseOption::startAddress
uint32_t startAddress
Start address to erase.
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:90
Bootloader::FlashFirmwareOption::baseAddress
uint32_t baseAddress
Base address where image file is written to.(Only used for binary file.)
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:73
Bootloader::TargetInformation::ramSize
UINT32 ramSize
RAM memory size.
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:55
Bootloader::FlashFirmwareOption
FlashFirmwareOption struct contains information for an update progress.
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:66
Bootloader::TargetInformation::rsvRgnFlashEnd
UINT32 rsvRgnFlashEnd
End address of flash reserved region.
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:57
Bootloader::FlashFirmwareOption::imageFilePath
std::string imageFilePath
Absolute path for image file.
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:72
Bootloader::m_isConneted
bool m_isConneted
Flag is set when connect to a target device.
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:201
Bootloader::Bootloader
Bootloader()
Generated standard constructor.
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:106
Bootloader::TargetInformation::flashSectorSize
UINT32 flashSectorSize
Flash memory sector size.
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:54
Bootloader::m_statusEvent
HANDLE m_statusEvent
Update status event.
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:189
Bootloader::m_config
blfwkdll::Updater::PeripheralConfig m_config
Contains information for peripheral configuration.
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:206
std
STL namespace.
Bootloader::~Bootloader
virtual ~Bootloader()
Generated standard destructor.
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:108
Bootloader::TargetInformation::rsvRgnFlashStart
UINT32 rsvRgnFlashStart
Start address of flash reserved region.
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:56
Bootloader::TargetInformation::targetVersion
UINT32 targetVersion
Bootloader version.
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:50
Bootloader::TargetInformation::rsvRgnRamStart
UINT32 rsvRgnRamStart
Start address of RAM reserved region.
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:58
Bootloader::TargetInformation::rsvRgnRamEnd
UINT32 rsvRgnRamEnd
End address of RAM reserved region.
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:59
Bootloader::ProgramOnceOption::byteCount
uint32_t byteCount
IFR length( should be 4 or 8).
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:100
Bootloader::m_connectEvent
HANDLE m_connectEvent
Connect event.
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:191
Bootloader::EraseOption::ERASE_OPERATION
ERASE_OPERATION
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:81
Bootloader::TargetInformation::supportedCmd
UINT32 supportedCmd
Current device supported command.
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:60
Bootloader::m_eraseEvent
HANDLE m_eraseEvent
Erase event.
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:193
Bootloader::FlashFirmwareOption::backdoorkey
std::string backdoorkey
Backdoor key.
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:71
Bootloader::m_exitEvent
HANDLE m_exitEvent
Exit event to let child thread exit.
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:195
Bootloader::m_pThread
CWinThread * m_pThread
Pointer to child thread.
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:196
Bootloader::TargetInformation::flashSize
UINT32 flashSize
Flash memory size.
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:53
Bootloader::KibbleStatusCode
KibbleStatusCode
KibbleStatusCode struct contains two correct status code.
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:116
Bootloader::EraseOption::option
ERASE_OPERATION option
Erase operation..
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:88
Bootloader::m_programOnceEvent
HANDLE m_programOnceEvent
Program IFR event.
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:194
Bootloader::ProgramOnceOption
ProgramOnceOption struct contains information for a program IFR progress.
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:97
Bootloader::ExitInstance
virtual int ExitInstance()
Overrides.
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:112
Bootloader
Bootloader class.
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:42
Bootloader::FlashFirmwareOption::autoConnect
BOOL autoConnect
Auto connect device after an update, if set TRUE.(Currently, not used)
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:68
Bootloader::m_pingEvent
HANDLE m_pingEvent
Ping event.
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:188
Bootloader::EraseOption
EraseOption struct contains information for an erase progress.
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:79
Bootloader::m_isExiting
bool m_isExiting
Flag is set to let child thread exit.
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:200
Bootloader::FlashFirmwareOption::useKeytoUnlock
BOOL useKeytoUnlock
Execute flash-security-disable to unlock the device.
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:70
Bootloader::TargetInformation::securityState
UINT32 securityState
Security state.
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:52
Bootloader::FlashFirmwareOption::doErasetoUnlock
BOOL doErasetoUnlock
Execute flash-erase-all-unsecure to unlock the device.
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:69
Bootloader::m_resetEvent
HANDLE m_resetEvent
Reset event.
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:190
Bootloader::m_updater
blfwkdll::Updater * m_updater
Pointer to a blfwkdll::Updater.
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:207
Bootloader::m_targetInfo
TargetInformation m_targetInfo
Contains devices information.
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:202
Bootloader::m_updateEvent
HANDLE m_updateEvent
Update event.
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:192
Bootloader::m_isRunning
bool m_isRunning
Flag is set when there is an operation under processing.
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:199
Bootloader::m_programOnceOption
ProgramOnceOption m_programOnceOption
Contains information for a programming-IFR operation.
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:205
Bootloader::TargetInformation::procotolVersion
UINT32 procotolVersion
Serial procotol version.
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:51
Bootloader::m_eraseOption
EraseOption m_eraseOption
Contains information for an erase operation.
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:204
Bootloader::InitInstance
virtual BOOL InitInstance()
Overrides.
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:110
Bootloader::m_firmwareConfig
FlashFirmwareOption m_firmwareConfig
Contains information for a update operation.
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:203
Bootloader::m_abort
bool m_abort
Flag is set to abort the update progress.
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:198
Bootloader::ProgramOnceOption::index
uint32_t index
IFR index.
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:99
Bootloader::TargetInformation
TargetInformation struct contains devices information.
Definition: apps/KinetisFlashTool/KinetisFlashTool/Bootloader.h:48