Skip to content

Commit

Permalink
rkDevelopTool: initial commit
Browse files Browse the repository at this point in the history
Signed-off-by: liuyi <[email protected]>
  • Loading branch information
liuyi committed Mar 7, 2017
0 parents commit 76af099
Show file tree
Hide file tree
Showing 21 changed files with 5,173 additions and 0 deletions.
117 changes: 117 additions & 0 deletions DefineHeader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#ifndef DEFINE_HEADER
#define DEFINE_HEADER
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <sys/stat.h>
#include <dirent.h>
#include <time.h>
#include <unistd.h>
#include <iconv.h>
#include <wchar.h>
#include <errno.h>
#include <pthread.h>
#include <libusb.h>

#include "Property.hpp"
#include <list>
#include <vector>
#include <set>
#include <string>
#include <sstream>
#include <algorithm>
using namespace std;
typedef unsigned char BYTE, *PBYTE;
typedef unsigned char UCHAR;
typedef unsigned short WCHAR;
typedef unsigned short USHORT;
typedef unsigned int UINT;
typedef unsigned int DWORD;

typedef enum{
RKNONE_DEVICE = 0,
RK27_DEVICE = 0x10,
RKCAYMAN_DEVICE,
RK28_DEVICE = 0x20,
RK281X_DEVICE,
RKPANDA_DEVICE,
RKNANO_DEVICE = 0x30,
RKSMART_DEVICE,
RKCROWN_DEVICE = 0x40,
RK29_DEVICE = 0x50,
RK292X_DEVICE,
RK30_DEVICE = 0x60,
RK30B_DEVICE,
RK31_DEVICE = 0x70,
RK32_DEVICE = 0x80
} ENUM_RKDEVICE_TYPE;
typedef enum{
RK_OS = 0,
ANDROID_OS = 0x1
} ENUM_OS_TYPE;

typedef enum{
RKUSB_NONE = 0x0,
RKUSB_MASKROM = 0x01,
RKUSB_LOADER = 0x02,
RKUSB_MSC = 0x04
} ENUM_RKUSB_TYPE;
typedef enum{
ENTRY471 = 1,
ENTRY472 = 2,
ENTRYLOADER = 4
} ENUM_RKBOOTENTRY;

#pragma pack(1)
typedef struct{
USHORT usYear;
BYTE ucMonth;
BYTE ucDay;
BYTE ucHour;
BYTE ucMinute;
BYTE ucSecond;
} STRUCT_RKTIME, *PSTRUCT_RKTIME;

typedef struct{
char szItemName[20];
char szItemValue[256];
} STRUCT_CONFIG_ITEM, *PSTRUCT_CONFIG_ITEM;
typedef struct _STRUCT_RKDEVICE_DESC{
USHORT usVid;
USHORT usPid;
USHORT usbcdUsb;
UINT uiLocationID;
ENUM_RKUSB_TYPE emUsbType;
ENUM_RKDEVICE_TYPE emDeviceType;
void *pUsbHandle;
} STRUCT_RKDEVICE_DESC, *PSTRUCT_RKDEVICE_DESC;
#pragma pack()
typedef list<STRUCT_RKDEVICE_DESC> RKDEVICE_DESC_SET;
typedef RKDEVICE_DESC_SET::iterator device_list_iter;
typedef vector<string> STRING_VECTOR;
typedef vector<UINT> UINT_VECTOR;
typedef vector<STRUCT_CONFIG_ITEM> CONFIG_ITEM_VECTOR;
typedef enum{
TESTDEVICE_PROGRESS,
DOWNLOADIMAGE_PROGRESS,
CHECKIMAGE_PROGRESS,
TAGBADBLOCK_PROGRESS,
TESTBLOCK_PROGRESS,
ERASEFLASH_PROGRESS,
ERASESYSTEM_PROGRESS,
LOWERFORMAT_PROGRESS,
ERASEUSERDATA_PROGRESS
} ENUM_PROGRESS_PROMPT;

typedef enum{
CALL_FIRST,
CALL_MIDDLE,
CALL_LAST
} ENUM_CALL_STEP;

typedef void (*ProgressPromptCB)(DWORD deviceLayer, ENUM_PROGRESS_PROMPT promptID, long long totalValue, long long currentValue, ENUM_CALL_STEP emCall);

bool WideStringToString(wchar_t *pszSrc, char *&pszDest);
bool StringToWideString(char *pszSrc, wchar_t *&pszDest);
#endif
21 changes: 21 additions & 0 deletions Endian.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef ENDIAN_HEADER
#define ENDIAN_HEADER

