18

All embedded devices includes a "Factory reset" option that allows the user to reset his device if something is wrong.

I am developing a Firmware on an STM32 board. The firmware includes a boot loader that allows to upgrade the application via UART (By sending a binary file that contains the new image) and I want to add another feature: A factory reset. When the user choose this option, the board shall load the original image.

What is a Factory reset? Is it about loading the whole binary file into memory again or it's just calling a function that reinitialize variables modified by the end user?

What are the best practices to do so?

Where to store the original FW? is it in an internal or external flash?

Pryda
  • 1,241
  • 2
  • 19
  • 30

4 Answers4

20

Generally speaking the factory reset function you mention will restore any saved variable data information back to default values. It is not true that all embedded devices have this capability. Some do but not all.

If you want your device to support a return to factory default firmware itself then your design has to incorporate a memory into the circuit to store that image. A common component for this is a SPI flash chip. Then your boot loader also needs to be changed to support a mode of getting a firmware image from the SPI flash chip instead of getting the image in through the serial port. If your device does not support user replaceable firmware then it is usually not necessary to provide a means to restore to factory default firmware.

Michael Karas
  • 56,889
  • 3
  • 70
  • 138
  • 1
    Not really an answer so I'll leave it as a comment: some device just revert settings to defaults, this is easy (for example, just erase the user settings). Others (fewer, I think) reset firmware to factory default. This is harder, since you need a way to replace the existing firmware with older firmware. – Dithermaster May 29 '18 at 01:14
11

If you take the most common example of factory defaults, it's your PC's UEFI (BIOS).

It is made with a flash chip and a volatile battery backup SRAM memory chip. The flash chip contains the program, and the SRAM contains the settings.

On factory reset, the contents of the volatile sram are erased. On the next boot, it detects that the checksum of the settings is invalid and restores the defaults contained in the program.

This is not limited to battery backup SRAM, the same can be done with FLASH or EEPROM. But battery backup SRAM can be erased without powering up the machine.


Another term is factory recovery, this simply means that it contains the main program twice. But only one copy can by upgraded by the user.
Dual-BIOS is an example of this.

On higher level systems, like phones and computers, it means that it uses the installation files to restore the operating system to factory conditions.

Jeroen3
  • 21,976
  • 36
  • 73
10

Factory reset is whatever you want it to be. It depends on the application and device type.

I usually do two things:

  1. Ensure that there is always a reliable way to enter the bootloader, so that even a partial/wrong firmware update can't brick the device.
  2. Have a way to reset the firmware settings in case the user changes something, a particular setting combination will crash the application etc.

Both can be done with buttons (long presses, short presses), DIP switches or other communication means (eg. UART, USB).

For example if you use one GPIO for a single button you could use it the following way:

  1. Power-on + button pressed = invoke bootloader
  2. Power-on, button not pressed = wait 3s, blink a led, if a button is pressed (within the window) and held for 5s then reset firmware settings
filo
  • 8,801
  • 1
  • 25
  • 46
2

As you said the factory reset reloads the initial factory image to the device. This can be necessary in case of a misconfiguration where the user just didn't know what he does or just wants to go back to the initial configuration. In cases like yours were a software update is performed you may wanna cover certain failure scenarios during the update. In this case you may even have a dedicated flash memory with the original factory image stored that can be selected using a jumper to restore factory default configuration. This is e.g. done on computer mainboards were you can restore original BIOS configuration in case an update would fail and corrupt the main image.

po.pe
  • 2,548
  • 1
  • 10
  • 25