How to generate srec file

cancel
Showing results for 
Search instead for 
Did you mean: 

How to generate srec file

1,872 Views
Contributor III

Hello,

 

How can I generate a srec file with s32 design studio, it's generating an .elf file by default, but how can I make a srec one? An also how can I see the data of that srec file so I can make an array with that data for simulation.

 

Thanks,

 

Vlad

Labels (1)
Tags (2)
13 Replies

36 Views
NXP Employee
NXP Employee

Hello Vlad,

If I understand this issue correctly you are trying to parse a S-record file stored as a constant (in Flash) and load the srec lines to the appropriate addresses (in RAM).

This seems to me like you are trying to develop your own bootloader (see the previous links posted by Martin which might be useful for you)

The first problem with your example is that the constant srecord is located in flash rather than in RAM (address 0x01002BD0) e.g.:

S3 15 01002BD0 182106B01881110CD231707FE4045063 BC\

So the first step is to generate s-record targeted for RAM. This requires not only changes to LCF file in the project you use for Srecord generation (LED blinking) but you also need to adjust  LED blinking startup code since you should not initialize entire SRAM for ECC init (this should be done by second - let's call it bootloader project). Otherwise, the startup would destroy RAM code itself). You don't have to initialize variables/data objects since they are already initialized by S-record copy.

Another question is if you plan to return to flash (bootloader) project.

I do not quite understand how you plan to "inject" the RAM targeted srec into flash because this static definition does not make much sense to me.

If you describe your problem from a higher level perspective we might be able to help you more.

Regards,

Stan

36 Views
Contributor III

Hello,

Thanks for the answer. I what to write into RAM not into flash, is there any example of modified startup code so I don't initialize entire SRAM? Also how do I generate s-record for RAM (it does not specify when I generate if there is for flash or for RAM).?

And no,I whant to remain in that function, not to return to the main function.

Thanks,

Vlad

0 Kudos

36 Views
NXP Employee
NXP Employee

Hi Vlad,

could you please clarify the whole idea? I am not sure, what you want to do. But you are not able to write to flash memory directly. You have to use some boot-loader.

Look at the following URLs

https://community.freescale.com/servlet/JiveServlet/download/427962-1-279359/bootloader.zip

https://community.freescale.com/message/427962#comment-427962

Also you can look at this URL:

Overview of RAppID Bootloader|NXP

But the easiest way, how to flash srecord to the micro is add the srecord to a project and flash it through the IDE (as I described above).

Regards,

Martin

0 Kudos

36 Views
Contributor III

Hello,

I want to write a SREC file into RAM memory by using a C code. I also parsed the srec by address and memory but it doesn't write to the specific memory. Must I restart the device also in the code so this will work? Here is my C code:

const char *mode = {"S00F000063765F5A345F312E73726563BF\

S31501002BD0182106B01881110CD231707FE4045063BC\

S31501002BE000207C008146C03318211114009318017E\

S31501002BF0112400051821101418011024707FE40413\

S31501002C007C0006AC7C00014654630030C231188159\

S31501002C10100C1C2100500008182106E00080D90183\

S31501002C20D7F1011F71200000553F00087140600077\

S31501002C30512A03C8710000017509C98C552A03C8B8\

S31501002C407120600071400001354913627800020D60\

S31501002C50513F000819298001553F0008515F0008BE\

S31501002C60712018007121C5407F8A48007D20002609\

S31501002C707529E0077529E03F7D2401207529203F4C\

S31501002C807A05004071200000553F00087120600060\

S31501002C9071406000314A1362754A063F194AE001E4\

S31501002CA0754A063F35491362712060003129136266\

S31501002CB07529063F7D2A4B787128E00055490000A9\

S31501002CC079FFFF90182106F0D3F1011F780000006B\

S31501002CD0182106E0D7F1011F712058001929D1806A\

S31501002CE051290004553F0008712058001929D18047\

S31501002CF0714000FE5D4901C8712058001929D18033\

S31501002D007140E11D194AD001554901E87120580069\

S31501002D101929D180714000FE5D4901CA7120580010\

S31501002D201929D1807140E13A194AD001554901EC7E\

S31501002D30712058001929D180515F0008754A001F7A\

S31501002D40714BC2F055490004712058001929D180F0\

S31501002D50515F000855490004197F802053EBFFFCA1\

S31501002D6003310004182106F0D3F1011F02317D3F22\

S31501002D700BA6197F801053EBFFFC033100041821C9\

S31501002D8006E0D7F1011F7D3E42A6553F0008513F9F\

S31501002D9000085D3F000C713FE404715FE404510AD1\

S31501002DA00000595F000C754A043F7D4A20704817A0\

S31501002DB07CEA50307D4A50F87D0A5038554900006A\

S31501002DC0715FE404593F000C7529043F19298008F5\

S31501002DD07D2910707D2A4A1451290000553F0010A3\

S31501002DE0711FE404593F000C7529043F7140E1004D\

S31501002DF01D4A2000192980087D2910707D284A1452\

S31501002E0055490000197F802053EBFFFC0331000474\

S31501002E10182106E0D7F1011F7D3E42A6553F000865\

S31501002E20513F00085D3F000C715FE404593F000CFF\

S31501002E307529043F192980047D2910707D2A4A14B9\

S31501002E4071400000554900007C008146197F8020B1\

S31501002E5053EBFFFC03310004182106F00080D50175\

S31501002E60D3F1011F7120E1001D291000031379FF21\

S31501002E70FEF779FFFF0D79FFFF9B197F8010500B3D\

S31501002E800004009053EBFFFC033100040000000036\

S70501000000F9"};

void functionSrec() {

  int i = 0;

  int end = 0;

  int end2;

  uint8_t value[255];

  uint8_t add[2];

  memcpy(add, &mode[end + 2], 2);

  end2 = 2 * strtol(add, NULL, 16);

  while (end < strlen(mode)) {

  i++;

  if (i == 1 && (mode[end + 1] == '0' || mode[end + 1] == '1')) {

  uint8_t address[4];

  address[0] = mode[end + 4];

  address[1] = mode[end + 5];

  address[2] = mode[end + 6];

  address[3] = mode[end + 7];

  uint8_t value2[end2 - 6];

  memcpy(value2, &mode[end + 8], end2 - 6);

  *((char *)address) = value2;

  }

  else if (i == 1 && mode[end + 1] == '2') {

  uint8_t address[6];

  address[0] = mode[end + 4];

  address[1] = mode[end + 5];

  address[2] = mode[end + 6];

  address[3] = mode[end + 7];

  address[4] = mode[end + 8];

  address[5] = mode[end + 9];

  uint8_t value2[end2 - 8];

  memcpy(value2, &mode[end + 10], end2 - 8);

  *(char *)address = value2;

  }

  else if (i == 1 && mode[end + 1] == '3') {

  uint8_t address[8];

  address[0] = mode[end + 4];

  address[1] = mode[end + 5];

  address[2] = mode[end + 6];

  address[3] = mode[end + 7];

  address[4] = mode[end + 8];

  address[5] = mode[end + 9];

  address[6] = mode[end + 10];

  address[7] = mode[end + 11];

  uint8_t value3[end2 - 10];

  memcpy(value3, &mode[end + 12], end2 - 10);

  *(char *)address = value3;

  }

  else if (i == 1 && mode[end + 1] == '7') {

  uint8_t address[8];

  address[0] = mode[end + 4];

  address[1] = mode[end + 5];

  address[2] = mode[end + 6];

  address[3] = mode[end + 7];

  address[4] = mode[end + 8];

  address[5] = mode[end + 9];

  address[6] = mode[end + 10];

  address[7] = mode[end + 11];

  uint8_t value2[end2 - 10];

  memcpy(value2, &mode[end + 12], end2 - 10);

  *((char *)address) = value2;

  }

  if (i == 1) {

  i = 0;

  end += (2 * strtol(add, NULL, 16)) + 4;

  memcpy(add, &mode[end + 2], 2);

  end2 = 2 * strtol(add, NULL, 16);

  }

  }

}

0 Kudos

36 Views
NXP Employee
NXP Employee

Hi Vlad,

look at the following example. The best way is to create your own section in linker file and copy srec to this section. In the example I created own section and placed there a function. The code is commented, but if you have any question, please feel free to write me back.

Example MPC5748G PretendedNetworkingCAN S32DS

Regards,

Martin

36 Views
Contributor III

Hello,

How exacticaly did you test it? I runned it several times, but it does not enter into LPU_Stop_Init function. Also why there is z2_3 project, it does not seemed used? I also see Lauterbach script, do I use it? and how do I use it?

Vlad

0 Kudos

36 Views
NXP Employee
NXP Employee

Hi Vlad,

please ignore my previous post about Pretended Networking Can example. I wanted to show you, how to create section in flash and RAM memory and how to copy code from flash section to the RAM section. I did not want to complicate the problem with low power modes, which are off topic now and debugging through PE Micro and S32DS is too difficult even impossible.

I tried to analyze your code with my colleague and we found many mistakes. At first, the srecord, which you want to copy to RAM, is for flash memory and it will be impossible to execute it from RAM. There are also some mistakes with pointers and copying code to RAM.

But we still do not know, what is your general idea. For example we guess, what you want to do with srecord in RAM memory. Please try to explain us the whole idea. Why do you want to copy srecord to RAM and what do you want to do with the srecord? If we do not know the whole idea, we are not able to propose correct solution. So once more, please clarify your whole idea and I will try to tell you, if your solution is possible or not and eventually I will try to show you correct way.

Regards,

Martin

0 Kudos

36 Views
Contributor III

Hello,

So the idea is: I have a char * with the content from a srec file (which has generated from a program who lights a led) , example :

const char *mode = {"S00F000063765F5A345F312E73726563BF\

S31501002BD0182106B01881110CD231707FE4045063BC\

S31501002BE000207C008146C03318211114009318017E\

S31501002BF0112400051821101418011024707FE40413\

S31501002C007C0006AC7C00014654630030C231188159\

S31501002C10100C1C2100500008182106E00080D90183\

S31501002C20D7F1011F71200000553F00087140600077\

S31501002C30512A03C8710000017509C98C552A03C8B8,etc} ,

and I parse this char with a function and I want in that function to set eatch value into his specific address(from the srec in that char *), and then to put that function in ram section and to jump to it after the main function so it will load the program that generated the srec file into my program and so it will light the led. Also I don't know how to make that jump so the program will remain in the address where the function is and not jump back to main function.(should I do a new section, also the startup code should be modified?) ?

Thanks,

Vlad

0 Kudos

36 Views
Contributor III

Thanks very much.

Vlad

0 Kudos

36 Views
NXP Employee
NXP Employee

Hi Vlad,

open project settings and in Cross Settings check Create flash image. Click OK. Open project setting again a check if there is Motorola S-record chosen in Standard S32DS Create Flash Image/General.

pastedImage_0.png

Recompile the project. Srecord is generated to folder debug or release according to compiling option. It is text file, so you can open it directly in S32 or you can you any text reader.

Regards,

Martin

0 Kudos

36 Views
Contributor III

Hello,

Thanks for the answer.

I am trying to load another srec file into a program( the program will light a led and the srec file if is loaded correctly it will load another led). I parsed the srec file but there is any example in C of how I can put the values into memory so that the program will proprerly load.

Thanks,

Vlad

0 Kudos

36 Views
NXP Employee
NXP Employee

Hi Vlad,

if you want to load srec to the micro, use the existing project or create new dummy project. Add srec file to project. Open debug configuration and switch to the Startup tab.

Uncheck load symbols and switch Load executable to Use file. Choose your srecord and click apply.

pastedImage_0.png

Now srecord will be flashed  to micro. But remember, there are no debug symbols in srecord. You will not be available to debug the code.

Regards,

Martin

0 Kudos

36 Views
Contributor III

Hello,

I want the loading to be done by C code, not by adding the srec file to be used by S32 design studio. I parsed the memory and addresses from the srec file but I don't know how to assign the values to address because on that addresses it gives me se_illegal memory.

Thanks,

Vlad

0 Kudos