Add KBOOT.

This commit is contained in:
László Monda
2016-08-10 01:45:15 +02:00
commit e6c1fce5b4
9392 changed files with 3751375 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.24720.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "KinetisFlashTool", "KinetisFlashTool\KinetisFlashTool.vcxproj", "{864CBA51-EAF2-491E-9C74-4791B49FE039}"
ProjectSection(ProjectDependencies) = postProject
{DE64A8C3-695A-491F-B3E3-24D6A3057A40} = {DE64A8C3-695A-491F-B3E3-24D6A3057A40}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "blfwkdll", "..\common\blfwkdll\blfwkdll.vcxproj", "{426D14FE-6F2B-442D-893D-B5730DD6941F}"
ProjectSection(ProjectDependencies) = postProject
{DE64A8C3-695A-491F-B3E3-24D6A3057A40} = {DE64A8C3-695A-491F-B3E3-24D6A3057A40}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "blfwk", "..\common\blfwkdll\blfwk.vcxproj", "{DE64A8C3-695A-491F-B3E3-24D6A3057A40}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{864CBA51-EAF2-491E-9C74-4791B49FE039}.Debug|x64.ActiveCfg = Debug|Win32
{864CBA51-EAF2-491E-9C74-4791B49FE039}.Debug|x64.Build.0 = Debug|Win32
{864CBA51-EAF2-491E-9C74-4791B49FE039}.Debug|x86.ActiveCfg = Debug|Win32
{864CBA51-EAF2-491E-9C74-4791B49FE039}.Debug|x86.Build.0 = Debug|Win32
{864CBA51-EAF2-491E-9C74-4791B49FE039}.Release|x64.ActiveCfg = Release|Win32
{864CBA51-EAF2-491E-9C74-4791B49FE039}.Release|x64.Build.0 = Release|Win32
{864CBA51-EAF2-491E-9C74-4791B49FE039}.Release|x86.ActiveCfg = Release|Win32
{864CBA51-EAF2-491E-9C74-4791B49FE039}.Release|x86.Build.0 = Release|Win32
{426D14FE-6F2B-442D-893D-B5730DD6941F}.Debug|x64.ActiveCfg = Debug|Win32
{426D14FE-6F2B-442D-893D-B5730DD6941F}.Debug|x64.Build.0 = Debug|Win32
{426D14FE-6F2B-442D-893D-B5730DD6941F}.Debug|x86.ActiveCfg = Debug|Win32
{426D14FE-6F2B-442D-893D-B5730DD6941F}.Debug|x86.Build.0 = Debug|Win32
{426D14FE-6F2B-442D-893D-B5730DD6941F}.Release|x64.ActiveCfg = Release|Win32
{426D14FE-6F2B-442D-893D-B5730DD6941F}.Release|x64.Build.0 = Release|Win32
{426D14FE-6F2B-442D-893D-B5730DD6941F}.Release|x86.ActiveCfg = Release|Win32
{426D14FE-6F2B-442D-893D-B5730DD6941F}.Release|x86.Build.0 = Release|Win32
{DE64A8C3-695A-491F-B3E3-24D6A3057A40}.Debug|x64.ActiveCfg = Debug|Win32
{DE64A8C3-695A-491F-B3E3-24D6A3057A40}.Debug|x64.Build.0 = Debug|Win32
{DE64A8C3-695A-491F-B3E3-24D6A3057A40}.Debug|x86.ActiveCfg = Debug|Win32
{DE64A8C3-695A-491F-B3E3-24D6A3057A40}.Debug|x86.Build.0 = Debug|Win32
{DE64A8C3-695A-491F-B3E3-24D6A3057A40}.Release|x64.ActiveCfg = Release|Win32
{DE64A8C3-695A-491F-B3E3-24D6A3057A40}.Release|x64.Build.0 = Release|Win32
{DE64A8C3-695A-491F-B3E3-24D6A3057A40}.Release|x86.ActiveCfg = Release|Win32
{DE64A8C3-695A-491F-B3E3-24D6A3057A40}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,210 @@
/*
* 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;
/*!
* \brief Bootloader class.
*/
class Bootloader : public CWinThread
{
public:
/*!
* \brief TargetInformation struct contains devices information.
*/
struct TargetInformation
{
UINT32 targetVersion; //!< Bootloader version.
UINT32 procotolVersion; //!< Serial procotol version.
UINT32 securityState; //!< Security state.
UINT32 flashSize; //!< Flash memory size.
UINT32 flashSectorSize; //!< Flash memory sector size.
UINT32 ramSize; //!< RAM memory size.
UINT32 rsvRgnFlashStart; //!< Start address of flash reserved region.
UINT32 rsvRgnFlashEnd; //!< End address of flash reserved region.
UINT32 rsvRgnRamStart; //!< Start address of RAM reserved region.
UINT32 rsvRgnRamEnd; //!< End address of RAM reserved region.
UINT32 supportedCmd; //!< Current device supported command.
};
/*!
* \brief FlashFirmwareOption struct contains information for an update progress.
*/
struct FlashFirmwareOption
{
BOOL autoConnect; //!< Auto connect device after an update, if set TRUE.(Currently, not used)
BOOL doErasetoUnlock; //!< Execute flash-erase-all-unsecure to unlock the device.
BOOL useKeytoUnlock; //!< Execute flash-security-disable to unlock the device.
std::string backdoorkey; //!< Backdoor key
std::string imageFilePath; //!< Absolute path for image file.
uint32_t baseAddress; //!< Base address where image file is written to.(Only used for binary file.)
};
/*!
* \brief EraseOption struct contains information for an erase progress.
*/
struct EraseOption
{
enum ERASE_OPERATION
{
erase_region = 0, //!< Execute flash-erase-region.
erase_all = 1, //!< Execute flash-erase-all.
erase_all_and_unsecure = 2 //!< Execute flash-erase-all-unsecure.
};
ERASE_OPERATION option; //!< Erase operation..
uint32_t memoryID; //!< Memory ID used for flash-erase-all command.
uint32_t startAddress; //!< Start address to erase.
uint32_t length; //!< Length in bytes to erase.
};
/*!
* \brief ProgramOnceOption struct contains information for a program IFR progress.
*/
struct ProgramOnceOption
{
uint32_t index; //!< IFR index.
uint32_t byteCount; //!< IFR length( should be 4 or 8).
std::string data; //!< IFR data to write. 4 or 8 hex digits with on leading "0x".
};
public:
//! \brief Generated standard constructor.
Bootloader() { this->Open(); };
//! \brief Generated standard destructor.
virtual ~Bootloader() { this->Close(); };
//! \brief Overrides.
virtual BOOL InitInstance() { return CWinThread::InitInstance(); };
//! \brief Overrides.
virtual int ExitInstance() { return CWinThread::ExitInstance(); };
/*!
* \brief KibbleStatusCode struct contains two correct status code.
*/
enum KibbleStatusCode
{
KBL_Status_Success = 0x0, //!< Success status.
KBL_Status_AbortDataPhase = 0x2712, //!< AbortDataPhase. This status will be received when executing RESET or
//! EXECUTE command in a SB file successfully.
};
/*!
* \brief Return whether currently a new operation can be processed.
*/
bool CanRun();
/*!
* \brief Do initialization and create a child thread.
*/
DWORD Open();
/*!
* \brief Do deinitialization and wait for child thread exit.
*/
void Close();
/*!
* \brief the callback function to update the progress.
*/
static void progressCallback(int percentage, int segmentIndex, int segmentCount);
/*!
* \brief Wait an event to be triggered.
*/
DWORD WaitForEvents(DWORD time);
/*!
* \brief Reset the triggered event after the corresponding progress is done.
*/
void ResetEvents(DWORD events);
/*!
* \brief Triggered a ping even to text the connection.
*/
void Ping();
/*!
* \brief Triggered a reset even, and disconnect target device.
*/
void Reset();
/*!
* \brief Triggered a connect even, and try to connect target device.
*/
void Connect(blfwkdll::Updater::PeripheralConfig *config);
/*!
* \brief Triggered a updatestatue even to collect device information.
*/
void UpdateStatus();
/*!
* \brief Triggered a update even to do a update progress.
*/
void UpdateImage(blfwkdll::Updater::PeripheralConfig *config, FlashFirmwareOption *option);
/*!
* \brief Triggered an erase even.
*/
void Erase(EraseOption *option);
/*!
* \brief Triggered an programming ifr even.
*/
void ProgramOnce(ProgramOnceOption *option);
HANDLE m_pingEvent; //!< Ping event.
HANDLE m_statusEvent; //!< Update status event.
HANDLE m_resetEvent; //!< Reset event.
HANDLE m_connectEvent; //!< Connect event.
HANDLE m_updateEvent; //!< Update event.
HANDLE m_eraseEvent; //!< Erase event.
HANDLE m_programOnceEvent; //!< Program IFR event.
HANDLE m_exitEvent; //!< Exit event to let child thread exit.
CWinThread *m_pThread; //!< Pointer to child thread.
bool m_abort; //!< Flag is set to abort the update progress.
bool m_isRunning; //!< Flag is set when there is an operation under processing.
bool m_isExiting; //!< Flag is set to let child thread exit.
bool m_isConneted; //!< Flag is set when connect to a target device.
TargetInformation m_targetInfo; //!< Contains devices information.
FlashFirmwareOption m_firmwareConfig; //!< Contains information for a update operation.
EraseOption m_eraseOption; //!< Contains information for an erase operation.
ProgramOnceOption m_programOnceOption; //!< Contains information for a programming-IFR operation.
blfwkdll::Updater::PeripheralConfig m_config; //!< Contains information for peripheral configuration.
blfwkdll::Updater *m_updater; //!< Pointer to a blfwkdll::Updater.
};
extern Bootloader *g_pBootloader; //!< Global pointer for bootloader.

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,113 @@
/*
* 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 "../../common/blfwkdll/blfwkdll.h"
// BootloaderConfigDlg dialog
/*!
* \brief BootloaderConfigDlg class is the UI Dialog class for the
* bootloader configuration page
*/
class BootloaderConfigDlg : public CDialogEx
{
DECLARE_DYNAMIC(BootloaderConfigDlg)
public:
//! \brief Generated standard constructor.
BootloaderConfigDlg(CWnd *pParent = NULL); // standard constructor
//! \brief Custom constructor
//!
//! \param config A pointer to BCA data memory.
//! (Must be specified)
//!
//! \param file A file pointer to the binary image, used for CRC calculation.
//! (Must be specified.)
//!
//! \param pParent the father dialog pointer.
BootloaderConfigDlg(blfwkdll::BootloaderConfigureAreaData *config, CFile *file, CWnd *pParent = NULL)
: CDialogEx(IDD_DIALOG_BOOTLOADERCONFIG, pParent)
{
m_config = config;
m_cFile = file;
};
//! \brief Generated standard destructor.
virtual ~BootloaderConfigDlg();
// Dialog Data
#ifdef AFX_DESIGN_TIME
enum
{
IDD = IDD_DIALOG_BOOTLOADERCONFIG
};
#endif
//! \brief Generated message map functions.
protected:
virtual void DoDataExchange(CDataExchange *pDX); // DDX/DDV support
DECLARE_MESSAGE_MAP()
virtual void OnOK();
public:
virtual BOOL OnInitDialog();
afx_msg void OnBnClickedCheckCrc();
afx_msg void OnBnClickedCheckI2cslaveAddress();
afx_msg void OnBnClickedCheckTimeout();
afx_msg void OnBnClickedCheckVid();
afx_msg void OnBnClickedCheckPid();
afx_msg void OnBnClickedCheckUsbstringPointer();
afx_msg void OnBnClickedCheckDisableHighspeed();
afx_msg void OnBnClickedCheckMmcauPointer();
afx_msg void OnBnClickedCheckOtfadPointer();
afx_msg void OnBnClickedCheckQspiPointer();
afx_msg void OnBnClickedCheckCantxid();
afx_msg void OnBnClickedCheckCanrxid();
afx_msg void OnBnClickedCheckCanspeed();
afx_msg void OnBnClickedRadioSpeedindex();
afx_msg void OnBnClickedReload();
afx_msg void OnBnClickedButtonConfigOk();
afx_msg void OnBnClickedButtonConfigCancel();
afx_msg void OnBnClickedButtonConfigGenerate();
public:
//! \brief Load BCA data to UI page.
void LoadBootloaderConfigureArea();
//! \brief Save UI config data to BCA.
//!
//! \return OnOK for success, OnCancel for failure.
int SaveBootloaderConfigureArea();
protected:
blfwkdll::BootloaderConfigureAreaData *m_config; //!< A pointer to BCA data.
CFile *m_cFile; //!< A pointer to the binary file, used for crc calculation.
};

