Link to home
Start Free TrialLog in
Avatar of forums_mp
forums_mp

asked on

srec file.

I have needs for an 'srec' file.  To do this, I thought perhaps I could first create a binary file, then convert the file to srec using a 'tool' called objcopyppc.

So now:

int main()
 {
  char mbyte[ 1048576];
  std::ofstream ofile( "bigfile.bin" );
  int i = 0;
  int m = 0;
  std::cout << "how many MiB shall I write? ";
  std::cin >> m;

  for( i = 0; i < m; ++i )
       ofile.write( (char*)mbyte, sizeof mbyte );

  return 0;
 }

I'll need to tweak the code above to ask the user to select a pattern. ie.  Choose betwen all zeros, or all ones or a counting pattern (1, 2, 3, .. ).
Conversly is it possible to just write code that'll generate the srec file withouth going through all this.  



Avatar of smpoojary
smpoojary

Update your code
std::ofstream ofile( "bigfile.bin" ,ios::out | ios::binary); //Otherwise file considers as text file

intialize mbyte with data

strcpy(mbyte,"111111111111111111111111111111111111111111111");

I don't know what you are going to do. Means I don't know about srec ....
-Mahesh
Avatar of forums_mp

ASKER


Actually, I discovered that what I needed to do was a lot simpler than what I proposed in my initial post.   So revisiting.  I need to create a 64 MiB file with all ones or zeros.   I'm working with 'two environments'.  Visual Studio. NET and Tornado.  

So now step 1.

Within visual studio, I create this simple program that'll create a 28 Byte size file.  

# include<iostream>
# include<iomanip>

#define MAX  7

int main( void )
{
   std::cout << std::endl; std::cout << std::endl;
   std::cout << "# include<iostream> " << std::endl;
   std::cout << "# define MAX  " << MAX << std::endl;
   std::cout << std::endl; std::cout << std::endl;

   std::cout << " int huge_array[" << MAX << "] = {" << std::endl;
   for (int idx(0); idx < MAX - 1; ++idx)
         std::cout << std::setw(15)
                   << "   0xFFFFFFFF, " 
//                   << "   0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF  "
                         << std::endl;

   std::cout << "   0xFFFFFFFF " << std::endl;
   std::cout << " } " << std::endl;
   std::cout << std::endl; std::cout << std::endl;
   std::cout << " int main() " << std::endl;
   std::cout << " { " << std::endl;
   std::cout << " } " << std::endl;
}

Lets assume executable is test.exe.  

Step 2.

From the command line I do:
 c:\test_project\Debug\test.exe >  test.c

Now test.c looks like:

# include<iostream>
# define MAX  7


 int huge_array[7] = {
   0xFFFFFFFF,
   0xFFFFFFFF,
   0xFFFFFFFF,
   0xFFFFFFFF,
   0xFFFFFFFF,
   0xFFFFFFFF,
   0xFFFFFFFF
 }

 int main()
 {
 }

Step 3.

I move over to tornado and execute/run test.c.  I end up with an object file (.o) thats 28 bytes.
I then use that 28 byte file to create my srec file.

You see, the Visual studio approach is a way for me to 'cheat' in terms of creatign the array.  i.e instead of typing huge_array's parameters by hand, I just use cout.   Now here's the trouble spot.  For a 64 MiB file MAX needs to be (16777216).   When I do
c:\test_project\Debug\test.exe >  test.c.  This takes time.  Furthermore, when I opt to open test.c within tornado or any text editor etc.  I get memory errors (pc has no memory).  

I'm not sure what to do here?
ASKER CERTIFIED SOLUTION
Avatar of Netminder
Netminder

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial