Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

'over the air' update; possible?


  • Please log in to reply
9 replies to this topic

#1 ziggurat29

ziggurat29

    Advanced Member

  • Members
  • PipPipPip
  • 244 posts

Posted 23 March 2013 - 08:58 PM

Is there any known facility/technique for updating the deployed application in an unattended fashion programattically in the field?

 

I would like to:

*  connect to my device from afar

*  send an updated application binary -- probably stored on SD

*  instruct the unit to go into some 'mode' whereby the application is updated (the 'deployment', not the firmware.  but hey maybe that too)

*  the restart the application

 

I haven't seen anything like this (or maybe my google fu simply fails me today), hence the question.

 

If not, I imagine I could maybe replace TinyBooter with a custom mechanism for doing this, since TinyBooter is mostly unneeded needed on the Netduino.

 

tia!

-dave



#2 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 23 March 2013 - 09:40 PM

There are several discussions within the forums regarding the pieces necessary to make this happen.  Look for "Loading Assemblies Dynamically from SD" and Web Server.

 

You can keep the up-datable portion of your application as a DLL on the SD card and load it dynamically.  Using something like the NeonMika Webserver or even a more simplified Web Server for just file updates and reboot commands you can upload a new DLL then reboot the netduino remotely.



#3 ziggurat29

ziggurat29

    Advanced Member

  • Members
  • PipPipPip
  • 244 posts

Posted 23 March 2013 - 10:47 PM

There are several discussions within the forums regarding the pieces necessary to make this happen.  Look for "Loading Assemblies Dynamically from SD" and Web Server.

 

You can keep the up-datable portion of your application as a DLL on the SD card and load it dynamically.  Using something like the NeonMika Webserver or even a more simplified Web Server for just file updates and reboot commands you can upload a new DLL then reboot the netduino remotely.

 

I'll look into that; truthfully my assumption was that any assembly I loaded from SD would be loaded into RAM before executing, which I did not want to do.  I was assuming that SD storage (ultimately coming over SPI from the card and interpreted as a block filesystem), is not XIP-capable, but I could be mistaken...

 

EDIT:  just tried search on your suggested keywords, and only got your and my post here, haha.  probably symptomatic of a poor search mechanism...  Edit2Edit:  or symptomatic of me not observing the grey patch indicating that the search was scoped to 'this topic' duh.



#4 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 24 March 2013 - 01:26 PM

I'll try to dig out the links to some posts later today and share them up. I may have them bookmarked.

#5 ziggurat29

ziggurat29

    Advanced Member

  • Members
  • PipPipPip
  • 244 posts

Posted 24 March 2013 - 02:22 PM

awesome.  I am familiar with the notion of dynamically loading the assembly and running it from the SD -- which is definitely interesting in its own right -- but I don't think I'll be able to run my whole application that way (presently about 90k).  But I'm open to trying, certainly if someone has already figured it out and save me the trouble.



#6 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 24 March 2013 - 07:10 PM

This is not exactly what you want, but I used to deploy the application from Visual Studio to Netduino gen 1 over the air via XBee serial link, it just required to recompile the firmware for serial deployment transport (for other than Netduino Mini, which worked out-of-the-box). If I remember it correctly, the deployment worked fine, but I got some problems with updating the firmware, I think it could have been solved by using flow control, but I did not really try that, I got distracted by other projects...



#7 ziggurat29

ziggurat29

    Advanced Member

  • Members
  • PipPipPip
  • 244 posts

Posted 24 March 2013 - 09:23 PM

haha that's great.  no not exactly what I was wanting, and I took liberty with the meaning 'over the air' in the interest of brevity.  Basically, I want to stage the update on SD (I will get it there either wired or wireless), then once it is fully and safely delivered, the unit will update itself.  Reason of course is that these will not easily be field serviceable once installed.

Nonetheless, that gives me some ideas of where to look in the firmware code to reuse stuff.  I won't get to this for a month or so anyway.



#8 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 25 March 2013 - 11:22 AM

Hi Zigg sorry for the late response...

 

Here is Fabian's article on loading from SD Card. http://fabienroyer.w...ith-a-netduino/

If you search in the Netduino Forums on "loading assemblies dynamically" you'll find several threads where the process has been discussed.

 

Here is the NeonMika Webserver: http://neonmikawebserver.codeplex.com/

The discussion on the webserver is also in the forums at: http://forums.netdui...nmikawebserver/

 

What I can tell you is the file upload and download works great with the NeonMika webserver that Markus developed. I have a windows application that is uploading and downloading files from a Netduino via Ethernet.

 

As far as Fabian's code and loading Assemblies Dynamically... I haven't worked with it yet, but theoretically it should be possible to upload an updated DLL to the SD card that is the core of your application.  Then write a reboot routine in the webserver which I have done and can help you with example code.



#9 ziggurat29

ziggurat29

    Advanced Member

  • Members
  • PipPipPip
  • 244 posts