View File

@@ -0,0 +1,199 @@
/*
* 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
char code_section1[] =
"/*\n\
* Copyright (c) 2013 - 15, Freescale Semiconductor, Inc.\n\
* All rights reserved\n\
*\n\
* Redistribution and use in source and binary forms, with or without modification,\n\
*are permitted provided that the following conditions are met :\n\
*\n\
* o Redistributions of source code must retain the above copyright notice, this list\n\
* of conditions and the following disclaimer.\n\
*\n\
* o Redistributions in binary form must reproduce the above copyright notice, this\n\
* list of conditions and the following disclaimer in the documentation and / or\n\
* other materials provided with the distribution.\n\
*\n\
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its\n\
* contributors may be used to endorse or promote products derived from this\n\
* software without specific prior written permission.\n\
*\n\
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND\n\
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n\
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n\
* DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR\n\
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n\
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n\
*LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON\n\
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n\
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\n\
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\
*/\n\
\n\
/*!\n\
* @brief Device specific configuration file for Kinetis bootloader\n\
*\n\
* Provides a bootloader configuration structure and a global variable that\n\
* contains\n\
* the system bootloader configuration data.\n\
*/\n\
\n\
#include <stdint.h>\n\
\n\
/*!\n\
* @brief Defines the structure to set the Bootloader Configuration Area\n\
*\n\
* This type of variable is used to set the Bootloader Configuration Area\n\
* of the chip.\n\
*\n\
* Warning: some configuration may not work on the devices that donot support \n\
* corresponding feature.\n\
*/\n\
typedef struct BootloaderConfiguration\n\
{\n\
uint32_t tag; //!< [00:03] Magic number to verify bootloader configuration is\n\
//! valid. Must be set to 'kcfg'.\n\
uint32_t crcStartAddress; //!< [04:07] Start address for application image CRC\n\
//! check. If the bits are all set then Kinetis\n\
//! bootloader by default will not perform any CRC \n\
//! check.\n\
uint32_t crcByteCount; //!< [08:0b] Byte count for application image CRC\n\
//! check. If the bits are all set then Kinetis\n\
//! bootloader by default will not prform any CRC check.\n\
uint32_t crcExpectedValue; //!< [0c:0f] Expected CRC value for application CRC\n\
//! check. If the bits are all set then Kinetis\n\
//! bootloader by default will not perform any CRC\n\
//! check.\n\
uint8_t enabledPeripherals; //!< [10:10] Bitfield of peripherals to enable.\n\
//! bit 0 - LPUART, bit 1 - I2C, bit 2 - SPI,\n\
//! bit 3 - CAN, bit 4 - USB\n\
//! Kinetis bootloader will enable the peripheral if\n\
//! corresponding bit is set to 1.\n\
uint8_t i2cSlaveAddress; //!< [11:11] If not 0xFF, used as the 7-bit I2C slave\n\
//! address. If 0xFF, defaults to 0x10\n\
//! for I2C slave address.\n\
uint16_t peripheralDetectionTimeoutMs; //!< [12:13] Timeout in milliseconds\n\
//! for active peripheral detection. If\n\
//! 0xFFFF, defaults to 5 seconds.\n\
uint16_t usbVid; //!< [14:15] Sets the USB Vendor ID reported by the device\n\
//! during enumeration. If 0xFFFF, it defaults to 0x15A2.\n\
uint16_t usbPid; //!< [16:17] Sets the USB Product ID reported by the device\n\
//! during enumeration.\n\
uint32_t usbStringsPointer; //!< [18:1b] Sets the USB Strings reported by the\n\
//! device during enumeration.\n\
uint8_t clockFlags; //!< [1c:1c] The flags in the clockFlags configuration\n\
//! field are enabled if the corresponding bit is cleared (0).\n\
//! bit 0 - HighSpeed Enable high speed mode (i.e., 48 MHz).\n\
uint8_t clockDivider; //!< [1d:1d] Inverted value of the divider to use for\n\
//! core and bus clocks when in high speed mode.\n\
uint8_t bootFlags; //!< [1e:1e] If bit 0 is cleared, then Kinetis bootloader\n\
//! will jump to either Quad SPI Flash or internal flash\n\
//! image depending on FOPT BOOTSRC_SEL bits.\n\
//! If the bit is set, then Kinetis bootloader will prepare\n\
//! for host communication over serial peripherals.\n\
uint8_t pad0; //!< [1f:1f] Reserved, set to 0xFF\n\
uint32_t mmcauConfigPointer; //!< [20:23] A pointer to the MMCAU configuration\n\
//! structure in memory.\n\
uint32_t keyBlobPointer; //!< [24:27]Holds a pointer value to the key blob\n\
//! array used to configure OTFAD\n\
uint8_t pad1; //!< [28:28] reserved\n\
uint8_t canConfig1; //!< [29:29] ClkSel[1], PropSeg[3], SpeedIndex[4]\n\
uint16_t canConfig2; //!< [2a:2b] Pdiv[8], Pseg1[3], Pseg2[3], rjw[2]\n\
uint16_t canTxId; //!< [2c:2d] txId\n\
uint16_t canRxId; //!< [2e:2f] rxId\n\
uint32_t qspi_config_block_pointer; //!< [30:33] A pointer to the QSPI config\n\
//! block in internal flash array.\n\
uint32_t reserved[3]; //!<[34:3f] reserved\n\
} bootloader_config_t;\n\
\n\
/*\n\
* Warning: To enable bootloader configuration, User still needs two extra steps :\n\
*\n\
* Step1 : Enable BOOTLOADER_CONFIG.\n\
* Example : #define BOOTLOADER_CONFIG 1\n\
*\n\
* Step2 : Add configuration of the section \"BootloaderConfig\" to your\n\
* linker configuration file.\n\
* Example(IAR) :\n\
* define symbol __application_startaddress = 0; // User-defined\n\
* define symbol m_bootloader_config_start = __application_startaddress + 0x3C0;\n\
* define symbol m_bootloader_config_end = __application_startaddress + 0x3FF;\n\
* define region m_bootloader_config_region = mem:[from m_bootloader_config_start to m_bootloader_config_end];\n\
* place in m_bootloader_config_region{ section BootloaderConfig };\n\
*\n\
* Example(Keil) :\n\
* #define __application_startaddress = 0 // User-defined\n\
* #define m_bootloader_config_start __application_startaddress + 0x3C0\n\
* #define m_bootloader_config_size 0x00000040\n\
*\n\
* LR_m_bootloader_config m_bootloader_config_start m_bootloader_config_size{\n\
* ER_m_bootloader_config m_bootloader_config_start m_bootloader_config_size{ ; load address = execution address\n\
* * (BootloaderConfig)\n\
* }\n\
* }\n\
*\n\
* Example(ARM - GCC) :\n\
* MEMORY\n\
* {\n\
* m_bootloader_config(RX) : ORIGIN = 0x000003C0, LENGTH = 0x00000040\n\
* }\n\
* .bootloader_config :\n\
* {\n\
* . = ALIGN(4);\n\
* KEEP(*(.BootloaderConfig)) // Bootloader Configuration Area (BCA)\n\
* . = ALIGN(4);\n\
* } > m_bootloader_config\n\
*\n\
*/\n\
\n\
#ifdef BOOTLOADER_CONFIG\n\
/* Bootlader configuration area */\n\
#if defined(__IAR_SYSTEMS_ICC__)\n\
/* Pragma to place the Bootloader Configuration Array on correct location\n\
* defined in linker file. */\n\
#pragma language = extended\n\
#pragma location = \"BootloaderConfig\"\n\
__root const bootloader_config_t BootloaderConfig @\"BootloaderConfig\" =\n\
#elif defined(__GNUC__)\n\
__attribute__((section(\".BootloaderConfig\"))) const bootloader_config_t BootloaderConfig =\n\
#elif defined(__CC_ARM)\n\
__attribute__((section(\"BootloaderConfig\"))) const bootloader_config_t BootloaderConfig __attribute__((used)) =\n\
#else\n\
#error Unsupported compiler!\n\
#endif\n\
{";
char code_section2[] =
"\n };\n\
#endif";

View File

