Spark CLI Flash Memory

Hi all,

Is there a way to use the Spark CLI interface to write into the flash memory of the spark core?
Does the CLI use the dfu-util tool to write the firmware to the spark core?

Muez

Yup! The spark-cli is essentially sending a dfu-util command for the various functions like spark keys server, spark flash --usb or spark flash --factory etc.

Maybe added a general function like spark flash flash_address bin_file` would be awesome :wink:

Take a look at : https://github.com/spark/spark-cli/blob/master/js/lib/dfu.js

Hi @kennethlimcp,

I was looking at that file a while ago, but the problem is I don’t see those functions getting called from the main ApiClient.js.

Hi @Muez,

The dfu-util stuff for the cli is wrapped by the “dfu.js” module here:

https://github.com/spark/spark-cli/blob/master/js/lib/dfu.js

It shouldn’t be too tough to extend it to write arbitrary files to arbitrary addresses, just be careful not to nuke your keys! :slight_smile:

Thanks!
David

Hi @Dave,

I changed the writeFirmware function to this:

writeFirmware: function(binaryPath, leave) {
        return that.writeDfu(1, binaryPath, “0x00100000”, true);
    },

and then when I Ioad a binary to the Spark Core using:

./spark.sh cloud flash spark_core_name path

The core doesnot leave the dfu mode.

Why do you think is that the case?

Why did you change to 0x00100000? Also, you changed the alt to 1 which writes to the External flash…

It seems like you wrote to a memory space which does not exist (max is 0x200000 on external flash) which might be the reason why the core doesn’t reset since the command is somehow invalid.

I’m not sure where you are writing to…

You might want to refer to the mapped address:

http://docs.spark.io/hardware/#memory-mapping-internal-flash-memory-map

I’m just curious what does the output of the DFU-util say. :stuck_out_tongue:

The arguments of the writeDfu function are the alt dfu option (1 - to select flash memory), the binaryPath, the address where I want to write to (0x00100000 a valid flash address) and leave dfu option.

Can you try 0x100000 instead of 0x00100000?

Hi @Muez,

That’s because you’re calling cloud flash ..., when you should be calling flash --usb myfirmware.bin

Thanks,
David

1 Like

Hey,
What I think @Muez is attempting to do is.

To write to the external flash using the cloud.
I too am curious if this is possible and how this can be done using the spark-cli found on github.

Hi @Raul,

Good question! We’ve been thinking about this, and we’ve started working towards it, here’s an example:

@satishgn added the ability to flash firmware over serial, as well as making the OTA process more flexible for writing to arbitrary flash addresses using the same OTA system we have in place already. Look for this to be included hopefully later this summer. :slight_smile:

Thanks,
David

1 Like