Hi all,
sorry for this very lame NEWBIE question.
New to the forum so not sure where to post my topic either, so apologies if i have done it in the wrong spot.
I come from a world of tuning aftermarket automotive engine management computers.
Now when you first connect to MOST (ECU's) you can upload the file from the engine management ECU to your laptop and save it to a new file folder and give it a name.
This allows you to save the file and look at the settings etc at a later time or right there and then, make adjustments, change the name and save the new file to the ECU.
Why is this not a possibility with ARDUINO or other SBC's.
Or is it.
From the very little i know and have seen this can not be done.
I know you need to upload the sketch etc from different sites or from the person who wrote the file.
Is the inability to do this a software protection strategy to stop people from copying other's files and using them against their will. (COPY WRITE BREACHES ETC).
Or is this due to the componentry used on these small devices.
Thanks for your time.
Kind Regards

My guess why you don't see anyone doing this is that the data format is proprietary, and generally indecipherable without the codex.

Hello Dave,

The answer lies in the fact you are talking about 2 different things:
On an ECU, or indeed any piece of kit that uses some kind of embedded controller (an internet router for example), there will be some software, which you don't have access to, and a configuration, which you do have access to. Your ECU will be running some proprietary software and that software will have within it the capability to change some configuration values to modify the performance of the engine the ECU controls. It is these configuration values that you can download, modify then upload later, not the underlying software.

On an embedded controller, Arduino or otherwise, you are the one writing the software, you have access to the software and can specify what it does and you can modify it, however, there is an important difference between the configuration values you modify on an ECU and the software. When you write software for an Arduino the language you are using is C/C++, which is (sort of) human readable. The controller does not know anything about C/C++, it only knows about machine code. When you compile and upload your C/C++ file the compiler converts it to machine code and uploads that. The micro-controller does not see or know anything about your original code. So, yes, you can download from a micro-controller the code it has in it but you won't recover the original program that the programmer wrote because it's not there to recover. If you spend a LOT of time and effort you might be able to re-construct the original program, but really, it's probably easier to start again and write your own.

Which OS is your laptop running? What laptop program do you use to download from the ECU? Does that program have options for AVR and ARM microcontrollers?

even for a secret service with high skilled specialist it will take weeks to reconstruct what a machine code does in summary. It will be much easier to learn programming and write your own code.

To use a mechanical analogon.
The single-machine-code command is like screws and hex-nuts and struts of different size.
From the sequence they are ligned up you might be able to see this screw and this hex-nut connect the following two struts.
But from this you are not able to see if they are part of the chassis or if the belong to some part of the motor of a car.
And you aren't able to see if the whole thing is a car maybe it is a caterpillar.

And in addition: everything is build from a relative small number of commands. Like the whole car with all it's details is build from small LEGO-bricks. Imagine a 1:1 size model of a car or truck completely build from standard-LEGO-bricks. This makes it so hard to re-construct the whole thing from the level machine-code.

best regards Stefan

In general you can read the code from an arduino and store it in a file, but as has been stated this is not generally very usable, unless your intent is to copy the code to an identical arduino board. Most (if not all) of the processor chips used in the arduino’s have the capability of protecting the code by disabling the ability to read it, you will often see this in commercial products to discourage casual hackers.

Your question inspired me to a (at least for me ) interesting idea:
For standard-arduinos space is quite limited. An additional storage-device like an EEPROM would be used for this.

In addition to uploading the machine-code uploading the textfile containing that exact version of the source-code
that is running on the board. This means additional work in coding and in maintaining but it would offer if everything is lost except the board that is running the code itself . If the board itself holds the sourcecode you could still download it
from there as the last rescue. Other boards like ESP8266 or ESP32 have quite a lot of flash-memory that could be uses as general-purpose memory. (SPIFFS)

Right now I'm using some macro-functions to identify the code running

void PrintFileNameDateTime()
  Serial.print("Code running comes from file ");
  Serial.print("compiled ");

this function uses macro-commands like "FILE" . If you compile the sourcecode the compiler replaces the "FILE" with the real actual filename you are compiling.
I add this to the setup-function

void setup() {
  Serial.begin(115200);   // Init Serial Monitor
  Serial.println();  // a carriage return to make sure serial-output begins in colum 1 of a new line

So the code itselfs can tell the filename etc. of that sourcecode that was used to compile the machinecode

best regards Stefan


Now when you first connect to MOST (ECU's) you can upload the file from the engine management ECU to your laptop and save it to a new file folder and give it a name.
This allows you to save the file and look at the settings etc at a later time or right there and then, make adjustments, change the name and save the new file to the ECU.
Why is this not a possibility with ARDUINO or other SBC's.

It looks like a YX [sic] problem. The thread has wondered off on recovery of source code and other matters tangent or even orthogonal.

Your program will be written and uploaded. Presumably you have some configuration data, the program must account for uploading this, storing it and upon request downloading it.

These upload and download are entirely written by you as part of the program. Entirely distinct from uploading the program, which you do by the IDE as usual and have to keep the source of which safe on your big rig.

You can store the configuration in EEPROM on board, or a bigger EEPROM you attach or an SD card.

Uploading could be you put the configuration on the SD card, downloading is the program writes the configuration on the SD card. Mobius dash board cameras use this method. They read a congif.sys to set parameters, then erase that file. To get the config, it writes that same file to the SD card. Slick.

[Or you just get and set parameters over serial communication. You would design a process for this again as part of the program. It is done alla time and can be as simple or as complex as you like. And as full or not of error checking, &c.]

If it is changes to the program, even that is entirely possible. You could write a little interpreter and upload and download "programs". It mightn't be fast enough for your purposes. Or writing an interpreter is beyond you.



To get an idea of why reading the program out of an Ardiuno isn't much help, this sketch:

void setup() {}
void loop() {}

gets uploaded as 444 bytes of binary:


That's pretty much what you'd get if you downloaded the contents of the Arduino memory. It's not something you can easily interpret.

IF your sketch had one or more large look-up tables like an ECU it might be possible to find those in the memory dump and modify the table contents... But most sketches aren't like that.