commit
33 files changed, 1664 insertions(+), 0 deletions(-)

A => ameba_tools_macosx/amebasize
A => ameba_tools_macosx/bsp/image/ram_1.p.bin
A => ameba_tools_macosx/bsp/image/ram_1.r.bin
A => ameba_tools_macosx/postbuild_img2_arduino_macosx
A => ameba_tools_macosx/tools/macosx/checksum
A => ameba_tools_macosx/tools/macosx/padding
A => ameba_tools_macosx/tools/macosx/pick
A => ameba_tools_macosx/tools/macosx/src/amebasize.c
A => ameba_tools_macosx/tools/macosx/src/checksum.c
A => ameba_tools_macosx/tools/macosx/src/padding.c
A => ameba_tools_macosx/tools/macosx/src/pick.c
A => ameba_tools_macosx/tools/macosx/src/postbuild_img2_arduino_macosx.cpp
A => ameba_tools_macosx/tools/macosx/src/upload_dap_macosx.cpp
A => ameba_tools_macosx/tools/macosx/src/upload_ota_macosx.c
A => ameba_tools_macosx/upload_dap_macosx
A => ameba_tools_macosx/upload_ota_macosx
A => ameba_tools_windows/amebasize.exe
A => ameba_tools_windows/bsp/image/ram_1.p.bin
A => ameba_tools_windows/bsp/image/ram_1.r.bin
A => ameba_tools_windows/postbuild_img2_arduino_windows.exe
A => ameba_tools_windows/tools/windows/checksum.exe
A => ameba_tools_windows/tools/windows/padding.exe
A => ameba_tools_windows/tools/windows/pick.exe
A => ameba_tools_windows/tools/windows/src/amebasize.c
A => ameba_tools_windows/tools/windows/src/checksum.c
A => ameba_tools_windows/tools/windows/src/padding.c
A => ameba_tools_windows/tools/windows/src/pick.c
A => ameba_tools_windows/tools/windows/src/postbuild_img2_arduino_windows.cpp
A => ameba_tools_windows/tools/windows/src/simplesort.cpp
A => ameba_tools_windows/tools/windows/src/upload_dap.cpp
A => ameba_tools_windows/tools/windows/src/upload_ota.c
A => ameba_tools_windows/upload_dap.exe
A => ameba_tools_windows/upload_ota.exe
A => ameba_tools_macosx/amebasize +0 -0

        
A => ameba_tools_macosx/bsp/image/ram_1.p.bin +0 -0

        
A => ameba_tools_macosx/bsp/image/ram_1.r.bin +0 -0

        
A => ameba_tools_macosx/postbuild_img2_arduino_macosx +0 -0

        
A => ameba_tools_macosx/tools/macosx/checksum +0 -0

        
A => ameba_tools_macosx/tools/macosx/padding +0 -0

        
A => ameba_tools_macosx/tools/macosx/pick +0 -0

        
A => ameba_tools_macosx/tools/macosx/src/amebasize.c +47 -0
@@ 0,0 1,47 @@ 
+/*
+
+Compile command:
+	gcc -o amebasize tools/macosx/src/amebasize.c
+
+*/
+
+#include <stdio.h>
+
+int main(int argc, char *argv[]) {
+
+	int size;
+	char filename[512];
+
+	if (argc < 2) {
+		return -1;
+	}
+
+	sprintf(filename, "%s/ram_1.p.bin", argv[1]);
+	FILE* fp_bootloader = fopen(filename, "rb");
+	if (fp_bootloader != NULL) {
+		fseek(fp_bootloader, 0L, SEEK_END);
+		size = ftell(fp_bootloader);
+		fclose(fp_bootloader);
+		printf("bootloader %d\n", size);
+	}
+
+	sprintf(filename, "%s/ram_2.p.bin", argv[1]);
+	FILE* fp_img2 = fopen(filename, "rb");
+	if (fp_img2 != NULL) {
+		fseek(fp_img2, 0L, SEEK_END);
+		size = ftell(fp_img2);
+		fclose(fp_img2);
+		printf("image2 %d\n", size);
+	}
+
+	sprintf(filename, "%s/ram_3.p.bin", argv[1]);
+	FILE* fp_img3 = fopen(filename, "rb");
+	if (fp_img3 != NULL) {
+		fseek(fp_img3, 0L, SEEK_END);
+		size = ftell(fp_img3);
+		fclose(fp_img3);
+		printf("image3 %d\n", size);
+	}
+
+	return 0;
+}

          
A => ameba_tools_macosx/tools/macosx/src/checksum.c +57 -0
@@ 0,0 1,57 @@ 
+// checksum.cpp : Defines the entry point for the console application.
+
+/*
+
+Compile command:
+	gcc -o tools/macosx/checksum tools/macosx/src/checksum.c
+
+*/
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+int main(int argc, char *argv[])
+{
+	FILE *fp;
+	unsigned int checksum = 0;
+	//unsigned char buf[502000]; //MAX FW Size = 512K-44K/2 = 501760
+	unsigned char *buf;
+	int i;
+	int size = 0;
+
+	if(argc != 2)	return -1;
+
+	fp = fopen(argv[1], "rb+");
+	if(!fp)	return -2;
+
+
+	fseek(fp,0L,SEEK_END);
+	size = ftell(fp);
+	fseek(fp,0L,SEEK_SET);
+	
+	buf = malloc(size+100);
+	if(!buf){
+		fclose(fp);
+		return -3;
+	}
+	
+	printf("size = %d \n\r", size);
+
+	memset(buf, 0, size+100);
+
+	fread(buf, 1, size, fp);
+
+	for(i=0;i<size;i++){
+		checksum += buf[i];
+	}
+	
+	fseek(fp,0L,SEEK_END);
+	
+	fwrite(&checksum, sizeof(int), 1, fp);
+
+	printf("checksum %x\n\r", checksum);
+
+	free(buf);
+	fclose(fp);
+}

          
A => ameba_tools_macosx/tools/macosx/src/padding.c +46 -0
@@ 0,0 1,46 @@ 
+/*
+
+Compile command:
+	gcc -o tools/macosx/padding tools/macosx/src/padding.c
+
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+int main(int argc, char *argv[])
+{
+	FILE* fp;
+
+	// argv[1] -> length
+	// argv[2] -> data
+	// argv[3] -> output file name
+	char	*unit;
+	int 	length = strtod(argv[1], &unit);
+	char	data = strtod(argv[2], NULL);
+	char	*buf;
+
+	printf("total %d %s, padding data %x, name %s\n", length, unit, data&0xFF, argv[3]);
+	if(unit[0]==0)	length*=1;
+	else if(unit[0]=='K'||unit[0]=='k')	length*=1024;
+	else if(unit[0]=='M'||unit[0]=='m')	length*=(1024*1024);
+	else if(unit[0]=='G'||unit[0]=='g')	length*=(1024*1024);
+	else {
+		printf("unit %s is Not valid\n", unit);
+		return -1;
+	}
+	fp = fopen(argv[3], "r+b");
+	if(!fp)	return -1;
+
+	buf = malloc(length);
+	memset(buf, data, length);
+	printf("Original size %zd\n", fread(buf, 1, length, fp));
+	fseek(fp, 0, SEEK_SET);
+	printf("Padding  size %zd\n", fwrite(buf, 1, length, fp));
+	
+	free(buf);
+	fclose(fp);
+
+	return 0;
+}

          
A => ameba_tools_macosx/tools/macosx/src/pick.c +126 -0
@@ 0,0 1,126 @@ 
+/*
+
+Compile command:
+	gcc -o tools/macosx/pick tools/macosx/src/pick.c
+
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/stat.h> 
+#include <fcntl.h>
+#include <sys/types.h>
+
+#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(int argc, char* argv[])
+{
+	int arg_num = 6;
+
+	if(strstr(argv[5],"head"))	arg_num++;
+
+	if(argc!=arg_num){
+			printf("Usage: pick.exe <start addr> <end addr> <input name> <output name> <body[+offset] , head [image2_start]>\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 = 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(strcmp(argv[5],"head")==0){
+				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;
+}

          
A => ameba_tools_macosx/tools/macosx/src/postbuild_img2_arduino_macosx.cpp +209 -0
@@ 0,0 1,209 @@ 
+/*
+
+Compile command:
+    g++ -o postbuild_img2_arduino_macosx tools/macosx/src/postbuild_img2_arduino_macosx.cpp
+
+*/
+
+#include <iostream>
+#include <sstream>
+#include <cstring>
+#include <cstdlib>
+#include <fstream>
+#include <unistd.h>
+#include <vector>
+
+using namespace std;
+
+int main(int argc, char *argv[]) {
+
+	int ret = 0;
+    stringstream cmdss;
+    string cmd, line, msg;
+	vector<string> lines;
+	vector<string>::iterator iter;
+    string path_tool;
+    string path_arm_none_eabi_gcc;
+	string path_symbol_black_list;
+	string bksym;
+    ifstream fin;
+
+    bool has_sdram = false;
+    string sram_start_st = "", sram_end_st = "", sdram_start_st = "", sdram_end_st = "";
+    unsigned int sram_start = 0, sram_end = 0, sdram_start = 0, sdram_end = 0;
+
+    size_t pos;
+
+    // 0. change work folder
+    chdir(argv[1]);
+
+    // 1. copy elf application.axf to current folder
+    cmdss.clear();
+    cmdss << "cp " << argv[2] << " ./";
+    getline(cmdss, cmd);
+    cout << cmd << endl;
+    system(cmd.c_str());
+
+    // 2. remove previous files
+    cmd = "rm -f application.map";
+    cout << cmd << endl;
+    system(cmd.c_str());
+
+    cmd = "rm -f application.asm";
+    cout << cmd << endl;
+    system(cmd.c_str());
+
+    cmd = "rm -f *.bin";
+    cout << cmd << endl;
+    system(cmd.c_str());
+
+    // 3. generate information files
+    path_arm_none_eabi_gcc.assign(argv[3]);
+
+    cmdss.clear();
+    cmdss << path_arm_none_eabi_gcc << "arm-none-eabi-nm --numeric-sort application.axf > application.map";
+    getline(cmdss, cmd);
+    cout << cmd << endl;
+    system(cmd.c_str());
+
+    fin.open("application.map");
+    while( getline(fin, line) ) {
+        lines.push_back(line);
+    }
+    fin.close();
+
+    cmdss.clear();
+    cmdss << path_arm_none_eabi_gcc << "arm-none-eabi-objdump -d application.axf > application.asm";
+    getline(cmdss, cmd);
+    cout << cmd << endl;
+    system(cmd.c_str());
+
+	// 3.1 check if any forbidden symbols
+	path_symbol_black_list.assign(argv[4]);
+	fin.open(path_symbol_black_list.c_str(), ifstream::in);
+	cout << path_symbol_black_list << endl;
+	ret = 0;
+	if (fin) {
+		while ( !fin.eof() && ret == 0) {
+			fin >> bksym;
+			getline(fin, msg);
+
+			// check if this symbole appears in the map file
+			for (iter = lines.begin(); iter != lines.end(); ++iter) {
+				if ( (iter->find(bksym)) != string::npos ) {
+					cerr << endl << "ERROR: " << msg << endl << endl;
+					ret = -1;
+					break;
+				}
+			}
+		}
+	}
+	fin.close();
+
+	if (ret != 0) {
+		return -1;
+	}
+
+    // 4. grep sram and sdram information
+    for (iter = lines.begin(); iter != lines.end(); ++iter) {
+        line = *iter;
+        pos = line.find("__ram_image2_text_start__");
+        if ( pos != string::npos ) {
+            sram_start_st = line.substr(0, pos-3);
+            sram_start = strtol(sram_start_st.c_str(), NULL, 16);
+        }
+        pos = line.find("__ram_image2_text_end__");
+        if ( pos != string::npos ) {
+            sram_end_st = line.substr(0, pos-3);
+            sram_end = strtol(sram_end_st.c_str(), NULL, 16);
+        }
+        pos = line.find("__sdram_data_start__");
+        if ( pos != string::npos ) {
+            sdram_start_st = line.substr(0, pos-3);
+            sdram_start = strtol(sdram_start_st.c_str(), NULL, 16);
+        }
+        pos = line.find("__sdram_data_end__");
+        if ( pos != string::npos ) {
+            sdram_end_st = line.substr(0, pos-3);
+            sdram_end = strtol(sdram_end_st.c_str(), NULL, 16);
+        }
+    }
+
+    if (sdram_start > 0 && sdram_end > 0) {
+        has_sdram = true;
+    }
+
+    cout << "sram  " << sram_start_st << " ~ " << sram_end_st << endl;
+    if (has_sdram) {
+        cout << "sdram " << sdram_start_st << " ~ " << sdram_end_st << endl;
+    }
+
+    // 5. generate image 2 and image 3
+    cmdss.clear();
+    cmdss << path_arm_none_eabi_gcc << "arm-none-eabi-objcopy -j .image2.start.table -j .ram_image2.text -j .ram.data -Obinary ./application.axf ./ram_2.bin";
+    getline(cmdss, cmd);
+    cout << cmd << endl;
+    system(cmd.c_str());
+
+    if (has_sdram) {
+        cmdss.clear();
+        cmdss << path_arm_none_eabi_gcc << "arm-none-eabi-objcopy -j .image3 -j .ARM.exidx -j .sdr_data -Obinary ./application.axf ./sdram.bin";
+        getline(cmdss, cmd);
+        cout << cmd << endl;
+        system(cmd.c_str());
+    }
+
+    // 6. fulfill header
+    cmdss.clear();
+    cmdss << "./tools/macosx/pick " << sram_start << " " << sram_end << " ram_2.bin ram_2.p.bin body+reset_offset+sig";
+    getline(cmdss, cmd);
+    cout << cmd << endl;
+    system(cmd.c_str());
+
+    cmdss.clear();
+    cmdss << "./tools/macosx/pick " << sram_start << " " << sram_end << " ram_2.bin ram_2.ns.bin body+reset_offset";
+    getline(cmdss, cmd);
+    cout << cmd << endl;
+    system(cmd.c_str());
+
+    if (has_sdram) {
+        cmdss.clear();
+        cmdss << "./tools/macosx/pick " << sdram_start << " " << sdram_end << " sdram.bin ram_3.p.bin body+reset_offset";
+        getline(cmdss, cmd);
+        cout << cmd << endl;
+        system(cmd.c_str());
+    }
+
+    // 7. prepare image 1
+    cmd = "cp bsp/image/ram_1.p.bin ./";
+    cout << cmd << endl;
+    system(cmd.c_str());
+
+    cmd = "./tools/macosx/padding 44k 0xFF ram_1.p.bin";
+    cout << cmd << endl;
+    system(cmd.c_str());
+
+    // 8. generate ram_all.bin
+    if (has_sdram) {
+        cmd = "cat ram_1.p.bin ram_2.p.bin ram_3.p.bin > ram_all.bin";
+        cout << cmd << endl;
+        system(cmd.c_str());
+        cmd = "cat ram_2.ns.bin ram_3.p.bin > ota.bin";
+        cout << cmd << endl;
+        system(cmd.c_str());
+    } else {
+        cmd = "cat ram_1.p.bin ram_2.p.bin > ram_all.bin";
+        cout << cmd << endl;
+        system(cmd.c_str());
+        cmd = "cat ram_2.ns.bin > ota.bin";
+        cout << cmd << endl;
+        system(cmd.c_str());
+    }
+
+    // 9. add checksum
+    cmd = "./tools/macosx/checksum ota.bin";
+    cout << cmd << endl;
+    system(cmd.c_str());
+
+    return 0;
+}

          
A => ameba_tools_macosx/tools/macosx/src/upload_dap_macosx.cpp +82 -0
@@ 0,0 1,82 @@ 
+/*
+
+Compile command:
+        g++ -o upload_dap_macosx tools/macosx/src/upload_dap_macosx.cpp
+
+*/
+
+#include <iostream>
+#include <sstream>
+#include <vector>
+#include <cstring>
+#include <cstdlib>
+#include <string>
+#include <cstdio>
+#include <sys/stat.h>
+
+using namespace std;
+
+bool isFileExist(string path) {
+	bool ret = false;
+	struct stat info;
+
+	do {
+		if (stat(path.c_str(), &info) != 0) {
+			break;
+		}
+
+		ret = true;
+	} while (0);
+
+	return ret;
+}
+
+int main(int argc, char *argv[]) {
+
+	int i;
+	bool mbed_disk_found = false;
+
+	string cmd;
+	vector<string> lines;
+	vector<string>::iterator iter;
+
+	stringstream ss;
+	string disk_caption;
+	string disk_volumename;
+	string filepath;
+
+	string filepath_ram_all;
+	if (argc >= 2) {
+		// the path of ram_all.bin is feed from arg
+		filepath_ram_all.assign(argv[1]);
+	} else {
+		// assume ram_all.bin is in current path
+		filepath_ram_all.assign("ram_all.bin");
+	}
+
+	do {
+		// 2. check if MBED disk is accessable
+		filepath = "/Volumes/MBED/mbed.htm";
+		if (!isFileExist(filepath)) {
+			cout << "ERR: Cannot access mbed driver!" << endl;
+			break;
+		}
+
+		// 3. check if ram_all.bin exist
+		if (!isFileExist(filepath_ram_all)) {
+			cout << "ERR: Cannot find ram_all.bin!" << endl;
+			break;
+		}
+
+		// 4. copy ram_all.bin into mbed device
+		cout << "uploading..." << endl;
+		cmd = "cp \"" + filepath_ram_all;
+		cmd.append("\" /Volumes/MBED/;sync");
+		cout << cmd << endl;
+		system(cmd.c_str());
+
+		cout << "upload finish" << endl;
+	} while (0);
+
+	return 0;
+}

          
A => ameba_tools_macosx/tools/macosx/src/upload_ota_macosx.c +187 -0
@@ 0,0 1,187 @@ 
+/*
+
+Compile command:
+	gcc -o upload_ota_macosx tools/macosx/src/upload_ota_macosx.c
+
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include "getopt.h"
+
+#define BUF_SIZE 256
+
+#define CMD_FILENAME    0x01
+#define CMD_IP          0x02
+#define CMD_PORT        0x04
+#define CMD_HELP        0x08
+
+#define CHUNK_SIZE 1460
+
+static struct option long_options[] = {
+    {"file",      required_argument, 0, 'f'},
+    {"interface", required_argument, 0, 'i'},
+    {"port",      required_argument, 0, 'p'},
+    {"help",      no_argument,       0, 'h'},
+    {0,           0,                 0,  0 }
+};
+
+void dumpMenu() {
+    printf("Usage: upload_ota\r\n");
+    printf("  -f  --file       the OTA image to be uploaded\r\n");
+    printf("  -i  --interface  the network ip address\r\n");
+    printf("  -p  --port       the network port\r\n");
+    printf("  -h  --help\r\n");
+}
+
+void ota_process(char *filename, char *ipstring, int port) {
+
+    FILE *pFile;
+    struct stat info;
+    uint32_t ota_description[3];
+    long filesize;
+    unsigned char *ota_buf = NULL;
+
+    uint32_t checksum = 0;
+
+    int s;
+    struct sockaddr_in server;
+    int i, n;
+    int processed_size;
+
+    printf("file: %s\r\n", filename);
+    printf("ip: %s\r\n", ipstring);
+    printf("port: %d\r\n", port);
+
+    do {
+        pFile = fopen(filename, "rb");
+        if ( pFile == NULL ) {
+            printf("ERR: Fail to open file: %s\r\n", filename);
+            break;
+        }
+
+        // get file size;
+        fseek(pFile, 0L, SEEK_END);
+        filesize = ftell(pFile);
+        fseek(pFile, 0, SEEK_SET);
+
+        ota_buf = (unsigned char *) malloc (filesize);
+        if (ota_buf == NULL) {
+            printf("ERR: no enough memory\r\n");
+            break;
+        }
+        fread(ota_buf, 1, filesize, pFile);
+        fclose(pFile);
+
+        checksum = 0;
+        for (i=0; i<filesize; i++) {
+            checksum += (ota_buf[i] & 0xff);
+        }
+
+        s = socket(AF_INET, SOCK_STREAM, 0);
+        if (s < 0) {
+            printf("ERR: Could not create socket\r\n");
+            break;
+        }
+
+        server.sin_addr.s_addr = inet_addr(ipstring);
+        server.sin_family = AF_INET;
+        server.sin_port = htons( port );
+
+        printf("Try to connect...\r\n");
+        if ( connect(s, (struct sockaddr *)&server, sizeof(server)) < 0 ) {
+            printf("ERR: Connect error\r\n");
+            break;
+        }
+
+        ota_description[0] = checksum;
+        ota_description[1] = 0;
+        ota_description[2] = (uint32_t) filesize;
+
+        printf("Send OTA info...\r\n");
+        n = send(s, (unsigned char *)ota_description, sizeof(ota_description), 0);
+        if (n < 0) {
+            printf("ERR: fail to send OTA description\r\n");
+            break;
+        }
+
+        printf("String uploading...\r\n");
+        n = send(s, (const char *)ota_buf, filesize, 0);
+        if (n < 0) {
+            printf("ERR: fail to send OTA image\r\n");
+            break;
+        }
+
+        close(s);
+
+        printf("Upload success\r\n");
+
+    } while (0);
+
+    if (ota_buf != NULL) {
+        free(ota_buf);
+        ota_buf = NULL;
+    }
+}
+
+int main(int argc, char *argv[]) {
+
+    int c;
+    int opt_idx = 0;
+
+    unsigned char cmd = 0;
+
+    char filename[BUF_SIZE];
+    char ipstring[16];
+    char portstring[10];
+    int port;
+
+    while (1) {
+        c = getopt_long(argc, argv, "f:i:p:h?", long_options, &opt_idx);
+
+        if (c== -1) break;
+
+        switch (c) {
+            case 'f':
+                sprintf(filename, "%s", optarg);
+                cmd |= CMD_FILENAME;
+                break;
+            case 'i':
+                if (strlen(optarg) < 16) {
+                    sprintf(ipstring, "%s", optarg);
+                    cmd |= CMD_IP;
+                }
+                break;
+            case 'p':
+                if (strlen(optarg) < 10) {
+                    sprintf(portstring, "%s", optarg);
+                    cmd |= CMD_PORT;
+                }
+                break;
+            case 'h':
+            case '?':
+            default:
+                cmd |= CMD_HELP;
+                break;
+        }
+    }
+
+    if (cmd & CMD_HELP) {
+        dumpMenu();
+    } else if (cmd & (CMD_FILENAME | CMD_IP | CMD_PORT)) {
+        port = atoi(portstring);
+        ota_process(filename, ipstring, port);
+    } else {
+        dumpMenu();
+    }
+
+    return 0;
+}
+

          
A => ameba_tools_macosx/upload_dap_macosx +0 -0

        
A => ameba_tools_macosx/upload_ota_macosx +0 -0

        
A => ameba_tools_windows/amebasize.exe +0 -0

        
A => ameba_tools_windows/bsp/image/ram_1.p.bin +0 -0

        
A => ameba_tools_windows/bsp/image/ram_1.r.bin +0 -0

        
A => ameba_tools_windows/postbuild_img2_arduino_windows.exe +0 -0

        
A => ameba_tools_windows/tools/windows/checksum.exe +0 -0

        
A => ameba_tools_windows/tools/windows/padding.exe +0 -0

        
A => ameba_tools_windows/tools/windows/pick.exe +0 -0

        
A => ameba_tools_windows/tools/windows/src/amebasize.c +47 -0
@@ 0,0 1,47 @@ 
+/*
+
+Compile under windows (using mingw):
+    mingw32-gcc.exe -o amebasize.exe tools\windows\src\amebasize.c -static
+
+*/
+
+#include <stdio.h>
+
+int main(int argc, char *argv[]) {
+
+	int size;
+	char filename[512];
+
+	if (argc < 2) {
+		return -1;
+	}
+
+	sprintf(filename, "%s\\ram_1.p.bin", argv[1]);
+	FILE* fp_bootloader = fopen(filename, "rb");
+	if (fp_bootloader != NULL) {
+		fseek(fp_bootloader, 0L, SEEK_END);
+		size = ftell(fp_bootloader);
+		fclose(fp_bootloader);
+		printf("bootloader %d\n", size);
+	}
+
+	sprintf(filename, "%s\\ram_2.p.bin", argv[1]);
+	FILE* fp_img2 = fopen(filename, "rb");
+	if (fp_img2 != NULL) {
+		fseek(fp_img2, 0L, SEEK_END);
+		size = ftell(fp_img2);
+		fclose(fp_img2);
+		printf("image2 %d\n", size);
+	}
+
+	sprintf(filename, "%s\\ram_3.p.bin", argv[1]);
+	FILE* fp_img3 = fopen(filename, "rb");
+	if (fp_img3 != NULL) {
+		fseek(fp_img3, 0L, SEEK_END);
+		size = ftell(fp_img3);
+		fclose(fp_img3);
+		printf("image3 %d\n", size);
+	}
+
+	return 0;
+}
  No newline at end of file

          
