Skip to content

Commit

Permalink
Update for 1-10 mp image tool release
Browse files Browse the repository at this point in the history
  • Loading branch information
M-ichae-l committed Aug 25, 2023
1 parent 951cb71 commit 8e9512a
Show file tree
Hide file tree
Showing 6 changed files with 302 additions and 0 deletions.
Binary file not shown.
4 changes: 4 additions & 0 deletions Ameba_misc/Image_Releated/Readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

km0_boot_all.bin address 0x08000000
km4_boot_all.bin address 0x08004000
km0_km4_image2.bin address 0x08006000
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
Compile:
linux:
g++ -o upload_image_tool_linux tools/linux/src/upload_image_tool_linux.cpp -static
g++ -std=c++11 -o upload_image_tool_linux upload_image_tool_linux.cpp -static
g++ -std=c++11 -o upload_image_tool_linux upload_image_tool_linux.cpp -lpthread
*/

#include <iostream>
#include <sstream>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cstdio>
#include <sys/stat.h>
#include <fstream>
#include <unistd.h>

//#include <windows.h>

#include <thread>
//#include <mutex>

#include <time.h>
#include <errno.h>

using namespace std;

//mutex mu;
int check_image_upload = 0;

int msleep(long msec) {
struct timespec ts;
int res;

if (msec < 0) {
errno = EINVAL;
return -1;
}

ts.tv_sec = msec / 1000;
ts.tv_nsec = (msec % 1000) * 1000000;

do {
res = nanosleep(&ts, &ts);
} while (res && errno == EINTR);

return res;
}

void image_tool_thread(char* t1_com) {
stringstream t1_cmdss;
string t1_cmd;

t1_cmdss.clear();
// run image tool with serial port as argument
t1_cmdss << "./tools/linux/image_tool/amebad_image_tool " << t1_com;

// copy command in cmdss to cmd
t1_cmd = t1_cmdss.str();
system(t1_cmd.c_str());

// mu.lock();
check_image_upload = 100;
// mu.unlock();
}

void image_tool_progress() {
cout << "Uploading." << flush;
while (1) {
msleep(500);
// mu.lock();
if (check_image_upload != 0) {
break;
} else {
cout << "." << flush;
}
// mu.unlock();
}
cout << " Upload Image done. " << endl;
}

int main(int argc, char *argv[]) {
string cmd;

// change directory to {runtime.tools.ameba_d_tools.path}
chdir(argv[1]);

// 5 seconds count down to allow user setting ameba D to UART download mode
cmd = "Please enter the upload mode (wait 5s)";
cout << cmd << endl;
for (int i = 5; i > 0; i--) {
sleep(1);
cmd = to_string(i);
cout << " 0" << cmd << endl;
}

thread t2(image_tool_progress);
thread t1(image_tool_thread, argv[2]);

// t2.detach();
// t1.detach();
t2.join();
t1.join();

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
Compile:
macos:
g++ -o upload_image_tool_macos upload_image_tool_macos.cpp
g++ -std=c++11 -o upload_image_tool_macos upload_image_tool_macos.cpp
*/

#include <iostream>
#include <sstream>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cstdio>
#include <sys/stat.h>
#include <fstream>
#include <unistd.h>

//#include <windows.h>

#include <thread>
//#include <mutex>

#include <time.h>
#include <errno.h>

using namespace std;

//mutex mu;
int check_image_upload = 0;

int msleep(long msec) {
struct timespec ts;
int res;

if (msec < 0) {
errno = EINVAL;
return -1;
}

ts.tv_sec = msec / 1000;
ts.tv_nsec = (msec % 1000) * 1000000;

do {
res = nanosleep(&ts, &ts);
} while (res && errno == EINTR);

return res;
}

void image_tool_thread(char* t1_com) {
stringstream t1_cmdss;
string t1_cmd;

t1_cmdss.clear();
t1_cmdss << "./tools/macos/image_tool/amebad_image_tool " << t1_com;
getline(t1_cmdss, t1_cmd);
cout << t1_cmd << endl;
system(t1_cmd.c_str());

// mu.lock();
check_image_upload = 100;
// mu.unlock();
}

void image_tool_progress() {
cout << "Uploading." << flush;
while (1) {
msleep(500);
// mu.lock();
if (check_image_upload != 0) {
break;
} else {
cout << "." << flush;
}
// mu.unlock();
}
cout << " Upload Image done. " << endl;
}

int main(int argc, char *argv[]) {
string cmd;

chdir(argv[1]);

cmd = "Please enter the upload mode (wait 5s)";
cout << cmd << endl;
for (int i = 5; i > 0; i--) {
sleep(1);
cmd = to_string(i);
cout << " 0" << cmd << endl;
}

thread t2(image_tool_progress);
thread t1(image_tool_thread, argv[2]);

// t2.detach();
// t1.detach();
t2.join();
t1.join();

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
Compile:
windows:
mingw32-g++.exe -o upload_image_tool_windows.exe upload_image_tool_windows.cpp -static
i686-w64-mingw32-g++.exe -o upload_image_tool_windows.exe upload_image_tool_windows.cpp -static
*/

#include <iostream>
#include <sstream>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cstdio>
#include <sys/stat.h>
#include <fstream>
#include <unistd.h>

#include <windows.h>

#include <thread>
//#include <mutex>

using namespace std;

//mutex mu;
int check_image_upload = 0;

void image_tool_thread(char* t1_com) {
stringstream t1_cmdss;
string t1_cmd;
t1_cmdss.clear();
t1_cmdss << ".\\tools\\windows\\image_tool\\amebad_image_tool.exe " << t1_com;
getline(t1_cmdss, t1_cmd);
system(t1_cmd.c_str());
// mu.lock();
check_image_upload = 100;
// mu.unlock();
}

void image_tool_progress() {
cout << "Uploading." << flush;
while (1) {
Sleep(500);
// mu.lock();
if (check_image_upload != 0) {
break;
} else {
cout << "." << flush;
}
// mu.unlock();
}
cout << " Upload Image done. " << endl;
}


int main(int argc, char *argv[]) {
string cmd;
chdir(argv[1]);

cmd = "Please enter the upload mode (wait 5s)";
cout << cmd << endl;
for (int i = 5; i > 0; i--)
{
Sleep(1000);
cmd = to_string(i);
cout << " 0" << cmd << endl;
}

thread t2(image_tool_progress);
thread t1(image_tool_thread, argv[2]);

// t2.detach();
// t1.detach();
t2.join();
t1.join();

return 0;
}

0 comments on commit 8e9512a

Please sign in to comment.