@@ -0,0 +1,399 @@
/*
* 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.
*/
#include "stdafx.h"
#include "KinetisFlashTool.h"
#include "ConfigDlg.h"
#include "afxdialogex.h"
#include "HistoryData.h"
#include "utility.h"
#include "BootloaderConfigDlg.h"
extern void PrintLog(const wchar_t *format, ...);
// ConfigDlg dialog
IMPLEMENT_DYNAMIC(ConfigDlg, CDialogEx)
// See ConfigDlg.h for documentation of this method.
ConfigDlg::ConfigDlg(CWnd *pParent /*=NULL*/)
: CDialogEx(IDD_DIALOG_CONFIG, pParent)
, m_bcaData(NULL)
, m_bcaBinaries(_T(""))
{
}
// See ConfigDlg.h for documentation of this method.
ConfigDlg::~ConfigDlg()
{
if (m_bcaData != NULL)
{
free(m_bcaData);
}
}
// See ConfigDlg.h for documentation of this method.
void ConfigDlg::DoDataExchange(CDataExchange *pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_COMBO_FILE2, m_ctrlImageFile);
DDX_Text(pDX, IDC_EDIT_BCA_BINARY, m_bcaBinaries);
}
BEGIN_MESSAGE_MAP(ConfigDlg, CDialogEx)
ON_BN_CLICKED(IDC_BUTTON_BROWSE2, &ConfigDlg::OnBnClickedButtonBrowse)
ON_CBN_SELCHANGE(IDC_COMBO_FILE2, &ConfigDlg::OnSelchangeComboFile)
ON_BN_CLICKED(IDC_BUTTON_SAVE_BCA, &ConfigDlg::OnBnClickedButtonSaveBca)
ON_EN_CHANGE(IDC_EDIT_BCA_BINARY, &ConfigDlg::OnChangeEditBcaData)
ON_WM_SHOWWINDOW()
ON_BN_CLICKED(IDC_BUTTON_CONFIG_BCA, &ConfigDlg::OnBnClickedButtonConfigBca)
ON_CBN_KILLFOCUS(IDC_COMBO_FILE2, &ConfigDlg::OnKillfocusComboFile)
END_MESSAGE_MAP()
// See ConfigDlg.h for documentation of this method.
void ConfigDlg::OnOK()
{
// CDialogEx::OnOK();
}
// See ConfigDlg.h for documentation of this method.
void ConfigDlg::OnCancel()
{
// CDialogEx::OnCancel();
}
// See ConfigDlg.h for documentation of this method.
BOOL ConfigDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
// TODO: Add extra initialization here
if (m_bcaData == NULL)
{
m_bcaData = (char *)malloc(64);
FillMemory(m_bcaData, 64, 0xFF);
}
// 128 for BCA characters,
// There are four lines of BCA characters
// 2*4 for four "\r\n" pairs.
((CEdit *)GetDlgItem(IDC_EDIT_BCA_BINARY))->SetLimitText(128 + 2 * 4);
// RefreshImageFileList();
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
}
// See ConfigDlg.h for documentation of this method.
void ConfigDlg::RefreshImageFileList()
{
// Clear the contents
m_ctrlImageFile.ResetContent();
for (size_t i = 0; i < g_pHistoryData->GetFileCount(); i++)
{
m_ctrlImageFile.AddString(g_pHistoryData->GetFilePath(i));
}
bool enableSave = false;
if (g_pHistoryData->GetFileCount() > 0)
{
m_ctrlImageFile.SetCurSel(0);
if (g_pHistoryData->GetFileType(0) != HistoryData::FileType::kBinary)
{
PrintLog(_T("Warning: Currently, only binary file is supported!\r\n"));
enableSave = false;
}
else if (ReadBootloaderConfigureArea())
{
enableSave = true;
}
}
else
{
enableSave = false;
}
if (!enableSave)
{
ResetBootloaderConfigureArea();
}
GetDlgItem(IDC_BUTTON_SAVE_BCA)->EnableWindow(enableSave);
}
// See ConfigDlg.h for documentation of this method.
BOOL ConfigDlg::ReadBootloaderConfigureArea()
{
CString filePath;
m_ctrlImageFile.GetWindowTextW(filePath);
CFile *cFile = new CFile(filePath.GetBuffer(), CFile::modeReadWrite | CFile::typeBinary);
filePath.ReleaseBuffer();
ULONGLONG length = cFile->GetLength();
if (length < 0x400)
{
PrintLog(_T("Warning: File(%s) is smaller than 1K bytes, fill 0xFFs to extend it to 1K bytes."), filePath);
cFile->SeekToEnd();
while (length < 0x400)
{
cFile->Write("\xFF", 1);
length++;
}
cFile->Flush(); // Flush the 0xFFs to file.
}
cFile->Seek(0x3C0, CFile::begin);
cFile->Read(m_bcaData, 64);
PrintLog(_T("Read BCA data from image file."));
delete cFile;
UpdateDataOfBootloaderConfigureArea(FALSE);
return TRUE;
}
// See ConfigDlg.h for documentation of this method.
void ConfigDlg::UpdateDataOfBootloaderConfigureArea(BOOL direction)
{
if (direction)
{
UpdateData(TRUE); // Update UI to CString m_bcaBinaries
int length = m_bcaBinaries.GetLength();
LPWSTR buffer = m_bcaBinaries.GetBuffer();
char tempHigh, tempLow;
int posBin = 0, posChar = 0;
while ((posBin < 64) && (posChar < length))
{
// Only convert legal characters.
if (isxdigit(buffer[posChar * 2]) && isxdigit(buffer[posChar * 2 + 1]))
{
tempHigh = buffer[posChar * 2] & 0xFF; // change TCHAR to char, abandon the high bits.
tempLow = buffer[posChar * 2 + 1] & 0xFF; // change TCHAR to char, abandon the high bits.
m_bcaData[posBin] = ((hex_to_int(tempHigh) & 0xFF) << 4) | (hex_to_int(tempLow) & 0xFF);
posBin++;
posChar++;
}
else
{
// Skip the illegal character pairs.
posChar++;
}
}
m_bcaBinaries.ReleaseBuffer();
}
else
{
LPTSTR buffer = m_bcaBinaries.GetBuffer(128 + 2 * 4 + 1); // 128 for 128 BCA characters
// 2 * 4 for enter characters("\r\n") each line
// 1 byte more for for terminator("\0")
int posBin = 0, posChar = 0;
for (; posBin < 64; posChar++, posBin++)
{
// 32 characters each line.
if ((!(posBin % 0x10)) && (posBin != 0))
{
// Add "\r\n" at the end of each line
buffer[posChar * 2] = '\r';
buffer[posChar * 2 + 1] = '\n';
posChar++;
}
buffer[posChar * 2] = int_to_hex(m_bcaData[posBin] >> 4);
buffer[posChar * 2 + 1] = int_to_hex(m_bcaData[posBin]);
}
buffer[posChar * 2] = '\0';
m_bcaBinaries.ReleaseBuffer();
UpdateData(FALSE); // Update CString m_bcaBinaries to UI
}
}
// See ConfigDlg.h for documentation of this method.
void ConfigDlg::WriteBootloaderConfigureArea()
{
UpdateDataOfBootloaderConfigureArea(TRUE);
CString filePath;
m_ctrlImageFile.GetWindowTextW(filePath);
CFile *cFile = new CFile(filePath.GetBuffer(), CFile::modeWrite | CFile::typeBinary);
filePath.ReleaseBuffer();
cFile->Seek(0x3C0, CFile::begin);
cFile->Write(m_bcaData, 64);
cFile->Flush();
PrintLog(_T("Write new BCA data to image file."));
delete (cFile);
}
// See ConfigDlg.h for documentation of this method.
void ConfigDlg::ResetBootloaderConfigureArea()
{
if (m_bcaData == NULL)
{
m_bcaData = (char *)malloc(64);
}
FillMemory(m_bcaData, 64, 0xFF);
UpdateDataOfBootloaderConfigureArea(FALSE);
}
// See ConfigDlg.h for documentation of this method.
void ConfigDlg::OnShowWindow(BOOL bShow, UINT nStatus)
{
CDialogEx::OnShowWindow(bShow, nStatus);
// Image file list might be changed at other tab page.
// Refresh it when showing this tab page.
if (bShow)
{
RefreshImageFileList();
}
}
// See ConfigDlg.h for documentation of this method.
void ConfigDlg::OnBnClickedButtonBrowse()
{
CFileDialog cFileDlg(TRUE);
cFileDlg.m_ofn.lpstrTitle = _T("Select the image file");
cFileDlg.m_ofn.lpstrFilter = _T("Supported files(*.bin)\0*.bin;\0All files(*.*)\0*.*\0\0");
if (IDOK == cFileDlg.DoModal())
{
CString fullPath = cFileDlg.GetPathName();
if (file_exists(fullPath))
{
g_pHistoryData->InsertFile(fullPath);
RefreshImageFileList();
}
else
{
PrintLog(_T("Invalid full path filename, or file doesn't exist.(%s)"), fullPath);
}
}
}
// See ConfigDlg.h for documentation of this method.
void ConfigDlg::OnChangeEditBcaData()
{
// Update UI to string variable;
UpdateData(TRUE);
}
// See ConfigDlg.h for documentation of this method.
void ConfigDlg::OnSelchangeComboFile()
{
// If a file is selected, bubble it to the head of a file list.
g_pHistoryData->BubbleSelectedFile(m_ctrlImageFile.GetCurSel());
RefreshImageFileList();
}
void ConfigDlg::OnKillfocusComboFile()
{
if (m_ctrlImageFile.GetCurSel() >= 0)
{
// If no change in the textbox, then return;
return;
}
CString filePath;
m_ctrlImageFile.GetWindowTextW(filePath);
// Test if the file exists
if (file_exists(filePath))
{
// File exists, add it to history file list, and refresh commbo box.
g_pHistoryData->InsertFile(filePath);
RefreshImageFileList();
}
else
{
// File doesn't exist.
if (!filePath.IsEmpty())
{
PrintLog(_T("Invalid full path filename, or file doesn't exist.(%s)"), filePath);
}
m_ctrlImageFile.SetCurSel(-1); // Set invalid selection.
ResetBootloaderConfigureArea(); // Reset configureArea to 0xFFs.
GetDlgItem(IDC_BUTTON_SAVE_BCA)->EnableWindow(false); // Disable save button.
}
}
// See ConfigDlg.h for documentation of this method.
void ConfigDlg::OnBnClickedButtonConfigBca()
{
// BCA data in the UI page might be changed.
// Update it to memory region.
UpdateDataOfBootloaderConfigureArea(TRUE);
CString filePath;
m_ctrlImageFile.GetWindowTextW(filePath);
CFile *cFile = new CFile;
if (!cFile->Open(filePath, CFile::modeRead | CFile::typeBinary, NULL))
{
// If cannot open this file, transfer NULL to bootloader config dlg.
delete cFile;
cFile = NULL;
}
else
{
// Check if this file is binary file.
CString extension = PathFindExtension(filePath);
if (extension.CompareNoCase(_T(".bin")) != 0)
{
// If not binary file, close it and transfer NULL to bootloader config dlg.
cFile->Close();
delete cFile;
cFile = NULL;
}
}
BootloaderConfigDlg dlg((blfwkdll::BootloaderConfigureAreaData *)m_bcaData, cFile, this);
dlg.DoModal();
// Update the new BCA to UI page.
UpdateDataOfBootloaderConfigureArea(FALSE);
if (cFile != NULL)
{
cFile->Close();
delete cFile;
cFile = NULL;
}
}
// See ConfigDlg.h for documentation of this method.
void ConfigDlg::OnBnClickedButtonSaveBca()
{
WriteBootloaderConfigureArea();
}

View File

@@ -0,0 +1,100 @@
/*
* 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"
// ConfigDlg Dialog
/*!
* \brief ConfigDlg class is the UI Dialog class for the
* BCA utilities tab page
*/
class ConfigDlg : public CDialogEx
{
DECLARE_DYNAMIC(ConfigDlg)
public:
//! \brief Generated standard constructor.
ConfigDlg(CWnd *pParent = NULL); // standard constructor
//! \brief Generated standard destructor.
virtual ~ConfigDlg();
// Dialog Data
#ifdef AFX_DESIGN_TIME
enum
{
IDD = IDD_DIALOG_CONFIG
};
#endif
//! \brief Generated message map functions.
protected:
virtual void DoDataExchange(CDataExchange *pDX); // DDX/DDV support
DECLARE_MESSAGE_MAP()
virtual void OnOK();
virtual void OnCancel();
public:
virtual BOOL OnInitDialog();
afx_msg void OnShowWindow(BOOL bShow, UINT nStatus);
afx_msg void OnSelchangeComboFile();
afx_msg void OnKillfocusComboFile();
afx_msg void OnBnClickedButtonBrowse();
afx_msg void OnChangeEditBcaData();
afx_msg void OnBnClickedButtonConfigBca();
afx_msg void OnBnClickedButtonSaveBca();
public:
//! \brief Refresh the image file list.
void RefreshImageFileList();
//! \brief Read BCA data from image file to memory region(m_bcaData).
BOOL ReadBootloaderConfigureArea();
//! \brief Update BCA data between memory region and UI
//!
//! \param direction The update direction between UI and memory.
//! TRUE: from UI to memory
//! FALSE: from memory to UI
void UpdateDataOfBootloaderConfigureArea(BOOL direction);
//! \brief Write BCA data to image file.
void WriteBootloaderConfigureArea();
//! \brief Reset BCA data to all 0xFFs.
void ResetBootloaderConfigureArea();
public:
CComboBox m_ctrlImageFile; //!< A control variable for the Combox, IDC_COMBO_FILE2.
CString m_bcaBinaries; //!< A string variable for the Edit Control, IDC_EDIT_BCA_BINARY.
char *m_bcaData; //!< A pointer, pointing to a memory region that contains BCA binaries.
};

