Changes between Version 11 and Version 12 of gscreboot


Ignore:
Timestamp:
07/28/2020 03:17:39 PM (4 years ago)
Author:
Tim Harvey
Comment:

remove extra i2c command example and cleanup

Legend:

Unmodified
Added
Removed
Modified
  • gscreboot

    v11 v12  
    1010 * SoC errata
    1111
    12 Because of these situations with a soft reboot, Gateworks has provided reliable ways to reboot the single board computer.
     12If 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.
     13
     14**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.**
    1315
    1416== Reboot Command ==
     
    5052}}}
    5153
    52 Manual I2C Method:
    53 {{{#!bash
    54 i2cset -f -y 0 0x20 2 0xff
    55 i2cset -f -y 0 0x20 3 0xff
    56 i2cset -f -y 0 0x20 4 0xff
    57 i2cset -f -y 0 0x20 5 0xff
    58 i2cset -f -y 0 0x20 1 0x43
    59 }}}
    60 '''However, in order to 'wake up' or turn the board back on, the board pushbutton will need to be pressed. '''
     54Note that a user pushbutton press and release will wake the board up when in sleep mode.
     55
    6156
    6257== Manual Reboot via GSC Sleep ==
     
    7166 * '''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.
    7267
    73 === Older Manual Method ===
    74 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}}}.
     68== GSC Sleep via I2C ==
     69If 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}}}.
    7570
    7671Please 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.
    7772
    7873Then, make the file executable with the chmod command, something like so:
    79 {{{
     74{{{#!bash
    8075chmod 777 reboot.sh
    8176}}}
     
    128123= How to Override the Systemd Reboot Process on a Ventana
    129124
    130 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.
    131 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.
     125Gateworks 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.
    132126
    133 **
    134 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.
    135 **
     127Shutdown 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.
    136128
    137 == Background
    138 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.
    139 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:
     129The 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.
    140130
    141 {{{
    142 # SPDX-License-Identifier: LGPL-2.1+
    143 # This file is part of systemd.
    144 # systemd is free software; you can redistribute it and/or modify it
    145 # under the terms of the GNU Lesser General Public License as published by
    146 # the Free Software Foundation; either version 2.1 of the License, or
    147 # (at your option) any later version.
    148 
    149 [Unit]
    150 Description=Reboot
    151 Documentation=man:systemd-halt.service(8)
    152 DefaultDependencies=no
    153 Requires=shutdown.target umount.target final.target
    154 After=shutdown.target umount.target final.target
    155 
    156 [Service]
    157 Type=oneshot
    158 ExecStart=/bin/systemctl --force reboot
     131To create a {{{gsc-poweroff}}} script in the {{{/lib/systemd/system-shutdown}}} you can do the following:
     132{{{#!bash
     133# add systemd system-shutdown hook to use the GSC to power-down
     134cat <<\EOF > /lib/systemd/system-shutdown/gsc-poweroff
     135#!/bin/bash
     136# use GSC to power cycle the system
     137echo 2 > /sys/bus/i2c/devices/0-0020/powerdown
     138EOF
     139chmod +x /lib/systemd/system-shutdown/gsc-poweroff
    159140}}}
    160 
    161 Changing the systemd-reboot.service command line to run the Gateworks Ventana reboot script rather than run systemctl allows us to override the default
    162 reboot behavior.
    163 
    164 == Steps
    165 
    166 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.
    167 
    168 {{{
    169 #!/bin/sh
    170 #
    171 # usage: gsc_sleep [seconds]
    172 #
    173 # default 2 second sleep ensures between 1 and 2 seconds pass before powerup
    174 SECS=${1:-2}
    175 # syncs the filesystem
    176 echo "Syncing filesystems"
    177 sync
    178 # perform i2c transactions in loop to retry on i2c timeouts
    179 echo "Powering down for $SECS seconds"
    180 while [ 1 ]; do
    181 # set R6-R9 with 32bit number of seconds to wake
    182 i2cset -f -y 0 0x20 6 $((SECS % 256)) || continue
    183 SECS=$((SECS >> 8))
    184 i2cset -f -y 0 0x20 7 $((SECS % 256)) || continue
    185 SECS=$((SECS >> 8))
    186 i2cset -f -y 0 0x20 8 $((SECS % 256)) || continue
    187 SECS=$((SECS >> 8))
    188 i2cset -f -y 0 0x20 9 $((SECS % 256)) || continue
    189 # latch sleep time - taking care to not disturb other bits
    190 R1=$(i2cget -f -y 0 0x20 1) || continue
    191 R1=$((R1 | 0x04)) # set R1.2 LATCH_SLEEP
    192 i2cset -f -y 0 0x20 1 $R1 || continue
    193 # set R1.0 SLEEP_ENABLE and R1.1 ACTIVATE_SLEEP - taking care not to disturb other bits
    194 R1=$(i2cget -f -y 0 0x20 1) || continue
    195 R1=$((R1 | 0x03)) # set R1.0 and R1.1
    196 i2cset -f -y 0 0x20 1 $R1 || continue
    197 done
    198 }}}
    199 
    200 {{{#!bash
    201 chmod 777 /usr/bin/ventana_reboot
    202 }}}
    203 
    204 
    205 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.
    206 
    207 {{{
    208 # SPDX-License-Identifier: LGPL-2.1+
    209 # This file is part of systemd.
    210 # systemd is free software; you can redistribute it and/or modify it
    211 # under the terms of the GNU Lesser General Public License as published by
    212 # the Free Software Foundation; either version 2.1 of the License, or
    213 # (at your option) any later version.
    214 
    215 [Unit]
    216 Description=Reboot
    217 Documentation=man:systemd-halt.service(8)
    218 DefaultDependencies=no
    219 Requires=shutdown.target umount.target final.target
    220 After=shutdown.target umount.target final.target
    221 
    222 [Service]
    223 Type=oneshot
    224 ExecStart=/usr/bin/ventana_reboot
    225 }}}
    226 
    227 3.  Reload systemd so that it picks up the changes.
    228 
    229 {{{#!bash
    230 systemctl daemon-reload
    231 }}}