Posted 25 March 2013 - 01:21 PM

thanks so much for doing the research!  I'll devise an A/B test on memory impact and report back the results.



#10 ziggurat29

ziggurat29

    Advanced Member

  • Members
  • PipPipPip
  • 244 posts

Posted 26 March 2013 - 04:14 PM

OK, I performed some tests.  Here's a brief(?) summary of the tests, the results, etc.  I have attached my test projects, which also has more detailed run captures, on the off chance anyone might want to fiddle with it some more without redoing the test code from scratch.

 

This was run on NP2 firmware 4.2.2.1, and compiled with DevStudio 2010 Ultimate.

Four tests ('static' means 'not dynamicallly loaded'):

1)  baseline static, trivial operation, get final approximate free memory with GC(true)

2)  baseline dynamic, same trivial operation, but in a separate assembly loaded from SD card

3)  nontrivial static, has reference to hefty module, use it minimally

4)  nontrivial dynamic, same thing from SD card.  This has three flavors; more on that later.

 

OK, right as I started out constructing test 2 it becme obvious that I personally was not going to be able to use this technique for my application because this does indeed load the assembly into RAM, and currently my assembly is 58k in release build (with deps it gets to 90k deployed), but my app currently quiesces with about 50k bytes free, so in my case I have a RAM shortage.  So much for me and my application.

Still the technique seems interesting so I pressed on with the tests.  Here is a summary of the final free memory as reported by GC(true), which is fairly approximate as it turns out; more on that later.

 

Test01 -- 105012 Test02 --  87708 Test03 --  99468

Test04 wontwork -- n/a Test04 explicit   --  59172 Test04 implicit   --  82080  

(the doc in the project has more detailed sampling points throughout the execution if you're at all curious)

 

Test 4 has three flavors because it has a reference to another assembly.  There is a 'wontwork' project that, well, wont work, because it does not satisfy that dependency.  It just there to prove the point, and if you want to see how the system behaves in that case.  The other two satisfy that dependency by either having the host (loading) module reference the dependent assembly itself (implicit), or having that modules load the dependency from the SD card (explicit).

 

Some Observations:

*  you need the 'le' version of your built module.  Assembly.Load() will fail if you pick the wrong one.  Not lots of helpful debug messages, though.

*  scary debugger message when doing Assembly.Load()

  "Invalid address 0 and range 40 Ram Start 20000000, Ram end 20020000"

I grepped in the firmware source and found it as part of Debugger.cpp  Interestingly, this same line is commented out in 4.2.1 stuff.  So you may or may not get it depending on your firmware version.

I think it is confined to the debugger and benign in the real world.  To be sure I would have to attach the jtag and analyze the call stack and I was not in the mood for that mishegas so I skipped looking into it further.

*  GC(true) is pretty approximate.  In one run I had memory increasing with each alloc!  I put in a 10 second sleep and the numbers made more sense, so I guess that there some internal framework-allocated resources that get released in a manner outside of your control.  I mention this so that in general folks don't get too caught up in GC(true) numbers or attribute more vercity to them than they are worth.  They're useful but can be misleading if you don't double check sanity.

*  When explicitly loading SystemTextRegularExpression in test 4 'explicit' the app would hang at the Assembly.Load().  However, it would immediately unhang if I set a breakpoint while it was hung!  I don't know if the hang is debugger related (and not happen with no debugger attached).  To find out I one would need to change all the Debug.Prints() to spew to a file or something else and run it without the debugger to see what happens.  But this doesn't inspire confidence in stability.  Note, no hangs of this sort were experienced with the 'implicit' load test.

 

What can you do with it?

 

*  Well, in my case I can't use it as-is just because my project is too big.  But if your particular application isn't strapped for RAM, then this may be a viable approach.

*  Also, maybe with planning you can use it more effectively.  For instance, my project has three different communications mechanisms, but really in practice only one of them will be used depending on the site requirements.  So maybe I could break up my project so that it only loads the one it needs, like an old-school 'overlay'.

*  It could be very useful in certain niche cases, loading some sort of 'personality' from the SD card.  For instance, I have a site specific config file on the SD card, and I have code I wrote to parse it.  But alternatively I could have an assembly that consists of the string values and dynamically load that instead of parsing the config file.  Those values would have wound up in RAM anyway, and I save all the parsing code, so it could be a memory saver in the end.

*  a writeable byte array with an executable assembly in it?  hmm, all sorts of self-modifying code shenanigans come to mind!

 

Hope this is of interest to someone!

 

-dave

 

p.s. Fabien Royer did all the work to figure out how to load the assemblies, as per the link Dave VanderWekke provided above -- I just made these tests.  There's a bunch of other interesting things on that site, so it's worth a visit irrespective of this dynamically loading thing.

 

Attached File  NP2DynLoadTest.zip   36.25KB   17 downloads






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.