From 34d4d9f465cc29867196bb22b73e811d5b984800 Mon Sep 17 00:00:00 2001 From: pvvx Date: Tue, 7 Feb 2017 12:31:00 +0300 Subject: [PATCH] src pick --- .../iar_utility/common/tools/src/pick.cpp | 136 ++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 RTL00_SDKV35a/component/soc/realtek/8195a/misc/iar_utility/common/tools/src/pick.cpp diff --git a/RTL00_SDKV35a/component/soc/realtek/8195a/misc/iar_utility/common/tools/src/pick.cpp b/RTL00_SDKV35a/component/soc/realtek/8195a/misc/iar_utility/common/tools/src/pick.cpp new file mode 100644 index 0000000..6bd15ae --- /dev/null +++ b/RTL00_SDKV35a/component/soc/realtek/8195a/misc/iar_utility/common/tools/src/pick.cpp @@ -0,0 +1,136 @@ +// pick.cpp : main project file. + +#include "stdafx.h" + +using namespace System; + +#include +#include +#include +//#include +#include +#include +#include + +#define PATTERN_1 0x96969999 +#define PATTERN_2 0xFC66CC3F +#define PATTERN_3 0x03CC33C0 +#define PATTERN_4 0x6231DCE5 + +unsigned int fw_head[4] = { PATTERN_1, PATTERN_2, PATTERN_3, PATTERN_4 }; +unsigned int seg_head[4] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF }; +/* +int main(array ^args) +{ + Console::WriteLine(L"Hello World"); + return 0; +} +*/ +int main(int argc, char* argv[]) +{ + int arg_num = 6; + + if ((argc>5) && (strstr(argv[5], "head"))) arg_num++; + + if (argc != arg_num){ + printf("Usage: pick.exe \n"); + return -1; + } + + unsigned char *buf; + + unsigned int start;//=atoi(argv[1]); + unsigned int end;// = atoi(argv[2]); + unsigned int base; + + int is_raw = 0; + int is_sig = 0; + + char *inf = argv[3]; + char *outf = argv[4]; + + int size; + FILE *ifp, *ofp; + + //if(argv[1][0]=='0'&&(argv[1][1]=='x'||argv[1][1]=='X')) + // sscanf(argv[1], "0x%x", &start); + //else + // start=atoi(argv[1]); + start = strtol(argv[1], NULL, 0); + + //if(argv[2][0]=='0'&&(argv[2][1]=='x'||argv[2][1]=='X')) + // sscanf(argv[2], "0x%x", &end); + //else + // end=atoi(argv[2]); + end = strtol(argv[2], NULL, 0); + + base = start & 0xFFFF0000; + + if (strstr(argv[5], "reset_offset")){ + base = start; + } + + if (strstr(argv[5], "raw")){ + is_raw = 1; + } + else + is_raw = 0; + + if (strstr(argv[5], "sig")){ + is_sig = 1; + } + else + is_sig = 0; + + printf("b:%d s:%d e:%d\n", base, start, end); + //printf("%s %s\n", inf, outf); + + ifp = fopen(inf, "rb"); + if (!ifp) return -2; + ofp = fopen(outf, "wb"); + if (!ofp) return -3; + + fseek(ifp, 0, SEEK_END); + size = ftell(ifp); + + printf("size %d\n", size); + buf = (unsigned char *)malloc(size); + if (!buf) return -4; + + if (end == 0) end = base + size; + + if (end - start + 1 > 0){ + fseek(ifp, start - base, SEEK_SET); + fread(buf, end - start, 1, ifp); + if (is_raw == 0){ + if (strstr(argv[5], "head")){ + int offset = strtol(argv[6], NULL, 0); + printf("append fw head %x\n", offset); + fwrite(fw_head, 4, sizeof(unsigned int), ofp); + seg_head[2] = (0xFFFF0000 | (offset / 1024)); + } + else{ + if (is_sig){ + seg_head[2] = 0x35393138; + seg_head[3] = 0x31313738; + } + else{ + seg_head[2] = 0xFFFFFFFF; + seg_head[3] = 0xFFFFFFFF; + } + } + seg_head[0] = end - start; + seg_head[1] = start; + fwrite(seg_head, 4, sizeof(unsigned int), ofp); + } + fwrite(buf, end - start, 1, ofp); + + } + printf("copy size %d\n", end - start); + fclose(ifp); + fclose(ofp); + free(buf); + + return 0; +} +