View File

@@ -0,0 +1,223 @@
/*
* 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.
*/
#include "stdafx.h"
#include "KinetisFlashTool.h"
#include "FlashDlg.h"
#include "afxdialogex.h"
#include "Bootloader.h"
#include "utility.h"
// FlashDlg dialog
IMPLEMENT_DYNAMIC(FlashDlg, CDialogEx)
#define ERASE_REGION (_T("Erase Region"))
#define ERASE_ALL (_T("Erase All"))
#define ERASE_ALL_UNSECURE (_T("Erase All and Unsecure"))
#define INTERNAL_FLASH (_T("Internal Flash"))
#define QUADSPI_MEMORY (_T("QuadSPI 0 Memory"))
extern void PrintLog(const wchar_t *format, ...);
// See FlashDlg.h for documentation of this method.
FlashDlg::FlashDlg(CWnd *pParent /*=NULL*/)
: CDialogEx(IDD_DIALOG_FLASH, pParent)
{
}
// See FlashDlg.h for documentation of this method.
FlashDlg::~FlashDlg()
{
}
// See FlashDlg.h for documentation of this method.
void FlashDlg::DoDataExchange(CDataExchange *pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_COMBO_ERASE_OPT, m_comboEraseOpt);
DDX_Control(pDX, IDC_COMBO_ERASE_MEMORYID, m_comboMemoryID);
}
BEGIN_MESSAGE_MAP(FlashDlg, CDialogEx)
ON_CBN_SELCHANGE(IDC_COMBO_ERASE_OPT, &FlashDlg::OnSelchangeComboEraseOpt)
ON_BN_CLICKED(IDC_BUTTON_ERASE, &FlashDlg::OnBnClickedButtonErase)
ON_BN_CLICKED(IDC_BUTTON_IFR, &FlashDlg::OnBnClickedButtonIfr)
END_MESSAGE_MAP()
// See ConfigDlg.h for documentation of this method.
void FlashDlg::OnOK()
{
// CDialogEx::OnOK();
}
// See ConfigDlg.h for documentation of this method.
void FlashDlg::OnCancel()
{
// CDialogEx::OnCancel();
}
// See FlashDlg.h for documentation of this method.
BOOL FlashDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
// TODO: Add extra initialization here
// Init the combo boxes
m_comboEraseOpt.AddString(ERASE_REGION);
m_comboEraseOpt.AddString(ERASE_ALL);
m_comboEraseOpt.AddString(ERASE_ALL_UNSECURE);
m_comboEraseOpt.SetCurSel(0);
GetDlgItem(IDC_STATIC_ERASE_ID)->EnableWindow(false);
GetDlgItem(IDC_COMBO_ERASE_MEMORYID)->EnableWindow(false);
m_comboMemoryID.AddString(INTERNAL_FLASH);
m_comboMemoryID.AddString(QUADSPI_MEMORY);
m_comboMemoryID.SetCurSel(0);
return TRUE; // return TRUE unless you set the focus to a control
}
// See FlashDlg.h for documentation of this method.
void FlashDlg::OnSelchangeComboEraseOpt()
{
int eraseOpt = m_comboEraseOpt.GetCurSel();
// Memory ID combox only is enabled when erase-all command is selected.
GetDlgItem(IDC_STATIC_ERASE_ID)->EnableWindow(eraseOpt == 1);
GetDlgItem(IDC_COMBO_ERASE_MEMORYID)->EnableWindow(eraseOpt == 1);
// address and length only is enabled when erase-region command is selected.
GetDlgItem(IDC_STATIC_ERASE_ADDR)->EnableWindow(!eraseOpt);
GetDlgItem(IDC_EDIT_ERASE_ADDRESS)->EnableWindow(!eraseOpt);
GetDlgItem(IDC_STATIC_ERASE_LENGTH)->EnableWindow(!eraseOpt);
GetDlgItem(IDC_EDIT_ERASE_LENGTH)->EnableWindow(!eraseOpt);
}
// See FlashDlg.h for documentation of this method.
void FlashDlg::OnBnClickedButtonErase()
{
if (!g_pBootloader->m_isConneted)
{
PrintLog(_T("No device is connected!\r\nPlease press Connect button to connect the device first.\r\n"));
return;
}
Bootloader::EraseOption option;
ZeroMemory(&option, sizeof(Bootloader::EraseOption));
int eraseOpt = m_comboEraseOpt.GetCurSel();
if (eraseOpt == 0) // erase region
{
option.option = Bootloader::EraseOption::ERASE_OPERATION::erase_region;
CString startAddr;
GetDlgItem(IDC_EDIT_ERASE_ADDRESS)->GetWindowTextW(startAddr);
if (!cstringtoui(startAddr, option.startAddress))
{
PrintLog(_T("Error: Invalid Start Address.(%s)"), startAddr);
return;
}
CString length;
GetDlgItem(IDC_EDIT_ERASE_LENGTH)->GetWindowTextW(length);
if (!cstringtoui(length, option.length))
{
PrintLog(_T("Error: Invalid Length.(%s)"), length);
return;
}
}
else if (eraseOpt == 1) // flash-erase-all
{
int memoryId = m_comboMemoryID.GetCurSel();
if ((memoryId == 1) && (!(g_pBootloader->m_targetInfo.supportedCmd &
blfwkdll::Updater::COMMAND_MASK::kCommandMask_ConfigureQuadSpi)))
{
PrintLog(_T("Current Device doesn't support QuadSPI.\r\n"));
return;
}
option.option = Bootloader::EraseOption::ERASE_OPERATION::erase_all;
option.memoryID = static_cast<uint32_t>(memoryId);
}
else if (eraseOpt == 2) // flash-erase-all-unsecure
{
if (!(g_pBootloader->m_targetInfo.supportedCmd &
blfwkdll::Updater::COMMAND_MASK::kCommandMask_FlashEraseAllUnsecure))
{
PrintLog(_T("Current Device doesn't support FlashEraseAllUnsecure.\r\n"));
return;
}
option.option = Bootloader::EraseOption::ERASE_OPERATION::erase_all_and_unsecure;
}
g_pBootloader->Erase(&option);
}
// See FlashDlg.h for documentation of this method.
void FlashDlg::OnBnClickedButtonIfr()
{
if (!g_pBootloader->m_isConneted)
{
PrintLog(_T("No device is connected!\r\nPlease press Connect button to connect the device first.\r\n"));
return;
}
if (!(g_pBootloader->m_targetInfo.supportedCmd & blfwkdll::Updater::COMMAND_MASK::kCommandMask_FlashProgramOnce))
{
PrintLog(_T("Current Device doesn't support FlashProgramOnce.\r\n"));
return;
}
Bootloader::ProgramOnceOption option;
CString strW;
GetDlgItem(IDC_EDIT_IFR_INDEX)->GetWindowTextW(strW);
if (!cstringtoui(strW, option.index))
{
PrintLog(_T("Error: Invalid index.(%s)"), strW);
return;
}
GetDlgItem(IDC_EDIT_IFR_BYTECOUNT)->GetWindowTextW(strW);
if (!cstringtoui(strW, option.byteCount))
{
PrintLog(_T("Error: Invalid byteCount.(%s)"), strW);
return;
}
// Convert WCHAR to CHAR
GetDlgItem(IDC_EDIT_IFR_DATA)->GetWindowTextW(strW);
CStringA strA(strW.GetBuffer());
strW.ReleaseBuffer();
option.data = strA.GetBuffer();
strA.ReleaseBuffer();
g_pBootloader->ProgramOnce(&option);
}

View File

@@ -0,0 +1,75 @@
/*
* 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"
// FlashDlg Dialog
/*!
* \brief FlashDlg class is the UI Dialog class for the
* Flash utilities tab page
*/
class FlashDlg : public CDialogEx
{
DECLARE_DYNAMIC(FlashDlg)
public:
//! \brief Generated standard constructor.
FlashDlg(CWnd *pParent = NULL); // standard constructor
//! \brief Generated standard destructor.
virtual ~FlashDlg();
// Dialog Data
#ifdef AFX_DESIGN_TIME
enum
{
IDD = IDD_DIALOG_FLASH
};
#endif
protected:
//! \brief Generated message map functions.
virtual void DoDataExchange(CDataExchange *pDX); // DDX/DDV support
DECLARE_MESSAGE_MAP()
virtual void OnOK();
virtual void OnCancel();
public:
//! \brief Generated message map functions.
virtual BOOL OnInitDialog();
afx_msg void OnSelchangeComboEraseOpt();
afx_msg void OnBnClickedButtonErase();
afx_msg void OnBnClickedButtonIfr();
CComboBox m_comboEraseOpt; //!< Control variable for erase option combox
CComboBox m_comboMemoryID; //!< Control variable for memory option combox
};

View File

@@ -0,0 +1,35 @@
/*
* Copyright (c) 2013-16, 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.
*/
#include "stdafx.h"
#include "HistoryData.h"
// See HistoryData.h for documentation of this variable.
HistoryData *g_pHistoryData;

View File

@@ -0,0 +1,383 @@
/*
* Copyright (c) 2013-16, 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 <vector>
#include <cstring>
/*!
* \brief HistoryData class stores the operation history.
* Save users operation steps.
*/
class HistoryData
{
public:
//! \brief Generated standard constructor.
HistoryData()
: m_currentDevice(-1)
, m_currentBaudRate(-1)
, m_imageAddress(0){};
//! \brief Generated standard destructor.
virtual ~HistoryData(){};
//! @brief File types.
enum FileType
{
kBinary, //!< Binary file.(.bin)
kSBFile, //!< SB file.(.sb)
kIntelHex, //!< Intel hex file.(.hex)
kSRecord, //!< Srecord file.(.srec, s19)
kUnsupported //!< Unsupported file type.
};
//! \brief Get current selected device index at device list.
//!
//! \return negative: no device is selected.
//! non-negative: current selected device index at device list.
int32_t GetCurrentDevice() { return m_currentDevice; };
//! \brief Change the index of current selected device.
//!
//! \param index at device list.
void SetCurrentDevice(int32_t index) { m_currentDevice = index; };
//! \brief Get the baud rate at the specified index.
//!
//! \param index of the list.
//!
//! \return the value of the baud rate.
int32_t GetBaudRate(size_t index) { return m_baudRate.at(index); };
//! \brief Get count of the baud rates in the list.
//!
//! \return the count.
size_t GetBaudRateCount() { return m_baudRate.size(); };
//! \brief Get current selected baud rate index at the list.
//!
//! \return negative: no baud rate is selected.
//! non-negative: current selected baud rate index at the list.
int32_t GetCurrentBaudRate() { return m_currentBaudRate; };
//! \brief Change the index of current selected baud rate.
//!
//! \param index at baud rate list.
void SetCurrentBaudRate(int32_t index) { m_currentBaudRate = index; };
//! \brief Append a new baud rate at the end of the list.
//!
//! \param the value of baud rate.
void AddBaudRate(int32_t baudrate)
{
// Find whether the new baudrate already exists in the list
for (std::vector<int32_t>::iterator it = m_baudRate.begin(); it != m_baudRate.end(); it++)
{
// If find the matched baud rate, return.
if (baudrate == *it)
{
return;
}
}
// If no matched, add it to end of list.
m_baudRate.push_back(baudrate);
};
//! \brief Insert a new baud rate, and change the current selected baud rate.
//! If the baud rate already exists in the list, only change the selected baud rate index
//!
//! \param the value of baud rate.
void InsertBaudRate(int32_t baudrate)
{
// If find index of the baud rate to insert.
for (std::vector<int32_t>::iterator it = m_baudRate.begin(); it != m_baudRate.end(); it++)
{
// Check next index.
if (baudrate > *it)
{
continue;
}
// The same baudrate in the list, just set it as current selected baud rate.
else if (baudrate == *it)
{
SetCurrentBaudRate(it - m_baudRate.begin());
return;
}
// Find the correct index, insert it and set it as current selected baud rate.
else
{
m_baudRate.insert(it, baudrate);
SetCurrentBaudRate(it - m_baudRate.begin());
return;
}
}
// If baudrate is bigger than any one in the list, add it to list back.
m_baudRate.push_back(baudrate);
SetCurrentBaudRate(GetBaudRateCount());
return;
};
//! \brief Get the VID at the specified index.
//!
//! \param index of the list.
//!
//! \return the value of the PID.
uint16_t GetVid(size_t index) { return m_vids.at(index); };
//! \brief Get count of the VID in the list .
//!
//! \return the count.
size_t GetVidCount() { return m_vids.size(); };
//! \brief Append a new VID at the end of the list.
//!
//! \param the value of VID.
void AddVid(uint16_t vid)
{
// Find whether the new vid already exists in the list.
for (std::vector<uint16_t>::iterator it = m_vids.begin(); it != m_vids.end(); it++)
{
// If find the matched vid, return.
if (vid == *it)
{
return;
}
}
// If no matched, add it to end of list.
m_vids.push_back(vid);
};
//! \brief Insert a VID at the head of the list.
//! If the VID already exists in the list, only bubble that VID to list head.
//!
//! \param the value of VID.
void InsertVid(uint16_t vid)
{
// Find whether the new vid already exists in the list.
for (std::vector<uint16_t>::iterator it = m_vids.begin(); it != m_vids.end(); it++)
{
// If find the matched vid, bubble it to the head of list. Then return.
if (vid == *it)
{
BubbleSelectedVid(it - m_vids.begin());
return;
}
}
// If no matched, add it to head of list.
m_vids.insert(m_vids.begin(), vid);
};
//! \brief bubble the VID at the specified index to the head of the VID list
//!
//! \param the index of VID.
void BubbleSelectedVid(size_t index)
{
uint16_t vid = m_vids.at(index);
m_vids.erase(m_vids.begin() + index);
m_vids.insert(m_vids.begin(), vid);
}
//! \brief Get the PID at the specified index.
//!
//! \param index of the list.
//!
//! \return the value of the PID.
uint16_t GetPid(size_t index) { return m_pids.at(index); };
//! \brief Get count of the PID in the list .
//!
//! \return the count.
size_t GetPidCount() { return m_pids.size(); };
//! \brief Append a new PID at the end of the list.
//!
//! \param the value of PID.
void AddPid(uint16_t pid)
{
// Find whether the new pid already exists in the list.
for (std::vector<uint16_t>::iterator it = m_pids.begin(); it != m_pids.end(); it++)
{
// If find the matched pid, return.
if (pid == *it)
{
return;
}
}
// If no matched, add it to end of list.
m_pids.push_back(pid);
};
//! \brief Insert a PID at the head of the list.
//! If the PID already exists in the list, only bubble it to list head.
//!
//! \param the value of PID.
void InsertPid(uint16_t pid)
{
// Find whether the new pid already exists in the list.
for (std::vector<uint16_t>::iterator it = m_pids.begin(); it != m_pids.end(); it++)
{
// If find the matched pid, bubble it to the head of list. Then return.
if (pid == *it)
{
BubbleSelectedPid(it - m_pids.begin());
return;
}
}
// If no matched, add it to head of list.
m_pids.insert(m_pids.begin(), pid);
};
//! \brief bubble the PID at the specified index to the head of the PID list
//!
//! \param the index of PID.
void BubbleSelectedPid(size_t index)
{
uint16_t pid = m_pids.at(index);
m_pids.erase(m_pids.begin() + index);
m_pids.insert(m_pids.begin(), pid);
}
//! \brief Get the file full path at the specified index of the file list.
//!
//! \param index of the list.
//!
//! \return full path string.
CString GetFilePath(int index) { return m_imageFile.at(index); };
//! \brief Get the file name at the specified index of the file list.
//!
//! \param index of the list.
//!
//! \return file name string.
CString GetFileName(int index)
{
CString fullPath = m_imageFile.at(index);
int pos = fullPath.ReverseFind(_T('\\'));
return fullPath.Right(fullPath.GetLength() - pos - 1);
};
//! \brief Get the file type of the file at the specified index of the file list.
//!
//! \param index of the list.
//!
//! \return file type.
FileType GetFileType(int index)
{
CString extension = PathFindExtension(m_imageFile.at(index));
if (extension.CompareNoCase(_T(".bin")) == 0)
{
return kBinary;
}
else if (extension.CompareNoCase(_T(".sb")) == 0)
{
return kSBFile;
}
else if (extension.CompareNoCase(_T(".hex")) == 0)
{
return kIntelHex;
}
else if ((extension.CompareNoCase(_T(".srec")) == 0) || (extension.CompareNoCase(_T(".s19")) == 0))
{
return kSRecord;
}
else
{
return kUnsupported;
}
}
//! \brief Get count of the files in the list .
//!
//! \return the count.
size_t GetFileCount() { return m_imageFile.size(); };
//! \brief Append a new file at the end of the list.
//!
//! \param the full path of the file.
void AddFile(CString fullPath)
{
// Find whether this file already exists in the file list.
for (std::vector<CString>::iterator it = m_imageFile.begin(); it != m_imageFile.end(); it++)
{
// If find the matched file, return.
if (fullPath.Compare(*it) == 0)
{
return;
}
}
// If no matched file, add it to end of file list.
m_imageFile.push_back(fullPath);
};
//! \brief Insert a file at the head of the list.
//! If the file already exists in the list, only bubble that file to list head.
//!
//! \param the full path of the file.
void InsertFile(CString fullPath)
{
// Find whether this file already exists in the file list.
for (std::vector<CString>::iterator it = m_imageFile.begin(); it != m_imageFile.end(); it++)
{
// If find the matched file, bubble it to the head of file list. Then return.
if (fullPath.Compare(*it) == 0)
{
BubbleSelectedFile(it - m_imageFile.begin());
return;
}
}
// If no matched file, add it to head of file list.
m_imageFile.insert(m_imageFile.begin(), fullPath);
};
//! \brief bubble the file at the specified index to the head of the file list
//!
//! \param the index of file.
void BubbleSelectedFile(int32_t index)
{
CString file = m_imageFile.at(index);
m_imageFile.erase(m_imageFile.begin() + index);
m_imageFile.insert(m_imageFile.begin(), file);
}
//! \brief Get image address previous used.
//!
//! \return value of the image address.
uint32_t GetImageAddress() { return m_imageAddress; };
//! \brief Change image address.
//!
//! \param value of the image address.
void SetImageAddress(uint32_t imageAddress) { m_imageAddress = imageAddress; };
//! \brief Get the string of backdoor key previous used.
//!
//! \return the string of backdoor key.
CString GetBackdoorKey() { return m_backdoorKey; }
//! \brief Change the string of backdoor key.
//!
//! \param the string of backdoor key.;
void SetBackdoorKey(CString backdoorKey) { m_backdoorKey = backdoorKey; };
private:
int32_t m_currentDevice; //!< current selected device at device list.
std::vector<int32_t> m_baudRate; //!< baud rate list.
int32_t m_currentBaudRate; //!< current selected baud rate.
std::vector<uint16_t> m_vids; //!< vid list.
std::vector<uint16_t> m_pids; //!< pid list.
std::vector<CString> m_imageFile; //!< image file list.
uint32_t m_imageAddress; //!< image address.
CString m_backdoorKey; //!< string of backdoor key.
};
extern HistoryData *g_pHistoryData; //!< Global point to HistoryData class.

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,68 @@
/*
* 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.
*/
// KinetisFlashTool.h : main header file for the PROJECT_NAME application
//
#pragma once
#ifndef __AFXWIN_H__
#error "include 'stdafx.h' before including this file for PCH"
#endif
#include "resource.h" // main symbols
// CKinetisFlashToolApp:
// See KinetisFlashTool.cpp for the implementation of this class
//
class CKinetisFlashToolApp : public CWinApp
{
public:
CKinetisFlashToolApp();
// Overrides
public:
virtual BOOL InitInstance();
virtual int ExitInstance();
// Implementation
DECLARE_MESSAGE_MAP()
public:
//! \brief Parse init file to get the history information.
bool ParseIniFile(CString strFilename);
//! \brief Save history information to init file.
bool WriteIniFile(CString strFilename);
};
extern CKinetisFlashToolApp theApp;

View File

