new zealand
Offline
Newbie
Karma: 0
Posts: 7
Arduino rocks
|
 |
« on: July 20, 2010, 07:59:05 pm » |
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
|
|
|
|
|
Logged
|
|
|
|
|
Left Coast, CA (USA)
Offline
Brattain Member
Karma: 279
Posts: 15316
Measurement changes behavior
|
 |
« Reply #1 on: July 20, 2010, 08:02:34 pm » |
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
|
|
|
|
« Last Edit: July 20, 2010, 08:27:48 pm by retrolefty »
|
Logged
|
|
|
|
|
new zealand
Offline
Newbie
Karma: 0
Posts: 7
Arduino rocks
|
 |
« Reply #2 on: July 20, 2010, 08:26:42 pm » |
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
|
|
|
|
|
Logged
|
|
|
|
|
Left Coast, CA (USA)
Offline
Brattain Member
Karma: 279
Posts: 15316
Measurement changes behavior
|
 |
« Reply #3 on: July 20, 2010, 08:30:47 pm » |
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
|
|
|
|
|
Logged
|
|
|
|
|
NZ
Offline
Sr. Member
Karma: 0
Posts: 376
Turtle in a hard shell
|
 |
« Reply #4 on: July 20, 2010, 11:51:02 pm » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
nr Bundaberg, Australia
Offline
Tesla Member
Karma: 71
Posts: 6827
Scattered showers my arse -- Noah, 2348BC.
|
 |
« Reply #5 on: July 20, 2010, 11:54:33 pm » |
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?
|
|
|
|
|
Logged
|
|
|
|
|
Lancashire, UK
Offline
Edison Member
Karma: 8
Posts: 1988
|
 |
« Reply #6 on: July 21, 2010, 11:55:03 am » |
Look on the bright side, Microsoft's business model pretty much depends on the one way aspect of compiling code.......
|
|
|
|
|
Logged
|
|
|
|
|
new zealand
Offline
Newbie
Karma: 0
Posts: 7
Arduino rocks
|
 |
« Reply #7 on: July 21, 2010, 06:05:24 pm » |
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!
|
|
|
|
|
Logged
|
|
|
|
|
Left Coast, CA (USA)
Offline
Brattain Member
Karma: 279
Posts: 15316
Measurement changes behavior
|
 |
« Reply #8 on: July 21, 2010, 09:02:13 pm » |
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
|
|
|
|
|
Logged
|
|
|
|
|
Holland
Offline
Sr. Member
Karma: 0
Posts: 439
Arduino likes cookies too
|
 |
« Reply #9 on: July 22, 2010, 01:55:53 am » |
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  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 
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
God Member
Karma: 0
Posts: 596
Arduino rocks
|
 |
« Reply #10 on: July 22, 2010, 02:59:27 pm » |
@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...
|
|
|
|
|
Logged
|
|
|
|
|
NZ
Offline
Sr. Member
Karma: 0
Posts: 376
Turtle in a hard shell
|
 |
« Reply #11 on: July 22, 2010, 07:44:24 pm » |
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-)
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
God Member
Karma: 0
Posts: 596
Arduino rocks
|
 |
« Reply #12 on: July 23, 2010, 01:13:09 am » |
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: 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"... ;-)
|
|
|
|
|
Logged
|
|
|
|
|
nr Bundaberg, Australia
Offline
Tesla Member
Karma: 71
Posts: 6827
Scattered showers my arse -- Noah, 2348BC.
|
 |
« Reply #13 on: July 23, 2010, 01:42:18 am » |
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 
|
|
|
|
|
Logged
|
|
|
|
|
|