wiki:gscreboot

Version 13 (modified by Cale Collins, 3 years ago) ( diff )

added note to systemd reboot process

The Reboot Command - History

The reboot command in Linux is a 'soft' reboot which means that the processor is restarted but not actually powered down and powered back on.

Invariably there are situations which sometimes can cause a typical 'soft restart' via the Linux reboot command to hang or not properly restart. There are a variety of reasons for this occurring including:

  • Peripherals left in an unexpected state which don't have a reset line to them
  • Capacitive load issues where certain peripheral combinations can cause the primary power supply to drain slowly resulting in need for a minimum 'power off' time to clear
  • SoC errata

If you need to work around one of these issues the Gateworks GSC SLEEP function can be used to power cycle the single board computer if desired.

Note that boards that have GSCv3 (Newport, Venice, and GW5910, GW5913 from the Ventana family) have a feature that is enabled by default (via CPU_WDOG_POWERCYCLE in the GSC_CTRL_0 register) which will power-cycle the board automatically if the CPU watchdog is tripped, which is what occurs on a soft reboot command. Therefore on these newer boards there is no need to override the 'reboot' command as discussed below.

Reboot Command

In order to have a high reliability Gateworks has designed most of its products with a GSC and a on-board primary power supply which the GSC has the ability to disable. This design provides the following capabilities:

  • Capability of powering the board off, and on again at a specific time (GSC Sleep mode)
  • Providing a sane alternative to soft reset which power-cycles the board (with a user specified 'off' time)

Our latest BSP's have been updated to so that the reboot command will perform a 1 second GSC sleep essentially creating a 'hard' or 'machine' restart:

  • Yocto 1.8
  • Android L5 (3.14.28 kernel) - commit 7cb45f3
  • OpenWrt 16.02 (4.4 kernel) -commit 3d57ef0
    • Example
      • Note the line that states it is using a GSC powerdown
      • Note that the Reset cause shown in example below shows POR, because the GSC actually cycled the board power. If the Reset cause shows WDOG, then the CPU watchdog kicked in, which is not the desired result.
        root@OpenWrt:/# reboot
        root@OpenWrt:/# 
        [  273.301224] imx2-wdt 20bc000.wdog: Device shutdown: Expect reboot!
        [  273.307825] reboot: Restarting system
        [  273.311504] gsc 0-0020: GSC powerdown for 1 seconds
        U-Boot 2015.04-g040377a (Apr 11 2017 - 10:05:57)
        
        CPU:   Freescale i.MX6DL rev1.1 at 792MHz
        CPU:   Industrial temperature grade (-40C to 105C) at 57C
        Reset cause: POR
        
        

poweroff / shutdown command

Gateworks recommend using an indefinite GSC sleep (documented below) rather than the poweroff / shutdown command directly.

For systems with GSC Drivers:

#2147483647 is the max integer for a 32 bit register
sync && echo 2147483647 > /sys/bus/i2c/devices/i2c-0/0-0020/powerdown

Note that a user pushbutton press and release will wake the board up when in sleep mode.

Manual Reboot via GSC Sleep

Older BSP's with the GSC driver (OpenWrt 14.08, Yocto 1.7, Android 4.4.3 (KitKat)) that have an earlier version of the GSC driver can use use the drivers powerdown sysfs hook to request a 1 second powerdown and therefore perform a safe restart as:

  1. Stop any applications or services which may be writing files that you care about
  2. sync the filesystems
  3. Write the number of seconds to power the board down for to the gsc powerdown sysfs hook (recommend 2 seconds as this garuntees '1 to 2 seconds')
    sync && echo 2 > /sys/bus/i2c/devices/i2c-0/0-0020/powerdown
    
  • Note : If performing this reset without a coin cell battery, a maximum of 4 seconds should be used for resetting the board. Anything longer may put the board to 'sleep' and not allow it to wake up without pressing the pushbutton or unplugging and plugging in the main power supply.

GSC Sleep via I2C

If for some reason you are using a BSP that does not have the GSC kernel drivers you can invoke GSC sleep manually with i2cget/i2cset.

Please copy and paste the following code and put it into a file on the Gateworks board called reboot.sh using something like the editor vi.

Then, make the file executable with the chmod command, something like so:

chmod 777 reboot.sh

Then run the command to reboot the board:

./reboot.sh

Reboot Code Below:

#!/bin/sh
#
# usage: gsc_sleep [seconds]
#

# default 2 second sleep ensures between 1 and 2 seconds pass before powerup
SECS=${1:-2}

# syncs the filesystem
echo "Syncing filesystems"
sync

# perform i2c transactions in loop to retry on i2c timeouts
echo "Powering down for $SECS seconds"
while [ 1 ]; do
  # set R6-R9 with 32bit number of seconds to wake
  i2cset -f -y 0 0x20 6 $((SECS % 256)) || continue
  SECS=$((SECS >> 8))
  i2cset -f -y 0 0x20 7 $((SECS % 256)) || continue
  SECS=$((SECS >> 8))
  i2cset -f -y 0 0x20 8 $((SECS % 256)) || continue
  SECS=$((SECS >> 8))
  i2cset -f -y 0 0x20 9 $((SECS % 256)) || continue

  # latch sleep time - taking care to not disturb other bits
  R1=$(i2cget -f -y 0 0x20 1) || continue
  R1=$((R1 | 0x04)) # set R1.2 LATCH_SLEEP
  i2cset -f -y 0 0x20 1 $R1 || continue

  # set R1.0 SLEEP_ENABLE and R1.1 ACTIVATE_SLEEP - taking care not to disturb other bits
  R1=$(i2cget -f -y 0 0x20 1) || continue
  R1=$((R1 | 0x03)) # set R1.0 and R1.1
  i2cset -f -y 0 0x20 1 $R1 || continue
done

See the complete GSC reference here

How to Override the Systemd Reboot Process on a Ventana

NOTE: For Newport and Venice the CPU WDOG output goes to the GSC and the default GSC configuration is to turn a WDOG reset into a power cycle and thus the system-shutdown handler isn't needed.

Gateworks Ventana devices do not reboot using the same mechanisms as a traditional desktop computer. Attempting to reboot the device using traditional Linux commands will cause the device to hang and requires a power cycle to regain connectivity with the device.

Shutdown and reboot are managed by systemd on modern Ubuntu Linux installations. As a matter of fact, the shutdown and reboot utilities are simply symbolic links to the systemctl utility. When the systemctl utility is run as one of these commands, it instructs systemd to transition the system to the desired target. This is the reboot.target in the case of a reboot.

The process systemd uses to reboot is documented in the bootup manpage, which can be viewed by running the command "man 7 bootup". This documentation shows that systemd transitions through a number of targets when it reboots shutting down services along the way. It runs the systemd-reboot.service as the last step to transition to the reboot.target.

To create a gsc-poweroff script in the /lib/systemd/system-shutdown you can do the following:

# add systemd system-shutdown hook to use the GSC to power-down
cat <<\EOF > /lib/systemd/system-shutdown/gsc-poweroff
#!/bin/bash
# use GSC to power cycle the system
echo 2 > /sys/bus/i2c/devices/0-0020/powerdown
EOF
chmod +x /lib/systemd/system-shutdown/gsc-poweroff
Note: See TracWiki for help on using the wiki.