Buildroot System One-Click Restore Configuration Guide

The DTU series and G series both have user-defined keys. In the Buildroot system, the default function is the one-click restore system configuration function, but customers can customize its functionality.

Buildroot System One-Click Restore Configuration Guide

  1. Default KEY One-Click Restore System Configuration

After the system starts, long press the KEY button for more than 30 seconds, the system will execute the /usr/sbin/system_reset.sh script, which is as follows:

#!/bin/sh

ifconfig eth0 192.168.0.15 up
ifconfig eth1 10.10.80.15 up


if [ -d /etc/.init.d ]
then
        rm /etc/init.d/* -rf
        cp /etc/.init.d/* /etc/init.d/ -a
        cp /etc/.dhcpcd.conf /etc/dhcpcd.conf
        sync
fi

This allows users who forget the IP or have a startup script blocking access to the system to restore it by long pressing the key. This script can be modified to achieve the desired functionality, or the startup script for this program can be removed to allow the user’s own program to check the state of the KEY.

  1. Automatically Run Watchdog After Boot

By default, after the system boots, the watchdog program runs automatically and performs watchdog feeding. If the program malfunctions or the power is restored after undervoltage, the system will automatically restart.

The device node for the watchdog can be modified in the configuration file /etc/config/daemon.json as follows:

{
    "input": "/dev/input/event1",
    "watchdog": "/dev/watchdog",
    "process": [
      {
        "Id": 1,
        "Name": "app",
        "Path": "/root/app &",
        "Status": true
      }
    ]
}

Some systems have dual watchdogs, and the configuration file can be modified to specify this.

Buildroot System One-Click Restore Configuration Guide

  1. Daemon Process

The Buildroot system can use a daemon process to start programs, allowing them to run in the background, and if they exit abnormally, the daemon will automatically restart the program.

A daemon process script can be created under /etc/init.d/, for example, the script S99daemon is a sample daemon script as follows:

Modify name, command, and command_args as needed

#!/bin/sh

# to ensure uniqueness and for stop, restart and status
name="EXAMPLE"
# The path of the client executable
command="/usr/bin/EXAMPLE"
# Any command line arguments for the client executable
command_args=""

[ -x "$command" ] || exit 0

case "$1" in
    start)
        # This if statement isn't strictly necessary but it's user friendly
        if "$daemon" --running --name "$name" --pidfiles "$pidfiles"
        then
            echo "$name is already running."
        else
            echo -n "Starting $name..."
            "$daemon" --respawn $daemon_start_args \
                --name "$name" --pidfiles "$pidfiles" \
                ${user:+--user $user} ${chroot:+--chroot $chroot} \
                ${chdir:+--chdir $chdir} ${umask:+--umask $umask} \
                ${stdout:+--stdout $stdout} ${stderr:+--stderr $stderr} \
                -- \
                "$command" $command_args
            echo done.
        fi
        ;;  

    stop)
        # This if statement isn't strictly necessary but it's user friendly
        if "$daemon" --running --name "$name" --pidfiles "$pidfiles"
        then
            echo -n "Stopping $name..."
            "$daemon" --stop --name "$name" --pidfiles "$pidfiles"
            echo done.
        else
            echo "$name is not running."
        fi
        ;;  

    restart|reload)
        if "$daemon" --running --name "$name" --pidfiles "$pidfiles"
        then
            echo -n "Restarting $name..."
            "$daemon" --restart --name "$name" --pidfiles "$pidfiles"
            echo done.
        else
            echo "$name is not running."
            exit 1
        fi
        ;;  

    status)
        "$daemon" --running --name "$name" --pidfiles "$pidfiles" --verbose
        ;;  

    *)
        echo "usage: $0 <start|stop|restart|reload|status>" >&2
        exit 1
esac

exit 0

To view processes with ps:

  181 root     /sbin/klogd -n
  204 root     /sbin/udevd -d
  255 dhcpcd   dhcpcd: [manager] [ip4] [ip6]
  256 root     dhcpcd: [privileged proxy]
  257 dhcpcd   dhcpcd: [network proxy]
  258 dhcpcd   dhcpcd: [control proxy]
  275 root     /usr/sbin/ntpd -g -p /var/run/ntpd.pid
  404 root     nginx: master process /usr/sbin/nginx
  405 www-data nginx: worker process
  431 root     sshd: /usr/sbin/sshd [listener] 0 of 10-100 startups
  434 root     -bash
  473 dhcpcd   dhcpcd: [BPF ARP] eth0 192.168.0.15
  485 root     key_reset: /usr/sbin/key_reset
  498 root     [kworker/0:2]
  501 root     [kworker/0:0]
  502 root     ps
#

Kill the process key_reset and check again:

# kill 485
# watchdog watchdog0: watchdog did not stop!
# ps
  204 root     /sbin/udevd -d
  255 dhcpcd   dhcpcd: [manager] [ip4] [ip6]
  256 root     dhcpcd: [privileged proxy]
  257 dhcpcd   dhcpcd: [network proxy]
  258 dhcpcd   dhcpcd: [control proxy]
  275 root     /usr/sbin/ntpd -g -p /var/run/ntpd.pid
  404 root     nginx: master process /usr/sbin/nginx
  405 www-data nginx: worker process
  431 root     sshd: /usr/sbin/sshd [listener] 0 of 10-100 startups
  434 root     -bash
  473 dhcpcd   dhcpcd: [BPF ARP] eth0 192.168.0.15
  498 root     [kworker/0:2]
  501 root     [kworker/0:0]
  503 root     [kworker/0:1]
  504 root     key_reset: /usr/sbin/key_reset
  507 root     ps
#

You can see that the key_reset process ID has changed and has been restarted. The key_reset internally opens the watchdog, and if the key_reset program is not started in time to feed the watchdog, the system will restart.

Buildroot System One-Click Restore Configuration Guide

Supports related functional hardware connections

DTU701 Edge Computing Gateway

DTU702 Edge Computing Gateway

DTU802 Edge Computing Gateway

DTU802B Edge Computing Gateway

DTU902 Edge Computing Gateway

G5501 Edge Computing Gateway

G5301 Edge Computing Gateway

Buildroot System One-Click Restore Configuration Guide

Leave a Comment