@@ -0,0 +1,170 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{864CBA51-EAF2-491E-9C74-4791B49FE039}</ProjectGuid>
<RootNamespace>KinetisFlashTool</RootNamespace>
<Keyword>MFCProj</Keyword>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140_xp</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<UseOfMfc>Static</UseOfMfc>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140_xp</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<UseOfMfc>Static</UseOfMfc>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>$(VC_IncludePath);$(WindowsSdk_71A_IncludePath);</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>..\..\..\src;..\..\..\src\bm_usb</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<RegisterOutput>false</RegisterOutput>
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>setupapi.lib</AdditionalDependencies>
<EnableUAC>true</EnableUAC>
</Link>
<Midl>
<MkTypLibCompatible>false</MkTypLibCompatible>
<ValidateAllParameters>true</ValidateAllParameters>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<TypeLibraryName>$(IntDir)KinetisFlashTool.tlb</TypeLibraryName>
<HeaderFileName>KinetisFlashTool_h.h</HeaderFileName>
</Midl>
<ResourceCompile>
<Culture>0x0409</Culture>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>Use</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>..\..\..\src;..\..\..\src\bm_usb</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<RegisterOutput>true</RegisterOutput>
<AdditionalDependencies>setupapi.lib</AdditionalDependencies>
</Link>
<Midl>
<MkTypLibCompatible>false</MkTypLibCompatible>
<ValidateAllParameters>true</ValidateAllParameters>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<TypeLibraryName>$(IntDir)KinetisFlashTool.tlb</TypeLibraryName>
<HeaderFileName>KinetisFlashTool_h.h</HeaderFileName>
</Midl>
<ResourceCompile>
<Culture>0x0409</Culture>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="Bootloader.h" />
<ClInclude Include="BootloaderConfigDlg.h" />
<ClInclude Include="BootloaderConfigText.h" />
<ClInclude Include="ConfigDlg.h" />
<ClInclude Include="FlashDlg.h" />
<ClInclude Include="KinetisFlashTool.h" />
<ClInclude Include="KinetisFlashToolDlg.h" />
<ClInclude Include="Resource.h" />
<ClInclude Include="SerialList.h" />
<ClInclude Include="stdafx.h" />
<ClInclude Include="targetver.h" />
<ClInclude Include="UpdateDlg.h" />
<ClInclude Include="HistoryData.h" />
<ClInclude Include="utility.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="Bootloader.cpp" />
<ClCompile Include="BootloaderConfigDlg.cpp" />
<ClCompile Include="ConfigDlg.cpp" />
<ClCompile Include="FlashDlg.cpp" />
<ClCompile Include="KinetisFlashTool.cpp" />
<ClCompile Include="KinetisFlashToolDlg.cpp" />
<ClCompile Include="SerialList.cpp" />
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="UpdateDlg.cpp" />
<ClCompile Include="HistoryData.cpp" />
<ClCompile Include="utility.cpp" />
</ItemGroup>
<ItemGroup>
<None Include="res\KinetisFlashTool.rc2" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="KinetisFlashTool.rc" />
</ItemGroup>
<ItemGroup>
<Image Include="res\Freescale.ico" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\common\blfwkdll\blfwkdll.vcxproj">
<Project>{426d14fe-6f2b-442d-893d-b5730dd6941f}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
<ProjectExtensions>
<VisualStudio>
<UserProperties RESOURCE_FILE="KinetisFlashTool.rc" />
</VisualStudio>
</ProjectExtensions>
</Project>

View File

@@ -0,0 +1,111 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="KinetisFlashTool.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="KinetisFlashToolDlg.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="stdafx.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="targetver.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Resource.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="UpdateDlg.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="SerialList.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="HistoryData.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="utility.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Bootloader.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ConfigDlg.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="BootloaderConfigDlg.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="FlashDlg.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="BootloaderConfigText.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="KinetisFlashTool.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="KinetisFlashToolDlg.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="stdafx.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="UpdateDlg.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="SerialList.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="HistoryData.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="utility.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Bootloader.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ConfigDlg.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="BootloaderConfigDlg.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="FlashDlg.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="res\KinetisFlashTool.rc2">
<Filter>Resource Files</Filter>
</None>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="KinetisFlashTool.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<Image Include="res\Freescale.ico">
<Filter>Resource Files</Filter>
</Image>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,153 @@
/*
* 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.
*/
// KinetisFlashToolDlg.h : header file
//
#pragma once
#include "afxwin.h"
#include "afxcmn.h"
#include <Setupapi.h>
#include "UpdateDlg.h"
#include "FlashDlg.h"
#include "ConfigDlg.h"
#include "../../common/blfwkdll/blfwkdll.h"
// class CKinetisFlashToolDlgAutoProxy;
// CKinetisFlashToolDlg dialog
/*!
* \brief CKinetisFlashToolDlg class is the UI Dialog class for the main page
*/
class CKinetisFlashToolDlg : public CDialogEx
{
DECLARE_DYNAMIC(CKinetisFlashToolDlg);
// friend class CKinetisFlashToolDlgAutoProxy;
// Construction
public:
//! \brief Generated standard constructor.
CKinetisFlashToolDlg(CWnd *pParent = NULL); // standard constructor
//! \brief Generated standard destructor.
virtual ~CKinetisFlashToolDlg();
// Dialog Data
enum
{
IDD = IDD_KINETISFLASHTOOL_DIALOG
};
protected:
virtual void DoDataExchange(CDataExchange *pDX); // DDX/DDV support
// Implementation
protected:
// CKinetisFlashToolDlgAutoProxy* m_pAutoProxy;
HICON m_hIcon;
BOOL CanExit();
//! \brief Generated message map functions.
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
afx_msg void OnClose();
virtual void OnOK();
virtual void OnCancel();
DECLARE_MESSAGE_MAP()
//! \brief Scan COM port and update it to UI.
void RefreshComPortList();
//! \brief Refresh baud rate list.
void RefreshBaudrateList();
//! \brief Refresh PID list.
void RefreshPidList();
//! \brief Refresh VID list.
void RefreshVidList();
//! \brief Append a new log string to the log textbox.
//!
//! \param Log string.
void AppendLog(CString log);
//! \brief Reset operation.
void Reset();
//! \brief Connect operation.
void Connect();
public:
//! \brief Generated message map functions.
afx_msg void OnBnClickedRadio();
afx_msg void OnCbnSelchangeComboPortVid();
afx_msg void OnCbnSelchangeComboBaudPid();
afx_msg void OnKillfocusComboPortVid();
afx_msg void OnKillfocusComboBaudPid();
afx_msg void OnClickedButtonCntReset();
afx_msg void OnTcnSelchangeTabFunc(NMHDR *pNMHDR, LRESULT *pResult);
afx_msg void OnTimer(UINT_PTR nIDEvent);
afx_msg BOOL OnDeviceChange(UINT nEventType, DWORD_PTR dwData);
//! \brief User defined message map functions.
afx_msg LRESULT OnUpdateLog(WPARAM wParam, LPARAM lParam);
afx_msg LRESULT OnChangeConnection(WPARAM wParam, LPARAM lParam);
afx_msg LRESULT OnUpdateStatus(WPARAM wParam, LPARAM lParam);
//! \brief Get the PeripheralConfig of bootloader.
void GetPeripheralConfig(blfwkdll::Updater::PeripheralConfig *config);
//! \brief Register usb device interface.
void RegisterUsbDeviceInterface();
CComboBox m_comboPortOrVID; //!< Control variable for Com port/VID combox
CComboBox m_comboBaudOrPID; //!< Control variable for Baud rate/PID combox
CString m_bootloaderVersion; //!< Variable for device info
CString m_protoclVersion; //!< Variable for device info
CString m_securityState; //!< Variable for device info
CString m_flashSize; //!< Variable for device info
CString m_flashSector; //!< Variable for device info
CString m_ramSize; //!< Variable for device info
CString m_rsvRgnFlashStart; //!< Variable for device info
CString m_rsvRgnFlashEnd; //!< Variable for device info
CString m_rsvRgnRamStart; //!< Variable for device info
CString m_rsvRgnRamEnd; //!< Variable for device info
CTabCtrl m_tabFunc; //!< Control variable for tab control.
CString m_log; //!< Variable for log text box.
CEdit m_logCtrl; //!< Control variable for log textbox.
UpdateDlg m_updateDlg; //!< Variable for update tab page.
FlashDlg m_flashDlg; //!< Variable for flash utility tab page.
ConfigDlg m_bootloaderConfigDLg; //!< Variable for config tab page.
HDEVNOTIFY m_devNotify; //!< Handler for device change notify.
};

View File

@@ -0,0 +1,86 @@
/*
* 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.
*/
#include "stdafx.h"
#include "SerialList.h"
#define KEY_SERIALCOMM_PATH _T("HARDWARE\\DEVICEMAP\\SERIALCOMM")
// See SerialList.h for documentation of this method.
SerialList *g_pAllComDevices;
// See SerialList.h for documentation of this method.
void SerialList::ScanSerialDevices()
{
if (m_serialDevices.size() != 0)
{
m_serialDevices.clear();
}
HKEY hKey;
int i = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, KEY_SERIALCOMM_PATH, NULL, KEY_READ, &hKey);
if (i == ERROR_SUCCESS)
{
int i = 0, status;
TCHAR Name[128], Data[32];
DWORD dNameLength, dDataLength;
do
{
dNameLength = sizeof(Name);
dDataLength = sizeof(Data);
status = ::RegEnumValue(hKey, i, Name, &dNameLength, NULL, NULL, (PUCHAR)Data, &dDataLength);
if ((status == ERROR_SUCCESS) && (dDataLength != 0))
{
m_serialDevices.push_back(SerialDevice(Data));
}
i++;
} while (status != ERROR_NO_MORE_ITEMS);
}
::RegCloseKey(hKey);
SortSerialDevices();
}
// See SerialList.h for documentation of this method.
void SerialList::SortSerialDevices()
{
size_t length = GetDeviceCount();
for (size_t i = 0; i < length; i++)
{
for (size_t j = i + 1; j < length; j++)
{
if (GetDevice(i).GetNum() > GetDevice(j).GetNum())
{
std::swap(m_serialDevices[i], m_serialDevices[j]);
}
}
}
}

View File

@@ -0,0 +1,111 @@
/*
* 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 <vector>
#include <cstring>
/*!
* \brief SerialDevice class represent a COM port hardware on host
*/
class SerialDevice
{
public:
//! \brief Generated standard constructor.
SerialDevice()
: m_port(_T("")){};
//! \brief Generated standard constructor with a parameter.
SerialDevice(LPCTSTR port)
: m_port(port){};
//! \brief Generated standard destructor.
virtual ~SerialDevice(){};
//! \brief Get the string containing COM port.(COMxx)
virtual CString GetString() { return (m_port); };
//! \brief Get the port number only.
virtual uint32_t GetNum() { return _ttoi(m_port.Mid(3)); };
private:
CString m_port; //!< A string variable contains COM port string.
};
/*!
* \brief SerialList class contains all serial devices on host
*/
class SerialList
{
public:
//! \brief Generated standard constructor.
SerialList(){};
//! \brief Generated standard destructor.
virtual ~SerialList(){};
//! \brief Get SerialDevice variable at specified index.
SerialDevice GetDevice(int index) { return m_serialDevices.at(index); };
//! \brief Get the number of devices in the list.
size_t GetDeviceCount() { return m_serialDevices.size(); };
//! \brief Find whether the specified device is in the list.
int FindSerialDevice(SerialDevice device)
{
std::vector<SerialDevice>::iterator it;
for (it = m_serialDevices.begin(); it != m_serialDevices.end(); it++)
{
// Check next index.
if (device.GetNum() > it->GetNum())
{
continue;
}
// The same COM device in the list, return the index
else if (device.GetNum() == it->GetNum())
{
return it - m_serialDevices.begin();
}
// No matched, return negative.
else
{
return -1;
}
}
return -1;
}
//! \brief Scan all COM port hardware on the host.
void ScanSerialDevices();
//! \brief Sort all devices in the list as ascending order
void SortSerialDevices();
private:
std::vector<SerialDevice> m_serialDevices; //!< Serial Device list.
};
extern SerialList *g_pAllComDevices; //!< Global point to SerialList class.

View File

