[[PageOutline]] = 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 Because of these situations with a soft reboot, Gateworks has provided reliable ways to reboot the single board computer. == 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 - Kernel (flsc-3.14 kernel) - [https://github.com/Gateworks/linux-imx6/commit/061ef9dff9c45a0a7941d3a3378367499f8fb9b8 commit 061ef9] - Yocto 1.8 OS [https://github.com/Gateworks/meta-gateworks/commit/22f181ed32b32c746b9b3a4640e85da26ba94bf9 commit 22f181] - Android L5 (3.14.28 kernel) - [https://github.com/Gateworks/linux-imx6/commit/7cb45f3718c5e5e1b384608fc5b9070fa753621f commit 7cb45f3] - OpenWrt 16.02 (4.4 kernel) -[https://github.com/Gateworks/openwrt/commit/3d57ef0c66e6a8ffa71ff79deb70929c8c9603ce 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: {{{#!bash #2147483647 is the max integer for a 32 bit register sync && echo 2147483647 > /sys/bus/i2c/devices/i2c-0/0-0020/powerdown }}} Manual I2C Method: {{{#!bash i2cset -f -y 0 0x20 2 0xff i2cset -f -y 0 0x20 3 0xff i2cset -f -y 0 0x20 4 0xff i2cset -f -y 0 0x20 5 0xff i2cset -f -y 0 0x20 1 0x43 }}} '''However, in order to 'wake up' or turn the board back on, the board pushbutton will need to be pressed. ''' == 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 [wiki:gsc#driver 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') {{{#!bash 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. === Older Manual Method === If for some reason you are using a BSP that does not have the GSC kernel drivers you can do this 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: {{{#!bash #!/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 [wiki:gsc here] = How to Override the Systemd Reboot Process on a Ventana 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. Rather, you must run a script that issues I2C commands to reset the device. We can work around this issue by changing the mechanism systemd uses to reboot the device to use the Ventana reboot script. This allows users and third-party configuration tools, such as Ansible, to reboot the system using traditional system utilities, such as **reboot** and **shutdown** without causing the device to hang. ** NOTICE: The approach outlined in this section is not necessarily recommended. It would likely be frowned upon by the authors of systemd. Further, an update or upgrade of systemd could revert the changes. Use at your own risk. ** == Background 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 [https://www.man7.org/linux/man-pages/man7/bootup.7.html 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. On Ubuntu 18.04, the content of systemd-reboot.service unit file is: {{{ # SPDX-License-Identifier: LGPL-2.1+ # This file is part of systemd. # systemd is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. [Unit] Description=Reboot Documentation=man:systemd-halt.service(8) DefaultDependencies=no Requires=shutdown.target umount.target final.target After=shutdown.target umount.target final.target [Service] Type=oneshot ExecStart=/bin/systemctl --force reboot }}} Changing the systemd-reboot.service command line to run the Gateworks Ventana reboot script rather than run systemctl allows us to override the default reboot behavior. == Steps 1. Copy the Gateworks Ventana reboot script to an appropriate location on the target operating system. Make sure it is owned by root and is marked as executable. In our case, we wrote the contents to /usr/bin/ventana_reboot. {{{ #!/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 }}} {{{#!bash chmod 777 /usr/bin/ventana_reboot }}} 2. Edit /lib/systemd/system/systemd-reboot.service and replace the contents of the ExecStart entry with a call to the Gateworks Ventana reboot script. {{{ # SPDX-License-Identifier: LGPL-2.1+ # This file is part of systemd. # systemd is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. [Unit] Description=Reboot Documentation=man:systemd-halt.service(8) DefaultDependencies=no Requires=shutdown.target umount.target final.target After=shutdown.target umount.target final.target [Service] Type=oneshot ExecStart=/usr/bin/ventana_reboot }}} 3. Reload systemd so that it picks up the changes. {{{#!bash systemctl daemon-reload }}}