#define Endian16_Swap(value) (((((unsigned short)value) << 8) & 0xFF00)|\
((((unsigned short)value) >> 8) & 0x00FF))

#define Endian32_Swap(value) (((((unsigned int)value) << 24) & 0xFF000000) |\
((((unsigned int)value) << 8) & 0x00FF0000) |\
((((unsigned int)value) >> 8) & 0x0000FF00) |\
((((unsigned int)value) >> 24) & 0x000000FF))

#define EndianS16_LtoB(value) ((short)Endian16_Swap(value))
#define EndianS16_BtoL(value) ((short)Endian16_Swap(value))
#define EndianU16_LtoB(value) ((unsigned short)Endian16_Swap(value))
#define EndianU16_BtoL(value) ((unsigned short)Endian16_Swap(value))
#define EndianS32_LtoB(value) ((int)Endian32_Swap(value))
#define EndianS32_BtoL(value) ((int)Endian32_Swap(value))
#define EndianU32_LtoB(value) ((unsigned int)Endian32_Swap(value))
#define EndianU32_BtoL(value) ((unsigned int)Endian32_Swap(value))

#endif
24 changes: 24 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Simple Makefile for RK Flash Tool

CC = g++
LD = $(CC)
CXXFLAGS = -O2 -Wall -fno-strict-aliasing -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE -I/usr/local/include/libusb-1.0
LDFLAGS = -L/usr/local/lib -Wl,-Bstatic -lusb-1.0 -Wl,-Bdynamic -lrt -lpthread


PROGS = $(patsubst %.cpp,%.o, $(wildcard *.cpp))

rkDevelopTool: $(PROGS)
$(CC) $(CXXFLAGS) $^ -o rkDevelopTool $(LDFLAGS)

install: $(PROGS)
install -d -m 0755 /usr/local/bin
install -m 0755 ./rkDevelopTool /usr/local/bin

clean:
rm $(PROGS) ./rkDevelopTool

uninstall:
cd /usr/local/bin && rm -f ./rkDevelopTool


94 changes: 94 additions & 0 deletions Property.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
//-- Property.hpp --

/*--------------------------------------------------------------------------
Class Library
Copyrights Emad Barsoum ([email protected]) 2003. All rights reserved.
________________________________________________________________
PROJECT : General
MODULE : property
FILENAME : Property.hpp
BUILD : 1
History of Modifications:
Date(dd/mm/yyyy)Person Description
---- ------ -----------
25/03/2003 Emad Barsoum Initial design and coding
CLASS NAME: property
VERSION: 1.0
DESCRIPTION:
This class try to simulate property for C++, using template technique.
LICENSE:
You are free to change or modify or redistribute the code, just keep the header.
And you can use this class in any application you want without any warranty.
*/
#include <assert.h>
#include <stdlib.h>
#if !defined INC_PROPERTY_HPP
#define INC_PROPERTY_HPP

#define READ_ONLY 1
#define WRITE_ONLY 2
#define READ_WRITE 3

template<typename Container, typename ValueType, int nPropType>
class property
{
public:
property()
{
m_cObject = NULL;
Set = NULL;
Get = NULL;
}
//-- This to set a pointer to the class that contain the property --
void setContainer(Container* cObject)
{
m_cObject = cObject;
}
//-- Set the set member function that will change the value --
void setter(void (Container::*pSet)(ValueType value))
{
if((nPropType == WRITE_ONLY) || (nPropType == READ_WRITE))
Set = pSet;
else
Set = NULL;
}
//-- Set the get member function that will retrieve the value --
void getter(ValueType (Container::*pGet)())
{
if((nPropType == READ_ONLY) || (nPropType == READ_WRITE))
Get = pGet;
else
Get = NULL;
}
//-- Overload the '=' sign to set the value using the set member --
ValueType operator =(const ValueType& value)
{
assert(m_cObject != NULL);
assert(Set != NULL);
(m_cObject->*Set)(value);
return value;
}

//-- To make possible to cast the property class to the internal type --
operator ValueType()
{
assert(m_cObject != NULL);
assert(Get != NULL);
return (m_cObject->*Get)();
}

private:
Container* m_cObject;//-- Pointer to the module that contain the property --
void (Container::*Set)(ValueType value);//-- Pointer to set member function --
ValueType (Container::*Get)();//-- Pointer to get member function --
};

#endif
Loading

0 comments on commit 76af099

Please sign in to comment.