@@ -0,0 +1,377 @@
/*
* 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.
*/
#include "stdafx.h"
#include "KinetisFlashTool.h"
#include "UpdateDlg.h"
#include "afxdialogex.h"
#include "Bootloader.h"
#include "HistoryData.h"
#include "utility.h"
#include "KinetisFlashToolDlg.h"
extern void PrintLog(const wchar_t *format, ...);
extern CKinetisFlashToolDlg *g_pMainDlg;
// UpdateDlg Dialog
IMPLEMENT_DYNAMIC(UpdateDlg, CDialogEx)
// See UpdateDlg.h for documentation of this method.
UpdateDlg::UpdateDlg(CWnd *pParent /*=NULL*/)
: CDialogEx(IDD_DIALOG_UPDATE, pParent)
, m_address(_T(""))
, m_backdoorKey(_T(""))
, m_doErasetoUnlock(false)
, m_useKeytoUnlock(false)
{
}
// See UpdateDlg.h for documentation of this method.
UpdateDlg::~UpdateDlg()
{
}
// See UpdateDlg.h for documentation of this method.
void UpdateDlg::DoDataExchange(CDataExchange *pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDIT_ADDRESS, m_address);
DDX_Control(pDX, IDC_COMBO_FILE, m_ctrlImageFile);
DDX_Text(pDX, IDC_EDIT_KEY, m_backdoorKey);
DDX_Control(pDX, IDC_PROGRESS_BAR, m_progressCtrl);
}
BEGIN_MESSAGE_MAP(UpdateDlg, CDialogEx)
ON_BN_CLICKED(IDC_BUTTON_UPDATE, &UpdateDlg::OnBnClickedButtonUpdate)
ON_BN_CLICKED(IDC_BUTTON_BROWSE, &UpdateDlg::OnBnClickedButtonBrowse)
ON_BN_CLICKED(IDC_RADIO_ERASE, &UpdateDlg::OnBnClickedRadioErase)
ON_BN_CLICKED(IDC_RADIO_UNLOCK, &UpdateDlg::OnBnClickedRadioUnlock)
ON_EN_CHANGE(IDC_EDIT_ADDRESS, &UpdateDlg::OnChangeEdit)
ON_EN_CHANGE(IDC_EDIT_KEY, &UpdateDlg::OnChangeEdit)
ON_CBN_SELCHANGE(IDC_COMBO_FILE, &UpdateDlg::OnSelchangeComboFile)
ON_CBN_KILLFOCUS(IDC_COMBO_FILE, &UpdateDlg::OnKillfocusComboFile)
ON_WM_SHOWWINDOW()
// User defined message
ON_MESSAGE(USER_MS_UPDATA_PROGRESS, &UpdateDlg::OnUpdateProgress)
END_MESSAGE_MAP()
// See UpdateDlg.h for documentation of this method.
void UpdateDlg::OnOK()
{
// CDialogEx::OnOK();
}
// See UpdateDlg.h for documentation of this method.
void UpdateDlg::OnCancel()
{
// CDialogEx::OnCancel();
}
// See UpdateDlg.h for documentation of this method.
BOOL UpdateDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
// TODO: Add extra initialization here
// Init the image file list
RefreshImageFileList();
// Load saved image address.
m_address = format_cstring(_T("0x%08X"), g_pHistoryData->GetImageAddress());
// Max num of characters is 10, including "0x" leading
((CEdit *)GetDlgItem(IDC_EDIT_ADDRESS))->SetLimitText(10);
// Disable check of auto connect
// This control only takes effect when connected.
((CButton *)GetDlgItem(IDC_CHECK_AUTOCNT))->SetCheck(false);
// Init values are false.
((CButton *)GetDlgItem(IDC_RADIO_ERASE))->SetCheck(m_doErasetoUnlock);
((CButton *)GetDlgItem(IDC_RADIO_UNLOCK))->SetCheck(m_useKeytoUnlock);
GetDlgItem(IDC_STATIC_KEY)->EnableWindow(false);
GetDlgItem(IDC_EDIT_KEY)->EnableWindow(false);
m_progressCtrl.SetRange(0, 100);
// Load save backdoor key
m_backdoorKey = g_pHistoryData->GetBackdoorKey();
// Max num of characters is 16. Must hex digits without "0x" leading.
((CEdit *)GetDlgItem(IDC_EDIT_KEY))->SetLimitText(16);
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
}
// See UpdateDlg.h for documentation of this method.
void UpdateDlg::OnShowWindow(BOOL bShow, UINT nStatus)
{
CDialogEx::OnShowWindow(bShow, nStatus);
if (bShow)
{
// Config page might change the image file list.
// Need refreshing every time open the update page.
RefreshImageFileList();
}
}
// See UpdateDlg.h for documentation of this method.
void UpdateDlg::RefreshImageFileList()
{
// Clear the content.
m_ctrlImageFile.ResetContent();
for (size_t i = 0; i < g_pHistoryData->GetFileCount(); i++)
{
m_ctrlImageFile.AddString(g_pHistoryData->GetFilePath(i));
}
if (g_pHistoryData->GetFileCount() > 0)
{
m_ctrlImageFile.SetCurSel(0);
if (g_pHistoryData->GetFileType(0) == HistoryData::FileType::kBinary)
{
// Enable image address if a binary file is selected.
GetDlgItem(IDC_STATIC_ADDRESS)->EnableWindow(true);
GetDlgItem(IDC_EDIT_ADDRESS)->EnableWindow(true);
}
else
{
GetDlgItem(IDC_STATIC_ADDRESS)->EnableWindow(false);
GetDlgItem(IDC_EDIT_ADDRESS)->EnableWindow(false);
}
GetDlgItem(IDC_BUTTON_UPDATE)->EnableWindow(true);
}
else
{
GetDlgItem(IDC_BUTTON_UPDATE)->EnableWindow(false);
}
}
// See UpdateDlg.h for documentation of this method.
void UpdateDlg::OnBnClickedButtonBrowse()
{
CFileDialog cFileDlg(TRUE);
cFileDlg.m_ofn.lpstrTitle = _T("Select the image file");
cFileDlg.m_ofn.lpstrFilter =
_T("Supported files(*.bin, *.sb, *.srec, *.s19, ")
_T("*.hex)\0*.bin;*.sb;*.srec;*.s19;*.hex\0All files(*.*)\0*.*\0\0");
if (IDOK == cFileDlg.DoModal())
{
CString fullPath = cFileDlg.GetPathName().GetBuffer();
if (file_exists(fullPath))
{
g_pHistoryData->InsertFile(fullPath);
RefreshImageFileList();
}
else
{
PrintLog(_T("Invalid full path filename, or file doesn't exist.(%s)"), fullPath);
}
}
}
// See UpdateDlg.h for documentation of this method.
void UpdateDlg::OnSelchangeComboFile()
{
g_pHistoryData->BubbleSelectedFile(m_ctrlImageFile.GetCurSel());
RefreshImageFileList();
}
// See UpdateDlg.h for documentation of this method.
void UpdateDlg::OnKillfocusComboFile()
{
if (m_ctrlImageFile.GetCurSel() >= 0)
{
// If no change in the textbox, then return;
return;
}
CString filePath;
m_ctrlImageFile.GetWindowTextW(filePath);
// Test if the file exists
if (file_exists(filePath))
{
// File exists, add it to history file list, and refresh commbo box.
g_pHistoryData->InsertFile(filePath);
RefreshImageFileList();
}
else
{
// File doesn't exist.
if (!filePath.IsEmpty())
{
PrintLog(_T("Invalid full path filename, or file doesn't exist.(%s)"), filePath);
}
m_ctrlImageFile.SetCurSel(-1); // Set invalid selection.
GetDlgItem(IDC_BUTTON_UPDATE)->EnableWindow(false);
}
}
// See UpdateDlg.h for documentation of this method.
void UpdateDlg::OnBnClickedRadioErase()
{
// Invert the state, and update the UI
m_doErasetoUnlock = !m_doErasetoUnlock;
((CButton *)GetDlgItem(IDC_RADIO_ERASE))->SetCheck(m_doErasetoUnlock);
if (m_doErasetoUnlock)
{
// if check the flash-erase-all-unsecure, disable backdoor key text input.
GetDlgItem(IDC_STATIC_KEY)->EnableWindow(false);
GetDlgItem(IDC_EDIT_KEY)->EnableWindow(false);
// And uncheck flash-security-disable.
m_useKeytoUnlock = false;
((CButton *)GetDlgItem(IDC_RADIO_UNLOCK))->SetCheck(false);
}
#ifdef _DEBUG
PrintLog(_T("Erase = %s, Unlock = %s"), m_doErasetoUnlock ? _T("True") : _T("False"),
m_useKeytoUnlock ? _T("True") : _T("False"));
#endif
}
// See UpdateDlg.h for documentation of this method.
void UpdateDlg::OnBnClickedRadioUnlock()
{
// Invert the state, and update the UI
m_useKeytoUnlock = !m_useKeytoUnlock;
((CButton *)GetDlgItem(IDC_RADIO_UNLOCK))->SetCheck(m_useKeytoUnlock);
if (m_useKeytoUnlock)
{
// if check the flash-security-disable, enable backdoor key text input.
GetDlgItem(IDC_STATIC_KEY)->EnableWindow(true);
GetDlgItem(IDC_EDIT_KEY)->EnableWindow(true);
// And uncheck flash-erase-all-unsecure.
m_doErasetoUnlock = false;
((CButton *)GetDlgItem(IDC_RADIO_ERASE))->SetCheck(false);
}
else
{
// if uncheck the flash-erase-all-unsecure, disable backdoor key text input.
GetDlgItem(IDC_STATIC_KEY)->EnableWindow(false);
GetDlgItem(IDC_EDIT_KEY)->EnableWindow(false);
}
#ifdef _DEBUG
PrintLog(_T("Erase = %s, Unlock = %s"), m_doErasetoUnlock ? _T("True") : _T("False"),
m_useKeytoUnlock ? _T("True") : _T("False"));
#endif
}
// See UpdateDlg.h for documentation of this method.
void UpdateDlg::OnChangeEdit()
{
// update UI to variables(m_address and m_backdoorKey)
UpdateData(true);
}
// See UpdateDlg.h for documentation of this method.
void UpdateDlg::OnBnClickedButtonUpdate()
{
#ifdef DISABLE_QUICK_UPDATE
if (!g_pBootloader->m_isConneted)
{
PrintLog(_T("No device is connected!\r\nTry to connect device first.\r\n"));
}
#endif
Bootloader::FlashFirmwareOption config;
// Convert CString to std::string.
CString wFullPath;
m_ctrlImageFile.GetWindowTextW(wFullPath);
CStringA tFullPath(wFullPath.GetBuffer());
wFullPath.ReleaseBuffer();
config.imageFilePath = tFullPath.GetBuffer();
tFullPath.ReleaseBuffer();
CString extension = PathFindExtension(wFullPath);
if (extension.CompareNoCase(_T(".bin")) == 0)
{
if (!cstringtoui(m_address, config.baseAddress))
{
PrintLog(_T("Error: Invalid address input.(%s)"), m_address);
return;
}
}
else
{
config.baseAddress = 0;
}
config.doErasetoUnlock = m_doErasetoUnlock && (g_pBootloader->m_targetInfo.securityState != 0);
config.useKeytoUnlock = m_useKeytoUnlock && (g_pBootloader->m_targetInfo.securityState != 0);
CStringA tBackdoorkey(m_backdoorKey.GetBuffer());
config.backdoorkey = tBackdoorkey.GetBuffer();
// For normal update, kill timer when autocnt button is not checked.
if (((CButton *)GetDlgItem(IDC_CHECK_AUTOCNT))->GetCheck() != BST_CHECKED)
{
g_pMainDlg->KillTimer(1);
}
else
{
g_pMainDlg->SetTimer(1, 1000, NULL);
}
#ifndef DISABLE_QUICK_UPDATE
if (g_pBootloader->m_isConneted)
{
#endif
g_pBootloader->UpdateImage(NULL, &config);
#ifndef DISABLE_QUICK_UPDATE
}
else
{
blfwkdll::Updater::PeripheralConfig peripheralConfig;
g_pMainDlg->GetPeripheralConfig(&peripheralConfig);
g_pBootloader->UpdateImage(&peripheralConfig, &config);
}
#endif
}
// See UpdateDlg.h for documentation of this method.
LRESULT UpdateDlg::OnUpdateProgress(WPARAM wParam, LPARAM lParam)
{
int percentage = m_progressCtrl.GetPos();
if (percentage != (int)wParam)
{
percentage = (int)wParam;
GetDlgItem(IDC_STATIC_PROGRESS_BAR)->SetWindowTextW(format_cstring(_T("%2d%%"), percentage));
m_progressCtrl.SetPos(percentage);
}
return 0;
}

