# Can I change factory reset firmware?

**URL:** <https://community.particle.io/t/can-i-change-factory-reset-firmware/3247>\
**Category:** Firmware\
**Created:** [March 5, 2014, 2:19pm UTC](https://community.particle.io/t/can-i-change-factory-reset-firmware/3247 "2014-03-05T14:19:13Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryotsuke](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/ryotsuke/32/1902_2.png) [@ryotsuke](https://community.particle.io/u/ryotsuke)\
**Post date:** [March 5, 2014, 2:19pm UTC](https://community.particle.io/t/can-i-change-factory-reset-firmware/3247/1 "2014-03-05T14:19:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kennethlimcp](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@kennethlimcp](https://community.particle.io/u/kennethlimcp)\
**Post date:** [March 5, 2014, 2:22pm UTC](https://community.particle.io/t/can-i-change-factory-reset-firmware/3247/2 "2014-03-05T14:22:24Z")

</div>

@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

---

<div class="post-metadata">

**Author:** ![ryotsuke](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/ryotsuke/32/1902_2.png) [@ryotsuke](https://community.particle.io/u/ryotsuke)\
**Post date:** [March 5, 2014, 2:24pm UTC](https://community.particle.io/t/can-i-change-factory-reset-firmware/3247/3 "2014-03-05T14:24:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kennethlimcp](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@kennethlimcp](https://community.particle.io/u/kennethlimcp)\
**Post date:** [March 5, 2014, 2:30pm UTC](https://community.particle.io/t/can-i-change-factory-reset-firmware/3247/4 "2014-03-05T14:30:09Z")

</div>

This isn’t really exposed yet but you can look somewhere around:

> <https://github.com/particle-iot/firmware/blob/228767ba6a1d7cba24b2ca7d769cb4e3ceb31d2b/src/wifi_credentials_reader.cpp>

---

<div class="post-metadata">

**Author:** ![ryotsuke](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/ryotsuke/32/1902_2.png) [@ryotsuke](https://community.particle.io/u/ryotsuke)\
**Post date:** [March 5, 2014, 2:49pm UTC](https://community.particle.io/t/can-i-change-factory-reset-firmware/3247/5 "2014-03-05T14:49:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ryotsuke](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/ryotsuke/32/1902_2.png) [@ryotsuke](https://community.particle.io/u/ryotsuke)\
**Post date:** [March 5, 2014, 2:53pm UTC](https://community.particle.io/t/can-i-change-factory-reset-firmware/3247/6 "2014-03-05T14:53:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ryotsuke](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/ryotsuke/32/1902_2.png) [@ryotsuke](https://community.particle.io/u/ryotsuke)\
**Post date:** [March 5, 2014, 3:00pm UTC](https://community.particle.io/t/can-i-change-factory-reset-firmware/3247/7 "2014-03-05T15:00:18Z")

</div>

I believe i need to change something like this

WLAN\_MANUAL\_CONNECT = 1  
and set data here:

[http://screenshots.ryotsuke.ru/scr\_6c369d9fff1e.png](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)

---

<div class="post-metadata">

**Author:** ![kennethlimcp](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@kennethlimcp](https://community.particle.io/u/kennethlimcp)\
**Post date:** [March 5, 2014, 3:04pm UTC](https://community.particle.io/t/can-i-change-factory-reset-firmware/3247/8 "2014-03-05T15:04:01Z")

</div>

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

That's the user-code firmware. Oh wells 🙂

> [@ryotsuke](#):
>
> You possibly misunderstood. I want to change the firmware that sparks resets to. Spark-cli "spark flash firmware core-firmware.bin"

---

<div class="post-metadata">

**Author:** ![ryotsuke](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/ryotsuke/32/1902_2.png) [@ryotsuke](https://community.particle.io/u/ryotsuke)\
**Post date:** [March 5, 2014, 3:07pm UTC](https://community.particle.io/t/can-i-change-factory-reset-firmware/3247/9 "2014-03-05T15:07:27Z")

</div>

So I’ve explained now what I would like to have?  
Is it possible?

English is not my native, perhaps I sound confusing

---

<div class="post-metadata">

**Author:** ![timb](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/timb/32/1913_2.png) [@timb](https://community.particle.io/u/timb)\
**Post date:** [March 5, 2014, 3:43pm UTC](https://community.particle.io/t/can-i-change-factory-reset-firmware/3247/10 "2014-03-05T15:43:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ryotsuke](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/ryotsuke/32/1902_2.png) [@ryotsuke](https://community.particle.io/u/ryotsuke)\
**Post date:** [March 5, 2014, 3:57pm UTC](https://community.particle.io/t/can-i-change-factory-reset-firmware/3247/11 "2014-03-05T15:57:58Z")

</div>

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

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)

---

<div class="post-metadata">

**Author:** ![Dave](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/dave/32/181_2.png) [@Dave](https://community.particle.io/u/Dave)\
**Post date:** [March 5, 2014, 4:13pm UTC](https://community.particle.io/t/can-i-change-factory-reset-firmware/3247/12 "2014-03-05T16:13:47Z")

</div>

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

Thanks,  
David

---

<div class="post-metadata">

**Author:** ![ryotsuke](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/ryotsuke/32/1902_2.png) [@ryotsuke](https://community.particle.io/u/ryotsuke)\
**Post date:** [March 5, 2014, 4:21pm UTC](https://community.particle.io/t/can-i-change-factory-reset-firmware/3247/13 "2014-03-05T16:21:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Dave](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/dave/32/181_2.png) [@Dave](https://community.particle.io/u/Dave)\
**Post date:** [March 5, 2014, 4:33pm UTC](https://community.particle.io/t/can-i-change-factory-reset-firmware/3247/14 "2014-03-05T16:33:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ryotsuke](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/ryotsuke/32/1902_2.png) [@ryotsuke](https://community.particle.io/u/ryotsuke)\
**Post date:** [March 5, 2014, 4:43pm UTC](https://community.particle.io/t/can-i-change-factory-reset-firmware/3247/15 "2014-03-05T16:43:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Dave](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/dave/32/181_2.png) [@Dave](https://community.particle.io/u/Dave)\
**Post date:** [March 5, 2014, 4:57pm UTC](https://community.particle.io/t/can-i-change-factory-reset-firmware/3247/16 "2014-03-05T16:57:36Z")

</div>

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);
```

---

<div class="post-metadata">

**Author:** ![frlobo](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/frlobo/32/1279_2.png) [@frlobo](https://community.particle.io/u/frlobo)\
**Post date:** [May 5, 2014, 6:51pm UTC](https://community.particle.io/t/can-i-change-factory-reset-firmware/3247/17 "2014-05-05T18:51:18Z")

</div>

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)?

---

<div class="post-metadata">

**Author:** ![kennethlimcp](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@kennethlimcp](https://community.particle.io/u/kennethlimcp)\
**Post date:** [May 5, 2014, 11:32pm UTC](https://community.particle.io/t/can-i-change-factory-reset-firmware/3247/18 "2014-05-05T23:32:46Z")

</div>

@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?

---

<div class="post-metadata">

**Author:** ![frlobo](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/frlobo/32/1279_2.png) [@frlobo](https://community.particle.io/u/frlobo)\
**Post date:** [May 6, 2014, 6:17am UTC](https://community.particle.io/t/can-i-change-factory-reset-firmware/3247/19 "2014-05-06T06:17:50Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![kennethlimcp](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@kennethlimcp](https://community.particle.io/u/kennethlimcp)\
**Post date:** [May 6, 2014, 6:34am UTC](https://community.particle.io/t/can-i-change-factory-reset-firmware/3247/20 "2014-05-06T06:34:07Z")

</div>

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](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 😉

[Next page](https://community.particle.io/t/can-i-change-factory-reset-firmware/3247.md?page=2)
