Skip to content

Commit

Permalink
Title: fix build fail when user name with space
Browse files Browse the repository at this point in the history
  • Loading branch information
Ameba8195 committed Jan 26, 2016
1 parent 7a53e02 commit 82378fb
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 63 deletions.
61 changes: 0 additions & 61 deletions ameba_tools/postbuild_img2_arduino.bat

This file was deleted.

Binary file added ameba_tools/postbuild_img2_arduino_windows.exe
Binary file not shown.
File renamed without changes.
187 changes: 187 additions & 0 deletions ameba_tools/tools/windows/src/postbuild_img2_arduino_windows.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
#include <iostream>
#include <sstream>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <unistd.h>

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[]) {

stringstream cmdss;
string cmd, line;
string path_tool;
string path_arm_none_eabi_gcc;
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 << "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\" application.axf | .\\tools\\sort.exe > application.map";
getline(cmdss, cmd);
cout << cmd << endl;
system(cmd.c_str());

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());

// 4. grep sram and sdram information
fin.open("application.map");
while ( getline(fin, line) ) {
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);
}
}
fin.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\\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\\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\\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\\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\\checksum.exe ota.bin";
cout << cmd << endl;
system(cmd.c_str());

return 0;
}
File renamed without changes.
4 changes: 2 additions & 2 deletions hardware/platform.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ recipe.nm.pattern=cp "{build.path}/{build.project_name}.axf" "{build.path}/appli
recipe.strip.pattern="{compiler.path}{compiler.strip.cmd}" "{build.path}/{build.project_name}.axf"

## Create image
recipe.objcopy.hex.cmd=postbuild_img2_arduino.bat
recipe.objcopy.hex.cmd.windows=postbuild_img2_arduino.bat
recipe.objcopy.hex.cmd=postbuild_img2_arduino_windows.exe
recipe.objcopy.hex.cmd.windows=postbuild_img2_arduino_windows.exe
recipe.objcopy.hex.cmd.macosx=postbuild_img2_arduino_mac
recipe.objcopy.hex.imagepath={build.path}\application.axf
recipe.objcopy.hex.imagepath.macosx="{build.path}/application.axf"
Expand Down

0 comments on commit 82378fb

Please sign in to comment.