Changes between Version 8 and Version 9 of gscreboot


Ignore:
Timestamp:
06/01/2020 11:50:57 PM (4 years ago)
Author:
Cale Collins
Comment:

added systemd reset hack

Legend:

Unmodified
Added
Removed
Modified
  • gscreboot

    v8 v9  
    125125
    126126See the complete GSC reference [wiki:gsc here]
     127
     128= How to Override the Systemd Reboot Process on a Ventana
     129
     130Gateworks 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.
     131We 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.
     132
     133**
     134NOTICE: The approach outlined in this section is admittedly a hack. 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**
     136
     137== Background
     138Shutdown 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.
     139The 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:
     140
     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]
     150Description=Reboot
     151Documentation=man:systemd-halt.service(8)
     152DefaultDependencies=no
     153Requires=shutdown.target umount.target final.target
     154After=shutdown.target umount.target final.target
     155
     156[Service]
     157Type=oneshot
     158ExecStart=/bin/systemctl --force reboot
     159}}}
     160
     161Changing the systemd-reboot.service command line to run the Gateworks Ventana reboot script rather than run systemctl allows us to override the default
     162reboot behavior.
     163
     164== Steps
     165
     1661. 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
     174SECS=${1:-2}
     175# syncs the filesystem
     176echo "Syncing filesystems"
     177sync
     178# perform i2c transactions in loop to retry on i2c timeouts
     179echo "Powering down for $SECS seconds"
     180while [ 1 ]; do
     181# set R6-R9 with 32bit number of seconds to wake
     182i2cset -f -y 0 0x20 6 $((SECS % 256)) || continue
     183SECS=$((SECS >> 8))
     184i2cset -f -y 0 0x20 7 $((SECS % 256)) || continue
     185SECS=$((SECS >> 8))
     186i2cset -f -y 0 0x20 8 $((SECS % 256)) || continue
     187SECS=$((SECS >> 8))
     188i2cset -f -y 0 0x20 9 $((SECS % 256)) || continue
     189# latch sleep time - taking care to not disturb other bits
     190R1=$(i2cget -f -y 0 0x20 1) || continue
     191R1=$((R1 | 0x04)) # set R1.2 LATCH_SLEEP
     192i2cset -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
     194R1=$(i2cget -f -y 0 0x20 1) || continue
     195R1=$((R1 | 0x03)) # set R1.0 and R1.1
     196i2cset -f -y 0 0x20 1 $R1 || continue
     197done
     198}}}
     199
     200{{{#!bash
     201chmod 777 /usr/bin/ventana_reboot
     202}}}
     203
     204
     2052. 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]
     216Description=Reboot
     217Documentation=man:systemd-halt.service(8)
     218DefaultDependencies=no
     219Requires=shutdown.target umount.target final.target
     220After=shutdown.target umount.target final.target
     221
     222[Service]
     223Type=oneshot
     224ExecStart=/usr/bin/ventana_reboot
     225}}}
     226
     2273.  Reload systemd so that it picks up the changes.
     228
     229{{{#!bash
     230systemctl daemon-reload
     231}}}