Can I change factory reset firmware?

Can I make my own factory reset firmware with my own default wifi credentials?
Would be handy during debug experiments

@ryotsuke did you try the spark-cli?

It allows you to compile your code into a .bin file and you can use it to replace the factory-reset firmware through dfu-util

And what code should I use to set default wifi credentials? So I still could set other ones with mode button and Smart Config

This isnā€™t really exposed yet but you can look somewhere around:

You possibly misunderstood. I want to change the firmware that sparks resets to.
Spark-cli ā€œspark flash firmware core-firmware.binā€ is used to flash new firmware, but it is not replacing default one, that appears on board after reset.
Code youā€™ve provided allows to set new credentials, but I want to store default ones directly inside.
So basically I want my frimware with my settings appear directly after factory reset with no further actions required.
Setting default credentials so no need to set them again after factory reset is main purpose.

Use case:

Now:

  1. Flash firmware from cloud, core hangs
  2. Factory Reset
  3. Attach to PC
  4. Use serial client to set credentials
  5. Detach core
  6. Wait to connect to cloud

I want (for now):

  1. Flash firmware from cloud, core hangs
  2. Factory Reset
  3. Wait to connect to cloud

Potential later use:

  1. Core hangs
  2. Factory reset
  3. Core connects to my wifi defaults, than updates itself from local cloud with preconfigured firmware name

Last one will be increadibly handy for updating lot of cores in some enterprise environment.

I believe i need to change something like this

WLAN_MANUAL_CONNECT = 1
and set data here:

http://screenshots.ryotsuke.ru/scr_6c369d9fff1e.png

But iā€™m not sure what will happen to this data after firmware from cloud updates.
Also I dont know how to make this factory firmware (if it is possible at all)

1 Like

You said 'factory reset firmware' earlier. core-firmware.bin doesn't change the factory reset firmware.

That's the user-code firmware. Oh wells :slight_smile:

So Iā€™ve explained now what I would like to have?
Is it possible?

English is not my native, perhaps I sound confusing

Create a firmware with the WiFi credentials you want, use the local build tools to compile a bin and use dfu-util to replace the Factory Reset bin.

dfu-util can write to any area of internal or or external SPI flash (which is where the factory reset firmware is located). See the Memory Map in the Spark Docs. (Iā€™d get you a link but Iā€™m posting from my phone.)

So if I write anything to
0x20000 Factory Reset Firmware Location 128 KB max
It becomes factory reset firmware. Great :smile:

What about hard coding credentials. If I just override variables like _ssid[] core will connect, but after OTA these variables will have values from cloud version. I need to write values to same place connect_callback(ssid, password, security_type) does, but do that only once per factory reset (not per reset) so they can be changed with mode button (I assume we donā€™t change anything more in default firmware at the moment)

1 Like

Hi @ryotsuke,

Yes! Writing any firmware to 0x20000 will replace the firmware the core loads during a factory reset. You can manually set the credentials the firmware will use every time with the ā€œWLAN_MANUAL_CONNECTā€ process you outlined above, but if you want these credentials to persist after flashing different firmware (provided you donā€™t include the default creds in all your flashed snippets), you would need to save a wifi profile on the cc3000.

You could add something like this to your setup:

void wifi_add_profile_callback(const char *ssid, const char *password, unsigned long security_type);

Though you would probably want some extra logic to make sure youā€™re not adding too many profiles, etc, etc. :smile:

Thanks,
David

so setup should be

void setup() {
    clear_profiles();//???
    wifi_add_profile_callback("my ssid", "my password", WPA2);
}

Still confusing:

  1. Will this work with recent firmware changes that init WLAN before static constructors and setup methods?
  2. I use mode button, enter other credentials and gotcha - they are resetted by setup() again

Exactly, so you could do something like have it in a class constructor before setup (#1). #2 is a little harder, honestly it sounds like the ā€˜betterā€™ solution for you would be to tweak the bootloader slightly so that it doesnā€™t clear wifi profiles during a factory reset.

May be I just need a way to read credentials and set them if they are completely empty. Is there anything like that?
If factory reset itself cleanups wifi credentials, that will be a solution

Hmm, Iā€™m not aware of a way to read profiles back out, but there certainly could be.

Alternatively, you could also modify the connection policy on the CC3000 to default to connect to open access points, by setting ā€œshould_connect_to_open_apā€

extern long wlan_ioctl_set_connection_policy(
               unsigned long should_connect_to_open_ap,
               unsigned long should_use_fast_connect,
               unsigned long ulUseProfiles);

Sorry for the request. But I am a newbieā€¦

Is there like a step by step tutorial someone is willing to drop here to make my code become the default Firmware, and make sure it does not become bigger in size than the default factory firmware (allowed size)?

@frlobo,

I hope I got your question right. The default factory reset firmware is a Tinker App like what you get with a new :spark: core.

I can post the code in the default Tinker app and you can paste in a new App I WebIDE but any new code you add will make the size larger.

Whatā€™s your concern? Running out of memory?

No. My concern is that I want my app to be able to be flashed with the default factory reset instead of the Tinker App. And as I read in this thread, there is a size limit for this app in order to be ref lashed correctly to the right place in memory.

I am not concerned about memory at all. Its a fairly small program, but I just want to make sure I understand the limits right.

Now ā€¦ Once I replace in the webIDE the Tinker Appā€¦ Whatā€™s next steps to set this new (my) app as the default APP for any factory reset operation instead of the Tinker App? (IE: Mode Button for 10 secs with Reset Tap).

Thanks for the help!

I canā€™t get your question somehowā€¦

You want to replace the Factory Reset Firmware with your own firmware which loads every time you perform a factory reset?

Thereā€™s not too much of a limit for the Factory reset and it stays in the External flash from 0x20000 to 0x3FFFF if iā€™m not wrong.

Take a look at: http://docs.spark.io/#/hardware/memory-mapping-external-flash-memory-map

I have a tutorial to replace the default factory firmware if i got your question correct :wink: