AdditionAgentRAM - an unused piece of memory? - General Discussion and Assistance - CHDK Forum  

AdditionAgentRAM - an unused piece of memory?

  • 32 Replies
  • 18367 Views
*

Offline srsa_4c

  • ******
  • 4451
AdditionAgentRAM - an unused piece of memory?
« on: 04 / November / 2013, 12:52:45 »
Advertisements
I stumbled into a memory area that doesn't appear to be used in normal camera operation.
There is an event procedure named "AdditionAgentRAM", which is available in DryOS models starting with the late r23 generation. It loads a binary (same signature check as for diskboot files), and executes it as a task. The interesting part is that the memory it's using is not malloc'd, but starts at a fixed address instead. The available space is 204800 bytes for older models, 139264 bytes for newer models.
I set up the CHDK RAM dumper to dump this area, and used the cam for a while, made dumps several times for later comparison. I haven't been able to corrupt its content...
The memory seems not even initialized, mostly 0xff bytes with some noise.
Next try was to set MEMISOSTART to the start of this memory... and the resulting diskboot files appear to work fine. Tested on the a3200 and a470 so far. Screenshot shows the a3200, running from this memory.



Cameras with this feature are detailed in a table.

It would be good if this could be tested on more models (testing = dumping & comparing this chunk of RAM).

Any (other) ideas what this memory could be used for?

Patch for the sigfinder (and my changes to the 2 cameras) is attached.

*

Offline ahull

  • *****
  • 634
Re: AdditionAgentRAM - an unused piece of memory?
« Reply #1 on: 04 / November / 2013, 14:10:09 »
It seems this has been spotted before, but it is interesting to see it is usable.

http://chdk.setepontos.com/index.php?topic=5549.msg53686#msg53686

2Mb (or 1.4Mb) sounds quite a useful chunk of memory. As to what to do with it, IP stack for IP over USB perhaps  :P (just a random thought, not a particularly serious suggestion.).

Edit: I need to learn to count  ;) 200K or 140K... not 2Mb or 1.4Mb
« Last Edit: 04 / November / 2013, 16:59:43 by ahull »

*

Offline reyalp

  • ******
  • 14079
Re: AdditionAgentRAM - an unused piece of memory?
« Reply #2 on: 04 / November / 2013, 16:12:02 »
2Mb (or 1.4Mb) sounds quite a useful chunk of memory.
Yes, but this is ~200k or ~140k :)

This could be enough for the main CHDK binary, but 140k is *very* tight (my current d10 trunk build is 147924 bytes). If we were going to use this, we'd probably want a build time check of CHDK size vs ram area size.

Still, could be useful for cameras that have low memory, while avoiding some of the exmem issues. Since it's fairly small, I wouldn't be surprised if it is otherwise unused. However, I seem to remember some factory mode related binaries being loaded to the same address as a framebuffer, so checking various shooting modes, video recording, ptp would probably be a good idea.

I guess with some hacking, we could put a subset of code/data/bss there.

Another option would be to make a separate suba pool, which might help avoid some fragmentation issues. Since the addresses are known, you could wrap malloc/free etc to know which pool a pointer came from. In this way, CHDK could allocate from addition ram where possible, and still fall back to regular heap if it filled up.

I don't remember offhand if suba supports multiple discontinuous regions internally.
Don't forget what the H stands for.

Re: AdditionAgentRAM - an unused piece of memory?
« Reply #3 on: 04 / November / 2013, 16:18:32 »
2Mb (or 1.4Mb) sounds quite a useful chunk of memory.
Yes, but this is ~200k or ~140k :)
....
I guess with some hacking, we could put a subset of code/data/bss there.
My biggest Lua script currently runs around 20K for the source file.  I'm not sure I've seen any larger scripts although there probably are some.  Would storing the source file there help with some of the "out of memory" errors we are sometimes seeing when re-running big scripts?
Ported :   A1200    SD940   G10    Powershot N    G16


*

Offline reyalp

  • ******
  • 14079
Re: AdditionAgentRAM - an unused piece of memory?
« Reply #4 on: 04 / November / 2013, 16:29:17 »
My biggest Lua script currently runs around 20K for the source file.  I'm not sure I've seen any larger scripts although there probably are some.  Would storing the source file there help with some of the "out of memory" errors we are sometimes seeing when re-running big scripts?
For Lua, we should just discard the source after it's loaded. Once it's compiled to bytecode lua doesn't need the source any more. I think we've discussed this before. Note you can do this automatically by putting most of your code in a module and requiring it.

If we use the AdditionAgentRAM memory, hard coding it to be used just for script wouldn't be my first choice.
Quote
Would storing the source file there help with some of the "out of memory" errors we are sometimes seeing when re-running big scripts?
I suspect (but haven't verified) that interrupting lua with the interrupt key can leak memory (you sometimes get a Lua assert, which is normally ignored but doesn't actually clean up after itself. Probably related to restore). Otherwise, re-running scripts should not be a problem.
Don't forget what the H stands for.

*

Offline msl

  • *****
  • 1280
  • A720 IS, SX220 HS 1.01a
    • CHDK-DE links
Re: AdditionAgentRAM - an unused piece of memory?
« Reply #5 on: 04 / November / 2013, 16:59:51 »
My biggest Lua script currently runs around 20K for the source file.  I'm not sure I've seen any larger scripts although there probably are some.
~60K  :)
http://trac.assembla.com/chdkde/browser/scripts/twilight/twilive.lua

Most cameras need a loader script for this.

msl
CHDK-DE:  CHDK-DE links

Re: AdditionAgentRAM - an unused piece of memory?
« Reply #6 on: 04 / November / 2013, 17:04:26 »
Maybe this could be used for icons, fonts or some things like this.

@ msl: 60 K?! Even my text editor is only ~20 :D
if (2*b || !2*b) {
    cout<<question
}

Compile error: poor Yorick

Re: AdditionAgentRAM - an unused piece of memory?
« Reply #7 on: 04 / November / 2013, 18:56:39 »
For Lua, we should just discard the source after it's loaded. Once it's compiled to bytecode lua doesn't need the source any more. I think we've discussed this before. Note you can do this automatically by putting most of your code in a module and requiring it.
I remember the conversation.  You mentioned something about needing to keep the source loaded because of the way @param values were used (IIRC) ?

I suspect (but haven't verified) that interrupting lua with the interrupt key can leak memory (you sometimes get a Lua assert, which is normally ignored but doesn't actually clean up after itself. Probably related to restore). Otherwise, re-running scripts should not be a problem.
I've noticed while debugging scripts that I seem to run out of memory after a few error exits related to trying to use nil values.  Of course now that I want to demonstrate it,  I can't reproduce it.   There was also this curiosity where the OP claims to not be able to start a script more than once :  http://chdk.setepontos.com/index.php?topic=10822.msg106693#msg106693

~60K  :)
I surrender - my eyes hurt just looking at that one.
« Last Edit: 04 / November / 2013, 19:37:44 by waterwingz »
Ported :   A1200    SD940   G10    Powershot N    G16


Re: AdditionAgentRAM - an unused piece of memory?
« Reply #8 on: 05 / November / 2013, 02:43:16 »
Hello,

I have the code "addition Agen tram - on unused piece of memory" transfer to my SX230HS and everything works so far without errors.
The advantage is that I can set "Super Fine" quality as well, without leading to crashes.
This leads to a significant improvement of the JPG-quality .
Thank you for that.

Another question: Is it possible to set the Canon firmware to another storage path for the JPG images.

I would like to save Panorama-images or HDR-images into separate directories. Any idea?

Greetings

Re: AdditionAgentRAM - an unused piece of memory?
« Reply #9 on: 05 / November / 2013, 05:25:26 »
The advantage is that I can set "Super Fine" quality as well, without leading to crashes.
This leads to a significant improvement of the JPG-quality .

This seems to be rather important advantage! If there would be no other problems I think that this camera could use this memory region as default for CHDK.
if (2*b || !2*b) {
    cout<<question
}

Compile error: poor Yorick

 

Related Topics