A => ameba_tools_windows/tools/windows/src/checksum.c +107 -0
@@ 0,0 1,107 @@ 
+// checksum.cpp : Defines the entry point for the console application.
+
+/*
+
+Compile command:
+	mingw32-gcc.exe -o tools\windows\checksum.exe tools\windows\src\checksum.c -static
+
+*/
+
+#if 1
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+int main(int argc, char *argv[])
+{
+	FILE *fp;
+	unsigned int checksum = 0;
+	//unsigned char buf[502000]; //MAX FW Size = 512K-44K/2 = 501760
+	unsigned char *buf;
+	int i;
+	int size = 0;
+
+	if(argc != 2)	return -1;
+
+	fp = fopen(argv[1], "rb+");
+	if(!fp)	return -2;
+
+
+	fseek(fp,0L,SEEK_END);
+	size = ftell(fp);
+	fseek(fp,0L,SEEK_SET);
+	
+	buf = malloc(size+100);
+	if(!buf){
+		fclose(fp);
+		return -3;
+	}
+	
+	printf("size = %d \n\r", size);
+
+	memset(buf, 0, size+100);
+
+	fread(buf, 1, size, fp);
+
+	for(i=0;i<size;i++){
+		checksum += buf[i];
+	}
+	
+	fseek(fp,0L,SEEK_END);
+	
+	fwrite(&checksum, sizeof(int), 1, fp);
+
+	printf("checksum %x\n\r", checksum);
+
+	free(buf);
+	fclose(fp);
+}
+
+#else
+
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+int main(int argc, char *argv[])
+{
+	//FILE *fp;
+	int fd;	
+	unsigned int checksum = 0;
+	
+	if(argc != 2)	return -1;
+
+	//fp = fopen(argv[1], "r+");
+	//if(!fp)	return -2;
+	fd = open(argv[1], O_RDWR);
+	if(fd<0) return -2;
+
+	//fseek(fp, 0, SEEK_SET);
+	lseek(fd, 0, SEEK_SET);
+	int size = lseek(fd, 0, SEEK_END);
+	lseek(fd, 0, SEEK_SET);
+
+	printf("size = %d \n\r", size);
+
+	unsigned char buf[size+100];
+
+	memset(buf, 0, size+100);
+
+	read(fd, buf, size);
+
+	for(int i=0;i<size;i++){
+		checksum += buf[i];
+	}
+	
+	lseek(fd, 0, SEEK_END);
+	
+	write(fd, &checksum, sizeof(int));
+
+	printf("checksum %x\n\r", checksum);
+	close(fd);
+}
+#endif

          
A => ameba_tools_windows/tools/windows/src/padding.c +44 -0
@@ 0,0 1,44 @@ 
+/*
+
+Compile command:
+	mingw32-gcc.exe -o tools\windows\padding.exe tools\windows\src\padding.c -static
+
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+void main(int argc, char *argv[])
+{
+	FILE* fp;
+
+	// argv[1] -> length
+	// argv[2] -> data
+	// argv[3] -> output file name
+	char	*unit;
+	int 	length = strtod(argv[1], &unit);
+	char	data = strtod(argv[2], NULL);
+	char	*buf;
+
+	printf("total %d %s, padding data %x, name %s\n", length, unit, data&0xFF, argv[3]);
+	if(unit[0]==0)	length*=1;
+	else if(unit[0]=='K'||unit[0]=='k')	length*=1024;
+	else if(unit[0]=='M'||unit[0]=='m')	length*=(1024*1024);
+	else if(unit[0]=='G'||unit[0]=='g')	length*=(1024*1024);
+	else {
+		printf("unit %s is Not valid\n", unit);
+		return;
+	}
+	fp = fopen(argv[3], "r+b");
+	if(!fp)	return;
+
+	buf = malloc(length);
+	memset(buf, data, length);
+	printf("Original size %zd\n", fread(buf, 1, length, fp));
+	fseek(fp, 0, SEEK_SET);
+	printf("Padding  size %zd\n", fwrite(buf, 1, length, fp));
+	
+	free(buf);
+	fclose(fp);
+}

          
A => ameba_tools_windows/tools/windows/src/pick.c +126 -0
@@ 0,0 1,126 @@ 
+/*
+
+Compile command:
+	mingw32-gcc.exe -o tools\windows\pick.exe tools\windows\src\pick.c -static
+
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/stat.h> 
+#include <fcntl.h>
+#include <sys/types.h>
+
+#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(int argc, char* argv[])
+{
+	int arg_num = 6;
+
+	if(strstr(argv[5],"head"))	arg_num++;
+
+	if(argc!=arg_num){
+			printf("Usage: pick.exe <start addr> <end addr> <input name> <output name> <body[+offset] , head [image2_start]>\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 = 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(strcmp(argv[5],"head")==0){
+				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;
+}

          
A => ameba_tools_windows/tools/windows/src/postbuild_img2_arduino_windows.cpp +236 -0
@@ 0,0 1,236 @@ 
+/*
+
+Compile command:
+	mingw32-g++.exe -o postbuild_img2_arduino_windows.exe tools\windows\src\postbuild_img2_arduino_windows.cpp -static
+
+*/
+
+#include <iostream>
+#include <sstream>
+#include <cstring>
+#include <cstdlib>
+#include <fstream>
+#include <unistd.h>
+#include <vector>
+
+using namespace std;
+
+void replaceAll( string& source, const string& from, const string& to )
+{
+    string newString;
+    newString.reserve( source.length() );  // avoids a few memory allocations
+
+    string::size_type lastPos = 0;
+    string::size_type findPos;
+
+    while( string::npos != ( findPos = source.find( from, lastPos )))
+    {
+        newString.append( source, lastPos, findPos - lastPos );
+        newString += to;
+        lastPos = findPos + from.length();
+    }
+
+    // Care for the rest after last occurrence
+    newString += source.substr( lastPos );
+
+    source.swap( newString );
+}
+
+int main(int argc, char *argv[]) {
+
+	int ret = 0;
+    stringstream cmdss;
+    string cmd, line, msg;
+	vector<string> lines;
+	vector<string>::iterator iter;
+    string path_tool;
+    string path_arm_none_eabi_gcc;
+	string path_symbol_black_list;
+	string bksym;
+    ifstream fin;
+    ofstream fout;
+
+    bool has_sdram = false;
+    string sram_start_st = "", sram_end_st = "", sdram_start_st = "", sdram_end_st = "";
+    unsigned int sram_start = 0, sram_end = 0, sdram_start = 0, sdram_end = 0;
+
+    size_t pos;
+
+    // 0. change work folder
+    chdir(argv[1]);
+
+    // 1. copy elf application.axf to current folder
+    cmdss.clear();
+    cmdss << "xcopy /y " << argv[2] << " .\\";
+    getline(cmdss, cmd);
+    cout << cmd << endl;
+    system(cmd.c_str());
+
+    // 2. remove previous files
+    cmd = "if exist application.map del application.map";
+    cout << cmd << endl;
+    system(cmd.c_str());
+
+    cmd = "if exist application.asm del application.asm";
+    cout << cmd << endl;
+    system(cmd.c_str());
+
+    cmd = "if exist *.bin del *.bin";
+    cout << cmd << endl;
+    system(cmd.c_str());
+
+    // 3. generate information files
+    path_arm_none_eabi_gcc.assign(argv[3]);
+    replaceAll(path_arm_none_eabi_gcc, "/", "\\");
+
+    cmdss.clear();
+    cmdss << "\"" <<path_arm_none_eabi_gcc << "arm-none-eabi-nm.exe\" --numeric-sort application.axf > application.map";
+    getline(cmdss, cmd);
+    cout << cmd << endl;
+    system(cmd.c_str());
+
+    fin.open("application.map");
+    while( getline(fin, line) ) {
+        lines.push_back(line);
+    }
+    fin.close();
+
+    cmdss.clear();
+    cmdss << "\"" <<path_arm_none_eabi_gcc << "arm-none-eabi-objdump.exe\" -d application.axf > application.asm";
+    getline(cmdss, cmd);
+    cout << cmd << endl;
+    system(cmd.c_str());
+
+	// 3.1 check if any forbidden symbols
+	path_symbol_black_list.assign(argv[4]);
+	replaceAll(path_symbol_black_list, "/", "\\");
+	fin.open(path_symbol_black_list.c_str(), ifstream::in);
+	cout << path_symbol_black_list << endl;
+	ret = 0;
+	if (fin) {
+		while ( !fin.eof() && ret == 0) {
+			fin >> bksym;
+			getline(fin, msg);
+
+			// check if this symbole appears in the map file
+			for (iter = lines.begin(); iter != lines.end(); ++iter) {
+				if ( (iter->find(bksym)) != string::npos ) {
+					cerr << "ERROR: " << msg << endl;
+					ret = -1;
+					break;
+				}
+			}
+		}
+	}
+	fin.close();
+
+	if (ret != 0) {
+		return -1;
+	}
+
+    // 4. grep sram and sdram information
+	fout.open("application.map");
+    for (iter = lines.begin(); iter != lines.end(); ++iter) {
+		fout << *iter << endl;
+        line = *iter;
+        pos = line.find("__ram_image2_text_start__");
+        if ( pos != string::npos ) {
+            sram_start_st = line.substr(0, pos-3);
+            sram_start = strtol(sram_start_st.c_str(), NULL, 16);
+        }
+        pos = line.find("__ram_image2_text_end__");
+        if ( pos != string::npos ) {
+            sram_end_st = line.substr(0, pos-3);
+            sram_end = strtol(sram_end_st.c_str(), NULL, 16);
+        }
+        pos = line.find("__sdram_data_start__");
+        if ( pos != string::npos ) {
+            sdram_start_st = line.substr(0, pos-3);
+            sdram_start = strtol(sdram_start_st.c_str(), NULL, 16);
+        }
+        pos = line.find("__sdram_data_end__");
+        if ( pos != string::npos ) {
+            sdram_end_st = line.substr(0, pos-3);
+            sdram_end = strtol(sdram_end_st.c_str(), NULL, 16);
+        }
+    }
+	fout.close();
+
+    if (sdram_start > 0 && sdram_end > 0) {
+        has_sdram = true;
+    }
+
+    cout << "sram  " << sram_start_st << " ~ " << sram_end_st << endl;
+    if (has_sdram) {
+        cout << "sdram " << sdram_start_st << " ~ " << sdram_end_st << endl;
+    }
+
+    // 5. generate image 2 and image 3
+    cmdss.clear();
+    cmdss << "\"" <<path_arm_none_eabi_gcc << "arm-none-eabi-objcopy.exe\" -j .image2.start.table -j .ram_image2.text -j .ram.data -Obinary .\\application.axf .\\ram_2.bin";
+    getline(cmdss, cmd);
+    cout << cmd << endl;
+    system(cmd.c_str());
+
+    if (has_sdram) {
+        cmdss.clear();
+        cmdss << "\"" << path_arm_none_eabi_gcc << "arm-none-eabi-objcopy.exe\" -j .image3 -j .ARM.exidx -j .sdr_data -Obinary .\\application.axf .\\sdram.bin";
+        getline(cmdss, cmd);
+        cout << cmd << endl;
+        system(cmd.c_str());
+    }
+
+    // 6. fulfill header
+    cmdss.clear();
+    cmdss << ".\\tools\\windows\\pick.exe " << sram_start << " " << sram_end << " ram_2.bin ram_2.p.bin body+reset_offset+sig";
+    getline(cmdss, cmd);
+    cout << cmd << endl;
+    system(cmd.c_str());
+
+    cmdss.clear();
+    cmdss << ".\\tools\\windows\\pick.exe " << sram_start << " " << sram_end << " ram_2.bin ram_2.ns.bin body+reset_offset";
+    getline(cmdss, cmd);
+    cout << cmd << endl;
+    system(cmd.c_str());
+
+    if (has_sdram) {
+        cmdss.clear();
+        cmdss << ".\\tools\\windows\\pick.exe " << sdram_start << " " << sdram_end << " sdram.bin ram_3.p.bin body+reset_offset";
+        getline(cmdss, cmd);
+        cout << cmd << endl;
+        system(cmd.c_str());
+    }
+
+    // 7. prepare image 1
+    cmd = "copy bsp\\image\\ram_1.p.bin .\\";
+    cout << cmd << endl;
+    system(cmd.c_str());
+
+    cmd = ".\\tools\\windows\\padding.exe 44k 0xFF ram_1.p.bin";
+    cout << cmd << endl;
+    system(cmd.c_str());
+
+    // 8. generate ram_all.bin
+    if (has_sdram) {
+        cmd = "copy /b ram_1.p.bin+ram_2.p.bin+ram_3.p.bin ram_all.bin";
+        cout << cmd << endl;
+        system(cmd.c_str());
+        cmd = "copy /b ram_2.ns.bin+ram_3.p.bin ota.bin";
+        cout << cmd << endl;
+        system(cmd.c_str());
+    } else {
+        cmd = "copy /b ram_1.p.bin+ram_2.p.bin ram_all.bin";
+        cout << cmd << endl;
+        system(cmd.c_str());
+        cmd = "copy /b ram_2.ns.bin ota.bin";
+        cout << cmd << endl;
+        system(cmd.c_str());
+    }
+
+    // 9. add checksum
+    cmd = ".\\tools\\windows\\checksum.exe ota.bin";
+    cout << cmd << endl;
+    system(cmd.c_str());
+
+    return 0;
+}

          
A => ameba_tools_windows/tools/windows/src/simplesort.cpp +0 -0

        
A => ameba_tools_windows/tools/windows/src/upload_dap.cpp +157 -0
@@ 0,0 1,157 @@ 
+/*
+
+Compile command:
+	mingw32-g++.exe -o upload_dap.exe tools\windows\src\upload_dap.cpp -static
+
+*/
+
+#include <iostream>
+#include <sstream>
+#include <vector>
+#include <cstring>
+#include <cstdlib>
+#include <string>
+#include <cstdio>
+#include <sys/stat.h>
+
+using namespace std;
+
+#define CHECK_DISK_RETRY 3
+
+int retrieve_system_call_result (string cmd, vector<string> *lines) {
+
+	int ret = 0;
+
+	FILE *fin;
+	stringstream ss;
+	string line;
+	const int bufsize = 256;
+	char buf[bufsize];
+
+	bool buffer_result = true;
+
+	if (lines == NULL) {
+		buffer_result = false;
+	} else {
+		lines->clear();
+	}
+
+	do {
+		fin = popen(cmd.c_str(), "r");
+		if (fin == NULL || errno != 0) {
+			ret = -1;
+			break;
+		}
+
+		while(fgets(buf, bufsize, fin) != NULL) {
+			if (buffer_result) {
+				ss << buf;
+			}
+		}
+
+		// now ss contain the results. Dump into string vector
+		if (buffer_result) {
+			lines->clear();
+			while(getline(ss, line)) {
+				lines->push_back(line);
+			}
+		}
+		pclose(fin);
+	} while (0);
+
+	return ret;
+}
+
+bool isFileExist(string path) {
+	bool ret = false;
+	struct stat info;
+
+	do {
+		if (stat(path.c_str(), &info) != 0) {
+			break;
+		}
+
+		ret = true;
+	} while (0);
+
+	return ret;
+}
+
+int main(int argc, char *argv[]) {
+
+	int i;
+	bool mbed_disk_found = false;
+
+	string cmd;
+	vector<string> lines;
+	vector<string>::iterator iter;
+
+	stringstream ss;
+	string disk_caption;
+	string disk_volumename;
+	string filepath;
+
+	string filepath_ram_all;
+	if (argc >= 2) {
+		// the path of ram_all.bin is feed from arg
+		filepath_ram_all.assign(argv[1]);
+	} else {
+		// assume ram_all.bin is in current path
+		filepath_ram_all.assign("ram_all.bin");
+	}
+
+	do {
+		// 1. check if MBED disk driver exist
+		for (i=0; i<CHECK_DISK_RETRY; i++) {
+			mbed_disk_found = false;
+			cmd = "wmic logicaldisk get caption,volumename";
+			retrieve_system_call_result(cmd, &lines);
+
+			for (iter = lines.begin() + 1; iter != lines.end() - 1; iter++) {
+				ss.clear();
+				ss.str(*iter);
+				ss >> disk_caption >> disk_volumename;
+
+				if (disk_volumename.compare("MBED") == 0) {
+					mbed_disk_found = true;
+					break;
+				}
+			}
+
+			if (mbed_disk_found) {
+				break;
+			}
+		}
+
+		if (!mbed_disk_found) {
+			cout << "ERR: Cannot find ameba on mbed driver! Please re-plug Ameba." << endl;
+			break;
+		}
+
+		// 2. check if MBED disk is accessable
+		filepath = disk_caption + "\\mbed.htm";
+		if (!isFileExist(filepath)) {
+			cout << "ERR: Cannot access mbed driver!" << endl;
+			break;
+		}
+
+		// 3. check if ram_all.bin exist
+		if (!isFileExist(filepath_ram_all)) {
+			cout << "ERR: Cannot find ram_all.bin!" << endl;
+			break;
+		}
+
+		// 4. copy ram_all.bin into mbed device
+		cout << "uploading..." << endl;
+		cmd = "copy \"" + filepath_ram_all;
+		cmd.append("\" ");
+		cmd.append(disk_caption);
+		cout << cmd << endl;
+		system(cmd.c_str());
+
+		cout << "upload finish" << endl;
+	} while (0);
+
+
+	return 0;
+}

          
A => ameba_tools_windows/tools/windows/src/upload_ota.c +193 -0
@@ 0,0 1,193 @@ 
+/*
+ * Compiler: MinGW (32bit)
+ * 
+ * mingw32-gcc.exe -o upload_ota.exe tools\windows\src\upload_ota.c-lwsock32 -static
+ *
+ **/
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <io.h>
+#include <sys/stat.h>
+#include "getopt.h"
+#include <winsock2.h>
+
+#pragma comment(lib,"ws2_32.lib") //Winsock Library
+
+#define BUF_SIZE 256
+
+#define CMD_FILENAME    0x01
+#define CMD_IP          0x02
+#define CMD_PORT        0x04
+#define CMD_HELP        0x08
+
+#define CHUNK_SIZE 1460
+
+static struct option long_options[] = {
+    {"file",      required_argument, 0, 'f'},
+    {"interface", required_argument, 0, 'i'},
+    {"port",      required_argument, 0, 'p'},
+    {"help",      no_argument,       0, 'h'},
+    {0,           0,                 0,  0 }
+};
+
+void dumpMenu() {
+    printf("Usage: upload_ota\r\n");
+    printf("  -f  --file       the OTA image to be uploaded\r\n");
+    printf("  -i  --interface  the network ip address\r\n");
+    printf("  -p  --port       the network port\r\n");
+    printf("  -h  --help\r\n");
+}
+
+void ota_process(char *filename, char *ipstring, int port) {
+
+    FILE *pFile;
+    struct stat info;
+    uint32_t ota_description[3];
+    long filesize;
+    unsigned char *ota_buf = NULL;
+
+    SOCKET s;
+    WSADATA wsa;
+
+    uint32_t checksum = 0;
+    struct sockaddr_in server;
+    int i, n;
+    printf("file: %s\r\n", filename);
+    printf("ip: %s\r\n", ipstring);
+    printf("port: %d\r\n", port);
+
+    do {
+        pFile = fopen(filename, "rb");
+        if ( pFile == NULL ) {
+            printf("ERR: Fail to open file: %s\r\n", filename);
+            break;
+        }
+
+        // get file size;
+        fseek(pFile, 0L, SEEK_END);
+        filesize = ftell(pFile);
+        fseek(pFile, 0, SEEK_SET);
+
+        ota_buf = (unsigned char *) malloc (filesize);
+        if (ota_buf == NULL) {
+            printf("ERR: no enough memory\r\n");
+            break;
+        }
+        fread(ota_buf, 1, filesize, pFile);
+        fclose(pFile);
+
+        checksum = 0;
+        for (i=0; i<filesize; i++) {
+            checksum += (ota_buf[i] & 0xff);
+        }
+
+        if (WSAStartup(MAKEWORD(2,2),&wsa) != 0) {
+            printf("ERR: FAIL to init Winsock, error code: %d\r\n", WSAGetLastError());
+            break;
+        }
+
+        s = socket(AF_INET, SOCK_STREAM, 0);
+        if (s == INVALID_SOCKET) {
+            printf("ERR: Could not create socket, error code: %d\r\n",  WSAGetLastError());
+            break;
+        }
+
+        server.sin_addr.s_addr = inet_addr(ipstring);
+        server.sin_family = AF_INET;
+        server.sin_port = htons( port );
+
+        printf("Try to connect...\r\n");
+        if ( connect(s, (struct sockaddr *)&server, sizeof(server)) < 0 ) {
+            printf("ERR: Connect error\r\n");
+            break;
+        }
+
+        ota_description[0] = checksum;
+        ota_description[1] = 0;
+        ota_description[2] = (uint32_t) filesize;
+
+        printf("Send OTA info...\r\n");
+        n = send(s, (unsigned char *)ota_description, sizeof(ota_description), 0);
+        if (n < 0) {
+            printf("ERR: fail to send OTA description\r\n");
+            break;
+        }
+
+        printf("String uploading...\r\n");
+        n = send(s, (const char *)ota_buf, filesize, 0);
+        if (n < 0) {
+            printf("ERR: fail to send OTA image\r\n");
+            break;
+        }
+
+        closesocket(s);
+
+        WSACleanup();
+
+        printf("Upload success\r\n");
+
+    } while (0);
+
+    if (ota_buf != NULL) {
+        free(ota_buf);
+        ota_buf = NULL;
+    }
+}
+
+int main(int argc, char *argv[]) {
+
+    int c;
+    int opt_idx = 0;
+
+    unsigned char cmd = 0;
+
+    char filename[BUF_SIZE];
+    char ipstring[16];
+    char portstring[10];
+    int port;
+
+    while (1) {
+        c = getopt_long(argc, argv, "f:i:p:h?", long_options, &opt_idx);
+
+        if (c== -1) break;
+
+        switch (c) {
+            case 'f':
+                sprintf(filename, "%s", optarg);
+                cmd |= CMD_FILENAME;
+                break;
+            case 'i':
+                if (strlen(optarg) < 16) {
+                    sprintf(ipstring, "%s", optarg);
+                    cmd |= CMD_IP;
+                }
+                break;
+            case 'p':
+                if (strlen(optarg) < 10) {
+                    sprintf(portstring, "%s", optarg);
+                    cmd |= CMD_PORT;
+                }
+                break;
+            case 'h':
+            case '?':
+            default:
+                cmd |= CMD_HELP;
+                break;
+        }
+    }
+
+    if (cmd & CMD_HELP) {
+        dumpMenu();
+    } else if (cmd & (CMD_FILENAME | CMD_IP | CMD_PORT)) {
+        port = atoi(portstring);
+        ota_process(filename, ipstring, port);
+    } else {
+        dumpMenu();
+    }
+
+    return 0;
+}
+

          
A => ameba_tools_windows/upload_dap.exe +0 -0

        
A => ameba_tools_windows/upload_ota.exe +0 -0