View File

@@ -0,0 +1,89 @@
/*
* 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 "afxcmn.h"
// UpdateDlg dialog
/*!
* \brief UpdateDlg class is the UI Dialog class for the
* Update tab page
*/
class UpdateDlg : public CDialogEx
{
DECLARE_DYNAMIC(UpdateDlg)
public:
//! \brief Generated standard constructor.
UpdateDlg(CWnd *pParent = NULL); // standard constructor
//! \brief Generated standard destructor.
virtual ~UpdateDlg();
// Dialog Data
#ifdef AFX_DESIGN_TIME
enum
{
IDD = IDD_DIALOG_UPDATE
};
#endif
protected:
//! \brief Generated message map functions.
virtual void DoDataExchange(CDataExchange *pDX); // DDX/DDV support
DECLARE_MESSAGE_MAP()
virtual void OnOK();
virtual void OnCancel();
public:
//! \brief Generated message map functions.
virtual BOOL OnInitDialog();
afx_msg void OnShowWindow(BOOL bShow, UINT nStatus);
afx_msg void OnSelchangeComboFile();
afx_msg void OnKillfocusComboFile();
afx_msg void OnBnClickedButtonBrowse();
afx_msg void OnBnClickedRadioErase();
afx_msg void OnBnClickedRadioUnlock();
afx_msg void OnChangeEdit();
afx_msg void OnBnClickedButtonUpdate();
afx_msg LRESULT OnUpdateProgress(WPARAM wParam, LPARAM lParam);
//! \brief Refresh the image file list.
void RefreshImageFileList();
CComboBox m_ctrlImageFile; //!< A control variable for the Combox, IDC_COMBO_FILE.
CString m_address; //!< A control variable for the Edit Control, IDC_EDIT_ADDRESS.
CString m_backdoorKey; //!< A control variable for the Edit Control, IDC_EDIT_KEY.
BOOL m_doErasetoUnlock; //!< A variable for whether do
//! flash-erase-all-unsecure command when updating.
BOOL m_useKeytoUnlock; //!< A variable for whether do flash-security-disable
//! command when updating.
CProgressCtrl m_progressCtrl;
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

View File

@@ -0,0 +1,35 @@
/*
* Copyright (c) 2015, 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.
*/
// stdafx.cpp : source file that includes just the standard includes
// KinetisFlashTool.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"

View File

@@ -0,0 +1,102 @@
/*
* Copyright (c) 2015, 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.
*/
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently,
// but are changed infrequently
#pragma once
#ifndef VC_EXTRALEAN
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
#endif
#include "targetver.h"
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit
// turns off MFC's hiding of some common and often safely ignored warning messages
#define _AFX_ALL_WARNINGS
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#include <afxdisp.h> // MFC Automation classes
#ifndef _AFX_NO_OLE_SUPPORT
#include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
#endif
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT
#include <afxcontrolbars.h> // MFC support for ribbons and control bars
// This macro is the same as IMPLEMENT_OLECREATE, except it passes TRUE
// for the bMultiInstance parameter to the COleObjectFactory constructor.
// We want a separate instance of this application to be launched for
// each automation proxy object requested by automation controllers.
#ifndef IMPLEMENT_OLECREATE2
#define IMPLEMENT_OLECREATE2(class_name, external_name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
AFX_DATADEF COleObjectFactory class_name::factory(class_name::guid, RUNTIME_CLASS(class_name), TRUE, \
_T(external_name)); \
const AFX_DATADEF GUID class_name::guid = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } };
#endif // IMPLEMENT_OLECREATE2
#ifdef _UNICODE
#if defined _M_IX86
#pragma comment( \
linker, \
"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_X64
#pragma comment( \
linker, \
"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else
#pragma comment( \
linker, \
"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif
#endif
#define USER_MS_UPDATA_LOG WM_USER + 100
#define USER_MS_CONNECTION_CHANGE WM_USER + 101
#define USER_MS_UPDATA_STATUS WM_USER + 102
#define USER_MS_UPDATA_PROGRESS WM_USER + 103
#include <InitGuid.h>
// GUID interface for COM port device (86E0D1E0-8089-11D0-9CE4-08003E301F73)
DEFINE_GUID(GUID_DEVINTERFACE_COMPORT, 0x86E0D1E0, 0x8089, 0x11D0, 0x9C, 0xE4, 0x08, 0x00, 0x3E, 0x30, 0x1F, 0x73);
// GUID interface for USB device (A5DCBF10-6530-11D2-901F-00C04FB951ED)
DEFINE_GUID(GUID_DEVINTERFACE_USB_DEVICE, 0xA5DCBF10, 0x6530, 0x11D2, 0x90, 0x1F, 0x00, 0xC0, 0x4F, 0xB9, 0x51, 0xED);
// GUID device class for ports (4d36E978-E325-11CE-BFC1-08002BE10318)
DEFINE_GUID(GUID_DEVCLASS_PORTS, 0x4d36E978, 0xE325, 0x11CE, 0xBF, 0xC1, 0x08, 0x00, 0x2B, 0xE1, 0x03, 0x18);
// GUID device class for USB (36FC9E60-C465-11CF-8056-444553540000)
DEFINE_GUID(GUID_DEVCLASS_USB, 0x36FC9E60, 0xC465, 0x11CF, 0x80, 0x56, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00);

View File

@@ -0,0 +1,38 @@
/*
* Copyright (c) 2015, 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
// Including SDKDDKVer.h defines the highest available Windows platform.
// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
#include <SDKDDKVer.h>

View File

@@ -0,0 +1,201 @@
/*
* 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.
*/
#include "stdafx.h"
#include "utility.h"
#include <stdio.h>
#include <stdarg.h>
#include <stdexcept>
#include <string.h>
#include <stdlib.h>
//! Size of the temporary buffer to hold the formatted output string.
#define WIN32_FMT_BUF_LEN (512)
/*!
* \brief Simple template class to free a pointer.
*/
template <typename T>
class free_ptr
{
public:
//! \brief Constructor.
free_ptr(T ptr)
: m_p(ptr)
{
}
//! \brief Destructor.
~free_ptr()
{
if (m_p)
{
free(m_p);
}
}
protected:
T m_p; //!< The value to free.
};
// See utility.h for documentation of this method.
CString format_cstring(const wchar_t *format, ...)
{
LPWSTR buffer;
va_list args;
int len;
int result = -1;
va_start(args, format);
len = _vsctprintf(format, args) + 1;
buffer = (LPWSTR)malloc(len * sizeof(WCHAR));
if (buffer)
{
result = std::vswprintf(buffer, len, format, args);
}
va_end(args);
if (result != -1 && buffer)
{
free_ptr<LPWSTR> freebuf(buffer);
return CString(buffer);
}
return _T("");
}
// See utility.h for documentation of this method.
bool cstringtoi(const CString &s, INT32 &number)
{
if (s.IsEmpty())
return false;
TCHAR *p;
INT64 temp;
temp = _tcstoll(s, &p, 0);
if ((temp > INT32_MAX) || (temp < INT32_MIN))
{
return false;
}
number = static_cast<INT32>(temp);
return (p != NULL) && (*p == 0);
}
// See utility.h for documentation of this method.
bool cstringtoui(const CString &s, UINT32 &number)
{
if (s.IsEmpty())
return false;
if (s[0] == '-')
return false;
TCHAR *p;
UINT64 temp;
temp = _tcstoull(s, &p, 0);
if (temp > UINT32_MAX)
{
return false;
}
number = static_cast<UINT32>(temp);
return (p != NULL) && (*p == 0);
}
// See utility.h for documentation of this method.
CString scale_bytes(UINT64 sizeInBytes)
{
double originalSize = (double)sizeInBytes;
double scaledSize = 0;
scaledSize = originalSize / (1024 * 1024 * 1024);
if (scaledSize >= 1.0) // GB
{
if (sizeInBytes % (1024 * 1024 * 1024))
return format_cstring(_T("%.3f GB"), scaledSize);
else
return format_cstring(_T("%.f GB"), scaledSize);
}
scaledSize = originalSize / (1024 * 1024);
if (scaledSize >= 1.0) // MB
{
if (sizeInBytes % (1024 * 1024))
return format_cstring(_T("%.3f MB"), scaledSize);
else
return format_cstring(_T("%.f MB"), scaledSize);
}
scaledSize = originalSize / 1024;
if (scaledSize >= 1.0) // KB
{
if (sizeInBytes % 1024)
return format_cstring(_T("%.3f KB"), scaledSize);
else
return format_cstring(_T("%.f KB"), scaledSize);
}
else // bytes
{
return format_cstring(_T("%d bytes"), sizeInBytes);
}
} // scale_bytes()
// See utility.h for documentation of this method.
unsigned char hex_to_int(char hex)
{
if (isdigit(hex))
return hex - '0';
else if (hex >= 'a' && hex <= 'f')
return 10 + hex - 'a';
else if (hex >= 'A' && hex <= 'F')
return 10 + hex - 'A';
// unknow char
return 0;
}
// See utility.h for documentation of this method.
char int_to_hex(unsigned char digit)
{
digit &= 0xF;
if (digit < 10)
return digit + '0';
else
return digit - 10 + 'A';
}
// See utility.h for documentation of this method.
bool file_exists(CString fullPath)
{
// Do not use PathFileExists here. folder names should not be acceptable.
CFile testFileExist;
if (!testFileExist.Open(fullPath, CFile::modeRead, NULL))
{
return false;
}
testFileExist.Close();
return true;
}

View File

@@ -0,0 +1,58 @@
/*
* 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
//! \brief Get a formated CString.
CString format_cstring(const wchar_t *fmt, ...);
//! \brief Convert a CString to int.
//!
//! \return false for an error occurred during the conversion.
//! true for success.
bool cstringtoi(const CString &s, INT32 &number);
//! \brief Convert a CString to unsigned int.
//!
//! \return false for an error occurred during the conversion.
//! true for success.
bool cstringtoui(const CString &s, UINT32 &number);
//! \brief Convert unsigned int to formated size string.
CString scale_bytes(UINT64 sizeInBytes);
//! \brief Convert an ASICII hex text to an integer.
unsigned char hex_to_int(char hex);
//! \brief Convert an integer to an ASICII hex.
char int_to_hex(unsigned char digit);
//! \brief Test whether the file exists.
bool file_exists(CString fullPath);