diff --git a/board/aarch64/r2s/README.md b/board/aarch64/r2s/README.md index 55dd6290..46304984 100644 --- a/board/aarch64/r2s/README.md +++ b/board/aarch64/r2s/README.md @@ -16,6 +16,7 @@ The front system LEDs work as follows in Infix: | **Stage** | **SYS** | **LAN** | **WAN** | |----------------|---------|---------|---------| | Power-on | dimmed | off | off | +| Factory reset | on | on | on | | Linux loading | on | off | off | | System loading | 1 Hz | off | off | | System up | off | on | off | @@ -48,6 +49,28 @@ LEDs will blink at 5 Hz to clearly indicate something is very wrong. In all error cases the console shows the problem. +Factory Reset +------------- + +The reset button on the side can be used not only to safely reboot the +device, but can also be used to trigger a factory reset at power on. + +At power-on, keep the reset button pressed for 10 seconds. The system +LEDs (SYS, WAN, LAN) will all blink at 1 Hz, to help you count down the +seconds. When the 10 seconds have passed all LEDs are turned off before +loading Linux. + +When Linux boots up it confirms the factory reset by lighting up the +LEDs again, no blinking this time. The LEDs stay on until all files and +directories on read/writable partitions (`/cfg` and `/var`) have been +safely erased. + +The system then continues loading, turning off all LEDs except SYS, +which blinks calmly at 1 Hz as usual until the system has completed +loading, this time with a `startup-config` freshly restored from the +device's `factory-config`. + + How to Build ------------ diff --git a/board/aarch64/r2s/uboot/extras.config b/board/aarch64/r2s/uboot/extras.config index 19bcfa1d..fb36c0ba 100644 --- a/board/aarch64/r2s/uboot/extras.config +++ b/board/aarch64/r2s/uboot/extras.config @@ -1,3 +1,9 @@ +CONFIG_BUTTON=y +CONFIG_BUTTON_GPIO=y + +CONFIG_LED=y +CONFIG_LED_GPIO=y + # CONFIG_MMC_PCI is not set CONFIG_DEVICE_TREE_INCLUDES="infix-env.dtsi infix-key.dtsi r2s-env.dtsi" CONFIG_SYS_PROMPT="(r2s) " diff --git a/board/aarch64/r2s/uboot/r2s-env.dtsi b/board/aarch64/r2s/uboot/r2s-env.dtsi index 279d27e8..7fd318f6 100644 --- a/board/aarch64/r2s/uboot/r2s-env.dtsi +++ b/board/aarch64/r2s/uboot/r2s-env.dtsi @@ -6,7 +6,42 @@ /* This is a development platform, hard code developer mode */ ixbtn-devmode = "setenv dev_mode yes; echo Enabled"; - ixbtn-factory = "echo \"No button available, use bootmenu\""; + + /* Override default definitiion to add LED feedback */ + ixbtn-factory = " +if button factory-reset; then + echo \"Keep button pressed for 10 seconds to engage factory reset ...\" + + for tick in . . . . . . . . . .; do + led nanopi-r2s:red:sys on + led nanopi-r2s:green:lan on + led nanopi-r2s:green:wan on + sleep 0.5 + led nanopi-r2s:red:sys off + led nanopi-r2s:green:lan off + led nanopi-r2s:green:wan off + sleep 0.5 + echo -n \"Checking button: \" + button factory-reset || exit + done + + echo -n \"Final button check: \" + if button factory-reset; then + setenv factory_reset yes + echo \"FACTORY RESET ENGAGED\" + fi +fi +"; + }; + }; + + keys { + compatible = "gpio-keys"; + + factory-reset { + gpios = <&gpio0 0 GPIO_ACTIVE_LOW>; + linux,code = ; + label = "factory-reset"; }; }; };