NEWBIE QUESTION , UPLOAD FROM DEVICE

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
Dave.

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.println(__FILE__);
  Serial.print("compiled ");
  Serial.print(__DATE__);
  Serial.println(__TIME__);  
}

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
  PrintFileNameDateTime();

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

best regards Stefan

DAVE_PRO_TUNING:
...

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.
...
Dave.

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.

HTH

a7

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:

:100000000C9434000C9446000C9446000C9446006A
:100010000C9446000C9446000C9446000C94460048
:100020000C9446000C9446000C9446000C94460038
:100030000C9446000C9446000C9446000C94460028
:100040000C9448000C9446000C9446000C94460016
:100050000C9446000C9446000C9446000C94460008
:100060000C9446000C94460011241FBECFEFD8E03C
:10007000DEBFCDBF21E0A0E0B1E001C01D92A930FC
:10008000B207E1F70E9492000C94DC000C9400008F
:100090001F920F920FB60F9211242F933F938F93BD
:1000A0009F93AF93BF938091050190910601A0911A
:1000B0000701B09108013091040123E0230F2D378F
:1000C00058F50196A11DB11D2093040180930501EF
:1000D00090930601A0930701B0930801809100015D
:1000E00090910101A0910201B09103010196A11D1F
:1000F000B11D8093000190930101A0930201B09380
:100100000301BF91AF919F918F913F912F910F90DC
:100110000FBE0F901F90189526E8230F0296A11D81
:10012000B11DD2CF789484B5826084BD84B58160DE
:1001300084BD85B5826085BD85B5816085BD8091B2
:100140006E00816080936E0010928100809181002A
:100150008260809381008091810081608093810022
:10016000809180008160809380008091B1008460E4
:100170008093B1008091B00081608093B000809145
:100180007A00846080937A0080917A008260809304
:100190007A0080917A00816080937A0080917A0061
:1001A000806880937A001092C100C0E0D0E0209770
:0C01B000F1F30E940000FBCFF894FFCF99
:00000001FF

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.