How To Count Memory

Discussion to talk about software related topics only.
kackle123
Posts: 73
Joined: Tue Nov 23, 2010 1:35 pm

How To Count Memory

Post by kackle123 »

Can someone help me understand the memory on the SB70LC? Supposedly it has 8 MB of RAM and 512 kB of flash memory. My _APP.s19 is about 527 kB in file size. First of all, why does my 527 kB file work in a 512 kB SB70LC? Secondly, why does NBEclipse say the following upon compilation of the same project:

Code: Select all

Used 175690 bytes of 491520 available flash (35.74%)
175 kB is nowhere near 527 kB. Is 175 kB representing program variables only?
User avatar
dciliske
Posts: 624
Joined: Mon Feb 06, 2012 9:37 am
Location: San Diego, CA
Contact:

Re: How To Count Memory

Post by dciliske »

So, the _APP.s19 is not the same as the app image, per se. An S19 file is a text encoding (specifically an SRECord) of a binary structure that contains additional information about the data. Take a look at the wiki page for more info http://en.wikipedia.org/wiki/SREC_(file_format).

The value that is reported is from compcode, which is the tool that compresses the image and generates the S19. It absolutely knows how big the actual image is.

-Dan
Dan Ciliske
Project Engineer
Netburner, Inc
User avatar
pbreed
Posts: 1091
Joined: Thu Apr 24, 2008 3:58 pm

Re: How To Count Memory

Post by pbreed »

the xx_app.s19 is a srecord format of a compressed binary blob that is the a compressed version of the actual executable,
(Think zip file)

So there are really 3 sizes here:

Size of the xx_app.s19 text file, usually 3X the size of the compressed binary.

Size of the binary image represented by the S19 file....

Size of the decompressed executable in memory...

I compiled Tictacktoe for a PK70 and the output from compcode:


compressed 159780 bytes into 96825 bytes

158780 is the uncompressed image size.

96825 is the compressed image (also how much flash is used)

The _APP.s19 file in this example is 290586

The reports at the bottom...

Used 96849 bytes of 3997696 available flash (2.42%)

Used 648872 bytes of 8388608 available ram (7.74%)

IE the executable is 158780... and the ram variables are 490092 bytes for a total ram usage of 648872...
(Note the code executes out of RAM not out of flash, its just loaded from flash)

Hope this helps....
User avatar
pbreed
Posts: 1091
Joined: Thu Apr 24, 2008 3:58 pm

Re: How To Count Memory

Post by pbreed »

To be clear fro your example...

>Used 175690 bytes of 491520 available flash (35.74%)

This means exactly what it says it does ...
your compressed application will take up 35.75% of the available flash.

The fact that the s-record text file you give to autoupdate is 3X as big has to do with the format its stored in not its content.
The S-record is not the format it is stored in flash, so while your text file is 527K the actual stored image is just 175690 bytes our of 491520
(Note 491520 is 32K less than 512K because the flash also holds the boot boot monitor (16K sector), config record (8K sector)
and user param space. (8K sector)


Hope that helps...
kackle123
Posts: 73
Joined: Tue Nov 23, 2010 1:35 pm

Re: How To Count Memory

Post by kackle123 »

Thank you for your replies. I think I'm getting this...

The binary executable is run from RAM but is first stored in flash. Before it can be run from RAM, it must be copied from flash. Not only that, it must be decompressed while being copied to RAM (during boot up?) because it was compressed (by "compcode" during compilation) before being stored in flash. (I assume this compression is done to expand the board's storage without increasing cost.)

The compiler reports how large the compressed binary executable is in flash. It also reports how large the decompressed binary executable (summed with variables' storage) will take up in RAM.

Please confirm that everything I wrote is true.

So why is there both an .S19 AND an _APP.s19?
Last edited by kackle123 on Wed Oct 16, 2019 2:16 pm, edited 1 time in total.
User avatar
pbreed
Posts: 1091
Joined: Thu Apr 24, 2008 3:58 pm

Re: How To Count Memory

Post by pbreed »

Yes exactly correct....

Why both an _APP.s19 and S19.....
Compcode takes the plain xx.S19 to make the xx_app.s19

We could kill it after compcode is done.... but there are some rare debugging cases
(mostly in internal NB development when messing with flash) where you want to load an
app directly to RAM using the monitor and run it there without modifying flash first.

In fact since the transmission is the slowest part
s19->_app.s19->flash->ram->run is faster than s19->ram->run...


Paul
kackle123
Posts: 73
Joined: Tue Nov 23, 2010 1:35 pm

Re: How To Count Memory

Post by kackle123 »

Okay, we're almost there...

My .S19 is 905 kB. Its _APP.S19 is 527 kB. Neither fits in flash. Is it compressed yet again before uploading into flash? If so, by what?
Last edited by kackle123 on Wed Oct 16, 2019 2:17 pm, edited 1 time in total.
sulliwk06
Posts: 118
Joined: Tue Sep 17, 2013 7:14 am

Re: How To Count Memory

Post by sulliwk06 »

kackle123 wrote:Okay, we're almost there...

My .S19 is 905 kB. It's _APP.S19 is 527 kB. Neither fits in flash. Is it compressed yet again before uploading into flash? If so, by what?
The S19 format is actually a text representation of the image. I believe the file is decoded into it's binary form as it's written to flash. I've actually been wondering if I might be able speed up the serial update process for my MOD5213 by transferring it as the smaller raw binary and not the S19 format. But I'm not sure if some of the error checking in the S19 file is too important to give up.
User avatar
dciliske
Posts: 624
Joined: Mon Feb 06, 2012 9:37 am
Location: San Diego, CA
Contact:

Re: How To Count Memory

Post by dciliske »

For the mod5213, I'm fairly certain that the serialupdate facility (separate from the monitor download) sends the image as raw binary. The utility does the conversion internally.

-Dan
Dan Ciliske
Project Engineer
Netburner, Inc
kackle123
Posts: 73
Joined: Tue Nov 23, 2010 1:35 pm

Re: How To Count Memory

Post by kackle123 »

So you think the external software (serialupdate and AutoUpdate.exe) compress the image before sending it to the CPU's flash, or do you think the CPU compresses it before putting it in its own flash?

And, what's the point of making _APP.S19 then if it has to be further compressed?
Post Reply