Go Down

Topic: upload sketch from arduino board to ide (Read 2524 times) previous topic - next topic

kenkoknz

Hi, Can anyone advise me how to upload sketch from arduino board to the ide? Sometimes it would be useful to upload the code from the arduino board to ide to see what sketch is programed on the chip.
Thanks,
K  

retrolefty

#1
Jul 21, 2010, 03:02 am Last Edit: Jul 21, 2010, 03:27 am by retrolefty Reason: 1
Quote
Hi, Can anyone advise me how to upload sketch from arduino board to the ide? Sometimes it would be useful to upload the code from the arduino board to ide to see what sketch is programed on the chip.


Nope, doesn't work that way. You have to save a copy of your C/C++ sketch program away somewhere as a back up of the source code.

A 'trick' I use sometimes is to add code to send the sketch name out the serial port in the setup portion of the sketch so I can see what was last loaded by opening the IDE serial monitor.

Lefty

kenkoknz

thanks lefty,
i was thinking some 'smarties' out there would have worked out a program to initiate a program memory dump of the the chip, and a 'reverse' complier to change the machine code back to source code - maybe doable?
k

retrolefty

Quote
i was thinking some 'smarties' out there would have worked out a program to initiate a program memory dump of the the chip, and a 'reverse' complier to change the machine code back to source code - maybe doable?


In theory, possibly, but then again maybe not practical? The problem is that the 'reverse complier' part would be a task only a software god might take on, with little return on the time investment made.  ;)

Lefty

WanaGo

This type of 'Upload' is common to PLC's (Programmable Logic Controllers - Industrial control systems basically), however isnt done by reverse compiling the code.

The code is written to flash like normal, but the uncompiled code is also able to be uploaded to memory and saved as a file basically. Then when an upload is done, the file is basically downloaded off the processor and opened with the editor.

Most likely not possible with AVR's as the memory may be too small and most likely wouldnt support this, however could most likely be done if you attached a SD sheild (or the like) - however the IDE would need to be modified in order to get the automated upload of the uncompiled code to SD, most likely.

Something to ponder on.

I am an Automation Engineer by trade, and use PLC's everyday, and this feature is very appealing especially if your backup is lost or you 'inherit' a PLC which was programmed some time ago and you have no source code.

Graynomad

Reverse assemblers (aka dissassemblers) used to be pretty common, we used to use them to reverse engineer DOS programs. But reverse assembly is a relatively simple procedure, to generate C/C++ from binary is a world away in difficulty.

I'm not even sure it would be possible with modern optomising compilers?
Rob Gray aka the GRAYnomad www.robgray.com

pluggy

Look on the bright side, Microsoft's business model pretty much depends on the one way aspect of compiling code.......
http://pluggy.is-a-geek.com/index.html

kenkoknz


Lefty quote "In theory, possibly, but then again maybe not practical? The problem is that the 'reverse complier' part would be a task only a software god might take on, with little return on the time investment made."

What i like about "open source" is that the focus is not so much on return on investment (on time and money), but rather the propogation and development of the environment for all to share, and i think this is fantastic. I think a lot of people contributes sketches etc more as a challenge and perhaps to prove that it could be done rather that looking for return on investment. There are some very clever people out there!



retrolefty

Quote
I think a lot of people contributes sketches etc more as a challenge and perhaps to prove that it could be done rather that looking for return on investment. There are some very clever people out there!


There sure are clever and smart people around and I have benefited a lot from user contributed sketches and libraries. However a 'reverse compiler' would again take a extream effort in time (should it support all PC OS platforms?) so I will go out on a limb here and say it's just not something that's going to happen. It doesn't really solve a great need of many people Vs the time and effort required.

Lefty


Imahilus

Software god?
Meh, you don't have to be a 'software god' to write an interpreter...
It would require a decent amount of insanity in this case, because it is bound to be tedious.. and I expect it to see little to no use by this community  :P

What you get from a disassembler isn't what the original source looked like, but rather an optimised version of this (see remark about compiler optimisation).
Interesting to see what sort of pranks the compiler pulls to squeeze efficiency from your code, but not too helpful in discerning the methods used to create the application (and the reason for using those methods).


In anycase, afraid I won't be volunteering for this project :P

mromani

@WanaGo

Interesting idea. The IDE could automatically compress the source code with a bunch of methods (e.g. gzip, bzip2, 7z), see which produces the smallest result and store it in the flash space along with the actual machine code.
To distinguish the compressed source code "file" from actual code, the former could be stored "starting from the end" of the flash memory space.
That's just some random idea off of top of my head...

WanaGo

To me that makes the most sense if someone wanted to takle this. It may not suit the main purpose of this thread though as I am assuming it is to recover code that hasnt been saved.

Future wise though, if someone wanted a project and could figure out how to upload something other than compiled code to the AVR's flash. No idea if this is possible or not - I am by no means at the level needed with AVR's to even attempt testing that.

But as I say, if uncompiled code could be loaded into the AVR then it can easily be extracted again and run in the IDE. I guess the uncompiled verison of the code would be considerable even when compressed, as I wouldnt think it would be anywhere near as small as compiled code. So only really an option for larger AVR's, or via SD card etc.

More to ponder, im sure someone has run out of projects and would like to experiment :)...

Anyone...  8-)

mromani

A 328p has 32K of flash, which is plenty for most projects. The .pde files, being text, can be compressed with high ratios.
For medium size projects an external eeprom or better yet an sd card as you say would be needed, but there are many sketches for which this approach would be feasible, IMHO.

Example:

Code: [Select]

marcello@ced-desktop:~/sketchbook$ ls -l sketch* Test/Test.pde
-rw-r--r-- 1 marcello marcello 3201 2010-07-13 17:43 Test/Test.pde
-rw-r--r-- 1 marcello marcello 1271 2010-07-23 08:05 test.7z
-rw-r--r-- 1 marcello marcello 1374 2010-07-23 08:04 test.tar.bz2


A 3K sketch becomes a 1,2K 7zip file.
And what about stripping out the comments ? No wait, that would probably defeat the main point of this "feature"... ;-)

Graynomad

Quote
And what about stripping out the comments ? No wait, that would probably defeat the main point of this "feature"... ;-)

Maybe, but it could be an option to fit code that otherwise wouldn't fit, better that than nothing.

Course if we're talking about my code it wouldn't make any difference to the sizeĀ :)
Rob Gray aka the GRAYnomad www.robgray.com

Go Up